diff options
-rwxr-xr-x | plugins/demo_plugin/custom_demo.css | 7 | ||||
-rwxr-xr-x | plugins/demo_plugin/demo_plugin.js | 1 | ||||
-rwxr-xr-x | plugins/demo_plugin/demo_plugin.php | 317 | ||||
-rwxr-xr-x | plugins/demo_plugin/field.html | 2 |
4 files changed, 327 insertions, 0 deletions
diff --git a/plugins/demo_plugin/custom_demo.css b/plugins/demo_plugin/custom_demo.css new file mode 100755 index 00000000..ab1720b5 --- /dev/null +++ b/plugins/demo_plugin/custom_demo.css | |||
@@ -0,0 +1,7 @@ | |||
1 | .linktitle a { | ||
2 | color: red; | ||
3 | } | ||
4 | |||
5 | .upper_plugin_demo { | ||
6 | float: left; | ||
7 | } \ No newline at end of file | ||
diff --git a/plugins/demo_plugin/demo_plugin.js b/plugins/demo_plugin/demo_plugin.js new file mode 100755 index 00000000..1fc327e6 --- /dev/null +++ b/plugins/demo_plugin/demo_plugin.js | |||
@@ -0,0 +1 @@ | |||
console.log("I love the smell of napalm in the morning."); \ No newline at end of file | |||
diff --git a/plugins/demo_plugin/demo_plugin.php b/plugins/demo_plugin/demo_plugin.php new file mode 100755 index 00000000..84763c2b --- /dev/null +++ b/plugins/demo_plugin/demo_plugin.php | |||
@@ -0,0 +1,317 @@ | |||
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 | } | ||
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 | */ | ||
62 | function 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 | ||
77 | * - js_files | ||
78 | * | ||
79 | * Data: | ||
80 | * - _PAGE_: current page | ||
81 | * - _LOGGEDIN_: true/false | ||
82 | * | ||
83 | * @param array $data data passed to plugin | ||
84 | * | ||
85 | * @return array altered $data. | ||
86 | */ | ||
87 | function hook_demo_plugin_render_footer($data) | ||
88 | { | ||
89 | // footer text | ||
90 | $data['text'][] = 'Shaarli is now enhanced by the awesome demo_plugin.'; | ||
91 | |||
92 | // List of plugin's JS files. | ||
93 | // Note that you just need to specify CSS path. | ||
94 | $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/demo_plugin/demo_plugin.js'; | ||
95 | |||
96 | return $data; | ||
97 | } | ||
98 | |||
99 | /* | ||
100 | * SPECIFIC PAGES | ||
101 | */ | ||
102 | |||
103 | /** | ||
104 | * Hook render_linklist. | ||
105 | * | ||
106 | * Template placeholders: | ||
107 | * - action_plugin: next to 'private only' button. | ||
108 | * - plugin_start_zone: page start | ||
109 | * - plugin_end_zone: page end | ||
110 | * - link_plugin: icons below each links. | ||
111 | * | ||
112 | * Data: | ||
113 | * - _LOGGEDIN_: true/false | ||
114 | * | ||
115 | * @param array $data data passed to plugin | ||
116 | * | ||
117 | * @return array altered $data. | ||
118 | */ | ||
119 | function hook_demo_plugin_render_linklist($data) | ||
120 | { | ||
121 | // action_plugin | ||
122 | $data['action_plugin'][] = '<div class="upper_plugin_demo"><a href="?up" title="Uppercase!">←</a></div>'; | ||
123 | |||
124 | if (isset($_GET['up'])) { | ||
125 | // Manipulate link data | ||
126 | foreach ($data['links'] as &$value) { | ||
127 | $value['description'] = strtoupper($value['description']); | ||
128 | $value['title'] = strtoupper($value['title']); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | // link_plugin (for each link) | ||
133 | foreach ($data['links'] as &$value) { | ||
134 | $value['link_plugin'][] = ' DEMO \o/'; | ||
135 | } | ||
136 | |||
137 | // plugin_start_zone | ||
138 | $data['plugin_start_zone'][] = '<center>BEFORE</center>'; | ||
139 | // plugin_start_zone | ||
140 | $data['plugin_end_zone'][] = '<center>AFTER</center>'; | ||
141 | |||
142 | return $data; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * Hook render_editlink. | ||
147 | * | ||
148 | * Template placeholders: | ||
149 | * - field_plugin: add link fields after tags. | ||
150 | * | ||
151 | * @param array $data data passed to plugin | ||
152 | * | ||
153 | * @return array altered $data. | ||
154 | */ | ||
155 | function hook_demo_plugin_render_editlink($data) | ||
156 | { | ||
157 | // Load HTML into a string | ||
158 | $html = file_get_contents(PluginManager::$PLUGINS_PATH .'/demo_plugin/field.html'); | ||
159 | |||
160 | // replace value in HTML if it exists in $data | ||
161 | if (!empty($data['link']['stuff'])) { | ||
162 | $html = sprintf($html, $data['link']['stuff']); | ||
163 | } else { | ||
164 | $html = sprintf($html, ''); | ||
165 | } | ||
166 | |||
167 | // field_plugin | ||
168 | $data['edit_link_plugin'][] = $html; | ||
169 | |||
170 | return $data; | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Hook render_tools. | ||
175 | * | ||
176 | * Template placeholders: | ||
177 | * - tools_plugin: after other tools. | ||
178 | * | ||
179 | * @param array $data data passed to plugin | ||
180 | * | ||
181 | * @return array altered $data. | ||
182 | */ | ||
183 | function hook_demo_plugin_render_tools($data) | ||
184 | { | ||
185 | // field_plugin | ||
186 | $data['tools_plugin'][] = 'tools_plugin'; | ||
187 | |||
188 | return $data; | ||
189 | } | ||
190 | |||
191 | /** | ||
192 | * Hook render_picwall. | ||
193 | * | ||
194 | * Template placeholders: | ||
195 | * - plugin_start_zone: page start. | ||
196 | * - plugin_end_zone: page end. | ||
197 | * | ||
198 | * Data: | ||
199 | * - _LOGGEDIN_: true/false | ||
200 | * | ||
201 | * @param array $data data passed to plugin | ||
202 | * | ||
203 | * @return array altered $data. | ||
204 | */ | ||
205 | function hook_demo_plugin_render_picwall($data) | ||
206 | { | ||
207 | // plugin_start_zone | ||
208 | $data['plugin_start_zone'][] = '<center>BEFORE</center>'; | ||
209 | // plugin_end_zone | ||
210 | $data['plugin_end_zone'][] = '<center>AFTER</center>'; | ||
211 | |||
212 | return $data; | ||
213 | } | ||
214 | |||
215 | /** | ||
216 | * Hook render_tagcloud. | ||
217 | * | ||
218 | * Template placeholders: | ||
219 | * - plugin_start_zone: page start. | ||
220 | * - plugin_end_zone: page end. | ||
221 | * | ||
222 | * Data: | ||
223 | * - _LOGGEDIN_: true/false | ||
224 | * | ||
225 | * @param array $data data passed to plugin | ||
226 | * | ||
227 | * @return array altered $data. | ||
228 | */ | ||
229 | function hook_demo_plugin_render_tagcloud($data) | ||
230 | { | ||
231 | // plugin_start_zone | ||
232 | $data['plugin_start_zone'][] = '<center>BEFORE</center>'; | ||
233 | // plugin_end_zone | ||
234 | $data['plugin_end_zone'][] = '<center>AFTER</center>'; | ||
235 | |||
236 | return $data; | ||
237 | } | ||
238 | |||
239 | /** | ||
240 | * Hook render_daily. | ||
241 | * | ||
242 | * Template placeholders: | ||
243 | * - plugin_start_zone: page start. | ||
244 | * - plugin_end_zone: page end. | ||
245 | * | ||
246 | * Data: | ||
247 | * - _LOGGEDIN_: true/false | ||
248 | * | ||
249 | * @param array $data data passed to plugin | ||
250 | * | ||
251 | * @return array altered $data. | ||
252 | */ | ||
253 | function hook_demo_plugin_render_daily($data) | ||
254 | { | ||
255 | // plugin_start_zone | ||
256 | $data['plugin_start_zone'][] = '<center>BEFORE</center>'; | ||
257 | // plugin_end_zone | ||
258 | $data['plugin_end_zone'][] = '<center>AFTER</center>'; | ||
259 | |||
260 | |||
261 | // Manipulate columns data | ||
262 | foreach ($data['cols'] as &$value) { | ||
263 | foreach ($value as &$value2) { | ||
264 | $value2['formatedDescription'] .= ' ಠ_ಠ'; | ||
265 | } | ||
266 | } | ||
267 | |||
268 | // Add plugin content at the end of each link | ||
269 | foreach ($data['cols'] as &$value) { | ||
270 | foreach ($value as &$value2) { | ||
271 | $value2['link_plugin'][] = 'DEMO'; | ||
272 | } | ||
273 | } | ||
274 | |||
275 | return $data; | ||
276 | } | ||
277 | |||
278 | /* | ||
279 | * DATA SAVING HOOK. | ||
280 | */ | ||
281 | |||
282 | /** | ||
283 | * Hook savelink. | ||
284 | * | ||
285 | * Triggered when a link is save (new or edit). | ||
286 | * All new links now contain a 'stuff' value. | ||
287 | * | ||
288 | * @param array $data contains the new link data. | ||
289 | * | ||
290 | * @return array altered $data. | ||
291 | */ | ||
292 | function hook_demo_plugin_save_link($data) | ||
293 | { | ||
294 | |||
295 | // Save stuff added in editlink field | ||
296 | if (!empty($_POST['lf_stuff'])) { | ||
297 | $data['stuff'] = escape($_POST['lf_stuff']); | ||
298 | } | ||
299 | |||
300 | return $data; | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * Hook delete_link. | ||
305 | * | ||
306 | * Triggered when a link is deleted. | ||
307 | * | ||
308 | * @param array $data contains the link to be deleted. | ||
309 | * | ||
310 | * @return array altered data. | ||
311 | */ | ||
312 | function hook_demo_plugin_delete_link($data) | ||
313 | { | ||
314 | if (strpos($data['url'], 'youtube.com') !== false) { | ||
315 | exit('You can not delete a YouTube link. Don\'t ask.'); | ||
316 | } | ||
317 | } \ No newline at end of file | ||
diff --git a/plugins/demo_plugin/field.html b/plugins/demo_plugin/field.html new file mode 100755 index 00000000..00281c4e --- /dev/null +++ b/plugins/demo_plugin/field.html | |||
@@ -0,0 +1,2 @@ | |||
1 | <label for="lf_stuff"><i>Demo Stuff</i></label><br> | ||
2 | <input type="text" name="lf_stuff" id="lf_stuff" value="%s" class="lf_input"><br> \ No newline at end of file | ||