get('toto', 'nope'); $errors[] = 'This a demo init error.'; return $errors; } /** * Hook render_header. * Executed on every page redering. * * Template placeholders: * - buttons_toolbar * - fields_toolbar * * @param array $data data passed to plugin * * @return array altered $data. */ function hook_demo_plugin_render_header($data) { // Only execute when linklist is rendered. if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) { // If loggedin if ($data['_LOGGEDIN_'] === true) { /* * 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; } /* * 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 $button = array( 'attr' => array( 'href' => '#', ), 'html' => 'Demo', ); $data['buttons_toolbar'][] = $button; return $data; } /** * Hook render_includes. * Executed on every page redering. * * Template placeholders: * - css_files * * Data: * - _PAGE_: current page * - _LOGGEDIN_: true/false * * @param array $data data passed to plugin * * @return array altered $data. */ function hook_demo_plugin_render_includes($data) { // List of plugin's CSS files. // Note that you just need to specify CSS path. $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/demo_plugin/custom_demo.css'; return $data; } /** * Hook render_footer. * Executed on every page redering. * * Template placeholders: * - text * - endofpage * - js_files * * Data: * - _PAGE_: current page * - _LOGGEDIN_: true/false * * @param array $data data passed to plugin * * @return array altered $data. */ 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'][] = ''; // 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'; return $data; } /* * SPECIFIC PAGES */ /** * Hook render_linklist. * * Template placeholders: * - action_plugin: next to 'private only' button. * - plugin_start_zone: page start * - plugin_end_zone: page end * - link_plugin: icons below each links. * * Data: * - _LOGGEDIN_: true/false * * @param array $data data passed to plugin * * @return array altered $data. */ function hook_demo_plugin_render_linklist($data) { /* * 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 foreach ($data['links'] as &$value) { $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) { $value['link_plugin'][] = ' DEMO \o/'; } // plugin_start_zone $data['plugin_start_zone'][] = '