xref: /plugin/statistics/admin.php (revision 259897e1d9b79981a90f65c7b397d8864c166b64)
11878f16fSAndreas Gohr<?php
21878f16fSAndreas Gohr/**
31878f16fSAndreas Gohr * statistics plugin
41878f16fSAndreas Gohr *
51878f16fSAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
66b6f8822SAndreas Gohr * @author     Andreas Gohr <gohr@splitbrain.org>
71878f16fSAndreas Gohr */
81878f16fSAndreas Gohr
91878f16fSAndreas Gohr// must be run within Dokuwiki
101878f16fSAndreas Gohrif(!defined('DOKU_INC')) die();
111878f16fSAndreas Gohr
122998b1f6SAndreas Gohr
131878f16fSAndreas Gohr/**
141878f16fSAndreas Gohr * All DokuWiki plugins to extend the admin function
151878f16fSAndreas Gohr * need to inherit from this class
161878f16fSAndreas Gohr */
171878f16fSAndreas Gohrclass admin_plugin_statistics extends DokuWiki_Admin_Plugin {
18a901d721SAndreas Gohr    public    $dblink = null;
19a901d721SAndreas Gohr    protected $opt    = '';
20a901d721SAndreas Gohr    protected $from   = '';
21a901d721SAndreas Gohr    protected $to     = '';
22a901d721SAndreas Gohr    protected $start  = '';
23a901d721SAndreas Gohr    protected $tlimit = '';
24a901d721SAndreas Gohr
25a901d721SAndreas Gohr    /**
26a901d721SAndreas Gohr     * Available statistic pages
27a901d721SAndreas Gohr     */
28a901d721SAndreas Gohr    protected $pages  = array('dashboard','page','referer','newreferer',
295bccfe87SAndreas Gohr                              'outlinks','searchengines','searchphrases',
305bccfe87SAndreas Gohr                              'searchwords', 'internalsearchphrases',
315bccfe87SAndreas Gohr                              'internalsearchwords','browsers','os',
3225446aa2SAndreas Gohr                              'countries','resolution','viewport');
331878f16fSAndreas Gohr
341878f16fSAndreas Gohr    /**
356b6f8822SAndreas Gohr     * Initialize the helper
366b6f8822SAndreas Gohr     */
376b6f8822SAndreas Gohr    public function __construct() {
386b6f8822SAndreas Gohr        $this->hlp = plugin_load('helper','statistics');
396b6f8822SAndreas Gohr    }
406b6f8822SAndreas Gohr
416b6f8822SAndreas Gohr    /**
421878f16fSAndreas Gohr     * Access for managers allowed
431878f16fSAndreas Gohr     */
446b6f8822SAndreas Gohr    public function forAdminOnly(){
451878f16fSAndreas Gohr        return false;
461878f16fSAndreas Gohr    }
471878f16fSAndreas Gohr
481878f16fSAndreas Gohr    /**
491878f16fSAndreas Gohr     * return sort order for position in admin menu
501878f16fSAndreas Gohr     */
516b6f8822SAndreas Gohr    public function getMenuSort() {
526b6f8822SAndreas Gohr        return 350;
531878f16fSAndreas Gohr    }
541878f16fSAndreas Gohr
551878f16fSAndreas Gohr    /**
561878f16fSAndreas Gohr     * handle user request
571878f16fSAndreas Gohr     */
586b6f8822SAndreas Gohr    public function handle() {
59264f1744SAndreas Gohr        $this->opt = preg_replace('/[^a-z]+/','',$_REQUEST['opt']);
60a901d721SAndreas Gohr        if(!in_array($this->opt,$this->pages)) $this->opt = 'dashboard';
61a901d721SAndreas Gohr
6295eb68e6SAndreas Gohr        $this->start = (int) $_REQUEST['s'];
63e8699bceSAndreas Gohr        $this->setTimeframe($_REQUEST['f'],$_REQUEST['t']);
64e8699bceSAndreas Gohr    }
6595eb68e6SAndreas Gohr
66e8699bceSAndreas Gohr    /**
67e8699bceSAndreas Gohr     * set limit clause
68e8699bceSAndreas Gohr     */
696b6f8822SAndreas Gohr    public function setTimeframe($from,$to){
70264f1744SAndreas Gohr        // fixme add better sanity checking here:
71e8699bceSAndreas Gohr        $from = preg_replace('/[^\d\-]+/','',$from);
72e8699bceSAndreas Gohr        $to   = preg_replace('/[^\d\-]+/','',$to);
73e8699bceSAndreas Gohr        if(!$from) $from = date('Y-m-d');
74e8699bceSAndreas Gohr        if(!$to)   $to   = date('Y-m-d');
75264f1744SAndreas Gohr
76264f1744SAndreas Gohr        //setup limit clause
772ee939eeSAndreas Gohr        $tlimit = "A.dt >= '$from 00:00:00' AND A.dt <= '$to 23:59:59'";
78e8699bceSAndreas Gohr        $this->tlimit = $tlimit;
79e8699bceSAndreas Gohr        $this->from   = $from;
80e8699bceSAndreas Gohr        $this->to     = $to;
811878f16fSAndreas Gohr    }
821878f16fSAndreas Gohr
831878f16fSAndreas Gohr    /**
8479b4a855SAndreas Gohr     * Output the Statistics
851878f16fSAndreas Gohr     */
861878f16fSAndreas Gohr    function html() {
871d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
880c3b1e44SAndreas Gohr        echo '<h1>'.$this->getLang('menu').'</h1>';
89264f1744SAndreas Gohr        $this->html_timeselect();
90441bfb8eSAndreas Gohr        tpl_flush();
91264f1744SAndreas Gohr
9279b4a855SAndreas Gohr        $method = 'html_'.$this->opt;
9379b4a855SAndreas Gohr        if(method_exists($this,$method)){
94a901d721SAndreas Gohr            echo '<div class="plg_stats_'.$this->opt.'">';
95a901d721SAndreas Gohr            echo '<h2>'.$this->getLang($this->opt).'</h2>';
9679b4a855SAndreas Gohr            $this->$method();
97a901d721SAndreas Gohr            echo '</div>';
9814d99ec0SAndreas Gohr        }
991d2d78ccSAndreas Gohr        echo '</div>';
10014d99ec0SAndreas Gohr    }
10114d99ec0SAndreas Gohr
1026b6f8822SAndreas Gohr    /**
1036b6f8822SAndreas Gohr     * Return the TOC
1046b6f8822SAndreas Gohr     *
1056b6f8822SAndreas Gohr     * @return array
1066b6f8822SAndreas Gohr     */
10747ffcf7dSAndreas Gohr    function getTOC(){
10847ffcf7dSAndreas Gohr        $toc = array();
109a901d721SAndreas Gohr        foreach($this->pages as $page){
11047ffcf7dSAndreas Gohr            $toc[] = array(
11147ffcf7dSAndreas Gohr                    'link'  => '?do=admin&amp;page=statistics&amp;opt='.$page.'&amp;f='.$this->from.'&amp;t='.$this->to,
11247ffcf7dSAndreas Gohr                    'title' => $this->getLang($page),
11347ffcf7dSAndreas Gohr                    'level' => 1,
11447ffcf7dSAndreas Gohr                    'type'  => 'ul'
11547ffcf7dSAndreas Gohr            );
11647ffcf7dSAndreas Gohr        }
11747ffcf7dSAndreas Gohr        return $toc;
1189da6395dSAndreas Gohr    }
1199da6395dSAndreas Gohr
120dc7b1e5eSAndreas Gohr
121dc7b1e5eSAndreas Gohr    function html_graph($name,$width,$height){
122dc7b1e5eSAndreas Gohr        $url = DOKU_BASE.'lib/plugins/statistics/img.php?img='.$name.
123dc7b1e5eSAndreas Gohr               '&amp;f='.$this->from.'&amp;t='.$this->to;
124dc7b1e5eSAndreas Gohr        echo '<img src="'.$url.'" class="graph" width="'.$width.'" height="'.$height.'"/>';
125dc7b1e5eSAndreas Gohr    }
126dc7b1e5eSAndreas Gohr
127dc7b1e5eSAndreas Gohr
1286b6f8822SAndreas Gohr    /**
1296b6f8822SAndreas Gohr     * Outputs pagination links
1306b6f8822SAndreas Gohr     *
1316b6f8822SAndreas Gohr     * @param type $limit
1326b6f8822SAndreas Gohr     * @param type $next
1336b6f8822SAndreas Gohr     */
1342507f8e0SAndreas Gohr    function html_pager($limit,$next){
1352507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1362507f8e0SAndreas Gohr
1372507f8e0SAndreas Gohr        if($this->start > 0){
1382507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
1390c3b1e44SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$this->from.'&amp;t='.$this->to.'&amp;s='.$go.'" class="prev">'.$this->getLang('prev').'</a>';
1402507f8e0SAndreas Gohr        }
1412507f8e0SAndreas Gohr
1422507f8e0SAndreas Gohr        if($next){
1432507f8e0SAndreas Gohr            $go = $this->start + $limit;
1440c3b1e44SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$this->from.'&amp;t='.$this->to.'&amp;s='.$go.'" class="next">'.$this->getLang('next').'</a>';
1452507f8e0SAndreas Gohr        }
1462507f8e0SAndreas Gohr        echo '</div>';
1472507f8e0SAndreas Gohr    }
1482507f8e0SAndreas Gohr
149264f1744SAndreas Gohr    /**
150264f1744SAndreas Gohr     * Print the time selection menu
151264f1744SAndreas Gohr     */
15214d99ec0SAndreas Gohr    function html_timeselect(){
1536985b606SAndreas Gohr        $today   = date('Y-m-d');
1546985b606SAndreas Gohr        $last1   = date('Y-m-d',time()-(60*60*24));
1556985b606SAndreas Gohr        $last7   = date('Y-m-d',time()-(60*60*24*7));
1566985b606SAndreas Gohr        $last30  = date('Y-m-d',time()-(60*60*24*30));
15714d99ec0SAndreas Gohr
158264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
1596985b606SAndreas Gohr        echo '<span>'.$this->getLang('time_select').'</span> ';
160264f1744SAndreas Gohr
161264f1744SAndreas Gohr        echo '<form action="" method="get">';
162264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
163264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
164264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="'.$this->opt.'" />';
165264f1744SAndreas Gohr        echo '<input type="text" name="f" value="'.$this->from.'" class="edit" />';
166264f1744SAndreas Gohr        echo '<input type="text" name="t" value="'.$this->to.'" class="edit" />';
167264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
16814d99ec0SAndreas Gohr        echo '</form>';
169264f1744SAndreas Gohr
1706985b606SAndreas Gohr        echo '<ul>';
1716985b606SAndreas Gohr        foreach(array('today','last1','last7','last30') as $time){
1726985b606SAndreas Gohr            echo '<li>';
1736985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$$time.'&amp;t='.$today.'">';
1746985b606SAndreas Gohr            echo $this->getLang('time_'.$time);
1756985b606SAndreas Gohr            echo '</a>';
1766985b606SAndreas Gohr            echo '</li>';
1776985b606SAndreas Gohr        }
1786985b606SAndreas Gohr        echo '</ul>';
1796985b606SAndreas Gohr
180264f1744SAndreas Gohr        echo '</div>';
18114d99ec0SAndreas Gohr    }
18214d99ec0SAndreas Gohr
18314d99ec0SAndreas Gohr
184f5f32cbfSAndreas Gohr    /**
185f5f32cbfSAndreas Gohr     * Print an introductionary screen
186f5f32cbfSAndreas Gohr     */
18714d99ec0SAndreas Gohr    function html_dashboard(){
188878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_dashboard').'</p>';
1892812a751SAndreas Gohr
1902812a751SAndreas Gohr        // general info
1912812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
1926b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
1931d2d78ccSAndreas Gohr
1941d2d78ccSAndreas Gohr        echo '<ul class="left">';
1951d2d78ccSAndreas Gohr        foreach(array('pageviews','sessions','visitors','users','logins') as $name){
196eabe0d07SAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
197eabe0d07SAndreas Gohr        }
1982812a751SAndreas Gohr        echo '</ul>';
1991d2d78ccSAndreas Gohr
2001d2d78ccSAndreas Gohr        echo '<ul class="left">';
2011d2d78ccSAndreas Gohr        foreach(array('bouncerate','timespent','avgpages','newvisitors','registrations') as $name){
2021d2d78ccSAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
2031d2d78ccSAndreas Gohr        }
2041d2d78ccSAndreas Gohr        echo '</ul>';
2051d2d78ccSAndreas Gohr
206*259897e1SAndreas Gohr        $this->html_graph('dashboardviews',700,280);
207*259897e1SAndreas Gohr        $this->html_graph('dashboardwiki',700,280);
2082812a751SAndreas Gohr        echo '</div>';
2092812a751SAndreas Gohr
21014d99ec0SAndreas Gohr
21187d5e44bSAndreas Gohr        // top pages today
212264f1744SAndreas Gohr        echo '<div>';
213dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_mostpopular').'</h2>';
2146b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,15);
2152812a751SAndreas Gohr        $this->html_resulttable($result);
2160c3b1e44SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=page&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">'.$this->getLang('more').'</a>';
217264f1744SAndreas Gohr        echo '</div>';
21887d5e44bSAndreas Gohr
21987d5e44bSAndreas Gohr        // top referer today
220264f1744SAndreas Gohr        echo '<div>';
221dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_newincoming').'</h2>';
2226b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,15);
2232812a751SAndreas Gohr        $this->html_resulttable($result);
2240c3b1e44SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=newreferer&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">'.$this->getLang('more').'</a>';
225264f1744SAndreas Gohr        echo '</div>';
22654f6c432SAndreas Gohr
22729dea504SAndreas Gohr        // top searches today
228264f1744SAndreas Gohr        echo '<div>';
229dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_topsearch').'</h2>';
2306b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchphrases($this->tlimit,$this->start,15);
23129dea504SAndreas Gohr        $this->html_resulttable($result);
2320c3b1e44SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=searchphrases&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">'.$this->getLang('more').'</a>';
233264f1744SAndreas Gohr        echo '</div>';
23414d99ec0SAndreas Gohr    }
23514d99ec0SAndreas Gohr
236c67866d1SAndreas Gohr    function html_countries(){
237878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_countries').'</p>';
238878be5c9SAndreas Gohr        $this->html_graph('countries',400,200);
2396b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit,$this->start,150);
2402507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2419da6395dSAndreas Gohr    }
2429da6395dSAndreas Gohr
2439da6395dSAndreas Gohr    function html_page(){
244878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_page').'</p>';
2456b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,150);
2462507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2479da6395dSAndreas Gohr    }
2489da6395dSAndreas Gohr
2494f41a2ccSAndreas Gohr    function html_browsers(){
250878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_browsers').'</p>';
251878be5c9SAndreas Gohr        $this->html_graph('browsers',400,200);
2526b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit,$this->start,150,true);
2532507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
25475fa767dSAndreas Gohr    }
25575fa767dSAndreas Gohr
256bd4217d3SAndreas Gohr    function html_os(){
257878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_os').'</p>';
258878be5c9SAndreas Gohr        $this->html_graph('os',400,200);
2596b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit,$this->start,150,true);
2602507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
261bd4217d3SAndreas Gohr    }
262bd4217d3SAndreas Gohr
2639da6395dSAndreas Gohr    function html_referer(){
2646b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2652812a751SAndreas Gohr
2662812a751SAndreas Gohr        $all    = $result['search']+$result['external']+$result['direct'];
2672812a751SAndreas Gohr
26894023548SAndreas Gohr        if($all){
269878be5c9SAndreas Gohr            printf('<p>'.$this->getLang('intro_referer').'</p>',
270878be5c9SAndreas Gohr                   $all,$result['direct'],(100*$result['direct']/$all),
2712812a751SAndreas Gohr                   $result['search'],(100*$result['search']/$all),$result['external'],
2722812a751SAndreas Gohr                   (100*$result['external']/$all));
27394023548SAndreas Gohr        }
2742812a751SAndreas Gohr
2756b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit,$this->start,150);
2762507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2779da6395dSAndreas Gohr    }
2789da6395dSAndreas Gohr
279e7a2f1e0SAndreas Gohr    function html_newreferer(){
280878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_newreferer').'</p>';
281e7a2f1e0SAndreas Gohr
2826b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,150);
2832507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
284e7a2f1e0SAndreas Gohr    }
285e7a2f1e0SAndreas Gohr
286e25286daSAndreas Gohr    function html_outlinks(){
287878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_outlinks').'</p>';
2886b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit,$this->start,150);
289e25286daSAndreas Gohr        $this->html_resulttable($result,'',150);
290e25286daSAndreas Gohr    }
291e25286daSAndreas Gohr
29212dcdeccSAndreas Gohr    function html_searchphrases(){
293878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchphrases').'</p>';
2945bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,150);
29512dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
29612dcdeccSAndreas Gohr    }
29712dcdeccSAndreas Gohr
29812dcdeccSAndreas Gohr    function html_searchwords(){
299878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchwords').'</p>';
3005bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true,$this->tlimit,$this->start,150);
3015bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
3025bccfe87SAndreas Gohr    }
3035bccfe87SAndreas Gohr
3045bccfe87SAndreas Gohr    function html_internalsearchphrases(){
305878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_internalsearchphrases').'</p>';
3065bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false,$this->tlimit,$this->start,150);
3075bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
3085bccfe87SAndreas Gohr    }
3095bccfe87SAndreas Gohr
3105bccfe87SAndreas Gohr    function html_internalsearchwords(){
311878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_internalsearchwords').'</p>';
3125bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false,$this->tlimit,$this->start,150);
31312dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
31412dcdeccSAndreas Gohr    }
31512dcdeccSAndreas Gohr
31612dcdeccSAndreas Gohr    function html_searchengines(){
317878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchengines').'</p>';
31825b71d4bSAndreas Gohr        $this->html_graph('searchengines',400,200);
3196b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit,$this->start,150);
32012dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
32112dcdeccSAndreas Gohr    }
32212dcdeccSAndreas Gohr
323c73e16f1SAndreas Gohr    function html_resolution(){
32425446aa2SAndreas Gohr        echo '<p>'.$this->getLang('intro_resolution').'</p>';
32525446aa2SAndreas Gohr        $this->html_graph('resolution',650,490);
326307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit,$this->start,150);
327307baf3fSAndreas Gohr        $this->html_resulttable($result,'',150);
32825446aa2SAndreas Gohr    }
329307baf3fSAndreas Gohr
33025446aa2SAndreas Gohr    function html_viewport(){
33125446aa2SAndreas Gohr        echo '<p>'.$this->getLang('intro_viewport').'</p>';
33225446aa2SAndreas Gohr        $this->html_graph('viewport',650,490);
33325446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit,$this->start,150);
33425446aa2SAndreas Gohr        $this->html_resulttable($result,'',150);
335c73e16f1SAndreas Gohr    }
3369da6395dSAndreas Gohr
3379da6395dSAndreas Gohr
33814d99ec0SAndreas Gohr    /**
33914d99ec0SAndreas Gohr     * Display a result in a HTML table
34014d99ec0SAndreas Gohr     */
3412507f8e0SAndreas Gohr    function html_resulttable($result,$header='',$pager=0){
34214d99ec0SAndreas Gohr        echo '<table>';
3432812a751SAndreas Gohr        if(is_array($header)){
34414d99ec0SAndreas Gohr            echo '<tr>';
34514d99ec0SAndreas Gohr            foreach($header as $h){
34614d99ec0SAndreas Gohr                echo '<th>'.hsc($h).'</th>';
34714d99ec0SAndreas Gohr            }
34814d99ec0SAndreas Gohr            echo '</tr>';
3492812a751SAndreas Gohr        }
35014d99ec0SAndreas Gohr
3512507f8e0SAndreas Gohr        $count = 0;
3522ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row){
35314d99ec0SAndreas Gohr            echo '<tr>';
35414d99ec0SAndreas Gohr            foreach($row as $k => $v){
355f3818071SAndreas Gohr                if($k == 'res_x') continue;
356f3818071SAndreas Gohr                if($k == 'res_y') continue;
357f3818071SAndreas Gohr
3582812a751SAndreas Gohr                echo '<td class="plg_stats_X'.$k.'">';
35914d99ec0SAndreas Gohr                if($k == 'page'){
36014d99ec0SAndreas Gohr                    echo '<a href="'.wl($v).'" class="wikilink1">';
36114d99ec0SAndreas Gohr                    echo hsc($v);
36214d99ec0SAndreas Gohr                    echo '</a>';
36314d99ec0SAndreas Gohr                }elseif($k == 'url'){
36454f6c432SAndreas Gohr                    $url = hsc($v);
36583b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/','',$url);
3662812a751SAndreas Gohr                    if(strlen($url) > 45){
3672812a751SAndreas Gohr                        $url = substr($url,0,30).' &hellip; '.substr($url,-15);
36854f6c432SAndreas Gohr                    }
36914d99ec0SAndreas Gohr                    echo '<a href="'.$v.'" class="urlextern">';
37054f6c432SAndreas Gohr                    echo $url;
37114d99ec0SAndreas Gohr                    echo '</a>';
3725bccfe87SAndreas Gohr                }elseif($k == 'ilookup'){
3735bccfe87SAndreas Gohr                    echo '<a href="'.wl('',array('id'=>$v,'do'=>'search')).'">Search</a>';
37429dea504SAndreas Gohr                }elseif($k == 'lookup'){
37529dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q='.rawurlencode($v).'">';
37613a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
37729dea504SAndreas Gohr                    echo '</a> ';
37829dea504SAndreas Gohr
37929dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p='.rawurlencode($v).'">';
38013a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
38129dea504SAndreas Gohr                    echo '</a> ';
38229dea504SAndreas Gohr
38313a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q='.rawurlencode($v).'">';
38413a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
38529dea504SAndreas Gohr                    echo '</a> ';
38629dea504SAndreas Gohr
38712dcdeccSAndreas Gohr                }elseif($k == 'engine'){
38813a86c14SAndreas Gohr                    include_once(dirname(__FILE__).'/inc/searchengines.php');
38913a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])){
39013a86c14SAndreas Gohr                        echo '<a href="'.$SEARCHENGINEINFO[$v][1].'">'.$SEARCHENGINEINFO[$v][0].'</a>';
39113a86c14SAndreas Gohr                    }else{
39213a86c14SAndreas Gohr                        echo hsc(ucwords($v));
39313a86c14SAndreas Gohr                    }
39413a86c14SAndreas Gohr                }elseif($k == 'eflag'){
39513a86c14SAndreas Gohr                    $this->html_icon('search',$v);
39675fa767dSAndreas Gohr                }elseif($k == 'bflag'){
39713a86c14SAndreas Gohr                    $this->html_icon('browser',$v);
398bd4217d3SAndreas Gohr                }elseif($k == 'osflag'){
39913a86c14SAndreas Gohr                    $this->html_icon('os',$v);
40075fa767dSAndreas Gohr                }elseif($k == 'cflag'){
40113a86c14SAndreas Gohr                    $this->html_icon('flags',$v);
40214d99ec0SAndreas Gohr                }elseif($k == 'html'){
40314d99ec0SAndreas Gohr                    echo $v;
40414d99ec0SAndreas Gohr                }else{
40514d99ec0SAndreas Gohr                    echo hsc($v);
40614d99ec0SAndreas Gohr                }
40714d99ec0SAndreas Gohr                echo '</td>';
40814d99ec0SAndreas Gohr            }
40914d99ec0SAndreas Gohr            echo '</tr>';
4102507f8e0SAndreas Gohr
4112507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4122507f8e0SAndreas Gohr            $count++;
41314d99ec0SAndreas Gohr        }
41414d99ec0SAndreas Gohr        echo '</table>';
4152507f8e0SAndreas Gohr
4162507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager,count($result) > $pager);
4171878f16fSAndreas Gohr    }
4181878f16fSAndreas Gohr
41913a86c14SAndreas Gohr    function html_icon($type,$value){
42013a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/','',$value));
42113a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/'.$type.'/'.$value.'.png';
42213a86c14SAndreas Gohr        if(file_exists(DOKU_INC.$file)){
42313a86c14SAndreas Gohr            echo '<img src="'.DOKU_BASE.$file.'" alt="'.hsc($value).'" width="16" height="16" />';
42413a86c14SAndreas Gohr        }
42513a86c14SAndreas Gohr    }
4261878f16fSAndreas Gohr}
427