/** * Delete a forum poll. * * @param AUTO_LINK The ID of the poll we're deleting. * @param LONG_TEXT The reason for deleting the poll. * @return AUTO_LINK The ID of the topic the poll is on. */ function ocf_delete_poll($poll_id, $reason) { require_code('ocf_polls'); $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('*'), array('t_poll_id' => $poll_id), '', 1); if (!ocf_may_delete_poll_by($topic_info[0]['t_forum_id'], $topic_info[0]['t_cache_first_member_id'])) { access_denied('I_ERROR'); } $topic_id = $topic_info[0]['id']; $name = $GLOBALS['FORUM_DB']->query_value('f_polls', 'po_question', array('id' => $poll_id)); $GLOBALS['FORUM_DB']->query_delete('f_polls', array('id' => $poll_id), '', 1); $GLOBALS['FORUM_DB']->query_delete('f_poll_answers', array('pa_poll_id' => $poll_id)); $GLOBALS['FORUM_DB']->query_delete('f_poll_votes', array('pv_poll_id' => $poll_id)); $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_poll_id' => NULL), array('t_poll_id' => $poll_id), '', 1); require_code('ocf_general_action2'); ocf_mod_log_it('DELETE_TOPIC_POLL', strval($poll_id), $name, $reason); return $topic_id; }
/** * Delete a topic. * * @param AUTO_LINK The ID of the topic to delete. * @param LONG_TEXT The reason for this action . * @param ?AUTO_LINK Where topic to move posts in this topic to (NULL: delete the posts). * @return AUTO_LINK The forum ID the topic is in (could be found without calling the function, but as we've looked it up, it is worth keeping). */ function ocf_delete_topic($topic_id, $reason = '', $post_target_topic_id = NULL) { // Info about source $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_pt_to', 't_pt_from', 't_cache_first_title', 't_cache_first_member_id', 't_poll_id', 't_forum_id', 't_cache_num_posts', 't_validated'), array('id' => $topic_id)); if (!array_key_exists(0, $info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $name = $info[0]['t_cache_first_title']; $poll_id = $info[0]['t_poll_id']; $forum_id = $info[0]['t_forum_id']; $num_posts = $info[0]['t_cache_num_posts']; $validated = $info[0]['t_validated']; if (!ocf_may_delete_topics_by($forum_id, get_member(), $info[0]['t_cache_first_member_id']) || !is_null($info[0]['t_pt_from']) && $info[0]['t_pt_from'] != get_member() && (!is_null($info[0]['t_pt_to']) && $info[0]['t_pt_to'] != get_member()) && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($forum_id)) { access_denied('I_ERROR'); } if (!is_null($post_target_topic_id)) { $to = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 't_forum_id', array('id' => $post_target_topic_id)); if (is_null($to)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } } if (!is_null($forum_id)) { // Update member post counts if we've switched between post-count countable forums $post_count_info = $GLOBALS['FORUM_DB']->query('SELECT id,f_post_count_increment FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval((int) $forum_id) . (!is_null($post_target_topic_id) ? ' OR id=' . strval((int) $to) : ''), 2); if ($post_count_info[0]['id'] == $forum_id) { $from_cnt = $post_count_info[0]['f_post_count_increment']; $to_cnt = array_key_exists(1, $post_count_info) ? $post_count_info[1]['f_post_count_increment'] : 0; } else { $from_cnt = $post_count_info[1]['f_post_count_increment']; $to_cnt = $post_count_info[0]['f_post_count_increment']; } require_code('ocf_posts_action'); if ($from_cnt != $to_cnt) { $sql = 'SELECT p_poster FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_topic_id=' . strval((int) $topic_id); if (addon_installed('unvalidated')) { $sql .= ' AND p_validated=1'; } $_member_post_counts = collapse_1d_complexity('p_poster', $GLOBALS['FORUM_DB']->query($sql)); $member_post_counts = array_count_values($_member_post_counts); foreach ($member_post_counts as $member_id => $member_post_count) { if ($to_cnt == 0) { $member_post_count = -$member_post_count; } ocf_force_update_member_post_count($member_id, $member_post_count); } } } // What to do with our posts if (!is_null($post_target_topic_id)) { $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to, 'p_topic_id' => $post_target_topic_id), array('p_topic_id' => $topic_id)); require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($post_target_topic_id); if (!is_null($forum_id)) { ocf_force_update_forum_cacheing($forum_id, $to, 1, $num_posts); } } else { $_postdetails = $GLOBALS['FORUM_DB']->query('SELECT p_post FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_topic_id=' . strval((int) $topic_id)); foreach ($_postdetails as $post) { delete_lang($post['p_post'], $GLOBALS['FORUM_DB']); } $GLOBALS['FORUM_DB']->query_delete('f_posts', array('p_topic_id' => $topic_id)); } // Delete stuff if (!is_null($poll_id)) { require_code('ocf_polls_action'); require_code('ocf_polls_action2'); ocf_delete_poll($poll_id, ''); } $GLOBALS['FORUM_DB']->query_delete('f_topics', array('id' => $topic_id), '', 1); $GLOBALS['FORUM_DB']->query_delete('f_read_logs', array('l_topic_id' => $topic_id)); require_code('notifications'); delete_all_notifications_on('ocf_topics', strval($topic_id)); // Delete the ticket row if it's a ticket if (addon_installed('tickets')) { require_code('tickets'); if (!is_null($forum_id) && is_ticket_forum($forum_id)) { require_code('tickets2'); delete_ticket_by_topic_id($topic_id); } } // Update forum view cacheing if (!is_null($forum_id)) { require_code('ocf_posts_action2'); ocf_force_update_forum_cacheing($forum_id, $validated == 0 ? 0 : -1, -$num_posts); } require_code('ocf_general_action2'); ocf_mod_log_it('DELETE_TOPIC', strval($topic_id), $name, $reason); if (!is_null($forum_id)) { require_code('ocf_posts_action'); ocf_decache_ocp_blocks($forum_id); } else { decache('side_ocf_personal_topics'); decache('_new_pp'); } return $forum_id; }
/** * Standard import function. * * @param object The DB connection to import from * @param string The table prefix the target prefix is using * @param PATH The base directory we are importing from */ function import_logs($db, $table_prefix, $file_base) { require_code('ocf_general_action2'); $rows = $db->query('SELECT * FROM ' . $table_prefix . 'editlog'); foreach ($rows as $row) { if (import_check_if_imported('editlog', strval($row['postid']))) { continue; } ocf_mod_log_it('EDIT_POST', strval(import_id_remap_get('post', strval($row['postid']), true)), '', $row['reason'], $row['userid'], $row['dateline']); import_id_remap_put('editlog', strval($row['postid']), -1); } $rows = $db->query('SELECT * FROM ' . $table_prefix . 'deletionlog'); foreach ($rows as $row) { if (import_check_if_imported('deletionlog', strval($row['primaryid']))) { continue; } if ($row['type'] == 'post') { ocf_mod_log_it('DELETE_POST', '', '', $row['reason'], $row['userid']); } elseif ($row['type'] == 'thread') { ocf_mod_log_it('DELETE_TOPIC', '', '', $row['reason'], $row['userid']); } import_id_remap_put('deletionlog', strval($row['primaryid']), -1); } /* moderatorlog Closed Closed Thread Opened Thread Post * by * Removed Post * Edited Stuck Stuck Thread Thread edited. (visible: ?; open: ?; sticky: ?) Thread moved to '*'. Thread Removed adminlog */ }
/** * Perform a multi moderation. * * @param AUTO_LINK The ID of the multi moderation we are performing. * @param AUTO_LINK The ID of the topic we are performing the multi moderation on. * @param LONG_TEXT The reason for performing the multi moderation (may be blank). * @param LONG_TEXT The post text for a post to be added to the topic (blank: do not add a post). * @param BINARY Whether the post is marked emphasised. * @param BINARY Whether to skip showing the posters signature in the post. */ function ocf_perform_multi_moderation($id, $topic_id, $reason, $post_text = '', $is_emphasised = 1, $skip_sig = 0) { $topic_details = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_cache_first_title', 't_cache_first_post_id'), array('id' => $topic_id), '', 1); if (!array_key_exists(0, $topic_details)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $from = $topic_details[0]['t_forum_id']; if (!ocf_may_perform_multi_moderation($from)) { access_denied('I_ERROR'); } $mm = $GLOBALS['FORUM_DB']->query_select('f_multi_moderations', array('*'), array('id' => $id)); if (!array_key_exists(0, $mm)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } require_code('ocfiltering'); $idlist = ocfilter_to_idlist_using_db($mm[0]['mm_forum_multi_code'], 'id', 'f_forums', 'f_forums', 'f_parent_forum', 'f_parent_forum', 'id', true, true, $GLOBALS['FORUM_DB']); if (!in_array($from, $idlist)) { warn_exit(do_lang_tempcode('MM_APPLY_TWICE')); } $pin_state = $mm[0]['mm_pin_state']; $open_state = $mm[0]['mm_open_state']; $sink_state = $mm[0]['mm_sink_state']; $move_to = $mm[0]['mm_move_to']; $title_suffix = $mm[0]['mm_title_suffix']; //$post_text=$mm[0]['mm_post_text']; We'll allow user to specify the post_text, with this as a default $update_array = array(); if (!is_null($pin_state)) { $update_array['t_pinned'] = $pin_state; } if (!is_null($sink_state)) { $update_array['t_sunk'] = $sink_state; } if (!is_null($open_state)) { $update_array['t_is_open'] = $open_state; } if ($title_suffix != '') { $new_title = $topic_details[0]['t_cache_first_title'] . ' [' . $title_suffix . ']'; $update_array['t_cache_first_title'] = $new_title; $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_title' => $new_title), array('id' => $topic_details[0]['t_cache_first_post_id']), '', 1); } if (count($update_array) != 0) { $GLOBALS['FORUM_DB']->query_update('f_topics', $update_array, array('id' => $topic_id), '', 1); } if (!is_null($move_to)) { require_code('ocf_topics_action'); require_code('ocf_topics_action2'); ocf_move_topics($from, $move_to, array($topic_id)); } if ($post_text != '') { require_code('ocf_posts_action'); require_code('ocf_posts_action2'); require_code('ocf_topics_action'); require_code('ocf_topics_action2'); ocf_make_post($topic_id, '', $post_text, $skip_sig, false, 1, $is_emphasised); $forum_id = is_null($move_to) ? $from : $move_to; handle_topic_ticket_reply($forum_id, $topic_id, $topic_details[0]['t_cache_first_title'], $post_text); } require_code('ocf_general_action2'); ocf_mod_log_it('PERFORM_MULTI_MODERATION', strval($id), strval($topic_id), $reason); }
/** * Move posts from one topic to another. * * @param AUTO_LINK The ID of the source topic. * @param AUTO_LINK The ID of the destination topic. * @param array A list of post IDs to move. * @param LONG_TEXT The reason for this action. * @param ?AUTO_LINK The forum the destination topic is in (NULL: find from DB). * @param boolean Whether to delete the topic if all posts in it have been moved. * @param ?SHORT_TEXT The title for the new topic (NULL: work out / irrelevant). * @return boolean Whether the topic was deleted. */ function ocf_move_posts($from_topic_id, $to_topic_id, $posts, $reason, $to_forum_id = NULL, $delete_if_empty = false, $title = NULL) { if (is_null($to_topic_id)) { if (is_null($to_forum_id)) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } require_code('ocf_topics_action'); $to_topic_id = ocf_make_topic($to_forum_id); if (!is_null($title) && count($posts) != 0) { $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_title' => $title), array('id' => $posts[0]), '', 1); } } // Info about source $from_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id'), array('id' => $from_topic_id)); if (!array_key_exists(0, $from_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $from_forum_id = $from_info[0]['t_forum_id']; $to_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id'), array('id' => $to_topic_id)); if (!array_key_exists(0, $to_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $to_forum_id = $to_info[0]['t_forum_id']; $or_list = ''; foreach ($posts as $post) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'id=' . strval((int) $post); } // Check access if (!ocf_may_moderate_forum($from_forum_id)) { access_denied('I_ERROR'); } $_postdetails = $GLOBALS['FORUM_DB']->query('SELECT p_cache_forum_id,p_intended_solely_for,p_validated FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE ' . $or_list); $num_posts_counted = 0; foreach ($_postdetails as $post) { if (is_null($post['p_intended_solely_for']) && $post['p_validated'] == 1) { $num_posts_counted++; } if ($post['p_cache_forum_id'] != $from_forum_id) { fatal_exit(do_lang_tempcode('INTERNAL_ERROR')); } } $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . strval((int) $to_forum_id) . ', p_topic_id=' . strval((int) $to_topic_id) . ' WHERE ' . $or_list); // Update cacheing require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($from_topic_id, -$num_posts_counted, true, true); ocf_force_update_topic_cacheing($to_topic_id, $num_posts_counted, true, true); if (!is_null($from_forum_id) && !is_null($to_topic_id) && $from_forum_id != $to_topic_id) { if ($from_forum_id != $to_forum_id) { require_code('ocf_forums_action2'); ocf_force_update_forum_cacheing($from_forum_id, 0, -$num_posts_counted); ocf_force_update_forum_cacheing($to_forum_id, 0, $num_posts_counted); // Update member post counts if we've switched between post-count countable forums $post_count_info = $GLOBALS['FORUM_DB']->query('SELECT id,f_post_count_increment FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums WHERE id=' . strval((int) $from_forum_id) . ' OR id=' . strval((int) $to_forum_id), 2); if ($post_count_info[0]['id'] == $from_forum_id) { $from = $post_count_info[0]['f_post_count_increment']; $to = $post_count_info[1]['f_post_count_increment']; } else { $from = $post_count_info[1]['f_post_count_increment']; $to = $post_count_info[0]['f_post_count_increment']; } if ($from != $to) { $sql = 'SELECT p_poster FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE (' . $or_list . ')'; if (addon_installed('unvalidated')) { $sql .= ' AND p_validated=1'; } $_member_post_counts = collapse_1d_complexity('p_poster', $GLOBALS['FORUM_DB']->query($sql)); $member_post_counts = array_count_values($_member_post_counts); foreach ($member_post_counts as $member_id => $member_post_count) { if ($to == 0) { $member_post_count = -$member_post_count; } ocf_force_update_member_post_count($member_id, $member_post_count); } } } } $test = $delete_if_empty ? $GLOBALS['FORUM_DB']->query_value('f_posts', 'COUNT(*)', array('p_topic_id' => $from_topic_id)) : 1; if ($test == 0) { $num_view_count = 0; $num_view_count += $GLOBALS['FORUM_DB']->query_value('f_topics', 't_num_views', array('id' => $from_topic_id)); $num_view_count += $GLOBALS['FORUM_DB']->query_value('f_topics', 't_num_views', array('id' => $to_topic_id)); $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_num_views' => $num_view_count), array('id' => $to_topic_id), '', 1); require_code('ocf_topics_action'); require_code('ocf_topics_action2'); ocf_delete_topic($from_topic_id, do_lang('MOVE_POSTS')); return true; } else { // Make informative post $me_link = '[page="' . get_module_zone('members') . '" type="view" id="' . strval(get_member()) . '" caption="' . $GLOBALS['OCF_DRIVER']->get_username(get_member()) . '"]members[/page]'; $topic_title = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_cache_first_title', array('id' => $to_topic_id)); $lang = do_lang('INLINE_POSTS_MOVED_MESSAGE', $me_link, integer_format(count($posts)), array('[page="' . get_module_zone('topicview') . '" id="' . strval($to_topic_id) . '" caption="' . str_replace('"', '\\"', str_replace('[', '\\[', $topic_title)) . '"]topicview[/page]')); ocf_make_post($from_topic_id, '', $lang, 0, false, 1, 1, NULL, NULL, $GLOBALS['FORUM_DB']->query_value('f_posts', 'p_time', array('id' => $posts[0])) + 1, NULL, NULL, NULL, NULL, false); require_code('ocf_general_action2'); ocf_mod_log_it('MOVE_POSTS', strval($to_topic_id), strval(count($posts)), $reason); if (!is_null($from_forum_id)) { ocf_decache_ocp_blocks($from_forum_id); } if (!is_null($to_forum_id)) { ocf_decache_ocp_blocks($to_forum_id); } return false; } return false; // should never get here }