/** * Merge selected posts into selected topic */ function merge_posts($topic_id, $to_topic_id) { global $db, $template, $user, $phpEx, $src_root_path, $auth; if (!$to_topic_id) { $template->assign_var('MESSAGE', $user->lang['NO_FINAL_TOPIC_SELECTED']); return; } $sync_topics = array($topic_id, $to_topic_id); $topic_data = src_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_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 (!src_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, false); 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 ' . POSTS_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("{$src_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&t=' . $topic_id) . '">', '</a>'); } else { if (!function_exists('src_update_rows_avoiding_duplicates_notify_status')) { include $src_root_path . 'includes/functions_database_helper.' . $phpEx; } // If the topic no longer exist, we will update the topic watch table. src_update_rows_avoiding_duplicates_notify_status($db, TOPICS_WATCH_TABLE, 'topic_id', array($topic_id), $to_topic_id); // If the topic no longer exist, we will update the bookmarks table. src_update_rows_avoiding_duplicates($db, BOOKMARKS_TABLE, 'topic_id', array($topic_id), $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("{$src_root_path}viewtopic.{$phpEx}", 'f=' . $to_forum_id . '&t=' . $to_topic_id) . '">', '</a>'); $redirect = request_var('redirect', "{$src_root_path}viewtopic.{$phpEx}?f={$to_forum_id}&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_POSTS', $s_hidden_fields); } }
if ($topic_id) { $sql = 'SELECT forum_id FROM ' . TOPICS_TABLE . "\n\t\tWHERE topic_id = {$topic_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $forum_id = (int) $row['forum_id']; } } // If the user doesn't have any moderator powers (globally or locally) he can't access the mcp if (!$auth->acl_getf_global('m_')) { // Except he is using one of the quickmod tools for users $user_quickmod_actions = array('lock' => 'f_user_lock', 'make_sticky' => 'f_sticky', 'make_announce' => 'f_announce', 'make_global' => 'f_announce', 'make_normal' => array('f_announce', 'f_sticky')); $allow_user = false; if ($quickmod && isset($user_quickmod_actions[$action]) && $user->data['is_registered'] && $auth->acl_gets($user_quickmod_actions[$action], $forum_id)) { $topic_info = src_get_topic_data(array($topic_id)); if ($topic_info[$topic_id]['topic_poster'] == $user->data['user_id']) { $allow_user = true; } } if (!$allow_user) { trigger_error('NOT_AUTHORISED'); } } // if the user cannot read the forum he tries to access then we won't allow mcp access either if ($forum_id && !$auth->acl_get('f_read', $forum_id)) { trigger_error('NOT_AUTHORISED'); } /** * Allow applying additional permissions to MCP access besides f_read *
/** * Fork Topic */ function mcp_fork_topic($topic_ids) { global $auth, $user, $db, $template, $config; global $phpEx, $src_root_path, $src_dispatcher; if (!src_check_ids($topic_ids, TOPICS_TABLE, 'topic_id', array('m_'))) { return; } $to_forum_id = request_var('to_forum_id', 0); $forum_id = request_var('f', 0); $redirect = request_var('redirect', build_url(array('action', 'quickmod'))); $additional_msg = $success_msg = ''; $counter = array(); $s_hidden_fields = build_hidden_fields(array('topic_id_list' => $topic_ids, 'f' => $forum_id, 'action' => 'fork', 'redirect' => $redirect)); if ($to_forum_id) { $forum_data = src_get_forum_data($to_forum_id, 'f_post'); if (!sizeof($topic_ids)) { $additional_msg = $user->lang['NO_TOPIC_SELECTED']; } else { if (!sizeof($forum_data)) { $additional_msg = $user->lang['FORUM_NOT_EXIST']; } else { $forum_data = $forum_data[$to_forum_id]; if ($forum_data['forum_type'] != FORUM_POST) { $additional_msg = $user->lang['FORUM_NOT_POSTABLE']; } else { if (!$auth->acl_get('f_post', $to_forum_id)) { $additional_msg = $user->lang['USER_CANNOT_POST']; } } } } } else { if (isset($_POST['confirm'])) { $additional_msg = $user->lang['FORUM_NOT_EXIST']; } } if ($additional_msg) { $request->overwrite('confirm', null, \src\request\request_interface::POST); $request->overwrite('confirm_key', null); } if (confirm_box(true)) { $topic_data = src_get_topic_data($topic_ids, 'f_post'); $total_topics = $total_topics_unapproved = $total_topics_softdeleted = 0; $total_posts = $total_posts_unapproved = $total_posts_softdeleted = 0; $new_topic_id_list = array(); foreach ($topic_data as $topic_id => $topic_row) { if (!isset($search_type) && $topic_row['enable_indexing']) { // Select the search method and do some additional checks to ensure it can actually be utilised $search_type = $config['search_type']; if (!class_exists($search_type)) { trigger_error('NO_SUCH_SEARCH_MODULE'); } $error = false; $search = new $search_type($error, $src_root_path, $phpEx, $auth, $config, $db, $user, $src_dispatcher); $search_mode = 'post'; if ($error) { trigger_error($error); } } else { if (!isset($search_type) && !$topic_row['enable_indexing']) { $search_type = false; } } $sql_ary = array('forum_id' => (int) $to_forum_id, 'icon_id' => (int) $topic_row['icon_id'], 'topic_attachment' => (int) $topic_row['topic_attachment'], 'topic_visibility' => (int) $topic_row['topic_visibility'], 'topic_reported' => 0, 'topic_title' => (string) $topic_row['topic_title'], 'topic_poster' => (int) $topic_row['topic_poster'], 'topic_time' => (int) $topic_row['topic_time'], 'topic_posts_approved' => (int) $topic_row['topic_posts_approved'], 'topic_posts_unapproved' => (int) $topic_row['topic_posts_unapproved'], 'topic_posts_softdeleted' => (int) $topic_row['topic_posts_softdeleted'], 'topic_status' => (int) $topic_row['topic_status'], 'topic_type' => (int) $topic_row['topic_type'], 'topic_first_poster_name' => (string) $topic_row['topic_first_poster_name'], 'topic_last_poster_id' => (int) $topic_row['topic_last_poster_id'], 'topic_last_poster_name' => (string) $topic_row['topic_last_poster_name'], 'topic_last_post_time' => (int) $topic_row['topic_last_post_time'], 'topic_last_view_time' => (int) $topic_row['topic_last_view_time'], 'topic_bumped' => (int) $topic_row['topic_bumped'], 'topic_bumper' => (int) $topic_row['topic_bumper'], 'poll_title' => (string) $topic_row['poll_title'], 'poll_start' => (int) $topic_row['poll_start'], 'poll_length' => (int) $topic_row['poll_length'], 'poll_max_options' => (int) $topic_row['poll_max_options'], 'poll_vote_change' => (int) $topic_row['poll_vote_change']); $db->sql_query('INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_topic_id = $db->sql_nextid(); $new_topic_id_list[$topic_id] = $new_topic_id; switch ($topic_row['topic_visibility']) { case ITEM_APPROVED: $total_topics++; break; case ITEM_UNAPPROVED: case ITEM_REAPPROVE: $total_topics_unapproved++; break; case ITEM_DELETED: $total_topics_softdeleted++; break; } if ($topic_row['poll_start']) { $poll_rows = array(); $sql = 'SELECT * FROM ' . POLL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE topic_id = {$topic_id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $sql_ary = array('poll_option_id' => (int) $row['poll_option_id'], 'topic_id' => (int) $new_topic_id, 'poll_option_text' => (string) $row['poll_option_text'], 'poll_option_total' => 0); $db->sql_query('INSERT INTO ' . POLL_OPTIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); } $db->sql_freeresult($result); } $sql = 'SELECT * FROM ' . POSTS_TABLE . "\n\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\tORDER BY post_time ASC, post_id ASC"; $result = $db->sql_query($sql); $post_rows = array(); while ($row = $db->sql_fetchrow($result)) { $post_rows[] = $row; } $db->sql_freeresult($result); if (!sizeof($post_rows)) { continue; } foreach ($post_rows as $row) { $sql_ary = array('topic_id' => (int) $new_topic_id, 'forum_id' => (int) $to_forum_id, 'poster_id' => (int) $row['poster_id'], 'icon_id' => (int) $row['icon_id'], 'poster_ip' => (string) $row['poster_ip'], 'post_time' => (int) $row['post_time'], 'post_visibility' => (int) $row['post_visibility'], 'post_reported' => 0, 'enable_bbcode' => (int) $row['enable_bbcode'], 'enable_smilies' => (int) $row['enable_smilies'], 'enable_magic_url' => (int) $row['enable_magic_url'], 'enable_sig' => (int) $row['enable_sig'], 'post_username' => (string) $row['post_username'], 'post_subject' => (string) $row['post_subject'], 'post_text' => (string) $row['post_text'], 'post_edit_reason' => (string) $row['post_edit_reason'], 'post_edit_user' => (int) $row['post_edit_user'], 'post_checksum' => (string) $row['post_checksum'], 'post_attachment' => (int) $row['post_attachment'], 'bbcode_bitfield' => $row['bbcode_bitfield'], 'bbcode_uid' => (string) $row['bbcode_uid'], 'post_edit_time' => (int) $row['post_edit_time'], 'post_edit_count' => (int) $row['post_edit_count'], 'post_edit_locked' => (int) $row['post_edit_locked'], 'post_postcount' => $row['post_postcount']); // Adjust post count only if the post can be incremented to the user counter if ($row['post_postcount']) { if (isset($counter[$row['poster_id']])) { ++$counter[$row['poster_id']]; } else { $counter[$row['poster_id']] = 1; } } $db->sql_query('INSERT INTO ' . POSTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary)); $new_post_id = $db->sql_nextid(); switch ($row['post_visibility']) { case ITEM_APPROVED: $total_posts++; break; case ITEM_UNAPPROVED: case ITEM_REAPPROVE: $total_posts_unapproved++; break; case ITEM_DELETED: $total_posts_softdeleted++; break; } // Copy whether the topic is dotted markread('post', $to_forum_id, $new_topic_id, 0, $row['poster_id']); if (!empty($search_type)) { $search->index($search_mode, $new_post_id, $sql_ary['post_text'], $sql_ary['post_subject'], $sql_ary['poster_id'], $topic_row['topic_type'] == POST_GLOBAL ? 0 : $to_forum_id); $search_mode = 'reply'; // After one we index replies } // Copy Attachments if ($row['post_attachment']) { $sql = 'SELECT * FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\tWHERE post_msg_id = {$row['post_id']}\n\t\t\t\t\t\t\tAND topic_id = {$topic_id}\n\t\t\t\t\t\t\tAND in_message = 0"; $result = $db->sql_query($sql); $sql_ary = array(); while ($attach_row = $db->sql_fetchrow($result)) { $sql_ary[] = array('post_msg_id' => (int) $new_post_id, 'topic_id' => (int) $new_topic_id, 'in_message' => 0, 'is_orphan' => (int) $attach_row['is_orphan'], 'poster_id' => (int) $attach_row['poster_id'], 'physical_filename' => (string) utf8_basename($attach_row['physical_filename']), 'real_filename' => (string) utf8_basename($attach_row['real_filename']), 'download_count' => (int) $attach_row['download_count'], 'attach_comment' => (string) $attach_row['attach_comment'], 'extension' => (string) $attach_row['extension'], 'mimetype' => (string) $attach_row['mimetype'], 'filesize' => (int) $attach_row['filesize'], 'filetime' => (int) $attach_row['filetime'], 'thumbnail' => (int) $attach_row['thumbnail']); } $db->sql_freeresult($result); if (sizeof($sql_ary)) { $db->sql_multi_insert(ATTACHMENTS_TABLE, $sql_ary); } } } // Copy topic subscriptions to new topic $sql = 'SELECT user_id, notify_status FROM ' . TOPICS_WATCH_TABLE . ' WHERE topic_id = ' . $topic_id; $result = $db->sql_query($sql); $sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $sql_ary[] = array('topic_id' => (int) $new_topic_id, 'user_id' => (int) $row['user_id'], 'notify_status' => (int) $row['notify_status']); } $db->sql_freeresult($result); if (sizeof($sql_ary)) { $db->sql_multi_insert(TOPICS_WATCH_TABLE, $sql_ary); } // Copy bookmarks to new topic $sql = 'SELECT user_id FROM ' . BOOKMARKS_TABLE . ' WHERE topic_id = ' . $topic_id; $result = $db->sql_query($sql); $sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $sql_ary[] = array('topic_id' => (int) $new_topic_id, 'user_id' => (int) $row['user_id']); } $db->sql_freeresult($result); if (sizeof($sql_ary)) { $db->sql_multi_insert(BOOKMARKS_TABLE, $sql_ary); } } // Sync new topics, parent forums and srcrd stats $sql = 'UPDATE ' . FORUMS_TABLE . ' SET forum_posts_approved = forum_posts_approved + ' . $total_posts . ', forum_posts_unapproved = forum_posts_unapproved + ' . $total_posts_unapproved . ', forum_posts_softdeleted = forum_posts_softdeleted + ' . $total_posts_softdeleted . ', forum_topics_approved = forum_topics_approved + ' . $total_topics . ', forum_topics_unapproved = forum_topics_unapproved + ' . $total_topics_unapproved . ', forum_topics_softdeleted = forum_topics_softdeleted + ' . $total_topics_softdeleted . ' WHERE forum_id = ' . $to_forum_id; $db->sql_query($sql); if (!empty($counter)) { // Do only one query per user and not a query per post. foreach ($counter as $user_id => $count) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts + ' . (int) $count . ' WHERE user_id = ' . (int) $user_id; $db->sql_query($sql); } } sync('topic', 'topic_id', $new_topic_id_list); sync('forum', 'forum_id', $to_forum_id); set_config_count('num_topics', sizeof($new_topic_id_list), true); set_config_count('num_posts', $total_posts, true); foreach ($new_topic_id_list as $topic_id => $new_topic_id) { add_log('mod', $to_forum_id, $new_topic_id, 'LOG_FORK', $topic_row['forum_name']); } $success_msg = sizeof($topic_ids) == 1 ? 'TOPIC_FORKED_SUCCESS' : 'TOPICS_FORKED_SUCCESS'; } else { $template->assign_vars(array('S_FORUM_SELECT' => make_forum_select($to_forum_id, false, false, true, true, true), 'S_CAN_LEAVE_SHADOW' => false, 'ADDITIONAL_MSG' => $additional_msg)); confirm_box(false, 'FORK_TOPIC' . (sizeof($topic_ids) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_move.html'); } $redirect = request_var('redirect', "index.{$phpEx}"); $redirect = reapply_sid($redirect); if (!$success_msg) { redirect($redirect); } else { $redirect_url = append_sid("{$src_root_path}viewforum.{$phpEx}", 'f=' . $forum_id); meta_refresh(3, $redirect_url); $return_link = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect_url . '">', '</a>'); if ($forum_id != $to_forum_id) { $return_link .= '<br /><br />' . sprintf($user->lang['RETURN_NEW_FORUM'], '<a href="' . append_sid("{$src_root_path}viewforum.{$phpEx}", 'f=' . $to_forum_id) . '">', '</a>'); } trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_link); } }
/** * Approve/Restore topics * * @param $action string Action we perform on the posts ('approve' or 'restore') * @param $topic_id_list array IDs of the topics to approve/restore * @param $id mixed Category of the current active module * @param $mode string Active module * @return null */ public static function approve_topics($action, $topic_id_list, $id, $mode) { global $db, $template, $user, $config; global $phpEx, $src_root_path, $request, $src_container, $src_dispatcher; if (!src_check_ids($topic_id_list, TOPICS_TABLE, 'topic_id', array('m_approve'))) { trigger_error('NOT_AUTHORISED'); } $redirect = $request->variable('redirect', build_url(array('quickmod'))); $redirect = reapply_sid($redirect); $success_msg = $topic_url = ''; $approve_log = array(); $s_hidden_fields = build_hidden_fields(array('i' => $id, 'mode' => $mode, 'topic_id_list' => $topic_id_list, 'action' => $action, 'redirect' => $redirect)); $topic_info = src_get_topic_data($topic_id_list, 'm_approve'); if (confirm_box(true)) { $notify_poster = $action == 'approve' && isset($_REQUEST['notify_poster']) ? true : false; $src_content_visibility = $src_container->get('content.visibility'); $first_post_ids = array(); foreach ($topic_info as $topic_id => $topic_data) { $src_content_visibility->set_topic_visibility(ITEM_APPROVED, $topic_id, $topic_data['forum_id'], $user->data['user_id'], time(), ''); $first_post_ids[$topic_id] = (int) $topic_data['topic_first_post_id']; $topic_url = append_sid("{$src_root_path}viewtopic.{$phpEx}", "f={$topic_data['forum_id']}&t={$topic_id}"); $approve_log[] = array('forum_id' => $topic_data['forum_id'], 'topic_id' => $topic_data['topic_id'], 'topic_title' => $topic_data['topic_title']); } if (sizeof($topic_info) >= 1) { $success_msg = sizeof($topic_info) == 1 ? 'TOPIC_' . strtoupper($action) . 'D_SUCCESS' : 'TOPICS_' . strtoupper($action) . 'D_SUCCESS'; } foreach ($approve_log as $log_data) { add_log('mod', $log_data['forum_id'], $log_data['topic_id'], 'LOG_TOPIC_' . strtoupper($action) . 'D', $log_data['topic_title']); } // Only send out the mails, when the posts are being approved if ($action == 'approve') { // Grab the first post text as it's needed for the quote notification. $sql = 'SELECT topic_id, post_text FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('post_id', $first_post_ids); $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $topic_info[$row['topic_id']]['post_text'] = $row['post_text']; } $db->sql_freeresult($result); // Handle notifications $src_notifications = $src_container->get('notification_manager'); foreach ($topic_info as $topic_id => $topic_data) { $topic_data = array_merge($topic_data, array('post_id' => $topic_data['topic_first_post_id'], 'post_subject' => $topic_data['topic_title'], 'post_time' => $topic_data['topic_time'], 'poster_id' => $topic_data['topic_poster'], 'post_username' => $topic_data['topic_first_poster_name'])); $src_notifications->delete_notifications('notification.type.topic_in_queue', $topic_id); // Only add notifications, if we are not reapproving post // When the topic was already approved, but was edited and // now needs re-approval, we don't want to notify the users // again. if ($topic_data['topic_visibility'] == ITEM_UNAPPROVED) { $src_notifications->add_notifications(array('notification.type.quote', 'notification.type.topic'), $topic_data); } $src_notifications->mark_notifications_read('notification.type.quote', $topic_data['post_id'], $user->data['user_id']); $src_notifications->mark_notifications_read('notification.type.topic', $topic_id, $user->data['user_id']); if ($notify_poster) { $src_notifications->add_notifications('notification.type.approve_topic', $topic_data); } } } /** * Perform additional actions during topics(s) approval * * @event core.approve_topics_after * @var string action Variable containing the action we perform on the posts ('approve' or 'restore') * @var mixed topic_info Array containing info for all topics being approved * @var array first_post_ids Array containing ids of all first posts * @var bool notify_poster Variable telling if the poster should be notified or not * @var string success_msg Variable containing the language key for the success message * @var string redirect Variable containing the redirect url * @since 3.1.4-RC1 */ $vars = array('action', 'topic_info', 'first_post_ids', 'notify_poster', 'success_msg', 'redirect'); extract($src_dispatcher->trigger_event('core.approve_topics_after', compact($vars))); meta_refresh(3, $redirect); $message = $user->lang[$success_msg]; if ($request->is_ajax()) { $json_response = new \src\json_response(); $json_response->send(array('MESSAGE_TITLE' => $user->lang['INFORMATION'], 'MESSAGE_TEXT' => $message, 'REFRESH_DATA' => null, 'visible' => true)); } $message .= '<br /><br />' . $user->lang('RETURN_PAGE', '<a href="' . $redirect . '">', '</a>'); // If approving one topic, also give links back to topic... if (sizeof($topic_info) == 1 && $topic_url) { $message .= '<br /><br />' . $user->lang('RETURN_TOPIC', '<a href="' . $topic_url . '">', '</a>'); } trigger_error($message); } else { $show_notify = false; if ($action == 'approve') { foreach ($topic_info as $topic_data) { if ($topic_data['topic_poster'] == ANONYMOUS) { continue; } else { $show_notify = true; break; } } } $template->assign_vars(array('S_NOTIFY_POSTER' => $show_notify, 'S_' . strtoupper($action) => true)); confirm_box(false, strtoupper($action) . '_TOPIC' . (sizeof($topic_id_list) == 1 ? '' : 'S'), $s_hidden_fields, 'mcp_approve.html'); } redirect($redirect); }