api_topics_and_posts.php

来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 810 行 · 第 1/2 页

PHP
810
字号
<?php/*+--------------------------------------------------------------------------|   Invision Power Board v2.1.5|   =============================================|   by Matthew Mecham|   (c) 2001 - 2005 Invision Power Services, Inc.|   |   =============================================|   Web: |   Time: Wed, 01 Mar 2006 19:11:28 GMT|   Release: |   Licence Info: +---------------------------------------------------------------------------|   > $Date: 2006-02-01 18:16:26 +0000 (Wed, 01 Feb 2006) $|   > $Revision: 132 $|   > $Author: bfarber $+---------------------------------------------------------------------------||   > API: Topics and Posts|   > Module written by Matt Mecham|   > Date started: Wednesday 20th July 2005 (14:48)|+--------------------------------------------------------------------------*//*** API: Topics & Posts** IMPORTANT: This API DOESN'T check permissions, etc* So, it's entirely possible to add replies to closed topics* and to post new topics where the user doesn't normally have* permission.* EXAMPLE USAGE* <code>* $api = new api_topics_and_posts();* $api->ipsclass =& $this->ipsclass;* // ADD POST REPLY* $api->set_author_by_name('matt');* $api->set_post_content("<b>Hello World!</b> :D");* $api->set_topic_id( 100 );* # Default for show_signature is 1, added here for completeness* $api->post_settings['show_signature'] = 1;* # Optionally turn off rebuild to not rebuild topic, forum and stats* # $api->delay_rebuild = 1;* $api->create_new_reply();* // ADD NEW TOPIC* $api->set_author_by_name('matt');* $api->set_post_content("<b>Hello World!</b> :D");* $api->set_forum_id( 10 );* $api->set_topic_title('Hello World');* $api->set_topic_description('I am the description');* $api->set_topic_state('open');* $api->create_new_topic();* </code>** @package		InvisionPowerBoard* @subpackage	APIs* @author		Matt Mecham* @copyright	Invision Power Services, Inc.* @version		2.1*/if ( ! defined( 'IPS_API_PATH' ) ){	/**	* Define classes path	*/	define( 'IPS_API_PATH', dirname(__FILE__) ? dirname(__FILE__) : '.' );}if ( ! class_exists( 'api_core' ) ){	require_once( IPS_API_PATH.'/api_core.php' );}/*** API: Topics & Posts** This class deals with all showing, creating and editing topics and posts** @package		InvisionPowerBoard* @subpackage	APIs* @author  	 	Matt Mecham* @version		2.1* @since		2.1.0*/class api_topics_and_posts extends api_core{	/**	* Author DB row	*	* @var array	*/	var $author = array();		/**	* Post content	*	* @var string	*/	var $post_content = "";		/**	* Topic ID	*	* @var integer	*/	var $topic_id = "";		/**	* Set forum ID	*	* @var integer	*/	var $forum_id = "";		/**	* Topic DB row	*	* @var array	*/	var $topic = array();		/**	* Forum DB row	*	* @var array	*/	var $forum = array();		/**	* Editor class	*	* @var object	*/	var $editor;		/**	* Post class	*	* @var object	*/	var $post;		/**	* Email class	*	* @var object	*/	var $email;			/**	* Parser class	*	* @var object	*/	var $parser;		/**	* Func Mod	*	* @var object	*/	var $func_mod;		/**	* Flag classes loaded?	*	* @var 	integer	boolean	*/	var $classes_loaded = 0;		/**	* Delay rebuild flag	*	* If set to 1, you will need to manually	* rebuild topic info and forum info.	*	* @var 	integer	boolean	*/	var $delay_rebuild = 0;		/**	* Post settings	*	* @var	array	show_signature, show_emoticons, post_icon_id, is_invisible, post_date, ip_address, parse_html	*/	var $post_settings = array( 'show_signature' => 1,								'show_emoticons' => 1,								'post_icon_id'   => 0,								'is_invisible'   => 0,								'post_date'      => 0,								'ip_address'     => 0,								'parse_html'     => 0  );									/**	* Topic settings	*	* @var	array	topic_date, post_icon_id	*/	var $topic_settings = array( 'topic_date'     => 0,								 'post_icon_id'   => 0 );		/**	* Topic title	*	* @var string	*/	var $topic_title;		/**	* Topic description	*	* @var string	*/	var $topic_desc;		/**	* Topic state	*	* @var string (open or closed)	*/	var $topic_state = 'open';		/**	* Topic pinned	*	* @var integer	*/	var $topic_pinned = 0;		/**	* Topic invisible	*	* @var integer	*/	var $topic_invisible = 0;		/*-------------------------------------------------------------------------*/	// Create new topic	/*-------------------------------------------------------------------------*/	/**	* Saves the post	*	* @return	void 	*/	function create_new_topic()	{		//-------------------------------		// Got anything?		//-------------------------------				if ( ! $this->author OR ! $this->post_content OR ! $this->forum_id OR ! $this->topic_title )		{			$this->api_error[]  = 'not_all_data_ready';			$this->post_content = '';			return FALSE;		}				$this->api_tap_load_classes();				$this->topic_invisible = $this->topic_invisible ? $this->topic_invisible : $this->post_settings['is_invisible'];				//-------------------------------		// Attempt to format		//-------------------------------				$this->topic = array(							  'title'            => $this->ipsclass->parse_clean_value( $this->topic_title ),							  'description'      => $this->ipsclass->parse_clean_value( $this->topic_desc ),							  'state'            => $this->topic_state,							  'posts'            => 0,							  'starter_id'       => $this->author['id'],							  'starter_name'     => $this->author['members_display_name'],							  'start_date'       => $this->topic_settings['topic_date'] ? $this->topic_settings['topic_date'] : time(),							  'last_poster_id'   => $this->author['id'],							  'last_poster_name' => $this->author['members_display_name'],							  'last_post'        => $this->topic_settings['topic_date'] ? $this->topic_settings['topic_date'] : time(),							  'icon_id'          => $this->topic_settings['post_icon_id'],							  'author_mode'      => 1,							  'poll_state'       => 0,							  'last_vote'        => 0,							  'views'            => 0,							  'forum_id'         => $this->forum_id,							  'approved'         => $this->topic_invisible ? 0 : 1,							  'pinned'           => $this->topic_pinned );				//-------------------------------		// Insert topic		//-------------------------------				$this->ipsclass->DB->do_insert( 'topics', $this->topic );							$this->topic_id     = $this->ipsclass->DB->get_insert_id();		$this->topic['tid'] = $this->topic_id;				//-----------------------------------------		// Re-do member info		//-----------------------------------------				$temp_store = $this->ipsclass->member;				$this->ipsclass->member = $this->author;				//-----------------------------------------		// Tracker?		//-----------------------------------------				$this->post->forum_tracker( $this->topic['forum_id'], $this->topic_id, $this->topic['title'], $this->forum['name'], $this->post_content );				//-------------------------------		// Add post		//-------------------------------				$return_val = $this->create_new_reply();				$this->ipsclass->member = $temp_store;				return $return_val;	}		/*-------------------------------------------------------------------------*/	// Create new topic	/*-------------------------------------------------------------------------*/	/**	* Create new topic	*	* @return	void 	*/	function create_new_reply()	{		//-------------------------------		// Got anything?		//-------------------------------				if ( ! $this->author OR ! $this->post_content OR ! $this->topic_id )		{			$this->api_error[]  = 'no_post_content';			$this->post_content = '';			return FALSE;		}				$this->api_tap_load_classes();				//-------------------------------		// Attempt to format		//-------------------------------				$post = array(						'author_id'      => $this->author['id'],						'use_sig'        => $this->post_settings['show_signature'],						'use_emo'        => $this->post_settings['show_emoticons'],						'ip_address'     => $this->post_settings['ip_address'] ? $this->post_settings['ip_address'] : $this->ipsclass->ip_address,						'post_date'      => $this->post_settings['post_date']  ? $this->post_settings['post_date']  : time(),						'icon_id'        => $this->post_settings['post_icon_id'],						'post'           => $this->post_content,						'author_name'    => $this->author['members_display_name'],						'topic_id'       => $this->topic_id,						'queued'         => $this->post_settings['is_invisible'],						'post_htmlstate' => 0,						'post_key'       => md5( time() ),					 );					 		//-----------------------------------------		// Add post to DB		//-----------------------------------------				$this->ipsclass->DB->do_insert( 'posts', $post );				//-----------------------------------------		// Rebuild topic		//-----------------------------------------				$this->func_mod->rebuild_topic( $this->topic_id, 0 );				//-----------------------------------------		// Increment member?		//-----------------------------------------				if ( $this->forum['inc_postcount'] )		{			$this->ipsclass->DB->simple_update( 'members', 'posts=posts+1', 'id='.intval( $this->author['id'] ) );			$this->ipsclass->DB->simple_exec();		}				//-----------------------------------------		// Re-do member info		//-----------------------------------------				$temp_store = $this->ipsclass->member;				$this->ipsclass->member = $this->author;				//-----------------------------------------		// Tracker? (Only run when not creating topic)		//-----------------------------------------				if ( ! $this->topic_title )		{			$this->post->topic_tracker( $this->topic_id, $this->post_content, $this->author['members_display_name'], time() );		}				//-----------------------------------------

⌨️ 快捷键说明

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