get_article_image: return basic kind to which flavor image belongs

master
Andrew Dolgov 4 years ago
parent db3fcb861b
commit e40b79ab33

@ -786,11 +786,15 @@ class API extends Handler {
$headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); $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_image"] = $flavor_image;
$headline_row["flavor_stream"] = $flavor_stream; $headline_row["flavor_stream"] = $flavor_stream;
/* optional */
if ($flavor_kind)
$headline_row["flavor_kind"] = $flavor_kind;
array_push($headlines, $headline_row); array_push($headlines, $headline_row);
} }
} else if (is_numeric($result) && $result == -1) { } else if (is_numeric($result) && $result == -1) {

@ -716,6 +716,11 @@ class Article extends Handler_Protected {
$article_image = ""; $article_image = "";
$article_stream = ""; $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) { 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); 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)) { if ($rrr = preg_match("/\/embed\/([\w-]+)/", $e->getAttribute("src"), $matches)) {
$article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg"; $article_image = "https://img.youtube.com/vi/" . $matches[1] . "/hqdefault.jpg";
$article_stream = "https://youtu.be/" . $matches[1]; $article_stream = "https://youtu.be/" . $matches[1];
$article_kind = ARTICLE_KIND_YOUTUBE;
break; break;
} }
} else if ($e->nodeName == "video") { } else if ($e->nodeName == "video") {
@ -743,6 +749,7 @@ class Article extends Handler_Protected {
if ($src) { if ($src) {
$article_stream = $src->getAttribute("src"); $article_stream = $src->getAttribute("src");
$article_kind = ARTICLE_KIND_VIDEO;
} }
break; break;
@ -778,7 +785,7 @@ class Article extends Handler_Protected {
if ($article_stream && $cache->exists(sha1($article_stream))) if ($article_stream && $cache->exists(sha1($article_stream)))
$article_stream = $cache->getUrl(sha1($article_stream)); $article_stream = $cache->getUrl(sha1($article_stream));
return [$article_image, $article_stream]; return [$article_image, $article_stream, $article_kind];
} }
} }

Loading…
Cancel
Save