diff options
Diffstat (limited to 'phpBB/includes/mcp/mcp_main.php')
| -rw-r--r-- | phpBB/includes/mcp/mcp_main.php | 303 | 
1 files changed, 222 insertions, 81 deletions
| diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php index 016094c5d4..9702056d7b 100644 --- a/phpBB/includes/mcp/mcp_main.php +++ b/phpBB/includes/mcp/mcp_main.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package mcp -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -18,7 +22,6 @@ if (!defined('IN_PHPBB'))  /**  * mcp_main  * Handling mcp actions -* @package mcp  */  class mcp_main  { @@ -32,8 +35,8 @@ class mcp_main  	function main($id, $mode)  	{ -		global $auth, $db, $user, $template, $action; -		global $config, $phpbb_root_path, $phpEx, $request; +		global $auth, $user, $action; +		global $phpbb_root_path, $phpEx, $request;  		global $phpbb_dispatcher;  		$quickmod = ($mode == 'quickmod') ? true : false; @@ -42,7 +45,7 @@ class mcp_main  		{  			case 'lock':  			case 'unlock': -				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); +				$topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));  				if (!sizeof($topic_ids))  				{ @@ -55,7 +58,7 @@ class mcp_main  			case 'lock_post':  			case 'unlock_post': -				$post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0)); +				$post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0));  				if (!sizeof($post_ids))  				{ @@ -70,7 +73,7 @@ class mcp_main  			case 'make_global':  			case 'make_normal': -				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); +				$topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));  				if (!sizeof($topic_ids))  				{ @@ -83,7 +86,7 @@ class mcp_main  			case 'move':  				$user->add_lang('viewtopic'); -				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); +				$topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));  				if (!sizeof($topic_ids))  				{ @@ -96,7 +99,7 @@ class mcp_main  			case 'fork':  				$user->add_lang('viewtopic'); -				$topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0)); +				$topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));  				if (!sizeof($topic_ids))  				{ @@ -120,7 +123,7 @@ class mcp_main  					trigger_error('NO_TOPIC_SELECTED');  				} -				mcp_delete_topic($topic_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); +				mcp_delete_topic($topic_ids, $soft_delete, $request->variable('delete_reason', '', true));  			break;  			case 'delete_post': @@ -137,7 +140,7 @@ class mcp_main  					trigger_error('NO_POST_SELECTED');  				} -				mcp_delete_post($post_ids, $soft_delete, ($soft_delete) ? $request->variable('delete_reason', '', true) : ''); +				mcp_delete_post($post_ids, $soft_delete, $request->variable('delete_reason', '', true));  			break;  			case 'restore_topic': @@ -158,9 +161,13 @@ class mcp_main  				* This event allows you to handle custom quickmod options  				*  				* @event core.modify_quickmod_actions +				* @var	string	action		Topic quick moderation action name +				* @var	bool	quickmod	Flag indicating whether MCP is in quick moderation mode  				* @since 3.1.0-a4 +				* @change 3.1.0-RC4 Added variables: action, quickmod  				*/ -				$phpbb_dispatcher->dispatch('core.modify_quickmod_actions'); +				$vars = array('action', 'quickmod'); +				extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_actions', compact($vars)));  			break;  		} @@ -182,9 +189,9 @@ class mcp_main  				$user->add_lang('viewforum'); -				$forum_id = request_var('f', 0); +				$forum_id = $request->variable('f', 0); -				$forum_info = get_forum_data($forum_id, 'm_', true); +				$forum_info = phpbb_get_forum_data($forum_id, 'm_', true);  				if (!sizeof($forum_info))  				{ @@ -219,6 +226,31 @@ class mcp_main  			break;  			default: +				if ($quickmod) +				{ +					switch ($action) +					{ +						case 'lock': +						case 'unlock': +						case 'make_announce': +						case 'make_sticky': +						case 'make_global': +						case 'make_normal': +						case 'make_onindex': +						case 'move': +						case 'fork': +						case 'delete_topic': +							trigger_error('TOPIC_NOT_EXIST'); +						break; + +						case 'lock_post': +						case 'unlock_post': +						case 'delete_post': +							trigger_error('POST_NOT_EXIST'); +						break; +					} +				} +  				trigger_error('NO_MODE', E_USER_ERROR);  			break;  		} @@ -230,7 +262,7 @@ class mcp_main  */  function lock_unlock($action, $ids)  { -	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; +	global $user, $db, $request, $phpbb_log, $phpbb_dispatcher;  	if ($action == 'lock' || $action == 'unlock')  	{ @@ -249,7 +281,7 @@ function lock_unlock($action, $ids)  	$orig_ids = $ids; -	if (!check_ids($ids, $table, $sql_id, array('m_lock'))) +	if (!phpbb_check_ids($ids, $table, $sql_id, array('m_lock')))  	{  		// Make sure that for f_user_lock only the lock action is triggered.  		if ($action != 'lock') @@ -259,14 +291,14 @@ function lock_unlock($action, $ids)  		$ids = $orig_ids; -		if (!check_ids($ids, $table, $sql_id, array('f_user_lock'))) +		if (!phpbb_check_ids($ids, $table, $sql_id, array('f_user_lock')))  		{  			return;  		}  	}  	unset($orig_ids); -	$redirect = request_var('redirect', build_url(array('action', 'quickmod'))); +	$redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));  	$redirect = reapply_sid($redirect);  	$s_hidden_fields = build_hidden_fields(array( @@ -274,7 +306,6 @@ function lock_unlock($action, $ids)  		'action'			=> $action,  		'redirect'			=> $redirect)  	); -	$success_msg = '';  	if (confirm_box(true))  	{ @@ -283,13 +314,34 @@ function lock_unlock($action, $ids)  			WHERE ' . $db->sql_in_set($sql_id, $ids);  		$db->sql_query($sql); -		$data = ($action == 'lock' || $action == 'unlock') ? get_topic_data($ids) : get_post_data($ids); +		$data = ($action == 'lock' || $action == 'unlock') ? phpbb_get_topic_data($ids) : phpbb_get_post_data($ids);  		foreach ($data as $id => $row)  		{ -			add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_' . strtoupper($action), $row['topic_title']); +			$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_' . strtoupper($action), false, array( +				'forum_id' => $row['forum_id'], +				'topic_id' => $row['topic_id'], +				'post_id'  => isset($row['post_id']) ? $row['post_id'] : 0, +				$row['topic_title'] +			));  		} +		/** +		 * Perform additional actions after locking/unlocking posts/topics +		 * +		 * @event core.mcp_lock_unlock_after +		 * @var	string	action				Variable containing the action we perform on the posts/topics ('lock', 'unlock', 'lock_post' or 'unlock_post') +		 * @var	array	ids					Array containing the post/topic IDs that have been locked/unlocked +		 * @var	array	data				Array containing posts/topics data +		 * @since 3.1.7-RC1 +		 */ +		$vars = array( +			'action', +			'ids', +			'data', +		); +		extract($phpbb_dispatcher->trigger_event('core.mcp_lock_unlock_after', compact($vars))); +  		$success_msg = $l_prefix . ((sizeof($ids) == 1) ? '' : 'S') . '_' . (($action == 'lock' || $action == 'lock_post') ? 'LOCKED' : 'UNLOCKED') . '_SUCCESS';  		meta_refresh(2, $redirect); @@ -314,7 +366,7 @@ function lock_unlock($action, $ids)  */  function change_topic_type($action, $topic_ids)  { -	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request; +	global $user, $db, $request, $phpbb_log;  	switch ($action)  	{ @@ -326,7 +378,7 @@ function change_topic_type($action, $topic_ids)  		case 'make_global':  			$new_topic_type = POST_GLOBAL; -			$check_acl = 'f_announce'; +			$check_acl = 'f_announce_global';  			$l_new_type = (sizeof($topic_ids) == 1) ? 'MCP_MAKE_GLOBAL' : 'MCP_MAKE_GLOBALS';  		break; @@ -343,14 +395,14 @@ function change_topic_type($action, $topic_ids)  		break;  	} -	$forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', $check_acl, true); +	$forum_id = phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', $check_acl, true);  	if ($forum_id === false)  	{  		return;  	} -	$redirect = request_var('redirect', build_url(array('action', 'quickmod'))); +	$redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));  	$redirect = reapply_sid($redirect);  	$s_hidden_fields = array( @@ -359,7 +411,6 @@ function change_topic_type($action, $topic_ids)  		'action'		=> $action,  		'redirect'		=> $redirect,  	); -	$success_msg = '';  	if (confirm_box(true))  	{ @@ -385,11 +436,15 @@ function change_topic_type($action, $topic_ids)  		if (sizeof($topic_ids))  		{ -			$data = get_topic_data($topic_ids); +			$data = phpbb_get_topic_data($topic_ids);  			foreach ($data as $topic_id => $row)  			{ -				add_log('mod', $forum_id, $topic_id, 'LOG_TOPIC_TYPE_CHANGED', $row['topic_title']); +				$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_TOPIC_TYPE_CHANGED', false, array( +					'forum_id' => $forum_id, +					'topic_id' => $topic_id, +					$row['topic_title'] +				));  			}  		} @@ -415,20 +470,19 @@ function change_topic_type($action, $topic_ids)  */  function mcp_move_topic($topic_ids)  { -	global $auth, $user, $db, $template; +	global $auth, $user, $db, $template, $phpbb_log, $request;  	global $phpEx, $phpbb_root_path; -	global $request;  	// Here we limit the operation to one forum only -	$forum_id = check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true); +	$forum_id = phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_move'), true);  	if ($forum_id === false)  	{  		return;  	} -	$to_forum_id = request_var('to_forum_id', 0); -	$redirect = request_var('redirect', build_url(array('action', 'quickmod'))); +	$to_forum_id = $request->variable('to_forum_id', 0); +	$redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));  	$additional_msg = $success_msg = '';  	$s_hidden_fields = build_hidden_fields(array( @@ -440,7 +494,7 @@ function mcp_move_topic($topic_ids)  	if ($to_forum_id)  	{ -		$forum_data = get_forum_data($to_forum_id, 'f_post'); +		$forum_data = phpbb_get_forum_data($to_forum_id, 'f_post');  		if (!sizeof($forum_data))  		{ @@ -477,7 +531,7 @@ function mcp_move_topic($topic_ids)  	if (confirm_box(true))  	{ -		$topic_data = get_topic_data($topic_ids); +		$topic_data = phpbb_get_topic_data($topic_ids);  		$leave_shadow = (isset($_POST['move_leave_shadow'])) ? true : false;  		$forum_sync_data = array(); @@ -494,11 +548,11 @@ function mcp_move_topic($topic_ids)  			{  				$topics_moved++;  			} -			elseif ($topic_info['topic_visibility'] == ITEM_UNAPPROVED) +			else if ($topic_info['topic_visibility'] == ITEM_UNAPPROVED || $topic_info['topic_visibility'] == ITEM_REAPPROVE)  			{  				$topics_moved_unapproved++;  			} -			elseif ($topic_info['topic_visibility'] == ITEM_DELETED) +			else if ($topic_info['topic_visibility'] == ITEM_DELETED)  			{  				$topics_moved_softdeleted++;  			} @@ -525,9 +579,19 @@ function mcp_move_topic($topic_ids)  		$forum_ids = array($to_forum_id);  		foreach ($topic_data as $topic_id => $row)  		{ -			// Get the list of forums to resync, add a log entry +			// Get the list of forums to resync  			$forum_ids[] = $row['forum_id']; -			add_log('mod', $to_forum_id, $topic_id, 'LOG_MOVE', $row['forum_name'], $forum_data['forum_name']); + +			// We add the $to_forum_id twice, because 'forum_id' is updated +			// when the topic is moved again later. +			$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MOVE', false, array( +				'forum_id'		=> (int) $to_forum_id, +				'topic_id'		=> (int) $topic_id, +				$row['forum_name'], +				$forum_data['forum_name'], +				(int) $row['forum_id'], +				(int) $forum_data['forum_id'], +			));  			// Leave a redirection if required and only if the topic is visible to users  			if ($leave_shadow && $row['topic_visibility'] == ITEM_APPROVED && $row['topic_type'] != POST_GLOBAL) @@ -555,7 +619,7 @@ function mcp_move_topic($topic_ids)  					'topic_last_poster_id'	=>	(int) $row['topic_last_poster_id'],  					'topic_last_poster_colour'=>(string) $row['topic_last_poster_colour'],  					'topic_last_poster_name'=>	(string) $row['topic_last_poster_name'], -					'topic_last_post_subject'=>	(string)  $row['topic_last_post_subject'], +					'topic_last_post_subject'=>	(string) $row['topic_last_post_subject'],  					'topic_last_post_time'	=>	(int) $row['topic_last_post_time'],  					'topic_last_view_time'	=>	(int) $row['topic_last_view_time'],  					'topic_moved_id'		=>	(int) $row['topic_id'], @@ -638,7 +702,7 @@ function mcp_move_topic($topic_ids)  		confirm_box(false, 'MOVE_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');  	} -	$redirect = request_var('redirect', "index.$phpEx"); +	$redirect = $request->variable('redirect', "index.$phpEx");  	$redirect = reapply_sid($redirect);  	if (!$success_msg) @@ -663,9 +727,9 @@ function mcp_move_topic($topic_ids)  */  function mcp_restore_topic($topic_ids)  { -	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; +	global $user, $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_log; -	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve'))) +	if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve')))  	{  		return;  	} @@ -685,15 +749,21 @@ function mcp_restore_topic($topic_ids)  	{  		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS'; -		$data = get_topic_data($topic_ids); +		$data = phpbb_get_topic_data($topic_ids); +		/* @var $phpbb_content_visibility \phpbb\content_visibility */  		$phpbb_content_visibility = $phpbb_container->get('content.visibility');  		foreach ($data as $topic_id => $row)  		{  			$return = $phpbb_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), '');  			if (!empty($return))  			{ -				add_log('mod', $row['forum_id'], $topic_id, 'LOG_RESTORE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); +				$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_RESTORE_TOPIC', false, array( +					'forum_id' => $row['forum_id'], +					'topic_id' => $topic_id, +					$row['topic_title'], +					$row['topic_first_poster_name'] +				));  			}  		}  	} @@ -736,9 +806,10 @@ function mcp_restore_topic($topic_ids)  */  function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_topic')  { -	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; +	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_log; -	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete'))) +	$check_permission = ($is_soft) ? 'm_softdelete' : 'm_delete'; +	if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array($check_permission)))  	{  		return;  	} @@ -758,36 +829,53 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''  	{  		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_DELETED_SUCCESS' : 'TOPICS_DELETED_SUCCESS'; -		$data = get_topic_data($topic_ids); +		$data = phpbb_get_topic_data($topic_ids);  		foreach ($data as $topic_id => $row)  		{  			if ($row['topic_moved_id'])  			{ -				add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_SHADOW_TOPIC', $row['topic_title']); +				$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_DELETE_SHADOW_TOPIC', false, array( +					'forum_id' => $row['forum_id'], +					'topic_id' => $topic_id, +					$row['topic_title'] +				));  			}  			else  			{  				// Only soft delete non-shadow topics  				if ($is_soft)  				{ +					/* @var $phpbb_content_visibility \phpbb\content_visibility */  					$phpbb_content_visibility = $phpbb_container->get('content.visibility');  					$return = $phpbb_content_visibility->set_topic_visibility(ITEM_DELETED, $topic_id, $row['forum_id'], $user->data['user_id'], time(), $soft_delete_reason);  					if (!empty($return))  					{ -						add_log('mod', $row['forum_id'], $topic_id, 'LOG_SOFTDELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); +						$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SOFTDELETE_TOPIC', false, array( +							'forum_id' => $row['forum_id'], +							'topic_id' => $topic_id, +							$row['topic_title'], +							$row['topic_first_poster_name'], +							$soft_delete_reason +						));  					}  				}  				else  				{ -					add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']); +					$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_DELETE_TOPIC', false, array( +						'forum_id' => $row['forum_id'], +						'topic_id' => $topic_id, +						$row['topic_title'], +						$row['topic_first_poster_name'], +						$soft_delete_reason +					));  				}  			}  		}  		if (!$is_soft)  		{ -			$return = delete_topics('topic_id', $topic_ids); +			delete_topics('topic_id', $topic_ids);  		}  	}  	else @@ -796,8 +884,17 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''  		$user->add_lang('posting'); +		// If there are only shadow topics, we neither need a reason nor softdelete +		$sql = 'SELECT topic_id +			FROM ' . TOPICS_TABLE . ' +			WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . ' +				AND topic_moved_id = 0'; +		$result = $db->sql_query_limit($sql, 1); +		$only_shadow = !$db->sql_fetchfield('topic_id'); +		$db->sql_freeresult($result); +  		$only_softdeleted = false; -		if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id)) +		if (!$only_shadow && $auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id))  		{  			// If there are only soft deleted topics, we display a message why the option is not available  			$sql = 'SELECT topic_id @@ -810,11 +907,11 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''  		}  		$template->assign_vars(array( +			'S_SHADOW_TOPICS'		=> $only_shadow,  			'S_SOFTDELETED'			=> $only_softdeleted,  			'S_TOPIC_MODE'			=> true,  			'S_ALLOWED_DELETE'		=> $auth->acl_get('m_delete', $forum_id),  			'S_ALLOWED_SOFTDELETE'	=> $auth->acl_get('m_softdelete', $forum_id), -			'S_DELETE_REASON'		=> $auth->acl_get('m_softdelete', $forum_id),  		));  		$l_confirm = (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS'; @@ -823,7 +920,7 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''  			$l_confirm .= '_PERMANENTLY';  			$s_hidden_fields['delete_permanent'] = '1';  		} -		else if (!$auth->acl_get('m_softdelete', $forum_id)) +		else if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id))  		{  			$s_hidden_fields['delete_permanent'] = '1';  		} @@ -865,9 +962,10 @@ function mcp_delete_topic($topic_ids, $is_soft = false, $soft_delete_reason = ''  */  function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_post')  { -	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container; +	global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container, $phpbb_log; -	if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_softdelete'))) +	$check_permission = ($is_soft) ? 'm_softdelete' : 'm_delete'; +	if (!phpbb_check_ids($post_ids, POSTS_TABLE, 'post_id', array($check_permission)))  	{  		return;  	} @@ -885,7 +983,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  	if (confirm_box(true) && $is_soft)  	{ -		$post_info = get_post_data($post_ids); +		$post_info = phpbb_get_post_data($post_ids);  		$topic_info = $approve_log = array(); @@ -921,6 +1019,7 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  			);  		} +		/* @var $phpbb_content_visibility \phpbb\content_visibility */  		$phpbb_content_visibility = $phpbb_container->get('content.visibility');  		foreach ($topic_info as $topic_id => $topic_data)  		{ @@ -935,7 +1034,14 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  		foreach ($approve_log as $row)  		{  			$post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username']; -			add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_SOFTDELETE_POST', $row['post_subject'], $post_username); +			$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_SOFTDELETE_POST', false, array( +				'forum_id' => $row['forum_id'], +				'topic_id' => $row['topic_id'], +				'post_id'  => $row['post_id'], +				$row['post_subject'], +				$post_username, +				$soft_delete_reason +			));  		}  		$topic_id = $request->variable('t', 0); @@ -973,12 +1079,19 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  		$affected_topics = sizeof($topic_id_list);  		$db->sql_freeresult($result); -		$post_data = get_post_data($post_ids); +		$post_data = phpbb_get_post_data($post_ids);  		foreach ($post_data as $id => $row)  		{  			$post_username = ($row['poster_id'] == ANONYMOUS && !empty($row['post_username'])) ? $row['post_username'] : $row['username']; -			add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username); +			$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_DELETE_POST', false, array( +				'forum_id' => $row['forum_id'], +				'topic_id' => $row['topic_id'], +				'post_id'  => $row['post_id'], +				$row['post_subject'], +				$post_username, +				$soft_delete_reason +			));  		}  		// Now delete the posts, topics and forums are automatically resync'ed @@ -1051,7 +1164,6 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  			'S_SOFTDELETED'			=> $only_softdeleted,  			'S_ALLOWED_DELETE'		=> $auth->acl_get('m_delete', $forum_id),  			'S_ALLOWED_SOFTDELETE'	=> $auth->acl_get('m_softdelete', $forum_id), -			'S_DELETE_REASON'		=> $auth->acl_get('m_softdelete', $forum_id),  		));  		$l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS'; @@ -1093,17 +1205,18 @@ function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '',  function mcp_fork_topic($topic_ids)  {  	global $auth, $user, $db, $template, $config; -	global $phpEx, $phpbb_root_path; +	global $phpEx, $phpbb_root_path, $phpbb_log, $request, $phpbb_dispatcher; -	if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_'))) +	if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_')))  	{  		return;  	} -	$to_forum_id = request_var('to_forum_id', 0); -	$forum_id = request_var('f', 0); -	$redirect = request_var('redirect', build_url(array('action', 'quickmod'))); +	$to_forum_id = $request->variable('to_forum_id', 0); +	$forum_id = $request->variable('f', 0); +	$redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));  	$additional_msg = $success_msg = ''; +	$counter = array();  	$s_hidden_fields = build_hidden_fields(array(  		'topic_id_list'	=> $topic_ids, @@ -1114,7 +1227,7 @@ function mcp_fork_topic($topic_ids)  	if ($to_forum_id)  	{ -		$forum_data = get_forum_data($to_forum_id, 'f_post'); +		$forum_data = phpbb_get_forum_data($to_forum_id, 'f_post');  		if (!sizeof($topic_ids))  		{ @@ -1151,7 +1264,7 @@ function mcp_fork_topic($topic_ids)  	if (confirm_box(true))  	{ -		$topic_data = get_topic_data($topic_ids, 'f_post'); +		$topic_data = phpbb_get_topic_data($topic_ids, 'f_post');  		$total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0;  		$total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0; @@ -1170,7 +1283,7 @@ function mcp_fork_topic($topic_ids)  				}  				$error = false; -				$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user); +				$search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);  				$search_mode = 'post';  				if ($error) @@ -1221,6 +1334,7 @@ function mcp_fork_topic($topic_ids)  					$total_topics++;  				break;  				case ITEM_UNAPPROVED: +				case ITEM_REAPPROVE:  					$total_topics_unapproved++;  				break;  				case ITEM_DELETED: @@ -1230,8 +1344,6 @@ function mcp_fork_topic($topic_ids)  			if ($topic_row['poll_start'])  			{ -				$poll_rows = array(); -  				$sql = 'SELECT *  					FROM ' . POLL_OPTIONS_TABLE . "  					WHERE topic_id = $topic_id"; @@ -1248,12 +1360,13 @@ function mcp_fork_topic($topic_ids)  					$db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));  				} +				$db->sql_freeresult($result);  			}  			$sql = 'SELECT *  				FROM ' . POSTS_TABLE . "  				WHERE topic_id = $topic_id -				ORDER BY post_time ASC"; +				ORDER BY post_time ASC, post_id ASC";  			$result = $db->sql_query($sql);  			$post_rows = array(); @@ -1295,9 +1408,20 @@ function mcp_fork_topic($topic_ids)  					'post_edit_time'	=> (int) $row['post_edit_time'],  					'post_edit_count'	=> (int) $row['post_edit_count'],  					'post_edit_locked'	=> (int) $row['post_edit_locked'], -					'post_postcount'	=> 0, +					'post_postcount'	=> $row['post_postcount'],  				); - +				// Adjust post count only if the post can be incremented to the user counter +				if ($row['post_postcount']) +				{ +					if (isset($counter[$row['poster_id']])) +					{ +						++$counter[$row['poster_id']]; +					} +					else +					{ +						$counter[$row['poster_id']] = 1; +					} +				}  				$db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));  				$new_post_id = $db->sql_nextid(); @@ -1307,6 +1431,7 @@ function mcp_fork_topic($topic_ids)  						$total_posts++;  					break;  					case ITEM_UNAPPROVED: +					case ITEM_REAPPROVE:  						$total_posts_unapproved++;  					break;  					case ITEM_DELETED: @@ -1416,15 +1541,31 @@ function mcp_fork_topic($topic_ids)  			WHERE forum_id = ' . $to_forum_id;  		$db->sql_query($sql); +		if (!empty($counter)) +		{ +			// Do only one query per user and not a query per post. +			foreach ($counter as $user_id => $count) +			{ +				$sql = 'UPDATE ' . USERS_TABLE . ' +					SET user_posts = user_posts + ' . (int) $count . ' +					WHERE user_id = ' . (int) $user_id; +				$db->sql_query($sql); +			} +		} +  		sync('topic', 'topic_id', $new_topic_id_list);  		sync('forum', 'forum_id', $to_forum_id); -		set_config_count('num_topics', sizeof($new_topic_id_list), true); -		set_config_count('num_posts', $total_posts, true); +		$config->increment('num_topics', sizeof($new_topic_id_list), false); +		$config->increment('num_posts', $total_posts, false);  		foreach ($new_topic_id_list as $topic_id => $new_topic_id)  		{ -			add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']); +			$phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_FORK', false, array( +				'forum_id' => $to_forum_id, +				'topic_id' => $new_topic_id, +				$topic_row['forum_name'] +			));  		}  		$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; @@ -1440,7 +1581,7 @@ function mcp_fork_topic($topic_ids)  		confirm_box(false, 'FORK_TOPIC' . ((sizeof($topic_ids) == 1) ? '' : 'S'), $s_hidden_fields, 'mcp_move.html');  	} -	$redirect = request_var('redirect', "index.$phpEx"); +	$redirect = $request->variable('redirect', "index.$phpEx");  	$redirect = reapply_sid($redirect);  	if (!$success_msg) | 
