X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fbookmark%2FLinkUtils.php;h=faf5dbfd4fe24906bf980d8f4cc72e0472b7e008;hb=458b6b9918ec27154dd45416947bb93bedb97109;hp=35a5b290454b32870464c6457fea73059d613f4c;hpb=786f35f2700d83687ef494b98e3dace37d268e1c;p=github%2Fshaarli%2FShaarli.git
diff --git a/application/bookmark/LinkUtils.php b/application/bookmark/LinkUtils.php
index 35a5b290..faf5dbfd 100644
--- a/application/bookmark/LinkUtils.php
+++ b/application/bookmark/LinkUtils.php
@@ -1,64 +1,6 @@
+ * - 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);
+ // We need a OR here to accept either 'property=og:noquote' or 'property="og:unrelated og:my-tag"'
+ $orCondition = '["\']?(?:og:)?'. $tag .'["\']?|["\'][^\'"]*?(?:og:)?' . $tag . '[^\'"]*?[\'"]';
+ // Try to retrieve OpenGraph image.
+ $ogRegex = '#]+(?:'. $properties .')=(?:'. $orCondition .')[^>]*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 .')=(?:'. $orCondition .').*?>#';
+
+ 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
*/
@@ -162,7 +116,7 @@ function hashtag_autolink($description, $indexUrl = '')
* \p{Mn} - any non marking space (accents, umlauts, etc)
*/
$regex = '/(^|\s)#([\p{Pc}\p{N}\p{L}\p{Mn}]+)/mui';
- $replacement = '$1#$2';
+ $replacement = '$1#$2';
return preg_replace($regex, $replacement, $description);
}
@@ -202,7 +156,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);
}
/**