⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forum.class

📁 GForge 3.0 协作开发平台 支持CVS, mailing lists, bug tracking, message boards/forums, task management, perman
💻 CLASS
字号:
<?php/** * GForge Forums Facility * * Copyright 2002 GForge, LLC * http://gforge.org/ * * @version   $Id: Forum.class,v 1.11 2003/02/12 17:23:47 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');require_once('common/forum/ForumMessage.class');class Forum extends Error {	/**	 * Associative array of data from db.	 *	 * @var	 array   $data_array.	 */	var $data_array;	/**	 * The Group object.	 *	 * @var	 object  $Group.	 */	var $Group; //group object	/**	 * An array of 'types' for this forum - nested, flat, ultimate, etc.	 *	 * @var	 array	view_types.	 */	var $view_types;	/**	 *  Constructor.	 *	 *	@param	object	The Group object to which this forum is associated.	 *  @param  int	 The group_forum_id.	 *  @param  array	The associative array of data.	 *	@return	boolean	success.	 */	function Forum(&$Group, $group_forum_id=false, $arr=false) {		global $Language;		$this->Error();		if (!$Group || !is_object($Group)) {			$this->setError($Language->getText('general','error_no_valid_group_object','Forum'));			return false;		}		if ($Group->isError()) {			$this->setError('Forum:: '.$Group->getErrorMessage());			return false;		}		$this->Group =& $Group;		if ($group_forum_id) {			if (!$arr || !is_array($arr)) {				if (!$this->fetchData($group_forum_id)) {					return false;				}			} else {				$this->data_array =& $arr;				if ($this->data_array['group_id'] != $this->Group->getID()) {					$this->setError($Language->getText('general','error_group_id'));					$this->data_array = null;					return false;				}			}			if (!$this->isPublic()) {				$perm =& $this->Group->getPermission( session_get_user() );				if (!$perm || !is_object($perm) || !$perm->isMember()) {					$this->setPermissionDeniedError();					$this->data_array = null;					return false;				}			}		}		$this->view_types[]='ultimate';		$this->view_types[]='flat';		$this->view_types[]='nested';		$this->view_types[]='threaded';		return true;	}	/**	 *	create - use this function to create a new entry in the database.	 *	 *	@param	string	The name of the forum.	 *	@param	string	The description of the forum.	 *	@param	int	Pass (1) if it should be public (0) for private.	 *	@param	string	The email address to send all new posts to.	 *	@param	int	Pass (1) if a welcome message should be created (0) for no welcome message.	 *	@param	int	Pass (1) if we should allow non-logged-in users to post (0) for mandatory login.	 *	@return	boolean	success.	 */	function create($forum_name,$description,$is_public=1,$send_all_posts_to='',$create_default_message=1,$allow_anonymous=1) {		global $Language;		if (strlen($forum_name) < 3) {			$this->setError($Language->getText('forum_common','error_min_name_length'));			return false;		}		if (strlen($description) < 10) {			$this->setError($Language->getText('forum_common','error_min_desc_length'));			return false;		}		if ($send_all_posts_to && !validate_email($send_all_posts_to)) {			$this->setInvalidEmailError();			return false;		}		// This is a hack to allow non-site-wide-admins to post		// news.  The news/submit.php checks for proper permissions.		// This needs to be revisited.		global $sys_news_group;		if ($this->Group->getID() == $sys_news_group) {			// Future check will be added.		} else {			// Current permissions check.			$perm =& $this->Group->getPermission( session_get_user() );			if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {				$this->setPermissionDeniedError();				return false;			}		}		$sql="INSERT INTO forum_group_list (group_id,forum_name,is_public,description,send_all_posts_to,allow_anonymous)			VALUES ('".$this->Group->getId()."',			'". htmlspecialchars($forum_name) ."',			'$is_public',			'". htmlspecialchars($description) ."',			'$send_all_posts_to',			'$allow_anonymous')";		db_begin();		$result=db_query($sql);		if (!$result) {			db_rollback();			$this->setError($Language->getText('forum_common','error_adding_forum').db_error());			return false;		}		$this->group_forum_id=db_insertid($result,'forum_group_list','group_forum_id');		$this->fetchData($this->group_forum_id);		if ($create_default_message) {			$fm=new ForumMessage($this);			if (!$fm->create("Welcome to ".$forum_name,"Welcome to ".$forum_name)) {				$this->setError($fm->getErrorMessage());				return false;			}		}		db_commit();		return true;	}	/**	 *  fetchData - re-fetch the data for this forum from the database.	 *	 *  @param  int	 The forum_id.	 *	@return	boolean	success.	 */	function fetchData($group_forum_id) {		global $Language;		$res=db_query("SELECT * FROM forum_group_list_vw			WHERE group_forum_id='$group_forum_id'			AND group_id='". $this->Group->getID() ."'");		if (!$res || db_numrows($res) < 1) {			$this->setError($Language->getText('forum_common','error_invalid_group_forum_id'));			return false;		}		$this->data_array =& db_fetch_array($res);		db_free_result($res);		return true;	}	/**	 *	getGroup - get the Group object this ArtifactType is associated with.	 *	 *	@return	object	The Group object.	 */	function &getGroup() {		return $this->Group;	}	/**	 *	getID - The id of this forum.	 *	 *	@return	int	The group_forum_id #.	 */	function getID() {		return $this->data_array['group_forum_id'];	}	/**	 *	getNextThreadID - The next thread_id for a new top in this forum.	 *	 *	@return	int	The next thread_id #.	 */	function getNextThreadID() {		$result=db_query("SELECT nextval('forum_thread_seq')");		if (!$result || db_numrows($result) < 1) {			echo db_error();			return false;		} else {			return db_result($result,0,0);		}	}	/**	 *	getSavedDate - The unix time when the person last hit "save my place".	 *	 *	@return	int	The unix time.	 */	function getSavedDate() {		if ($this->save_date) {			return $this->save_date;		} else {			if (session_loggedin()) {				$sql="SELECT save_date FROM forum_saved_place					WHERE user_id='".user_getid()."' AND forum_id='". $this->getID() ."';";				$result = db_query($sql);				if ($result && db_numrows($result) > 0) {					$this->save_date=db_result($result,0,'save_date');					return $this->save_date;				} else {					//highlight new messages from the past week only					$this->save_date=(time()-604800);					return $this->save_date;				}			} else {				//highlight new messages from the past week only				$this->save_date=(time()-604800);				return $this->save_date;			}		}	}	/**	 *	allowAnonymous - does this forum allow non-logged in users to post.	 *	 *	@return boolean	allow_anonymous.	 */	function allowAnonymous() {		return $this->data_array['allow_anonymous'];	}	/**	 *	isPublic - Is this forum open to the general public.	 *	 *	@return boolean	is_public.	 */	function isPublic() {		return $this->data_array['is_public'];	}	/**	 *	getName - get the name of this forum.	 *	 *	@return string	The name of this forum.	 */	function getName() {		return $this->data_array['forum_name'];	}	/**	 *	getSendAllPostsTo - an optional email address to send all forum posts to.	 *	 *	@return string	The email address.	 */	function getSendAllPostsTo() {		return $this->data_array['send_all_posts_to'];	}	/**	 *	getDescription - the description of this forum.	 *	 *	@return string	The description.	 */	function getDescription() {		return $this->data_array['description'];	}	/**	 *	getMessageCount - the total number of messages in this forum.	 *	 *	@return int	The count.	 */	function getMessageCount() {		return $this->data_array['total'];	}	/**	 *	getThreadCount - the total number of threads in this forum.	 *	 *	@return int	The count.	 */	function getThreadCount() {		return $this->data_array['threads'];	}	/**	 *	getMostRecentDate - the most recent date of a post to this board.	 *	 *	@return int	The most recent date.	 */	function getMostRecentDate() {		return $this->data_array['recent'];	}	/**	 *	getMonitoringIDs - return an array of user_id's for those monitoring this forum.	 *	 *	@return	array	The array of user_id's.	 */	function getMonitoringIDs() {		$sql="SELECT user_id FROM forum_monitored_forums WHERE forum_id='".$this->getID()."'";		$result=db_query($sql);		return util_result_column_to_array($result);	}	/**	 *	setMonitor - Add the current user to the list of people monitoring the forum.	 *	 *	@return	boolean	success.	 */	function setMonitor() {		global $Language;		if (!session_loggedin()) {			$this->setError($Language->getText('forum_common','error_set_monitor'));			return false;		}		$sql="SELECT * FROM forum_monitored_forums			WHERE user_id='".user_getid()."' AND forum_id='".$this->getID()."';";		$result = db_query($sql);		if (!$result || db_numrows($result) < 1) {			/*				User is not already monitoring thread, so				insert a row so monitoring can begin			*/			$sql="INSERT INTO forum_monitored_forums (forum_id,user_id)				VALUES ('".$this->getID()."','".user_getid()."')";			$result = db_query($sql);			if (!$result) {				$this->setError($Language->getText('forum_common','error_unable_to_add_monitor').' : '.db_error());				return false;			}		}		return true;	}	/**	 *	stopMonitor - Remove the current user from the list of people monitoring the forum.	 *	 *	@return	boolean	success.	 */	function stopMonitor() {		global $Language;		if (!session_loggedin()) {			$this->setError($Language->getText('forum_common','error_set_monitor'));			return false;		}		$sql="DELETE FROM forum_monitored_forums			WHERE user_id='".user_getid()."' AND forum_id='".$this->getID()."';";		return db_query($sql);	}	/**	 *	isMonitoring - See if the current user is in the list of people monitoring the forum.	 *	 *	@return	boolean	is_monitoring.	 */	function isMonitoring() {		if (!session_loggedin()) {			return false;		}		$sql="SELECT * FROM forum_monitored_forums			WHERE user_id='".user_getid()."' AND forum_id='".$this->getID()."';";		$result = db_query($sql);		if (!$result || db_numrows($result) < 1) {			return false;		} else {			return true;		}	}	/**	 *	savePlace - set a unix time into the database for this user, so future messages can be highlighted.	 *	 *	@return	boolean	success.	 */	function savePlace() {		global $Language;		if (!session_loggedin()) {			$this->setError($Language->getText('forum_common','error_save_when_logged_in'));			return false;		}		$sql="SELECT * FROM forum_saved_place			WHERE user_id='".user_getid()."' AND forum_id='".$this->getID()."'";		$result = db_query($sql);		if (!$result || db_numrows($result) < 1) {			/*				User is not already monitoring thread, so				insert a row so monitoring can begin			*/			$sql="INSERT INTO forum_saved_place (forum_id,user_id,save_date)				VALUES ('".$this->getID()."','".user_getid()."','".time()."')";			$result = db_query($sql);			if (!$result) {				$this->setError($Language->getText('forum_common_forum','error_save_place').': '.db_error());				return false;			}		} else {			$sql="UPDATE forum_saved_place				SET save_date='".time()."'				WHERE user_id='".user_getid()."' AND forum_id='".$this->getID()."'";			$result = db_query($sql);			if (!$result) {				$this->setError('Forum::savePlace() '.db_error());				return false;			}		}		return true;	}	/**	 *	update - use this function to update an entry in the database.	 *	 *	@param	string	The name of the forum.	 *	@param	string	The description of the forum.	 *	@param	int	Pass (1) if it should be public (0) for private.	 *	@param	string	The email address to send all new posts to.	 *	@param	int	Pass (1) if we should allow non-logged-in users to post (0) for mandatory login.	 *	@return	boolean	success.	 */	function update($forum_name,$description,$is_public=1,$send_all_posts_to='',$allow_anonymous=0) {		global $Language;		if (strlen($forum_name) < 3) {			$this->setError($Language->getText('forum_common','error_min_name_length'));			return false;		}		if (strlen($description) < 10) {			$this->setError($Language->getText('forum_common','error_min_desc_length'));			return false;		}		if ($send_all_posts_to && !validate_email($send_all_posts_to)) {			$this->setInvalidEmailError();			return false;		}		$perm =& $this->Group->getPermission( session_get_user() );		if (!$perm || !is_object($perm) || !$perm->isForumAdmin()) {			$this->setPermissionDeniedError();			return false;		}		$res=db_query("UPDATE forum_group_list SET			forum_name='". htmlspecialchars($forum_name) ."',			description='". htmlspecialchars($description) ."',			is_public='$is_public',			send_all_posts_to='$send_all_posts_to',			allow_anonymous='$allow_anonymous'			WHERE group_id='".$this->Group->getID()."'			AND group_forum_id='".$this->getID()."'");		if (!$res || db_affected_rows($res) < 1) {			$this->setError($Language->getText('general','error_on_update').': '.db_error());			return false;		}		return true;	}}?>

⌨️ 快捷键说明

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