xref: /plugin/statistics/admin.php (revision 1d2d78ccfd1a2e0ecb56189275fa7e319b7a350d)
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',
325bccfe87SAndreas Gohr                              'countries','resolution');
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() {
87*1d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
88264f1744SAndreas Gohr        echo '<h1>Access Statistics</h1>';
89264f1744SAndreas Gohr        $this->html_timeselect();
90264f1744SAndreas Gohr
9179b4a855SAndreas Gohr        $method = 'html_'.$this->opt;
9279b4a855SAndreas Gohr        if(method_exists($this,$method)){
93a901d721SAndreas Gohr            echo '<div class="plg_stats_'.$this->opt.'">';
94a901d721SAndreas Gohr            echo '<h2>'.$this->getLang($this->opt).'</h2>';
9579b4a855SAndreas Gohr            $this->$method();
96a901d721SAndreas Gohr            echo '</div>';
9714d99ec0SAndreas Gohr        }
98*1d2d78ccSAndreas Gohr        echo '</div>';
9914d99ec0SAndreas Gohr    }
10014d99ec0SAndreas Gohr
1016b6f8822SAndreas Gohr    /**
1026b6f8822SAndreas Gohr     * Return the TOC
1036b6f8822SAndreas Gohr     *
1046b6f8822SAndreas Gohr     * @return array
1056b6f8822SAndreas Gohr     */
10647ffcf7dSAndreas Gohr    function getTOC(){
10747ffcf7dSAndreas Gohr        $toc = array();
108a901d721SAndreas Gohr        foreach($this->pages as $page){
10947ffcf7dSAndreas Gohr            $toc[] = array(
11047ffcf7dSAndreas Gohr                    'link'  => '?do=admin&amp;page=statistics&amp;opt='.$page.'&amp;f='.$this->from.'&amp;t='.$this->to,
11147ffcf7dSAndreas Gohr                    'title' => $this->getLang($page),
11247ffcf7dSAndreas Gohr                    'level' => 1,
11347ffcf7dSAndreas Gohr                    'type'  => 'ul'
11447ffcf7dSAndreas Gohr            );
11547ffcf7dSAndreas Gohr        }
11647ffcf7dSAndreas Gohr        return $toc;
1179da6395dSAndreas Gohr    }
1189da6395dSAndreas Gohr
1196b6f8822SAndreas Gohr    /**
1206b6f8822SAndreas Gohr     * Outputs pagination links
1216b6f8822SAndreas Gohr     *
1226b6f8822SAndreas Gohr     * @fixme does this still work?
1236b6f8822SAndreas Gohr     *
1246b6f8822SAndreas Gohr     * @param type $limit
1256b6f8822SAndreas Gohr     * @param type $next
1266b6f8822SAndreas Gohr     */
1272507f8e0SAndreas Gohr    function html_pager($limit,$next){
1282507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1292507f8e0SAndreas Gohr
1302507f8e0SAndreas Gohr        if($this->start > 0){
1312507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
1322507f8e0SAndreas 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">previous page</a>';
1332507f8e0SAndreas Gohr        }
1342507f8e0SAndreas Gohr
1352507f8e0SAndreas Gohr        if($next){
1362507f8e0SAndreas Gohr            $go = $this->start + $limit;
1372507f8e0SAndreas 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">next page</a>';
1382507f8e0SAndreas Gohr        }
1392507f8e0SAndreas Gohr        echo '</div>';
1402507f8e0SAndreas Gohr    }
1412507f8e0SAndreas Gohr
142264f1744SAndreas Gohr    /**
143264f1744SAndreas Gohr     * Print the time selection menu
144264f1744SAndreas Gohr     */
14514d99ec0SAndreas Gohr    function html_timeselect(){
146264f1744SAndreas Gohr        $now   = date('Y-m-d');
147264f1744SAndreas Gohr        $yday  = date('Y-m-d',time()-(60*60*24));
148264f1744SAndreas Gohr        $week  = date('Y-m-d',time()-(60*60*24*7));
149264f1744SAndreas Gohr        $month = date('Y-m-d',time()-(60*60*24*30));
15014d99ec0SAndreas Gohr
151264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
152264f1744SAndreas Gohr        echo '<span>Select the timeframe:</span>';
153264f1744SAndreas Gohr        echo '<ul>';
154264f1744SAndreas Gohr
155264f1744SAndreas Gohr        echo '<li>';
1562507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$now.'&amp;t='.$now.'">';
157264f1744SAndreas Gohr        echo 'today';
158264f1744SAndreas Gohr        echo '</a>';
159264f1744SAndreas Gohr        echo '</li>';
160264f1744SAndreas Gohr
161264f1744SAndreas Gohr        echo '<li>';
1622507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$yday.'&amp;t='.$yday.'">';
163264f1744SAndreas Gohr        echo 'yesterday';
164264f1744SAndreas Gohr        echo '</a>';
165264f1744SAndreas Gohr        echo '</li>';
166264f1744SAndreas Gohr
167264f1744SAndreas Gohr        echo '<li>';
1682507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$week.'&amp;t='.$now.'">';
169264f1744SAndreas Gohr        echo 'last 7 days';
170264f1744SAndreas Gohr        echo '</a>';
171264f1744SAndreas Gohr        echo '</li>';
172264f1744SAndreas Gohr
173264f1744SAndreas Gohr        echo '<li>';
1742507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt='.$this->opt.'&amp;f='.$month.'&amp;t='.$now.'">';
175264f1744SAndreas Gohr        echo 'last 30 days';
176264f1744SAndreas Gohr        echo '</a>';
177264f1744SAndreas Gohr        echo '</li>';
178264f1744SAndreas Gohr
179264f1744SAndreas Gohr        echo '</ul>';
180264f1744SAndreas Gohr
181264f1744SAndreas Gohr
182264f1744SAndreas Gohr        echo '<form action="" method="get">';
183264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
184264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
185264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="'.$this->opt.'" />';
186264f1744SAndreas Gohr        echo '<input type="text" name="f" value="'.$this->from.'" class="edit" />';
187264f1744SAndreas Gohr        echo '<input type="text" name="t" value="'.$this->to.'" class="edit" />';
188264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
18914d99ec0SAndreas Gohr        echo '</form>';
190264f1744SAndreas Gohr
191264f1744SAndreas Gohr        echo '</div>';
19214d99ec0SAndreas Gohr    }
19314d99ec0SAndreas Gohr
19414d99ec0SAndreas Gohr
195f5f32cbfSAndreas Gohr    /**
196f5f32cbfSAndreas Gohr     * Print an introductionary screen
197f5f32cbfSAndreas Gohr     */
19814d99ec0SAndreas Gohr    function html_dashboard(){
1992812a751SAndreas Gohr        echo '<p>This page gives you a quick overview on what is happening in your Wiki. For detailed lists
2002812a751SAndreas Gohr              choose a topic from the list.</p>';
2012812a751SAndreas Gohr
2022812a751SAndreas Gohr        // general info
2032812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
2046b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
205*1d2d78ccSAndreas Gohr
206*1d2d78ccSAndreas Gohr        echo '<ul class="left">';
207*1d2d78ccSAndreas Gohr        foreach(array('pageviews','sessions','visitors','users','logins') as $name){
208eabe0d07SAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
209eabe0d07SAndreas Gohr        }
2102812a751SAndreas Gohr        echo '</ul>';
211*1d2d78ccSAndreas Gohr
212*1d2d78ccSAndreas Gohr        echo '<ul class="left">';
213*1d2d78ccSAndreas Gohr        foreach(array('bouncerate','timespent','avgpages','newvisitors','registrations') as $name){
214*1d2d78ccSAndreas Gohr            echo '<li><div class="li">'.sprintf($this->getLang('dash_'.$name),$result[$name]).'</div></li>';
215*1d2d78ccSAndreas Gohr        }
216*1d2d78ccSAndreas Gohr        echo '</ul>';
217*1d2d78ccSAndreas Gohr
218*1d2d78ccSAndreas Gohr
2192812a751SAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/img.php?img=trend&amp;f='.$this->from.'&amp;t='.$this->to.'" />';
2202812a751SAndreas Gohr        echo '</div>';
2212812a751SAndreas Gohr
22214d99ec0SAndreas Gohr
22387d5e44bSAndreas Gohr        // top pages today
224264f1744SAndreas Gohr        echo '<div>';
225264f1744SAndreas Gohr        echo '<h2>Most popular pages</h2>';
2266b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,15);
2272812a751SAndreas Gohr        $this->html_resulttable($result);
2282507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=page&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">more</a>';
229264f1744SAndreas Gohr        echo '</div>';
23087d5e44bSAndreas Gohr
23187d5e44bSAndreas Gohr        // top referer today
232264f1744SAndreas Gohr        echo '<div>';
233e7a2f1e0SAndreas Gohr        echo '<h2>Newest incoming links</h2>';
2346b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,15);
2352812a751SAndreas Gohr        $this->html_resulttable($result);
2362507f8e0SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=newreferer&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">more</a>';
237264f1744SAndreas Gohr        echo '</div>';
23854f6c432SAndreas Gohr
23929dea504SAndreas Gohr        // top searches today
240264f1744SAndreas Gohr        echo '<div>';
24129dea504SAndreas Gohr        echo '<h2>Top search phrases</h2>';
2426b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchphrases($this->tlimit,$this->start,15);
24329dea504SAndreas Gohr        $this->html_resulttable($result);
24429dea504SAndreas Gohr        echo '<a href="?do=admin&amp;page=statistics&amp;opt=searchphrases&amp;f='.$this->from.'&amp;t='.$this->to.'" class="more">more</a>';
245264f1744SAndreas Gohr        echo '</div>';
24614d99ec0SAndreas Gohr    }
24714d99ec0SAndreas Gohr
248c67866d1SAndreas Gohr    function html_countries(){
249c67866d1SAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/img.php?img=countries&amp;f='.$this->from.'&amp;t='.$this->to.'" />';
2506b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit,$this->start,150);
2512507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2529da6395dSAndreas Gohr    }
2539da6395dSAndreas Gohr
2549da6395dSAndreas Gohr    function html_page(){
2556b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit,$this->start,150);
2562507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2579da6395dSAndreas Gohr    }
2589da6395dSAndreas Gohr
2594f41a2ccSAndreas Gohr    function html_browsers(){
2604f41a2ccSAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/img.php?img=browsers&amp;f='.$this->from.'&amp;t='.$this->to.'" />';
2616b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit,$this->start,150,true);
2622507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
26375fa767dSAndreas Gohr    }
26475fa767dSAndreas Gohr
265bd4217d3SAndreas Gohr    function html_os(){
2666b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit,$this->start,150,true);
2672507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
268bd4217d3SAndreas Gohr    }
269bd4217d3SAndreas Gohr
2709da6395dSAndreas Gohr    function html_referer(){
2716b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2722812a751SAndreas Gohr
2732812a751SAndreas Gohr        $all    = $result['search']+$result['external']+$result['direct'];
2742812a751SAndreas Gohr
27594023548SAndreas Gohr        if($all){
2762812a751SAndreas Gohr            printf("<p>Of all %d external visits, %d (%.1f%%) were bookmarked (direct) accesses,
2772812a751SAndreas Gohr                    %d (%.1f%%) came from search engines and %d (%.1f%%) were referred through
2782812a751SAndreas Gohr                    links from other pages.</p>",$all,$result['direct'],(100*$result['direct']/$all),
2792812a751SAndreas Gohr                    $result['search'],(100*$result['search']/$all),$result['external'],
2802812a751SAndreas Gohr                    (100*$result['external']/$all));
28194023548SAndreas Gohr        }
2822812a751SAndreas Gohr
2836b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit,$this->start,150);
2842507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
2859da6395dSAndreas Gohr    }
2869da6395dSAndreas Gohr
287e7a2f1e0SAndreas Gohr    function html_newreferer(){
288e7a2f1e0SAndreas Gohr        echo '<p>The following incoming links where first logged in the selected time frame,
289e7a2f1e0SAndreas Gohr              and have never been seen before.</p>';
290e7a2f1e0SAndreas Gohr
2916b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,150);
2922507f8e0SAndreas Gohr        $this->html_resulttable($result,'',150);
293e7a2f1e0SAndreas Gohr    }
294e7a2f1e0SAndreas Gohr
295e25286daSAndreas Gohr    function html_outlinks(){
2966b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit,$this->start,150);
297e25286daSAndreas Gohr        $this->html_resulttable($result,'',150);
298e25286daSAndreas Gohr    }
299e25286daSAndreas Gohr
30012dcdeccSAndreas Gohr    function html_searchphrases(){
3015bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,150);
30212dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
30312dcdeccSAndreas Gohr    }
30412dcdeccSAndreas Gohr
30512dcdeccSAndreas Gohr    function html_searchwords(){
3065bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true,$this->tlimit,$this->start,150);
3075bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
3085bccfe87SAndreas Gohr    }
3095bccfe87SAndreas Gohr
3105bccfe87SAndreas Gohr    function html_internalsearchphrases(){
3115bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false,$this->tlimit,$this->start,150);
3125bccfe87SAndreas Gohr        $this->html_resulttable($result,'',150);
3135bccfe87SAndreas Gohr    }
3145bccfe87SAndreas Gohr
3155bccfe87SAndreas Gohr    function html_internalsearchwords(){
3165bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false,$this->tlimit,$this->start,150);
31712dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
31812dcdeccSAndreas Gohr    }
31912dcdeccSAndreas Gohr
32012dcdeccSAndreas Gohr    function html_searchengines(){
3216b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit,$this->start,150);
32212dcdeccSAndreas Gohr        $this->html_resulttable($result,'',150);
32312dcdeccSAndreas Gohr    }
32412dcdeccSAndreas Gohr
325e25286daSAndreas Gohr
326c73e16f1SAndreas Gohr    function html_resolution(){
327307baf3fSAndreas Gohr
328307baf3fSAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/img.php?img=resolution&amp;f='.$this->from.'&amp;t='.$this->to.'" />';
329c73e16f1SAndreas Gohr
330c73e16f1SAndreas Gohr        echo '<p>While the data above gives you some info about the resolution your visitors use, it does not tell you
331c73e16f1SAndreas Gohr              much about about the real size of their browser windows. The graphic below shows the size distribution of
332c73e16f1SAndreas Gohr              the view port (document area) of your visitor\'s browsers. Please note that this data can not be logged
333c73e16f1SAndreas Gohr              in all browsers. Because users may resize their browser window while browsing your site the statistics may
334c73e16f1SAndreas Gohr              be flawed. Take it with a grain of salt.</p>';
335c73e16f1SAndreas Gohr
336307baf3fSAndreas Gohr        echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/img.php?img=viewport&amp;f='.$this->from.'&amp;t='.$this->to.'" />';
337307baf3fSAndreas Gohr
338307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit,$this->start,150);
339307baf3fSAndreas Gohr        $this->html_resulttable($result,'',150);
340307baf3fSAndreas Gohr
341307baf3fSAndreas Gohr
342c73e16f1SAndreas Gohr    }
3439da6395dSAndreas Gohr
3449da6395dSAndreas Gohr
34514d99ec0SAndreas Gohr    /**
34614d99ec0SAndreas Gohr     * Display a result in a HTML table
34714d99ec0SAndreas Gohr     */
3482507f8e0SAndreas Gohr    function html_resulttable($result,$header='',$pager=0){
34914d99ec0SAndreas Gohr        echo '<table>';
3502812a751SAndreas Gohr        if(is_array($header)){
35114d99ec0SAndreas Gohr            echo '<tr>';
35214d99ec0SAndreas Gohr            foreach($header as $h){
35314d99ec0SAndreas Gohr                echo '<th>'.hsc($h).'</th>';
35414d99ec0SAndreas Gohr            }
35514d99ec0SAndreas Gohr            echo '</tr>';
3562812a751SAndreas Gohr        }
35714d99ec0SAndreas Gohr
3582507f8e0SAndreas Gohr        $count = 0;
3592ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row){
36014d99ec0SAndreas Gohr            echo '<tr>';
36114d99ec0SAndreas Gohr            foreach($row as $k => $v){
3622812a751SAndreas Gohr                echo '<td class="plg_stats_X'.$k.'">';
36314d99ec0SAndreas Gohr                if($k == 'page'){
36414d99ec0SAndreas Gohr                    echo '<a href="'.wl($v).'" class="wikilink1">';
36514d99ec0SAndreas Gohr                    echo hsc($v);
36614d99ec0SAndreas Gohr                    echo '</a>';
36714d99ec0SAndreas Gohr                }elseif($k == 'url'){
36854f6c432SAndreas Gohr                    $url = hsc($v);
36983b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/','',$url);
3702812a751SAndreas Gohr                    if(strlen($url) > 45){
3712812a751SAndreas Gohr                        $url = substr($url,0,30).' &hellip; '.substr($url,-15);
37254f6c432SAndreas Gohr                    }
37314d99ec0SAndreas Gohr                    echo '<a href="'.$v.'" class="urlextern">';
37454f6c432SAndreas Gohr                    echo $url;
37514d99ec0SAndreas Gohr                    echo '</a>';
3765bccfe87SAndreas Gohr                }elseif($k == 'ilookup'){
3775bccfe87SAndreas Gohr                    echo '<a href="'.wl('',array('id'=>$v,'do'=>'search')).'">Search</a>';
37829dea504SAndreas Gohr                }elseif($k == 'lookup'){
37929dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q='.rawurlencode($v).'">';
38029dea504SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/google.png" alt="lookup in Google" border="0" />';
38129dea504SAndreas Gohr                    echo '</a> ';
38229dea504SAndreas Gohr
38329dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p='.rawurlencode($v).'">';
38429dea504SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/yahoo.png" alt="lookup in Yahoo" border="0" />';
38529dea504SAndreas Gohr                    echo '</a> ';
38629dea504SAndreas Gohr
38729dea504SAndreas Gohr                    echo '<a href="http://search.msn.com/results.aspx?q='.rawurlencode($v).'">';
38829dea504SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/search/msn.png" alt="lookup in MSN Live" border="0" />';
38929dea504SAndreas Gohr                    echo '</a> ';
39029dea504SAndreas Gohr
39112dcdeccSAndreas Gohr                }elseif($k == 'engine'){
39212dcdeccSAndreas Gohr                    include_once(dirname(__FILE__).'/inc/search_engines.php');
39312dcdeccSAndreas Gohr                    echo $SearchEnginesHashLib[$v];
39475fa767dSAndreas Gohr                }elseif($k == 'bflag'){
3952998b1f6SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/browser/'.strtolower(preg_replace('/[^\w]+/','',$v)).'.png" alt="'.hsc($v).'" />';
396bd4217d3SAndreas Gohr                }elseif($k == 'osflag'){
3972998b1f6SAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/os/'.strtolower(preg_replace('/[^\w]+/','',$v)).'.png" alt="'.hsc($v).'" />';
39875fa767dSAndreas Gohr                }elseif($k == 'cflag'){
39975fa767dSAndreas Gohr                    echo '<img src="'.DOKU_BASE.'lib/plugins/statistics/ico/flags/'.hsc($v).'.png" alt="'.hsc($v).'" width="18" height="12" />';
40014d99ec0SAndreas Gohr                }elseif($k == 'html'){
40114d99ec0SAndreas Gohr                    echo $v;
40214d99ec0SAndreas Gohr                }else{
40314d99ec0SAndreas Gohr                    echo hsc($v);
40414d99ec0SAndreas Gohr                }
40514d99ec0SAndreas Gohr                echo '</td>';
40614d99ec0SAndreas Gohr            }
40714d99ec0SAndreas Gohr            echo '</tr>';
4082507f8e0SAndreas Gohr
4092507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4102507f8e0SAndreas Gohr            $count++;
41114d99ec0SAndreas Gohr        }
41214d99ec0SAndreas Gohr        echo '</table>';
4132507f8e0SAndreas Gohr
4142507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager,count($result) > $pager);
4151878f16fSAndreas Gohr    }
4161878f16fSAndreas Gohr
4171878f16fSAndreas Gohr}
418