You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
<?php
|
|
class YFrames extends Plugin {
|
|
|
|
private $host;
|
|
|
|
function about() {
|
|
return array(1.0,
|
|
"iFrames for Youtube feeds",
|
|
"phga");
|
|
}
|
|
|
|
function init($host) {
|
|
$this->host = $host;
|
|
|
|
$host->add_hook($host::HOOK_ARTICLE_FILTER, $this);
|
|
$host->add_hook($host::HOOK_IFRAME_WHITELISTED, $this);
|
|
}
|
|
|
|
function hook_iframe_whitelisted($src) {
|
|
return in_array($src, ["www.youtube.com", "youtube.com", "youtu.be"]);
|
|
}
|
|
|
|
function hook_article_filter($article) {
|
|
|
|
// Match allowed links and extract "video ID"
|
|
if (preg_match_all("/.*(youtube|youtu)\.(com|be)\/watch\?v=([\w\d_-]+).*/i",
|
|
$article["link"], $matches, PREG_PATTERN_ORDER)) {
|
|
|
|
if ($matches[3][0]) {
|
|
$link = "https://www.youtube.com/embed/" . $matches[3][0];
|
|
$attributes = "width='819' height='460' class='youtube-player' allowfullscreen";
|
|
$yframe = "<iframe src='$link' $attributes></iframe>";
|
|
|
|
$article["content"] = $yframe;
|
|
}
|
|
}
|
|
|
|
$article["content"] .= "<br/>" . $link;
|
|
return $article;
|
|
}
|
|
|
|
function api_version() {
|
|
return 2;
|
|
}
|
|
|
|
}
|