]>
git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/demo_plugin/demo_plugin.php
5 * This plugin try to cover Shaarli's plugin API entirely.
6 * Can be used by plugin developper to make their own.
10 * RENDER HEADER, INCLUDES, FOOTER
12 * Those hooks are called at every page rendering.
13 * You can filter its execution by checking _PAGE_ value
14 * and check user status with _LOGGEDIN_.
18 * Initialization function.
19 * It will be called when the plugin is loaded.
20 * This function can be used to return a list of initialization errors.
22 * @param $conf ConfigManager instance.
24 * @return array List of errors (optional).
26 function demo_plugin_init($conf)
28 $conf->get('toto', 'nope');
30 $errors[] = 'This a demo init error.';
36 * Executed on every page redering.
38 * Template placeholders:
42 * @param array $data data passed to plugin
44 * @return array altered $data.
46 function hook_demo_plugin_render_header($data)
48 // Only execute when linklist is rendered.
49 if ($data['_PAGE_'] == Router
::$PAGE_LINKLIST) {
52 if ($data['_LOGGEDIN_'] === true) {
55 * A link is an array of its attributes (key="value"),
56 * and a mandatory `html` key, which contains its value.
61 'class' => 'mybutton',
62 'title' => 'hover me',
64 'html' => 'DEMO buttons toolbar',
66 $data['buttons_toolbar'][] = $button;
70 * Add additional input fields in the tools.
71 * A field is an array containing:
73 * 'form-attribute-1' => 'form attribute 1 value',
74 * 'form-attribute-2' => 'form attribute 2 value',
77 * 'input-1-attribute-1 => 'input 1 attribute 1 value',
78 * 'input-1-attribute-2 => 'input 1 attribute 2 value',
81 * 'input-2-attribute-1 => 'input 2 attribute 1 value',
85 * This example renders as:
86 * <form form-attribute-1="form attribute 1 value" form-attribute-2="form attribute 2 value">
87 * <input input-1-attribute-1="input 1 attribute 1 value" input-1-attribute-2="input 1 attribute 2 value">
88 * <input input-2-attribute-1="input 2 attribute 1 value">
101 'placeholder' => 'demo',
105 $data['fields_toolbar'][] = $form;
107 // Another button always displayed
114 $data['buttons_toolbar'][] = $button;
120 * Hook render_includes.
121 * Executed on every page redering.
123 * Template placeholders:
127 * - _PAGE_: current page
128 * - _LOGGEDIN_: true/false
130 * @param array $data data passed to plugin
132 * @return array altered $data.
134 function hook_demo_plugin_render_includes($data)
136 // List of plugin's CSS files.
137 // Note that you just need to specify CSS path.
138 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
144 * Hook render_footer.
145 * Executed on every page redering.
147 * Template placeholders:
153 * - _PAGE_: current page
154 * - _LOGGEDIN_: true/false
156 * @param array $data data passed to plugin
158 * @return array altered $data.
160 function hook_demo_plugin_render_footer($data)
163 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
165 // Free elements at the end of the page.
166 $data['endofpage'][] = '<marquee id="demo_marquee">' .
167 'DEMO: it\'s 1999 all over again!' .
170 // List of plugin's JS files.
171 // Note that you just need to specify CSS path.
172 $data['js_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
182 * Hook render_linklist.
184 * Template placeholders:
185 * - action_plugin: next to 'private only' button.
186 * - plugin_start_zone: page start
187 * - plugin_end_zone: page end
188 * - link_plugin: icons below each links.
191 * - _LOGGEDIN_: true/false
193 * @param array $data data passed to plugin
195 * @return array altered $data.
197 function hook_demo_plugin_render_linklist($data)
200 * Action links (action_plugin):
201 * A link is an array of its attributes (key="value"),
202 * and a mandatory `html` key, which contains its value.
203 * It's also recommended to add key 'on' or 'off' for theme rendering.
208 'title' => 'Uppercase!',
213 if (isset($_GET['up'])) {
214 // Manipulate link data
215 foreach ($data['links'] as &$value) {
216 $value['description'] = strtoupper($value['description']);
217 $value['title'] = strtoupper($value['title']);
219 $action['on'] = true;
221 $action['off'] = true;
223 $data['action_plugin'][] = $action;
225 // link_plugin (for each link)
226 foreach ($data['links'] as &$value) {
227 $value['link_plugin'][] = ' DEMO \o/';
231 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
233 $data['plugin_end_zone'][] = '<center>AFTER</center>';
239 * Hook render_editlink.
241 * Template placeholders:
242 * - field_plugin: add link fields after tags.
244 * @param array $data data passed to plugin
246 * @return array altered $data.
248 function hook_demo_plugin_render_editlink($data)
250 // Load HTML into a string
251 $html = file_get_contents(PluginManager
::$PLUGINS_PATH .'/demo_plugin/field.html');
253 // replace value in HTML if it exists in $data
254 if (!empty($data['link']['stuff'])) {
255 $html = sprintf($html, $data['link']['stuff']);
257 $html = sprintf($html, '');
261 $data['edit_link_plugin'][] = $html;
269 * Template placeholders:
270 * - tools_plugin: after other tools.
272 * @param array $data data passed to plugin
274 * @return array altered $data.
276 function hook_demo_plugin_render_tools($data)
279 $data['tools_plugin'][] = 'tools_plugin';
285 * Hook render_picwall.
287 * Template placeholders:
288 * - plugin_start_zone: page start.
289 * - plugin_end_zone: page end.
292 * - _LOGGEDIN_: true/false
294 * @param array $data data passed to plugin
296 * @return array altered $data.
298 function hook_demo_plugin_render_picwall($data)
301 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
303 $data['plugin_end_zone'][] = '<center>AFTER</center>';
309 * Hook render_tagcloud.
311 * Template placeholders:
312 * - plugin_start_zone: page start.
313 * - plugin_end_zone: page end.
316 * - _LOGGEDIN_: true/false
318 * @param array $data data passed to plugin
320 * @return array altered $data.
322 function hook_demo_plugin_render_tagcloud($data)
325 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
327 $data['plugin_end_zone'][] = '<center>AFTER</center>';
335 * Template placeholders:
336 * - plugin_start_zone: page start.
337 * - plugin_end_zone: page end.
340 * - _LOGGEDIN_: true/false
342 * @param array $data data passed to plugin
344 * @return array altered $data.
346 function hook_demo_plugin_render_daily($data)
349 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
351 $data['plugin_end_zone'][] = '<center>AFTER</center>';
354 // Manipulate columns data
355 foreach ($data['cols'] as &$value) {
356 foreach ($value as &$value2) {
357 $value2['formatedDescription'] .= ' ಠ_ಠ';
361 // Add plugin content at the end of each link
362 foreach ($data['cols'] as &$value) {
363 foreach ($value as &$value2) {
364 $value2['link_plugin'][] = 'DEMO';
378 * Triggered when a link is save (new or edit).
379 * All new links now contain a 'stuff' value.
381 * @param array $data contains the new link data.
383 * @return array altered $data.
385 function hook_demo_plugin_save_link($data)
388 // Save stuff added in editlink field
389 if (!empty($_POST['lf_stuff'])) {
390 $data['stuff'] = escape($_POST['lf_stuff']);
399 * Triggered when a link is deleted.
401 * @param array $data contains the link to be deleted.
403 * @return array altered data.
405 function hook_demo_plugin_delete_link($data)
407 if (strpos($data['url'], 'youtube.com') !== false) {
408 exit('You can not delete a YouTube link. Don\'t ask.');
413 * Execute render_feed hook.
414 * Called with ATOM and RSS feed.
417 * - _PAGE_: current page
418 * - _LOGGEDIN_: true/false
420 * @param array $data data passed to plugin
422 * @return array altered $data.
424 function hook_demo_plugin_render_feed($data)
426 foreach ($data['links'] as &$link) {
427 if ($data['_PAGE_'] == Router
::$PAGE_FEED_ATOM) {
428 $link['description'] .= ' - ATOM Feed' ;
430 elseif ($data['_PAGE_'] == Router
::$PAGE_FEED_RSS) {
431 $link['description'] .= ' - RSS Feed';