xref: /plugin/statistics/admin.php (revision cae4a1c5d0ac2520d0d70293c31b44783a9dea09)
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 {
1733a136e5SAndreas Gohr    /** @var string the currently selected page */
18a901d721SAndreas Gohr    protected $opt = '';
1933a136e5SAndreas Gohr
2033a136e5SAndreas Gohr    /** @var string from date in YYYY-MM-DD */
21a901d721SAndreas Gohr    protected $from = '';
2233a136e5SAndreas Gohr    /** @var string to date in YYYY-MM-DD */
23a901d721SAndreas Gohr    protected $to = '';
2433a136e5SAndreas Gohr    /** @var int Offset to use when displaying paged data */
2533a136e5SAndreas Gohr    protected $start = 0;
2633a136e5SAndreas Gohr
2733a136e5SAndreas Gohr    /** @var string MySQL timelimit statement */
28a901d721SAndreas Gohr    protected $tlimit = '';
29a901d721SAndreas Gohr
3033a136e5SAndreas Gohr    /** @var helper_plugin_statistics  */
3133a136e5SAndreas Gohr    protected $hlp;
3233a136e5SAndreas Gohr
33a901d721SAndreas Gohr    /**
34a901d721SAndreas Gohr     * Available statistic pages
35a901d721SAndreas Gohr     */
360863c19cSAndreas Gohr    protected $pages = array(
371664ba1dSAndreas Gohr        'dashboard', 'page', 'edits', 'images', 'downloads',
38*cae4a1c5SAndreas Gohr        'history', 'referer', 'newreferer',
395bccfe87SAndreas Gohr        'outlinks', 'searchengines', 'searchphrases',
405bccfe87SAndreas Gohr        'searchwords', 'internalsearchphrases',
415bccfe87SAndreas Gohr        'internalsearchwords', 'browsers', 'os',
4233a136e5SAndreas Gohr        'countries', 'resolution', 'viewport',
4333a136e5SAndreas Gohr        'seenusers'
440863c19cSAndreas Gohr    );
451878f16fSAndreas Gohr
461878f16fSAndreas Gohr    /**
476b6f8822SAndreas Gohr     * Initialize the helper
486b6f8822SAndreas Gohr     */
496b6f8822SAndreas Gohr    public function __construct() {
506b6f8822SAndreas Gohr        $this->hlp = plugin_load('helper', 'statistics');
516b6f8822SAndreas Gohr    }
526b6f8822SAndreas Gohr
536b6f8822SAndreas Gohr    /**
541878f16fSAndreas Gohr     * Access for managers allowed
551878f16fSAndreas Gohr     */
566b6f8822SAndreas Gohr    public function forAdminOnly() {
571878f16fSAndreas Gohr        return false;
581878f16fSAndreas Gohr    }
591878f16fSAndreas Gohr
601878f16fSAndreas Gohr    /**
611878f16fSAndreas Gohr     * return sort order for position in admin menu
621878f16fSAndreas Gohr     */
636b6f8822SAndreas Gohr    public function getMenuSort() {
646b6f8822SAndreas Gohr        return 350;
651878f16fSAndreas Gohr    }
661878f16fSAndreas Gohr
671878f16fSAndreas Gohr    /**
681878f16fSAndreas Gohr     * handle user request
691878f16fSAndreas Gohr     */
706b6f8822SAndreas Gohr    public function handle() {
71264f1744SAndreas Gohr        $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']);
72a901d721SAndreas Gohr        if(!in_array($this->opt, $this->pages)) $this->opt = 'dashboard';
73a901d721SAndreas Gohr
7495eb68e6SAndreas Gohr        $this->start = (int) $_REQUEST['s'];
75e8699bceSAndreas Gohr        $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']);
76e8699bceSAndreas Gohr    }
7795eb68e6SAndreas Gohr
78e8699bceSAndreas Gohr    /**
79e8699bceSAndreas Gohr     * set limit clause
80e8699bceSAndreas Gohr     */
816b6f8822SAndreas Gohr    public function setTimeframe($from, $to) {
823bf3de81SAndreas Gohr        $this->tlimit = $this->hlp->Query()->mktlimit($from, $to);
83e8699bceSAndreas Gohr        $this->from   = $from;
84e8699bceSAndreas Gohr        $this->to     = $to;
851878f16fSAndreas Gohr    }
861878f16fSAndreas Gohr
871878f16fSAndreas Gohr    /**
8879b4a855SAndreas Gohr     * Output the Statistics
891878f16fSAndreas Gohr     */
901878f16fSAndreas Gohr    function html() {
911d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
920c3b1e44SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
93264f1744SAndreas Gohr        $this->html_timeselect();
94441bfb8eSAndreas Gohr        tpl_flush();
95264f1744SAndreas Gohr
9679b4a855SAndreas Gohr        $method = 'html_' . $this->opt;
9779b4a855SAndreas Gohr        if(method_exists($this, $method)) {
98a901d721SAndreas Gohr            echo '<div class="plg_stats_' . $this->opt . '">';
99a901d721SAndreas Gohr            echo '<h2>' . $this->getLang($this->opt) . '</h2>';
10079b4a855SAndreas Gohr            $this->$method();
101a901d721SAndreas Gohr            echo '</div>';
10214d99ec0SAndreas Gohr        }
1031d2d78ccSAndreas Gohr        echo '</div>';
10414d99ec0SAndreas Gohr    }
10514d99ec0SAndreas Gohr
1066b6f8822SAndreas Gohr    /**
1076b6f8822SAndreas Gohr     * Return the TOC
1086b6f8822SAndreas Gohr     *
1096b6f8822SAndreas Gohr     * @return array
1106b6f8822SAndreas Gohr     */
11147ffcf7dSAndreas Gohr    function getTOC() {
11247ffcf7dSAndreas Gohr        $toc = array();
113a901d721SAndreas Gohr        foreach($this->pages as $page) {
11447ffcf7dSAndreas Gohr            $toc[] = array(
11547ffcf7dSAndreas Gohr                'link'  => '?do=admin&amp;page=statistics&amp;opt=' . $page . '&amp;f=' . $this->from . '&amp;t=' . $this->to,
11647ffcf7dSAndreas Gohr                'title' => $this->getLang($page),
11747ffcf7dSAndreas Gohr                'level' => 1,
11847ffcf7dSAndreas Gohr                'type'  => 'ul'
11947ffcf7dSAndreas Gohr            );
12047ffcf7dSAndreas Gohr        }
12147ffcf7dSAndreas Gohr        return $toc;
1229da6395dSAndreas Gohr    }
1239da6395dSAndreas Gohr
124dc7b1e5eSAndreas Gohr    function html_graph($name, $width, $height) {
125dc7b1e5eSAndreas Gohr        $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name .
126dc7b1e5eSAndreas Gohr            '&amp;f=' . $this->from . '&amp;t=' . $this->to;
127dc7b1e5eSAndreas Gohr        echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>';
128dc7b1e5eSAndreas Gohr    }
129dc7b1e5eSAndreas Gohr
1306b6f8822SAndreas Gohr    /**
1316b6f8822SAndreas Gohr     * Outputs pagination links
1326b6f8822SAndreas Gohr     *
13333a136e5SAndreas Gohr     * @param int $limit
13433a136e5SAndreas Gohr     * @param int $next
1356b6f8822SAndreas Gohr     */
1362507f8e0SAndreas Gohr    function html_pager($limit, $next) {
1372507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1382507f8e0SAndreas Gohr
1392507f8e0SAndreas Gohr        if($this->start > 0) {
1402507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
141d43cd6e0SAndreas 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>';
1422507f8e0SAndreas Gohr        }
1432507f8e0SAndreas Gohr
1442507f8e0SAndreas Gohr        if($next) {
1452507f8e0SAndreas Gohr            $go = $this->start + $limit;
146d43cd6e0SAndreas 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>';
1472507f8e0SAndreas Gohr        }
1482507f8e0SAndreas Gohr        echo '</div>';
1492507f8e0SAndreas Gohr    }
1502507f8e0SAndreas Gohr
151264f1744SAndreas Gohr    /**
152264f1744SAndreas Gohr     * Print the time selection menu
153264f1744SAndreas Gohr     */
15414d99ec0SAndreas Gohr    function html_timeselect() {
1556985b606SAndreas Gohr        $today  = date('Y-m-d');
1566985b606SAndreas Gohr        $last1  = date('Y-m-d', time() - (60 * 60 * 24));
1576985b606SAndreas Gohr        $last7  = date('Y-m-d', time() - (60 * 60 * 24 * 7));
1586985b606SAndreas Gohr        $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30));
15914d99ec0SAndreas Gohr
160264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
1616985b606SAndreas Gohr        echo '<span>' . $this->getLang('time_select') . '</span> ';
162264f1744SAndreas Gohr
163264f1744SAndreas Gohr        echo '<form action="" method="get">';
164264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
165264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
166264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="' . $this->opt . '" />';
167264f1744SAndreas Gohr        echo '<input type="text" name="f" value="' . $this->from . '" class="edit" />';
168264f1744SAndreas Gohr        echo '<input type="text" name="t" value="' . $this->to . '" class="edit" />';
169264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
17014d99ec0SAndreas Gohr        echo '</form>';
171264f1744SAndreas Gohr
1726985b606SAndreas Gohr        echo '<ul>';
1736985b606SAndreas Gohr        foreach(array('today', 'last1', 'last7', 'last30') as $time) {
1746985b606SAndreas Gohr            echo '<li>';
1756985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt=' . $this->opt . '&amp;f=' . $$time . '&amp;t=' . $today . '">';
1766985b606SAndreas Gohr            echo $this->getLang('time_' . $time);
1776985b606SAndreas Gohr            echo '</a>';
1786985b606SAndreas Gohr            echo '</li>';
1796985b606SAndreas Gohr        }
1806985b606SAndreas Gohr        echo '</ul>';
1816985b606SAndreas Gohr
182264f1744SAndreas Gohr        echo '</div>';
18314d99ec0SAndreas Gohr    }
18414d99ec0SAndreas Gohr
185f5f32cbfSAndreas Gohr    /**
186f5f32cbfSAndreas Gohr     * Print an introductionary screen
187f5f32cbfSAndreas Gohr     */
18814d99ec0SAndreas Gohr    function html_dashboard() {
189878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_dashboard') . '</p>';
1902812a751SAndreas Gohr
1912812a751SAndreas Gohr        // general info
1922812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
1936b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
1941d2d78ccSAndreas Gohr
1951d2d78ccSAndreas Gohr        echo '<ul class="left">';
19633a136e5SAndreas Gohr        foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) {
197eabe0d07SAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
198eabe0d07SAndreas Gohr        }
1992812a751SAndreas Gohr        echo '</ul>';
2001d2d78ccSAndreas Gohr
2011d2d78ccSAndreas Gohr        echo '<ul class="left">';
2021d2d78ccSAndreas Gohr        foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) {
2031d2d78ccSAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
2041d2d78ccSAndreas Gohr        }
2051d2d78ccSAndreas Gohr        echo '</ul>';
2061d2d78ccSAndreas Gohr
207259897e1SAndreas Gohr        $this->html_graph('dashboardviews', 700, 280);
208259897e1SAndreas Gohr        $this->html_graph('dashboardwiki', 700, 280);
2092812a751SAndreas Gohr        echo '</div>';
2102812a751SAndreas 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);
216d43cd6e0SAndreas 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>';
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);
224d43cd6e0SAndreas 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>';
225264f1744SAndreas Gohr        echo '</div>';
22654f6c432SAndreas Gohr
22729dea504SAndreas Gohr        // top searches today
228264f1744SAndreas Gohr        echo '<div>';
229dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>';
23012b59231SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15);
23129dea504SAndreas Gohr        $this->html_resulttable($result);
232d43cd6e0SAndreas 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>';
233264f1744SAndreas Gohr        echo '</div>';
23414d99ec0SAndreas Gohr    }
23514d99ec0SAndreas Gohr
236*cae4a1c5SAndreas Gohr    function html_history() {
237*cae4a1c5SAndreas Gohr        echo '<p>' . $this->getLang('intro_history') . '</p>';
238*cae4a1c5SAndreas Gohr        $this->html_graph('history', 600, 200);
239*cae4a1c5SAndreas Gohr        #$result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150);
240*cae4a1c5SAndreas Gohr        #$this->html_resulttable($result, '', 150);
241*cae4a1c5SAndreas Gohr    }
242*cae4a1c5SAndreas Gohr
243c67866d1SAndreas Gohr    function html_countries() {
244878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_countries') . '</p>';
245878be5c9SAndreas Gohr        $this->html_graph('countries', 400, 200);
2466b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150);
2472507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2489da6395dSAndreas Gohr    }
2499da6395dSAndreas Gohr
2509da6395dSAndreas Gohr    function html_page() {
251878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_page') . '</p>';
2526b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150);
2532507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2549da6395dSAndreas Gohr    }
2559da6395dSAndreas Gohr
2561664ba1dSAndreas Gohr    function html_edits() {
2571664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_edits') . '</p>';
2581664ba1dSAndreas Gohr        $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150);
2591664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2601664ba1dSAndreas Gohr    }
2611664ba1dSAndreas Gohr
2621664ba1dSAndreas Gohr    function html_images() {
2631664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_images') . '</p>';
2641664ba1dSAndreas Gohr        $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150);
2651664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2661664ba1dSAndreas Gohr    }
2671664ba1dSAndreas Gohr
2681664ba1dSAndreas Gohr    function html_downloads() {
2691664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_downloads') . '</p>';
2701664ba1dSAndreas Gohr        $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150);
2711664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2721664ba1dSAndreas Gohr    }
2731664ba1dSAndreas Gohr
2744f41a2ccSAndreas Gohr    function html_browsers() {
275878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_browsers') . '</p>';
276878be5c9SAndreas Gohr        $this->html_graph('browsers', 400, 200);
2776b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true);
2782507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
27975fa767dSAndreas Gohr    }
28075fa767dSAndreas Gohr
281bd4217d3SAndreas Gohr    function html_os() {
282878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_os') . '</p>';
283878be5c9SAndreas Gohr        $this->html_graph('os', 400, 200);
2846b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true);
2852507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
286bd4217d3SAndreas Gohr    }
287bd4217d3SAndreas Gohr
2889da6395dSAndreas Gohr    function html_referer() {
2896b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2902812a751SAndreas Gohr
2912812a751SAndreas Gohr        $all = $result['search'] + $result['external'] + $result['direct'];
2922812a751SAndreas Gohr
29394023548SAndreas Gohr        if($all) {
2940863c19cSAndreas Gohr            printf(
2950863c19cSAndreas Gohr                '<p>' . $this->getLang('intro_referer') . '</p>',
296878be5c9SAndreas Gohr                $all, $result['direct'], (100 * $result['direct'] / $all),
2972812a751SAndreas Gohr                $result['search'], (100 * $result['search'] / $all), $result['external'],
2980863c19cSAndreas Gohr                (100 * $result['external'] / $all)
2990863c19cSAndreas Gohr            );
30094023548SAndreas Gohr        }
3012812a751SAndreas Gohr
3026b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150);
3032507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3049da6395dSAndreas Gohr    }
3059da6395dSAndreas Gohr
306e7a2f1e0SAndreas Gohr    function html_newreferer() {
307878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_newreferer') . '</p>';
308e7a2f1e0SAndreas Gohr
3096b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150);
3102507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
311e7a2f1e0SAndreas Gohr    }
312e7a2f1e0SAndreas Gohr
313e25286daSAndreas Gohr    function html_outlinks() {
314878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_outlinks') . '</p>';
3156b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150);
316e25286daSAndreas Gohr        $this->html_resulttable($result, '', 150);
317e25286daSAndreas Gohr    }
318e25286daSAndreas Gohr
31912dcdeccSAndreas Gohr    function html_searchphrases() {
320878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchphrases') . '</p>';
3215bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150);
32212dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
32312dcdeccSAndreas Gohr    }
32412dcdeccSAndreas Gohr
32512dcdeccSAndreas Gohr    function html_searchwords() {
326878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchwords') . '</p>';
3275bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150);
3285bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
3295bccfe87SAndreas Gohr    }
3305bccfe87SAndreas Gohr
3315bccfe87SAndreas Gohr    function html_internalsearchphrases() {
332878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>';
3335bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150);
3345bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
3355bccfe87SAndreas Gohr    }
3365bccfe87SAndreas Gohr
3375bccfe87SAndreas Gohr    function html_internalsearchwords() {
338878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>';
3395bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150);
34012dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
34112dcdeccSAndreas Gohr    }
34212dcdeccSAndreas Gohr
34312dcdeccSAndreas Gohr    function html_searchengines() {
344878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchengines') . '</p>';
34525b71d4bSAndreas Gohr        $this->html_graph('searchengines', 400, 200);
3466b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150);
34712dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
34812dcdeccSAndreas Gohr    }
34912dcdeccSAndreas Gohr
350c73e16f1SAndreas Gohr    function html_resolution() {
35125446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_resolution') . '</p>';
35225446aa2SAndreas Gohr        $this->html_graph('resolution', 650, 490);
353307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150);
354307baf3fSAndreas Gohr        $this->html_resulttable($result, '', 150);
35525446aa2SAndreas Gohr    }
356307baf3fSAndreas Gohr
35725446aa2SAndreas Gohr    function html_viewport() {
35825446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_viewport') . '</p>';
35925446aa2SAndreas Gohr        $this->html_graph('viewport', 650, 490);
36025446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150);
36125446aa2SAndreas Gohr        $this->html_resulttable($result, '', 150);
362c73e16f1SAndreas Gohr    }
3639da6395dSAndreas Gohr
36433a136e5SAndreas Gohr    function html_seenusers() {
36533a136e5SAndreas Gohr        echo '<p>' . $this->getLang('intro_seenusers') . '</p>';
36633a136e5SAndreas Gohr        $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150);
36733a136e5SAndreas Gohr        $this->html_resulttable($result, '', 150);
36833a136e5SAndreas Gohr    }
36933a136e5SAndreas Gohr
37014d99ec0SAndreas Gohr    /**
37114d99ec0SAndreas Gohr     * Display a result in a HTML table
37214d99ec0SAndreas Gohr     */
3732507f8e0SAndreas Gohr    function html_resulttable($result, $header = '', $pager = 0) {
37414d99ec0SAndreas Gohr        echo '<table>';
3752812a751SAndreas Gohr        if(is_array($header)) {
37614d99ec0SAndreas Gohr            echo '<tr>';
37714d99ec0SAndreas Gohr            foreach($header as $h) {
37814d99ec0SAndreas Gohr                echo '<th>' . hsc($h) . '</th>';
37914d99ec0SAndreas Gohr            }
38014d99ec0SAndreas Gohr            echo '</tr>';
3812812a751SAndreas Gohr        }
38214d99ec0SAndreas Gohr
3832507f8e0SAndreas Gohr        $count = 0;
3842ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row) {
38514d99ec0SAndreas Gohr            echo '<tr>';
38614d99ec0SAndreas Gohr            foreach($row as $k => $v) {
387f3818071SAndreas Gohr                if($k == 'res_x') continue;
388f3818071SAndreas Gohr                if($k == 'res_y') continue;
389f3818071SAndreas Gohr
3902812a751SAndreas Gohr                echo '<td class="plg_stats_X' . $k . '">';
39114d99ec0SAndreas Gohr                if($k == 'page') {
39214d99ec0SAndreas Gohr                    echo '<a href="' . wl($v) . '" class="wikilink1">';
39314d99ec0SAndreas Gohr                    echo hsc($v);
39414d99ec0SAndreas Gohr                    echo '</a>';
3951664ba1dSAndreas Gohr                } elseif($k == 'media') {
3961664ba1dSAndreas Gohr                        echo '<a href="' . ml($v) . '" class="wikilink1">';
3971664ba1dSAndreas Gohr                        echo hsc($v);
3981664ba1dSAndreas Gohr                        echo '</a>';
3991664ba1dSAndreas Gohr                } elseif($k == 'filesize') {
4001664ba1dSAndreas Gohr                    echo filesize_h($v);
40114d99ec0SAndreas Gohr                } elseif($k == 'url') {
40254f6c432SAndreas Gohr                    $url = hsc($v);
40383b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url);
4042812a751SAndreas Gohr                    if(strlen($url) > 45) {
4052812a751SAndreas Gohr                        $url = substr($url, 0, 30) . ' &hellip; ' . substr($url, -15);
40654f6c432SAndreas Gohr                    }
40714d99ec0SAndreas Gohr                    echo '<a href="' . $v . '" class="urlextern">';
40854f6c432SAndreas Gohr                    echo $url;
40914d99ec0SAndreas Gohr                    echo '</a>';
4105bccfe87SAndreas Gohr                } elseif($k == 'ilookup') {
4115bccfe87SAndreas Gohr                    echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>';
41229dea504SAndreas Gohr                } elseif($k == 'lookup') {
41329dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">';
41413a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
41529dea504SAndreas Gohr                    echo '</a> ';
41629dea504SAndreas Gohr
41729dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">';
41813a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
41929dea504SAndreas Gohr                    echo '</a> ';
42029dea504SAndreas Gohr
42113a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">';
42213a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
42329dea504SAndreas Gohr                    echo '</a> ';
42429dea504SAndreas Gohr
42512dcdeccSAndreas Gohr                } elseif($k == 'engine') {
42613a86c14SAndreas Gohr                    include_once(dirname(__FILE__) . '/inc/searchengines.php');
42713a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])) {
42813a86c14SAndreas Gohr                        echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>';
42913a86c14SAndreas Gohr                    } else {
43013a86c14SAndreas Gohr                        echo hsc(ucwords($v));
43113a86c14SAndreas Gohr                    }
43213a86c14SAndreas Gohr                } elseif($k == 'eflag') {
43313a86c14SAndreas Gohr                    $this->html_icon('search', $v);
43475fa767dSAndreas Gohr                } elseif($k == 'bflag') {
43513a86c14SAndreas Gohr                    $this->html_icon('browser', $v);
436bd4217d3SAndreas Gohr                } elseif($k == 'osflag') {
43713a86c14SAndreas Gohr                    $this->html_icon('os', $v);
43875fa767dSAndreas Gohr                } elseif($k == 'cflag') {
43913a86c14SAndreas Gohr                    $this->html_icon('flags', $v);
44014d99ec0SAndreas Gohr                } elseif($k == 'html') {
44114d99ec0SAndreas Gohr                    echo $v;
44214d99ec0SAndreas Gohr                } else {
44314d99ec0SAndreas Gohr                    echo hsc($v);
44414d99ec0SAndreas Gohr                }
44514d99ec0SAndreas Gohr                echo '</td>';
44614d99ec0SAndreas Gohr            }
44714d99ec0SAndreas Gohr            echo '</tr>';
4482507f8e0SAndreas Gohr
4492507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4502507f8e0SAndreas Gohr            $count++;
45114d99ec0SAndreas Gohr        }
45214d99ec0SAndreas Gohr        echo '</table>';
4532507f8e0SAndreas Gohr
4542507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager, count($result) > $pager);
4551878f16fSAndreas Gohr    }
4561878f16fSAndreas Gohr
45713a86c14SAndreas Gohr    function html_icon($type, $value) {
45813a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/', '', $value));
4599bb008afSAndreas Gohr        $value = str_replace(' ', '_', $value);
46013a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png';
461dffb869bSAndreas Gohr        if($type == 'flags') {
462dffb869bSAndreas Gohr            $w = 18;
463dffb869bSAndreas Gohr            $h = 12;
464dffb869bSAndreas Gohr        } else {
465dffb869bSAndreas Gohr            $w = 16;
466dffb869bSAndreas Gohr            $h = 16;
467dffb869bSAndreas Gohr        }
46813a86c14SAndreas Gohr        if(file_exists(DOKU_INC . $file)) {
469dffb869bSAndreas Gohr            echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />';
47013a86c14SAndreas Gohr        }
47113a86c14SAndreas Gohr    }
4721878f16fSAndreas Gohr}
473