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