]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/Plugin-System.html
Bump version to v0.9.0
[github/shaarli/Shaarli.git] / doc / Plugin-System.html
CommitLineData
992af0b9
V
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <meta name="generator" content="pandoc">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
5409ade2 7 <title>Shaarli – Plugin System</title>
992af0b9 8 <style type="text/css">code{white-space: pre;}</style>
992af0b9 9 <style type="text/css">
5409ade2 10div.sourceCode { overflow-x: auto; }
992af0b9
V
11table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
12 margin: 0; padding: 0; vertical-align: baseline; border: none; }
13table.sourceCode { width: 100%; line-height: 100%; }
14td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
15td.sourceCode { padding-left: 5px; }
5409ade2
A
16code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
17code > span.dt { color: #902000; } /* DataType */
18code > span.dv { color: #40a070; } /* DecVal */
19code > span.bn { color: #40a070; } /* BaseN */
20code > span.fl { color: #40a070; } /* Float */
21code > span.ch { color: #4070a0; } /* Char */
22code > span.st { color: #4070a0; } /* String */
23code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
24code > span.ot { color: #007020; } /* Other */
25code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
26code > span.fu { color: #06287e; } /* Function */
27code > span.er { color: #ff0000; font-weight: bold; } /* Error */
28code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
29code > span.cn { color: #880000; } /* Constant */
30code > span.sc { color: #4070a0; } /* SpecialChar */
31code > span.vs { color: #4070a0; } /* VerbatimString */
32code > span.ss { color: #bb6688; } /* SpecialString */
33code > span.im { } /* Import */
34code > span.va { color: #19177c; } /* Variable */
35code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
36code > span.op { color: #666666; } /* Operator */
37code > span.bu { } /* BuiltIn */
38code > span.ex { } /* Extension */
39code > span.pp { color: #bc7a00; } /* Preprocessor */
40code > span.at { color: #7d9029; } /* Attribute */
41code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
42code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
43code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
44code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
992af0b9
V
45 </style>
46 <link rel="stylesheet" href="github-markdown.css">
5409ade2
A
47 <!--[if lt IE 9]>
48 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
49 <![endif]-->
992af0b9
V
50</head>
51<body>
52<div id="local-sidebar">
53<ul>
54<li><a href="Home.html">Home</a></li>
fdf88d19 55<li>Setup
992af0b9 56<ul>
fdf88d19
A
57<li><a href="Download-and-Installation.html">Download and Installation</a></li>
58<li><a href="Upgrade-and-migration.html">Upgrade and migration</a></li>
992af0b9
V
59<li><a href="Server-requirements.html">Server requirements</a></li>
60<li><a href="Server-configuration.html">Server configuration</a></li>
5409ade2 61<li><a href="Server-security.html">Server security</a></li>
992af0b9 62<li><a href="Shaarli-configuration.html">Shaarli configuration</a></li>
08dcd8ea 63<li><a href="Plugins.html">Plugins</a></li>
992af0b9 64</ul></li>
5409ade2 65<li><a href="Docker.html">Docker</a></li>
992af0b9
V
66<li><a href="Usage.html">Usage</a>
67<ul>
68<li><a href="Sharing-button.html">Sharing button</a> (bookmarklet)</li>
5409ade2 69<li><a href="Browsing-and-Searching.html">Browsing and Searching</a></li>
992af0b9
V
70<li><a href="Firefox-share.html">Firefox share</a></li>
71<li><a href="RSS-feeds.html">RSS feeds</a></li>
b230bf20 72<li><a href="REST-API.html">REST API</a></li>
992af0b9
V
73</ul></li>
74<li>How To
75<ul>
76<li><a href="Backup,-restore,-import-and-export.html">Backup, restore, import and export</a></li>
77<li><a href="Copy-an-existing-installation-over-SSH-and-serve-it-locally.html">Copy an existing installation over SSH and serve it locally</a></li>
5409ade2 78<li><a href="Create-and-serve-multiple-Shaarlis-(farm).html">Create and serve multiple Shaarlis (farm)</a></li>
992af0b9 79<li><a href="Download-CSS-styles-from-an-OPML-list.html">Download CSS styles from an OPML list</a></li>
6335a0fc 80<li><a href="Datastore-hacks.html">Datastore hacks</a></li>
992af0b9
V
81</ul></li>
82<li><a href="Troubleshooting.html">Troubleshooting</a></li>
83<li><a href="Development.html">Development</a>
84<ul>
85<li><a href="GnuPG-signature.html">GnuPG signature</a></li>
86<li><a href="Coding-guidelines.html">Coding guidelines</a></li>
87<li><a href="Directory-structure.html">Directory structure</a></li>
88<li><a href="3rd-party-libraries.html">3rd party libraries</a></li>
89<li><a href="Plugin-System.html">Plugin System</a></li>
5409ade2 90<li><a href="Release-Shaarli.html">Release Shaarli</a></li>
b230bf20 91<li><a href="Versioning-and-Branches.html">Versioning and Branches</a></li>
992af0b9
V
92<li><a href="Security.html">Security</a></li>
93<li><a href="Static-analysis.html">Static analysis</a></li>
94<li><a href="Theming.html">Theming</a></li>
95<li><a href="Unit-tests.html">Unit tests</a></li>
96</ul></li>
97<li>About
98<ul>
99<li><a href="FAQ.html">FAQ</a></li>
100<li><a href="Community-&amp;-Related-software.html">Community &amp; Related software</a></li>
992af0b9
V
101</ul></li>
102</ul>
103</div>
104<h1 id="plugin-system">Plugin System</h1>
5409ade2 105<p><a href="#developer-api"><strong>I am a developer.</strong> Developer API.</a><a href=".html"></a></p>
992af0b9 106<p><a href="#guide-for-template-designer"><strong>I am a template designer.</strong> Guide for template designer.</a><a href=".html"></a></p>
5409ade2 107<h2 id="developer-api">Developer API</h2>
992af0b9
V
108<h3 id="what-can-i-do-with-plugins">What can I do with plugins?</h3>
109<p>The plugin system let you:</p>
110<ul>
111<li>insert content into specific places across templates.</li>
112<li>alter data before templates rendering.</li>
113<li>alter data before saving new links.</li>
114</ul>
115<h3 id="how-can-i-create-a-plugin-for-shaarli">How can I create a plugin for Shaarli?</h3>
116<p>First, chose a plugin name, such as <code>demo_plugin</code>.</p>
117<p>Under <code>plugin</code> folder, create a folder named with your plugin name. Then create a <plugin_name>.php file in that folder.</p>
118<p>You should have the following tree view:</p>
119<pre><code>| index.php
120| plugins/
121|---| demo_plugin/
122| |---| demo_plugin.php</code></pre>
b230bf20
A
123<h3 id="plugin-initialization">Plugin initialization</h3>
124<p>At the beginning of Shaarli execution, all enabled plugins are loaded. At this point, the plugin system looks for an <code>init()</code> function to execute and run it if it exists. This function must be named this way, and takes the <code>ConfigManager</code> as parameter.</p>
125<pre><code>&lt;plugin_name&gt;_init($conf)</code></pre>
126<p>This function can be used to create initial data, load default settings, etc. But also to set <em>plugin errors</em>. If the initialization function returns an array of strings, they will be understand as errors, and displayed in the header to logged in users.</p>
992af0b9
V
127<h3 id="understanding-hooks">Understanding hooks</h3>
128<p>A plugin is a set of functions. Each function will be triggered by the plugin system at certain point in Shaarli execution.</p>
129<p>These functions need to be named with this pattern:</p>
b230bf20
A
130<pre><code>hook_&lt;plugin_name&gt;_&lt;hook_name&gt;($data, $conf)</code></pre>
131<p>Parameters:</p>
132<ul>
133<li>data: see <a href="https://github.com/shaarli/Shaarli/wiki/Plugin-System#plugins-data">$data section</a><a href=".html"></a></li>
134<li>conf: the <code>ConfigManager</code> instance.</li>
135</ul>
992af0b9 136<p>For exemple, if my plugin want to add data to the header, this function is needed:</p>
b230bf20 137<pre><code>hook_demo_plugin_render_header</code></pre>
992af0b9
V
138<p>If this function is declared, and the plugin enabled, it will be called every time Shaarli is rendering the header.</p>
139<h3 id="plugins-data">Plugin's data</h3>
140<h4 id="parameters">Parameters</h4>
141<p>Every hook function has a <code>$data</code> parameter. Its content differs for each hooks.</p>
142<p><strong>This parameter needs to be returned every time</strong>, otherwise data is lost.</p>
143<pre><code>return $data;</code></pre>
144<h4 id="filling-templates-placeholder">Filling templates placeholder</h4>
145<p>Template placeholders are displayed in template in specific places.</p>
146<p>RainTPL displays every element contained in the placeholder's array. These element can be added by plugins.</p>
147<p>For example, let's add a value in the placeholder <code>top_placeholder</code> which is displayed at the top of my page:</p>
5409ade2 148<div class="sourceCode"><pre class="sourceCode php"><code class="sourceCode php"><span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;top_placeholder&#39;</span><span class="ot">[]</span> = <span class="st">&#39;My content&#39;</span><span class="ot">;](]</span>-=-<span class="st">&#39;My-content&#39;</span><span class="ot">;</span>.html<span class="ot">)</span>
992af0b9
V
149<span class="co"># OR</span>
150<span class="fu">array_push</span><span class="ot">(</span><span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;top_placeholder&#39;</span><span class="ot">],</span> <span class="st">&#39;My&#39;</span><span class="ot">,</span> <span class="st">&#39;content&#39;</span><span class="ot">);[](</span>.html<span class="ot">)</span>
151
5409ade2 152<span class="kw">return</span> <span class="kw">$data</span><span class="ot">;</span></code></pre></div>
992af0b9
V
153<h4 id="data-manipulation">Data manipulation</h4>
154<p>When a page is displayed, every variable send to the template engine is passed to plugins before that in <code>$data</code>.</p>
155<p>The data contained by this array can be altered before template rendering.</p>
156<p>For exemple, in linklist, it is possible to alter every title:</p>
5409ade2 157<div class="sourceCode"><pre class="sourceCode php"><code class="sourceCode php"><span class="co">// mind the reference if you want $data to be altered</span>
992af0b9
V
158<span class="kw">foreach</span> <span class="ot">(</span><span class="kw">$data</span><span class="ot">[</span><span class="st">&#39;links&#39;</span><span class="ot">]</span> <span class="kw">as</span> &amp;<span class="kw">$value</span><span class="ot">)</span> {<span class="ot">[](</span>.html<span class="ot">)</span>
159 <span class="co">// String reverse every title.</span>
160 <span class="kw">$value</span><span class="ot">[</span><span class="st">&#39;title&#39;</span><span class="ot">]</span> = <span class="fu">strrev</span><span class="ot">(</span><span class="kw">$value</span><span class="ot">[</span><span class="st">&#39;title&#39;</span><span class="ot">]);[](</span>.html<span class="ot">)</span>
161}
162
5409ade2
A
163<span class="kw">return</span> <span class="kw">$data</span><span class="ot">;</span></code></pre></div>
164<h3 id="metadata">Metadata</h3>
165<p>Every plugin needs a <code>&lt;plugin_name&gt;.meta</code> file, which is in fact an <code>.ini</code> file (<code>KEY=&quot;VALUE&quot;</code>), to be listed in plugin administration.</p>
166<p>Each file contain two keys:</p>
167<ul>
168<li><code>description</code>: plugin description</li>
169<li><code>parameters</code>: user parameter names, separated by a <code>;</code>.</li>
b230bf20 170<li><code>parameter.&lt;PARAMETER_NAME&gt;</code>: add a text description the specified parameter.</li>
5409ade2
A
171</ul>
172<blockquote>
173<p>Note: In PHP, <code>parse_ini_file()</code> seems to want strings to be between by quotes <code>&quot;</code> in the ini file.</p>
174</blockquote>
992af0b9
V
175<h3 id="its-not-working">It's not working!</h3>
176<p>Use <code>demo_plugin</code> as a functional example. It covers most of the plugin system features.</p>
177<p>If it's still not working, please <a href="https://github.com/shaarli/Shaarli/issues/new">open an issue</a>.<a href=".html"></a></p>
178<h3 id="hooks">Hooks</h3>
5409ade2
A
179<table style="width:42%;">
180<colgroup>
181<col style="width: 19%" />
182<col style="width: 22%" />
183</colgroup>
992af0b9
V
184<thead>
185<tr class="header">
5409ade2 186<th>Hooks</th>
992af0b9
V
187<th style="text-align: center;">Description</th>
188</tr>
189</thead>
190<tbody>
191<tr class="odd">
5409ade2 192<td><a href="#render_header">render_header</a></td>
992af0b9
V
193<td style="text-align: center;">Allow plugin to add content in page headers.</td>
194</tr>
195<tr class="even">
5409ade2 196<td><a href="#render_includes">render_includes</a></td>
992af0b9
V
197<td style="text-align: center;">Allow plugin to include their own CSS files.</td>
198</tr>
199<tr class="odd">
5409ade2 200<td><a href="#render_footer">render_footer</a></td>
992af0b9
V
201<td style="text-align: center;">Allow plugin to add content in page footer and include their own JS files.</td>
202</tr>
203<tr class="even">
5409ade2 204<td><a href="#render_linklist">render_linklist</a></td>
992af0b9
V
205<td style="text-align: center;">It allows to add content at the begining and end of the page, after every link displayed and to alter link data.</td>
206</tr>
207<tr class="odd">
5409ade2 208<td><a href="#render_editlink">render_editlink</a></td>
992af0b9
V
209<td style="text-align: center;">Allow to add fields in the form, or display elements.</td>
210</tr>
211<tr class="even">
5409ade2 212<td><a href="#render_tools">render_tools</a></td>
992af0b9
V
213<td style="text-align: center;">Allow to add content at the end of the page.</td>
214</tr>
215<tr class="odd">
5409ade2 216<td><a href="#render_picwall">render_picwall</a></td>
992af0b9
V
217<td style="text-align: center;">Allow to add content at the top and bottom of the page.</td>
218</tr>
219<tr class="even">
5409ade2 220<td><a href="#render_tagcloud">render_tagcloud</a></td>
b230bf20 221<td style="text-align: center;">Allow to add content at the top and bottom of the page, and after all tags.</td>
992af0b9
V
222</tr>
223<tr class="odd">
b230bf20
A
224<td><a href="#render_taglist">render_taglist</a></td>
225<td style="text-align: center;">Allow to add content at the top and bottom of the page, and after all tags.</td>
226</tr>
227<tr class="even">
5409ade2 228<td><a href="#render_daily">render_daily</a></td>
992af0b9
V
229<td style="text-align: center;">Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.</td>
230</tr>
b230bf20
A
231<tr class="odd">
232<td><a href="#render_feed">render_feed</a></td>
233<td style="text-align: center;">Allow to do add tags in RSS and ATOM feeds.</td>
234</tr>
992af0b9 235<tr class="even">
b230bf20 236<td><a href="#save_link">save_link</a></td>
992af0b9
V
237<td style="text-align: center;">Allow to alter the link being saved in the datastore.</td>
238</tr>
b230bf20
A
239<tr class="odd">
240<td><a href="#delete_link">delete_link</a></td>
241<td style="text-align: center;">Allow to do an action before a link is deleted from the datastore.</td>
242</tr>
992af0b9
V
243</tbody>
244</table>
245<h4 id="render_header">render_header</h4>
246<p>Triggered on every page.</p>
247<p>Allow plugin to add content in page headers.</p>
248<h5 id="data">Data</h5>
249<p><code>$data</code> is an array containing:</p>
250<ul>
251<li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
252<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
253</ul>
254<h5 id="template-placeholders">Template placeholders</h5>
255<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
256<p>List of placeholders:</p>
257<ul>
258<li><code>buttons_toolbar</code>: after the list of buttons in the header.</li>
259</ul>
260<p><img src="http://i.imgur.com/ssJUOrt.png" alt="buttons_toolbar_example" /><a href=".html"></a></p>
261<ul>
262<li><code>fields_toolbar</code>: after search fields in the header.</li>
263</ul>
264<blockquote>
265<p>Note: This will only be called in linklist.</p>
266</blockquote>
267<p><img src="http://i.imgur.com/3GMifI2.png" alt="fields_toolbar_example" /><a href=".html"></a></p>
268<h4 id="render_includes">render_includes</h4>
269<p>Triggered on every page.</p>
270<p>Allow plugin to include their own CSS files.</p>
271<h5 id="data-1">Data</h5>
272<p><code>$data</code> is an array containing:</p>
273<ul>
274<li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
275<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
276</ul>
277<h5 id="template-placeholders-1">Template placeholders</h5>
278<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
279<p>List of placeholders:</p>
280<ul>
281<li><code>css_files</code>: called after loading default CSS.</li>
282</ul>
283<blockquote>
284<p>Note: only add the path of the CSS file. E.g: <code>plugins/demo_plugin/custom_demo.css</code>.</p>
285</blockquote>
286<h4 id="render_footer">render_footer</h4>
287<p>Triggered on every page.</p>
288<p>Allow plugin to add content in page footer and include their own JS files.</p>
289<h5 id="data-2">Data</h5>
290<p><code>$data</code> is an array containing:</p>
291<ul>
292<li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
293<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
294</ul>
295<h5 id="template-placeholders-2">Template placeholders</h5>
296<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
297<p>List of placeholders:</p>
298<ul>
299<li><code>text</code>: called after the end of the footer text.</li>
08dcd8ea 300<li><code>endofpage</code>: called at the end of the page.</li>
992af0b9
V
301</ul>
302<p><img src="http://i.imgur.com/L5S2YEH.png" alt="text_example" /><a href=".html"></a></p>
303<ul>
304<li><code>js_files</code>: called at the end of the page, to include custom JS scripts.</li>
305</ul>
306<blockquote>
307<p>Note: only add the path of the JS file. E.g: <code>plugins/demo_plugin/custom_demo.js</code>.</p>
308</blockquote>
309<h4 id="render_linklist">render_linklist</h4>
310<p>Triggered when <code>linklist</code> is displayed (list of links, permalink, search, tag filtered, etc.).</p>
311<p>It allows to add content at the begining and end of the page, after every link displayed and to alter link data.</p>
312<h5 id="data-3">Data</h5>
313<p><code>$data</code> is an array containing:</p>
314<ul>
315<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
316<li>All templates data, including links.</li>
317</ul>
318<h5 id="template-placeholders-3">Template placeholders</h5>
319<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
320<p>List of placeholders:</p>
321<ul>
322<li><code>action_plugin</code>: next to the button &quot;private only&quot; at the top and bottom of the page.</li>
323</ul>
324<p><img src="http://i.imgur.com/Q12PWg0.png" alt="action_plugin_example" /><a href=".html"></a></p>
325<ul>
326<li><code>link_plugin</code>: for every link, between permalink and link URL.</li>
327</ul>
328<p><img src="http://i.imgur.com/3oDPhWx.png" alt="link_plugin_example" /><a href=".html"></a></p>
329<ul>
330<li><code>plugin_start_zone</code>: before displaying the template content.</li>
331</ul>
332<p><img src="http://i.imgur.com/OVBkGy3.png" alt="plugin_start_zone_example" /><a href=".html"></a></p>
333<ul>
334<li><code>plugin_end_zone</code>: after displaying the template content.</li>
335</ul>
336<p><img src="http://i.imgur.com/6IoRuop.png" alt="plugin_end_zone_example" /><a href=".html"></a></p>
337<h4 id="render_editlink">render_editlink</h4>
338<p>Triggered when the link edition form is displayed.</p>
339<p>Allow to add fields in the form, or display elements.</p>
340<h5 id="data-4">Data</h5>
341<p><code>$data</code> is an array containing:</p>
342<ul>
343<li>All templates data.</li>
344</ul>
345<h5 id="template-placeholders-4">Template placeholders</h5>
346<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
347<p>List of placeholders:</p>
348<ul>
349<li><code>edit_link_plugin</code>: after tags field.</li>
350</ul>
351<p><img src="http://i.imgur.com/5u17Ens.png" alt="edit_link_plugin_example" /><a href=".html"></a></p>
352<h4 id="render_tools">render_tools</h4>
353<p>Triggered when the &quot;tools&quot; page is displayed.</p>
354<p>Allow to add content at the end of the page.</p>
355<h5 id="data-5">Data</h5>
356<p><code>$data</code> is an array containing:</p>
357<ul>
358<li>All templates data.</li>
359</ul>
360<h5 id="template-placeholders-5">Template placeholders</h5>
361<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
362<p>List of placeholders:</p>
363<ul>
364<li><code>tools_plugin</code>: at the end of the page.</li>
365</ul>
366<p><img src="http://i.imgur.com/Bqhu9oQ.png" alt="tools_plugin_example" /><a href=".html"></a></p>
367<h4 id="render_picwall">render_picwall</h4>
368<p>Triggered when picwall is displayed.</p>
369<p>Allow to add content at the top and bottom of the page.</p>
370<h5 id="data-6">Data</h5>
371<p><code>$data</code> is an array containing:</p>
372<ul>
373<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
374<li>All templates data.</li>
375</ul>
376<h5 id="template-placeholders-6">Template placeholders</h5>
377<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
378<p>List of placeholders:</p>
379<ul>
380<li><p><code>plugin_start_zone</code>: before displaying the template content.</p></li>
381<li><p><code>plugin_end_zone</code>: after displaying the template content.</p></li>
382</ul>
383<p><img src="http://i.imgur.com/tVTQFER.png" alt="plugin_start_end_zone_example" /><a href=".html"></a></p>
384<h4 id="render_tagcloud">render_tagcloud</h4>
385<p>Triggered when tagcloud is displayed.</p>
386<p>Allow to add content at the top and bottom of the page.</p>
387<h5 id="data-7">Data</h5>
388<p><code>$data</code> is an array containing:</p>
389<ul>
390<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
391<li>All templates data.</li>
392</ul>
393<h5 id="template-placeholders-7">Template placeholders</h5>
394<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
395<p>List of placeholders:</p>
396<ul>
397<li><p><code>plugin_start_zone</code>: before displaying the template content.</p></li>
398<li><p><code>plugin_end_zone</code>: after displaying the template content.</p></li>
399</ul>
b230bf20
A
400<p>For each tag, the following placeholder can be used:</p>
401<ul>
402<li><code>tag_plugin</code>: after each tag</li>
403</ul>
992af0b9 404<p><img src="http://i.imgur.com/vHmyT3a.png" alt="plugin_start_end_zone_example" /><a href=".html"></a></p>
b230bf20
A
405<h4 id="render_taglist">render_taglist</h4>
406<p>Triggered when taglist is displayed.</p>
407<p>Allow to add content at the top and bottom of the page.</p>
408<h5 id="data-8">Data</h5>
409<p><code>$data</code> is an array containing:</p>
410<ul>
411<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
412<li>All templates data.</li>
413</ul>
414<h5 id="template-placeholders-8">Template placeholders</h5>
415<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
416<p>List of placeholders:</p>
417<ul>
418<li><p><code>plugin_start_zone</code>: before displaying the template content.</p></li>
419<li><p><code>plugin_end_zone</code>: after displaying the template content.</p></li>
420</ul>
421<p>For each tag, the following placeholder can be used:</p>
422<ul>
423<li><code>tag_plugin</code>: after each tag</li>
424</ul>
992af0b9
V
425<h4 id="render_daily">render_daily</h4>
426<p>Triggered when tagcloud is displayed.</p>
427<p>Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.</p>
b230bf20 428<h5 id="data-9">Data</h5>
992af0b9
V
429<p><code>$data</code> is an array containing:</p>
430<ul>
431<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
432<li>All templates data, including links.</li>
433</ul>
b230bf20 434<h5 id="template-placeholders-9">Template placeholders</h5>
992af0b9
V
435<p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
436<p>List of placeholders:</p>
437<ul>
438<li><code>link_plugin</code>: used at bottom of each link.</li>
439</ul>
440<p><img src="http://i.imgur.com/hzhMfSZ.png" alt="link_plugin_example" /><a href=".html"></a></p>
441<ul>
442<li><p><code>plugin_start_zone</code>: before displaying the template content.</p></li>
443<li><p><code>plugin_end_zone</code>: after displaying the template content.</p></li>
444</ul>
b230bf20
A
445<h4 id="render_feed">render_feed</h4>
446<p>Triggered when the ATOM or RSS feed is displayed.</p>
447<p>Allow to add tags in the feed, either in the header or for each items. Items (links) can also be altered before being rendered.</p>
448<h5 id="data-10">Data</h5>
449<p><code>$data</code> is an array containing:</p>
450<ul>
451<li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
452<li><code>_PAGE_</code>: containing either <code>rss</code> or <code>atom</code>.</li>
453<li>All templates data, including links.</li>
454</ul>
455<h5 id="template-placeholders-10">Template placeholders</h5>
456<p>Tags can be added in feeds by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.<a href=".html"></a></p>
457<p>List of placeholders:</p>
458<ul>
459<li><code>feed_plugins_header</code>: used as a header tag in the feed.</li>
460</ul>
461<p>For each links:</p>
462<ul>
463<li><code>feed_plugins</code>: additional tag for every link entry.</li>
464</ul>
465<h4 id="save_link">save_link</h4>
992af0b9
V
466<p>Triggered when a link is save (new link or edit).</p>
467<p>Allow to alter the link being saved in the datastore.</p>
b230bf20 468<h5 id="data-11">Data</h5>
992af0b9
V
469<p><code>$data</code> is an array containing the link being saved:</p>
470<ul>
b230bf20 471<li>id</li>
992af0b9
V
472<li>title</li>
473<li>url</li>
b230bf20 474<li>shorturl</li>
992af0b9 475<li>description</li>
992af0b9
V
476<li>private</li>
477<li>tags</li>
b230bf20
A
478<li>created</li>
479<li>updated</li>
480</ul>
481<h4 id="delete_link">delete_link</h4>
482<p>Triggered when a link is deleted.</p>
483<p>Allow to execute any action before the link is actually removed from the datastore</p>
484<h5 id="data-12">Data</h5>
485<p><code>$data</code> is an array containing the link being saved:</p>
486<ul>
487<li>id</li>
488<li>title</li>
489<li>url</li>
490<li>shorturl</li>
491<li>description</li>
492<li>private</li>
493<li>tags</li>
494<li>created</li>
495<li>updated</li>
992af0b9
V
496</ul>
497<h2 id="guide-for-template-designer">Guide for template designer</h2>
5409ade2
A
498<h3 id="plugin-administration">Plugin administration</h3>
499<p>Your theme must include a plugin administration page: <code>pluginsadmin.html</code>.</p>
500<blockquote>
501<p>Note: repo's template link needs to be added when the PR is merged.</p>
502</blockquote>
503<p>Use the default one as an example.</p>
504<p>Aside from classic RainTPL loops, plugins order is handle by JavaScript. You can just include <code>plugin_admin.js</code>, only if:</p>
505<ul>
506<li>you're using a table.</li>
507<li>you call orderUp() and orderUp() onclick on arrows.</li>
508<li>you add data-line and data-order to your rows.</li>
509</ul>
510<p>Otherwise, you can use your own JS as long as this field is send by the form:</p>
511<p><input type="hidden" name="order_{$key}" value="{$counter}"></p>
992af0b9
V
512<h3 id="placeholder-system">Placeholder system</h3>
513<p>In order to make plugins work with every custom themes, you need to add variable placeholder in your templates.</p>
514<p>It's a RainTPL loop like this:</p>
515<pre><code>{loop=&quot;$plugin_variable&quot;}
516 {$value}
517{/loop}</code></pre>
518<p>You should enable <code>demo_plugin</code> for testing purpose, since it uses every placeholder available.</p>
519<h3 id="list-of-placeholders">List of placeholders</h3>
520<p><strong>page.header.html</strong></p>
521<p>At the end of the menu:</p>
522<pre><code>{loop=&quot;$plugins_header.buttons_toolbar&quot;}
523 {$value}
524{/loop}</code></pre>
5409ade2
A
525<p>At the end of file, before clearing floating blocks:</p>
526<pre><code>{if=&quot;!empty($plugin_errors) &amp;&amp; isLoggedIn()&quot;}
527 &lt;ul class=&quot;errors&quot;&gt;
528 {loop=&quot;plugin_errors&quot;}
529 &lt;li&gt;{$value}&lt;/li&gt;
530 {/loop}
531 &lt;/ul&gt;
532{/if}</code></pre>
992af0b9
V
533<p><strong>includes.html</strong></p>
534<p>At the end of the file:</p>
5409ade2 535<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugins_includes.css_files&quot;}
992af0b9 536<span class="kw">&lt;link</span><span class="ot"> type=</span><span class="st">&quot;text/css&quot;</span><span class="ot"> rel=</span><span class="st">&quot;stylesheet&quot;</span><span class="ot"> href=</span><span class="st">&quot;{$value}#&quot;</span><span class="kw">/&gt;</span>
5409ade2 537{/loop}</code></pre></div>
992af0b9
V
538<p><strong>page.footer.html</strong></p>
539<p>At the end of your footer notes:</p>
5409ade2 540<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugins_footer.text&quot;}
992af0b9 541 {$value}
5409ade2 542{/loop}</code></pre></div>
992af0b9 543<p>At the end of file:</p>
5409ade2 544<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugins_footer.js_files&quot;}
992af0b9 545 <span class="kw">&lt;script</span><span class="ot"> src=</span><span class="st">&quot;{$value}#&quot;</span><span class="kw">&gt;&lt;/script&gt;</span>
5409ade2 546{/loop}</code></pre></div>
992af0b9
V
547<p><strong>linklist.html</strong></p>
548<p>After search fields:</p>
5409ade2 549<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugins_header.fields_toolbar&quot;}
992af0b9 550 {$value}
5409ade2 551{/loop}</code></pre></div>
992af0b9 552<p>Before displaying the link list (after paging):</p>
5409ade2 553<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugin_start_zone&quot;}
992af0b9 554 {$value}
5409ade2 555{/loop}</code></pre></div>
992af0b9 556<p>For every links (icons):</p>
5409ade2 557<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$value.link_plugin&quot;}
992af0b9 558 <span class="kw">&lt;span&gt;</span>{$value}<span class="kw">&lt;/span&gt;</span>
5409ade2 559{/loop}</code></pre></div>
992af0b9 560<p>Before end paging:</p>
5409ade2 561<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$plugin_end_zone&quot;}
992af0b9 562 {$value}
5409ade2 563{/loop}</code></pre></div>
992af0b9
V
564<p><strong>linklist.paging.html</strong></p>
565<p>After the &quot;private only&quot; icon:</p>
5409ade2 566<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$action_plugin&quot;}
992af0b9 567 {$value}
5409ade2 568{/loop}</code></pre></div>
992af0b9
V
569<p><strong>editlink.html</strong></p>
570<p>After tags field:</p>
5409ade2 571<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$edit_link_plugin&quot;}
992af0b9 572 {$value}
5409ade2 573{/loop}</code></pre></div>
992af0b9
V
574<p><strong>tools.html</strong></p>
575<p>After the last tool:</p>
5409ade2 576<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">{loop=&quot;$tools_plugin&quot;}
992af0b9 577 {$value}
5409ade2 578{/loop}</code></pre></div>
992af0b9
V
579<p><strong>picwall.html</strong></p>
580<p>Top:</p>
5409ade2 581<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_start_picwall&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
582 {loop=&quot;$plugin_start_zone&quot;}
583 {$value}
584 {/loop}
5409ade2 585<span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9 586<p>Bottom:</p>
5409ade2 587<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_end_picwall&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
588 {loop=&quot;$plugin_end_zone&quot;}
589 {$value}
590 {/loop}
5409ade2 591<span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9
V
592<p><strong>tagcloud.html</strong></p>
593<p>Top:</p>
5409ade2 594<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"> <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_start_tagcloud&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
595 {loop=&quot;$plugin_start_zone&quot;}
596 {$value}
597 {/loop}
5409ade2 598 <span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9 599<p>Bottom:</p>
5409ade2 600<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"> <span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_end_tagcloud&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
601 {loop=&quot;$plugin_end_zone&quot;}
602 {$value}
603 {/loop}
5409ade2 604 <span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9
V
605<p><strong>daily.html</strong></p>
606<p>Top:</p>
5409ade2 607<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_start_picwall&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
608 {loop=&quot;$plugin_start_zone&quot;}
609 {$value}
610 {/loop}
5409ade2 611<span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9 612<p>After every link:</p>
5409ade2 613<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"><span class="kw">&lt;div</span><span class="ot"> class=</span><span class="st">&quot;dailyEntryFooter&quot;</span><span class="kw">&gt;</span>
992af0b9
V
614 {loop=&quot;$link.link_plugin&quot;}
615 {$value}
616 {/loop}
5409ade2 617<span class="kw">&lt;/div&gt;</span></code></pre></div>
992af0b9 618<p>Bottom:</p>
5409ade2 619<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html"><span class="kw">&lt;div</span><span class="ot"> id=</span><span class="st">&quot;plugin_zone_end_picwall&quot;</span><span class="ot"> class=</span><span class="st">&quot;plugin_zone&quot;</span><span class="kw">&gt;</span>
992af0b9
V
620 {loop=&quot;$plugin_end_zone&quot;}
621 {$value}
622 {/loop}
5409ade2 623<span class="kw">&lt;/div&gt;</span></code></pre></div>
b230bf20
A
624<p><strong>feed.atom.xml</strong> and <strong>feed.rss.xml</strong>:</p>
625<p>In headers tags section:</p>
626<div class="sourceCode"><pre class="sourceCode xml"><code class="sourceCode xml">{loop=&quot;$feed_plugins_header&quot;}
627 {$value}
628{/loop}</code></pre></div>
629<p>After each entry:</p>
630<div class="sourceCode"><pre class="sourceCode xml"><code class="sourceCode xml">{loop=&quot;$value.feed_plugins&quot;}
631 {$value}
632{/loop}</code></pre></div>
992af0b9
V
633</body>
634</html>