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 { 17*33a136e5SAndreas Gohr /** @var string the currently selected page */ 18a901d721SAndreas Gohr protected $opt = ''; 19*33a136e5SAndreas Gohr 20*33a136e5SAndreas Gohr /** @var string from date in YYYY-MM-DD */ 21a901d721SAndreas Gohr protected $from = ''; 22*33a136e5SAndreas Gohr /** @var string to date in YYYY-MM-DD */ 23a901d721SAndreas Gohr protected $to = ''; 24*33a136e5SAndreas Gohr /** @var int Offset to use when displaying paged data */ 25*33a136e5SAndreas Gohr protected $start = 0; 26*33a136e5SAndreas Gohr 27*33a136e5SAndreas Gohr /** @var string MySQL timelimit statement */ 28a901d721SAndreas Gohr protected $tlimit = ''; 29a901d721SAndreas Gohr 30*33a136e5SAndreas Gohr /** @var helper_plugin_statistics */ 31*33a136e5SAndreas Gohr protected $hlp; 32*33a136e5SAndreas Gohr 33a901d721SAndreas Gohr /** 34a901d721SAndreas Gohr * Available statistic pages 35a901d721SAndreas Gohr */ 360863c19cSAndreas Gohr protected $pages = array( 370863c19cSAndreas Gohr 'dashboard', 'page', 'referer', 'newreferer', 385bccfe87SAndreas Gohr 'outlinks', 'searchengines', 'searchphrases', 395bccfe87SAndreas Gohr 'searchwords', 'internalsearchphrases', 405bccfe87SAndreas Gohr 'internalsearchwords', 'browsers', 'os', 41*33a136e5SAndreas Gohr 'countries', 'resolution', 'viewport', 42*33a136e5SAndreas Gohr 'seenusers' 430863c19cSAndreas Gohr ); 441878f16fSAndreas Gohr 451878f16fSAndreas Gohr /** 466b6f8822SAndreas Gohr * Initialize the helper 476b6f8822SAndreas Gohr */ 486b6f8822SAndreas Gohr public function __construct() { 496b6f8822SAndreas Gohr $this->hlp = plugin_load('helper', 'statistics'); 506b6f8822SAndreas Gohr } 516b6f8822SAndreas Gohr 526b6f8822SAndreas Gohr /** 531878f16fSAndreas Gohr * Access for managers allowed 541878f16fSAndreas Gohr */ 556b6f8822SAndreas Gohr public function forAdminOnly() { 561878f16fSAndreas Gohr return false; 571878f16fSAndreas Gohr } 581878f16fSAndreas Gohr 591878f16fSAndreas Gohr /** 601878f16fSAndreas Gohr * return sort order for position in admin menu 611878f16fSAndreas Gohr */ 626b6f8822SAndreas Gohr public function getMenuSort() { 636b6f8822SAndreas Gohr return 350; 641878f16fSAndreas Gohr } 651878f16fSAndreas Gohr 661878f16fSAndreas Gohr /** 671878f16fSAndreas Gohr * handle user request 681878f16fSAndreas Gohr */ 696b6f8822SAndreas Gohr public function handle() { 70264f1744SAndreas Gohr $this->opt = preg_replace('/[^a-z]+/', '', $_REQUEST['opt']); 71a901d721SAndreas Gohr if(!in_array($this->opt, $this->pages)) $this->opt = 'dashboard'; 72a901d721SAndreas Gohr 7395eb68e6SAndreas Gohr $this->start = (int) $_REQUEST['s']; 74e8699bceSAndreas Gohr $this->setTimeframe($_REQUEST['f'], $_REQUEST['t']); 75e8699bceSAndreas Gohr } 7695eb68e6SAndreas Gohr 77e8699bceSAndreas Gohr /** 78e8699bceSAndreas Gohr * set limit clause 79e8699bceSAndreas Gohr */ 806b6f8822SAndreas Gohr public function setTimeframe($from, $to) { 813bf3de81SAndreas Gohr $this->tlimit = $this->hlp->Query()->mktlimit($from, $to); 82e8699bceSAndreas Gohr $this->from = $from; 83e8699bceSAndreas Gohr $this->to = $to; 841878f16fSAndreas Gohr } 851878f16fSAndreas Gohr 861878f16fSAndreas Gohr /** 8779b4a855SAndreas Gohr * Output the Statistics 881878f16fSAndreas Gohr */ 891878f16fSAndreas Gohr function html() { 901d2d78ccSAndreas Gohr echo '<div id="plugin__statistics">'; 910c3b1e44SAndreas Gohr echo '<h1>' . $this->getLang('menu') . '</h1>'; 92264f1744SAndreas Gohr $this->html_timeselect(); 93441bfb8eSAndreas Gohr tpl_flush(); 94264f1744SAndreas Gohr 9579b4a855SAndreas Gohr $method = 'html_' . $this->opt; 9679b4a855SAndreas Gohr if(method_exists($this, $method)) { 97a901d721SAndreas Gohr echo '<div class="plg_stats_' . $this->opt . '">'; 98a901d721SAndreas Gohr echo '<h2>' . $this->getLang($this->opt) . '</h2>'; 9979b4a855SAndreas Gohr $this->$method(); 100a901d721SAndreas Gohr echo '</div>'; 10114d99ec0SAndreas Gohr } 1021d2d78ccSAndreas Gohr echo '</div>'; 10314d99ec0SAndreas Gohr } 10414d99ec0SAndreas Gohr 1056b6f8822SAndreas Gohr /** 1066b6f8822SAndreas Gohr * Return the TOC 1076b6f8822SAndreas Gohr * 1086b6f8822SAndreas Gohr * @return array 1096b6f8822SAndreas Gohr */ 11047ffcf7dSAndreas Gohr function getTOC() { 11147ffcf7dSAndreas Gohr $toc = array(); 112a901d721SAndreas Gohr foreach($this->pages as $page) { 11347ffcf7dSAndreas Gohr $toc[] = array( 11447ffcf7dSAndreas Gohr 'link' => '?do=admin&page=statistics&opt=' . $page . '&f=' . $this->from . '&t=' . $this->to, 11547ffcf7dSAndreas Gohr 'title' => $this->getLang($page), 11647ffcf7dSAndreas Gohr 'level' => 1, 11747ffcf7dSAndreas Gohr 'type' => 'ul' 11847ffcf7dSAndreas Gohr ); 11947ffcf7dSAndreas Gohr } 12047ffcf7dSAndreas Gohr return $toc; 1219da6395dSAndreas Gohr } 1229da6395dSAndreas Gohr 123dc7b1e5eSAndreas Gohr function html_graph($name, $width, $height) { 124dc7b1e5eSAndreas Gohr $url = DOKU_BASE . 'lib/plugins/statistics/img.php?img=' . $name . 125dc7b1e5eSAndreas Gohr '&f=' . $this->from . '&t=' . $this->to; 126dc7b1e5eSAndreas Gohr echo '<img src="' . $url . '" class="graph" width="' . $width . '" height="' . $height . '"/>'; 127dc7b1e5eSAndreas Gohr } 128dc7b1e5eSAndreas Gohr 1296b6f8822SAndreas Gohr /** 1306b6f8822SAndreas Gohr * Outputs pagination links 1316b6f8822SAndreas Gohr * 132*33a136e5SAndreas Gohr * @param int $limit 133*33a136e5SAndreas Gohr * @param int $next 1346b6f8822SAndreas Gohr */ 1352507f8e0SAndreas Gohr function html_pager($limit, $next) { 1362507f8e0SAndreas Gohr echo '<div class="plg_stats_pager">'; 1372507f8e0SAndreas Gohr 1382507f8e0SAndreas Gohr if($this->start > 0) { 1392507f8e0SAndreas Gohr $go = max($this->start - $limit, 0); 140d43cd6e0SAndreas 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>'; 1412507f8e0SAndreas Gohr } 1422507f8e0SAndreas Gohr 1432507f8e0SAndreas Gohr if($next) { 1442507f8e0SAndreas Gohr $go = $this->start + $limit; 145d43cd6e0SAndreas 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>'; 1462507f8e0SAndreas Gohr } 1472507f8e0SAndreas Gohr echo '</div>'; 1482507f8e0SAndreas Gohr } 1492507f8e0SAndreas Gohr 150264f1744SAndreas Gohr /** 151264f1744SAndreas Gohr * Print the time selection menu 152264f1744SAndreas Gohr */ 15314d99ec0SAndreas Gohr function html_timeselect() { 1546985b606SAndreas Gohr $today = date('Y-m-d'); 1556985b606SAndreas Gohr $last1 = date('Y-m-d', time() - (60 * 60 * 24)); 1566985b606SAndreas Gohr $last7 = date('Y-m-d', time() - (60 * 60 * 24 * 7)); 1576985b606SAndreas Gohr $last30 = date('Y-m-d', time() - (60 * 60 * 24 * 30)); 15814d99ec0SAndreas Gohr 159264f1744SAndreas Gohr echo '<div class="plg_stats_timeselect">'; 1606985b606SAndreas Gohr echo '<span>' . $this->getLang('time_select') . '</span> '; 161264f1744SAndreas Gohr 162264f1744SAndreas Gohr echo '<form action="" method="get">'; 163264f1744SAndreas Gohr echo '<input type="hidden" name="do" value="admin" />'; 164264f1744SAndreas Gohr echo '<input type="hidden" name="page" value="statistics" />'; 165264f1744SAndreas Gohr echo '<input type="hidden" name="opt" value="' . $this->opt . '" />'; 166264f1744SAndreas Gohr echo '<input type="text" name="f" value="' . $this->from . '" class="edit" />'; 167264f1744SAndreas Gohr echo '<input type="text" name="t" value="' . $this->to . '" class="edit" />'; 168264f1744SAndreas Gohr echo '<input type="submit" value="go" class="button" />'; 16914d99ec0SAndreas Gohr echo '</form>'; 170264f1744SAndreas Gohr 1716985b606SAndreas Gohr echo '<ul>'; 1726985b606SAndreas Gohr foreach(array('today', 'last1', 'last7', 'last30') as $time) { 1736985b606SAndreas Gohr echo '<li>'; 1746985b606SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=' . $this->opt . '&f=' . $$time . '&t=' . $today . '">'; 1756985b606SAndreas Gohr echo $this->getLang('time_' . $time); 1766985b606SAndreas Gohr echo '</a>'; 1776985b606SAndreas Gohr echo '</li>'; 1786985b606SAndreas Gohr } 1796985b606SAndreas Gohr echo '</ul>'; 1806985b606SAndreas Gohr 181264f1744SAndreas Gohr echo '</div>'; 18214d99ec0SAndreas Gohr } 18314d99ec0SAndreas Gohr 184f5f32cbfSAndreas Gohr /** 185f5f32cbfSAndreas Gohr * Print an introductionary screen 186f5f32cbfSAndreas Gohr */ 18714d99ec0SAndreas Gohr function html_dashboard() { 188878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_dashboard') . '</p>'; 1892812a751SAndreas Gohr 1902812a751SAndreas Gohr // general info 1912812a751SAndreas Gohr echo '<div class="plg_stats_top">'; 1926b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 1931d2d78ccSAndreas Gohr 1941d2d78ccSAndreas Gohr echo '<ul class="left">'; 195*33a136e5SAndreas Gohr foreach(array('pageviews', 'sessions', 'visitors', 'users', 'logins', 'current') as $name) { 196eabe0d07SAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 197eabe0d07SAndreas Gohr } 1982812a751SAndreas Gohr echo '</ul>'; 1991d2d78ccSAndreas Gohr 2001d2d78ccSAndreas Gohr echo '<ul class="left">'; 2011d2d78ccSAndreas Gohr foreach(array('bouncerate', 'timespent', 'avgpages', 'newvisitors', 'registrations') as $name) { 2021d2d78ccSAndreas Gohr echo '<li><div class="li">' . sprintf($this->getLang('dash_' . $name), $result[$name]) . '</div></li>'; 2031d2d78ccSAndreas Gohr } 2041d2d78ccSAndreas Gohr echo '</ul>'; 2051d2d78ccSAndreas Gohr 206259897e1SAndreas Gohr $this->html_graph('dashboardviews', 700, 280); 207259897e1SAndreas Gohr $this->html_graph('dashboardwiki', 700, 280); 2082812a751SAndreas Gohr echo '</div>'; 2092812a751SAndreas Gohr 21087d5e44bSAndreas Gohr // top pages today 211264f1744SAndreas Gohr echo '<div>'; 212dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_mostpopular') . '</h2>'; 2136b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 15); 2142812a751SAndreas Gohr $this->html_resulttable($result); 215d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=page&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 216264f1744SAndreas Gohr echo '</div>'; 21787d5e44bSAndreas Gohr 21887d5e44bSAndreas Gohr // top referer today 219264f1744SAndreas Gohr echo '<div>'; 220dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_newincoming') . '</h2>'; 2216b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 15); 2222812a751SAndreas Gohr $this->html_resulttable($result); 223d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=newreferer&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 224264f1744SAndreas Gohr echo '</div>'; 22554f6c432SAndreas Gohr 22629dea504SAndreas Gohr // top searches today 227264f1744SAndreas Gohr echo '<div>'; 228dc7b1e5eSAndreas Gohr echo '<h2>' . $this->getLang('dash_topsearch') . '</h2>'; 22912b59231SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 15); 23029dea504SAndreas Gohr $this->html_resulttable($result); 231d43cd6e0SAndreas Gohr echo '<a href="?do=admin&page=statistics&opt=searchphrases&f=' . $this->from . '&t=' . $this->to . '" class="more button">' . $this->getLang('more') . '</a>'; 232264f1744SAndreas Gohr echo '</div>'; 23314d99ec0SAndreas Gohr } 23414d99ec0SAndreas Gohr 235c67866d1SAndreas Gohr function html_countries() { 236878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_countries') . '</p>'; 237878be5c9SAndreas Gohr $this->html_graph('countries', 400, 200); 2386b6f8822SAndreas Gohr $result = $this->hlp->Query()->countries($this->tlimit, $this->start, 150); 2392507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2409da6395dSAndreas Gohr } 2419da6395dSAndreas Gohr 2429da6395dSAndreas Gohr function html_page() { 243878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_page') . '</p>'; 2446b6f8822SAndreas Gohr $result = $this->hlp->Query()->pages($this->tlimit, $this->start, 150); 2452507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2469da6395dSAndreas Gohr } 2479da6395dSAndreas Gohr 2484f41a2ccSAndreas Gohr function html_browsers() { 249878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_browsers') . '</p>'; 250878be5c9SAndreas Gohr $this->html_graph('browsers', 400, 200); 2516b6f8822SAndreas Gohr $result = $this->hlp->Query()->browsers($this->tlimit, $this->start, 150, true); 2522507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 25375fa767dSAndreas Gohr } 25475fa767dSAndreas Gohr 255bd4217d3SAndreas Gohr function html_os() { 256878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_os') . '</p>'; 257878be5c9SAndreas Gohr $this->html_graph('os', 400, 200); 2586b6f8822SAndreas Gohr $result = $this->hlp->Query()->os($this->tlimit, $this->start, 150, true); 2592507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 260bd4217d3SAndreas Gohr } 261bd4217d3SAndreas Gohr 2629da6395dSAndreas Gohr function html_referer() { 2636b6f8822SAndreas Gohr $result = $this->hlp->Query()->aggregate($this->tlimit); 2642812a751SAndreas Gohr 2652812a751SAndreas Gohr $all = $result['search'] + $result['external'] + $result['direct']; 2662812a751SAndreas Gohr 26794023548SAndreas Gohr if($all) { 2680863c19cSAndreas Gohr printf( 2690863c19cSAndreas Gohr '<p>' . $this->getLang('intro_referer') . '</p>', 270878be5c9SAndreas Gohr $all, $result['direct'], (100 * $result['direct'] / $all), 2712812a751SAndreas Gohr $result['search'], (100 * $result['search'] / $all), $result['external'], 2720863c19cSAndreas Gohr (100 * $result['external'] / $all) 2730863c19cSAndreas Gohr ); 27494023548SAndreas Gohr } 2752812a751SAndreas Gohr 2766b6f8822SAndreas Gohr $result = $this->hlp->Query()->referer($this->tlimit, $this->start, 150); 2772507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 2789da6395dSAndreas Gohr } 2799da6395dSAndreas Gohr 280e7a2f1e0SAndreas Gohr function html_newreferer() { 281878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_newreferer') . '</p>'; 282e7a2f1e0SAndreas Gohr 2836b6f8822SAndreas Gohr $result = $this->hlp->Query()->newreferer($this->tlimit, $this->start, 150); 2842507f8e0SAndreas Gohr $this->html_resulttable($result, '', 150); 285e7a2f1e0SAndreas Gohr } 286e7a2f1e0SAndreas Gohr 287e25286daSAndreas Gohr function html_outlinks() { 288878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_outlinks') . '</p>'; 2896b6f8822SAndreas Gohr $result = $this->hlp->Query()->outlinks($this->tlimit, $this->start, 150); 290e25286daSAndreas Gohr $this->html_resulttable($result, '', 150); 291e25286daSAndreas Gohr } 292e25286daSAndreas Gohr 29312dcdeccSAndreas Gohr function html_searchphrases() { 294878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchphrases') . '</p>'; 2955bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(true, $this->tlimit, $this->start, 150); 29612dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 29712dcdeccSAndreas Gohr } 29812dcdeccSAndreas Gohr 29912dcdeccSAndreas Gohr function html_searchwords() { 300878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchwords') . '</p>'; 3015bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(true, $this->tlimit, $this->start, 150); 3025bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3035bccfe87SAndreas Gohr } 3045bccfe87SAndreas Gohr 3055bccfe87SAndreas Gohr function html_internalsearchphrases() { 306878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchphrases') . '</p>'; 3075bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchphrases(false, $this->tlimit, $this->start, 150); 3085bccfe87SAndreas Gohr $this->html_resulttable($result, '', 150); 3095bccfe87SAndreas Gohr } 3105bccfe87SAndreas Gohr 3115bccfe87SAndreas Gohr function html_internalsearchwords() { 312878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_internalsearchwords') . '</p>'; 3135bccfe87SAndreas Gohr $result = $this->hlp->Query()->searchwords(false, $this->tlimit, $this->start, 150); 31412dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 31512dcdeccSAndreas Gohr } 31612dcdeccSAndreas Gohr 31712dcdeccSAndreas Gohr function html_searchengines() { 318878be5c9SAndreas Gohr echo '<p>' . $this->getLang('intro_searchengines') . '</p>'; 31925b71d4bSAndreas Gohr $this->html_graph('searchengines', 400, 200); 3206b6f8822SAndreas Gohr $result = $this->hlp->Query()->searchengines($this->tlimit, $this->start, 150); 32112dcdeccSAndreas Gohr $this->html_resulttable($result, '', 150); 32212dcdeccSAndreas Gohr } 32312dcdeccSAndreas Gohr 324c73e16f1SAndreas Gohr function html_resolution() { 32525446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_resolution') . '</p>'; 32625446aa2SAndreas Gohr $this->html_graph('resolution', 650, 490); 327307baf3fSAndreas Gohr $result = $this->hlp->Query()->resolution($this->tlimit, $this->start, 150); 328307baf3fSAndreas Gohr $this->html_resulttable($result, '', 150); 32925446aa2SAndreas Gohr } 330307baf3fSAndreas Gohr 33125446aa2SAndreas Gohr function html_viewport() { 33225446aa2SAndreas Gohr echo '<p>' . $this->getLang('intro_viewport') . '</p>'; 33325446aa2SAndreas Gohr $this->html_graph('viewport', 650, 490); 33425446aa2SAndreas Gohr $result = $this->hlp->Query()->viewport($this->tlimit, $this->start, 150); 33525446aa2SAndreas Gohr $this->html_resulttable($result, '', 150); 336c73e16f1SAndreas Gohr } 3379da6395dSAndreas Gohr 338*33a136e5SAndreas Gohr function html_seenusers() { 339*33a136e5SAndreas Gohr echo '<p>' . $this->getLang('intro_seenusers') . '</p>'; 340*33a136e5SAndreas Gohr $result = $this->hlp->Query()->seenusers($this->tlimit, $this->start, 150); 341*33a136e5SAndreas Gohr $this->html_resulttable($result, '', 150); 342*33a136e5SAndreas Gohr } 343*33a136e5SAndreas Gohr 34414d99ec0SAndreas Gohr /** 34514d99ec0SAndreas Gohr * Display a result in a HTML table 34614d99ec0SAndreas Gohr */ 3472507f8e0SAndreas Gohr function html_resulttable($result, $header = '', $pager = 0) { 34814d99ec0SAndreas Gohr echo '<table>'; 3492812a751SAndreas Gohr if(is_array($header)) { 35014d99ec0SAndreas Gohr echo '<tr>'; 35114d99ec0SAndreas Gohr foreach($header as $h) { 35214d99ec0SAndreas Gohr echo '<th>' . hsc($h) . '</th>'; 35314d99ec0SAndreas Gohr } 35414d99ec0SAndreas Gohr echo '</tr>'; 3552812a751SAndreas Gohr } 35614d99ec0SAndreas Gohr 3572507f8e0SAndreas Gohr $count = 0; 3582ee939eeSAndreas Gohr if(is_array($result)) foreach($result as $row) { 35914d99ec0SAndreas Gohr echo '<tr>'; 36014d99ec0SAndreas Gohr foreach($row as $k => $v) { 361f3818071SAndreas Gohr if($k == 'res_x') continue; 362f3818071SAndreas Gohr if($k == 'res_y') continue; 363f3818071SAndreas Gohr 3642812a751SAndreas Gohr echo '<td class="plg_stats_X' . $k . '">'; 36514d99ec0SAndreas Gohr if($k == 'page') { 36614d99ec0SAndreas Gohr echo '<a href="' . wl($v) . '" class="wikilink1">'; 36714d99ec0SAndreas Gohr echo hsc($v); 36814d99ec0SAndreas Gohr echo '</a>'; 36914d99ec0SAndreas Gohr } elseif($k == 'url') { 37054f6c432SAndreas Gohr $url = hsc($v); 37183b63546SAndreas Gohr $url = preg_replace('/^https?:\/\/(www\.)?/', '', $url); 3722812a751SAndreas Gohr if(strlen($url) > 45) { 3732812a751SAndreas Gohr $url = substr($url, 0, 30) . ' … ' . substr($url, -15); 37454f6c432SAndreas Gohr } 37514d99ec0SAndreas Gohr echo '<a href="' . $v . '" class="urlextern">'; 37654f6c432SAndreas Gohr echo $url; 37714d99ec0SAndreas Gohr echo '</a>'; 3785bccfe87SAndreas Gohr } elseif($k == 'ilookup') { 3795bccfe87SAndreas Gohr echo '<a href="' . wl('', array('id' => $v, 'do' => 'search')) . '">Search</a>'; 38029dea504SAndreas Gohr } elseif($k == 'lookup') { 38129dea504SAndreas Gohr echo '<a href="http://www.google.com/search?q=' . rawurlencode($v) . '">'; 38213a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/google.png" alt="Google" border="0" />'; 38329dea504SAndreas Gohr echo '</a> '; 38429dea504SAndreas Gohr 38529dea504SAndreas Gohr echo '<a href="http://search.yahoo.com/search?p=' . rawurlencode($v) . '">'; 38613a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/yahoo.png" alt="Yahoo!" border="0" />'; 38729dea504SAndreas Gohr echo '</a> '; 38829dea504SAndreas Gohr 38913a86c14SAndreas Gohr echo '<a href="http://www.bing.com/search?q=' . rawurlencode($v) . '">'; 39013a86c14SAndreas Gohr echo '<img src="' . DOKU_BASE . 'lib/plugins/statistics/ico/search/bing.png" alt="Bing" border="0" />'; 39129dea504SAndreas Gohr echo '</a> '; 39229dea504SAndreas Gohr 39312dcdeccSAndreas Gohr } elseif($k == 'engine') { 39413a86c14SAndreas Gohr include_once(dirname(__FILE__) . '/inc/searchengines.php'); 39513a86c14SAndreas Gohr if(isset($SEARCHENGINEINFO[$v])) { 39613a86c14SAndreas Gohr echo '<a href="' . $SEARCHENGINEINFO[$v][1] . '">' . $SEARCHENGINEINFO[$v][0] . '</a>'; 39713a86c14SAndreas Gohr } else { 39813a86c14SAndreas Gohr echo hsc(ucwords($v)); 39913a86c14SAndreas Gohr } 40013a86c14SAndreas Gohr } elseif($k == 'eflag') { 40113a86c14SAndreas Gohr $this->html_icon('search', $v); 40275fa767dSAndreas Gohr } elseif($k == 'bflag') { 40313a86c14SAndreas Gohr $this->html_icon('browser', $v); 404bd4217d3SAndreas Gohr } elseif($k == 'osflag') { 40513a86c14SAndreas Gohr $this->html_icon('os', $v); 40675fa767dSAndreas Gohr } elseif($k == 'cflag') { 40713a86c14SAndreas Gohr $this->html_icon('flags', $v); 40814d99ec0SAndreas Gohr } elseif($k == 'html') { 40914d99ec0SAndreas Gohr echo $v; 41014d99ec0SAndreas Gohr } else { 41114d99ec0SAndreas Gohr echo hsc($v); 41214d99ec0SAndreas Gohr } 41314d99ec0SAndreas Gohr echo '</td>'; 41414d99ec0SAndreas Gohr } 41514d99ec0SAndreas Gohr echo '</tr>'; 4162507f8e0SAndreas Gohr 4172507f8e0SAndreas Gohr if($pager && ($count == $pager)) break; 4182507f8e0SAndreas Gohr $count++; 41914d99ec0SAndreas Gohr } 42014d99ec0SAndreas Gohr echo '</table>'; 4212507f8e0SAndreas Gohr 4222507f8e0SAndreas Gohr if($pager) $this->html_pager($pager, count($result) > $pager); 4231878f16fSAndreas Gohr } 4241878f16fSAndreas Gohr 42513a86c14SAndreas Gohr function html_icon($type, $value) { 42613a86c14SAndreas Gohr $value = strtolower(preg_replace('/[^\w]+/', '', $value)); 4279bb008afSAndreas Gohr $value = str_replace(' ', '_', $value); 42813a86c14SAndreas Gohr $file = 'lib/plugins/statistics/ico/' . $type . '/' . $value . '.png'; 429dffb869bSAndreas Gohr if($type == 'flags') { 430dffb869bSAndreas Gohr $w = 18; 431dffb869bSAndreas Gohr $h = 12; 432dffb869bSAndreas Gohr } else { 433dffb869bSAndreas Gohr $w = 16; 434dffb869bSAndreas Gohr $h = 16; 435dffb869bSAndreas Gohr } 43613a86c14SAndreas Gohr if(file_exists(DOKU_INC . $file)) { 437dffb869bSAndreas Gohr echo '<img src="' . DOKU_BASE . $file . '" alt="' . hsc($value) . '" width="' . $w . '" height="' . $h . '" />'; 43813a86c14SAndreas Gohr } 43913a86c14SAndreas Gohr } 4401878f16fSAndreas Gohr} 441