/** * Standard modular run function. * * @return tempcode Results */ function run() { if (get_forum_type() != 'ocf') { return new ocp_tempcode(); } else { ocf_require_all_forum_stuff(); } if (function_exists('set_time_limit')) { @set_time_limit(0); } // Topics and posts $start = 0; do { $topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_forum_id'), NULL, '', 500, $start); foreach ($topics as $topic) { require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($topic['id'], NULL, true, true); // NB: p_cache_forum_id must not be intval'd as may be null if (is_null($topic['t_forum_id'])) { $topic['t_forum_id'] = NULL; } $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . (is_null($topic['t_forum_id']) ? 'NULL' : strval($topic['t_forum_id'])) . ' WHERE p_topic_id=' . (is_null($topic['id']) ? 'NULL' : strval($topic['id']))); } $start += 500; } while (array_key_exists(0, $topics)); // Polls $start = 0; do { $polls = $GLOBALS['FORUM_DB']->query_select('f_polls', array('id'), NULL, '', 500, $start); foreach ($polls as $poll) { $total_votes = $GLOBALS['FORUM_DB']->query_value('f_poll_votes', 'COUNT(*)', array('pv_poll_id' => $poll['id'])); $GLOBALS['FORUM_DB']->query_update('f_polls', array('po_cache_total_votes' => $total_votes), array('id' => $poll['id']), '', 1); $answers = $GLOBALS['FORUM_DB']->query_select('f_poll_answers', array('id'), array('pa_poll_id' => $poll['id'])); foreach ($answers as $answer) { $votes = $GLOBALS['FORUM_DB']->query_value('f_poll_votes', 'COUNT(*)', array('pv_answer_id' => $answer['id'], 'pv_poll_id' => $poll['id'])); $GLOBALS['FORUM_DB']->query_update('f_poll_answers', array('pa_cache_num_votes' => $votes), array('id' => $answer['id']), '', 1); } } $start += 500; } while (array_key_exists(0, $polls)); return new ocp_tempcode(); }
/** * 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; }
/** * Get details of a topic (to show eventually as a row in a forum or results view). This is a helper function, and thus the interface is not very user friendly. * * @param array The DB row of the topic. * @param MEMBER The member the details are being prepared for. * @param integer The hot topic definition (taken from the config options). * @param boolean Whether the viewing member has a post in the topic. * @return array The details. */ function ocf_get_topic_array($topic_row, $member_id, $hot_topic_definition, $involved) { $topic = array(); if (is_null($topic_row['t_cache_first_post']) || $topic_row['t_cache_first_post'] === 0) { $topic['first_post'] = new ocp_tempcode(); } else { if (!is_null($topic_row['_trans_post']) && $topic_row['_trans_post'] != '') { $topic['first_post'] = new ocp_tempcode(); if (!$topic['first_post']->from_assembly($topic_row['_trans_post'])) { $topic_row['_trans_post'] = NULL; } } if (is_null($topic_row['_trans_post']) || $topic_row['_trans_post'] == '') { if (!is_null($topic_row['t_cache_first_post'])) { $topic['first_post'] = get_translated_tempcode($topic_row['t_cache_first_post'], $GLOBALS['FORUM_DB']); } else { $topic['first_post'] = new ocp_tempcode(); } } else { $topic['first_post']->singular_bind('ATTACHMENT_DOWNLOADS', make_string_tempcode('?')); } } // Pre-load it, so meta-data isn't altered later $bak = $GLOBALS['META_DATA']; $topic['first_post'] = get_translated_tempcode($topic_row['t_cache_first_post'], $GLOBALS['FORUM_DB']); $topic['first_post']->evaluate(); $GLOBALS['META_DATA'] = $bak; $topic['id'] = $topic_row['id']; $topic['num_views'] = $topic_row['t_num_views']; $topic['num_posts'] = $topic_row['t_cache_num_posts']; $topic['forum_id'] = $topic_row['t_forum_id']; $topic['description'] = $topic_row['t_description']; $topic['description_link'] = $topic_row['t_description_link']; // If it's a spacer post, we need to intercede at this point, and make a better one $linked_type = ''; $linked_id = ''; $is_spacer_post = substr($topic['first_post']->evaluate(), 0, strlen(do_lang('SPACER_POST_MATCHER'))) == do_lang('SPACER_POST_MATCHER'); if ($is_spacer_post) { $c_prefix = do_lang('COMMENT') . ': #'; if (substr($topic['description'], 0, strlen($c_prefix)) == $c_prefix && $topic['description_link'] != '') { list($linked_type, $linked_id) = explode('_', substr($topic['description'], strlen($c_prefix)), 2); $topic['description'] = ''; require_code('ocf_posts'); list(, $new_post) = ocf_display_spacer_post($linked_type, $linked_id); if (!is_null($new_post)) { $topic['first_post'] = $new_post; } } } $topic['emoticon'] = $topic_row['t_emoticon']; $topic['first_time'] = $topic_row['t_cache_first_time']; $topic['first_title'] = $topic_row['t_cache_first_title']; if ($topic['first_title'] == '') { $topic['first_title'] = do_lang_tempcode('NA'); } if ($is_spacer_post) { $topic['first_title'] = do_lang('SPACER_TOPIC_TITLE_WRAP', $topic['first_title']); } $topic['first_username'] = $topic_row['t_cache_first_username']; $topic['first_member_id'] = $topic_row['t_cache_first_member_id']; if (is_null($topic['first_member_id'])) { require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($topic_row['id'], NULL, true, true); //$_topic_row=$GLOBALS['FORUM_DB']->query_select('f_topics',array('*'),array('id'=>$topic_row['id']),'',1); //$topic_row=$_topic_row[0]; //$topic['first_member_id']=$GLOBALS['OCF_DRIVER']->get_guest_id(); } if (!is_null($topic_row['t_cache_last_post_id'])) { $topic['last_post_id'] = $topic_row['t_cache_last_post_id']; $topic['last_time'] = $topic_row['t_cache_last_time']; $topic['last_time_string'] = get_timezoned_date($topic_row['t_cache_last_time']); $topic['last_title'] = $topic_row['t_cache_last_title']; $topic['last_username'] = $topic_row['t_cache_last_username']; $topic['last_member_id'] = $topic_row['t_cache_last_member_id']; } // Modifiers $topic['modifiers'] = array(); $has_read = ocf_has_read_topic($topic['id'], $topic_row['t_cache_last_time'], $member_id, $topic_row['l_time']); if (!$has_read) { $topic['modifiers'][] = 'unread'; } if ($involved) { $topic['modifiers'][] = 'involved'; } if ($topic_row['t_cascading'] == 1) { $topic['modifiers'][] = 'announcement'; } if ($topic_row['t_pinned'] == 1) { $topic['modifiers'][] = 'pinned'; } if ($topic_row['t_sunk'] == 1) { $topic['modifiers'][] = 'sunk'; } if ($topic_row['t_is_open'] == 0) { $topic['modifiers'][] = 'closed'; } if ($topic_row['t_validated'] == 0) { $topic['modifiers'][] = 'unvalidated'; } if (!is_null($topic_row['t_poll_id'])) { $topic['modifiers'][] = 'poll'; } $num_posts = $topic_row['t_cache_num_posts']; $start_time = $topic_row['t_cache_first_time']; $end_time = $topic_row['t_cache_last_time']; $days = floatval($end_time - $start_time) / 60.0 / 60.0 / 24.0; if ($days == 0.0) { $days = 1.0; } if ($num_posts >= 8 && intval(round(floatval($num_posts) / $days)) >= $hot_topic_definition) { $topic['modifiers'][] = 'hot'; } return $topic; }
/** * Add a post. * * @param AUTO_LINK The ID of the topic to add the post to. * @param SHORT_TEXT The title of the post (may be blank). * @param LONG_TEXT The post. * @param BINARY Whether to skip showing the posters signature in the post. * @param boolean Whether the post is the first in the topic. * @param ?BINARY Whether the post is validated (NULL: unknown, find whether it needs to be marked unvalidated initially). * @param BINARY Whether the post is marked emphasised. * @param ?string The name of the person making the post (NULL: username of current member). * @param ?IP The IP address the post is to be made under (NULL: IP of current user). * @param ?TIME The time of the post (NULL: now). * @param ?MEMBER The poster (NULL: current member). * @param ?MEMBER The member that this post is intended solely for (NULL: public). * @param ?TIME The last edit time of the post (NULL: never edited). * @param ?MEMBER The member that was last to edit the post (NULL: never edited). * @param boolean Whether to check permissions for whether the post may be made as it is given. * @param boolean Whether to update the caches after making the post. * @param ?AUTO_LINK The forum the post will be in (NULL: find out from the DB). * @param boolean Whether to allow attachments in this post. * @param ?string The title of the topic (NULL: find from the DB). * @param BINARY Whether the topic is a sunk topic. * @param ?AUTO_LINK Force an ID (NULL: don't force an ID) * @param boolean Whether to make the post anonymous * @param boolean Whether to skip post checks * @param boolean Whether this is for a new Private Topic * @param boolean Whether to explicitly insert the Comcode with admin privileges * @param ?AUTO_LINK Parent post ID (NULL: none-threaded/root-of-thread) * @return AUTO_LINK The ID of the new post. */ function ocf_make_post($topic_id, $title, $post, $skip_sig = 0, $is_starter = false, $validated = NULL, $is_emphasised = 0, $poster_name_if_guest = NULL, $ip_address = NULL, $time = NULL, $poster = NULL, $intended_solely_for = NULL, $last_edit_time = NULL, $last_edit_by = NULL, $check_permissions = true, $update_cacheing = true, $forum_id = NULL, $support_attachments = true, $topic_title = '', $sunk = 0, $id = NULL, $anonymous = false, $skip_post_checks = false, $is_pt = false, $insert_comcode_as_admin = false, $parent_id = NULL) { if (is_null($poster)) { $poster = get_member(); } if ($check_permissions) { if (strlen($title) > 120) { warn_exit(do_lang_tempcode('TITLE_TOO_LONG')); } if (get_option('prevent_shouting') == '1') { if (strtoupper($title) == $title) { $title = ucwords($title); } } if (is_null($intended_solely_for) && !$skip_post_checks) { ocf_check_post($post, $topic_id, $poster); } } if (is_null($ip_address)) { $ip_address = get_ip_address(); } if (is_null($time)) { $time = time(); $send_notification = true; } else { $send_notification = false; } if (is_null($poster_name_if_guest)) { if ($poster == $GLOBALS['OCF_DRIVER']->get_guest_id() || $anonymous) { $poster_name_if_guest = do_lang('GUEST'); } else { $poster_name_if_guest = $GLOBALS['OCF_DRIVER']->get_username($poster); if (is_null($poster_name_if_guest)) { $poster_name_if_guest = do_lang('UNKNOWN'); } } } if (is_null($forum_id) || $topic_title == '' && !$is_starter) { $info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_is_open', 't_pt_from', 't_pt_to', 't_forum_id', 't_cache_last_member_id', 't_cache_first_title'), array('id' => $topic_id), '', 1); if (!array_key_exists(0, $info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $forum_id = $info[0]['t_forum_id']; $topic_title = $info[0]['t_cache_first_title']; if ($topic_title == '') { $topic_title = $title; } if ($check_permissions) { if ($info[0]['t_pt_from'] != get_member() && $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($forum_id)) { if ($check_permissions && $poster == $GLOBALS['OCF_DRIVER']->get_guest_id()) { access_denied('I_ERROR'); } $validated = 1; // Personal posts always validated } else { if ($check_permissions) { if ($info[0]['t_is_open'] == 0 && !ocf_may_moderate_forum($forum_id)) { access_denied('I_ERROR'); } $last_member_id = $info[0]['t_cache_last_member_id']; if (!ocf_may_post_in_topic($forum_id, $topic_id, $last_member_id) && !$is_starter) { access_denied('I_ERROR'); } } } // Ensure parent post is from the same topic if (!is_null($parent_id)) { $test_topic_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_posts', 'p_topic_id', array('id' => $parent_id), ' AND ' . ocf_get_topic_where($topic_id, $poster)); if (is_null($test_topic_id)) { $parent_id = NULL; } } if (is_null($validated) || $validated == 1 && $check_permissions) { if (!is_null($forum_id) && !has_specific_permission(get_member(), 'bypass_validation_lowrange_content', 'topics', array('forums', $forum_id))) { $validated = 0; } else { $validated = 1; } } if (!$support_attachments) { $lang_id = insert_lang_comcode($post, 4, $GLOBALS['FORUM_DB'], $insert_comcode_as_admin); } else { $lang_id = 0; } if (!addon_installed('unvalidated')) { $validated = 1; } $map = array('p_title' => substr($title, 0, 255), 'p_post' => $lang_id, 'p_ip_address' => $ip_address, 'p_time' => $time, 'p_poster' => $anonymous ? db_get_first_id() : $poster, 'p_poster_name_if_guest' => substr($poster_name_if_guest, 0, 80), 'p_validated' => $validated, 'p_topic_id' => $topic_id, 'p_is_emphasised' => $is_emphasised, 'p_cache_forum_id' => $forum_id, 'p_last_edit_time' => $last_edit_time, 'p_last_edit_by' => $last_edit_by, 'p_intended_solely_for' => $intended_solely_for, 'p_skip_sig' => $skip_sig, 'p_parent_id' => $parent_id); if (!is_null($id)) { $map['id'] = $id; } $post_id = $GLOBALS['FORUM_DB']->query_insert('f_posts', $map, true); if ($support_attachments) { require_code('attachments2'); $lang_id = insert_lang_comcode_attachments(4, $post, 'ocf_post', strval($post_id), $GLOBALS['FORUM_DB']); $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_post' => $lang_id), array('id' => $post_id), '', 1); } $_url = build_url(array('page' => 'topicview', 'type' => 'findpost', 'id' => $post_id), 'forum', NULL, false, false, true, 'post_' . strval($post_id)); $url = $_url->evaluate(); if ($validated == 0) { if ($check_permissions) { // send_validation_mail is used for other content - but forum is special $subject = do_lang('POST_REQUIRING_VALIDATION_MAIL_SUBJECT', $topic_title, NULL, NULL, get_site_default_lang()); $post_text = get_translated_text($lang_id, $GLOBALS['FORUM_DB'], get_site_default_lang()); $mail = do_lang('POST_REQUIRING_VALIDATION_MAIL', comcode_escape($url), comcode_escape($poster_name_if_guest), $post_text); require_code('notifications'); dispatch_notification('needs_validation', NULL, $subject, $mail); } } else { if ($check_permissions) { if ($send_notification) { $post_comcode = get_translated_text($lang_id, $GLOBALS['FORUM_DB']); require_code('ocf_posts_action2'); ocf_send_topic_notification($url, $topic_id, $forum_id, $anonymous ? db_get_first_id() : $poster, $is_starter, $post_comcode, $topic_title, $intended_solely_for, $is_pt); // Send a notification for the inline PP if (!is_null($intended_solely_for)) { require_code('notifications'); $msubject = do_lang('NEW_PERSONAL_POST_SUBJECT', $topic_title, NULL, NULL, get_lang($intended_solely_for)); $mmessage = do_lang('NEW_PERSONAL_POST_MESSAGE', comcode_escape($GLOBALS['FORUM_DRIVER']->get_username($anonymous ? db_get_first_id() : $poster)), comcode_escape($topic_title), array(comcode_escape($url), $post_comcode), get_lang($intended_solely_for)); dispatch_notification('ocf_new_pt', NULL, $msubject, $mmessage, array($intended_solely_for), $anonymous ? db_get_first_id() : $poster); } } } } if ($check_permissions) { // Is the user gonna automatically enable notifications for this? $auto_monitor_contrib_content = $GLOBALS['OCF_DRIVER']->get_member_row_field($poster, 'm_auto_monitor_contrib_content'); if ($auto_monitor_contrib_content == 1) { require_code('notifications'); enable_notifications('ocf_topic', strval($topic_id), $poster); } } if ($update_cacheing) { if (function_exists('get_member')) { if (function_exists('ocf_ping_topic_read')) { ocf_ping_topic_read($topic_id); } if (is_null($forum_id)) { $with = $info[0]['t_pt_from']; if ($with == get_member()) { $with = $info[0]['t_pt_to']; } decache('side_ocf_personal_topics', array($with)); decache('_new_pp', array($with)); } if (get_option('show_post_validation') == '1') { decache('main_staff_checklist'); } } if (is_null($intended_solely_for)) { if ($validated == 1) { require_code('ocf_posts_action2'); ocf_force_update_topic_cacheing($topic_id, 1, true, $is_starter, $post_id, $time, $title, $lang_id, $poster_name_if_guest, $poster); } if ($validated == 1) { if (!is_null($forum_id)) { require_code('ocf_posts_action2'); // Find if the topic is validated. This can be approximate, if we don't get 1 then ocf_force_update_forum_cacheing will do a search, making the code very slightly slower if (!$check_permissions || is_null($forum_id)) { $topic_validated = 1; } else { if ($is_starter) { $topic_validated = has_specific_permission($poster, 'bypass_validation_midrange_content', 'topics', array('forums', $forum_id)) ? 1 : 0; } else { $topic_validated = $GLOBALS['FORUM_DB']->query_value('f_topics', 't_validated', array('id' => $topic_id)); } } ocf_force_update_forum_cacheing($forum_id, $is_starter ? 1 : 0, 1, $topic_validated == 0 ? NULL : $topic_id, $topic_validated == 0 ? NULL : $topic_title, $topic_validated == 0 ? NULL : $time, $topic_validated == 0 ? NULL : $poster_name_if_guest, $topic_validated == 0 ? NULL : $poster, $topic_validated == 0 ? NULL : $forum_id); } } } // Update post count if (!is_null($forum_id)) { $post_counts = is_null($forum_id) ? 1 : $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_post_count_increment', array('id' => $forum_id)); if ($post_counts === 1 && !$anonymous && $validated == 1) { ocf_force_update_member_post_count($poster, 1); } if ($check_permissions) { ocf_decache_ocp_blocks($forum_id, NULL, $intended_solely_for); } // i.e. we don't run this if in installer } if ($poster != $GLOBALS['OCF_DRIVER']->get_guest_id()) { require_code('ocf_posts_action2'); ocf_member_handle_promotion($poster); } } return $post_id; }
/** * 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 }
/** * The actualiser for merging members. * * @return tempcode The UI */ function actual() { $title = get_page_title('MERGE_MEMBERS'); $to_username = post_param('to'); $to_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($to_username); if (is_null($to_id) || is_guest($to_id)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', $to_username)); } $from_username = post_param('from'); $from_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($from_username); if (is_guest($from_id)) { warn_exit(do_lang_tempcode('INTERNAL_ERROR')); } if (is_null($from_id) || is_guest($from_id)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', $from_username)); } if ($to_id == $from_id) { warn_exit(do_lang_tempcode('MERGE_SAME')); } $meta = $GLOBALS['SITE_DB']->query('SELECT m_table,m_name FROM ' . get_table_prefix() . 'db_meta WHERE ' . db_string_equal_to('m_type', 'USER') . ' OR ' . db_string_equal_to('m_type', '?USER') . ' OR ' . db_string_equal_to('m_type', '*USER')); foreach ($meta as $m) { $GLOBALS['SITE_DB']->query_update($m['m_table'], array($m['m_name'] => $to_id), array($m['m_name'] => $from_id), '', NULL, NULL, false, true); } $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_poster_name_if_guest' => $to_username), array('p_poster' => $from_id)); $new_post_count = $GLOBALS['FORUM_DRIVER']->get_member_row_field($from_id, 'm_cache_num_posts') + $GLOBALS['FORUM_DRIVER']->get_member_row_field($to_id, 'm_cache_num_posts'); $GLOBALS['FORUM_DB']->query_update('f_members', array('m_cache_num_posts' => $new_post_count), array('id' => $to_id), '', 1); require_code('ocf_members_action'); require_code('ocf_members_action2'); $fields = ocf_get_custom_fields_member($from_id); foreach ($fields as $key => $val) { if ($val != '') { ocf_set_custom_field($to_id, $key, $val); } } ocf_delete_member($from_id); // Cache emptying ... ocf_require_all_forum_stuff(); require_code('ocf_posts_action'); require_code('ocf_posts_action2'); require_code('ocf_topics_action2'); require_code('ocf_forums_action2'); // Members ocf_force_update_member_post_count($to_id); $num_warnings = $GLOBALS['FORUM_DB']->query_value('f_warnings', 'COUNT(*)', array('w_member_id' => $to_id)); $GLOBALS['FORUM_DB']->query_update('f_members', array('m_cache_warnings' => $num_warnings), array('id' => $to_id), '', 1); // Topics and posts require_code('ocf_topics_action'); $topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_forum_id'), array('t_cache_first_member_id' => $from_id)); foreach ($topics as $topic) { ocf_force_update_topic_cacheing($topic['id'], NULL, true, true); } $topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_forum_id'), array('t_cache_last_member_id' => $from_id)); foreach ($topics as $topic) { ocf_force_update_topic_cacheing($topic['id'], NULL, true, true); } // Forums require_code('ocf_posts_action2'); $forums = $GLOBALS['FORUM_DB']->query_select('f_forums', array('id'), array('f_cache_last_member_id' => $from_id)); foreach ($forums as $forum) { ocf_force_update_forum_cacheing($forum['id']); } // --- log_it('MERGE_MEMBERS', $from_username, $to_username); breadcrumb_set_parents(array(array('_SEARCH:admin_ocf_join:menu', do_lang_tempcode('MEMBERS')), array('_SELF:_SELF:misc', do_lang_tempcode('MERGE_MEMBERS')))); breadcrumb_set_self(do_lang_tempcode('DONE')); $username = $GLOBALS['FORUM_DRIVER']->member_profile_hyperlink($to_id); return inform_screen($title, do_lang_tempcode('MERGED_MEMBERS', $username)); }