]>
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.
60 'class' => 'mybutton',
61 'title' => 'hover me',
62 'html' => 'DEMO buttons toolbar',
64 $data['buttons_toolbar'][] = $button;
68 * Add additional input fields in the tools.
69 * A field is an array containing:
71 * 'form-attribute-1' => 'form attribute 1 value',
72 * 'form-attribute-2' => 'form attribute 2 value',
75 * 'input-1-attribute-1 => 'input 1 attribute 1 value',
76 * 'input-1-attribute-2 => 'input 1 attribute 2 value',
79 * 'input-2-attribute-1 => 'input 2 attribute 1 value',
83 * This example renders as:
84 * <form form-attribute-1="form attribute 1 value" form-attribute-2="form attribute 2 value">
85 * <input input-1-attribute-1="input 1 attribute 1 value" input-1-attribute-2="input 1 attribute 2 value">
86 * <input input-2-attribute-1="input 2 attribute 1 value">
97 'placeholder' => 'demo',
101 $data['fields_toolbar'][] = $form;
103 // Another button always displayed
108 $data['buttons_toolbar'][] = $button;
114 * Hook render_includes.
115 * Executed on every page redering.
117 * Template placeholders:
121 * - _PAGE_: current page
122 * - _LOGGEDIN_: true/false
124 * @param array $data data passed to plugin
126 * @return array altered $data.
128 function hook_demo_plugin_render_includes($data)
130 // List of plugin's CSS files.
131 // Note that you just need to specify CSS path.
132 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
138 * Hook render_footer.
139 * Executed on every page redering.
141 * Template placeholders:
147 * - _PAGE_: current page
148 * - _LOGGEDIN_: true/false
150 * @param array $data data passed to plugin
152 * @return array altered $data.
154 function hook_demo_plugin_render_footer($data)
157 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
159 // Free elements at the end of the page.
160 $data['endofpage'][] = '<marquee id="demo_marquee">' .
161 'DEMO: it\'s 1999 all over again!' .
164 // List of plugin's JS files.
165 // Note that you just need to specify CSS path.
166 $data['js_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
176 * Hook render_linklist.
178 * Template placeholders:
179 * - action_plugin: next to 'private only' button.
180 * - plugin_start_zone: page start
181 * - plugin_end_zone: page end
182 * - link_plugin: icons below each links.
185 * - _LOGGEDIN_: true/false
187 * @param array $data data passed to plugin
189 * @return array altered $data.
191 function hook_demo_plugin_render_linklist($data)
194 * Action links (action_plugin):
195 * A link is an array of its attributes (key="value"),
196 * and a mandatory `html` key, which contains its value.
197 * It's also recommended to add key 'on' or 'off' for theme rendering.
201 'title' => 'Uppercase!',
205 if (isset($_GET['up'])) {
206 // Manipulate link data
207 foreach ($data['links'] as &$value) {
208 $value['description'] = strtoupper($value['description']);
209 $value['title'] = strtoupper($value['title']);
211 $action['on'] = true;
213 $action['off'] = true;
215 $data['action_plugin'][] = $action;
217 // link_plugin (for each link)
218 foreach ($data['links'] as &$value) {
219 $value['link_plugin'][] = ' DEMO \o/';
223 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
225 $data['plugin_end_zone'][] = '<center>AFTER</center>';
231 * Hook render_editlink.
233 * Template placeholders:
234 * - field_plugin: add link fields after tags.
236 * @param array $data data passed to plugin
238 * @return array altered $data.
240 function hook_demo_plugin_render_editlink($data)
242 // Load HTML into a string
243 $html = file_get_contents(PluginManager
::$PLUGINS_PATH .'/demo_plugin/field.html');
245 // replace value in HTML if it exists in $data
246 if (!empty($data['link']['stuff'])) {
247 $html = sprintf($html, $data['link']['stuff']);
249 $html = sprintf($html, '');
253 $data['edit_link_plugin'][] = $html;
261 * Template placeholders:
262 * - tools_plugin: after other tools.
264 * @param array $data data passed to plugin
266 * @return array altered $data.
268 function hook_demo_plugin_render_tools($data)
271 $data['tools_plugin'][] = 'tools_plugin';
277 * Hook render_picwall.
279 * Template placeholders:
280 * - plugin_start_zone: page start.
281 * - plugin_end_zone: page end.
284 * - _LOGGEDIN_: true/false
286 * @param array $data data passed to plugin
288 * @return array altered $data.
290 function hook_demo_plugin_render_picwall($data)
293 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
295 $data['plugin_end_zone'][] = '<center>AFTER</center>';
301 * Hook render_tagcloud.
303 * Template placeholders:
304 * - plugin_start_zone: page start.
305 * - plugin_end_zone: page end.
308 * - _LOGGEDIN_: true/false
310 * @param array $data data passed to plugin
312 * @return array altered $data.
314 function hook_demo_plugin_render_tagcloud($data)
317 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
319 $data['plugin_end_zone'][] = '<center>AFTER</center>';
327 * Template placeholders:
328 * - plugin_start_zone: page start.
329 * - plugin_end_zone: page end.
332 * - _LOGGEDIN_: true/false
334 * @param array $data data passed to plugin
336 * @return array altered $data.
338 function hook_demo_plugin_render_daily($data)
341 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
343 $data['plugin_end_zone'][] = '<center>AFTER</center>';
346 // Manipulate columns data
347 foreach ($data['cols'] as &$value) {
348 foreach ($value as &$value2) {
349 $value2['formatedDescription'] .= ' ಠ_ಠ';
353 // Add plugin content at the end of each link
354 foreach ($data['cols'] as &$value) {
355 foreach ($value as &$value2) {
356 $value2['link_plugin'][] = 'DEMO';
370 * Triggered when a link is save (new or edit).
371 * All new links now contain a 'stuff' value.
373 * @param array $data contains the new link data.
375 * @return array altered $data.
377 function hook_demo_plugin_save_link($data)
380 // Save stuff added in editlink field
381 if (!empty($_POST['lf_stuff'])) {
382 $data['stuff'] = escape($_POST['lf_stuff']);
391 * Triggered when a link is deleted.
393 * @param array $data contains the link to be deleted.
395 * @return array altered data.
397 function hook_demo_plugin_delete_link($data)
399 if (strpos($data['url'], 'youtube.com') !== false) {
400 exit('You can not delete a YouTube link. Don\'t ask.');
405 * Execute render_feed hook.
406 * Called with ATOM and RSS feed.
409 * - _PAGE_: current page
410 * - _LOGGEDIN_: true/false
412 * @param array $data data passed to plugin
414 * @return array altered $data.
416 function hook_demo_plugin_render_feed($data)
418 foreach ($data['links'] as &$link) {
419 if ($data['_PAGE_'] == Router
::$PAGE_FEED_ATOM) {
420 $link['description'] .= ' - ATOM Feed' ;
422 elseif ($data['_PAGE_'] == Router
::$PAGE_FEED_RSS) {
423 $link['description'] .= ' - RSS Feed';