2 > Note: Plugin current status - in developpement (not merged into master).
4 [**I am a user.** Plugin User Guide.](#plugin-user-guide)[](.html)
6 [**I am a developper.** Developper API.](#developper-api)[](.html)
8 [**I am a template designer.** Guide for template designer.](#guide-for-template-designer)[](.html)
14 In `config.php`, change $GLOBALS['config'['ENABLED_PLUGINS'] array:]('ENABLED_PLUGINS']-array:.html)
17 $GLOBALS['config'['ENABLED_PLUGINS']]('ENABLED_PLUGINS'].html)
23 $GLOBALS['config'['ENABLED_PLUGINS'] = array(]('ENABLED_PLUGINS']-=-array(.html)
24 'qrcode', 'archiveorg', 'readityourself', 'playvideos',
25 'wallabag', 'markdown', 'addlink_toolbar',
31 Plugin maintained by the community:
33 * Archive.org - add a clickable icon to every link to archive.org.
34 * Addlink in toolbar - add a field to paste new links URL in toolbar.
35 * Markdown - write and display Shaare in Markdown.
36 * Play videos - popup to play all videos displayed in linklist.
37 * QRCode - add a clickable icon generating a QRCode for every link.
38 * ReadItYourself - add a clickable icon for ReadItYourself.
39 * Wallabag - add a clickable icon for Wallabag.
43 ### What can I do with plugins?
45 The plugin system let you:
47 * insert content into specific places across templates.
48 * alter data before templates rendering.
49 * alter data before saving new links.
51 ### How can I create a plugin for Shaarli?
53 First, chose a plugin name, such as `demo_plugin`.
55 Under `plugin` folder, create a folder named with your plugin name. Then create a <plugin_name>.php file in that folder.
57 You should have the following tree view:
63 | |---| demo_plugin.php
66 ### Understanding hooks
68 A plugin is a set of functions. Each function will be triggered by the plugin system at certain point in Shaarli execution.
70 These functions need to be named with this pattern:
73 hook_<plugin_name>_<hook_name>
76 For exemple, if my plugin want to add data to the header, this function is needed:
78 hook_demo_plugin_render_header()
80 If this function is declared, and the plugin enabled, it will be called every time Shaarli is rendering the header.
86 Every hook function has a `$data` parameter. Its content differs for each hooks.
88 **This parameter needs to be returned every time**, otherwise data is lost.
92 #### Filling templates placeholder
94 Template placeholders are displayed in template in specific places.
96 RainTPL displays every element contained in the placeholder's array. These element can be added by plugins.
98 For example, let's add a value in the placeholder `top_placeholder` which is displayed at the top of my page:
101 $data['top_placeholder'[] = 'My content';](]-=-'My-content';.html)
103 array_push($data['top_placeholder'], 'My', 'content');[](.html)
108 #### Data manipulation
110 When a page is displayed, every variable send to the template engine is passed to plugins before that in `$data`.
112 The data contained by this array can be altered before template rendering.
114 For exemple, in linklist, it is possible to alter every title:
117 // mind the reference if you want $data to be altered
118 foreach ($data['links'] as &$value) {[](.html)
119 // String reverse every title.
120 $value['title'] = strrev($value['title']);[](.html)
126 ### It's not working!
128 Use `demo_plugin` as a functional example. It covers most of the plugin system features.
130 If it's still not working, please [open an issue](https://github.com/shaarli/Shaarli/issues/new).[](.html)
134 | Hooks | Description |
135 | ------------- |:-------------:|
136 | [render_header](#render_header) | Allow plugin to add content in page headers. |[](.html)
137 | [render_includes](#render_includes) | Allow plugin to include their own CSS files. |[](.html)
138 | [render_footer](#render_footer) | Allow plugin to add content in page footer and include their own JS files. | [](.html)
139 | [render_linklist](#render_linklist) | It allows to add content at the begining and end of the page, after every link displayed and to alter link data. |[](.html)
140 | [render_editlink](#render_editlink) | Allow to add fields in the form, or display elements. |[](.html)
141 | [render_tools](#render_tools) | Allow to add content at the end of the page. |[](.html)
142 | [render_picwall](#render_picwall) | Allow to add content at the top and bottom of the page. |[](.html)
143 | [render_tagcloud](#render_tagcloud) | Allow to add content at the top and bottom of the page. |[](.html)
144 | [render_daily](#render_daily) | Allow to add content at the top and bottom of the page, the bottom of each link and to alter data. |[](.html)
145 | [savelink](#savelink) | Allow to alter the link being saved in the datastore. |[](.html)
150 Triggered on every page.
152 Allow plugin to add content in page headers.
156 `$data` is an array containing:
158 * `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
159 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
161 ##### Template placeholders
163 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
165 List of placeholders:
167 * `buttons_toolbar`: after the list of buttons in the header.
169 ![buttons_toolbar_example](http://i.imgur.com/ssJUOrt.png)[](.html)
171 * `fields_toolbar`: after search fields in the header.
173 > Note: This will only be called in linklist.
175 ![fields_toolbar_example](http://i.imgur.com/3GMifI2.png)[](.html)
179 Triggered on every page.
181 Allow plugin to include their own CSS files.
185 `$data` is an array containing:
187 * `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
188 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
190 ##### Template placeholders
192 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
194 List of placeholders:
196 * `css_files`: called after loading default CSS.
198 > Note: only add the path of the CSS file. E.g: `plugins/demo_plugin/custom_demo.css`.
202 Triggered on every page.
204 Allow plugin to add content in page footer and include their own JS files.
208 `$data` is an array containing:
210 * `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
211 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
213 ##### Template placeholders
215 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
217 List of placeholders:
219 * `text`: called after the end of the footer text.
221 ![text_example](http://i.imgur.com/L5S2YEH.png)[](.html)
223 * `js_files`: called at the end of the page, to include custom JS scripts.
225 > Note: only add the path of the JS file. E.g: `plugins/demo_plugin/custom_demo.js`.
229 Triggered when `linklist` is displayed (list of links, permalink, search, tag filtered, etc.).
231 It allows to add content at the begining and end of the page, after every link displayed and to alter link data.
235 `$data` is an array containing:
237 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
238 * All templates data, including links.
240 ##### Template placeholders
242 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
244 List of placeholders:
246 * `action_plugin`: next to the button "private only" at the top and bottom of the page.
248 ![action_plugin_example](http://i.imgur.com/Q12PWg0.png)[](.html)
250 * `link_plugin`: for every link, between permalink and link URL.
252 ![link_plugin_example](http://i.imgur.com/3oDPhWx.png)[](.html)
254 * `plugin_start_zone`: before displaying the template content.
256 ![plugin_start_zone_example](http://i.imgur.com/OVBkGy3.png)[](.html)
258 * `plugin_end_zone`: after displaying the template content.
260 ![plugin_end_zone_example](http://i.imgur.com/6IoRuop.png)[](.html)
264 Triggered when the link edition form is displayed.
266 Allow to add fields in the form, or display elements.
270 `$data` is an array containing:
272 * All templates data.
274 ##### Template placeholders
276 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
278 List of placeholders:
280 * `edit_link_plugin`: after tags field.
282 ![edit_link_plugin_example](http://i.imgur.com/5u17Ens.png)[](.html)
286 Triggered when the "tools" page is displayed.
288 Allow to add content at the end of the page.
292 `$data` is an array containing:
294 * All templates data.
296 ##### Template placeholders
298 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
300 List of placeholders:
302 * `tools_plugin`: at the end of the page.
304 ![tools_plugin_example](http://i.imgur.com/Bqhu9oQ.png)[](.html)
308 Triggered when picwall is displayed.
310 Allow to add content at the top and bottom of the page.
314 `$data` is an array containing:
316 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
317 * All templates data.
319 ##### Template placeholders
321 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
323 List of placeholders:
325 * `plugin_start_zone`: before displaying the template content.
327 * `plugin_end_zone`: after displaying the template content.
329 ![plugin_start_end_zone_example](http://i.imgur.com/tVTQFER.png)[](.html)
333 Triggered when tagcloud is displayed.
335 Allow to add content at the top and bottom of the page.
339 `$data` is an array containing:
341 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
342 * All templates data.
344 ##### Template placeholders
346 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
348 List of placeholders:
350 * `plugin_start_zone`: before displaying the template content.
352 * `plugin_end_zone`: after displaying the template content.
354 ![plugin_start_end_zone_example](http://i.imgur.com/vHmyT3a.png)[](.html)
358 Triggered when tagcloud is displayed.
360 Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.
364 `$data` is an array containing:
366 * `_LOGGEDIN_`: true if user is logged in, false otherwise.
367 * All templates data, including links.
369 ##### Template placeholders
371 Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.[](.html)
373 List of placeholders:
375 * `link_plugin`: used at bottom of each link.
377 ![link_plugin_example](http://i.imgur.com/hzhMfSZ.png)[](.html)
379 * `plugin_start_zone`: before displaying the template content.
381 * `plugin_end_zone`: after displaying the template content.
385 Triggered when a link is save (new link or edit).
387 Allow to alter the link being saved in the datastore.
391 `$data` is an array containing the link being saved:
400 ## Guide for template designer
402 ### Placeholder system
404 In order to make plugins work with every custom themes, you need to add variable placeholder in your templates.
406 It's a RainTPL loop like this:
408 {loop="$plugin_variable"}
412 You should enable `demo_plugin` for testing purpose, since it uses every placeholder available.
414 ### List of placeholders
418 At the end of the menu:
420 {loop="$plugins_header.buttons_toolbar"}
426 At the end of the file:
429 {loop="$plugins_includes.css_files"}
430 <link type="text/css" rel="stylesheet" href="{$value}#"/>
436 At the end of your footer notes:
439 {loop="$plugins_footer.text"}
447 {loop="$plugins_footer.js_files"}
448 <script src="{$value}#"></script>
457 {loop="$plugins_header.fields_toolbar"}
462 Before displaying the link list (after paging):
465 {loop="$plugin_start_zone"}
470 For every links (icons):
473 {loop="$value.link_plugin"}
474 <span>{$value}</span>
481 {loop="$plugin_end_zone"}
486 **linklist.paging.html**
488 After the "private only" icon:
491 {loop="$action_plugin"}
501 {loop="$edit_link_plugin"}
511 {loop="$tools_plugin"}
521 <div id="plugin_zone_start_picwall" class="plugin_zone">
522 {loop="$plugin_start_zone"}
531 <div id="plugin_zone_end_picwall" class="plugin_zone">
532 {loop="$plugin_end_zone"}
543 <div id="plugin_zone_start_tagcloud" class="plugin_zone">
544 {loop="$plugin_start_zone"}
553 <div id="plugin_zone_end_tagcloud" class="plugin_zone">
554 {loop="$plugin_end_zone"}
565 <div id="plugin_zone_start_picwall" class="plugin_zone">
566 {loop="$plugin_start_zone"}
575 <div class="dailyEntryFooter">
576 {loop="$link.link_plugin"}
585 <div id="plugin_zone_end_picwall" class="plugin_zone">
586 {loop="$plugin_end_zone"}