2015-04-21 11:07:20 +00:00
|
|
|
<?php
|
|
|
|
class Af_Youtube_Embed extends Plugin {
|
|
|
|
|
|
|
|
function about() {
|
2021-03-01 09:11:42 +00:00
|
|
|
return array(null,
|
2019-11-27 19:46:43 +00:00
|
|
|
"Embed videos in Youtube RSS feeds (and whitelist Youtube iframes)",
|
2015-04-21 11:07:20 +00:00
|
|
|
"fox");
|
|
|
|
}
|
|
|
|
|
|
|
|
function init($host) {
|
|
|
|
$host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this);
|
2019-11-27 19:46:43 +00:00
|
|
|
$host->add_hook($host::HOOK_IFRAME_WHITELISTED, $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hook_iframe_whitelisted($src) {
|
2021-05-07 04:37:27 +00:00
|
|
|
return in_array($src, ["www.youtube.com", "youtube.com",
|
|
|
|
"www.youtube-nocookie.com", "youtube-nocookie.com",
|
|
|
|
"youtu.be"]);
|
2015-04-21 11:07:20 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 08:11:49 +00:00
|
|
|
function hook_render_enclosure($entry, $id, $rv) {
|
2015-04-21 11:07:20 +00:00
|
|
|
|
2021-05-07 04:37:27 +00:00
|
|
|
$url = $entry["content_url"];
|
2015-04-21 11:07:20 +00:00
|
|
|
|
2021-05-07 04:37:27 +00:00
|
|
|
if ($vid_id = UrlHelper::url_to_youtube_vid($url)) {
|
2015-04-21 11:07:20 +00:00
|
|
|
|
2021-04-21 15:47:49 +00:00
|
|
|
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>";
|
2015-04-21 11:07:20 +00:00
|
|
|
|
|
|
|
}
|
2021-11-14 17:19:12 +00:00
|
|
|
|
|
|
|
return "";
|
2015-04-21 11:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function api_version() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|