aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2016-03-12 14:39:06 +0100
committerArthurHoaro <arthur@hoa.ro>2016-03-18 19:13:48 +0100
commitbcd078bf0a5119fe0c8441b803b4fe05fdaa6d18 (patch)
treee2dae6aa50d4a069438c1cd0b0ae7b1bd2c0bd2b
parente67712ba0f8896f0d7e676292f557b5999c2848d (diff)
downloadShaarli-bcd078bf0a5119fe0c8441b803b4fe05fdaa6d18.tar.gz
Shaarli-bcd078bf0a5119fe0c8441b803b4fe05fdaa6d18.tar.zst
Shaarli-bcd078bf0a5119fe0c8441b803b4fe05fdaa6d18.zip
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.
-rw-r--r--index.php6
-rw-r--r--plugins/demo_plugin/demo_plugin.php27
2 files changed, 32 insertions, 1 deletions
diff --git a/index.php b/index.php
index 261c8a37..73b83533 100644
--- a/index.php
+++ b/index.php
@@ -785,6 +785,12 @@ function showRSS($pageBuilder, $linkDB)
785 $data['usepermalinks'] = $usepermalinks; 785 $data['usepermalinks'] = $usepermalinks;
786 $data['links'] = $linkDisp; 786 $data['links'] = $linkDisp;
787 787
788 $pluginManager = PluginManager::getInstance();
789 $pluginManager->executeHooks('render_feed', $data, array(
790 'loggedin' => isLoggedIn(),
791 'target' => Router::$PAGE_RSS,
792 ));
793
788 $pageBuilder->assignAll($data); 794 $pageBuilder->assignAll($data);
789 $pageBuilder->renderPage('feed.rss', false); 795 $pageBuilder->renderPage('feed.rss', false);
790 $cache->cache(ob_get_contents()); 796 $cache->cache(ob_get_contents());
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php
index f5f028e0..18834e53 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)
322 if (strpos($data['url'], 'youtube.com') !== false) { 322 if (strpos($data['url'], 'youtube.com') !== false) {
323 exit('You can not delete a YouTube link. Don\'t ask.'); 323 exit('You can not delete a YouTube link. Don\'t ask.');
324 } 324 }
325} \ No newline at end of file 325}
326
327/**
328 * Execute render_feed hook.
329 * Called with ATOM and RSS feed.
330 *
331 * Special data keys:
332 * - _PAGE_: current page
333 * - _LOGGEDIN_: true/false
334 *
335 * @param array $data data passed to plugin
336 *
337 * @return array altered $data.
338 */
339function hook_demo_plugin_render_feed($data)
340{
341 foreach ($data['links'] as &$link) {
342 if ($data['_PAGE_'] == Router::$PAGE_FEED_ATOM) {
343 $link['description'] .= ' - ATOM Feed' ;
344 }
345 elseif ($data['_PAGE_'] == Router::$PAGE_FEED_RSS) {
346 $link['description'] .= ' - RSS Feed';
347 }
348 }
349 return $data;
350}