]> git.immae.eu Git - github/shaarli/Shaarli.git/blob - plugins/piwik/piwik.php
Apply PHP Code Beautifier on source code for linter automatic fixes
[github/shaarli/Shaarli.git] / plugins / piwik / piwik.php
1 <?php
2
3 /**
4 * Piwik plugin.
5 * Adds tracking code on each page.
6 */
7
8 use Shaarli\Plugin\PluginManager;
9
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 */
19 function piwik_init($conf)
20 {
21 $piwikUrl = $conf->get('plugins.PIWIK_URL');
22 $piwikSiteid = $conf->get('plugins.PIWIK_SITEID');
23 if (empty($piwikUrl) || empty($piwikSiteid)) {
24 $error = t('Piwik plugin error: ' .
25 'Please define PIWIK_URL and PIWIK_SITEID in the plugin administration page.');
26 return [$error];
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 */
47 function 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.
56 $data['endofpage'][] = sprintf(
57 file_get_contents(PluginManager::$PLUGINS_PATH . '/piwik/piwik.html'),
58 $piwikUrl,
59 $piwikSiteid,
60 $piwikUrl,
61 $piwikSiteid
62 );
63
64 return $data;
65 }
66
67 /**
68 * This function is never called, but contains translation calls for GNU gettext extraction.
69 */
70 function 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 }