forummessage.class

来自「GForge 3.0 协作开发平台 支持CVS, mailing lists, 」· CLASS 代码 · 共 423 行

CLASS
423
字号
<?php/** * GForge Forums Facility * * Copyright 2002 GForge, LLC * http://gforge.org/ * * @version   $Id: ForumMessage.class,v 1.7 2003/02/14 14:58:16 bigdisk Exp $ * * This file is part of GForge. * * GForge is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * GForge is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GForge; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *//*	Message Forums	By Tim Perdue, Sourceforge, 11/99	Massive rewrite by Tim Perdue 7/2000 (nested/views/save)	Complete OO rewrite by Tim Perdue 12/2002*/require_once('common/include/Error.class');class ForumMessage extends Error {	/**	 * Associative array of data from db.	 *	 * @var	 array   $data_array.	 */	var $data_array;	/**	 * The Forum object.	 *	 * @var	 object  $Forum.	 */	var $Forum;			/**	 *  Constructor.	 *	 *	@param	object	The Forum object to which this ForumMessage is associated.	 *  @param  int	 The message_id.	 *  @param  array   The associative array of data.	 *	@return	boolean	success.	 */	function ForumMessage(&$Forum, $msg_id=false, $arr=false) {		global $Language;		$this->Error();		if (!$Forum || !is_object($Forum)) {			$this->setError($Language->getText('forum_common_forummessage','no_valid_forum_object'));			return false;		}		if ($Forum->isError()) {			$this->setError('ForumMessage:: '.$Forum->getErrorMessage());			return false;		}		$this->Forum =& $Forum;		if ($msg_id) {			if (!$arr || !is_array($arr)) {				if (!$this->fetchData($msg_id)) {					return false;				}			} else {				$this->data_array =& $arr;				//				//	Verify this message truly belongs to this Forum				//				if ($this->data_array['group_forum_id'] != $this->Forum->getID()) {					$this->setError($Language->getText('forum_common_forummessage','error_group_forum_id'));					$this->data_array=null;					return false;				}			}		}		return true;	}	/**	 *	create - use this function to create a new message in the database.	 *	 *	@param	string	The subject of the message.	 *	@param	string	The body of the message.	 *	@param	int	The thread_id of the message, if known.	 *	@param	int	The message_id of the parent message, if any.	 *	@return	boolean success.	 */	function create($subject, $body, $thread_id='', $is_followup_to='') {		global $Language;		if (!$body || !$subject) {			$this->setError($Language->getText('forum_common_forummessage','error_required_fields'));			return false;		}		if (!session_loggedin() && !$this->Forum->allowAnonymous()) {			$this->setError($Language->getText('forum_common_forummessage','error_not_logged'));			return false;		}		if (!session_loggedin()) {			$user_id=100;		} else {			$user_id=user_getid();		}		if ($is_follow_up_to) {			$ParentMessage=new ForumMessage($this->Forum,$is_followup_to);			if (!$ParentMessage || !is_object($ParentMessage)) {				$this->setError("ForumMessage::create()".$Language->getText('forum_common_forummessage','error_no_valid_parent_message'));				return false;			}			if ($ParentMessage->isError()) {				$this->setError('ForumMessage::create() '.$ParentMessage->getErrorMessage());				return false;			}		}		if (!$is_followup_to) { 			$is_followup_to=0; 		}		//see if that message has been posted already for all the idiots that double-post		$res3=db_query("SELECT * FROM forum 			WHERE is_followup_to='$is_followup_to' 			AND body='".  htmlspecialchars($body) ."'			AND subject='".  htmlspecialchars($subject) ."' 			AND group_forum_id='". $this->Forum->getId() ."' 			AND posted_by='$user_id'");		if (db_numrows($res3) > 0) {			//already posted this message			$this->setError($Language->getText('forum_utils','double_post'));			return false;		} else {			echo db_error();		}		db_begin();		if (!$thread_id) {			$thread_id=$this->Forum->getNextThreadID();			$is_followup_to=0;			if (!$thread_id) {				$this->setError('ForumMessage::create() '.$Language->getText('forum_common_forummessage','error_getting_next_thread'));				db_rollback();				return false;			}		} else {			//			//  increment the parent's followup count if necessary			//			$res4=db_query("UPDATE forum SET most_recent_date='". time() ."' 				WHERE thread_id='$thread_id' AND is_followup_to='0'");			if (!$res4 || db_affected_rows($res4) < 1) {				$this->setError($Language->getText('forum_common_forummessage','error_cannot_update_master_thread'));				db_rollback();				return false;			} else {				//				//  mark the parent with followups as an optimization later				//				$res3=db_query("UPDATE forum SET has_followups='1',most_recent_date='". time() ."' 					WHERE msg_id='$is_followup_to'");				if (!$res3) {					$this->setError($Language->getText('forum_common_forummessage','error_cannot_update_parent'));					db_rollback();					return false;				}			}		}		$sql="INSERT INTO forum (group_forum_id,posted_by,subject,			body,date,is_followup_to,thread_id,most_recent_date) 			VALUES ('". $this->Forum->getID() ."', '$user_id', '". htmlspecialchars($subject) ."', 			'". htmlspecialchars($body) ."', '". time() ."','$is_followup_to','$thread_id','". time() ."')";		$result=db_query($sql);		if (!$result || db_affected_rows($result) < 1) {			$this->setError($Language->getText('forum_common_forummessage','error_posting_failed').' '.db_error());			db_rollback();			return false;		} else {			$msg_id=db_insertid($result,'forum','msg_id');			if (!$this->fetchData($msg_id)) {				db_rollback();				return false;			}			if (!$msg_id) {				db_rollback();				$this->setError($Language->getText('forum_common_forummessage','error_get_message_id'));				return false;			} else {				if (!$this->sendNotice()) {					db_rollback();					return false;				}//echo "Committing";				db_commit();//echo "db_error()".db_error();				return true;			}		}	}	/**	 *  fetchData - re-fetch the data for this forum_message from the database.	 *	 *  @param  int	 The message ID.	 *  @return boolean	success.	 */	function fetchData($msg_id) {		global $Language;		$res=db_query("SELECT * FROM forum_user_vw			WHERE msg_id='$msg_id'			AND group_forum_id='". $this->Forum->getID() ."'");		if (!$res || db_numrows($res) < 1) {			$this->setError($Language->getText('forum_common_forummessage','error_invalid_message_id').db_error());			return false;		}		$this->data_array =& db_fetch_array($res);		db_free_result($res);		return true;	}	/**	 *	getForum - get the Forum object this ForumMessage is associated with.	 *	 *	@return	object	The Forum object.	 */	function &getForum() {		return $this->Forum;	}	/**	 *	getID - get this message_id.	 *	 *	@return	int	The message_id.	 */	function getID() {		return $this->data_array['msg_id'];	}	/**	 *	getPosterName - get the unix user_name of this message's poster.	 *	 *	@return	string	The poster's unix name.	 */	function getPosterName() {		return $this->data_array['user_name'];	}	/**	 *	getPosterID - get this user_id of this message's poster.	 *	 *	@return	int	The user_id.	 */	function getPosterID() {		return $this->data_array['posted_by'];	}	/**	 *	getPosterRealName - get the real name of this message's poster.	 *	 *	@return	string	The real name.	 */	function getPosterRealName() {		return $this->data_array['realname'];	}	/**	 *	getSubject - get the subject of this message.	 *	 *	@return	string	The subject.	 */	function getSubject() {		return $this->data_array['subject'];	}	/**	 *	getBody - get the body of this message.	 *	 *	@return	String	The body.	 */	function getBody() {		return $this->data_array['body'];	}	/**	 *	getPostDate - get the post date of this message.	 *	 *	@return	int	The post date.	 */	function getPostDate() {		return $this->data_array['date'];	}	/**	 *	getParentID - get the id of the parent message, if this is a followup.	 *	 *	@return	int	The parent id.	 */	function getParentID() {		return $this->data_array['is_followup_to'];	}	/**	 *	getThreadID - get the thread_id of the message.	 *	 *	@return	int	The thread_id.	 */	function getThreadID() {		return $this->data_array['thread_id'];	}	/**	 *	getMostRecentDate - get the date of the most recent followup.	 *	 *	@return	int	The date of the most recent followup.	 */	function getMostRecentDate() {		return $this->data_array['most_recent_date'];	}	/**	 *	hasFollowups - whether this message has any followups.	 *	 *	@return boolean has_followups.	 */	function hasFollowups() {		return $this->data_array['has_followups'];	}	/**	 *	delete - Delete this message and its followups.	 *	 *	@return	int	The count of deleted messages.	 */	function delete() {		$msg_id=$this->getID();		$perm =& $this->Forum->Group->getPermission( session_get_user() );		if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {			$this->setPermissionDeniedError();			return false;		}		$sql="SELECT msg_id FROM forum 			WHERE is_followup_to='$msg_id' 			AND group_forum_id='".$this->Forum->getID()."'";		$result=db_query($sql);		$rows=db_numrows($result);		$count=1;		for ($i=0;$i<$rows;$i++) {			$msg = new ForumMessage($this->Forum,db_result($result,$i,'msg_id'));			$count += $msg->delete();		}		$sql="DELETE FROM forum 			WHERE msg_id='$msg_id' 			AND group_forum_id='".$this->Forum->getID()."'";		$toss=db_query($sql);		return $count;	}	/**	 *	sendNotice - contains the logic to send out email followups when a message is posted.	 *	 *	@return boolean success.	 */	function sendNotice() {		global $Language;		$ids =& $this->Forum->getMonitoringIDs();		//		//	See if there is anyone to send messages to		//		if (!count($ids) > 0 && !$this->Forum->getSendAllPostsTo()) {			return true;		}		$messagelink='http://'.$GLOBALS[sys_default_domain].'/forum/message.php?msg_id='.$this->getID();		$messagesender=$this->getPosterName();		$messagebody=util_line_wrap(util_unconvert_htmlspecialchars($this->getBody()));		$messagesys=$GLOBALS['sys_name'];		$messagemonitor='http://'.$GLOBALS[sys_default_domain].'/forum/monitor.php?forum_id='.$this->Forum->getID() .'&group_id='.$this->Forum->Group->getID().'&stop=1';		//		$body = stripcslashes($Language->getText('forum_utils', 'mailmonitor', array($messagelink, $messagesender, $messagebody, $messagesys, $messagemonitor)));		$body = "\nRead and respond to this message at: ".		"\nhttp://$GLOBALS[sys_default_domain]/forum/message.php?msg_id=".$this->getID().		"\nBy: " . $this->getPosterName() .		"\n\n" . util_line_wrap(util_unconvert_htmlspecialchars($this->getBody())).		"\n\n______________________________________________________________________".		"\nRead and respond to this message at: ".		"\nhttp://$GLOBALS[sys_default_domain]/forum/message.php?msg_id=".$this->getID().		"\n\nYou are receiving this email because you elected to monitor this forum.".		"\nTo stop monitoring this forum, login to $GLOBALS[sys_name] and visit: ".		"\nhttp://$GLOBALS[sys_default_domain]/forum/monitor.php?forum_id=".$this->Forum->getID() .'&group_id='.$this->Forum->Group->getID().'&stop=1';		$subject="[" . $this->Forum->Group->getUnixName() . " - " . $this->Forum->getName() ."] ".util_unconvert_htmlspecialchars($this->getSubject());		util_handle_message(array_unique($ids),$subject,$body,$this->Forum->getSendAllPostsTo());		return true;	}}?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?