"overview"); public function admin_overview($action, $vars) { switch($action) { default: $this->readSingle(time()); break; } } public function admin($sub, $action, $vars) { switch($sub) { case "overview": $this->admin_overview($action, $vars); $hits = 0; foreach($this->visitors as $k => $v) { $hits += $v; } echo "

".$hits." hits.

\n"; echo "

Referers:

\n"; echo "\n"; echo "

Pages:

\n"; echo "\n"; echo "

Visitors:

\n"; echo "

".sizeof($this->visitors)." unique visitors.

\n"; echo "\n"; break; } } private function read($file) { $xml = file_get_contents($file); $xml = "\n\n" . $xml . "\n\n"; $dom = new DomDocument; $dom->preserveWhiteSpace = TRUE; $dom->loadXML($xml); $entries = $dom->getElementsByTagName('entry'); foreach($entries as $entry) { $skip = false; $remoteaddrs = $entry->getElementsByTagName('remoteaddr'); foreach($remoteaddrs as $remoteaddr) { $addr = $remoteaddr->textContent; if($addr == "87.63.201.210") $skip = true; } $agents = $entry->getElementsByTagName('agent'); foreach($agents as $agent) { $ag = $agent->textContent; if(stripos($ag, "bot") > 0) $skip = true; } if($skip == true) continue; $this->visitors[$addr]++; $refs = $entry->getElementsByTagName('referer'); foreach($refs as $ref) { $url = $ref->textContent; if(strpos($url, "executionroom.com") > 0 || $url == "") {} else $this->referers[$url]++; } $pages = $entry->getElementsByTagName('page'); foreach($pages as $page) { $pg = $page->textContent; if($pg != "") $this->pages[$pg]++; } } arsort($this->referers); arsort($this->pages); arsort($this->visitors); } public function log($loadtime) { $now = time(); $str = "". "". // Time "".xmlenc($_SERVER['REMOTE_ADDR'])."". // remote ip "".xmlenc($_SERVER['REMOTE_HOST'])."". // remote hostname "".xmlenc($loadtime)."". // Loadtime "".xmlenc($GLOBALS['page'])."". // Page // $_SERVER['REMOTE_PORT'] . // current port // $_SERVER['SCRIPT_FILENAME'] . // script name "".xmlenc($_SERVER['HTTP_USER_AGENT'])."". // User agent (browser) "".xmlenc($_SERVER['HTTP_REFERER'])."". // referer (link) "".xmlenc($_SERVER['REQUEST_URI'])."". // URI // GeoIP ?? "\n"; $file = $this->getFilename($now); if(!file_exists(dirname($file))) mkdir(dirname($file), 0777, true); $fp = fopen($file, "a"); fwrite($fp, $str); fclose($fp); } private function getFilename($timestamp) { $year = "2010"; $month = "03"; $file = $this->statsdir . "/" . $year . "/" . $month . ".xml"; return $file; } private function readSingle($timestamp) { $file = $this->getFilename($timestamp); if(file_exists($file)) $this->read($file); } private function readAll() { } public function SiteStats($statsdir, $readall = false) { $this->statsdir = $statsdir; if(file_exists($statsdir) && is_dir($statsdir)) { if($readall) { $this->readAll(); } else { // $this->readSingle(time()); } } } } function sitestats_init() { global $DATA_DIR; return new SiteStats($DATA_DIR."/sitestats", true); } ?>