diff options
-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']; |