]>
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) {
37 $data['buttons_toolbar'][] = '<li><a href="#">DEMO_buttons_toolbar</a></li>';
41 $data['fields_toolbar'][] = 'DEMO_fields_toolbar';
43 // Another button always displayed
44 $data['buttons_toolbar'][] = '<li><a href="#">DEMO</a></li>';
50 * Hook render_includes.
51 * Executed on every page redering.
53 * Template placeholders:
57 * - _PAGE_: current page
58 * - _LOGGEDIN_: true/false
60 * @param array $data data passed to plugin
62 * @return array altered $data.
64 function hook_demo_plugin_render_includes($data)
66 // List of plugin's CSS files.
67 // Note that you just need to specify CSS path.
68 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
75 * Executed on every page redering.
77 * Template placeholders:
83 * - _PAGE_: current page
84 * - _LOGGEDIN_: true/false
86 * @param array $data data passed to plugin
88 * @return array altered $data.
90 function hook_demo_plugin_render_footer($data)
93 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
95 // Free elements at the end of the page.
96 $data['endofpage'][] = '<marquee id="demo_marquee">' .
97 'DEMO: it\'s 1999 all over again!' .
100 // List of plugin's JS files.
101 // Note that you just need to specify CSS path.
102 $data['js_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
112 * Hook render_linklist.
114 * Template placeholders:
115 * - action_plugin: next to 'private only' button.
116 * - plugin_start_zone: page start
117 * - plugin_end_zone: page end
118 * - link_plugin: icons below each links.
121 * - _LOGGEDIN_: true/false
123 * @param array $data data passed to plugin
125 * @return array altered $data.
127 function hook_demo_plugin_render_linklist($data)
130 $data['action_plugin'][] = '<div class="upper_plugin_demo"><a href="?up" title="Uppercase!">←</a></div>';
132 if (isset($_GET['up'])) {
133 // Manipulate link data
134 foreach ($data['links'] as &$value) {
135 $value['description'] = strtoupper($value['description']);
136 $value['title'] = strtoupper($value['title']);
140 // link_plugin (for each link)
141 foreach ($data['links'] as &$value) {
142 $value['link_plugin'][] = ' DEMO \o/';
146 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
148 $data['plugin_end_zone'][] = '<center>AFTER</center>';
154 * Hook render_editlink.
156 * Template placeholders:
157 * - field_plugin: add link fields after tags.
159 * @param array $data data passed to plugin
161 * @return array altered $data.
163 function hook_demo_plugin_render_editlink($data)
165 // Load HTML into a string
166 $html = file_get_contents(PluginManager
::$PLUGINS_PATH .'/demo_plugin/field.html');
168 // replace value in HTML if it exists in $data
169 if (!empty($data['link']['stuff'])) {
170 $html = sprintf($html, $data['link']['stuff']);
172 $html = sprintf($html, '');
176 $data['edit_link_plugin'][] = $html;
184 * Template placeholders:
185 * - tools_plugin: after other tools.
187 * @param array $data data passed to plugin
189 * @return array altered $data.
191 function hook_demo_plugin_render_tools($data)
194 $data['tools_plugin'][] = 'tools_plugin';
200 * Hook render_picwall.
202 * Template placeholders:
203 * - plugin_start_zone: page start.
204 * - plugin_end_zone: page end.
207 * - _LOGGEDIN_: true/false
209 * @param array $data data passed to plugin
211 * @return array altered $data.
213 function hook_demo_plugin_render_picwall($data)
216 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
218 $data['plugin_end_zone'][] = '<center>AFTER</center>';
224 * Hook render_tagcloud.
226 * Template placeholders:
227 * - plugin_start_zone: page start.
228 * - plugin_end_zone: page end.
231 * - _LOGGEDIN_: true/false
233 * @param array $data data passed to plugin
235 * @return array altered $data.
237 function hook_demo_plugin_render_tagcloud($data)
240 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
242 $data['plugin_end_zone'][] = '<center>AFTER</center>';
250 * Template placeholders:
251 * - plugin_start_zone: page start.
252 * - plugin_end_zone: page end.
255 * - _LOGGEDIN_: true/false
257 * @param array $data data passed to plugin
259 * @return array altered $data.
261 function hook_demo_plugin_render_daily($data)
264 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
266 $data['plugin_end_zone'][] = '<center>AFTER</center>';
269 // Manipulate columns data
270 foreach ($data['cols'] as &$value) {
271 foreach ($value as &$value2) {
272 $value2['formatedDescription'] .= ' ಠ_ಠ';
276 // Add plugin content at the end of each link
277 foreach ($data['cols'] as &$value) {
278 foreach ($value as &$value2) {
279 $value2['link_plugin'][] = 'DEMO';
293 * Triggered when a link is save (new or edit).
294 * All new links now contain a 'stuff' value.
296 * @param array $data contains the new link data.
298 * @return array altered $data.
300 function hook_demo_plugin_save_link($data)
303 // Save stuff added in editlink field
304 if (!empty($_POST['lf_stuff'])) {
305 $data['stuff'] = escape($_POST['lf_stuff']);
314 * Triggered when a link is deleted.
316 * @param array $data contains the link to be deleted.
318 * @return array altered data.
320 function hook_demo_plugin_delete_link($data)
322 if (strpos($data['url'], 'youtube.com') !== false) {
323 exit('You can not delete a YouTube link. Don\'t ask.');