1<?php
2/**
3 * DokuWiki plugin for Piwik2
4 *
5 * Hook into application -> executed after header metadata was rendered
6 *
7 * @license GPLv3 (http://www.gnu.org/licenses/gpl.html)
8 * @author  Marcel Lange <info@ask-sheldon.con>
9 */
10
11if (!defined('DOKU_INC')) {
12    die();
13}
14if (!defined('DOKU_PLUGIN')) {
15    define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
16}
17require_once DOKU_PLUGIN . 'action.php';
18require_once DOKU_PLUGIN . 'piwik2/code.php';
19
20class action_plugin_piwik2 extends DokuWiki_Action_Plugin
21{
22    function register(Doku_Event_Handler $controller)
23    {
24        $controller->register_hook(
25            'TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_hook_header'
26        );
27    }
28
29    function _hook_header(Doku_Event $event, $param)
30    {
31        $data = piwik_code();
32        $event->data['script'][] = array(
33            'type'    => 'text/javascript',
34            'charset' => 'utf-8',
35            '_data'   => $data,
36        );
37    }
38}
39