11878f16fSAndreas Gohr<?php 2a8acb244SAndreas Gohr 3211caa5dSAndreas Gohr// phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps 4a8acb244SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 5a8acb244SAndreas Gohr 61878f16fSAndreas Gohr/** 71878f16fSAndreas Gohr * statistics plugin 81878f16fSAndreas Gohr * 91878f16fSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 106b6f8822SAndreas Gohr * @author Andreas Gohr <gohr@splitbrain.org> 111878f16fSAndreas Gohr */ 12a8acb244SAndreas Gohrclass admin_plugin_statistics extends AdminPlugin 13a8acb244SAndreas Gohr{ 1433a136e5SAndreas Gohr /** @var string the currently selected page */ 15a901d721SAndreas Gohr protected $opt = ''; 1633a136e5SAndreas Gohr 1733a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 18a901d721SAndreas Gohr protected $from = ''; 1933a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 20a901d721SAndreas Gohr protected $to = ''; 2133a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 2233a136e5SAndreas Gohr protected $start = 0; 2333a136e5SAndreas Gohr 2433a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 2533a136e5SAndreas Gohr protected $hlp; 2633a136e5SAndreas Gohr 27a901d721SAndreas Gohr /** 28a901d721SAndreas Gohr * Available statistic pages 29a901d721SAndreas Gohr */ 30483101d3SAndreas Gohr protected $pages = [ 31483101d3SAndreas Gohr 'dashboard' => 1, 32483101d3SAndreas Gohr 'content' => ['page', 'edits', 'images', 'downloads', 'history'], 33483101d3SAndreas Gohr 'users' => ['topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'], 34483101d3SAndreas Gohr 'links' => ['referer', 'newreferer', 'outlinks'], 35483101d3SAndreas Gohr 'search' => ['searchengines', 'searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords'], 36483101d3SAndreas Gohr 'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport'] 37483101d3SAndreas Gohr ]; 381878f16fSAndreas Gohr 3981ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 40a8acb244SAndreas Gohr protected $allowedpages = []; 4181ff4c3aSAndreas Gohr 421878f16fSAndreas Gohr /** 436b6f8822SAndreas Gohr * Initialize the helper 446b6f8822SAndreas Gohr */ 45a8acb244SAndreas Gohr public function __construct() 46a8acb244SAndreas Gohr { 476b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 4881ff4c3aSAndreas Gohr 4981ff4c3aSAndreas Gohr // build a list of pages 5081ff4c3aSAndreas Gohr foreach ($this->pages as $key => $val) { 5181ff4c3aSAndreas Gohr if (is_array($val)) { 5281ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 5381ff4c3aSAndreas Gohr } else { 5481ff4c3aSAndreas Gohr $this->allowedpages[] = $key; 5581ff4c3aSAndreas Gohr } 5681ff4c3aSAndreas Gohr } 576b6f8822SAndreas Gohr } 586b6f8822SAndreas Gohr 596b6f8822SAndreas Gohr /** 601878f16fSAndreas Gohr * Access for managers allowed 611878f16fSAndreas Gohr */ 62a8acb244SAndreas Gohr public function forAdminOnly() 63a8acb244SAndreas Gohr { 641878f16fSAndreas Gohr return false; 651878f16fSAndreas Gohr } 661878f16fSAndreas Gohr 671878f16fSAndreas Gohr /** 681878f16fSAndreas Gohr * return sort order for position in admin menu 691878f16fSAndreas Gohr */ 70a8acb244SAndreas Gohr public function getMenuSort() 71a8acb244SAndreas Gohr { 726b6f8822SAndreas Gohr return 350; 731878f16fSAndreas Gohr } 741878f16fSAndreas Gohr 751878f16fSAndreas Gohr /** 761878f16fSAndreas Gohr * handle user request 771878f16fSAndreas Gohr */ 78a8acb244SAndreas Gohr public function handle() 79a8acb244SAndreas Gohr { 80483101d3SAndreas Gohr global $INPUT; 81483101d3SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); 8281ff4c3aSAndreas Gohr if (!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard'; 83a901d721SAndreas Gohr 84483101d3SAndreas Gohr $this->start = $INPUT->int('s'); 85483101d3SAndreas Gohr $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d'))); 86e8699bceSAndreas Gohr } 8795eb68e6SAndreas Gohr 88e8699bceSAndreas Gohr /** 89e8699bceSAndreas Gohr * set limit clause 90e8699bceSAndreas Gohr */ 91a8acb244SAndreas Gohr public function setTimeframe($from, $to) 92a8acb244SAndreas Gohr { 93047fcb0fSAndreas Gohr // swap if wrong order 94a8acb244SAndreas Gohr if ($from > $to) [$from, $to] = [$to, $from]; 95047fcb0fSAndreas Gohr 96211caa5dSAndreas Gohr $this->hlp->getQuery()->setTimeFrame($from, $to); 97e8699bceSAndreas Gohr $this->from = $from; 98e8699bceSAndreas Gohr $this->to = $to; 991878f16fSAndreas Gohr } 1001878f16fSAndreas Gohr 1011878f16fSAndreas Gohr /** 10279b4a855SAndreas Gohr * Output the Statistics 1031878f16fSAndreas Gohr */ 104a8acb244SAndreas Gohr public function html() 105a8acb244SAndreas Gohr { 106b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chart.js"></script>'; 107b0cf2118SAnna Dabrowska echo '<script src="' . DOKU_BASE . 'lib/plugins/statistics/lib/chartjs-plugin-datalabels.js"></script>'; 108b0cf2118SAnna Dabrowska 1091d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1100c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 111264f1744SAndreas Gohr $this->html_timeselect(); 112441bfb8eSAndreas Gohr tpl_flush(); 113264f1744SAndreas Gohr 11479b4a855SAndreas Gohr $method = 'html_' . $this->opt; 11579b4a855SAndreas Gohr if (method_exists($this, $method)) { 116a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 117a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 11879b4a855SAndreas Gohr $this->$method(); 119a901d721SAndreas Gohr echo '</div>'; 12014d99ec0SAndreas Gohr } 1211d2d78ccSAndreas Gohr echo '</div>'; 12214d99ec0SAndreas Gohr } 12314d99ec0SAndreas Gohr 1246b6f8822SAndreas Gohr /** 1256b6f8822SAndreas Gohr * Return the TOC 1266b6f8822SAndreas Gohr * 1276b6f8822SAndreas Gohr * @return array 1286b6f8822SAndreas Gohr */ 129a8acb244SAndreas Gohr public function getTOC() 130a8acb244SAndreas Gohr { 131a8acb244SAndreas Gohr $toc = []; 13281ff4c3aSAndreas Gohr foreach ($this->pages as $key => $info) { 13381ff4c3aSAndreas Gohr if (is_array($info)) { 13481ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 13581ff4c3aSAndreas Gohr '', 13681ff4c3aSAndreas Gohr $this->getLang($key), 13781ff4c3aSAndreas Gohr 1, 13881ff4c3aSAndreas Gohr '' 13947ffcf7dSAndreas Gohr ); 14081ff4c3aSAndreas Gohr 14181ff4c3aSAndreas Gohr foreach ($info as $page) { 14281ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 143211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . 144211caa5dSAndreas Gohr '&f=' . $this->from . 145211caa5dSAndreas Gohr '&t=' . $this->to, 14681ff4c3aSAndreas Gohr $this->getLang($page), 14781ff4c3aSAndreas Gohr 2, 14881ff4c3aSAndreas Gohr '' 14981ff4c3aSAndreas Gohr ); 15081ff4c3aSAndreas Gohr } 15181ff4c3aSAndreas Gohr } else { 15281ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 153211caa5dSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . 154211caa5dSAndreas Gohr '&f=' . $this->from . 155211caa5dSAndreas Gohr '&t=' . $this->to, 15681ff4c3aSAndreas Gohr $this->getLang($key), 15781ff4c3aSAndreas Gohr 1, 15881ff4c3aSAndreas Gohr '' 15981ff4c3aSAndreas Gohr ); 16081ff4c3aSAndreas Gohr } 16147ffcf7dSAndreas Gohr } 16247ffcf7dSAndreas Gohr return $toc; 1639da6395dSAndreas Gohr } 1649da6395dSAndreas Gohr 165a8acb244SAndreas Gohr public function html_graph($name, $width, $height) 166a8acb244SAndreas Gohr { 167211caa5dSAndreas Gohr $this->hlp->getGraph($this->from, $this->to, $width, $height)->$name(); 168dc7b1e5eSAndreas Gohr } 169dc7b1e5eSAndreas Gohr 1706b6f8822SAndreas Gohr /** 1716b6f8822SAndreas Gohr * Outputs pagination links 1726b6f8822SAndreas Gohr * 17333a136e5SAndreas Gohr * @param int $limit 17433a136e5SAndreas Gohr * @param int $next 1756b6f8822SAndreas Gohr */ 176a8acb244SAndreas Gohr public function html_pager($limit, $next) 177a8acb244SAndreas Gohr { 178211caa5dSAndreas Gohr $params = [ 179211caa5dSAndreas Gohr 'do' => 'admin', 180211caa5dSAndreas Gohr 'page' => 'statistics', 181211caa5dSAndreas Gohr 'opt' => $this->opt, 182211caa5dSAndreas Gohr 'f' => $this->from, 183211caa5dSAndreas Gohr 't' => $this->to, 184211caa5dSAndreas Gohr ]; 1852507f8e0SAndreas Gohr 186211caa5dSAndreas Gohr echo '<div class="plg_stats_pager">'; 1872507f8e0SAndreas Gohr if ($this->start > 0) { 1882507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 189211caa5dSAndreas Gohr $params['s'] = $go; 190211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="prev button">' . $this->getLang('prev') . '</a>'; 1912507f8e0SAndreas Gohr } 1922507f8e0SAndreas Gohr 1932507f8e0SAndreas Gohr if ($next) { 1942507f8e0SAndreas Gohr $go = $this->start + $limit; 195211caa5dSAndreas Gohr $params['s'] = $go; 196211caa5dSAndreas Gohr echo '<a href="?' . buildURLparams($params) . '" class="next button">' . $this->getLang('next') . '</a>'; 1972507f8e0SAndreas Gohr } 1982507f8e0SAndreas Gohr echo '</div>'; 1992507f8e0SAndreas Gohr } 2002507f8e0SAndreas Gohr 201264f1744SAndreas Gohr /** 202264f1744SAndreas Gohr * Print the time selection menu 203264f1744SAndreas Gohr */ 204a8acb244SAndreas Gohr public function html_timeselect() 205a8acb244SAndreas Gohr { 206483101d3SAndreas Gohr $quick = [ 207483101d3SAndreas Gohr 'today' => date('Y-m-d'), 208483101d3SAndreas Gohr 'last1' => date('Y-m-d', time() - (60 * 60 * 24)), 209483101d3SAndreas Gohr 'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)), 210483101d3SAndreas Gohr 'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)), 211483101d3SAndreas Gohr ]; 212483101d3SAndreas Gohr 21314d99ec0SAndreas Gohr 214264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 2156985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 216264f1744SAndreas Gohr 217047fcb0fSAndreas Gohr echo '<form action="' . DOKU_SCRIPT . '" method="get">'; 218264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 219264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 220264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 221483101d3SAndreas Gohr echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />'; 222483101d3SAndreas Gohr echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />'; 223264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 22414d99ec0SAndreas Gohr echo '</form>'; 225264f1744SAndreas Gohr 2266985b606SAndreas Gohr echo '<ul>'; 227483101d3SAndreas Gohr foreach ($quick as $name => $time) { 228211caa5dSAndreas Gohr $url = buildURLparams([ 229211caa5dSAndreas Gohr 'do' => 'admin', 230211caa5dSAndreas Gohr 'page' => 'statistics', 231211caa5dSAndreas Gohr 'opt' => $this->opt, 232211caa5dSAndreas Gohr 'f' => $time, 233211caa5dSAndreas Gohr 't' => $quick['today'], 234211caa5dSAndreas Gohr ]); 235211caa5dSAndreas Gohr 2366985b606SAndreas Gohr echo '<li>'; 237211caa5dSAndreas Gohr echo '<a href="?' . $url . '">'; 238483101d3SAndreas Gohr echo $this->getLang('time_' . $name); 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 */ 250a8acb244SAndreas Gohr public function html_dashboard() 251a8acb244SAndreas Gohr { 252878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2532812a751SAndreas Gohr 2542812a751SAndreas Gohr // general info 2552812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 256211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 2571d2d78ccSAndreas Gohr 258*1fd51258SAndreas Gohr echo '<ul>'; 259a8acb244SAndreas Gohr foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) { 260eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 261eabe0d07SAndreas Gohr } 2622812a751SAndreas Gohr echo '</ul>'; 2631d2d78ccSAndreas Gohr 264*1fd51258SAndreas Gohr echo '<ul>'; 265a8acb244SAndreas Gohr foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations'] as $name) { 2661d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2671d2d78ccSAndreas Gohr } 2681d2d78ccSAndreas Gohr echo '</ul>'; 2691d2d78ccSAndreas Gohr 270259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 271259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2722812a751SAndreas Gohr echo '</div>'; 2732812a751SAndreas Gohr 274211caa5dSAndreas Gohr $quickgraphs = [ 275211caa5dSAndreas Gohr ['lbl' => 'dash_mostpopular', 'query' => 'pages', 'opt' => 'page'], 276211caa5dSAndreas Gohr ['lbl' => 'dash_newincoming', 'query' => 'newreferer', 'opt' => 'newreferer'], 277211caa5dSAndreas Gohr ['lbl' => 'dash_topsearch', 'query' => 'searchphrases', 'opt' => 'internalsearchphrases'], 278211caa5dSAndreas Gohr ]; 27987d5e44bSAndreas Gohr 280211caa5dSAndreas Gohr foreach ($quickgraphs as $graph) { 281211caa5dSAndreas Gohr $params = [ 282211caa5dSAndreas Gohr 'do' => 'admin', 283211caa5dSAndreas Gohr 'page' => 'statistics', 284211caa5dSAndreas Gohr 'f' => $this->from, 285211caa5dSAndreas Gohr 't' => $this->to, 286211caa5dSAndreas Gohr 'opt' => $graph['opt'], 287211caa5dSAndreas Gohr ]; 28854f6c432SAndreas Gohr 289264f1744SAndreas Gohr echo '<div>'; 290211caa5dSAndreas Gohr echo '<h2>' . $this->getLang($graph['lbl']) . '</h2>'; 291211caa5dSAndreas Gohr $result = call_user_func([$this->hlp->getQuery(), $graph['query']]); 29229dea504SAndreas Gohr $this->html_resulttable($result); 293*1fd51258SAndreas Gohr echo '<p><a href="?' . buildURLparams($params) . '" class="more">' . $this->getLang('more') . '…</a></p>'; 294264f1744SAndreas Gohr echo '</div>'; 29514d99ec0SAndreas Gohr } 296211caa5dSAndreas Gohr } 29714d99ec0SAndreas Gohr 298a8acb244SAndreas Gohr public function html_history() 299a8acb244SAndreas Gohr { 300cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 301338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 302338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 303338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 304338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 305cae4a1c5SAndreas Gohr } 306cae4a1c5SAndreas Gohr 307a8acb244SAndreas Gohr public function html_countries() 308a8acb244SAndreas Gohr { 309878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 3101d379254SAnna Dabrowska $this->html_graph('countries', 300, 300); 311211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->countries(); 3122507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3139da6395dSAndreas Gohr } 3149da6395dSAndreas Gohr 315a8acb244SAndreas Gohr public function html_page() 316a8acb244SAndreas Gohr { 317878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 318211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->pages(); 3192507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3209da6395dSAndreas Gohr } 3219da6395dSAndreas Gohr 322a8acb244SAndreas Gohr public function html_edits() 323a8acb244SAndreas Gohr { 3241664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 325211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->edits(); 3261664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3271664ba1dSAndreas Gohr } 3281664ba1dSAndreas Gohr 329a8acb244SAndreas Gohr public function html_images() 330a8acb244SAndreas Gohr { 3311664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 332616c1e8bSAndreas Gohr 333211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->imagessum(); 334616c1e8bSAndreas Gohr echo '<p>'; 335616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 336616c1e8bSAndreas Gohr echo '</p>'; 337616c1e8bSAndreas Gohr 338211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->images(); 3391664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3401664ba1dSAndreas Gohr } 3411664ba1dSAndreas Gohr 342a8acb244SAndreas Gohr public function html_downloads() 343a8acb244SAndreas Gohr { 3441664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 345616c1e8bSAndreas Gohr 346211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloadssum(); 347616c1e8bSAndreas Gohr echo '<p>'; 348616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 349616c1e8bSAndreas Gohr echo '</p>'; 350616c1e8bSAndreas Gohr 351211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->downloads(); 3521664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3531664ba1dSAndreas Gohr } 3541664ba1dSAndreas Gohr 355a8acb244SAndreas Gohr public function html_browsers() 356a8acb244SAndreas Gohr { 357878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 3581d379254SAnna Dabrowska $this->html_graph('browsers', 300, 300); 359211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->browsers(false); 3602507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 36175fa767dSAndreas Gohr } 36275fa767dSAndreas Gohr 363a8acb244SAndreas Gohr public function html_topuser() 364a8acb244SAndreas Gohr { 36581ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 3661d379254SAnna Dabrowska $this->html_graph('topuser', 300, 300); 367211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->topuser(); 36881ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 36981ff4c3aSAndreas Gohr } 37081ff4c3aSAndreas Gohr 371a8acb244SAndreas Gohr public function html_topeditor() 372a8acb244SAndreas Gohr { 37381ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 3741d379254SAnna Dabrowska $this->html_graph('topeditor', 300, 300); 375211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->topeditor(); 37681ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37781ff4c3aSAndreas Gohr } 37881ff4c3aSAndreas Gohr 379a8acb244SAndreas Gohr public function html_topgroup() 380a8acb244SAndreas Gohr { 38181ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 3821d379254SAnna Dabrowska $this->html_graph('topgroup', 300, 300); 383211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->topgroup(); 38481ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 38581ff4c3aSAndreas Gohr } 38681ff4c3aSAndreas Gohr 387a8acb244SAndreas Gohr public function html_topgroupedit() 388a8acb244SAndreas Gohr { 38981ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 3901d379254SAnna Dabrowska $this->html_graph('topgroupedit', 300, 300); 391211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->topgroupedit(); 39281ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 39381ff4c3aSAndreas Gohr } 39481ff4c3aSAndreas Gohr 395a8acb244SAndreas Gohr public function html_os() 396a8acb244SAndreas Gohr { 397878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 3981d379254SAnna Dabrowska $this->html_graph('os', 300, 300); 399211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->os(); 4002507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 401bd4217d3SAndreas Gohr } 402bd4217d3SAndreas Gohr 403a8acb244SAndreas Gohr public function html_referer() 404a8acb244SAndreas Gohr { 405211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->aggregate(); 4062812a751SAndreas Gohr 4072812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 4082812a751SAndreas Gohr 40994023548SAndreas Gohr if ($all) { 4100863c19cSAndreas Gohr printf( 4110863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 412a8acb244SAndreas Gohr $all, 413a8acb244SAndreas Gohr $result['direct'], 414a8acb244SAndreas Gohr (100 * $result['direct'] / $all), 415a8acb244SAndreas Gohr $result['search'], 416a8acb244SAndreas Gohr (100 * $result['search'] / $all), 417a8acb244SAndreas Gohr $result['external'], 4180863c19cSAndreas Gohr (100 * $result['external'] / $all) 4190863c19cSAndreas Gohr ); 42094023548SAndreas Gohr } 4212812a751SAndreas Gohr 422211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->referer(); 4232507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4249da6395dSAndreas Gohr } 4259da6395dSAndreas Gohr 426a8acb244SAndreas Gohr public function html_newreferer() 427a8acb244SAndreas Gohr { 428878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 429e7a2f1e0SAndreas Gohr 430211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->newreferer(); 4312507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 432e7a2f1e0SAndreas Gohr } 433e7a2f1e0SAndreas Gohr 434a8acb244SAndreas Gohr public function html_outlinks() 435a8acb244SAndreas Gohr { 436878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 437211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->outlinks(); 438e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 439e25286daSAndreas Gohr } 440e25286daSAndreas Gohr 441a8acb244SAndreas Gohr public function html_searchphrases() 442a8acb244SAndreas Gohr { 443878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 444211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->searchphrases(true); 44512dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 44612dcdeccSAndreas Gohr } 44712dcdeccSAndreas Gohr 448a8acb244SAndreas Gohr public function html_searchwords() 449a8acb244SAndreas Gohr { 450878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 451211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->searchwords(true); 4525bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4535bccfe87SAndreas Gohr } 4545bccfe87SAndreas Gohr 455a8acb244SAndreas Gohr public function html_internalsearchphrases() 456a8acb244SAndreas Gohr { 457878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 458211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->searchphrases(false); 4595bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4605bccfe87SAndreas Gohr } 4615bccfe87SAndreas Gohr 462a8acb244SAndreas Gohr public function html_internalsearchwords() 463a8acb244SAndreas Gohr { 464878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 465211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->searchwords(false); 46612dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 46712dcdeccSAndreas Gohr } 46812dcdeccSAndreas Gohr 469a8acb244SAndreas Gohr public function html_searchengines() 470a8acb244SAndreas Gohr { 471878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 47225b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 473211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->searchengines(); 47412dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 47512dcdeccSAndreas Gohr } 47612dcdeccSAndreas Gohr 477a8acb244SAndreas Gohr public function html_resolution() 478a8acb244SAndreas Gohr { 47925446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 48025446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 481211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->resolution(); 482307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 48325446aa2SAndreas Gohr } 484307baf3fSAndreas Gohr 485a8acb244SAndreas Gohr public function html_viewport() 486a8acb244SAndreas Gohr { 48725446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 48825446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 489211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->viewport(); 49025446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 491c73e16f1SAndreas Gohr } 4929da6395dSAndreas Gohr 493a8acb244SAndreas Gohr public function html_seenusers() 494a8acb244SAndreas Gohr { 49533a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 496211caa5dSAndreas Gohr $result = $this->hlp->getQuery()->seenusers(); 49733a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 49833a136e5SAndreas Gohr } 49933a136e5SAndreas Gohr 50014d99ec0SAndreas Gohr /** 50114d99ec0SAndreas Gohr * Display a result in a HTML table 50214d99ec0SAndreas Gohr */ 503a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 504a8acb244SAndreas Gohr { 50556f647ddSAndreas Gohr echo '<table class="inline">'; 5062812a751SAndreas Gohr if (is_array($header)) { 50714d99ec0SAndreas Gohr echo '<tr>'; 50814d99ec0SAndreas Gohr foreach ($header as $h) { 50914d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 51014d99ec0SAndreas Gohr } 51114d99ec0SAndreas Gohr echo '</tr>'; 5122812a751SAndreas Gohr } 51314d99ec0SAndreas Gohr 5142507f8e0SAndreas Gohr $count = 0; 5152ee939eeSAndreas Gohr if (is_array($result)) foreach ($result as $row) { 51614d99ec0SAndreas Gohr echo '<tr>'; 51714d99ec0SAndreas Gohr foreach ($row as $k => $v) { 518f3818071SAndreas Gohr if ($k == 'res_x') continue; 519f3818071SAndreas Gohr if ($k == 'res_y') continue; 520f3818071SAndreas Gohr 5212812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 52214d99ec0SAndreas Gohr if ($k == 'page') { 52314d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 52414d99ec0SAndreas Gohr echo hsc($v); 52514d99ec0SAndreas Gohr echo '</a>'; 5261664ba1dSAndreas Gohr } elseif ($k == 'media') { 5271664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 5281664ba1dSAndreas Gohr echo hsc($v); 5291664ba1dSAndreas Gohr echo '</a>'; 5301664ba1dSAndreas Gohr } elseif ($k == 'filesize') { 5311664ba1dSAndreas Gohr echo filesize_h($v); 53214d99ec0SAndreas Gohr } elseif ($k == 'url') { 53354f6c432SAndreas Gohr $url = hsc($v); 53483b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 5352812a751SAndreas Gohr if (strlen($url) > 45) { 5362812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 53754f6c432SAndreas Gohr } 53814d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 53954f6c432SAndreas Gohr echo $url; 54014d99ec0SAndreas Gohr echo '</a>'; 5415bccfe87SAndreas Gohr } elseif ($k == 'ilookup') { 542a8acb244SAndreas Gohr echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>'; 54329dea504SAndreas Gohr } elseif ($k == 'lookup') { 54429dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 545211caa5dSAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" />'; 54629dea504SAndreas Gohr echo '</a> '; 54729dea504SAndreas Gohr 54829dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 549211caa5dSAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" />'; 55029dea504SAndreas Gohr echo '</a> '; 55129dea504SAndreas Gohr 55213a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 553211caa5dSAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" />'; 55429dea504SAndreas Gohr echo '</a> '; 55512dcdeccSAndreas Gohr } elseif ($k == 'engine') { 556211caa5dSAndreas Gohr // FIXME thhis is not correct anymore 55713a86c14SAndreas Gohr if (isset($SEARCHENGINEINFO[$v])) { 55813a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 55913a86c14SAndreas Gohr } else { 56013a86c14SAndreas Gohr echo hsc(ucwords($v)); 56113a86c14SAndreas Gohr } 56213a86c14SAndreas Gohr } elseif ($k == 'eflag') { 56313a86c14SAndreas Gohr $this->html_icon('search', $v); 56475fa767dSAndreas Gohr } elseif ($k == 'bflag') { 56513a86c14SAndreas Gohr $this->html_icon('browser', $v); 566bd4217d3SAndreas Gohr } elseif ($k == 'osflag') { 56713a86c14SAndreas Gohr $this->html_icon('os', $v); 56875fa767dSAndreas Gohr } elseif ($k == 'cflag') { 56913a86c14SAndreas Gohr $this->html_icon('flags', $v); 57014d99ec0SAndreas Gohr } elseif ($k == 'html') { 57114d99ec0SAndreas Gohr echo $v; 57214d99ec0SAndreas Gohr } else { 57314d99ec0SAndreas Gohr echo hsc($v); 57414d99ec0SAndreas Gohr } 57514d99ec0SAndreas Gohr echo '</td>'; 57614d99ec0SAndreas Gohr } 57714d99ec0SAndreas Gohr echo '</tr>'; 5782507f8e0SAndreas Gohr 5792507f8e0SAndreas Gohr if ($pager && ($count == $pager)) break; 5802507f8e0SAndreas Gohr $count++; 58114d99ec0SAndreas Gohr } 58214d99ec0SAndreas Gohr echo '</table>'; 5832507f8e0SAndreas Gohr 5842507f8e0SAndreas Gohr if ($pager) $this->html_pager($pager, count($result) > $pager); 5851878f16fSAndreas Gohr } 5861878f16fSAndreas Gohr 587a8acb244SAndreas Gohr public function html_icon($type, $value) 588a8acb244SAndreas Gohr { 58913a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5909bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 591a8acb244SAndreas Gohr 59213a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 593dffb869bSAndreas Gohr if ($type == 'flags') { 594dffb869bSAndreas Gohr $w = 18; 595dffb869bSAndreas Gohr $h = 12; 596dffb869bSAndreas Gohr } else { 597dffb869bSAndreas Gohr $w = 16; 598dffb869bSAndreas Gohr $h = 16; 599dffb869bSAndreas Gohr } 600211caa5dSAndreas Gohr if (!file_exists(DOKU_INC . $file)) return; 601211caa5dSAndreas Gohr 602dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 60313a86c14SAndreas Gohr } 60413a86c14SAndreas Gohr} 605