]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - plugins/piwik/piwik.php
Apply PHP Code Beautifier on source code for linter automatic fixes
[github/shaarli/Shaarli.git] / plugins / piwik / piwik.php
CommitLineData
e6c7e336 1<?php
53054b2b 2
e6c7e336
AO
3/**
4 * Piwik plugin.
5 * Adds tracking code on each page.
6 */
7
e1850388
V
8use Shaarli\Plugin\PluginManager;
9
e6c7e336
AO
10/**
11 * Initialization function.
12 * It will be called when the plugin is loaded.
13 * This function can be used to return a list of initialization errors.
14 *
15 * @param $conf ConfigManager instance.
16 *
17 * @return array List of errors (optional).
18 */
19function piwik_init($conf)
20{
21 $piwikUrl = $conf->get('plugins.PIWIK_URL');
22 $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
23 if (empty($piwikUrl) || empty($piwikSiteid)) {
12266213
A
24 $error = t('Piwik plugin error: ' .
25 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.');
53054b2b 26 return [$error];
e6c7e336
AO
27 }
28}
29
30/**
31 * Hook render_footer.
32 * Executed on every page redering.
33 *
34 * Template placeholders:
35 * - text
36 * - endofpage
37 * - js_files
38 *
39 * Data:
40 * - _PAGE_: current page
41 * - _LOGGEDIN_: true/false
42 *
43 * @param array $data data passed to plugin
44 *
45 * @return array altered $data.
46 */
47function hook_piwik_render_footer($data, $conf)
48{
49 $piwikUrl = $conf->get('plugins.PIWIK_URL');
50 $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
51 if (empty($piwikUrl) || empty($piwikSiteid)) {
52 return $data;
53 }
54
55 // Free elements at the end of the page.
fe83d45c
A
56 $data['endofpage'][] = sprintf(
57 file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'),
58 $piwikUrl,
59 $piwikSiteid,
60 $piwikUrl,
61 $piwikSiteid
62 );
e6c7e336
AO
63
64 return $data;
65}
12266213
A
66
67/**
68 * This function is never called, but contains translation calls for GNU gettext extraction.
69 */
70function piwik_dummy_translation()
71{
72 // meta
73 t('A plugin that adds Piwik tracking code to Shaarli pages.');
74 t('Piwik URL');
75 t('Piwik site ID');
76}