index.html 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. <!DOCTYPE html>
  2. <!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
  3. <!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
  4. <head>
  5. <meta charset="utf-8">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8. <link rel="shortcut icon" href="../img/favicon.ico">
  9. <title>Plugin System - Shaarli Documentation</title>
  10. <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
  11. <link rel="stylesheet" href="../css/theme.css" type="text/css" />
  12. <link rel="stylesheet" href="../css/theme_extra.css" type="text/css" />
  13. <link rel="stylesheet" href="../css/highlight.css">
  14. <link href="../github-markdown.css" rel="stylesheet">
  15. <script>
  16. // Current page data
  17. var mkdocs_page_name = "Plugin System";
  18. var mkdocs_page_input_path = "Plugin-System.md";
  19. var mkdocs_page_url = "/Plugin-System/";
  20. </script>
  21. <script src="../js/jquery-2.1.1.min.js"></script>
  22. <script src="../js/modernizr-2.8.3.min.js"></script>
  23. <script type="text/javascript" src="../js/highlight.pack.js"></script>
  24. </head>
  25. <body class="wy-body-for-nav" role="document">
  26. <div class="wy-grid-for-nav">
  27. <nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
  28. <div class="wy-side-nav-search">
  29. <a href=".." class="icon icon-home"> Shaarli Documentation</a>
  30. <div role="search">
  31. <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
  32. <input type="text" name="q" placeholder="Search docs" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <ul class="current">
  38. <li class="toctree-l1">
  39. <a class="" href="..">Home</a>
  40. </li>
  41. <li class="toctree-l1">
  42. <span class="caption-text">Setup</span>
  43. <ul class="subnav">
  44. <li class="">
  45. <a class="" href="../Download-and-Installation/">Download and Installation</a>
  46. </li>
  47. <li class="">
  48. <a class="" href="../Upgrade-and-migration/">Upgrade and migration</a>
  49. </li>
  50. <li class="">
  51. <a class="" href="../Server-requirements/">Server requirements</a>
  52. </li>
  53. <li class="">
  54. <a class="" href="../Server-configuration/">Server configuration</a>
  55. </li>
  56. <li class="">
  57. <a class="" href="../Server-security/">Server security</a>
  58. </li>
  59. <li class="">
  60. <a class="" href="../Shaarli-configuration/">Shaarli configuration</a>
  61. </li>
  62. <li class="">
  63. <a class="" href="../Plugins/">Plugins</a>
  64. </li>
  65. </ul>
  66. </li>
  67. <li class="toctree-l1">
  68. <span class="caption-text">Docker</span>
  69. <ul class="subnav">
  70. <li class="">
  71. <a class="" href="../docker/docker-101/">Docker 101</a>
  72. </li>
  73. <li class="">
  74. <a class="" href="../docker/shaarli-images/">Shaarli images</a>
  75. </li>
  76. <li class="">
  77. <a class="" href="../docker/reverse-proxy-configuration/">Reverse proxy configuration</a>
  78. </li>
  79. <li class="">
  80. <a class="" href="../docker/resources/">Docker resources</a>
  81. </li>
  82. </ul>
  83. </li>
  84. <li class="toctree-l1">
  85. <span class="caption-text">Usage</span>
  86. <ul class="subnav">
  87. <li class="">
  88. <a class="" href="../Features/">Features</a>
  89. </li>
  90. <li class="">
  91. <a class="" href="../Bookmarklet/">Bookmarklet</a>
  92. </li>
  93. <li class="">
  94. <a class="" href="../Browsing-and-searching/">Browsing and searching</a>
  95. </li>
  96. <li class="">
  97. <a class="" href="../Firefox-share/">Firefox share</a>
  98. </li>
  99. <li class="">
  100. <a class="" href="../RSS-feeds/">RSS feeds</a>
  101. </li>
  102. <li class="">
  103. <a class="" href="../REST-API/">REST API</a>
  104. </li>
  105. </ul>
  106. </li>
  107. <li class="toctree-l1">
  108. <span class="caption-text">How To</span>
  109. <ul class="subnav">
  110. <li class="">
  111. <a class="" href="../Backup,-restore,-import-and-export/">Backup, restore, import and export</a>
  112. </li>
  113. <li class="">
  114. <a class="" href="../Various-hacks/">Various hacks</a>
  115. </li>
  116. </ul>
  117. </li>
  118. <li class="toctree-l1">
  119. <a class="" href="../Troubleshooting/">Troubleshooting</a>
  120. </li>
  121. <li class="toctree-l1">
  122. <span class="caption-text">Development</span>
  123. <ul class="subnav">
  124. <li class="">
  125. <a class="" href="../Development-guidelines/">Development guidelines</a>
  126. </li>
  127. <li class="">
  128. <a class="" href="../Continuous-integration-tools/">Continuous integration tools</a>
  129. </li>
  130. <li class="">
  131. <a class="" href="../GnuPG-signature/">GnuPG signature</a>
  132. </li>
  133. <li class="">
  134. <a class="" href="../Coding-guidelines/">Coding guidelines</a>
  135. </li>
  136. <li class="">
  137. <a class="" href="../Directory-structure/">Directory structure</a>
  138. </li>
  139. <li class="">
  140. <a class="" href="../3rd-party-libraries/">3rd party libraries</a>
  141. </li>
  142. <li class=" current">
  143. <a class="current" href="./">Plugin System</a>
  144. <ul class="subnav">
  145. <li class="toctree-l3"><a href="#developer-api">Developer API</a></li>
  146. <ul>
  147. <li><a class="toctree-l4" href="#what-can-i-do-with-plugins">What can I do with plugins?</a></li>
  148. <li><a class="toctree-l4" href="#how-can-i-create-a-plugin-for-shaarli">How can I create a plugin for Shaarli?</a></li>
  149. <li><a class="toctree-l4" href="#plugin-initialization">Plugin initialization</a></li>
  150. <li><a class="toctree-l4" href="#understanding-hooks">Understanding hooks</a></li>
  151. <li><a class="toctree-l4" href="#plugins-data">Plugin's data</a></li>
  152. <li><a class="toctree-l4" href="#metadata">Metadata</a></li>
  153. <li><a class="toctree-l4" href="#its-not-working">It's not working!</a></li>
  154. <li><a class="toctree-l4" href="#hooks">Hooks</a></li>
  155. </ul>
  156. <li class="toctree-l3"><a href="#guide-for-template-designer">Guide for template designer</a></li>
  157. <ul>
  158. <li><a class="toctree-l4" href="#plugin-administration">Plugin administration</a></li>
  159. <li><a class="toctree-l4" href="#placeholder-system">Placeholder system</a></li>
  160. <li><a class="toctree-l4" href="#list-of-placeholders">List of placeholders</a></li>
  161. </ul>
  162. </ul>
  163. </li>
  164. <li class="">
  165. <a class="" href="../Release-Shaarli/">Release Shaarli</a>
  166. </li>
  167. <li class="">
  168. <a class="" href="../Versioning-and-Branches/">Versioning and Branches</a>
  169. </li>
  170. <li class="">
  171. <a class="" href="../Security/">Security</a>
  172. </li>
  173. <li class="">
  174. <a class="" href="../Static-analysis/">Static analysis</a>
  175. </li>
  176. <li class="">
  177. <a class="" href="../Theming/">Theming</a>
  178. </li>
  179. <li class="">
  180. <a class="" href="../Unit-tests/">Unit tests</a>
  181. </li>
  182. </ul>
  183. </li>
  184. <li class="toctree-l1">
  185. <span class="caption-text">About</span>
  186. <ul class="subnav">
  187. <li class="">
  188. <a class="" href="../FAQ/">FAQ</a>
  189. </li>
  190. <li class="">
  191. <a class="" href="../Community-&-Related-software/">Community & Related software</a>
  192. </li>
  193. </ul>
  194. </li>
  195. </ul>
  196. </div>
  197. &nbsp;
  198. </nav>
  199. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  200. <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
  201. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  202. <a href="..">Shaarli Documentation</a>
  203. </nav>
  204. <div class="wy-nav-content">
  205. <div class="rst-content">
  206. <div role="navigation" aria-label="breadcrumbs navigation">
  207. <ul class="wy-breadcrumbs">
  208. <li><a href="..">Docs</a> &raquo;</li>
  209. <li>Development &raquo;</li>
  210. <li>Plugin System</li>
  211. <li class="wy-breadcrumbs-aside">
  212. <a href="https://github.com/shaarli/Shaarli/edit/master/docs/Plugin-System.md"
  213. class="icon icon-github"> Edit on GitHub</a>
  214. </li>
  215. </ul>
  216. <hr/>
  217. </div>
  218. <div role="main">
  219. <div class="section">
  220. <p><a href="#developer-api"><strong>I am a developer.</strong> Developer API.</a></p>
  221. <p><a href="#guide-for-template-designer"><strong>I am a template designer.</strong> Guide for template designer.</a></p>
  222. <h2 id="developer-api">Developer API</h2>
  223. <h3 id="what-can-i-do-with-plugins">What can I do with plugins?</h3>
  224. <p>The plugin system let you:</p>
  225. <ul>
  226. <li>insert content into specific places across templates.</li>
  227. <li>alter data before templates rendering.</li>
  228. <li>alter data before saving new links.</li>
  229. </ul>
  230. <h3 id="how-can-i-create-a-plugin-for-shaarli">How can I create a plugin for Shaarli?</h3>
  231. <p>First, chose a plugin name, such as <code>demo_plugin</code>.</p>
  232. <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>
  233. <p>You should have the following tree view:</p>
  234. <pre><code>| index.php
  235. | plugins/
  236. |---| demo_plugin/
  237. | |---| demo_plugin.php
  238. </code></pre>
  239. <h3 id="plugin-initialization">Plugin initialization</h3>
  240. <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>
  241. <pre><code>&lt;plugin_name&gt;_init($conf)
  242. </code></pre>
  243. <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>
  244. <h3 id="understanding-hooks">Understanding hooks</h3>
  245. <p>A plugin is a set of functions. Each function will be triggered by the plugin system at certain point in Shaarli execution.</p>
  246. <p>These functions need to be named with this pattern:</p>
  247. <pre><code>hook_&lt;plugin_name&gt;_&lt;hook_name&gt;($data, $conf)
  248. </code></pre>
  249. <p>Parameters:</p>
  250. <ul>
  251. <li>data: see <a href="https://github.com/shaarli/Shaarli/wiki/Plugin-System#plugins-data">$data section</a></li>
  252. <li>conf: the <code>ConfigManager</code> instance.</li>
  253. </ul>
  254. <p>For exemple, if my plugin want to add data to the header, this function is needed:</p>
  255. <pre><code>hook_demo_plugin_render_header
  256. </code></pre>
  257. <p>If this function is declared, and the plugin enabled, it will be called every time Shaarli is rendering the header.</p>
  258. <h3 id="plugins-data">Plugin's data</h3>
  259. <h4 id="parameters">Parameters</h4>
  260. <p>Every hook function has a <code>$data</code> parameter. Its content differs for each hooks.</p>
  261. <p><strong>This parameter needs to be returned every time</strong>, otherwise data is lost.</p>
  262. <pre><code>return $data;
  263. </code></pre>
  264. <h4 id="filling-templates-placeholder">Filling templates placeholder</h4>
  265. <p>Template placeholders are displayed in template in specific places.</p>
  266. <p>RainTPL displays every element contained in the placeholder's array. These element can be added by plugins.</p>
  267. <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>
  268. <pre><code class="php">$data['top_placeholder'][] = 'My content';
  269. # OR
  270. array_push($data['top_placeholder'], 'My', 'content');
  271. return $data;
  272. </code></pre>
  273. <h4 id="data-manipulation">Data manipulation</h4>
  274. <p>When a page is displayed, every variable send to the template engine is passed to plugins before that in <code>$data</code>.</p>
  275. <p>The data contained by this array can be altered before template rendering.</p>
  276. <p>For exemple, in linklist, it is possible to alter every title:</p>
  277. <pre><code class="php">// mind the reference if you want $data to be altered
  278. foreach ($data['links'] as &amp;$value) {
  279. // String reverse every title.
  280. $value['title'] = strrev($value['title']);
  281. }
  282. return $data;
  283. </code></pre>
  284. <h3 id="metadata">Metadata</h3>
  285. <p>Every plugin needs a <code>&lt;plugin_name&gt;.meta</code> file, which is in fact an <code>.ini</code> file (<code>KEY="VALUE"</code>), to be listed in plugin administration.</p>
  286. <p>Each file contain two keys:</p>
  287. <ul>
  288. <li><code>description</code>: plugin description</li>
  289. <li><code>parameters</code>: user parameter names, separated by a <code>;</code>.</li>
  290. <li><code>parameter.&lt;PARAMETER_NAME&gt;</code>: add a text description the specified parameter.</li>
  291. </ul>
  292. <blockquote>
  293. <p>Note: In PHP, <code>parse_ini_file()</code> seems to want strings to be between by quotes <code>"</code> in the ini file.</p>
  294. </blockquote>
  295. <h3 id="its-not-working">It's not working!</h3>
  296. <p>Use <code>demo_plugin</code> as a functional example. It covers most of the plugin system features.</p>
  297. <p>If it's still not working, please <a href="https://github.com/shaarli/Shaarli/issues/new">open an issue</a>.</p>
  298. <h3 id="hooks">Hooks</h3>
  299. <table>
  300. <thead>
  301. <tr>
  302. <th>Hooks</th>
  303. <th align="center">Description</th>
  304. </tr>
  305. </thead>
  306. <tbody>
  307. <tr>
  308. <td><a href="#render_header">render_header</a></td>
  309. <td align="center">Allow plugin to add content in page headers.</td>
  310. </tr>
  311. <tr>
  312. <td><a href="#render_includes">render_includes</a></td>
  313. <td align="center">Allow plugin to include their own CSS files.</td>
  314. </tr>
  315. <tr>
  316. <td><a href="#render_footer">render_footer</a></td>
  317. <td align="center">Allow plugin to add content in page footer and include their own JS files.</td>
  318. </tr>
  319. <tr>
  320. <td><a href="#render_linklist">render_linklist</a></td>
  321. <td 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>
  322. </tr>
  323. <tr>
  324. <td><a href="#render_editlink">render_editlink</a></td>
  325. <td align="center">Allow to add fields in the form, or display elements.</td>
  326. </tr>
  327. <tr>
  328. <td><a href="#render_tools">render_tools</a></td>
  329. <td align="center">Allow to add content at the end of the page.</td>
  330. </tr>
  331. <tr>
  332. <td><a href="#render_picwall">render_picwall</a></td>
  333. <td align="center">Allow to add content at the top and bottom of the page.</td>
  334. </tr>
  335. <tr>
  336. <td><a href="#render_tagcloud">render_tagcloud</a></td>
  337. <td align="center">Allow to add content at the top and bottom of the page, and after all tags.</td>
  338. </tr>
  339. <tr>
  340. <td><a href="#render_taglist">render_taglist</a></td>
  341. <td align="center">Allow to add content at the top and bottom of the page, and after all tags.</td>
  342. </tr>
  343. <tr>
  344. <td><a href="#render_daily">render_daily</a></td>
  345. <td align="center">Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.</td>
  346. </tr>
  347. <tr>
  348. <td><a href="#render_feed">render_feed</a></td>
  349. <td align="center">Allow to do add tags in RSS and ATOM feeds.</td>
  350. </tr>
  351. <tr>
  352. <td><a href="#save_link">save_link</a></td>
  353. <td align="center">Allow to alter the link being saved in the datastore.</td>
  354. </tr>
  355. <tr>
  356. <td><a href="#delete_link">delete_link</a></td>
  357. <td align="center">Allow to do an action before a link is deleted from the datastore.</td>
  358. </tr>
  359. </tbody>
  360. </table>
  361. <h4 id="render_header">render_header</h4>
  362. <p>Triggered on every page.</p>
  363. <p>Allow plugin to add content in page headers.</p>
  364. <h5 id="data">Data</h5>
  365. <p><code>$data</code> is an array containing:</p>
  366. <ul>
  367. <li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
  368. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  369. </ul>
  370. <h5 id="template-placeholders">Template placeholders</h5>
  371. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  372. <p>List of placeholders:</p>
  373. <ul>
  374. <li><code>buttons_toolbar</code>: after the list of buttons in the header.</li>
  375. </ul>
  376. <p><img alt="buttons_toolbar_example" src="http://i.imgur.com/ssJUOrt.png" /></p>
  377. <ul>
  378. <li><code>fields_toolbar</code>: after search fields in the header.</li>
  379. </ul>
  380. <blockquote>
  381. <p>Note: This will only be called in linklist.</p>
  382. </blockquote>
  383. <p><img alt="fields_toolbar_example" src="http://i.imgur.com/3GMifI2.png" /></p>
  384. <h4 id="render_includes">render_includes</h4>
  385. <p>Triggered on every page.</p>
  386. <p>Allow plugin to include their own CSS files.</p>
  387. <h5 id="data_1">Data</h5>
  388. <p><code>$data</code> is an array containing:</p>
  389. <ul>
  390. <li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
  391. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  392. </ul>
  393. <h5 id="template-placeholders_1">Template placeholders</h5>
  394. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  395. <p>List of placeholders:</p>
  396. <ul>
  397. <li><code>css_files</code>: called after loading default CSS.</li>
  398. </ul>
  399. <blockquote>
  400. <p>Note: only add the path of the CSS file. E.g: <code>plugins/demo_plugin/custom_demo.css</code>.</p>
  401. </blockquote>
  402. <h4 id="render_footer">render_footer</h4>
  403. <p>Triggered on every page.</p>
  404. <p>Allow plugin to add content in page footer and include their own JS files.</p>
  405. <h5 id="data_2">Data</h5>
  406. <p><code>$data</code> is an array containing:</p>
  407. <ul>
  408. <li><code>_PAGE_</code>: current target page (eg: <code>linklist</code>, <code>picwall</code>, etc.).</li>
  409. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  410. </ul>
  411. <h5 id="template-placeholders_2">Template placeholders</h5>
  412. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  413. <p>List of placeholders:</p>
  414. <ul>
  415. <li><code>text</code>: called after the end of the footer text.</li>
  416. <li><code>endofpage</code>: called at the end of the page.</li>
  417. </ul>
  418. <p><img alt="text_example" src="http://i.imgur.com/L5S2YEH.png" /></p>
  419. <ul>
  420. <li><code>js_files</code>: called at the end of the page, to include custom JS scripts.</li>
  421. </ul>
  422. <blockquote>
  423. <p>Note: only add the path of the JS file. E.g: <code>plugins/demo_plugin/custom_demo.js</code>.</p>
  424. </blockquote>
  425. <h4 id="render_linklist">render_linklist</h4>
  426. <p>Triggered when <code>linklist</code> is displayed (list of links, permalink, search, tag filtered, etc.).</p>
  427. <p>It allows to add content at the begining and end of the page, after every link displayed and to alter link data.</p>
  428. <h5 id="data_3">Data</h5>
  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>
  434. <h5 id="template-placeholders_3">Template placeholders</h5>
  435. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  436. <p>List of placeholders:</p>
  437. <ul>
  438. <li><code>action_plugin</code>: next to the button "private only" at the top and bottom of the page.</li>
  439. </ul>
  440. <p><img alt="action_plugin_example" src="http://i.imgur.com/Q12PWg0.png" /></p>
  441. <ul>
  442. <li><code>link_plugin</code>: for every link, between permalink and link URL.</li>
  443. </ul>
  444. <p><img alt="link_plugin_example" src="http://i.imgur.com/3oDPhWx.png" /></p>
  445. <ul>
  446. <li><code>plugin_start_zone</code>: before displaying the template content.</li>
  447. </ul>
  448. <p><img alt="plugin_start_zone_example" src="http://i.imgur.com/OVBkGy3.png" /></p>
  449. <ul>
  450. <li><code>plugin_end_zone</code>: after displaying the template content.</li>
  451. </ul>
  452. <p><img alt="plugin_end_zone_example" src="http://i.imgur.com/6IoRuop.png" /></p>
  453. <h4 id="render_editlink">render_editlink</h4>
  454. <p>Triggered when the link edition form is displayed.</p>
  455. <p>Allow to add fields in the form, or display elements.</p>
  456. <h5 id="data_4">Data</h5>
  457. <p><code>$data</code> is an array containing:</p>
  458. <ul>
  459. <li>All templates data.</li>
  460. </ul>
  461. <h5 id="template-placeholders_4">Template placeholders</h5>
  462. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  463. <p>List of placeholders:</p>
  464. <ul>
  465. <li><code>edit_link_plugin</code>: after tags field.</li>
  466. </ul>
  467. <p><img alt="edit_link_plugin_example" src="http://i.imgur.com/5u17Ens.png" /></p>
  468. <h4 id="render_tools">render_tools</h4>
  469. <p>Triggered when the "tools" page is displayed.</p>
  470. <p>Allow to add content at the end of the page.</p>
  471. <h5 id="data_5">Data</h5>
  472. <p><code>$data</code> is an array containing:</p>
  473. <ul>
  474. <li>All templates data.</li>
  475. </ul>
  476. <h5 id="template-placeholders_5">Template placeholders</h5>
  477. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  478. <p>List of placeholders:</p>
  479. <ul>
  480. <li><code>tools_plugin</code>: at the end of the page.</li>
  481. </ul>
  482. <p><img alt="tools_plugin_example" src="http://i.imgur.com/Bqhu9oQ.png" /></p>
  483. <h4 id="render_picwall">render_picwall</h4>
  484. <p>Triggered when picwall is displayed.</p>
  485. <p>Allow to add content at the top and bottom of the page.</p>
  486. <h5 id="data_6">Data</h5>
  487. <p><code>$data</code> is an array containing:</p>
  488. <ul>
  489. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  490. <li>All templates data.</li>
  491. </ul>
  492. <h5 id="template-placeholders_6">Template placeholders</h5>
  493. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  494. <p>List of placeholders:</p>
  495. <ul>
  496. <li>
  497. <p><code>plugin_start_zone</code>: before displaying the template content.</p>
  498. </li>
  499. <li>
  500. <p><code>plugin_end_zone</code>: after displaying the template content.</p>
  501. </li>
  502. </ul>
  503. <p><img alt="plugin_start_end_zone_example" src="http://i.imgur.com/tVTQFER.png" /></p>
  504. <h4 id="render_tagcloud">render_tagcloud</h4>
  505. <p>Triggered when tagcloud is displayed.</p>
  506. <p>Allow to add content at the top and bottom of the page.</p>
  507. <h5 id="data_7">Data</h5>
  508. <p><code>$data</code> is an array containing:</p>
  509. <ul>
  510. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  511. <li>All templates data.</li>
  512. </ul>
  513. <h5 id="template-placeholders_7">Template placeholders</h5>
  514. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  515. <p>List of placeholders:</p>
  516. <ul>
  517. <li>
  518. <p><code>plugin_start_zone</code>: before displaying the template content.</p>
  519. </li>
  520. <li>
  521. <p><code>plugin_end_zone</code>: after displaying the template content.</p>
  522. </li>
  523. </ul>
  524. <p>For each tag, the following placeholder can be used:</p>
  525. <ul>
  526. <li><code>tag_plugin</code>: after each tag</li>
  527. </ul>
  528. <p><img alt="plugin_start_end_zone_example" src="http://i.imgur.com/vHmyT3a.png" /></p>
  529. <h4 id="render_taglist">render_taglist</h4>
  530. <p>Triggered when taglist is displayed.</p>
  531. <p>Allow to add content at the top and bottom of the page.</p>
  532. <h5 id="data_8">Data</h5>
  533. <p><code>$data</code> is an array containing:</p>
  534. <ul>
  535. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  536. <li>All templates data.</li>
  537. </ul>
  538. <h5 id="template-placeholders_8">Template placeholders</h5>
  539. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  540. <p>List of placeholders:</p>
  541. <ul>
  542. <li>
  543. <p><code>plugin_start_zone</code>: before displaying the template content.</p>
  544. </li>
  545. <li>
  546. <p><code>plugin_end_zone</code>: after displaying the template content.</p>
  547. </li>
  548. </ul>
  549. <p>For each tag, the following placeholder can be used:</p>
  550. <ul>
  551. <li><code>tag_plugin</code>: after each tag</li>
  552. </ul>
  553. <h4 id="render_daily">render_daily</h4>
  554. <p>Triggered when tagcloud is displayed.</p>
  555. <p>Allow to add content at the top and bottom of the page, the bottom of each link and to alter data.</p>
  556. <h5 id="data_9">Data</h5>
  557. <p><code>$data</code> is an array containing:</p>
  558. <ul>
  559. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  560. <li>All templates data, including links.</li>
  561. </ul>
  562. <h5 id="template-placeholders_9">Template placeholders</h5>
  563. <p>Items can be displayed in templates by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  564. <p>List of placeholders:</p>
  565. <ul>
  566. <li><code>link_plugin</code>: used at bottom of each link.</li>
  567. </ul>
  568. <p><img alt="link_plugin_example" src="http://i.imgur.com/hzhMfSZ.png" /></p>
  569. <ul>
  570. <li>
  571. <p><code>plugin_start_zone</code>: before displaying the template content.</p>
  572. </li>
  573. <li>
  574. <p><code>plugin_end_zone</code>: after displaying the template content.</p>
  575. </li>
  576. </ul>
  577. <h4 id="render_feed">render_feed</h4>
  578. <p>Triggered when the ATOM or RSS feed is displayed.</p>
  579. <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>
  580. <h5 id="data_10">Data</h5>
  581. <p><code>$data</code> is an array containing:</p>
  582. <ul>
  583. <li><code>_LOGGEDIN_</code>: true if user is logged in, false otherwise.</li>
  584. <li><code>_PAGE_</code>: containing either <code>rss</code> or <code>atom</code>.</li>
  585. <li>All templates data, including links.</li>
  586. </ul>
  587. <h5 id="template-placeholders_10">Template placeholders</h5>
  588. <p>Tags can be added in feeds by adding an entry in <code>$data['&lt;placeholder&gt;']</code> array.</p>
  589. <p>List of placeholders:</p>
  590. <ul>
  591. <li><code>feed_plugins_header</code>: used as a header tag in the feed.</li>
  592. </ul>
  593. <p>For each links:</p>
  594. <ul>
  595. <li><code>feed_plugins</code>: additional tag for every link entry.</li>
  596. </ul>
  597. <h4 id="save_link">save_link</h4>
  598. <p>Triggered when a link is save (new link or edit).</p>
  599. <p>Allow to alter the link being saved in the datastore.</p>
  600. <h5 id="data_11">Data</h5>
  601. <p><code>$data</code> is an array containing the link being saved:</p>
  602. <ul>
  603. <li>id</li>
  604. <li>title</li>
  605. <li>url</li>
  606. <li>shorturl</li>
  607. <li>description</li>
  608. <li>private</li>
  609. <li>tags</li>
  610. <li>created</li>
  611. <li>updated</li>
  612. </ul>
  613. <h4 id="delete_link">delete_link</h4>
  614. <p>Triggered when a link is deleted.</p>
  615. <p>Allow to execute any action before the link is actually removed from the datastore</p>
  616. <h5 id="data_12">Data</h5>
  617. <p><code>$data</code> is an array containing the link being saved:</p>
  618. <ul>
  619. <li>id</li>
  620. <li>title</li>
  621. <li>url</li>
  622. <li>shorturl</li>
  623. <li>description</li>
  624. <li>private</li>
  625. <li>tags</li>
  626. <li>created</li>
  627. <li>updated</li>
  628. </ul>
  629. <h2 id="guide-for-template-designer">Guide for template designer</h2>
  630. <h3 id="plugin-administration">Plugin administration</h3>
  631. <p>Your theme must include a plugin administration page: <code>pluginsadmin.html</code>.</p>
  632. <blockquote>
  633. <p>Note: repo's template link needs to be added when the PR is merged.</p>
  634. </blockquote>
  635. <p>Use the default one as an example.</p>
  636. <p>Aside from classic RainTPL loops, plugins order is handle by JavaScript. You can just include <code>plugin_admin.js</code>, only if:</p>
  637. <ul>
  638. <li>you're using a table.</li>
  639. <li>you call orderUp() and orderUp() onclick on arrows.</li>
  640. <li>you add data-line and data-order to your rows.</li>
  641. </ul>
  642. <p>Otherwise, you can use your own JS as long as this field is send by the form:</p>
  643. <p><input type="hidden" name="order_{$key}" value="{$counter}"></p>
  644. <h3 id="placeholder-system">Placeholder system</h3>
  645. <p>In order to make plugins work with every custom themes, you need to add variable placeholder in your templates. </p>
  646. <p>It's a RainTPL loop like this:</p>
  647. <pre><code>{loop="$plugin_variable"}
  648. {$value}
  649. {/loop}
  650. </code></pre>
  651. <p>You should enable <code>demo_plugin</code> for testing purpose, since it uses every placeholder available.</p>
  652. <h3 id="list-of-placeholders">List of placeholders</h3>
  653. <p><strong>page.header.html</strong></p>
  654. <p>At the end of the menu:</p>
  655. <pre><code>{loop="$plugins_header.buttons_toolbar"}
  656. {$value}
  657. {/loop}
  658. </code></pre>
  659. <p>At the end of file, before clearing floating blocks:</p>
  660. <pre><code>{if="!empty($plugin_errors) &amp;&amp; isLoggedIn()"}
  661. &lt;ul class="errors"&gt;
  662. {loop="plugin_errors"}
  663. &lt;li&gt;{$value}&lt;/li&gt;
  664. {/loop}
  665. &lt;/ul&gt;
  666. {/if}
  667. </code></pre>
  668. <p><strong>includes.html</strong></p>
  669. <p>At the end of the file:</p>
  670. <pre><code class="html">{loop=&quot;$plugins_includes.css_files&quot;}
  671. &lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;{$value}#&quot;/&gt;
  672. {/loop}
  673. </code></pre>
  674. <p><strong>page.footer.html</strong></p>
  675. <p>At the end of your footer notes:</p>
  676. <pre><code class="html">{loop=&quot;$plugins_footer.text&quot;}
  677. {$value}
  678. {/loop}
  679. </code></pre>
  680. <p>At the end of file:</p>
  681. <pre><code class="html">{loop=&quot;$plugins_footer.js_files&quot;}
  682. &lt;script src=&quot;{$value}#&quot;&gt;&lt;/script&gt;
  683. {/loop}
  684. </code></pre>
  685. <p><strong>linklist.html</strong></p>
  686. <p>After search fields:</p>
  687. <pre><code class="html">{loop=&quot;$plugins_header.fields_toolbar&quot;}
  688. {$value}
  689. {/loop}
  690. </code></pre>
  691. <p>Before displaying the link list (after paging):</p>
  692. <pre><code class="html">{loop=&quot;$plugin_start_zone&quot;}
  693. {$value}
  694. {/loop}
  695. </code></pre>
  696. <p>For every links (icons):</p>
  697. <pre><code class="html">{loop=&quot;$value.link_plugin&quot;}
  698. &lt;span&gt;{$value}&lt;/span&gt;
  699. {/loop}
  700. </code></pre>
  701. <p>Before end paging:</p>
  702. <pre><code class="html">{loop=&quot;$plugin_end_zone&quot;}
  703. {$value}
  704. {/loop}
  705. </code></pre>
  706. <p><strong>linklist.paging.html</strong></p>
  707. <p>After the "private only" icon:</p>
  708. <pre><code class="html">{loop=&quot;$action_plugin&quot;}
  709. {$value}
  710. {/loop}
  711. </code></pre>
  712. <p><strong>editlink.html</strong></p>
  713. <p>After tags field:</p>
  714. <pre><code class="html">{loop=&quot;$edit_link_plugin&quot;}
  715. {$value}
  716. {/loop}
  717. </code></pre>
  718. <p><strong>tools.html</strong></p>
  719. <p>After the last tool:</p>
  720. <pre><code class="html">{loop=&quot;$tools_plugin&quot;}
  721. {$value}
  722. {/loop}
  723. </code></pre>
  724. <p><strong>picwall.html</strong></p>
  725. <p>Top:</p>
  726. <pre><code class="html">&lt;div id=&quot;plugin_zone_start_picwall&quot; class=&quot;plugin_zone&quot;&gt;
  727. {loop=&quot;$plugin_start_zone&quot;}
  728. {$value}
  729. {/loop}
  730. &lt;/div&gt;
  731. </code></pre>
  732. <p>Bottom:</p>
  733. <pre><code class="html">&lt;div id=&quot;plugin_zone_end_picwall&quot; class=&quot;plugin_zone&quot;&gt;
  734. {loop=&quot;$plugin_end_zone&quot;}
  735. {$value}
  736. {/loop}
  737. &lt;/div&gt;
  738. </code></pre>
  739. <p><strong>tagcloud.html</strong></p>
  740. <p>Top:</p>
  741. <pre><code class="html"> &lt;div id=&quot;plugin_zone_start_tagcloud&quot; class=&quot;plugin_zone&quot;&gt;
  742. {loop=&quot;$plugin_start_zone&quot;}
  743. {$value}
  744. {/loop}
  745. &lt;/div&gt;
  746. </code></pre>
  747. <p>Bottom:</p>
  748. <pre><code class="html"> &lt;div id=&quot;plugin_zone_end_tagcloud&quot; class=&quot;plugin_zone&quot;&gt;
  749. {loop=&quot;$plugin_end_zone&quot;}
  750. {$value}
  751. {/loop}
  752. &lt;/div&gt;
  753. </code></pre>
  754. <p><strong>daily.html</strong></p>
  755. <p>Top:</p>
  756. <pre><code class="html">&lt;div id=&quot;plugin_zone_start_picwall&quot; class=&quot;plugin_zone&quot;&gt;
  757. {loop=&quot;$plugin_start_zone&quot;}
  758. {$value}
  759. {/loop}
  760. &lt;/div&gt;
  761. </code></pre>
  762. <p>After every link:</p>
  763. <pre><code class="html">&lt;div class=&quot;dailyEntryFooter&quot;&gt;
  764. {loop=&quot;$link.link_plugin&quot;}
  765. {$value}
  766. {/loop}
  767. &lt;/div&gt;
  768. </code></pre>
  769. <p>Bottom:</p>
  770. <pre><code class="html">&lt;div id=&quot;plugin_zone_end_picwall&quot; class=&quot;plugin_zone&quot;&gt;
  771. {loop=&quot;$plugin_end_zone&quot;}
  772. {$value}
  773. {/loop}
  774. &lt;/div&gt;
  775. </code></pre>
  776. <p><strong>feed.atom.xml</strong> and <strong>feed.rss.xml</strong>:</p>
  777. <p>In headers tags section:</p>
  778. <pre><code class="xml">{loop=&quot;$feed_plugins_header&quot;}
  779. {$value}
  780. {/loop}
  781. </code></pre>
  782. <p>After each entry:</p>
  783. <pre><code class="xml">{loop=&quot;$value.feed_plugins&quot;}
  784. {$value}
  785. {/loop}
  786. </code></pre>
  787. </div>
  788. </div>
  789. <footer>
  790. <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
  791. <a href="../Release-Shaarli/" class="btn btn-neutral float-right" title="Release Shaarli">Next <span class="icon icon-circle-arrow-right"></span></a>
  792. <a href="../3rd-party-libraries/" class="btn btn-neutral" title="3rd party libraries"><span class="icon icon-circle-arrow-left"></span> Previous</a>
  793. </div>
  794. <hr/>
  795. <div role="contentinfo">
  796. <!-- Copyright etc -->
  797. </div>
  798. Built with <a href="http://www.mkdocs.org">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
  799. </footer>
  800. </div>
  801. </div>
  802. </section>
  803. </div>
  804. <div class="rst-versions" role="note" style="cursor: pointer">
  805. <span class="rst-current-version" data-toggle="rst-current-version">
  806. <a href="https://github.com/shaarli/Shaarli" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
  807. <span><a href="../3rd-party-libraries/" style="color: #fcfcfc;">&laquo; Previous</a></span>
  808. <span style="margin-left: 15px"><a href="../Release-Shaarli/" style="color: #fcfcfc">Next &raquo;</a></span>
  809. </span>
  810. </div>
  811. <script src="../js/theme.js"></script>
  812. </body>
  813. </html>