<?php require 'admin-action.php'; $topic_id = (int) $_GET['id']; $topic = get_topic($topic_id); if (!$topic) { bb_die(__('There is a problem with that topic, pardner.')); } if (!bb_current_user_can('close_topic', $topic_id)) { nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); exit; } bb_check_admin_referer('close-topic_' . $topic_id); if (topic_is_open($topic_id)) { bb_close_topic($topic_id); $message = 'closed'; } else { bb_open_topic($topic_id); $message = 'opened'; } if ($sendto = nxt_get_referer()) { $sendto = remove_query_arg('message', $sendto); $sendto = add_query_arg('message', $message, $sendto); } else { $sendto = get_topic_link($topic_id); } bb_safe_redirect($sendto); exit;
/** * Closes a topic * * @since 1.0 * @return integer|object 0 when already changed, 1 when successfully changed 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 closed * @param integer $args[2] 0 closes, 1 opens (optional) * * XML-RPC request to close the topic with slug of "really-old-topic" * <methodCall> * <methodName>bb.closeTopic</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><string>really-old-topic</string></value></param> * </params> * </methodCall> * * XML-RPC request to open the topic with slug of "really-old-topic" * <methodCall> * <methodName>bb.closeTopic</methodName> * <params> * <param><value><string>joeblow</string></value></param> * <param><value><string>123password</string></value></param> * <param><value><string>really-old-topic</string></value></param> * <param><value><integer>1</integer></value></param> * </params> * </methodCall> */ function bb_closeTopic($args) { do_action('bb_xmlrpc_call', 'bb.closeTopic'); // 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, 'close_topics', __('You do not have permission to close topics.')); do_action('bb_xmlrpc_call_authenticated', 'bb.closeTopic'); // 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 close this topic if (!bb_current_user_can('close_topic', $topic_id)) { $this->error = new IXR_Error(403, __('You do not have permission to close this topic.')); return $this->error; } // Open or close? $close = isset($args[3]) ? (int) $args[3] : 0; // Forget it if it's already matching if ($close === (int) $topic->topic_open) { return 0; } // Close the topic if (!$close && !bb_close_topic($topic_id)) { $this->error = new IXR_Error(500, __('The topic could not be closed.')); return $this->error; } // Open the topic if ($close && !bb_open_topic($topic_id)) { $this->error = new IXR_Error(500, __('The topic could not be opened.')); return $this->error; } $result = 1; do_action('bb_xmlrpc_call_return', 'bb.closeTopic'); return $result; }
function bp_forums_openclose_topic($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('topic_id' => false, 'mode' => 'close'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if ('close' == $mode) { return bb_close_topic($topic_id); } else { if ('open' == $mode) { return bb_open_topic($topic_id); } } return false; }
/** * Set a topic's open/closed status. * * @param array $args { * @type int $topic_id ID of the topic whose status is being changed. * @type string $mode New status of the topic. 'open' or 'close'. * Default: 'close'. * } * @return bool True on success, false on failure. */ function bp_forums_openclose_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, 'mode' => 'close')); extract($r, EXTR_SKIP); if ('close' == $mode) { return bb_close_topic($topic_id); } else { if ('open' == $mode) { return bb_open_topic($topic_id); } } return false; }
<?php require_once 'admin.php'; if ('post' == strtolower($_SERVER['REQUEST_METHOD'])) { bb_check_admin_referer('topic-bulk'); $topic_ids = array_map('absint', $_POST['topic']); $affected = 0; $action = trim($_POST['action']); switch ($action) { case 'close': foreach ($topic_ids as $topic_id) { $affected += bb_close_topic($topic_id); } $query_vars = array('message' => 'closed', 'count' => $affected); break; case 'open': foreach ($topic_ids as $topic_id) { $affected += bb_open_topic($topic_id); } $query_vars = array('message' => 'opened', 'count' => $affected); break; case 'delete': foreach ($topic_ids as $topic_id) { $affected += (int) (bool) bb_delete_topic($topic_id, 1); } $query_vars = array('message' => 'deleted', 'count' => $affected); break; case 'undelete': foreach ($topic_ids as $topic_id) { $affected += (int) (bool) bb_delete_topic($topic_id, 0); }