From cce5e7710295021b41d9aaecc503a60fb99256be Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 4 Oct 2008 10:38:03 +0000 Subject: Initial revision --- forum/utils/forums.php | 133 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 forum/utils/forums.php (limited to 'forum/utils/forums.php') diff --git a/forum/utils/forums.php b/forum/utils/forums.php new file mode 100644 index 0000000..9305623 --- /dev/null +++ b/forum/utils/forums.php @@ -0,0 +1,133 @@ +newStuff = $newStuff; + } + + public function show() + { + echo "
"; + if($this->newStuff) echo "
"; + else echo "
"; + echo "fid . "\">" . $this->name . ""; + echo "
"; + } + + public function Forum($fid, $readlist, $writelist, $name) + { + $this->fid = $fid; + $this->readlist = $readlist; + $this->writelist = $writelist; + $this->name = $name; + } +} + +class Forums { + + private $file; + public $forums = array(); + + public function add($forum) { + $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->members as $member) { + fwrite($fp, " id, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " name=\"" . + htmlspecialchars($member->name, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " description=\"" . + htmlspecialchars($member->description, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " image=\"" . + htmlspecialchars($member->image, ENT_QUOTES, "UTF-8") . "\">\n"); + + + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + */ + } + + /* + public function deleteForumUser($id) + { + if($this->members[$id]) { + unset($this->members[$id]); + // $this->write(); + } else { + echo "

ERROR: User! ".$id." does not exist!

\n"; + return false; + } + return true; + } + */ + + public function getForum($fid) + { + $forum = $this->forums[$fid]; + return $forum; + } + + public function show() + { + foreach($this->forums as $forum) { + $forum->show(); + } + } + + 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('readlist'), + $f->getAttribute('writelist'), + $f->getAttribute('name')); + + $this->add($forum); + + $threads = new Threads($FORUMS_DIR . "/" . $f->getAttribute('fid')); + $forum->setNewStuff($threads->newStuff()); + } + } + + public function Forums($file) + { + $this->file = $file; + $this->read(); + } + +} +?> \ No newline at end of file -- cgit v1.2.3