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 } 41 42 43 /** 44 * @fixme call this in the webbug call 45 */ 46 function putpixel(){ 47 global $ID; 48 $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID). 49 '&r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time(); 50 51 echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>'; 52 } 53 54 55 /** 56 * Log page edits actions 57 */ 58 function logedits(&$event, $param){ 59 if($event->data[3]) return; // no revision 60 61 if(file_exists($event->data[0][0])){ 62 if($event->data[0][1] == ''){ 63 $type = 'D'; 64 }else{ 65 $type = 'E'; 66 } 67 }else{ 68 $type = 'C'; 69 } 70 $hlp = plugin_load('helper','statistics'); 71 $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type); 72 } 73 74 /** 75 * Log internal search 76 */ 77 function logsearch(&$event, $param){ 78 $hlp = plugin_load('helper','statistics'); 79 $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki'); 80 } 81 82 /** 83 * Log login/logouts 84 */ 85 function loglogins(&$event, $param){ 86 $type = ''; 87 $act = $this->_act_clean($event->data); 88 if($act == 'logout'){ 89 $type = 'o'; 90 }elseif($_SERVER['REMOTE_USER'] && $act=='login'){ 91 if($_REQUEST['r']){ 92 $type = 'p'; 93 }else{ 94 $type = 'l'; 95 } 96 }elseif($_REQUEST['u'] && !$_REQUEST['http_credentials'] && !$_SERVER['REMOTE_USER']){ 97 $type = 'f'; 98 } 99 if(!$type) return; 100 101 $hlp = plugin_load('helper','statistics'); 102 $hlp->Logger()->log_login($type); 103 } 104 105 106 /** 107 * Pre-Sanitize the action command 108 * 109 * Similar to act_clean in action.php but simplified and without 110 * error messages 111 */ 112 function _act_clean($act){ 113 // check if the action was given as array key 114 if(is_array($act)){ 115 list($act) = array_keys($act); 116 } 117 118 //remove all bad chars 119 $act = strtolower($act); 120 $act = preg_replace('/[^a-z_]+/','',$act); 121 122 return $act; 123 } 124} 125