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( 37*1664ba1dSAndreas Gohr 'dashboard', 'page', 'edits', 'images', 'downloads', 38*1664ba1dSAndreas Gohr '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 236c67866d1SAndreas Gohr function html_countries() { 237878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 238878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 2396b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 2402507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2419da6395dSAndreas Gohr } 2429da6395dSAndreas Gohr 2439da6395dSAndreas Gohr function html_page() { 244878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 2456b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 2462507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2479da6395dSAndreas Gohr } 2489da6395dSAndreas Gohr 249*1664ba1dSAndreas Gohr function html_edits() { 250*1664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 251*1664ba1dSAndreas Gohr $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150); 252*1664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 253*1664ba1dSAndreas Gohr } 254*1664ba1dSAndreas Gohr 255*1664ba1dSAndreas Gohr function html_images() { 256*1664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 257*1664ba1dSAndreas Gohr $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150); 258*1664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 259*1664ba1dSAndreas Gohr } 260*1664ba1dSAndreas Gohr 261*1664ba1dSAndreas Gohr function html_downloads() { 262*1664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 263*1664ba1dSAndreas Gohr $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150); 264*1664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 265*1664ba1dSAndreas Gohr } 266*1664ba1dSAndreas Gohr 2674f41a2ccSAndreas Gohr function html_browsers() { 268878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 269878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 2706b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 2712507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 27275fa767dSAndreas Gohr } 27375fa767dSAndreas Gohr 274bd4217d3SAndreas Gohr function html_os() { 275878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 276878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 2776b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 2782507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 279bd4217d3SAndreas Gohr } 280bd4217d3SAndreas Gohr 2819da6395dSAndreas Gohr function html_referer() { 2826b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 2832812a751SAndreas Gohr 2842812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 2852812a751SAndreas Gohr 28694023548SAndreas Gohr if($all) { 2870863c19cSAndreas Gohr printf( 2880863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 289878be5c9SAndreas Gohr $all, $result['direct'], (100 * $result['direct'] / $all), 2902812a751SAndreas Gohr $result['search'], (100 * $result['search'] / $all), $result['external'], 2910863c19cSAndreas Gohr (100 * $result['external'] / $all) 2920863c19cSAndreas Gohr ); 29394023548SAndreas Gohr } 2942812a751SAndreas Gohr 2956b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 2962507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2979da6395dSAndreas Gohr } 2989da6395dSAndreas Gohr 299e7a2f1e0SAndreas Gohr function html_newreferer() { 300878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 301e7a2f1e0SAndreas Gohr 3026b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 3032507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 304e7a2f1e0SAndreas Gohr } 305e7a2f1e0SAndreas Gohr 306e25286daSAndreas Gohr function html_outlinks() { 307878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 3086b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 309e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 310e25286daSAndreas Gohr } 311e25286daSAndreas Gohr 31212dcdeccSAndreas Gohr function html_searchphrases() { 313878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 3145bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 31512dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 31612dcdeccSAndreas Gohr } 31712dcdeccSAndreas Gohr 31812dcdeccSAndreas Gohr function html_searchwords() { 319878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 3205bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 3215bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3225bccfe87SAndreas Gohr } 3235bccfe87SAndreas Gohr 3245bccfe87SAndreas Gohr function html_internalsearchphrases() { 325878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 3265bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 3275bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3285bccfe87SAndreas Gohr } 3295bccfe87SAndreas Gohr 3305bccfe87SAndreas Gohr function html_internalsearchwords() { 331878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 3325bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 33312dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 33412dcdeccSAndreas Gohr } 33512dcdeccSAndreas Gohr 33612dcdeccSAndreas Gohr function html_searchengines() { 337878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 33825b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 3396b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 34012dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 34112dcdeccSAndreas Gohr } 34212dcdeccSAndreas Gohr 343c73e16f1SAndreas Gohr function html_resolution() { 34425446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 34525446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 346307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 347307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 34825446aa2SAndreas Gohr } 349307baf3fSAndreas Gohr 35025446aa2SAndreas Gohr function html_viewport() { 35125446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 35225446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 35325446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 35425446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 355c73e16f1SAndreas Gohr } 3569da6395dSAndreas Gohr 35733a136e5SAndreas Gohr function html_seenusers() { 35833a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 35933a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 36033a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 36133a136e5SAndreas Gohr } 36233a136e5SAndreas Gohr 36314d99ec0SAndreas Gohr /** 36414d99ec0SAndreas Gohr * Display a result in a HTML table 36514d99ec0SAndreas Gohr */ 3662507f8e0SAndreas Gohr function html_resulttable($result, $header = '', $pager = 0) { 36714d99ec0SAndreas Gohr echo '<table>'; 3682812a751SAndreas Gohr if(is_array($header)) { 36914d99ec0SAndreas Gohr echo '<tr>'; 37014d99ec0SAndreas Gohr foreach($header as $h) { 37114d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 37214d99ec0SAndreas Gohr } 37314d99ec0SAndreas Gohr echo '</tr>'; 3742812a751SAndreas Gohr } 37514d99ec0SAndreas Gohr 3762507f8e0SAndreas Gohr $count = 0; 3772ee939eeSAndreas Gohr if(is_array($result)) foreach($result as $row) { 37814d99ec0SAndreas Gohr echo '<tr>'; 37914d99ec0SAndreas Gohr foreach($row as $k => $v) { 380f3818071SAndreas Gohr if($k == 'res_x') continue; 381f3818071SAndreas Gohr if($k == 'res_y') continue; 382f3818071SAndreas Gohr 3832812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 38414d99ec0SAndreas Gohr if($k == 'page') { 38514d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 38614d99ec0SAndreas Gohr echo hsc($v); 38714d99ec0SAndreas Gohr echo '</a>'; 388*1664ba1dSAndreas Gohr } elseif($k == 'media') { 389*1664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 390*1664ba1dSAndreas Gohr echo hsc($v); 391*1664ba1dSAndreas Gohr echo '</a>'; 392*1664ba1dSAndreas Gohr } elseif($k == 'filesize') { 393*1664ba1dSAndreas Gohr echo filesize_h($v); 39414d99ec0SAndreas Gohr } elseif($k == 'url') { 39554f6c432SAndreas Gohr $url = hsc($v); 39683b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 3972812a751SAndreas Gohr if(strlen($url) > 45) { 3982812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 39954f6c432SAndreas Gohr } 40014d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 40154f6c432SAndreas Gohr echo $url; 40214d99ec0SAndreas Gohr echo '</a>'; 4035bccfe87SAndreas Gohr } elseif($k == 'ilookup') { 4045bccfe87SAndreas Gohr echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>'; 40529dea504SAndreas Gohr } elseif($k == 'lookup') { 40629dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 40713a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 40829dea504SAndreas Gohr echo '</a> '; 40929dea504SAndreas Gohr 41029dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 41113a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 41229dea504SAndreas Gohr echo '</a> '; 41329dea504SAndreas Gohr 41413a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 41513a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 41629dea504SAndreas Gohr echo '</a> '; 41729dea504SAndreas Gohr 41812dcdeccSAndreas Gohr } elseif($k == 'engine') { 41913a86c14SAndreas Gohr include_once(dirname(__FILE__) . '/inc/searchengines.php'); 42013a86c14SAndreas Gohr if(isset($SEARCHENGINEINFO[$v])) { 42113a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 42213a86c14SAndreas Gohr } else { 42313a86c14SAndreas Gohr echo hsc(ucwords($v)); 42413a86c14SAndreas Gohr } 42513a86c14SAndreas Gohr } elseif($k == 'eflag') { 42613a86c14SAndreas Gohr $this->html_icon('search', $v); 42775fa767dSAndreas Gohr } elseif($k == 'bflag') { 42813a86c14SAndreas Gohr $this->html_icon('browser', $v); 429bd4217d3SAndreas Gohr } elseif($k == 'osflag') { 43013a86c14SAndreas Gohr $this->html_icon('os', $v); 43175fa767dSAndreas Gohr } elseif($k == 'cflag') { 43213a86c14SAndreas Gohr $this->html_icon('flags', $v); 43314d99ec0SAndreas Gohr } elseif($k == 'html') { 43414d99ec0SAndreas Gohr echo $v; 43514d99ec0SAndreas Gohr } else { 43614d99ec0SAndreas Gohr echo hsc($v); 43714d99ec0SAndreas Gohr } 43814d99ec0SAndreas Gohr echo '</td>'; 43914d99ec0SAndreas Gohr } 44014d99ec0SAndreas Gohr echo '</tr>'; 4412507f8e0SAndreas Gohr 4422507f8e0SAndreas Gohr if($pager && ($count == $pager)) break; 4432507f8e0SAndreas Gohr $count++; 44414d99ec0SAndreas Gohr } 44514d99ec0SAndreas Gohr echo '</table>'; 4462507f8e0SAndreas Gohr 4472507f8e0SAndreas Gohr if($pager) $this->html_pager($pager, count($result) > $pager); 4481878f16fSAndreas Gohr } 4491878f16fSAndreas Gohr 45013a86c14SAndreas Gohr function html_icon($type, $value) { 45113a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 4529bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 45313a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 454dffb869bSAndreas Gohr if($type == 'flags') { 455dffb869bSAndreas Gohr $w = 18; 456dffb869bSAndreas Gohr $h = 12; 457dffb869bSAndreas Gohr } else { 458dffb869bSAndreas Gohr $w = 16; 459dffb869bSAndreas Gohr $h = 16; 460dffb869bSAndreas Gohr } 46113a86c14SAndreas Gohr if(file_exists(DOKU_INC . $file)) { 462dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 46313a86c14SAndreas Gohr } 46413a86c14SAndreas Gohr } 4651878f16fSAndreas Gohr} 466