From 68e2b05f657dca2a389cb9d585215c126e5da290 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 14 Aug 2019 16:55:38 +0300 Subject: * move get_article_image to Article; implement better og:image detection (similar to android app) * pass article image to API clients in headlines row object --- classes/handler/public.php | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'classes/handler/public.php') diff --git a/classes/handler/public.php b/classes/handler/public.php index eb5363eab..b476805e1 100755 --- a/classes/handler/public.php +++ b/classes/handler/public.php @@ -157,7 +157,7 @@ class Handler_Public extends Handler { } $tpl->setVariable('ARTICLE_OG_IMAGE', - $this->get_article_image($enclosures, $line['content'], $feed_site_url), true); + Article::get_article_image($enclosures, $line['content'], $feed_site_url), true); $tpl->addBlock('entry'); } @@ -319,34 +319,6 @@ class Handler_Public extends Handler { print "Article not found."; } - private function get_article_image($enclosures, $content, $site_url) { - $og_image = false; - - foreach ($enclosures as $enc) { - if (strpos($enc["content_type"], "image/") !== FALSE) { - return rewrite_relative_url($site_url, $enc["content_url"]); - } - } - - if (!$og_image) { - $tmpdoc = new DOMDocument(); - - if (@$tmpdoc->loadHTML('' . mb_substr($content, 0, 131070))) { - $tmpxpath = new DOMXPath($tmpdoc); - $imgs = $tmpxpath->query("//img"); - - foreach ($imgs as $img) { - $src = $img->getAttribute("src"); - - if (mb_strpos($src, "data:") !== 0) - return rewrite_relative_url($site_url, $src); - } - } - } - - return false; - } - private function format_article($id, $owner_uid) { $pdo = Db::pdo(); @@ -409,7 +381,7 @@ class Handler_Public extends Handler { $rv .= ""; - $og_image = $this->get_article_image($enclosures, $line['content'], $line["site_url"]); + $og_image = Article::get_article_image($enclosures, $line['content'], $line["site_url"]); if ($og_image) { $rv .= ""; -- cgit v1.2.3