function bp_forums_update_forum($args = '') { do_action('bbpress_init'); $r = wp_parse_args($args, array('forum_id' => '', 'forum_name' => '', 'forum_desc' => '', 'forum_slug' => '', 'forum_parent_id' => bp_forums_parent_forum_id(), 'forum_order' => false, 'forum_is_category' => 0)); extract($r, EXTR_SKIP); return bb_update_forum(array('forum_id' => (int) $forum_id, 'forum_name' => stripslashes($forum_name), 'forum_desc' => stripslashes($forum_desc), 'forum_slug' => stripslashes($forum_slug), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category)); }
} bb_check_admin_referer('add-forum'); if (false !== bb_new_forum($_POST)) { bb_safe_redirect($sent_from); exit; } else { bb_die(__('The forum was not added')); } break; case 'update': bb_check_admin_referer('update-forum'); if (!($forums = bb_get_forums())) { bb_die(__('No forums to update!')); } if ((int) $_POST['forum_id'] && isset($_POST['forum_name']) && '' !== $_POST['forum_name']) { bb_update_forum($_POST); } foreach (array('action', 'id') as $arg) { $sent_from = remove_query_arg($arg, $sent_from); } bb_safe_redirect(add_query_arg('message', 'updated', $sent_from)); exit; break; case 'delete': bb_check_admin_referer('delete-forums'); $forum_id = (int) $_POST['forum_id']; $move_topics_forum = (int) $_POST['move_topics_forum']; if (!bb_current_user_can('delete_forum', $forum_id)) { bb_die(__("You don't have the authority to kill off the forums.")); } if (isset($_POST['move_topics']) && $_POST['move_topics'] != 'delete') {
/** * Edits an existing forum * * @since 1.0 * @return array|object The forum data when successfully edited 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 array $args[2] The values for the various settings in the new forum, at least one must be specified * @param integer|string $args[2]['forum_id'] The unique id of the forum to be edited * @param string $args[2]['name'] The name of the forum (optional) * @param string $args[2]['slug'] The slug for the forum (optional) * @param string $args[2]['description'] The description of the forum (optional) * @param integer $args[2]['parent_id'] The unique id of the parent forum for this forum (optional) * @param integer $args[2]['order'] The position of the forum in the forum list (optional) * @param integer $args[2]['is_category'] Whether the forum is simply a container category (optional) * * XML-RPC request to edit a forum with id 11, changing the description * <methodCall> * <methodName>bb.editForum</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><struct> * <member> * <name>forum_id</name> * <value><integer>11</integer></value> * </member> * <member> * <name>description</name> * <value><string>This is a great forum for all sorts of reasons.</string></value> * </member> * </struct></value></param> * </params> * </methodCall> */ function bb_editForum($args) { do_action('bb_xmlrpc_call', 'bb.editForum'); // 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, 'manage_forums', __('You do not have permission to manage forums.')); do_action('bb_xmlrpc_call_authenticated', 'bb.editForum'); // If an error was raised by authentication or by an action then return it if ($this->error) { return $this->error; } // Make sure there is something for us to do if (!$args[2] || !is_array($args[2]) || !count($args[2])) { $this->error = new IXR_Error(400, __('The forum data is invalid.')); return $this->error; } $structure = (array) $args[2]; // Can be numeric id or slug $forum_id = isset($structure['forum_id']) ? $structure['forum_id'] : 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 forum exists if (!($forum = bb_get_forum($forum_id))) { $this->error = new IXR_Error(400, __('No forum found.')); return $this->error; } // Cast the forum object as an array $forum = (array) $forum; // The forum id may have been a slug, so make sure it's an integer here $forum_id = (int) $forum['forum_id']; // Remove some unneeded indexes unset($forum['topics']); unset($forum['posts']); // Add one if it isn't there if (!isset($forum['forum_is_category'])) { $forum['forum_is_category'] = 0; } // Validate the name for the forum if (isset($structure['name']) && !$structure['name']) { $this->error = new IXR_Error(400, __('The forum name is invalid.')); return $this->error; } // Inject structure into an array suitable for bb_update_forum() $bb_update_forum_args = array('forum_name' => $structure['name']); // Slug cannot be blank if (isset($structure['slug']) && $structure['slug'] !== '') { $bb_update_forum_args['forum_slug'] = $structure['slug']; } // Description can be nothing if (isset($structure['description'])) { $bb_update_forum_args['forum_desc'] = $structure['description']; } // Parent forum ID must be an integer and it can be 0 if (isset($structure['parent_id']) && is_integer($structure['parent_id'])) { $bb_update_forum_args['forum_parent'] = $structure['parent_id']; } // Order must be an integer and it can be 0 if (isset($structure['order']) && is_integer($structure['order'])) { $bb_update_forum_args['forum_order'] = $structure['order']; } // Category flag must be an integer and it can be 0 if (isset($structure['is_category']) && is_integer($structure['is_category'])) { $bb_update_forum_args['forum_is_category'] = $structure['is_category']; } // Merge the changes into the existing data for the forum $bb_update_forum_args = nxt_parse_args($bb_update_forum_args, $forum); // Leave the require until the very end require_once BB_PATH . 'bb-admin/includes/functions.bb-admin.php'; // Update the forum if (!bb_update_forum($bb_update_forum_args)) { $this->error = new IXR_Error(500, __('The forum could not be edited.')); return $this->error; } // Only include "safe" data in the array $forum = $this->prepare_forum(bb_get_forum($forum_id)); do_action('bb_xmlrpc_call_return', 'bb.editForum'); return $forum; }
if (!bb_current_user_can('manage_forums')) { die('-1'); } bb_check_ajax_referer($action); if (!is_array($_POST['order'])) { die('0'); } global $bbdb; $forums = array(); bb_get_forums(); // cache foreach ($_POST['order'] as $pos => $forum_id) { $forum = $bbdb->escape_deep(get_object_vars(bb_get_forum($forum_id))); $forum['forum_order'] = $pos; $forums[(int) $forum_id] = $forum; } foreach ($_POST['root'] as $root => $ids) { foreach ($ids as $forum_id) { $forums[(int) $forum_id]['forum_parent'] = (int) $root; } } foreach ($forums as $forum) { bb_update_forum($forum); } die('1'); break; default: do_action('bb_ajax_' . $_POST['action']); break; } die('0');