xref: /plugin/statistics/admin.php (revision 0863c19c7bf8b95c6f464efd1fa1fd2c4f9b4e94)
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
121878f16fSAndreas Gohr/**
131878f16fSAndreas Gohr * All DokuWiki plugins to extend the admin function
141878f16fSAndreas Gohr * need to inherit from this class
151878f16fSAndreas Gohr */
161878f16fSAndreas Gohrclass admin_plugin_statistics extends DokuWiki_Admin_Plugin {
17a901d721SAndreas Gohr    public $dblink = null;
18a901d721SAndreas Gohr    protected $opt = '';
19a901d721SAndreas Gohr    protected $from = '';
20a901d721SAndreas Gohr    protected $to = '';
21a901d721SAndreas Gohr    protected $start = '';
22a901d721SAndreas Gohr    protected $tlimit = '';
23a901d721SAndreas Gohr
24a901d721SAndreas Gohr    /**
25a901d721SAndreas Gohr     * Available statistic pages
26a901d721SAndreas Gohr     */
27*0863c19cSAndreas Gohr    protected $pages = array(
28*0863c19cSAndreas Gohr        'dashboard', 'page', 'referer', 'newreferer',
295bccfe87SAndreas Gohr        'outlinks', 'searchengines', 'searchphrases',
305bccfe87SAndreas Gohr        'searchwords', 'internalsearchphrases',
315bccfe87SAndreas Gohr        'internalsearchwords', 'browsers', 'os',
32*0863c19cSAndreas Gohr        'countries', 'resolution', 'viewport'
33*0863c19cSAndreas Gohr    );
341878f16fSAndreas Gohr
351878f16fSAndreas Gohr    /**
366b6f8822SAndreas Gohr     * Initialize the helper
376b6f8822SAndreas Gohr     */
386b6f8822SAndreas Gohr    public function __construct() {
396b6f8822SAndreas Gohr        $this->hlp = plugin_load('helper', 'statistics');
406b6f8822SAndreas Gohr    }
416b6f8822SAndreas Gohr
426b6f8822SAndreas Gohr    /**
431878f16fSAndreas Gohr     * Access for managers allowed
441878f16fSAndreas Gohr     */
456b6f8822SAndreas Gohr    public function forAdminOnly() {
461878f16fSAndreas Gohr        return false;
471878f16fSAndreas Gohr    }
481878f16fSAndreas Gohr
491878f16fSAndreas Gohr    /**
501878f16fSAndreas Gohr     * return sort order for position in admin menu
511878f16fSAndreas Gohr     */
526b6f8822SAndreas Gohr    public function getMenuSort() {
536b6f8822SAndreas Gohr        return 350;
541878f16fSAndreas Gohr    }
551878f16fSAndreas Gohr
561878f16fSAndreas Gohr    /**
571878f16fSAndreas Gohr     * handle user request
581878f16fSAndreas Gohr     */
596b6f8822SAndreas Gohr    public function handle() {
60264f1744SAndreas Gohr        $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']);
61a901d721SAndreas Gohr        if(!in_array($this->opt, $this->pages)) $this->opt = 'dashboard';
62a901d721SAndreas Gohr
6395eb68e6SAndreas Gohr        $this->start = (int) $_REQUEST['s'];
64e8699bceSAndreas Gohr        $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']);
65e8699bceSAndreas Gohr    }
6695eb68e6SAndreas Gohr
67e8699bceSAndreas Gohr    /**
68e8699bceSAndreas Gohr     * set limit clause
69e8699bceSAndreas Gohr     */
706b6f8822SAndreas Gohr    public function setTimeframe($from, $to) {
713bf3de81SAndreas Gohr        $this->tlimit = $this->hlp->Query()->mktlimit($from, $to);
72e8699bceSAndreas Gohr        $this->from   = $from;
73e8699bceSAndreas Gohr        $this->to     = $to;
741878f16fSAndreas Gohr    }
751878f16fSAndreas Gohr
761878f16fSAndreas Gohr    /**
7779b4a855SAndreas Gohr     * Output the Statistics
781878f16fSAndreas Gohr     */
791878f16fSAndreas Gohr    function html() {
801d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
810c3b1e44SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
82264f1744SAndreas Gohr        $this->html_timeselect();
83441bfb8eSAndreas Gohr        tpl_flush();
84264f1744SAndreas Gohr
8579b4a855SAndreas Gohr        $method = 'html_' . $this->opt;
8679b4a855SAndreas Gohr        if(method_exists($this, $method)) {
87a901d721SAndreas Gohr            echo '<div class="plg_stats_' . $this->opt . '">';
88a901d721SAndreas Gohr            echo '<h2>' . $this->getLang($this->opt) . '</h2>';
8979b4a855SAndreas Gohr            $this->$method();
90a901d721SAndreas Gohr            echo '</div>';
9114d99ec0SAndreas Gohr        }
921d2d78ccSAndreas Gohr        echo '</div>';
9314d99ec0SAndreas Gohr    }
9414d99ec0SAndreas Gohr
956b6f8822SAndreas Gohr    /**
966b6f8822SAndreas Gohr     * Return the TOC
976b6f8822SAndreas Gohr     *
986b6f8822SAndreas Gohr     * @return array
996b6f8822SAndreas Gohr     */
10047ffcf7dSAndreas Gohr    function getTOC() {
10147ffcf7dSAndreas Gohr        $toc = array();
102a901d721SAndreas Gohr        foreach($this->pages as $page) {
10347ffcf7dSAndreas Gohr            $toc[] = array(
10447ffcf7dSAndreas Gohr                'link'  => '?do=admin&amp;page=statistics&amp;opt=' . $page . '&amp;f=' . $this->from . '&amp;t=' . $this->to,
10547ffcf7dSAndreas Gohr                'title' => $this->getLang($page),
10647ffcf7dSAndreas Gohr                'level' => 1,
10747ffcf7dSAndreas Gohr                'type'  => 'ul'
10847ffcf7dSAndreas Gohr            );
10947ffcf7dSAndreas Gohr        }
11047ffcf7dSAndreas Gohr        return $toc;
1119da6395dSAndreas Gohr    }
1129da6395dSAndreas 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
1196b6f8822SAndreas Gohr    /**
1206b6f8822SAndreas Gohr     * Outputs pagination links
1216b6f8822SAndreas Gohr     *
1226b6f8822SAndreas Gohr     * @param type $limit
1236b6f8822SAndreas Gohr     * @param type $next
1246b6f8822SAndreas Gohr     */
1252507f8e0SAndreas Gohr    function html_pager($limit, $next) {
1262507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1272507f8e0SAndreas Gohr
1282507f8e0SAndreas Gohr        if($this->start > 0) {
1292507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
130d43cd6e0SAndreas 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>';
1312507f8e0SAndreas Gohr        }
1322507f8e0SAndreas Gohr
1332507f8e0SAndreas Gohr        if($next) {
1342507f8e0SAndreas Gohr            $go = $this->start + $limit;
135d43cd6e0SAndreas 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>';
1362507f8e0SAndreas Gohr        }
1372507f8e0SAndreas Gohr        echo '</div>';
1382507f8e0SAndreas Gohr    }
1392507f8e0SAndreas Gohr
140264f1744SAndreas Gohr    /**
141264f1744SAndreas Gohr     * Print the time selection menu
142264f1744SAndreas Gohr     */
14314d99ec0SAndreas Gohr    function html_timeselect() {
1446985b606SAndreas Gohr        $today  = date('Y-m-d');
1456985b606SAndreas Gohr        $last1  = date('Y-m-d', time() - (60 * 60 * 24));
1466985b606SAndreas Gohr        $last7  = date('Y-m-d', time() - (60 * 60 * 24 * 7));
1476985b606SAndreas Gohr        $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30));
14814d99ec0SAndreas Gohr
149264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
1506985b606SAndreas Gohr        echo '<span>' . $this->getLang('time_select') . '</span> ';
151264f1744SAndreas Gohr
152264f1744SAndreas Gohr        echo '<form action="" method="get">';
153264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
154264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
155264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="' . $this->opt . '" />';
156264f1744SAndreas Gohr        echo '<input type="text" name="f" value="' . $this->from . '" class="edit" />';
157264f1744SAndreas Gohr        echo '<input type="text" name="t" value="' . $this->to . '" class="edit" />';
158264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
15914d99ec0SAndreas Gohr        echo '</form>';
160264f1744SAndreas Gohr
1616985b606SAndreas Gohr        echo '<ul>';
1626985b606SAndreas Gohr        foreach(array('today', 'last1', 'last7', 'last30') as $time) {
1636985b606SAndreas Gohr            echo '<li>';
1646985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt=' . $this->opt . '&amp;f=' . $$time . '&amp;t=' . $today . '">';
1656985b606SAndreas Gohr            echo $this->getLang('time_' . $time);
1666985b606SAndreas Gohr            echo '</a>';
1676985b606SAndreas Gohr            echo '</li>';
1686985b606SAndreas Gohr        }
1696985b606SAndreas Gohr        echo '</ul>';
1706985b606SAndreas Gohr
171264f1744SAndreas Gohr        echo '</div>';
17214d99ec0SAndreas Gohr    }
17314d99ec0SAndreas Gohr
174f5f32cbfSAndreas Gohr    /**
175f5f32cbfSAndreas Gohr     * Print an introductionary screen
176f5f32cbfSAndreas Gohr     */
17714d99ec0SAndreas Gohr    function html_dashboard() {
178878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_dashboard') . '</p>';
1792812a751SAndreas Gohr
1802812a751SAndreas Gohr        // general info
1812812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
1826b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
1831d2d78ccSAndreas Gohr
1841d2d78ccSAndreas Gohr        echo '<ul class="left">';
1851d2d78ccSAndreas Gohr        foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins') as $name) {
186eabe0d07SAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
187eabe0d07SAndreas Gohr        }
1882812a751SAndreas Gohr        echo '</ul>';
1891d2d78ccSAndreas Gohr
1901d2d78ccSAndreas Gohr        echo '<ul class="left">';
1911d2d78ccSAndreas Gohr        foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) {
1921d2d78ccSAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
1931d2d78ccSAndreas Gohr        }
1941d2d78ccSAndreas Gohr        echo '</ul>';
1951d2d78ccSAndreas Gohr
196259897e1SAndreas Gohr        $this->html_graph('dashboardviews', 700, 280);
197259897e1SAndreas Gohr        $this->html_graph('dashboardwiki', 700, 280);
1982812a751SAndreas Gohr        echo '</div>';
1992812a751SAndreas Gohr
20087d5e44bSAndreas Gohr        // top pages today
201264f1744SAndreas Gohr        echo '<div>';
202dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>';
2036b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15);
2042812a751SAndreas Gohr        $this->html_resulttable($result);
205d43cd6e0SAndreas 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>';
206264f1744SAndreas Gohr        echo '</div>';
20787d5e44bSAndreas Gohr
20887d5e44bSAndreas Gohr        // top referer today
209264f1744SAndreas Gohr        echo '<div>';
210dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>';
2116b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15);
2122812a751SAndreas Gohr        $this->html_resulttable($result);
213d43cd6e0SAndreas 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>';
214264f1744SAndreas Gohr        echo '</div>';
21554f6c432SAndreas Gohr
21629dea504SAndreas Gohr        // top searches today
217264f1744SAndreas Gohr        echo '<div>';
218dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>';
21912b59231SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15);
22029dea504SAndreas Gohr        $this->html_resulttable($result);
221d43cd6e0SAndreas 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>';
222264f1744SAndreas Gohr        echo '</div>';
22314d99ec0SAndreas Gohr    }
22414d99ec0SAndreas Gohr
225c67866d1SAndreas Gohr    function html_countries() {
226878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_countries') . '</p>';
227878be5c9SAndreas Gohr        $this->html_graph('countries', 400, 200);
2286b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150);
2292507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2309da6395dSAndreas Gohr    }
2319da6395dSAndreas Gohr
2329da6395dSAndreas Gohr    function html_page() {
233878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_page') . '</p>';
2346b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150);
2352507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2369da6395dSAndreas Gohr    }
2379da6395dSAndreas Gohr
2384f41a2ccSAndreas Gohr    function html_browsers() {
239878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_browsers') . '</p>';
240878be5c9SAndreas Gohr        $this->html_graph('browsers', 400, 200);
2416b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true);
2422507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
24375fa767dSAndreas Gohr    }
24475fa767dSAndreas Gohr
245bd4217d3SAndreas Gohr    function html_os() {
246878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_os') . '</p>';
247878be5c9SAndreas Gohr        $this->html_graph('os', 400, 200);
2486b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true);
2492507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
250bd4217d3SAndreas Gohr    }
251bd4217d3SAndreas Gohr
2529da6395dSAndreas Gohr    function html_referer() {
2536b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2542812a751SAndreas Gohr
2552812a751SAndreas Gohr        $all = $result['search'] + $result['external'] + $result['direct'];
2562812a751SAndreas Gohr
25794023548SAndreas Gohr        if($all) {
258*0863c19cSAndreas Gohr            printf(
259*0863c19cSAndreas Gohr                '<p>' . $this->getLang('intro_referer') . '</p>',
260878be5c9SAndreas Gohr                $all, $result['direct'], (100 * $result['direct'] / $all),
2612812a751SAndreas Gohr                $result['search'], (100 * $result['search'] / $all), $result['external'],
262*0863c19cSAndreas Gohr                (100 * $result['external'] / $all)
263*0863c19cSAndreas Gohr            );
26494023548SAndreas Gohr        }
2652812a751SAndreas Gohr
2666b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150);
2672507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2689da6395dSAndreas Gohr    }
2699da6395dSAndreas Gohr
270e7a2f1e0SAndreas Gohr    function html_newreferer() {
271878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_newreferer') . '</p>';
272e7a2f1e0SAndreas Gohr
2736b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150);
2742507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
275e7a2f1e0SAndreas Gohr    }
276e7a2f1e0SAndreas Gohr
277e25286daSAndreas Gohr    function html_outlinks() {
278878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_outlinks') . '</p>';
2796b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150);
280e25286daSAndreas Gohr        $this->html_resulttable($result, '', 150);
281e25286daSAndreas Gohr    }
282e25286daSAndreas Gohr
28312dcdeccSAndreas Gohr    function html_searchphrases() {
284878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchphrases') . '</p>';
2855bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150);
28612dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
28712dcdeccSAndreas Gohr    }
28812dcdeccSAndreas Gohr
28912dcdeccSAndreas Gohr    function html_searchwords() {
290878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchwords') . '</p>';
2915bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150);
2925bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
2935bccfe87SAndreas Gohr    }
2945bccfe87SAndreas Gohr
2955bccfe87SAndreas Gohr    function html_internalsearchphrases() {
296878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>';
2975bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150);
2985bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
2995bccfe87SAndreas Gohr    }
3005bccfe87SAndreas Gohr
3015bccfe87SAndreas Gohr    function html_internalsearchwords() {
302878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>';
3035bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150);
30412dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
30512dcdeccSAndreas Gohr    }
30612dcdeccSAndreas Gohr
30712dcdeccSAndreas Gohr    function html_searchengines() {
308878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchengines') . '</p>';
30925b71d4bSAndreas Gohr        $this->html_graph('searchengines', 400, 200);
3106b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150);
31112dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
31212dcdeccSAndreas Gohr    }
31312dcdeccSAndreas Gohr
314c73e16f1SAndreas Gohr    function html_resolution() {
31525446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_resolution') . '</p>';
31625446aa2SAndreas Gohr        $this->html_graph('resolution', 650, 490);
317307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150);
318307baf3fSAndreas Gohr        $this->html_resulttable($result, '', 150);
31925446aa2SAndreas Gohr    }
320307baf3fSAndreas Gohr
32125446aa2SAndreas Gohr    function html_viewport() {
32225446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_viewport') . '</p>';
32325446aa2SAndreas Gohr        $this->html_graph('viewport', 650, 490);
32425446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150);
32525446aa2SAndreas Gohr        $this->html_resulttable($result, '', 150);
326c73e16f1SAndreas Gohr    }
3279da6395dSAndreas Gohr
32814d99ec0SAndreas Gohr    /**
32914d99ec0SAndreas Gohr     * Display a result in a HTML table
33014d99ec0SAndreas Gohr     */
3312507f8e0SAndreas Gohr    function html_resulttable($result, $header = '', $pager = 0) {
33214d99ec0SAndreas Gohr        echo '<table>';
3332812a751SAndreas Gohr        if(is_array($header)) {
33414d99ec0SAndreas Gohr            echo '<tr>';
33514d99ec0SAndreas Gohr            foreach($header as $h) {
33614d99ec0SAndreas Gohr                echo '<th>' . hsc($h) . '</th>';
33714d99ec0SAndreas Gohr            }
33814d99ec0SAndreas Gohr            echo '</tr>';
3392812a751SAndreas Gohr        }
34014d99ec0SAndreas Gohr
3412507f8e0SAndreas Gohr        $count = 0;
3422ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row) {
34314d99ec0SAndreas Gohr            echo '<tr>';
34414d99ec0SAndreas Gohr            foreach($row as $k => $v) {
345f3818071SAndreas Gohr                if($k == 'res_x') continue;
346f3818071SAndreas Gohr                if($k == 'res_y') continue;
347f3818071SAndreas Gohr
3482812a751SAndreas Gohr                echo '<td class="plg_stats_X' . $k . '">';
34914d99ec0SAndreas Gohr                if($k == 'page') {
35014d99ec0SAndreas Gohr                    echo '<a href="' . wl($v) . '" class="wikilink1">';
35114d99ec0SAndreas Gohr                    echo hsc($v);
35214d99ec0SAndreas Gohr                    echo '</a>';
35314d99ec0SAndreas Gohr                } elseif($k == 'url') {
35454f6c432SAndreas Gohr                    $url = hsc($v);
35583b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url);
3562812a751SAndreas Gohr                    if(strlen($url) > 45) {
3572812a751SAndreas Gohr                        $url = substr($url, 0, 30) . ' &hellip; ' . substr($url, -15);
35854f6c432SAndreas Gohr                    }
35914d99ec0SAndreas Gohr                    echo '<a href="' . $v . '" class="urlextern">';
36054f6c432SAndreas Gohr                    echo $url;
36114d99ec0SAndreas Gohr                    echo '</a>';
3625bccfe87SAndreas Gohr                } elseif($k == 'ilookup') {
3635bccfe87SAndreas Gohr                    echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>';
36429dea504SAndreas Gohr                } elseif($k == 'lookup') {
36529dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">';
36613a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
36729dea504SAndreas Gohr                    echo '</a> ';
36829dea504SAndreas Gohr
36929dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">';
37013a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
37129dea504SAndreas Gohr                    echo '</a> ';
37229dea504SAndreas Gohr
37313a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">';
37413a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
37529dea504SAndreas Gohr                    echo '</a> ';
37629dea504SAndreas Gohr
37712dcdeccSAndreas Gohr                } elseif($k == 'engine') {
37813a86c14SAndreas Gohr                    include_once(dirname(__FILE__) . '/inc/searchengines.php');
37913a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])) {
38013a86c14SAndreas Gohr                        echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>';
38113a86c14SAndreas Gohr                    } else {
38213a86c14SAndreas Gohr                        echo hsc(ucwords($v));
38313a86c14SAndreas Gohr                    }
38413a86c14SAndreas Gohr                } elseif($k == 'eflag') {
38513a86c14SAndreas Gohr                    $this->html_icon('search', $v);
38675fa767dSAndreas Gohr                } elseif($k == 'bflag') {
38713a86c14SAndreas Gohr                    $this->html_icon('browser', $v);
388bd4217d3SAndreas Gohr                } elseif($k == 'osflag') {
38913a86c14SAndreas Gohr                    $this->html_icon('os', $v);
39075fa767dSAndreas Gohr                } elseif($k == 'cflag') {
39113a86c14SAndreas Gohr                    $this->html_icon('flags', $v);
39214d99ec0SAndreas Gohr                } elseif($k == 'html') {
39314d99ec0SAndreas Gohr                    echo $v;
39414d99ec0SAndreas Gohr                } else {
39514d99ec0SAndreas Gohr                    echo hsc($v);
39614d99ec0SAndreas Gohr                }
39714d99ec0SAndreas Gohr                echo '</td>';
39814d99ec0SAndreas Gohr            }
39914d99ec0SAndreas Gohr            echo '</tr>';
4002507f8e0SAndreas Gohr
4012507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4022507f8e0SAndreas Gohr            $count++;
40314d99ec0SAndreas Gohr        }
40414d99ec0SAndreas Gohr        echo '</table>';
4052507f8e0SAndreas Gohr
4062507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager, count($result) > $pager);
4071878f16fSAndreas Gohr    }
4081878f16fSAndreas Gohr
40913a86c14SAndreas Gohr    function html_icon($type, $value) {
41013a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/', '', $value));
4119bb008afSAndreas Gohr        $value = str_replace(' ', '_', $value);
41213a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png';
413dffb869bSAndreas Gohr        if($type == 'flags') {
414dffb869bSAndreas Gohr            $w = 18;
415dffb869bSAndreas Gohr            $h = 12;
416dffb869bSAndreas Gohr        } else {
417dffb869bSAndreas Gohr            $w = 16;
418dffb869bSAndreas Gohr            $h = 16;
419dffb869bSAndreas Gohr        }
42013a86c14SAndreas Gohr        if(file_exists(DOKU_INC . $file)) {
421dffb869bSAndreas Gohr            echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />';
42213a86c14SAndreas Gohr        }
42313a86c14SAndreas Gohr    }
4241878f16fSAndreas Gohr}
425