-[**I am a developer: ** Developer API](#developer-api)
-
-[**I am a template designer: ** Guide for template designers](#guide-for-template-designer)
-
----
+# Plugin system
## Developer API
### What can I do with plugins?
-The plugin system let you:
+The plugin system lets you:
- insert content into specific places across templates.
- alter data before templates rendering.
- alter data before saving new links.
+
### How can I create a plugin for Shaarli?
First, chose a plugin name, such as `demo_plugin`.
| |---| demo_plugin.php
```
+
### Plugin initialization
At the beginning of Shaarli execution, all enabled plugins are loaded. At this point, the plugin system looks for an `init()` function in the <plugin_name>.php to execute and run it if it exists. This function must be named this way, and takes the `ConfigManager` as parameter.
If this function is declared, and the plugin enabled, it will be called every time Shaarli is rendering the header.
+
### Plugin's data
#### Parameters
return $data;
```
+
#### Data manipulation
When a page is displayed, every variable send to the template engine is passed to plugins before that in `$data`.
> Note: In PHP, `parse_ini_file()` seems to want strings to be between by quotes `"` in the ini file.
+
### It's not working!
Use `demo_plugin` as a functional example. It covers most of the plugin system features.
If it's still not working, please [open an issue](https://github.com/shaarli/Shaarli/issues/new).
+
### Hooks
| Hooks | Description |
| [save_plugin_parameters](#save_plugin_parameters) | Allow to manipulate plugin parameters before they're saved. |
-
#### render_header
-Triggered on every page.
+Triggered on every page - allows plugins to add content in page headers.
-Allow plugin to add content in page headers.
##### Data
![fields_toolbar_example](http://i.imgur.com/3GMifI2.png)
-#### render_includes
-Triggered on every page.
+#### render_includes
-Allow plugin to include their own CSS files.
+Triggered on every page - allows plugins to include their own CSS files.
-##### Data
+##### data
`$data` is an array containing:
> Note: only add the path of the CSS file. E.g: `plugins/demo_plugin/custom_demo.css`.
+
#### render_footer
Triggered on every page.
Allow plugin to add content in page footer and include their own JS files.
-##### Data
+##### data
`$data` is an array containing:
> Note: only add the path of the JS file. E.g: `plugins/demo_plugin/custom_demo.js`.
+
#### render_linklist
Triggered when `linklist` is displayed (list of links, permalink, search, tag filtered, etc.).
It allows to add content at the begining and end of the page, after every link displayed and to alter link data.
-##### Data
+##### data
`$data` is an array containing:
- All templates data, including links.
- [Special data](#special-data)
-##### Template placeholders
+##### template placeholders
Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.
![plugin_end_zone_example](http://i.imgur.com/6IoRuop.png)
+
#### render_editlink
Triggered when the link edition form is displayed.
Allow to add fields in the form, or display elements.
-##### Data
+##### data
`$data` is an array containing:
- All templates data.
- [Special data](#special-data)
-##### Template placeholders
+##### template placeholders
Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.
![edit_link_plugin_example](http://i.imgur.com/5u17Ens.png)
+
#### render_tools
Triggered when the "tools" page is displayed.
Allow to add content at the end of the page.
-##### Data
+##### data
`$data` is an array containing:
- All templates data.
- [Special data](#special-data)
-##### Template placeholders
+##### template placeholders
Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.
![tools_plugin_example](http://i.imgur.com/Bqhu9oQ.png)
+
#### render_picwall
Triggered when picwall is displayed.
Allow to add content at the top and bottom of the page.
-##### Data
+##### data
`$data` is an array containing:
- All templates data.
- [Special data](#special-data)
-##### Template placeholders
+##### template placeholders
Items can be displayed in templates by adding an entry in `$data['<placeholder>']` array.
![plugin_start_end_zone_example](http://i.imgur.com/tVTQFER.png)
+
#### render_tagcloud
Triggered when tagcloud is displayed.
Allow to add content at the top and bottom of the page.
-##### Data
+##### data
`$data` is an array containing:
#### render_taglist
-Triggered when taglist is displayed.
-
-Allow to add content at the top and bottom of the page.
+Triggered when taglist is displayed - allows to add content at the top and bottom of the page.
-##### Data
+##### data
`$data` is an array containing:
Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.
-##### Data
+
+##### data
`$data` is an array containing:
- `plugin_start_zone`: before displaying the template content.
- `plugin_end_zone`: after displaying the template content.
+
#### render_feed
Triggered when the ATOM or RSS feed is displayed.
Allow to add tags in the feed, either in the header or for each items. Items (links) can also be altered before being rendered.
-##### Data
+##### data
`$data` is an array containing:
- `feed_plugins`: additional tag for every link entry.
+
#### save_link
Triggered when a link is save (new link or edit).
Allow to alter the link being saved in the datastore.
-##### Data
+##### data
`$data` is an array containing the link being saved:
Allow to execute any action before the link is actually removed from the datastore
-##### Data
+##### data
`$data` is an array containing the link being deleted:
Plugins can perform an action every times their settings are updated.
For example it is used to update the CSS file of the `default_colors` plugins.
-##### Data
+##### data
`$data` input contains the `$_POST` array.
Also [special data](#special-data).
-## Guide for template designer
+## Guide for template designers
### Plugin administration