diff options
Diffstat (limited to 'init.php')
-rw-r--r-- | init.php | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/init.php b/init.php new file mode 100644 index 0000000..c16b903 --- /dev/null +++ b/init.php @@ -0,0 +1,48 @@ +<?php +class Af_Youtube_Thumb extends Plugin { + private $host; + + function about() { + return array(null, + "Show Youtube videos as clickable thumbnails", + "fox"); + } + + function init($host) { + $this->host = $host; + + $host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this); + } + + function get_css() { + return file_get_contents(__DIR__ . "/init.css"); + } + + function hook_render_enclosure($entry, $hide_images) { + + $matches = array(); + $url = $entry["content_url"]; + + if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $url, $matches) || + preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $url, $matches) || + preg_match("/\/\/youtu.be\/([\w-]+)/", $url, $matches)) { + + $vid_id = $matches[1]; + + $thumb_url = htmlspecialchars("https://img.youtube.com/vi/$vid_id/hqdefault.jpg"); + $url = htmlspecialchars($url); + + return "<a target='_blank' rel='noopener noreferrer' href=\"$url\" title=\"".$this->__("Click to open video")."\"> + <div class='youtube-thumb'> + <img class='thumbnail' src=\"$thumb_url\" referrerpolicy='no-referrer'> + <div class='watermark' src=\"plugins.local/af_youtube_thumb/img/youtube.svg\"> + </div> + </a>"; + } + } + + function api_version() { + return 2; + } + +} |