CINXE.COM
Plugins - Gancio
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <title>Plugins - Gancio</title> <link href="https://github.com/lesion" rel="me"> <link href="eventi@cisti.org" rel="me"> <link rel="webmention" href="https://webmention.io/gancio.org/webmention" /> <link rel="pingback" href="https://webmention.io/gancio.org/xmlrpc" /> <link rel="shortcut icon" href="https://gancio.org/favicon.ico" type="image/x-icon"> <link rel="stylesheet" href="https://gancio.org/assets/css/just-the-docs-default.css"> <link rel="stylesheet" href="https://gancio.org/assets/css/premonition.css"> <script type="text/javascript" src="https://gancio.org/assets/js/vendor/lunr.min.js"></script> <script type="text/javascript" src="https://gancio.org/assets/js/just-the-docs.js"></script> <script src="https://gancio.org/assets/js/jquery-3.3.1.min.js"></script> <link rel="stylesheet" href="https://gancio.org/assets/css/jquery.fancybox.min.css"> <script src="https://gancio.org/assets/js/jquery.fancybox.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Begin Jekyll SEO tag v2.8.0 --> <title>Plugins | Gancio</title> <meta name="generator" content="Jekyll v4.3.2" /> <meta property="og:title" content="Plugins" /> <meta property="og:locale" content="en_US" /> <meta name="description" content="A shared agenda for local communities with AP support" /> <meta property="og:description" content="A shared agenda for local communities with AP support" /> <link rel="canonical" href="https://gancio.org/dev/plugins" /> <meta property="og:url" content="https://gancio.org/dev/plugins" /> <meta property="og:site_name" content="Gancio" /> <meta property="og:type" content="website" /> <meta name="twitter:card" content="summary" /> <meta property="twitter:title" content="Plugins" /> <script type="application/ld+json"> {"@context":"https://schema.org","@type":"WebPage","description":"A shared agenda for local communities with AP support","headline":"Plugins","url":"https://gancio.org/dev/plugins"}</script> <!-- End Jekyll SEO tag --> </head> <body> <a class="skip-to-main" href="#main-content">Skip to main content</a> <svg xmlns="http://www.w3.org/2000/svg" class="d-none"> <symbol id="svg-link" viewBox="0 0 24 24"> <title>Link</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"> <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path> </svg> </symbol> <symbol id="svg-menu" viewBox="0 0 24 24"> <title>Menu</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-menu"> <line x1="3" y1="12" x2="21" y2="12"></line><line x1="3" y1="6" x2="21" y2="6"></line><line x1="3" y1="18" x2="21" y2="18"></line> </svg> </symbol> <symbol id="svg-arrow-right" viewBox="0 0 24 24"> <title>Expand</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-chevron-right"> <polyline points="9 18 15 12 9 6"></polyline> </svg> </symbol> <!-- Feather. MIT License: https://github.com/feathericons/feather/blob/master/LICENSE --> <symbol id="svg-external-link" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"> <title id="svg-external-link-title">(external link)</title> <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line> </symbol> <symbol id="svg-doc" viewBox="0 0 24 24"> <title>Document</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file"> <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"></path><polyline points="13 2 13 9 20 9"></polyline> </svg> </symbol> <symbol id="svg-search" viewBox="0 0 24 24"> <title>Search</title> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"> <circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line> </svg> </symbol> <!-- Bootstrap Icons. MIT License: https://github.com/twbs/icons/blob/main/LICENSE.md --> <symbol id="svg-copy" viewBox="0 0 16 16"> <title>Copy</title> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard" viewBox="0 0 16 16"> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/> <path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/> </svg> </symbol> <symbol id="svg-copied" viewBox="0 0 16 16"> <title>Copied</title> <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clipboard-check-fill" viewBox="0 0 16 16"> <path d="M6.5 0A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3Zm3 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3Z"/> <path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1A2.5 2.5 0 0 1 9.5 5h-3A2.5 2.5 0 0 1 4 2.5v-1Zm6.854 7.354-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 0 1 .708-.708L7.5 10.793l2.646-2.647a.5.5 0 0 1 .708.708Z"/> </svg> </symbol> </svg> <div class="side-bar"> <div class="site-header" role="banner"> <a href="/" class="site-title lh-tight"> Gancio </a> <button id="menu-button" class="site-button btn-reset" aria-label="Toggle menu" aria-pressed="false"> <svg viewBox="0 0 24 24" class="icon" aria-hidden="true"><use xlink:href="#svg-menu"></use></svg> </button> </div> <nav aria-label="Main" id="site-nav" class="site-nav"> <ul class="nav-list"><li class="nav-list-item"><a href="/" class="nav-list-link">Home</a></li><li class="nav-list-item"><button class="nav-list-expander btn-reset" aria-label="toggle items in Usage category" aria-pressed="false"> <svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg> </button><a href="/usage" class="nav-list-link">Usage</a><ul class="nav-list"><li class="nav-list-item"><a href="/usage/embed" class="nav-list-link">Embed events in webpages</a></li><li class="nav-list-item"><a href="/usage/moderation" class="nav-list-link">Moderation</a></li><li class="nav-list-item"><a href="/usage/users" class="nav-list-link">Users</a></li><li class="nav-list-item"><a href="/usage/cli" class="nav-list-link">CLI</a></li><li class="nav-list-item"><a href="/usage/federation" class="nav-list-link">Federation</a></li><li class="nav-list-item"><a href="/usage/plugins" class="nav-list-link">Plugins</a></li><li class="nav-list-item"><a href="/usage/custom_css" class="nav-list-link">Custom CSS</a></li><li class="nav-list-item"><a href="/usage/custom_js" class="nav-list-link">Custom Javascript</a></li></ul></li><li class="nav-list-item"><a href="/screenshot" class="nav-list-link">Screenshots</a></li><li class="nav-list-item"><button class="nav-list-expander btn-reset" aria-label="toggle items in Install category" aria-pressed="false"> <svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg> </button><a href="/install" class="nav-list-link">Install</a><ul class="nav-list"><li class="nav-list-item"><a href="/install/debian" class="nav-list-link">Debian</a></li><li class="nav-list-item"><a href="/install/nixos" class="nav-list-link">NixOS</a></li><li class="nav-list-item"><a href="/install/docker" class="nav-list-link">Docker</a></li><li class="nav-list-item"><a href="/install/backup" class="nav-list-link">Backup</a></li><li class="nav-list-item"><a href="/install/config" class="nav-list-link">Configuration</a></li><li class="nav-list-item"><a href="/install/nominatim" class="nav-list-link">Nominatim</a></li><li class="nav-list-item"><a href="/install/nginx" class="nav-list-link">Nginx setup</a></li></ul></li><li class="nav-list-item"><button class="nav-list-expander btn-reset" aria-label="toggle items in Hacking category" aria-pressed="false"> <svg viewBox="0 0 24 24" aria-hidden="true"><use xlink:href="#svg-arrow-right"></use></svg> </button><a href="/dev" class="nav-list-link">Hacking</a><ul class="nav-list"><li class="nav-list-item"><a href="/dev/structure" class="nav-list-link">Project Structure</a></li><li class="nav-list-item"><a href="/dev/plugins" class="nav-list-link">Plugins</a></li><li class="nav-list-item"><a href="/dev/oauth" class="nav-list-link">OAuth</a></li><li class="nav-list-item"><a href="/dev/locales" class="nav-list-link">Internationalization</a></li><li class="nav-list-item"><a href="/dev/api" class="nav-list-link">API</a></li></ul></li><li class="nav-list-item"><a href="/contribute" class="nav-list-link">Contribute</a></li><li class="nav-list-item"><a href="/instances" class="nav-list-link">Instances</a></li><li class="nav-list-item"><a href="/about" class="nav-list-link">About</a></li><li class="nav-list-item"><a href="/contacts" class="nav-list-link">Contacts</a></li><li class="nav-list-item"><a href="/federation" class="nav-list-link">Federation</a></li><li class="nav-list-item"><a href="/changelog" class="nav-list-link">Changelog</a></li></ul> </nav> <footer class="site-footer"> This site uses <a href="https://github.com/just-the-docs/just-the-docs">Just the Docs</a>, a documentation theme for Jekyll. </footer> </div> <div class="main" id="top"> <div id="main-header" class="main-header"> <div class="search" role="search"> <div class="search-input-wrap"> <input type="text" id="search-input" class="search-input" tabindex="0" placeholder="Search Gancio" aria-label="Search Gancio" autocomplete="off"> <label for="search-input" class="search-label"><svg viewBox="0 0 24 24" class="search-icon"><use xlink:href="#svg-search"></use></svg></label> </div> <div id="search-results" class="search-results"></div> </div> <nav aria-label="Auxiliary" class="aux-nav"> <ul class="aux-nav-list"> <li class="aux-nav-list-item"> <a href="https://framagit.org/les/gancio" class="site-button" > Source </a> </li> <li class="aux-nav-list-item"> <a href="https://mastodon.cisti.org/@gancio" class="site-button" > @gancio@mastodon.cisti.org </a> </li> </ul> </nav> </div> <div class="main-content-wrap"> <nav aria-label="Breadcrumb" class="breadcrumb-nav"> <ol class="breadcrumb-nav-list"> <li class="breadcrumb-nav-list-item"><a href="/dev">Hacking</a></li> <li class="breadcrumb-nav-list-item"><span>Plugins</span></li> </ol> </nav> <div id="main-content" class="main-content"> <main> <h2 id="plugins"> <a href="#plugins" class="anchor-heading" aria-labelledby="plugins"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Plugins </h2> <p>Since <strong>v.1.2.2</strong> you can write your own plugin that react to event related action (create,update,delete).</p> <div class="premonition info"> <i class="premonition pn-info"></i> <div class="content"> <p class="header">What this is useful for?</p><ul> <li>Do you want to create a post in your wordpress website each time an event is published? <a href="http://wp-api.org/node-wpapi/using-the-client/#creating-posts">hint</a></li> <li>Do you want to send a summary notification of daily events via mail?</li> <li>Notify a telegram group or share via twitter?</li> </ul> <p><a href="/contacts"><strong><u>Please share your plugins or your needs</u></strong></a></p> </div> </div> <h2 id="example"> <a href="#example" class="anchor-heading" aria-labelledby="example"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Example </h2> <p>Here is a complete example of plugins feature: <a href="https://framagit.org/les/gancio/-/blob/master/plugins/gancioPluginExample.js">https://framagit.org/les/gancio/-/blob/master/plugins/gancioPluginExample.js</a> .</p> <h2 id="basic-plugin-syntax"> <a href="#basic-plugin-syntax" class="anchor-heading" aria-labelledby="basic-plugin-syntax"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Basic plugin syntax </h2> <p>A plugin is essentially an <code class="language-plaintext highlighter-rouge">index.js</code> file inside its own path in <code class="language-plaintext highlighter-rouge">./plugins</code>, e.g. <code class="language-plaintext highlighter-rouge">./plugins/my-example-plugin/index.js</code></p> <div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="p">{</span> <span class="p">}</span> </code></pre></div></div> <p>Plugins should be inside <code class="language-plaintext highlighter-rouge">./plugins</code> directory but you can specify another location using <a href="https://gancio.org/install/config#plugins-path"><code class="language-plaintext highlighter-rouge">plugins_path</code></a> configuration.</p> <h2 id="plugin-details"> <a href="#plugin-details" class="anchor-heading" aria-labelledby="plugin-details"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Plugin details </h2> <p>A plugins <strong>MUST</strong> expose a <code class="language-plaintext highlighter-rouge">configuration</code> key where to specify its details:</p> <div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">module</span><span class="p">.</span><span class="nx">exports</span> <span class="o">=</span> <span class="p">{</span> <span class="na">configuration</span><span class="p">:</span> <span class="p">{</span> <span class="na">name</span><span class="p">:</span> <span class="dl">'</span><span class="s1">Example</span><span class="dl">'</span><span class="p">,</span> <span class="na">author</span><span class="p">:</span> <span class="dl">'</span><span class="s1">lesion</span><span class="dl">'</span><span class="p">,</span> <span class="na">url</span><span class="p">:</span> <span class="dl">'</span><span class="s1">https://framagit.org/les/gancio/plugins/gancioPluginExample.js</span><span class="dl">'</span><span class="p">,</span> <span class="na">description</span><span class="p">:</span> <span class="dl">'</span><span class="s1">Example plugin</span><span class="dl">'</span><span class="p">,</span> <span class="na">settings</span><span class="p">:</span> <span class="p">{</span> <span class="na">my_plugin_string_setting</span><span class="p">:</span> <span class="p">{</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">TEXT</span><span class="dl">'</span><span class="p">,</span> <span class="na">description</span><span class="p">:</span> <span class="dl">'</span><span class="s1">My plugin string setting</span><span class="dl">'</span><span class="p">,</span> <span class="na">required</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="na">hint</span><span class="p">:</span> <span class="dl">'</span><span class="s1">My plugin setting support <strong>html too</strong></span><span class="dl">'</span> <span class="p">},</span> <span class="na">enable_this_feature_in_my_plugin</span><span class="p">:</span> <span class="p">{</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">CHECK</span><span class="dl">'</span><span class="p">,</span> <span class="na">description</span><span class="p">:</span> <span class="dl">'</span><span class="s1">My plugin best feature</span><span class="dl">'</span><span class="p">,</span> <span class="na">required</span><span class="p">:</span> <span class="kc">true</span><span class="p">,</span> <span class="na">hint</span><span class="p">:</span> <span class="dl">'</span><span class="s1">This feature is super dupe, enable it!</span><span class="dl">'</span> <span class="p">},</span> <span class="na">min_post</span><span class="p">:</span> <span class="p">{</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">NUMBER</span><span class="dl">'</span><span class="p">,</span> <span class="na">description</span><span class="p">:</span> <span class="dl">'</span><span class="s1">it supports number too</span><span class="dl">'</span> <span class="p">},</span> <span class="na">my_default_language</span><span class="p">:</span> <span class="p">{</span> <span class="na">description</span><span class="p">:</span> <span class="dl">'</span><span class="s1">My default language</span><span class="dl">'</span><span class="p">,</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">LIST</span><span class="dl">'</span><span class="p">,</span> <span class="na">items</span><span class="p">:</span> <span class="p">[</span><span class="dl">'</span><span class="s1">it</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">en</span><span class="dl">'</span><span class="p">,</span> <span class="dl">'</span><span class="s1">fr</span><span class="dl">'</span><span class="p">]</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> <span class="p">}</span> </code></pre></div></div> <p><a href="/assets/plugins/settings.png" data-fancybox="group" data-caption="Home"><img src="/assets/plugins/settings.png" alt="/assets/plugins/settings.png" /></a></p> <h2 id="load-a-plugin"> <a href="#load-a-plugin" class="anchor-heading" aria-labelledby="load-a-plugin"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Load a plugin </h2> <p>When a plugin is enabled by an administrator, Gancio will call the <code class="language-plaintext highlighter-rouge">load</code> method if specified:</p> <div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nf">load </span><span class="p">({</span> <span class="na">settings</span><span class="p">:</span> <span class="nx">gancio_settings</span><span class="p">,</span> <span class="nx">db</span><span class="p">,</span> <span class="nx">helpers</span><span class="p">,</span> <span class="nx">log</span><span class="p">},</span> <span class="nx">settings</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// access to your plugin local settings</span> <span class="nx">console</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="dl">'</span><span class="s1">Your local settings are in </span><span class="dl">'</span><span class="p">,</span> <span class="nx">settings</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="s2">`For example, you can access to your default language setting by using </span><span class="p">${</span><span class="nx">settings</span><span class="p">.</span><span class="nx">my_default_language</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span> <span class="c1">// access to gancio settings</span> <span class="nx">console</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="s2">`Gancio settings are in </span><span class="p">${</span><span class="nx">gancio_settings</span><span class="p">}</span><span class="s2">, e.g. </span><span class="p">${</span><span class="nx">gancio</span><span class="p">.</span><span class="nx">settings</span><span class="p">.</span><span class="nx">baseurl</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span> <span class="c1">// log something</span> <span class="nx">log</span><span class="p">.</span><span class="nf">warn</span><span class="p">(</span><span class="dl">'</span><span class="s1">This is a log entry from my example plugin</span><span class="dl">'</span><span class="p">)</span> <span class="c1">// use the DB (since 1.6.14)</span> <span class="nx">console</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="nx">db</span><span class="p">.</span><span class="nx">models</span><span class="p">.</span><span class="nf">findAll</span><span class="p">())</span> <span class="nx">console</span><span class="p">.</span><span class="nf">info</span><span class="p">(</span><span class="nx">db</span><span class="p">.</span><span class="nf">query</span><span class="p">(</span><span class="dl">'</span><span class="s1">CREATE TABLE IF NOT EXISTS myPluginTable</span><span class="dl">'</span><span class="p">))</span> <span class="p">}</span> </code></pre></div></div> <h2 id="expose-an-api-since-164"> <a href="#expose-an-api-since-164" class="anchor-heading" aria-labelledby="expose-an-api-since-164"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Expose an API <span class="label label-yellow">since 1.6.4</span> </h2> <p>Plugins could have public HTTP endpoints by exposing an express Router in routeAPI object.</p> <div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">express</span> <span class="o">=</span> <span class="nf">require</span><span class="p">(</span><span class="dl">'</span><span class="s1">express</span><span class="dl">'</span><span class="p">)</span> <span class="kd">const</span> <span class="nx">routeAPI</span> <span class="o">=</span> <span class="nx">express</span><span class="p">.</span><span class="nc">Router</span><span class="p">()</span> <span class="nx">routeAPI</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="dl">'</span><span class="s1">/test</span><span class="dl">'</span><span class="p">,</span> <span class="p">(</span><span class="nx">req</span><span class="p">,</span> <span class="nx">res</span><span class="p">)</span> <span class="o">=></span> <span class="p">{</span> <span class="nx">res</span><span class="p">.</span><span class="nf">json</span><span class="p">(</span><span class="dl">'</span><span class="s1">WOW!</span><span class="dl">'</span><span class="p">)</span> <span class="p">})</span> </code></pre></div></div> <p>This endpoint will be exposed at <code class="language-plaintext highlighter-rouge"><your_instance>/api/plugin/<your_plugin_name>/test</code></p> <h2 id="access-to-db-since-164"> <a href="#access-to-db-since-164" class="anchor-heading" aria-labelledby="access-to-db-since-164"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Access to DB <span class="label label-yellow">since 1.6.4</span> </h2> <p>TODO</p> <h2 id="helpers-documentation-needed"> <a href="#helpers-documentation-needed" class="anchor-heading" aria-labelledby="helpers-documentation-needed"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> Helpers <span class="label label-red">DOCUMENTATION NEEDED</span> </h2> <ul> <li>randomString</li> <li>sanitizeHTML</li> <li>queryParamToBool</li> </ul> <h2 id="react-to-events"> <a href="#react-to-events" class="anchor-heading" aria-labelledby="react-to-events"><svg viewBox="0 0 16 16" aria-hidden="true"><use xlink:href="#svg-link"></use></svg></a> React to events </h2> <div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="nf">onEventCreate </span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> <span class="kd">const</span> <span class="nx">eventLink</span> <span class="o">=</span> <span class="s2">`</span><span class="p">${</span><span class="nx">plugin</span><span class="p">.</span><span class="nx">gancio</span><span class="p">.</span><span class="nx">settings</span><span class="p">.</span><span class="nx">baseurl</span><span class="p">}</span><span class="s2">/event/</span><span class="p">${</span><span class="nx">event</span><span class="p">.</span><span class="nx">slug</span><span class="p">}</span><span class="s2">`</span> <span class="k">if </span><span class="p">(</span><span class="o">!</span><span class="nx">event</span><span class="p">.</span><span class="nx">is_visible</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nf">error</span><span class="p">(</span><span class="s2">`Unconfirmed event created: </span><span class="p">${</span><span class="nx">event</span><span class="p">.</span><span class="nx">title</span><span class="p">}</span><span class="s2"> / </span><span class="p">${</span><span class="nx">eventLink</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span> <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nf">error</span><span class="p">(</span><span class="s2">`Event created: </span><span class="p">${</span><span class="nx">event</span><span class="p">.</span><span class="nx">title</span><span class="p">}</span><span class="s2"> / </span><span class="p">${</span><span class="nx">eventLink</span><span class="p">}</span><span class="s2">`</span><span class="p">)</span> <span class="p">}</span> <span class="p">},</span> <span class="nf">onEventUpdate </span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nf">error</span><span class="p">(</span><span class="s2">`Event "</span><span class="p">${</span><span class="nx">event</span><span class="p">.</span><span class="nx">title</span><span class="p">}</span><span class="s2">" updated`</span><span class="p">)</span> <span class="p">},</span> <span class="nf">onEventDelete </span><span class="p">(</span><span class="nx">event</span><span class="p">)</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nf">error</span><span class="p">(</span><span class="s2">`Event "</span><span class="p">${</span><span class="nx">event</span><span class="p">.</span><span class="nx">title</span><span class="p">}</span><span class="s2">" deleted`</span><span class="p">)</span> <span class="p">}</span> </code></pre></div></div> </main> <hr> <footer> <div class="d-flex mt-2"> <p class="text-small text-grey-dk-000 mb-0"> <a href="https://framagit.org/les/gancio/-/tree/master/docs/dev/plugin.md" id="edit-this-page">Edit this page</a> </p> </div> </footer> </div> </div> <div class="search-overlay"></div> </div> </body> </html>