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 */ 29483101d3SAndreas Gohr protected $pages = [ 30483101d3SAndreas Gohr 'dashboard' => 1, 31483101d3SAndreas Gohr 'content' => ['page', 'edits', 'images', 'downloads', 'history'], 32483101d3SAndreas Gohr 'users' => ['topuser', 'topeditor', 'topgroup', 'topgroupedit', 'seenusers'], 33483101d3SAndreas Gohr 'links' => ['referer', 'newreferer', 'outlinks'], 34483101d3SAndreas Gohr 'search' => ['searchengines', 'searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords'], 35483101d3SAndreas Gohr 'technology' => ['browsers', 'os', 'countries', 'resolution', 'viewport'] 36483101d3SAndreas 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 { 79483101d3SAndreas Gohr global $INPUT; 80483101d3SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $INPUT->str('opt')); 8181ff4c3aSAndreas Gohr if (!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard'; 82a901d721SAndreas Gohr 83483101d3SAndreas Gohr $this->start = $INPUT->int('s'); 84483101d3SAndreas 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 { 159f0a4cceeSAnna Dabrowska $this->hlp->Graph($this->from, $this->to, $width, $height)->$name(); 160dc7b1e5eSAndreas Gohr } 161dc7b1e5eSAndreas Gohr 1626b6f8822SAndreas Gohr /** 1636b6f8822SAndreas Gohr * Outputs pagination links 1646b6f8822SAndreas Gohr * 16533a136e5SAndreas Gohr * @param int $limit 16633a136e5SAndreas Gohr * @param int $next 1676b6f8822SAndreas Gohr */ 168a8acb244SAndreas Gohr public function html_pager($limit, $next) 169a8acb244SAndreas Gohr { 1702507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 1712507f8e0SAndreas Gohr 1722507f8e0SAndreas Gohr if ($this->start > 0) { 1732507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 174d43cd6e0SAndreas 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>'; 1752507f8e0SAndreas Gohr } 1762507f8e0SAndreas Gohr 1772507f8e0SAndreas Gohr if ($next) { 1782507f8e0SAndreas Gohr $go = $this->start + $limit; 179d43cd6e0SAndreas 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>'; 1802507f8e0SAndreas Gohr } 1812507f8e0SAndreas Gohr echo '</div>'; 1822507f8e0SAndreas Gohr } 1832507f8e0SAndreas Gohr 184264f1744SAndreas Gohr /** 185264f1744SAndreas Gohr * Print the time selection menu 186264f1744SAndreas Gohr */ 187a8acb244SAndreas Gohr public function html_timeselect() 188a8acb244SAndreas Gohr { 189483101d3SAndreas Gohr $quick = [ 190483101d3SAndreas Gohr 'today' => date('Y-m-d'), 191483101d3SAndreas Gohr 'last1' => date('Y-m-d', time() - (60 * 60 * 24)), 192483101d3SAndreas Gohr 'last7' => date('Y-m-d', time() - (60 * 60 * 24 * 7)), 193483101d3SAndreas Gohr 'last30' => date('Y-m-d', time() - (60 * 60 * 24 * 30)), 194483101d3SAndreas Gohr ]; 195483101d3SAndreas Gohr 19614d99ec0SAndreas Gohr 197264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 1986985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 199264f1744SAndreas Gohr 200047fcb0fSAndreas Gohr echo '<form action="' . DOKU_SCRIPT . '" method="get">'; 201264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 202264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 203264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 204483101d3SAndreas Gohr echo '<input type="date" name="f" value="' . $this->from . '" class="edit" />'; 205483101d3SAndreas Gohr echo '<input type="date" name="t" value="' . $this->to . '" class="edit" />'; 206264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 20714d99ec0SAndreas Gohr echo '</form>'; 208264f1744SAndreas Gohr 2096985b606SAndreas Gohr echo '<ul>'; 210483101d3SAndreas Gohr foreach ($quick as $name => $time) { 2116985b606SAndreas Gohr echo '<li>'; 212483101d3SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $time . '&t=' . $quick['today'] . '">'; 213483101d3SAndreas Gohr echo $this->getLang('time_' . $name); 2146985b606SAndreas Gohr echo '</a>'; 2156985b606SAndreas Gohr echo '</li>'; 2166985b606SAndreas Gohr } 2176985b606SAndreas Gohr echo '</ul>'; 2186985b606SAndreas Gohr 219264f1744SAndreas Gohr echo '</div>'; 22014d99ec0SAndreas Gohr } 22114d99ec0SAndreas Gohr 222f5f32cbfSAndreas Gohr /** 223f5f32cbfSAndreas Gohr * Print an introductionary screen 224f5f32cbfSAndreas Gohr */ 225a8acb244SAndreas Gohr public function html_dashboard() 226a8acb244SAndreas Gohr { 227878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2282812a751SAndreas Gohr 2292812a751SAndreas Gohr // general info 2302812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 2317428e816SAndreas Gohr $result = $this->hlp->Query()->aggregate(); 2321d2d78ccSAndreas Gohr 2331d2d78ccSAndreas Gohr echo '<ul class="left">'; 234a8acb244SAndreas Gohr foreach (['pageviews', 'sessions', 'visitors', 'users', 'logins', 'current'] as $name) { 235eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 236eabe0d07SAndreas Gohr } 2372812a751SAndreas Gohr echo '</ul>'; 2381d2d78ccSAndreas Gohr 2391d2d78ccSAndreas Gohr echo '<ul class="left">'; 240a8acb244SAndreas Gohr foreach (['bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations'] as $name) { 2411d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2421d2d78ccSAndreas Gohr } 2431d2d78ccSAndreas Gohr echo '</ul>'; 2441d2d78ccSAndreas Gohr 24556f647ddSAndreas Gohr echo '<br style="clear: left" />'; 24656f647ddSAndreas Gohr 247259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 248259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2492812a751SAndreas Gohr echo '</div>'; 2502812a751SAndreas Gohr 25187d5e44bSAndreas Gohr // top pages today 252264f1744SAndreas Gohr echo '<div>'; 253dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2547428e816SAndreas Gohr $result = $this->hlp->Query()->pages($this->start, 15); 2552812a751SAndreas Gohr $this->html_resulttable($result); 256d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 257264f1744SAndreas Gohr echo '</div>'; 25887d5e44bSAndreas Gohr 25987d5e44bSAndreas Gohr // top referer today 260264f1744SAndreas Gohr echo '<div>'; 261dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2627428e816SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->start, 15); 2632812a751SAndreas Gohr $this->html_resulttable($result); 264d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 265264f1744SAndreas Gohr echo '</div>'; 26654f6c432SAndreas Gohr 26729dea504SAndreas Gohr // top searches today 268264f1744SAndreas Gohr echo '<div>'; 269dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 2707428e816SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->start, 15); 27129dea504SAndreas Gohr $this->html_resulttable($result); 272d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 273264f1744SAndreas Gohr echo '</div>'; 27414d99ec0SAndreas Gohr } 27514d99ec0SAndreas Gohr 276a8acb244SAndreas Gohr public function html_history() 277a8acb244SAndreas Gohr { 278cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 279338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 280338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 281338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 282338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 283cae4a1c5SAndreas Gohr } 284cae4a1c5SAndreas Gohr 285a8acb244SAndreas Gohr public function html_countries() 286a8acb244SAndreas Gohr { 287878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 288*1d379254SAnna Dabrowska $this->html_graph('countries', 300, 300); 289f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->countries(); 2902507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2919da6395dSAndreas Gohr } 2929da6395dSAndreas Gohr 293a8acb244SAndreas Gohr public function html_page() 294a8acb244SAndreas Gohr { 295878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 296f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->pages(); 2972507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2989da6395dSAndreas Gohr } 2999da6395dSAndreas Gohr 300a8acb244SAndreas Gohr public function html_edits() 301a8acb244SAndreas Gohr { 3021664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 303f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->edits(); 3041664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3051664ba1dSAndreas Gohr } 3061664ba1dSAndreas Gohr 307a8acb244SAndreas Gohr public function html_images() 308a8acb244SAndreas Gohr { 3091664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 310616c1e8bSAndreas Gohr 3117428e816SAndreas Gohr $result = $this->hlp->Query()->imagessum(); 312616c1e8bSAndreas Gohr echo '<p>'; 313616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 314616c1e8bSAndreas Gohr echo '</p>'; 315616c1e8bSAndreas Gohr 316f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->images(); 3171664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3181664ba1dSAndreas Gohr } 3191664ba1dSAndreas Gohr 320a8acb244SAndreas Gohr public function html_downloads() 321a8acb244SAndreas Gohr { 3221664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 323616c1e8bSAndreas Gohr 3247428e816SAndreas Gohr $result = $this->hlp->Query()->downloadssum(); 325616c1e8bSAndreas Gohr echo '<p>'; 326616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 327616c1e8bSAndreas Gohr echo '</p>'; 328616c1e8bSAndreas Gohr 329f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->downloads(); 3301664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3311664ba1dSAndreas Gohr } 3321664ba1dSAndreas Gohr 333a8acb244SAndreas Gohr public function html_browsers() 334a8acb244SAndreas Gohr { 335878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 336*1d379254SAnna Dabrowska $this->html_graph('browsers', 300, 300); 337f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->browsers(false); 3382507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 33975fa767dSAndreas Gohr } 34075fa767dSAndreas Gohr 341a8acb244SAndreas Gohr public function html_topuser() 342a8acb244SAndreas Gohr { 34381ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 344*1d379254SAnna Dabrowska $this->html_graph('topuser', 300, 300); 345f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->topuser(); 34681ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 34781ff4c3aSAndreas Gohr } 34881ff4c3aSAndreas Gohr 349a8acb244SAndreas Gohr public function html_topeditor() 350a8acb244SAndreas Gohr { 35181ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 352*1d379254SAnna Dabrowska $this->html_graph('topeditor', 300, 300); 353f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->topeditor(); 35481ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 35581ff4c3aSAndreas Gohr } 35681ff4c3aSAndreas Gohr 357a8acb244SAndreas Gohr public function html_topgroup() 358a8acb244SAndreas Gohr { 35981ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 360*1d379254SAnna Dabrowska $this->html_graph('topgroup', 300, 300); 361f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->topgroup(); 36281ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 36381ff4c3aSAndreas Gohr } 36481ff4c3aSAndreas Gohr 365a8acb244SAndreas Gohr public function html_topgroupedit() 366a8acb244SAndreas Gohr { 36781ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 368*1d379254SAnna Dabrowska $this->html_graph('topgroupedit', 300, 300); 369f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->topgroupedit(); 37081ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37181ff4c3aSAndreas Gohr } 37281ff4c3aSAndreas Gohr 373a8acb244SAndreas Gohr public function html_os() 374a8acb244SAndreas Gohr { 375878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 376*1d379254SAnna Dabrowska $this->html_graph('os', 300, 300); 377f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->os(); 3782507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 379bd4217d3SAndreas Gohr } 380bd4217d3SAndreas Gohr 381a8acb244SAndreas Gohr public function html_referer() 382a8acb244SAndreas Gohr { 3837428e816SAndreas Gohr $result = $this->hlp->Query()->aggregate(); 3842812a751SAndreas Gohr 3852812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 3862812a751SAndreas Gohr 38794023548SAndreas Gohr if ($all) { 3880863c19cSAndreas Gohr printf( 3890863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 390a8acb244SAndreas Gohr $all, 391a8acb244SAndreas Gohr $result['direct'], 392a8acb244SAndreas Gohr (100 * $result['direct'] / $all), 393a8acb244SAndreas Gohr $result['search'], 394a8acb244SAndreas Gohr (100 * $result['search'] / $all), 395a8acb244SAndreas Gohr $result['external'], 3960863c19cSAndreas Gohr (100 * $result['external'] / $all) 3970863c19cSAndreas Gohr ); 39894023548SAndreas Gohr } 3992812a751SAndreas Gohr 400f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->referer(); 4012507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4029da6395dSAndreas Gohr } 4039da6395dSAndreas Gohr 404a8acb244SAndreas Gohr public function html_newreferer() 405a8acb244SAndreas Gohr { 406878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 407e7a2f1e0SAndreas Gohr 408f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->newreferer(); 4092507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 410e7a2f1e0SAndreas Gohr } 411e7a2f1e0SAndreas Gohr 412a8acb244SAndreas Gohr public function html_outlinks() 413a8acb244SAndreas Gohr { 414878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 415f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->outlinks(); 416e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 417e25286daSAndreas Gohr } 418e25286daSAndreas Gohr 419a8acb244SAndreas Gohr public function html_searchphrases() 420a8acb244SAndreas Gohr { 421878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 422f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->searchphrases(true); 42312dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 42412dcdeccSAndreas Gohr } 42512dcdeccSAndreas Gohr 426a8acb244SAndreas Gohr public function html_searchwords() 427a8acb244SAndreas Gohr { 428878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 429f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->searchwords(true); 4305bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4315bccfe87SAndreas Gohr } 4325bccfe87SAndreas Gohr 433a8acb244SAndreas Gohr public function html_internalsearchphrases() 434a8acb244SAndreas Gohr { 435878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 436f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->searchphrases(false); 4375bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4385bccfe87SAndreas Gohr } 4395bccfe87SAndreas Gohr 440a8acb244SAndreas Gohr public function html_internalsearchwords() 441a8acb244SAndreas Gohr { 442878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 443f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->searchwords(false); 44412dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 44512dcdeccSAndreas Gohr } 44612dcdeccSAndreas Gohr 447a8acb244SAndreas Gohr public function html_searchengines() 448a8acb244SAndreas Gohr { 449878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 45025b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 451f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->searchengines(); 45212dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 45312dcdeccSAndreas Gohr } 45412dcdeccSAndreas Gohr 455a8acb244SAndreas Gohr public function html_resolution() 456a8acb244SAndreas Gohr { 45725446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 45825446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 459f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->resolution(); 460307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 46125446aa2SAndreas Gohr } 462307baf3fSAndreas Gohr 463a8acb244SAndreas Gohr public function html_viewport() 464a8acb244SAndreas Gohr { 46525446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 46625446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 467f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->viewport(); 46825446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 469c73e16f1SAndreas Gohr } 4709da6395dSAndreas Gohr 471a8acb244SAndreas Gohr public function html_seenusers() 472a8acb244SAndreas Gohr { 47333a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 474f0a4cceeSAnna Dabrowska $result = $this->hlp->Query()->seenusers(); 47533a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 47633a136e5SAndreas Gohr } 47733a136e5SAndreas Gohr 47814d99ec0SAndreas Gohr /** 47914d99ec0SAndreas Gohr * Display a result in a HTML table 48014d99ec0SAndreas Gohr */ 481a8acb244SAndreas Gohr public function html_resulttable($result, $header = '', $pager = 0) 482a8acb244SAndreas Gohr { 48356f647ddSAndreas Gohr echo '<table class="inline">'; 4842812a751SAndreas Gohr if (is_array($header)) { 48514d99ec0SAndreas Gohr echo '<tr>'; 48614d99ec0SAndreas Gohr foreach ($header as $h) { 48714d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 48814d99ec0SAndreas Gohr } 48914d99ec0SAndreas Gohr echo '</tr>'; 4902812a751SAndreas Gohr } 49114d99ec0SAndreas Gohr 4922507f8e0SAndreas Gohr $count = 0; 4932ee939eeSAndreas Gohr if (is_array($result)) foreach ($result as $row) { 49414d99ec0SAndreas Gohr echo '<tr>'; 49514d99ec0SAndreas Gohr foreach ($row as $k => $v) { 496f3818071SAndreas Gohr if ($k == 'res_x') continue; 497f3818071SAndreas Gohr if ($k == 'res_y') continue; 498f3818071SAndreas Gohr 4992812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 50014d99ec0SAndreas Gohr if ($k == 'page') { 50114d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 50214d99ec0SAndreas Gohr echo hsc($v); 50314d99ec0SAndreas Gohr echo '</a>'; 5041664ba1dSAndreas Gohr } elseif ($k == 'media') { 5051664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 5061664ba1dSAndreas Gohr echo hsc($v); 5071664ba1dSAndreas Gohr echo '</a>'; 5081664ba1dSAndreas Gohr } elseif ($k == 'filesize') { 5091664ba1dSAndreas Gohr echo filesize_h($v); 51014d99ec0SAndreas Gohr } elseif ($k == 'url') { 51154f6c432SAndreas Gohr $url = hsc($v); 51283b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 5132812a751SAndreas Gohr if (strlen($url) > 45) { 5142812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 51554f6c432SAndreas Gohr } 51614d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 51754f6c432SAndreas Gohr echo $url; 51814d99ec0SAndreas Gohr echo '</a>'; 5195bccfe87SAndreas Gohr } elseif ($k == 'ilookup') { 520a8acb244SAndreas Gohr echo '<a href="' . wl('', ['id' => $v, 'do' => 'search']) . '">Search</a>'; 52129dea504SAndreas Gohr } elseif ($k == 'lookup') { 52229dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 52313a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 52429dea504SAndreas Gohr echo '</a> '; 52529dea504SAndreas Gohr 52629dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 52713a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 52829dea504SAndreas Gohr echo '</a> '; 52929dea504SAndreas Gohr 53013a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 53113a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 53229dea504SAndreas Gohr echo '</a> '; 53312dcdeccSAndreas Gohr } elseif ($k == 'engine') { 534a8acb244SAndreas Gohr include_once(__DIR__ . '/inc/searchengines.php'); 53513a86c14SAndreas Gohr if (isset($SEARCHENGINEINFO[$v])) { 53613a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 53713a86c14SAndreas Gohr } else { 53813a86c14SAndreas Gohr echo hsc(ucwords($v)); 53913a86c14SAndreas Gohr } 54013a86c14SAndreas Gohr } elseif ($k == 'eflag') { 54113a86c14SAndreas Gohr $this->html_icon('search', $v); 54275fa767dSAndreas Gohr } elseif ($k == 'bflag') { 54313a86c14SAndreas Gohr $this->html_icon('browser', $v); 544bd4217d3SAndreas Gohr } elseif ($k == 'osflag') { 54513a86c14SAndreas Gohr $this->html_icon('os', $v); 54675fa767dSAndreas Gohr } elseif ($k == 'cflag') { 54713a86c14SAndreas Gohr $this->html_icon('flags', $v); 54814d99ec0SAndreas Gohr } elseif ($k == 'html') { 54914d99ec0SAndreas Gohr echo $v; 55014d99ec0SAndreas Gohr } else { 55114d99ec0SAndreas Gohr echo hsc($v); 55214d99ec0SAndreas Gohr } 55314d99ec0SAndreas Gohr echo '</td>'; 55414d99ec0SAndreas Gohr } 55514d99ec0SAndreas Gohr echo '</tr>'; 5562507f8e0SAndreas Gohr 5572507f8e0SAndreas Gohr if ($pager && ($count == $pager)) break; 5582507f8e0SAndreas Gohr $count++; 55914d99ec0SAndreas Gohr } 56014d99ec0SAndreas Gohr echo '</table>'; 5612507f8e0SAndreas Gohr 5622507f8e0SAndreas Gohr if ($pager) $this->html_pager($pager, count($result) > $pager); 5631878f16fSAndreas Gohr } 5641878f16fSAndreas Gohr 565a8acb244SAndreas Gohr public function html_icon($type, $value) 566a8acb244SAndreas Gohr { 56713a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5689bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 569a8acb244SAndreas Gohr 57013a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 571dffb869bSAndreas Gohr if ($type == 'flags') { 572dffb869bSAndreas Gohr $w = 18; 573dffb869bSAndreas Gohr $h = 12; 574dffb869bSAndreas Gohr } else { 575dffb869bSAndreas Gohr $w = 16; 576dffb869bSAndreas Gohr $h = 16; 577dffb869bSAndreas Gohr } 57813a86c14SAndreas Gohr if (file_exists(DOKU_INC . $file)) { 579dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 58013a86c14SAndreas Gohr } 58113a86c14SAndreas Gohr } 5821878f16fSAndreas Gohr} 583