X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fbookmark%2FLinkUtils.php;h=8837943037dd52468ff6e73bbbc39f8e669b1b04;hb=78c2f122e067f8bab62deb7ef758708721f4a9ba;hp=35a5b290454b32870464c6457fea73059d613f4c;hpb=786f35f2700d83687ef494b98e3dace37d268e1c;p=github%2Fshaarli%2FShaarli.git diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php index 35a5b290..88379430 100644 --- a/application/bookmark/LinkUtils.php +++ b/application/bookmark/LinkUtils.php @@ -1,19 +1,31 @@ + * - Meta tag: * - * @param array|Countable $links Linklist. + * @param string $tag Name of the tag to retrieve. + * @param string $html HTML content where to look for charset. * - * @return int Number of private links. + * @return bool|string Charset string if found, false otherwise. */ -function count_private($links) +function html_extract_tag($tag, $html) { - $cpt = 0; - foreach ($links as $link) { - if ($link['private']) { - $cpt += 1; - } + $propertiesKey = ['property', 'name', 'itemprop']; + $properties = implode('|', $propertiesKey); + // Try to retrieve OpenGraph image. + $ogRegex = '#]+(?:'. $properties .')=["\']?(?:og:)?'. $tag .'["\'\s][^>]*content=["\']?(.*?)["\'/>]#'; + // If the attributes are not in the order property => content (e.g. Github) + // New regex to keep this readable... more or less. + $ogRegexReverse = '#]+content=["\']([^"\']+)[^>]+(?:'. $properties .')=["\']?(?:og)?:'. $tag .'["\'\s/>]#'; + + if (preg_match($ogRegex, $html, $matches) > 0 + || preg_match($ogRegexReverse, $html, $matches) > 0 + ) { + return $matches[1]; } - return $cpt; + return false; } /** - * In a string, converts URLs to clickable links. + * In a string, converts URLs to clickable bookmarks. * * @param string $text input string. * - * @return string returns $text with all links converted to HTML links. + * @return string returns $text with all bookmarks converted to HTML bookmarks. * * @see Function inspired from http://www.php.net/manual/en/function.preg-replace.php#85722 */ @@ -202,7 +260,7 @@ function format_description($description, $indexUrl = '') */ function link_small_hash($date, $id) { - return smallHash($date->format(LinkDB::LINK_DATE_FORMAT) . $id); + return smallHash($date->format(Bookmark::LINK_DATE_FORMAT) . $id); } /**