Closes #291 Fixes #227 Modifications - HTML content: match the new Wiki structure - Makefile - generate a custom HTML sidebar - include the sidebar on all pages - infer and prepend page titles - handle relative links - add title metadata, e.g. Shaarli - <Page Name> Signed-off-by: VirtualTam <virtualtam@flibidi.net>
14 KiB
#Plugin System
Note: Plugin current status - in developpement (not merged into master).
I am a user. Plugin User Guide.
I am a developper. Developper API.
I am a template designer. Guide for template designer.
Plugin User Guide
Manage plugins
In config.php
, change $GLOBALS'config'['ENABLED_PLUGINS'] array:
$GLOBALS['config'['ENABLED_PLUGINS']]('ENABLED_PLUGINS'].html)
Full list:
$GLOBALS['config'['ENABLED_PLUGINS'] = array(]('ENABLED_PLUGINS']-=-array(.html)
'qrcode', 'archiveorg', 'readityourself', 'playvideos',
'wallabag', 'markdown', 'addlink_toolbar',
);
List of plugins
Plugin maintained by the community:
- Archive.org - add a clickable icon to every link to archive.org.
- Addlink in toolbar - add a field to paste new links URL in toolbar.
- Markdown - write and display Shaare in Markdown.
- Play videos - popup to play all videos displayed in linklist.
- QRCode - add a clickable icon generating a QRCode for every link.
- ReadItYourself - add a clickable icon for ReadItYourself.
- Wallabag - add a clickable icon for Wallabag.
Developper API
What can I do with plugins?
The plugin system let 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
.
Under plugin
folder, create a folder named with your plugin name. Then create a <plugin_name>.php file in that folder.
You should have the following tree view:
| index.php
| plugins/
|---| demo_plugin/
| |---| demo_plugin.php
Understanding hooks
A plugin is a set of functions. Each function will be triggered by the plugin system at certain point in Shaarli execution.
These functions need to be named with this pattern:
hook_<plugin_name>_<hook_name>
For exemple, if my plugin want to add data to the header, this function is needed:
hook_demo_plugin_render_header()
If this function is declared, and the plugin enabled, it will be called every time Shaarli is rendering the header.
Plugin's data
Parameters
Every hook function has a $data
parameter. Its content differs for each hooks.
This parameter needs to be returned every time, otherwise data is lost.
return $data;
Filling templates placeholder
Template placeholders are displayed in template in specific places.
RainTPL displays every element contained in the placeholder's array. These element can be added by plugins.
For example, let's add a value in the placeholder top_placeholder
which is displayed at the top of my page:
$data['top_placeholder'[] = 'My content';](]-=-'My-content';.html)
# OR
array_push($data['top_placeholder'], 'My', 'content');[](.html)
return $data;
Data manipulation
When a page is displayed, every variable send to the template engine is passed to plugins before that in $data
.
The data contained by this array can be altered before template rendering.
For exemple, in linklist, it is possible to alter every title:
// mind the reference if you want $data to be altered
foreach ($data['links'] as &$value) {[](.html)
// String reverse every title.
$value['title'] = strrev($value['title']);[](.html)
}
return $data;
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.
Hooks
Hooks | Description |
---|---|
render_header | Allow plugin to add content in page headers. |
render_includes | Allow plugin to include their own CSS files. |
render_footer | Allow plugin to add content in page footer and include their own JS files. |
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 | Allow to add fields in the form, or display elements. |
render_tools | Allow to add content at the end of the page. |
render_picwall | Allow to add content at the top and bottom of the page. |
render_tagcloud | Allow to add content at the top and bottom of the page. |
render_daily | Allow to add content at the top and bottom of the page, the bottom of each link and to alter data. |
savelink | Allow to alter the link being saved in the datastore. |
render_header
Triggered on every page.
Allow plugin to add content in page headers.
Data
$data
is an array containing:
_PAGE_
: current target page (eg:linklist
,picwall
, etc.)._LOGGEDIN_
: true if user is logged in, false otherwise.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
buttons_toolbar
: after the list of buttons in the header.
fields_toolbar
: after search fields in the header.
Note: This will only be called in linklist.
render_includes
Triggered on every page.
Allow plugin to include their own CSS files.
Data
$data
is an array containing:
_PAGE_
: current target page (eg:linklist
,picwall
, etc.)._LOGGEDIN_
: true if user is logged in, false otherwise.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
css_files
: called after loading default CSS.
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
is an array containing:
_PAGE_
: current target page (eg:linklist
,picwall
, etc.)._LOGGEDIN_
: true if user is logged in, false otherwise.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
text
: called after the end of the footer text.
js_files
: called at the end of the page, to include custom JS scripts.
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
is an array containing:
_LOGGEDIN_
: true if user is logged in, false otherwise.- All templates data, including links.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
action_plugin
: next to the button "private only" at the top and bottom of the page.
link_plugin
: for every link, between permalink and link URL.
plugin_start_zone
: before displaying the template content.
plugin_end_zone
: after displaying the template content.
render_editlink
Triggered when the link edition form is displayed.
Allow to add fields in the form, or display elements.
Data
$data
is an array containing:
- All templates data.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
edit_link_plugin
: after tags field.
render_tools
Triggered when the "tools" page is displayed.
Allow to add content at the end of the page.
Data
$data
is an array containing:
- All templates data.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
tools_plugin
: at the end of the page.
render_picwall
Triggered when picwall is displayed.
Allow to add content at the top and bottom of the page.
Data
$data
is an array containing:
_LOGGEDIN_
: true if user is logged in, false otherwise.- All templates data.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
-
plugin_start_zone
: before displaying the template content. -
plugin_end_zone
: after displaying the template content.
render_tagcloud
Triggered when tagcloud is displayed.
Allow to add content at the top and bottom of the page.
Data
$data
is an array containing:
_LOGGEDIN_
: true if user is logged in, false otherwise.- All templates data.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
-
plugin_start_zone
: before displaying the template content. -
plugin_end_zone
: after displaying the template content.
render_daily
Triggered when tagcloud is displayed.
Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.
Data
$data
is an array containing:
_LOGGEDIN_
: true if user is logged in, false otherwise.- All templates data, including links.
Template placeholders
Items can be displayed in templates by adding an entry in $data['<placeholder>']
array.
List of placeholders:
link_plugin
: used at bottom of each link.
-
plugin_start_zone
: before displaying the template content. -
plugin_end_zone
: after displaying the template content.
savelink
Triggered when a link is save (new link or edit).
Allow to alter the link being saved in the datastore.
Data
$data
is an array containing the link being saved:
- title
- url
- description
- linkdate
- private
- tags
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.
It's a RainTPL loop like this:
{loop="$plugin_variable"}
{$value}
{/loop}
You should enable demo_plugin
for testing purpose, since it uses every placeholder available.
List of placeholders
page.header.html
At the end of the menu:
{loop="$plugins_header.buttons_toolbar"}
{$value}
{/loop}
includes.html
At the end of the file:
{loop="$plugins_includes.css_files"}
<link type="text/css" rel="stylesheet" href="{$value}#"/>
{/loop}
page.footer.html
At the end of your footer notes:
{loop="$plugins_footer.text"}
{$value}
{/loop}
At the end of file:
{loop="$plugins_footer.js_files"}
<script src="{$value}#"></script>
{/loop}
linklist.html
After search fields:
{loop="$plugins_header.fields_toolbar"}
{$value}
{/loop}
Before displaying the link list (after paging):
{loop="$plugin_start_zone"}
{$value}
{/loop}
For every links (icons):
{loop="$value.link_plugin"}
<span>{$value}</span>
{/loop}
Before end paging:
{loop="$plugin_end_zone"}
{$value}
{/loop}
linklist.paging.html
After the "private only" icon:
{loop="$action_plugin"}
{$value}
{/loop}
editlink.html
After tags field:
{loop="$edit_link_plugin"}
{$value}
{/loop}
tools.html
After the last tool:
{loop="$tools_plugin"}
{$value}
{/loop}
picwall.html
Top:
<div id="plugin_zone_start_picwall" class="plugin_zone">
{loop="$plugin_start_zone"}
{$value}
{/loop}
</div>
Bottom:
<div id="plugin_zone_end_picwall" class="plugin_zone">
{loop="$plugin_end_zone"}
{$value}
{/loop}
</div>
tagcloud.html
Top:
<div id="plugin_zone_start_tagcloud" class="plugin_zone">
{loop="$plugin_start_zone"}
{$value}
{/loop}
</div>
Bottom:
<div id="plugin_zone_end_tagcloud" class="plugin_zone">
{loop="$plugin_end_zone"}
{$value}
{/loop}
</div>
daily.html
Top:
<div id="plugin_zone_start_picwall" class="plugin_zone">
{loop="$plugin_start_zone"}
{$value}
{/loop}
</div>
After every link:
<div class="dailyEntryFooter">
{loop="$link.link_plugin"}
{$value}
{/loop}
</div>
Bottom:
<div id="plugin_zone_end_picwall" class="plugin_zone">
{loop="$plugin_end_zone"}
{$value}
{/loop}
</div>