xref: /plugin/statistics/action.php (revision 535aeea1040f5c184382c2d5edecf3296fd7552b)
114d99ec0SAndreas Gohr<?php
214d99ec0SAndreas Gohr/**
314d99ec0SAndreas Gohr *
414d99ec0SAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
514d99ec0SAndreas Gohr * @author     Andreas Gohr <gohr@cosmocode.de>
614d99ec0SAndreas Gohr */
714d99ec0SAndreas Gohr
814d99ec0SAndreas Gohr// must be run within Dokuwiki
914d99ec0SAndreas Gohrif(!defined('DOKU_INC')) die();
1014d99ec0SAndreas Gohr
1114d99ec0SAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
1214d99ec0SAndreas Gohrrequire_once(DOKU_PLUGIN.'action.php');
1314d99ec0SAndreas Gohr
1414d99ec0SAndreas Gohrclass action_plugin_statistics extends DokuWiki_Action_Plugin {
1514d99ec0SAndreas Gohr
1614d99ec0SAndreas Gohr    /**
1714d99ec0SAndreas Gohr     * register the eventhandlers and initialize some options
1814d99ec0SAndreas Gohr     */
1914d99ec0SAndreas Gohr    function register(&$controller){
20eabe0d07SAndreas Gohr        global $JSINFO;
21eabe0d07SAndreas Gohr        global $ACT;
22eabe0d07SAndreas Gohr        $JSINFO['act'] = $ACT;
2314d99ec0SAndreas Gohr
24eabe0d07SAndreas Gohr
2558511ae8SAndreas Gohr        $controller->register_hook('IO_WIKIPAGE_WRITE',
2658511ae8SAndreas Gohr                                   'BEFORE',
2758511ae8SAndreas Gohr                                   $this,
2858511ae8SAndreas Gohr                                   'logedits',
2958511ae8SAndreas Gohr                                   array());
305bccfe87SAndreas Gohr        $controller->register_hook('SEARCH_QUERY_FULLPAGE',
315bccfe87SAndreas Gohr                                   'AFTER',
325bccfe87SAndreas Gohr                                   $this,
335bccfe87SAndreas Gohr                                   'logsearch',
345bccfe87SAndreas Gohr                                   array());
35b5e880bdSAndreas Gohr        $controller->register_hook('ACTION_ACT_PREPROCESS',
36b5e880bdSAndreas Gohr                                   'BEFORE',
37b5e880bdSAndreas Gohr                                   $this,
38b5e880bdSAndreas Gohr                                   'loglogins',
39b5e880bdSAndreas Gohr                                   array());
40*535aeea1SAndreas Gohr        $controller->register_hook('AUTH_USER_CHANGE',
41*535aeea1SAndreas Gohr                                   'AFTER',
42*535aeea1SAndreas Gohr                                   $this,
43*535aeea1SAndreas Gohr                                   'logregistration',
44*535aeea1SAndreas Gohr                                   array());
4514d99ec0SAndreas Gohr    }
4614d99ec0SAndreas Gohr
4714d99ec0SAndreas Gohr
4814d99ec0SAndreas Gohr    /**
4914d99ec0SAndreas Gohr     * @fixme call this in the webbug call
5014d99ec0SAndreas Gohr     */
5114d99ec0SAndreas Gohr    function putpixel(){
5214d99ec0SAndreas Gohr        global $ID;
5314d99ec0SAndreas Gohr        $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID).
5414d99ec0SAndreas Gohr               '&amp;r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time();
5514d99ec0SAndreas Gohr
5614d99ec0SAndreas Gohr        echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>';
5714d99ec0SAndreas Gohr    }
5858511ae8SAndreas Gohr
5958511ae8SAndreas Gohr
6058511ae8SAndreas Gohr    /**
615bccfe87SAndreas Gohr     * Log page edits actions
6258511ae8SAndreas Gohr     */
6358511ae8SAndreas Gohr    function logedits(&$event, $param){
6458511ae8SAndreas Gohr        if($event->data[3]) return; // no revision
6558511ae8SAndreas Gohr
6658511ae8SAndreas Gohr        if(file_exists($event->data[0][0])){
6758511ae8SAndreas Gohr            if($event->data[0][1] == ''){
6858511ae8SAndreas Gohr                $type = 'D';
6958511ae8SAndreas Gohr            }else{
7058511ae8SAndreas Gohr                $type = 'E';
7158511ae8SAndreas Gohr            }
7258511ae8SAndreas Gohr        }else{
7358511ae8SAndreas Gohr            $type = 'C';
7458511ae8SAndreas Gohr        }
7558511ae8SAndreas Gohr        $hlp = plugin_load('helper','statistics');
7658511ae8SAndreas Gohr        $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type);
7758511ae8SAndreas Gohr    }
785bccfe87SAndreas Gohr
795bccfe87SAndreas Gohr    /**
805bccfe87SAndreas Gohr     * Log internal search
815bccfe87SAndreas Gohr     */
825bccfe87SAndreas Gohr    function logsearch(&$event, $param){
835bccfe87SAndreas Gohr        $hlp = plugin_load('helper','statistics');
845bccfe87SAndreas Gohr        $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki');
855bccfe87SAndreas Gohr    }
86b5e880bdSAndreas Gohr
87b5e880bdSAndreas Gohr    /**
88b5e880bdSAndreas Gohr     * Log login/logouts
89b5e880bdSAndreas Gohr     */
90b5e880bdSAndreas Gohr    function loglogins(&$event, $param){
91b5e880bdSAndreas Gohr        $type = '';
92b5e880bdSAndreas Gohr        $act = $this->_act_clean($event->data);
93b5e880bdSAndreas Gohr        if($act == 'logout'){
94b5e880bdSAndreas Gohr            $type = 'o';
95b5e880bdSAndreas Gohr        }elseif($_SERVER['REMOTE_USER'] && $act=='login'){
96b5e880bdSAndreas Gohr            if($_REQUEST['r']){
97b5e880bdSAndreas Gohr                $type = 'p';
98b5e880bdSAndreas Gohr            }else{
99b5e880bdSAndreas Gohr                $type = 'l';
100b5e880bdSAndreas Gohr            }
101b5e880bdSAndreas Gohr        }elseif($_REQUEST['u'] && !$_REQUEST['http_credentials'] && !$_SERVER['REMOTE_USER']){
102b5e880bdSAndreas Gohr            $type = 'f';
103b5e880bdSAndreas Gohr        }
104b5e880bdSAndreas Gohr        if(!$type) return;
105b5e880bdSAndreas Gohr
106b5e880bdSAndreas Gohr        $hlp = plugin_load('helper','statistics');
107b5e880bdSAndreas Gohr        $hlp->Logger()->log_login($type);
10814d99ec0SAndreas Gohr    }
10914d99ec0SAndreas Gohr
110*535aeea1SAndreas Gohr    /**
111*535aeea1SAndreas Gohr     * Log user creations
112*535aeea1SAndreas Gohr     */
113*535aeea1SAndreas Gohr    function logregistration(&$event, $param){
114*535aeea1SAndreas Gohr        if($event->data['type'] == 'create'){
115*535aeea1SAndreas Gohr            $hlp = plugin_load('helper','statistics');
116*535aeea1SAndreas Gohr            $hlp->Logger()->log_login('C',$event->data['params'][0]);
117*535aeea1SAndreas Gohr        }
118*535aeea1SAndreas Gohr    }
119b5e880bdSAndreas Gohr
120b5e880bdSAndreas Gohr    /**
121b5e880bdSAndreas Gohr     * Pre-Sanitize the action command
122b5e880bdSAndreas Gohr     *
123b5e880bdSAndreas Gohr     * Similar to act_clean in action.php but simplified and without
124b5e880bdSAndreas Gohr     * error messages
125b5e880bdSAndreas Gohr     */
126b5e880bdSAndreas Gohr    function _act_clean($act){
127b5e880bdSAndreas Gohr         // check if the action was given as array key
128b5e880bdSAndreas Gohr         if(is_array($act)){
129b5e880bdSAndreas Gohr           list($act) = array_keys($act);
130b5e880bdSAndreas Gohr         }
131b5e880bdSAndreas Gohr
132b5e880bdSAndreas Gohr         //remove all bad chars
133b5e880bdSAndreas Gohr         $act = strtolower($act);
134b5e880bdSAndreas Gohr         $act = preg_replace('/[^a-z_]+/','',$act);
135b5e880bdSAndreas Gohr
136b5e880bdSAndreas Gohr         return $act;
137b5e880bdSAndreas Gohr     }
138b5e880bdSAndreas Gohr}
139