blob: c16b9031b03ada86a6ffe6491884796539ee5e6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
}
}
|