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