Example #1
0
 /**
  * Returns the tags in a given topic or all tags
  *
  * @since 1.0
  * @return integer|object The tag data 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 integer|string $args[2] The topic id or slug (optional)
  *
  * XML-RPC request to get all tags in the topic with slug "woot-frist-topic"
  * <methodCall>
  *     <methodName>bb.getTopicTags</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><string>woot-frist-topic</string></value></param>
  *     </params>
  * </methodCall>
  */
 function bb_getTopicTags($args)
 {
     do_action('bb_xmlrpc_call', 'bb.getTopicTags');
     // Escape args
     $this->escape($args);
     // Get the login credentials
     $username = $args[0];
     $password = (string) $args[1];
     // Check the user is valid
     if ($this->auth_readonly) {
         $user = $this->authenticate($username, $password);
     }
     do_action('bb_xmlrpc_call_authenticated', 'bb.getTopicTags');
     // 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) {
         if (!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;
         // Now get the tags
         if (!($tags = bb_get_topic_tags($topic_id))) {
             $this->error = new IXR_Error(500, __('No topic tags found.'));
             return $this->error;
         }
     } else {
         global $nxt_taxonomy_object;
         $tags = $nxt_taxonomy_object->get_terms('bb_topic_tag', array('get' => 'all'));
         if (is_nxt_error($tags)) {
             $this->error = new IXR_Error(500, __('Could not retrieve all topic tags.'));
             return $this->error;
         }
         for ($i = 0; isset($tags[$i]); $i++) {
             _bb_make_tag_compat($tags[$i]);
         }
     }
     // Only include "safe" data in the array
     $_tags = array();
     foreach ($tags as $tag) {
         $_tags[] = $this->prepare_topic_tag($tag);
     }
     do_action('bb_xmlrpc_call_return', 'bb.getTopicTags');
     // Return the tags
     return $_tags;
 }
Example #2
0
function bb_tag_search($args = '')
{
    global $page, $nxt_taxonomy_object;
    if ($args && is_string($args) && false === strpos($args, '=')) {
        $args = array('search' => $args);
    }
    $defaults = array('search' => '', 'number' => false);
    $args = nxt_parse_args($args);
    if (isset($args['query'])) {
        $args['search'] = $args['query'];
    }
    if (isset($args['tags_per_page'])) {
        $args['number'] = $args['tags_per_page'];
    }
    unset($args['query'], $args['tags_per_page']);
    $args = nxt_parse_args($args, $defaults);
    extract($args, EXTR_SKIP);
    $number = (int) $number;
    $search = trim($search);
    if (strlen($search) < 3) {
        return new nxt_Error('invalid-query', __('Your search term was too short'));
    }
    $number = 0 < $number ? $number : bb_get_option('page_topics');
    if (1 < $page) {
        $offset = (intval($page) - 1) * $number;
    }
    $args = array_merge($args, compact('number', 'offset', 'search'));
    $terms = $nxt_taxonomy_object->get_terms('bb_topic_tag', $args);
    if (is_nxt_error($terms)) {
        return false;
    }
    for ($i = 0; isset($terms[$i]); $i++) {
        _bb_make_tag_compat($terms[$i]);
    }
    return $terms;
}
/**
 * bb_get_top_tags() - Returns most popular tags.
 *
 * @param mixed $args
 * @return array|false Term objects (back-compat), false on failure
 */
function bb_get_top_tags($args = null)
{
    global $wp_taxonomy_object;
    $args = wp_parse_args($args, array('number' => 40));
    $args['order'] = 'DESC';
    $args['orderby'] = 'count';
    $terms = $wp_taxonomy_object->get_terms('bb_topic_tag', $args);
    if (is_wp_error($terms)) {
        return false;
    }
    foreach ($terms as $term) {
        _bb_make_tag_compat($term);
    }
    return $terms;
}