11878f16fSAndreas Gohr<?php 2a8acb244SAndreas Gohr 3a8acb244SAndreas Gohruse dokuwiki\Extension\AdminPlugin; 4a8acb244SAndreas 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 */ 11a8acb244SAndreas Gohrclass admin_plugin_statistics extends AdminPlugin 12a8acb244SAndreas Gohr{ 1333a136e5SAndreas Gohr /** @var string the currently selected page */ 14a901d721SAndreas Gohr protected $opt = ''; 1533a136e5SAndreas Gohr 1633a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 17a901d721SAndreas Gohr protected $from = ''; 1833a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 19a901d721SAndreas Gohr protected $to = ''; 2033a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 2133a136e5SAndreas Gohr protected $start = 0; 2233a136e5SAndreas Gohr 2333a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 2433a136e5SAndreas Gohr protected $hlp; 2533a136e5SAndreas Gohr 26a901d721SAndreas Gohr /** 27a901d721SAndreas Gohr * Available statistic pages 28a901d721SAndreas Gohr */ 29*483101d3SAndreas Gohr protected $pages = [ 30*483101d3SAndreas Gohr 'dashboard' => 1, 31*483101d3SAndreas Gohr 'content' => ['page', 'edits', 'images', 'downloads', 'history'], 32*483101d3SAndreas Gohr 'users' => ['topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'], 33*483101d3SAndreas Gohr 'links' => ['referer', 'newreferer', 'outlinks'], 34*483101d3SAndreas Gohr 'search' => ['searchengines', 'searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords'], 35*483101d3SAndreas Gohr 'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport'] 36*483101d3SAndreas Gohr ]; 371878f16fSAndreas Gohr 3881ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 39a8acb244SAndreas Gohr protected $allowedpages = []; 4081ff4c3aSAndreas Gohr 411878f16fSAndreas Gohr /** 426b6f8822SAndreas Gohr * Initialize the helper 436b6f8822SAndreas Gohr */ 44a8acb244SAndreas Gohr public function __construct() 45a8acb244SAndreas Gohr { 466b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 4781ff4c3aSAndreas Gohr 4881ff4c3aSAndreas Gohr // build a list of pages 4981ff4c3aSAndreas Gohr foreach ($this->pages as $key => $val) { 5081ff4c3aSAndreas Gohr if (is_array($val)) { 5181ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 5281ff4c3aSAndreas Gohr } else { 5381ff4c3aSAndreas Gohr $this->allowedpages[] = $key; 5481ff4c3aSAndreas Gohr } 5581ff4c3aSAndreas Gohr } 566b6f8822SAndreas Gohr } 576b6f8822SAndreas Gohr 586b6f8822SAndreas Gohr /** 591878f16fSAndreas Gohr * Access for managers allowed 601878f16fSAndreas Gohr */ 61a8acb244SAndreas Gohr public function forAdminOnly() 62a8acb244SAndreas Gohr { 631878f16fSAndreas Gohr return false; 641878f16fSAndreas Gohr } 651878f16fSAndreas Gohr 661878f16fSAndreas Gohr /** 671878f16fSAndreas Gohr * return sort order for position in admin menu 681878f16fSAndreas Gohr */ 69a8acb244SAndreas Gohr public function getMenuSort() 70a8acb244SAndreas Gohr { 716b6f8822SAndreas Gohr return 350; 721878f16fSAndreas Gohr } 731878f16fSAndreas Gohr 741878f16fSAndreas Gohr /** 751878f16fSAndreas Gohr * handle user request 761878f16fSAndreas Gohr */ 77a8acb244SAndreas Gohr public function handle() 78a8acb244SAndreas Gohr { 79*483101d3SAndreas Gohr global $INPUT; 80*483101d3SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); 8181ff4c3aSAndreas Gohr if (!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard'; 82a901d721SAndreas Gohr 83*483101d3SAndreas Gohr $this->start = $INPUT->int('s'); 84*483101d3SAndreas Gohr $this->setTimeframe($INPUT->str('f', date('Y-m-d')), $INPUT->str('t', date('Y-m-d'))); 85e8699bceSAndreas Gohr } 8695eb68e6SAndreas Gohr 87e8699bceSAndreas Gohr /** 88e8699bceSAndreas Gohr * set limit clause 89e8699bceSAndreas Gohr */ 90a8acb244SAndreas Gohr public function setTimeframe($from, $to) 91a8acb244SAndreas Gohr { 92047fcb0fSAndreas Gohr // swap if wrong order 93a8acb244SAndreas Gohr if ($from > $to) [$from, $to] = [$to, $from]; 94047fcb0fSAndreas Gohr 957428e816SAndreas Gohr $this->hlp->Query()->setTimeFrame($from, $to); 96e8699bceSAndreas Gohr $this->from = $from; 97e8699bceSAndreas Gohr $this->to = $to; 981878f16fSAndreas Gohr } 991878f16fSAndreas Gohr 1001878f16fSAndreas Gohr /** 10179b4a855SAndreas Gohr * Output the Statistics 1021878f16fSAndreas Gohr */ 103a8acb244SAndreas Gohr public function html() 104a8acb244SAndreas Gohr { 1051d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1060c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 107264f1744SAndreas Gohr $this->html_timeselect(); 108441bfb8eSAndreas Gohr tpl_flush(); 109264f1744SAndreas Gohr 11079b4a855SAndreas Gohr $method = 'html_' . $this->opt; 11179b4a855SAndreas Gohr if (method_exists($this, $method)) { 112a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 113a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 11479b4a855SAndreas Gohr $this->$method(); 115a901d721SAndreas Gohr echo '</div>'; 11614d99ec0SAndreas Gohr } 1171d2d78ccSAndreas Gohr echo '</div>'; 11814d99ec0SAndreas Gohr } 11914d99ec0SAndreas Gohr 1206b6f8822SAndreas Gohr /** 1216b6f8822SAndreas Gohr * Return the TOC 1226b6f8822SAndreas Gohr * 1236b6f8822SAndreas Gohr * @return array 1246b6f8822SAndreas Gohr */ 125a8acb244SAndreas Gohr public function getTOC() 126a8acb244SAndreas Gohr { 127a8acb244SAndreas Gohr $toc = []; 12881ff4c3aSAndreas Gohr foreach ($this->pages as $key => $info) { 12981ff4c3aSAndreas Gohr if (is_array($info)) { 13081ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 13181ff4c3aSAndreas Gohr '', 13281ff4c3aSAndreas Gohr $this->getLang($key), 13381ff4c3aSAndreas Gohr 1, 13481ff4c3aSAndreas Gohr '' 13547ffcf7dSAndreas Gohr ); 13681ff4c3aSAndreas Gohr 13781ff4c3aSAndreas Gohr foreach ($info as $page) { 13881ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 13981ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 14081ff4c3aSAndreas Gohr $this->getLang($page), 14181ff4c3aSAndreas Gohr 2, 14281ff4c3aSAndreas Gohr '' 14381ff4c3aSAndreas Gohr ); 14481ff4c3aSAndreas Gohr } 14581ff4c3aSAndreas Gohr } else { 14681ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 14781ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . '&f=' . $this->from . '&t=' . $this->to, 14881ff4c3aSAndreas Gohr $this->getLang($key), 14981ff4c3aSAndreas Gohr 1, 15081ff4c3aSAndreas Gohr '' 15181ff4c3aSAndreas Gohr ); 15281ff4c3aSAndreas Gohr } 15347ffcf7dSAndreas Gohr } 15447ffcf7dSAndreas Gohr return $toc; 1559da6395dSAndreas Gohr } 1569da6395dSAndreas Gohr 157a8acb244SAndreas Gohr public function html_graph($name, $width, $height) 158a8acb244SAndreas Gohr { 159dc7b1e5eSAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name . 160dc7b1e5eSAndreas Gohr '&f=' . $this->from . '&t=' . $this->to; 161dc7b1e5eSAndreas Gohr echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>'; 162dc7b1e5eSAndreas Gohr } 163dc7b1e5eSAndreas Gohr 1646b6f8822SAndreas Gohr /** 1656b6f8822SAndreas Gohr * Outputs pagination links 1666b6f8822SAndreas Gohr * 16733a136e5SAndreas Gohr * @param int $limit 16833a136e5SAndreas Gohr * @param int $next 1696b6f8822SAndreas Gohr */ 170a8acb244SAndreas Gohr public function html_pager($limit, $next) 171a8acb244SAndreas Gohr { 1722507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 1732507f8e0SAndreas Gohr 1742507f8e0SAndreas Gohr if ($this->start > 0) { 1752507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 176d43cd6e0SAndreas 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>'; 1772507f8e0SAndreas Gohr } 1782507f8e0SAndreas Gohr 1792507f8e0SAndreas Gohr if ($next) { 1802507f8e0SAndreas Gohr $go = $this->start + $limit; 181d43cd6e0SAndreas 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>'; 1822507f8e0SAndreas Gohr } 1832507f8e0SAndreas Gohr echo '</div>'; 1842507f8e0SAndreas Gohr } 1852507f8e0SAndreas Gohr 186264f1744SAndreas Gohr /** 187264f1744SAndreas Gohr * Print the time selection menu 188264f1744SAndreas Gohr */ 189a8acb244SAndreas Gohr public function html_timeselect() 190a8acb244SAndreas Gohr { 191*483101d3SAndreas Gohr $quick = [ 192*483101d3SAndreas Gohr 'today' => date('Y-m-d'), 193*483101d3SAndreas Gohr 'last1' => date('Y-m-d', time() - (60 * 60 * 24)), 194*483101d3SAndreas Gohr 'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)), 195*483101d3SAndreas Gohr 'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)), 196*483101d3SAndreas Gohr ]; 197*483101d3SAndreas Gohr 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 . '" />'; 206*483101d3SAndreas Gohr echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />'; 207*483101d3SAndreas Gohr echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />'; 208264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 20914d99ec0SAndreas Gohr echo '</form>'; 210264f1744SAndreas Gohr 2116985b606SAndreas Gohr echo '<ul>'; 212*483101d3SAndreas Gohr foreach ($quick as $name => $time) { 2136985b606SAndreas Gohr echo '<li>'; 214*483101d3SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $time . '&t=' . $quick['today'] . '">'; 215*483101d3SAndreas Gohr echo $this->getLang('time_' . $name); 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 */ 227a8acb244SAndreas Gohr public function html_dashboard() 228a8acb244SAndreas Gohr { 229878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2302812a751SAndreas Gohr 2312812a751SAndreas Gohr // general info 2322812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 2337428e816SAndreas Gohr $result = $this->hlp->Query()->aggregate(); 2341d2d78ccSAndreas Gohr 2351d2d78ccSAndreas Gohr echo '<ul class="left">'; 236a8acb244SAndreas 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">'; 242a8acb244SAndreas 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>'; 2567428e816SAndreas Gohr $result = $this->hlp->Query()->pages($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>'; 2647428e816SAndreas Gohr $result = $this->hlp->Query()->newreferer($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>'; 2727428e816SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $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 278a8acb244SAndreas Gohr public function html_history() 279a8acb244SAndreas 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 287a8acb244SAndreas Gohr public function html_countries() 288a8acb244SAndreas Gohr { 289878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 290878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 2917428e816SAndreas Gohr $result = $this->hlp->Query()->countries($this->start, 150); 2922507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2939da6395dSAndreas Gohr } 2949da6395dSAndreas Gohr 295a8acb244SAndreas Gohr public function html_page() 296a8acb244SAndreas Gohr { 297878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 2987428e816SAndreas Gohr $result = $this->hlp->Query()->pages($this->start, 150); 2992507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3009da6395dSAndreas Gohr } 3019da6395dSAndreas Gohr 302a8acb244SAndreas Gohr public function html_edits() 303a8acb244SAndreas Gohr { 3041664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 3057428e816SAndreas Gohr $result = $this->hlp->Query()->edits($this->start, 150); 3061664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3071664ba1dSAndreas Gohr } 3081664ba1dSAndreas Gohr 309a8acb244SAndreas Gohr public function html_images() 310a8acb244SAndreas Gohr { 3111664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 312616c1e8bSAndreas Gohr 3137428e816SAndreas Gohr $result = $this->hlp->Query()->imagessum(); 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 3187428e816SAndreas Gohr $result = $this->hlp->Query()->images($this->start, 150); 3191664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3201664ba1dSAndreas Gohr } 3211664ba1dSAndreas Gohr 322a8acb244SAndreas Gohr public function html_downloads() 323a8acb244SAndreas Gohr { 3241664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 325616c1e8bSAndreas Gohr 3267428e816SAndreas Gohr $result = $this->hlp->Query()->downloadssum(); 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 3317428e816SAndreas Gohr $result = $this->hlp->Query()->downloads($this->start, 150); 3321664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3331664ba1dSAndreas Gohr } 3341664ba1dSAndreas Gohr 335a8acb244SAndreas Gohr public function html_browsers() 336a8acb244SAndreas Gohr { 337878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 338878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 3397428e816SAndreas Gohr $result = $this->hlp->Query()->browsers($this->start, 150, true); 3402507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 34175fa767dSAndreas Gohr } 34275fa767dSAndreas Gohr 343a8acb244SAndreas Gohr public function html_topuser() 344a8acb244SAndreas Gohr { 34581ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 34681ff4c3aSAndreas Gohr $this->html_graph('topuser', 400, 200); 3477428e816SAndreas Gohr $result = $this->hlp->Query()->topuser($this->start, 150); 34881ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 34981ff4c3aSAndreas Gohr } 35081ff4c3aSAndreas Gohr 351a8acb244SAndreas Gohr public function html_topeditor() 352a8acb244SAndreas Gohr { 35381ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 35481ff4c3aSAndreas Gohr $this->html_graph('topeditor', 400, 200); 3557428e816SAndreas Gohr $result = $this->hlp->Query()->topeditor($this->start, 150); 35681ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 35781ff4c3aSAndreas Gohr } 35881ff4c3aSAndreas Gohr 359a8acb244SAndreas Gohr public function html_topgroup() 360a8acb244SAndreas Gohr { 36181ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 36281ff4c3aSAndreas Gohr $this->html_graph('topgroup', 400, 200); 3637428e816SAndreas Gohr $result = $this->hlp->Query()->topgroup($this->start, 150); 36481ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 36581ff4c3aSAndreas Gohr } 36681ff4c3aSAndreas Gohr 367a8acb244SAndreas Gohr public function html_topgroupedit() 368a8acb244SAndreas Gohr { 36981ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 37081ff4c3aSAndreas Gohr $this->html_graph('topgroupedit', 400, 200); 3717428e816SAndreas Gohr $result = $this->hlp->Query()->topgroupedit($this->start, 150); 37281ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37381ff4c3aSAndreas Gohr } 37481ff4c3aSAndreas Gohr 375a8acb244SAndreas Gohr public function html_os() 376a8acb244SAndreas Gohr { 377878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 378878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 3797428e816SAndreas Gohr $result = $this->hlp->Query()->os($this->start, 150); 3802507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 381bd4217d3SAndreas Gohr } 382bd4217d3SAndreas Gohr 383a8acb244SAndreas Gohr public function html_referer() 384a8acb244SAndreas Gohr { 3857428e816SAndreas Gohr $result = $this->hlp->Query()->aggregate(); 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>', 392a8acb244SAndreas Gohr $all, 393a8acb244SAndreas Gohr $result['direct'], 394a8acb244SAndreas Gohr (100 * $result['direct'] / $all), 395a8acb244SAndreas Gohr $result['search'], 396a8acb244SAndreas Gohr (100 * $result['search'] / $all), 397a8acb244SAndreas Gohr $result['external'], 3980863c19cSAndreas Gohr (100 * $result['external'] / $all) 3990863c19cSAndreas Gohr ); 40094023548SAndreas Gohr } 4012812a751SAndreas Gohr 4027428e816SAndreas Gohr $result = $this->hlp->Query()->referer($this->start, 150); 4032507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4049da6395dSAndreas Gohr } 4059da6395dSAndreas Gohr 406a8acb244SAndreas Gohr public function html_newreferer() 407a8acb244SAndreas Gohr { 408878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 409e7a2f1e0SAndreas Gohr 4107428e816SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->start, 150); 4112507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 412e7a2f1e0SAndreas Gohr } 413e7a2f1e0SAndreas Gohr 414a8acb244SAndreas Gohr public function html_outlinks() 415a8acb244SAndreas Gohr { 416878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 4177428e816SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->start, 150); 418e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 419e25286daSAndreas Gohr } 420e25286daSAndreas Gohr 421a8acb244SAndreas Gohr public function html_searchphrases() 422a8acb244SAndreas Gohr { 423878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 4247428e816SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->start, 150); 42512dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 42612dcdeccSAndreas Gohr } 42712dcdeccSAndreas Gohr 428a8acb244SAndreas Gohr public function html_searchwords() 429a8acb244SAndreas Gohr { 430878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 4317428e816SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->start, 150); 4325bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4335bccfe87SAndreas Gohr } 4345bccfe87SAndreas Gohr 435a8acb244SAndreas Gohr public function html_internalsearchphrases() 436a8acb244SAndreas Gohr { 437878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 4387428e816SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->start, 150); 4395bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4405bccfe87SAndreas Gohr } 4415bccfe87SAndreas Gohr 442a8acb244SAndreas Gohr public function html_internalsearchwords() 443a8acb244SAndreas Gohr { 444878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 4457428e816SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->start, 150); 44612dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 44712dcdeccSAndreas Gohr } 44812dcdeccSAndreas Gohr 449a8acb244SAndreas Gohr public function html_searchengines() 450a8acb244SAndreas Gohr { 451878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 45225b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 4537428e816SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->start, 150); 45412dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 45512dcdeccSAndreas Gohr } 45612dcdeccSAndreas Gohr 457a8acb244SAndreas Gohr public function html_resolution() 458a8acb244SAndreas Gohr { 45925446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 46025446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 4617428e816SAndreas Gohr $result = $this->hlp->Query()->resolution($this->start, 150); 462307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 46325446aa2SAndreas Gohr } 464307baf3fSAndreas Gohr 465a8acb244SAndreas Gohr public function html_viewport() 466a8acb244SAndreas Gohr { 46725446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 46825446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 4697428e816SAndreas Gohr $result = $this->hlp->Query()->viewport($this->start, 150); 47025446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 471c73e16f1SAndreas Gohr } 4729da6395dSAndreas Gohr 473a8acb244SAndreas Gohr public function html_seenusers() 474a8acb244SAndreas Gohr { 47533a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 4767428e816SAndreas Gohr $result = $this->hlp->Query()->seenusers($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 */ 483a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 484a8acb244SAndreas 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') { 522a8acb244SAndreas 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') { 536a8acb244SAndreas 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 567a8acb244SAndreas Gohr public function html_icon($type, $value) 568a8acb244SAndreas Gohr { 56913a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5709bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 571a8acb244SAndreas 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