X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLinkUtils.php;h=976474de721ad14636b9b431f0cec06a8920e120;hb=b3e1f92e9cd0cae35bc726ca3a2356b4e631ccfa;hp=eeca631f566ad5ee84d1eb76cc7f20e439355a13;hpb=9ccca40189652e529732683abcdf54fcf775c9ec;p=github%2Fshaarli%2FShaarli.git diff --git a/application/LinkUtils.php b/application/LinkUtils.php index eeca631f..976474de 100644 --- a/application/LinkUtils.php +++ b/application/LinkUtils.php @@ -81,7 +81,7 @@ function html_extract_charset($html) /** * Count private links in given linklist. * - * @param array $links Linklist. + * @param array|Countable $links Linklist. * * @return int Number of private links. */ @@ -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; @@ -162,9 +164,23 @@ function space2nbsp($text) * * @param string $description shaare's description. * @param string $redirector if a redirector is set, use it to gerenate links. + * @param string $indexUrl URL to Shaarli's index. * * @return string formatted description. */ 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); +}