/**
 * bb_add_topic_tag() - Adds a single tag to a topic.
 *
 * @param int $topic_id
 * @param string $tag The (unsanitized) full name of the tag to be added
 * @return int|bool The TT_ID of the new bb_topic_tag or false on failure
 */
function bb_add_topic_tag($topic_id, $tag)
{
    $tt_ids = bb_add_topic_tags($topic_id, $tag);
    if (is_array($tt_ids)) {
        return $tt_ids[0];
    }
    return false;
}
function bb_insert_topic($args = null)
{
    global $bbdb;
    if (!($args = wp_parse_args($args))) {
        return false;
    }
    $fields = array_keys($args);
    if (isset($args['topic_id']) && false !== $args['topic_id']) {
        $update = true;
        if (!($topic_id = (int) get_topic_id($args['topic_id']))) {
            return false;
        }
        // Get from db, not cache.  Good idea?  Prevents trying to update meta_key names in the topic table (get_topic() returns appended topic obj)
        $topic = $bbdb->get_row($bbdb->prepare("SELECT * FROM {$bbdb->topics} WHERE topic_id = %d", $topic_id));
        $defaults = get_object_vars($topic);
        unset($defaults['topic_id']);
        // Only update the args we passed
        $fields = array_intersect($fields, array_keys($defaults));
        if (in_array('topic_poster', $fields)) {
            $fields[] = 'topic_poster_name';
        }
        if (in_array('topic_last_poster', $fields)) {
            $fields[] = 'topic_last_poster_name';
        }
    } else {
        $topic_id = false;
        $update = false;
        $now = bb_current_time('mysql');
        $current_user_id = bb_get_current_user_info('id');
        $defaults = array('topic_title' => '', 'topic_slug' => '', 'topic_poster' => $current_user_id, 'topic_poster_name' => '', 'topic_last_poster' => $current_user_id, 'topic_last_poster_name' => '', 'topic_start_time' => $now, 'topic_time' => $now, 'topic_open' => 1, 'forum_id' => 0);
        // Insert all args
        $fields = array_keys($defaults);
    }
    $defaults['tags'] = false;
    // accepts array or comma delimited string
    extract(wp_parse_args($args, $defaults));
    unset($defaults['tags']);
    if (!($forum = bb_get_forum($forum_id))) {
        return false;
    }
    $forum_id = (int) $forum->forum_id;
    if (!($user = bb_get_user($topic_poster))) {
        $user = bb_get_user($topic_poster_name, array('by' => 'login'));
    }
    if (!empty($user)) {
        $topic_poster = $user->ID;
        $topic_poster_name = $user->user_login;
    }
    if (!($last_user = bb_get_user($topic_last_poster))) {
        $last_user = bb_get_user($topic_last_poster_name, array('by' => 'login'));
    }
    if (!empty($last_user)) {
        $topic_last_poster = $last_user->ID;
        $topic_last_poster_name = $last_user->user_login;
    }
    if (in_array('topic_title', $fields)) {
        $topic_title = apply_filters('pre_topic_title', $topic_title, $topic_id);
        if (strlen($topic_title) < 1) {
            return false;
        }
    }
    if (in_array('topic_slug', $fields)) {
        $slug_sql = $update ? "SELECT topic_slug FROM {$bbdb->topics} WHERE topic_slug = %s AND topic_id != %d" : "SELECT topic_slug FROM {$bbdb->topics} WHERE topic_slug = %s";
        $topic_slug = $_topic_slug = bb_slug_sanitize($topic_slug ? $topic_slug : wp_specialchars_decode($topic_title, ENT_QUOTES));
        if (strlen($_topic_slug) < 1) {
            $topic_slug = $_topic_slug = '0';
        }
        while (is_numeric($topic_slug) || ($existing_slug = $bbdb->get_var($bbdb->prepare($slug_sql, $topic_slug, $topic_id)))) {
            $topic_slug = bb_slug_increment($_topic_slug, $existing_slug);
        }
    }
    if ($update) {
        $bbdb->update($bbdb->topics, compact($fields), compact('topic_id'));
        wp_cache_delete($topic_id, 'bb_topic');
        if (in_array('topic_slug', $fields)) {
            wp_cache_delete($topic->topic_slug, 'bb_topic_slug');
        }
        wp_cache_flush('bb_query');
        wp_cache_flush('bb_cache_posts_post_ids');
        do_action('bb_update_topic', $topic_id);
    } else {
        $bbdb->insert($bbdb->topics, compact($fields));
        $topic_id = $bbdb->insert_id;
        $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1 WHERE forum_id = %d", $forum_id));
        wp_cache_delete($forum_id, 'bb_forum');
        wp_cache_flush('bb_forums');
        wp_cache_flush('bb_query');
        wp_cache_flush('bb_cache_posts_post_ids');
        do_action('bb_new_topic', $topic_id);
    }
    if (!empty($tags)) {
        bb_add_topic_tags($topic_id, $tags);
    }
    do_action('bb_insert_topic', $topic_id, $args, compact(array_keys($args)));
    // topic_id, what was passed, what was used
    return $topic_id;
}
Exemple #3
0
<?php

require './bb-load.php';
bb_auth('logged_in');
if (!bb_is_user_logged_in()) {
    bb_die(__('You need to be logged in to add a tag.'));
}
$topic_id = (int) @$_POST['id'];
$page = (int) @$_POST['page'];
$tag = @$_POST['tag'];
$tag = stripslashes($tag);
bb_check_admin_referer('add-tag_' . $topic_id);
$topic = get_topic($topic_id);
if (!$topic) {
    bb_die(__('Topic not found.'));
}
if (bb_add_topic_tags($topic_id, $tag)) {
    wp_redirect(get_topic_link($topic_id, $page));
} else {
    bb_die(__('The tag was not added.  Either the tag name was invalid or the topic is closed.'));
}
exit;
Exemple #4
0
 /**
  * Adds the specified tags to the specified topic
  *
  * @since 1.0
  * @return array|object The tags which were added 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 string|integer $args[2] The topic id or slug
  * @param string|array $args[3] The tags to add to the topic
  *
  * XML-RPC request to add the tag "banana" to the topic with id 219
  * <methodCall>
  *     <methodName>bb.addTopicTags</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><int>219</int></value></param>
  *         <param><value><string>banana</string></value></param>
  *     </params>
  * </methodCall>
  *
  * XML-RPC request to add the tags "banana" and "man" to the topic with id 219
  * <methodCall>
  *     <methodName>bb.addTopicTags</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><int>219</int></value></param>
  *         <param><value><string>banana, man</string></value></param>
  *     </params>
  * </methodCall>
  *
  * XML-RPC request to add the tags "banana" and "man" to the topic with id 219 using an array
  * <methodCall>
  *     <methodName>bb.addTopicTags</methodName>
  *     <params>
  *         <param><value><string>joeblow</string></value></param>
  *         <param><value><string>123password</string></value></param>
  *         <param><value><int>219</int></value></param>
  *         <param><value><array>
  *             <data><value><string>banana</string></value></data>
  *             <data><value><string>man</string></value></data>
  *         </array></value></param>
  *     </params>
  * </methodCall>
  */
 function bb_addTopicTags($args)
 {
     do_action('bb_xmlrpc_call', 'bb.addTopicTags');
     // 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, 'edit_tags', __('You do not have permission to edit tags.'));
     do_action('bb_xmlrpc_call_authenticated', 'bb.addTopicTags');
     // 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 add tags to this topic
     if (!bb_current_user_can('add_tag_to', $topic_id)) {
         $this->error = new IXR_Error(403, __('You do not have permission to add tags to this topic.'));
         return $this->error;
     }
     $tags = isset($args[3]) ? $args[3] : false;
     // Check for bad data
     if (!$tags || !is_string($tags) && !is_array($tags)) {
         $this->error = new IXR_Error(400, __('The tag data is invalid.'));
         return $this->error;
     }
     // Add the tags
     if (!($tag_ids = bb_add_topic_tags($topic_id, $tags))) {
         $this->error = new IXR_Error(500, __('The tags could not be added.'));
         return $this->error;
     }
     // Only include "safe" data in the array
     $_tags = array();
     foreach ($tag_ids as $tag_id) {
         $_tags[] = $this->prepare_topic_tag(bb_get_tag($tag_id));
     }
     do_action('bb_xmlrpc_call_return', 'bb.addTopicTags');
     // Return the tags which were added as an array
     return $_tags;
 }
function add_topic_tags($topic_id, $tags)
{
    bb_log_deprecated('function', __FUNCTION__, 'bb_add_topic_tags');
    return bb_add_topic_tags($topic_id, $tags);
}
Exemple #6
0
    $topic_id = (int) $_POST['topic_id'];
    bb_check_admin_referer('create-post_' . $topic_id);
}
if (bb_is_login_required() && !bb_current_user_can('write_post', $topic_id)) {
    bb_die(__('You are not allowed to post.  Are you logged in?'));
}
if (!topic_is_open($topic_id)) {
    bb_die(__('This topic has been closed'));
}
$post_data = array('post_text' => stripslashes($_POST['post_content']), 'topic_id' => $topic_id);
foreach (array('post_author', 'post_email', 'post_url') as $field) {
    if (!empty(${$field})) {
        $post_data[$field] = ${$field};
    }
}
$post_id = bb_insert_post($post_data);
$tags = trim($_POST['tags']);
bb_add_topic_tags($topic_id, $tags);
$topic = get_topic($topic_id, false);
$link = get_post_link($post_id);
if ($topic->topic_posts) {
    $link = add_query_arg('replies', $topic->topic_posts, $link);
}
// This action used to be bb_post.php, changed to avoid conflict in bb_load_template()
do_action('bb-post.php', $post_id);
if ($post_id) {
    nxt_redirect($link);
} else {
    nxt_redirect(bb_get_uri(null, null, BB_URI_CONTEXT_HEADER));
}
exit;
Exemple #7
0
     if (!bb_current_user_can('edit_tag_by_on', $bb_current_id, $id)) {
         die('-1');
     }
     bb_check_ajax_referer("add-tag_{$id}");
     global $tag, $topic;
     add_action('bb_tag_added', 'bb_grab_results', 10, 3);
     add_action('bb_already_tagged', 'bb_grab_results', 10, 3);
     $tag_name = @$_POST['tag'];
     $tag_name = stripslashes($tag_name);
     $topic = get_topic($id);
     if (!$topic) {
         die('0');
     }
     $tag_name = rawurldecode($tag_name);
     $x = new WP_Ajax_Response();
     foreach (bb_add_topic_tags($id, $tag_name) as $tag_id) {
         if (!is_numeric($tag_id) || !($tag = bb_get_tag((int) $tag_id, bb_get_current_user_info('id'), $topic->topic_id))) {
             if (!($tag = bb_get_tag($tag_id))) {
                 continue;
             }
         }
         $tag->user_id = bb_get_current_user_info('id');
         $tag_id_val = $tag->tag_id . '_' . $tag->user_id;
         $tag->raw_tag = esc_attr($tag->raw_tag);
         $x->add(array('what' => 'tag', 'id' => $tag_id_val, 'data' => _bb_list_tag_item($tag, array('list_id' => 'tags-list', 'format' => 'list'))));
     }
     $x->send();
     break;
 case 'delete-tag':
     list($tag_id, $user_id) = explode('_', $_POST['id']);
     $tag_id = (int) $tag_id;
/**
 * Custom insert topic function so that we could do what we need
 *
 * All counting functions have been removed from here, recount should be done
 * after running this script. Update topic things have also been removed.
 *
 * @param mixed $args
 * @return int|bool New topic ID if post was created, otherwise false
 */
function w2bc_insert_topic($args = null)
{
    global $bbdb;
    if (!($args = wp_parse_args($args))) {
        return false;
    }
    $fields = array_keys($args);
    $topic_id = false;
    $update = false;
    $now = bb_current_time('mysql');
    $current_user_id = bb_get_current_user_info('id');
    $defaults = array('topic_title' => '', 'topic_slug' => '', 'topic_poster' => $current_user_id, 'topic_poster_name' => '', 'topic_last_poster' => $current_user_id, 'topic_last_poster_name' => '', 'topic_start_time' => $now, 'topic_time' => $now, 'topic_open' => 1, 'forum_id' => 1);
    // Insert all args
    $fields = array_keys($defaults);
    $defaults['tags'] = false;
    // accepts array or comma delimited string
    extract(wp_parse_args($args, $defaults));
    unset($defaults['tags']);
    $forum_id = (int) $forum_id;
    if (bb_is_user_logged_in() || bb_is_login_required()) {
        if (!($user = bb_get_user($topic_poster))) {
            if (!($user = bb_get_user($topic_poster_name, array('by' => 'login')))) {
                return false;
            }
        }
        $topic_poster = $topic_last_poster = $user->ID;
        $topic_poster_name = $topic_last_poster_name = $user->user_login;
    }
    if (in_array('topic_title', $fields)) {
        $topic_title = stripslashes($topic_title);
        $topic_title = apply_filters('pre_topic_title', $topic_title, $topic_id);
        if (strlen($topic_title) < 1) {
            return false;
        }
    }
    if (in_array('topic_slug', $fields)) {
        $topic_slug = $_topic_slug = bb_slug_sanitize($topic_slug ? $topic_slug : wp_specialchars_decode($topic_title, ENT_QUOTES));
        if (strlen($_topic_slug) < 1) {
            $topic_slug = $_topic_slug = '0';
        }
        if ($slug = $bbdb->get_var($bbdb->prepare("SELECT topic_slug FROM {$bbdb->topics} WHERE topic_slug = %s", $topic_slug))) {
            echo "<li>A topic with the slug <em>{$slug}</em> already exists and hence to prevent duplicate topics, the topic wasn't added.";
            return false;
        }
    }
    $bbdb->insert($bbdb->topics, compact($fields));
    $topic_id = $bbdb->insert_id;
    wp_cache_delete($forum_id, 'bb_forum');
    wp_cache_flush('bb_forums');
    wp_cache_flush('bb_query');
    wp_cache_flush('bb_cache_posts_post_ids');
    do_action('bb_new_topic', $topic_id);
    if ($tags = stripslashes($tags)) {
        bb_add_topic_tags($topic_id, $tags);
    }
    do_action('bb_insert_topic', $topic_id, $args, compact(array_keys($args)));
    // topic_id, what was passed, what was used
    return $topic_id;
}