/** * 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); } // Forums require_code('ocf_posts_action2'); $start = 0; do { $forums = $GLOBALS['FORUM_DB']->query_select('f_forums', array('id'), NULL, '', 100, $start); foreach ($forums as $forum) { ocf_force_update_forum_cacheing($forum['id']); } $start += 100; } while ($forums != array()); return new ocp_tempcode(); }
/** * Move some topics. * * @param AUTO_LINK The forum the topics are currently in. * @param AUTO_LINK The forum the topics are being moved to. * @param ?array A list of the topic IDs to move (NULL: move all topics from source forum). */ function ocf_move_topics($from, $to, $topics = NULL) { if ($from == $to) { return; } // That would be nuts, and interfere with our logic require_code('notifications'); require_code('ocf_topics'); require_code('ocf_forums_action2'); $forum_name = ocf_ensure_forum_exists($to); if (!ocf_may_moderate_forum($from)) { access_denied('I_ERROR'); } $topic_count = 0; if (is_null($topics)) { if (is_null($from)) { access_denied('I_ERROR'); } $all_topics = $GLOBALS['FORUM_DB']->query_select('f_topics', array('id', 't_cache_num_posts', 't_validated'), array('t_forum_id' => $from)); $or_list = ''; $post_count = 0; $topics = array(); foreach ($all_topics as $topic_info) { $topics[] = $topic_info['id']; if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'id=' . strval((int) $topic_info['id']); $post_count += $topic_info['t_cache_num_posts']; if ($topic_info['t_validated'] == 1) { $topic_count++; } } $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_forum_id' => $to), array('t_forum_id' => $from)); // Update forum IDs' for posts $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_cache_forum_id' => $from)); $or_list_2 = str_replace('id', 'p_topic_id', $or_list); if ($or_list_2 == '') { return; } } elseif (count($topics) == 1) { $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to', 't_cache_first_title', 't_cache_num_posts', 't_validated'), array('id' => $topics[0])); if (!array_key_exists(0, $topic_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topics[0]) && !has_specific_permission(get_member(), 'view_other_pt') && is_null($topic_info[0]['t_forum_id'])) { access_denied('I_ERROR'); } if ($topic_info[0]['t_validated'] == 1) { $topic_count++; } $topic_title = $topic_info[0]['t_cache_first_title']; $post_count = $topic_info[0]['t_cache_num_posts']; $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_pt_from' => NULL, 't_pt_to' => NULL, 't_forum_id' => $to), array('t_forum_id' => $from, 'id' => $topics[0]), '', 1); // Extra where constraint for added security log_it('MOVE_TOPICS', $topic_title, strval($topics[0])); $or_list = 'id=' . strval($topics[0]); $or_list_2 = 'p_topic_id=' . strval($topics[0]); // Update forum IDs' for posts $GLOBALS['FORUM_DB']->query_update('f_posts', array('p_cache_forum_id' => $to), array('p_topic_id' => $topics[0])); } else { if (count($topics) == 0) { return; } // Nuts, lol $or_list = ''; foreach ($topics as $topic_id) { if ($or_list != '') { $or_list .= ' OR '; } $or_list .= 'id=' . strval((int) $topic_id); if (is_null($from)) { $topic_info = $GLOBALS['FORUM_DB']->query_select('f_topics', array('t_forum_id', 't_pt_from', 't_pt_to'), array('id' => $topic_id)); if (array_key_exists(0, $topic_info)) { if ($topic_info[0]['t_validated'] == 1) { $topic_count++; } if ($topic_info[0]['t_forum_id'] != $from || $topic_info[0]['t_pt_from'] != get_member() && $topic_info[0]['t_pt_to'] != get_member() && !ocf_has_special_pt_access($topic_id) && !has_specific_permission(get_member(), 'view_other_pt')) { access_denied('I_ERROR'); } } } else { $topic_count++; // Might not be validated, which means technically we shouldn't do this, but it's low chance, low impact, and the indicator is only a cache thing anyway } } $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics SET t_forum_id=' . strval((int) $to) . ',t_pt_from=NULL,t_pt_to=NULL WHERE t_forum_id' . (is_null($from) ? ' IS NULL' : '=' . strval((int) $from)) . ' AND (' . $or_list . ')'); log_it('MOVE_TOPICS', do_lang('MULTIPLE')); $post_count = $GLOBALS['FORUM_DB']->query_value_null_ok_full('SELECT SUM(t_cache_num_posts) FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list); // Update forum IDs' for posts $or_list_2 = str_replace('id', 'p_topic_id', $or_list); $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts SET p_cache_forum_id=' . strval((int) $to) . ' WHERE ' . $or_list_2); } require_code('ocf_posts_action2'); // Update source forum cache view if (!is_null($from)) { ocf_force_update_forum_cacheing($from, -$topic_count, -$post_count); } // Update dest forum cache view ocf_force_update_forum_cacheing($to, $topic_count, $post_count); if (!is_null($from)) { // 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) . ' OR id=' . strval((int) $to), 2); if ($post_count_info[0]['id'] == $from) { $from_cnt = $post_count_info[0]['f_post_count_increment']; $to_cnt = $post_count_info[1]['f_post_count_increment']; } 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 (' . $or_list_2 . ')'; 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); } } } require_code('ocf_posts_action'); if (!is_null($from)) { ocf_decache_ocp_blocks($from); } else { decache('side_ocf_personal_topics'); decache('_new_pp'); } ocf_decache_ocp_blocks($to, $forum_name); if (function_exists('set_time_limit')) { @set_time_limit(0); } $start = 0; do { $topics2 = $GLOBALS['FORUM_DB']->query('SELECT id,t_cache_first_title,t_cache_last_time FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list, 100, $start); require_code('urls2'); foreach ($topics2 as $_topic) { if ($_topic['t_cache_last_time'] < time() - 60 * 60 * 24 * 14) { continue; } $topic_id = $_topic['id']; $topic_title = $_topic['t_cache_first_title']; suggest_new_idmoniker_for('topicview', 'misc', strval($topic_id), $topic_title); // Now lets inform people tracking the topic that it has moved $subject = do_lang('TOPIC_MOVE_MAIL_SUBJECT', get_site_name(), $topic_title); $mail = do_lang('TOPIC_MOVE_MAIL', comcode_escape(get_site_name()), comcode_escape($topic_title), array(comcode_escape($forum_name))); dispatch_notification('ocf_topic', strval($topic_id), $subject, $mail); } } while (count($topics2) == 100); }
/** * Edit a forum. * * @param AUTO_LINK The ID of the forum we are editing. * @param SHORT_TEXT The name of the forum. * @param SHORT_TEXT The description for the forum. * @param AUTO_LINK What forum category the forum will be filed with. * @param ?AUTO_LINK The ID of the parent forum (NULL: this is the root forum). * @param integer The position of this forum relative to other forums viewable on the same screen (if parent forum hasn't specified automatic ordering). * @param BINARY Whether post counts will be incremented if members post in the forum. * @param BINARY Whether the ordering of subforums is done automatically, alphabetically). * @param LONG_TEXT The question that is shown for newbies to the forum (blank: none). * @param SHORT_TEXT The answer to the question (blank: no specific answer.. if there's a 'question', it just requires a click-through). * @param SHORT_TEXT Either blank for no redirection, the ID of another forum we are mirroring, or a URL to redirect to. * @param ID_TEXT The order the topics are shown in, by default. * @param BINARY Whether the forum is threaded. * @param boolean Whether to force forum rules to be re-agreed to, if they've just been changed. */ function ocf_edit_forum($forum_id, $name, $description, $category_id, $new_parent, $position, $post_count_increment, $order_sub_alpha, $intro_question, $intro_answer, $redirection = '', $order = 'last_post', $is_threaded = 0, $reset_intro_acceptance = false) { if ($category_id == -1) { $category_id = NULL; } if ($new_parent == -1) { $new_parent = NULL; } require_code('urls2'); suggest_new_idmoniker_for('forumview', 'misc', strval($forum_id), $name); if (!is_null($category_id) && $category_id != INTEGER_MAGIC_NULL) { ocf_ensure_category_exists($category_id); } if (!is_null($new_parent) && $new_parent != INTEGER_MAGIC_NULL) { ocf_ensure_forum_exists($new_parent); } $forum_info = $GLOBALS['FORUM_DB']->query_select('f_forums', array('*'), array('id' => $forum_id), '', 1); if (!array_key_exists(0, $forum_info)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } $old_parent = $forum_info[0]['f_parent_forum']; $old_name = $forum_info[0]['f_name']; $under_category_id = $new_parent; while (!is_null($under_category_id) && $under_category_id != INTEGER_MAGIC_NULL) { if ($forum_id == $under_category_id) { warn_exit(do_lang_tempcode('FORUM_CANNOT_BE_OWN_PARENT')); } $under_category_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_parent_forum', array('id' => $under_category_id)); } if ($reset_intro_acceptance && trim(get_translated_text($forum_info[0]['f_intro_question'], $GLOBALS['FORUM_DB'])) != trim($intro_question) && $intro_question != STRING_MAGIC_NULL) { $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_ip', array('i_forum_id' => $forum_id)); $GLOBALS['FORUM_DB']->query_delete('f_forum_intro_member', array('i_forum_id' => $forum_id)); } $GLOBALS['FORUM_DB']->query_update('f_forums', array('f_name' => $name, 'f_description' => lang_remap($forum_info[0]['f_description'], $description, $GLOBALS['FORUM_DB']), 'f_category_id' => $category_id, 'f_parent_forum' => $new_parent, 'f_position' => $position, 'f_order_sub_alpha' => $order_sub_alpha, 'f_intro_question' => lang_remap($forum_info[0]['f_intro_question'], $intro_question, $GLOBALS['FORUM_DB']), 'f_intro_answer' => $intro_answer, 'f_post_count_increment' => $post_count_increment, 'f_redirection' => $redirection, 'f_order' => $order, 'f_is_threaded' => $is_threaded), array('id' => $forum_id), '', 1); if ($old_name != $name) { $test = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_name', array('f_name' => $old_name)); if (is_null($test)) { require_code('config2'); update_config_option_reference($old_name, $name, 'forum'); } } if ($old_parent != $new_parent && $new_parent != INTEGER_MAGIC_NULL) { // Recalc stats require_code('ocf_posts_action2'); $num_topics_forum = $forum_info[0]['f_cache_num_topics']; // This is valid, because we move all this forums subforums too $num_posts_forum = $forum_info[0]['f_cache_num_posts']; if (!is_null($old_parent)) { ocf_force_update_forum_cacheing($old_parent, -$num_topics_forum, -$num_posts_forum); } if (!is_null($new_parent)) { ocf_force_update_forum_cacheing($new_parent, $num_topics_forum, $num_posts_forum); } } log_it('EDIT_FORUM', strval($forum_id), $name); }
/** * Update a forums cached details. * * @param AUTO_LINK The ID of the forum to update the cached details of. * @param ?integer How much to increment the topic count by (NULL: It has to be completely recalculated). * @param ?integer How much to increment the post count by (NULL: It has to be completely recalculated). * @param ?AUTO_LINK The ID of the last topic (NULL: Unknown, it will have to be looked up). * @param ?string The title of the last topic (NULL: Unknown, it will have to be looked up). * @param ?TIME The last post time of the last topic (NULL: Unknown, it will have to be looked up). * @param ?string The last post username of the last topic (NULL: Unknown, it will have to be looked up). * @param ?MEMBER The last post member of the last topic (NULL: Unknown, it will have to be looked up). * @param ?AUTO_LINK The forum the last post was in (note this makes sense, because there may be subforums under this forum that we have to take into account). (NULL: Unknown, it will have to be looked up). */ function ocf_force_update_forum_cacheing($forum_id, $num_topics_increment = NULL, $num_posts_increment = NULL, $last_topic_id = NULL, $last_title = NULL, $last_time = NULL, $last_username = NULL, $last_member_id = NULL, $last_forum_id = NULL) { if (is_null($num_topics_increment) && !is_null($num_posts_increment)) { $num_topics_increment = 0; } if (!is_null($num_topics_increment) && is_null($num_posts_increment)) { $num_posts_increment = 0; } if (is_null($last_topic_id)) { require_code('ocf_forums'); $or_list = ocf_get_all_subordinate_forums($forum_id, 't_forum_id', NULL, true); $last_topic = $GLOBALS['FORUM_DB']->query('SELECT * FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE (' . $or_list . ') AND t_validated=1 ORDER BY t_cache_last_time DESC', 1); if (!array_key_exists(0, $last_topic)) { $last_topic_id = NULL; $last_title = ''; $last_time = NULL; $last_username = ''; $last_member_id = NULL; $last_forum_id = NULL; } else { $last_topic_id = $last_topic[0]['id']; $last_title = $last_topic[0]['t_cache_first_title']; // Actually, the first title of the last topic $last_time = $last_topic[0]['t_cache_last_time']; $last_username = $last_topic[0]['t_cache_last_username']; $last_member_id = $last_topic[0]['t_cache_last_member_id']; $last_forum_id = $last_topic[0]['t_forum_id']; } } else { if (is_null($num_topics_increment)) { $or_list = ocf_get_all_subordinate_forums($forum_id, 't_forum_id', NULL, true); } } if (is_null($num_topics_increment)) { $_num_topics = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS topic_count FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE ' . $or_list); $num_topics = $_num_topics[0]['topic_count']; $or_list_2 = str_replace('t_forum_id', 'p_cache_forum_id', $or_list); $_num_posts = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS post_count FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE p_intended_solely_for IS NULL AND (' . $or_list_2 . ')'); $num_posts = $_num_posts[0]['post_count']; } $GLOBALS['FORUM_DB']->query('UPDATE ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_forums SET ' . (!is_null($num_posts_increment) ? ' f_cache_num_topics=(f_cache_num_topics+' . strval((int) $num_topics_increment) . '), f_cache_num_posts=(f_cache_num_posts+' . strval((int) $num_posts_increment) . '),' : ' f_cache_num_topics=' . strval((int) $num_topics) . ', f_cache_num_posts=' . strval((int) $num_posts) . ', ') . 'f_cache_last_topic_id=' . (!is_null($last_topic_id) ? strval($last_topic_id) : 'NULL') . ', f_cache_last_title=\'' . db_escape_string($last_title) . '\', f_cache_last_time=' . (!is_null($last_time) ? strval($last_time) : 'NULL') . ', f_cache_last_username=\'' . db_escape_string($last_username) . '\', f_cache_last_member_id=' . (!is_null($last_member_id) ? strval($last_member_id) : 'NULL') . ', f_cache_last_forum_id=' . (!is_null($last_forum_id) ? strval($last_forum_id) : 'NULL') . ' WHERE id=' . strval((int) $forum_id), 1); // Now, are there any parents who need updating? if (!is_null($forum_id)) { $parent_forum = $GLOBALS['FORUM_DB']->query_value_null_ok('f_forums', 'f_parent_forum', array('id' => $forum_id)); if (!is_null($parent_forum) && $parent_forum != db_get_first_id()) { ocf_force_update_forum_cacheing($parent_forum, $num_topics_increment, $num_posts_increment); } } }
/** * The actualiser to make a normal topic a Private Topic. * * @return tempcode The UI */ function _make_personal() { $topic_id = post_param_integer('id'); $forum_id = $GLOBALS['FORUM_DB']->query_value_null_ok('f_topics', 't_forum_id', array('id' => $topic_id)); if (is_null($forum_id)) { warn_exit(do_lang_tempcode('MISSING_RESOURCE')); } if (!ocf_may_moderate_forum($forum_id, get_member())) { access_denied('I_ERROR'); } $_a = post_param('a'); $_b = post_param('b'); $a = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_a); if (is_null($a)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', $_a)); } $b = $GLOBALS['FORUM_DRIVER']->get_member_from_username($_b); if (is_null($b)) { warn_exit(do_lang_tempcode('_USER_NO_EXIST', $_b)); } $GLOBALS['FORUM_DB']->query_update('f_topics', array('t_pt_from' => $a, 't_pt_to' => $b, 't_forum_id' => NULL), array('id' => $topic_id), '', 1); // Update forum cache view require_code('ocf_posts_action2'); ocf_force_update_forum_cacheing($forum_id, -1); return $this->redirect_to('MAKE_PERSONAL', $topic_id); }
/** * 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)); }