xref: /plugin/statistics/admin.php (revision 54f6c432a6875831742324eaa410b4f4bd14f817)
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() {
4014d99ec0SAndreas Gohr        return 150;
411878f16fSAndreas Gohr    }
421878f16fSAndreas Gohr
431878f16fSAndreas Gohr    /**
441878f16fSAndreas Gohr     * handle user request
451878f16fSAndreas Gohr     */
461878f16fSAndreas Gohr    function handle() {
471878f16fSAndreas Gohr    }
481878f16fSAndreas Gohr
491878f16fSAndreas Gohr    /**
5094171ff3SAndreas Gohr     * fixme build statistics here
511878f16fSAndreas Gohr     */
521878f16fSAndreas Gohr    function html() {
5314d99ec0SAndreas Gohr        // fixme build a navigation menu in a TOC here
5414d99ec0SAndreas Gohr
5514d99ec0SAndreas Gohr        switch($_REQUEST['opt']){
5614d99ec0SAndreas Gohr
5714d99ec0SAndreas Gohr            default:
5814d99ec0SAndreas Gohr                echo $this->locale_xhtml('intro');
5914d99ec0SAndreas Gohr                echo $this->html_dashboard();
6014d99ec0SAndreas Gohr        }
6114d99ec0SAndreas Gohr    }
6214d99ec0SAndreas Gohr
6314d99ec0SAndreas Gohr    function html_timeselect(){
6414d99ec0SAndreas Gohr        echo '<form>';
6514d99ec0SAndreas Gohr
6614d99ec0SAndreas Gohr        echo '</form>';
6714d99ec0SAndreas Gohr    }
6814d99ec0SAndreas Gohr
6914d99ec0SAndreas Gohr
7014d99ec0SAndreas Gohr    function html_dashboard(){
7114d99ec0SAndreas Gohr
7287d5e44bSAndreas Gohr        // top pages today
7314d99ec0SAndreas Gohr        $sql = "SELECT page, COUNT(*) as cnt
7414d99ec0SAndreas Gohr                  FROM ".$this->getConf('db_prefix')."access
7514d99ec0SAndreas Gohr                 WHERE DATE(dt) = CURDATE()
7687d5e44bSAndreas Gohr                   AND ua_type = 'browser'
7714d99ec0SAndreas Gohr              GROUP BY page
7814d99ec0SAndreas Gohr              ORDER BY cnt DESC, page
7914d99ec0SAndreas Gohr                 LIMIT 20";
8014d99ec0SAndreas Gohr        $result = $this->runSQL($sql);
8187d5e44bSAndreas Gohr        $this->html_resulttable($result,array('Pages','Count'));
8287d5e44bSAndreas Gohr
8387d5e44bSAndreas Gohr        // top referer today
8487d5e44bSAndreas Gohr        $sql = "SELECT ref as url, COUNT(*) as cnt
8587d5e44bSAndreas Gohr                  FROM ".$this->getConf('db_prefix')."access
8687d5e44bSAndreas Gohr                 WHERE DATE(dt) = CURDATE()
8787d5e44bSAndreas Gohr                   AND ua_type = 'browser'
8887d5e44bSAndreas Gohr                   AND ref_type = 'external'
8987d5e44bSAndreas Gohr              GROUP BY ref_md5
9087d5e44bSAndreas Gohr              ORDER BY cnt DESC, url
9187d5e44bSAndreas Gohr                 LIMIT 20";
9287d5e44bSAndreas Gohr        $result = $this->runSQL($sql);
9387d5e44bSAndreas Gohr        $this->html_resulttable($result,array('Incoming Links','Count'));
94*54f6c432SAndreas Gohr
95*54f6c432SAndreas Gohr        // top countries today
96*54f6c432SAndreas Gohr        $sql = "SELECT B.country, COUNT(*) as cnt
97*54f6c432SAndreas Gohr                  FROM ".$this->getConf('db_prefix')."access as A,
98*54f6c432SAndreas Gohr                       ".$this->getConf('db_prefix')."iplocation as B
99*54f6c432SAndreas Gohr                 WHERE DATE(A.dt) = CURDATE()
100*54f6c432SAndreas Gohr                   AND A.ip = B.ip
101*54f6c432SAndreas Gohr              GROUP BY B.country
102*54f6c432SAndreas Gohr              ORDER BY cnt DESC, B.country
103*54f6c432SAndreas Gohr                 LIMIT 20";
104*54f6c432SAndreas Gohr        $result = $this->runSQL($sql);
105*54f6c432SAndreas Gohr        $this->html_resulttable($result,array('Countries','Count'));
10614d99ec0SAndreas Gohr    }
10714d99ec0SAndreas Gohr
10814d99ec0SAndreas Gohr    /**
10914d99ec0SAndreas Gohr     * Display a result in a HTML table
11014d99ec0SAndreas Gohr     */
11114d99ec0SAndreas Gohr    function html_resulttable($result,$header){
11214d99ec0SAndreas Gohr        echo '<table>';
11314d99ec0SAndreas Gohr        echo '<tr>';
11414d99ec0SAndreas Gohr        foreach($header as $h){
11514d99ec0SAndreas Gohr            echo '<th>'.hsc($h).'</th>';
11614d99ec0SAndreas Gohr        }
11714d99ec0SAndreas Gohr        echo '</tr>';
11814d99ec0SAndreas Gohr
11914d99ec0SAndreas Gohr        foreach($result as $row){
12014d99ec0SAndreas Gohr            echo '<tr>';
12114d99ec0SAndreas Gohr            foreach($row as $k => $v){
12214d99ec0SAndreas Gohr                echo '<td class="stats_'.$k.'">';
12314d99ec0SAndreas Gohr                if($k == 'page'){
12414d99ec0SAndreas Gohr                    echo '<a href="'.wl($v).'" class="wikilink1">';
12514d99ec0SAndreas Gohr                    echo hsc($v);
12614d99ec0SAndreas Gohr                    echo '</a>';
12714d99ec0SAndreas Gohr                }elseif($k == 'url'){
128*54f6c432SAndreas Gohr                    $url = hsc($v);
129*54f6c432SAndreas Gohr                    if(strlen($url) > 50){
130*54f6c432SAndreas Gohr                        $url = substr($url,0,30).' &hellip; '.substr($url,-20);
131*54f6c432SAndreas Gohr                    }
13214d99ec0SAndreas Gohr                    echo '<a href="'.$v.'" class="urlextern">';
133*54f6c432SAndreas Gohr                    echo $url;
13414d99ec0SAndreas Gohr                    echo '</a>';
13514d99ec0SAndreas Gohr                }elseif($k == 'html'){
13614d99ec0SAndreas Gohr                    echo $v;
13714d99ec0SAndreas Gohr                }else{
13814d99ec0SAndreas Gohr                    echo hsc($v);
13914d99ec0SAndreas Gohr                }
14014d99ec0SAndreas Gohr                echo '</td>';
14114d99ec0SAndreas Gohr            }
14214d99ec0SAndreas Gohr            echo '</tr>';
14314d99ec0SAndreas Gohr        }
14414d99ec0SAndreas Gohr        echo '</table>';
1451878f16fSAndreas Gohr    }
1461878f16fSAndreas Gohr
1471878f16fSAndreas Gohr
1481878f16fSAndreas Gohr    /**
14914d99ec0SAndreas Gohr     * Return a link to the DB, opening the connection if needed
1501878f16fSAndreas Gohr     */
15114d99ec0SAndreas Gohr    function dbLink(){
1521878f16fSAndreas Gohr        // connect to DB if needed
1531878f16fSAndreas Gohr        if(!$this->dblink){
1541878f16fSAndreas Gohr            $this->dblink = mysql_connect($this->getConf('db_server'),
1551878f16fSAndreas Gohr                                          $this->getConf('db_user'),
1561878f16fSAndreas Gohr                                          $this->getConf('db_password'));
1571878f16fSAndreas Gohr            if(!$this->dblink){
1581878f16fSAndreas Gohr                msg('DB Error: connection failed',-1);
1591878f16fSAndreas Gohr                return null;
1601878f16fSAndreas Gohr            }
1611878f16fSAndreas Gohr            // set utf-8
1621878f16fSAndreas Gohr            if(!mysql_db_query($this->getConf('db_database'),'set names utf8',$this->dblink)){
1631878f16fSAndreas Gohr                msg('DB Error: could not set UTF-8 ('.mysql_error($this->dblink).')',-1);
1641878f16fSAndreas Gohr                return null;
1651878f16fSAndreas Gohr            }
1661878f16fSAndreas Gohr        }
16714d99ec0SAndreas Gohr        return $this->dblink;
16814d99ec0SAndreas Gohr    }
1691878f16fSAndreas Gohr
17014d99ec0SAndreas Gohr    /**
17114d99ec0SAndreas Gohr     * Simple function to run a DB query
17214d99ec0SAndreas Gohr     */
17314d99ec0SAndreas Gohr    function runSQL($sql_string) {
17414d99ec0SAndreas Gohr        $link = $this->dbLink();
17514d99ec0SAndreas Gohr
17614d99ec0SAndreas Gohr        $result = mysql_db_query($this->conf['db_database'],$sql_string,$link);
17794171ff3SAndreas Gohr        if(!$result){
17814d99ec0SAndreas Gohr            msg('DB Error: '.mysql_error($link),-1);
1791878f16fSAndreas Gohr            return null;
1801878f16fSAndreas Gohr        }
1811878f16fSAndreas Gohr
1821878f16fSAndreas Gohr        $resultarray = array();
1831878f16fSAndreas Gohr
1841878f16fSAndreas Gohr        //mysql_db_query returns 1 on a insert statement -> no need to ask for results
1851878f16fSAndreas Gohr        if ($result != 1) {
1861878f16fSAndreas Gohr            for($i=0; $i< mysql_num_rows($result); $i++) {
1871878f16fSAndreas Gohr                $temparray = mysql_fetch_assoc($result);
1881878f16fSAndreas Gohr                $resultarray[]=$temparray;
1891878f16fSAndreas Gohr            }
1901878f16fSAndreas Gohr            mysql_free_result($result);
1911878f16fSAndreas Gohr        }
1921878f16fSAndreas Gohr
19314d99ec0SAndreas Gohr        if (mysql_insert_id($link)) {
19414d99ec0SAndreas Gohr            $resultarray = mysql_insert_id($link); //give back ID on insert
1951878f16fSAndreas Gohr        }
1961878f16fSAndreas Gohr
1971878f16fSAndreas Gohr        return $resultarray;
1981878f16fSAndreas Gohr    }
1991878f16fSAndreas Gohr
2001878f16fSAndreas Gohr    /**
20114d99ec0SAndreas Gohr     * Returns a short name for a User Agent and sets type, version and os info
2021878f16fSAndreas Gohr     */
20314d99ec0SAndreas Gohr    function ua_info($ua,&$type,&$ver,&$os){
20414d99ec0SAndreas Gohr        $ua = strtr($ua,' +','__');
20514d99ec0SAndreas Gohr        $ua = strtolower($ua);
20614d99ec0SAndreas Gohr
20714d99ec0SAndreas Gohr        // common browsers
20814d99ec0SAndreas Gohr        $regvermsie     = '/msie([+_ ]|)([\d\.]*)/i';
20914d99ec0SAndreas Gohr        $regvernetscape = '/netscape.?\/([\d\.]*)/i';
21014d99ec0SAndreas Gohr        $regverfirefox  = '/firefox\/([\d\.]*)/i';
21114d99ec0SAndreas Gohr        $regversvn      = '/svn\/([\d\.]*)/i';
21214d99ec0SAndreas Gohr        $regvermozilla  = '/mozilla(\/|)([\d\.]*)/i';
21314d99ec0SAndreas Gohr        $regnotie       = '/webtv|omniweb|opera/i';
21414d99ec0SAndreas Gohr        $regnotnetscape = '/gecko|compatible|opera|galeon|safari/i';
21514d99ec0SAndreas Gohr
21614d99ec0SAndreas Gohr        $name = '';
21714d99ec0SAndreas Gohr        # IE ?
21814d99ec0SAndreas Gohr        if(preg_match($regvermsie,$ua,$m) && !preg_match($regnotie,$ua)){
21914d99ec0SAndreas Gohr            $type = 'browser';
22014d99ec0SAndreas Gohr            $ver  = $m[2];
22114d99ec0SAndreas Gohr            $name = 'msie';
22214d99ec0SAndreas Gohr        }
22314d99ec0SAndreas Gohr        # Firefox ?
22414d99ec0SAndreas Gohr        elseif (preg_match($regverfirefox,$ua,$m)){
22514d99ec0SAndreas Gohr            $type = 'browser';
22614d99ec0SAndreas Gohr            $ver  = $m[1];
22714d99ec0SAndreas Gohr            $name = 'firefox';
22814d99ec0SAndreas Gohr        }
22914d99ec0SAndreas Gohr        # Subversion ?
23014d99ec0SAndreas Gohr        elseif (preg_match($regversvn,$ua,$m)){
23114d99ec0SAndreas Gohr            $type = 'rcs';
23214d99ec0SAndreas Gohr            $ver  = $m[1];
23314d99ec0SAndreas Gohr            $name = 'svn';
23414d99ec0SAndreas Gohr        }
23514d99ec0SAndreas Gohr        # Netscape 6.x, 7.x ... ?
23614d99ec0SAndreas Gohr        elseif (preg_match($regvernetscape,$ua,$m)){
23714d99ec0SAndreas Gohr            $type = 'browser';
23814d99ec0SAndreas Gohr            $ver  = $m[1];
23914d99ec0SAndreas Gohr            $name = 'netscape';
24014d99ec0SAndreas Gohr        }
24114d99ec0SAndreas Gohr        # Netscape 3.x, 4.x ... ?
24214d99ec0SAndreas Gohr        elseif(preg_match($regvermozilla,$ua,$m) && !preg_match($regnotnetscape,$ua)){
24314d99ec0SAndreas Gohr            $type = 'browser';
24414d99ec0SAndreas Gohr            $ver  = $m[2];
24514d99ec0SAndreas Gohr            $name = 'netscape';
24614d99ec0SAndreas Gohr        }else{
24714d99ec0SAndreas Gohr            include(dirname(__FILE__).'/inc/browsers.php');
24814d99ec0SAndreas Gohr            foreach($BrowsersSearchIDOrder as $regex){
24914d99ec0SAndreas Gohr                if(preg_match('/'.$regex.'/',$ua)){
25014d99ec0SAndreas Gohr                    // it's a browser!
25114d99ec0SAndreas Gohr                    $type = 'browser';
25214d99ec0SAndreas Gohr                    $name = strtolower($regex);
25314d99ec0SAndreas Gohr                    break;
25414d99ec0SAndreas Gohr                }
25514d99ec0SAndreas Gohr            }
25614d99ec0SAndreas Gohr        }
25714d99ec0SAndreas Gohr
25814d99ec0SAndreas Gohr        // check OS for browsers
25914d99ec0SAndreas Gohr        if($type == 'browser'){
26014d99ec0SAndreas Gohr            include(dirname(__FILE__).'/inc/operating_systems.php');
26114d99ec0SAndreas Gohr            foreach($OSSearchIDOrder as $regex){
26214d99ec0SAndreas Gohr                if(preg_match('/'.$regex.'/',$ua)){
26314d99ec0SAndreas Gohr                    $os = $OSHashID[$regex];
26414d99ec0SAndreas Gohr                    break;
26514d99ec0SAndreas Gohr                }
26614d99ec0SAndreas Gohr            }
26714d99ec0SAndreas Gohr
26814d99ec0SAndreas Gohr        }
26914d99ec0SAndreas Gohr
27014d99ec0SAndreas Gohr        // are we done now?
27114d99ec0SAndreas Gohr        if($name) return $name;
27214d99ec0SAndreas Gohr
27314d99ec0SAndreas Gohr        include(dirname(__FILE__).'/inc/robots.php');
27414d99ec0SAndreas Gohr        foreach($RobotsSearchIDOrder as $regex){
27514d99ec0SAndreas Gohr            if(preg_match('/'.$regex.'/',$ua)){
27614d99ec0SAndreas Gohr                    // it's a robot!
27714d99ec0SAndreas Gohr                    $type = 'robot';
27814d99ec0SAndreas Gohr                    return strtolower($regex);
27914d99ec0SAndreas Gohr            }
28014d99ec0SAndreas Gohr        }
28114d99ec0SAndreas Gohr
28214d99ec0SAndreas Gohr        // dunno
2831878f16fSAndreas Gohr        return '';
2841878f16fSAndreas Gohr    }
2851878f16fSAndreas Gohr
2861878f16fSAndreas Gohr    /**
28714d99ec0SAndreas Gohr     *
28814d99ec0SAndreas Gohr     * @fixme: put search engine queries in seperate table here
28914d99ec0SAndreas Gohr     */
29014d99ec0SAndreas Gohr    function log_search($referer,&$type){
29114d99ec0SAndreas Gohr        $referer = strtr($referer,' +','__');
29214d99ec0SAndreas Gohr        $referer = strtolower($referer);
29314d99ec0SAndreas Gohr
29414d99ec0SAndreas Gohr        include(dirname(__FILE__).'/inc/search_engines.php');
29514d99ec0SAndreas Gohr
29614d99ec0SAndreas Gohr        foreach($SearchEnginesSearchIDOrder as $regex){
29714d99ec0SAndreas Gohr            if(preg_match('/'.$regex.'/',$referer)){
29814d99ec0SAndreas Gohr                if(!$NotSearchEnginesKeys[$regex] ||
29914d99ec0SAndreas Gohr                   !preg_match('/'.$NotSearchEnginesKeys[$regex].'/',$referer)){
30014d99ec0SAndreas Gohr                    // it's a search engine!
30114d99ec0SAndreas Gohr                    $type = 'search';
30214d99ec0SAndreas Gohr                    break;
30314d99ec0SAndreas Gohr                }
30414d99ec0SAndreas Gohr            }
30514d99ec0SAndreas Gohr        }
30614d99ec0SAndreas Gohr        if($type != 'search') return; // we're done here
30714d99ec0SAndreas Gohr
30814d99ec0SAndreas Gohr        #fixme now do the keyword magic!
30914d99ec0SAndreas Gohr    }
31014d99ec0SAndreas Gohr
31114d99ec0SAndreas Gohr    /**
31214d99ec0SAndreas Gohr     * Resolve IP to country/city
31314d99ec0SAndreas Gohr     */
31414d99ec0SAndreas Gohr    function log_ip($ip){
31514d99ec0SAndreas Gohr        // check if IP already known and up-to-date
31614d99ec0SAndreas Gohr        $sql = "SELECT ip
31714d99ec0SAndreas Gohr                  FROM ".$this->getConf('db_prefix')."iplocation
31814d99ec0SAndreas Gohr                 WHERE ip ='".addslashes($ip)."'
31914d99ec0SAndreas Gohr                   AND lastupd > DATE_SUB(CURDATE(),INTERVAL 30 DAY)";
32014d99ec0SAndreas Gohr        $result = $this->runSQL($sql);
32114d99ec0SAndreas Gohr        if($result[0]['ip']) return;
32214d99ec0SAndreas Gohr
32314d99ec0SAndreas Gohr        $http = new DokuHTTPClient();
32414d99ec0SAndreas Gohr        $http->timeout = 10;
32514d99ec0SAndreas Gohr        $data = $http->get('http://api.hostip.info/get_html.php?ip='.$ip);
32614d99ec0SAndreas Gohr
32714d99ec0SAndreas Gohr        if(preg_match('/^Country: (.*?) \((.*?)\)\nCity: (.*?)$/s',$data,$match)){
32814d99ec0SAndreas Gohr            $country = addslashes(trim($match[1]));
32914d99ec0SAndreas Gohr            $code    = addslashes(strtolower(trim($match[2])));
33014d99ec0SAndreas Gohr            $city    = addslashes(trim($match[3]));
33114d99ec0SAndreas Gohr            $host    = addslashes(gethostbyaddr($ip));
33214d99ec0SAndreas Gohr            $ip      = addslashes($ip);
33314d99ec0SAndreas Gohr
33414d99ec0SAndreas Gohr            $sql = "REPLACE INTO ".$this->getConf('db_prefix')."iplocation
33514d99ec0SAndreas Gohr                        SET ip = '$ip',
33614d99ec0SAndreas Gohr                            country = '$country',
33714d99ec0SAndreas Gohr                            code    = '$code',
33814d99ec0SAndreas Gohr                            city    = '$city',
33914d99ec0SAndreas Gohr                            host    = '$host'";
34014d99ec0SAndreas Gohr            $this->runSQL($sql);
34114d99ec0SAndreas Gohr        }
34214d99ec0SAndreas Gohr    }
34314d99ec0SAndreas Gohr
34414d99ec0SAndreas Gohr    /**
3451878f16fSAndreas Gohr     * log a page access
3461878f16fSAndreas Gohr     *
3471878f16fSAndreas Gohr     * called from log.php
3481878f16fSAndreas Gohr     */
3491878f16fSAndreas Gohr    function log_access(){
35094171ff3SAndreas Gohr        if(!$_REQUEST['p']) return;
35194171ff3SAndreas Gohr
35214d99ec0SAndreas Gohr        # FIXME check referer against blacklist and drop logging for bad boys
35314d99ec0SAndreas Gohr
35414d99ec0SAndreas Gohr        // handle referer
35514d99ec0SAndreas Gohr        $referer = trim($_REQUEST['r']);
35614d99ec0SAndreas Gohr        if($referer){
35714d99ec0SAndreas Gohr            $ref     = addslashes($referer);
35814d99ec0SAndreas Gohr            $ref_md5 = ($ref) ? md5($referer) : '';
35914d99ec0SAndreas Gohr            if(strpos($referer,DOKU_URL) === 0){
36014d99ec0SAndreas Gohr                $ref_type = 'internal';
36114d99ec0SAndreas Gohr            }else{
36214d99ec0SAndreas Gohr                $ref_type = 'external';
36314d99ec0SAndreas Gohr                $this->log_search($referer,$ref_type);
36414d99ec0SAndreas Gohr            }
36514d99ec0SAndreas Gohr        }else{
36614d99ec0SAndreas Gohr            $ref      = '';
36714d99ec0SAndreas Gohr            $ref_md5  = '';
36814d99ec0SAndreas Gohr            $ref_type = '';
36914d99ec0SAndreas Gohr        }
37014d99ec0SAndreas Gohr
37114d99ec0SAndreas Gohr        // handle user agent
37214d99ec0SAndreas Gohr        $agent   = trim($_SERVER['HTTP_USER_AGENT']);
37314d99ec0SAndreas Gohr
37414d99ec0SAndreas Gohr        $ua      = addslashes($agent);
37514d99ec0SAndreas Gohr        $ua_type = '';
37614d99ec0SAndreas Gohr        $ua_ver  = '';
37714d99ec0SAndreas Gohr        $os      = '';
37814d99ec0SAndreas Gohr        $ua_info = addslashes($this->ua_info($agent,$ua_type,$ua_ver,$os));
37914d99ec0SAndreas Gohr
3801878f16fSAndreas Gohr        $page    = addslashes($_REQUEST['p']);
3811878f16fSAndreas Gohr        $ip      = addslashes($_SERVER['REMOTE_ADDR']);
3821878f16fSAndreas Gohr        $sx      = (int) $_REQUEST['sx'];
3831878f16fSAndreas Gohr        $sy      = (int) $_REQUEST['sy'];
3841878f16fSAndreas Gohr        $vx      = (int) $_REQUEST['vx'];
3851878f16fSAndreas Gohr        $vy      = (int) $_REQUEST['vy'];
3861878f16fSAndreas Gohr        $user    = addslashes($_SERVER['REMOTE_USER']);
3871878f16fSAndreas Gohr        $session = addslashes(session_id());
3881878f16fSAndreas Gohr
38994171ff3SAndreas Gohr        $sql  = "INSERT DELAYED INTO ".$this->getConf('db_prefix')."access
3901878f16fSAndreas Gohr                    SET page     = '$page',
3911878f16fSAndreas Gohr                        ip       = '$ip',
3921878f16fSAndreas Gohr                        ua       = '$ua',
3931878f16fSAndreas Gohr                        ua_info  = '$ua_info',
39414d99ec0SAndreas Gohr                        ua_type  = '$ua_type',
39514d99ec0SAndreas Gohr                        ua_ver   = '$ua_ver',
39614d99ec0SAndreas Gohr                        os       = '$os',
3971878f16fSAndreas Gohr                        ref      = '$ref',
39894171ff3SAndreas Gohr                        ref_md5  = '$ref_md5',
39914d99ec0SAndreas Gohr                        ref_type = '$ref_type',
4001878f16fSAndreas Gohr                        screen_x = '$sx',
4011878f16fSAndreas Gohr                        screen_y = '$sy',
4021878f16fSAndreas Gohr                        view_x   = '$vx',
4031878f16fSAndreas Gohr                        view_y   = '$vy',
4041878f16fSAndreas Gohr                        user     = '$user',
4051878f16fSAndreas Gohr                        session  = '$session'";
4061878f16fSAndreas Gohr        $ok = $this->runSQL($sql);
4071878f16fSAndreas Gohr        if(is_null($ok)){
4081878f16fSAndreas Gohr            global $MSG;
4091878f16fSAndreas Gohr            print_r($MSG);
4101878f16fSAndreas Gohr        }
41114d99ec0SAndreas Gohr
41214d99ec0SAndreas Gohr        // resolve the IP
41314d99ec0SAndreas Gohr        $this->log_ip($_SERVER['REMOTE_ADDR']);
4141878f16fSAndreas Gohr    }
4151878f16fSAndreas Gohr
4161878f16fSAndreas Gohr    /**
4171878f16fSAndreas Gohr     * Just send a 1x1 pixel blank gif to the browser
4181878f16fSAndreas Gohr     *
4191878f16fSAndreas Gohr     * @called from log.php
4201878f16fSAndreas Gohr     *
4211878f16fSAndreas Gohr     * @author Andreas Gohr <andi@splitbrain.org>
4221878f16fSAndreas Gohr     * @author Harry Fuecks <fuecks@gmail.com>
4231878f16fSAndreas Gohr     */
4241878f16fSAndreas Gohr    function sendGIF(){
4251878f16fSAndreas Gohr        $img = base64_decode('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAEALAAAAAABAAEAAAIBTAA7');
4261878f16fSAndreas Gohr        header('Content-Type: image/gif');
4271878f16fSAndreas Gohr        header('Content-Length: '.strlen($img));
4281878f16fSAndreas Gohr        header('Connection: Close');
4291878f16fSAndreas Gohr        print $img;
4301878f16fSAndreas Gohr        flush();
4311878f16fSAndreas Gohr        // Browser should drop connection after this
4321878f16fSAndreas Gohr        // Thinks it's got the whole image
4331878f16fSAndreas Gohr    }
4341878f16fSAndreas Gohr
4351878f16fSAndreas Gohr}
436