1<?php
2/**
3 * DokuWiki plugin for matomo
4 *
5 * Generates the inserted js/html code that is inserted into dom (HTML-HEAD)
6 *
7 * @license GPLv3 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Marcel Lange <info@ask-sheldon.con>
9 */
10require_once(DOKU_INC . 'inc/auth.php');
11
12
13/**
14 * Injects the necessary trackingcodes for matomo tracking into DOM
15 * like specified in the plugin manager fields
16 */
17function matomo_code()
18{
19    global $conf;
20
21    if (isset($conf['plugin']['matomo']['js_tracking_code'])
22        || (isset($conf['plugin']['matomo']['img_tracking_code']))
23    ) {
24        // Config does not contain keys if they are default;
25        // so check whether they are set & to non-default value
26
27        // default 0, so check if it's not set or 0
28        if (!isset($conf['plugin']['matomo']['track_admin_user'])
29            || $conf['plugin']['matomo']['track_admin_user'] == 0
30        ) {
31            if (isset($_SERVER['REMOTE_USER']) && auth_isadmin()) {
32                return;
33            }
34        }
35
36        // default 1, so check if it's set and 0
37        if (isset($conf['plugin']['matomo']['track_user'])
38            && $conf['plugin']['matomo']['track_user'] == 0
39        ) {
40            if (isset($_SERVER['REMOTE_USER'])) {
41                return;
42            }
43        }
44
45        //changes made by Marcel Lange (info@bravehartk2.de)
46        $trackingCode = (isset($conf['plugin']['matomo']['js_tracking_code']))
47            ? $conf['plugin']['matomo']['js_tracking_code'] : '';
48        if (isset($conf['plugin']['matomo']['use_img_tracking'])
49            && $conf['plugin']['matomo']['use_img_tracking'] == 1
50            && isset($conf['plugin']['matomo']['img_tracking_code'])
51        ) {
52            $trackingCode = $conf['plugin']['matomo']['img_tracking_code'];
53        }
54        ptln($trackingCode);
55    } else {
56        // Show configuration tip for admin
57        if (isset($_SERVER['REMOTE_USER']) && auth_isadmin()) {
58            msg('Please configure the matomo plugin');
59        }
60    }
61}
62