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 $controller->register_hook('ACTION_ACT_PREPROCESS', 36 'BEFORE', 37 $this, 38 'loglogins', 39 array()); 40 $controller->register_hook('AUTH_USER_CHANGE', 41 'AFTER', 42 $this, 43 'logregistration', 44 array()); 45 } 46 47 48 /** 49 * @fixme call this in the webbug call 50 */ 51 function putpixel(){ 52 global $ID; 53 $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID). 54 '&r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time(); 55 56 echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>'; 57 } 58 59 60 /** 61 * Log page edits actions 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 * Log internal search 81 */ 82 function logsearch(&$event, $param){ 83 $hlp = plugin_load('helper','statistics'); 84 $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki'); 85 } 86 87 /** 88 * Log login/logouts 89 */ 90 function loglogins(&$event, $param){ 91 $type = ''; 92 $act = $this->_act_clean($event->data); 93 if($act == 'logout'){ 94 $type = 'o'; 95 }elseif($_SERVER['REMOTE_USER'] && $act=='login'){ 96 if($_REQUEST['r']){ 97 $type = 'p'; 98 }else{ 99 $type = 'l'; 100 } 101 }elseif($_REQUEST['u'] && !$_REQUEST['http_credentials'] && !$_SERVER['REMOTE_USER']){ 102 $type = 'f'; 103 } 104 if(!$type) return; 105 106 $hlp = plugin_load('helper','statistics'); 107 $hlp->Logger()->log_login($type); 108 } 109 110 /** 111 * Log user creations 112 */ 113 function logregistration(&$event, $param){ 114 if($event->data['type'] == 'create'){ 115 $hlp = plugin_load('helper','statistics'); 116 $hlp->Logger()->log_login('C',$event->data['params'][0]); 117 } 118 } 119 120 /** 121 * Pre-Sanitize the action command 122 * 123 * Similar to act_clean in action.php but simplified and without 124 * error messages 125 */ 126 function _act_clean($act){ 127 // check if the action was given as array key 128 if(is_array($act)){ 129 list($act) = array_keys($act); 130 } 131 132 //remove all bad chars 133 $act = strtolower($act); 134 $act = preg_replace('/[^a-z_]+/','',$act); 135 136 return $act; 137 } 138} 139