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