xref: /plugin/statistics/admin.php (revision 616c1e8bfa342cfa9dcabbb51d8eed57ac7e29f7)
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(
3781ff4c3aSAndreas Gohr        'dashboard' => 1,
3881ff4c3aSAndreas Gohr
3981ff4c3aSAndreas Gohr        'content' => array(
4081ff4c3aSAndreas Gohr            'page',
4181ff4c3aSAndreas Gohr            'edits',
4281ff4c3aSAndreas Gohr            'images',
4381ff4c3aSAndreas Gohr            'downloads',
4481ff4c3aSAndreas Gohr            'history',
4581ff4c3aSAndreas Gohr        ),
4681ff4c3aSAndreas Gohr        'users' => array(
4781ff4c3aSAndreas Gohr            'topuser',
4881ff4c3aSAndreas Gohr            'topeditor',
4981ff4c3aSAndreas Gohr            'topgroup',
5081ff4c3aSAndreas Gohr            'topgroupedit',
5181ff4c3aSAndreas Gohr            'seenusers',
5281ff4c3aSAndreas Gohr        ),
5381ff4c3aSAndreas Gohr        'links' => array(
5481ff4c3aSAndreas Gohr            'referer',
5581ff4c3aSAndreas Gohr            'newreferer',
5681ff4c3aSAndreas Gohr            'outlinks',
5781ff4c3aSAndreas Gohr        ),
5881ff4c3aSAndreas Gohr        'search' => array(
5981ff4c3aSAndreas Gohr            'searchengines',
6081ff4c3aSAndreas Gohr            'searchphrases',
6181ff4c3aSAndreas Gohr            'searchwords',
6281ff4c3aSAndreas Gohr            'internalsearchphrases',
6381ff4c3aSAndreas Gohr            'internalsearchwords',
6481ff4c3aSAndreas Gohr        ),
6581ff4c3aSAndreas Gohr        'technology' => array(
6681ff4c3aSAndreas Gohr            'browsers',
6781ff4c3aSAndreas Gohr            'os',
6881ff4c3aSAndreas Gohr            'countries',
6981ff4c3aSAndreas Gohr            'resolution',
7081ff4c3aSAndreas Gohr            'viewport',
7181ff4c3aSAndreas Gohr        ),
720863c19cSAndreas Gohr    );
731878f16fSAndreas Gohr
7481ff4c3aSAndreas Gohr    /** @var array keeps a list of all real content pages, generated from above array */
7581ff4c3aSAndreas Gohr    protected $allowedpages = array();
7681ff4c3aSAndreas Gohr
771878f16fSAndreas Gohr    /**
786b6f8822SAndreas Gohr     * Initialize the helper
796b6f8822SAndreas Gohr     */
806b6f8822SAndreas Gohr    public function __construct() {
816b6f8822SAndreas Gohr        $this->hlp = plugin_load('helper', 'statistics');
8281ff4c3aSAndreas Gohr
8381ff4c3aSAndreas Gohr        // build a list of pages
8481ff4c3aSAndreas Gohr        foreach($this->pages as $key => $val) {
8581ff4c3aSAndreas Gohr            if(is_array($val)) {
8681ff4c3aSAndreas Gohr                $this->allowedpages = array_merge($this->allowedpages, $val);
8781ff4c3aSAndreas Gohr            }else {
8881ff4c3aSAndreas Gohr                $this->allowedpages[] = $key;
8981ff4c3aSAndreas Gohr            }
9081ff4c3aSAndreas Gohr        }
916b6f8822SAndreas Gohr    }
926b6f8822SAndreas Gohr
936b6f8822SAndreas Gohr    /**
941878f16fSAndreas Gohr     * Access for managers allowed
951878f16fSAndreas Gohr     */
966b6f8822SAndreas Gohr    public function forAdminOnly() {
971878f16fSAndreas Gohr        return false;
981878f16fSAndreas Gohr    }
991878f16fSAndreas Gohr
1001878f16fSAndreas Gohr    /**
1011878f16fSAndreas Gohr     * return sort order for position in admin menu
1021878f16fSAndreas Gohr     */
1036b6f8822SAndreas Gohr    public function getMenuSort() {
1046b6f8822SAndreas Gohr        return 350;
1051878f16fSAndreas Gohr    }
1061878f16fSAndreas Gohr
1071878f16fSAndreas Gohr    /**
1081878f16fSAndreas Gohr     * handle user request
1091878f16fSAndreas Gohr     */
1106b6f8822SAndreas Gohr    public function handle() {
111264f1744SAndreas Gohr        $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']);
11281ff4c3aSAndreas Gohr        if(!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard';
113a901d721SAndreas Gohr
11495eb68e6SAndreas Gohr        $this->start = (int) $_REQUEST['s'];
115e8699bceSAndreas Gohr        $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']);
116e8699bceSAndreas Gohr    }
11795eb68e6SAndreas Gohr
118e8699bceSAndreas Gohr    /**
119e8699bceSAndreas Gohr     * set limit clause
120e8699bceSAndreas Gohr     */
1216b6f8822SAndreas Gohr    public function setTimeframe($from, $to) {
122047fcb0fSAndreas Gohr        // swap if wrong order
123047fcb0fSAndreas Gohr        if($from > $to) list($from, $to) = array($to, $from);
124047fcb0fSAndreas Gohr
1253bf3de81SAndreas Gohr        $this->tlimit = $this->hlp->Query()->mktlimit($from, $to);
126e8699bceSAndreas Gohr        $this->from   = $from;
127e8699bceSAndreas Gohr        $this->to     = $to;
1281878f16fSAndreas Gohr    }
1291878f16fSAndreas Gohr
1301878f16fSAndreas Gohr    /**
13179b4a855SAndreas Gohr     * Output the Statistics
1321878f16fSAndreas Gohr     */
1331878f16fSAndreas Gohr    function html() {
1341d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
1350c3b1e44SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
136264f1744SAndreas Gohr        $this->html_timeselect();
137441bfb8eSAndreas Gohr        tpl_flush();
138264f1744SAndreas Gohr
13979b4a855SAndreas Gohr        $method = 'html_' . $this->opt;
14079b4a855SAndreas Gohr        if(method_exists($this, $method)) {
141a901d721SAndreas Gohr            echo '<div class="plg_stats_' . $this->opt . '">';
142a901d721SAndreas Gohr            echo '<h2>' . $this->getLang($this->opt) . '</h2>';
14379b4a855SAndreas Gohr            $this->$method();
144a901d721SAndreas Gohr            echo '</div>';
14514d99ec0SAndreas Gohr        }
1461d2d78ccSAndreas Gohr        echo '</div>';
14714d99ec0SAndreas Gohr    }
14814d99ec0SAndreas Gohr
1496b6f8822SAndreas Gohr    /**
1506b6f8822SAndreas Gohr     * Return the TOC
1516b6f8822SAndreas Gohr     *
1526b6f8822SAndreas Gohr     * @return array
1536b6f8822SAndreas Gohr     */
15447ffcf7dSAndreas Gohr    function getTOC() {
15547ffcf7dSAndreas Gohr        $toc = array();
15681ff4c3aSAndreas Gohr        foreach($this->pages as $key => $info) {
15781ff4c3aSAndreas Gohr            if (is_array($info)) {
15881ff4c3aSAndreas Gohr
15981ff4c3aSAndreas Gohr                $toc[] = html_mktocitem(
16081ff4c3aSAndreas Gohr                    '',
16181ff4c3aSAndreas Gohr                    $this->getLang($key),
16281ff4c3aSAndreas Gohr                    1,
16381ff4c3aSAndreas Gohr                    ''
16447ffcf7dSAndreas Gohr                );
16581ff4c3aSAndreas Gohr
16681ff4c3aSAndreas Gohr                foreach($info as $page) {
16781ff4c3aSAndreas Gohr                    $toc[] = html_mktocitem(
16881ff4c3aSAndreas Gohr                        '?do=admin&amp;page=statistics&amp;opt=' . $page . '&amp;f=' . $this->from . '&amp;t=' . $this->to,
16981ff4c3aSAndreas Gohr                        $this->getLang($page),
17081ff4c3aSAndreas Gohr                        2,
17181ff4c3aSAndreas Gohr                        ''
17281ff4c3aSAndreas Gohr                    );
17381ff4c3aSAndreas Gohr                }
17481ff4c3aSAndreas Gohr            } else {
17581ff4c3aSAndreas Gohr                $toc[] = html_mktocitem(
17681ff4c3aSAndreas Gohr                    '?do=admin&amp;page=statistics&amp;opt=' . $key . '&amp;f=' . $this->from . '&amp;t=' . $this->to,
17781ff4c3aSAndreas Gohr                    $this->getLang($key),
17881ff4c3aSAndreas Gohr                    1,
17981ff4c3aSAndreas Gohr                    ''
18081ff4c3aSAndreas Gohr                );
18181ff4c3aSAndreas Gohr            }
18247ffcf7dSAndreas Gohr        }
18347ffcf7dSAndreas Gohr        return $toc;
1849da6395dSAndreas Gohr    }
1859da6395dSAndreas Gohr
186dc7b1e5eSAndreas Gohr    function html_graph($name, $width, $height) {
187dc7b1e5eSAndreas Gohr        $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name .
188dc7b1e5eSAndreas Gohr            '&amp;f=' . $this->from . '&amp;t=' . $this->to;
189dc7b1e5eSAndreas Gohr        echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>';
190dc7b1e5eSAndreas Gohr    }
191dc7b1e5eSAndreas Gohr
1926b6f8822SAndreas Gohr    /**
1936b6f8822SAndreas Gohr     * Outputs pagination links
1946b6f8822SAndreas Gohr     *
19533a136e5SAndreas Gohr     * @param int $limit
19633a136e5SAndreas Gohr     * @param int $next
1976b6f8822SAndreas Gohr     */
1982507f8e0SAndreas Gohr    function html_pager($limit, $next) {
1992507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
2002507f8e0SAndreas Gohr
2012507f8e0SAndreas Gohr        if($this->start > 0) {
2022507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
203d43cd6e0SAndreas 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>';
2042507f8e0SAndreas Gohr        }
2052507f8e0SAndreas Gohr
2062507f8e0SAndreas Gohr        if($next) {
2072507f8e0SAndreas Gohr            $go = $this->start + $limit;
208d43cd6e0SAndreas 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>';
2092507f8e0SAndreas Gohr        }
2102507f8e0SAndreas Gohr        echo '</div>';
2112507f8e0SAndreas Gohr    }
2122507f8e0SAndreas Gohr
213264f1744SAndreas Gohr    /**
214264f1744SAndreas Gohr     * Print the time selection menu
215264f1744SAndreas Gohr     */
21614d99ec0SAndreas Gohr    function html_timeselect() {
2176985b606SAndreas Gohr        $today  = date('Y-m-d');
2186985b606SAndreas Gohr        $last1  = date('Y-m-d', time() - (60 * 60 * 24));
2196985b606SAndreas Gohr        $last7  = date('Y-m-d', time() - (60 * 60 * 24 * 7));
2206985b606SAndreas Gohr        $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30));
22114d99ec0SAndreas Gohr
222264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
2236985b606SAndreas Gohr        echo '<span>' . $this->getLang('time_select') . '</span> ';
224264f1744SAndreas Gohr
225047fcb0fSAndreas Gohr        echo '<form action="'.DOKU_SCRIPT.'" method="get">';
226264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
227264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
228264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="' . $this->opt . '" />';
229047fcb0fSAndreas Gohr        echo '<input type="text" name="f" value="' . $this->from . '" class="edit datepicker" />';
230047fcb0fSAndreas Gohr        echo '<input type="text" name="t" value="' . $this->to . '" class="edit datepicker" />';
231264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
23214d99ec0SAndreas Gohr        echo '</form>';
233264f1744SAndreas Gohr
2346985b606SAndreas Gohr        echo '<ul>';
2356985b606SAndreas Gohr        foreach(array('today', 'last1', 'last7', 'last30') as $time) {
2366985b606SAndreas Gohr            echo '<li>';
2376985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt=' . $this->opt . '&amp;f=' . $$time . '&amp;t=' . $today . '">';
2386985b606SAndreas Gohr            echo $this->getLang('time_' . $time);
2396985b606SAndreas Gohr            echo '</a>';
2406985b606SAndreas Gohr            echo '</li>';
2416985b606SAndreas Gohr        }
2426985b606SAndreas Gohr        echo '</ul>';
2436985b606SAndreas Gohr
244264f1744SAndreas Gohr        echo '</div>';
24514d99ec0SAndreas Gohr    }
24614d99ec0SAndreas Gohr
247f5f32cbfSAndreas Gohr    /**
248f5f32cbfSAndreas Gohr     * Print an introductionary screen
249f5f32cbfSAndreas Gohr     */
25014d99ec0SAndreas Gohr    function html_dashboard() {
251878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_dashboard') . '</p>';
2522812a751SAndreas Gohr
2532812a751SAndreas Gohr        // general info
2542812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
2556b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2561d2d78ccSAndreas Gohr
2571d2d78ccSAndreas Gohr        echo '<ul class="left">';
25833a136e5SAndreas Gohr        foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) {
259eabe0d07SAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
260eabe0d07SAndreas Gohr        }
2612812a751SAndreas Gohr        echo '</ul>';
2621d2d78ccSAndreas Gohr
2631d2d78ccSAndreas Gohr        echo '<ul class="left">';
2641d2d78ccSAndreas Gohr        foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) {
2651d2d78ccSAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
2661d2d78ccSAndreas Gohr        }
2671d2d78ccSAndreas Gohr        echo '</ul>';
2681d2d78ccSAndreas Gohr
269259897e1SAndreas Gohr        $this->html_graph('dashboardviews', 700, 280);
270259897e1SAndreas Gohr        $this->html_graph('dashboardwiki', 700, 280);
2712812a751SAndreas Gohr        echo '</div>';
2722812a751SAndreas Gohr
27387d5e44bSAndreas Gohr        // top pages today
274264f1744SAndreas Gohr        echo '<div>';
275dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>';
2766b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15);
2772812a751SAndreas Gohr        $this->html_resulttable($result);
278d43cd6e0SAndreas 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>';
279264f1744SAndreas Gohr        echo '</div>';
28087d5e44bSAndreas Gohr
28187d5e44bSAndreas Gohr        // top referer today
282264f1744SAndreas Gohr        echo '<div>';
283dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>';
2846b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15);
2852812a751SAndreas Gohr        $this->html_resulttable($result);
286d43cd6e0SAndreas 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>';
287264f1744SAndreas Gohr        echo '</div>';
28854f6c432SAndreas Gohr
28929dea504SAndreas Gohr        // top searches today
290264f1744SAndreas Gohr        echo '<div>';
291dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>';
29212b59231SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15);
29329dea504SAndreas Gohr        $this->html_resulttable($result);
294d43cd6e0SAndreas 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>';
295264f1744SAndreas Gohr        echo '</div>';
29614d99ec0SAndreas Gohr    }
29714d99ec0SAndreas Gohr
298cae4a1c5SAndreas Gohr    function html_history() {
299cae4a1c5SAndreas Gohr        echo '<p>' . $this->getLang('intro_history') . '</p>';
300338987f5SAndreas Gohr        $this->html_graph('history_page_count', 600, 200);
301338987f5SAndreas Gohr        $this->html_graph('history_page_size', 600, 200);
302338987f5SAndreas Gohr        $this->html_graph('history_media_count', 600, 200);
303338987f5SAndreas Gohr        $this->html_graph('history_media_size', 600, 200);
304cae4a1c5SAndreas Gohr    }
305cae4a1c5SAndreas Gohr
306c67866d1SAndreas Gohr    function html_countries() {
307878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_countries') . '</p>';
308878be5c9SAndreas Gohr        $this->html_graph('countries', 400, 200);
3096b6f8822SAndreas Gohr        $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150);
3102507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3119da6395dSAndreas Gohr    }
3129da6395dSAndreas Gohr
3139da6395dSAndreas Gohr    function html_page() {
314878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_page') . '</p>';
3156b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150);
3162507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3179da6395dSAndreas Gohr    }
3189da6395dSAndreas Gohr
3191664ba1dSAndreas Gohr    function html_edits() {
3201664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_edits') . '</p>';
3211664ba1dSAndreas Gohr        $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150);
3221664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3231664ba1dSAndreas Gohr    }
3241664ba1dSAndreas Gohr
3251664ba1dSAndreas Gohr    function html_images() {
3261664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_images') . '</p>';
327*616c1e8bSAndreas Gohr
328*616c1e8bSAndreas Gohr        $result = $this->hlp->Query()->imagessum($this->tlimit);
329*616c1e8bSAndreas Gohr        echo '<p>';
330*616c1e8bSAndreas Gohr        echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize']));
331*616c1e8bSAndreas Gohr        echo '</p>';
332*616c1e8bSAndreas Gohr
3331664ba1dSAndreas Gohr        $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150);
3341664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3351664ba1dSAndreas Gohr    }
3361664ba1dSAndreas Gohr
3371664ba1dSAndreas Gohr    function html_downloads() {
3381664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_downloads') . '</p>';
339*616c1e8bSAndreas Gohr
340*616c1e8bSAndreas Gohr        $result = $this->hlp->Query()->downloadssum($this->tlimit);
341*616c1e8bSAndreas Gohr        echo '<p>';
342*616c1e8bSAndreas Gohr        echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize']));
343*616c1e8bSAndreas Gohr        echo '</p>';
344*616c1e8bSAndreas Gohr
3451664ba1dSAndreas Gohr        $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150);
3461664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3471664ba1dSAndreas Gohr    }
3481664ba1dSAndreas Gohr
3494f41a2ccSAndreas Gohr    function html_browsers() {
350878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_browsers') . '</p>';
351878be5c9SAndreas Gohr        $this->html_graph('browsers', 400, 200);
3526b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true);
3532507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
35475fa767dSAndreas Gohr    }
35575fa767dSAndreas Gohr
35681ff4c3aSAndreas Gohr    function html_topuser(){
35781ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topuser') . '</p>';
35881ff4c3aSAndreas Gohr        $this->html_graph('topuser', 400, 200);
35981ff4c3aSAndreas Gohr        $result = $this->hlp->Query()->topuser($this->tlimit, $this->start, 150, true);
36081ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
36181ff4c3aSAndreas Gohr    }
36281ff4c3aSAndreas Gohr
36381ff4c3aSAndreas Gohr    function html_topeditor(){
36481ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topeditor') . '</p>';
36581ff4c3aSAndreas Gohr        $this->html_graph('topeditor', 400, 200);
36681ff4c3aSAndreas Gohr        $result = $this->hlp->Query()->topeditor($this->tlimit, $this->start, 150, true);
36781ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
36881ff4c3aSAndreas Gohr    }
36981ff4c3aSAndreas Gohr
37081ff4c3aSAndreas Gohr    function html_topgroup(){
37181ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topgroup') . '</p>';
37281ff4c3aSAndreas Gohr        $this->html_graph('topgroup', 400, 200);
37381ff4c3aSAndreas Gohr        $result = $this->hlp->Query()->topgroup($this->tlimit, $this->start, 150, true);
37481ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
37581ff4c3aSAndreas Gohr    }
37681ff4c3aSAndreas Gohr
37781ff4c3aSAndreas Gohr    function html_topgroupedit(){
37881ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>';
37981ff4c3aSAndreas Gohr        $this->html_graph('topgroupedit', 400, 200);
38081ff4c3aSAndreas Gohr        $result = $this->hlp->Query()->topgroupedit($this->tlimit, $this->start, 150, true);
38181ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
38281ff4c3aSAndreas Gohr    }
38381ff4c3aSAndreas Gohr
384bd4217d3SAndreas Gohr    function html_os() {
385878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_os') . '</p>';
386878be5c9SAndreas Gohr        $this->html_graph('os', 400, 200);
3876b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true);
3882507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
389bd4217d3SAndreas Gohr    }
390bd4217d3SAndreas Gohr
3919da6395dSAndreas Gohr    function html_referer() {
3926b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
3932812a751SAndreas Gohr
3942812a751SAndreas Gohr        $all = $result['search'] + $result['external'] + $result['direct'];
3952812a751SAndreas Gohr
39694023548SAndreas Gohr        if($all) {
3970863c19cSAndreas Gohr            printf(
3980863c19cSAndreas Gohr                '<p>' . $this->getLang('intro_referer') . '</p>',
399878be5c9SAndreas Gohr                $all, $result['direct'], (100 * $result['direct'] / $all),
4002812a751SAndreas Gohr                $result['search'], (100 * $result['search'] / $all), $result['external'],
4010863c19cSAndreas Gohr                (100 * $result['external'] / $all)
4020863c19cSAndreas Gohr            );
40394023548SAndreas Gohr        }
4042812a751SAndreas Gohr
4056b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150);
4062507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
4079da6395dSAndreas Gohr    }
4089da6395dSAndreas Gohr
409e7a2f1e0SAndreas Gohr    function html_newreferer() {
410878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_newreferer') . '</p>';
411e7a2f1e0SAndreas Gohr
4126b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150);
4132507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
414e7a2f1e0SAndreas Gohr    }
415e7a2f1e0SAndreas Gohr
416e25286daSAndreas Gohr    function html_outlinks() {
417878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_outlinks') . '</p>';
4186b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150);
419e25286daSAndreas Gohr        $this->html_resulttable($result, '', 150);
420e25286daSAndreas Gohr    }
421e25286daSAndreas Gohr
42212dcdeccSAndreas Gohr    function html_searchphrases() {
423878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchphrases') . '</p>';
4245bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150);
42512dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
42612dcdeccSAndreas Gohr    }
42712dcdeccSAndreas Gohr
42812dcdeccSAndreas Gohr    function html_searchwords() {
429878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchwords') . '</p>';
4305bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150);
4315bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
4325bccfe87SAndreas Gohr    }
4335bccfe87SAndreas Gohr
4345bccfe87SAndreas Gohr    function html_internalsearchphrases() {
435878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>';
4365bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150);
4375bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
4385bccfe87SAndreas Gohr    }
4395bccfe87SAndreas Gohr
4405bccfe87SAndreas Gohr    function html_internalsearchwords() {
441878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>';
4425bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150);
44312dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
44412dcdeccSAndreas Gohr    }
44512dcdeccSAndreas Gohr
44612dcdeccSAndreas Gohr    function html_searchengines() {
447878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchengines') . '</p>';
44825b71d4bSAndreas Gohr        $this->html_graph('searchengines', 400, 200);
4496b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150);
45012dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
45112dcdeccSAndreas Gohr    }
45212dcdeccSAndreas Gohr
453c73e16f1SAndreas Gohr    function html_resolution() {
45425446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_resolution') . '</p>';
45525446aa2SAndreas Gohr        $this->html_graph('resolution', 650, 490);
456307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150);
457307baf3fSAndreas Gohr        $this->html_resulttable($result, '', 150);
45825446aa2SAndreas Gohr    }
459307baf3fSAndreas Gohr
46025446aa2SAndreas Gohr    function html_viewport() {
46125446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_viewport') . '</p>';
46225446aa2SAndreas Gohr        $this->html_graph('viewport', 650, 490);
46325446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150);
46425446aa2SAndreas Gohr        $this->html_resulttable($result, '', 150);
465c73e16f1SAndreas Gohr    }
4669da6395dSAndreas Gohr
46733a136e5SAndreas Gohr    function html_seenusers() {
46833a136e5SAndreas Gohr        echo '<p>' . $this->getLang('intro_seenusers') . '</p>';
46933a136e5SAndreas Gohr        $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150);
47033a136e5SAndreas Gohr        $this->html_resulttable($result, '', 150);
47133a136e5SAndreas Gohr    }
47233a136e5SAndreas Gohr
47314d99ec0SAndreas Gohr    /**
47414d99ec0SAndreas Gohr     * Display a result in a HTML table
47514d99ec0SAndreas Gohr     */
4762507f8e0SAndreas Gohr    function html_resulttable($result, $header = '', $pager = 0) {
47714d99ec0SAndreas Gohr        echo '<table>';
4782812a751SAndreas Gohr        if(is_array($header)) {
47914d99ec0SAndreas Gohr            echo '<tr>';
48014d99ec0SAndreas Gohr            foreach($header as $h) {
48114d99ec0SAndreas Gohr                echo '<th>' . hsc($h) . '</th>';
48214d99ec0SAndreas Gohr            }
48314d99ec0SAndreas Gohr            echo '</tr>';
4842812a751SAndreas Gohr        }
48514d99ec0SAndreas Gohr
4862507f8e0SAndreas Gohr        $count = 0;
4872ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row) {
48814d99ec0SAndreas Gohr            echo '<tr>';
48914d99ec0SAndreas Gohr            foreach($row as $k => $v) {
490f3818071SAndreas Gohr                if($k == 'res_x') continue;
491f3818071SAndreas Gohr                if($k == 'res_y') continue;
492f3818071SAndreas Gohr
4932812a751SAndreas Gohr                echo '<td class="plg_stats_X' . $k . '">';
49414d99ec0SAndreas Gohr                if($k == 'page') {
49514d99ec0SAndreas Gohr                    echo '<a href="' . wl($v) . '" class="wikilink1">';
49614d99ec0SAndreas Gohr                    echo hsc($v);
49714d99ec0SAndreas Gohr                    echo '</a>';
4981664ba1dSAndreas Gohr                } elseif($k == 'media') {
4991664ba1dSAndreas Gohr                        echo '<a href="' . ml($v) . '" class="wikilink1">';
5001664ba1dSAndreas Gohr                        echo hsc($v);
5011664ba1dSAndreas Gohr                        echo '</a>';
5021664ba1dSAndreas Gohr                } elseif($k == 'filesize') {
5031664ba1dSAndreas Gohr                    echo filesize_h($v);
50414d99ec0SAndreas Gohr                } elseif($k == 'url') {
50554f6c432SAndreas Gohr                    $url = hsc($v);
50683b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url);
5072812a751SAndreas Gohr                    if(strlen($url) > 45) {
5082812a751SAndreas Gohr                        $url = substr($url, 0, 30) . ' &hellip; ' . substr($url, -15);
50954f6c432SAndreas Gohr                    }
51014d99ec0SAndreas Gohr                    echo '<a href="' . $v . '" class="urlextern">';
51154f6c432SAndreas Gohr                    echo $url;
51214d99ec0SAndreas Gohr                    echo '</a>';
5135bccfe87SAndreas Gohr                } elseif($k == 'ilookup') {
5145bccfe87SAndreas Gohr                    echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>';
51529dea504SAndreas Gohr                } elseif($k == 'lookup') {
51629dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">';
51713a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
51829dea504SAndreas Gohr                    echo '</a> ';
51929dea504SAndreas Gohr
52029dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">';
52113a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
52229dea504SAndreas Gohr                    echo '</a> ';
52329dea504SAndreas Gohr
52413a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">';
52513a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
52629dea504SAndreas Gohr                    echo '</a> ';
52729dea504SAndreas Gohr
52812dcdeccSAndreas Gohr                } elseif($k == 'engine') {
52913a86c14SAndreas Gohr                    include_once(dirname(__FILE__) . '/inc/searchengines.php');
53013a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])) {
53113a86c14SAndreas Gohr                        echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>';
53213a86c14SAndreas Gohr                    } else {
53313a86c14SAndreas Gohr                        echo hsc(ucwords($v));
53413a86c14SAndreas Gohr                    }
53513a86c14SAndreas Gohr                } elseif($k == 'eflag') {
53613a86c14SAndreas Gohr                    $this->html_icon('search', $v);
53775fa767dSAndreas Gohr                } elseif($k == 'bflag') {
53813a86c14SAndreas Gohr                    $this->html_icon('browser', $v);
539bd4217d3SAndreas Gohr                } elseif($k == 'osflag') {
54013a86c14SAndreas Gohr                    $this->html_icon('os', $v);
54175fa767dSAndreas Gohr                } elseif($k == 'cflag') {
54213a86c14SAndreas Gohr                    $this->html_icon('flags', $v);
54314d99ec0SAndreas Gohr                } elseif($k == 'html') {
54414d99ec0SAndreas Gohr                    echo $v;
54514d99ec0SAndreas Gohr                } else {
54614d99ec0SAndreas Gohr                    echo hsc($v);
54714d99ec0SAndreas Gohr                }
54814d99ec0SAndreas Gohr                echo '</td>';
54914d99ec0SAndreas Gohr            }
55014d99ec0SAndreas Gohr            echo '</tr>';
5512507f8e0SAndreas Gohr
5522507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
5532507f8e0SAndreas Gohr            $count++;
55414d99ec0SAndreas Gohr        }
55514d99ec0SAndreas Gohr        echo '</table>';
5562507f8e0SAndreas Gohr
5572507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager, count($result) > $pager);
5581878f16fSAndreas Gohr    }
5591878f16fSAndreas Gohr
56013a86c14SAndreas Gohr    function html_icon($type, $value) {
56113a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/', '', $value));
5629bb008afSAndreas Gohr        $value = str_replace(' ', '_', $value);
56313a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png';
564dffb869bSAndreas Gohr        if($type == 'flags') {
565dffb869bSAndreas Gohr            $w = 18;
566dffb869bSAndreas Gohr            $h = 12;
567dffb869bSAndreas Gohr        } else {
568dffb869bSAndreas Gohr            $w = 16;
569dffb869bSAndreas Gohr            $h = 16;
570dffb869bSAndreas Gohr        }
57113a86c14SAndreas Gohr        if(file_exists(DOKU_INC . $file)) {
572dffb869bSAndreas Gohr            echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />';
57313a86c14SAndreas Gohr        }
57413a86c14SAndreas Gohr    }
5751878f16fSAndreas Gohr}
576