xref: /plugin/statistics/admin.php (revision dffb869bc12e0394991303b57a99fb60d9805e14)
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){
703bf3de81SAndreas Gohr        $this->tlimit = $this->hlp->Query()->mktlimit($from,$to);
71e8699bceSAndreas Gohr        $this->from   = $from;
72e8699bceSAndreas Gohr        $this->to     = $to;
731878f16fSAndreas Gohr    }
741878f16fSAndreas Gohr
751878f16fSAndreas Gohr    /**
7679b4a855SAndreas Gohr     * Output the Statistics
771878f16fSAndreas Gohr     */
781878f16fSAndreas Gohr    function html() {
791d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
800c3b1e44SAndreas Gohr        echo '<h1>'.$this->getLang('menu').'</h1>';
81264f1744SAndreas Gohr        $this->html_timeselect();
82441bfb8eSAndreas Gohr        tpl_flush();
83264f1744SAndreas Gohr
8479b4a855SAndreas Gohr        $method = 'html_'.$this->opt;
8579b4a855SAndreas Gohr        if(method_exists($this,$method)){
86a901d721SAndreas Gohr            echo '<div class="plg_stats_'.$this->opt.'">';
87a901d721SAndreas Gohr            echo '<h2>'.$this->getLang($this->opt).'</h2>';
8879b4a855SAndreas Gohr            $this->$method();
89a901d721SAndreas Gohr            echo '</div>';
9014d99ec0SAndreas Gohr        }
911d2d78ccSAndreas Gohr        echo '</div>';
9214d99ec0SAndreas Gohr    }
9314d99ec0SAndreas Gohr
946b6f8822SAndreas Gohr    /**
956b6f8822SAndreas Gohr     * Return the TOC
966b6f8822SAndreas Gohr     *
976b6f8822SAndreas Gohr     * @return array
986b6f8822SAndreas Gohr     */
9947ffcf7dSAndreas Gohr    function getTOC(){
10047ffcf7dSAndreas Gohr        $toc = array();
101a901d721SAndreas Gohr        foreach($this->pages as $page){
10247ffcf7dSAndreas Gohr            $toc[] = array(
10347ffcf7dSAndreas Gohr                    'link'  => '?do=admin&amp;page=statistics&amp;opt='.$page.'&amp;f='.$this->from.'&amp;t='.$this->to,
10447ffcf7dSAndreas Gohr                    'title' => $this->getLang($page),
10547ffcf7dSAndreas Gohr                    'level' => 1,
10647ffcf7dSAndreas Gohr                    'type'  => 'ul'
10747ffcf7dSAndreas Gohr            );
10847ffcf7dSAndreas Gohr        }
10947ffcf7dSAndreas Gohr        return $toc;
1109da6395dSAndreas Gohr    }
1119da6395dSAndreas Gohr
112dc7b1e5eSAndreas Gohr
113dc7b1e5eSAndreas Gohr    function html_graph($name,$width,$height){
114dc7b1e5eSAndreas Gohr        $url = DOKU_BASE.'lib/plugins/statistics/img.php?img='.$name.
115dc7b1e5eSAndreas Gohr               '&amp;f='.$this->from.'&amp;t='.$this->to;
116dc7b1e5eSAndreas Gohr        echo '<img src="'.$url.'" class="graph" width="'.$width.'" height="'.$height.'"/>';
117dc7b1e5eSAndreas Gohr    }
118dc7b1e5eSAndreas Gohr
119dc7b1e5eSAndreas Gohr
1206b6f8822SAndreas Gohr    /**
1216b6f8822SAndreas Gohr     * Outputs pagination links
1226b6f8822SAndreas Gohr     *
1236b6f8822SAndreas Gohr     * @param type $limit
1246b6f8822SAndreas Gohr     * @param type $next
1256b6f8822SAndreas Gohr     */
1262507f8e0SAndreas Gohr    function html_pager($limit,$next){
1272507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1282507f8e0SAndreas Gohr
1292507f8e0SAndreas Gohr        if($this->start > 0){
1302507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
131d43cd6e0SAndreas 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 button">'.$this->getLang('prev').'</a>';
1322507f8e0SAndreas Gohr        }
1332507f8e0SAndreas Gohr
1342507f8e0SAndreas Gohr        if($next){
1352507f8e0SAndreas Gohr            $go = $this->start + $limit;
136d43cd6e0SAndreas 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 button">'.$this->getLang('next').'</a>';
1372507f8e0SAndreas Gohr        }
1382507f8e0SAndreas Gohr        echo '</div>';
1392507f8e0SAndreas Gohr    }
1402507f8e0SAndreas Gohr
141264f1744SAndreas Gohr    /**
142264f1744SAndreas Gohr     * Print the time selection menu
143264f1744SAndreas Gohr     */
14414d99ec0SAndreas Gohr    function html_timeselect(){
1456985b606SAndreas Gohr        $today   = date('Y-m-d');
1466985b606SAndreas Gohr        $last1   = date('Y-m-d',time()-(60*60*24));
1476985b606SAndreas Gohr        $last7   = date('Y-m-d',time()-(60*60*24*7));
1486985b606SAndreas Gohr        $last30  = date('Y-m-d',time()-(60*60*24*30));
14914d99ec0SAndreas Gohr
150264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
1516985b606SAndreas Gohr        echo '<span>'.$this->getLang('time_select').'</span> ';
152264f1744SAndreas Gohr
153264f1744SAndreas Gohr        echo '<form action="" method="get">';
154264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
155264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
156264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="'.$this->opt.'" />';
157264f1744SAndreas Gohr        echo '<input type="text" name="f" value="'.$this->from.'" class="edit" />';
158264f1744SAndreas Gohr        echo '<input type="text" name="t" value="'.$this->to.'" class="edit" />';
159264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
16014d99ec0SAndreas Gohr        echo '</form>';
161264f1744SAndreas Gohr
1626985b606SAndreas Gohr        echo '<ul>';
1636985b606SAndreas Gohr        foreach(array('today','last1','last7','last30') as $time){
1646985b606SAndreas Gohr            echo '<li>';
1656985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$$time.'&amp;t='.$today.'">';
1666985b606SAndreas Gohr            echo $this->getLang('time_'.$time);
1676985b606SAndreas Gohr            echo '</a>';
1686985b606SAndreas Gohr            echo '</li>';
1696985b606SAndreas Gohr        }
1706985b606SAndreas Gohr        echo '</ul>';
1716985b606SAndreas Gohr
172264f1744SAndreas Gohr        echo '</div>';
17314d99ec0SAndreas Gohr    }
17414d99ec0SAndreas Gohr
17514d99ec0SAndreas Gohr
176f5f32cbfSAndreas Gohr    /**
177f5f32cbfSAndreas Gohr     * Print an introductionary screen
178f5f32cbfSAndreas Gohr     */
17914d99ec0SAndreas Gohr    function html_dashboard(){
180878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_dashboard').'</p>';
1812812a751SAndreas Gohr
1822812a751SAndreas Gohr        // general info
1832812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
1846b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
1851d2d78ccSAndreas Gohr
1861d2d78ccSAndreas Gohr        echo '<ul class="left">';
1871d2d78ccSAndreas Gohr        foreach(array('pageviews','sessions','visitors','users','logins') as $name){
188eabe0d07SAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
189eabe0d07SAndreas Gohr        }
1902812a751SAndreas Gohr        echo '</ul>';
1911d2d78ccSAndreas Gohr
1921d2d78ccSAndreas Gohr        echo '<ul class="left">';
1931d2d78ccSAndreas Gohr        foreach(array('bouncerate','timespent','avgpages','newvisitors','registrations') as $name){
1941d2d78ccSAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
1951d2d78ccSAndreas Gohr        }
1961d2d78ccSAndreas Gohr        echo '</ul>';
1971d2d78ccSAndreas Gohr
198259897e1SAndreas Gohr        $this->html_graph('dashboardviews',700,280);
199259897e1SAndreas Gohr        $this->html_graph('dashboardwiki',700,280);
2002812a751SAndreas Gohr        echo '</div>';
2012812a751SAndreas Gohr
20214d99ec0SAndreas Gohr
20387d5e44bSAndreas Gohr        // top pages today
204264f1744SAndreas Gohr        echo '<div>';
205dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_mostpopular').'</h2>';
2066b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,15);
2072812a751SAndreas Gohr        $this->html_resulttable($result);
208d43cd6e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=page&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more button">'.$this->getLang('more').'</a>';
209264f1744SAndreas Gohr        echo '</div>';
21087d5e44bSAndreas Gohr
21187d5e44bSAndreas Gohr        // top referer today
212264f1744SAndreas Gohr        echo '<div>';
213dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_newincoming').'</h2>';
2146b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,15);
2152812a751SAndreas Gohr        $this->html_resulttable($result);
216d43cd6e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=newreferer&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more button">'.$this->getLang('more').'</a>';
217264f1744SAndreas Gohr        echo '</div>';
21854f6c432SAndreas Gohr
21929dea504SAndreas Gohr        // top searches today
220264f1744SAndreas Gohr        echo '<div>';
221dc7b1e5eSAndreas Gohr        echo '<h2>'.$this->getLang('dash_topsearch').'</h2>';
22212b59231SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,15);
22329dea504SAndreas Gohr        $this->html_resulttable($result);
224d43cd6e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=searchphrases&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more button">'.$this->getLang('more').'</a>';
225264f1744SAndreas Gohr        echo '</div>';
22614d99ec0SAndreas Gohr    }
22714d99ec0SAndreas Gohr
228c67866d1SAndreas Gohr    function html_countries(){
229878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_countries').'</p>';
230878be5c9SAndreas Gohr        $this->html_graph('countries',400,200);
2316b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit,$this->start,150);
2322507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2339da6395dSAndreas Gohr    }
2349da6395dSAndreas Gohr
2359da6395dSAndreas Gohr    function html_page(){
236878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_page').'</p>';
2376b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,150);
2382507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2399da6395dSAndreas Gohr    }
2409da6395dSAndreas Gohr
2414f41a2ccSAndreas Gohr    function html_browsers(){
242878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_browsers').'</p>';
243878be5c9SAndreas Gohr        $this->html_graph('browsers',400,200);
2446b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit,$this->start,150,true);
2452507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
24675fa767dSAndreas Gohr    }
24775fa767dSAndreas Gohr
248bd4217d3SAndreas Gohr    function html_os(){
249878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_os').'</p>';
250878be5c9SAndreas Gohr        $this->html_graph('os',400,200);
2516b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit,$this->start,150,true);
2522507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
253bd4217d3SAndreas Gohr    }
254bd4217d3SAndreas Gohr
2559da6395dSAndreas Gohr    function html_referer(){
2566b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2572812a751SAndreas Gohr
2582812a751SAndreas Gohr        $all    = $result['search']+$result['external']+$result['direct'];
2592812a751SAndreas Gohr
26094023548SAndreas Gohr        if($all){
261878be5c9SAndreas Gohr            printf('<p>'.$this->getLang('intro_referer').'</p>',
262878be5c9SAndreas Gohr                   $all,$result['direct'],(100*$result['direct']/$all),
2632812a751SAndreas Gohr                   $result['search'],(100*$result['search']/$all),$result['external'],
2642812a751SAndreas Gohr                   (100*$result['external']/$all));
26594023548SAndreas Gohr        }
2662812a751SAndreas Gohr
2676b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit,$this->start,150);
2682507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2699da6395dSAndreas Gohr    }
2709da6395dSAndreas Gohr
271e7a2f1e0SAndreas Gohr    function html_newreferer(){
272878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_newreferer').'</p>';
273e7a2f1e0SAndreas Gohr
2746b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,150);
2752507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
276e7a2f1e0SAndreas Gohr    }
277e7a2f1e0SAndreas Gohr
278e25286daSAndreas Gohr    function html_outlinks(){
279878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_outlinks').'</p>';
2806b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit,$this->start,150);
281e25286daSAndreas Gohr        $this->html_resulttable($result,'',150);
282e25286daSAndreas Gohr    }
283e25286daSAndreas Gohr
28412dcdeccSAndreas Gohr    function html_searchphrases(){
285878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchphrases').'</p>';
2865bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,150);
28712dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
28812dcdeccSAndreas Gohr    }
28912dcdeccSAndreas Gohr
29012dcdeccSAndreas Gohr    function html_searchwords(){
291878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchwords').'</p>';
2925bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true,$this->tlimit,$this->start,150);
2935bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
2945bccfe87SAndreas Gohr    }
2955bccfe87SAndreas Gohr
2965bccfe87SAndreas Gohr    function html_internalsearchphrases(){
297878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_internalsearchphrases').'</p>';
2985bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false,$this->tlimit,$this->start,150);
2995bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
3005bccfe87SAndreas Gohr    }
3015bccfe87SAndreas Gohr
3025bccfe87SAndreas Gohr    function html_internalsearchwords(){
303878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_internalsearchwords').'</p>';
3045bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false,$this->tlimit,$this->start,150);
30512dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
30612dcdeccSAndreas Gohr    }
30712dcdeccSAndreas Gohr
30812dcdeccSAndreas Gohr    function html_searchengines(){
309878be5c9SAndreas Gohr        echo '<p>'.$this->getLang('intro_searchengines').'</p>';
31025b71d4bSAndreas Gohr        $this->html_graph('searchengines',400,200);
3116b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit,$this->start,150);
31212dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
31312dcdeccSAndreas Gohr    }
31412dcdeccSAndreas Gohr
315c73e16f1SAndreas Gohr    function html_resolution(){
31625446aa2SAndreas Gohr        echo '<p>'.$this->getLang('intro_resolution').'</p>';
31725446aa2SAndreas Gohr        $this->html_graph('resolution',650,490);
318307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit,$this->start,150);
319307baf3fSAndreas Gohr        $this->html_resulttable($result,'',150);
32025446aa2SAndreas Gohr    }
321307baf3fSAndreas Gohr
32225446aa2SAndreas Gohr    function html_viewport(){
32325446aa2SAndreas Gohr        echo '<p>'.$this->getLang('intro_viewport').'</p>';
32425446aa2SAndreas Gohr        $this->html_graph('viewport',650,490);
32525446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit,$this->start,150);
32625446aa2SAndreas Gohr        $this->html_resulttable($result,'',150);
327c73e16f1SAndreas Gohr    }
3289da6395dSAndreas Gohr
3299da6395dSAndreas Gohr
33014d99ec0SAndreas Gohr    /**
33114d99ec0SAndreas Gohr     * Display a result in a HTML table
33214d99ec0SAndreas Gohr     */
3332507f8e0SAndreas Gohr    function html_resulttable($result,$header='',$pager=0){
33414d99ec0SAndreas Gohr        echo '<table>';
3352812a751SAndreas Gohr        if(is_array($header)){
33614d99ec0SAndreas Gohr            echo '<tr>';
33714d99ec0SAndreas Gohr            foreach($header as $h){
33814d99ec0SAndreas Gohr                echo '<th>'.hsc($h).'</th>';
33914d99ec0SAndreas Gohr            }
34014d99ec0SAndreas Gohr            echo '</tr>';
3412812a751SAndreas Gohr        }
34214d99ec0SAndreas Gohr
3432507f8e0SAndreas Gohr        $count = 0;
3442ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row){
34514d99ec0SAndreas Gohr            echo '<tr>';
34614d99ec0SAndreas Gohr            foreach($row as $k => $v){
347f3818071SAndreas Gohr                if($k == 'res_x') continue;
348f3818071SAndreas Gohr                if($k == 'res_y') continue;
349f3818071SAndreas Gohr
3502812a751SAndreas Gohr                echo '<td class="plg_stats_X'.$k.'">';
35114d99ec0SAndreas Gohr                if($k == 'page'){
35214d99ec0SAndreas Gohr                    echo '<a href="'.wl($v).'" class="wikilink1">';
35314d99ec0SAndreas Gohr                    echo hsc($v);
35414d99ec0SAndreas Gohr                    echo '</a>';
35514d99ec0SAndreas Gohr                }elseif($k == 'url'){
35654f6c432SAndreas Gohr                    $url = hsc($v);
35783b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/','',$url);
3582812a751SAndreas Gohr                    if(strlen($url) > 45){
3592812a751SAndreas Gohr                        $url = substr($url,0,30).' &hellip; '.substr($url,-15);
36054f6c432SAndreas Gohr                    }
36114d99ec0SAndreas Gohr                    echo '<a href="'.$v.'" class="urlextern">';
36254f6c432SAndreas Gohr                    echo $url;
36314d99ec0SAndreas Gohr                    echo '</a>';
3645bccfe87SAndreas Gohr                }elseif($k == 'ilookup'){
3655bccfe87SAndreas Gohr                    echo '<a href="'.wl('',array('id'=>$v,'do'=>'search')).'">Search</a>';
36629dea504SAndreas Gohr                }elseif($k == 'lookup'){
36729dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q='.rawurlencode($v).'">';
36813a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
36929dea504SAndreas Gohr                    echo '</a> ';
37029dea504SAndreas Gohr
37129dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p='.rawurlencode($v).'">';
37213a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
37329dea504SAndreas Gohr                    echo '</a> ';
37429dea504SAndreas Gohr
37513a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q='.rawurlencode($v).'">';
37613a86c14SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
37729dea504SAndreas Gohr                    echo '</a> ';
37829dea504SAndreas Gohr
37912dcdeccSAndreas Gohr                }elseif($k == 'engine'){
38013a86c14SAndreas Gohr                    include_once(dirname(__FILE__).'/inc/searchengines.php');
38113a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])){
38213a86c14SAndreas Gohr                        echo '<a href="'.$SEARCHENGINEINFO[$v][1].'">'.$SEARCHENGINEINFO[$v][0].'</a>';
38313a86c14SAndreas Gohr                    }else{
38413a86c14SAndreas Gohr                        echo hsc(ucwords($v));
38513a86c14SAndreas Gohr                    }
38613a86c14SAndreas Gohr                }elseif($k == 'eflag'){
38713a86c14SAndreas Gohr                    $this->html_icon('search',$v);
38875fa767dSAndreas Gohr                }elseif($k == 'bflag'){
38913a86c14SAndreas Gohr                    $this->html_icon('browser',$v);
390bd4217d3SAndreas Gohr                }elseif($k == 'osflag'){
39113a86c14SAndreas Gohr                    $this->html_icon('os',$v);
39275fa767dSAndreas Gohr                }elseif($k == 'cflag'){
39313a86c14SAndreas Gohr                    $this->html_icon('flags',$v);
39414d99ec0SAndreas Gohr                }elseif($k == 'html'){
39514d99ec0SAndreas Gohr                    echo $v;
39614d99ec0SAndreas Gohr                }else{
39714d99ec0SAndreas Gohr                    echo hsc($v);
39814d99ec0SAndreas Gohr                }
39914d99ec0SAndreas Gohr                echo '</td>';
40014d99ec0SAndreas Gohr            }
40114d99ec0SAndreas Gohr            echo '</tr>';
4022507f8e0SAndreas Gohr
4032507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4042507f8e0SAndreas Gohr            $count++;
40514d99ec0SAndreas Gohr        }
40614d99ec0SAndreas Gohr        echo '</table>';
4072507f8e0SAndreas Gohr
4082507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager,count($result) > $pager);
4091878f16fSAndreas Gohr    }
4101878f16fSAndreas Gohr
41113a86c14SAndreas Gohr    function html_icon($type,$value){
41213a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/','',$value));
4139bb008afSAndreas Gohr        $value = str_replace(' ','_',$value);
41413a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/'.$type.'/'.$value.'.png';
415*dffb869bSAndreas Gohr        if($type == 'flags'){
416*dffb869bSAndreas Gohr            $w = 18;
417*dffb869bSAndreas Gohr            $h = 12;
418*dffb869bSAndreas Gohr        }else{
419*dffb869bSAndreas Gohr            $w = 16;
420*dffb869bSAndreas Gohr            $h = 16;
421*dffb869bSAndreas Gohr        }
42213a86c14SAndreas Gohr        if(file_exists(DOKU_INC.$file)){
423*dffb869bSAndreas Gohr            echo '<img src="'.DOKU_BASE.$file.'" alt="'.hsc($value).'" width="'.$w.'" height="'.$h.'" />';
42413a86c14SAndreas Gohr        }
42513a86c14SAndreas Gohr    }
4261878f16fSAndreas Gohr}
427