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*81ff4c3aSAndreas Gohr 'dashboard' => 1, 38*81ff4c3aSAndreas Gohr 39*81ff4c3aSAndreas Gohr 'content' => array( 40*81ff4c3aSAndreas Gohr 'page', 41*81ff4c3aSAndreas Gohr 'edits', 42*81ff4c3aSAndreas Gohr 'images', 43*81ff4c3aSAndreas Gohr 'downloads', 44*81ff4c3aSAndreas Gohr 'history', 45*81ff4c3aSAndreas Gohr ), 46*81ff4c3aSAndreas Gohr 'users' => array( 47*81ff4c3aSAndreas Gohr 'topuser', 48*81ff4c3aSAndreas Gohr 'topeditor', 49*81ff4c3aSAndreas Gohr 'topgroup', 50*81ff4c3aSAndreas Gohr 'topgroupedit', 51*81ff4c3aSAndreas Gohr 'seenusers', 52*81ff4c3aSAndreas Gohr ), 53*81ff4c3aSAndreas Gohr 'links' => array( 54*81ff4c3aSAndreas Gohr 'referer', 55*81ff4c3aSAndreas Gohr 'newreferer', 56*81ff4c3aSAndreas Gohr 'outlinks', 57*81ff4c3aSAndreas Gohr ), 58*81ff4c3aSAndreas Gohr 'search' => array( 59*81ff4c3aSAndreas Gohr 'searchengines', 60*81ff4c3aSAndreas Gohr 'searchphrases', 61*81ff4c3aSAndreas Gohr 'searchwords', 62*81ff4c3aSAndreas Gohr 'internalsearchphrases', 63*81ff4c3aSAndreas Gohr 'internalsearchwords', 64*81ff4c3aSAndreas Gohr ), 65*81ff4c3aSAndreas Gohr 'technology' => array( 66*81ff4c3aSAndreas Gohr 'browsers', 67*81ff4c3aSAndreas Gohr 'os', 68*81ff4c3aSAndreas Gohr 'countries', 69*81ff4c3aSAndreas Gohr 'resolution', 70*81ff4c3aSAndreas Gohr 'viewport', 71*81ff4c3aSAndreas Gohr ), 720863c19cSAndreas Gohr ); 731878f16fSAndreas Gohr 74*81ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 75*81ff4c3aSAndreas Gohr protected $allowedpages = array(); 76*81ff4c3aSAndreas Gohr 771878f16fSAndreas Gohr /** 786b6f8822SAndreas Gohr * Initialize the helper 796b6f8822SAndreas Gohr */ 806b6f8822SAndreas Gohr public function __construct() { 816b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 82*81ff4c3aSAndreas Gohr 83*81ff4c3aSAndreas Gohr // build a list of pages 84*81ff4c3aSAndreas Gohr foreach($this->pages as $key => $val) { 85*81ff4c3aSAndreas Gohr if(is_array($val)) { 86*81ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 87*81ff4c3aSAndreas Gohr }else { 88*81ff4c3aSAndreas Gohr $this->allowedpages[] = $key; 89*81ff4c3aSAndreas Gohr } 90*81ff4c3aSAndreas Gohr } 916b6f8822SAndreas Gohr } 926b6f8822SAndreas Gohr 936b6f8822SAndreas Gohr /** 941878f16fSAndreas Gohr * Access for managers allowed 951878f16fSAndreas Gohr */ 966b6f8822SAndreas Gohr public function forAdminOnly() { 971878f16fSAndreas Gohr return false; 981878f16fSAndreas Gohr } 991878f16fSAndreas Gohr 1001878f16fSAndreas Gohr /** 1011878f16fSAndreas Gohr * return sort order for position in admin menu 1021878f16fSAndreas Gohr */ 1036b6f8822SAndreas Gohr public function getMenuSort() { 1046b6f8822SAndreas Gohr return 350; 1051878f16fSAndreas Gohr } 1061878f16fSAndreas Gohr 1071878f16fSAndreas Gohr /** 1081878f16fSAndreas Gohr * handle user request 1091878f16fSAndreas Gohr */ 1106b6f8822SAndreas Gohr public function handle() { 111264f1744SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']); 112*81ff4c3aSAndreas Gohr if(!in_array($this->opt, $this->allowedpages)) $this->opt = 'dashboard'; 113a901d721SAndreas Gohr 11495eb68e6SAndreas Gohr $this->start = (int) $_REQUEST['s']; 115e8699bceSAndreas Gohr $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']); 116e8699bceSAndreas Gohr } 11795eb68e6SAndreas Gohr 118e8699bceSAndreas Gohr /** 119e8699bceSAndreas Gohr * set limit clause 120e8699bceSAndreas Gohr */ 1216b6f8822SAndreas Gohr public function setTimeframe($from, $to) { 122047fcb0fSAndreas Gohr // swap if wrong order 123047fcb0fSAndreas Gohr if($from > $to) list($from, $to) = array($to, $from); 124047fcb0fSAndreas Gohr 1253bf3de81SAndreas Gohr $this->tlimit = $this->hlp->Query()->mktlimit($from, $to); 126e8699bceSAndreas Gohr $this->from = $from; 127e8699bceSAndreas Gohr $this->to = $to; 1281878f16fSAndreas Gohr } 1291878f16fSAndreas Gohr 1301878f16fSAndreas Gohr /** 13179b4a855SAndreas Gohr * Output the Statistics 1321878f16fSAndreas Gohr */ 1331878f16fSAndreas Gohr function html() { 1341d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 1350c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 136264f1744SAndreas Gohr $this->html_timeselect(); 137441bfb8eSAndreas Gohr tpl_flush(); 138264f1744SAndreas Gohr 13979b4a855SAndreas Gohr $method = 'html_' . $this->opt; 14079b4a855SAndreas Gohr if(method_exists($this, $method)) { 141a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 142a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 14379b4a855SAndreas Gohr $this->$method(); 144a901d721SAndreas Gohr echo '</div>'; 14514d99ec0SAndreas Gohr } 1461d2d78ccSAndreas Gohr echo '</div>'; 14714d99ec0SAndreas Gohr } 14814d99ec0SAndreas Gohr 1496b6f8822SAndreas Gohr /** 1506b6f8822SAndreas Gohr * Return the TOC 1516b6f8822SAndreas Gohr * 1526b6f8822SAndreas Gohr * @return array 1536b6f8822SAndreas Gohr */ 15447ffcf7dSAndreas Gohr function getTOC() { 15547ffcf7dSAndreas Gohr $toc = array(); 156*81ff4c3aSAndreas Gohr foreach($this->pages as $key => $info) { 157*81ff4c3aSAndreas Gohr if (is_array($info)) { 158*81ff4c3aSAndreas Gohr 159*81ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 160*81ff4c3aSAndreas Gohr '', 161*81ff4c3aSAndreas Gohr $this->getLang($key), 162*81ff4c3aSAndreas Gohr 1, 163*81ff4c3aSAndreas Gohr '' 16447ffcf7dSAndreas Gohr ); 165*81ff4c3aSAndreas Gohr 166*81ff4c3aSAndreas Gohr foreach($info as $page) { 167*81ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 168*81ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 169*81ff4c3aSAndreas Gohr $this->getLang($page), 170*81ff4c3aSAndreas Gohr 2, 171*81ff4c3aSAndreas Gohr '' 172*81ff4c3aSAndreas Gohr ); 173*81ff4c3aSAndreas Gohr } 174*81ff4c3aSAndreas Gohr } else { 175*81ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 176*81ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . '&f=' . $this->from . '&t=' . $this->to, 177*81ff4c3aSAndreas Gohr $this->getLang($key), 178*81ff4c3aSAndreas Gohr 1, 179*81ff4c3aSAndreas Gohr '' 180*81ff4c3aSAndreas Gohr ); 181*81ff4c3aSAndreas Gohr } 18247ffcf7dSAndreas Gohr } 18347ffcf7dSAndreas Gohr return $toc; 1849da6395dSAndreas Gohr } 1859da6395dSAndreas Gohr 186dc7b1e5eSAndreas Gohr function html_graph($name, $width, $height) { 187dc7b1e5eSAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name . 188dc7b1e5eSAndreas Gohr '&f=' . $this->from . '&t=' . $this->to; 189dc7b1e5eSAndreas Gohr echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>'; 190dc7b1e5eSAndreas Gohr } 191dc7b1e5eSAndreas Gohr 1926b6f8822SAndreas Gohr /** 1936b6f8822SAndreas Gohr * Outputs pagination links 1946b6f8822SAndreas Gohr * 19533a136e5SAndreas Gohr * @param int $limit 19633a136e5SAndreas Gohr * @param int $next 1976b6f8822SAndreas Gohr */ 1982507f8e0SAndreas Gohr function html_pager($limit, $next) { 1992507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 2002507f8e0SAndreas Gohr 2012507f8e0SAndreas Gohr if($this->start > 0) { 2022507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 203d43cd6e0SAndreas 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>'; 2042507f8e0SAndreas Gohr } 2052507f8e0SAndreas Gohr 2062507f8e0SAndreas Gohr if($next) { 2072507f8e0SAndreas Gohr $go = $this->start + $limit; 208d43cd6e0SAndreas 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>'; 2092507f8e0SAndreas Gohr } 2102507f8e0SAndreas Gohr echo '</div>'; 2112507f8e0SAndreas Gohr } 2122507f8e0SAndreas Gohr 213264f1744SAndreas Gohr /** 214264f1744SAndreas Gohr * Print the time selection menu 215264f1744SAndreas Gohr */ 21614d99ec0SAndreas Gohr function html_timeselect() { 2176985b606SAndreas Gohr $today = date('Y-m-d'); 2186985b606SAndreas Gohr $last1 = date('Y-m-d', time() - (60 * 60 * 24)); 2196985b606SAndreas Gohr $last7 = date('Y-m-d', time() - (60 * 60 * 24 * 7)); 2206985b606SAndreas Gohr $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30)); 22114d99ec0SAndreas Gohr 222264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 2236985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 224264f1744SAndreas Gohr 225047fcb0fSAndreas Gohr echo '<form action="'.DOKU_SCRIPT.'" method="get">'; 226264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 227264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 228264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 229047fcb0fSAndreas Gohr echo '<input type="text" name="f" value="' . $this->from . '" class="edit datepicker" />'; 230047fcb0fSAndreas Gohr echo '<input type="text" name="t" value="' . $this->to . '" class="edit datepicker" />'; 231264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 23214d99ec0SAndreas Gohr echo '</form>'; 233264f1744SAndreas Gohr 2346985b606SAndreas Gohr echo '<ul>'; 2356985b606SAndreas Gohr foreach(array('today', 'last1', 'last7', 'last30') as $time) { 2366985b606SAndreas Gohr echo '<li>'; 2376985b606SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $$time . '&t=' . $today . '">'; 2386985b606SAndreas Gohr echo $this->getLang('time_' . $time); 2396985b606SAndreas Gohr echo '</a>'; 2406985b606SAndreas Gohr echo '</li>'; 2416985b606SAndreas Gohr } 2426985b606SAndreas Gohr echo '</ul>'; 2436985b606SAndreas Gohr 244264f1744SAndreas Gohr echo '</div>'; 24514d99ec0SAndreas Gohr } 24614d99ec0SAndreas Gohr 247f5f32cbfSAndreas Gohr /** 248f5f32cbfSAndreas Gohr * Print an introductionary screen 249f5f32cbfSAndreas Gohr */ 25014d99ec0SAndreas Gohr function html_dashboard() { 251878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 2522812a751SAndreas Gohr 2532812a751SAndreas Gohr // general info 2542812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 2556b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 2561d2d78ccSAndreas Gohr 2571d2d78ccSAndreas Gohr echo '<ul class="left">'; 25833a136e5SAndreas Gohr foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) { 259eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 260eabe0d07SAndreas Gohr } 2612812a751SAndreas Gohr echo '</ul>'; 2621d2d78ccSAndreas Gohr 2631d2d78ccSAndreas Gohr echo '<ul class="left">'; 2641d2d78ccSAndreas Gohr foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) { 2651d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2661d2d78ccSAndreas Gohr } 2671d2d78ccSAndreas Gohr echo '</ul>'; 2681d2d78ccSAndreas Gohr 269259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 270259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2712812a751SAndreas Gohr echo '</div>'; 2722812a751SAndreas Gohr 27387d5e44bSAndreas Gohr // top pages today 274264f1744SAndreas Gohr echo '<div>'; 275dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2766b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15); 2772812a751SAndreas Gohr $this->html_resulttable($result); 278d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 279264f1744SAndreas Gohr echo '</div>'; 28087d5e44bSAndreas Gohr 28187d5e44bSAndreas Gohr // top referer today 282264f1744SAndreas Gohr echo '<div>'; 283dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2846b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15); 2852812a751SAndreas Gohr $this->html_resulttable($result); 286d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 287264f1744SAndreas Gohr echo '</div>'; 28854f6c432SAndreas Gohr 28929dea504SAndreas Gohr // top searches today 290264f1744SAndreas Gohr echo '<div>'; 291dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 29212b59231SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15); 29329dea504SAndreas Gohr $this->html_resulttable($result); 294d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 295264f1744SAndreas Gohr echo '</div>'; 29614d99ec0SAndreas Gohr } 29714d99ec0SAndreas Gohr 298cae4a1c5SAndreas Gohr function html_history() { 299cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 300338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 301338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 302338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 303338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 304cae4a1c5SAndreas Gohr } 305cae4a1c5SAndreas Gohr 306c67866d1SAndreas Gohr function html_countries() { 307878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 308878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 3096b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 3102507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3119da6395dSAndreas Gohr } 3129da6395dSAndreas Gohr 3139da6395dSAndreas Gohr function html_page() { 314878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 3156b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 3162507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3179da6395dSAndreas Gohr } 3189da6395dSAndreas Gohr 3191664ba1dSAndreas Gohr function html_edits() { 3201664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 3211664ba1dSAndreas Gohr $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150); 3221664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3231664ba1dSAndreas Gohr } 3241664ba1dSAndreas Gohr 3251664ba1dSAndreas Gohr function html_images() { 3261664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 3271664ba1dSAndreas Gohr $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150); 3281664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3291664ba1dSAndreas Gohr } 3301664ba1dSAndreas Gohr 3311664ba1dSAndreas Gohr function html_downloads() { 3321664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 3331664ba1dSAndreas Gohr $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150); 3341664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3351664ba1dSAndreas Gohr } 3361664ba1dSAndreas Gohr 3374f41a2ccSAndreas Gohr function html_browsers() { 338878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 339878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 3406b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 3412507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 34275fa767dSAndreas Gohr } 34375fa767dSAndreas Gohr 344*81ff4c3aSAndreas Gohr function html_topuser(){ 345*81ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 346*81ff4c3aSAndreas Gohr $this->html_graph('topuser', 400, 200); 347*81ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topuser($this->tlimit, $this->start, 150, true); 348*81ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 349*81ff4c3aSAndreas Gohr } 350*81ff4c3aSAndreas Gohr 351*81ff4c3aSAndreas Gohr function html_topeditor(){ 352*81ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 353*81ff4c3aSAndreas Gohr $this->html_graph('topeditor', 400, 200); 354*81ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topeditor($this->tlimit, $this->start, 150, true); 355*81ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 356*81ff4c3aSAndreas Gohr } 357*81ff4c3aSAndreas Gohr 358*81ff4c3aSAndreas Gohr function html_topgroup(){ 359*81ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 360*81ff4c3aSAndreas Gohr $this->html_graph('topgroup', 400, 200); 361*81ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroup($this->tlimit, $this->start, 150, true); 362*81ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 363*81ff4c3aSAndreas Gohr } 364*81ff4c3aSAndreas Gohr 365*81ff4c3aSAndreas Gohr function html_topgroupedit(){ 366*81ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 367*81ff4c3aSAndreas Gohr $this->html_graph('topgroupedit', 400, 200); 368*81ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroupedit($this->tlimit, $this->start, 150, true); 369*81ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 370*81ff4c3aSAndreas Gohr } 371*81ff4c3aSAndreas Gohr 372bd4217d3SAndreas Gohr function html_os() { 373878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 374878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 3756b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 3762507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 377bd4217d3SAndreas Gohr } 378bd4217d3SAndreas Gohr 3799da6395dSAndreas Gohr function html_referer() { 3806b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 3812812a751SAndreas Gohr 3822812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 3832812a751SAndreas Gohr 38494023548SAndreas Gohr if($all) { 3850863c19cSAndreas Gohr printf( 3860863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 387878be5c9SAndreas Gohr $all, $result['direct'], (100 * $result['direct'] / $all), 3882812a751SAndreas Gohr $result['search'], (100 * $result['search'] / $all), $result['external'], 3890863c19cSAndreas Gohr (100 * $result['external'] / $all) 3900863c19cSAndreas Gohr ); 39194023548SAndreas Gohr } 3922812a751SAndreas Gohr 3936b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 3942507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3959da6395dSAndreas Gohr } 3969da6395dSAndreas Gohr 397e7a2f1e0SAndreas Gohr function html_newreferer() { 398878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 399e7a2f1e0SAndreas Gohr 4006b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 4012507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 402e7a2f1e0SAndreas Gohr } 403e7a2f1e0SAndreas Gohr 404e25286daSAndreas Gohr function html_outlinks() { 405878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 4066b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 407e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 408e25286daSAndreas Gohr } 409e25286daSAndreas Gohr 41012dcdeccSAndreas Gohr function html_searchphrases() { 411878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 4125bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 41312dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 41412dcdeccSAndreas Gohr } 41512dcdeccSAndreas Gohr 41612dcdeccSAndreas Gohr function html_searchwords() { 417878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 4185bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 4195bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4205bccfe87SAndreas Gohr } 4215bccfe87SAndreas Gohr 4225bccfe87SAndreas Gohr function html_internalsearchphrases() { 423878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 4245bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 4255bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4265bccfe87SAndreas Gohr } 4275bccfe87SAndreas Gohr 4285bccfe87SAndreas Gohr function html_internalsearchwords() { 429878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 4305bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 43112dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 43212dcdeccSAndreas Gohr } 43312dcdeccSAndreas Gohr 43412dcdeccSAndreas Gohr function html_searchengines() { 435878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 43625b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 4376b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 43812dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 43912dcdeccSAndreas Gohr } 44012dcdeccSAndreas Gohr 441c73e16f1SAndreas Gohr function html_resolution() { 44225446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 44325446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 444307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 445307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 44625446aa2SAndreas Gohr } 447307baf3fSAndreas Gohr 44825446aa2SAndreas Gohr function html_viewport() { 44925446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 45025446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 45125446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 45225446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 453c73e16f1SAndreas Gohr } 4549da6395dSAndreas Gohr 45533a136e5SAndreas Gohr function html_seenusers() { 45633a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 45733a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 45833a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 45933a136e5SAndreas Gohr } 46033a136e5SAndreas Gohr 46114d99ec0SAndreas Gohr /** 46214d99ec0SAndreas Gohr * Display a result in a HTML table 46314d99ec0SAndreas Gohr */ 4642507f8e0SAndreas Gohr function html_resulttable($result, $header = '', $pager = 0) { 46514d99ec0SAndreas Gohr echo '<table>'; 4662812a751SAndreas Gohr if(is_array($header)) { 46714d99ec0SAndreas Gohr echo '<tr>'; 46814d99ec0SAndreas Gohr foreach($header as $h) { 46914d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 47014d99ec0SAndreas Gohr } 47114d99ec0SAndreas Gohr echo '</tr>'; 4722812a751SAndreas Gohr } 47314d99ec0SAndreas Gohr 4742507f8e0SAndreas Gohr $count = 0; 4752ee939eeSAndreas Gohr if(is_array($result)) foreach($result as $row) { 47614d99ec0SAndreas Gohr echo '<tr>'; 47714d99ec0SAndreas Gohr foreach($row as $k => $v) { 478f3818071SAndreas Gohr if($k == 'res_x') continue; 479f3818071SAndreas Gohr if($k == 'res_y') continue; 480f3818071SAndreas Gohr 4812812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 48214d99ec0SAndreas Gohr if($k == 'page') { 48314d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 48414d99ec0SAndreas Gohr echo hsc($v); 48514d99ec0SAndreas Gohr echo '</a>'; 4861664ba1dSAndreas Gohr } elseif($k == 'media') { 4871664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 4881664ba1dSAndreas Gohr echo hsc($v); 4891664ba1dSAndreas Gohr echo '</a>'; 4901664ba1dSAndreas Gohr } elseif($k == 'filesize') { 4911664ba1dSAndreas Gohr echo filesize_h($v); 49214d99ec0SAndreas Gohr } elseif($k == 'url') { 49354f6c432SAndreas Gohr $url = hsc($v); 49483b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 4952812a751SAndreas Gohr if(strlen($url) > 45) { 4962812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 49754f6c432SAndreas Gohr } 49814d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 49954f6c432SAndreas Gohr echo $url; 50014d99ec0SAndreas Gohr echo '</a>'; 5015bccfe87SAndreas Gohr } elseif($k == 'ilookup') { 5025bccfe87SAndreas Gohr echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>'; 50329dea504SAndreas Gohr } elseif($k == 'lookup') { 50429dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 50513a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 50629dea504SAndreas Gohr echo '</a> '; 50729dea504SAndreas Gohr 50829dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 50913a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 51029dea504SAndreas Gohr echo '</a> '; 51129dea504SAndreas Gohr 51213a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 51313a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 51429dea504SAndreas Gohr echo '</a> '; 51529dea504SAndreas Gohr 51612dcdeccSAndreas Gohr } elseif($k == 'engine') { 51713a86c14SAndreas Gohr include_once(dirname(__FILE__) . '/inc/searchengines.php'); 51813a86c14SAndreas Gohr if(isset($SEARCHENGINEINFO[$v])) { 51913a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 52013a86c14SAndreas Gohr } else { 52113a86c14SAndreas Gohr echo hsc(ucwords($v)); 52213a86c14SAndreas Gohr } 52313a86c14SAndreas Gohr } elseif($k == 'eflag') { 52413a86c14SAndreas Gohr $this->html_icon('search', $v); 52575fa767dSAndreas Gohr } elseif($k == 'bflag') { 52613a86c14SAndreas Gohr $this->html_icon('browser', $v); 527bd4217d3SAndreas Gohr } elseif($k == 'osflag') { 52813a86c14SAndreas Gohr $this->html_icon('os', $v); 52975fa767dSAndreas Gohr } elseif($k == 'cflag') { 53013a86c14SAndreas Gohr $this->html_icon('flags', $v); 53114d99ec0SAndreas Gohr } elseif($k == 'html') { 53214d99ec0SAndreas Gohr echo $v; 53314d99ec0SAndreas Gohr } else { 53414d99ec0SAndreas Gohr echo hsc($v); 53514d99ec0SAndreas Gohr } 53614d99ec0SAndreas Gohr echo '</td>'; 53714d99ec0SAndreas Gohr } 53814d99ec0SAndreas Gohr echo '</tr>'; 5392507f8e0SAndreas Gohr 5402507f8e0SAndreas Gohr if($pager && ($count == $pager)) break; 5412507f8e0SAndreas Gohr $count++; 54214d99ec0SAndreas Gohr } 54314d99ec0SAndreas Gohr echo '</table>'; 5442507f8e0SAndreas Gohr 5452507f8e0SAndreas Gohr if($pager) $this->html_pager($pager, count($result) > $pager); 5461878f16fSAndreas Gohr } 5471878f16fSAndreas Gohr 54813a86c14SAndreas Gohr function html_icon($type, $value) { 54913a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5509bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 55113a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 552dffb869bSAndreas Gohr if($type == 'flags') { 553dffb869bSAndreas Gohr $w = 18; 554dffb869bSAndreas Gohr $h = 12; 555dffb869bSAndreas Gohr } else { 556dffb869bSAndreas Gohr $w = 16; 557dffb869bSAndreas Gohr $h = 16; 558dffb869bSAndreas Gohr } 55913a86c14SAndreas Gohr if(file_exists(DOKU_INC . $file)) { 560dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 56113a86c14SAndreas Gohr } 56213a86c14SAndreas Gohr } 5631878f16fSAndreas Gohr} 564