diff options
author | deva <deva> | 2010-03-16 15:09:43 +0000 |
---|---|---|
committer | deva <deva> | 2010-03-16 15:09:43 +0000 |
commit | f85e1443a041a1e4ad38a9d79dac81c94a07e05c (patch) | |
tree | 34c0678b4de10ea5c91294bb67bec4fb29c46477 /utils/modules/sitestats.php | |
parent | 6f1a8b8a59ce23383dce430c1da1a91fc7fff72b (diff) |
Add simple stat log mechanism.
Diffstat (limited to 'utils/modules/sitestats.php')
-rw-r--r-- | utils/modules/sitestats.php | 130 |
1 files changed, 130 insertions, 0 deletions
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 @@ +<?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +global $UTIL_DIR; + +include_once($UTIL_DIR . "/convert.php"); + +class SiteStats { + + public $statsdir; + public $stats = array(); + + // Admin config + public $admin_title = "Site Stats"; + public $admin_submodules = array("Overview" => "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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); + + fwrite($fp, "<configs>\n"); + foreach($this->configs as $name => $value) { + fwrite($fp, " <config name=\"".$name."\"\n"); + fwrite($fp, " value=\"". + htmlspecialchars(serialize($value), ENT_QUOTES, "UTF-8")."\"/>\n"); + } + fwrite($fp, "</configs>\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 = "<entry>". + "<time>".xmlenc($now)."</time>". // Time + "<remoteaddr>".xmlenc($_SERVER['REMOTE_ADDR'])."</remoteaddr>". // remote ip + "<remotehost>".xmlenc($_SERVER['REMOTE_HOST'])."</remotehost>". // remote hostname + "<loadtime>".xmlenc($loadtime)."</loadtime>". // Loadtime + "<page>".xmlenc($GLOBALS['page'])."</page>". // Page + // $_SERVER['REMOTE_PORT'] . // current port + // $_SERVER['SCRIPT_FILENAME'] . // script name + "<agent>".xmlenc($_SERVER['HTTP_USER_AGENT'])."</agent>". // User agent (browser) + "<referer>".xmlenc($_SERVER['HTTP_REFERER'])."</referer>". // referer (link) + "<uri>".xmlenc($_SERVER['REQUEST_URI'])."</uri>". // URI + // GeoIP ?? + "</entry>\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 |