summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2022-02-17 11:22:14 +0300
committerAndrew Dolgov <[email protected]>2022-02-17 11:22:18 +0300
commit930ad7292a3d1cdd57edd4fc6ea88bfe67d62579 (patch)
tree0a7c24d5605df51f50ca6751ebfb824384c2d4ba
parente721d2db4049bc3ed9fbf76c5f8c8adc5c895df6 (diff)
* limited support for HOOK_ARTICLE_IMAGE (enclosures only)
* limited support for HOOK_RENDER_ARTICLE_API (content URLs only)
-rw-r--r--init.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/init.php b/init.php
index 014e8de..4556ed2 100644
--- a/init.php
+++ b/init.php
@@ -11,12 +11,29 @@ class Af_Youtube_Thumb extends Plugin {
$host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this);
$host->add_hook($host::HOOK_RENDER_ARTICLE, $this);
$host->add_hook($host::HOOK_RENDER_ARTICLE_CDM, $this);
+ $host->add_hook($host::HOOK_RENDER_ARTICLE_API, $this);
+ $host->add_hook($host::HOOK_ARTICLE_IMAGE, $this);
}
function get_css() {
return file_get_contents(__DIR__ . "/init.css");
}
+ function hook_article_image($enclosures, $content, $site_url, $article) {
+
+ foreach ($enclosures as $enc) {
+ if ($vid_id = UrlHelper::url_to_youtube_vid($enc["content_url"])) {
+ $thumb_url = htmlspecialchars("https://img.youtube.com/vi/$vid_id/hqdefault.jpg");
+
+ return [$thumb_url, "", $content];
+ }
+ }
+
+ // TODO: deal with youtube URLs in article content
+
+ return ["", "", $content];
+ }
+
function hook_render_enclosure($entry, $article_id, $rv) {
$url = $entry["content_url"];
@@ -41,6 +58,12 @@ class Af_Youtube_Thumb extends Plugin {
return $this->hook_render_article_cdm($article);
}
+ function hook_render_article_api($params) {
+ $article = isset($params['headline']) ? $params['headline'] : $params['article'];
+
+ return $this->hook_render_article_cdm($article);
+ }
+
/* function hook_render_article_api($row) {
$article = isset($row['headline']) ? $row['headline'] : $row['article'];