diff options
author | Andrew Dolgov <[email protected]> | 2022-02-17 11:22:14 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-02-17 11:22:18 +0300 |
commit | 930ad7292a3d1cdd57edd4fc6ea88bfe67d62579 (patch) | |
tree | 0a7c24d5605df51f50ca6751ebfb824384c2d4ba | |
parent | e721d2db4049bc3ed9fbf76c5f8c8adc5c895df6 (diff) |
* limited support for HOOK_ARTICLE_IMAGE (enclosures only)
* limited support for HOOK_RENDER_ARTICLE_API (content URLs only)
-rw-r--r-- | init.php | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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']; |