コード例 #1
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'];
 }
コード例 #2
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__;
}
コード例 #3
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'];
 }
コード例 #4
0
function bb_repermalink()
{
    global $page;
    $location = bb_get_location();
    $uri = $_SERVER['REQUEST_URI'];
    if (isset($_GET['id'])) {
        $id = $_GET['id'];
    } else {
        $id = bb_get_path();
    }
    $_original_id = $id;
    do_action('pre_permalink', $id);
    $id = apply_filters('bb_repermalink', $id);
    switch ($location) {
        case 'front-page':
            $path = null;
            $querystring = null;
            if ($page > 1) {
                if (bb_get_option('mod_rewrite')) {
                    $path = 'page/' . $page;
                } else {
                    $querystring = array('page' => $page);
                }
            }
            $permalink = bb_get_uri($path, $querystring, BB_URI_CONTEXT_HEADER);
            $issue_404 = true;
            break;
        case 'forum-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $forum_id, $forum;
            $forum = bb_get_forum($id);
            $forum_id = $forum->forum_id;
            $permalink = get_forum_link($forum->forum_id, $page);
            break;
        case 'topic-edit-page':
        case 'topic-page':
            if (empty($id)) {
                $permalink = bb_get_uri(null, null, BB_URI_CONTEXT_HEADER);
                break;
            }
            global $topic_id, $topic;
            $topic = get_topic($id);
            $topic_id = $topic->topic_id;
            $permalink = get_topic_link($topic->topic_id, $page);
            break;
        case 'profile-page':
            // This handles the admin side of the profile as well.
            global $user_id, $user, $profile_hooks, $self;
            if (isset($_GET['id'])) {
                $id = $_GET['id'];
            } elseif (isset($_GET['username'])) {
                $id = $_GET['username'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            if (!$id) {
                $user = bb_get_current_user();
                // Attempt to go to the current users profile
            } else {
                if (bb_get_option('mod_rewrite') === 'slugs') {
                    if (!($user = bb_get_user_by_nicename($id))) {
                        $user = bb_get_user($id);
                    }
                } else {
                    if (!($user = bb_get_user($id))) {
                        $user = bb_get_user_by_nicename($id);
                    }
                }
            }
            if (!$user || 1 == $user->user_status && !bb_current_user_can('moderate')) {
                bb_die(__('User not found.'), '', 404);
            }
            $user_id = $user->ID;
            bb_global_profile_menu_structure();
            $valid = false;
            if ($tab = isset($_GET['tab']) ? $_GET['tab'] : bb_get_path(2)) {
                foreach ($profile_hooks as $valid_tab => $valid_file) {
                    if ($tab == $valid_tab) {
                        $valid = true;
                        $self = $valid_file;
                    }
                }
            }
            if ($valid) {
                $permalink = get_profile_tab_link($user->ID, $tab, $page);
            } else {
                $permalink = get_user_profile_link($user->ID, $page);
                unset($self, $tab);
            }
            break;
        case 'favorites-page':
            $permalink = get_favorites_link();
            break;
        case 'tag-page':
            // It's not an integer and tags.php pulls double duty.
            $id = isset($_GET['tag']) ? $_GET['tag'] : false;
            if (!$id || !bb_get_tag((string) $id)) {
                $permalink = bb_get_tag_page_link();
            } else {
                global $tag, $tag_name;
                $tag_name = $id;
                $tag = bb_get_tag((string) $id);
                $permalink = bb_get_tag_link(0, $page);
                // 0 => grabs $tag from global.
            }
            break;
        case 'view-page':
            // Not an integer
            if (isset($_GET['view'])) {
                $id = $_GET['view'];
            } else {
                $id = bb_get_path();
            }
            $_original_id = $id;
            global $view;
            $view = $id;
            $permalink = get_view_link($view, $page);
            break;
        default:
            return;
            break;
    }
    nxt_parse_str($_SERVER['QUERY_STRING'], $args);
    $args = urlencode_deep($args);
    if ($args) {
        $permalink = add_query_arg($args, $permalink);
        if (bb_get_option('mod_rewrite')) {
            $pretty_args = array('id', 'page', 'tag', 'tab', 'username');
            // these are already specified in the path
            if ($location == 'view-page') {
                $pretty_args[] = 'view';
            }
            foreach ($pretty_args as $pretty_arg) {
                $permalink = remove_query_arg($pretty_arg, $permalink);
            }
        }
    }
    $permalink = apply_filters('bb_repermalink_result', $permalink, $location);
    $domain = bb_get_option('domain');
    $domain = preg_replace('/^https?/', '', $domain);
    $check = preg_replace('|^.*' . trim($domain, ' /') . '|', '', $permalink, 1);
    $uri = rtrim($uri, " \t\n\r\v?");
    $uri = str_replace('/index.php', '/', $uri);
    global $bb_log;
    $bb_log->debug($uri, 'bb_repermalink() ' . __('REQUEST_URI'));
    $bb_log->debug($check, 'bb_repermalink() ' . __('should be'));
    $bb_log->debug($permalink, 'bb_repermalink() ' . __('full permalink'));
    $bb_log->debug(isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : null, 'bb_repermalink() ' . __('PATH_INFO'));
    if ($check != $uri && $check != str_replace(urlencode($_original_id), $_original_id, $uri)) {
        if ($issue_404 && rtrim($check, " \t\n\r\v/") !== rtrim($uri, " \t\n\r\v/")) {
            status_header(404);
            bb_load_template('404.php');
        } else {
            nxt_redirect($permalink);
        }
        exit;
    }
    do_action('post_permalink', $permalink);
}
コード例 #5
0
ファイル: rss.php プロジェクト: abc2mit/abc2mit.github.io
     $link_self = bb_get_view_rss_link($feed_id);
     break;
 case 'topic':
     if (!($topic = get_topic($feed_id))) {
         die;
     }
     if (!($posts = get_thread($feed_id, 0, 1))) {
         die;
     }
     $title = esc_html(sprintf(__('%1$s &raquo; Topic: %2$s'), bb_get_option('name'), get_topic_title()));
     $link = get_topic_link($feed_id);
     $link_self = get_topic_rss_link($feed_id);
     break;
 case 'profile':
     if (bb_get_option('mod_rewrite') === 'slugs') {
         $user = bb_get_user_by_nicename($feed_id);
     } else {
         $user = bb_get_user($feed_id);
     }
     if (!$user) {
         die;
     }
     if (!($posts = get_user_favorites($user->ID))) {
         die;
     }
     $title = esc_html(sprintf(__('%1$s &raquo; User Favorites: %2$s'), bb_get_option('name'), $user->user_login));
     $link = bb_get_profile_link($feed_id);
     $link_self = get_favorites_rss_link($feed_id);
     break;
 case 'tag-topics':
     if (!($tag = bb_get_tag($feed_id))) {