xref: /plugin/statistics/action.php (revision 58511ae849ec6bd3e5b34a2ef74810800e82010b)
1<?php
2/**
3 *
4 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
5 * @author     Andreas Gohr <gohr@cosmocode.de>
6 */
7
8// must be run within Dokuwiki
9if(!defined('DOKU_INC')) die();
10
11if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
12require_once(DOKU_PLUGIN.'action.php');
13
14class action_plugin_statistics extends DokuWiki_Action_Plugin {
15
16    /**
17     * register the eventhandlers and initialize some options
18     */
19    function register(&$controller){
20
21        $controller->register_hook('TPL_METAHEADER_OUTPUT',
22                                   'BEFORE',
23                                   $this,
24                                   'handle_metaheaders',
25                                   array());
26        $controller->register_hook('IO_WIKIPAGE_WRITE',
27                                   'BEFORE',
28                                   $this,
29                                   'logedits',
30                                   array());
31    }
32
33    /**
34     * Extend the meta headers
35     */
36    function handle_metaheaders(&$event, $param){
37        global $ACT;
38        global $ID;
39        if($ACT != 'show') return; //only log page views for now
40
41        $page = rawurlencode($ID);
42        $data = "plugin_statistics.init('$page');";
43        $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>$data);
44    }
45
46    /**
47     * @fixme call this in the webbug call
48     */
49    function putpixel(){
50        global $ID;
51        $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID).
52               '&amp;r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time();
53
54        echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>';
55    }
56
57
58    /**
59     * Log edits and creates
60     *
61     * @fixme handle deletions
62     */
63    function logedits(&$event, $param){
64        if($event->data[3]) return; // no revision
65
66        if(file_exists($event->data[0][0])){
67            if($event->data[0][1] == ''){
68                $type = 'D';
69            }else{
70                $type = 'E';
71            }
72        }else{
73            $type = 'C';
74        }
75        $hlp = plugin_load('helper','statistics');
76        $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type);
77    }
78}
79
80