From f5302247c6eecba217f35173b3f038cc828a7402 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 29 May 2018 22:04:02 +0300 Subject: share: add support for og:image, etc. metadata for shared articles --- classes/article.php | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) mode change 100644 => 100755 classes/article.php (limited to 'classes/article.php') diff --git a/classes/article.php b/classes/article.php old mode 100644 new mode 100755 index edf95b743..c8ee5b931 --- a/classes/article.php +++ b/classes/article.php @@ -629,16 +629,52 @@ class Article extends Handler_Protected { } } + $enclosures = self::get_article_enclosures($line["id"]); + if ($zoom_mode) { header("Content-Type: text/html"); - $rv['content'] .= " + $rv['content'] .= " + ".$line["title"]."". stylesheet_tag("css/default.css")." - + "; + + $rv['content'] .= "\n"; + $rv['content'] .= "\n"; + $rv['content'] .= "\n"; + + $rv['content'] .= ""; + + $og_image = false; + + foreach ($enclosures as $enc) { + if (strpos($enc["content_type"], "image/") !== FALSE) { + $og_image = $enc["content_url"]; + break; + } + } + + if (!$og_image) { + $tmpdoc = new DOMDocument(); + + if (@$tmpdoc->loadHTML(mb_substr($line["content"], 0, 131070))) { + $tmpxpath = new DOMXPath($tmpdoc); + $first_img = $tmpxpath->query("//img")->item(0); + + if ($first_img) { + $og_image = $first_img->getAttribute("src"); + } + } + } + + if ($og_image) { + $rv['content'] .= ""; + } - "; + $rv['content'] .= ""; } $rv['content'] .= "
"; -- cgit v1.2.3