aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/mcp/mcp_main.php
diff options
context:
space:
mode:
Diffstat (limited to 'phpBB/includes/mcp/mcp_main.php')
-rw-r--r--phpBB/includes/mcp/mcp_main.php922
1 files changed, 586 insertions, 336 deletions
diff --git a/phpBB/includes/mcp/mcp_main.php b/phpBB/includes/mcp/mcp_main.php
index 0cef8933fc..69c66639df 100644
--- a/phpBB/includes/mcp/mcp_main.php
+++ b/phpBB/includes/mcp/mcp_main.php
@@ -1,10 +1,13 @@
<?php
/**
*
-* @package mcp
-* @version $Id$
-* @copyright (c) 2005 phpBB Group
-* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+* 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.
*
*/
@@ -19,7 +22,6 @@ if (!defined('IN_PHPBB'))
/**
* mcp_main
* Handling mcp actions
-* @package mcp
*/
class mcp_main
{
@@ -34,7 +36,8 @@ class mcp_main
function main($id, $mode)
{
global $auth, $db, $user, $template, $action;
- global $config, $phpbb_root_path, $phpEx;
+ global $config, $phpbb_root_path, $phpEx, $request;
+ global $phpbb_dispatcher;
$quickmod = ($mode == 'quickmod') ? true : false;
@@ -109,27 +112,62 @@ class mcp_main
case 'delete_topic':
$user->add_lang('viewtopic');
- $topic_ids = (!$quickmod) ? request_var('topic_id_list', array(0)) : array(request_var('t', 0));
+ // f parameter is not reliable for permission usage, however we just use it to decide
+ // which permission we will check later on. So if it is manipulated, we will still catch it later on.
+ $forum_id = $request->variable('f', 0);
+ $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));
+ $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false;
if (!sizeof($topic_ids))
{
trigger_error('NO_TOPIC_SELECTED');
}
- mcp_delete_topic($topic_ids);
+ mcp_delete_topic($topic_ids, $soft_delete, $request->variable('delete_reason', '', true));
break;
case 'delete_post':
$user->add_lang('posting');
- $post_ids = (!$quickmod) ? request_var('post_id_list', array(0)) : array(request_var('p', 0));
+ // f parameter is not reliable for permission usage, however we just use it to decide
+ // which permission we will check later on. So if it is manipulated, we will still catch it later on.
+ $forum_id = $request->variable('f', 0);
+ $post_ids = (!$quickmod) ? $request->variable('post_id_list', array(0)) : array($request->variable('p', 0));
+ $soft_delete = (($request->is_set_post('confirm') && !$request->is_set_post('delete_permanent')) || !$auth->acl_get('m_delete', $forum_id)) ? true : false;
if (!sizeof($post_ids))
{
trigger_error('NO_POST_SELECTED');
}
- mcp_delete_post($post_ids);
+ mcp_delete_post($post_ids, $soft_delete, $request->variable('delete_reason', '', true));
+ break;
+
+ case 'restore_topic':
+ $user->add_lang('posting');
+
+ $topic_ids = (!$quickmod) ? $request->variable('topic_id_list', array(0)) : array($request->variable('t', 0));
+
+ if (!sizeof($topic_ids))
+ {
+ trigger_error('NO_TOPIC_SELECTED');
+ }
+
+ mcp_restore_topic($topic_ids);
+ break;
+
+ default:
+ /**
+ * 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
+ * @changed 3.1.0-RC4 Added variables: action, quickmod
+ */
+ $vars = array('action', 'quickmod');
+ extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_actions', compact($vars)));
break;
}
@@ -153,7 +191,7 @@ class mcp_main
$forum_id = request_var('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))
{
@@ -188,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;
}
@@ -199,7 +262,7 @@ class mcp_main
*/
function lock_unlock($action, $ids)
{
- global $auth, $user, $db, $phpEx, $phpbb_root_path;
+ global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_dispatcher;
if ($action == 'lock' || $action == 'unlock')
{
@@ -218,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')
@@ -228,7 +291,7 @@ 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;
}
@@ -236,6 +299,7 @@ function lock_unlock($action, $ids)
unset($orig_ids);
$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
+ $redirect = reapply_sid($redirect);
$s_hidden_fields = build_hidden_fields(array(
$sql_id . '_list' => $ids,
@@ -251,32 +315,46 @@ 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']);
}
+ /**
+ * 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';
- }
- else
- {
- confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
- }
- $redirect = request_var('redirect', "index.$phpEx");
- $redirect = reapply_sid($redirect);
+ meta_refresh(2, $redirect);
+ $message = $user->lang[$success_msg];
- if (!$success_msg)
- {
- redirect($redirect);
+ if (!$request->is_ajax())
+ {
+ $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
+ }
+ trigger_error($message);
}
else
{
- meta_refresh(2, $redirect);
- trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
+ confirm_box(false, strtoupper($action) . '_' . $l_prefix . ((sizeof($ids) == 1) ? '' : 'S'), $s_hidden_fields);
}
+
+ redirect($redirect);
}
/**
@@ -284,7 +362,7 @@ function lock_unlock($action, $ids)
*/
function change_topic_type($action, $topic_ids)
{
- global $auth, $user, $db, $phpEx, $phpbb_root_path;
+ global $auth, $user, $db, $phpEx, $phpbb_root_path, $request;
switch ($action)
{
@@ -313,7 +391,7 @@ 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)
{
@@ -321,6 +399,7 @@ function change_topic_type($action, $topic_ids)
}
$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
+ $redirect = reapply_sid($redirect);
$s_hidden_fields = array(
'topic_id_list' => $topic_ids,
@@ -332,196 +411,51 @@ function change_topic_type($action, $topic_ids)
if (confirm_box(true))
{
- if ($new_topic_type != POST_GLOBAL)
+ $sql = 'UPDATE ' . TOPICS_TABLE . "
+ SET topic_type = $new_topic_type
+ WHERE " . $db->sql_in_set('topic_id', $topic_ids);
+ $db->sql_query($sql);
+
+ if (($new_topic_type == POST_GLOBAL) && sizeof($topic_ids))
{
+ // Delete topic shadows for global announcements
+ $sql = 'DELETE FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
+ $db->sql_query($sql);
+
$sql = 'UPDATE ' . TOPICS_TABLE . "
SET topic_type = $new_topic_type
- WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
- AND forum_id <> 0';
+ WHERE " . $db->sql_in_set('topic_id', $topic_ids);
$db->sql_query($sql);
-
- // Reset forum id if a global topic is within the array
- $to_forum_id = request_var('to_forum_id', 0);
-
- if ($to_forum_id)
- {
- $sql = 'UPDATE ' . TOPICS_TABLE . "
- SET topic_type = $new_topic_type, forum_id = $to_forum_id
- WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
- AND forum_id = 0';
- $db->sql_query($sql);
-
- // Update forum_ids for all posts
- $sql = 'UPDATE ' . POSTS_TABLE . "
- SET forum_id = $to_forum_id
- WHERE " . $db->sql_in_set('topic_id', $topic_ids) . '
- AND forum_id = 0';
- $db->sql_query($sql);
-
- // Do a little forum sync stuff
- $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
- FROM ' . TOPICS_TABLE . ' t
- WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
- $result = $db->sql_query($sql);
- $row_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- $sync_sql = array();
-
- if ($row_data['topic_posts'])
- {
- $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . (int) $row_data['topic_posts'];
- }
-
- if ($row_data['topics_authed'])
- {
- $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $row_data['topics_authed'];
- }
-
- $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) sizeof($topic_ids);
-
- foreach ($sync_sql as $forum_id_key => $array)
- {
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET ' . implode(', ', $array) . '
- WHERE forum_id = ' . $forum_id_key;
- $db->sql_query($sql);
- }
-
- sync('forum', 'forum_id', $to_forum_id);
- }
- }
- else
- {
- // Get away with those topics already being a global announcement by re-calculating $topic_ids
- $sql = 'SELECT topic_id
- FROM ' . TOPICS_TABLE . '
- WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
- AND forum_id <> 0';
- $result = $db->sql_query($sql);
-
- $topic_ids = array();
- while ($row = $db->sql_fetchrow($result))
- {
- $topic_ids[] = $row['topic_id'];
- }
- $db->sql_freeresult($result);
-
- if (sizeof($topic_ids))
- {
- // Delete topic shadows for global announcements
- $sql = 'DELETE FROM ' . TOPICS_TABLE . '
- WHERE ' . $db->sql_in_set('topic_moved_id', $topic_ids);
- $db->sql_query($sql);
-
- $sql = 'UPDATE ' . TOPICS_TABLE . "
- SET topic_type = $new_topic_type, forum_id = 0
- WHERE " . $db->sql_in_set('topic_id', $topic_ids);
- $db->sql_query($sql);
-
- // Update forum_ids for all posts
- $sql = 'UPDATE ' . POSTS_TABLE . '
- SET forum_id = 0
- WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
- $db->sql_query($sql);
-
- // Do a little forum sync stuff
- $sql = 'SELECT SUM(t.topic_replies + t.topic_approved) as topic_posts, COUNT(t.topic_approved) as topics_authed
- FROM ' . TOPICS_TABLE . ' t
- WHERE ' . $db->sql_in_set('t.topic_id', $topic_ids);
- $result = $db->sql_query($sql);
- $row_data = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- $sync_sql = array();
-
- if ($row_data['topic_posts'])
- {
- $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . (int) $row_data['topic_posts'];
- }
-
- if ($row_data['topics_authed'])
- {
- $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $row_data['topics_authed'];
- }
-
- $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) sizeof($topic_ids);
-
- foreach ($sync_sql as $forum_id_key => $array)
- {
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET ' . implode(', ', $array) . '
- WHERE forum_id = ' . $forum_id_key;
- $db->sql_query($sql);
- }
-
- sync('forum', 'forum_id', $forum_id);
- }
}
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_TYPE_CHANGED' : 'TOPICS_TYPE_CHANGED';
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']);
}
}
- }
- else
- {
- // Global topic involved?
- $global_involved = false;
- if ($new_topic_type != POST_GLOBAL)
- {
- $sql = 'SELECT forum_id
- FROM ' . TOPICS_TABLE . '
- WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
- AND forum_id = 0';
- $result = $db->sql_query($sql);
- $row = $db->sql_fetchrow($result);
- $db->sql_freeresult($result);
-
- if ($row)
- {
- $global_involved = true;
- }
- }
-
- if ($global_involved)
- {
- global $template;
-
- $template->assign_vars(array(
- 'S_FORUM_SELECT' => make_forum_select(request_var('f', $forum_id), false, false, true, true),
- 'S_CAN_LEAVE_SHADOW' => false,
- 'ADDITIONAL_MSG' => (sizeof($topic_ids) == 1) ? $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENT'] : $user->lang['SELECT_FORUM_GLOBAL_ANNOUNCEMENTS'])
- );
+ meta_refresh(2, $redirect);
+ $message = $user->lang[$success_msg];
- confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields), 'mcp_move.html');
- }
- else
+ if (!$request->is_ajax())
{
- confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
+ $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>');
}
- }
-
- $redirect = request_var('redirect', "index.$phpEx");
- $redirect = reapply_sid($redirect);
-
- if (!$success_msg)
- {
- redirect($redirect);
+ trigger_error($message);
}
else
{
- meta_refresh(2, $redirect);
- trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
+ confirm_box(false, $l_new_type, build_hidden_fields($s_hidden_fields));
}
+
+ redirect($redirect);
}
/**
@@ -529,11 +463,11 @@ 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, $phpbb_dispatcher;
global $phpEx, $phpbb_root_path;
// 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)
{
@@ -553,7 +487,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))
{
@@ -584,13 +518,13 @@ function mcp_move_topic($topic_ids)
if (!$to_forum_id || $additional_msg)
{
- unset($_POST['confirm']);
- unset($_REQUEST['confirm_key']);
+ $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
+ $request->overwrite('confirm_key', null);
}
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();
@@ -598,98 +532,77 @@ function mcp_move_topic($topic_ids)
$forum_sync_data[$forum_id] = current($topic_data);
$forum_sync_data[$to_forum_id] = $forum_data;
- // Real topics added to target forum
- $topics_moved = sizeof($topic_data);
-
- // Approved topics added to target forum
- $topics_authed_moved = 0;
-
- // Posts (topic replies + topic post if approved) added to target forum
- $topic_posts_added = 0;
-
- // Posts (topic replies + topic post if approved and not global announcement) removed from source forum
- $topic_posts_removed = 0;
-
- // Real topics removed from source forum (all topics without global announcements)
- $topics_removed = 0;
-
- // Approved topics removed from source forum (except global announcements)
- $topics_authed_removed = 0;
+ $topics_moved = $topics_moved_unapproved = $topics_moved_softdeleted = 0;
+ $posts_moved = $posts_moved_unapproved = $posts_moved_softdeleted = 0;
foreach ($topic_data as $topic_id => $topic_info)
{
- if ($topic_info['topic_approved'])
+ if ($topic_info['topic_visibility'] == ITEM_APPROVED)
{
- $topics_authed_moved++;
- $topic_posts_added++;
+ $topics_moved++;
}
-
- $topic_posts_added += $topic_info['topic_replies'];
-
- if ($topic_info['topic_type'] != POST_GLOBAL)
+ else if ($topic_info['topic_visibility'] == ITEM_UNAPPROVED || $topic_info['topic_visibility'] == ITEM_REAPPROVE)
{
- $topics_removed++;
- $topic_posts_removed += $topic_info['topic_replies'];
-
- if ($topic_info['topic_approved'])
- {
- $topics_authed_removed++;
- $topic_posts_removed++;
- }
+ $topics_moved_unapproved++;
}
+ else if ($topic_info['topic_visibility'] == ITEM_DELETED)
+ {
+ $topics_moved_softdeleted++;
+ }
+
+ $posts_moved += $topic_info['topic_posts_approved'];
+ $posts_moved_unapproved += $topic_info['topic_posts_unapproved'];
+ $posts_moved_softdeleted += $topic_info['topic_posts_softdeleted'];
}
$db->sql_transaction('begin');
- $sync_sql = array();
-
- if ($topic_posts_added)
- {
- $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $topic_posts_added;
- }
+ // Move topics, but do not resync yet
+ move_topics($topic_ids, $to_forum_id, false);
- if ($topics_authed_moved)
+ if ($request->is_set_post('move_lock_topics') && $auth->acl_get('m_lock', $to_forum_id))
{
- $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . (int) $topics_authed_moved;
+ $sql = 'UPDATE ' . TOPICS_TABLE . '
+ SET topic_status = ' . ITEM_LOCKED . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
+ $db->sql_query($sql);
}
- $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . (int) $topics_moved;
-
- // Move topics, but do not resync yet
- move_topics($topic_ids, $to_forum_id, false);
-
+ $shadow_topics = 0;
$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']);
- // If we have moved a global announcement, we need to correct the topic type
- if ($row['topic_type'] == POST_GLOBAL)
- {
- $sql = 'UPDATE ' . TOPICS_TABLE . '
- SET topic_type = ' . POST_ANNOUNCE . '
- WHERE topic_id = ' . (int) $row['topic_id'];
- $db->sql_query($sql);
- }
+ // 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_approved'] && $row['topic_type'] != POST_GLOBAL)
+ if ($leave_shadow && $row['topic_visibility'] == ITEM_APPROVED && $row['topic_type'] != POST_GLOBAL)
{
$shadow = array(
'forum_id' => (int) $row['forum_id'],
'icon_id' => (int) $row['icon_id'],
'topic_attachment' => (int) $row['topic_attachment'],
- 'topic_approved' => 1, // a shadow topic is always approved
+ 'topic_visibility' => ITEM_APPROVED, // a shadow topic is always approved
'topic_reported' => 0, // a shadow topic is never reported
'topic_title' => (string) $row['topic_title'],
'topic_poster' => (int) $row['topic_poster'],
'topic_time' => (int) $row['topic_time'],
'topic_time_limit' => (int) $row['topic_time_limit'],
'topic_views' => (int) $row['topic_views'],
- 'topic_replies' => (int) $row['topic_replies'],
- 'topic_replies_real' => (int) $row['topic_replies_real'],
+ 'topic_posts_approved' => (int) $row['topic_posts_approved'],
+ 'topic_posts_unapproved'=> (int) $row['topic_posts_unapproved'],
+ 'topic_posts_softdeleted'=> (int) $row['topic_posts_softdeleted'],
'topic_status' => ITEM_MOVED,
'topic_type' => POST_NORMAL,
'topic_first_post_id' => (int) $row['topic_first_post_id'],
@@ -699,7 +612,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'],
@@ -712,28 +625,63 @@ function mcp_move_topic($topic_ids)
'poll_last_vote' => (int) $row['poll_last_vote']
);
+ /**
+ * Perform actions before shadow topic is created.
+ *
+ * @event core.mcp_main_modify_shadow_sql
+ * @var array shadow SQL array to be used by $db->sql_build_array
+ * @var array row Topic data
+ * @since 3.1.11-RC1
+ * @changed 3.1.11-RC1 Added variable: row
+ */
+ $vars = array(
+ 'shadow',
+ 'row',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.mcp_main_modify_shadow_sql', compact($vars)));
+
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . $db->sql_build_array('INSERT', $shadow));
// Shadow topics only count on new "topics" and not posts... a shadow topic alone has 0 posts
- $topics_removed--;
- $topics_authed_removed--;
+ $shadow_topics++;
}
}
unset($topic_data);
- if ($topic_posts_removed)
+ $sync_sql = array();
+ if ($posts_moved)
{
- $sync_sql[$forum_id][] = 'forum_posts = forum_posts - ' . $topic_posts_removed;
+ $sync_sql[$to_forum_id][] = 'forum_posts_approved = forum_posts_approved + ' . (int) $posts_moved;
+ $sync_sql[$forum_id][] = 'forum_posts_approved = forum_posts_approved - ' . (int) $posts_moved;
}
-
- if ($topics_removed)
+ if ($posts_moved_unapproved)
+ {
+ $sync_sql[$to_forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved + ' . (int) $posts_moved_unapproved;
+ $sync_sql[$forum_id][] = 'forum_posts_unapproved = forum_posts_unapproved - ' . (int) $posts_moved_unapproved;
+ }
+ if ($posts_moved_softdeleted)
{
- $sync_sql[$forum_id][] = 'forum_topics_real = forum_topics_real - ' . (int) $topics_removed;
+ $sync_sql[$to_forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted + ' . (int) $posts_moved_softdeleted;
+ $sync_sql[$forum_id][] = 'forum_posts_softdeleted = forum_posts_softdeleted - ' . (int) $posts_moved_softdeleted;
}
- if ($topics_authed_removed)
+ if ($topics_moved)
+ {
+ $sync_sql[$to_forum_id][] = 'forum_topics_approved = forum_topics_approved + ' . (int) $topics_moved;
+ if ($topics_moved - $shadow_topics > 0)
+ {
+ $sync_sql[$forum_id][] = 'forum_topics_approved = forum_topics_approved - ' . (int) ($topics_moved - $shadow_topics);
+ }
+ }
+ if ($topics_moved_unapproved)
{
- $sync_sql[$forum_id][] = 'forum_topics = forum_topics - ' . (int) $topics_authed_removed;
+ $sync_sql[$to_forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved + ' . (int) $topics_moved_unapproved;
+ $sync_sql[$forum_id][] = 'forum_topics_unapproved = forum_topics_unapproved - ' . (int) $topics_moved_unapproved;
+ }
+ if ($topics_moved_softdeleted)
+ {
+ $sync_sql[$to_forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted + ' . (int) $topics_moved_softdeleted;
+ $sync_sql[$forum_id][] = 'forum_topics_softdeleted = forum_topics_softdeleted - ' . (int) $topics_moved_softdeleted;
}
$success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_MOVED_SUCCESS' : 'TOPICS_MOVED_SUCCESS';
@@ -755,6 +703,7 @@ function mcp_move_topic($topic_ids)
$template->assign_vars(array(
'S_FORUM_SELECT' => make_forum_select($to_forum_id, $forum_id, false, true, true, true),
'S_CAN_LEAVE_SHADOW' => true,
+ 'S_CAN_LOCK_TOPIC' => ($auth->acl_get('m_lock', $to_forum_id)) ? true : false,
'ADDITIONAL_MSG' => $additional_msg)
);
@@ -782,25 +731,99 @@ function mcp_move_topic($topic_ids)
}
/**
-* Delete Topics
+* Restore Topics
*/
-function mcp_delete_topic($topic_ids)
+function mcp_restore_topic($topic_ids)
{
- global $auth, $user, $db, $phpEx, $phpbb_root_path;
+ global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container;
- if (!check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_delete')))
+ if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_approve')))
{
return;
}
- $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
- $forum_id = request_var('f', 0);
+ $redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));
+ $forum_id = $request->variable('f', 0);
$s_hidden_fields = build_hidden_fields(array(
'topic_id_list' => $topic_ids,
'f' => $forum_id,
- 'action' => 'delete_topic',
- 'redirect' => $redirect)
+ 'action' => 'restore_topic',
+ 'redirect' => $redirect,
+ ));
+ $success_msg = '';
+
+ if (confirm_box(true))
+ {
+ $success_msg = (sizeof($topic_ids) == 1) ? 'TOPIC_RESTORED_SUCCESS' : 'TOPICS_RESTORED_SUCCESS';
+
+ $data = phpbb_get_topic_data($topic_ids);
+
+ $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']);
+ }
+ }
+ }
+ else
+ {
+ confirm_box(false, (sizeof($topic_ids) == 1) ? 'RESTORE_TOPIC' : 'RESTORE_TOPICS', $s_hidden_fields);
+ }
+
+ $topic_id = $request->variable('t', 0);
+ if (!$request->is_set('quickmod', \phpbb\request\request_interface::REQUEST))
+ {
+ $redirect = $request->variable('redirect', "index.$phpEx");
+ $redirect = reapply_sid($redirect);
+ $redirect_message = 'PAGE';
+ }
+ else if ($topic_id)
+ {
+ $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id);
+ $redirect_message = 'TOPIC';
+ }
+ else
+ {
+ $redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
+ $redirect_message = 'FORUM';
+ }
+
+ if (!$success_msg)
+ {
+ redirect($redirect);
+ }
+ else
+ {
+ meta_refresh(3, $redirect);
+ trigger_error($user->lang[$success_msg] . '<br /><br />' . sprintf($user->lang['RETURN_' . $redirect_message], '<a href="' . $redirect . '">', '</a>'));
+ }
+}
+
+/**
+* Delete Topics
+*/
+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;
+
+ $check_permission = ($is_soft) ? 'm_softdelete' : 'm_delete';
+ if (!phpbb_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array($check_permission)))
+ {
+ return;
+ }
+
+ $redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));
+ $forum_id = $request->variable('f', 0);
+
+ $s_hidden_fields = array(
+ 'topic_id_list' => $topic_ids,
+ 'f' => $forum_id,
+ 'action' => $action,
+ 'redirect' => $redirect,
);
$success_msg = '';
@@ -808,7 +831,7 @@ function mcp_delete_topic($topic_ids)
{
$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)
{
@@ -818,23 +841,91 @@ function mcp_delete_topic($topic_ids)
}
else
{
- add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name']);
+ // Only soft delete non-shadow topics
+ if ($is_soft)
+ {
+ $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'], $soft_delete_reason);
+ }
+ }
+ else
+ {
+ add_log('mod', $row['forum_id'], $topic_id, 'LOG_DELETE_TOPIC', $row['topic_title'], $row['topic_first_poster_name'], $soft_delete_reason);
+ }
}
}
- $return = delete_topics('topic_id', $topic_ids);
+ if (!$is_soft)
+ {
+ $return = delete_topics('topic_id', $topic_ids);
+ }
}
else
{
- confirm_box(false, (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS', $s_hidden_fields);
+ global $template;
+
+ $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 (!$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
+ FROM ' . TOPICS_TABLE . '
+ WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
+ AND topic_visibility <> ' . ITEM_DELETED;
+ $result = $db->sql_query_limit($sql, 1);
+ $only_softdeleted = !$db->sql_fetchfield('topic_id');
+ $db->sql_freeresult($result);
+ }
+
+ $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),
+ 'DELETE_TOPIC_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_TOPIC_PERMANENTLY', sizeof($topic_ids)),
+ ));
+
+ $l_confirm = (sizeof($topic_ids) == 1) ? 'DELETE_TOPIC' : 'DELETE_TOPICS';
+ if ($only_softdeleted)
+ {
+ $l_confirm .= '_PERMANENTLY';
+ $s_hidden_fields['delete_permanent'] = '1';
+ }
+ else if ($only_shadow || !$auth->acl_get('m_softdelete', $forum_id))
+ {
+ $s_hidden_fields['delete_permanent'] = '1';
+ }
+
+ confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html');
}
- if (!isset($_REQUEST['quickmod']))
+ $topic_id = $request->variable('t', 0);
+ if (!$request->is_set('quickmod', \phpbb\request\request_interface::REQUEST))
{
- $redirect = request_var('redirect', "index.$phpEx");
+ $redirect = $request->variable('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
$redirect_message = 'PAGE';
}
+ else if ($is_soft && $topic_id)
+ {
+ $redirect = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $topic_id);
+ $redirect_message = 'TOPIC';
+ }
else
{
$redirect = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id);
@@ -855,27 +946,94 @@ function mcp_delete_topic($topic_ids)
/**
* Delete Posts
*/
-function mcp_delete_post($post_ids)
+function mcp_delete_post($post_ids, $is_soft = false, $soft_delete_reason = '', $action = 'delete_post')
{
- global $auth, $user, $db, $phpEx, $phpbb_root_path;
+ global $auth, $user, $db, $phpEx, $phpbb_root_path, $request, $phpbb_container;
- if (!check_ids($post_ids, POSTS_TABLE, 'post_id', array('m_delete')))
+ $check_permission = ($is_soft) ? 'm_softdelete' : 'm_delete';
+ if (!phpbb_check_ids($post_ids, POSTS_TABLE, 'post_id', array($check_permission)))
{
return;
}
- $redirect = request_var('redirect', build_url(array('action', 'quickmod')));
- $forum_id = request_var('f', 0);
+ $redirect = $request->variable('redirect', build_url(array('action', 'quickmod')));
+ $forum_id = $request->variable('f', 0);
- $s_hidden_fields = build_hidden_fields(array(
+ $s_hidden_fields = array(
'post_id_list' => $post_ids,
'f' => $forum_id,
- 'action' => 'delete_post',
- 'redirect' => $redirect)
+ 'action' => $action,
+ 'redirect' => $redirect,
);
$success_msg = '';
- if (confirm_box(true))
+ if (confirm_box(true) && $is_soft)
+ {
+ $post_info = phpbb_get_post_data($post_ids);
+
+ $topic_info = $approve_log = array();
+
+ // Group the posts by topic_id
+ foreach ($post_info as $post_id => $post_data)
+ {
+ if ($post_data['post_visibility'] != ITEM_APPROVED)
+ {
+ continue;
+ }
+ $topic_id = (int) $post_data['topic_id'];
+
+ $topic_info[$topic_id]['posts'][] = (int) $post_id;
+ $topic_info[$topic_id]['forum_id'] = (int) $post_data['forum_id'];
+
+ if ($post_id == $post_data['topic_first_post_id'])
+ {
+ $topic_info[$topic_id]['first_post'] = true;
+ }
+
+ if ($post_id == $post_data['topic_last_post_id'])
+ {
+ $topic_info[$topic_id]['last_post'] = true;
+ }
+
+ $approve_log[] = array(
+ 'forum_id' => $post_data['forum_id'],
+ 'topic_id' => $post_data['topic_id'],
+ 'post_subject' => $post_data['post_subject'],
+ 'poster_id' => $post_data['poster_id'],
+ 'post_username' => $post_data['post_username'],
+ 'username' => $post_data['username'],
+ );
+ }
+
+ $phpbb_content_visibility = $phpbb_container->get('content.visibility');
+ foreach ($topic_info as $topic_id => $topic_data)
+ {
+ $phpbb_content_visibility->set_post_visibility(ITEM_DELETED, $topic_data['posts'], $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), $soft_delete_reason, isset($topic_data['first_post']), isset($topic_data['last_post']));
+ }
+ $affected_topics = sizeof($topic_info);
+ // None of the topics is really deleted, so a redirect won't hurt much.
+ $deleted_topics = 0;
+
+ $success_msg = (sizeof($post_info) == 1) ? $user->lang['POST_DELETED_SUCCESS'] : $user->lang['POSTS_DELETED_SUCCESS'];
+
+ 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, $soft_delete_reason);
+ }
+
+ $topic_id = $request->variable('t', 0);
+
+ // Return links
+ $return_link = array();
+ if ($affected_topics == 1 && $topic_id)
+ {
+ $return_link[] = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;t=$topic_id") . '">', '</a>');
+ }
+ $return_link[] = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id) . '">', '</a>');
+
+ }
+ else if (confirm_box(true))
{
if (!function_exists('delete_posts'))
{
@@ -899,12 +1057,12 @@ function mcp_delete_post($post_ids)
$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);
+ add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_DELETE_POST', $row['post_subject'], $post_username, $soft_delete_reason);
}
// Now delete the posts, topics and forums are automatically resync'ed
@@ -918,7 +1076,7 @@ function mcp_delete_post($post_ids)
$deleted_topics = ($row = $db->sql_fetchrow($result)) ? ($affected_topics - $row['topics_left']) : $affected_topics;
$db->sql_freeresult($result);
- $topic_id = request_var('t', 0);
+ $topic_id = $request->variable('t', 0);
// Return links
$return_link = array();
@@ -956,10 +1114,45 @@ function mcp_delete_post($post_ids)
}
else
{
- confirm_box(false, (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS', $s_hidden_fields);
+ global $template;
+
+ $user->add_lang('posting');
+
+ $only_softdeleted = false;
+ if ($auth->acl_get('m_delete', $forum_id) && $auth->acl_get('m_softdelete', $forum_id))
+ {
+ // If there are only soft deleted posts, we display a message why the option is not available
+ $sql = 'SELECT post_id
+ FROM ' . POSTS_TABLE . '
+ WHERE ' . $db->sql_in_set('post_id', $post_ids) . '
+ AND post_visibility <> ' . ITEM_DELETED;
+ $result = $db->sql_query_limit($sql, 1);
+ $only_softdeleted = !$db->sql_fetchfield('post_id');
+ $db->sql_freeresult($result);
+ }
+
+ $template->assign_vars(array(
+ 'S_SOFTDELETED' => $only_softdeleted,
+ 'S_ALLOWED_DELETE' => $auth->acl_get('m_delete', $forum_id),
+ 'S_ALLOWED_SOFTDELETE' => $auth->acl_get('m_softdelete', $forum_id),
+ 'DELETE_POST_PERMANENTLY_EXPLAIN' => $user->lang('DELETE_POST_PERMANENTLY', sizeof($post_ids)),
+ ));
+
+ $l_confirm = (sizeof($post_ids) == 1) ? 'DELETE_POST' : 'DELETE_POSTS';
+ if ($only_softdeleted)
+ {
+ $l_confirm .= '_PERMANENTLY';
+ $s_hidden_fields['delete_permanent'] = '1';
+ }
+ else if (!$auth->acl_get('m_softdelete', $forum_id))
+ {
+ $s_hidden_fields['delete_permanent'] = '1';
+ }
+
+ confirm_box(false, $l_confirm, build_hidden_fields($s_hidden_fields), 'confirm_delete_body.html');
}
- $redirect = request_var('redirect', "index.$phpEx");
+ $redirect = $request->variable('redirect', "index.$phpEx");
$redirect = reapply_sid($redirect);
if (!$success_msg)
@@ -984,9 +1177,9 @@ function mcp_delete_post($post_ids)
function mcp_fork_topic($topic_ids)
{
global $auth, $user, $db, $template, $config;
- global $phpEx, $phpbb_root_path;
+ global $phpEx, $phpbb_root_path, $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;
}
@@ -995,6 +1188,7 @@ function mcp_fork_topic($topic_ids)
$forum_id = request_var('f', 0);
$redirect = request_var('redirect', build_url(array('action', 'quickmod')));
$additional_msg = $success_msg = '';
+ $counter = array();
$s_hidden_fields = build_hidden_fields(array(
'topic_id_list' => $topic_ids,
@@ -1005,7 +1199,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))
{
@@ -1036,37 +1230,32 @@ function mcp_fork_topic($topic_ids)
if ($additional_msg)
{
- unset($_POST['confirm']);
- unset($_REQUEST['confirm_key']);
+ $request->overwrite('confirm', null, \phpbb\request\request_interface::POST);
+ $request->overwrite('confirm_key', null);
}
if (confirm_box(true))
{
- $topic_data = get_topic_data($topic_ids, 'f_post');
+ $topic_data = phpbb_get_topic_data($topic_ids, 'f_post');
- $total_posts = 0;
+ $total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0;
+ $total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0;
$new_topic_id_list = array();
-
foreach ($topic_data as $topic_id => $topic_row)
{
if (!isset($search_type) && $topic_row['enable_indexing'])
{
// Select the search method and do some additional checks to ensure it can actually be utilised
- $search_type = basename($config['search_type']);
-
- if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
- {
- trigger_error('NO_SUCH_SEARCH_MODULE');
- }
+ $search_type = $config['search_type'];
if (!class_exists($search_type))
{
- include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+ trigger_error('NO_SUCH_SEARCH_MODULE');
}
$error = false;
- $search = new $search_type($error);
+ $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
$search_mode = 'post';
if ($error)
@@ -1083,13 +1272,14 @@ function mcp_fork_topic($topic_ids)
'forum_id' => (int) $to_forum_id,
'icon_id' => (int) $topic_row['icon_id'],
'topic_attachment' => (int) $topic_row['topic_attachment'],
- 'topic_approved' => 1,
+ 'topic_visibility' => (int) $topic_row['topic_visibility'],
'topic_reported' => 0,
'topic_title' => (string) $topic_row['topic_title'],
'topic_poster' => (int) $topic_row['topic_poster'],
'topic_time' => (int) $topic_row['topic_time'],
- 'topic_replies' => (int) $topic_row['topic_replies_real'],
- 'topic_replies_real' => (int) $topic_row['topic_replies_real'],
+ 'topic_posts_approved' => (int) $topic_row['topic_posts_approved'],
+ 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'],
+ 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'],
'topic_status' => (int) $topic_row['topic_status'],
'topic_type' => (int) $topic_row['topic_type'],
'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'],
@@ -1106,10 +1296,39 @@ function mcp_fork_topic($topic_ids)
'poll_vote_change' => (int) $topic_row['poll_vote_change'],
);
+ /**
+ * Perform actions before forked topic is created.
+ *
+ * @event core.mcp_main_modify_fork_sql
+ * @var array sql_ary SQL array to be used by $db->sql_build_array
+ * @var array topic_row Topic data
+ * @since 3.1.11-RC1
+ * @changed 3.1.11-RC1 Added variable: topic_row
+ */
+ $vars = array(
+ 'sql_ary',
+ 'topic_row',
+ );
+ extract($phpbb_dispatcher->trigger_event('core.mcp_main_modify_fork_sql', compact($vars)));
+
$db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
$new_topic_id = $db->sql_nextid();
$new_topic_id_list[$topic_id] = $new_topic_id;
+ switch ($topic_row['topic_visibility'])
+ {
+ case ITEM_APPROVED:
+ $total_topics++;
+ break;
+ case ITEM_UNAPPROVED:
+ case ITEM_REAPPROVE:
+ $total_topics_unapproved++;
+ break;
+ case ITEM_DELETED:
+ $total_topics_softdeleted++;
+ break;
+ }
+
if ($topic_row['poll_start'])
{
$poll_rows = array();
@@ -1130,12 +1349,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();
@@ -1150,7 +1370,6 @@ function mcp_fork_topic($topic_ids)
continue;
}
- $total_posts += sizeof($post_rows);
foreach ($post_rows as $row)
{
$sql_ary = array(
@@ -1160,7 +1379,7 @@ function mcp_fork_topic($topic_ids)
'icon_id' => (int) $row['icon_id'],
'poster_ip' => (string) $row['poster_ip'],
'post_time' => (int) $row['post_time'],
- 'post_approved' => 1,
+ 'post_visibility' => (int) $row['post_visibility'],
'post_reported' => 0,
'enable_bbcode' => (int) $row['enable_bbcode'],
'enable_smilies' => (int) $row['enable_smilies'],
@@ -1178,12 +1397,37 @@ 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();
+ switch ($row['post_visibility'])
+ {
+ case ITEM_APPROVED:
+ $total_posts++;
+ break;
+ case ITEM_UNAPPROVED:
+ case ITEM_REAPPROVE:
+ $total_posts_unapproved++;
+ break;
+ case ITEM_DELETED:
+ $total_posts_softdeleted++;
+ break;
+ }
+
// Copy whether the topic is dotted
markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']);
@@ -1276,23 +1520,31 @@ function mcp_fork_topic($topic_ids)
}
// Sync new topics, parent forums and board stats
- sync('topic', 'topic_id', $new_topic_id_list);
-
- $sync_sql = array();
-
- $sync_sql[$to_forum_id][] = 'forum_posts = forum_posts + ' . $total_posts;
- $sync_sql[$to_forum_id][] = 'forum_topics = forum_topics + ' . sizeof($new_topic_id_list);
- $sync_sql[$to_forum_id][] = 'forum_topics_real = forum_topics_real + ' . sizeof($new_topic_id_list);
+ $sql = 'UPDATE ' . FORUMS_TABLE . '
+ SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ',
+ forum_posts_unapproved = forum_posts_unapproved + ' . $total_posts_unapproved . ',
+ forum_posts_softdeleted = forum_posts_softdeleted + ' . $total_posts_softdeleted . ',
+ forum_topics_approved = forum_topics_approved + ' . $total_topics . ',
+ forum_topics_unapproved = forum_topics_unapproved + ' . $total_topics_unapproved . ',
+ forum_topics_softdeleted = forum_topics_softdeleted + ' . $total_topics_softdeleted . '
+ WHERE forum_id = ' . $to_forum_id;
+ $db->sql_query($sql);
- foreach ($sync_sql as $forum_id_key => $array)
+ if (!empty($counter))
{
- $sql = 'UPDATE ' . FORUMS_TABLE . '
- SET ' . implode(', ', $array) . '
- WHERE forum_id = ' . $forum_id_key;
- $db->sql_query($sql);
+ // 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);
@@ -1335,5 +1587,3 @@ function mcp_fork_topic($topic_ids)
trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
}
}
-
-?> \ No newline at end of file