The WP Remote WordPress Plugin - Version 2.0.3

Version Description

Download this release

Release Info

Developer willmot
Plugin Icon 128x128 The WP Remote WordPress Plugin
Version 2.0.3
Comparing to
See all releases

Code changes from version 2.0.2 to 2.0.3

hm-backup/hm-backup.php CHANGED
@@ -94,48 +94,7 @@ class HM_Backup {
94
  * @static
95
  * @access public
96
  */
97
- private static $instance;
98
-
99
- /**
100
- * An array of all the files in root
101
- * excluding excludes
102
- *
103
- * @var array
104
- * @access private
105
- */
106
- private $files;
107
-
108
- /**
109
- * Contains an array of errors
110
- *
111
- * @var mixed
112
- * @access private
113
- */
114
- private $errors;
115
-
116
- /**
117
- * Contains an array of warnings
118
- *
119
- * @var mixed
120
- * @access private
121
- */
122
- private $warnings;
123
-
124
- /**
125
- * The archive method used
126
- *
127
- * @var string
128
- * @access private
129
- */
130
- private $archive_method;
131
-
132
- /**
133
- * The mysqldump method used
134
- *
135
- * @var string
136
- * @access private
137
- */
138
- private $mysqldump_method;
139
 
140
  /**
141
  * Sets up the default properties
@@ -149,12 +108,8 @@ class HM_Backup {
149
  @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
150
  @set_time_limit( 0 );
151
 
152
- $this->errors = array();
153
-
154
- set_error_handler( array( &$this, 'error_handler' ) );
155
-
156
  // Defaults
157
- $this->root = $this->conform_dir( ABSPATH );
158
 
159
  $this->path = $this->conform_dir( WP_CONTENT_DIR . '/backups' );
160
 
@@ -193,17 +148,7 @@ class HM_Backup {
193
  * @return string
194
  */
195
  public function archive_filepath() {
196
- return trailingslashit( $this->path() ) . $this->archive_filename();
197
- }
198
-
199
- /**
200
- * The full filepath to the archive file.
201
- *
202
- * @access public
203
- * @return string
204
- */
205
- public function archive_filename() {
206
- return strtolower( sanitize_file_name( remove_accents( $this->archive_filename ) ) );
207
  }
208
 
209
  /**
@@ -213,27 +158,7 @@ class HM_Backup {
213
  * @return string
214
  */
215
  public function database_dump_filepath() {
216
- return trailingslashit( $this->path() ) . $this->database_dump_filename();
217
- }
218
-
219
- public function database_dump_filename() {
220
- return strtolower( sanitize_file_name( remove_accents( $this->database_dump_filename ) ) );
221
- }
222
-
223
- public function root() {
224
- return $this->conform_dir( $this->root );
225
- }
226
-
227
- public function path() {
228
- return $this->conform_dir( $this->path );
229
- }
230
-
231
- public function archive_method() {
232
- return $this->archive_method;
233
- }
234
-
235
- public function mysqldump_method() {
236
- return $this->mysqldump_method;
237
  }
238
 
239
  /**
@@ -253,7 +178,7 @@ class HM_Backup {
253
  // Zip everything up
254
  $this->archive();
255
 
256
- do_action( 'hmbkp_backup_complete', $this );
257
 
258
  }
259
 
@@ -270,8 +195,6 @@ class HM_Backup {
270
 
271
  do_action( 'hmbkp_mysqldump_started' );
272
 
273
- $this->mysqldump_method = 'mysqldump';
274
-
275
  // Use mysqldump if we can
276
  if ( $this->mysqldump_command_path ) {
277
 
@@ -323,15 +246,13 @@ class HM_Backup {
323
  */
324
  public function mysqldump_fallback() {
325
 
326
- $this->mysqldump_method = 'mysqldump_fallback';
327
-
328
  $this->db = mysql_pconnect( DB_HOST, DB_USER, DB_PASSWORD );
329
 
330
  mysql_select_db( DB_NAME, $this->db );
331
  mysql_set_charset( DB_CHARSET, $this->db );
332
 
333
  // Begin new backup of MySql
334
- $tables = mysql_query( 'SHOW TABLES' );
335
 
336
  $sql_file = "# WordPress : " . get_bloginfo( 'url' ) . " MySQL database backup\n";
337
  $sql_file .= "#\n";
@@ -374,11 +295,11 @@ class HM_Backup {
374
  $this->zip();
375
 
376
  // If not or if the shell zip failed then use ZipArchive
377
- if ( ( empty( $this->archive_verified ) || $this->errors() ) && class_exists( 'ZipArchive' ) && empty( $this->skip_zip_archive ) )
378
  $this->zip_archive();
379
 
380
  // If ZipArchive is unavailable or one of the above failed
381
- if ( ( empty( $this->archive_verified ) || $this->errors() ) )
382
  $this->pcl_zip();
383
 
384
  // Delete the database dump file
@@ -397,21 +318,17 @@ class HM_Backup {
397
  */
398
  public function zip() {
399
 
400
- $this->archive_method = 'zip';
401
-
402
  // Zip up $this->root with excludes
403
  if ( ! $this->database_only && $this->exclude_string( 'zip' ) )
404
- $this->error( 'zip', shell_exec( 'cd ' . escapeshellarg( $this->root() ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -rq ' . escapeshellarg( $this->archive_filepath() ) . ' ./' . ' -x ' . $this->exclude_string( 'zip' ) . ' 2>&1' ) );
405
-
406
  // Zip up $this->root without excludes
407
  elseif ( ! $this->database_only )
408
- $this->error( 'zip', shell_exec( 'cd ' . escapeshellarg( $this->root() ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -rq ' . escapeshellarg( $this->archive_filepath() ) . ' ./' . ' 2>&1' ) );
409
-
410
  // Add the database dump to the archive
411
  if ( ! $this->files_only )
412
- $this->error( 'zip', shell_exec( 'cd ' . escapeshellarg( $this->path() ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -uq ' . escapeshellarg( $this->archive_filepath() ) . ' ' . escapeshellarg( $this->database_dump_filename() ) . ' 2>&1' ) );
413
-
414
- $this->check_archive();
415
 
416
  }
417
 
@@ -424,8 +341,6 @@ class HM_Backup {
424
  */
425
  public function zip_archive() {
426
 
427
- $this->archive_method = 'ziparchive';
428
-
429
  $zip = new ZipArchive();
430
 
431
  if ( ! class_exists( 'ZipArchive' ) || ! $zip->open( $this->archive_filepath(), ZIPARCHIVE::CREATE ) )
@@ -433,15 +348,26 @@ class HM_Backup {
433
 
434
  if ( ! $this->database_only ) {
435
 
 
 
436
  $files_added = 0;
437
 
438
- foreach ( $this->files() as $file ) {
439
 
440
- if ( is_dir( trailingslashit( $this->root() ) . $file ) )
441
- $zip->addEmptyDir( trailingslashit( $file ) );
442
 
443
- elseif ( is_file( trailingslashit( $this->root() ) . $file ) )
444
- $zip->addFile( trailingslashit( $this->root() ) . $file, $file );
 
 
 
 
 
 
 
 
 
 
445
 
446
  if ( ++$files_added % 500 === 0 )
447
  if ( ! $zip->close() || ! $zip->open( $this->archive_filepath(), ZIPARCHIVE::CREATE ) )
@@ -453,18 +379,10 @@ class HM_Backup {
453
 
454
  // Add the database
455
  if ( ! $this->files_only )
456
- $zip->addFile( $this->database_dump_filepath(), $this->database_dump_filename() );
457
-
458
- if ( $zip->status )
459
- $this->error( 'ziparchive', $zip->status );
460
-
461
- if ( $zip->statusSys )
462
- $this->error( 'ziparchive', $zip->statusSys );
463
 
464
  $zip->close();
465
 
466
- $this->check_archive();
467
-
468
  }
469
 
470
  /**
@@ -478,200 +396,27 @@ class HM_Backup {
478
  */
479
  public function pcl_zip() {
480
 
481
- $this->archive_method = 'pclzip';
482
-
483
  global $_hmbkp_exclude_string;
484
 
485
  $_hmbkp_exclude_string = $this->exclude_string( 'regex' );
486
 
487
- $this->load_pclzip();
 
 
 
488
 
489
  $archive = new PclZip( $this->archive_filepath() );
490
 
491
  // Zip up everything
492
  if ( ! $this->database_only )
493
- if ( ! $archive->add( $this->root(), PCLZIP_OPT_REMOVE_PATH, $this->root(), PCLZIP_CB_PRE_ADD, 'hmbkp_pclzip_callback' ) )
494
- $this->error( 'pclzip', $archive->errorInfo( true ) );
495
 
496
  // Add the database
497
  if ( ! $this->files_only )
498
- if ( ! $archive->add( $this->database_dump_filepath(), PCLZIP_OPT_REMOVE_PATH, $this->path() ) )
499
- $this->error( 'pclzip', $archive->errorInfo( true ) );
500
 
501
  unset( $GLOBALS['_hmbkp_exclude_string'] );
502
 
503
- $this->check_archive();
504
-
505
- }
506
-
507
- /**
508
- * Verify that the archive is valid and contains all the files it should contain.
509
- *
510
- * @access public
511
- * @return bool
512
- */
513
- public function check_archive() {
514
-
515
- // If we've already passed then no need to check again
516
- if ( ! empty( $this->archive_verified ) )
517
- return true;
518
-
519
- if ( ! file_exists( $this->archive_filepath() ) )
520
- $this->error( $this->archive_method(), __( 'The backup file was not created', 'hmbkp' ) );
521
-
522
- // Verify using the zip command if possible
523
- if ( ! $this->errors() && $this->zip_command_path ) {
524
-
525
- $verify = shell_exec( escapeshellarg( $this->zip_command_path ) . ' -T ' . escapeshellarg( $this->archive_filepath() ) . ' 2> /dev/null' );
526
-
527
- if ( strpos( $verify, 'OK' ) === false )
528
- $this->error( $this->archive_method(), $verify );
529
-
530
- }
531
-
532
- if ( ! $this->errors() ) {
533
-
534
- // If it's a file backup, get an array of all the files that should have been backed up
535
- if ( ! $this->database_only )
536
- $files = $this->files();
537
-
538
- // Check that the database was backed up
539
- if ( ! $this->files_only )
540
- $files[] = $this->database_dump_filename();
541
-
542
- $this->load_pclzip();
543
-
544
- $archive = new PclZip( $this->archive_filepath() );
545
- $filesystem = $archive->extract( PCLZIP_OPT_EXTRACT_AS_STRING );
546
-
547
- foreach( $filesystem as $file )
548
- $archive_files[] = untrailingslashit( $file['filename'] );
549
-
550
- // Check that the array of files that should have been backed up matches the array of files in the zip
551
- if ( $files !== $archive_files )
552
- $this->error( $this->archive_method(), __( 'Backup file doesn\'t contain the the following files: ', 'hmbkp' ) . implode( ', ', array_diff( $files, $archive_files ) ) );
553
-
554
- }
555
-
556
- // If there are errors delete the backup file.
557
- if ( $this->errors() && file_exists( $this->archive_filepath() ) )
558
- unlink( $this->archive_filepath() );
559
-
560
- if ( $this->errors() )
561
- return false;
562
-
563
- return $this->archive_verified = true;
564
-
565
- }
566
-
567
- /**
568
- * Generate the array of files to be backed up by looping through
569
- * root, ignored unreadable files and excludes
570
- *
571
- * @access public
572
- * @return array
573
- */
574
- public function files() {
575
-
576
- if ( ! empty( $this->files ) )
577
- return $this->files;
578
-
579
- $this->files = array();
580
-
581
- if ( defined( 'RecursiveDirectoryIterator::FOLLOW_SYMLINKS' ) ) {
582
-
583
- $filesystem = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $this->root(), RecursiveDirectoryIterator::FOLLOW_SYMLINKS ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
584
-
585
- $excludes = $this->exclude_string( 'regex' );
586
-
587
- foreach ( $filesystem as $file ) {
588
-
589
- if ( ! $file->isReadable() ) {
590
- $this->unreadable_files[] = $file->getPathName();
591
- continue;
592
- }
593
-
594
- $pathname = str_ireplace( trailingslashit( $this->root() ), '', $this->conform_dir( $file->getPathname() ) );
595
-
596
- // Excludes
597
- if ( $excludes && preg_match( '(' . $excludes . ')', $pathname ) )
598
- continue;
599
-
600
- // Don't include database dump as it's added separately
601
- if ( basename( $pathname ) == $this->database_dump_filename() )
602
- continue;
603
-
604
- $this->files[] = $pathname;
605
-
606
- }
607
-
608
- } else {
609
-
610
- $this->files = $this->files_fallback( $this->root() );
611
-
612
- }
613
-
614
- if ( ! empty( $this->unreadable_files ) )
615
- $this->warning( $this->archive_method(), __( 'The following files are unreadable and couldn\'t be backed up: ', 'hmbkp' ) . implode( ', ', $this->unreadable_files ) );
616
-
617
- return $this->files;
618
-
619
- }
620
-
621
- /**
622
- * Fallback function for generating a filesystem
623
- * array
624
- *
625
- * Used if RecursiveDirectoryIterator::FOLLOW_SYMLINKS isn't available
626
- *
627
- * @access private
628
- * @param stromg $dir
629
- * @param array $files. (default: array())
630
- * @return array
631
- */
632
- private function files_fallback( $dir, $files = array() ) {
633
-
634
- $handle = opendir( $dir );
635
-
636
- $excludes = $this->exclude_string( 'regex' );
637
-
638
- while ( $file = readdir( $handle ) ) :
639
-
640
- // Ignore current dir and containing dir and any unreadable files or directories
641
- if ( $file == '.' || $file == '..' )
642
- continue;
643
-
644
- $filepath = $this->conform_dir( trailingslashit( $dir ) . $file );
645
- $file = str_ireplace( trailingslashit( $this->root() ), '', $filepath );
646
-
647
- if ( ! is_readable( $filepath ) ) {
648
- $this->unreadable_files[] = $filepath;
649
- continue;
650
- }
651
-
652
- // Skip the backups dir and any excluded paths
653
- if ( ( $excludes && preg_match( '(' . $excludes . ')', $file ) ) )
654
- continue;
655
-
656
- $files[] = $file;
657
-
658
- if ( is_dir( $filepath ) )
659
- $files = $this->files_fallback( $filepath, $files );
660
-
661
- endwhile;
662
-
663
- return $files;
664
-
665
- }
666
-
667
- private function load_pclzip() {
668
-
669
- // Load PclZip
670
- if ( ! defined( 'PCLZIP_TEMPORARY_DIR' ) )
671
- define( 'PCLZIP_TEMPORARY_DIR', $this->path() );
672
-
673
- require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
674
-
675
  }
676
 
677
  /**
@@ -772,10 +517,6 @@ class HM_Backup {
772
  // Sanitize the excludes
773
  $excludes = array_filter( array_unique( array_map( 'trim', (array) $this->excludes ) ) );
774
 
775
- // If path() is inside root(), exclude it
776
- if ( strpos( $this->path(), $this->root() ) !== false )
777
- $excludes[] = trailingslashit( $this->path() );
778
-
779
  foreach( $excludes as $key => &$rule ) {
780
 
781
  $file = $absolute = $fragment = false;
@@ -793,7 +534,7 @@ class HM_Backup {
793
  $fragment = true;
794
 
795
  // Strip $this->root and conform
796
- $rule = str_ireplace( $this->root(), '', untrailingslashit( $this->conform_dir( $rule ) ) );
797
 
798
  // Strip the preceeding slash
799
  if ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
@@ -827,7 +568,7 @@ class HM_Backup {
827
 
828
  // Escape shell args for zip command
829
  if ( $context == 'zip' )
830
- $excludes = array_map( 'escapeshellarg', array_unique( $excludes ) );
831
 
832
  return implode( $separator, $excludes );
833
 
@@ -941,7 +682,7 @@ class HM_Backup {
941
  private function make_sql( $sql_file, $table ) {
942
 
943
  // Add SQL statement to drop existing table
944
- $sql_file .= "\n";
945
  $sql_file .= "\n";
946
  $sql_file .= "#\n";
947
  $sql_file .= "# Delete any existing table " . $this->sql_backquote( $table ) . "\n";
@@ -995,13 +736,11 @@ class HM_Backup {
995
 
996
  // Checks whether the field is an integer or not
997
  for ( $j = 0; $j < $fields_cnt; $j++ ) {
998
-
999
  $field_set[$j] = $this->sql_backquote( mysql_field_name( $result, $j ) );
1000
  $type = mysql_field_type( $result, $j );
1001
 
1002
  if ( $type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || $type == 'timestamp')
1003
  $field_num[$j] = true;
1004
-
1005
  else
1006
  $field_num[$j] = false;
1007
 
@@ -1116,94 +855,6 @@ class HM_Backup {
1116
 
1117
  }
1118
 
1119
- /**
1120
- * Get the errors
1121
- *
1122
- * @access public
1123
- * @return null
1124
- */
1125
- public function errors() {
1126
-
1127
- return $this->errors;
1128
-
1129
- }
1130
-
1131
-
1132
- /**
1133
- * Add an error to the errors stack
1134
- *
1135
- * @access private
1136
- * @param string $context
1137
- * @param mixed $error
1138
- * @return null
1139
- */
1140
- private function error( $context, $error ) {
1141
-
1142
- if ( empty( $context ) || empty( $error ) )
1143
- return;
1144
-
1145
- if ( $context == 'zip' && strpos( $error, 'zip warning' ) !== false )
1146
- return $this->warning( $context, $error );
1147
-
1148
-
1149
- $this->errors[$context][$_key = md5( implode( ':' , (array) $error ) )] = $error;
1150
-
1151
- }
1152
-
1153
- /**
1154
- * Get the warnings
1155
- *
1156
- * @access public
1157
- * @return null
1158
- */
1159
- public function warnings() {
1160
-
1161
- return $this->warnings;
1162
-
1163
- }
1164
-
1165
-
1166
- /**
1167
- * Add an warning to the warnings stack
1168
- *
1169
- * @access private
1170
- * @param string $context
1171
- * @param mixed $warning
1172
- * @return null
1173
- */
1174
- private function warning( $context, $warning ) {
1175
-
1176
- if ( empty( $context ) || empty( $warning ) )
1177
- return;
1178
-
1179
- $this->warnings[$context][$_key = md5( implode( ':' , (array) $warning ) )] = $warning;
1180
-
1181
- }
1182
-
1183
-
1184
- /**
1185
- * Custom error handler for catching errors
1186
- *
1187
- * @access private
1188
- * @param string $type
1189
- * @param string $message
1190
- * @param string $file
1191
- * @param string $line
1192
- * @return null
1193
- */
1194
- public function error_handler( $type ) {
1195
-
1196
- if ( in_array( $type, array( E_STRICT, E_DEPRECATED ) ) || error_reporting() === 0 )
1197
- return false;
1198
-
1199
- $args = func_get_args();
1200
-
1201
- $this->warning( 'php', array_splice( $args, 0, 4 ) );
1202
-
1203
- return false;
1204
-
1205
- }
1206
-
1207
  }
1208
 
1209
  /**
@@ -1221,7 +872,7 @@ function hmbkp_pclzip_callback( $event, &$file ) {
1221
  global $_hmbkp_exclude_string;
1222
 
1223
  // Don't try to add unreadable files.
1224
- if ( ! is_readable( $file['filename'] ) || ! file_exists( $file['filename'] ) )
1225
  return false;
1226
 
1227
  // Match everything else past the exclude list
94
  * @static
95
  * @access public
96
  */
97
+ public static $instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  /**
100
  * Sets up the default properties
108
  @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
109
  @set_time_limit( 0 );
110
 
 
 
 
 
111
  // Defaults
112
+ $this->root = ABSPATH;
113
 
114
  $this->path = $this->conform_dir( WP_CONTENT_DIR . '/backups' );
115
 
148
  * @return string
149
  */
150
  public function archive_filepath() {
151
+ return trailingslashit( $this->path ) . $this->archive_filename;
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
  /**
158
  * @return string
159
  */
160
  public function database_dump_filepath() {
161
+ return trailingslashit( $this->path ) . $this->database_dump_filename;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
  /**
178
  // Zip everything up
179
  $this->archive();
180
 
181
+ do_action( 'hmbkp_backup_complete' );
182
 
183
  }
184
 
195
 
196
  do_action( 'hmbkp_mysqldump_started' );
197
 
 
 
198
  // Use mysqldump if we can
199
  if ( $this->mysqldump_command_path ) {
200
 
246
  */
247
  public function mysqldump_fallback() {
248
 
 
 
249
  $this->db = mysql_pconnect( DB_HOST, DB_USER, DB_PASSWORD );
250
 
251
  mysql_select_db( DB_NAME, $this->db );
252
  mysql_set_charset( DB_CHARSET, $this->db );
253
 
254
  // Begin new backup of MySql
255
+ $tables = mysql_list_tables( DB_NAME );
256
 
257
  $sql_file = "# WordPress : " . get_bloginfo( 'url' ) . " MySQL database backup\n";
258
  $sql_file .= "#\n";
295
  $this->zip();
296
 
297
  // If not or if the shell zip failed then use ZipArchive
298
+ if ( ! file_exists( $this->archive_filepath() ) && class_exists( 'ZipArchive' ) && empty( $this->skip_zip_archive ) )
299
  $this->zip_archive();
300
 
301
  // If ZipArchive is unavailable or one of the above failed
302
+ if ( ! file_exists( $this->archive_filepath() ) )
303
  $this->pcl_zip();
304
 
305
  // Delete the database dump file
318
  */
319
  public function zip() {
320
 
 
 
321
  // Zip up $this->root with excludes
322
  if ( ! $this->database_only && $this->exclude_string( 'zip' ) )
323
+ shell_exec( 'cd ' . escapeshellarg( $this->root ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -rq ' . escapeshellarg( $this->archive_filepath() ) . ' ./' . ' -x ' . $this->exclude_string( 'zip' ) . ' 2> /dev/null' );
324
+
325
  // Zip up $this->root without excludes
326
  elseif ( ! $this->database_only )
327
+ shell_exec( 'cd ' . escapeshellarg( $this->root ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -rq ' . escapeshellarg( $this->archive_filepath() ) . ' ./' . ' 2> /dev/null' );
328
+
329
  // Add the database dump to the archive
330
  if ( ! $this->files_only )
331
+ shell_exec( 'cd ' . escapeshellarg( $this->path ) . ' && ' . escapeshellarg( $this->zip_command_path ) . ' -uq ' . escapeshellarg( $this->archive_filepath() ) . ' ' . escapeshellarg( $this->database_dump_filename ) . ' 2> /dev/null' );
 
 
332
 
333
  }
334
 
341
  */
342
  public function zip_archive() {
343
 
 
 
344
  $zip = new ZipArchive();
345
 
346
  if ( ! class_exists( 'ZipArchive' ) || ! $zip->open( $this->archive_filepath(), ZIPARCHIVE::CREATE ) )
348
 
349
  if ( ! $this->database_only ) {
350
 
351
+ $files = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $this->root ), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD );
352
+
353
  $files_added = 0;
354
 
355
+ $excludes = $this->exclude_string( 'regex' );
356
 
357
+ foreach ( $files as $file ) {
 
358
 
359
+ if ( ! $file->isReadable() )
360
+ continue;
361
+
362
+ // Excludes
363
+ if ( $excludes && preg_match( '(' . $excludes . ')', str_replace( $this->root, '', $this->conform_dir( $file->getPathname() ) ) ) )
364
+ continue;
365
+
366
+ if ( $file->isDir() )
367
+ $zip->addEmptyDir( str_replace( trailingslashit( $this->root ), '', trailingslashit( $file->getPathname() ) ) );
368
+
369
+ elseif ( $file->isFile() )
370
+ $zip->addFile( $file, str_replace( trailingslashit( $this->root ), '', $file->getPathname() ) );
371
 
372
  if ( ++$files_added % 500 === 0 )
373
  if ( ! $zip->close() || ! $zip->open( $this->archive_filepath(), ZIPARCHIVE::CREATE ) )
379
 
380
  // Add the database
381
  if ( ! $this->files_only )
382
+ $zip->addFile( $this->database_dump_filepath(), $this->database_dump_filename );
 
 
 
 
 
 
383
 
384
  $zip->close();
385
 
 
 
386
  }
387
 
388
  /**
396
  */
397
  public function pcl_zip() {
398
 
 
 
399
  global $_hmbkp_exclude_string;
400
 
401
  $_hmbkp_exclude_string = $this->exclude_string( 'regex' );
402
 
403
+ if ( ! defined( 'PCLZIP_TEMPORARY_DIR' ) )
404
+ define( 'PCLZIP_TEMPORARY_DIR', $this->path );
405
+
406
+ require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
407
 
408
  $archive = new PclZip( $this->archive_filepath() );
409
 
410
  // Zip up everything
411
  if ( ! $this->database_only )
412
+ $archive->add( $this->root, PCLZIP_OPT_REMOVE_PATH, $this->root, PCLZIP_CB_PRE_ADD, 'hmbkp_pclzip_callback' );
 
413
 
414
  // Add the database
415
  if ( ! $this->files_only )
416
+ $archive->add( $this->database_dump_filepath(), PCLZIP_OPT_REMOVE_PATH, $this->path );
 
417
 
418
  unset( $GLOBALS['_hmbkp_exclude_string'] );
419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  }
421
 
422
  /**
517
  // Sanitize the excludes
518
  $excludes = array_filter( array_unique( array_map( 'trim', (array) $this->excludes ) ) );
519
 
 
 
 
 
520
  foreach( $excludes as $key => &$rule ) {
521
 
522
  $file = $absolute = $fragment = false;
534
  $fragment = true;
535
 
536
  // Strip $this->root and conform
537
+ $rule = str_replace( $this->conform_dir( $this->root ), '', untrailingslashit( $this->conform_dir( $rule ) ) );
538
 
539
  // Strip the preceeding slash
540
  if ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
568
 
569
  // Escape shell args for zip command
570
  if ( $context == 'zip' )
571
+ $excludes = array_map( 'escapeshellarg', $excludes );
572
 
573
  return implode( $separator, $excludes );
574
 
682
  private function make_sql( $sql_file, $table ) {
683
 
684
  // Add SQL statement to drop existing table
685
+ $sql_file = "\n";
686
  $sql_file .= "\n";
687
  $sql_file .= "#\n";
688
  $sql_file .= "# Delete any existing table " . $this->sql_backquote( $table ) . "\n";
736
 
737
  // Checks whether the field is an integer or not
738
  for ( $j = 0; $j < $fields_cnt; $j++ ) {
 
739
  $field_set[$j] = $this->sql_backquote( mysql_field_name( $result, $j ) );
740
  $type = mysql_field_type( $result, $j );
741
 
742
  if ( $type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' || $type == 'timestamp')
743
  $field_num[$j] = true;
 
744
  else
745
  $field_num[$j] = false;
746
 
855
 
856
  }
857
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
858
  }
859
 
860
  /**
872
  global $_hmbkp_exclude_string;
873
 
874
  // Don't try to add unreadable files.
875
+ if ( ! is_readable( $file['filename'] ) || ! file_exists( $file['filename'] ) || is_link( $file['filename'] ) )
876
  return false;
877
 
878
  // Match everything else past the exclude list
wprp.plugin.php → plugin.php RENAMED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Manage your WordPress site with <a href="https://wpremote.com/">WP Remote</a>. Deactivate to clear your API Key.
6
- Version: 2.0.2
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  */
3
  /*
4
  Plugin Name: WP Remote
5
  Description: Manage your WordPress site with <a href="https://wpremote.com/">WP Remote</a>. Deactivate to clear your API Key.
6
+ Version: 2.0.3
7
  Author: Human Made Limited
8
  Author URI: http://hmn.md/
9
  */
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: humanmade, joehoyle, mattheu, tcrsavage, willmot
3
  Tags: wpremote, remote administration, multiple wordpress
4
  Requires at least: 2.9
5
  Tested up to: 3.3.1
6
- Stable tag: 2.0.2
7
 
8
  WP Remote is a free web app that enables you to easily manage all of your WordPress powered sites from one place.
9
 
3
  Tags: wpremote, remote administration, multiple wordpress
4
  Requires at least: 2.9
5
  Tested up to: 3.3.1
6
+ Stable tag: 2.0.3
7
 
8
  WP Remote is a free web app that enables you to easily manage all of your WordPress powered sites from one place.
9