]>
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) {
54 $data['buttons_toolbar'][] = '<li><a href="#">DEMO_buttons_toolbar</a></li>';
58 $data['fields_toolbar'][] = 'DEMO_fields_toolbar';
60 // Another button always displayed
61 $data['buttons_toolbar'][] = '<li><a href="#">DEMO</a></li>';
67 * Hook render_includes.
68 * Executed on every page redering.
70 * Template placeholders:
74 * - _PAGE_: current page
75 * - _LOGGEDIN_: true/false
77 * @param array $data data passed to plugin
79 * @return array altered $data.
81 function hook_demo_plugin_render_includes($data)
83 // List of plugin's CSS files.
84 // Note that you just need to specify CSS path.
85 $data['css_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
92 * Executed on every page redering.
94 * Template placeholders:
100 * - _PAGE_: current page
101 * - _LOGGEDIN_: true/false
103 * @param array $data data passed to plugin
105 * @return array altered $data.
107 function hook_demo_plugin_render_footer($data)
110 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
112 // Free elements at the end of the page.
113 $data['endofpage'][] = '<marquee id="demo_marquee">' .
114 'DEMO: it\'s 1999 all over again!' .
117 // List of plugin's JS files.
118 // Note that you just need to specify CSS path.
119 $data['js_files'][] = PluginManager
::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
129 * Hook render_linklist.
131 * Template placeholders:
132 * - action_plugin: next to 'private only' button.
133 * - plugin_start_zone: page start
134 * - plugin_end_zone: page end
135 * - link_plugin: icons below each links.
138 * - _LOGGEDIN_: true/false
140 * @param array $data data passed to plugin
142 * @return array altered $data.
144 function hook_demo_plugin_render_linklist($data)
147 $data['action_plugin'][] = '<div class="upper_plugin_demo"><a href="?up" title="Uppercase!">←</a></div>';
149 if (isset($_GET['up'])) {
150 // Manipulate link data
151 foreach ($data['links'] as &$value) {
152 $value['description'] = strtoupper($value['description']);
153 $value['title'] = strtoupper($value['title']);
157 // link_plugin (for each link)
158 foreach ($data['links'] as &$value) {
159 $value['link_plugin'][] = ' DEMO \o/';
163 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
165 $data['plugin_end_zone'][] = '<center>AFTER</center>';
171 * Hook render_editlink.
173 * Template placeholders:
174 * - field_plugin: add link fields after tags.
176 * @param array $data data passed to plugin
178 * @return array altered $data.
180 function hook_demo_plugin_render_editlink($data)
182 // Load HTML into a string
183 $html = file_get_contents(PluginManager
::$PLUGINS_PATH .'/demo_plugin/field.html');
185 // replace value in HTML if it exists in $data
186 if (!empty($data['link']['stuff'])) {
187 $html = sprintf($html, $data['link']['stuff']);
189 $html = sprintf($html, '');
193 $data['edit_link_plugin'][] = $html;
201 * Template placeholders:
202 * - tools_plugin: after other tools.
204 * @param array $data data passed to plugin
206 * @return array altered $data.
208 function hook_demo_plugin_render_tools($data)
211 $data['tools_plugin'][] = 'tools_plugin';
217 * Hook render_picwall.
219 * Template placeholders:
220 * - plugin_start_zone: page start.
221 * - plugin_end_zone: page end.
224 * - _LOGGEDIN_: true/false
226 * @param array $data data passed to plugin
228 * @return array altered $data.
230 function hook_demo_plugin_render_picwall($data)
233 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
235 $data['plugin_end_zone'][] = '<center>AFTER</center>';
241 * Hook render_tagcloud.
243 * Template placeholders:
244 * - plugin_start_zone: page start.
245 * - plugin_end_zone: page end.
248 * - _LOGGEDIN_: true/false
250 * @param array $data data passed to plugin
252 * @return array altered $data.
254 function hook_demo_plugin_render_tagcloud($data)
257 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
259 $data['plugin_end_zone'][] = '<center>AFTER</center>';
267 * Template placeholders:
268 * - plugin_start_zone: page start.
269 * - plugin_end_zone: page end.
272 * - _LOGGEDIN_: true/false
274 * @param array $data data passed to plugin
276 * @return array altered $data.
278 function hook_demo_plugin_render_daily($data)
281 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
283 $data['plugin_end_zone'][] = '<center>AFTER</center>';
286 // Manipulate columns data
287 foreach ($data['cols'] as &$value) {
288 foreach ($value as &$value2) {
289 $value2['formatedDescription'] .= ' ಠ_ಠ';
293 // Add plugin content at the end of each link
294 foreach ($data['cols'] as &$value) {
295 foreach ($value as &$value2) {
296 $value2['link_plugin'][] = 'DEMO';
310 * Triggered when a link is save (new or edit).
311 * All new links now contain a 'stuff' value.
313 * @param array $data contains the new link data.
315 * @return array altered $data.
317 function hook_demo_plugin_save_link($data)
320 // Save stuff added in editlink field
321 if (!empty($_POST['lf_stuff'])) {
322 $data['stuff'] = escape($_POST['lf_stuff']);
331 * Triggered when a link is deleted.
333 * @param array $data contains the link to be deleted.
335 * @return array altered data.
337 function hook_demo_plugin_delete_link($data)
339 if (strpos($data['url'], 'youtube.com') !== false) {
340 exit('You can not delete a YouTube link. Don\'t ask.');
345 * Execute render_feed hook.
346 * Called with ATOM and RSS feed.
349 * - _PAGE_: current page
350 * - _LOGGEDIN_: true/false
352 * @param array $data data passed to plugin
354 * @return array altered $data.
356 function hook_demo_plugin_render_feed($data)
358 foreach ($data['links'] as &$link) {
359 if ($data['_PAGE_'] == Router
::$PAGE_FEED_ATOM) {
360 $link['description'] .= ' - ATOM Feed' ;
362 elseif ($data['_PAGE_'] == Router
::$PAGE_FEED_RSS) {
363 $link['description'] .= ' - RSS Feed';