func_mod.php

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

PHP
1,245
字号
<?php/*+--------------------------------------------------------------------------|   Invision Power Board v2.1.6|   ========================================|   by Matthew Mecham|   (c) 2001 - 2004 Invision Power Services|   http://www.ibforums.com|   ========================================|   Web: http://www.invisionboard.com|   Time: Thu, 04 May 2006 17:39:49 GMT|   Release: b415613eeb952a2741ff6d53e0266428|   Email: matt@ibforums.com|   Licence Info: http://www.invisionpower.com+---------------------------------------------------------------------------||   > Moderator Core Functions|   > Module written by Matt Mecham|   > DBA Checked: Fri 21 May 2004|+--------------------------------------------------------------------------| NOTE:| This module does not do any access/permission checks, it merely| does what is asked and returns - see function for more info+--------------------------------------------------------------------------*/class func_mod{	//-----------------------------------------	// @modfunctions: constructor	// -----------	// Accepts: NOTHING	// Returns: NOTHING (TRUE)	//-----------------------------------------		var $topic = "";	var $forum = "";	var $error = "";		var $auto_update = FALSE;		var $stm   = "";	var $upload_dir = "";		var $moderator  = "";		function func_mod()	{		$this->error = "";				$this->upload_dir = $this->ipsclass->vars['upload_dir'];				return TRUE;	}		//-----------------------------------------	// @init: initialize module (allows us to create new obj)	// -----------	// Accepts: References to @$forum [ @$topic , @$moderator ]	// Returns: NOTHING (TRUE)	//-----------------------------------------		function init($forum="", $topic="", $moderator="")	{		$this->forum = $forum;				if ( is_array($topic) )		{			$this->topic = $topic;		}				if ( is_array($moderator) )		{			$this->moderator = $moderator;		}				return TRUE;	}			//-----------------------------------------	// @post_delete: delete post ID(s)	// -----------	// Accepts: $id (array | string) 	// Returns: NOTHING (TRUE/FALSE)	//-----------------------------------------		function post_delete($id)	{		$posts      = array();		$attach_tid = array();		$topics     = array();				$this->error = "";		if ( is_array( $id ) )		{			$id = $this->ipsclass->clean_int_array( $id );			if ( count($id) > 0 )			{				$pid = " IN(".implode(",",$id).")";			}			else			{				return FALSE;			}		}		else		{			if ( intval($id) )			{				$pid   = "=$id";			}			else			{				return FALSE;			}		}				//-----------------------------------------		// Get Stuff		//-----------------------------------------				$this->ipsclass->DB->simple_construct( array( 'select' => 'pid, topic_id', 'from' => 'posts', 'where' => 'pid'.$pid ) );		$this->ipsclass->DB->simple_exec();				while ( $r = $this->ipsclass->DB->fetch_row() )		{			$posts[ $r['pid'] ]       = $r['topic_id'];			$topics[ $r['topic_id'] ] = 1;		}				//-----------------------------------------		// Is there an attachment to this post?		//-----------------------------------------				$this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'attachments', 'where' => "attach_pid".$pid ) );		$this->ipsclass->DB->simple_exec();				$attach_ids = array();				while ( $killmeh = $this->ipsclass->DB->fetch_row( ) )		{			if ( $killmeh['attach_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_location'] );			}			if ( $killmeh['attach_thumb_location'] )			{				@unlink( $this->ipsclass->vars['upload_dir']."/".$killmeh['attach_thumb_location'] );			}						$attach_ids[] = $killmeh['attach_id'];			$attach_tid[ $posts[ $killmeh['attach_pid'] ] ] = $posts[ $killmeh['attach_pid'] ];		}				if ( count($attach_ids) )		{			$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'attachments', 'where' => "attach_id IN(".implode(",",$attach_ids).")" ) );						//-----------------------------------------			// Recount topic upload marker			//-----------------------------------------						require_once( ROOT_PATH.'sources/classes/post/class_post.php' );						$postlib           =  new class_post();			$postlib->ipsclass =& $this->ipsclass;						foreach( $attach_tid as $apid => $tid )			{				$postlib->pf_recount_topic_attachments($tid);			}		}				//-----------------------------------------		// delete the post		//-----------------------------------------				$this->ipsclass->DB->simple_exec_query( array( 'delete' => 'posts', 'where' => "pid".$pid ) );				//-----------------------------------------		// Update the stats		//-----------------------------------------				$this->ipsclass->cache['stats']['total_replies'] -= count($posts);				$this->ipsclass->update_cache( array( 'name' => 'stats', 'array' => 1, 'deletefirst' => 0 ) );				//-----------------------------------------		// Update all relevant topics		//-----------------------------------------				foreach( array_keys($topics) as $tid )		{			$this->rebuild_topic($tid);		}				$this->add_moderate_log("", "", "", $pid, "Deleted posts ($pid)");		return TRUE;	}		//-----------------------------------------	// @topic_add_reply: Appends topic with reply	// -----------	// Accepts: $post, $tids = array( 'tid', 'forumid' );	//         	// Returns: NOTHING (TRUE/FALSE)	//-----------------------------------------		function rebuild_topic($tid, $doforum=1)	{		$tid = intval($tid);				//-----------------------------------------		// Get the correct number of replies		//-----------------------------------------				$this->ipsclass->DB->simple_construct( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id=$tid and queued != 1" ) );		$this->ipsclass->DB->simple_exec();				$posts = $this->ipsclass->DB->fetch_row();				$pcount = intval( $posts['posts'] - 1 );				//-----------------------------------------		// Get the correct number of queued replies		//-----------------------------------------				$this->ipsclass->DB->simple_construct( array( 'select' => 'COUNT(*) as posts', 'from' => 'posts', 'where' => "topic_id=$tid and queued=1" ) );		$this->ipsclass->DB->simple_exec();				$qposts = $this->ipsclass->DB->fetch_row();				$qpcount = intval( $qposts['posts'] );				//-----------------------------------------		// Get last post info		//-----------------------------------------				$this->ipsclass->DB->cache_add_query( 'mod_func_get_last_post', array( 'tid' => $tid ) );		$this->ipsclass->DB->cache_exec_query();				$last_post = $this->ipsclass->DB->fetch_row();				//-----------------------------------------		// Get first post info		//-----------------------------------------				$this->ipsclass->DB->build_query( array( 'select'   => 'p.post_date, p.author_id, p.author_name, p.pid',												 'from'     => array( 'posts' => 'p' ),												 'where'    => "p.topic_id=$tid",												 'order'    => 'p.pid ASC',												 'limit'    => array(0,1),												 'add_join' => array( 0 => array( 'select' => 'm.id, m.members_display_name',																				  'from'   => array( 'members' => 'm' ),																				  'where'  => "p.author_id=m.id",																				  'type'   => 'left' ) )										)      );				$this->ipsclass->DB->exec_query();				$first_post = $this->ipsclass->DB->fetch_row();				//-----------------------------------------		// Get number of attachments		//-----------------------------------------				$this->ipsclass->DB->cache_add_query( 'mod_func_get_attach_count', array( 'tid' => $tid ) );		$this->ipsclass->DB->cache_exec_query();				$attach = $this->ipsclass->DB->fetch_row();		//-----------------------------------------		// Update topic		//-----------------------------------------				$this->ipsclass->DB->do_update( 'topics', array( 'last_post'         => $last_post['post_date'],														 'last_poster_id'    => $last_post['author_id'],														 'last_poster_name'  => $last_post['members_display_name'] ? $last_post['members_display_name'] : $last_post['author_name'],														 'topic_queuedposts' => $qpcount,														 'posts'             => $pcount,														 'starter_id'        => $first_post['author_id'],														 'starter_name'      => $first_post['members_display_name'] ? $first_post['members_display_name'] : $first_post['author_name'],														 'start_date'        => $first_post['post_date'],														 'topic_firstpost'   => $first_post['pid'],														 'topic_hasattach'   => intval($attach['count'])													   ), 'tid='.$tid );									   		//-----------------------------------------		// Update first post		//-----------------------------------------				if ( $first_post['new_topic'] != 1 and $first_post['pid'] )		{			$this->ipsclass->DB->do_shutdown_update( 'posts', array( 'new_topic' => 0 ), 'topic_id='.$tid );			$this->ipsclass->DB->do_shutdown_update( 'posts', array( 'new_topic' => 1 ), 'pid='.$first_post['pid'] );		}				//-----------------------------------------		// If we deleted the last post in a topic that was		// the last post in a forum, best update that :D		//-----------------------------------------				if ( ($this->ipsclass->forums->forums_by_id[ $last_post['forum_id'] ]['last_id'] == $tid) AND ($doforum == 1) )		{			$tt = $this->ipsclass->DB->simple_exec_query( array( 'select' => 'title, tid, last_post, last_poster_id, last_poster_name',																 'from'   => 'topics',																 'where'  => 'forum_id='.$last_post['forum_id'].' and approved=1',																 'order'  => 'last_post desc',																 'limit'  => array( 0,1 )														)      );						$dbs = array(						 'last_title'       => $tt['title']            ? $tt['title']            : "",						 'last_id'          => $tt['tid']              ? $tt['tid']              : "",						 'last_post'        => $tt['last_post']        ? $tt['last_post']        : "",						 'last_poster_name' => $tt['last_poster_name'] ? $tt['last_poster_name'] : "",						 'last_poster_id'   => $tt['last_poster_id']   ? $tt['last_poster_id']   : "",						);						$this->ipsclass->DB->do_update( 'forums', $dbs, "id=".intval($this->forum['id']) );						//-----------------------------------------			// Update forum cache			//-----------------------------------------						foreach( $dbs as $k => $v )			{				$this->ipsclass->cache['forum_cache'][ $this->forum['id'] ][ $k ] = $v;			}						$this->ipsclass->update_cache( array( 'name' => 'forum_cache', 'array' => 1, 'deletefirst' => 0 ) );		}		return TRUE;	}		//-----------------------------------------	// @topic_add_reply: Appends topic with reply	// -----------	// Accepts: $post, $tids = array( 'tid', 'forumid' );	//         	// Returns: NOTHING (TRUE/FALSE)	//-----------------------------------------		function topic_add_reply($post="", $tids=array(), $incpost=0)	{		if ( $post == "" )		{			return FALSE;		}				if ( count( $tids ) < 1 )		{			return FALSE;		}				$post = array(					  'author_id'   => $this->ipsclass->member['id'],					  'use_sig'     => 1,					  'use_emo'     => 1,					  'ip_address'  => $this->ipsclass->input['IP_ADDRESS'],					  'post_date'   => time(),					  'icon_id'     => 0,					  'post'        => $post,					  'author_name' => $this->ipsclass->member['members_display_name'],					  'topic_id'    => "",					  'queued'      => 0,					 );					 		//-----------------------------------------		// Add posts...		//-----------------------------------------		 		$seen_fids = array();		$add_posts = 0;				foreach( $tids as $row )		{			$tid = intval($row[0]);			$fid = intval($row[1]);			$pa  = array();			$ta  = array();						if ( ! in_array( $fid, $seen_fids ) )			{				$seen_fids[] = $fid;			}						if ( $tid and $fid )			{				$pa = $post;				$pa['topic_id'] = $tid;								$this->ipsclass->DB->do_insert( 'posts', $pa );								$ta = array (							  'last_poster_id'   => $this->ipsclass->member['id'],							  'last_poster_name' => $this->ipsclass->member['members_display_name'],							  'last_post'        => $pa['post_date'],							);											$db_string = $this->ipsclass->DB->compile_db_update_string( $ta );								$this->ipsclass->DB->simple_exec_query( array( 'update' => 'topics', 'set' => $db_string.", posts=posts+1", 'where' => 'tid='.$tid ) );						$add_posts++;			}		}						if ( $this->auto_update != FALSE )		{			if ( count($seen_fids) > 0 )

⌨️ 快捷键说明

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