<?php
// Copyright (c) 2007 FORUM Team - see LICENSE for details
class Data{
private $data = array();
private $datatype;
function __construct($datatype = "generic"){
$this->datatype = $datatype;
if (!is_dir(FORUM_ROOT."/data/{$this->datatype}"))
mkdir(FORUM_ROOT."/data/{$this->datatype}");
}
function __destruct(){ // Save all changed objects
foreach ($this->data as $name => $list){
if ($list->changed)
file_put_contents(FORUM_ROOT."/data/{$this->datatype}/$name.php",Data::Create($list->All));
}
}
function __get($name){ // Retrieve object data
if (!isset($this->data[$name]))
$this->data[$name] = new DataObject($name,$this->datatype);
return $this->data[$name];
}
function __unset($name){ // delete object
$uf = FORUM_ROOT."/data/{$this->datatype}/$name.php";
if (is_writable($uf) && !is_dir($uf)) // Remove file from disk
unlink($uf);
if (isset($this->data[$name])){
unset($this->data[$name]);
return true;
} else
return false; // Will not delete from cache if it has been changed, or doesnt exist (TODO:why?)
}
function __isset($name){ // check if an object exists
return (isset($this->data[$name]) || file_exists(FORUM_ROOT."/data/{$this->datatype}/$name.php"));
}
static function Create($data){ // Function to generate compressed data php file
if ((defined('NOGZIP') && NOGZIP) || (defined('GZIP_DISABLED') && GZIP_DISABLED))
return "<?php fseek(\$f = fopen(__FILE__,'rb'),__COMPILER_HALT_OFFSET__); return unserialize(stream_get_contents(\$f));\n__halt_compiler();".serialize($data);
else
return "<?php fseek(\$f = fopen(__FILE__,'rb'),__COMPILER_HALT_OFFSET__); return unserialize(gzinflate(stream_get_contents(\$f)));\n__halt_compiler();".gzdeflate(serialize($data));
}
}
<?php
// Copyright (c) 2007 FORUM Team - see LICENSE for details
class Profile extends Data{
function __construct(){
parent::__construct('profile');
}
function ListAll(){
$users = array();
foreach (File::Glob(FORUM_ROOT.'/data/profile/*.php') as $filename){
$user = rfe(basename($filename));
$users[user($user)] = user($user);
}
return $users;
}
}