-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow non string input for lettersOnly function
- Loading branch information
Showing
1 changed file
with
4 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,72 +71,6 @@ public static function addUrlParams($url, array $addParams, | |
return $urlFinal; | ||
} | ||
|
||
/** | ||
* Turn all URLs in clickable links. | ||
* | ||
* @author Arnold Daniels <[email protected]> | ||
* | ||
* @param string $value | ||
* @param array $protocols http/https, ftp, mail, twitter | ||
* @param array $attributes | ||
* @param string $mode normal or all | ||
* | ||
* @deprecated since version 1.37 | ||
* | ||
* @return string | ||
*/ | ||
public static function linkify($value, $protocols = array('http', 'mail'), | ||
array $attributes = array()) { | ||
// Link attributes | ||
$attr = ''; | ||
foreach ($attributes as $key => $val) { | ||
$attr = ' ' . strval($key) . '="' . htmlentities(strval($val)) . '"'; | ||
} | ||
|
||
$links = array(); | ||
|
||
// Extract existing links and tags | ||
$value = preg_replace_callback('~(<a .*?>.*?</a>|<.*?>)~i', | ||
function ($match) use (&$links) { | ||
return '<' . array_push($links, $match[1]) . '>'; | ||
}, $value); | ||
|
||
// Extract text links for each protocol | ||
foreach ((array) $protocols as $protocol) { | ||
switch ($protocol) { | ||
case 'http': | ||
case 'https': $value = preg_replace_callback('~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i', | ||
function ($match) use ($protocol, &$links, $attr) { | ||
if ($match[1]) | ||
$protocol = $match[1]; | ||
$link = $match[2] ?: $match[3]; | ||
return '<' . array_push($links, | ||
"<a $attr href=\"$protocol://$link\">$link</a>") . '>'; | ||
}, $value); | ||
break; | ||
case 'mail': $value = preg_replace_callback('~([^\s<]+?@[^\s<]+?\.[^\s<]+)(?<![\.,:])~', | ||
function ($match) use (&$links, $attr) { | ||
return '<' . array_push($links, | ||
"<a $attr href=\"mailto:{$match[1]}\">{$match[1]}</a>") . '>'; | ||
}, $value); | ||
break; | ||
default: $value = preg_replace_callback('~' . preg_quote($protocol, | ||
'~') . '://([^\s<]+?)(?<![\.,:])~i', | ||
function ($match) use ($protocol, &$links, $attr) { | ||
return '<' . array_push($links, | ||
"<a $attr href=\"$protocol://{$match[1]}\">{$match[1]}</a>") . '>'; | ||
}, $value); | ||
break; | ||
} | ||
} | ||
|
||
// Insert all link | ||
return preg_replace_callback('/<(\d+)>/', | ||
function ($match) use (&$links) { | ||
return $links[$match[1] - 1]; | ||
}, $value); | ||
} | ||
|
||
/** | ||
* Move data field $columName from $sourceArray to $destinationArray. | ||
* | ||
|
@@ -411,8 +345,8 @@ public static function reindexArrayBy(array $data, string $indexBy = null) { | |
* | ||
* @return string text bez zvláštních znaků | ||
*/ | ||
public static function lettersOnly($text) { | ||
return preg_replace('/[^(a-zA-Z0-9)]*/', '', $text); | ||
public static function lettersOnly($text): string { | ||
return preg_replace('/[^(a-zA-Z0-9)]*/', '', strval($text)); | ||
} | ||
|
||
/** | ||
|
@@ -422,7 +356,7 @@ public static function lettersOnly($text) { | |
* | ||
* @return boolean | ||
*/ | ||
public static function isSerialized(string $data) { | ||
public static function isSerialized(string $data): bool { | ||
$data = trim($data); | ||
if ('N;' == $data) { | ||
return true; | ||
|
@@ -499,7 +433,7 @@ public static function formatBytes($bytes) { | |
* @param string $constant | ||
* @param mixed $cfg Default value | ||
* | ||
* @return string | ||
* @return string|int|boolean | ||
*/ | ||
public static function cfg(/*string*/ $constant, $cfg = null) { | ||
if (!empty($constant) && defined($constant)) { | ||
|