]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - plugins/demo_plugin/demo_plugin.php
Adding a new placeholder in render_footer hook.
[github/shaarli/Shaarli.git] / plugins / demo_plugin / demo_plugin.php
CommitLineData
786ddad9
A
1<?php
2/**
3 * Demo Plugin.
4 *
5 * This plugin try to cover Shaarli's plugin API entirely.
6 * Can be used by plugin developper to make their own.
7 */
8
9/*
10 * RENDER HEADER, INCLUDES, FOOTER
11 *
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_.
15 */
16
17/**
18 * Hook render_header.
19 * Executed on every page redering.
20 *
21 * Template placeholders:
22 * - buttons_toolbar
23 * - fields_toolbar
24 *
25 * @param array $data data passed to plugin
26 *
27 * @return array altered $data.
28 */
29function hook_demo_plugin_render_header($data)
30{
31 // Only execute when linklist is rendered.
32 if ($data['_PAGE_'] == Router::$PAGE_LINKLIST) {
33
34 // If loggedin
35 if ($data['_LOGGEDIN_'] === true) {
36 // Buttons in toolbar
37 $data['buttons_toolbar'][] = '<li><a href="#">DEMO_buttons_toolbar</a></li>';
38 }
39
40 // Fields in toolbar
41 $data['fields_toolbar'][] = 'DEMO_fields_toolbar';
42 }
43
44 return $data;
45}
46
47/**
48 * Hook render_includes.
49 * Executed on every page redering.
50 *
51 * Template placeholders:
52 * - css_files
53 *
54 * Data:
55 * - _PAGE_: current page
56 * - _LOGGEDIN_: true/false
57 *
58 * @param array $data data passed to plugin
59 *
60 * @return array altered $data.
61 */
62function hook_demo_plugin_render_includes($data)
63{
64 // List of plugin's CSS files.
65 // Note that you just need to specify CSS path.
66 $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/demo_plugin/custom_demo.css';
67
68 return $data;
69}
70
71/**
72 * Hook render_footer.
73 * Executed on every page redering.
74 *
75 * Template placeholders:
76 * - text
40a5f296 77 * - endofpage
786ddad9
A
78 * - js_files
79 *
80 * Data:
81 * - _PAGE_: current page
82 * - _LOGGEDIN_: true/false
83 *
84 * @param array $data data passed to plugin
85 *
86 * @return array altered $data.
87 */
88function hook_demo_plugin_render_footer($data)
89{
90 // footer text
91 $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.';
92
40a5f296
A
93 // Free elements at the end of the page.
94 $data['endofpage'][] = '<marquee id="demo_marquee">' .
95 'DEMO: it\'s 1999 all over again!' .
96 '</marquee>';
97
786ddad9
A
98 // List of plugin's JS files.
99 // Note that you just need to specify CSS path.
100 $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js';
101
102 return $data;
103}
104
105/*
106 * SPECIFIC PAGES
107 */
108
109/**
110 * Hook render_linklist.
111 *
112 * Template placeholders:
113 * - action_plugin: next to 'private only' button.
114 * - plugin_start_zone: page start
115 * - plugin_end_zone: page end
116 * - link_plugin: icons below each links.
117 *
118 * Data:
119 * - _LOGGEDIN_: true/false
120 *
121 * @param array $data data passed to plugin
122 *
123 * @return array altered $data.
124 */
125function hook_demo_plugin_render_linklist($data)
126{
127 // action_plugin
128 $data['action_plugin'][] = '<div class="upper_plugin_demo"><a href="?up" title="Uppercase!">←</a></div>';
129
130 if (isset($_GET['up'])) {
131 // Manipulate link data
132 foreach ($data['links'] as &$value) {
133 $value['description'] = strtoupper($value['description']);
134 $value['title'] = strtoupper($value['title']);
135 }
136 }
137
138 // link_plugin (for each link)
139 foreach ($data['links'] as &$value) {
140 $value['link_plugin'][] = ' DEMO \o/';
141 }
142
143 // plugin_start_zone
144 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
145 // plugin_start_zone
146 $data['plugin_end_zone'][] = '<center>AFTER</center>';
147
148 return $data;
149}
150
151/**
152 * Hook render_editlink.
153 *
154 * Template placeholders:
155 * - field_plugin: add link fields after tags.
156 *
157 * @param array $data data passed to plugin
158 *
159 * @return array altered $data.
160 */
161function hook_demo_plugin_render_editlink($data)
162{
163 // Load HTML into a string
164 $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html');
165
166 // replace value in HTML if it exists in $data
167 if (!empty($data['link']['stuff'])) {
168 $html = sprintf($html, $data['link']['stuff']);
169 } else {
170 $html = sprintf($html, '');
171 }
172
173 // field_plugin
174 $data['edit_link_plugin'][] = $html;
175
176 return $data;
177}
178
179/**
180 * Hook render_tools.
181 *
182 * Template placeholders:
183 * - tools_plugin: after other tools.
184 *
185 * @param array $data data passed to plugin
186 *
187 * @return array altered $data.
188 */
189function hook_demo_plugin_render_tools($data)
190{
191 // field_plugin
192 $data['tools_plugin'][] = 'tools_plugin';
193
194 return $data;
195}
196
197/**
198 * Hook render_picwall.
199 *
200 * Template placeholders:
201 * - plugin_start_zone: page start.
202 * - plugin_end_zone: page end.
203 *
204 * Data:
205 * - _LOGGEDIN_: true/false
206 *
207 * @param array $data data passed to plugin
208 *
209 * @return array altered $data.
210 */
211function hook_demo_plugin_render_picwall($data)
212{
213 // plugin_start_zone
214 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
215 // plugin_end_zone
216 $data['plugin_end_zone'][] = '<center>AFTER</center>';
217
218 return $data;
219}
220
221/**
222 * Hook render_tagcloud.
223 *
224 * Template placeholders:
225 * - plugin_start_zone: page start.
226 * - plugin_end_zone: page end.
227 *
228 * Data:
229 * - _LOGGEDIN_: true/false
230 *
231 * @param array $data data passed to plugin
232 *
233 * @return array altered $data.
234 */
235function hook_demo_plugin_render_tagcloud($data)
236{
237 // plugin_start_zone
238 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
239 // plugin_end_zone
240 $data['plugin_end_zone'][] = '<center>AFTER</center>';
241
242 return $data;
243}
244
245/**
246 * Hook render_daily.
247 *
248 * Template placeholders:
249 * - plugin_start_zone: page start.
250 * - plugin_end_zone: page end.
251 *
252 * Data:
253 * - _LOGGEDIN_: true/false
254 *
255 * @param array $data data passed to plugin
256 *
257 * @return array altered $data.
258 */
259function hook_demo_plugin_render_daily($data)
260{
261 // plugin_start_zone
262 $data['plugin_start_zone'][] = '<center>BEFORE</center>';
263 // plugin_end_zone
264 $data['plugin_end_zone'][] = '<center>AFTER</center>';
265
266
267 // Manipulate columns data
268 foreach ($data['cols'] as &$value) {
269 foreach ($value as &$value2) {
270 $value2['formatedDescription'] .= ' ಠ_ಠ';
271 }
272 }
273
274 // Add plugin content at the end of each link
275 foreach ($data['cols'] as &$value) {
276 foreach ($value as &$value2) {
277 $value2['link_plugin'][] = 'DEMO';
278 }
279 }
280
281 return $data;
282}
283
284/*
285 * DATA SAVING HOOK.
286 */
287
288/**
289 * Hook savelink.
290 *
291 * Triggered when a link is save (new or edit).
292 * All new links now contain a 'stuff' value.
293 *
294 * @param array $data contains the new link data.
295 *
296 * @return array altered $data.
297 */
298function hook_demo_plugin_save_link($data)
299{
300
301 // Save stuff added in editlink field
302 if (!empty($_POST['lf_stuff'])) {
303 $data['stuff'] = escape($_POST['lf_stuff']);
304 }
305
306 return $data;
307}
308
309/**
310 * Hook delete_link.
311 *
312 * Triggered when a link is deleted.
313 *
314 * @param array $data contains the link to be deleted.
315 *
316 * @return array altered data.
317 */
318function hook_demo_plugin_delete_link($data)
319{
320 if (strpos($data['url'], 'youtube.com') !== false) {
321 exit('You can not delete a YouTube link. Don\'t ask.');
322 }
323}