xref: /plugin/statistics/action.php (revision 5bccfe87d56f4416693ee1df97e12fabb789443f)
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        $controller->register_hook('SEARCH_QUERY_FULLPAGE',
32                                   'AFTER',
33                                   $this,
34                                   'logsearch',
35                                   array());
36    }
37
38    /**
39     * Extend the meta headers
40     */
41    function handle_metaheaders(&$event, $param){
42        global $ACT;
43        global $ID;
44        if($ACT != 'show') return; //only log page views for now
45
46        $page = rawurlencode($ID);
47        $data = "plugin_statistics.init('$page');";
48        $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>$data);
49    }
50
51    /**
52     * @fixme call this in the webbug call
53     */
54    function putpixel(){
55        global $ID;
56        $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID).
57               '&amp;r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time();
58
59        echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>';
60    }
61
62
63    /**
64     * Log page edits actions
65     */
66    function logedits(&$event, $param){
67        if($event->data[3]) return; // no revision
68
69        if(file_exists($event->data[0][0])){
70            if($event->data[0][1] == ''){
71                $type = 'D';
72            }else{
73                $type = 'E';
74            }
75        }else{
76            $type = 'C';
77        }
78        $hlp = plugin_load('helper','statistics');
79        $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type);
80    }
81
82    /**
83     * Log internal search
84     */
85    function logsearch(&$event, $param){
86        $hlp = plugin_load('helper','statistics');
87        $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki');
88    }
89}
90
91