*/ 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->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("