From: <dts...@us...> - 2003-06-03 20:07:44
|
Update of /cvsroot/phpwebsite-comm/modules/phpwsbb/class In directory sc8-pr-cvs1:/tmp/cvs-serv32753/class Modified Files: Manager.php Message.php Added Files: Thread.php Log Message: Adding thread layer --- NEW FILE: Thread.php --- <?php /** * @version $Id: Thread.php,v 1.1 2003/06/03 20:07:10 dtseiler Exp $ * @author Don Seiler <do...@NO...> */ class PHPWSBB_Thread extends PHPWS_Item { /** * Sticky flag * * @var bit * @access private */ var $_sticky = 0; /** * Locked flag * * @var bit * @access private */ var $_locked = 0; /** * Number of replies to this message * * @var integer * @access private */ var $_replies = 0; /** * The ids of all the messages under this one * * @var array * @access private */ var $messages = array(); function PHPWSBB_Thread($THREAD_ID = NULL) { /* These variable are excluded when calling commit() */ $exclude = array("messages"); $this->addExclude($exclude); /* Set database table */ $this->setTable("mod_phpwsbb_threads"); /* Populate this object if ID exists */ if(isset($THREAD_ID)) { $this->setId($THREAD_ID); $this->init(); $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_phpwsbb_messages WHERE tid=" . $this->getId() . " ORDER BY created;"; $this->messages = $GLOBALS["core"]->getCol($sql); } }// END FUNC PHPWSBB_Thread function _view() { $tags = array(); $tags["ID"] = $this->getId(); $tags["OWNER"] = $this->getOwner(); $tags["EDITOR"] = $this->getEditor(); $tags["IP"] = $this->getIp(); $tags["CREATED"] = $this->getCreated(); $tags["UPDATED"] = $this->getUpdated(); $tags["LABEL"] = $this->getLabel(); $tags["STICKY"] = $this->_sticky; $tags["LOCKED"] = $this->_locked; $tags["REPLIES"] = $this->_replies; //$tags["REPLY"] = "<a href=\"./index.php?module=phpwsbb&PHPWSBB_MAN_OP=reply&PHPWS_MAN_ITEMS[]=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Reply to Message") . "</a>"; // Need to cycle through all messages and view $content = $GLOBALS["core"]->processTemplate($tags, "phpwsbb", "view.tpl"); foreach($this->messages as $mid) { $message = new PHPWSBB_Message($mid); $content .= "<br />" . $message->_view(); } return $content; }// END FUNC _view function updateThreadStats() { if(!empty($this->_id)) { $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_phpwsbb_messages WHERE tid=" . $this->getId() . " ORDER BY created;"; $this->messages = $GLOBALS["core"]->getCol($sql); $this->_replies = count($this->messages) - 1; } else { $this->_replies = 0; } $this->commit(); } function action() { switch($_REQUEST["PHPWSBB_THREAD_OP"]) { case "view": $title = $this->getLabel(); $content = $_SESSION["PHPWSBB_Manager"]->_menu(); $content .= $this->_view(); break; case "delete": case "fork": case "lock": default: $title = "NO OP"; $content = "This function is not yet implemented"; } if(isset($content)) { $GLOBALS["CNT_phpwsbb"]["title"] = $title; $GLOBALS["CNT_phpwsbb"]["content"] .= $content; } }// END FUNC _action }// END CLASS PHPWSBB_Message Index: Manager.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/phpwsbb/class/Manager.php,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Manager.php 3 Jun 2003 19:03:15 -0000 1.7 --- Manager.php 3 Jun 2003 20:07:10 -0000 1.8 *************** *** 7,11 **** class PHPWSBB_Manager extends PHPWS_Manager { ! var $message = NULL; /** --- 7,20 ---- class PHPWSBB_Manager extends PHPWS_Manager { ! var $notice = NULL; ! ! /** ! * The thread object ! * ! * @var PHPWSBB_Message ! * @access public ! */ ! var $thread = NULL; ! /** *************** *** 15,23 **** * @access public */ ! var $phpwsbb_message = NULL; function PHPWSBB_Manager() { $this->setModule("phpwsbb"); - $this->setTable("mod_phpwsbb_messages"); $this->setRequest("PHPWSBB_MAN_OP"); $this->init(); --- 24,31 ---- * @access public */ ! var $message = NULL; function PHPWSBB_Manager() { $this->setModule("phpwsbb"); $this->setRequest("PHPWSBB_MAN_OP"); $this->init(); *************** *** 39,65 **** $links = array(); ! $links[] = "<a href=\"index.php?module=phpwsbb&PHPWSBB_MAN_OP=list\">" . $_SESSION["translate"]->it("List Messages") . "</a>"; ! $links[] = "<a href=\"index.php?module=phpwsbb&PHPWSBB_MAN_OP=new\">" . $_SESSION["translate"]->it("Add New Message") . "</a>"; $GLOBALS["CNT_phpwsbb"]["content"] .= $this->_menu(); ! $GLOBALS["CNT_phpwsbb"]["content"] .= $this->getList("messages", $_SESSION["translate"]->it("Bulletin Board Messages")); }// END FUNC _list function _view() { ! $this->phpwsbb_message = new PHPWSBB_Message($_REQUEST["PHPWS_MAN_ITEMS"][0]); ! $_REQUEST["PHPWSBB_MESSAGE_OP"] = "view"; }// END FUNC _view function _new() { ! $this->phpwsbb_message = new PHPWSBB_Message; $_REQUEST["PHPWSBB_MESSAGE_OP"] = "edit"; }// END FUNC _new function _reply() { ! $this->phpwsbb_message = new PHPWSBB_Message; ! $this->phpwsbb_message->_pid = $_REQUEST["PHPWS_MAN_ITEMS"][0]; $_REQUEST["PHPWSBB_MESSAGE_OP"] = "edit"; }// END FUNC _new --- 47,74 ---- $links = array(); ! $links[] = "<a href=\"index.php?module=phpwsbb&PHPWSBB_MAN_OP=list\">" . $_SESSION["translate"]->it("List Topics") . "</a>"; ! $links[] = "<a href=\"index.php?module=phpwsbb&PHPWSBB_MAN_OP=new\">" . $_SESSION["translate"]->it("Add New Topic") . "</a>"; $GLOBALS["CNT_phpwsbb"]["content"] .= $this->_menu(); ! $this->setTable("mod_phpwsbb_threads"); ! $GLOBALS["CNT_phpwsbb"]["content"] .= $this->getList("threads", $_SESSION["translate"]->it("Bulletin Board Topics")); }// END FUNC _list function _view() { ! $this->thread = new PHPWSBB_Thread($_REQUEST["PHPWS_MAN_ITEMS"][0]); ! $_REQUEST["PHPWSBB_THREAD_OP"] = "view"; }// END FUNC _view function _new() { ! $this->message = new PHPWSBB_Message; $_REQUEST["PHPWSBB_MESSAGE_OP"] = "edit"; }// END FUNC _new function _reply() { ! $this->message = new PHPWSBB_Message; ! $this->message->_tid = $_REQUEST["PHPWS_MAN_ITEMS"][0]; $_REQUEST["PHPWSBB_MESSAGE_OP"] = "edit"; }// END FUNC _new Index: Message.php =================================================================== RCS file: /cvsroot/phpwebsite-comm/modules/phpwsbb/class/Message.php,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Message.php 3 Jun 2003 19:03:15 -0000 1.8 --- Message.php 3 Jun 2003 20:07:10 -0000 1.9 *************** *** 8,17 **** /** ! * The parent id of this message * * @var integer * @access private */ ! var $_pid = 0; /** --- 8,17 ---- /** ! * The thread id of this message * * @var integer * @access private */ ! var $_tid = 0; /** *************** *** 39,86 **** var $_body = NULL; - /** - * Sticky flag - * - * @var bit - * @access private - */ - var $_sticky = 0; - - /** - * Locked flag - * - * @var bit - * @access private - */ - var $_locked = 0; - - /** - * Number of replies to this message - * - * @var integer - * @access private - */ - var $_replies = 0; - - /** - * Timestamp of last post - * - * @var string - * @access private - */ - var $_lastreply = NULL; - - /** - * The ids of all the messages under this one - * - * @var array - * @access private - */ - var $children = array(); function PHPWSBB_Message($MESSAGE_ID = NULL) { /* These variable are excluded when calling commit() */ ! $exclude = array("children"); ! $this->addExclude($exclude); /* Set database table */ --- 39,47 ---- var $_body = NULL; function PHPWSBB_Message($MESSAGE_ID = NULL) { /* These variable are excluded when calling commit() */ ! //$exclude = array("children"); ! //$this->addExclude($exclude); /* Set database table */ *************** *** 91,96 **** $this->setId($MESSAGE_ID); $this->init(); - $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_phpwsbb_messages WHERE pid=" . $this->getId() . " ORDER BY created;"; - $this->children = $GLOBALS["core"]->getCol($sql); } --- 52,55 ---- *************** *** 111,119 **** $tags["GUESTNAME"] = $this->_guestname; $tags["GUESTEMAIL"] = $this->_guestemail; ! $tags["PID"] = $this->_pid; ! $tags["STICKY"] = $this->_sticky; ! $tags["LOCKED"] = $this->_locked; ! $tags["REPLIES"] = $this->_replies; ! $tags["LASTREPLY"] = $this->_lastreply; $poster = $this->getOwner(); --- 70,74 ---- $tags["GUESTNAME"] = $this->_guestname; $tags["GUESTEMAIL"] = $this->_guestemail; ! $tags["TID"] = $this->_tid; $poster = $this->getOwner(); *************** *** 125,142 **** $tags["POSTED"] = $_SESSION["translate"]->it("Posted by [var1] on [var2]", $poster, $this->getCreated()); ! //$tags["REPLY"] = "<a href=\"./index.php?module=phpwsbb&PHPWSBB_MAN_OP=reply&PHPWSBB_pid=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Reply to Message") . "</a>"; ! if(empty($this->_pid)) ! $tags["REPLY"] = "<a href=\"./index.php?module=phpwsbb&PHPWSBB_MAN_OP=reply&PHPWS_MAN_ITEMS[]=" . $this->getId() . "\">" . $_SESSION["translate"]->it("Reply to Message") . "</a>"; ! ! // Need to cycle through all children still ! ! $content = $GLOBALS["core"]->processTemplate($tags, "phpwsbb", "view.tpl"); ! ! foreach($this->children as $cid) { ! $child = new PHPWSBB_Message($cid); ! $content .= "<br />" . $child->_view(); ! } ! return $content; }// END FUNC _view --- 80,87 ---- $tags["POSTED"] = $_SESSION["translate"]->it("Posted by [var1] on [var2]", $poster, $this->getCreated()); ! if(!empty($this->_tid)) ! $tags["REPLY"] = "<a href=\"./index.php?module=phpwsbb&PHPWSBB_MAN_OP=reply&PHPWS_MAN_ITEMS[]=" . $this->_tid . "\">" . $_SESSION["translate"]->it("Reply to Message") . "</a>"; ! return $GLOBALS["core"]->processTemplate($tags, "phpwsbb", "view.tpl"); }// END FUNC _view *************** *** 196,200 **** $form->add("module", "hidden", "phpwsbb"); $form->add("PHPWSBB_MESSAGE_OP", "hidden", "save"); ! $form->add("Message_pid", "hidden", $this->_pid); $tags = array(); --- 141,145 ---- $form->add("module", "hidden", "phpwsbb"); $form->add("PHPWSBB_MESSAGE_OP", "hidden", "save"); ! $form->add("Message_tid", "hidden", $this->_tid); $tags = array(); *************** *** 226,234 **** $this->_body = $_REQUEST["Message_body"]; - if(isset($_REQUEST["Message_pid"])) - if(empty($_REQUEST["Message_pid"])) - $this->_pid = 0; - else - $this->_pid = $_REQUEST["Message_pid"]; if(isset($_REQUEST["Message_guestname"])) --- 171,174 ---- *************** *** 238,242 **** $this->_guestemail = $_REQUEST["Message_guestemail"]; ! $this->getLatest(); $error = $this->commit(); --- 178,193 ---- $this->_guestemail = $_REQUEST["Message_guestemail"]; ! if(!empty($_REQUEST["Message_tid"])) ! $this->_tid = $_REQUEST["Message_tid"]; ! else { ! // Need to create thread ! echo "<h3>creating new thread</h3>"; ! $thread = new PHPWSBB_Thread; ! $thread->setLabel($this->getLabel()); ! $thread->_lastreply = time(); ! $thread->commit(); ! $this->_tid = $thread->getId(); ! echo "<h3>thread has tid " . $this->getId() . "</h3>"; ! } $error = $this->commit(); *************** *** 251,274 **** } else { $GLOBALS["CNT_phpwsbb"]["content"] .= $_SESSION["translate"]->it("Your message was successfully saved.") . "<br />\n"; - $_REQUEST["PHPWSBB_MESSAGE_OP"] = "view"; - $this->action(); - } - }// END FUNC _save ! function getLatest() { ! if(!empty($this->_id)) { ! $sql = "SELECT id FROM " . $GLOBALS["core"]->tbl_prefix . "mod_phpwsbb_messages WHERE pid=" . $this->getId() . " ORDER BY created;"; ! $this->children = $GLOBALS["core"]->getCol($sql); ! $this->_replies = count($this->children); ! if($this->_replies > 0) { ! $lastreply = new PHPWSBB_Message($this->childre[($this->_replies - 1)]); ! $this->_lastreply = $lastreply->getCreated(); ! } ! } else { ! $this->_replies = 0; ! $this->_lastreply = time(); ! } ! } --- 202,214 ---- } else { $GLOBALS["CNT_phpwsbb"]["content"] .= $_SESSION["translate"]->it("Your message was successfully saved.") . "<br />\n"; + // Update thread object with new statistics + $thread = new PHPWSBB_Thread($this->_tid); + $thread->updateThreadStats(); ! $_REQUEST["PHPWSBB_THREAD_OP"] = "view"; ! $thread->action(); ! } ! }// END FUNC _save *************** *** 279,283 **** $title = $_SESSION["translate"]->it("Edit Message"); else ! if(isset($this->_pid)) $title = $_SESSION["translate"]->it("Reply to Message"); else --- 219,223 ---- $title = $_SESSION["translate"]->it("Edit Message"); else ! if(isset($this->_tid)) $title = $_SESSION["translate"]->it("Reply to Message"); else |