forked from interconnectit/Search-Replace-DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
5476 lines (4879 loc) · 291 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
*
* Safe Search and Replace on Database with Serialized Data v4.1.3
* Copyright © 2020 Interconnect IT Limited
*
* This script is to solve the problem of doing database search and replace when
* some data is stored within PHP serialized arrays or objects.
*
* For more information, see
* http://interconnectit.com/124/search-and-replace-for-wordpress-databases/
*
* To contribute go to
* http://github.com/interconnectit/search-replace-db
*
* To use, load the script on your server and point your web browser to it.
* In some situations, consider using the command line interface version.
*
* BIG WARNING! Take a backup first, and carefully test the results of this
* code. If you don't, and you vape your data then you only have yourself to
* blame. Seriously. And if your English is bad and you don't fully
* understand the instructions then STOP. Right there. Yes. Before you do any
* damage.
*
* USE OF THIS SCRIPT IS ENTIRELY AT YOUR OWN RISK. I/We accept no liability
* from its use.
*
* First Written 2009-05-25 by David Coveney of Interconnect IT Ltd (UK)
* http://www.davidcoveney.com or http://interconnectit.com
* and released under the GPL v3
* ie, do what ever you want with the code, and we take no responsibility for it
* OK? If you don't wish to take responsibility, hire us at Interconnect IT Ltd
* on +44 (0)151 331 5140 and we will do the work for you at our hourly rate,
* minimum 1hr
*
* This file is part of Search-Replace-DB.
*
* Search-Replace-DB is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or any later version.
*
* Search-Replace-DB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Search-Replace-DB.
* If not, see <https://www.gnu.org/licenses/>.
*/
require_once( realpath( dirname( __FILE__ ) ) . '/srdb.class.php' );
class icit_srdb_ui extends icit_srdb {
/**
* @var string Root path of the CMS
*/
public $path;
public $name;
public $user;
public $pass;
public $host;
public $port;
public $charset;
public $collate;
public $tables;
public $search;
public $replace;
public $exclude_cols;
public $include_cols;
public $regex;
public $regex_i;
public $regex_m;
public $regex_s;
public $regex_x;
public function __construct() {
// php 5.4 date timezone requirement, shouldn't affect anything
date_default_timezone_set( 'Europe/London' );
// prevent fatals from hiding the UI
register_shutdown_function( array( $this, 'fatal_handler' ) );
$this->response();
}
public function response(
$name = '',
$user = '',
$pass = '',
$host = '127.0.0.1',
$port = 3306,
$charset = 'utf8',
$collate = ''
) {
if ( version_compare( PHP_VERSION, '7.3' ) < 0 ) {
$this->add_error( "This script has been tested using PHP7.3 +, whereas your version is: " . PHP_VERSION . ". Although this script may work with older versions you do so at your own risk. Please update php and try again",
"compatibility" );
}
if ( ! extension_loaded( "mbstring" ) ) {
$this->add_error( "This script requires mbstring. Please install mbstring and try again", "compatibility" );
}
// always override with post data
if ( isset( $_POST['name'] ) ) {
$this->name = $_POST['name']; // your database
$this->user = $_POST['user']; // your db userid
$this->pass = $_POST['pass']; // your db password
$this->host = $_POST['host']; // normally localhost, but not necessarily.
$port_input = $_POST['port'];
// Make sure that the string version of absint(port) is identical to the string input.
// This prevents expressions, decimals, spaces, etc.
$port_as_string = (string) $port_input ? (string) $port_input : "0";
if ( (string) abs( (int) $port_input ) !== $port_as_string ) {
// Mangled port number: non numeric.
$this->add_error( 'Port number must be a positive integer. If you are unsure, try the default port 3306.',
'db' );
// Force a bad run by supplying nonsense.
$this->port = "nonsense";
} else {
$this->port = abs( (int) $port_input );
}
$this->charset = 'utf8';
$this->collate = '';
}
// Search replace details
$this->search = isset( $_POST['search'] ) ? $_POST['search'] : '';
$this->replace = isset( $_POST['replace'] ) ? $_POST['replace'] : '';
// regex options
$this->regex = isset( $_POST['regex'] );
$this->regex_i = isset( $_POST['regex_i'] );
$this->regex_m = isset( $_POST['regex_m'] );
$this->regex_s = isset( $_POST['regex_s'] );
$this->regex_x = isset( $_POST['regex_x'] );
// Tables to scanned
$this->tables = isset( $_POST['tables'] ) && is_array( $_POST['tables'] ) ? $_POST['tables'] : array();
if ( isset( $_POST['use_tables'] ) && $_POST['use_tables'] == 'all' ) {
$this->tables = array();
}
// exclude / include columns
$this->exclude_cols = isset( $_POST['exclude_cols'] ) ? $_POST['exclude_cols'] : array();
if ( $this->exclude_cols && is_string( $this->exclude_cols ) ) {
$this->exclude_cols = array_filter( array_map( 'trim', explode( ',', $this->exclude_cols ) ) );
}
$this->include_cols = isset( $_POST['include_cols'] ) ? $_POST['include_cols'] : array();
if ( $this->include_cols && is_string( $this->include_cols ) ) {
$this->include_cols = array_filter( array_map( 'trim', explode( ',', $this->include_cols ) ) );
}
// are doing something?
$show = '';
if ( isset( $_POST['submit'] ) ) {
if ( is_array( $_POST['submit'] ) ) {
$show = key( $_POST['submit'] );
}
if ( is_string( $_POST['submit'] ) ) {
$show = preg_replace( '/submit\[([a-z0-9]+)\]/', '$1', $_POST['submit'] );
}
}
// is it an AJAX call
$ajax = isset( $_POST['ajax'] );
// body callback
$html = 'ui';
switch ( $show ) {
// remove search replace
case 'delete':
{
// determine if it's the folder of compiled version
$path = basename( __FILE__ ) == 'index.php' ? str_replace( basename( __FILE__ ), '',
__FILE__ ) : __FILE__;
if ( $this->delete_script( $path ) ) {
$this->add_error( 'Could not fully delete Search/Replace. You will have to delete it manually',
'delete' );
} else {
if ( ! ( is_file( __FILE__ ) && file_exists( __FILE__ ) ) ) {
$this->add_error( 'Search/Replace has been successfully removed from your server', 'delete' );
}
}
$html = 'deleted';
break;
}
case 'liverun':
{
// bsy-web, 20130621: Check live run was explicitly clicked and only set false then
$this->dry_run = false;
}
case 'dryrun':
{
// build regex string
// non UI implements can just pass in complete regex string
if ( $this->regex ) {
$mods = '';
if ( $this->regex_i ) {
$mods .= 'i';
}
if ( $this->regex_s ) {
$mods .= 's';
}
if ( $this->regex_m ) {
$mods .= 'm';
}
if ( $this->regex_x ) {
$mods .= 'x';
}
if(is_array($this->search)){
foreach ($this->search as $searchKey => $searchString){
$this->search[$searchKey] = '/' . $searchString . '/' . $mods;
}
}else{
$this->search = '/' . $this->search . '/' . $mods;
}
}
// call search replace class
$parent = parent::__construct( array(
'name' => $this->name,
'user' => $this->user,
'pass' => $this->pass,
'host' => $this->host,
'port' => $this->port,
'search' => $this->search,
'replace' => $this->replace,
'tables' => $this->tables,
'dry_run' => $this->dry_run,
'regex' => $this->regex,
'exclude_cols' => $this->exclude_cols,
'include_cols' => $this->include_cols
) );
break;
}
case 'innodb':
{
// call search replace class to alter engine
$parent = parent::__construct( array(
'name' => $this->name,
'user' => $this->user,
'pass' => $this->pass,
'host' => $this->host,
'port' => $this->port,
'tables' => $this->tables,
'alter_engine' => 'InnoDB',
) );
break;
}
case 'utf8':
{
// call search replace class to alter engine
$parent = parent::__construct( array(
'name' => $this->name,
'user' => $this->user,
'pass' => $this->pass,
'host' => $this->host,
'port' => $this->port,
'tables' => $this->tables,
'alter_collation' => 'utf8_unicode_ci',
) );
break;
}
case 'utf8mb4':
{
// call search replace class to alter engine
$parent = parent::__construct( array(
'name' => $this->name,
'user' => $this->user,
'pass' => $this->pass,
'host' => $this->host,
'port' => $this->port,
'tables' => $this->tables,
'alter_collation' => 'utf8mb4_unicode_ci',
) );
break;
}
case 'update':
default:
{
// get tables or error messages
$this->db_setup();
if ( $this->db_valid() ) {
// get engines
$this->engines = $this->get_engines();
// get tables
$this->all_tables = $this->get_tables();
}
break;
}
}
$info = array(
'table_select' => $this->table_select( false ),
'engines' => $this->engines
);
// set header again before output in case WP does it's thing
header( 'HTTP/1.1 200 OK' );
header( 'Cache-Control: no-cache, no-store, must-revalidate' ); // HTTP 1.1.
header( 'Pragma: no-cache' ); // HTTP 1.0.
header( 'Expires: 0' ); // Proxies.
if ( ! $ajax ) {
$this->html( $html );
} else {
// return json version of results
header( 'Content-Type: application/json' );
echo json_encode( array(
'errors' => $this->errors,
'report' => $this->report,
'info' => $info
) );
exit;
}
}
public function exceptions( $exception ) {
$this->add_error( '<p class="exception">' . $exception->getMessage() . '</p>' );
}
public function error_handler( $no, $message, $file, $line ) {
$this->add_error( '<p class="error">' . "<strong>{$no}:</strong> {$message} in {$file} on line {$line}" . '</p>',
'results' );
$this->add_error( 'This is usually caused by a plugin storing classes as a serialised string which other
PHP classes can\'t then access. It is not possible to unserialise this data because the PHP can\'t access this class.
P.S. It\'s most commonly a Yoast plugin that causes this error. Your changes will still have taken place within the rest of the database.',
'results' );
}
public function fatal_handler() {
$error = error_get_last();
if ( $error !== null ) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
if ( $errno == 1 ) {
header( 'HTTP/1.1 200 OK' );
$this->add_error( '<p class="error">Could not bootstrap environment.<br /> ' . "Fatal error in {$errfile}, line {$errline}. {$errstr}" . '</p>',
'environment' );
$this->response();
}
}
}
/**
* Checks an array of fully qualified filenames to see if they are all
* SRDB filenames.
*
* @param array $array_of_paths
*
* @return boolean true if all paths are most likely SRDB files.
*/
public function safe_to_delete_all_filenames( $array_of_paths ) {
foreach ( $array_of_paths as $path ) {
if ( ! $this->safe_to_delete_filename( $path ) ) {
return false;
}
}
return true;
}
/**
* Delete files and directories
*
* @param string $path directory/file path
*
*/
public function delete_script( $path ) {
$path = rtrim( $path, DIRECTORY_SEPARATOR );
$file_list = array(
"README.md",
"srdb.cli.php",
"composer.lock",
"CHANGELOG.md",
"phpunit.xml",
"index.php",
"LICENSE.txt",
"composer.json",
"package.json",
"tests" . DIRECTORY_SEPARATOR . "DataSetGenerator.php",
"tests" . DIRECTORY_SEPARATOR . "DataSet.xml",
"tests" . DIRECTORY_SEPARATOR . "SrdbTest.php",
"srdb.class.php",
);
foreach ( $file_list as $file ) {
if ( is_file( $path . DIRECTORY_SEPARATOR . $file ) ) {
if ( @unlink( $path . DIRECTORY_SEPARATOR . $file ) === false ) {
return - 1;
}
}
}
if ( is_dir( $path . DIRECTORY_SEPARATOR . 'tests' ) ) {
if ( @rmdir( $path . DIRECTORY_SEPARATOR . 'tests' ) === false ) {
return - 1;
}
}
return 0;
}
/**
* Simple html escaping
*
* @param string $string Thing that needs escaping
* @param bool $echo Do we echo or return?
*
* @return string Escaped string.
*/
public function esc_html_attr( $string = '', $echo = false ) {
$output = htmlentities( $string, ENT_QUOTES, 'UTF-8' );
if ( $echo ) {
echo $output;
} else {
return $output;
}
}
public function checked( $value, $value2, $echo = true ) {
$output = $value == $value2 ? ' checked="checked"' : '';
if ( $echo ) {
echo $output;
}
return $output;
}
public function selected( $value, $value2, $echo = true ) {
$output = $value == $value2 ? ' selected="selected"' : '';
if ( $echo ) {
echo $output;
}
return $output;
}
public function get_errors( $type ) {
if ( ! isset( $this->errors[ $type ] ) || ! count( $this->errors[ $type ] ) ) {
return;
}
echo '<div class="errors">';
$dup_errors = array();
foreach ( $this->errors[ $type ] as $error ) {
if ( ! in_array( $error, $dup_errors ) ) {
if ( $error instanceof Exception ) {
echo '<p class="exception">' . $error->getMessage() . '</p>';
} elseif ( is_string( $error ) ) {
echo $error;
}
}
array_push( $dup_errors, $error );
}
echo '</div>';
}
public function get_report( $table = null ) {
$report = $this->report;
if ( empty( $report ) ) {
return;
}
$report = $report[0];
$dry_run = $this->dry_run;
$search = $this->search;
$replace = $this->replace;
// Calc the time taken.
$time = array_sum( explode( ' ', $report['end'] ) ) - array_sum( explode( ' ', $report['start'] ) );
if ( $time < 0 ) {
$time = $time * - 1;
}
$srch_rplc_input_phrase = $dry_run ?
'searching for <strong>"' . $this->esc_html_attr( $search ) . '"</strong> (to be replaced by <strong>"' . $this->esc_html_attr( $replace ) . '"</strong>)' :
'replacing <strong>"' . $this->esc_html_attr( $search ) . '"</strong> with <strong>"' . $this->esc_html_attr( $replace ) . '"</strong>';
echo '
<div class="report">';
echo '
<h2>Report</h2>';
echo '
<p>';
printf(
'In the process of %s we scanned <strong>%d</strong> tables with a total of
<strong>%d</strong> rows, <strong>%d</strong> cells %s changed.
<strong>%d</strong> db updates were actually performed.
It all took <strong>%f</strong> seconds.',
$srch_rplc_input_phrase,
$report['tables'],
$report['rows'],
$report['change'],
$dry_run ? 'would have been' : 'were',
$report['updates'],
$time
);
echo '
</p>';
echo '
<table class="table-reports-0">
<thead>
<tr>
<th>Table</th>
<th>Rows</th>
<th>Cells changed</th>
<th>Updates</th>
<th>Seconds</th>
</tr>
</thead>
<tbody>';
foreach ( $report['table_reports'] as $table => $t_report ) {
$t_time = array_sum( explode( ' ', $t_report['end'] ) ) - array_sum( explode( ' ', $t_report['start'] ) );
echo '
<tr>';
printf( '
<th>%s:</th>
<td>%d</td>
<td>%d</td>
<td>%d</td>
<td>%f</td>',
$table,
$t_report['rows'],
$t_report['change'],
$t_report['updates'],
$t_time
);
echo '
</tr>';
}
echo '
</tbody>
</table>';
echo '
</div>';
}
public function table_select( $echo = true ) {
$table_select = '';
if ( ! empty( $this->all_tables ) ) {
$table_select .= '<select name="tables[]" multiple="multiple">';
foreach ( $this->all_tables as $table ) {
$size = $table['Data_length'] / 1000;
$size_unit = 'kb';
if ( $size > 1000 ) {
$size = $size / 1000;
$size_unit = 'Mb';
}
if ( $size > 1000 ) {
$size = $size / 1000;
$size_unit = 'Gb';
}
$size = number_format( $size, 2 ) . $size_unit;
$rows = $table['Rows'] > 1 ? 'rows' : 'row';
$table_select .= sprintf( '<option value="%s" %s>%s</option>',
$this->esc_html_attr( $table[0], false ),
$this->selected( true, in_array( $table[0], $this->tables ), false ),
"{$table[0]}: {$table['Engine']}, rows: {$table['Rows']}, size: {$size}, collation: {$table['Collation']}, character_set: {$table['Character_set']}"
);
}
$table_select .= '</select>';
}
if ( $echo ) {
echo $table_select;
}
return $table_select;
}
public function isSecure() {
return
! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off';
}
public function ui() {
if ( ! $this->isSecure() ) {
?>
<div class="special-errors">
<h4>Warning</h4>
<?php echo printf( '<p>The network connection you are using is transmitting your password unencrypted. <br/> Consider using an https:// connection, or change your database password after using the script </p>' ); ?>
</div>
<?php
}
// Warn if we're running in safe mode as we'll probably time out.
if ( ini_get( 'safe_mode' ) ) {
?>
<div class="special-errors">
<h4>Warning</h4>
<?php echo printf( '<p>Safe mode is on so you may run into problems if it takes longer than %s seconds to process your request.</p>',
ini_get( 'max_execution_time' ) ); ?>
</div>
<?php
}
?>
<?php
// templates/ui.php
?>
<form action="" method="post">
<!-- 1. search/replace -->
<fieldset class="row row-search">
<h1>Search<span>Replace</span></h1>
<?php $this->get_errors( 'search' ); ?>
<div class="fields fields-large">
<div class="sr-boxes">
<div class="sr-box-0">
<div class="field field-medium">
<label for="search-0"><span class="label-text">replace</span> <span
class="hide-if-regex-off regex-left">/</span><input id="search-0" type="text"
placeholder="search for…"
value="<?php $this->esc_html_attr( $this->search,
true ); ?>"
name="search-0"/><span
class="hide-if-regex-off regex-right">/</span></label>
</div>
<div class="field field-medium">
<label for="replace-0"><span class="label-text">with</span>
<input id="replace-0" type="text" placeholder="replace with…" value="<?php $this->esc_html_attr( $this->replace, true ); ?>" name="replace-0"/></label></div>
</div>
</div>
<div>
<button class="multi-search add-search" type="modify-ui" onclick="add_search()">+ add more
search terms
</button>
<button class="multi-search remove-search hide-if-multisearch-off" type="modify-ui"
onclick="remove_search()">- remove search terms
</button>
</div>
<label class="label-text" for="regex" class="field-advanced"><input id="regex" type="checkbox"
name="regex"
value="1" <?php $this->checked( true,
$this->regex ); ?> />
use regex</label>
<div class="fields field-advanced hide-if-regex-off">
<label for="regex_i" class="field field-advanced"><input type="checkbox" name="regex_i"
id="regex_i"
value="1" <?php $this->checked( true,
$this->regex_i ); ?> />
<abbr title="case insensitive">Case insensitive</abbr></abbr></label>
<label for="regex_m" class="field field-advanced"><input type="checkbox" name="regex_m"
id="regex_m"
value="1" <?php $this->checked( true,
$this->regex_m ); ?> />
<abbr title="multiline">Multiline</abbr></label>
<label for="regex_x" class="field field-advanced"><input type="checkbox" name="regex_x"
id="regex_x"
value="1" <?php $this->checked( true,
$this->regex_x ); ?> />
<abbr title="extended mode">Extended mode</abbr></label>
<label for="regex_s" class="field field-advanced"><input type="checkbox" name="regex_s"
id="regex_s"
value="1" <?php $this->checked( true,
$this->regex_s ); ?> />
<abbr title="dot also matches newlines">Dot also matches newlines</abbr></label>
</div>
</fieldset>
<!-- 2. db details -->
<fieldset class="row row-db">
<h1>Database Details</h1>
<?php $this->get_errors( 'environment' ); ?>
<?php $this->get_errors( 'recoverable_db' ); ?>
<?php $this->get_errors( 'compatibility' ); ?>
<?php $this->get_errors( 'connection' ); ?>
<div class="fields fields-small">
<div class="field field-short">
<label for="name">database name</label>
<input id="name" name="name" type="text"
value="<?php $this->esc_html_attr( $this->name, true ); ?>"/>
</div>
<div class="field field-short">
<label for="user">username</label>
<input id="user" name="user" type="text"
value="<?php $this->esc_html_attr( $this->user, true ); ?>"/>
</div>
<div class="field field-short">
<label for="pass">pass</label>
<input id="pass" name="pass" type="password"
value="<?php $this->esc_html_attr( $this->pass, true ); ?>"/>
</div>
<div class="field field-short">
<label for="host">host</label>
<input id="host" name="host" type="text"
value="<?php $this->esc_html_attr( $this->host, true ); ?>"/>
</div>
<div class="field field-short">
<label for="port">port</label>
<input id="port" name="port" type="text"
value="<?php $this->esc_html_attr( $this->port, true ); ?>"/>
</div>
<span class="submit-group">
<input type="submit" name="submit[update]" value="Test connection"/>
</span>
<div class="successful-connection" style="display:none">
Success. You are connected.
</div>
</div>
</fieldset>
<!-- 3. tables -->
<fieldset class="row row-tables">
<h1>Which Tables?</h1>
<?php $this->get_errors( 'tables' ); ?>
<div class="fields">
<div class="field radio">
<label for="all_tables">
<input id="all_tables" name="use_tables" value="all"
type="radio" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?> <?php $this->checked( true, empty( $this->tables ) ); ?> />
all tables
</label>
</div>
<div class="field radio">
<label for="subset_tables">
<input id="subset_tables" name="use_tables" value="subset"
type="radio" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?> <?php $this->checked( false, empty( $this->tables ) ); ?> />
select tables
</label>
</div>
<div class="field table-select hide-if-js"><?php $this->table_select(); ?></div>
</div>
<div class="fields field-advanced">
<div class="field field-advanced field-medium">
<label for="exclude_cols">columns to exclude (optional, comma separated)</label>
<input id="exclude_cols" type="text" name="exclude_cols"
value="<?php $this->esc_html_attr( implode( ',', $this->exclude_cols ) ) ?>"
placeholder="eg. guid"/>
</div>
<div class="field field-advanced field-medium">
<label for="include_cols">columns to include only (optional, comma separated)</label>
<input id="include_cols" type="text" name="include_cols"
value="<?php $this->esc_html_attr( implode( ',', $this->include_cols ) ) ?>"
placeholder="eg. post_content, post_excerpt"/>
</div>
</div>
<div class="fields">
<span class="submit-group">
<?php if ( in_array( 'InnoDB', $this->engines ) ) { ?>
<input type="submit" name="submit[innodb]"
value="convert to innodb" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?>
class="db-required secondary field-advanced"/>
<?php } ?>
<input type="submit" name="submit[utf8]"
value="convert to utf8 unicode" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?>
class="db-required secondary field-advanced"/>
<input type="submit" name="submit[utf8mb4]"
value="convert to utf8mb4 unicode" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?>
class="db-required secondary field-advanced"/>
</span>
</div>
</fieldset>
<!-- 4. results -->
<fieldset class="row row-results">
<h1>Let's go</h1>
<?php $this->get_errors( 'results' ); ?>
<div class="fields">
<span class="submit-group">
<div class="dryrun">
<input type="submit" name="submit[dryrun]"
value="Do a safe test run" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?>
class="db-required"/>
</div>
<hr>
<div class="liverun">
<div><p class="label-text">You cannot undo this once started - are you sure?</p></div>
<input type="submit" name="submit[liverun]"
value="Search and Replace" <?php if ( ! $this->db_valid() ) {
echo 'disabled="disabled"';
} ?>
class="db-required run-script"/>
</div>
</span>
</div>
<?php $this->get_report(); ?>
</fieldset>
<!-- 5. branding -->
<section class="row row-delete">
<h1>DELETE</h1>
<div class="fields">
<p>
<input type="submit" name="submit[delete]" value="delete me"/>
Once you’re done click the <strong>delete me</strong> button to secure your server
</p>
</div>
</section>
<div id="deleteModal" class="modal">
<!-- Modal content -->
<div class="modal-content">
<span class="close">×</span>
<p>Some text in the Modal..</p>
</div>
</div>
</form>
<section class="help">
<h1 class="branding">interconnect/it</h1>
<h2>Safe Search and Replace on Database with Serialized Data v4.1.3</h2>
<p>This developer/sysadmin tool carries out search/replace functions on MySQL DBs and can handle serialised
PHP Arrays and Objects.</p>
<p><strong class="red">WARNINGS!</strong>
Ensure data is backed up.
There is NO UNDO!
Be careful running this script on a production server.</p>
<h3>Don't Forget to Remove Me!</h3>
<p>Delete this utility from your
server after use by clicking the 'delete me' button. It represents a major security threat to your
database if
maliciously used.</p>
<p>If you have feedback or want to contribute to this script click the delete button to find out how.</p>
<p><em>We don't put links on the search replace UI itself to avoid seeing URLs for the script in our access
logs.</em></p>
<h3>Again, use Of This Script Is Entirely At Your Own Risk</h3>
<p>The easiest and safest way to use this script is to copy your site's files and DB to a new location.
You then, if required, fix up your .htaccess and wp-config.php appropriately. Once
done, run this script, select your tables (in most cases all of them) and then
enter the search replace strings. You can press back in your browser to do
this several times, as may be required in some cases.</p>
</section>
<?php
}
public function deleted() {
// templates/delete.php
?>
<!-- 1. branding -->
<section class="row row-branding">
<h1><a href="http://interconnectit.com/" target="_blank">interconnect<span>/</span><strong>it</strong></a>
</h1>
<?php $this->get_errors( 'delete' ); ?>
<div class="content">
<p>Thanks for using our search/replace tool! We’d really appreciate it if you took a
minute to join our mailing list and check out some of our other products.</p>
</div>
</section>
<!-- 2. subscribe -->
<section class="row row-subscribe">
<h1>Newsletter</h1>
<form action="http://interconnectit.us2.list-manage.com/subscribe/post" method="POST"
class="fields fields-small">
<input type="hidden" name="u" value="08ec797202866aded7b2619b2">
<input type="hidden" name="id" value="aa9c21f993">
<div id="mergeTable" class="mergeTable">
<div class="mergeRow dojoDndItem mergeRow-email field field-short" id="mergeRow-0">
<label for="MERGE0"><strong>email address</strong> <span class="asterisk">*</span></label>
<input type="email" autocapitalize="off" autocorrect="off" name="MERGE0" id="MERGE0" size="25"
value="">
</div>
<div class="mergeRow dojoDndItem mergeRow-text field field-short" id="mergeRow-1">
<label for="MERGE1">first name</label>
<input type="text" name="MERGE1" id="MERGE1" size="25" value="">
</div>
<div class="mergeRow dojoDndItem mergeRow-text field field-short" id="mergeRow-2">
<label for="MERGE2">last name</label>
<input type="text" name="MERGE2" id="MERGE2" size="25" value="">
</div>