From e6c7e336637f82b1073b63f3cc6c8887c37c647f Mon Sep 17 00:00:00 2001 From: Adrien Oliva Date: Fri, 28 Oct 2016 10:03:32 +0200 Subject: [PATCH] Add Piwik Plugin [PullRequest #677] Change after Review Fix logic, my bad! --- plugins/piwik/piwik.meta | 4 +++ plugins/piwik/piwik.php | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 plugins/piwik/piwik.meta create mode 100644 plugins/piwik/piwik.php diff --git a/plugins/piwik/piwik.meta b/plugins/piwik/piwik.meta new file mode 100644 index 00000000..20b9628e --- /dev/null +++ b/plugins/piwik/piwik.meta @@ -0,0 +1,4 @@ +description="A plugin that adds Piwik tracking code to Shaarli pages." +parameters="PIWIK_URL;PIWIK_SITEID" +parameter.PIWIK_URL="Piwik URL" +parameter.PIWIK_SITEID="Piwik site ID" diff --git a/plugins/piwik/piwik.php b/plugins/piwik/piwik.php new file mode 100644 index 00000000..7c44909c --- /dev/null +++ b/plugins/piwik/piwik.php @@ -0,0 +1,71 @@ +get('plugins.PIWIK_URL'); + $piwikSiteid = $conf->get('plugins.PIWIK_SITEID'); + if (empty($piwikUrl) || empty($piwikSiteid)) { + $error = 'Piwik plugin error: ' . + 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.'; + return array($error); + } +} + +/** + * Hook render_footer. + * Executed on every page redering. + * + * Template placeholders: + * - text + * - endofpage + * - js_files + * + * Data: + * - _PAGE_: current page + * - _LOGGEDIN_: true/false + * + * @param array $data data passed to plugin + * + * @return array altered $data. + */ +function hook_piwik_render_footer($data, $conf) +{ + $piwikUrl = $conf->get('plugins.PIWIK_URL'); + $piwikSiteid = $conf->get('plugins.PIWIK_SITEID'); + if (empty($piwikUrl) || empty($piwikSiteid)) { + return $data; + } + + // Free elements at the end of the page. + $data['endofpage'][] = '' . +'' . +'' . +''; + + return $data; +} +