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