From afc66efe4710b64fb8901f7a41cd9f9285065c91 Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 6 Jul 2010 13:23:54 +0000 Subject: More informative overview. --- forum/utils/threads.php | 71 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'forum/utils') diff --git a/forum/utils/threads.php b/forum/utils/threads.php index 258f97c..52dda06 100644 --- a/forum/utils/threads.php +++ b/forum/utils/threads.php @@ -17,9 +17,23 @@ class Thread { public $lastseen = array(); public $lastpost; + public $first_pid; + public $first_title; + public $first_user; + public $first_date; + + public $last_pid; + public $last_title; + public $last_user; + public $last_date; + + public $numposts; + public $numunread; + public function show() { global $fid, $current_user; + global $users; $jumptonew = ""; $newcls = " thread_nonew"; @@ -32,12 +46,44 @@ class Thread { echo "  \n"; echo " " . $this->name . "\n"; + echo " ".$this->numposts." posts"; + if($this->numunread != 0) { + echo " (".$this->numunread." unread)"; + } + echo "\n"; echo " Last post: ". date("j. M Y - G:i", $this->lastpost)."\n"; - // echo " ".$this->numposts." posts\n"; + $user = $users->getUser($this->first_user); + echo " By ".$user->name; + echo " at ". date("j. M Y - G:i", $this->first_date)."\n"; echo " \n"; } + public function processPost($pid, $title, $user, $date) + { + global $current_user; + + $this->numposts++; + + if($this->lastseen[$current_user->uid] < $date) { + $this->numunread++; + } + + if($date < $this->first_date || $this->first_date == -1) { + $this->first_pid = $pid; + $this->first_title = $title; + $this->first_user = $user; + $this->first_date = $date; + } + + if($date > $this->last_date || $this->last_date == -1) { + $this->last_pid = $pid; + $this->last_title = $title; + $this->last_user = $user; + $this->last_date = $date; + } + } + private function loadLastSeen($lastseen) { if($lastseen == "") return; @@ -52,6 +98,10 @@ class Thread { public function Thread($tid, $name, $lastpost, $lastseen) { + $this->numunread = 0; + $this->numposts = 0; + $this->first_date = -1; + $this->last_date = -1; $this->tid = $tid; $this->name = $name; $this->lastpost = $lastpost; @@ -156,6 +206,21 @@ class Threads { return false; } + private function recurser($parentpost, $element, $thread) + { + if($element->tagName != "post") return; + + $thread->processPost($element->getAttribute('pid'), + $element->getAttribute('title'), + $element->getAttribute('user'), + $element->getAttribute('date')); + + foreach($element->childNodes as $child) { + if($child->tagName == "post") + $this->recurser($post, $child, $thread); + } + } + private function read() { $dh = opendir($this->dir); @@ -172,6 +237,10 @@ class Threads { $f->getAttribute('lastpost'), $f->getAttribute('lastseen')); + foreach($f->childNodes as $child) { + $this->recurser(false, $child, $thread); + } + $this->add($thread); } } -- cgit v1.2.3