From e40b79ab330b93ef14bb6a71e857673721579d68 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 7 Dec 2020 12:09:06 +0300 Subject: get_article_image: return basic kind to which flavor image belongs --- classes/api.php | 6 +++++- classes/article.php | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/api.php b/classes/api.php index 3bba4fa8d..6b857f689 100755 --- a/classes/api.php +++ b/classes/api.php @@ -786,11 +786,15 @@ class API extends Handler { $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); - list ($flavor_image, $flavor_stream) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]); + list ($flavor_image, $flavor_stream, $flavor_kind) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]); $headline_row["flavor_image"] = $flavor_image; $headline_row["flavor_stream"] = $flavor_stream; + /* optional */ + if ($flavor_kind) + $headline_row["flavor_kind"] = $flavor_kind; + array_push($headlines, $headline_row); } } else if (is_numeric($result) && $result == -1) { diff --git a/classes/article.php b/classes/article.php index 430109283..5b699a103 100755 --- a/classes/article.php +++ b/classes/article.php @@ -716,6 +716,11 @@ class Article extends Handler_Protected { $article_image = ""; $article_stream = ""; + $article_kind = 0; + + define('ARTICLE_KIND_ALBUM', 1); /* TODO */ + define('ARTICLE_KIND_VIDEO', 2); + define('ARTICLE_KIND_YOUTUBE', 3); foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_ARTICLE_IMAGE) as $p) { list ($article_image, $article_stream, $content) = $p->hook_article_image($enclosures, $content, $site_url); @@ -734,6 +739,7 @@ class Article extends Handler_Protected { if ($rrr = preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) { $article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg"; $article_stream = "https://youtu.be/" . $matches[1]; + $article_kind = ARTICLE_KIND_YOUTUBE; break; } } else if ($e->nodeName == "video") { @@ -743,6 +749,7 @@ class Article extends Handler_Protected { if ($src) { $article_stream = $src->getAttribute("src"); + $article_kind = ARTICLE_KIND_VIDEO; } break; @@ -778,7 +785,7 @@ class Article extends Handler_Protected { if ($article_stream && $cache->exists(sha1($article_stream))) $article_stream = $cache->getUrl(sha1($article_stream)); - return [$article_image, $article_stream]; + return [$article_image, $article_stream, $article_kind]; } } -- cgit v1.2.3