Example #1
0
function jquery_install_site($site, $user)
{
    $sites = jquery_sites();
    $details = $sites[$site];
    if (strpos($site, '/')) {
        list($domain, $path) = explode('/', $site, 2);
        $path = '/' . trim($path, '/') . '/';
    } else {
        $domain = $site;
        $path = '/';
    }
    $default_options = jquery_default_site_options();
    $default_options['admin_email'] = $user->user_email;
    if (1 !== $details['blog_id']) {
        $blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, $path, 1);
        if ($blog_id != $details['blog_id']) {
            wp_die("Something went very wrong when trying to install {$domain} as site {$blog_id}-{$details['blog_id']}. Find nacin.");
        }
        switch_to_blog($blog_id);
        install_blog($blog_id, $details['options']['blogname']);
        add_user_to_blog($blog_id, $user->ID, 'administrator');
    }
    $options = array_merge($default_options, $details['options']);
    foreach ($options as $option => $value) {
        update_option($option, $value);
    }
    delete_option('rewrite_rules');
    restore_current_blog();
}
Example #2
0
function jquery_install_remaining_sites($user)
{
    $domains = jquery_domains();
    $default_options = jquery_default_site_options();
    $default_options['admin_email'] = $user->user_email;
    foreach ($domains as $domain => $details) {
        if (1 !== $details['blog_id']) {
            $blog_id = insert_blog(JQUERY_STAGING_PREFIX . $domain, '/', 1);
            if ($blog_id != $details['blog_id']) {
                wp_die("Something went very wrong when trying to install {$domain} as site {$blog_id}-{$details['blog_id']}. Find nacin.");
            }
            switch_to_blog($blog_id);
            install_blog($blog_id, $details['options']['blogname']);
            add_user_to_blog($blog_id, $user->ID, 'administrator');
        }
        $options = array_merge($default_options, $details['options']);
        foreach ($options as $option => $value) {
            update_option($option, $value);
        }
        // Work around a superficial bug in install_blog(), fixed in WP r21172.
        $home = untrailingslashit(get_option('home'));
        $siteurl = untrailingslashit(get_option('siteurl'));
        update_option('home', 'http://example.com');
        // Please just don't ask.
        update_option('siteurl', 'http://example.com');
        update_option('home', $home);
        update_option('siteurl', $siteurl);
        flush_rewrite_rules();
        restore_current_blog();
    }
}
Example #3
0
/**
 * Create a site.
 *
 * This function runs when a user self-registers a new site as well
 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
 * for events that should affect all new sites.
 *
 * On subdirectory installs, $domain is the same as the main site's
 * domain, and the path is the subdirectory name (eg 'example.com'
 * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
 * root domain (eg 'blog1.example.com'), and $path is '/'.
 *
 * @since MU
 * @uses domain_exists()
 * @uses insert_blog()
 * @uses wp_install_defaults()
 * @uses add_user_to_blog()
 *
 * @param string $domain The new site's domain.
 * @param string $path The new site's path.
 * @param string $title The new site's title.
 * @param int $user_id The user ID of the new site's admin.
 * @param array $meta Optional. Used to set initial site options.
 * @param int $site_id Optional. Only relevant on multi-network installs.
 * @return mixed Returns WP_Error object on failure, int $blog_id on success
 */
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = '', $site_id = 1)
{
    $domain = preg_replace('/\\s+/', '', sanitize_user($domain, true));
    if (is_subdomain_install()) {
        $domain = str_replace('@', '', $domain);
    }
    $title = strip_tags($title);
    $user_id = (int) $user_id;
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return new WP_Error('blog_taken', __('Site already exists.'));
    }
    if (!defined('WP_INSTALLING')) {
        define('WP_INSTALLING', true);
    }
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return new WP_Error('insert_blog', __('Could not create site.'));
    }
    switch_to_blog($blog_id);
    install_blog($blog_id, $title);
    wp_install_defaults($user_id);
    add_user_to_blog($blog_id, $user_id, 'administrator');
    if (is_array($meta)) {
        foreach ($meta as $key => $value) {
            if ($key == 'public' || $key == 'archived' || $key == 'mature' || $key == 'spam' || $key == 'deleted' || $key == 'lang_id') {
                update_blog_status($blog_id, $key, $value);
            } else {
                update_option($key, $value);
            }
        }
    }
    add_option('WPLANG', get_site_option('WPLANG'));
    update_option('blog_public', (int) $meta['public']);
    if (!is_super_admin() && !get_user_meta($user_id, 'primary_blog', true)) {
        update_user_meta($user_id, 'primary_blog', $blog_id);
    }
    restore_current_blog();
    do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta);
    return $blog_id;
}
/**
 * Create an empty blog.
 *
 * @since MU 1.0
 * @deprecated 4.4.0
 *
 * @param string $domain       The new blog's domain.
 * @param string $path         The new blog's path.
 * @param string $weblog_title The new blog's title.
 * @param int    $site_id      Optional. Defaults to 1.
 * @return string|int The ID of the newly created blog
 */
function create_empty_blog($domain, $path, $weblog_title, $site_id = 1)
{
    _deprecated_function(__FUNCTION__, '4.4.0');
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return __('<strong>ERROR</strong>: Site URL already taken.');
    }
    // Need to back up wpdb table names, and create a new wp_blogs entry for new blog.
    // Need to get blog_id from wp_blogs, and create new table names.
    // Must restore table names at the end of function.
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return __('<strong>ERROR</strong>: problem creating site entry.');
    }
    switch_to_blog($blog_id);
    install_blog($blog_id);
    restore_current_blog();
    return $blog_id;
}
Example #5
0
/**
 * Create a site.
 *
 * This function runs when a user self-registers a new site as well
 * as when a Super Admin creates a new site. Hook to 'wpmu_new_blog'
 * for events that should affect all new sites.
 *
 * On subdirectory installs, $domain is the same as the main site's
 * domain, and the path is the subdirectory name (eg 'example.com'
 * and '/blog1/'). On subdomain installs, $domain is the new subdomain +
 * root domain (eg 'blog1.example.com'), and $path is '/'.
 *
 * @since MU
 *
 * @param string $domain  The new site's domain.
 * @param string $path    The new site's path.
 * @param string $title   The new site's title.
 * @param int    $user_id The user ID of the new site's admin.
 * @param array  $meta    Optional. Used to set initial site options.
 * @param int    $site_id Optional. Only relevant on multi-network installs.
 * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success
 */
function wpmu_create_blog($domain, $path, $title, $user_id, $meta = array(), $site_id = 1)
{
    $defaults = array('public' => 0);
    $meta = wp_parse_args($meta, $defaults);
    $domain = preg_replace('/\\s+/', '', sanitize_user($domain, true));
    if (is_subdomain_install()) {
        $domain = str_replace('@', '', $domain);
    }
    $title = strip_tags($title);
    $user_id = (int) $user_id;
    if (empty($path)) {
        $path = '/';
    }
    // Check if the domain has been used already. We should return an error message.
    if (domain_exists($domain, $path, $site_id)) {
        return new WP_Error('blog_taken', __('Sorry, that site already exists!'));
    }
    if (!wp_installing()) {
        wp_installing(true);
    }
    if (!($blog_id = insert_blog($domain, $path, $site_id))) {
        return new WP_Error('insert_blog', __('Could not create site.'));
    }
    switch_to_blog($blog_id);
    install_blog($blog_id, $title);
    wp_install_defaults($user_id);
    add_user_to_blog($blog_id, $user_id, 'administrator');
    foreach ($meta as $key => $value) {
        if (in_array($key, array('public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) {
            update_blog_status($blog_id, $key, $value);
        } else {
            update_option($key, $value);
        }
    }
    add_option('WPLANG', get_site_option('WPLANG'));
    update_option('blog_public', (int) $meta['public']);
    if (!is_super_admin($user_id) && !get_user_meta($user_id, 'primary_blog', true)) {
        update_user_meta($user_id, 'primary_blog', $blog_id);
    }
    restore_current_blog();
    /**
     * Fires immediately after a new site is created.
     *
     * @since MU
     *
     * @param int    $blog_id Blog ID.
     * @param int    $user_id User ID.
     * @param string $domain  Site domain.
     * @param string $path    Site path.
     * @param int    $site_id Site ID. Only relevant on multi-network installs.
     * @param array  $meta    Meta data. Used to set initial site options.
     */
    do_action('wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta);
    return $blog_id;
}
             if (is_integer($new_blog_id)) {
                 _e("New site created with id: {$new_blog_id}<br/>", 'acswpmu_trdom');
             } else {
                 _e("<span class=\"error\">The URL {$domain} already exist, we skipped it!</span>", 'acswpmu_trdom');
                 $error = TRUE;
             }
         }
     }
 } else {
     if (!$error) {
         if ($exist_id = $wpdb->get_var("SELECT blog_id FROM {$wpdb->blogs} WHERE path = '{$path}/'")) {
             _e("<span class=\"error\">The URL {$fulldomain} already exist, we skipped it!</span>", 'acswpmu_trdom');
             $error = TRUE;
         } else {
             // Start with adding the new blog to the blogs table
             $new_blog_id = insert_blog($domain, $path, '1');
             if (is_integer($new_blog_id)) {
                 _e("New site created with id: {$new_blog_id}<br/>", 'acswpmu_trdom');
             } else {
                 _e("<span class=\"error\">The URL {$fulldomain} already exist, we skipped it!</span>", 'acswpmu_trdom');
                 $error = TRUE;
             }
         }
     }
 }
 //Next duplicate all tables from the template
 if (!$error) {
     $template_like = $wpdb->prefix . $template_id . "_";
     $template_new = $wpdb->prefix . $new_blog_id . "_";
     $temp_like = str_replace('_', '\\_', $template_like);
     //escape the _ for correct sql!!
Example #7
0
}
if (!isset($_POST["title"]) || empty($_POST["title"])) {
    die("Empty title");
}
if (!isset($_POST["content"])) {
    die("Some error occurred!");
}
$title = $_POST["title"];
$content = $_POST["content"];
$blog = $_GET["blog"];
$author = $_GET["auth"];
if ($_SESSION[$session] !== $author) {
    die("You are not authorized to edit this blog!");
}
if (blogid_existed($link, $blog)) {
    $authors = get_allauthors($link, $blog);
    if (!in_array($author, $authors)) {
        die("You are not authorized to edit this blog!");
    }
} else {
    insert_author_blog($link, $author, $blog);
    insert_blog($link, $blog, $title);
}
$f = fopen("{$blog}", "w") or die("Cannot save to {$blog}");
fwrite($f, $content);
fclose($f);
echo "Successfully saved to " . htmlspecialchars($title);
?>

<?php 
include_once '/var/www/html/foot.php';