Exemple #1
0
function MoveTopic2()
{
    global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context;
    global $board, $language, $user_info, $smcFunc;
    if (empty($topic)) {
        fatal_lang_error('no_access', false);
    }
    // You can't choose to have a redirection topic and use an empty reason.
    if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
        fatal_lang_error('movetopic_no_reason', false);
    }
    // Make sure this form hasn't been submitted before.
    checkSubmitOnce('check');
    $request = $smcFunc['db_query']('', '
		SELECT id_member_started, id_first_msg, approved
		FROM {db_prefix}topics
		WHERE id_topic = {int:current_topic}
		LIMIT 1', array('current_topic' => $topic));
    list($id_member_started, $id_first_msg, $context['is_approved']) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    // Can they see it?
    if (!$context['is_approved']) {
        isAllowedTo('approve_posts');
    }
    // Can they move topics on this board?
    if (!allowedTo('move_any')) {
        if ($id_member_started == $user_info['id']) {
            isAllowedTo('move_own');
            $boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any'));
        } else {
            isAllowedTo('move_any');
        }
    } else {
        $boards = boardsAllowedTo('move_any');
    }
    // If this topic isn't approved don't let them move it if they can't approve it!
    if ($modSettings['postmod_active'] && !$context['is_approved'] && !allowedTo('approve_posts')) {
        // Only allow them to move it to other boards they can't approve it in.
        $can_approve = boardsAllowedTo('approve_posts');
        $boards = array_intersect($boards, $can_approve);
    }
    checkSession();
    require_once $sourcedir . '/Subs-Post.php';
    // The destination board must be numeric.
    $_POST['toboard'] = (int) $_POST['toboard'];
    // Make sure they can see the board they are trying to move to (and get whether posts count in the target board).
    $request = $smcFunc['db_query']('', '
		SELECT b.count_posts, b.name, m.subject
		FROM {db_prefix}boards AS b
			INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
			INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
		WHERE {query_see_board}
			AND b.id_board = {int:to_board}
			AND b.redirect = {string:blank_redirect}
		LIMIT 1', array('current_topic' => $topic, 'to_board' => $_POST['toboard'], 'blank_redirect' => ''));
    if ($smcFunc['db_num_rows']($request) == 0) {
        fatal_lang_error('no_board');
    }
    list($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    // Remember this for later.
    $_SESSION['move_to_topic'] = $_POST['toboard'];
    // Rename the topic...
    if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '') {
        $_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
        // Keep checking the length.
        if ($smcFunc['strlen']($_POST['custom_subject']) > 100) {
            $_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100);
        }
        // If it's still valid move onwards and upwards.
        if ($_POST['custom_subject'] != '') {
            if (isset($_POST['enforce_subject'])) {
                // Get a response prefix, but in the forum's default language.
                if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) {
                    if ($language === $user_info['language']) {
                        $context['response_prefix'] = $txt['response_prefix'];
                    } else {
                        loadLanguage('index', $language, false);
                        $context['response_prefix'] = $txt['response_prefix'];
                        loadLanguage('index');
                    }
                    cache_put_data('response_prefix', $context['response_prefix'], 600);
                }
                $smcFunc['db_query']('', '
					UPDATE {db_prefix}messages
					SET subject = {string:subject}
					WHERE id_topic = {int:current_topic}', array('current_topic' => $topic, 'subject' => $context['response_prefix'] . $_POST['custom_subject']));
            }
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}messages
				SET subject = {string:custom_subject}
				WHERE id_msg = {int:id_first_msg}', array('id_first_msg' => $id_first_msg, 'custom_subject' => $_POST['custom_subject']));
            // Fix the subject cache.
            updateStats('subject', $topic, $_POST['custom_subject']);
        }
    }
    // Create a link to this in the old board.
    //!!! Does this make sense if the topic was unapproved before? I'd just about say so.
    if (isset($_POST['postRedirect'])) {
        // Should be in the boardwide language.
        if ($user_info['language'] != $language) {
            loadLanguage('index', $language);
        }
        $_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
        preparsecode($_POST['reason']);
        // Add a URL onto the message.
        $_POST['reason'] = strtr($_POST['reason'], array($txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $_POST['toboard'] . '.0]' . $board_name . '[/url]', $txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]'));
        $msgOptions = array('subject' => $txt['moved'] . ': ' . $subject, 'body' => $_POST['reason'], 'icon' => 'moved', 'smileys_enabled' => 1);
        $topicOptions = array('board' => $board, 'lock_mode' => 1, 'mark_as_read' => true);
        $posterOptions = array('id' => $user_info['id'], 'update_post_count' => empty($pcounter));
        createPost($msgOptions, $topicOptions, $posterOptions);
    }
    $request = $smcFunc['db_query']('', '
		SELECT count_posts
		FROM {db_prefix}boards
		WHERE id_board = {int:current_board}
		LIMIT 1', array('current_board' => $board));
    list($pcounter_from) = $smcFunc['db_fetch_row']($request);
    $smcFunc['db_free_result']($request);
    if ($pcounter_from != $pcounter) {
        $request = $smcFunc['db_query']('', '
			SELECT id_member
			FROM {db_prefix}messages
			WHERE id_topic = {int:current_topic}
				AND approved = {int:is_approved}', array('current_topic' => $topic, 'is_approved' => 1));
        $posters = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (!isset($posters[$row['id_member']])) {
                $posters[$row['id_member']] = 0;
            }
            $posters[$row['id_member']]++;
        }
        $smcFunc['db_free_result']($request);
        foreach ($posters as $id_member => $posts) {
            // The board we're moving from counted posts, but not to.
            if (empty($pcounter_from)) {
                updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
            } else {
                updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
            }
        }
    }
    // Do the move (includes statistics update needed for the redirect topic).
    moveTopics($topic, $_POST['toboard']);
    // Log that they moved this topic.
    if (!allowedTo('move_own') || $id_member_started != $user_info['id']) {
        logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
    }
    // Notify people that this topic has been moved?
    sendNotifications($topic, 'move');
    // Why not go back to the original board in case they want to keep moving?
    if (!isset($_REQUEST['goback'])) {
        redirectexit('board=' . $board . '.0');
    } else {
        redirectexit('topic=' . $topic . '.0');
    }
}
Exemple #2
0
    if (isset($_POST['hidden'])) {
        $hidden = COM_applyFilter($_POST['hidden'], true);
    }
    $parent_id = '';
    if (isset($_POST['parent_id'])) {
        $parent_id = COM_applyFilter($_POST['parent_id']);
    }
    $sortnum = 0;
    if (isset($_POST['sortnum'])) {
        $sortnum = COM_applyFilter($_POST['sortnum'], true);
    }
    $display .= savetopic(COM_applyFilter($_POST['tid']), $_POST['topic_name'], $inherit, $hidden, $parent_id, $imageurl, $_POST['meta_description'], $_POST['meta_keywords'], $sortnum, COM_applyFilter($_POST['limitnews'], true), COM_applyFilter($_POST['owner_id'], true), COM_applyFilter($_POST['group_id'], true), $_POST['perm_owner'], $_POST['perm_group'], $_POST['perm_members'], $_POST['perm_anon'], $is_default, $is_archive);
} elseif ($mode == 'edit') {
    $tid = '';
    if (isset($_GET['tid'])) {
        $tid = COM_applyFilter($_GET['tid']);
    }
    $display .= edittopic($tid);
    $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG27[1]));
} elseif ($mode == 'change_sortnum' && SEC_checkToken()) {
    $display .= COM_showMessageFromParameter();
    moveTopics(COM_applyFilter($_GET['tid']), COM_applyFilter($_GET['where']));
    $display .= listTopics(SEC_createToken());
    $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG27[8]));
} else {
    // 'cancel' or no mode at all
    $display .= COM_showMessageFromParameter();
    $display .= listTopics(SEC_createToken());
    $display = COM_createHTMLDocument($display, array('pagetitle' => $LANG27[8]));
}
COM_output($display);
Exemple #3
0
/**
 * Allows for moderation from the message index.
 * @todo refactor this...
 */
function QuickModeration()
{
    global $sourcedir, $board, $user_info, $modSettings, $smcFunc, $context;
    // Check the session = get or post.
    checkSession('request');
    // Lets go straight to the restore area.
    if (isset($_REQUEST['qaction']) && $_REQUEST['qaction'] == 'restore' && !empty($_REQUEST['topics'])) {
        redirectexit('action=restoretopic;topics=' . implode(',', $_REQUEST['topics']) . ';' . $context['session_var'] . '=' . $context['session_id']);
    }
    if (isset($_SESSION['topicseen_cache'])) {
        $_SESSION['topicseen_cache'] = array();
    }
    // This is going to be needed to send off the notifications and for updateLastMessages().
    require_once $sourcedir . '/Subs-Post.php';
    // Remember the last board they moved things to.
    if (isset($_REQUEST['move_to'])) {
        $_SESSION['move_to_topic'] = $_REQUEST['move_to'];
    }
    // Only a few possible actions.
    $possibleActions = array();
    if (!empty($board)) {
        $boards_can = array('make_sticky' => allowedTo('make_sticky') ? array($board) : array(), 'move_any' => allowedTo('move_any') ? array($board) : array(), 'move_own' => allowedTo('move_own') ? array($board) : array(), 'remove_any' => allowedTo('remove_any') ? array($board) : array(), 'remove_own' => allowedTo('remove_own') ? array($board) : array(), 'lock_any' => allowedTo('lock_any') ? array($board) : array(), 'lock_own' => allowedTo('lock_own') ? array($board) : array(), 'merge_any' => allowedTo('merge_any') ? array($board) : array(), 'approve_posts' => allowedTo('approve_posts') ? array($board) : array());
        $redirect_url = 'board=' . $board . '.' . $_REQUEST['start'];
    } else {
        /**
         * @todo Ugly. There's no getting around this, is there?
         * @todo Maybe just do this on the actions people want to use?
         */
        $boards_can = boardsAllowedTo(array('make_sticky', 'move_any', 'move_own', 'remove_any', 'remove_own', 'lock_any', 'lock_own', 'merge_any', 'approve_posts'), true, false);
        $redirect_url = isset($_POST['redirect_url']) ? $_POST['redirect_url'] : (isset($_SESSION['old_url']) ? $_SESSION['old_url'] : '');
    }
    if (!$user_info['is_guest']) {
        $possibleActions[] = 'markread';
    }
    if (!empty($boards_can['make_sticky']) && !empty($modSettings['enableStickyTopics'])) {
        $possibleActions[] = 'sticky';
    }
    if (!empty($boards_can['move_any']) || !empty($boards_can['move_own'])) {
        $possibleActions[] = 'move';
    }
    if (!empty($boards_can['remove_any']) || !empty($boards_can['remove_own'])) {
        $possibleActions[] = 'remove';
    }
    if (!empty($boards_can['lock_any']) || !empty($boards_can['lock_own'])) {
        $possibleActions[] = 'lock';
    }
    if (!empty($boards_can['merge_any'])) {
        $possibleActions[] = 'merge';
    }
    if (!empty($boards_can['approve_posts'])) {
        $possibleActions[] = 'approve';
    }
    // Two methods: $_REQUEST['actions'] (id_topic => action), and $_REQUEST['topics'] and $_REQUEST['qaction'].
    // (if action is 'move', $_REQUEST['move_to'] or $_REQUEST['move_tos'][$topic] is used.)
    if (!empty($_REQUEST['topics'])) {
        // If the action isn't valid, just quit now.
        if (empty($_REQUEST['qaction']) || !in_array($_REQUEST['qaction'], $possibleActions)) {
            redirectexit($redirect_url);
        }
        // Merge requires all topics as one parameter and can be done at once.
        if ($_REQUEST['qaction'] == 'merge') {
            // Merge requires at least two topics.
            if (empty($_REQUEST['topics']) || count($_REQUEST['topics']) < 2) {
                redirectexit($redirect_url);
            }
            require_once $sourcedir . '/SplitTopics.php';
            return MergeExecute($_REQUEST['topics']);
        }
        // Just convert to the other method, to make it easier.
        foreach ($_REQUEST['topics'] as $topic) {
            $_REQUEST['actions'][(int) $topic] = $_REQUEST['qaction'];
        }
    }
    // Weird... how'd you get here?
    if (empty($_REQUEST['actions'])) {
        redirectexit($redirect_url);
    }
    // Validate each action.
    $temp = array();
    foreach ($_REQUEST['actions'] as $topic => $action) {
        if (in_array($action, $possibleActions)) {
            $temp[(int) $topic] = $action;
        }
    }
    $_REQUEST['actions'] = $temp;
    if (!empty($_REQUEST['actions'])) {
        // Find all topics...
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, id_member_started, id_board, locked, approved, unapproved_posts
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:action_topic_ids})
			LIMIT ' . count($_REQUEST['actions']), array('action_topic_ids' => array_keys($_REQUEST['actions'])));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            if (!empty($board)) {
                if ($row['id_board'] != $board || $modSettings['postmod_active'] && !$row['approved'] && !allowedTo('approve_posts')) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                }
            } else {
                // Don't allow them to act on unapproved posts they can't see...
                if ($modSettings['postmod_active'] && !$row['approved'] && !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts'])) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                } elseif ($_REQUEST['actions'][$row['id_topic']] == 'sticky' && !in_array(0, $boards_can['make_sticky']) && !in_array($row['id_board'], $boards_can['make_sticky'])) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                } elseif ($_REQUEST['actions'][$row['id_topic']] == 'move' && !in_array(0, $boards_can['move_any']) && !in_array($row['id_board'], $boards_can['move_any']) && ($row['id_member_started'] != $user_info['id'] || !in_array(0, $boards_can['move_own']) && !in_array($row['id_board'], $boards_can['move_own']))) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                } elseif ($_REQUEST['actions'][$row['id_topic']] == 'remove' && !in_array(0, $boards_can['remove_any']) && !in_array($row['id_board'], $boards_can['remove_any']) && ($row['id_member_started'] != $user_info['id'] || !in_array(0, $boards_can['remove_own']) && !in_array($row['id_board'], $boards_can['remove_own']))) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                } elseif ($_REQUEST['actions'][$row['id_topic']] == 'lock' && !in_array(0, $boards_can['lock_any']) && !in_array($row['id_board'], $boards_can['lock_any']) && ($row['id_member_started'] != $user_info['id'] || $row['locked'] == 1 || !in_array(0, $boards_can['lock_own']) && !in_array($row['id_board'], $boards_can['lock_own']))) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                } elseif ($_REQUEST['actions'][$row['id_topic']] == 'approve' && (!$row['unapproved_posts'] || !in_array(0, $boards_can['approve_posts']) && !in_array($row['id_board'], $boards_can['approve_posts']))) {
                    unset($_REQUEST['actions'][$row['id_topic']]);
                }
            }
        }
        $smcFunc['db_free_result']($request);
    }
    $stickyCache = array();
    $moveCache = array(0 => array(), 1 => array());
    $removeCache = array();
    $lockCache = array();
    $markCache = array();
    $approveCache = array();
    // Separate the actions.
    foreach ($_REQUEST['actions'] as $topic => $action) {
        $topic = (int) $topic;
        if ($action == 'markread') {
            $markCache[] = $topic;
        } elseif ($action == 'sticky') {
            $stickyCache[] = $topic;
        } elseif ($action == 'move') {
            require_once $sourcedir . '/MoveTopic.php';
            moveTopicConcurrence();
            // $moveCache[0] is the topic, $moveCache[1] is the board to move to.
            $moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
            if (empty($moveCache[1][$topic])) {
                continue;
            }
            $moveCache[0][] = $topic;
        } elseif ($action == 'remove') {
            $removeCache[] = $topic;
        } elseif ($action == 'lock') {
            $lockCache[] = $topic;
        } elseif ($action == 'approve') {
            $approveCache[] = $topic;
        }
    }
    if (empty($board)) {
        $affectedBoards = array();
    } else {
        $affectedBoards = array($board => array(0, 0));
    }
    // Do all the stickies...
    if (!empty($stickyCache)) {
        $smcFunc['db_query']('', '
			UPDATE {db_prefix}topics
			SET is_sticky = CASE WHEN is_sticky = {int:is_sticky} THEN 0 ELSE 1 END
			WHERE id_topic IN ({array_int:sticky_topic_ids})', array('sticky_topic_ids' => $stickyCache, 'is_sticky' => 1));
        // Get the board IDs and Sticky status
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, id_board, is_sticky
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:sticky_topic_ids})
			LIMIT ' . count($stickyCache), array('sticky_topic_ids' => $stickyCache));
        $stickyCacheBoards = array();
        $stickyCacheStatus = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $stickyCacheBoards[$row['id_topic']] = $row['id_board'];
            $stickyCacheStatus[$row['id_topic']] = empty($row['is_sticky']);
        }
        $smcFunc['db_free_result']($request);
    }
    // Move sucka! (this is, by the by, probably the most complicated part....)
    if (!empty($moveCache[0])) {
        // I know - I just KNOW you're trying to beat the system.  Too bad for you... we CHECK :P.
        $request = $smcFunc['db_query']('', '
			SELECT t.id_topic, t.id_board, b.count_posts
			FROM {db_prefix}topics AS t
				LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
			WHERE t.id_topic IN ({array_int:move_topic_ids})' . (!empty($board) && !allowedTo('move_any') ? '
				AND t.id_member_started = {int:current_member}' : '') . '
			LIMIT ' . count($moveCache[0]), array('current_member' => $user_info['id'], 'move_topic_ids' => $moveCache[0]));
        $moveTos = array();
        $moveCache2 = array();
        $countPosts = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $to = $moveCache[1][$row['id_topic']];
            if (empty($to)) {
                continue;
            }
            // Does this topic's board count the posts or not?
            $countPosts[$row['id_topic']] = empty($row['count_posts']);
            if (!isset($moveTos[$to])) {
                $moveTos[$to] = array();
            }
            $moveTos[$to][] = $row['id_topic'];
            // For reporting...
            $moveCache2[] = array($row['id_topic'], $row['id_board'], $to);
        }
        $smcFunc['db_free_result']($request);
        $moveCache = $moveCache2;
        require_once $sourcedir . '/MoveTopic.php';
        // Do the actual moves...
        foreach ($moveTos as $to => $topics) {
            moveTopics($topics, $to);
        }
        // Does the post counts need to be updated?
        if (!empty($moveTos)) {
            $topicRecounts = array();
            $request = $smcFunc['db_query']('', '
				SELECT id_board, count_posts
				FROM {db_prefix}boards
				WHERE id_board IN ({array_int:move_boards})', array('move_boards' => array_keys($moveTos)));
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $cp = empty($row['count_posts']);
                // Go through all the topics that are being moved to this board.
                foreach ($moveTos[$row['id_board']] as $topic) {
                    // If both boards have the same value for post counting then no adjustment needs to be made.
                    if ($countPosts[$topic] != $cp) {
                        // If the board being moved to does count the posts then the other one doesn't so add to their post count.
                        $topicRecounts[$topic] = $cp ? '+' : '-';
                    }
                }
            }
            $smcFunc['db_free_result']($request);
            if (!empty($topicRecounts)) {
                $members = array();
                // Get all the members who have posted in the moved topics.
                $request = $smcFunc['db_query']('', '
					SELECT id_member, id_topic
					FROM {db_prefix}messages
					WHERE id_topic IN ({array_int:moved_topic_ids})', array('moved_topic_ids' => array_keys($topicRecounts)));
                while ($row = $smcFunc['db_fetch_assoc']($request)) {
                    if (!isset($members[$row['id_member']])) {
                        $members[$row['id_member']] = 0;
                    }
                    if ($topicRecounts[$row['id_topic']] === '+') {
                        $members[$row['id_member']] += 1;
                    } else {
                        $members[$row['id_member']] -= 1;
                    }
                }
                $smcFunc['db_free_result']($request);
                // And now update them member's post counts
                foreach ($members as $id_member => $post_adj) {
                    updateMemberData($id_member, array('posts' => 'posts + ' . $post_adj));
                }
            }
        }
    }
    // Now delete the topics...
    if (!empty($removeCache)) {
        // They can only delete their own topics. (we wouldn't be here if they couldn't do that..)
        $result = $smcFunc['db_query']('', '
			SELECT id_topic, id_board
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:removed_topic_ids})' . (!empty($board) && !allowedTo('remove_any') ? '
				AND id_member_started = {int:current_member}' : '') . '
			LIMIT ' . count($removeCache), array('current_member' => $user_info['id'], 'removed_topic_ids' => $removeCache));
        $removeCache = array();
        $removeCacheBoards = array();
        while ($row = $smcFunc['db_fetch_assoc']($result)) {
            $removeCache[] = $row['id_topic'];
            $removeCacheBoards[$row['id_topic']] = $row['id_board'];
        }
        $smcFunc['db_free_result']($result);
        // Maybe *none* were their own topics.
        if (!empty($removeCache)) {
            // Gotta send the notifications *first*!
            foreach ($removeCache as $topic) {
                // Only log the topic ID if it's not in the recycle board.
                logAction('remove', array(empty($modSettings['recycle_enable']) || $modSettings['recycle_board'] != $removeCacheBoards[$topic] ? 'topic' : 'old_topic_id' => $topic, 'board' => $removeCacheBoards[$topic]));
                sendNotifications($topic, 'remove');
            }
            require_once $sourcedir . '/RemoveTopic.php';
            removeTopics($removeCache);
        }
    }
    // Approve the topics...
    if (!empty($approveCache)) {
        // We need unapproved topic ids and their authors!
        $request = $smcFunc['db_query']('', '
			SELECT id_topic, id_member_started
			FROM {db_prefix}topics
			WHERE id_topic IN ({array_int:approve_topic_ids})
				AND approved = {int:not_approved}
			LIMIT ' . count($approveCache), array('approve_topic_ids' => $approveCache, 'not_approved' => 0));
        $approveCache = array();
        $approveCacheMembers = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            $approveCache[] = $row['id_topic'];
            $approveCacheMembers[$row['id_topic']] = $row['id_member_started'];
        }
        $smcFunc['db_free_result']($request);
        // Any topics to approve?
        if (!empty($approveCache)) {
            // Handle the approval part...
            approveTopics($approveCache);
            // Time for some logging!
            foreach ($approveCache as $topic) {
                logAction('approve_topic', array('topic' => $topic, 'member' => $approveCacheMembers[$topic]));
            }
        }
    }
    // And (almost) lastly, lock the topics...
    if (!empty($lockCache)) {
        $lockStatus = array();
        // Gotta make sure they CAN lock/unlock these topics...
        if (!empty($board) && !allowedTo('lock_any')) {
            // Make sure they started the topic AND it isn't already locked by someone with higher priv's.
            $result = $smcFunc['db_query']('', '
				SELECT id_topic, locked, id_board
				FROM {db_prefix}topics
				WHERE id_topic IN ({array_int:locked_topic_ids})
					AND id_member_started = {int:current_member}
					AND locked IN (2, 0)
				LIMIT ' . count($lockCache), array('current_member' => $user_info['id'], 'locked_topic_ids' => $lockCache));
            $lockCache = array();
            $lockCacheBoards = array();
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $lockCache[] = $row['id_topic'];
                $lockCacheBoards[$row['id_topic']] = $row['id_board'];
                $lockStatus[$row['id_topic']] = empty($row['locked']);
            }
            $smcFunc['db_free_result']($result);
        } else {
            $result = $smcFunc['db_query']('', '
				SELECT id_topic, locked, id_board
				FROM {db_prefix}topics
				WHERE id_topic IN ({array_int:locked_topic_ids})
				LIMIT ' . count($lockCache), array('locked_topic_ids' => $lockCache));
            $lockCacheBoards = array();
            while ($row = $smcFunc['db_fetch_assoc']($result)) {
                $lockStatus[$row['id_topic']] = empty($row['locked']);
                $lockCacheBoards[$row['id_topic']] = $row['id_board'];
            }
            $smcFunc['db_free_result']($result);
        }
        // It could just be that *none* were their own topics...
        if (!empty($lockCache)) {
            // Alternate the locked value.
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}topics
				SET locked = CASE WHEN locked = {int:is_locked} THEN ' . (allowedTo('lock_any') ? '1' : '2') . ' ELSE 0 END
				WHERE id_topic IN ({array_int:locked_topic_ids})', array('locked_topic_ids' => $lockCache, 'is_locked' => 0));
        }
    }
    if (!empty($markCache)) {
        $markArray = array();
        foreach ($markCache as $topic) {
            $markArray[] = array($modSettings['maxMsgID'], $user_info['id'], $topic);
        }
        $smcFunc['db_insert']('replace', '{db_prefix}log_topics', array('id_msg' => 'int', 'id_member' => 'int', 'id_topic' => 'int'), $markArray, array('id_member', 'id_topic'));
    }
    foreach ($moveCache as $topic) {
        // Didn't actually move anything!
        if (!isset($topic[0])) {
            break;
        }
        logAction('move', array('topic' => $topic[0], 'board_from' => $topic[1], 'board_to' => $topic[2]));
        sendNotifications($topic[0], 'move');
    }
    foreach ($lockCache as $topic) {
        logAction($lockStatus[$topic] ? 'lock' : 'unlock', array('topic' => $topic, 'board' => $lockCacheBoards[$topic]));
        sendNotifications($topic, $lockStatus[$topic] ? 'lock' : 'unlock');
    }
    foreach ($stickyCache as $topic) {
        logAction($stickyCacheStatus[$topic] ? 'unsticky' : 'sticky', array('topic' => $topic, 'board' => $stickyCacheBoards[$topic]));
        sendNotifications($topic, 'sticky');
    }
    updateStats('topic');
    updateStats('message');
    updateSettings(array('calendar_updated' => time()));
    if (!empty($affectedBoards)) {
        updateLastMessages(array_keys($affectedBoards));
    }
    redirectexit($redirect_url);
}
function MaintainMassMoveTopics()
{
    global $smcFunc, $sourcedir, $context, $txt;
    // Only admins.
    isAllowedTo('admin_forum');
    checkSession('request');
    // Set up to the context.
    $context['page_title'] = $txt['not_done_title'];
    $context['continue_countdown'] = '3';
    $context['continue_post_data'] = '';
    $context['continue_get_data'] = '';
    $context['sub_template'] = 'not_done';
    $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
    $context['start_time'] = time();
    // First time we do this?
    $id_board_from = isset($_POST['id_board_from']) ? (int) $_POST['id_board_from'] : (int) $_REQUEST['id_board_from'];
    $id_board_to = isset($_POST['id_board_to']) ? (int) $_POST['id_board_to'] : (int) $_REQUEST['id_board_to'];
    // No boards then this is your stop.
    if (empty($id_board_from) || empty($id_board_to)) {
        return;
    }
    // How many topics are we converting?
    if (!isset($_REQUEST['totaltopics'])) {
        $request = $smcFunc['db_query']('', '
			SELECT COUNT(*)
			FROM {db_prefix}topics
			WHERE id_board = {int:id_board_from}', array('id_board_from' => $id_board_from));
        list($total_topics) = $smcFunc['db_fetch_row']($request);
        $smcFunc['db_free_result']($request);
    } else {
        $total_topics = (int) $_REQUEST['totaltopics'];
    }
    // Seems like we need this here.
    $context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
    // We have topics to move so start the process.
    if (!empty($total_topics)) {
        while ($context['start'] <= $total_topics) {
            // Lets get the topics.
            $request = $smcFunc['db_query']('', '
				SELECT id_topic
				FROM {db_prefix}topics
				WHERE id_board = {int:id_board_from}
				LIMIT 10', array('id_board_from' => $id_board_from));
            // Get the ids.
            $topics = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $topics[] = $row['id_topic'];
            }
            // Just return if we don't have any topics left to move.
            if (empty($topics)) {
                cache_put_data('board-' . $id_board_from, null, 120);
                cache_put_data('board-' . $id_board_to, null, 120);
                redirectexit('action=admin;area=maintain;sa=topics;done=massmove');
            }
            // Lets move them.
            require_once $sourcedir . '/MoveTopic.php';
            moveTopics($topics, $id_board_to);
            // We've done at least ten more topics.
            $context['start'] += 10;
            // Lets wait a while.
            if (time() - $context['start_time'] > 3) {
                // What's the percent?
                $context['continue_percent'] = round(100 * ($context['start'] / $total_topics), 1);
                $context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
                // Let the template system do it's thang.
                return;
            }
        }
    }
    // Don't confuse admins by having an out of date cache.
    cache_put_data('board-' . $id_board_from, null, 120);
    cache_put_data('board-' . $id_board_to, null, 120);
    redirectexit('action=admin;area=maintain;sa=topics;done=massmove');
}
Exemple #5
0
/**
 * If we are also moving the topic somewhere else, let's try do to it
 * Includes checks for permissions move_own/any, etc.
 *
 * @param mixed[] $boards an array containing basic info of the origin and destination boards (from splitDestinationBoard)
 * @param int $totopic id of the destination topic
 */
function splitAttemptMove($boards, $totopic)
{
    global $board, $user_info;
    $db = database();
    // If the starting and final boards are different we have to check some permissions and stuff
    if ($boards['destination']['id'] != $board) {
        $doMove = false;
        if (allowedTo('move_any')) {
            $doMove = true;
        } else {
            $new_topic = getTopicInfo($totopic);
            if ($new_topic['id_member_started'] == $user_info['id'] && allowedTo('move_own')) {
                $doMove = true;
            }
        }
        if ($doMove) {
            // Update member statistics if needed
            // @todo this should probably go into a function...
            if ($boards['destination']['count_posts'] != $boards['current']['count_posts']) {
                $request = $db->query('', '
					SELECT id_member
					FROM {db_prefix}messages
					WHERE id_topic = {int:current_topic}
						AND approved = {int:is_approved}', array('current_topic' => $totopic, 'is_approved' => 1));
                $posters = array();
                while ($row = $db->fetch_assoc($request)) {
                    if (!isset($posters[$row['id_member']])) {
                        $posters[$row['id_member']] = 0;
                    }
                    $posters[$row['id_member']]++;
                }
                $db->free_result($request);
                foreach ($posters as $id_member => $posts) {
                    // The board we're moving from counted posts, but not to.
                    if (empty($boards['current']['count_posts'])) {
                        updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
                    } else {
                        updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
                    }
                }
            }
            // And finally move it!
            moveTopics($totopic, $boards['destination']['id']);
        } else {
            $boards['destination'] = $boards['current'];
        }
    }
}
Exemple #6
0
/**
 * Move back a topic from the recycle board to its original board.
 */
function RestoreTopic()
{
    global $context, $smcFunc, $modSettings, $sourcedir;
    // Check session.
    checkSession('get');
    // Is recycled board enabled?
    if (empty($modSettings['recycle_enable'])) {
        fatal_lang_error('restored_disabled', 'critical');
    }
    // Can we be in here?
    isAllowedTo('move_any', $modSettings['recycle_board']);
    // We need this file.
    require_once $sourcedir . '/MoveTopic.php';
    $unfound_messages = array();
    $topics_to_restore = array();
    // Restoring messages?
    if (!empty($_REQUEST['msgs'])) {
        $msgs = explode(',', $_REQUEST['msgs']);
        foreach ($msgs as $k => $msg) {
            $msgs[$k] = (int) $msg;
        }
        // Get the id_previous_board and id_previous_topic.
        $request = $smcFunc['db_query']('', '
			SELECT m.id_topic, m.id_msg, m.id_board, m.subject, m.id_member, t.id_previous_board, t.id_previous_topic,
				t.id_first_msg, b.count_posts, IFNULL(pt.id_board, 0) AS possible_prev_board
			FROM {db_prefix}messages AS m
				INNER JOIN {db_prefix}topics AS t ON (t.id_topic = m.id_topic)
				INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
				LEFT JOIN {db_prefix}topics AS pt ON (pt.id_topic = t.id_previous_topic)
			WHERE m.id_msg IN ({array_int:messages})', array('messages' => $msgs));
        $actioned_messages = array();
        $previous_topics = array();
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // Restoring the first post means topic.
            if ($row['id_msg'] == $row['id_first_msg'] && $row['id_previous_topic'] == $row['id_topic']) {
                $topics_to_restore[] = $row['id_topic'];
                continue;
            }
            // Don't know where it's going?
            if (empty($row['id_previous_topic'])) {
                $unfound_messages[$row['id_msg']] = $row['subject'];
                continue;
            }
            $previous_topics[] = $row['id_previous_topic'];
            if (empty($actioned_messages[$row['id_previous_topic']])) {
                $actioned_messages[$row['id_previous_topic']] = array('msgs' => array(), 'count_posts' => $row['count_posts'], 'subject' => $row['subject'], 'previous_board' => $row['id_previous_board'], 'possible_prev_board' => $row['possible_prev_board'], 'current_topic' => $row['id_topic'], 'current_board' => $row['id_board'], 'members' => array());
            }
            $actioned_messages[$row['id_previous_topic']]['msgs'][$row['id_msg']] = $row['subject'];
            if ($row['id_member']) {
                $actioned_messages[$row['id_previous_topic']]['members'][] = $row['id_member'];
            }
        }
        $smcFunc['db_free_result']($request);
        // Check for topics we are going to fully restore.
        foreach ($actioned_messages as $topic => $data) {
            if (in_array($topic, $topics_to_restore)) {
                unset($actioned_messages[$topic]);
            }
        }
        // Load any previous topics to check they exist.
        if (!empty($previous_topics)) {
            $request = $smcFunc['db_query']('', '
				SELECT t.id_topic, t.id_board, m.subject
				FROM {db_prefix}topics AS t
					INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
				WHERE t.id_topic IN ({array_int:previous_topics})', array('previous_topics' => $previous_topics));
            $previous_topics = array();
            while ($row = $smcFunc['db_fetch_assoc']($request)) {
                $previous_topics[$row['id_topic']] = array('board' => $row['id_board'], 'subject' => $row['subject']);
            }
            $smcFunc['db_free_result']($request);
        }
        // Restore each topic.
        $messages = array();
        foreach ($actioned_messages as $topic => $data) {
            // If we have topics we are going to restore the whole lot ignore them.
            if (in_array($topic, $topics_to_restore)) {
                unset($actioned_messages[$topic]);
                continue;
            }
            // Move the posts back then!
            if (isset($previous_topics[$topic])) {
                mergePosts(array_keys($data['msgs']), $data['current_topic'], $topic);
                // Log em.
                logAction('restore_posts', array('topic' => $topic, 'subject' => $previous_topics[$topic]['subject'], 'board' => empty($data['previous_board']) ? $data['possible_prev_board'] : $data['previous_board']));
                $messages = array_merge(array_keys($data['msgs']), $messages);
            } else {
                foreach ($data['msgs'] as $msg) {
                    $unfound_messages[$msg['id']] = $msg['subject'];
                }
            }
        }
        // Put the icons back.
        if (!empty($messages)) {
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}messages
				SET icon = {string:icon}
				WHERE id_msg IN ({array_int:messages})', array('icon' => 'xx', 'messages' => $messages));
        }
    }
    // Now any topics?
    if (!empty($_REQUEST['topics'])) {
        $topics = explode(',', $_REQUEST['topics']);
        foreach ($topics as $key => $id) {
            $topics_to_restore[] = (int) $id;
        }
    }
    if (!empty($topics_to_restore)) {
        // Lets get the data for these topics.
        $request = $smcFunc['db_query']('', '
			SELECT t.id_topic, t.id_previous_board, t.id_board, t.id_first_msg, m.subject
			FROM {db_prefix}topics AS t
				INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
			WHERE t.id_topic IN ({array_int:topics})', array('topics' => $topics_to_restore));
        while ($row = $smcFunc['db_fetch_assoc']($request)) {
            // We can only restore if the previous board is set.
            if (empty($row['id_previous_board'])) {
                $unfound_messages[$row['id_first_msg']] = $row['subject'];
                continue;
            }
            // Ok we got here so me move them from here to there.
            moveTopics($row['id_topic'], $row['id_previous_board']);
            // Lets remove the recycled icon.
            $smcFunc['db_query']('', '
				UPDATE {db_prefix}messages
				SET icon = {string:icon}
				WHERE id_topic = {int:id_topic}', array('icon' => 'xx', 'id_topic' => $row['id_topic']));
            // Lets see if the board that we are returning to has post count enabled.
            $request2 = $smcFunc['db_query']('', '
				SELECT count_posts
				FROM {db_prefix}boards
				WHERE id_board = {int:board}', array('board' => $row['id_previous_board']));
            list($count_posts) = $smcFunc['db_fetch_row']($request2);
            $smcFunc['db_free_result']($request2);
            if (empty($count_posts)) {
                // Lets get the members that need their post count restored.
                $request2 = $smcFunc['db_query']('', '
					SELECT id_member, COUNT(id_msg) AS post_count
					FROM {db_prefix}messages
					WHERE id_topic = {int:topic}
						AND approved = {int:is_approved}
					GROUP BY id_member', array('topic' => $row['id_topic'], 'is_approved' => 1));
                while ($member = $smcFunc['db_fetch_assoc']($request2)) {
                    updateMemberData($member['id_member'], array('posts' => 'posts + ' . $member['post_count']));
                }
                $smcFunc['db_free_result']($request2);
            }
            // Log it.
            logAction('restore_topic', array('topic' => $row['id_topic'], 'board' => $row['id_board'], 'board_to' => $row['id_previous_board']));
        }
        $smcFunc['db_free_result']($request);
    }
    // Didn't find some things?
    if (!empty($unfound_messages)) {
        fatal_lang_error('restore_not_found', false, array(implode('<br />', $unfound_messages)));
    }
    // Just send them to the index if they get here.
    redirectexit();
}
Exemple #7
0
function removeTopics($topics, $decreasePostCount = true, $ignoreRecycling = false)
{
    global $db_prefix, $sourcedir, $modSettings;
    // Nothing to do?
    if (empty($topics)) {
        return;
    } elseif (is_numeric($topics)) {
        $condition = '= ' . $topics;
        $topics = array($topics);
    } elseif (count($topics) == 1) {
        $condition = '= ' . $topics[0];
    } else {
        $condition = 'IN (' . implode(', ', $topics) . ')';
    }
    // Decrease the post counts.
    if ($decreasePostCount) {
        $requestMembers = db_query("\n\t\t\tSELECT m.ID_MEMBER, COUNT(*) AS posts\n\t\t\tFROM ({$db_prefix}messages AS m, {$db_prefix}boards AS b)\n\t\t\tWHERE m.ID_TOPIC {$condition}\n\t\t\t\tAND b.ID_BOARD = m.ID_BOARD\n\t\t\t\tAND m.icon != 'recycled'\n\t\t\t\tAND b.countPosts = 0\n\t\t\tGROUP BY m.ID_MEMBER", __FILE__, __LINE__);
        if (mysql_num_rows($requestMembers) > 0) {
            while ($rowMembers = mysql_fetch_assoc($requestMembers)) {
                updateMemberData($rowMembers['ID_MEMBER'], array('posts' => 'posts - ' . $rowMembers['posts']));
            }
        }
        mysql_free_result($requestMembers);
    }
    // Recycle topics that aren't in the recycle board...
    if (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 && !$ignoreRecycling) {
        $request = db_query("\n\t\t\tSELECT ID_TOPIC\n\t\t\tFROM {$db_prefix}topics\n\t\t\tWHERE ID_TOPIC {$condition}\n\t\t\t\tAND ID_BOARD != {$modSettings['recycle_board']}\n\t\t\tLIMIT " . count($topics), __FILE__, __LINE__);
        if (mysql_num_rows($request) > 0) {
            // Get topics that will be recycled.
            $recycleTopics = array();
            while ($row = mysql_fetch_assoc($request)) {
                $recycleTopics[] = $row['ID_TOPIC'];
            }
            mysql_free_result($request);
            // Mark recycled topics as recycled.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}messages\n\t\t\t\tSET icon = 'recycled'\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $recycleTopics) . ")", __FILE__, __LINE__);
            // De-sticky and unlock topics.
            db_query("\n\t\t\t\tUPDATE {$db_prefix}topics\n\t\t\t\tSET \n\t\t\t\t\tlocked = 0,\n\t\t\t\t\tisSticky = 0\n\t\t\t\tWHERE ID_TOPIC IN (" . implode(', ', $recycleTopics) . ")", __FILE__, __LINE__);
            // Move the topics to the recycle board.
            require_once $sourcedir . '/MoveTopic.php';
            moveTopics($recycleTopics, $modSettings['recycle_board']);
            // Topics that were recycled don't need to be deleted, so subtract them.
            $topics = array_diff($topics, $recycleTopics);
            // Topic list has changed, so does the condition to select topics.
            $condition = 'IN (' . implode(', ', $topics) . ')';
        } else {
            mysql_free_result($request);
        }
    }
    // Still topics left to delete?
    if (empty($topics)) {
        return;
    }
    $adjustBoards = array();
    // Find out how many posts we are deleting.
    $request = db_query("\n\t\tSELECT ID_BOARD, COUNT(*) AS numTopics, SUM(numReplies) AS numReplies\n\t\tFROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC {$condition}\n\t\tGROUP BY ID_BOARD", __FILE__, __LINE__);
    while ($row = mysql_fetch_assoc($request)) {
        // The numReplies is only the *replies*.  There're also the first posts in the topics.
        $adjustBoards[] = array('numPosts' => $row['numReplies'] + $row['numTopics'], 'numTopics' => $row['numTopics'], 'ID_BOARD' => $row['ID_BOARD']);
    }
    mysql_free_result($request);
    // Decrease the posts/topics...
    foreach ($adjustBoards as $stats) {
        db_query("\n\t\t\tUPDATE {$db_prefix}boards\n\t\t\tSET \n\t\t\t\tnumTopics = IF({$stats['numTopics']} > numTopics, 0, numTopics - {$stats['numTopics']}),\n\t\t\t\tnumPosts = IF ({$stats['numPosts']} > numPosts, 0, numPosts - {$stats['numPosts']})\n\t\t\tWHERE ID_BOARD = {$stats['ID_BOARD']}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
    }
    // Remove Polls.
    $request = db_query("\n\t\tSELECT ID_POLL\n\t\tFROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC {$condition}\n\t\t\tAND ID_POLL > 0\n\t\tLIMIT " . count($topics), __FILE__, __LINE__);
    $polls = array();
    while ($row = mysql_fetch_assoc($request)) {
        $polls[] = $row['ID_POLL'];
    }
    mysql_free_result($request);
    if (!empty($polls)) {
        $pollCondition = count($polls) == 1 ? '= ' . $polls[0] : 'IN (' . implode(', ', $polls) . ')';
        db_query("\n\t\t\tDELETE FROM {$db_prefix}polls\n\t\t\tWHERE ID_POLL {$pollCondition}\n\t\t\tLIMIT " . count($polls), __FILE__, __LINE__);
        db_query("\n\t\t\tDELETE FROM {$db_prefix}poll_choices\n\t\t\tWHERE ID_POLL {$pollCondition}", __FILE__, __LINE__);
        db_query("\n\t\t\tDELETE FROM {$db_prefix}log_polls\n\t\t\tWHERE ID_POLL {$pollCondition}", __FILE__, __LINE__);
    }
    // Get rid of the attachment, if it exists.
    require_once $sourcedir . '/ManageAttachments.php';
    removeAttachments('a.attachmentType = 0 AND m.ID_TOPIC ' . $condition, 'messages');
    // Delete possible search index entries.
    if (!empty($modSettings['search_custom_index_config'])) {
        $customIndexSettings = unserialize($modSettings['search_custom_index_config']);
        $words = array();
        $messages = array();
        $request = db_query("\n\t\t\tSELECT ID_MSG, body\n\t\t\tFROM {$db_prefix}messages\n\t\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
        while ($row = mysql_fetch_assoc($request)) {
            $words = array_merge($words, text2words($row['body'], $customIndexSettings['bytes_per_word'], true));
            $messages[] = $row['ID_MSG'];
        }
        mysql_free_result($request);
        $words = array_unique($words);
        if (!empty($words) && !empty($messages)) {
            db_query("\n\t\t\t\tDELETE FROM {$db_prefix}log_search_words\n\t\t\t\tWHERE ID_WORD IN (" . implode(', ', $words) . ")\n\t\t\t\t\tAND ID_MSG IN (" . implode(', ', $messages) . ')', __FILE__, __LINE__);
        }
    }
    // Delete anything related to the topic.
    db_query("\n\t\tDELETE FROM {$db_prefix}messages\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}calendar\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}log_topics\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}log_notify\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC {$condition}\n\t\tLIMIT " . count($topics), __FILE__, __LINE__);
    db_query("\n\t\tDELETE FROM {$db_prefix}log_search_subjects\n\t\tWHERE ID_TOPIC {$condition}", __FILE__, __LINE__);
    // Update the totals...
    updateStats('message');
    updateStats('topic');
    updateStats('calendar');
    require_once $sourcedir . '/Subs-Post.php';
    $updates = array();
    foreach ($adjustBoards as $stats) {
        $updates[] = $stats['ID_BOARD'];
    }
    updateLastMessages($updates);
}
 /**
  * Execute the move of a topic.
  * It is called on the submit of action_movetopic.
  * This function logs that topics have been moved in the moderation log.
  * If the member is the topic starter requires the move_own permission,
  * otherwise requires the move_any permission.
  * Upon successful completion redirects to message index.
  * Accessed via ?action=movetopic2.
  *
  * @uses subs/Post.subs.php.
  */
 public function action_movetopic2()
 {
     global $txt, $board, $topic, $scripturl, $context, $language, $user_info;
     if (empty($topic)) {
         fatal_lang_error('no_access', false);
     }
     // You can't choose to have a redirection topic and use an empty reason.
     if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) {
         fatal_lang_error('movetopic_no_reason', false);
     }
     // You have to tell us were you are moving to
     if (!isset($_POST['toboard'])) {
         fatal_lang_error('movetopic_no_board', false);
     }
     // We will need this
     require_once SUBSDIR . '/Topic.subs.php';
     moveTopicConcurrence();
     // Make sure this form hasn't been submitted before.
     checkSubmitOnce('check');
     // Get the basic details on this topic
     $topic_info = getTopicInfo($topic);
     $context['is_approved'] = $topic_info['approved'];
     // Can they see it?
     if (!$context['is_approved']) {
         isAllowedTo('approve_posts');
     }
     // Can they move topics on this board?
     if (!allowedTo('move_any')) {
         if ($topic_info['id_member_started'] == $user_info['id']) {
             isAllowedTo('move_own');
         } else {
             isAllowedTo('move_any');
         }
     }
     checkSession();
     require_once SUBSDIR . '/Post.subs.php';
     require_once SUBSDIR . '/Boards.subs.php';
     // The destination board must be numeric.
     $toboard = (int) $_POST['toboard'];
     // Make sure they can see the board they are trying to move to (and get whether posts count in the target board).
     $board_info = boardInfo($toboard, $topic);
     if (empty($board_info)) {
         fatal_lang_error('no_board');
     }
     // Remember this for later.
     $_SESSION['move_to_topic'] = array('move_to' => $toboard);
     // Rename the topic...
     if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '') {
         $custom_subject = strtr(Util::htmltrim(Util::htmlspecialchars($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => ''));
         // Keep checking the length.
         if (Util::strlen($custom_subject) > 100) {
             $custom_subject = Util::substr($custom_subject, 0, 100);
         }
         // If it's still valid move onwards and upwards.
         if ($custom_subject != '') {
             $all_messages = isset($_POST['enforce_subject']);
             if ($all_messages) {
                 // Get a response prefix, but in the forum's default language.
                 $context['response_prefix'] = response_prefix();
                 topicSubject($topic_info, $custom_subject, $context['response_prefix'], $all_messages);
             } else {
                 topicSubject($topic_info, $custom_subject);
             }
             // Fix the subject cache.
             updateStats('subject', $topic, $custom_subject);
         }
     }
     // Create a link to this in the old board.
     // @todo Does this make sense if the topic was unapproved before? I'd just about say so.
     if (isset($_POST['postRedirect'])) {
         // Should be in the boardwide language.
         if ($user_info['language'] != $language) {
             loadLanguage('index', $language);
         }
         $reason = Util::htmlspecialchars($_POST['reason'], ENT_QUOTES);
         preparsecode($reason);
         // Add a URL onto the message.
         $reason = strtr($reason, array($txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $toboard . '.0]' . $board_info['name'] . '[/url]', $txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]'));
         // Auto remove this MOVED redirection topic in the future?
         $redirect_expires = !empty($_POST['redirect_expires']) ? (int) $_POST['redirect_expires'] : 0;
         // Redirect to the MOVED topic from topic list?
         $redirect_topic = isset($_POST['redirect_topic']) ? $topic : 0;
         // And remember the last expiry period too.
         $_SESSION['move_to_topic']['redirect_topic'] = $redirect_topic;
         $_SESSION['move_to_topic']['redirect_expires'] = $redirect_expires;
         $msgOptions = array('subject' => $txt['moved'] . ': ' . $board_info['subject'], 'body' => $reason, 'icon' => 'moved', 'smileys_enabled' => 1);
         $topicOptions = array('board' => $board, 'lock_mode' => 1, 'mark_as_read' => true, 'redirect_expires' => empty($redirect_expires) ? 0 : $redirect_expires * 60 + time(), 'redirect_topic' => $redirect_topic);
         $posterOptions = array('id' => $user_info['id'], 'update_post_count' => empty($board_info['count_posts']));
         createPost($msgOptions, $topicOptions, $posterOptions);
     }
     $board_from = boardInfo($board);
     if ($board_from['count_posts'] != $board_info['count_posts']) {
         $posters = postersCount($topic);
         foreach ($posters as $id_member => $posts) {
             // The board we're moving from counted posts, but not to.
             if (empty($board_from['count_posts'])) {
                 updateMemberData($id_member, array('posts' => 'posts - ' . $posts));
             } else {
                 updateMemberData($id_member, array('posts' => 'posts + ' . $posts));
             }
         }
     }
     // Do the move (includes statistics update needed for the redirect topic).
     moveTopics($topic, $toboard);
     // Log that they moved this topic.
     if (!allowedTo('move_own') || $topic_info['id_member_started'] != $user_info['id']) {
         logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $toboard));
     }
     // Notify people that this topic has been moved?
     require_once SUBSDIR . '/Notification.subs.php';
     sendNotifications($topic, 'move');
     // Why not go back to the original board in case they want to keep moving?
     if (!isset($_REQUEST['goback'])) {
         redirectexit('board=' . $board . '.0');
     } else {
         redirectexit('topic=' . $topic . '.0');
     }
 }
Exemple #9
0
function MoveTopic2()
{
    global $txt, $board, $topic, $scripturl, $sourcedir, $modSettings, $context;
    global $db_prefix, $ID_MEMBER, $board, $language, $user_info, $func;
    // Make sure this form hasn't been submitted before.
    checkSubmitOnce('check');
    $request = db_query("\n\t\tSELECT ID_MEMBER_STARTED, ID_FIRST_MSG\n\t\tFROM {$db_prefix}topics\n\t\tWHERE ID_TOPIC = {$topic}\n\t\tLIMIT 1", __FILE__, __LINE__);
    list($ID_MEMBER_STARTED, $ID_FIRST_MSG) = mysql_fetch_row($request);
    mysql_free_result($request);
    // Can they move topics on this board?
    if (!allowedTo('move_any')) {
        if ($ID_MEMBER_STARTED == $ID_MEMBER) {
            isAllowedTo('move_own');
            $boards = array_merge(boardsAllowedTo('move_own'), boardsAllowedTo('move_any'));
        } else {
            isAllowedTo('move_any');
        }
    } else {
        $boards = boardsAllowedTo('move_any');
    }
    checkSession();
    require_once $sourcedir . '/Subs-Post.php';
    // The destination board must be numeric.
    $_POST['toboard'] = (int) $_POST['toboard'];
    // !!!
    /*if (!in_array($_POST['toboard'], $boards) && !in_array(0, $boards))
    		fatal_lang_error('smf232');*/
    // Make sure they can see the board they are trying to move to (and get whether posts count in the target board).
    $request = db_query("\n\t\tSELECT b.countPosts, b.name, m.subject\n\t\tFROM ({$db_prefix}boards AS b, {$db_prefix}topics AS t, {$db_prefix}messages AS m)\n\t\tWHERE {$user_info['query_see_board']}\n\t\t\tAND b.ID_BOARD = {$_POST['toboard']}\n\t\t\tAND t.ID_TOPIC = {$topic}\n\t\t\tAND m.ID_MSG = t.ID_FIRST_MSG\n\t\tLIMIT 1", __FILE__, __LINE__);
    if (mysql_num_rows($request) == 0) {
        fatal_lang_error('smf232');
    }
    list($pcounter, $board_name, $subject) = mysql_fetch_row($request);
    mysql_free_result($request);
    // Remember this for later.
    $_SESSION['move_to_topic'] = $_POST['toboard'];
    // Rename the topic...
    if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '') {
        $_POST['custom_subject'] = $func['htmlspecialchars']($_POST['custom_subject']);
        if (isset($_POST['enforce_subject'])) {
            // Get a response prefix, but in the forum's default language.
            if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) {
                if ($language === $user_info['language']) {
                    $context['response_prefix'] = $txt['response_prefix'];
                } else {
                    loadLanguage('index', $language, false);
                    $context['response_prefix'] = $txt['response_prefix'];
                    loadLanguage('index');
                }
                cache_put_data('response_prefix', $context['response_prefix'], 600);
            }
            db_query("\n\t\t\t\tUPDATE {$db_prefix}messages\n\t\t\t\tSET subject = '{$context['response_prefix']}{$_POST['custom_subject']}'\n\t\t\t\tWHERE ID_TOPIC = {$topic}", __FILE__, __LINE__);
        }
        db_query("\n\t\t\tUPDATE {$db_prefix}messages\n\t\t\tSET subject = '{$_POST['custom_subject']}'\n\t\t\tWHERE ID_MSG = {$ID_FIRST_MSG}\n\t\t\tLIMIT 1", __FILE__, __LINE__);
        // Fix the subject cache.
        updateStats('subject', $topic, $_POST['custom_subject']);
    }
    // Create a link to this in the old board.
    if (isset($_POST['postRedirect'])) {
        // Should be in the boardwide language.
        if ($user_info['language'] != $language) {
            loadLanguage('index', $language);
        }
        $_POST['reason'] = $func['htmlspecialchars']($_POST['reason'], ENT_QUOTES);
        preparsecode($_POST['reason']);
        // Add a URL onto the message.
        $_POST['reason'] = strtr($_POST['reason'], array($txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $_POST['toboard'] . ']' . addslashes($board_name) . '[/url]', $txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]'));
        $msgOptions = array('subject' => addslashes($txt['smf56'] . ': ' . $subject), 'body' => $_POST['reason'], 'icon' => 'moved', 'smileys_enabled' => 1);
        $topicOptions = array('board' => $board, 'lock_mode' => 1, 'mark_as_read' => true);
        $posterOptions = array('id' => $ID_MEMBER, 'update_post_count' => !empty($pcounter));
        createPost($msgOptions, $topicOptions, $posterOptions);
    }
    $request = db_query("\n\t\tSELECT countPosts\n\t\tFROM {$db_prefix}boards\n\t\tWHERE ID_BOARD = {$board}\n\t\tLIMIT 1", __FILE__, __LINE__);
    list($pcounter_from) = mysql_fetch_row($request);
    mysql_free_result($request);
    if ($pcounter_from != $pcounter) {
        $request = db_query("\n\t\t\tSELECT ID_MEMBER\n\t\t\tFROM {$db_prefix}messages\n\t\t\tWHERE ID_TOPIC = {$topic}", __FILE__, __LINE__);
        $posters = array();
        while ($row = mysql_fetch_assoc($request)) {
            $posters[] = $row['ID_MEMBER'];
        }
        mysql_free_result($request);
        // The board we're moving from counted posts, but not to.
        if (empty($pcounter_from)) {
            updateMemberData($posters, array('posts' => '-'));
        } else {
            updateMemberData($posters, array('posts' => '+'));
        }
    }
    // Do the move (includes statistics update needed for the redirect topic).
    moveTopics($topic, $_POST['toboard']);
    // Log that they moved this topic.
    if (!allowedTo('move_own') || $ID_MEMBER_STARTED != $ID_MEMBER) {
        logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard']));
    }
    // Notify people that this topic has been moved?
    sendNotifications($topic, 'move');
    // Update the cache?
    if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] == 3) {
        cache_put_data('topic_board-' . $topic, null, 120);
    }
    // Why not go back to the original board in case they want to keep moving?
    if (!isset($_REQUEST['goback'])) {
        redirectexit('board=' . $board . '.0');
    } else {
        redirectexit('topic=' . $topic . '.0');
    }
}
Exemple #10
0
    if (!$xoopsSecurity->check()) {
        redirect_header('./topic.php?id=' . $posts, 2, __('Session token expired!', 'bxpress'));
        die;
    }
    $post->setApproved($app);
    if ($post->editText()) {
        $post->setText($post->editText());
    }
    $post->setEditText('');
    $post->save();
    redirect_header('./topic.php?id=' . $post->topic(), 1, __('Operation completed!', 'bxpress'));
}
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
switch ($op) {
    case 'move':
        moveTopics();
        break;
    case 'close':
        closeTopic(1);
        break;
    case 'open':
        closeTopic(0);
        break;
    case 'sticky':
        stickyTopic(1);
        break;
    case 'unsticky':
        stickyTopic(0);
        break;
    case 'delete':
        deleteTopics();
    /**
     * Moves topics from one board to another.
     *
     * @uses not_done template to pause the process.
     */
    public function action_massmove_display()
    {
        global $context, $txt, $time_start;
        // Only admins.
        isAllowedTo('admin_forum');
        // And valid requests
        checkSession();
        // Set up to the context.
        $context['page_title'] = $txt['not_done_title'];
        $context['continue_countdown'] = 3;
        $context['continue_post_data'] = '';
        $context['continue_get_data'] = '';
        $context['sub_template'] = 'not_done';
        $context['start'] = empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'];
        // First time we do this?
        $id_board_from = isset($_POST['id_board_from']) ? (int) $_POST['id_board_from'] : (int) $_REQUEST['id_board_from'];
        $id_board_to = isset($_POST['id_board_to']) ? (int) $_POST['id_board_to'] : (int) $_REQUEST['id_board_to'];
        // No boards then this is your stop.
        if (empty($id_board_from) || empty($id_board_to)) {
            return;
        }
        // These will be needed
        require_once SUBSDIR . '/Maintenance.subs.php';
        require_once SUBSDIR . '/Topic.subs.php';
        // How many topics are we moving?
        if (!isset($_REQUEST['totaltopics'])) {
            $total_topics = countTopicsFromBoard($id_board_from);
        } else {
            $total_topics = (int) $_REQUEST['totaltopics'];
            validateToken('admin_movetopics');
        }
        // We have topics to move so start the process.
        if (!empty($total_topics)) {
            while ($context['start'] <= $total_topics) {
                // Lets get the next 10 topics.
                $topics = getTopicsToMove($id_board_from);
                // Just return if we don't have any topics left to move.
                if (empty($topics)) {
                    break;
                }
                // Lets move them.
                moveTopics($topics, $id_board_to);
                // Increase the counter
                $context['start'] += 10;
                // If this is really taking some time, show the pause screen
                if (microtime(true) - $time_start > 3) {
                    createToken('admin_movetopics');
                    // What's the percent?
                    $context['continue_percent'] = round(100 * ($context['start'] / $total_topics), 1);
                    // Set up for the form
                    $context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';start=' . $context['start'];
                    $context['continue_post_data'] = '
						<input type="hidden" name="' . $context['session_var'] . '" value="' . $context['session_id'] . '" />
						<input type="hidden" name="' . $context['admin_movetopics_token_var'] . '" value="' . $context['admin_movetopics_token'] . '" />';
                    // Let the template system do it's thang.
                    return;
                }
            }
        }
        // Don't confuse admins by having an out of date cache.
        cache_put_data('board-' . $id_board_from, null, 120);
        cache_put_data('board-' . $id_board_to, null, 120);
        redirectexit('action=admin;area=maintain;sa=topics;done=massmove');
    }