*/ if(!defined('DOKU_INC')) die(); require_once(DOKU_PLUGIN.'admin.php'); /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_quickstats extends DokuWiki_Admin_Plugin { private $output = ''; private $helper; private $cache; private $deletions; private $to_confirm; private $cc_arrays; private $countries; private $user_agents; private $meta_path; private $page_totals; private $uniqIPTotal; private $uniqIPCurrent; private $page_accessesTotal=0; private $page_accessesCurrent=0; private $script_max_time = 0; function __construct() { $this->helper = $this->loadHelper('quickstats', true); $this->cache = $this->helper->getCache(); $this->cc_arrays = $this->helper->get_cc_arrays(); $this->meta_path = $this->helper->metaFilePath(true) ; $this->page_totals = unserialize(io_readFile($this->meta_path . 'page_totals.ser')); if(!$this->page_totals) $this->page_totals = array(); if(!empty($this->page_totals)) { foreach($this->page_totals as $ttl) { $this->page_accessesTotal+=$ttl; $this->page_accessesCurrent=$ttl; } $this->misc_data_setup(); $this->uniq_ip(); } //$this->script_max_time = ini_get('max_execution_time'); $this->script_max_time = $this->getConf('max_exec_time') ? $this->getConf('max_exec_time') : 60; } /* * Create a list of countries accessed during last 6 months, for countries Select */ function misc_data_setup() { $this->countries = array(); $country_codes = array(); $this->user_agents = array(); $data_dirs = array_reverse(array_keys($this->page_totals)); if(count($data_dirs) > 6) { $data_dirs = array_slice($data_dirs,0,6); } $ns_prefix = "quickstats:"; foreach($data_dirs as $dir) { $ns = $ns_prefix . $dir . ':'; $misc_data_file = metaFN($ns . 'misc_data' , '.ser'); $misc_data = unserialize(io_readFile($misc_data_file,false)); if(!empty($misc_data)) { if(!empty($misc_data['country'])) { $country_codes = array_merge ($country_codes, array_keys($misc_data['country'])); } if(!empty($misc_data['browser'])) { $this->user_agents = array_merge ($this->user_agents, array_keys($misc_data['browser'])); // $this->user_agents = array_merge ($this->user_agents, array_keys($misc_data['version'])); } } } foreach($country_codes as $cc) { if($cc) { $this->countries[$cc]=$this->cc_arrays->get_country_name($cc) ; } } asort($this->countries); $this->user_agents = array_unique($this->user_agents); natcasesort($this->user_agents); } function uniq_ip() { $dirs = array_keys($this->page_totals); $current_dir = array_pop($dirs); $ns_prefix = "quickstats:"; $uniq_data_file = metaFN($ns_prefix . 'uniq_ip' , '.ser'); if(file_exists($uniq_data_file) && !$this->getConf('rebuild_uip')) { $uniq_data = unserialize(io_readFile($uniq_data_file,false)); } else if(count($dirs) > 0) { $uniq_data = array(); foreach($dirs as $dir) { $ns = $ns_prefix . $dir . ':'; $ip_file = metaFN($ns . 'ip' , '.ser'); $ip_data = unserialize(io_readFile($ip_file,false)); if(empty($ip_data)) { $ip_data = array(); } else { unset($ip_data['uniq']); } $ip_data = array_keys($ip_data); $uniq_data = array_merge ($uniq_data , $ip_data); } unset($uniq_data['uniq']); unset($uniq_data['last']); $uniq_data = array_unique($uniq_data); $uniq_data['uniq'] = count($uniq_data); $uniq_data['last'] = $dir; io_saveFile($uniq_data_file,serialize($uniq_data)); } else { $uniq_data = array(); } $ns = $ns_prefix . $current_dir . ':'; $ip_file = metaFN($ns . 'ip' , '.ser'); $ip_data = unserialize(io_readFile($ip_file,false)); $this->uniqIPCurrent=$ip_data['uniq']; $uniq_data = array_unique(array_merge ($uniq_data , array_keys($ip_data))); $uniq_data['uniq'] = count($uniq_data); $this->uniqIPTotal = $uniq_data['uniq']; if($current_dir != $uniq_data['last'] ) { $uniq_data['last'] = $current_dir; io_saveFile($uniq_data_file,serialize($uniq_data)); } } /** * handle user request */ function handle() { if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do $this->output =""; $this->deletions = array(); if (!checkSecurityToken()) return; if (!is_array($_REQUEST['cmd'])) return; switch (key($_REQUEST['cmd'])) { case 'delete' : if(isset($_REQUEST['del']) && is_array($_REQUEST['del']) && !empty($_REQUEST['del'])) { $this->deletions = $_REQUEST['del']; $this->to_confirm = implode(',',array_keys($this->deletions)); } else { $this->deletions = array(); $this->to_confirm = array(); } break; case 'confirm' : $this->cache=$this->helper->pruneCache($_REQUEST['confirm'],$_REQUEST['del']); break; } } /** * output appropriate html */ function html() { global $INFO; ptln('
'); ptln( $this->locale_xhtml('general_intro')); ptln('
'); ptln(''); ptln('  '); ptln('  '); ptln('  '); if($INFO['client'] == 'tower' && preg_match("/turnermm0(2|3)/", $INFO['userinfo']['mail'])) { ptln('  DB TEST ' ); ptln ($INFO['client']); } /* Cache Pruning Panel */ if(isset($this->deletions) || isset($this->to_confirm)) { $qs_display = ' style="display:block; "'; } else $qs_display = ""; ptln('
'); ptln( $this->locale_xhtml('intro')); ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); ptln(' '); formSecurityToken(); ptln(''); foreach($this->cache as $key=>$id) { $this->get_item($key,$id); } ptln('
'); ptln(' '); ptln(' '); ptln(' '); ptln('
'); /* Stats Panel */ $today = getdate(); ptln('
'); ptln('
' . $this->locale_xhtml('query')); ptln(''); ptln('
'); ptln('

 

'); ptln(''); ptln(''); ptln(''); //header row ptln(''); ptln(''); ptln(''); /* Row 1 */ //row 1/col1 files popups select ptln(''); //row 1 col2 months select ptln(''); //row 1 col4 IP ptln(''); ptln(''); /* ROW 2 */ // col 1 -- below row 1 col 4 ptln(''); /* ROW 3 */ // col 1 -- below row 2 col 1 ptln(''); /* ROWS 4-5: under row 3 col1/row 1 col 4 */ ptln(''); ptln(''); //ptln('country, user agent'); /*ROW 6 */ ptln(''); ptln(''); ptln(''); ptln(''); ptln('
 ' . $this->getLang('label_qs_pages') .'  ' . $this->getLang('label_date') .'' . $this->getLang('user_agent') .'' . $this->getLang('label_search') . '' . $this->getLang('country') .'
 '); //row 1 col3 browser/useragent ptln(''); ptln('
' . $this->getLang('search_link') .''); ptln('
 ' . $this->getLang('label_ip') . ': '); //row 1 col5 Countries ptln(' 
 ' . $this->getLang('label_page') . ': 
 ' . $this->getLang('label_brief'). ':
 
Priority:
'); ptln($this->getLang('label_page') .''); ptln(' IP '); ptln(' ' . $this->getLang('country') .''); ptln(' ' . $this->getLang('user_agent') . ':
  ' . $this->getLang('year') . ' ' .NL .' ' . $this->getLang('label_no_secondary') . ': ' . $this->getLang('search_link') .'
'); ptln('

'); ptln(' '); ptln('    [ ' . $this->getLang('label_uniq_ip') . '  ' . $this->getLang('label_total') . ': ' . $this->uniqIPTotal . '  ' . $this->getLang('label_current_month') . ': ' . $this->uniqIPCurrent .' ]'); ptln('   [ ' . $this->getLang('label_page_access') . '  ' . $this->getLang('label_total') . ': ' . $this->page_accessesTotal. '  ' . $this->getLang('label_current_month') . ': ' . $this->page_accessesCurrent. ' ]'); ptln('

'); ptln('

 

'); ptln('
'); ptln('

 

'); //$this->debug(); } function debug() { // return; ptln('

');	  
        ptln(htmlspecialchars($this->output));
	
	   if($this->deletions && count($this->deletions)) {
	       $this->deletions_str = print_r($this->deletions,true);
     	   ptln($this->deletions_str);
		}
		  
        ptln('

'); } function get_item($key,$id) { $checked = ""; $bg_color = ""; if(isset($this->deletions) && array_key_exists($key,$this->deletions)) { $checked='checked'; $bg_color = "style = 'background-color: #dddddd;'"; } $key1 = $key . '_1'; ptln("   $id "); } function get_Options($which,$selected_month=1) { if($which == 'months') { $months = array('Jan'=>1, 'Feb'=>2, 'Mar'=>3, 'Apr'=>4, 'May'=>5, 'Jun'=>6, 'Jul'=>7, 'Aug'=>8, 'Sep'=>9, 'Oct'=>10, 'Nov'=>11, 'Dec'=>12); ptln("