} jQuery( '#' + target_id ).append( "\n" + status_string ); textareaelem = document.getElementById( target_id ); textareaelem.scrollTop = textareaelem.scrollHeight; } </script> <?php echo '<div style="width: 98%;">'; echo pb_backupbuddy::status_box('Mass replacing in database powered by BackupBuddy v' . PB_BB_VERSION . '...'); echo '</div>'; echo '<div id="pb_importbuddy_working"><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."></div>'; pb_backupbuddy::flush(); //echo '<div id="pb_backupbuddy_replace_working"><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."></div>'; // Instantiate database replacement class. require_once pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php'; $dbreplace = new pluginbuddy_dbreplace(); // Set up variables by getting POST data. $needle = mysql_real_escape_string(pb_backupbuddy::_POST('needle')); if ($needle == '') { echo '<b>Error #4456582. Missing needle. You must enter text to search for.'; echo '<br><a href="' . pb_backupbuddy::page_url() . '&parent_config=' . htmlentities(pb_backupbuddy::_GET('parent_config')) . '" class="button secondary-button">← ' . __('back', 'it-l10n-backupbuddy') . '</a>'; return; } $replacement = mysql_real_escape_string(pb_backupbuddy::_POST('replacement')); pb_backupbuddy::status('message', 'Replacing `' . $needle . '` with `' . $replacement . '`.'); /* if ( pb_backupbuddy::_POST( 'maybe_serialized' ) == 'true' ) { pb_backupbuddy::status( 'message', 'Accounting for serialized data based on settings.' ); $maybe_serialized = true; } else { pb_backupbuddy::status( 'warning', 'NOT accounting for serialized data based on settings. Use with caution.' );
echo '<a name="database_replace"></a>'; echo 'This tool allows you to automatically replace text contained throughout your WordPress database.<br>'; echo '<br><b>Note:</b> ImportBuddy automatically handles migrating & replacing your site URLs and file paths during restore/migration; this tool is not needed for normal backup / restore operations.'; echo '<p><b>Tip:</b> When replacing a site address there may be more than one URL so multiple passes at replacements may need to be made. Ie. http://site.com, http://<b>www.</b>site.com, http<b>s</b>://site.com, etc.</p>'; echo '<p><img src="' . pb_backupbuddy::plugin_url() . '/images/bullet_error.png" style="vertical-align: -3px;"> Caution: This is an advanced feature. Use with care; improper use may result in data loss.</p>'; echo '<br>'; if (pb_backupbuddy::_GET('database_replace') == '1') { global $pb_backupbuddy_js_status; $pb_backupbuddy_js_status = true; echo '<div id="pb_importbuddy_working"><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."></div>'; echo '<script>jQuery("#pb_backupbuddy_status_wrap").show();</script>'; pb_backupbuddy::flush(); //echo '<div id="pb_backupbuddy_replace_working"><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."></div>'; // Instantiate database replacement class. require_once pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php'; $dbreplace = new pluginbuddy_dbreplace('', 1, 60 * 60 * 24); // Set up variables by getting POST data. $needle = mysql_real_escape_string(pb_backupbuddy::_POST('needle')); if ($needle == '') { echo '<b>Error #4456582. Missing needle. You must enter text to search for.'; echo '<br><a href="' . pb_backupbuddy::page_url() . '&parent_config=' . htmlentities(pb_backupbuddy::_GET('parent_config')) . '" class="button secondary-button">← ' . __('back', 'it-l10n-backupbuddy') . '</a>'; return; } $replacement = mysql_real_escape_string(pb_backupbuddy::_POST('replacement')); pb_backupbuddy::status('message', 'Replacing `' . $needle . '` with `' . $replacement . '`.'); /* if ( pb_backupbuddy::_POST( 'maybe_serialized' ) == 'true' ) { pb_backupbuddy::status( 'message', 'Accounting for serialized data based on settings.' ); $maybe_serialized = true; } else { pb_backupbuddy::status( 'warning', 'NOT accounting for serialized data based on settings. Use with caution.' );
$tables = array(); $rows = $wpdb->get_results("SELECT table_name FROM information_schema.tables WHERE table_name LIKE '" . str_replace('_', '\\_', $destination_db_prefix) . "%' AND table_schema = DATABASE()", ARRAY_A); foreach ($rows as $row) { $tables[] = $row['table_name']; } pb_backupbuddy::status('message', 'Found ' . count($rows) . ' WordPress tables. '); unset($rows); $bruteforce_tables = pb_backupbuddy::array_remove($tables, $bruteforce_excluded_tables); // Removes all tables listed in $excluded_tables from $tables. unset($tables); if ($destination_type == 'multisite_import') { require_once pb_backupbuddy::plugin_path() . '/lib/dbreplace/dbreplace.php'; } else { require_once 'importbuddy/lib/dbreplace/dbreplace.php'; } $dbreplace = new pluginbuddy_dbreplace($this); // ********** BEGIN MAKING OLD URLS UNIQUE AND TRIMMING CORRESPONDING NEW URLS ********** // This entire section is in place to prevent duplicate replacements. /* array_pairs_unique_first() * * Takes two arrays. Looks for any duplicate values in the first array. That item is removed. The corresponding item in the second array is removed also. * Resets indexes as a courtesy while maintaining order. * * @param array $a First array to make unique. * @param array $b Second array that has items removed that were in the same position as the removed duplicates found in $a. * @return */ function array_pairs_unique_first($a, $b) { $a_uniques = array_unique($a); // Get unique values in $a. Keys are maintained.
} mysql_free_result($result); // Free memory. } elseif ($_POST['table_selection'] == 'single_table') { $bruteforce_tables = array($_POST['table']); } if ($_POST['trim_whitespace'] == 'true') { $needle = trim($_POST['needle']); $replacement = trim($_POST['replacement']); } else { $needle = $_POST['needle']; $replacement = $_POST['replacement']; } $db_replace_file = $this->get_plugin_dir('repairbuddy/lib/dbreplace/dbreplace.php', dirname(dirname(dirname(dirname(__FILE__))))); require_once $db_replace_file; $dbreplace = new pluginbuddy_dbreplace($pluginbuddy_repairbuddy); foreach ($bruteforce_tables as $bruteforce_table) { //echo 'force ' . $bruteforce_table . ' replace ' . $needle . ' with ' . $replacement . '<br>'; $dbreplace->bruteforce_table($bruteforce_table, $_POST['needle'], $_POST['replacement']); } $pluginbuddy_repairbuddy->output_status('Database replacement complete.', false); echo '<script type="text/javascript">jQuery("#pb_repairbuddy_working").hide();</script>'; echo '<br><div style="text-align: center; margin-top: 30px;"><span class="pb_fancy">Database replacement complete.</span></div>'; } else { ?> <script type="text/javascript"> jQuery(document).ready(function() { jQuery( '#pb_repairbuddy_table' ).change( function() { alert( jQuery( '#pb_repairbuddy_table' ).val() ); jQuery.post( '<?php