From bcd078bf0a5119fe0c8441b803b4fe05fdaa6d18 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 12 Mar 2016 14:39:06 +0100 Subject: [PATCH] Plugin: add render_feed hook and call it while generating ATOM and RSS feed. Create an example of the new hook in the demo plugin. --- index.php | 6 ++++++ plugins/demo_plugin/demo_plugin.php | 27 ++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 261c8a3..73b8353 100644 --- 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()); diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index f5f028e..18834e5 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -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; +}