From: Andrew Dolgov Date: Tue, 21 Apr 2015 11:07:20 +0000 (+0300) Subject: add HOOK_RENDER_ENCLOSURE & af_youtube_embed plugin X-Git-Tag: 16.3~328 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=945346cbffe266beb48e930af859879821fb8ad6;p=tt-rss.git add HOOK_RENDER_ENCLOSURE & af_youtube_embed plugin --- diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 1ad7afd6..45769829 100644 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -43,6 +43,7 @@ class PluginHost { const HOOK_FORMAT_ENCLOSURES = 26; const HOOK_SUBSCRIBE_FEED = 27; const HOOK_HEADLINES_BEFORE = 28; + const HOOK_RENDER_ENCLOSURE = 29; const KIND_ALL = 1; const KIND_SYSTEM = 2; diff --git a/include/functions2.php b/include/functions2.php index a73f9a7a..27b1933d 100644 --- a/include/functions2.php +++ b/include/functions2.php @@ -1940,28 +1940,37 @@ foreach ($entries as $entry) { - if (preg_match("/image/", $entry["type"]) || - preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) { - - if (!$hide_images) { - $encsize = ''; - if ($entry['height'] > 0) - $encsize .= ' height="' . intval($entry['width']) . '"'; - if ($entry['width'] > 0) - $encsize .= ' width="' . intval($entry['height']) . '"'; - $rv .= "

\"".htmlspecialchars($entry["filename"])."\"

"; - } else { - $rv .= "

" .htmlspecialchars($entry["url"]) . "

"; - } + foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin) + $retval = $plugin->hook_render_enclosure($entry, $hide_images); - if ($entry['title']) { - $rv.= "
${entry['title']}
"; - } + + if ($retval) { + $rv .= $retval; + } else { + + if (preg_match("/image/", $entry["type"]) || + preg_match("/\.(jpg|png|gif|bmp)/i", $entry["filename"])) { + + if (!$hide_images) { + $encsize = ''; + if ($entry['height'] > 0) + $encsize .= ' height="' . intval($entry['width']) . '"'; + if ($entry['width'] > 0) + $encsize .= ' width="' . intval($entry['height']) . '"'; + $rv .= "

\"".htmlspecialchars($entry["filename"])."\"

"; + } else { + $rv .= "

" .htmlspecialchars($entry["url"]) . "

"; + } + + if ($entry['title']) { + $rv.= "
${entry['title']}
"; + } + } } } } diff --git a/plugins/af_youtube_embed/init.php b/plugins/af_youtube_embed/init.php new file mode 100644 index 00000000..78201134 --- /dev/null +++ b/plugins/af_youtube_embed/init.php @@ -0,0 +1,40 @@ +host = $host; + + $host->add_hook($host::HOOK_RENDER_ENCLOSURE, $this); + } + + function hook_render_enclosure($entry, $hide_images) { + + $matches = array(); + + if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry["url"], $matches) || + preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry["url"], $matches) || + preg_match("/\/\/youtu.be\/([\w-]+)/", $entry["url"], $matches)) { + + $vid_id = $matches[1]; + + return ""; + + } + } + + function api_version() { + return 2; + } + +} +?>