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 24*0863c19cSAndreas Gohr $controller->register_hook( 25*0863c19cSAndreas Gohr 'IO_WIKIPAGE_WRITE', 2658511ae8SAndreas Gohr 'BEFORE', 2758511ae8SAndreas Gohr $this, 2858511ae8SAndreas Gohr 'logedits', 29*0863c19cSAndreas Gohr array() 30*0863c19cSAndreas Gohr ); 31*0863c19cSAndreas Gohr $controller->register_hook( 32*0863c19cSAndreas Gohr 'SEARCH_QUERY_FULLPAGE', 335bccfe87SAndreas Gohr 'AFTER', 345bccfe87SAndreas Gohr $this, 355bccfe87SAndreas Gohr 'logsearch', 36*0863c19cSAndreas Gohr array() 37*0863c19cSAndreas Gohr ); 38*0863c19cSAndreas Gohr $controller->register_hook( 39*0863c19cSAndreas Gohr 'ACTION_ACT_PREPROCESS', 40b5e880bdSAndreas Gohr 'BEFORE', 41b5e880bdSAndreas Gohr $this, 42b5e880bdSAndreas Gohr 'loglogins', 43*0863c19cSAndreas Gohr array() 44*0863c19cSAndreas Gohr ); 45*0863c19cSAndreas Gohr $controller->register_hook( 46*0863c19cSAndreas Gohr 'AUTH_USER_CHANGE', 47535aeea1SAndreas Gohr 'AFTER', 48535aeea1SAndreas Gohr $this, 49535aeea1SAndreas Gohr 'logregistration', 50*0863c19cSAndreas Gohr array() 51*0863c19cSAndreas Gohr ); 5214d99ec0SAndreas Gohr } 5314d99ec0SAndreas Gohr 5414d99ec0SAndreas Gohr /** 5514d99ec0SAndreas Gohr * @fixme call this in the webbug call 5614d99ec0SAndreas Gohr */ 5714d99ec0SAndreas Gohr function putpixel() { 5814d99ec0SAndreas Gohr global $ID; 5914d99ec0SAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/log.php?p=' . rawurlencode($ID) . 6014d99ec0SAndreas Gohr '&r=' . rawurlencode($_SERVER['HTTP_REFERER']) . '&rnd=' . time(); 6114d99ec0SAndreas Gohr 6214d99ec0SAndreas Gohr echo '<noscript><img src="' . $url . '" width="1" height="1" /></noscript>'; 6314d99ec0SAndreas Gohr } 6458511ae8SAndreas Gohr 6558511ae8SAndreas Gohr /** 665bccfe87SAndreas Gohr * Log page edits actions 6758511ae8SAndreas Gohr */ 6858511ae8SAndreas Gohr function logedits(&$event, $param) { 6958511ae8SAndreas Gohr if($event->data[3]) return; // no revision 7058511ae8SAndreas Gohr 7158511ae8SAndreas Gohr if(file_exists($event->data[0][0])) { 7258511ae8SAndreas Gohr if($event->data[0][1] == '') { 7358511ae8SAndreas Gohr $type = 'D'; 7458511ae8SAndreas Gohr } else { 7558511ae8SAndreas Gohr $type = 'E'; 7658511ae8SAndreas Gohr } 7758511ae8SAndreas Gohr } else { 7858511ae8SAndreas Gohr $type = 'C'; 7958511ae8SAndreas Gohr } 8058511ae8SAndreas Gohr $hlp = plugin_load('helper', 'statistics'); 8158511ae8SAndreas Gohr $hlp->Logger()->log_edit(cleanID($event->data[1] . ':' . $event->data[2]), $type); 8258511ae8SAndreas Gohr } 835bccfe87SAndreas Gohr 845bccfe87SAndreas Gohr /** 855bccfe87SAndreas Gohr * Log internal search 865bccfe87SAndreas Gohr */ 875bccfe87SAndreas Gohr function logsearch(&$event, $param) { 885bccfe87SAndreas Gohr $hlp = plugin_load('helper', 'statistics'); 895bccfe87SAndreas Gohr $hlp->Logger()->log_search('', $event->data['query'], $event->data['highlight'], 'dokuwiki'); 905bccfe87SAndreas Gohr } 91b5e880bdSAndreas Gohr 92b5e880bdSAndreas Gohr /** 93b5e880bdSAndreas Gohr * Log login/logouts 94b5e880bdSAndreas Gohr */ 95b5e880bdSAndreas Gohr function loglogins(&$event, $param) { 96b5e880bdSAndreas Gohr $type = ''; 97b5e880bdSAndreas Gohr $act = $this->_act_clean($event->data); 98b5e880bdSAndreas Gohr if($act == 'logout') { 99b5e880bdSAndreas Gohr $type = 'o'; 100b5e880bdSAndreas Gohr } elseif($_SERVER['REMOTE_USER'] && $act == 'login') { 101b5e880bdSAndreas Gohr if($_REQUEST['r']) { 102b5e880bdSAndreas Gohr $type = 'p'; 103b5e880bdSAndreas Gohr } else { 104b5e880bdSAndreas Gohr $type = 'l'; 105b5e880bdSAndreas Gohr } 106b5e880bdSAndreas Gohr } elseif($_REQUEST['u'] && !$_REQUEST['http_credentials'] && !$_SERVER['REMOTE_USER']) { 107b5e880bdSAndreas Gohr $type = 'f'; 108b5e880bdSAndreas Gohr } 109b5e880bdSAndreas Gohr if(!$type) return; 110b5e880bdSAndreas Gohr 111b5e880bdSAndreas Gohr $hlp = plugin_load('helper', 'statistics'); 112b5e880bdSAndreas Gohr $hlp->Logger()->log_login($type); 11314d99ec0SAndreas Gohr } 11414d99ec0SAndreas Gohr 115535aeea1SAndreas Gohr /** 116535aeea1SAndreas Gohr * Log user creations 117535aeea1SAndreas Gohr */ 118535aeea1SAndreas Gohr function logregistration(&$event, $param) { 119535aeea1SAndreas Gohr if($event->data['type'] == 'create') { 120535aeea1SAndreas Gohr $hlp = plugin_load('helper', 'statistics'); 121535aeea1SAndreas Gohr $hlp->Logger()->log_login('C', $event->data['params'][0]); 122535aeea1SAndreas Gohr } 123535aeea1SAndreas Gohr } 124b5e880bdSAndreas Gohr 125b5e880bdSAndreas Gohr /** 126b5e880bdSAndreas Gohr * Pre-Sanitize the action command 127b5e880bdSAndreas Gohr * 128b5e880bdSAndreas Gohr * Similar to act_clean in action.php but simplified and without 129b5e880bdSAndreas Gohr * error messages 130b5e880bdSAndreas Gohr */ 131b5e880bdSAndreas Gohr function _act_clean($act) { 132b5e880bdSAndreas Gohr // check if the action was given as array key 133b5e880bdSAndreas Gohr if(is_array($act)) { 134b5e880bdSAndreas Gohr list($act) = array_keys($act); 135b5e880bdSAndreas Gohr } 136b5e880bdSAndreas Gohr 137b5e880bdSAndreas Gohr //remove all bad chars 138b5e880bdSAndreas Gohr $act = strtolower($act); 139b5e880bdSAndreas Gohr $act = preg_replace('/[^a-z_]+/', '', $act); 140b5e880bdSAndreas Gohr 141b5e880bdSAndreas Gohr return $act; 142b5e880bdSAndreas Gohr } 143b5e880bdSAndreas Gohr} 144