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()); 26*58511ae8SAndreas Gohr $controller->register_hook('IO_WIKIPAGE_WRITE', 27*58511ae8SAndreas Gohr 'BEFORE', 28*58511ae8SAndreas Gohr $this, 29*58511ae8SAndreas Gohr 'logedits', 30*58511ae8SAndreas Gohr array()); 3114d99ec0SAndreas Gohr } 3214d99ec0SAndreas Gohr 3314d99ec0SAndreas Gohr /** 3414d99ec0SAndreas Gohr * Extend the meta headers 3514d99ec0SAndreas Gohr */ 3614d99ec0SAndreas Gohr function handle_metaheaders(&$event, $param){ 3714d99ec0SAndreas Gohr global $ACT; 3814d99ec0SAndreas Gohr global $ID; 3914d99ec0SAndreas Gohr if($ACT != 'show') return; //only log page views for now 4014d99ec0SAndreas Gohr 4173051aefSAndreas Gohr $page = rawurlencode($ID); 4273051aefSAndreas Gohr $data = "plugin_statistics.init('$page');"; 4314d99ec0SAndreas Gohr $event->data['script'][] = array( 'type'=>'text/javascript', 'charset'=>'utf-8', '_data'=>$data); 4414d99ec0SAndreas Gohr } 4514d99ec0SAndreas Gohr 4614d99ec0SAndreas Gohr /** 4714d99ec0SAndreas Gohr * @fixme call this in the webbug call 4814d99ec0SAndreas Gohr */ 4914d99ec0SAndreas Gohr function putpixel(){ 5014d99ec0SAndreas Gohr global $ID; 5114d99ec0SAndreas Gohr $url = DOKU_BASE.'lib/plugins/statistics/log.php?p='.rawurlencode($ID). 5214d99ec0SAndreas Gohr '&r='.rawurlencode($_SERVER['HTTP_REFERER']).'&rnd='.time(); 5314d99ec0SAndreas Gohr 5414d99ec0SAndreas Gohr echo '<noscript><img src="'.$url.'" width="1" height="1" /></noscript>'; 5514d99ec0SAndreas Gohr } 56*58511ae8SAndreas Gohr 57*58511ae8SAndreas Gohr 58*58511ae8SAndreas Gohr /** 59*58511ae8SAndreas Gohr * Log edits and creates 60*58511ae8SAndreas Gohr * 61*58511ae8SAndreas Gohr * @fixme handle deletions 62*58511ae8SAndreas Gohr */ 63*58511ae8SAndreas Gohr function logedits(&$event, $param){ 64*58511ae8SAndreas Gohr if($event->data[3]) return; // no revision 65*58511ae8SAndreas Gohr 66*58511ae8SAndreas Gohr if(file_exists($event->data[0][0])){ 67*58511ae8SAndreas Gohr if($event->data[0][1] == ''){ 68*58511ae8SAndreas Gohr $type = 'D'; 69*58511ae8SAndreas Gohr }else{ 70*58511ae8SAndreas Gohr $type = 'E'; 71*58511ae8SAndreas Gohr } 72*58511ae8SAndreas Gohr }else{ 73*58511ae8SAndreas Gohr $type = 'C'; 74*58511ae8SAndreas Gohr } 75*58511ae8SAndreas Gohr $hlp = plugin_load('helper','statistics'); 76*58511ae8SAndreas Gohr $hlp->Logger()->log_edit(cleanID($event->data[1].':'.$event->data[2]), $type); 77*58511ae8SAndreas Gohr } 7814d99ec0SAndreas Gohr} 7914d99ec0SAndreas Gohr 80