xref: /plugin/statistics/admin.php (revision 047fcb0f7b78224e30f1c86ced663810afacb301)
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',
38cae4a1c5SAndreas 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) {
82*047fcb0fSAndreas Gohr        // swap if wrong order
83*047fcb0fSAndreas Gohr        if($from > $to) list($from, $to) = array($to, $from);
84*047fcb0fSAndreas Gohr
853bf3de81SAndreas Gohr        $this->tlimit = $this->hlp->Query()->mktlimit($from, $to);
86e8699bceSAndreas Gohr        $this->from   = $from;
87e8699bceSAndreas Gohr        $this->to     = $to;
881878f16fSAndreas Gohr    }
891878f16fSAndreas Gohr
901878f16fSAndreas Gohr    /**
9179b4a855SAndreas Gohr     * Output the Statistics
921878f16fSAndreas Gohr     */
931878f16fSAndreas Gohr    function html() {
941d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
950c3b1e44SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
96264f1744SAndreas Gohr        $this->html_timeselect();
97441bfb8eSAndreas Gohr        tpl_flush();
98264f1744SAndreas Gohr
9979b4a855SAndreas Gohr        $method = 'html_' . $this->opt;
10079b4a855SAndreas Gohr        if(method_exists($this, $method)) {
101a901d721SAndreas Gohr            echo '<div class="plg_stats_' . $this->opt . '">';
102a901d721SAndreas Gohr            echo '<h2>' . $this->getLang($this->opt) . '</h2>';
10379b4a855SAndreas Gohr            $this->$method();
104a901d721SAndreas Gohr            echo '</div>';
10514d99ec0SAndreas Gohr        }
1061d2d78ccSAndreas Gohr        echo '</div>';
10714d99ec0SAndreas Gohr    }
10814d99ec0SAndreas Gohr
1096b6f8822SAndreas Gohr    /**
1106b6f8822SAndreas Gohr     * Return the TOC
1116b6f8822SAndreas Gohr     *
1126b6f8822SAndreas Gohr     * @return array
1136b6f8822SAndreas Gohr     */
11447ffcf7dSAndreas Gohr    function getTOC() {
11547ffcf7dSAndreas Gohr        $toc = array();
116a901d721SAndreas Gohr        foreach($this->pages as $page) {
11747ffcf7dSAndreas Gohr            $toc[] = array(
11847ffcf7dSAndreas Gohr                'link'  => '?do=admin&amp;page=statistics&amp;opt=' . $page . '&amp;f=' . $this->from . '&amp;t=' . $this->to,
11947ffcf7dSAndreas Gohr                'title' => $this->getLang($page),
12047ffcf7dSAndreas Gohr                'level' => 1,
12147ffcf7dSAndreas Gohr                'type'  => 'ul'
12247ffcf7dSAndreas Gohr            );
12347ffcf7dSAndreas Gohr        }
12447ffcf7dSAndreas Gohr        return $toc;
1259da6395dSAndreas Gohr    }
1269da6395dSAndreas Gohr
127dc7b1e5eSAndreas Gohr    function html_graph($name, $width, $height) {
128dc7b1e5eSAndreas Gohr        $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name .
129dc7b1e5eSAndreas Gohr            '&amp;f=' . $this->from . '&amp;t=' . $this->to;
130dc7b1e5eSAndreas Gohr        echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>';
131dc7b1e5eSAndreas Gohr    }
132dc7b1e5eSAndreas Gohr
1336b6f8822SAndreas Gohr    /**
1346b6f8822SAndreas Gohr     * Outputs pagination links
1356b6f8822SAndreas Gohr     *
13633a136e5SAndreas Gohr     * @param int $limit
13733a136e5SAndreas Gohr     * @param int $next
1386b6f8822SAndreas Gohr     */
1392507f8e0SAndreas Gohr    function html_pager($limit, $next) {
1402507f8e0SAndreas Gohr        echo '<div class="plg_stats_pager">';
1412507f8e0SAndreas Gohr
1422507f8e0SAndreas Gohr        if($this->start > 0) {
1432507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
144d43cd6e0SAndreas 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>';
1452507f8e0SAndreas Gohr        }
1462507f8e0SAndreas Gohr
1472507f8e0SAndreas Gohr        if($next) {
1482507f8e0SAndreas Gohr            $go = $this->start + $limit;
149d43cd6e0SAndreas 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>';
1502507f8e0SAndreas Gohr        }
1512507f8e0SAndreas Gohr        echo '</div>';
1522507f8e0SAndreas Gohr    }
1532507f8e0SAndreas Gohr
154264f1744SAndreas Gohr    /**
155264f1744SAndreas Gohr     * Print the time selection menu
156264f1744SAndreas Gohr     */
15714d99ec0SAndreas Gohr    function html_timeselect() {
1586985b606SAndreas Gohr        $today  = date('Y-m-d');
1596985b606SAndreas Gohr        $last1  = date('Y-m-d', time() - (60 * 60 * 24));
1606985b606SAndreas Gohr        $last7  = date('Y-m-d', time() - (60 * 60 * 24 * 7));
1616985b606SAndreas Gohr        $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30));
16214d99ec0SAndreas Gohr
163264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
1646985b606SAndreas Gohr        echo '<span>' . $this->getLang('time_select') . '</span> ';
165264f1744SAndreas Gohr
166*047fcb0fSAndreas Gohr        echo '<form action="'.DOKU_SCRIPT.'" method="get">';
167264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
168264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
169264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="' . $this->opt . '" />';
170*047fcb0fSAndreas Gohr        echo '<input type="text" name="f" value="' . $this->from . '" class="edit datepicker" />';
171*047fcb0fSAndreas Gohr        echo '<input type="text" name="t" value="' . $this->to . '" class="edit datepicker" />';
172264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
17314d99ec0SAndreas Gohr        echo '</form>';
174264f1744SAndreas Gohr
1756985b606SAndreas Gohr        echo '<ul>';
1766985b606SAndreas Gohr        foreach(array('today', 'last1', 'last7', 'last30') as $time) {
1776985b606SAndreas Gohr            echo '<li>';
1786985b606SAndreas Gohr            echo '<a href="?do=admin&amp;page=statistics&amp;opt=' . $this->opt . '&amp;f=' . $$time . '&amp;t=' . $today . '">';
1796985b606SAndreas Gohr            echo $this->getLang('time_' . $time);
1806985b606SAndreas Gohr            echo '</a>';
1816985b606SAndreas Gohr            echo '</li>';
1826985b606SAndreas Gohr        }
1836985b606SAndreas Gohr        echo '</ul>';
1846985b606SAndreas Gohr
185264f1744SAndreas Gohr        echo '</div>';
18614d99ec0SAndreas Gohr    }
18714d99ec0SAndreas Gohr
188f5f32cbfSAndreas Gohr    /**
189f5f32cbfSAndreas Gohr     * Print an introductionary screen
190f5f32cbfSAndreas Gohr     */
19114d99ec0SAndreas Gohr    function html_dashboard() {
192878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_dashboard') . '</p>';
1932812a751SAndreas Gohr
1942812a751SAndreas Gohr        // general info
1952812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
1966b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
1971d2d78ccSAndreas Gohr
1981d2d78ccSAndreas Gohr        echo '<ul class="left">';
19933a136e5SAndreas Gohr        foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) {
200eabe0d07SAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
201eabe0d07SAndreas Gohr        }
2022812a751SAndreas Gohr        echo '</ul>';
2031d2d78ccSAndreas Gohr
2041d2d78ccSAndreas Gohr        echo '<ul class="left">';
2051d2d78ccSAndreas Gohr        foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) {
2061d2d78ccSAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
2071d2d78ccSAndreas Gohr        }
2081d2d78ccSAndreas Gohr        echo '</ul>';
2091d2d78ccSAndreas Gohr
210259897e1SAndreas Gohr        $this->html_graph('dashboardviews', 700, 280);
211259897e1SAndreas Gohr        $this->html_graph('dashboardwiki', 700, 280);
2122812a751SAndreas Gohr        echo '</div>';
2132812a751SAndreas Gohr
21487d5e44bSAndreas Gohr        // top pages today
215264f1744SAndreas Gohr        echo '<div>';
216dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>';
2176b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15);
2182812a751SAndreas Gohr        $this->html_resulttable($result);
219d43cd6e0SAndreas 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>';
220264f1744SAndreas Gohr        echo '</div>';
22187d5e44bSAndreas Gohr
22287d5e44bSAndreas Gohr        // top referer today
223264f1744SAndreas Gohr        echo '<div>';
224dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>';
2256b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15);
2262812a751SAndreas Gohr        $this->html_resulttable($result);
227d43cd6e0SAndreas 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>';
228264f1744SAndreas Gohr        echo '</div>';
22954f6c432SAndreas Gohr
23029dea504SAndreas Gohr        // top searches today
231264f1744SAndreas Gohr        echo '<div>';
232dc7b1e5eSAndreas Gohr        echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>';
23312b59231SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15);
23429dea504SAndreas Gohr        $this->html_resulttable($result);
235d43cd6e0SAndreas 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>';
236264f1744SAndreas Gohr        echo '</div>';
23714d99ec0SAndreas Gohr    }
23814d99ec0SAndreas Gohr
239cae4a1c5SAndreas Gohr    function html_history() {
240cae4a1c5SAndreas Gohr        echo '<p>' . $this->getLang('intro_history') . '</p>';
241338987f5SAndreas Gohr        $this->html_graph('history_page_count', 600, 200);
242338987f5SAndreas Gohr        $this->html_graph('history_page_size', 600, 200);
243338987f5SAndreas Gohr        $this->html_graph('history_media_count', 600, 200);
244338987f5SAndreas Gohr        $this->html_graph('history_media_size', 600, 200);
245cae4a1c5SAndreas Gohr    }
246cae4a1c5SAndreas Gohr
247c67866d1SAndreas Gohr    function html_countries() {
248878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_countries') . '</p>';
249878be5c9SAndreas Gohr        $this->html_graph('countries', 400, 200);
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() {
255878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_page') . '</p>';
2566b6f8822SAndreas Gohr        $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150);
2572507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
2589da6395dSAndreas Gohr    }
2599da6395dSAndreas Gohr
2601664ba1dSAndreas Gohr    function html_edits() {
2611664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_edits') . '</p>';
2621664ba1dSAndreas Gohr        $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150);
2631664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2641664ba1dSAndreas Gohr    }
2651664ba1dSAndreas Gohr
2661664ba1dSAndreas Gohr    function html_images() {
2671664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_images') . '</p>';
2681664ba1dSAndreas Gohr        $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150);
2691664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2701664ba1dSAndreas Gohr    }
2711664ba1dSAndreas Gohr
2721664ba1dSAndreas Gohr    function html_downloads() {
2731664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_downloads') . '</p>';
2741664ba1dSAndreas Gohr        $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150);
2751664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
2761664ba1dSAndreas Gohr    }
2771664ba1dSAndreas Gohr
2784f41a2ccSAndreas Gohr    function html_browsers() {
279878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_browsers') . '</p>';
280878be5c9SAndreas Gohr        $this->html_graph('browsers', 400, 200);
2816b6f8822SAndreas Gohr        $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true);
2822507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
28375fa767dSAndreas Gohr    }
28475fa767dSAndreas Gohr
285bd4217d3SAndreas Gohr    function html_os() {
286878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_os') . '</p>';
287878be5c9SAndreas Gohr        $this->html_graph('os', 400, 200);
2886b6f8822SAndreas Gohr        $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true);
2892507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
290bd4217d3SAndreas Gohr    }
291bd4217d3SAndreas Gohr
2929da6395dSAndreas Gohr    function html_referer() {
2936b6f8822SAndreas Gohr        $result = $this->hlp->Query()->aggregate($this->tlimit);
2942812a751SAndreas Gohr
2952812a751SAndreas Gohr        $all = $result['search'] + $result['external'] + $result['direct'];
2962812a751SAndreas Gohr
29794023548SAndreas Gohr        if($all) {
2980863c19cSAndreas Gohr            printf(
2990863c19cSAndreas Gohr                '<p>' . $this->getLang('intro_referer') . '</p>',
300878be5c9SAndreas Gohr                $all, $result['direct'], (100 * $result['direct'] / $all),
3012812a751SAndreas Gohr                $result['search'], (100 * $result['search'] / $all), $result['external'],
3020863c19cSAndreas Gohr                (100 * $result['external'] / $all)
3030863c19cSAndreas Gohr            );
30494023548SAndreas Gohr        }
3052812a751SAndreas Gohr
3066b6f8822SAndreas Gohr        $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150);
3072507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3089da6395dSAndreas Gohr    }
3099da6395dSAndreas Gohr
310e7a2f1e0SAndreas Gohr    function html_newreferer() {
311878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_newreferer') . '</p>';
312e7a2f1e0SAndreas Gohr
3136b6f8822SAndreas Gohr        $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150);
3142507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
315e7a2f1e0SAndreas Gohr    }
316e7a2f1e0SAndreas Gohr
317e25286daSAndreas Gohr    function html_outlinks() {
318878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_outlinks') . '</p>';
3196b6f8822SAndreas Gohr        $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150);
320e25286daSAndreas Gohr        $this->html_resulttable($result, '', 150);
321e25286daSAndreas Gohr    }
322e25286daSAndreas Gohr
32312dcdeccSAndreas Gohr    function html_searchphrases() {
324878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchphrases') . '</p>';
3255bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150);
32612dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
32712dcdeccSAndreas Gohr    }
32812dcdeccSAndreas Gohr
32912dcdeccSAndreas Gohr    function html_searchwords() {
330878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchwords') . '</p>';
3315bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150);
3325bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
3335bccfe87SAndreas Gohr    }
3345bccfe87SAndreas Gohr
3355bccfe87SAndreas Gohr    function html_internalsearchphrases() {
336878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>';
3375bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150);
3385bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
3395bccfe87SAndreas Gohr    }
3405bccfe87SAndreas Gohr
3415bccfe87SAndreas Gohr    function html_internalsearchwords() {
342878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>';
3435bccfe87SAndreas Gohr        $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150);
34412dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
34512dcdeccSAndreas Gohr    }
34612dcdeccSAndreas Gohr
34712dcdeccSAndreas Gohr    function html_searchengines() {
348878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchengines') . '</p>';
34925b71d4bSAndreas Gohr        $this->html_graph('searchengines', 400, 200);
3506b6f8822SAndreas Gohr        $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150);
35112dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
35212dcdeccSAndreas Gohr    }
35312dcdeccSAndreas Gohr
354c73e16f1SAndreas Gohr    function html_resolution() {
35525446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_resolution') . '</p>';
35625446aa2SAndreas Gohr        $this->html_graph('resolution', 650, 490);
357307baf3fSAndreas Gohr        $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150);
358307baf3fSAndreas Gohr        $this->html_resulttable($result, '', 150);
35925446aa2SAndreas Gohr    }
360307baf3fSAndreas Gohr
36125446aa2SAndreas Gohr    function html_viewport() {
36225446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_viewport') . '</p>';
36325446aa2SAndreas Gohr        $this->html_graph('viewport', 650, 490);
36425446aa2SAndreas Gohr        $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150);
36525446aa2SAndreas Gohr        $this->html_resulttable($result, '', 150);
366c73e16f1SAndreas Gohr    }
3679da6395dSAndreas Gohr
36833a136e5SAndreas Gohr    function html_seenusers() {
36933a136e5SAndreas Gohr        echo '<p>' . $this->getLang('intro_seenusers') . '</p>';
37033a136e5SAndreas Gohr        $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150);
37133a136e5SAndreas Gohr        $this->html_resulttable($result, '', 150);
37233a136e5SAndreas Gohr    }
37333a136e5SAndreas Gohr
37414d99ec0SAndreas Gohr    /**
37514d99ec0SAndreas Gohr     * Display a result in a HTML table
37614d99ec0SAndreas Gohr     */
3772507f8e0SAndreas Gohr    function html_resulttable($result, $header = '', $pager = 0) {
37814d99ec0SAndreas Gohr        echo '<table>';
3792812a751SAndreas Gohr        if(is_array($header)) {
38014d99ec0SAndreas Gohr            echo '<tr>';
38114d99ec0SAndreas Gohr            foreach($header as $h) {
38214d99ec0SAndreas Gohr                echo '<th>' . hsc($h) . '</th>';
38314d99ec0SAndreas Gohr            }
38414d99ec0SAndreas Gohr            echo '</tr>';
3852812a751SAndreas Gohr        }
38614d99ec0SAndreas Gohr
3872507f8e0SAndreas Gohr        $count = 0;
3882ee939eeSAndreas Gohr        if(is_array($result)) foreach($result as $row) {
38914d99ec0SAndreas Gohr            echo '<tr>';
39014d99ec0SAndreas Gohr            foreach($row as $k => $v) {
391f3818071SAndreas Gohr                if($k == 'res_x') continue;
392f3818071SAndreas Gohr                if($k == 'res_y') continue;
393f3818071SAndreas Gohr
3942812a751SAndreas Gohr                echo '<td class="plg_stats_X' . $k . '">';
39514d99ec0SAndreas Gohr                if($k == 'page') {
39614d99ec0SAndreas Gohr                    echo '<a href="' . wl($v) . '" class="wikilink1">';
39714d99ec0SAndreas Gohr                    echo hsc($v);
39814d99ec0SAndreas Gohr                    echo '</a>';
3991664ba1dSAndreas Gohr                } elseif($k == 'media') {
4001664ba1dSAndreas Gohr                        echo '<a href="' . ml($v) . '" class="wikilink1">';
4011664ba1dSAndreas Gohr                        echo hsc($v);
4021664ba1dSAndreas Gohr                        echo '</a>';
4031664ba1dSAndreas Gohr                } elseif($k == 'filesize') {
4041664ba1dSAndreas Gohr                    echo filesize_h($v);
40514d99ec0SAndreas Gohr                } elseif($k == 'url') {
40654f6c432SAndreas Gohr                    $url = hsc($v);
40783b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url);
4082812a751SAndreas Gohr                    if(strlen($url) > 45) {
4092812a751SAndreas Gohr                        $url = substr($url, 0, 30) . ' &hellip; ' . substr($url, -15);
41054f6c432SAndreas Gohr                    }
41114d99ec0SAndreas Gohr                    echo '<a href="' . $v . '" class="urlextern">';
41254f6c432SAndreas Gohr                    echo $url;
41314d99ec0SAndreas Gohr                    echo '</a>';
4145bccfe87SAndreas Gohr                } elseif($k == 'ilookup') {
4155bccfe87SAndreas Gohr                    echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>';
41629dea504SAndreas Gohr                } elseif($k == 'lookup') {
41729dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">';
41813a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />';
41929dea504SAndreas Gohr                    echo '</a> ';
42029dea504SAndreas Gohr
42129dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">';
42213a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />';
42329dea504SAndreas Gohr                    echo '</a> ';
42429dea504SAndreas Gohr
42513a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">';
42613a86c14SAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />';
42729dea504SAndreas Gohr                    echo '</a> ';
42829dea504SAndreas Gohr
42912dcdeccSAndreas Gohr                } elseif($k == 'engine') {
43013a86c14SAndreas Gohr                    include_once(dirname(__FILE__) . '/inc/searchengines.php');
43113a86c14SAndreas Gohr                    if(isset($SEARCHENGINEINFO[$v])) {
43213a86c14SAndreas Gohr                        echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>';
43313a86c14SAndreas Gohr                    } else {
43413a86c14SAndreas Gohr                        echo hsc(ucwords($v));
43513a86c14SAndreas Gohr                    }
43613a86c14SAndreas Gohr                } elseif($k == 'eflag') {
43713a86c14SAndreas Gohr                    $this->html_icon('search', $v);
43875fa767dSAndreas Gohr                } elseif($k == 'bflag') {
43913a86c14SAndreas Gohr                    $this->html_icon('browser', $v);
440bd4217d3SAndreas Gohr                } elseif($k == 'osflag') {
44113a86c14SAndreas Gohr                    $this->html_icon('os', $v);
44275fa767dSAndreas Gohr                } elseif($k == 'cflag') {
44313a86c14SAndreas Gohr                    $this->html_icon('flags', $v);
44414d99ec0SAndreas Gohr                } elseif($k == 'html') {
44514d99ec0SAndreas Gohr                    echo $v;
44614d99ec0SAndreas Gohr                } else {
44714d99ec0SAndreas Gohr                    echo hsc($v);
44814d99ec0SAndreas Gohr                }
44914d99ec0SAndreas Gohr                echo '</td>';
45014d99ec0SAndreas Gohr            }
45114d99ec0SAndreas Gohr            echo '</tr>';
4522507f8e0SAndreas Gohr
4532507f8e0SAndreas Gohr            if($pager && ($count == $pager)) break;
4542507f8e0SAndreas Gohr            $count++;
45514d99ec0SAndreas Gohr        }
45614d99ec0SAndreas Gohr        echo '</table>';
4572507f8e0SAndreas Gohr
4582507f8e0SAndreas Gohr        if($pager) $this->html_pager($pager, count($result) > $pager);
4591878f16fSAndreas Gohr    }
4601878f16fSAndreas Gohr
46113a86c14SAndreas Gohr    function html_icon($type, $value) {
46213a86c14SAndreas Gohr        $value = strtolower(preg_replace('/[^\w]+/', '', $value));
4639bb008afSAndreas Gohr        $value = str_replace(' ', '_', $value);
46413a86c14SAndreas Gohr        $file  = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png';
465dffb869bSAndreas Gohr        if($type == 'flags') {
466dffb869bSAndreas Gohr            $w = 18;
467dffb869bSAndreas Gohr            $h = 12;
468dffb869bSAndreas Gohr        } else {
469dffb869bSAndreas Gohr            $w = 16;
470dffb869bSAndreas Gohr            $h = 16;
471dffb869bSAndreas Gohr        }
47213a86c14SAndreas Gohr        if(file_exists(DOKU_INC . $file)) {
473dffb869bSAndreas Gohr            echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />';
47413a86c14SAndreas Gohr        }
47513a86c14SAndreas Gohr    }
4761878f16fSAndreas Gohr}
477