function bb_delete_topic($topic_id, $new_status = 0) { global $bbdb; $topic_id = (int) $topic_id; add_filter('get_topic_where', 'bb_no_where'); if ($topic = get_topic($topic_id)) { $new_status = (int) $new_status; $old_status = (int) $topic->topic_status; if ($new_status == $old_status) { return; } $thread_args = array('per_page' => -1, 'order' => 'DESC'); if (0 != $old_status && 0 == $new_status) { $thread_args['post_status'] = 'all'; } $poster_ids = array(); $posts = get_thread($topic_id, $thread_args); if ($posts && count($posts)) { foreach ($posts as $post) { _bb_delete_post($post->post_id, $new_status); $poster_ids[] = $post->poster_id; } } if (count($poster_ids)) { foreach (array_unique($poster_ids) as $id) { if ($user = bb_get_user($id)) { $topics_replied_key = $bbdb->prefix . 'topics_replied'; bb_update_usermeta($user->ID, $topics_replied_key, $old_status ? $user->{$topics_replied_key} + 1 : $user->{$topics_replied_key} - 1); } } } if ($ids = $bbdb->get_col("SELECT user_id, meta_value FROM {$bbdb->usermeta} WHERE meta_key = 'favorites' and FIND_IN_SET('{$topic_id}', meta_value) > 0")) { foreach ($ids as $id) { bb_remove_user_favorite($id, $topic_id); } } switch ($new_status) { case 0: // Undeleting $bbdb->update($bbdb->topics, array('topic_status' => $new_status), compact('topic_id')); $topic_posts = (int) $bbdb->get_var($bbdb->prepare("SELECT COUNT(*) FROM {$bbdb->posts} WHERE topic_id = %d AND post_status = 0", $topic_id)); $all_posts = (int) $bbdb->get_var($bbdb->prepare("SELECT COUNT(*) FROM {$bbdb->posts} WHERE topic_id = %d", $topic_id)); bb_update_topicmeta($topic_id, 'deleted_posts', $all_posts - $topic_posts); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1, posts = posts + %d WHERE forum_id = %d", $topic_posts, $topic->forum_id)); $bbdb->update($bbdb->topics, compact('topic_posts'), compact('topic_id')); bb_topic_set_last_post($topic_id); bb_update_post_positions($topic_id); break; default: // Other statuses (like Delete and Bozo) bb_remove_topic_tags($topic_id); $bbdb->update($bbdb->topics, array('topic_status' => $new_status, 'tag_count' => 0), compact('topic_id')); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics - 1, posts = posts - %d WHERE forum_id = %d", $topic->topic_posts, $topic->forum_id)); break; } do_action('bb_delete_topic', $topic_id, $new_status, $old_status); wp_cache_delete($topic_id, 'bb_topic'); wp_cache_delete($topic->topic_slug, 'bb_topic_slug'); wp_cache_delete($topic_id, 'bb_thread'); wp_cache_delete($topic->forum_id, 'bb_forum'); wp_cache_flush('bb_forums'); wp_cache_flush('bb_query'); wp_cache_flush('bb_cache_posts_post_ids'); return $topic_id; } else { return false; } }
function bb_delete_forum($forum_id) { global $bbdb; if (!bb_current_user_can('delete_forum', $forum_id)) { return false; } if (!($forum_id = (int) $forum_id)) { return false; } if (!($forum = bb_get_forum($forum_id))) { return false; } if ($topic_ids = $bbdb->get_col($bbdb->prepare("SELECT topic_id FROM {$bbdb->topics} WHERE forum_id = %d", $forum_id))) { foreach ($topic_ids as $topic_id) { bb_remove_topic_tags($topic_id); } $_topic_ids = join(',', array_map('intval', $topic_ids)); $bbdb->query("DELETE FROM {$bbdb->posts} WHERE topic_id IN ({$_topic_ids}) AND topic_id != 0"); $bbdb->query("DELETE FROM {$bbdb->meta} WHERE object_type = 'bb_topic' AND object_id IN ({$_topic_ids})"); $bbdb->query($bbdb->prepare("DELETE FROM {$bbdb->topics} WHERE forum_id = %d", $forum_id)); } $bbdb->update($bbdb->forums, array('forum_parent' => $forum->forum_parent), array('forum_parent' => $forum_id)); $return = $bbdb->query($bbdb->prepare("DELETE FROM {$bbdb->forums} WHERE forum_id = %d", $forum_id)); nxt_cache_flush('bb_post'); if ($topic_ids) { foreach ($topic_ids as $topic_id) { // should maybe just flush these groups instead nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); } } nxt_cache_delete($forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); return $return; }
/** * Update a topic's details. * * @param array $args { * Array of arguments. * @type int $topic_id ID of the topic being updated. * @type string $topic_title Updated title of the topic. * @type string $topic_title Updated text of the topic. * @type array|string|bool $topic_tags Array or comma-separated list of * topic tags. False to leave empty. Default: false. * } * @return object Details about the new topic, as returned by * {@link bp_forums_get_topic_details()}. */ function bp_forums_update_topic($args = '') { /** This action is documented in bp-forums/bp-forums-screens */ do_action('bbpress_init'); $r = wp_parse_args($args, array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false)); extract($r, EXTR_SKIP); // Check if the user is a spammer if (bp_is_user_inactive(bp_loggedin_user_id())) { return false; } // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags. bb_remove_topic_tags($topic_id); if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) { return false; } if (!($post = bb_get_first_post($topic_id))) { return false; } // Update the first post if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) { return false; } return bp_forums_get_topic_details($topic_id); }
/** * Removes the specified tags from the specified topic * * @since 1.0 * @return integer|object 1 when successfully executed or an IXR_Error object on failure * @param array $args Arguments passed by the XML-RPC call * @param string $args[0] The username for authentication * @param string $args[1] The password for authentication * @param string|integer $args[2] The topic id or slug * @param string|array $args[3] The tags to remove from the topic * * XML-RPC request to remove the tag "banana" to the topic with id 219 * <methodCall> * <methodName>bb.removeTopicTags</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><int>219</int></value></param> * <param><value><string>banana</string></value></param> * </params> * </methodCall> * * XML-RPC request to remove the tags "banana" and "man" to the topic with id 219 * <methodCall> * <methodName>bb.removeTopicTags</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><int>219</int></value></param> * <param><value><string>banana, man</string></value></param> * </params> * </methodCall> * * XML-RPC request to remove the tags "banana" and "man" to the topic with id 219 using an array * <methodCall> * <methodName>bb.removeTopicTags</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><int>219</int></value></param> * <param><value><array> * <data><value><string>banana</string></value></data> * <data><value><string>man</string></value></data> * </array></value></param> * </params> * </methodCall> */ function bb_removeTopicTags($args) { do_action('bb_xmlrpc_call', 'bb.removeTopicTags'); // Escape args $this->escape($args); // Get the login credentials $username = $args[0]; $password = (string) $args[1]; // Check the user is valid $user = $this->authenticate($username, $password, 'edit_tags', __('You do not have permission to edit tags.')); do_action('bb_xmlrpc_call_authenticated', 'bb.removeTopicTags'); // If an error was raised by authentication or by an action then return it if ($this->error) { return $this->error; } // Can be numeric id or slug $topic_id = isset($args[2]) ? $args[2] : false; // Check for bad data if (!$topic_id || !is_string($topic_id) && !is_integer($topic_id)) { $this->error = new IXR_Error(400, __('The topic id is invalid.')); return $this->error; } // Check the requested topic exists if (!($topic = get_topic($topic_id))) { $this->error = new IXR_Error(400, __('No topic found.')); return $this->error; } // The topic id may have been a slug, so make sure it's an integer here $topic_id = (int) $topic->topic_id; // Make sure they are allowed to add tags to this topic if (!bb_current_user_can('add_tag_to', $topic_id)) { $this->error = new IXR_Error(403, __('You do not have permission to remove tags from this topic.')); return $this->error; } $tags = isset($args[3]) ? $args[3] : false; // Check for bad data if (!$tags || !is_string($tags) && !is_array($tags)) { $this->error = new IXR_Error(400, __('The tag data is invalid.')); return $this->error; } // Add the tags if (!bb_remove_topic_tags($topic_id, $tags)) { $this->error = new IXR_Error(500, __('The tags could not be removed.')); return $this->error; } $result = 1; do_action('bb_xmlrpc_call_return', 'bb.removeTopicTags'); // Return the result return $result; }
function bp_forums_update_topic($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('topic_id' => false, 'topic_title' => '', 'topic_text' => '', 'topic_tags' => false); $r = nxt_parse_args($args, $defaults); extract($r, EXTR_SKIP); // Check if the user is a spammer if (bp_core_is_user_spammer($bp->loggedin_user->id) || bp_core_is_user_deleted($bp->loggedin_user->id)) { return false; } // bb_insert_topic() will append tags, but not remove them. So we remove all existing tags. bb_remove_topic_tags($topic_id); if (!($topic_id = bb_insert_topic(array('topic_id' => $topic_id, 'topic_title' => stripslashes($topic_title), 'tags' => $topic_tags)))) { return false; } if (!($post = bb_get_first_post($topic_id))) { return false; } // Update the first post if (!($post = bp_forums_insert_post(array('post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position)))) { return false; } return bp_forums_get_topic_details($topic_id); }