diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 19:17:33 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-07 19:17:33 +0200 |
commit | 01e942d44c7194607649817216aeb5d65c6acad6 (patch) | |
tree | 15777aa1005251f119e6dd680291147117766b5b /plugins/piwik | |
parent | bc22c9a0acb095970e9494cbe8954f0612e05dc0 (diff) | |
parent | 8868f3ca461011a8fb6dd9f90b60ed697ab52fc5 (diff) | |
download | Shaarli-01e942d44c7194607649817216aeb5d65c6acad6.tar.gz Shaarli-01e942d44c7194607649817216aeb5d65c6acad6.tar.zst Shaarli-01e942d44c7194607649817216aeb5d65c6acad6.zip |
Merge tag 'v0.8.4' into stable
Release v0.8.4
Diffstat (limited to 'plugins/piwik')
-rw-r--r-- | plugins/piwik/piwik.meta | 4 | ||||
-rw-r--r-- | plugins/piwik/piwik.php | 71 |
2 files changed, 75 insertions, 0 deletions
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 @@ | |||
1 | description="A plugin that adds Piwik tracking code to Shaarli pages." | ||
2 | parameters="PIWIK_URL;PIWIK_SITEID" | ||
3 | parameter.PIWIK_URL="Piwik URL" | ||
4 | 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 @@ | |||
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 = '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'][] = '<!-- Piwik -->' . | ||
54 | '<script type="text/javascript">' . | ||
55 | ' var _paq = _paq || [];' . | ||
56 | ' _paq.push([\'trackPageView\']);' . | ||
57 | ' _paq.push([\'enableLinkTracking\']);' . | ||
58 | ' (function() {' . | ||
59 | ' var u="//' . $piwikUrl . '/";' . | ||
60 | ' _paq.push([\'setTrackerUrl\', u+\'piwik.php\']);' . | ||
61 | ' _paq.push([\'setSiteId\', \'' . $piwikSiteid . '\']);' . | ||
62 | ' var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];' . | ||
63 | ' g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s);' . | ||
64 | ' })();' . | ||
65 | '</script>' . | ||
66 | '<noscript><p><img src="//' . $piwikUrl . '/piwik.php?idsite=' . $piwikSiteid . '" style="border:0;" alt="" /></p></noscript>' . | ||
67 | '<!-- End Piwik Code -->'; | ||
68 | |||
69 | return $data; | ||
70 | } | ||
71 | |||