]> git.wh0rd.org - tt-rss.git/commitdiff
add HOOK_RENDER_ENCLOSURE & af_youtube_embed plugin
authorAndrew Dolgov <noreply@fakecake.org>
Tue, 21 Apr 2015 11:07:20 +0000 (14:07 +0300)
committerAndrew Dolgov <noreply@fakecake.org>
Tue, 21 Apr 2015 11:07:20 +0000 (14:07 +0300)
classes/pluginhost.php
include/functions2.php
plugins/af_youtube_embed/init.php [new file with mode: 0644]

index 1ad7afd60f1081201e13381a705a48b020ed05e2..4576982912fed6a571e7b875e83b1b97ffecf3b5 100644 (file)
@@ -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;
index a73f9a7a786342f0563e77680937fdbaffefbee0..27b1933d0a0717c38b50b30b53c024c171660dcc 100644 (file)
 
                                        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 .= "<p><img
-                                                                       alt=\"".htmlspecialchars($entry["filename"])."\"
-                                                                       src=\"" .htmlspecialchars($entry["url"]) . "\"
-                                                                       " . $encsize . " /></p>";
-                                                               } else {
-                                                                       $rv .= "<p><a target=\"_blank\"
-                                                                       href=\"".htmlspecialchars($entry["url"])."\"
-                                                                       >" .htmlspecialchars($entry["url"]) . "</a></p>";
-                                                               }
+                                       foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ENCLOSURE) as $plugin)
+                                               $retval = $plugin->hook_render_enclosure($entry, $hide_images);
 
-                                                               if ($entry['title']) {
-                                                                       $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
-                                                               }
+
+                                               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 .= "<p><img
+                                                                               alt=\"".htmlspecialchars($entry["filename"])."\"
+                                                                               src=\"" .htmlspecialchars($entry["url"]) . "\"
+                                                                               " . $encsize . " /></p>";
+                                                                       } else {
+                                                                               $rv .= "<p><a target=\"_blank\"
+                                                                               href=\"".htmlspecialchars($entry["url"])."\"
+                                                                               >" .htmlspecialchars($entry["url"]) . "</a></p>";
+                                                                       }
+
+                                                                       if ($entry['title']) {
+                                                                               $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
+                                                                       }
+                                                       }
                                                }
                                        }
                                }
diff --git a/plugins/af_youtube_embed/init.php b/plugins/af_youtube_embed/init.php
new file mode 100644 (file)
index 0000000..7820113
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+class Af_Youtube_Embed extends Plugin {
+       private $host;
+
+       function about() {
+               return array(1.0,
+                       "Embed videos in Youtube RSS feeds",
+                       "fox");
+       }
+
+       function init($host) {
+               $this->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 "<iframe class=\"youtube-player\"
+                               type=\"text/html\" width=\"640\" height=\"385\"
+                               src=\"https://www.youtube.com/embed/$vid_id\"
+                               allowfullscreen frameborder=\"0\"></iframe>";
+
+               }
+       }
+
+       function api_version() {
+               return 2;
+       }
+
+}
+?>