/** * Sticks a topic to the top of a forum or the front page * * @since 1.0 * @return integer|object 0 if it is already stuck to the desired location, 1 when successfully stuck 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 stuck * @param integer $args[3] 0 unsticks, 1 sticks, 2 sticks to front (optional) * * XML-RPC request to stick the topic with id of 34 to the front page * <methodCall> * <methodName>bb.stickTopic</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><integer>1</integer></value></param> * </params> * </methodCall> */ function bb_stickTopic($args) { do_action('bb_xmlrpc_call', 'bb.stickTopic'); // 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, 'stick_topics', __('You do not have permission to stick topics.')); do_action('bb_xmlrpc_call_authenticated', 'bb.stickTopic'); // 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 stick this topic if (!bb_current_user_can('stick_topic', $topic_id)) { $this->error = new IXR_Error(403, __('You do not have permission to stick this topic.')); return $this->error; } // Stick to where? $where = isset($args[3]) ? (int) $args[3] : 1; // Forget it if it's already there if ($where === (int) $topic->topic_sticky) { return 0; } // Stick the topic if (!bb_stick_topic($topic_id, $where)) { $this->error = new IXR_Error(500, __('The topic could not be stuck.')); return $this->error; } $result = 1; do_action('bb_xmlrpc_call_return', 'bb.stickTopic'); return $result; }
<?php require 'admin-action.php'; $topic_id = (int) $_GET['id']; $topic = get_topic($topic_id); $super = isset($_GET['super']) && 1 == (int) $_GET['super'] ? 1 : 0; if (!$topic) { bb_die(__('There is a problem with that topic, pardner.')); } if (!bb_current_user_can('stick_topic', $topic_id)) { wp_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER)); exit; } bb_check_admin_referer('stick-topic_' . $topic_id); if (topic_is_sticky($topic_id)) { bb_unstick_topic($topic_id); } else { bb_stick_topic($topic_id, $super); } if (!($redirect = wp_get_referer())) { $redirect = get_topic_link($topic_id); } bb_safe_redirect($redirect); exit;
function bp_forums_sticky_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' => 'stick')); extract($r, EXTR_SKIP); if ('stick' == $mode) { return bb_stick_topic($topic_id); } else { if ('unstick' == $mode) { return bb_unstick_topic($topic_id); } } return false; }
function bp_forums_sticky_topic($args = '') { global $bp; do_action('bbpress_init'); $defaults = array('topic_id' => false, 'mode' => 'stick'); $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); if ('stick' == $mode) { return bb_stick_topic($topic_id); } else { if ('unstick' == $mode) { return bb_unstick_topic($topic_id); } } return false; }