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/threads.php | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 forum/utils/threads.php (limited to 'forum/utils/threads.php') diff --git a/forum/utils/threads.php b/forum/utils/threads.php new file mode 100644 index 0000000..e3f0996 --- /dev/null +++ b/forum/utils/threads.php @@ -0,0 +1,162 @@ + + * + * . + * . + * . + * + */ + +class Thread { + public $tid; + public $name; + public $lastseen = array(); + public $lastpost; + + public function show() + { + global $fid, $current_user; + echo "
"; + if($this->lastseen[$current_user->uid] < $this->lastpost) echo "
"; + else echo "
"; + echo "" . $this->name . ""; + echo "
"; + } + + private function loadLastSeen($lastseen) + { + if($lastseen == "") return; + $list = explode(",", $lastseen); + foreach($list as $l) { + $pair = explode("=", $l); + if($pair[0] != "" && $pair[1] != "") { + $this->lastseen[$pair[0]] = $pair[1]; + } + } + } + + public function Thread($tid, $name, $lastpost, $lastseen) + { + $this->tid = $tid; + $this->name = $name; + $this->lastpost = $lastpost; + $this->loadLastSeen($lastseen); + } +} + +class Threads { + + private $dir; + public $threads = array(); + + public function add($thread) { + // $key = $thread->name; + // $key = sprintf("%d-%d", $thread->lastpost, $thread->tid); + // $key = sprintf("%d", $thread->lastpost); + $key = $thread->lastpost . "-" . $thread->tid;//name; + // echo "[" . $key . "]"; + $this->threads[$key] = $thread; + } + + 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 getThread($tid) + { + $thread = $this->threads[$tid]; + return $thread; + } + + public function show() + { + foreach($this->threads as $thread) { + $thread->show(); + } + } + + public function newStuff() + { + global $current_user; + + foreach($this->threads as $thread) { + if($thread->lastseen[$current_user->uid] < $thread->lastpost) return true; + } + + return false; + } + + private function read() + { + $dh = opendir($this->dir); + while($file = readdir($dh)) { + if($file == "." || $file == "..") continue; + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->dir . "/" . $file); + $threads = $dom->getElementsByTagName('thread'); + + foreach($threads as $f) { + $thread = new Thread($f->getAttribute('tid'), + $f->getAttribute('name'), + $f->getAttribute('lastpost'), + $f->getAttribute('lastseen')); + + $this->add($thread); + } + } + } + + public function Threads($dir) + { + $this->dir = $dir; + $this->read(); + krsort($this->threads); + } + +} +?> \ No newline at end of file -- cgit v1.2.3