*/ // 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','viewport'); /** * 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 '
'.$this->getLang('intro_dashboard').'
'; // general info echo ''.$this->getLang('intro_countries').'
'; $this->html_graph('countries',400,200); $result = $this->hlp->Query()->countries($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_page(){ echo ''.$this->getLang('intro_page').'
'; $result = $this->hlp->Query()->pages($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_browsers(){ echo ''.$this->getLang('intro_browsers').'
'; $this->html_graph('browsers',400,200); $result = $this->hlp->Query()->browsers($this->tlimit,$this->start,150,true); $this->html_resulttable($result,'',150); } function html_os(){ echo ''.$this->getLang('intro_os').'
'; $this->html_graph('os',400,200); $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(''.$this->getLang('intro_referer').'
', $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 ''.$this->getLang('intro_newreferer').'
'; $result = $this->hlp->Query()->newreferer($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_outlinks(){ echo ''.$this->getLang('intro_outlinks').'
'; $result = $this->hlp->Query()->outlinks($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchphrases(){ echo ''.$this->getLang('intro_searchphrases').'
'; $result = $this->hlp->Query()->searchphrases(true,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchwords(){ echo ''.$this->getLang('intro_searchwords').'
'; $result = $this->hlp->Query()->searchwords(true,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_internalsearchphrases(){ echo ''.$this->getLang('intro_internalsearchphrases').'
'; $result = $this->hlp->Query()->searchphrases(false,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_internalsearchwords(){ echo ''.$this->getLang('intro_internalsearchwords').'
'; $result = $this->hlp->Query()->searchwords(false,$this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_searchengines(){ echo ''.$this->getLang('intro_searchengines').'
'; $this->html_graph('searchengines',400,200); $result = $this->hlp->Query()->searchengines($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_resolution(){ echo ''.$this->getLang('intro_resolution').'
'; $this->html_graph('resolution',650,490); $result = $this->hlp->Query()->resolution($this->tlimit,$this->start,150); $this->html_resulttable($result,'',150); } function html_viewport(){ echo ''.$this->getLang('intro_viewport').'
'; $this->html_graph('viewport',650,490); $result = $this->hlp->Query()->viewport($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 '| '.hsc($h).' | '; } echo '
|---|
';
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 ' ';
echo ' ';
echo '';
echo ' ';
echo ' ';
echo '';
echo ' ';
echo ' ';
}elseif($k == 'engine'){
include_once(dirname(__FILE__).'/inc/searchengines.php');
if(isset($SEARCHENGINEINFO[$v])){
echo ''.$SEARCHENGINEINFO[$v][0].'';
}else{
echo hsc(ucwords($v));
}
}elseif($k == 'eflag'){
$this->html_icon('search',$v);
}elseif($k == 'bflag'){
$this->html_icon('browser',$v);
}elseif($k == 'osflag'){
$this->html_icon('os',$v);
}elseif($k == 'cflag'){
$this->html_icon('flags',$v);
}elseif($k == 'html'){
echo $v;
}else{
echo hsc($v);
}
echo ' | ';
}
echo '