1<?php 2/** 3 * statistics plugin 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Andreas Gohr <gohr@cosmocode.de> 7 */ 8 9// must be run within Dokuwiki 10if(!defined('DOKU_INC')) die(); 11 12if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 13require_once(DOKU_PLUGIN.'admin.php'); 14 15/** 16 * All DokuWiki plugins to extend the admin function 17 * need to inherit from this class 18 */ 19class admin_plugin_statistics extends DokuWiki_Admin_Plugin { 20 var $dblink = null; 21 22 /** 23 * return some info 24 */ 25 function getInfo(){ 26 return confToHash(dirname(__FILE__).'/info.txt'); 27 } 28 29 /** 30 * Access for managers allowed 31 */ 32 function forAdminOnly(){ 33 return false; 34 } 35 36 /** 37 * return sort order for position in admin menu 38 */ 39 function getMenuSort() { 40 return 140; 41 } 42 43 /** 44 * handle user request 45 */ 46 function handle() { 47 } 48 49 /** 50 * output appropriate html 51 */ 52 function html() { 53 echo 'fixme'; 54 } 55 56 57 /** 58 * Simple function to run a DB query 59 */ 60 function runSQL($sql_string) { 61 // connect to DB if needed 62 if(!$this->dblink){ 63 $this->dblink = mysql_connect($this->getConf('db_server'), 64 $this->getConf('db_user'), 65 $this->getConf('db_password')); 66 if(!$this->dblink){ 67 msg('DB Error: connection failed',-1); 68 return null; 69 } 70 // set utf-8 71 if(!mysql_db_query($this->getConf('db_database'),'set names utf8',$this->dblink)){ 72 msg('DB Error: could not set UTF-8 ('.mysql_error($this->dblink).')',-1); 73 return null; 74 } 75 } 76 77 $result = mysql_db_query($this->getConf('db_database'),$sql_string,$this->dblink); 78 if(!mysql_db_query($this->conf['db_database'],$sql_string,$this->dblink)){ 79 msg('DB Error: '.mysql_error($this->dblink),-1); 80 return null; 81 } 82 83 $resultarray = array(); 84 85 //mysql_db_query returns 1 on a insert statement -> no need to ask for results 86 if ($result != 1) { 87 for($i=0; $i< mysql_num_rows($result); $i++) { 88 $temparray = mysql_fetch_assoc($result); 89 $resultarray[]=$temparray; 90 } 91 mysql_free_result($result); 92 } 93 94 if (mysql_insert_id($this->dblink)) { 95 $resultarray = mysql_insert_id($this->dblink); //give back ID on insert 96 } 97 98 return $resultarray; 99 } 100 101 /** 102 * Returns a short name for a User Agent 103 * 104 * @fixme: needs to be implemented 105 */ 106 function ua_info($ua){ 107 return ''; 108 } 109 110 111 112 /** 113 * log a page access 114 * 115 * called from log.php 116 */ 117 function log_access(){ 118 $page = addslashes($_REQUEST['p']); 119 $ip = addslashes($_SERVER['REMOTE_ADDR']); 120 $ua = addslashes($_SERVER['USER_AGENT']); 121 $ua_info = addslashes($this->ua_info($_SERVER['USER_AGENT'])); 122 $ref = addslashes($_REQUEST['r']); 123 $sx = (int) $_REQUEST['sx']; 124 $sy = (int) $_REQUEST['sy']; 125 $vx = (int) $_REQUEST['vx']; 126 $vy = (int) $_REQUEST['vy']; 127 $user = addslashes($_SERVER['REMOTE_USER']); 128 $session = addslashes(session_id()); 129 130 $sql = "INSERT INTO ".$this->getConf('db_prefix')."access 131 SET page = '$page', 132 ip = '$ip', 133 ua = '$ua', 134 ua_info = '$ua_info', 135 ref = '$ref', 136 ref_md5 = MD5('$ref'), 137 screen_x = '$sx', 138 screen_y = '$sy', 139 view_x = '$vx', 140 view_y = '$vy', 141 user = '$user', 142 session = '$session'"; 143 $ok = $this->runSQL($sql); 144 if(is_null($ok)){ 145 global $MSG; 146 print_r($MSG); 147 } 148 } 149 150 /** 151 * Just send a 1x1 pixel blank gif to the browser 152 * 153 * @called from log.php 154 * 155 * @author Andreas Gohr <andi@splitbrain.org> 156 * @author Harry Fuecks <fuecks@gmail.com> 157 */ 158 function sendGIF(){ 159 $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7'); 160 header('Content-Type: image/gif'); 161 header('Content-Length: '.strlen($img)); 162 header('Connection: Close'); 163 print $img; 164 flush(); 165 // Browser should drop connection after this 166 // Thinks it's got the whole image 167 } 168 169} 170