コード例 #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;
}
コード例 #2
0
 function bb_new_user($user_login, $user_email, $user_url, $user_status = 0)
 {
     global $wp_users_object, $bbdb;
     // is_email check + dns
     if (!($user_email = bb_verify_email($user_email))) {
         return new WP_Error('user_email', __('Invalid email address'), $user_email);
     }
     if (!($user_login = sanitize_user($user_login, true))) {
         return new WP_Error('user_login', __('Invalid username'), $user_login);
     }
     // user_status = 1 means the user has not yet been verified
     $user_status = is_numeric($user_status) ? (int) $user_status : 0;
     $user_nicename = $_user_nicename = bb_user_nicename_sanitize($user_login);
     if (strlen($_user_nicename) < 1) {
         return new WP_Error('user_login', __('Invalid username'), $user_login);
     }
     while (is_numeric($user_nicename) || ($existing_user = bb_get_user_by_nicename($user_nicename))) {
         $user_nicename = bb_slug_increment($_user_nicename, $existing_user->user_nicename, 50);
     }
     $user_url = bb_fix_link($user_url);
     $user_registered = bb_current_time('mysql');
     $password = wp_generate_password();
     $user_pass = wp_hash_password($password);
     $user = $wp_users_object->new_user(compact('user_login', 'user_email', 'user_url', 'user_nicename', 'user_status', 'user_pass'));
     if (is_wp_error($user)) {
         if ('user_nicename' == $user->get_error_code()) {
             return new WP_Error('user_login', $user->get_error_message());
         }
         return $user;
     }
     $user_id = $bbdb->insert_id;
     $options = bb_get_option('approve_user_registration_options');
     bb_update_usermeta($user_id, $bbdb->prefix . 'capabilities', array('waitingapproval' => true, 'member' => true));
     approve_user_registration_send_pass($user_id, $password);
     do_action('bb_new_user', $user['ID'], $user['plain_pass']);
     return $user['ID'];
 }
コード例 #3
0
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;
}
コード例 #4
0
function bb_upgrade_1020()
{
    if (($dbv = bb_get_option_from_db('bb_db_version')) && $dbv >= 977) {
        return;
    }
    global $bbdb;
    $users = $bbdb->get_results("SELECT ID, user_login, user_nicename FROM {$bbdb->users} WHERE user_nicename IS NULL OR user_nicename = ''");
    if ($users) {
        foreach ($users as $user) {
            $user_nicename = $_user_nicename = bb_user_nicename_sanitize($user->user_login);
            while (is_numeric($user_nicename) || ($existing_user = bb_get_user_by_nicename($user_nicename))) {
                $user_nicename = bb_slug_increment($_user_nicename, $existing_user->user_nicename, 50);
            }
            $bbdb->query("UPDATE {$bbdb->users} SET user_nicename = '{$user_nicename}' WHERE ID = {$user->ID};");
        }
    }
    bb_update_option('bb_db_version', 977);
    return 'Done adding nice-names to existing users: ' . __FUNCTION__;
}
コード例 #5
0
function bb_update_forum($args)
{
    global $bbdb;
    if (!bb_current_user_can('manage_forums')) {
        return false;
    }
    $defaults = array('forum_id' => 0, 'forum_name' => '', 'forum_slug' => '', 'forum_desc' => '', 'forum_parent' => 0, 'forum_order' => 0, 'forum_is_category' => 0);
    $fields = array('forum_name', 'forum_desc', 'forum_parent', 'forum_order');
    $args = nxt_parse_args($args, $defaults);
    if (1 < func_num_args()) {
        // For back compat
        $args['forum_id'] = func_get_arg(0);
        $args['forum_name'] = func_get_arg(1);
        $args['forum_desc'] = 2 < func_num_args() ? func_get_arg(2) : '';
        $args['forum_order'] = 3 < func_num_args() && is_numeric(func_get_arg(3)) ? func_get_arg(3) : 0;
    }
    extract($args, EXTR_SKIP);
    if (!($forum_id = (int) $forum_id)) {
        return false;
    }
    if (!($forum = bb_get_forum($forum_id))) {
        return false;
    }
    $forum_order = (int) $forum_order;
    $forum_parent = (int) $forum_parent;
    $forum_is_category = (int) $forum_is_category;
    $forum_name = apply_filters('bb_pre_forum_name', stripslashes(nxt_specialchars_decode($forum_name, ENT_QUOTES)), $forum_id);
    $forum_desc = apply_filters('bb_pre_forum_desc', stripslashes($forum_desc), $forum_id);
    if (strlen($forum_name) < 1) {
        return false;
    }
    // Slug is not changing, don't update it
    if (!$forum_slug || $forum_slug == $forum->forum_slug) {
        // [sic]
    } else {
        $forum_slug = $_forum_slug = bb_slug_sanitize($forum_slug);
        if (strlen($_forum_slug) < 1) {
            return false;
        }
        $forum_sql = "SELECT forum_slug FROM {$bbdb->forums} WHERE forum_slug = %s";
        while (is_numeric($forum_slug) || ($existing_slug = $bbdb->get_var($bbdb->prepare($forum_sql, $forum_slug)))) {
            $forum_slug = bb_slug_increment($_forum_slug, $existing_slug);
        }
        $fields[] = 'forum_slug';
    }
    nxt_cache_delete($forum_id, 'bb_forum');
    nxt_cache_flush('bb_forums');
    $update_result = $bbdb->update($bbdb->forums, compact($fields), compact('forum_id'));
    if ($forum_is_category) {
        bb_update_forummeta($forum_id, 'forum_is_category', $forum_is_category);
    } else {
        bb_delete_forummeta($forum_id, 'forum_is_category');
    }
    return $update_result;
}
コード例 #6
0
 function bb_new_user($user_login, $user_email, $user_url, $user_status = 1)
 {
     global $wp_users_object, $bbdb;
     // is_email check + dns
     if (!($user_email = is_email($user_email))) {
         return new WP_Error('user_email', __('Invalid email address'), $user_email);
     }
     if (!($user_login = sanitize_user($user_login, true))) {
         return new WP_Error('user_login', __('Invalid username'), $user_login);
     }
     // user_status = 1 means the user has not yet been verified
     $user_status = is_numeric($user_status) ? (int) $user_status : 1;
     if (defined('BB_INSTALLING')) {
         $user_status = 0;
     }
     $user_nicename = $_user_nicename = bb_user_nicename_sanitize($user_login);
     if (strlen($_user_nicename) < 1) {
         return new WP_Error('user_login', __('Invalid username'), $user_login);
     }
     while (is_numeric($user_nicename) || ($existing_user = bb_get_user_by_nicename($user_nicename))) {
         $user_nicename = bb_slug_increment($_user_nicename, $existing_user->user_nicename, 50);
     }
     $user_url = $user_url ? bb_fix_link($user_url) : '';
     $user_pass = bb_generate_password();
     $user = $wp_users_object->new_user(compact('user_login', 'user_email', 'user_url', 'user_nicename', 'user_status', 'user_pass'));
     if (is_wp_error($user)) {
         if ('user_nicename' == $user->get_error_code()) {
             return new WP_Error('user_login', $user->get_error_message());
         }
         return $user;
     }
     if (BB_INSTALLING) {
         bb_update_usermeta($user['ID'], $bbdb->prefix . 'capabilities', array('keymaster' => true));
     } else {
         bb_update_usermeta($user['ID'], $bbdb->prefix . 'capabilities', array('member' => true));
         bb_send_pass($user['ID'], $user['plain_pass']);
     }
     do_action('bb_new_user', $user['ID'], $user['plain_pass']);
     return $user['ID'];
 }