11878f16fSAndreas Gohr<?php 21878f16fSAndreas Gohr/** 31878f16fSAndreas Gohr * statistics plugin 41878f16fSAndreas Gohr * 51878f16fSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 61878f16fSAndreas Gohr * @author Andreas Gohr <gohr@cosmocode.de> 71878f16fSAndreas Gohr */ 81878f16fSAndreas Gohr 91878f16fSAndreas Gohr// must be run within Dokuwiki 101878f16fSAndreas Gohrif(!defined('DOKU_INC')) die(); 111878f16fSAndreas Gohr 121878f16fSAndreas Gohrif(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 131878f16fSAndreas Gohrrequire_once(DOKU_PLUGIN.'admin.php'); 141878f16fSAndreas Gohr 151878f16fSAndreas Gohr/** 161878f16fSAndreas Gohr * All DokuWiki plugins to extend the admin function 171878f16fSAndreas Gohr * need to inherit from this class 181878f16fSAndreas Gohr */ 191878f16fSAndreas Gohrclass admin_plugin_statistics extends DokuWiki_Admin_Plugin { 201878f16fSAndreas Gohr var $dblink = null; 211878f16fSAndreas Gohr 221878f16fSAndreas Gohr /** 231878f16fSAndreas Gohr * return some info 241878f16fSAndreas Gohr */ 251878f16fSAndreas Gohr function getInfo(){ 261878f16fSAndreas Gohr return confToHash(dirname(__FILE__).'/info.txt'); 271878f16fSAndreas Gohr } 281878f16fSAndreas Gohr 291878f16fSAndreas Gohr /** 301878f16fSAndreas Gohr * Access for managers allowed 311878f16fSAndreas Gohr */ 321878f16fSAndreas Gohr function forAdminOnly(){ 331878f16fSAndreas Gohr return false; 341878f16fSAndreas Gohr } 351878f16fSAndreas Gohr 361878f16fSAndreas Gohr /** 371878f16fSAndreas Gohr * return sort order for position in admin menu 381878f16fSAndreas Gohr */ 391878f16fSAndreas Gohr function getMenuSort() { 401878f16fSAndreas Gohr return 140; 411878f16fSAndreas Gohr } 421878f16fSAndreas Gohr 431878f16fSAndreas Gohr /** 441878f16fSAndreas Gohr * handle user request 451878f16fSAndreas Gohr */ 461878f16fSAndreas Gohr function handle() { 471878f16fSAndreas Gohr } 481878f16fSAndreas Gohr 491878f16fSAndreas Gohr /** 50*94171ff3SAndreas Gohr * fixme build statistics here 511878f16fSAndreas Gohr */ 521878f16fSAndreas Gohr function html() { 531878f16fSAndreas Gohr echo 'fixme'; 541878f16fSAndreas Gohr } 551878f16fSAndreas Gohr 561878f16fSAndreas Gohr 571878f16fSAndreas Gohr /** 581878f16fSAndreas Gohr * Simple function to run a DB query 591878f16fSAndreas Gohr */ 601878f16fSAndreas Gohr function runSQL($sql_string) { 611878f16fSAndreas Gohr // connect to DB if needed 621878f16fSAndreas Gohr if(!$this->dblink){ 631878f16fSAndreas Gohr $this->dblink = mysql_connect($this->getConf('db_server'), 641878f16fSAndreas Gohr $this->getConf('db_user'), 651878f16fSAndreas Gohr $this->getConf('db_password')); 661878f16fSAndreas Gohr if(!$this->dblink){ 671878f16fSAndreas Gohr msg('DB Error: connection failed',-1); 681878f16fSAndreas Gohr return null; 691878f16fSAndreas Gohr } 701878f16fSAndreas Gohr // set utf-8 711878f16fSAndreas Gohr if(!mysql_db_query($this->getConf('db_database'),'set names utf8',$this->dblink)){ 721878f16fSAndreas Gohr msg('DB Error: could not set UTF-8 ('.mysql_error($this->dblink).')',-1); 731878f16fSAndreas Gohr return null; 741878f16fSAndreas Gohr } 751878f16fSAndreas Gohr } 761878f16fSAndreas Gohr 77*94171ff3SAndreas Gohr $result = mysql_db_query($this->conf['db_database'],$sql_string,$this->dblink); 78*94171ff3SAndreas Gohr if(!$result){ 791878f16fSAndreas Gohr msg('DB Error: '.mysql_error($this->dblink),-1); 801878f16fSAndreas Gohr return null; 811878f16fSAndreas Gohr } 821878f16fSAndreas Gohr 831878f16fSAndreas Gohr $resultarray = array(); 841878f16fSAndreas Gohr 851878f16fSAndreas Gohr //mysql_db_query returns 1 on a insert statement -> no need to ask for results 861878f16fSAndreas Gohr if ($result != 1) { 871878f16fSAndreas Gohr for($i=0; $i< mysql_num_rows($result); $i++) { 881878f16fSAndreas Gohr $temparray = mysql_fetch_assoc($result); 891878f16fSAndreas Gohr $resultarray[]=$temparray; 901878f16fSAndreas Gohr } 911878f16fSAndreas Gohr mysql_free_result($result); 921878f16fSAndreas Gohr } 931878f16fSAndreas Gohr 941878f16fSAndreas Gohr if (mysql_insert_id($this->dblink)) { 951878f16fSAndreas Gohr $resultarray = mysql_insert_id($this->dblink); //give back ID on insert 961878f16fSAndreas Gohr } 971878f16fSAndreas Gohr 981878f16fSAndreas Gohr return $resultarray; 991878f16fSAndreas Gohr } 1001878f16fSAndreas Gohr 1011878f16fSAndreas Gohr /** 1021878f16fSAndreas Gohr * Returns a short name for a User Agent 1031878f16fSAndreas Gohr * 1041878f16fSAndreas Gohr * @fixme: needs to be implemented 1051878f16fSAndreas Gohr */ 1061878f16fSAndreas Gohr function ua_info($ua){ 1071878f16fSAndreas Gohr return ''; 1081878f16fSAndreas Gohr } 1091878f16fSAndreas Gohr 1101878f16fSAndreas Gohr /** 1111878f16fSAndreas Gohr * log a page access 1121878f16fSAndreas Gohr * 1131878f16fSAndreas Gohr * called from log.php 1141878f16fSAndreas Gohr */ 1151878f16fSAndreas Gohr function log_access(){ 116*94171ff3SAndreas Gohr if(!$_REQUEST['p']) return; 117*94171ff3SAndreas Gohr 1181878f16fSAndreas Gohr $page = addslashes($_REQUEST['p']); 1191878f16fSAndreas Gohr $ip = addslashes($_SERVER['REMOTE_ADDR']); 120*94171ff3SAndreas Gohr $ua = addslashes($_SERVER['HTTP_USER_AGENT']); 121*94171ff3SAndreas Gohr $ua_info = addslashes($this->ua_info($_SERVER['HTTP_USER_AGENT'])); 1221878f16fSAndreas Gohr $ref = addslashes($_REQUEST['r']); 123*94171ff3SAndreas Gohr $ref_md5 = ($ref) ? md5($ref) : ''; 1241878f16fSAndreas Gohr $sx = (int) $_REQUEST['sx']; 1251878f16fSAndreas Gohr $sy = (int) $_REQUEST['sy']; 1261878f16fSAndreas Gohr $vx = (int) $_REQUEST['vx']; 1271878f16fSAndreas Gohr $vy = (int) $_REQUEST['vy']; 1281878f16fSAndreas Gohr $user = addslashes($_SERVER['REMOTE_USER']); 1291878f16fSAndreas Gohr $session = addslashes(session_id()); 1301878f16fSAndreas Gohr 131*94171ff3SAndreas Gohr $sql = "INSERT DELAYED INTO ".$this->getConf('db_prefix')."access 1321878f16fSAndreas Gohr SET page = '$page', 1331878f16fSAndreas Gohr ip = '$ip', 1341878f16fSAndreas Gohr ua = '$ua', 1351878f16fSAndreas Gohr ua_info = '$ua_info', 1361878f16fSAndreas Gohr ref = '$ref', 137*94171ff3SAndreas Gohr ref_md5 = '$ref_md5', 1381878f16fSAndreas Gohr screen_x = '$sx', 1391878f16fSAndreas Gohr screen_y = '$sy', 1401878f16fSAndreas Gohr view_x = '$vx', 1411878f16fSAndreas Gohr view_y = '$vy', 1421878f16fSAndreas Gohr user = '$user', 1431878f16fSAndreas Gohr session = '$session'"; 1441878f16fSAndreas Gohr $ok = $this->runSQL($sql); 1451878f16fSAndreas Gohr if(is_null($ok)){ 1461878f16fSAndreas Gohr global $MSG; 1471878f16fSAndreas Gohr print_r($MSG); 1481878f16fSAndreas Gohr } 1491878f16fSAndreas Gohr } 1501878f16fSAndreas Gohr 1511878f16fSAndreas Gohr /** 1521878f16fSAndreas Gohr * Just send a 1x1 pixel blank gif to the browser 1531878f16fSAndreas Gohr * 1541878f16fSAndreas Gohr * @called from log.php 1551878f16fSAndreas Gohr * 1561878f16fSAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1571878f16fSAndreas Gohr * @author Harry Fuecks <fuecks@gmail.com> 1581878f16fSAndreas Gohr */ 1591878f16fSAndreas Gohr function sendGIF(){ 1601878f16fSAndreas Gohr $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7'); 1611878f16fSAndreas Gohr header('Content-Type: image/gif'); 1621878f16fSAndreas Gohr header('Content-Length: '.strlen($img)); 1631878f16fSAndreas Gohr header('Connection: Close'); 1641878f16fSAndreas Gohr print $img; 1651878f16fSAndreas Gohr flush(); 1661878f16fSAndreas Gohr // Browser should drop connection after this 1671878f16fSAndreas Gohr // Thinks it's got the whole image 1681878f16fSAndreas Gohr } 1691878f16fSAndreas Gohr 1701878f16fSAndreas Gohr} 171