xref: /plugin/statistics/admin.php (revision c4c84f989914854a8164dd20e63d673e898e858b)
11878f16fSAndreas Gohr<?php
2a8acb244SAndreas Gohr
3211caa5dSAndreas Gohr// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
4a8acb244SAndreas Gohruse dokuwiki\Extension\AdminPlugin;
5*c4c84f98SAndreas Gohruse dokuwiki\plugin\statistics\SearchEngines;
6a8acb244SAndreas Gohr
71878f16fSAndreas Gohr/**
81878f16fSAndreas Gohr * statistics plugin
91878f16fSAndreas Gohr *
101878f16fSAndreas Gohr * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
116b6f8822SAndreas Gohr * @author     Andreas Gohr <gohr@splitbrain.org>
121878f16fSAndreas Gohr */
13a8acb244SAndreas Gohrclass admin_plugin_statistics extends AdminPlugin
14a8acb244SAndreas Gohr{
1533a136e5SAndreas Gohr    /** @var string the currently selected page */
16a901d721SAndreas Gohr    protected $opt = '';
1733a136e5SAndreas Gohr
1833a136e5SAndreas Gohr    /** @var string from date in YYYY-MM-DD */
19a901d721SAndreas Gohr    protected $from = '';
2033a136e5SAndreas Gohr    /** @var string to date in YYYY-MM-DD */
21a901d721SAndreas Gohr    protected $to = '';
2233a136e5SAndreas Gohr    /** @var int Offset to use when displaying paged data */
2333a136e5SAndreas Gohr    protected $start = 0;
2433a136e5SAndreas Gohr
2533a136e5SAndreas Gohr    /** @var helper_plugin_statistics */
2633a136e5SAndreas Gohr    protected $hlp;
2733a136e5SAndreas Gohr
28a901d721SAndreas Gohr    /**
29a901d721SAndreas Gohr     * Available statistic pages
30a901d721SAndreas Gohr     */
31483101d3SAndreas Gohr    protected $pages = [
32483101d3SAndreas Gohr        'dashboard' => 1,
33483101d3SAndreas Gohr        'content' => ['page', 'edits', 'images', 'downloads', 'history'],
34483101d3SAndreas Gohr        'users' => ['topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'],
35483101d3SAndreas Gohr        'links' => ['referer', 'newreferer', 'outlinks'],
36483101d3SAndreas Gohr        'search' => ['searchengines', 'searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords'],
37483101d3SAndreas Gohr        'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport']
38483101d3SAndreas Gohr    ];
391878f16fSAndreas Gohr
4081ff4c3aSAndreas Gohr    /** @var array keeps a list of all real content pages, generated from above array */
41a8acb244SAndreas Gohr    protected $allowedpages = [];
4281ff4c3aSAndreas Gohr
431878f16fSAndreas Gohr    /**
446b6f8822SAndreas Gohr     * Initialize the helper
456b6f8822SAndreas Gohr     */
46a8acb244SAndreas Gohr    public function __construct()
47a8acb244SAndreas Gohr    {
486b6f8822SAndreas Gohr        $this->hlp = plugin_load('helper', 'statistics');
4981ff4c3aSAndreas Gohr
5081ff4c3aSAndreas Gohr        // build a list of pages
5181ff4c3aSAndreas Gohr        foreach ($this->pages as $key => $val) {
5281ff4c3aSAndreas Gohr            if (is_array($val)) {
5381ff4c3aSAndreas Gohr                $this->allowedpages = array_merge($this->allowedpages, $val);
5481ff4c3aSAndreas Gohr            } else {
5581ff4c3aSAndreas Gohr                $this->allowedpages[] = $key;
5681ff4c3aSAndreas Gohr            }
5781ff4c3aSAndreas Gohr        }
586b6f8822SAndreas Gohr    }
596b6f8822SAndreas Gohr
606b6f8822SAndreas Gohr    /**
611878f16fSAndreas Gohr     * Access for managers allowed
621878f16fSAndreas Gohr     */
63a8acb244SAndreas Gohr    public function forAdminOnly()
64a8acb244SAndreas Gohr    {
651878f16fSAndreas Gohr        return false;
661878f16fSAndreas Gohr    }
671878f16fSAndreas Gohr
681878f16fSAndreas Gohr    /**
691878f16fSAndreas Gohr     * return sort order for position in admin menu
701878f16fSAndreas Gohr     */
71a8acb244SAndreas Gohr    public function getMenuSort()
72a8acb244SAndreas Gohr    {
736b6f8822SAndreas Gohr        return 350;
741878f16fSAndreas Gohr    }
751878f16fSAndreas Gohr
761878f16fSAndreas Gohr    /**
771878f16fSAndreas Gohr     * handle user request
781878f16fSAndreas Gohr     */
79a8acb244SAndreas Gohr    public function handle()
80a8acb244SAndreas Gohr    {
81483101d3SAndreas Gohr        global $INPUT;
82483101d3SAndreas Gohr        $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt'));
8381ff4c3aSAndreas Gohr        if (!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard';
84a901d721SAndreas Gohr
85483101d3SAndreas Gohr        $this->start = $INPUT->int('s');
86483101d3SAndreas Gohr        $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d')));
87e8699bceSAndreas Gohr    }
8895eb68e6SAndreas Gohr
89e8699bceSAndreas Gohr    /**
90e8699bceSAndreas Gohr     * set limit clause
91e8699bceSAndreas Gohr     */
92a8acb244SAndreas Gohr    public function setTimeframe($from, $to)
93a8acb244SAndreas Gohr    {
94047fcb0fSAndreas Gohr        // swap if wrong order
95a8acb244SAndreas Gohr        if ($from > $to) [$from, $to] = [$to, $from];
96047fcb0fSAndreas Gohr
97211caa5dSAndreas Gohr        $this->hlp->getQuery()->setTimeFrame($from, $to);
98e8699bceSAndreas Gohr        $this->from = $from;
99e8699bceSAndreas Gohr        $this->to = $to;
1001878f16fSAndreas Gohr    }
1011878f16fSAndreas Gohr
1021878f16fSAndreas Gohr    /**
10379b4a855SAndreas Gohr     * Output the Statistics
1041878f16fSAndreas Gohr     */
105a8acb244SAndreas Gohr    public function html()
106a8acb244SAndreas Gohr    {
107b0cf2118SAnna Dabrowska        echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chart.js"></script>';
108b0cf2118SAnna Dabrowska        echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chartjs-plugin-datalabels.js"></script>';
109b0cf2118SAnna Dabrowska
1101d2d78ccSAndreas Gohr        echo '<div id="plugin__statistics">';
1110c3b1e44SAndreas Gohr        echo '<h1>' . $this->getLang('menu') . '</h1>';
112264f1744SAndreas Gohr        $this->html_timeselect();
113441bfb8eSAndreas Gohr        tpl_flush();
114264f1744SAndreas Gohr
11579b4a855SAndreas Gohr        $method = 'html_' . $this->opt;
11679b4a855SAndreas Gohr        if (method_exists($this, $method)) {
117a901d721SAndreas Gohr            echo '<div class="plg_stats_' . $this->opt . '">';
118a901d721SAndreas Gohr            echo '<h2>' . $this->getLang($this->opt) . '</h2>';
11979b4a855SAndreas Gohr            $this->$method();
120a901d721SAndreas Gohr            echo '</div>';
12114d99ec0SAndreas Gohr        }
1221d2d78ccSAndreas Gohr        echo '</div>';
12314d99ec0SAndreas Gohr    }
12414d99ec0SAndreas Gohr
1256b6f8822SAndreas Gohr    /**
1266b6f8822SAndreas Gohr     * Return the TOC
1276b6f8822SAndreas Gohr     *
1286b6f8822SAndreas Gohr     * @return array
1296b6f8822SAndreas Gohr     */
130a8acb244SAndreas Gohr    public function getTOC()
131a8acb244SAndreas Gohr    {
132a8acb244SAndreas Gohr        $toc = [];
13381ff4c3aSAndreas Gohr        foreach ($this->pages as $key => $info) {
13481ff4c3aSAndreas Gohr            if (is_array($info)) {
13581ff4c3aSAndreas Gohr                $toc[] = html_mktocitem(
13681ff4c3aSAndreas Gohr                    '',
13781ff4c3aSAndreas Gohr                    $this->getLang($key),
13881ff4c3aSAndreas Gohr                    1,
13981ff4c3aSAndreas Gohr                    ''
14047ffcf7dSAndreas Gohr                );
14181ff4c3aSAndreas Gohr
14281ff4c3aSAndreas Gohr                foreach ($info as $page) {
14381ff4c3aSAndreas Gohr                    $toc[] = html_mktocitem(
144211caa5dSAndreas Gohr                        '?do=admin&amp;page=statistics&amp;opt=' . $page .
145211caa5dSAndreas Gohr                        '&amp;f=' . $this->from .
146211caa5dSAndreas Gohr                        '&amp;t=' . $this->to,
14781ff4c3aSAndreas Gohr                        $this->getLang($page),
14881ff4c3aSAndreas Gohr                        2,
14981ff4c3aSAndreas Gohr                        ''
15081ff4c3aSAndreas Gohr                    );
15181ff4c3aSAndreas Gohr                }
15281ff4c3aSAndreas Gohr            } else {
15381ff4c3aSAndreas Gohr                $toc[] = html_mktocitem(
154211caa5dSAndreas Gohr                    '?do=admin&amp;page=statistics&amp;opt=' . $key .
155211caa5dSAndreas Gohr                    '&amp;f=' . $this->from .
156211caa5dSAndreas Gohr                    '&amp;t=' . $this->to,
15781ff4c3aSAndreas Gohr                    $this->getLang($key),
15881ff4c3aSAndreas Gohr                    1,
15981ff4c3aSAndreas Gohr                    ''
16081ff4c3aSAndreas Gohr                );
16181ff4c3aSAndreas Gohr            }
16247ffcf7dSAndreas Gohr        }
16347ffcf7dSAndreas Gohr        return $toc;
1649da6395dSAndreas Gohr    }
1659da6395dSAndreas Gohr
166a8acb244SAndreas Gohr    public function html_graph($name, $width, $height)
167a8acb244SAndreas Gohr    {
168211caa5dSAndreas Gohr        $this->hlp->getGraph($this->from, $this->to, $width, $height)->$name();
169dc7b1e5eSAndreas Gohr    }
170dc7b1e5eSAndreas Gohr
1716b6f8822SAndreas Gohr    /**
1726b6f8822SAndreas Gohr     * Outputs pagination links
1736b6f8822SAndreas Gohr     *
17433a136e5SAndreas Gohr     * @param int $limit
17533a136e5SAndreas Gohr     * @param int $next
1766b6f8822SAndreas Gohr     */
177a8acb244SAndreas Gohr    public function html_pager($limit, $next)
178a8acb244SAndreas Gohr    {
179211caa5dSAndreas Gohr        $params = [
180211caa5dSAndreas Gohr            'do' => 'admin',
181211caa5dSAndreas Gohr            'page' => 'statistics',
182211caa5dSAndreas Gohr            'opt' => $this->opt,
183211caa5dSAndreas Gohr            'f' => $this->from,
184211caa5dSAndreas Gohr            't' => $this->to,
185211caa5dSAndreas Gohr        ];
1862507f8e0SAndreas Gohr
187211caa5dSAndreas Gohr        echo '<div class="plg_stats_pager">';
1882507f8e0SAndreas Gohr        if ($this->start > 0) {
1892507f8e0SAndreas Gohr            $go = max($this->start - $limit, 0);
190211caa5dSAndreas Gohr            $params['s'] = $go;
191211caa5dSAndreas Gohr            echo '<a href="?' . buildURLparams($params) . '" class="prev button">' . $this->getLang('prev') . '</a>';
1922507f8e0SAndreas Gohr        }
1932507f8e0SAndreas Gohr
1942507f8e0SAndreas Gohr        if ($next) {
1952507f8e0SAndreas Gohr            $go = $this->start + $limit;
196211caa5dSAndreas Gohr            $params['s'] = $go;
197211caa5dSAndreas Gohr            echo '<a href="?' . buildURLparams($params) . '" class="next button">' . $this->getLang('next') . '</a>';
1982507f8e0SAndreas Gohr        }
1992507f8e0SAndreas Gohr        echo '</div>';
2002507f8e0SAndreas Gohr    }
2012507f8e0SAndreas Gohr
202264f1744SAndreas Gohr    /**
203264f1744SAndreas Gohr     * Print the time selection menu
204264f1744SAndreas Gohr     */
205a8acb244SAndreas Gohr    public function html_timeselect()
206a8acb244SAndreas Gohr    {
207483101d3SAndreas Gohr        $quick = [
208483101d3SAndreas Gohr            'today' => date('Y-m-d'),
209483101d3SAndreas Gohr            'last1' => date('Y-m-d', time() - (60 * 60 * 24)),
210483101d3SAndreas Gohr            'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)),
211483101d3SAndreas Gohr            'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)),
212483101d3SAndreas Gohr        ];
213483101d3SAndreas Gohr
21414d99ec0SAndreas Gohr
215264f1744SAndreas Gohr        echo '<div class="plg_stats_timeselect">';
2166985b606SAndreas Gohr        echo '<span>' . $this->getLang('time_select') . '</span> ';
217264f1744SAndreas Gohr
218047fcb0fSAndreas Gohr        echo '<form action="' . DOKU_SCRIPT . '" method="get">';
219264f1744SAndreas Gohr        echo '<input type="hidden" name="do" value="admin" />';
220264f1744SAndreas Gohr        echo '<input type="hidden" name="page" value="statistics" />';
221264f1744SAndreas Gohr        echo '<input type="hidden" name="opt" value="' . $this->opt . '" />';
222483101d3SAndreas Gohr        echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />';
223483101d3SAndreas Gohr        echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />';
224264f1744SAndreas Gohr        echo '<input type="submit" value="go" class="button" />';
22514d99ec0SAndreas Gohr        echo '</form>';
226264f1744SAndreas Gohr
2276985b606SAndreas Gohr        echo '<ul>';
228483101d3SAndreas Gohr        foreach ($quick as $name => $time) {
229211caa5dSAndreas Gohr            $url = buildURLparams([
230211caa5dSAndreas Gohr                'do' => 'admin',
231211caa5dSAndreas Gohr                'page' => 'statistics',
232211caa5dSAndreas Gohr                'opt' => $this->opt,
233211caa5dSAndreas Gohr                'f' => $time,
234211caa5dSAndreas Gohr                't' => $quick['today'],
235211caa5dSAndreas Gohr            ]);
236211caa5dSAndreas Gohr
2376985b606SAndreas Gohr            echo '<li>';
238211caa5dSAndreas Gohr            echo '<a href="?' . $url . '">';
239483101d3SAndreas Gohr            echo $this->getLang('time_' . $name);
2406985b606SAndreas Gohr            echo '</a>';
2416985b606SAndreas Gohr            echo '</li>';
2426985b606SAndreas Gohr        }
2436985b606SAndreas Gohr        echo '</ul>';
2446985b606SAndreas Gohr
245264f1744SAndreas Gohr        echo '</div>';
24614d99ec0SAndreas Gohr    }
24714d99ec0SAndreas Gohr
248f5f32cbfSAndreas Gohr    /**
249f5f32cbfSAndreas Gohr     * Print an introductionary screen
250f5f32cbfSAndreas Gohr     */
251a8acb244SAndreas Gohr    public function html_dashboard()
252a8acb244SAndreas Gohr    {
253878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_dashboard') . '</p>';
2542812a751SAndreas Gohr
2552812a751SAndreas Gohr        // general info
2562812a751SAndreas Gohr        echo '<div class="plg_stats_top">';
257211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->aggregate();
2581d2d78ccSAndreas Gohr
2591fd51258SAndreas Gohr        echo '<ul>';
260a8acb244SAndreas Gohr        foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) {
261eabe0d07SAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
262eabe0d07SAndreas Gohr        }
2632812a751SAndreas Gohr        echo '</ul>';
2641d2d78ccSAndreas Gohr
2651fd51258SAndreas Gohr        echo '<ul>';
266a8acb244SAndreas Gohr        foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations'] as $name) {
2671d2d78ccSAndreas Gohr            echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>';
2681d2d78ccSAndreas Gohr        }
2691d2d78ccSAndreas Gohr        echo '</ul>';
2701d2d78ccSAndreas Gohr
271259897e1SAndreas Gohr        $this->html_graph('dashboardviews', 700, 280);
272259897e1SAndreas Gohr        $this->html_graph('dashboardwiki', 700, 280);
2732812a751SAndreas Gohr        echo '</div>';
2742812a751SAndreas Gohr
275211caa5dSAndreas Gohr        $quickgraphs = [
276211caa5dSAndreas Gohr            ['lbl' => 'dash_mostpopular', 'query' => 'pages', 'opt' => 'page'],
277211caa5dSAndreas Gohr            ['lbl' => 'dash_newincoming', 'query' => 'newreferer', 'opt' => 'newreferer'],
278211caa5dSAndreas Gohr            ['lbl' => 'dash_topsearch', 'query' => 'searchphrases', 'opt' => 'internalsearchphrases'],
279211caa5dSAndreas Gohr        ];
28087d5e44bSAndreas Gohr
281211caa5dSAndreas Gohr        foreach ($quickgraphs as $graph) {
282211caa5dSAndreas Gohr            $params = [
283211caa5dSAndreas Gohr                'do' => 'admin',
284211caa5dSAndreas Gohr                'page' => 'statistics',
285211caa5dSAndreas Gohr                'f' => $this->from,
286211caa5dSAndreas Gohr                't' => $this->to,
287211caa5dSAndreas Gohr                'opt' => $graph['opt'],
288211caa5dSAndreas Gohr            ];
28954f6c432SAndreas Gohr
290264f1744SAndreas Gohr            echo '<div>';
291211caa5dSAndreas Gohr            echo '<h2>' . $this->getLang($graph['lbl']) . '</h2>';
292211caa5dSAndreas Gohr            $result = call_user_func([$this->hlp->getQuery(), $graph['query']]);
29329dea504SAndreas Gohr            $this->html_resulttable($result);
2941fd51258SAndreas Gohr            echo '<p><a href="?' . buildURLparams($params) . '" class="more">' . $this->getLang('more') . '…</a></p>';
295264f1744SAndreas Gohr            echo '</div>';
29614d99ec0SAndreas Gohr        }
297211caa5dSAndreas Gohr    }
29814d99ec0SAndreas Gohr
299a8acb244SAndreas Gohr    public function html_history()
300a8acb244SAndreas Gohr    {
301cae4a1c5SAndreas Gohr        echo '<p>' . $this->getLang('intro_history') . '</p>';
302338987f5SAndreas Gohr        $this->html_graph('history_page_count', 600, 200);
303338987f5SAndreas Gohr        $this->html_graph('history_page_size', 600, 200);
304338987f5SAndreas Gohr        $this->html_graph('history_media_count', 600, 200);
305338987f5SAndreas Gohr        $this->html_graph('history_media_size', 600, 200);
306cae4a1c5SAndreas Gohr    }
307cae4a1c5SAndreas Gohr
308a8acb244SAndreas Gohr    public function html_countries()
309a8acb244SAndreas Gohr    {
310878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_countries') . '</p>';
3111d379254SAnna Dabrowska        $this->html_graph('countries', 300, 300);
312211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->countries();
3132507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3149da6395dSAndreas Gohr    }
3159da6395dSAndreas Gohr
316a8acb244SAndreas Gohr    public function html_page()
317a8acb244SAndreas Gohr    {
318878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_page') . '</p>';
319211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->pages();
3202507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
3219da6395dSAndreas Gohr    }
3229da6395dSAndreas Gohr
323a8acb244SAndreas Gohr    public function html_edits()
324a8acb244SAndreas Gohr    {
3251664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_edits') . '</p>';
326211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->edits();
3271664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3281664ba1dSAndreas Gohr    }
3291664ba1dSAndreas Gohr
330a8acb244SAndreas Gohr    public function html_images()
331a8acb244SAndreas Gohr    {
3321664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_images') . '</p>';
333616c1e8bSAndreas Gohr
334211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->imagessum();
335616c1e8bSAndreas Gohr        echo '<p>';
336616c1e8bSAndreas Gohr        echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize']));
337616c1e8bSAndreas Gohr        echo '</p>';
338616c1e8bSAndreas Gohr
339211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->images();
3401664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3411664ba1dSAndreas Gohr    }
3421664ba1dSAndreas Gohr
343a8acb244SAndreas Gohr    public function html_downloads()
344a8acb244SAndreas Gohr    {
3451664ba1dSAndreas Gohr        echo '<p>' . $this->getLang('intro_downloads') . '</p>';
346616c1e8bSAndreas Gohr
347211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->downloadssum();
348616c1e8bSAndreas Gohr        echo '<p>';
349616c1e8bSAndreas Gohr        echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize']));
350616c1e8bSAndreas Gohr        echo '</p>';
351616c1e8bSAndreas Gohr
352211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->downloads();
3531664ba1dSAndreas Gohr        $this->html_resulttable($result, '', 150);
3541664ba1dSAndreas Gohr    }
3551664ba1dSAndreas Gohr
356a8acb244SAndreas Gohr    public function html_browsers()
357a8acb244SAndreas Gohr    {
358878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_browsers') . '</p>';
3591d379254SAnna Dabrowska        $this->html_graph('browsers', 300, 300);
360211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->browsers(false);
3612507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
36275fa767dSAndreas Gohr    }
36375fa767dSAndreas Gohr
364a8acb244SAndreas Gohr    public function html_topuser()
365a8acb244SAndreas Gohr    {
36681ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topuser') . '</p>';
3671d379254SAnna Dabrowska        $this->html_graph('topuser', 300, 300);
368211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->topuser();
36981ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
37081ff4c3aSAndreas Gohr    }
37181ff4c3aSAndreas Gohr
372a8acb244SAndreas Gohr    public function html_topeditor()
373a8acb244SAndreas Gohr    {
37481ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topeditor') . '</p>';
3751d379254SAnna Dabrowska        $this->html_graph('topeditor', 300, 300);
376211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->topeditor();
37781ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
37881ff4c3aSAndreas Gohr    }
37981ff4c3aSAndreas Gohr
380a8acb244SAndreas Gohr    public function html_topgroup()
381a8acb244SAndreas Gohr    {
38281ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topgroup') . '</p>';
3831d379254SAnna Dabrowska        $this->html_graph('topgroup', 300, 300);
384211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->topgroup();
38581ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
38681ff4c3aSAndreas Gohr    }
38781ff4c3aSAndreas Gohr
388a8acb244SAndreas Gohr    public function html_topgroupedit()
389a8acb244SAndreas Gohr    {
39081ff4c3aSAndreas Gohr        echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>';
3911d379254SAnna Dabrowska        $this->html_graph('topgroupedit', 300, 300);
392211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->topgroupedit();
39381ff4c3aSAndreas Gohr        $this->html_resulttable($result, '', 150);
39481ff4c3aSAndreas Gohr    }
39581ff4c3aSAndreas Gohr
396a8acb244SAndreas Gohr    public function html_os()
397a8acb244SAndreas Gohr    {
398878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_os') . '</p>';
3991d379254SAnna Dabrowska        $this->html_graph('os', 300, 300);
400211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->os();
4012507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
402bd4217d3SAndreas Gohr    }
403bd4217d3SAndreas Gohr
404a8acb244SAndreas Gohr    public function html_referer()
405a8acb244SAndreas Gohr    {
406211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->aggregate();
4072812a751SAndreas Gohr
4082812a751SAndreas Gohr        $all = $result['search'] + $result['external'] + $result['direct'];
4092812a751SAndreas Gohr
41094023548SAndreas Gohr        if ($all) {
4110863c19cSAndreas Gohr            printf(
4120863c19cSAndreas Gohr                '<p>' . $this->getLang('intro_referer') . '</p>',
413a8acb244SAndreas Gohr                $all,
414a8acb244SAndreas Gohr                $result['direct'],
415a8acb244SAndreas Gohr                (100 * $result['direct'] / $all),
416a8acb244SAndreas Gohr                $result['search'],
417a8acb244SAndreas Gohr                (100 * $result['search'] / $all),
418a8acb244SAndreas Gohr                $result['external'],
4190863c19cSAndreas Gohr                (100 * $result['external'] / $all)
4200863c19cSAndreas Gohr            );
42194023548SAndreas Gohr        }
4222812a751SAndreas Gohr
423211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->referer();
4242507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
4259da6395dSAndreas Gohr    }
4269da6395dSAndreas Gohr
427a8acb244SAndreas Gohr    public function html_newreferer()
428a8acb244SAndreas Gohr    {
429878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_newreferer') . '</p>';
430e7a2f1e0SAndreas Gohr
431211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->newreferer();
4322507f8e0SAndreas Gohr        $this->html_resulttable($result, '', 150);
433e7a2f1e0SAndreas Gohr    }
434e7a2f1e0SAndreas Gohr
435a8acb244SAndreas Gohr    public function html_outlinks()
436a8acb244SAndreas Gohr    {
437878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_outlinks') . '</p>';
438211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->outlinks();
439e25286daSAndreas Gohr        $this->html_resulttable($result, '', 150);
440e25286daSAndreas Gohr    }
441e25286daSAndreas Gohr
442a8acb244SAndreas Gohr    public function html_searchphrases()
443a8acb244SAndreas Gohr    {
444878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchphrases') . '</p>';
445211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->searchphrases(true);
44612dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
44712dcdeccSAndreas Gohr    }
44812dcdeccSAndreas Gohr
449a8acb244SAndreas Gohr    public function html_searchwords()
450a8acb244SAndreas Gohr    {
451878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchwords') . '</p>';
452211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->searchwords(true);
4535bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
4545bccfe87SAndreas Gohr    }
4555bccfe87SAndreas Gohr
456a8acb244SAndreas Gohr    public function html_internalsearchphrases()
457a8acb244SAndreas Gohr    {
458878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>';
459211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->searchphrases(false);
4605bccfe87SAndreas Gohr        $this->html_resulttable($result, '', 150);
4615bccfe87SAndreas Gohr    }
4625bccfe87SAndreas Gohr
463a8acb244SAndreas Gohr    public function html_internalsearchwords()
464a8acb244SAndreas Gohr    {
465878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>';
466211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->searchwords(false);
46712dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
46812dcdeccSAndreas Gohr    }
46912dcdeccSAndreas Gohr
470a8acb244SAndreas Gohr    public function html_searchengines()
471a8acb244SAndreas Gohr    {
472878be5c9SAndreas Gohr        echo '<p>' . $this->getLang('intro_searchengines') . '</p>';
47325b71d4bSAndreas Gohr        $this->html_graph('searchengines', 400, 200);
474211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->searchengines();
47512dcdeccSAndreas Gohr        $this->html_resulttable($result, '', 150);
47612dcdeccSAndreas Gohr    }
47712dcdeccSAndreas Gohr
478a8acb244SAndreas Gohr    public function html_resolution()
479a8acb244SAndreas Gohr    {
48025446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_resolution') . '</p>';
48125446aa2SAndreas Gohr        $this->html_graph('resolution', 650, 490);
482211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->resolution();
483307baf3fSAndreas Gohr        $this->html_resulttable($result, '', 150);
48425446aa2SAndreas Gohr    }
485307baf3fSAndreas Gohr
486a8acb244SAndreas Gohr    public function html_viewport()
487a8acb244SAndreas Gohr    {
48825446aa2SAndreas Gohr        echo '<p>' . $this->getLang('intro_viewport') . '</p>';
48925446aa2SAndreas Gohr        $this->html_graph('viewport', 650, 490);
490211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->viewport();
49125446aa2SAndreas Gohr        $this->html_resulttable($result, '', 150);
492c73e16f1SAndreas Gohr    }
4939da6395dSAndreas Gohr
494a8acb244SAndreas Gohr    public function html_seenusers()
495a8acb244SAndreas Gohr    {
49633a136e5SAndreas Gohr        echo '<p>' . $this->getLang('intro_seenusers') . '</p>';
497211caa5dSAndreas Gohr        $result = $this->hlp->getQuery()->seenusers();
49833a136e5SAndreas Gohr        $this->html_resulttable($result, '', 150);
49933a136e5SAndreas Gohr    }
50033a136e5SAndreas Gohr
50114d99ec0SAndreas Gohr    /**
50214d99ec0SAndreas Gohr     * Display a result in a HTML table
50314d99ec0SAndreas Gohr     */
504a8acb244SAndreas Gohr    public function html_resulttable($result, $header = '', $pager = 0)
505a8acb244SAndreas Gohr    {
50656f647ddSAndreas Gohr        echo '<table class="inline">';
5072812a751SAndreas Gohr        if (is_array($header)) {
50814d99ec0SAndreas Gohr            echo '<tr>';
50914d99ec0SAndreas Gohr            foreach ($header as $h) {
51014d99ec0SAndreas Gohr                echo '<th>' . hsc($h) . '</th>';
51114d99ec0SAndreas Gohr            }
51214d99ec0SAndreas Gohr            echo '</tr>';
5132812a751SAndreas Gohr        }
51414d99ec0SAndreas Gohr
5152507f8e0SAndreas Gohr        $count = 0;
5162ee939eeSAndreas Gohr        if (is_array($result)) foreach ($result as $row) {
51714d99ec0SAndreas Gohr            echo '<tr>';
51814d99ec0SAndreas Gohr            foreach ($row as $k => $v) {
519f3818071SAndreas Gohr                if ($k == 'res_x') continue;
520f3818071SAndreas Gohr                if ($k == 'res_y') continue;
521f3818071SAndreas Gohr
5222812a751SAndreas Gohr                echo '<td class="plg_stats_X' . $k . '">';
52314d99ec0SAndreas Gohr                if ($k == 'page') {
52414d99ec0SAndreas Gohr                    echo '<a href="' . wl($v) . '" class="wikilink1">';
52514d99ec0SAndreas Gohr                    echo hsc($v);
52614d99ec0SAndreas Gohr                    echo '</a>';
5271664ba1dSAndreas Gohr                } elseif ($k == 'media') {
5281664ba1dSAndreas Gohr                    echo '<a href="' . ml($v) . '" class="wikilink1">';
5291664ba1dSAndreas Gohr                    echo hsc($v);
5301664ba1dSAndreas Gohr                    echo '</a>';
5311664ba1dSAndreas Gohr                } elseif ($k == 'filesize') {
5321664ba1dSAndreas Gohr                    echo filesize_h($v);
53314d99ec0SAndreas Gohr                } elseif ($k == 'url') {
53454f6c432SAndreas Gohr                    $url = hsc($v);
53583b63546SAndreas Gohr                    $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url);
5362812a751SAndreas Gohr                    if (strlen($url) > 45) {
5372812a751SAndreas Gohr                        $url = substr($url, 0, 30) . ' &hellip; ' . substr($url, -15);
53854f6c432SAndreas Gohr                    }
53914d99ec0SAndreas Gohr                    echo '<a href="' . $v . '" class="urlextern">';
54054f6c432SAndreas Gohr                    echo $url;
54114d99ec0SAndreas Gohr                    echo '</a>';
5425bccfe87SAndreas Gohr                } elseif ($k == 'ilookup') {
543a8acb244SAndreas Gohr                    echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>';
54429dea504SAndreas Gohr                } elseif ($k == 'lookup') {
54529dea504SAndreas Gohr                    echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">';
546211caa5dSAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" />';
54729dea504SAndreas Gohr                    echo '</a> ';
54829dea504SAndreas Gohr
54929dea504SAndreas Gohr                    echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">';
550211caa5dSAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" />';
55129dea504SAndreas Gohr                    echo '</a> ';
55229dea504SAndreas Gohr
55313a86c14SAndreas Gohr                    echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">';
554211caa5dSAndreas Gohr                    echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" />';
55529dea504SAndreas Gohr                    echo '</a> ';
55612dcdeccSAndreas Gohr                } elseif ($k == 'engine') {
557*c4c84f98SAndreas Gohr                    $name = SearchEngines::getName($v);
558*c4c84f98SAndreas Gohr                    $url = SearchEngines::getURL($v);
559*c4c84f98SAndreas Gohr                    if ($url) {
560*c4c84f98SAndreas Gohr                        echo '<a href="' . $url . '">' . hsc($name) . '</a>';
56113a86c14SAndreas Gohr                    } else {
562*c4c84f98SAndreas Gohr                        echo hsc($name);
56313a86c14SAndreas Gohr                    }
56414d99ec0SAndreas Gohr                } elseif ($k == 'html') {
56514d99ec0SAndreas Gohr                    echo $v;
56614d99ec0SAndreas Gohr                } else {
56714d99ec0SAndreas Gohr                    echo hsc($v);
56814d99ec0SAndreas Gohr                }
56914d99ec0SAndreas Gohr                echo '</td>';
57014d99ec0SAndreas Gohr            }
57114d99ec0SAndreas Gohr            echo '</tr>';
5722507f8e0SAndreas Gohr
5732507f8e0SAndreas Gohr            if ($pager && ($count == $pager)) break;
5742507f8e0SAndreas Gohr            $count++;
57514d99ec0SAndreas Gohr        }
57614d99ec0SAndreas Gohr        echo '</table>';
5772507f8e0SAndreas Gohr
5782507f8e0SAndreas Gohr        if ($pager) $this->html_pager($pager, count($result) > $pager);
5791878f16fSAndreas Gohr    }
58013a86c14SAndreas Gohr}
581