From f85e1443a041a1e4ad38a9d79dac81c94a07e05c Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 16 Mar 2010 15:09:43 +0000 Subject: Add simple stat log mechanism. --- htdocs/index.php | 22 +++++++- utils/modules/sitestats.php | 130 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 utils/modules/sitestats.php diff --git a/htdocs/index.php b/htdocs/index.php index a550f77..d389e6d 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -16,6 +16,13 @@ if(!isset($JPEG_CACHE_QUALITY)) $JPEG_CACHE_QUALITY = 85; if($mode == "imagecache") { include_once($UTIL_DIR. "/imagecache.php"); getCachedImage($uri, $mod, $cat); + + include_once($MODULES_DIR."/sitestats.php"); + $stats = new SiteStats($DATA_DIR."/sitestats"); + + $stop_time = microtime(true); + $stats->log($stop_time - $start_time); + return; } @@ -62,6 +69,13 @@ if($config->value('splash') == "true") { log($stop_time - $start_time); + return; } } @@ -143,11 +157,15 @@ $_p = $pages->getPage("footer"); if($_p) $_p->show(); ?> -
This document was generated in seconds
+
This document was generated in seconds
Admin
- +log($stop_time - $start_time); +?> \ No newline at end of file diff --git a/utils/modules/sitestats.php b/utils/modules/sitestats.php new file mode 100644 index 0000000..c4bafbf --- /dev/null +++ b/utils/modules/sitestats.php @@ -0,0 +1,130 @@ + "overview"); + + public function admin_overview($action, $vars) + { + switch($action) { + default: + break; + } + } + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "overview": + $this->admin_overview($action, $vars); + break; + } + } + + /* + public function write() + { + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->configs as $name => $value) { + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + */ + private function read($file) + { + /* + $dom = new DomDocument; + $dom->preserveWhiteSpace = TRUE; + $dom->load($this->file); + $configElems = $dom->getElementsByTagName('config'); + + foreach ($configElems as $config) { + $this->setValue($config->getAttribute('name'), + unserialize(htmlspecialchars_decode($config->getAttribute('value'), ENT_QUOTES))); + } + */ + } + + 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); +} + +?> \ No newline at end of file -- cgit v1.2.3