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){ 2014d99ec0SAndreas Gohr 2114d99ec0SAndreas Gohr $controller->register_hook('TPL_METAHEADER_OUTPUT', 2214d99ec0SAndreas Gohr 'BEFORE', 2314d99ec0SAndreas Gohr $this, 2414d99ec0SAndreas Gohr 'handle_metaheaders', 2514d99ec0SAndreas Gohr array()); 2658511ae8SAndreas Gohr $controller->register_hook('IO_WIKIPAGE_WRITE', 2758511ae8SAndreas Gohr 'BEFORE', 2858511ae8SAndreas Gohr $this, 2958511ae8SAndreas Gohr 'logedits', 3058511ae8SAndreas Gohr array()); 31*5bccfe87SAndreas Gohr $controller->register_hook('SEARCH_QUERY_FULLPAGE', 32*5bccfe87SAndreas Gohr 'AFTER', 33*5bccfe87SAndreas Gohr $this, 34*5bccfe87SAndreas Gohr 'logsearch', 35*5bccfe87SAndreas Gohr array()); 3614d99ec0SAndreas Gohr } 3714d99ec0SAndreas Gohr 3814d99ec0SAndreas Gohr /** 3914d99ec0SAndreas Gohr * Extend the meta headers 4014d99ec0SAndreas Gohr */ 4114d99ec0SAndreas Gohr function handle_metaheaders(&$event, $param){ 4214d99ec0SAndreas Gohr global $ACT; 4314d99ec0SAndreas Gohr global $ID; 4414d99ec0SAndreas Gohr if($ACT != 'show') return; //only log page views for now 4514d99ec0SAndreas Gohr 4673051aefSAndreas Gohr $page = rawurlencode($ID); 4773051aefSAndreas Gohr $data = "plugin_statistics.init('$page');"; 4814d99ec0SAndreas Gohr $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>$data); 4914d99ec0SAndreas Gohr } 5014d99ec0SAndreas Gohr 5114d99ec0SAndreas Gohr /** 5214d99ec0SAndreas Gohr * @fixme call this in the webbug call 5314d99ec0SAndreas Gohr */ 5414d99ec0SAndreas Gohr function putpixel(){ 5514d99ec0SAndreas Gohr global $ID; 5614d99ec0SAndreas Gohr $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID). 5714d99ec0SAndreas Gohr '&r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time(); 5814d99ec0SAndreas Gohr 5914d99ec0SAndreas Gohr echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>'; 6014d99ec0SAndreas Gohr } 6158511ae8SAndreas Gohr 6258511ae8SAndreas Gohr 6358511ae8SAndreas Gohr /** 64*5bccfe87SAndreas Gohr * Log page edits actions 6558511ae8SAndreas Gohr */ 6658511ae8SAndreas Gohr function logedits(&$event, $param){ 6758511ae8SAndreas Gohr if($event->data[3]) return; // no revision 6858511ae8SAndreas Gohr 6958511ae8SAndreas Gohr if(file_exists($event->data[0][0])){ 7058511ae8SAndreas Gohr if($event->data[0][1] == ''){ 7158511ae8SAndreas Gohr $type = 'D'; 7258511ae8SAndreas Gohr }else{ 7358511ae8SAndreas Gohr $type = 'E'; 7458511ae8SAndreas Gohr } 7558511ae8SAndreas Gohr }else{ 7658511ae8SAndreas Gohr $type = 'C'; 7758511ae8SAndreas Gohr } 7858511ae8SAndreas Gohr $hlp = plugin_load('helper','statistics'); 7958511ae8SAndreas Gohr $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type); 8058511ae8SAndreas Gohr } 81*5bccfe87SAndreas Gohr 82*5bccfe87SAndreas Gohr /** 83*5bccfe87SAndreas Gohr * Log internal search 84*5bccfe87SAndreas Gohr */ 85*5bccfe87SAndreas Gohr function logsearch(&$event, $param){ 86*5bccfe87SAndreas Gohr $hlp = plugin_load('helper','statistics'); 87*5bccfe87SAndreas Gohr $hlp->Logger()->log_search('',$event->data['query'],$event->data['highlight'],'dokuwiki'); 88*5bccfe87SAndreas Gohr } 8914d99ec0SAndreas Gohr} 9014d99ec0SAndreas Gohr 91