]>
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_.
19 * Executed on every page redering.
21 * Template placeholders:
25 * @param array $data data passed to plugin
27 * @return array altered $data.
29 function hook_demo_plugin_render_header($data)
31 // Only execute when linklist is rendered.
32 if ($data['_PAGE_'] == Router
::$PAGE_LINKLIST) {
35 if ($data['_LOGGEDIN_'] === true) {
38 * A link is an array of its attributes (key="value"),
39 * and a mandatory `html` key, which contains its value.
43 'class' => 'mybutton',
44 'title' => 'hover me',
45 'html' => 'DEMO buttons toolbar',
47 $data['buttons_toolbar'][] = $button;
51 * Add additional input fields in the tools.
52 * A field is an array containing:
54 * 'form-attribute-1' => 'form attribute 1 value',
55 * 'form-attribute-2' => 'form attribute 2 value',
58 * 'input-1-attribute-1 => 'input 1 attribute 1 value',
59 * 'input-1-attribute-2 => 'input 1 attribute 2 value',
62 * 'input-2-attribute-1 => 'input 2 attribute 1 value',
66 * This example renders as:
67 * <form form-attribute-1="form attribute 1 value" form-attribute-2="form attribute 2 value">
68 * <input input-1-attribute-1="input 1 attribute 1 value" input-1-attribute-2="input 1 attribute 2 value">
69 * <input input-2-attribute-1="input 2 attribute 1 value">
80 'placeholder' => 'demo',
84 $data['fields_toolbar'][] = $form;
86 // Another button always displayed
91 $data['buttons_toolbar'][] = $button;
97 * Hook render_includes.
98 * Executed on every page redering.
100 * Template placeholders:
104 * - _PAGE_: current page
105 * - _LOGGEDIN_: true/false
107 * @param array $data data passed to plugin
109 * @return array altered $data.
111 function hook_demo_plugin_render_includes($data)
113 // List of plugin's CSS files.
114 // Note that you just need to specify CSS path.
115 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
121 * Hook render_footer.
122 * Executed on every page redering.
124 * Template placeholders:
130 * - _PAGE_: current page
131 * - _LOGGEDIN_: true/false
133 * @param array $data data passed to plugin
135 * @return array altered $data.
137 function hook_demo_plugin_render_footer($data)
140 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
142 // Free elements at the end of the page.
143 $data['endofpage'][] = '<marquee id="demo_marquee">' .
144 'DEMO: it\'s 1999 all over again!' .
147 // List of plugin's JS files.
148 // Note that you just need to specify CSS path.
149 $data['js_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
159 * Hook render_linklist.
161 * Template placeholders:
162 * - action_plugin: next to 'private only' button.
163 * - plugin_start_zone: page start
164 * - plugin_end_zone: page end
165 * - link_plugin: icons below each links.
168 * - _LOGGEDIN_: true/false
170 * @param array $data data passed to plugin
172 * @return array altered $data.
174 function hook_demo_plugin_render_linklist($data)
177 * Action links (action_plugin):
178 * A link is an array of its attributes (key="value"),
179 * and a mandatory `html` key, which contains its value.
180 * It's also recommended to add key 'on' or 'off' for theme rendering.
184 'title' => 'Uppercase!',
188 if (isset($_GET['up'])) {
189 // Manipulate link data
190 foreach ($data['links'] as &$value) {
191 $value['description'] = strtoupper($value['description']);
192 $value['title'] = strtoupper($value['title']);
194 $action['on'] = true;
196 $action['off'] = true;
198 $data['action_plugin'][] = $action;
200 // link_plugin (for each link)
201 foreach ($data['links'] as &$value) {
202 $value['link_plugin'][] = ' DEMO \o/';
206 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
208 $data['plugin_end_zone'][] = '<center>AFTER</center>';
214 * Hook render_editlink.
216 * Template placeholders:
217 * - field_plugin: add link fields after tags.
219 * @param array $data data passed to plugin
221 * @return array altered $data.
223 function hook_demo_plugin_render_editlink($data)
225 // Load HTML into a string
226 $html = file_get_contents(PluginManager
::$PLUGINS_PATH .'/demo_plugin/field.html');
228 // replace value in HTML if it exists in $data
229 if (!empty($data['link']['stuff'])) {
230 $html = sprintf($html, $data['link']['stuff']);
232 $html = sprintf($html, '');
236 $data['edit_link_plugin'][] = $html;
244 * Template placeholders:
245 * - tools_plugin: after other tools.
247 * @param array $data data passed to plugin
249 * @return array altered $data.
251 function hook_demo_plugin_render_tools($data)
254 $data['tools_plugin'][] = 'tools_plugin';
260 * Hook render_picwall.
262 * Template placeholders:
263 * - plugin_start_zone: page start.
264 * - plugin_end_zone: page end.
267 * - _LOGGEDIN_: true/false
269 * @param array $data data passed to plugin
271 * @return array altered $data.
273 function hook_demo_plugin_render_picwall($data)
276 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
278 $data['plugin_end_zone'][] = '<center>AFTER</center>';
284 * Hook render_tagcloud.
286 * Template placeholders:
287 * - plugin_start_zone: page start.
288 * - plugin_end_zone: page end.
291 * - _LOGGEDIN_: true/false
293 * @param array $data data passed to plugin
295 * @return array altered $data.
297 function hook_demo_plugin_render_tagcloud($data)
300 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
302 $data['plugin_end_zone'][] = '<center>AFTER</center>';
310 * Template placeholders:
311 * - plugin_start_zone: page start.
312 * - plugin_end_zone: page end.
315 * - _LOGGEDIN_: true/false
317 * @param array $data data passed to plugin
319 * @return array altered $data.
321 function hook_demo_plugin_render_daily($data)
324 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
326 $data['plugin_end_zone'][] = '<center>AFTER</center>';
329 // Manipulate columns data
330 foreach ($data['cols'] as &$value) {
331 foreach ($value as &$value2) {
332 $value2['formatedDescription'] .= ' ಠ_ಠ';
336 // Add plugin content at the end of each link
337 foreach ($data['cols'] as &$value) {
338 foreach ($value as &$value2) {
339 $value2['link_plugin'][] = 'DEMO';
353 * Triggered when a link is save (new or edit).
354 * All new links now contain a 'stuff' value.
356 * @param array $data contains the new link data.
358 * @return array altered $data.
360 function hook_demo_plugin_save_link($data)
363 // Save stuff added in editlink field
364 if (!empty($_POST['lf_stuff'])) {
365 $data['stuff'] = escape($_POST['lf_stuff']);
374 * Triggered when a link is deleted.
376 * @param array $data contains the link to be deleted.
378 * @return array altered data.
380 function hook_demo_plugin_delete_link($data)
382 if (strpos($data['url'], 'youtube.com') !== false) {
383 exit('You can not delete a YouTube link. Don\'t ask.');
388 * Execute render_feed hook.
389 * Called with ATOM and RSS feed.
392 * - _PAGE_: current page
393 * - _LOGGEDIN_: true/false
395 * @param array $data data passed to plugin
397 * @return array altered $data.
399 function hook_demo_plugin_render_feed($data)
401 foreach ($data['links'] as &$link) {
402 if ($data['_PAGE_'] == Router
::$PAGE_FEED_ATOM) {
403 $link['description'] .= ' - ATOM Feed' ;
405 elseif ($data['_PAGE_'] == Router
::$PAGE_FEED_RSS) {
406 $link['description'] .= ' - RSS Feed';