]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Plugin: add render_feed hook and call it while generating ATOM and RSS feed.
authorArthurHoaro <arthur@hoa.ro>
Sat, 12 Mar 2016 13:39:06 +0000 (14:39 +0100)
committerArthurHoaro <arthur@hoa.ro>
Fri, 18 Mar 2016 18:13:48 +0000 (19:13 +0100)
Create an example of the new hook in the demo plugin.

index.php
plugins/demo_plugin/demo_plugin.php

index 261c8a376b396c983a0e7e3c1d0f62a81db8c725..73b83533bf35be224b9a2a6e11e8697bb3a7afc5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -785,6 +785,12 @@ function showRSS($pageBuilder, $linkDB)
     $data['usepermalinks'] = $usepermalinks;
     $data['links'] = $linkDisp;
 
+    $pluginManager = PluginManager::getInstance();
+    $pluginManager->executeHooks('render_feed', $data, array(
+        'loggedin' => isLoggedIn(),
+        'target' => Router::$PAGE_RSS,
+    ));
+
     $pageBuilder->assignAll($data);
     $pageBuilder->renderPage('feed.rss', false);
     $cache->cache(ob_get_contents());
index f5f028e023c68a583ff12c5e7c0837006655492b..18834e5331d91cc9d217c18a284056097bcc23db 100644 (file)
@@ -322,4 +322,29 @@ function hook_demo_plugin_delete_link($data)
     if (strpos($data['url'], 'youtube.com') !== false) {
         exit('You can not delete a YouTube link. Don\'t ask.');
     }
-}
\ No newline at end of file
+}
+
+/**
+ * Execute render_feed hook.
+ * Called with ATOM and RSS feed.
+ *
+ * Special data keys:
+ *   - _PAGE_: current page
+ *   - _LOGGEDIN_: true/false
+ *
+ * @param array $data data passed to plugin
+ *
+ * @return array altered $data.
+ */
+function hook_demo_plugin_render_feed($data)
+{
+    foreach ($data['links'] as &$link) {
+        if ($data['_PAGE_'] == Router::$PAGE_FEED_ATOM) {
+            $link['description'] .= ' - ATOM Feed' ;
+        }
+        elseif ($data['_PAGE_'] == Router::$PAGE_FEED_RSS) {
+            $link['description'] .= ' - RSS Feed';
+        }
+    }
+    return $data;
+}