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( 3781ff4c3aSAndreas Gohr 'dashboard' => 1, 3881ff4c3aSAndreas Gohr 3981ff4c3aSAndreas Gohr 'content' => array( 4081ff4c3aSAndreas Gohr 'page', 4181ff4c3aSAndreas Gohr 'edits', 4281ff4c3aSAndreas Gohr 'images', 4381ff4c3aSAndreas Gohr 'downloads', 4481ff4c3aSAndreas Gohr 'history', 4581ff4c3aSAndreas Gohr ), 4681ff4c3aSAndreas Gohr 'users' => array( 4781ff4c3aSAndreas Gohr 'topuser', 4881ff4c3aSAndreas Gohr 'topeditor', 4981ff4c3aSAndreas Gohr 'topgroup', 5081ff4c3aSAndreas Gohr 'topgroupedit', 5181ff4c3aSAndreas Gohr 'seenusers', 5281ff4c3aSAndreas Gohr ), 5381ff4c3aSAndreas Gohr 'links' => array( 5481ff4c3aSAndreas Gohr 'referer', 5581ff4c3aSAndreas Gohr 'newreferer', 5681ff4c3aSAndreas Gohr 'outlinks', 5781ff4c3aSAndreas Gohr ), 5881ff4c3aSAndreas Gohr 'search' => array( 5981ff4c3aSAndreas Gohr 'searchengines', 6081ff4c3aSAndreas Gohr 'searchphrases', 6181ff4c3aSAndreas Gohr 'searchwords', 6281ff4c3aSAndreas Gohr 'internalsearchphrases', 6381ff4c3aSAndreas Gohr 'internalsearchwords', 6481ff4c3aSAndreas Gohr ), 6581ff4c3aSAndreas Gohr 'technology' => array( 6681ff4c3aSAndreas Gohr 'browsers', 6781ff4c3aSAndreas Gohr 'os', 6881ff4c3aSAndreas Gohr 'countries', 6981ff4c3aSAndreas Gohr 'resolution', 7081ff4c3aSAndreas Gohr 'viewport', 7181ff4c3aSAndreas Gohr ), 720863c19cSAndreas Gohr ); 731878f16fSAndreas Gohr 7481ff4c3aSAndreas Gohr /** @var array keeps a list of all real content pages, generated from above array */ 7581ff4c3aSAndreas Gohr protected $allowedpages = array(); 7681ff4c3aSAndreas Gohr 771878f16fSAndreas Gohr /** 786b6f8822SAndreas Gohr * Initialize the helper 796b6f8822SAndreas Gohr */ 806b6f8822SAndreas Gohr public function __construct() { 816b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 8281ff4c3aSAndreas Gohr 8381ff4c3aSAndreas Gohr // build a list of pages 8481ff4c3aSAndreas Gohr foreach($this->pages as $key => $val) { 8581ff4c3aSAndreas Gohr if(is_array($val)) { 8681ff4c3aSAndreas Gohr $this->allowedpages = array_merge($this->allowedpages, $val); 8781ff4c3aSAndreas Gohr }else { 8881ff4c3aSAndreas Gohr $this->allowedpages[] = $key; 8981ff4c3aSAndreas Gohr } 9081ff4c3aSAndreas 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']); 11281ff4c3aSAndreas 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(); 15681ff4c3aSAndreas Gohr foreach($this->pages as $key => $info) { 15781ff4c3aSAndreas Gohr if (is_array($info)) { 15881ff4c3aSAndreas Gohr 15981ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 16081ff4c3aSAndreas Gohr '', 16181ff4c3aSAndreas Gohr $this->getLang($key), 16281ff4c3aSAndreas Gohr 1, 16381ff4c3aSAndreas Gohr '' 16447ffcf7dSAndreas Gohr ); 16581ff4c3aSAndreas Gohr 16681ff4c3aSAndreas Gohr foreach($info as $page) { 16781ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 16881ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 16981ff4c3aSAndreas Gohr $this->getLang($page), 17081ff4c3aSAndreas Gohr 2, 17181ff4c3aSAndreas Gohr '' 17281ff4c3aSAndreas Gohr ); 17381ff4c3aSAndreas Gohr } 17481ff4c3aSAndreas Gohr } else { 17581ff4c3aSAndreas Gohr $toc[] = html_mktocitem( 17681ff4c3aSAndreas Gohr '?do=admin&page=statistics&opt=' . $key . '&f=' . $this->from . '&t=' . $this->to, 17781ff4c3aSAndreas Gohr $this->getLang($key), 17881ff4c3aSAndreas Gohr 1, 17981ff4c3aSAndreas Gohr '' 18081ff4c3aSAndreas Gohr ); 18181ff4c3aSAndreas 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 269*56f647ddSAndreas Gohr echo '<br style="clear: left" />'; 270*56f647ddSAndreas Gohr 271259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 272259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2732812a751SAndreas Gohr echo '</div>'; 2742812a751SAndreas Gohr 27587d5e44bSAndreas Gohr // top pages today 276264f1744SAndreas Gohr echo '<div>'; 277dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2786b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15); 2792812a751SAndreas Gohr $this->html_resulttable($result); 280d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 281264f1744SAndreas Gohr echo '</div>'; 28287d5e44bSAndreas Gohr 28387d5e44bSAndreas Gohr // top referer today 284264f1744SAndreas Gohr echo '<div>'; 285dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2866b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15); 2872812a751SAndreas Gohr $this->html_resulttable($result); 288d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 289264f1744SAndreas Gohr echo '</div>'; 29054f6c432SAndreas Gohr 29129dea504SAndreas Gohr // top searches today 292264f1744SAndreas Gohr echo '<div>'; 293dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 29412b59231SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15); 29529dea504SAndreas Gohr $this->html_resulttable($result); 296d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 297264f1744SAndreas Gohr echo '</div>'; 29814d99ec0SAndreas Gohr } 29914d99ec0SAndreas Gohr 300cae4a1c5SAndreas Gohr function html_history() { 301cae4a1c5SAndreas Gohr echo '<p>' . $this->getLang('intro_history') . '</p>'; 302338987f5SAndreas Gohr $this->html_graph('history_page_count', 600, 200); 303338987f5SAndreas Gohr $this->html_graph('history_page_size', 600, 200); 304338987f5SAndreas Gohr $this->html_graph('history_media_count', 600, 200); 305338987f5SAndreas Gohr $this->html_graph('history_media_size', 600, 200); 306cae4a1c5SAndreas Gohr } 307cae4a1c5SAndreas Gohr 308c67866d1SAndreas Gohr function html_countries() { 309878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 310878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 3116b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 3122507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3139da6395dSAndreas Gohr } 3149da6395dSAndreas Gohr 3159da6395dSAndreas Gohr function html_page() { 316878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 3176b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 3182507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 3199da6395dSAndreas Gohr } 3209da6395dSAndreas Gohr 3211664ba1dSAndreas Gohr function html_edits() { 3221664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_edits') . '</p>'; 3231664ba1dSAndreas Gohr $result = $this->hlp->Query()->edits($this->tlimit, $this->start, 150); 3241664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3251664ba1dSAndreas Gohr } 3261664ba1dSAndreas Gohr 3271664ba1dSAndreas Gohr function html_images() { 3281664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_images') . '</p>'; 329616c1e8bSAndreas Gohr 330616c1e8bSAndreas Gohr $result = $this->hlp->Query()->imagessum($this->tlimit); 331616c1e8bSAndreas Gohr echo '<p>'; 332616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 333616c1e8bSAndreas Gohr echo '</p>'; 334616c1e8bSAndreas Gohr 3351664ba1dSAndreas Gohr $result = $this->hlp->Query()->images($this->tlimit, $this->start, 150); 3361664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3371664ba1dSAndreas Gohr } 3381664ba1dSAndreas Gohr 3391664ba1dSAndreas Gohr function html_downloads() { 3401664ba1dSAndreas Gohr echo '<p>' . $this->getLang('intro_downloads') . '</p>'; 341616c1e8bSAndreas Gohr 342616c1e8bSAndreas Gohr $result = $this->hlp->Query()->downloadssum($this->tlimit); 343616c1e8bSAndreas Gohr echo '<p>'; 344616c1e8bSAndreas Gohr echo sprintf($this->getLang('trafficsum'), $result[0]['cnt'], filesize_h($result[0]['filesize'])); 345616c1e8bSAndreas Gohr echo '</p>'; 346616c1e8bSAndreas Gohr 3471664ba1dSAndreas Gohr $result = $this->hlp->Query()->downloads($this->tlimit, $this->start, 150); 3481664ba1dSAndreas Gohr $this->html_resulttable($result, '', 150); 3491664ba1dSAndreas Gohr } 3501664ba1dSAndreas Gohr 3514f41a2ccSAndreas Gohr function html_browsers() { 352878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 353878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 3546b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 3552507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 35675fa767dSAndreas Gohr } 35775fa767dSAndreas Gohr 35881ff4c3aSAndreas Gohr function html_topuser(){ 35981ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topuser') . '</p>'; 36081ff4c3aSAndreas Gohr $this->html_graph('topuser', 400, 200); 36181ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topuser($this->tlimit, $this->start, 150, true); 36281ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 36381ff4c3aSAndreas Gohr } 36481ff4c3aSAndreas Gohr 36581ff4c3aSAndreas Gohr function html_topeditor(){ 36681ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topeditor') . '</p>'; 36781ff4c3aSAndreas Gohr $this->html_graph('topeditor', 400, 200); 36881ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topeditor($this->tlimit, $this->start, 150, true); 36981ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37081ff4c3aSAndreas Gohr } 37181ff4c3aSAndreas Gohr 37281ff4c3aSAndreas Gohr function html_topgroup(){ 37381ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroup') . '</p>'; 37481ff4c3aSAndreas Gohr $this->html_graph('topgroup', 400, 200); 37581ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroup($this->tlimit, $this->start, 150, true); 37681ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 37781ff4c3aSAndreas Gohr } 37881ff4c3aSAndreas Gohr 37981ff4c3aSAndreas Gohr function html_topgroupedit(){ 38081ff4c3aSAndreas Gohr echo '<p>' . $this->getLang('intro_topgroupedit') . '</p>'; 38181ff4c3aSAndreas Gohr $this->html_graph('topgroupedit', 400, 200); 38281ff4c3aSAndreas Gohr $result = $this->hlp->Query()->topgroupedit($this->tlimit, $this->start, 150, true); 38381ff4c3aSAndreas Gohr $this->html_resulttable($result, '', 150); 38481ff4c3aSAndreas Gohr } 38581ff4c3aSAndreas Gohr 386bd4217d3SAndreas Gohr function html_os() { 387878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 388878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 3896b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 3902507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 391bd4217d3SAndreas Gohr } 392bd4217d3SAndreas Gohr 3939da6395dSAndreas Gohr function html_referer() { 3946b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 3952812a751SAndreas Gohr 3962812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 3972812a751SAndreas Gohr 39894023548SAndreas Gohr if($all) { 3990863c19cSAndreas Gohr printf( 4000863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 401878be5c9SAndreas Gohr $all, $result['direct'], (100 * $result['direct'] / $all), 4022812a751SAndreas Gohr $result['search'], (100 * $result['search'] / $all), $result['external'], 4030863c19cSAndreas Gohr (100 * $result['external'] / $all) 4040863c19cSAndreas Gohr ); 40594023548SAndreas Gohr } 4062812a751SAndreas Gohr 4076b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 4082507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 4099da6395dSAndreas Gohr } 4109da6395dSAndreas Gohr 411e7a2f1e0SAndreas Gohr function html_newreferer() { 412878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 413e7a2f1e0SAndreas Gohr 4146b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 4152507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 416e7a2f1e0SAndreas Gohr } 417e7a2f1e0SAndreas Gohr 418e25286daSAndreas Gohr function html_outlinks() { 419878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 4206b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 421e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 422e25286daSAndreas Gohr } 423e25286daSAndreas Gohr 42412dcdeccSAndreas Gohr function html_searchphrases() { 425878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 4265bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 42712dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 42812dcdeccSAndreas Gohr } 42912dcdeccSAndreas Gohr 43012dcdeccSAndreas Gohr function html_searchwords() { 431878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 4325bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 4335bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4345bccfe87SAndreas Gohr } 4355bccfe87SAndreas Gohr 4365bccfe87SAndreas Gohr function html_internalsearchphrases() { 437878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 4385bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 4395bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 4405bccfe87SAndreas Gohr } 4415bccfe87SAndreas Gohr 4425bccfe87SAndreas Gohr function html_internalsearchwords() { 443878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 4445bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 44512dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 44612dcdeccSAndreas Gohr } 44712dcdeccSAndreas Gohr 44812dcdeccSAndreas Gohr function html_searchengines() { 449878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 45025b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 4516b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 45212dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 45312dcdeccSAndreas Gohr } 45412dcdeccSAndreas Gohr 455c73e16f1SAndreas Gohr function html_resolution() { 45625446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 45725446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 458307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 459307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 46025446aa2SAndreas Gohr } 461307baf3fSAndreas Gohr 46225446aa2SAndreas Gohr function html_viewport() { 46325446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 46425446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 46525446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 46625446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 467c73e16f1SAndreas Gohr } 4689da6395dSAndreas Gohr 46933a136e5SAndreas Gohr function html_seenusers() { 47033a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 47133a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 47233a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 47333a136e5SAndreas Gohr } 47433a136e5SAndreas Gohr 47514d99ec0SAndreas Gohr /** 47614d99ec0SAndreas Gohr * Display a result in a HTML table 47714d99ec0SAndreas Gohr */ 4782507f8e0SAndreas Gohr function html_resulttable($result, $header = '', $pager = 0) { 479*56f647ddSAndreas Gohr echo '<table class="inline">'; 4802812a751SAndreas Gohr if(is_array($header)) { 48114d99ec0SAndreas Gohr echo '<tr>'; 48214d99ec0SAndreas Gohr foreach($header as $h) { 48314d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 48414d99ec0SAndreas Gohr } 48514d99ec0SAndreas Gohr echo '</tr>'; 4862812a751SAndreas Gohr } 48714d99ec0SAndreas Gohr 4882507f8e0SAndreas Gohr $count = 0; 4892ee939eeSAndreas Gohr if(is_array($result)) foreach($result as $row) { 49014d99ec0SAndreas Gohr echo '<tr>'; 49114d99ec0SAndreas Gohr foreach($row as $k => $v) { 492f3818071SAndreas Gohr if($k == 'res_x') continue; 493f3818071SAndreas Gohr if($k == 'res_y') continue; 494f3818071SAndreas Gohr 4952812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 49614d99ec0SAndreas Gohr if($k == 'page') { 49714d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 49814d99ec0SAndreas Gohr echo hsc($v); 49914d99ec0SAndreas Gohr echo '</a>'; 5001664ba1dSAndreas Gohr } elseif($k == 'media') { 5011664ba1dSAndreas Gohr echo '<a href="' . ml($v) . '" class="wikilink1">'; 5021664ba1dSAndreas Gohr echo hsc($v); 5031664ba1dSAndreas Gohr echo '</a>'; 5041664ba1dSAndreas Gohr } elseif($k == 'filesize') { 5051664ba1dSAndreas Gohr echo filesize_h($v); 50614d99ec0SAndreas Gohr } elseif($k == 'url') { 50754f6c432SAndreas Gohr $url = hsc($v); 50883b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 5092812a751SAndreas Gohr if(strlen($url) > 45) { 5102812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 51154f6c432SAndreas Gohr } 51214d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 51354f6c432SAndreas Gohr echo $url; 51414d99ec0SAndreas Gohr echo '</a>'; 5155bccfe87SAndreas Gohr } elseif($k == 'ilookup') { 5165bccfe87SAndreas Gohr echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>'; 51729dea504SAndreas Gohr } elseif($k == 'lookup') { 51829dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 51913a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 52029dea504SAndreas Gohr echo '</a> '; 52129dea504SAndreas Gohr 52229dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 52313a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 52429dea504SAndreas Gohr echo '</a> '; 52529dea504SAndreas Gohr 52613a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 52713a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 52829dea504SAndreas Gohr echo '</a> '; 52929dea504SAndreas Gohr 53012dcdeccSAndreas Gohr } elseif($k == 'engine') { 53113a86c14SAndreas Gohr include_once(dirname(__FILE__) . '/inc/searchengines.php'); 53213a86c14SAndreas Gohr if(isset($SEARCHENGINEINFO[$v])) { 53313a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 53413a86c14SAndreas Gohr } else { 53513a86c14SAndreas Gohr echo hsc(ucwords($v)); 53613a86c14SAndreas Gohr } 53713a86c14SAndreas Gohr } elseif($k == 'eflag') { 53813a86c14SAndreas Gohr $this->html_icon('search', $v); 53975fa767dSAndreas Gohr } elseif($k == 'bflag') { 54013a86c14SAndreas Gohr $this->html_icon('browser', $v); 541bd4217d3SAndreas Gohr } elseif($k == 'osflag') { 54213a86c14SAndreas Gohr $this->html_icon('os', $v); 54375fa767dSAndreas Gohr } elseif($k == 'cflag') { 54413a86c14SAndreas Gohr $this->html_icon('flags', $v); 54514d99ec0SAndreas Gohr } elseif($k == 'html') { 54614d99ec0SAndreas Gohr echo $v; 54714d99ec0SAndreas Gohr } else { 54814d99ec0SAndreas Gohr echo hsc($v); 54914d99ec0SAndreas Gohr } 55014d99ec0SAndreas Gohr echo '</td>'; 55114d99ec0SAndreas Gohr } 55214d99ec0SAndreas Gohr echo '</tr>'; 5532507f8e0SAndreas Gohr 5542507f8e0SAndreas Gohr if($pager && ($count == $pager)) break; 5552507f8e0SAndreas Gohr $count++; 55614d99ec0SAndreas Gohr } 55714d99ec0SAndreas Gohr echo '</table>'; 5582507f8e0SAndreas Gohr 5592507f8e0SAndreas Gohr if($pager) $this->html_pager($pager, count($result) > $pager); 5601878f16fSAndreas Gohr } 5611878f16fSAndreas Gohr 56213a86c14SAndreas Gohr function html_icon($type, $value) { 56313a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 5649bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 56513a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 566dffb869bSAndreas Gohr if($type == 'flags') { 567dffb869bSAndreas Gohr $w = 18; 568dffb869bSAndreas Gohr $h = 12; 569dffb869bSAndreas Gohr } else { 570dffb869bSAndreas Gohr $w = 16; 571dffb869bSAndreas Gohr $h = 16; 572dffb869bSAndreas Gohr } 57313a86c14SAndreas Gohr if(file_exists(DOKU_INC . $file)) { 574dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 57513a86c14SAndreas Gohr } 57613a86c14SAndreas Gohr } 5771878f16fSAndreas Gohr} 578