/** * Allows the user to select the messages to be split. * is accessed with ?action=splittopics;sa=selectTopics. * uses 'select' sub template of the SplitTopics template or (for * XMLhttp) the 'split' sub template of the Xml template. * supports XMLhttp for adding/removing a message to the selection. * uses a session variable to store the selected topics. * shows two independent page indexes for both the selected and * not-selected messages (;topic=1.x;start2=y). */ public function action_splitSelectTopics() { global $txt, $scripturl, $topic, $context, $modSettings, $options; $context['page_title'] = $txt['split_topic'] . ' - ' . $txt['select_split_posts']; $context['destination_board'] = !empty($_POST['move_to_board']) ? (int) $_POST['move_to_board'] : 0; // Haven't selected anything have we? $_SESSION['split_selection'][$topic] = empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic]; // This is a special case for split topics from quick-moderation checkboxes if (isset($_REQUEST['subname_enc'])) { $this->_new_topic_subject = urldecode($_REQUEST['subname_enc']); $this->_set_session_values(); } require_once SUBSDIR . '/Topic.subs.php'; require_once SUBSDIR . '/Messages.subs.php'; $context['not_selected'] = array('num_messages' => 0, 'start' => empty($_REQUEST['start']) ? 0 : (int) $_REQUEST['start'], 'messages' => array()); $context['selected'] = array('num_messages' => 0, 'start' => empty($_REQUEST['start2']) ? 0 : (int) $_REQUEST['start2'], 'messages' => array()); $context['topic'] = array('id' => $topic, 'subject' => urlencode($_SESSION['new_topic_subject'])); // Some stuff for our favorite template. $context['new_subject'] = $_SESSION['new_topic_subject']; // Using the "select" sub template. $context['sub_template'] = isset($_REQUEST['xml']) ? 'split' : 'select'; // All of the js for topic split selection is needed if (!isset($_REQUEST['xml'])) { loadJavascriptFile('topic.js'); } // Are we using a custom messages per page? $context['messages_per_page'] = empty($modSettings['disableCustomPerPage']) && !empty($options['messages_per_page']) ? $options['messages_per_page'] : $modSettings['defaultMaxMessages']; // Get the message ID's from before the move. if (isset($_REQUEST['xml'])) { $original_msgs = array('not_selected' => messageAt($context['not_selected']['start'], $topic, array('not_in' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => $context['messages_per_page'])), 'selected' => array()); // You can't split the last message off. if (empty($context['not_selected']['start']) && count($original_msgs['not_selected']) <= 1 && $_REQUEST['move'] == 'down') { $_REQUEST['move'] = ''; } if (!empty($_SESSION['split_selection'][$topic])) { $original_msgs['selected'] = messageAt($context['selected']['start'], $topic, array('include' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => $context['messages_per_page'])); } } // (De)select a message.. if (!empty($_REQUEST['move'])) { $_REQUEST['msg'] = (int) $_REQUEST['msg']; if ($_REQUEST['move'] == 'reset') { $_SESSION['split_selection'][$topic] = array(); } elseif ($_REQUEST['move'] == 'up') { $_SESSION['split_selection'][$topic] = array_diff($_SESSION['split_selection'][$topic], array($_REQUEST['msg'])); } else { $_SESSION['split_selection'][$topic][] = $_REQUEST['msg']; } } // Make sure the selection is still accurate. if (!empty($_SESSION['split_selection'][$topic])) { $_SESSION['split_selection'][$topic] = messageAt(0, $topic, array('include' => empty($_SESSION['split_selection'][$topic]) ? array() : $_SESSION['split_selection'][$topic], 'only_approved' => !$modSettings['postmod_active'] || !allowedTo('approve_posts'), 'limit' => false)); $selection = $_SESSION['split_selection'][$topic]; } else { $selection = array(); } // Get the number of messages (not) selected to be split. $split_counts = countSplitMessages($topic, !$modSettings['postmod_active'] || allowedTo('approve_posts'), $selection); foreach ($split_counts as $key => $num_messages) { $context[$key]['num_messages'] = $num_messages; } // Fix an oversized starting page (to make sure both pageindexes are properly set). if ($context['selected']['start'] >= $context['selected']['num_messages']) { $context['selected']['start'] = $context['selected']['num_messages'] <= $context['messages_per_page'] ? 0 : $context['selected']['num_messages'] - ($context['selected']['num_messages'] % $context['messages_per_page'] == 0 ? $context['messages_per_page'] : $context['selected']['num_messages'] % $context['messages_per_page']); } $page_index_url = $scripturl . '?action=splittopics;sa=selectTopics;subname=' . strtr(urlencode($_SESSION['new_topic_subject']), array('%' => '%%')) . ';topic=' . $topic; // Build a page list of the not-selected topics... $context['not_selected']['page_index'] = constructPageIndex($page_index_url . '.%1$d;start2=' . $context['selected']['start'], $context['not_selected']['start'], $context['not_selected']['num_messages'], $context['messages_per_page'], true); // ...and one of the selected topics. $context['selected']['page_index'] = constructPageIndex($page_index_url . '.' . $context['not_selected']['start'] . ';start2=%1$d', $context['selected']['start'], $context['selected']['num_messages'], $context['messages_per_page'], true); // Retrieve the unselected messages. $context['not_selected']['messages'] = selectMessages($topic, $context['not_selected']['start'], $context['messages_per_page'], empty($_SESSION['split_selection'][$topic]) ? array() : array('excluded' => $_SESSION['split_selection'][$topic]), $modSettings['postmod_active'] && !allowedTo('approve_posts')); // Now retrieve the selected messages. if (!empty($_SESSION['split_selection'][$topic])) { $context['selected']['messages'] = selectMessages($topic, $context['selected']['start'], $context['messages_per_page'], array('included' => $_SESSION['split_selection'][$topic]), $modSettings['postmod_active'] && !allowedTo('approve_posts')); } // The XMLhttp method only needs the stuff that changed, so let's compare. if (isset($_REQUEST['xml'])) { $changes = array('remove' => array('not_selected' => array_diff($original_msgs['not_selected'], array_keys($context['not_selected']['messages'])), 'selected' => array_diff($original_msgs['selected'], array_keys($context['selected']['messages']))), 'insert' => array('not_selected' => array_diff(array_keys($context['not_selected']['messages']), $original_msgs['not_selected']), 'selected' => array_diff(array_keys($context['selected']['messages']), $original_msgs['selected']))); $context['changes'] = array(); foreach ($changes as $change_type => $change_array) { foreach ($change_array as $section => $msg_array) { if (empty($msg_array)) { continue; } foreach ($msg_array as $id_msg) { $context['changes'][$change_type . $id_msg] = array('id' => $id_msg, 'type' => $change_type, 'section' => $section); if ($change_type == 'insert') { $context['changes']['insert' . $id_msg]['insert_value'] = $context[$section]['messages'][$id_msg]; } } } } } }
/** * Mark a single topic as unread. * Accessed by action=markasread;sa=topic */ public function action_marktopic() { global $board, $topic, $user_info; require_once SUBSDIR . '/Topic.subs.php'; require_once SUBSDIR . '/Messages.subs.php'; // Mark a topic unread. // First, let's figure out what the latest message is. $topicinfo = getTopicInfo($topic, 'all'); $topic_msg_id = (int) $_GET['t']; if (!empty($topic_msg_id)) { // If they read the whole topic, go back to the beginning. if ($topic_msg_id >= $topicinfo['id_last_msg']) { $earlyMsg = 0; } elseif ($topic_msg_id <= $topicinfo['id_first_msg']) { $earlyMsg = 0; } else { $earlyMsg = previousMessage($topic_msg_id, $topic); } } elseif ($_REQUEST['start'] == 0) { $earlyMsg = 0; } else { list($earlyMsg) = messageAt((int) $_REQUEST['start'], $topic); $earlyMsg--; } // Blam, unread! markTopicsRead(array($user_info['id'], $topic, $earlyMsg, $topicinfo['unwatched']), true); return 'board=' . $board . '.0'; }