11878f16fSAndreas Gohr<?php 21878f16fSAndreas Gohr/** 31878f16fSAndreas Gohr * statistics plugin 41878f16fSAndreas Gohr * 51878f16fSAndreas Gohr * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 66b6f8822SAndreas Gohr * @author Andreas Gohr <gohr@splitbrain.org> 71878f16fSAndreas Gohr */ 81878f16fSAndreas Gohr 91878f16fSAndreas Gohr// must be run within Dokuwiki 101878f16fSAndreas Gohrif(!defined('DOKU_INC')) die(); 111878f16fSAndreas Gohr 121878f16fSAndreas Gohr/** 131878f16fSAndreas Gohr * All DokuWiki plugins to extend the admin function 141878f16fSAndreas Gohr * need to inherit from this class 151878f16fSAndreas Gohr */ 161878f16fSAndreas Gohrclass admin_plugin_statistics extends DokuWiki_Admin_Plugin { 1733a136e5SAndreas Gohr /** @var string the currently selected page */ 18a901d721SAndreas Gohr protected $opt = ''; 1933a136e5SAndreas Gohr 2033a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 21a901d721SAndreas Gohr protected $from = ''; 2233a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 23a901d721SAndreas Gohr protected $to = ''; 2433a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 2533a136e5SAndreas Gohr protected $start = 0; 2633a136e5SAndreas Gohr 2733a136e5SAndreas Gohr /** @var string MySQL timelimit statement */ 28a901d721SAndreas Gohr protected $tlimit = ''; 29a901d721SAndreas Gohr 3033a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 3133a136e5SAndreas Gohr protected $hlp; 3233a136e5SAndreas Gohr 33a901d721SAndreas Gohr /** 34a901d721SAndreas Gohr * Available statistic pages 35a901d721SAndreas Gohr */ 360863c19cSAndreas Gohr protected $pages = array( 371664ba1dSAndreas Gohr 'dashboard', 'page', 'edits', 'images', 'downloads', 38cae4a1c5SAndreas Gohr 'history', 'referer', 'newreferer', 395bccfe87SAndreas Gohr 'outlinks', 'searchengines', 'searchphrases', 405bccfe87SAndreas Gohr 'searchwords', 'internalsearchphrases', 415bccfe87SAndreas Gohr 'internalsearchwords', 'browsers', 'os', 4233a136e5SAndreas Gohr 'countries', 'resolution', 'viewport', 4333a136e5SAndreas Gohr 'seenusers' 440863c19cSAndreas Gohr ); 451878f16fSAndreas Gohr 461878f16fSAndreas Gohr /** 476b6f8822SAndreas Gohr * Initialize the helper 486b6f8822SAndreas Gohr */ 496b6f8822SAndreas Gohr public function __construct() { 506b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 516b6f8822SAndreas Gohr } 526b6f8822SAndreas Gohr 536b6f8822SAndreas Gohr /** 541878f16fSAndreas Gohr * Access for managers allowed 551878f16fSAndreas Gohr */ 566b6f8822SAndreas Gohr public function forAdminOnly() { 571878f16fSAndreas Gohr return false; 581878f16fSAndreas Gohr } 591878f16fSAndreas Gohr 601878f16fSAndreas Gohr /** 611878f16fSAndreas Gohr * return sort order for position in admin menu 621878f16fSAndreas Gohr */ 636b6f8822SAndreas Gohr public function getMenuSort() { 646b6f8822SAndreas Gohr return 350; 651878f16fSAndreas Gohr } 661878f16fSAndreas Gohr 671878f16fSAndreas Gohr /** 681878f16fSAndreas Gohr * handle user request 691878f16fSAndreas Gohr */ 706b6f8822SAndreas Gohr public function handle() { 71264f1744SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']); 72a901d721SAndreas Gohr if(!in_array($this->opt, $this->pages)) $this->opt = 'dashboard'; 73a901d721SAndreas Gohr 7495eb68e6SAndreas Gohr $this->start = (int) $_REQUEST['s']; 75e8699bceSAndreas Gohr $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']); 76e8699bceSAndreas Gohr } 7795eb68e6SAndreas Gohr 78e8699bceSAndreas Gohr /** 79e8699bceSAndreas Gohr * set limit clause 80e8699bceSAndreas Gohr */ 816b6f8822SAndreas Gohr public function setTimeframe($from, $to) { 823bf3de81SAndreas Gohr $this->tlimit = $this->hlp->Query()->mktlimit($from, $to); 83e8699bceSAndreas Gohr $this->from = $from; 84e8699bceSAndreas Gohr $this->to = $to; 851878f16fSAndreas Gohr } 861878f16fSAndreas Gohr 871878f16fSAndreas Gohr /** 8879b4a855SAndreas Gohr * Output the Statistics 891878f16fSAndreas Gohr */ 901878f16fSAndreas Gohr function html() { 911d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 920c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 93264f1744SAndreas Gohr $this->html_timeselect(); 94441bfb8eSAndreas Gohr tpl_flush(); 95264f1744SAndreas Gohr 9679b4a855SAndreas Gohr $method = 'html_' . $this->opt; 9779b4a855SAndreas Gohr if(method_exists($this, $method)) { 98a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 99a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 10079b4a855SAndreas Gohr $this->$method(); 101a901d721SAndreas Gohr echo '</div>'; 10214d99ec0SAndreas Gohr } 1031d2d78ccSAndreas Gohr echo '</div>'; 10414d99ec0SAndreas Gohr } 10514d99ec0SAndreas Gohr 1066b6f8822SAndreas Gohr /** 1076b6f8822SAndreas Gohr * Return the TOC 1086b6f8822SAndreas Gohr * 1096b6f8822SAndreas Gohr * @return array 1106b6f8822SAndreas Gohr */ 11147ffcf7dSAndreas Gohr function getTOC() { 11247ffcf7dSAndreas Gohr $toc = array(); 113a901d721SAndreas Gohr foreach($this->pages as $page) { 11447ffcf7dSAndreas Gohr $toc[] = array( 11547ffcf7dSAndreas Gohr 'link' => '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 11647ffcf7dSAndreas Gohr 'title' => $this->getLang($page), 11747ffcf7dSAndreas Gohr 'level' => 1, 11847ffcf7dSAndreas Gohr 'type' => 'ul' 11947ffcf7dSAndreas Gohr ); 12047ffcf7dSAndreas Gohr } 12147ffcf7dSAndreas Gohr return $toc; 1229da6395dSAndreas Gohr } 1239da6395dSAndreas Gohr 124dc7b1e5eSAndreas Gohr function html_graph($name, $width, $height) { 125dc7b1e5eSAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name . 126dc7b1e5eSAndreas Gohr '&f=' . $this->from . '&t=' . $this->to; 127dc7b1e5eSAndreas Gohr echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>'; 128dc7b1e5eSAndreas Gohr } 129dc7b1e5eSAndreas Gohr 1306b6f8822SAndreas Gohr /** 1316b6f8822SAndreas Gohr * Outputs pagination links 1326b6f8822SAndreas Gohr * 13333a136e5SAndreas Gohr * @param int $limit 13433a136e5SAndreas Gohr * @param int $next 1356b6f8822SAndreas Gohr */ 1362507f8e0SAndreas Gohr function html_pager($limit, $next) { 1372507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 1382507f8e0SAndreas Gohr 1392507f8e0SAndreas Gohr if($this->start > 0) { 1402507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 141d43cd6e0SAndreas 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>'; 1422507f8e0SAndreas Gohr } 1432507f8e0SAndreas Gohr 1442507f8e0SAndreas Gohr if($next) { 1452507f8e0SAndreas Gohr $go = $this->start + $limit; 146d43cd6e0SAndreas 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>'; 1472507f8e0SAndreas Gohr } 1482507f8e0SAndreas Gohr echo '</div>'; 1492507f8e0SAndreas Gohr } 1502507f8e0SAndreas Gohr 151264f1744SAndreas Gohr /** 152264f1744SAndreas Gohr * Print the time selection menu 153264f1744SAndreas Gohr */ 15414d99ec0SAndreas Gohr function html_timeselect() { 1556985b606SAndreas Gohr $today = date('Y-m-d'); 1566985b606SAndreas Gohr $last1 = date('Y-m-d', time() - (60 * 60 * 24)); 1576985b606SAndreas Gohr $last7 = date('Y-m-d', time() - (60 * 60 * 24 * 7)); 1586985b606SAndreas Gohr $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30)); 15914d99ec0SAndreas Gohr 160264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 1616985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 162264f1744SAndreas Gohr 163264f1744SAndreas Gohr echo '<form action="" method="get">'; 164264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 165264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 166264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 167264f1744SAndreas Gohr echo '<input type="text" name="f" value="' . $this->from . '" class="edit" />'; 168264f1744SAndreas Gohr echo '<input type="text" name="t" value="' . $this->to . '" class="edit" />'; 169264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 17014d99ec0SAndreas Gohr echo '</form>'; 171264f1744SAndreas Gohr 1726985b606SAndreas Gohr echo '<ul>'; 1736985b606SAndreas Gohr foreach(array('today', 'last1', 'last7', 'last30') as $time) { 1746985b606SAndreas Gohr echo '<li>'; 1756985b606SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $$time . '&t=' . $today . '">'; 1766985b606SAndreas Gohr echo $this->getLang('time_' . $time); 1776985b606SAndreas Gohr echo '</a>'; 1786985b606SAndreas Gohr echo '</li>'; 1796985b606SAndreas Gohr } 1806985b606SAndreas Gohr echo '</ul>'; 1816985b606SAndreas Gohr 182264f1744SAndreas Gohr echo '</div>'; 18314d99ec0SAndreas Gohr } 18414d99ec0SAndreas Gohr 185f5f32cbfSAndreas Gohr /** 186f5f32cbfSAndreas Gohr * Print an introductionary screen 187f5f32cbfSAndreas Gohr */ 18814d99ec0SAndreas Gohr function html_dashboard() { 189878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 1902812a751SAndreas Gohr 1912812a751SAndreas Gohr // general info 1922812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 1936b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 1941d2d78ccSAndreas Gohr 1951d2d78ccSAndreas Gohr echo '<ul class="left">'; 19633a136e5SAndreas Gohr foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) { 197eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 198eabe0d07SAndreas Gohr } 1992812a751SAndreas Gohr echo '</ul>'; 2001d2d78ccSAndreas Gohr 2011d2d78ccSAndreas Gohr echo '<ul class="left">'; 2021d2d78ccSAndreas Gohr foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) { 2031d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2041d2d78ccSAndreas Gohr } 2051d2d78ccSAndreas Gohr echo '</ul>'; 2061d2d78ccSAndreas Gohr 207259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 208259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2092812a751SAndreas Gohr echo '</div>'; 2102812a751SAndreas Gohr 21187d5e44bSAndreas Gohr // top pages today 212264f1744SAndreas Gohr echo '<div>'; 213dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2146b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15); 2152812a751SAndreas Gohr $this->html_resulttable($result); 216d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 217264f1744SAndreas Gohr echo '</div>'; 21887d5e44bSAndreas Gohr 21987d5e44bSAndreas Gohr // top referer today 220264f1744SAndreas Gohr echo '<div>'; 221dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2226b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15); 2232812a751SAndreas Gohr $this->html_resulttable($result); 224d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 225264f1744SAndreas Gohr echo '</div>'; 22654f6c432SAndreas Gohr 22729dea504SAndreas Gohr // top searches today 228264f1744SAndreas Gohr echo '<div>'; 229dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 23012b59231SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15); 23129dea504SAndreas Gohr $this->html_resulttable($result); 232d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 233264f1744SAndreas Gohr echo '</div>'; 23414d99ec0SAndreas Gohr } 23514d99ec0SAndreas Gohr 236cae4a1c5SAndreas Gohr function html_history() { 237cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 238*338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 239*338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 240*338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 241*338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 242cae4a1c5SAndreas Gohr } 243cae4a1c5SAndreas Gohr 244c67866d1SAndreas Gohr function html_countries() { 245878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 246878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 2476b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 2482507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2499da6395dSAndreas Gohr } 2509da6395dSAndreas Gohr 2519da6395dSAndreas Gohr function html_page() { 252878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 2536b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 2542507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2559da6395dSAndreas Gohr } 2569da6395dSAndreas Gohr 2571664ba1dSAndreas Gohr function html_edits() { 2581664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 2591664ba1dSAndreas Gohr $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150); 2601664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 2611664ba1dSAndreas Gohr } 2621664ba1dSAndreas Gohr 2631664ba1dSAndreas Gohr function html_images() { 2641664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 2651664ba1dSAndreas Gohr $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150); 2661664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 2671664ba1dSAndreas Gohr } 2681664ba1dSAndreas Gohr 2691664ba1dSAndreas Gohr function html_downloads() { 2701664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 2711664ba1dSAndreas Gohr $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150); 2721664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 2731664ba1dSAndreas Gohr } 2741664ba1dSAndreas Gohr 2754f41a2ccSAndreas Gohr function html_browsers() { 276878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 277878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 2786b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 2792507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 28075fa767dSAndreas Gohr } 28175fa767dSAndreas Gohr 282bd4217d3SAndreas Gohr function html_os() { 283878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 284878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 2856b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 2862507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 287bd4217d3SAndreas Gohr } 288bd4217d3SAndreas Gohr 2899da6395dSAndreas Gohr function html_referer() { 2906b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 2912812a751SAndreas Gohr 2922812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 2932812a751SAndreas Gohr 29494023548SAndreas Gohr if($all) { 2950863c19cSAndreas Gohr printf( 2960863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 297878be5c9SAndreas Gohr $all, $result['direct'], (100 * $result['direct'] / $all), 2982812a751SAndreas Gohr $result['search'], (100 * $result['search'] / $all), $result['external'], 2990863c19cSAndreas Gohr (100 * $result['external'] / $all) 3000863c19cSAndreas Gohr ); 30194023548SAndreas Gohr } 3022812a751SAndreas Gohr 3036b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 3042507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3059da6395dSAndreas Gohr } 3069da6395dSAndreas Gohr 307e7a2f1e0SAndreas Gohr function html_newreferer() { 308878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 309e7a2f1e0SAndreas Gohr 3106b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 3112507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 312e7a2f1e0SAndreas Gohr } 313e7a2f1e0SAndreas Gohr 314e25286daSAndreas Gohr function html_outlinks() { 315878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 3166b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 317e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 318e25286daSAndreas Gohr } 319e25286daSAndreas Gohr 32012dcdeccSAndreas Gohr function html_searchphrases() { 321878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 3225bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 32312dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 32412dcdeccSAndreas Gohr } 32512dcdeccSAndreas Gohr 32612dcdeccSAndreas Gohr function html_searchwords() { 327878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 3285bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 3295bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3305bccfe87SAndreas Gohr } 3315bccfe87SAndreas Gohr 3325bccfe87SAndreas Gohr function html_internalsearchphrases() { 333878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 3345bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 3355bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3365bccfe87SAndreas Gohr } 3375bccfe87SAndreas Gohr 3385bccfe87SAndreas Gohr function html_internalsearchwords() { 339878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 3405bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 34112dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 34212dcdeccSAndreas Gohr } 34312dcdeccSAndreas Gohr 34412dcdeccSAndreas Gohr function html_searchengines() { 345878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 34625b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 3476b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 34812dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 34912dcdeccSAndreas Gohr } 35012dcdeccSAndreas Gohr 351c73e16f1SAndreas Gohr function html_resolution() { 35225446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 35325446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 354307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 355307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 35625446aa2SAndreas Gohr } 357307baf3fSAndreas Gohr 35825446aa2SAndreas Gohr function html_viewport() { 35925446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 36025446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 36125446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 36225446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 363c73e16f1SAndreas Gohr } 3649da6395dSAndreas Gohr 36533a136e5SAndreas Gohr function html_seenusers() { 36633a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 36733a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 36833a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 36933a136e5SAndreas Gohr } 37033a136e5SAndreas Gohr 37114d99ec0SAndreas Gohr /** 37214d99ec0SAndreas Gohr * Display a result in a HTML table 37314d99ec0SAndreas Gohr */ 3742507f8e0SAndreas Gohr function html_resulttable($result, $header = '', $pager = 0) { 37514d99ec0SAndreas Gohr echo '<table>'; 3762812a751SAndreas Gohr if(is_array($header)) { 37714d99ec0SAndreas Gohr echo '<tr>'; 37814d99ec0SAndreas Gohr foreach($header as $h) { 37914d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 38014d99ec0SAndreas Gohr } 38114d99ec0SAndreas Gohr echo '</tr>'; 3822812a751SAndreas Gohr } 38314d99ec0SAndreas Gohr 3842507f8e0SAndreas Gohr $count = 0; 3852ee939eeSAndreas Gohr if(is_array($result)) foreach($result as $row) { 38614d99ec0SAndreas Gohr echo '<tr>'; 38714d99ec0SAndreas Gohr foreach($row as $k => $v) { 388f3818071SAndreas Gohr if($k == 'res_x') continue; 389f3818071SAndreas Gohr if($k == 'res_y') continue; 390f3818071SAndreas Gohr 3912812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 39214d99ec0SAndreas Gohr if($k == 'page') { 39314d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 39414d99ec0SAndreas Gohr echo hsc($v); 39514d99ec0SAndreas Gohr echo '</a>'; 3961664ba1dSAndreas Gohr } elseif($k == 'media') { 3971664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 3981664ba1dSAndreas Gohr echo hsc($v); 3991664ba1dSAndreas Gohr echo '</a>'; 4001664ba1dSAndreas Gohr } elseif($k == 'filesize') { 4011664ba1dSAndreas Gohr echo filesize_h($v); 40214d99ec0SAndreas Gohr } elseif($k == 'url') { 40354f6c432SAndreas Gohr $url = hsc($v); 40483b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 4052812a751SAndreas Gohr if(strlen($url) > 45) { 4062812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 40754f6c432SAndreas Gohr } 40814d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 40954f6c432SAndreas Gohr echo $url; 41014d99ec0SAndreas Gohr echo '</a>'; 4115bccfe87SAndreas Gohr } elseif($k == 'ilookup') { 4125bccfe87SAndreas Gohr echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>'; 41329dea504SAndreas Gohr } elseif($k == 'lookup') { 41429dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 41513a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 41629dea504SAndreas Gohr echo '</a> '; 41729dea504SAndreas Gohr 41829dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 41913a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 42029dea504SAndreas Gohr echo '</a> '; 42129dea504SAndreas Gohr 42213a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 42313a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 42429dea504SAndreas Gohr echo '</a> '; 42529dea504SAndreas Gohr 42612dcdeccSAndreas Gohr } elseif($k == 'engine') { 42713a86c14SAndreas Gohr include_once(dirname(__FILE__) . '/inc/searchengines.php'); 42813a86c14SAndreas Gohr if(isset($SEARCHENGINEINFO[$v])) { 42913a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 43013a86c14SAndreas Gohr } else { 43113a86c14SAndreas Gohr echo hsc(ucwords($v)); 43213a86c14SAndreas Gohr } 43313a86c14SAndreas Gohr } elseif($k == 'eflag') { 43413a86c14SAndreas Gohr $this->html_icon('search', $v); 43575fa767dSAndreas Gohr } elseif($k == 'bflag') { 43613a86c14SAndreas Gohr $this->html_icon('browser', $v); 437bd4217d3SAndreas Gohr } elseif($k == 'osflag') { 43813a86c14SAndreas Gohr $this->html_icon('os', $v); 43975fa767dSAndreas Gohr } elseif($k == 'cflag') { 44013a86c14SAndreas Gohr $this->html_icon('flags', $v); 44114d99ec0SAndreas Gohr } elseif($k == 'html') { 44214d99ec0SAndreas Gohr echo $v; 44314d99ec0SAndreas Gohr } else { 44414d99ec0SAndreas Gohr echo hsc($v); 44514d99ec0SAndreas Gohr } 44614d99ec0SAndreas Gohr echo '</td>'; 44714d99ec0SAndreas Gohr } 44814d99ec0SAndreas Gohr echo '</tr>'; 4492507f8e0SAndreas Gohr 4502507f8e0SAndreas Gohr if($pager && ($count == $pager)) break; 4512507f8e0SAndreas Gohr $count++; 45214d99ec0SAndreas Gohr } 45314d99ec0SAndreas Gohr echo '</table>'; 4542507f8e0SAndreas Gohr 4552507f8e0SAndreas Gohr if($pager) $this->html_pager($pager, count($result) > $pager); 4561878f16fSAndreas Gohr } 4571878f16fSAndreas Gohr 45813a86c14SAndreas Gohr function html_icon($type, $value) { 45913a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 4609bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 46113a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 462dffb869bSAndreas Gohr if($type == 'flags') { 463dffb869bSAndreas Gohr $w = 18; 464dffb869bSAndreas Gohr $h = 12; 465dffb869bSAndreas Gohr } else { 466dffb869bSAndreas Gohr $w = 16; 467dffb869bSAndreas Gohr $h = 16; 468dffb869bSAndreas Gohr } 46913a86c14SAndreas Gohr if(file_exists(DOKU_INC . $file)) { 470dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 47113a86c14SAndreas Gohr } 47213a86c14SAndreas Gohr } 4731878f16fSAndreas Gohr} 474