function bp_blogs_validate_blog_signup() { global $nxtdb, $current_user, $blogname, $blog_title, $errors, $domain, $path, $current_site; if (!check_admin_referer('bp_blog_signup_form')) { return false; } $current_user = nxt_get_current_user(); if (!is_user_logged_in()) { die; } $result = bp_blogs_validate_blog_form(); extract($result); if ($errors->get_error_code()) { unset($_POST['submit']); bp_show_blog_signup_form($blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $meta = apply_filters('signup_create_blog_meta', array('lang_id' => 1, 'public' => $public)); // depreciated $meta = apply_filters('add_signup_meta', $meta); // If this is a subdomain install, set up the site inside the root domain. if (is_subdomain_install()) { $domain = $blogname . '.' . preg_replace('|^www\\.|', '', $current_site->domain); } nxtmu_create_blog($domain, $path, $blog_title, $current_user->ID, $meta, $nxtdb->siteid); bp_blogs_confirm_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); return true; }
/** * Activate a signup. * * Hook to 'nxtmu_activate_user' or 'nxtmu_activate_blog' for events * that should happen only when users or sites are self-created (since * those actions are not called when users and sites are created * by a Super Admin). * * @since MU * @uses nxt_generate_password() * @uses nxtmu_welcome_user_notification() * @uses add_user_to_blog() * @uses add_new_user_to_blog() * @uses nxtmu_create_user() * @uses nxtmu_create_blog() * @uses nxtmu_welcome_notification() * * @param string $key The activation key provided to the user. * @return array An array containing information about the activated user and/or blog */ function nxtmu_activate_signup($key) { global $nxtdb, $current_site; $signup = $nxtdb->get_row($nxtdb->prepare("SELECT * FROM {$nxtdb->signups} WHERE activation_key = %s", $key)); if (empty($signup)) { return new nxt_Error('invalid_key', __('Invalid activation key.')); } if ($signup->active) { if (empty($signup->domain)) { return new nxt_Error('already_active', __('The user is already active.'), $signup); } else { return new nxt_Error('already_active', __('The site is already active.'), $signup); } } $meta = unserialize($signup->meta); $user_login = $nxtdb->escape($signup->user_login); $user_email = $nxtdb->escape($signup->user_email); $password = nxt_generate_password(12, false); $user_id = username_exists($user_login); if (!$user_id) { $user_id = nxtmu_create_user($user_login, $password, $user_email); } else { $user_already_exists = true; } if (!$user_id) { return new nxt_Error('create_user', __('Could not create user'), $signup); } $now = current_time('mysql', true); if (empty($signup->domain)) { $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); if (isset($user_already_exists)) { return new nxt_Error('user_already_exists', __('That username is already activated.'), $signup); } nxtmu_welcome_user_notification($user_id, $password, $meta); add_new_user_to_blog($user_id, $user_email, $meta); do_action('nxtmu_activate_user', $user_id, $password, $meta); return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta); } $blog_id = nxtmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta, $nxtdb->siteid); // TODO: What to do if we create a user but cannot create a blog? if (is_nxt_error($blog_id)) { // If blog is taken, that means a previous attempt to activate this blog failed in between creating the blog and // setting the activation flag. Let's just set the active flag and instruct the user to reset their password. if ('blog_taken' == $blog_id->get_error_code()) { $blog_id->add_data($signup); $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); } return $blog_id; } $nxtdb->update($nxtdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $key)); nxtmu_welcome_notification($blog_id, $user_id, $password, $signup->title, $meta); do_action('nxtmu_activate_blog', $blog_id, $user_id, $password, $signup->title, $meta); return array('blog_id' => $blog_id, 'user_id' => $user_id, 'password' => $password, 'title' => $signup->title, 'meta' => $meta); }
function validate_another_blog_signup() { global $nxtdb, $blogname, $blog_title, $errors, $domain, $path; $current_user = nxt_get_current_user(); if (!is_user_logged_in()) { die; } $result = validate_blog_form(); extract($result); if ($errors->get_error_code()) { signup_another_blog($blogname, $blog_title, $errors); return false; } $public = (int) $_POST['blog_public']; $meta = apply_filters('signup_create_blog_meta', array('lang_id' => 1, 'public' => $public)); // deprecated $meta = apply_filters('add_signup_meta', $meta); nxtmu_create_blog($domain, $path, $blog_title, $current_user->ID, $meta, $nxtdb->siteid); confirm_another_blog_signup($domain, $path, $blog_title, $current_user->user_login, $current_user->user_email, $meta); return true; }
$path = $base . $domain . '/'; } $password = '******'; $user_id = email_exists($email); if (!$user_id) { // Create a new user with a random password $password = nxt_generate_password(12, false); $user_id = nxtmu_create_user($domain, $password, $email); if (false == $user_id) { nxt_die(__('There was an error creating the user.')); } else { nxt_new_user_notification($user_id, $password); } } $nxtdb->hide_errors(); $id = nxtmu_create_blog($newdomain, $path, $title, $user_id, array('public' => 1), $current_site->id); $nxtdb->show_errors(); if (!is_nxt_error($id)) { if (!is_super_admin($user_id) && !get_user_option('primary_blog', $user_id)) { update_user_option($user_id, 'primary_blog', $id, true); } $content_mail = sprintf(__("New site created by %1s\n\nAddress: %2s\nName: %3s"), $current_user->user_login, get_site_url($id), stripslashes($title)); nxt_mail(get_site_option('admin_email'), sprintf(__('[%s] New Site Created'), $current_site->site_name), $content_mail, 'From: "Site Admin" <' . get_site_option('admin_email') . '>'); nxtmu_welcome_notification($id, $user_id, $password, $title, array('public' => 1)); nxt_redirect(add_query_arg(array('update' => 'added', 'id' => $id), 'site-new.php')); exit; } else { nxt_die($id->get_error_message()); } } if (isset($_GET['update'])) {