First, chose a plugin name, such as `demo_plugin`.
-Under `plugin` folder, create a folder named with your plugin name. Then create a <plugin_name>.php file in that folder.
+Under `plugin` folder, create a folder named with your plugin name. Then create a <plugin_name>.meta file and a <plugin_name>.php file in that folder.
You should have the following tree view:
| index.php
| plugins/
|---| demo_plugin/
+| |---| demo_plugin.meta
| |---| 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 to execute and run it if it exists. This function must be named this way, and takes the `ConfigManager` as parameter.
+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.
<plugin_name>_init($conf)
This function can be used to create initial data, load default settings, etc. But also to set *plugin errors*. If the initialization function returns an array of strings, they will be understand as errors, and displayed in the header to logged in users.
+The plugin system also looks for a `description` variable in the <plugin_name>.meta file, to be displayed in the plugin administration page.
+
+ description="The plugin does this and that."
+
### Understanding hooks
A plugin is a set of functions. Each function will be triggered by the plugin system at certain point in Shaarli execution.
return $data;
+#### Special data
+
+Special additional data are passed to every hook through the
+`$data` parameter to give you access to additional context, and services.
+
+Complete list:
+
+ * `_PAGE_` (string): if the current hook is used to render a template, its name is passed through this additional parameter.
+ * `_LOGGEDIN_` (bool): whether the user is logged in or not.
+ * `_BASE_PATH_` (string): if Shaarli instance is hosted under a subfolder, contains the subfolder path to `index.php` (e.g. `https://domain.tld/shaarli/` -> `/shaarli/`).
+ * `_BOOKMARK_SERVICE_` (`BookmarkServiceInterface`): bookmark service instance, for advanced usage.
+
+Example:
+
+```php
+if ($data['_PAGE_'] === TemplatePage::LINKLIST && $data['LOGGEDIN'] === true) {
+ // Do something for logged in users when the link list is rendered
+}
+```
+
#### Filling templates placeholder
Template placeholders are displayed in template in specific places.
The data contained by this array can be altered before template rendering.
-For exemple, in linklist, it is possible to alter every title:
+For example, in linklist, it is possible to alter every title:
```php
// mind the reference if you want $data to be altered
| ------------- |:-------------:|
| [render_header](#render_header) | Allow plugin to add content in page headers. |
| [render_includes](#render_includes) | Allow plugin to include their own CSS files. |
-| [render_footer](#render_footer) | Allow plugin to add content in page footer and include their own JS files. |
+| [render_footer](#render_footer) | Allow plugin to add content in page footer and include their own JS files. |
| [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. |
| [render_editlink](#render_editlink) | Allow to add fields in the form, or display elements. |
| [render_tools](#render_tools) | Allow to add content at the end of the page. |
`$data` is an array containing:
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.).
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data, including links.
+ - All templates data, including links.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- All templates data.
+ - All templates data.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- All templates data.
+ - All templates data.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+ - All templates data.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+ - All templates data.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data.
+ - All templates data.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- All templates data, including links.
+ - All templates data, including links.
+ - [Special data](#special-data)
##### Template placeholders
`$data` is an array containing:
-- `_LOGGEDIN_`: true if user is logged in, false otherwise.
-- `_PAGE_`: containing either `rss` or `atom`.
-- All templates data, including links.
+ - All templates data, including links.
+ - [Special data](#special-data)
##### Template placeholders
- created
- updated
+Also [special data](#special-data).
+
#### delete_link
##### Data
-`$data` is an array containing the link being saved:
+`$data` is an array containing the link being deleted:
- id
- title
- created
- updated
+Also [special data](#special-data).
#### save_plugin_parameters
So if the plugin has a parameter called `MYPLUGIN_PARAMETER`,
the array will contain an entry with `MYPLUGIN_PARAMETER` as a key.
+Also [special data](#special-data).
## Guide for template designer
### Placeholder system
-In order to make plugins work with every custom themes, you need to add variable placeholder in your templates.
+In order to make plugins work with every custom themes, you need to add variable placeholder in your templates.
It's a RainTPL loop like this:
At the end of file, before clearing floating blocks:
- {if="!empty($plugin_errors) && isLoggedIn()"}
+ {if="!empty($plugin_errors) && $is_logged_in"}
<ul class="errors">
{loop="plugin_errors"}
<li>{$value}</li>