<?php if (is_installed()) { require '../application/config/config.php'; require '../application/config/database.php'; mysql_connect($db['default']['hostname'], $db['default']['username'], $db['default']['password']) or die(mysql_error()); mysql_select_db($db['default']['database']) or die(mysql_error()); // SEO urls $blog['enable_seo_urls'] = get_mod_rewrite_status(); // data $data = get_data($db['default']['dbprefix']); // drop old tables drop_old_tables($db['default']['dbprefix']); // create new tables create_new_tables($db['default']['dbprefix']); // insert old data insert_data($db['default']['dbprefix'], $data); mysql_close(); // write the main config file if ($blog['enable_seo_urls'] == TRUE) { write_main_config($config['base_url'], TRUE); } else { write_main_config($config['base_url'], FALSE); // delete the .htaccess file unlink('../.htaccess'); } echo 'Open Blog has been successfully updated to version 1.2.1.<br /><br /> Before you can start using your blog, you must delete the <strong>install/</strong> directory.<br /><br /> When you are done, go to your <a href="' . $config['base_url'] . '" target="_blank">blog home page</a>.'; } else { header("Location: update.php");
function TR_submenu() { global $wpdb, $TR_qstr; if ($_REQUEST['create_tables']) { $new_prefix = $_REQUEST['new_table_prefix']; update_option('TR_new_table_prefix', $new_prefix); $table_list = $wpdb->get_results("SHOW TABLES LIKE '" . TR_escape_like($new_prefix) . "%'", ARRAY_N); if ($table_list) { echo '<div class="updated fade"><p><strong> Prefix already exists on at least one table; please select a different table prefix. </strong></p></div>'; } else { $success = create_new_tables($new_prefix); if ($success === true) { $success = update_option_table($new_prefix); if ($success === true) { $success = update_usermeta_table($new_prefix); } } echo '<div class="wrap"> <h3>We executed the following queries ...</h3></div> <div class="updated fade" style="height:75px; overflow: auto"> <strong>' . $TR_qstr . '</strong> </div>'; if ($success === true) { echo '<div class="updated fade"><p><strong> New WordPress tables with prefix "' . $new_prefix . '" successfully created. </strong></p></div>'; } else { echo $success; } } } elseif ($_REQUEST['update_table_prefix']) { $new_prefix = get_option('TR_new_table_prefix'); // To keep the below easy-to-read. $old_prefix = $GLOBALS['table_prefix']; $new_table_list = $wpdb->get_results("SHOW TABLES LIKE '" . TR_escape_like($new_prefix) . "%'", ARRAY_N); $old_table_list = $wpdb->get_results("SHOW TABLES LIKE '" . TR_escape_like($old_prefix) . "%'", ARRAY_N); if (sizeof($new_table_list) != sizeof($old_table_list) || $new_prefix == $old_prefix) { echo '<div class="updated fade"><p><strong> New tables not created; please complete step 1 before changing table prefix. </strong></p></div>'; } else { $config_path = '../wp-config.php'; $_error_str = "<div class=\"updated fade\"><p><strong>\n\t\t\tWe could not automatically change prefix value; \n\t\t\tplease edit wp-config.php \n\t\t\tand set \$table_prefix to \"{$new_prefix}\".\n\t\t\t</strong></p></div>"; if (file_exists($config_path) && is_writable($config_path)) { $config_file = file_get_contents($config_path); $new_config_file = preg_replace('#\\$table_prefix\\s*=\\s*\'(.+)\';#', "\$table_prefix = '{$new_prefix}';", $config_file); if ($config_file == $new_config_file) { echo $_error_str; } else { $result = file_put_contents($config_path, $new_config_file); if ($result !== FALSE) { echo '<div class="updated fade"><p><strong> Your wp-config.php file has been successfully updated. </strong></p></div>'; } else { echo $_error_str; } } } else { echo $_error_str; } } } ?> <script type="text/javascript"> function checktext() { document.getElementById('create_tables_submit1').disabled = (document.getElementById('original_prefix1').value == document.getElementById('new_prefix1').value); } function settextfield(size, value){ if(value.search(/ /) != -1){ var y=document.getElementById("new_prefix1").value; alert('No empty spaces are allowed for table name.'); document.getElementById("new_prefix1").value=y.replace(new RegExp(' ',"g"), ''); } if(value.search(/\W/) != -1){ var y=document.getElementById("new_prefix1").value; alert('Special characters are not permitted in table name.'); document.getElementById("new_prefix1").value=y.replace(new RegExp('\\W',"g"), ''); } size = (value.length ); size = size + '' + 'em'; return size; } </script> <div class="wrap"> <h2>Table Rename Setup</h2> <h3>Step 1: Generate New Tables with Preexisting Data</h3> <!-- Old prefix --> Current Table Prefix:<br /> <form> <input size="<?php echo strlen($GLOBALS['table_prefix']) + 2; ?> " type="text" id="original_prefix1" style="min-width:6em;" value= "<?php echo htmlspecialchars($GLOBALS['table_prefix'], ENT_QUOTES); ?> " readonly> <span style="font-size:large;"></span> </form> <br /> <!-- New prefix --> New Table Prefix: <form name="generate_new_tables" action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input type="text" size="<?php echo strlen(get_option('TR_new_table_prefix')) + 2; ?> " style="min-width:6em;" id="new_prefix1" onkeyup="checktext(); this.style.width = settextfield(this.style.width, this.value);" id="new_prefix1" name="new_table_prefix" value="<?php if (get_option('TR_new_table_prefix') != $GLOBALS['table_prefix']) { echo htmlspecialchars(get_option('TR_new_table_prefix'), ENT_QUOTES); } ?> " > <span style="font-size:large;"></span> <br /><br /> <input type="submit" id="create_tables_submit1" onclick=" if(document.getElementById('new_prefix1').value == ''){ alert('Please enter a valid table name.'); return false; }" <?php echo get_option('TR_new_table_prefix') == $GLOBALS['table_prefix'] ? 'disabled' : ''; ?> name="create_tables" value="Generate New Tables"> </form> <h3>Step 2: Change $table_prefix in wp-config.php to Use New Tables</h3> <form name='change_table_prefix' action="<?php echo $_SERVER['REQUEST_URI']; ?> " method="post"> <input type="submit" name="update_table_prefix" value="Change $table_prefix"> </form> <?php echo '</div>'; }
} else { $database_error['wordpress'] = test_database_connection($database['wordpress']['hostname'], $database['wordpress']['username'], $database['wordpress']['password'], $database['wordpress']['name']); $database_error['openblog'] = test_database_connection($database['openblog']['hostname'], $database['openblog']['username'], $database['openblog']['password'], $database['openblog']['name']); if ($database_error['wordpress']) { echo "Could not connect to the server or select the database (Wordpress)!<br /><br /><a href=\"javascript:history.go(-1)\">‹‹ Back</a>"; } else { if ($database_error['openblog']) { echo "Could not connect to the server or select the database (Open Blog)!<br /><br /><a href=\"javascript:history.go(-1)\">‹‹ Back</a>"; } else { mysql_connect($database['wordpress']['hostname'], $database['wordpress']['username'], $database['wordpress']['password']) or die(mysql_error()); mysql_select_db($database['wordpress']['name']) or die(mysql_error()); $data = get_data($database['wordpress']['prefix']); mysql_close(); mysql_connect($database['openblog']['hostname'], $database['openblog']['username'], $database['openblog']['password']) or die(mysql_error()); mysql_select_db($database['openblog']['name']) or die(mysql_error()); create_new_tables($database['openblog']['prefix']); insert_data($database['wordpress']['prefix'], $database['openblog']['prefix'], $data); // write the main config file if ($blog['enable_seo_urls'] == TRUE) { write_main_config($blog['url'], TRUE); } else { write_main_config($blog['url'], FALSE); // delete the .htaccess file unlink('../.htaccess'); } // write the database config file write_database_config($database['openblog']['hostname'], $database['openblog']['username'], $database['openblog']['password'], $database['openblog']['name'], $database['openblog']['prefix']); mysql_close(); echo 'You have successfully migrated from Wordpress to Open Blog.<br /><br /> Before you can start using your blog, you must delete the <strong>install/</strong> directory.<br /><br /> When you are done, go to your <a href="' . $blog['url'] . '" target="_blank">blog home page</a>.';