X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=plugins%2Fdemo_plugin%2Fdemo_plugin.php;h=8fdbf66383c144226770cc03334701801e7f5da8;hb=ba0fd80732acbff0fcda57a0b31e4edfaa337001;hp=9384c21f53232652b4df891a0a179f3a6f41a8fe;hpb=38603b2450e983edfab5770bd3dd681c6073f898;p=github%2Fshaarli%2FShaarli.git diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php index 9384c21f..8fdbf663 100644 --- a/plugins/demo_plugin/demo_plugin.php +++ b/plugins/demo_plugin/demo_plugin.php @@ -14,6 +14,23 @@ * and check user status with _LOGGEDIN_. */ +/** + * Initialization function. + * It will be called when the plugin is loaded. + * This function can be used to return a list of initialization errors. + * + * @param $conf ConfigManager instance. + * + * @return array List of errors (optional). + */ +function demo_plugin_init($conf) +{ + $conf->get('toto', 'nope'); + + $errors[] = 'This a demo init error.'; + return $errors; +} + /** * Hook render_header. * Executed on every page redering. @@ -33,15 +50,68 @@ function hook_demo_plugin_render_header($data) // If loggedin if ($data['_LOGGEDIN_'] === true) { - // Buttons in toolbar - $data['buttons_toolbar'][] = '
  • DEMO_buttons_toolbar
  • '; + /* + * Links in toolbar: + * A link is an array of its attributes (key="value"), + * and a mandatory `html` key, which contains its value. + */ + $button = array( + 'attr' => array ( + 'href' => '#', + 'class' => 'mybutton', + 'title' => 'hover me', + ), + 'html' => 'DEMO buttons toolbar', + ); + $data['buttons_toolbar'][] = $button; } - // Fields in toolbar - $data['fields_toolbar'][] = 'DEMO_fields_toolbar'; + /* + * Add additional input fields in the tools. + * A field is an array containing: + * [ + * 'form-attribute-1' => 'form attribute 1 value', + * 'form-attribute-2' => 'form attribute 2 value', + * 'inputs' => [ + * [ + * 'input-1-attribute-1 => 'input 1 attribute 1 value', + * 'input-1-attribute-2 => 'input 1 attribute 2 value', + * ], + * [ + * 'input-2-attribute-1 => 'input 2 attribute 1 value', + * ], + * ], + * ] + * This example renders as: + *
    + * + * + *
    + */ + $form = array( + 'attr' => array( + 'method' => 'GET', + 'action' => '?', + 'class' => 'addform', + ), + 'inputs' => array( + array( + 'type' => 'text', + 'name' => 'demo', + 'placeholder' => 'demo', + ) + ) + ); + $data['fields_toolbar'][] = $form; } // Another button always displayed - $data['buttons_toolbar'][] = '
  • DEMO
  • '; + $button = array( + 'attr' => array( + 'href' => '#', + ), + 'html' => 'Demo', + ); + $data['buttons_toolbar'][] = $button; return $data; } @@ -76,6 +146,7 @@ function hook_demo_plugin_render_includes($data) * * Template placeholders: * - text + * - endofpage * - js_files * * Data: @@ -91,6 +162,11 @@ function hook_demo_plugin_render_footer($data) // footer text $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.'; + // Free elements at the end of the page. + $data['endofpage'][] = '' . + 'DEMO: it\'s 1999 all over again!' . + ''; + // List of plugin's JS files. // Note that you just need to specify CSS path. $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js'; @@ -120,8 +196,19 @@ function hook_demo_plugin_render_footer($data) */ function hook_demo_plugin_render_linklist($data) { - // action_plugin - $data['action_plugin'][] = '
    ←
    '; + /* + * Action links (action_plugin): + * A link is an array of its attributes (key="value"), + * and a mandatory `html` key, which contains its value. + * It's also recommended to add key 'on' or 'off' for theme rendering. + */ + $action = array( + 'attr' => array( + 'href' => '?up', + 'title' => 'Uppercase!', + ), + 'html' => '←', + ); if (isset($_GET['up'])) { // Manipulate link data @@ -129,7 +216,11 @@ function hook_demo_plugin_render_linklist($data) $value['description'] = strtoupper($value['description']); $value['title'] = strtoupper($value['title']); } + $action['on'] = true; + } else { + $action['off'] = true; } + $data['action_plugin'][] = $action; // link_plugin (for each link) foreach ($data['links'] as &$value) { @@ -316,4 +407,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; +}