Example #1
0
/**
 * NASTY ALERT, Exact copy of the internal bb_new_forum() function only this one does not check whether the user is allowed to create forums or not
 *
 * @Param: An array containing info for the new forum.
 * @return: The Id of the newly created forum
 * @author: Tom Willmot
 * @version 1.0
 **/
function nm_bb_new_forum($args)
{
    global $bbdb, $bb_cache;
    $defaults = array('forum_name' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => false);
    $args = wp_parse_args($args, $defaults);
    if (1 < func_num_args()) {
        // For back compat
        $args['forum_name'] = func_get_arg(0);
        $args['forum_desc'] = func_get_arg(1);
        $args['forum_order'] = 2 < func_num_args() ? func_get_arg(2) : 0;
    }
    extract($args, EXTR_SKIP);
    if (!is_numeric($forum_order)) {
        $forum_order = (int) $bbdb->get_var("SELECT MAX(forum_order) FROM {$bbdb->forums}") + 1;
    }
    $forum_order = (int) $forum_order;
    $forum_parent = (int) $forum_parent;
    $forum_name = apply_filters('bb_pre_forum_name', stripslashes($forum_name));
    $forum_desc = apply_filters('bb_pre_forum_desc', stripslashes($forum_desc));
    $forum_name = bb_trim_for_db($forum_name, 150);
    $forum_name = $bbdb->escape($forum_name);
    $forum_desc = $bbdb->escape($forum_desc);
    if (strlen($forum_name) < 1) {
        return false;
    }
    $forum_slug = $_forum_slug = bb_slug_sanitize($forum_name);
    while (is_numeric($forum_slug) || ($existing_slug = $bbdb->get_var("SELECT forum_slug FROM {$bbdb->forums} WHERE forum_slug = '{$forum_slug}'"))) {
        $forum_slug = bb_slug_increment($_forum_slug, $existing_slug);
    }
    $bbdb->query("INSERT INTO {$bbdb->forums} (forum_name, forum_slug, forum_desc, forum_parent, forum_order) VALUES ('{$forum_name}', '{$forum_slug}', '{$forum_desc}', '{$forum_parent}', '{$forum_order}')");
    $bb_cache->flush_one('forums');
    return $bbdb->insert_id;
}
function bb_rename_tag($tag_id, $tag_name)
{
    if (!bb_current_user_can('manage_tags')) {
        return false;
    }
    $tag_id = (int) $tag_id;
    $raw_tag = bb_trim_for_db($tag_name, 50);
    $tag_name = tag_sanitize($tag_name);
    if (empty($tag_name)) {
        return false;
    }
    if ($existing_tag = bb_get_tag($tag_name)) {
        if ($existing_tag->term_id !== $tag_id) {
            return false;
        }
    }
    if (!($old_tag = bb_get_tag($tag_id))) {
        return false;
    }
    global $wp_taxonomy_object;
    $ret = $wp_taxonomy_object->update_term($tag_id, 'bb_topic_tag', array('name' => $raw_tag, 'slug' => $tag_name));
    if ($ret && !is_wp_error($ret)) {
        do_action('bb_tag_renamed', $tag_id, $old_tag->raw_tag, $raw_tag);
        return bb_get_tag($tag_id);
    }
    return false;
}
function bb_trim_for_db_150($string)
{
    return bb_trim_for_db($string, 150);
}