Skip to content

Commit

Permalink
allow non string input for lettersOnly function
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitexus committed Aug 31, 2023
1 parent 82b7969 commit 293b3b4
Showing 1 changed file with 4 additions and 70 deletions.
74 changes: 4 additions & 70 deletions src/Ease/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 293b3b4

Please sign in to comment.