11878f16fSAndreas Gohr<?php 2*a8acb244SAndreas Gohr 3*a8acb244SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 4*a8acb244SAndreas Gohr 51878f16fSAndreas Gohr/** 61878f16fSAndreas Gohr * statistics plugin 71878f16fSAndreas Gohr * 81878f16fSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 96b6f8822SAndreas Gohr * @author Andreas Gohr <gohr@splitbrain.org> 101878f16fSAndreas Gohr */ 111878f16fSAndreas Gohr 121878f16fSAndreas Gohr// must be run within Dokuwiki 131878f16fSAndreas Gohrif (!defined('DOKU_INC')) die(); 141878f16fSAndreas Gohr 151878f16fSAndreas Gohr/** 161878f16fSAndreas Gohr * All DokuWiki plugins to extend the admin function 171878f16fSAndreas Gohr * need to inherit from this class 181878f16fSAndreas Gohr */ 19*a8acb244SAndreas Gohrclass admin_plugin_statistics extends AdminPlugin 20*a8acb244SAndreas Gohr{ 2133a136e5SAndreas Gohr /** @var string the currently selected page */ 22a901d721SAndreas Gohr protected $opt = ''; 2333a136e5SAndreas Gohr 2433a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 25a901d721SAndreas Gohr protected $from = ''; 2633a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 27a901d721SAndreas Gohr protected $to = ''; 2833a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 2933a136e5SAndreas Gohr protected $start = 0; 3033a136e5SAndreas Gohr 3133a136e5SAndreas Gohr /** @var string MySQL timelimit statement */ 32a901d721SAndreas Gohr protected $tlimit = ''; 33a901d721SAndreas Gohr 3433a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 3533a136e5SAndreas Gohr protected $hlp; 3633a136e5SAndreas Gohr 37a901d721SAndreas Gohr /** 38a901d721SAndreas Gohr * Available statistic pages 39a901d721SAndreas Gohr */ 40*a8acb244SAndreas Gohr protected $pages = ['dashboard' => 1, 'content' => ['page', 'edits', 'images', 'downloads', 'history'], 'users' => ['topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'], 'links' => ['referer', 'newreferer', 'outlinks'], 'search' => ['searchengines', 'searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords'], 'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport']]; 411878f16fSAndreas Gohr 4281ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 43*a8acb244SAndreas Gohr protected $allowedpages = []; 4481ff4c3aSAndreas Gohr 451878f16fSAndreas Gohr /** 466b6f8822SAndreas Gohr * Initialize the helper 476b6f8822SAndreas Gohr */ 48*a8acb244SAndreas Gohr public function __construct() 49*a8acb244SAndreas Gohr { 506b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 5181ff4c3aSAndreas Gohr 5281ff4c3aSAndreas Gohr // build a list of pages 5381ff4c3aSAndreas Gohr foreach ($this->pages as $key => $val) { 5481ff4c3aSAndreas Gohr if (is_array($val)) { 5581ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 5681ff4c3aSAndreas Gohr } else { 5781ff4c3aSAndreas Gohr $this->allowedpages[] = $key; 5881ff4c3aSAndreas Gohr } 5981ff4c3aSAndreas Gohr } 606b6f8822SAndreas Gohr } 616b6f8822SAndreas Gohr 626b6f8822SAndreas Gohr /** 631878f16fSAndreas Gohr * Access for managers allowed 641878f16fSAndreas Gohr */ 65*a8acb244SAndreas Gohr public function forAdminOnly() 66*a8acb244SAndreas Gohr { 671878f16fSAndreas Gohr return false; 681878f16fSAndreas Gohr } 691878f16fSAndreas Gohr 701878f16fSAndreas Gohr /** 711878f16fSAndreas Gohr * return sort order for position in admin menu 721878f16fSAndreas Gohr */ 73*a8acb244SAndreas Gohr public function getMenuSort() 74*a8acb244SAndreas Gohr { 756b6f8822SAndreas Gohr return 350; 761878f16fSAndreas Gohr } 771878f16fSAndreas Gohr 781878f16fSAndreas Gohr /** 791878f16fSAndreas Gohr * handle user request 801878f16fSAndreas Gohr */ 81*a8acb244SAndreas Gohr public function handle() 82*a8acb244SAndreas Gohr { 83264f1744SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']); 8481ff4c3aSAndreas Gohr if (!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard'; 85a901d721SAndreas Gohr 8695eb68e6SAndreas Gohr $this->start = (int) $_REQUEST['s']; 87e8699bceSAndreas Gohr $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']); 88e8699bceSAndreas Gohr } 8995eb68e6SAndreas Gohr 90e8699bceSAndreas Gohr /** 91e8699bceSAndreas Gohr * set limit clause 92e8699bceSAndreas Gohr */ 93*a8acb244SAndreas Gohr public function setTimeframe($from, $to) 94*a8acb244SAndreas Gohr { 95047fcb0fSAndreas Gohr // swap if wrong order 96*a8acb244SAndreas Gohr if ($from > $to) [$from, $to] = [$to, $from]; 97047fcb0fSAndreas Gohr 983bf3de81SAndreas Gohr $this->tlimit = $this->hlp->Query()->mktlimit($from, $to); 99e8699bceSAndreas Gohr $this->from = $from; 100e8699bceSAndreas Gohr $this->to = $to; 1011878f16fSAndreas Gohr } 1021878f16fSAndreas Gohr 1031878f16fSAndreas Gohr /** 10479b4a855SAndreas Gohr * Output the Statistics 1051878f16fSAndreas Gohr */ 106*a8acb244SAndreas Gohr public function html() 107*a8acb244SAndreas Gohr { 1081d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1090c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 110264f1744SAndreas Gohr $this->html_timeselect(); 111441bfb8eSAndreas Gohr tpl_flush(); 112264f1744SAndreas Gohr 11379b4a855SAndreas Gohr $method = 'html_' . $this->opt; 11479b4a855SAndreas Gohr if (method_exists($this, $method)) { 115a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 116a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 11779b4a855SAndreas Gohr $this->$method(); 118a901d721SAndreas Gohr echo '</div>'; 11914d99ec0SAndreas Gohr } 1201d2d78ccSAndreas Gohr echo '</div>'; 12114d99ec0SAndreas Gohr } 12214d99ec0SAndreas Gohr 1236b6f8822SAndreas Gohr /** 1246b6f8822SAndreas Gohr * Return the TOC 1256b6f8822SAndreas Gohr * 1266b6f8822SAndreas Gohr * @return array 1276b6f8822SAndreas Gohr */ 128*a8acb244SAndreas Gohr public function getTOC() 129*a8acb244SAndreas Gohr { 130*a8acb244SAndreas Gohr $toc = []; 13181ff4c3aSAndreas Gohr foreach ($this->pages as $key => $info) { 13281ff4c3aSAndreas Gohr if (is_array($info)) { 13381ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 13481ff4c3aSAndreas Gohr '', 13581ff4c3aSAndreas Gohr $this->getLang($key), 13681ff4c3aSAndreas Gohr 1, 13781ff4c3aSAndreas Gohr '' 13847ffcf7dSAndreas Gohr ); 13981ff4c3aSAndreas Gohr 14081ff4c3aSAndreas Gohr foreach ($info as $page) { 14181ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 14281ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 14381ff4c3aSAndreas Gohr $this->getLang($page), 14481ff4c3aSAndreas Gohr 2, 14581ff4c3aSAndreas Gohr '' 14681ff4c3aSAndreas Gohr ); 14781ff4c3aSAndreas Gohr } 14881ff4c3aSAndreas Gohr } else { 14981ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 15081ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . '&f=' . $this->from . '&t=' . $this->to, 15181ff4c3aSAndreas Gohr $this->getLang($key), 15281ff4c3aSAndreas Gohr 1, 15381ff4c3aSAndreas Gohr '' 15481ff4c3aSAndreas Gohr ); 15581ff4c3aSAndreas Gohr } 15647ffcf7dSAndreas Gohr } 15747ffcf7dSAndreas Gohr return $toc; 1589da6395dSAndreas Gohr } 1599da6395dSAndreas Gohr 160*a8acb244SAndreas Gohr public function html_graph($name, $width, $height) 161*a8acb244SAndreas Gohr { 162dc7b1e5eSAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name . 163dc7b1e5eSAndreas Gohr '&f=' . $this->from . '&t=' . $this->to; 164dc7b1e5eSAndreas Gohr echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>'; 165dc7b1e5eSAndreas Gohr } 166dc7b1e5eSAndreas Gohr 1676b6f8822SAndreas Gohr /** 1686b6f8822SAndreas Gohr * Outputs pagination links 1696b6f8822SAndreas Gohr * 17033a136e5SAndreas Gohr * @param int $limit 17133a136e5SAndreas Gohr * @param int $next 1726b6f8822SAndreas Gohr */ 173*a8acb244SAndreas Gohr public function html_pager($limit, $next) 174*a8acb244SAndreas Gohr { 1752507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 1762507f8e0SAndreas Gohr 1772507f8e0SAndreas Gohr if ($this->start > 0) { 1782507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 179d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $this->from . '&t=' . $this->to . '&s=' . $go . '" class="prev button">' . $this->getLang('prev') . '</a>'; 1802507f8e0SAndreas Gohr } 1812507f8e0SAndreas Gohr 1822507f8e0SAndreas Gohr if ($next) { 1832507f8e0SAndreas Gohr $go = $this->start + $limit; 184d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $this->from . '&t=' . $this->to . '&s=' . $go . '" class="next button">' . $this->getLang('next') . '</a>'; 1852507f8e0SAndreas Gohr } 1862507f8e0SAndreas Gohr echo '</div>'; 1872507f8e0SAndreas Gohr } 1882507f8e0SAndreas Gohr 189264f1744SAndreas Gohr /** 190264f1744SAndreas Gohr * Print the time selection menu 191264f1744SAndreas Gohr */ 192*a8acb244SAndreas Gohr public function html_timeselect() 193*a8acb244SAndreas Gohr { 1946985b606SAndreas Gohr $today = date('Y-m-d'); 1956985b606SAndreas Gohr $last1 = date('Y-m-d', time() - (60 * 60 * 24)); 1966985b606SAndreas Gohr $last7 = date('Y-m-d', time() - (60 * 60 * 24 * 7)); 1976985b606SAndreas Gohr $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30)); 19814d99ec0SAndreas Gohr 199264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 2006985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 201264f1744SAndreas Gohr 202047fcb0fSAndreas Gohr echo '<form action="' . DOKU_SCRIPT . '" method="get">'; 203264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 204264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 205264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 206047fcb0fSAndreas Gohr echo '<input type="text" name="f" value="' . $this->from . '" class="edit datepicker" />'; 207047fcb0fSAndreas Gohr echo '<input type="text" name="t" value="' . $this->to . '" class="edit datepicker" />'; 208264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 20914d99ec0SAndreas Gohr echo '</form>'; 210264f1744SAndreas Gohr 2116985b606SAndreas Gohr echo '<ul>'; 212*a8acb244SAndreas Gohr foreach (['today', 'last1', 'last7', 'last30'] as $time) { 2136985b606SAndreas Gohr echo '<li>'; 214*a8acb244SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . ${$time} . '&t=' . $today . '">'; 2156985b606SAndreas Gohr echo $this->getLang('time_' . $time); 2166985b606SAndreas Gohr echo '</a>'; 2176985b606SAndreas Gohr echo '</li>'; 2186985b606SAndreas Gohr } 2196985b606SAndreas Gohr echo '</ul>'; 2206985b606SAndreas Gohr 221264f1744SAndreas Gohr echo '</div>'; 22214d99ec0SAndreas Gohr } 22314d99ec0SAndreas Gohr 224f5f32cbfSAndreas Gohr /** 225f5f32cbfSAndreas Gohr * Print an introductionary screen 226f5f32cbfSAndreas Gohr */ 227*a8acb244SAndreas Gohr public function html_dashboard() 228*a8acb244SAndreas Gohr { 229878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2302812a751SAndreas Gohr 2312812a751SAndreas Gohr // general info 2322812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 2336b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 2341d2d78ccSAndreas Gohr 2351d2d78ccSAndreas Gohr echo '<ul class="left">'; 236*a8acb244SAndreas Gohr foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) { 237eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 238eabe0d07SAndreas Gohr } 2392812a751SAndreas Gohr echo '</ul>'; 2401d2d78ccSAndreas Gohr 2411d2d78ccSAndreas Gohr echo '<ul class="left">'; 242*a8acb244SAndreas Gohr foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations'] as $name) { 2431d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2441d2d78ccSAndreas Gohr } 2451d2d78ccSAndreas Gohr echo '</ul>'; 2461d2d78ccSAndreas Gohr 24756f647ddSAndreas Gohr echo '<br style="clear: left" />'; 24856f647ddSAndreas Gohr 249259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 250259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2512812a751SAndreas Gohr echo '</div>'; 2522812a751SAndreas Gohr 25387d5e44bSAndreas Gohr // top pages today 254264f1744SAndreas Gohr echo '<div>'; 255dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2566b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15); 2572812a751SAndreas Gohr $this->html_resulttable($result); 258d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 259264f1744SAndreas Gohr echo '</div>'; 26087d5e44bSAndreas Gohr 26187d5e44bSAndreas Gohr // top referer today 262264f1744SAndreas Gohr echo '<div>'; 263dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2646b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15); 2652812a751SAndreas Gohr $this->html_resulttable($result); 266d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 267264f1744SAndreas Gohr echo '</div>'; 26854f6c432SAndreas Gohr 26929dea504SAndreas Gohr // top searches today 270264f1744SAndreas Gohr echo '<div>'; 271dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 27212b59231SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15); 27329dea504SAndreas Gohr $this->html_resulttable($result); 274d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 275264f1744SAndreas Gohr echo '</div>'; 27614d99ec0SAndreas Gohr } 27714d99ec0SAndreas Gohr 278*a8acb244SAndreas Gohr public function html_history() 279*a8acb244SAndreas Gohr { 280cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 281338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 282338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 283338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 284338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 285cae4a1c5SAndreas Gohr } 286cae4a1c5SAndreas Gohr 287*a8acb244SAndreas Gohr public function html_countries() 288*a8acb244SAndreas Gohr { 289878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 290878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 2916b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 2922507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2939da6395dSAndreas Gohr } 2949da6395dSAndreas Gohr 295*a8acb244SAndreas Gohr public function html_page() 296*a8acb244SAndreas Gohr { 297878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 2986b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 2992507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3009da6395dSAndreas Gohr } 3019da6395dSAndreas Gohr 302*a8acb244SAndreas Gohr public function html_edits() 303*a8acb244SAndreas Gohr { 3041664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 3051664ba1dSAndreas Gohr $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150); 3061664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3071664ba1dSAndreas Gohr } 3081664ba1dSAndreas Gohr 309*a8acb244SAndreas Gohr public function html_images() 310*a8acb244SAndreas Gohr { 3111664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 312616c1e8bSAndreas Gohr 313616c1e8bSAndreas Gohr $result = $this->hlp->Query()->imagessum($this->tlimit); 314616c1e8bSAndreas Gohr echo '<p>'; 315616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 316616c1e8bSAndreas Gohr echo '</p>'; 317616c1e8bSAndreas Gohr 3181664ba1dSAndreas Gohr $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150); 3191664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3201664ba1dSAndreas Gohr } 3211664ba1dSAndreas Gohr 322*a8acb244SAndreas Gohr public function html_downloads() 323*a8acb244SAndreas Gohr { 3241664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 325616c1e8bSAndreas Gohr 326616c1e8bSAndreas Gohr $result = $this->hlp->Query()->downloadssum($this->tlimit); 327616c1e8bSAndreas Gohr echo '<p>'; 328616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 329616c1e8bSAndreas Gohr echo '</p>'; 330616c1e8bSAndreas Gohr 3311664ba1dSAndreas Gohr $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150); 3321664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3331664ba1dSAndreas Gohr } 3341664ba1dSAndreas Gohr 335*a8acb244SAndreas Gohr public function html_browsers() 336*a8acb244SAndreas Gohr { 337878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 338878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 3396b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 3402507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 34175fa767dSAndreas Gohr } 34275fa767dSAndreas Gohr 343*a8acb244SAndreas Gohr public function html_topuser() 344*a8acb244SAndreas Gohr { 34581ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 34681ff4c3aSAndreas Gohr $this->html_graph('topuser', 400, 200); 34781ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topuser($this->tlimit, $this->start, 150, true); 34881ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 34981ff4c3aSAndreas Gohr } 35081ff4c3aSAndreas Gohr 351*a8acb244SAndreas Gohr public function html_topeditor() 352*a8acb244SAndreas Gohr { 35381ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 35481ff4c3aSAndreas Gohr $this->html_graph('topeditor', 400, 200); 35581ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topeditor($this->tlimit, $this->start, 150, true); 35681ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 35781ff4c3aSAndreas Gohr } 35881ff4c3aSAndreas Gohr 359*a8acb244SAndreas Gohr public function html_topgroup() 360*a8acb244SAndreas Gohr { 36181ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 36281ff4c3aSAndreas Gohr $this->html_graph('topgroup', 400, 200); 36381ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroup($this->tlimit, $this->start, 150, true); 36481ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 36581ff4c3aSAndreas Gohr } 36681ff4c3aSAndreas Gohr 367*a8acb244SAndreas Gohr public function html_topgroupedit() 368*a8acb244SAndreas Gohr { 36981ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 37081ff4c3aSAndreas Gohr $this->html_graph('topgroupedit', 400, 200); 37181ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroupedit($this->tlimit, $this->start, 150, true); 37281ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37381ff4c3aSAndreas Gohr } 37481ff4c3aSAndreas Gohr 375*a8acb244SAndreas Gohr public function html_os() 376*a8acb244SAndreas Gohr { 377878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 378878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 3796b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 3802507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 381bd4217d3SAndreas Gohr } 382bd4217d3SAndreas Gohr 383*a8acb244SAndreas Gohr public function html_referer() 384*a8acb244SAndreas Gohr { 3856b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 3862812a751SAndreas Gohr 3872812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 3882812a751SAndreas Gohr 38994023548SAndreas Gohr if ($all) { 3900863c19cSAndreas Gohr printf( 3910863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 392*a8acb244SAndreas Gohr $all, 393*a8acb244SAndreas Gohr $result['direct'], 394*a8acb244SAndreas Gohr (100 * $result['direct'] / $all), 395*a8acb244SAndreas Gohr $result['search'], 396*a8acb244SAndreas Gohr (100 * $result['search'] / $all), 397*a8acb244SAndreas Gohr $result['external'], 3980863c19cSAndreas Gohr (100 * $result['external'] / $all) 3990863c19cSAndreas Gohr ); 40094023548SAndreas Gohr } 4012812a751SAndreas Gohr 4026b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 4032507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4049da6395dSAndreas Gohr } 4059da6395dSAndreas Gohr 406*a8acb244SAndreas Gohr public function html_newreferer() 407*a8acb244SAndreas Gohr { 408878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 409e7a2f1e0SAndreas Gohr 4106b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 4112507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 412e7a2f1e0SAndreas Gohr } 413e7a2f1e0SAndreas Gohr 414*a8acb244SAndreas Gohr public function html_outlinks() 415*a8acb244SAndreas Gohr { 416878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 4176b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 418e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 419e25286daSAndreas Gohr } 420e25286daSAndreas Gohr 421*a8acb244SAndreas Gohr public function html_searchphrases() 422*a8acb244SAndreas Gohr { 423878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 4245bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 42512dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 42612dcdeccSAndreas Gohr } 42712dcdeccSAndreas Gohr 428*a8acb244SAndreas Gohr public function html_searchwords() 429*a8acb244SAndreas Gohr { 430878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 4315bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 4325bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4335bccfe87SAndreas Gohr } 4345bccfe87SAndreas Gohr 435*a8acb244SAndreas Gohr public function html_internalsearchphrases() 436*a8acb244SAndreas Gohr { 437878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 4385bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 4395bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4405bccfe87SAndreas Gohr } 4415bccfe87SAndreas Gohr 442*a8acb244SAndreas Gohr public function html_internalsearchwords() 443*a8acb244SAndreas Gohr { 444878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 4455bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 44612dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 44712dcdeccSAndreas Gohr } 44812dcdeccSAndreas Gohr 449*a8acb244SAndreas Gohr public function html_searchengines() 450*a8acb244SAndreas Gohr { 451878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 45225b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 4536b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 45412dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 45512dcdeccSAndreas Gohr } 45612dcdeccSAndreas Gohr 457*a8acb244SAndreas Gohr public function html_resolution() 458*a8acb244SAndreas Gohr { 45925446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 46025446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 461307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 462307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 46325446aa2SAndreas Gohr } 464307baf3fSAndreas Gohr 465*a8acb244SAndreas Gohr public function html_viewport() 466*a8acb244SAndreas Gohr { 46725446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 46825446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 46925446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 47025446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 471c73e16f1SAndreas Gohr } 4729da6395dSAndreas Gohr 473*a8acb244SAndreas Gohr public function html_seenusers() 474*a8acb244SAndreas Gohr { 47533a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 47633a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 47733a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 47833a136e5SAndreas Gohr } 47933a136e5SAndreas Gohr 48014d99ec0SAndreas Gohr /** 48114d99ec0SAndreas Gohr * Display a result in a HTML table 48214d99ec0SAndreas Gohr */ 483*a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 484*a8acb244SAndreas Gohr { 48556f647ddSAndreas Gohr echo '<table class="inline">'; 4862812a751SAndreas Gohr if (is_array($header)) { 48714d99ec0SAndreas Gohr echo '<tr>'; 48814d99ec0SAndreas Gohr foreach ($header as $h) { 48914d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 49014d99ec0SAndreas Gohr } 49114d99ec0SAndreas Gohr echo '</tr>'; 4922812a751SAndreas Gohr } 49314d99ec0SAndreas Gohr 4942507f8e0SAndreas Gohr $count = 0; 4952ee939eeSAndreas Gohr if (is_array($result)) foreach ($result as $row) { 49614d99ec0SAndreas Gohr echo '<tr>'; 49714d99ec0SAndreas Gohr foreach ($row as $k => $v) { 498f3818071SAndreas Gohr if ($k == 'res_x') continue; 499f3818071SAndreas Gohr if ($k == 'res_y') continue; 500f3818071SAndreas Gohr 5012812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 50214d99ec0SAndreas Gohr if ($k == 'page') { 50314d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 50414d99ec0SAndreas Gohr echo hsc($v); 50514d99ec0SAndreas Gohr echo '</a>'; 5061664ba1dSAndreas Gohr } elseif ($k == 'media') { 5071664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 5081664ba1dSAndreas Gohr echo hsc($v); 5091664ba1dSAndreas Gohr echo '</a>'; 5101664ba1dSAndreas Gohr } elseif ($k == 'filesize') { 5111664ba1dSAndreas Gohr echo filesize_h($v); 51214d99ec0SAndreas Gohr } elseif ($k == 'url') { 51354f6c432SAndreas Gohr $url = hsc($v); 51483b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 5152812a751SAndreas Gohr if (strlen($url) > 45) { 5162812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 51754f6c432SAndreas Gohr } 51814d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 51954f6c432SAndreas Gohr echo $url; 52014d99ec0SAndreas Gohr echo '</a>'; 5215bccfe87SAndreas Gohr } elseif ($k == 'ilookup') { 522*a8acb244SAndreas Gohr echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>'; 52329dea504SAndreas Gohr } elseif ($k == 'lookup') { 52429dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 52513a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 52629dea504SAndreas Gohr echo '</a> '; 52729dea504SAndreas Gohr 52829dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 52913a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 53029dea504SAndreas Gohr echo '</a> '; 53129dea504SAndreas Gohr 53213a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 53313a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 53429dea504SAndreas Gohr echo '</a> '; 53512dcdeccSAndreas Gohr } elseif ($k == 'engine') { 536*a8acb244SAndreas Gohr include_once(__DIR__ . '/inc/searchengines.php'); 53713a86c14SAndreas Gohr if (isset($SEARCHENGINEINFO[$v])) { 53813a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 53913a86c14SAndreas Gohr } else { 54013a86c14SAndreas Gohr echo hsc(ucwords($v)); 54113a86c14SAndreas Gohr } 54213a86c14SAndreas Gohr } elseif ($k == 'eflag') { 54313a86c14SAndreas Gohr $this->html_icon('search', $v); 54475fa767dSAndreas Gohr } elseif ($k == 'bflag') { 54513a86c14SAndreas Gohr $this->html_icon('browser', $v); 546bd4217d3SAndreas Gohr } elseif ($k == 'osflag') { 54713a86c14SAndreas Gohr $this->html_icon('os', $v); 54875fa767dSAndreas Gohr } elseif ($k == 'cflag') { 54913a86c14SAndreas Gohr $this->html_icon('flags', $v); 55014d99ec0SAndreas Gohr } elseif ($k == 'html') { 55114d99ec0SAndreas Gohr echo $v; 55214d99ec0SAndreas Gohr } else { 55314d99ec0SAndreas Gohr echo hsc($v); 55414d99ec0SAndreas Gohr } 55514d99ec0SAndreas Gohr echo '</td>'; 55614d99ec0SAndreas Gohr } 55714d99ec0SAndreas Gohr echo '</tr>'; 5582507f8e0SAndreas Gohr 5592507f8e0SAndreas Gohr if ($pager && ($count == $pager)) break; 5602507f8e0SAndreas Gohr $count++; 56114d99ec0SAndreas Gohr } 56214d99ec0SAndreas Gohr echo '</table>'; 5632507f8e0SAndreas Gohr 5642507f8e0SAndreas Gohr if ($pager) $this->html_pager($pager, count($result) > $pager); 5651878f16fSAndreas Gohr } 5661878f16fSAndreas Gohr 567*a8acb244SAndreas Gohr public function html_icon($type, $value) 568*a8acb244SAndreas Gohr { 56913a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5709bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 571*a8acb244SAndreas Gohr 57213a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 573dffb869bSAndreas Gohr if ($type == 'flags') { 574dffb869bSAndreas Gohr $w = 18; 575dffb869bSAndreas Gohr $h = 12; 576dffb869bSAndreas Gohr } else { 577dffb869bSAndreas Gohr $w = 16; 578dffb869bSAndreas Gohr $h = 16; 579dffb869bSAndreas Gohr } 58013a86c14SAndreas Gohr if (file_exists(DOKU_INC . $file)) { 581dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 58213a86c14SAndreas Gohr } 58313a86c14SAndreas Gohr } 5841878f16fSAndreas Gohr} 585