Changeset 1357009
- Timestamp:
- 02/24/2016 03:48:10 AM (10 years ago)
- Location:
- automatic-domain-changer/trunk
- Files:
-
- 6 edited
-
auto-domain-change.php (modified) (12 diffs)
-
languages/auto-domain-change-es_ES.mo (modified) (previous)
-
languages/auto-domain-change-es_ES.po (modified) (5 diffs)
-
languages/auto-domain-change-fr_FR.mo (modified) (previous)
-
languages/auto-domain-change-fr_FR.po (modified) (5 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
automatic-domain-changer/trunk/auto-domain-change.php
r1155463 r1357009 5 5 Description: Automatically changes the domain of a WordPress blog 6 6 Author: NuageLab <wordpress-plugins@nuagelab.com> 7 Version: 1.0.17 Version: 2.0.0 8 8 License: GPLv2 or later 9 9 Author URI: http://www.nuagelab.com/wordpress-plugins … … 18 18 */ 19 19 class auto_domain_change{ 20 20 21 private static $_instance = null; 21 22 … … 66 67 require_once(ABSPATH .'wp-includes/pluggable.php'); 67 68 68 if (wp_verify_nonce( $_POST['nonce'],$_POST['action'])) {69 if (wp_verify_nonce(@$_POST['nonce'],@$_POST['action'])) { 69 70 $parts = explode('+',$_POST['action']); 70 71 switch ($parts[0]) { 71 72 case 'backup-database': 72 return $this->do_backup(); 73 if (current_user_can('export')) { 74 switch ($_POST['type']) { 75 case 'sql': 76 default: 77 return $this->do_backup_sql(); 78 case 'php': 79 return $this->do_backup_php(); 80 } 81 } 73 82 default: 74 83 // ignore … … 203 212 204 213 echo '<tr valign="top">'; 205 echo '<td colspan="2"><input type="checkbox" name="accept-terms" id="accept-terms" value="1" /> <label for="accept-terms"'.($error_terms?' style="color:red;font-weight:bold;"':'').'>'.__('I have backed up my database and will assume the responsability of any data loss or corruption.','auto-domain-change').'</label></td>'; 214 echo '<td colspan="2"><input type="checkbox" name="accept-terms" id="accept-terms" value="1" /> <label for="accept-terms"'.($error_terms?' style="color:red;font-weight:bold;"':'').'>'.__('I have backed up my database, checked the backups integrity, know how to restore it, and will assume the responsability of any data loss or corruption.','auto-domain-change').'</label>'; 215 echo '<br>'; 216 echo '<br>'; 217 echo '<p class="backup">'; 218 echo '<button class="adc-backup-button" data-type="sql">'.__('Backup database as SQL','auto-domain-change').'</button>'; 219 //echo ' '; 220 //echo '<button class="adc-backup-button" data-type="php">'.__('Backup database as PHP','auto-domain-change').'</button>'; 221 echo '</p>'; 222 echo '</td>'; 206 223 //echo '<td colspan="2"><input type="checkbox" name="accept-terms" id="accept-terms" value="1" /> <label for="accept-terms"'.($error_terms?' style="color:red;font-weight:bold;"':'').'>'.__('I have <a id="adc-backup-button" href="">backed up my database</a> and will assume the responsability of any data loss or corruption.','auto-domain-change').'</label></td>'; 207 224 echo '</tr>'; … … 217 234 wp_nonce_field($action,'nonce'); 218 235 echo '<input type="hidden" name="action" value="'.$action.'" />'; 236 echo '<input type="hidden" name="type" value="sql" />'; 219 237 echo '</form>'; 220 238 echo <<<EOD 221 239 <script> 222 240 (function($){ 223 $(' #adc-backup-button').click(function(ev){241 $('.adc-backup-button').click(function(ev){ 224 242 ev.preventDefault(); 243 $('#adc-backup-db input[name=type]').val( $(this).attr('data-type') ); 225 244 $('#adc-backup-db').submit(); 226 245 }); … … 254 273 echo '<hr>'; 255 274 256 mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 257 mysql_select_db(DB_NAME); 258 mysql_query('SET NAMES '.DB_CHARSET); 259 if (function_exists('mysql_set_charset')) mysql_set_charset(DB_CHARSET); 260 261 $ret = mysql_query('SHOW TABLES;'); 275 $ret = $wpdb->get_results('SHOW TABLES;'); 262 276 $tables = array(); 263 while ($row = mysql_fetch_assoc($ret)) {264 $row = array_values($row);277 foreach ($ret as $row) { 278 $row = get_object_vars($row); 265 279 $tables [] = reset($row); 266 280 } … … 271 285 272 286 // Get table indices 273 $ret = mysql_query('SHOW INDEX FROM '.$t); 287 $ret = $wpdb->get_results('SHOW INDEX FROM '.$t); 288 274 289 $id = null; 275 while ($row = mysql_fetch_assoc($ret)) { 290 foreach ($ret as $row) { 291 $row = get_object_vars($row); 276 292 if ($row['Key_name'] == 'PRIMARY') { 277 293 $id = $row['Column_name']; … … 291 307 292 308 // Process all rows 293 $ret = mysql_query('SELECT * FROM '.$t); 294 while ($row = mysql_fetch_assoc($ret)) { 295 $fields = array(); 296 $sets = array(); 297 298 // Process all columns 299 foreach ($row as $k=>$v) { 300 // Save original value 301 $ov = $v; 302 303 // Process value 304 $v = $this->processValue($v, $old, $new); 305 306 // If value changed, replace it 307 if ($ov != $v) { 308 $sets[] = '`'.$k.'`="'.mysql_real_escape_string($v).'"'; 309 $o = 0; 310 do { 311 $sql = 'SELECT * FROM ' . $t. ' LIMIT '.$o.',50;'; 312 $ret = $wpdb->get_results( $sql ); 313 foreach ($ret as $row) { 314 $row = get_object_vars($row); 315 316 $fields = array(); 317 $sets = array(); 318 319 // Process all columns 320 foreach ( $row as $k => $v ) { 321 // Save original value 322 $ov = $v; 323 324 // Process value 325 $v = $this->processValue( $v, $old, $new ); 326 327 // If value changed, replace it 328 if ( $ov != $v ) { 329 $sets[] = '`' . $k . '`="' . esc_sql( $v ) . '"'; 330 } 309 331 } 310 } 311 312 // Update table if we have something to set 313 if (count($sets) > 0) { 314 $sql = 'UPDATE '.$t.' SET '.implode(',',$sets).' WHERE `'.$id.'`='.$row[$id].' LIMIT 1;'; 315 mysql_query($sql); 316 } 317 } 332 333 // Update table if we have something to set 334 if ( count( $sets ) > 0 ) { 335 $sql = 'UPDATE ' . $t . ' SET ' . implode( ',', $sets ) . ' WHERE `' . $id . '`=' . $row[ $id ] . ' LIMIT 1;'; 336 $wpdb->get_results($sql); 337 } 338 } 339 340 $o += count($ret); 341 } while (count($ret) > 0); 318 342 } 319 343 … … 362 386 363 387 /** 364 * Change domain. This is where the magic happens. 365 * Called by admin_page() upon form submission. 388 * Backup database as SQL 366 389 * 367 390 * @author Tommy Lacroix <tlacroix@nuagelab.com> 368 391 * @access private 369 392 */ 370 private function do_backup ()393 private function do_backup_sql() 371 394 { 372 395 global $wpdb; … … 379 402 header('Content-Disposition: attachment; filename="'.$fn.'"'); 380 403 381 mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); 382 mysql_select_db(DB_NAME); 383 mysql_query('SET NAMES '.DB_CHARSET); 384 if (function_exists('mysql_set_charset')) mysql_set_charset(DB_CHARSET); 385 386 $ret = mysql_query('SHOW TABLES;'); 404 $ret = $wpdb->get_results('SHOW TABLES;'); 387 405 $tables = array(); 388 while ($row = mysql_fetch_assoc($ret)) { 406 foreach ($ret as $row) { 407 $row = get_object_vars($row); 389 408 $row = array_values($row); 390 409 $tables [] = reset($row); … … 396 415 397 416 // Get table indices 398 $ret = mysql_query('SHOW CREATE TABLE '.$t);417 $ret = $wpdb->get_results('SHOW CREATE TABLE '.$t); 399 418 $id = null; 400 while ($row = mysql_fetch_assoc($ret)) {401 $ct = $row ['Create Table'];419 foreach ($ret as $row) { 420 $ct = $row->{'Create Table'}; 402 421 echo $ct.';'.PHP_EOL; 403 422 } 404 423 405 424 // Process all rows 406 $ret = mysql_query('SELECT * FROM '.$t); 407 while ($row = mysql_fetch_assoc($ret)) { 408 $ak = array(); 409 $av = array(); 410 foreach ($row as $k=>$v) { 411 $ak[] = '`'.mysql_real_escape_string($k).'`'; 412 if ($v === null) $av[] = 'NULL'; 413 else $av[] = '"'.mysql_real_escape_string($v).'"'; 414 } 415 printf('INSERT INTO `%1$s` (%2$s) VALUES (%3$s);'.PHP_EOL, $t, implode(',',$ak), implode(',', $av)); 416 } 425 $o = 0; 426 do { 427 $ret = $wpdb->get_results( 'SELECT * FROM ' . $t . ' LIMIT '.$o.',50;' ); 428 foreach ($ret as $row) { 429 $row = get_object_vars($row); 430 431 $ak = array(); 432 $av = array(); 433 foreach ( $row as $k => $v ) { 434 $ak[] = '`' . esc_sql( $k ) . '`'; 435 if ( $v === null ) { 436 $av[] = 'NULL'; 437 } else { 438 $av[] = '"' . esc_sql( $v ) . '"'; 439 } 440 } 441 printf( 'INSERT INTO `%1$s` (%2$s) VALUES (%3$s);' . PHP_EOL, $t, implode( ',', $ak ), implode( ',', $av ) ); 442 } 443 $o += count($ret); 444 } while (count($ret) > 0); 417 445 echo PHP_EOL; 418 446 echo PHP_EOL; … … 420 448 421 449 die; 422 } // do_backup() 450 } // do_backup_sql() 451 452 453 /** 454 * Backup database as PHP 455 * 456 * @author Tommy Lacroix <tlacroix@nuagelab.com> 457 * @access private 458 */ 459 private function do_backup_php() 460 { 461 global $wpdb; 462 463 @set_time_limit(0); 464 465 $fn = preg_replace('/[^a-zA-Z0-9_\-]/', '_', preg_replace(',http(|s)://,i','',get_bloginfo('url'))).'-'.date('Ymd-His').'.php'; 466 467 header('Content-Type: text/plain; charset="UTF-8"'); 468 header('Content-Disposition: attachment; filename="'.$fn.'"'); 469 470 echo '<?php'.PHP_EOL; 471 echo '// Put this file at the root of your WordPress installation and execute it.'.PHP_EOL.PHP_EOL; 472 echo 'require "wp-config.php";' . PHP_EOL; 473 echo 'global $wpdb;' . PHP_EOL; 474 475 $ret = $wpdb->get_results('SHOW TABLES;'); 476 $tables = array(); 477 foreach ($ret as $row) { 478 $row = get_object_vars($row); 479 $row = array_values($row); 480 $tables [] = reset($row); 481 } 482 483 $ifdrop = 'if (isset($_GET["drop"])) $wpdb->get_var("DROP TABLE IF EXISTS `%T%`;"); if ($wpdb->last_error) die("Query failed");'.PHP_EOL; 484 485 foreach ($tables as $t) { 486 // Skip if the table name doesn't match the wordpress prefix 487 if (substr($t,0,strlen($wpdb->prefix)) != $wpdb->prefix) continue; 488 489 // Get table indices 490 $ret = $wpdb->get_results('SHOW CREATE TABLE '.$t); 491 $id = null; 492 foreach ($ret as $row) { 493 $ct = $row->{'Create Table'}; 494 echo str_replace('%T%', $t, $ifdrop); 495 printf('$wpdb->get_results('.var_export($ct, true).'); if ($wpdb->last_error) die("Query failed");'); 496 echo PHP_EOL; 497 } 498 499 // Process all rows 500 $o = 0; 501 do { 502 $ret = $wpdb->get_results( 'SELECT * FROM ' . $t . ' LIMIT ' . $o . ',50;' ); 503 foreach ( $ret as $row ) { 504 $row = get_object_vars( $row ); 505 $ak = array(); 506 $av = array(); 507 foreach ( $row as $k => $v ) { 508 $ak[] = '`' . esc_sql( $k ) . '`'; 509 if ( $v === null ) { 510 $av[] = 'NULL'; 511 } else { 512 $av[] = '"' . esc_sql( $v ) . '"'; 513 } 514 } 515 $query = sprintf( 'INSERT INTO `%1$s` (%2$s) VALUES (%3$s);', $t, implode( ',', $ak ), implode( ',', $av ) ); 516 echo '$wpdb->get_results(' . var_export($query,true). '); if ($wpdb->last_error) die("Query failed");'; 517 echo PHP_EOL; 518 } 519 $o += count($ret); 520 } while (count($ret) > 0); 521 echo PHP_EOL; 522 echo PHP_EOL; 523 } 524 525 die; 526 } // do_backup_php() 423 527 424 528 -
automatic-domain-changer/trunk/languages/auto-domain-change-es_ES.po
r1131397 r1357009 8 8 "Project-Id-Version: Auto Domain Changer\n" 9 9 "Report-Msgid-Bugs-To: \n" 10 "POT-Creation-Date: 201 4-09-17 10:31-0500\n"11 "PO-Revision-Date: 201 4-09-17 10:31-0500\n"10 "POT-Creation-Date: 2015-12-18 12:55-0500\n" 11 "PO-Revision-Date: 2015-12-18 12:57-0500\n" 12 12 "Last-Translator: Tommy Lacroix <tlacroix@nuagelab.com>\n" 13 13 "Language-Team: NuageLab <wordpress-plugins@nuagelab.com>\n" … … 19 19 "X-Poedit-SourceCharset: UTF-8\n" 20 20 "X-Poedit-Bookmarks: -1,430,-1,-1,-1,-1,-1,-1,-1,-1\n" 21 "X-Generator: Poedit 1. 5.4\n"21 "X-Generator: Poedit 1.7.4\n" 22 22 "X-Poedit-Basepath: ./\n" 23 23 "X-Poedit-KeywordsList: __;_e;_n\n" 24 24 "X-Poedit-SearchPath-0: ..\n" 25 25 26 #: ../auto-domain-change.php:1 1826 #: ../auto-domain-change.php:124 27 27 #, php-format 28 28 msgid "" … … 35 35 "\">ignorar</a>." 36 36 37 #: ../auto-domain-change.php:1 34 ../auto-domain-change.php:17437 #: ../auto-domain-change.php:140 ../auto-domain-change.php:180 38 38 msgid "Change Domain" 39 39 msgstr "Cambiar el dominio" 40 40 41 #: ../auto-domain-change.php:1 8541 #: ../auto-domain-change.php:191 42 42 msgid "Change domain from: " 43 43 msgstr "Cambiar el dominio de:" 44 44 45 #: ../auto-domain-change.php:19 045 #: ../auto-domain-change.php:196 46 46 msgid "Change domain to: " 47 47 msgstr "Cambiar el dominio al:" 48 48 49 #: ../auto-domain-change.php: 19649 #: ../auto-domain-change.php:202 50 50 msgid "Also change secure <code>https</code> links" 51 51 msgstr "También cambiar los enlaces seguros <code>https</code>" 52 52 53 #: ../auto-domain-change.php:20 153 #: ../auto-domain-change.php:207 54 54 msgid "" 55 55 "Change both <code>www.old-domain.com</code> and <code>old-domain.com</code> " … … 59 59 "domain.com</code>" 60 60 61 #: ../auto-domain-change.php:2 0561 #: ../auto-domain-change.php:211 62 62 msgid "" 63 "I have backed up my database and will assume the responsability of any data " 64 "loss or corruption." 63 "I have backed up my database, checked the backups integrity, know how to " 64 "restore it, and will assume the responsability of any data loss or " 65 "corruption." 65 66 msgstr "" 66 "He hecho una copia de seguridad de mi base de datos y no asumen ninguna " 67 "responsabilidad por cualquier pérdida o corrupción de datos." 67 "He hecho una copia de seguridad de mi base de datos, he verificado su " 68 "integridad, y asumo todo responsabilidad por cualquier pérdida o corrupción " 69 "de datos." 68 70 69 #: ../auto-domain-change.php:211 71 #: ../auto-domain-change.php:215 72 msgid "Backup database as SQL" 73 msgstr "Copia de seguridad como SQL" 74 75 #: ../auto-domain-change.php:217 76 msgid "Backup database as PHP" 77 msgstr "Copia de seguridad como PHP" 78 79 #: ../auto-domain-change.php:225 70 80 msgid "Change domain" 71 81 msgstr "Cambiar el dominio" 72 82 73 #: ../auto-domain-change.php:2 5283 #: ../auto-domain-change.php:268 74 84 #, php-format 75 85 msgid "Old domain: %1$s" 76 86 msgstr "Antiguo dominio: %1$s" 77 87 78 #: ../auto-domain-change.php:2 5388 #: ../auto-domain-change.php:269 79 89 #, php-format 80 90 msgid "New domain: %1$s" 81 91 msgstr "Nuevo dominio: %1$s" 82 92 83 #: ../auto-domain-change.php:2 8593 #: ../auto-domain-change.php:298 84 94 #, php-format 85 95 msgid "Skipping table %1$s because no unique id" … … 87 97 "La table %1$s ha sido ignorado, ya que no contiene identificadores únicos" 88 98 89 #: ../auto-domain-change.php: 28999 #: ../auto-domain-change.php:302 90 100 #, php-format 91 101 msgid "Processing table %1$s" 92 102 msgstr "Procesamiento tabla %1$s" 93 103 94 #: ../auto-domain-change.php:34 3104 #: ../auto-domain-change.php:344 95 105 msgid "Back" 96 106 msgstr "Volver" 107 108 #~ msgid "" 109 #~ "I have backed up my database and will assume the responsability of any " 110 #~ "data loss or corruption." 111 #~ msgstr "" 112 #~ "He hecho una copia de seguridad de mi base de datos y no asumen ninguna " 113 #~ "responsabilidad por cualquier pérdida o corrupción de datos." -
automatic-domain-changer/trunk/languages/auto-domain-change-fr_FR.po
r1131397 r1357009 8 8 "Project-Id-Version: Auto Domain Changer\n" 9 9 "Report-Msgid-Bugs-To: \n" 10 "POT-Creation-Date: 201 4-09-17 10:31-0500\n"11 "PO-Revision-Date: 201 4-09-17 10:31-0500\n"10 "POT-Creation-Date: 2015-12-18 12:53-0500\n" 11 "PO-Revision-Date: 2015-12-18 12:54-0500\n" 12 12 "Last-Translator: Tommy Lacroix <tlacroix@nuagelab.com>\n" 13 13 "Language-Team: NuageLab <wordpress-plugins@nuagelab.com>\n" … … 19 19 "X-Poedit-SourceCharset: UTF-8\n" 20 20 "X-Poedit-Bookmarks: -1,430,-1,-1,-1,-1,-1,-1,-1,-1\n" 21 "X-Generator: Poedit 1. 5.4\n"21 "X-Generator: Poedit 1.7.4\n" 22 22 "X-Poedit-Basepath: ./\n" 23 23 "X-Poedit-KeywordsList: __;_e;_n\n" 24 24 "X-Poedit-SearchPath-0: ..\n" 25 25 26 #: ../auto-domain-change.php:1 1826 #: ../auto-domain-change.php:124 27 27 #, php-format 28 28 msgid "" … … 35 35 "\">ignorer</a>." 36 36 37 #: ../auto-domain-change.php:1 34 ../auto-domain-change.php:17437 #: ../auto-domain-change.php:140 ../auto-domain-change.php:180 38 38 msgid "Change Domain" 39 39 msgstr "Changer le domaine" 40 40 41 #: ../auto-domain-change.php:1 8541 #: ../auto-domain-change.php:191 42 42 msgid "Change domain from: " 43 43 msgstr "Changer le domaine de :" 44 44 45 #: ../auto-domain-change.php:19 045 #: ../auto-domain-change.php:196 46 46 msgid "Change domain to: " 47 47 msgstr "Changer le domaine à :" 48 48 49 #: ../auto-domain-change.php: 19649 #: ../auto-domain-change.php:202 50 50 msgid "Also change secure <code>https</code> links" 51 51 msgstr "Changer également les liens sécurisés <code>https</code>" 52 52 53 #: ../auto-domain-change.php:20 153 #: ../auto-domain-change.php:207 54 54 msgid "" 55 55 "Change both <code>www.old-domain.com</code> and <code>old-domain.com</code> " … … 59 59 "domain.com</code>" 60 60 61 #: ../auto-domain-change.php:2 0561 #: ../auto-domain-change.php:211 62 62 msgid "" 63 "I have backed up my database and will assume the responsability of any data " 64 "loss or corruption." 63 "I have backed up my database, checked the backups integrity, know how to " 64 "restore it, and will assume the responsability of any data loss or " 65 "corruption." 65 66 msgstr "" 66 "J'ai fait une copie de sauvegarde de ma base de données et j'assume toute " 67 "J'ai fait un copie de sauvegarde de ma base de données, j'ai vérifié son " 68 "intégrité, je sais comment le remettre en place, et j'assume toute " 67 69 "responsabilité en cas de perte ou de corruption de données." 68 70 69 #: ../auto-domain-change.php:211 71 #: ../auto-domain-change.php:215 72 msgid "Backup database as SQL" 73 msgstr "Sauvegarde de la base de données au format SQL" 74 75 #: ../auto-domain-change.php:217 76 msgid "Backup database as PHP" 77 msgstr "Sauvegarde de la base de données au format PHP" 78 79 #: ../auto-domain-change.php:225 70 80 msgid "Change domain" 71 81 msgstr "Changer le domaine" 72 82 73 #: ../auto-domain-change.php:2 5283 #: ../auto-domain-change.php:268 74 84 #, php-format 75 85 msgid "Old domain: %1$s" 76 86 msgstr "Ancien domaine : %1$s" 77 87 78 #: ../auto-domain-change.php:2 5388 #: ../auto-domain-change.php:269 79 89 #, php-format 80 90 msgid "New domain: %1$s" 81 91 msgstr "Nouveau domaine : %1$s" 82 92 83 #: ../auto-domain-change.php:2 8593 #: ../auto-domain-change.php:298 84 94 #, php-format 85 95 msgid "Skipping table %1$s because no unique id" … … 87 97 "La table %1$s a été ignorée car elle ne contient pas d'identifiants uniques" 88 98 89 #: ../auto-domain-change.php: 28999 #: ../auto-domain-change.php:302 90 100 #, php-format 91 101 msgid "Processing table %1$s" 92 102 msgstr "Traitement de la table %1$s" 93 103 94 #: ../auto-domain-change.php:34 3104 #: ../auto-domain-change.php:344 95 105 msgid "Back" 96 106 msgstr "Retour" 107 108 #~ msgid "" 109 #~ "I have backed up my database and will assume the responsability of any " 110 #~ "data loss or corruption." 111 #~ msgstr "" 112 #~ "J'ai fait une copie de sauvegarde de ma base de données et j'assume toute " 113 #~ "responsabilité en cas de perte ou de corruption de données." -
automatic-domain-changer/trunk/readme.txt
r1206460 r1357009 4 4 Tags: admin, administration, links, resources, domain change, migration 5 5 Requires at least: 3.0 6 Tested up to: 4. 2.36 Tested up to: 4.4.2 7 7 Stable tag: trunk 8 8 License: GPLv2 or later … … 83 83 84 84 == Changelog == 85 = 2.0.0 = 86 * Tested up to WordPress 4.4.2 87 * Added backup functionnality 88 * Removed usage of mysql_* functions in favor of $wpdb 89 85 90 = 1.0.1 = 86 * Tested up to 4.2.291 * Tested up to WordPress 4.2.2 87 92 88 93 = 1.0 = 89 * Tested up to 4.2.194 * Tested up to WordPress 4.2.1 90 95 91 96 = 0.0.6 = 92 97 * Bug fix with the processValue function generating a warning (thanks to @sniemetz for letting us know about this issue) 93 98 * Slovak translation (thanks to Marek Letko) 94 * Tested up to 4.1.199 * Tested up to WordPress 4.1.1 95 100 96 101 = 0.0.5 =
Note: See TracChangeset
for help on using the changeset viewer.