diff options
author | Andrew Dolgov <[email protected]> | 2021-04-22 12:00:39 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-04-22 12:00:39 +0300 |
commit | 0b7db7d55ae747c2f3a5f7e11c9d231d93a3e929 (patch) | |
tree | 203c30d08cf2327526b754a6282bc7a184720e5a |
initial
-rw-r--r-- | img/youtube.svg | 1 | ||||
-rw-r--r-- | init.css | 18 | ||||
-rw-r--r-- | init.php | 48 |
3 files changed, 67 insertions, 0 deletions
diff --git a/img/youtube.svg b/img/youtube.svg new file mode 100644 index 0000000..cafd989 --- /dev/null +++ b/img/youtube.svg @@ -0,0 +1 @@ +<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24" height="24" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24" style="-ms-transform: rotate(360deg); -webkit-transform: rotate(360deg); transform: rotate(360deg);"><path d="M10 15l5.19-3L10 9v6m11.56-7.83c.13.47.22 1.1.28 1.9c.07.8.1 1.49.1 2.09L22 12c0 2.19-.16 3.8-.44 4.83c-.25.9-.83 1.48-1.73 1.73c-.47.13-1.33.22-2.65.28c-1.3.07-2.49.1-3.59.1L12 19c-4.19 0-6.8-.16-7.83-.44c-.9-.25-1.48-.83-1.73-1.73c-.13-.47-.22-1.1-.28-1.9c-.07-.8-.1-1.49-.1-2.09L2 12c0-2.19.16-3.8.44-4.83c.25-.9.83-1.48 1.73-1.73c.47-.13 1.33-.22 2.65-.28c1.3-.07 2.49-.1 3.59-.1L12 5c4.19 0 6.8.16 7.83.44c.9.25 1.48.83 1.73 1.73z" fill="black"/><rect x="0" y="0" width="24" height="24" fill="rgba(0, 0, 0, 0)" /></svg>
\ No newline at end of file diff --git a/init.css b/init.css new file mode 100644 index 0000000..1ad5969 --- /dev/null +++ b/init.css @@ -0,0 +1,18 @@ +.youtube-thumb { + position : relative; + display : inline-block; +} + +.youtube-thumb .watermark { + position : absolute; + left : 0; + top : 0; + width : 100% ! important; + height : 100% ! important; + filter : invert(1); + background-image : url("plugins.local/af_youtube_thumb/img/youtube.svg"); + background-size : 140px; + background-position-y : bottom; + background-position-x : 320px; + background-repeat : no-repeat; +} 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; + } + +} |