xref: /plugin/statistics/action.php (revision eabe0d07c30a5b0d4bf51212b11c020f21d748b1)
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        global $JSINFO;
21        global $ACT;
22        $JSINFO['act'] = $ACT;
23
24
25        $controller->register_hook('IO_WIKIPAGE_WRITE',
26                                   'BEFORE',
27                                   $this,
28                                   'logedits',
29                                   array());
30        $controller->register_hook('SEARCH_QUERY_FULLPAGE',
31                                   'AFTER',
32                                   $this,
33                                   'logsearch',
34                                   array());
35    }
36
37
38    /**
39     * @fixme call this in the webbug call
40     */
41    function putpixel(){
42        global $ID;
43        $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID).
44               '&amp;r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time();
45
46        echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>';
47    }
48
49
50    /**
51     * Log page edits actions
52     */
53    function logedits(&$event, $param){
54        if($event->data[3]) return; // no revision
55
56        if(file_exists($event->data[0][0])){
57            if($event->data[0][1] == ''){
58                $type = 'D';
59            }else{
60                $type = 'E';
61            }
62        }else{
63            $type = 'C';
64        }
65        $hlp = plugin_load('helper','statistics');
66        $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type);
67    }
68
69    /**
70     * Log internal search
71     */
72    function logsearch(&$event, $param){
73        $hlp = plugin_load('helper','statistics');
74        $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki');
75    }
76}
77
78