/**
* Merge selected posts into selected topic
*/
function merge_posts($topic_id, $to_topic_id)
{
    global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
    if (!$to_topic_id) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
    if (!sizeof($topic_data)) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = $topic_data[$to_topic_id];
    $post_id_list = request_var('post_id_list', array(0));
    $start = request_var('start', 0);
    if (!sizeof($post_id_list)) {
        $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
        return;
    }
    if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge'))) {
        return;
    }
    $redirect = request_var('redirect', build_url(array('quickmod')));
    $s_hidden_fields = build_hidden_fields(array('i' => 'main', 'post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'topic_view', 'action' => 'merge_posts', 'start' => $start, 'redirect' => $redirect, 't' => $topic_id));
    $success_msg = $return_link = '';
    if (confirm_box(true)) {
        $to_forum_id = $topic_data['forum_id'];
        move_posts($post_id_list, $to_topic_id);
        add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
        // Message and return links
        $success_msg = 'POSTS_MERGED_SUCCESS';
        // Does the original topic still exist? If yes, link back to it
        $sql = 'SELECT forum_id
			FROM ' . TOPICS_TABLE . '
			WHERE topic_id = ' . $topic_id;
        $result = $db->sql_query_limit($sql, 1);
        $row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if ($row) {
            $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $topic_id) . '">', '</a>');
        } else {
            // If the topic no longer exist, we will update the topic watch table.
            // To not let it error out on users watching both topics, we just return on an error...
            $db->sql_return_on_error(true);
            $db->sql_query('UPDATE ' . TOPICS_WATCH_TABLE . ' SET topic_id = ' . (int) $to_topic_id . ' WHERE topic_id = ' . (int) $topic_id);
            $db->sql_return_on_error(false);
            $db->sql_query('DELETE FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . (int) $topic_id);
        }
        // Link to the new topic
        $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
    } else {
        confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        return;
    } else {
        meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$to_forum_id}&amp;t={$to_topic_id}"));
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
示例#2
0
/**
* Merge selected topics into selected topic
*/
function merge_topics($forum_id, $topic_ids, $to_topic_id)
{
    global $db, $template, $user, $phpEx, $phpbb_root_path, $phpbb_log, $request;
    if (!sizeof($topic_ids)) {
        $template->assign_var('MESSAGE', $user->lang['NO_TOPIC_SELECTED']);
        return;
    }
    if (!$to_topic_id) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $sync_topics = array_merge($topic_ids, array($to_topic_id));
    $topic_data = phpbb_get_topic_data($sync_topics, 'm_merge');
    if (!sizeof($topic_data) || empty($topic_data[$to_topic_id])) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $sync_forums = array();
    foreach ($topic_data as $data) {
        $sync_forums[$data['forum_id']] = $data['forum_id'];
    }
    $topic_data = $topic_data[$to_topic_id];
    $post_id_list = $request->variable('post_id_list', array(0));
    $start = $request->variable('start', 0);
    if (!sizeof($post_id_list) && sizeof($topic_ids)) {
        $sql = 'SELECT post_id
			FROM ' . POSTS_TABLE . '
			WHERE ' . $db->sql_in_set('topic_id', $topic_ids);
        $result = $db->sql_query($sql);
        $post_id_list = array();
        while ($row = $db->sql_fetchrow($result)) {
            $post_id_list[] = $row['post_id'];
        }
        $db->sql_freeresult($result);
    }
    if (!sizeof($post_id_list)) {
        $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
        return;
    }
    if (!phpbb_check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_merge'))) {
        return;
    }
    $redirect = $request->variable('redirect', build_url(array('quickmod')));
    $s_hidden_fields = build_hidden_fields(array('i' => 'main', 'f' => $forum_id, 'post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'forum_view', 'action' => 'merge_topics', 'start' => $start, 'redirect' => $redirect, 'topic_id_list' => $topic_ids));
    $return_link = '';
    if (confirm_box(true)) {
        $to_forum_id = $topic_data['forum_id'];
        move_posts($post_id_list, $to_topic_id, false);
        $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_MERGE', false, array('forum_id' => $to_forum_id, 'topic_id' => $to_topic_id, $topic_data['topic_title']));
        // Message and return links
        $success_msg = 'POSTS_MERGED_SUCCESS';
        if (!function_exists('phpbb_update_rows_avoiding_duplicates_notify_status')) {
            include $phpbb_root_path . 'includes/functions_database_helper.' . $phpEx;
        }
        // Update the topic watch table.
        phpbb_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', $topic_ids, $to_topic_id);
        // Update the bookmarks table.
        phpbb_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', $topic_ids, $to_topic_id);
        // Re-sync the topics and forums because the auto-sync was deactivated in the call of  move_posts()
        sync('topic_reported', 'topic_id', $sync_topics);
        sync('topic_attachment', 'topic_id', $sync_topics);
        sync('topic', 'topic_id', $sync_topics, true);
        sync('forum', 'forum_id', $sync_forums, true, true);
        // Link to the new topic
        $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
        $redirect = $request->variable('redirect', "{$phpbb_root_path}viewtopic.{$phpEx}?f={$to_forum_id}&amp;t={$to_topic_id}");
        $redirect = reapply_sid($redirect);
        meta_refresh(3, $redirect);
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    } else {
        confirm_box(false, 'MERGE_TOPICS', $s_hidden_fields);
    }
}
 function merge_into($topic_id)
 {
     move_posts($this->post_id, $topic_id);
     $this->topic_id = $topic_id;
     $this->_topic = null;
 }
function merge_posts($topic_id, $to_topic_id)
{
    global $_CLASS;
    if (!$to_topic_id) {
        $_CLASS['core_template']->assign('MESSAGE', $_CLASS['core_user']->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
    if (!sizeof($topic_data)) {
        $_CLASS['core_template']->assign('MESSAGE', $_CLASS['core_user']->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = $topic_data[$to_topic_id];
    $post_id_list = request_var('post_id_list', array(0));
    $start = request_var('start', 0);
    if (!sizeof($post_id_list)) {
        $_CLASS['core_template']->assign('MESSAGE', $_CLASS['core_user']->lang['NO_POST_SELECTED']);
        return;
    }
    if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_merge'))) {
        return;
    }
    $redirect = request_var('redirect', $_CLASS['core_user']->data['session_page']);
    $s_hidden_fields = build_hidden_fields(array('post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'topic_view', 'action' => 'merge_posts', 'start' => $start, 'redirect' => $redirect, 'f' => $forum_id, 't' => $topic_id));
    $success_msg = $return_link = '';
    if (confirm_box(true)) {
        $to_forum_id = $topic_data['forum_id'];
        move_posts($post_id_list, $to_topic_id);
        add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
        // Message and return links
        $success_msg = 'POSTS_MERGED_SUCCESS';
        // Does the original topic still exist? If yes, link back to it
        $topic_data = get_topic_data(array($topic_id));
        if (sizeof($topic_data)) {
            $return_link .= sprintf($_CLASS['core_user']->lang['RETURN_TOPIC'], '<a href="' . generate_link('Forums&amp;file=viewtopic&amp;f=' . $forum_id . '&amp;t=' . $topic_id) . '">', '</a>');
        }
        // Link to the new topic
        $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($_CLASS['core_user']->lang['RETURN_NEW_TOPIC'], '<a href="' . generate_link('Forums&amp;file=viewtopic&amp;f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
    } else {
        confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
    }
    $redirect = request_var('redirect', generate_link('Forums'));
    /*if (strpos($redirect, '?') === false)
    	{
    		$redirect = substr_replace($redirect, ".$phpEx$SID&", strpos($redirect, '&'), 1);
    	}*/
    if (!$success_msg) {
        return;
    } else {
        $_CLASS['core_display']->meta_refresh(3, generate_link("Forums&amp;file=viewtopic&amp;f={$to_forum_id}&amp;t={$to_topic_id}"));
        trigger_error($_CLASS['core_user']->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
示例#5
0
/**
* Merge selected posts into selected topic
*/
function merge_posts($topic_id, $to_topic_id)
{
    global $db, $template, $user, $phpEx, $phpbb_root_path, $auth;
    if (!$to_topic_id) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = get_topic_data(array($to_topic_id), 'm_merge');
    if (!sizeof($topic_data)) {
        $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']);
        return;
    }
    $topic_data = $topic_data[$to_topic_id];
    $post_id_list = request_var('post_id_list', array(0));
    $start = request_var('start', 0);
    if (!sizeof($post_id_list)) {
        $template->assign_var('MESSAGE', $user->lang['NO_POST_SELECTED']);
        return;
    }
    if (!($forum_id = check_ids($post_id_list, POSTS_TABLE, 'post_id', 'm_merge'))) {
        return;
    }
    $redirect = request_var('redirect', $user->data['session_page']);
    $s_hidden_fields = build_hidden_fields(array('i' => 'main', 'post_id_list' => $post_id_list, 'to_topic_id' => $to_topic_id, 'mode' => 'topic_view', 'action' => 'merge_posts', 'start' => $start, 'redirect' => $redirect, 'f' => $forum_id, 't' => $topic_id));
    $success_msg = $return_link = '';
    if (confirm_box(true)) {
        $to_forum_id = $topic_data['forum_id'];
        move_posts($post_id_list, $to_topic_id);
        add_log('mod', $to_forum_id, $to_topic_id, 'LOG_MERGE', $topic_data['topic_title']);
        // Message and return links
        $success_msg = 'POSTS_MERGED_SUCCESS';
        // Does the original topic still exist? If yes, link back to it
        $topic_data = get_topic_data(array($topic_id));
        if (sizeof($topic_data)) {
            $return_link .= sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $forum_id . '&amp;t=' . $topic_id) . '">', '</a>');
        }
        // Link to the new topic
        $return_link .= ($return_link ? '<br /><br />' : '') . sprintf($user->lang['RETURN_NEW_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&amp;t=' . $to_topic_id) . '">', '</a>');
    } else {
        confirm_box(false, 'MERGE_POSTS', $s_hidden_fields);
    }
    $redirect = request_var('redirect', "index.{$phpEx}");
    $redirect = reapply_sid($redirect);
    if (!$success_msg) {
        return;
    } else {
        meta_refresh(3, append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$to_forum_id}&amp;t={$to_topic_id}"));
        trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link);
    }
}
/**
* Remove post(s)
*/
function delete_posts($where_type, $where_ids, $auto_sync = true, $posted_sync = true, $post_count_sync = true, $call_delete_topics = true)
{
    // move deleted posts to the spambox 'deleted posts' thread
    if ($where_type === 'post_id') {
        move_posts($where_ids, '20246', $auto_sync);
        return 1;
    }
    global $db, $config, $phpbb_root_path, $phpEx;
    if ($where_type === 'range') {
        $where_clause = $where_ids;
    } else {
        if (is_array($where_ids)) {
            $where_ids = array_unique($where_ids);
        } else {
            $where_ids = array($where_ids);
        }
        if (!sizeof($where_ids)) {
            return false;
        }
        $where_ids = array_map('intval', $where_ids);
        /*		Possible code for splitting post deletion
        		if (sizeof($where_ids) >= 1001)
        		{
        			// Split into chunks of 1000
        			$chunks = array_chunk($where_ids, 1000);
        
        			foreach ($chunks as $_where_ids)
        			{
        				delete_posts($where_type, $_where_ids, $auto_sync, $posted_sync, $post_count_sync, $call_delete_topics);
        			}
        
        			return;
        		}*/
        $where_clause = $db->sql_in_set($where_type, $where_ids);
    }
    $approved_posts = 0;
    $post_ids = $topic_ids = $forum_ids = $post_counts = $remove_topics = array();
    $sql = 'SELECT post_id, poster_id, post_approved, post_postcount, topic_id, forum_id
		FROM ' . POSTS_TABLE . '
		WHERE ' . $where_clause;
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)) {
        $post_ids[] = (int) $row['post_id'];
        $poster_ids[] = (int) $row['poster_id'];
        $topic_ids[] = (int) $row['topic_id'];
        $forum_ids[] = (int) $row['forum_id'];
        if ($row['post_postcount'] && $post_count_sync && $row['post_approved']) {
            $post_counts[$row['poster_id']] = !empty($post_counts[$row['poster_id']]) ? $post_counts[$row['poster_id']] + 1 : 1;
        }
        if ($row['post_approved']) {
            $approved_posts++;
        }
    }
    $db->sql_freeresult($result);
    if (!sizeof($post_ids)) {
        return false;
    }
    $db->sql_transaction('begin');
    $table_ary = array(POSTS_TABLE, REPORTS_TABLE);
    foreach ($table_ary as $table) {
        $sql = "DELETE FROM {$table}\n\t\t\tWHERE " . $db->sql_in_set('post_id', $post_ids);
        $db->sql_query($sql);
    }
    unset($table_ary);
    // Adjust users post counts
    if (sizeof($post_counts) && $post_count_sync) {
        foreach ($post_counts as $poster_id => $substract) {
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET user_posts = 0
				WHERE user_id = ' . $poster_id . '
				AND user_posts < ' . $substract;
            $db->sql_query($sql);
            $sql = 'UPDATE ' . USERS_TABLE . '
				SET user_posts = user_posts - ' . $substract . '
				WHERE user_id = ' . $poster_id . '
				AND user_posts >= ' . $substract;
            $db->sql_query($sql);
        }
    }
    // Remove topics now having no posts?
    if (sizeof($topic_ids)) {
        $sql = 'SELECT topic_id
			FROM ' . POSTS_TABLE . '
			WHERE ' . $db->sql_in_set('topic_id', $topic_ids) . '
			GROUP BY topic_id';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $remove_topics[] = $row['topic_id'];
        }
        $db->sql_freeresult($result);
        // Actually, those not within remove_topics should be removed. ;)
        $remove_topics = array_diff($topic_ids, $remove_topics);
    }
    // Remove the message from the search index
    $search_type = basename($config['search_type']);
    if (!file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx)) {
        trigger_error('NO_SUCH_SEARCH_MODULE');
    }
    include_once "{$phpbb_root_path}includes/search/{$search_type}.{$phpEx}";
    $error = false;
    $search = new $search_type($error);
    if ($error) {
        trigger_error($error);
    }
    $search->index_remove($post_ids, $poster_ids, $forum_ids);
    delete_attachments('post', $post_ids, false);
    $db->sql_transaction('commit');
    // Resync topics_posted table
    if ($posted_sync) {
        update_posted_info($topic_ids);
    }
    if ($auto_sync) {
        sync('topic_reported', 'topic_id', $topic_ids);
        sync('topic', 'topic_id', $topic_ids, true);
        sync('forum', 'forum_id', $forum_ids, true, true);
    }
    if ($approved_posts) {
        set_config_count('num_posts', $approved_posts * -1, true);
    }
    // We actually remove topics now to not be inconsistent (the delete_topics function calls this function too)
    if (sizeof($remove_topics) && $call_delete_topics) {
        delete_topics('topic_id', $remove_topics, $auto_sync, $post_count_sync, false);
    }
    return sizeof($post_ids);
}