numPosts = sizeof($threads->threads);
$this->latestPost = "";
$t = $threads->getLatestThread();
if($t) {
$this->latestPost = $t->name;
}
$this->newStuff = $newStuff;
}
public function show()
{
global $cache;
global $yeah;
$str = "";
$newcls = " forum_nonew";
if($yeah) {
$lp = $cache->get("forum_lastpost");
if($lp->value($this->fid)) $newcls = " forum_new";
} else {
if($this->newStuff) $newcls = " forum_new";
}
$str .= "
\n";
$str .= "
\n";
$str .= "
fid . "\">" . $this->name . "\n";
$str .= "
".
$this->latestPost . "\n";
if($yeah) {
$fc = $cache->get("forum_numberofthreads");
$str .= "
" .
$fc->value($this->fid) . " threads\n";
} else {
$str .= "
"
. sprintf("%d", $this->numPosts)." threads\n";
}
$str .= "
\n";
return $str;
}
public function Forum($fid, $name)
{
$this->fid = $fid;
$this->name = $name;
}
}
class Forums {
private $file;
public $forums = array();
public function add($forum) {
global $FORUMS_DIR;
if(!file_exists($FORUMS_DIR . "/". $forum->fid)) {
mkdir($FORUMS_DIR . "/". $forum->fid);
}
$key = $forum->fid;
$this->forums[$key] = $forum;
}
public function write()
{
$fp = fopen($this->file, "w");
$block = TRUE;
flock($fp, LOCK_EX, $block); // do an exclusive lock
fwrite($fp, "\n");
fwrite($fp, "\n");
foreach($this->forums as $forum) {
fwrite($fp, " fid . "\"\n");
fwrite($fp, " name=\"" . htmlspecialchars($forum->name, ENT_QUOTES, "UTF-8") . "\"/>\n");
}
fwrite($fp, "\n");
fclose($fp);
}
public function getForum($fid)
{
$forum = $this->forums[$fid];
return $forum;
}
public function show()
{
$str = "";
$str .= "\n";
foreach($this->forums as $forum) {
$str .= $forum->show();
}
$str .= "
\n";
return $str;
}
private function read()
{
global $FORUMS_DIR;
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load($this->file);
$forums = $dom->getElementsByTagName('forum');
foreach($forums as $f) {
$forum = new Forum($f->getAttribute('fid'),
$f->getAttribute('name'));
$this->add($forum);
$threads = new Threads($FORUMS_DIR . "/" . $f->getAttribute('fid'));
$forum->setNewStuff($threads->newStuff(), $threads);
}
}
public function Forums($file)
{
$this->file = $file;
if(file_exists($file)) $this->read();
else {
if(!file_exists(dirname($file))) {
if(!mkdir(dirname($file))) {
echo"Could not create directory: " . dirname($file);
die();
}
} else {
if(!is_dir(dirname($file))) {
echo dirname($file) . " exists but is not a directory";
die();
} else {
if(!is_readable(dirname($file)) || !is_writeable(dirname($file)) || !is_executable(dirname($file))) {
echo dirname($file) . " exists but does not have the correct permissions. (r/w/x)";
die();
}
}
}
}
}
}
?>