summaryrefslogtreecommitdiff
path: root/classes/handler/public.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-08-14 16:55:38 +0300
committerAndrew Dolgov <[email protected]>2019-08-14 16:55:38 +0300
commit68e2b05f657dca2a389cb9d585215c126e5da290 (patch)
tree50bc7e4ae3661b08cadec7bdf0b29100dc355dd0 /classes/handler/public.php
parent26dbe02968f543913f67c3d6966ae5fe454d2ab1 (diff)
* 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
Diffstat (limited to 'classes/handler/public.php')
-rwxr-xr-xclasses/handler/public.php32
1 files changed, 2 insertions, 30 deletions
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('<?xml encoding="UTF-8">' . 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 .= "</head>";
- $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 .= "<meta property='og:image' content=\"" . htmlspecialchars($og_image) . "\"/>";