summaryrefslogtreecommitdiff
path: root/plugins/af_youtube_embed/init.php
blob: ff44bb291a6aaa19b011baf169d74652e8371633 (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
<?php
class Af_Youtube_Embed extends Plugin {

	function about() {
		return array(null,
			"Embed videos in Youtube RSS feeds (and whitelist Youtube iframes)",
			"fox");
	}

	function init($host) {
		$host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this);
		$host->add_hook($host::HOOK_IFRAME_WHITELISTED, $this);
	}

	function hook_iframe_whitelisted($src) {
		return in_array($src, ["www.youtube.com", "youtube.com",
			"www.youtube-nocookie.com", "youtube-nocookie.com",
			"youtu.be"]);
	}

	function hook_render_enclosure($entry, $id, $rv) {

		$url = $entry["content_url"];

		if ($vid_id = UrlHelper::url_to_youtube_vid($url)) {

			return "<div class='embed-responsive'>
				<iframe class='youtube-player'
					type='text/html' width='640' height='385'
					src=\"https://www.youtube.com/embed/$vid_id\"
					allowfullscreen frameborder='0'></iframe>
				</div>";

		}

		return "";
	}

	function api_version() {
		return 2;
	}

}