*/ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_statistics extends DokuWiki_Admin_Plugin { public $dblink = null; protected $opt = ''; protected $from = ''; protected $to = ''; protected $start = ''; protected $tlimit = ''; /** * Available statistic pages */ protected $pages = array('dashboard','page','referer','newreferer', 'outlinks','searchengines','searchphrases', 'searchwords', 'internalsearchphrases', 'internalsearchwords','browsers','os', 'countries','resolution'); /** * Initialize the helper */ public function __construct() { $this->hlp = plugin_load('helper','statistics'); } /** * Access for managers allowed */ public function forAdminOnly(){ return false; } /** * return sort order for position in admin menu */ public function getMenuSort() { return 350; } /** * handle user request */ public function handle() { $this->opt = preg_replace('/[^a-z]+/','',$_REQUEST['opt']); if(!in_array($this->opt,$this->pages)) $this->opt = 'dashboard'; $this->start = (int) $_REQUEST['s']; $this->setTimeframe($_REQUEST['f'],$_REQUEST['t']); } /** * set limit clause */ public function setTimeframe($from,$to){ // fixme add better sanity checking here: $from = preg_replace('/[^\d\-]+/','',$from); $to = preg_replace('/[^\d\-]+/','',$to); if(!$from) $from = date('Y-m-d'); if(!$to) $to = date('Y-m-d'); //setup limit clause $tlimit = "A.dt >= '$from 00:00:00' AND A.dt <= '$to 23:59:59'"; $this->tlimit = $tlimit; $this->from = $from; $this->to = $to; } /** * Output the Statistics */ function html() { echo '

Access Statistics

'; $this->html_timeselect(); $method = 'html_'.$this->opt; if(method_exists($this,$method)){ echo '
'; echo '

'.$this->getLang($this->opt).'

'; $this->$method(); echo '
'; } } /** * Return the TOC * * @return array */ function getTOC(){ $toc = array(); foreach($this->pages as $page){ $toc[] = array( 'link' => '?do=admin&page=statistics&opt='.$page.'&f='.$this->from.'&t='.$this->to, 'title' => $this->getLang($page), 'level' => 1, 'type' => 'ul' ); } return $toc; } /** * Outputs pagination links * * @fixme does this still work? * * @param type $limit * @param type $next */ function html_pager($limit,$next){ echo '
'; if($this->start > 0){ $go = max($this->start - $limit, 0); echo ''; } if($next){ $go = $this->start + $limit; echo ''; } echo '
'; } /** * Print the time selection menu */ function html_timeselect(){ $now = date('Y-m-d'); $yday = date('Y-m-d',time()-(60*60*24)); $week = date('Y-m-d',time()-(60*60*24*7)); $month = date('Y-m-d',time()-(60*60*24*30)); echo '
'; echo 'Select the timeframe:'; echo ''; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'; echo '
'; } /** * Print an introductionary screen */ function html_dashboard(){ echo '

This page gives you a quick overview on what is happening in your Wiki. For detailed lists choose a topic from the list.

'; // general info echo '
'; $result = $this->hlp->Query()->aggregate($this->tlimit); echo ''; echo ''; echo '
'; // top pages today echo '
'; echo '

Most popular pages

'; $result = $this->hlp->Query()->pages($this->tlimit,$this->start,15); $this->html_resulttable($result); echo 'more'; echo '
'; // top referer today echo '
'; echo '

Newest incoming links

'; $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,15); $this->html_resulttable($result); echo 'more'; echo '
'; // top searches today echo '
'; echo '

Top search phrases

'; $result = $this->hlp->Query()->searchphrases($this->tlimit,$this->start,15); $this->html_resulttable($result); echo 'more'; echo '
'; } function html_countries(){ echo ''; $result = $this->hlp->Query()->countries($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_page(){ $result = $this->hlp->Query()->pages($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_browsers(){ echo ''; $result = $this->hlp->Query()->browsers($this->tlimit,$this->start,150,true); $this->html_resulttable($result,'',150); } function html_os(){ $result = $this->hlp->Query()->os($this->tlimit,$this->start,150,true); $this->html_resulttable($result,'',150); } function html_referer(){ $result = $this->hlp->Query()->aggregate($this->tlimit); $all = $result['search']+$result['external']+$result['direct']; if($all){ printf("

Of all %d external visits, %d (%.1f%%) were bookmarked (direct) accesses, %d (%.1f%%) came from search engines and %d (%.1f%%) were referred through links from other pages.

",$all,$result['direct'],(100*$result['direct']/$all), $result['search'],(100*$result['search']/$all),$result['external'], (100*$result['external']/$all)); } $result = $this->hlp->Query()->referer($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_newreferer(){ echo '

The following incoming links where first logged in the selected time frame, and have never been seen before.

'; $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_outlinks(){ $result = $this->hlp->Query()->outlinks($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchphrases(){ $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchwords(){ $result = $this->hlp->Query()->searchwords(true,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_internalsearchphrases(){ $result = $this->hlp->Query()->searchphrases(false,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_internalsearchwords(){ $result = $this->hlp->Query()->searchwords(false,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchengines(){ $result = $this->hlp->Query()->searchengines($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_resolution(){ echo ''; echo '

While the data above gives you some info about the resolution your visitors use, it does not tell you much about about the real size of their browser windows. The graphic below shows the size distribution of the view port (document area) of your visitor\'s browsers. Please note that this data can not be logged in all browsers. Because users may resize their browser window while browsing your site the statistics may be flawed. Take it with a grain of salt.

'; echo ''; $result = $this->hlp->Query()->resolution($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } /** * Display a result in a HTML table */ function html_resulttable($result,$header='',$pager=0){ echo ''; if(is_array($header)){ echo ''; foreach($header as $h){ echo ''; } echo ''; } $count = 0; if(is_array($result)) foreach($result as $row){ echo ''; foreach($row as $k => $v){ echo ''; } echo ''; if($pager && ($count == $pager)) break; $count++; } echo '
'.hsc($h).'
'; if($k == 'page'){ echo ''; echo hsc($v); echo ''; }elseif($k == 'url'){ $url = hsc($v); $url = preg_replace('/^https?:\/\/(www\.)?/','',$url); if(strlen($url) > 45){ $url = substr($url,0,30).' … '.substr($url,-15); } echo ''; echo $url; echo ''; }elseif($k == 'ilookup'){ echo 'Search'; }elseif($k == 'lookup'){ echo ''; echo 'lookup in Google'; echo ' '; echo ''; echo 'lookup in Yahoo'; echo ' '; echo ''; echo 'lookup in MSN Live'; echo ' '; }elseif($k == 'engine'){ include_once(dirname(__FILE__).'/inc/search_engines.php'); echo $SearchEnginesHashLib[$v]; }elseif($k == 'bflag'){ echo ''.hsc($v).''; }elseif($k == 'osflag'){ echo ''.hsc($v).''; }elseif($k == 'cflag'){ echo ''.hsc($v).''; }elseif($k == 'html'){ echo $v; }else{ echo hsc($v); } echo '
'; if($pager) $this->html_pager($pager,count($result) > $pager); } }