user_email; // prepare/get data based on single / multi input if ($_POST['acswpmu_single'] != 'on'){ $siteurl = $_POST['acswpmu_siteurl']; $blogname = $_POST['acswpmu_blogname']; $blogdescription = $_POST['acswpmu_blogdescription']; $the_array[0][0] = $siteurl; $the_array[0][1] = $blogdescription; $the_array[0][2] = $blogname; $the_array[0][3] = $user_id; $the_array[0][4] = $admin_email; $the_array[0][5] = $template_id; } else { // get post and trim to remove whitespace $new_sites = trim($_POST['acswpmu_new_sites']); // explode the post to lines $the_array = explode( "\n", $new_sites ); // explode each line for ( $i = 0; $i < sizeof( $the_array ); $i++ ) { $the_array[$i] = explode( ",", $the_array[$i] ); $the_array[$i][3] = $user_id; $the_array[$i][4] = $admin_email; $the_array[$i][5] = $template_id; } } // trim each value in the array from whitespaces and left comma's for ( $i = 0; $i < sizeof( $the_array ); $i++ ) { array_walk($the_array[$i], 'trim_value'); } // And now: here the loop starts if (sizeof($the_array) > 0) { echo "

" . __( 'Adding cloned sites ' . $siteurl, 'acswpmu_trdom' ) . "

"; // create tabs ?>
'; foreach($the_array as $line) { //get the data from the array into strings $siteurl = $line[0]; $blogdescription = $line[1]; $blogname = $line[2]; $user_id = $line[3]; $admin_email = $line[4]; $template_id = $line[5]; // Prepare some data $dashedsiteurl = str_replace('.', '-', $siteurl); $domain = $dashedsiteurl . "." . get_blog_details(1)->domain; echo "

" . __( 'Start with creating site for ' . $siteurl, 'acswpmu_trdom' ) . "

"; //check for correct and non empty siteurl if (!valid_url($siteurl)){ //_e("The url '$siteurl' is not a valid url.
", 'acswpmu_trdom' ); $error['Site URL'][] = "The url '$siteurl' is not a valid url."; } // Check first if domain already exists if($exist_id = $wpdb->get_var("SELECT blog_id FROM $wpdb->blogs WHERE domain = '$domain'")) { //print "Hey the domain $domain already exists ($exist_id), we skip it!!"; $error['Create new domain'] = "The domain $domain already exists (ID: $exist_id), we skipped it!"; } // Start with adding the new blog to the blogs table if (!$error){ _e("

Adding $domain to the database.

", 'acswpmu_trdom' ); $new_blog_id = insert_blog( $domain, '/', '1'); //Next duplicate all tables from the template _e("

Starting duplicating the template

", 'acswpmu_trdom' ); $template_like = $wpdb->prefix . $template_id . "_"; $template_new = $wpdb->prefix . $new_blog_id . "_"; $temp_like = str_replace('_', '\_', $template_like); //escape the _ for correct sql!! $template_tables = $wpdb->get_results( "SHOW TABLES LIKE '$temp_like%'", ARRAY_N ); foreach ($template_tables as $old_table) { $new_table = str_replace($template_like, $template_new, $old_table[0]); _e("Duplicate: $old_table[0] to $new_table : ", 'acswpmu_trdom' ); // check if table already exists if($wpdb->get_var("SHOW TABLES LIKE '$new_table'") != $new_table) { $result = $wpdb->query( "CREATE TABLE $new_table SELECT * FROM $old_table[0]"); if($result === FALSE) { _e("Failed.
", 'acswpmu_trdom' ); $error['Duplicating Tables'][] = "Failed to create $new_table"; } else { _e("OK.
", 'acswpmu_trdom' ); } } else { _e("Failed.
", 'acswpmu_trdom' ); $error['Duplicating Tables'][] = "The table $new_table already existed"; } } // Then add user to the new blog if(!$error) { _e("Connect the user to the blog.
", 'acswpmu_trdom' ); $role = "administrator"; if ( add_user_to_blog( $new_blog_id, $user_id, $role ) ) { echo __( 'Added user '.$user_id.' as '.$role.' to blog '.$new_blog_id.'.
', 'acswpmu_trdom' ); } else { echo __( 'Failed to add user '.$user_id.' as '.$role.' to blog '.$new_blog_id.'.
', 'acswpmu_trdom' ); } } // Add custom data to newly duplicated blog if(!$error) { _e("Update new data to the cloned site: ", 'acswpmu_trdom' ); // prepare some data if(!$blogname) { $blogname = $siteurl; } $home = "http://" . $domain . "/"; $site_url = "http://" . $siteurl . "/"; // update the cloned table with the new data update_blog_option ($new_blog_id, 'siteurl', $site_url); update_blog_option ($new_blog_id, 'blogname', $blogname); update_blog_option ($new_blog_id, 'blogdescription', $blogdescription); update_blog_option ($new_blog_id, 'admin_email', $admin_email); update_blog_option ($new_blog_id, 'home', $home); // update some data to the new blog_id update_blog_option ($new_blog_id, 'upload_path', 'wp-content/blogs.dir/' . $new_blog_id . '/files'); $new_options_table = $wpdb->prefix . $new_blog_id . '_options'; $old_name = $wpdb->prefix . $template_id . '_user_roles'; $new_name = $wpdb->prefix . $new_blog_id . '_user_roles'; $result = $wpdb->update( $new_options_table, array('option_name' => $new_name), array('option_name' => $old_name)); // 'check' if it went ok - NOTE: is just a basic check could give an error anyway... if(get_blog_option($new_blog_id, 'blogdescription') != $blogdescription) { _e("Maybe we had an error updating the new data.
", 'acswpmu_trdom' ); } else { _e("OK.
", 'acswpmu_trdom' ); } } // Last but not least domainmap de new cloned site if(!$error) { _e("Start domainmapping the new site: ", 'acswpmu_trdom' ); $tbl_domain_map = $wpdb->prefix . "domain_mapping"; // Check if domainmapping exists if($wpdb->get_var("SHOW TABLES LIKE '$tbl_domain_map'") == $tbl_domain_map) { // Map the domain $result = $wpdb->insert( $tbl_domain_map, array('blog_id' => $new_blog_id, 'domain' => $siteurl, 'active' => '1')); if($result) { _e("OK
", 'acswpmu_trdom' ); } else { $error['Domain mapping'] = "Domain mapping for $siteurl failed"; } } else { $error['Domain mapping'] = "Domainmapping failed because it is not activated!"; } } } // count succesfull cloned sites if(!$error) { $cloned[] = $siteurl; } // Feedback on errors if ($error){ echo "
" . __( 'Oops there where some errors:', 'acswpmu_trdom' ) . "
"; echo ''; foreach ($error as $key => $warning) { if(is_array($warning)){ foreach ($warning as $subwarning) { echo "$key: $subwarning
"; } } else { echo "$key: $warning
"; } } echo "
"; // count failed sites $failed[] = $siteurl; $error = NULL; } } echo '
'; } ?>
' . __( 'Job done, here are the results:', 'acswpmu_trdom' ) . ''; if ($nr_sites > 0) { _e("

It took only $time seconds to create and clone $nr_sites sites!

", 'acswpmu_trdom' ); } if ($failed) { _e("

Hey $nr_failed sites could not be cloned due to errors, you might want to check the log why they failed.

", 'acswpmu_trdom' ); } // show donation options if ($nr_sites > -1) { echo '

' . __( 'You must be pleased..', 'acswpmu_trdom' ) . '

'; echo __("

Normally this would have taken you at least $normaltime minutes to do this all manually.
You could thank me by buying a tea, coffee, cappuchino, or if you are very pleased with the time this plugin saved you, a coffee with cake!

", 'acswpmu_trdom'); echo __("

You can buy me one of these items by clicking on one of the buttons below.
Come on its only a coffee, give it a try!

", 'acswpmu_trdom'); ?>