X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLinkUtils.php;h=267e62cde41f9193e384cede8665311fe76ccd6e;hb=3512f4461722c9a3c7cf6511232bda156bf91970;hp=9d9ae3cb29f603f6a82a8125bf3cc4b8860c1183;hpb=7af9a41881ed0b9d44d18a0ce03a123a8441adf5;p=github%2Fshaarli%2FShaarli.git diff --git a/application/LinkUtils.php b/application/LinkUtils.php index 9d9ae3cb..267e62cd 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php @@ -89,7 +89,9 @@ function count_private($links) { $cpt = 0; foreach ($links as $link) { - $cpt = $link['private'] == true ? $cpt + 1 : $cpt; + if ($link['private']) { + $cpt += 1; + } } return $cpt; @@ -107,7 +109,7 @@ function count_private($links) */ function text2clickable($text, $redirector = '') { - $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[[:alnum:]]/?)!si'; + $regex = '!(((?:https?|ftp|file)://|apt:|magnet:)\S+[a-z0-9\(\)]/?)!si'; if (empty($redirector)) { return preg_replace($regex, '$1', $text); @@ -169,3 +171,16 @@ function space2nbsp($text) function format_description($description, $redirector = '', $indexUrl = '') { return nl2br(space2nbsp(hashtag_autolink(text2clickable($description, $redirector), $indexUrl))); } + +/** + * Generate a small hash for a link. + * + * @param DateTime $date Link creation date. + * @param int $id Link ID. + * + * @return string the small hash generated from link data. + */ +function link_small_hash($date, $id) +{ + return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); +}