/** * Moves a topic to a different forum * * @since 1.0 * @return integer|object the forum id where the topic lives after the method is called 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 integer|string $args[2] The unique id of the topic to be moved * @param integer|string $args[3] The unique id of the forum to be moved to * * XML-RPC request to move the topic with id of 34 to forum with slug of "better-forum" * <methodCall> * <methodName>bb.moveTopic</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><integer>34</integer></value></param> * <param><value><string>better-forum</string></value></param> * </params> * </methodCall> */ function bb_moveTopic($args) { do_action('bb_xmlrpc_call', 'bb.moveTopic'); // 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, 'move_topics', __('You do not have permission to move topics.')); do_action('bb_xmlrpc_call_authenticated', 'bb.moveTopic'); // 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; // Can be numeric id or slug $forum_id = isset($args[3]) ? $args[3] : false; // Check for bad data if (!$forum_id || !is_string($forum_id) && !is_integer($forum_id)) { $this->error = new IXR_Error(400, __('The forum id is invalid.')); return $this->error; } // Check the requested topic exists if (!($forum = bb_get_forum($forum_id))) { $this->error = new IXR_Error(400, __('No forum found.')); return $this->error; } // The forum id may have been a slug, so make sure it's an integer here $forum_id = (int) $forum->forum_id; // Only move it if it isn't already there if ($forum_id !== (int) $topic->forum_id) { // Make sure they are allowed to move this topic specifically to this forum if (!bb_current_user_can('move_topic', $topic_id, $forum_id)) { $this->error = new IXR_Error(403, __('You are not allowed to move this topic to this forum.')); return $this->error; } // Move the topic if (!bb_move_topic($topic_id, $forum_id)) { $this->error = new IXR_Error(500, __('The topic could not be moved.')); return $this->error; } } do_action('bb_xmlrpc_call_return', 'bb.moveTopic'); return $forum_id; }
<?php require_once 'admin-action.php'; $topic_id = absint($_POST['topic_id']); $forum_id = absint($_POST['forum_id']); if (!is_numeric($topic_id) || !is_numeric($forum_id)) { bb_die(__('Invalid topic or forum.')); } if (!bb_current_user_can('move_topic', $topic_id, $forum_id)) { nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); exit; } bb_check_admin_referer('move-topic_' . $topic_id); $topic = get_topic($topic_id); $forum = bb_get_forum($forum_id); if (!$topic || !$forum) { bb_die(__('Your topic or forum caused all manner of confusion')); } bb_move_topic($topic_id, $forum_id); if (!($redirect = nxt_get_referer())) { $redirect = get_topic_link($topic_id); } bb_safe_redirect($redirect); exit;