All-in-One WP Migration - Version 6.51

Version Description

Added

  • Validation on leave feedback, report issue and delete backup actions
  • More descriptive wpress file names on export

Changed

  • Remove "Unable to authenticate with secret key" message

Fixed

  • Wrong file size in wpress file on export
Download this release

Release Info

Developer bangelov
Plugin Icon 128x128 All-in-One WP Migration
Version 6.51
Comparing to
See all releases

Code changes from version 6.50 to 6.51

all-in-one-wp-migration.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
- * Version: 6.50
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
+ * Version: 6.51
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
constants.php CHANGED
@@ -31,7 +31,7 @@ define( 'AI1WM_DEBUG', false );
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
- define( 'AI1WM_VERSION', '6.50' );
35
 
36
  // ===============
37
  // = Plugin Name =
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
+ define( 'AI1WM_VERSION', '6.51' );
35
 
36
  // ===============
37
  // = Plugin Name =
exceptions.php CHANGED
@@ -29,10 +29,13 @@ class Ai1wm_Export_Exception extends Exception {}
29
  class Ai1wm_Http_Exception extends Exception {}
30
  class Ai1wm_Import_Exception extends Exception {}
31
  class Ai1wm_Import_Retry_Exception extends Exception {}
32
- class Ai1wm_Not_Accesible_Exception extends Exception {}
33
- class Ai1wm_Not_Found_Exception extends Exception {}
 
34
  class Ai1wm_Not_Readable_Exception extends Exception {}
35
  class Ai1wm_Not_Writable_Exception extends Exception {}
36
- class Ai1wm_Quota_Exceeded_Exception extends Exception {}
 
37
  class Ai1wm_Not_Valid_Secret_Key_Exception extends Exception {}
 
38
  class Ai1wm_Storage_Exception extends Exception {}
29
  class Ai1wm_Http_Exception extends Exception {}
30
  class Ai1wm_Import_Exception extends Exception {}
31
  class Ai1wm_Import_Retry_Exception extends Exception {}
32
+ class Ai1wm_Not_Accessible_Exception extends Exception {}
33
+ class Ai1wm_Not_Seekable_Exception extends Exception {}
34
+ class Ai1wm_Not_Tellable_Exception extends Exception {}
35
  class Ai1wm_Not_Readable_Exception extends Exception {}
36
  class Ai1wm_Not_Writable_Exception extends Exception {}
37
+ class Ai1wm_Not_Found_Exception extends Exception {}
38
+ class Ai1wm_Not_Directory_Exception extends Exception {}
39
  class Ai1wm_Not_Valid_Secret_Key_Exception extends Exception {}
40
+ class Ai1wm_Quota_Exceeded_Exception extends Exception {}
41
  class Ai1wm_Storage_Exception extends Exception {}
functions.php CHANGED
@@ -275,25 +275,27 @@ function ai1wm_parse_size( $size, $default = null ) {
275
  /**
276
  * Get current site name
277
  *
 
278
  * @return string
279
  */
280
- function ai1wm_site_name() {
281
- return parse_url( site_url(), PHP_URL_HOST );
282
  }
283
 
284
  /**
285
  * Get archive file name
286
  *
 
287
  * @return string
288
  */
289
- function ai1wm_archive_file() {
290
  $name = array();
291
 
292
  // Add domain
293
- $name[] = parse_url( site_url(), PHP_URL_HOST );
294
 
295
  // Add path
296
- if ( ( $path = explode( '/', parse_url( site_url(), PHP_URL_PATH ) ) ) ) {
297
  foreach ( $path as $directory ) {
298
  if ( $directory ) {
299
  $name[] = $directory;
@@ -316,16 +318,17 @@ function ai1wm_archive_file() {
316
  /**
317
  * Get archive folder name
318
  *
 
319
  * @return string
320
  */
321
- function ai1wm_archive_folder() {
322
  $name = array();
323
 
324
  // Add domain
325
- $name[] = parse_url( site_url(), PHP_URL_HOST );
326
 
327
  // Add path
328
- if ( ( $path = explode( '/', parse_url( site_url(), PHP_URL_PATH ) ) ) ) {
329
  foreach ( $path as $directory ) {
330
  if ( $directory ) {
331
  $name[] = $directory;
@@ -766,15 +769,15 @@ function ai1wm_urldecode( $value ) {
766
  /**
767
  * Opens a file in specified mode
768
  *
769
- * @param string $file Path to the file to open
770
- * @param string $mode Mode in which to open the file
771
  * @return resource
772
- * @throws Ai1wm_Not_Accesible_Exception
773
  */
774
  function ai1wm_open( $file, $mode ) {
775
- $file_handle = fopen( $file, $mode );
776
  if ( false === $file_handle ) {
777
- throw new Ai1wm_Not_Accesible_Exception( sprintf( __( 'Unable to open %s with mode %s', AI1WM_PLUGIN_NAME ), $file, $mode ) );
778
  }
779
 
780
  return $file_handle;
@@ -785,12 +788,12 @@ function ai1wm_open( $file, $mode ) {
785
  *
786
  * @param resource $handle File handle to write to
787
  * @param string $content Contents to write to the file
788
- * @return int
789
  * @throws Ai1wm_Not_Writable_Exception
790
  * @throws Ai1wm_Quota_Exceeded_Exception
791
  */
792
  function ai1wm_write( $handle, $content ) {
793
- $write_result = fwrite( $handle, $content );
794
  if ( false === $write_result ) {
795
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
796
  throw new Ai1wm_Not_Writable_Exception( sprintf( __( 'Unable to write to: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
@@ -807,11 +810,11 @@ function ai1wm_write( $handle, $content ) {
807
  *
808
  * @param resource $handle File handle to read from
809
  * @param string $filesize File size
810
- * @return int
811
  * @throws Ai1wm_Not_Readable_Exception
812
  */
813
  function ai1wm_read( $handle, $filesize ) {
814
- $read_result = fread( $handle, $filesize );
815
  if ( false === $read_result ) {
816
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
817
  throw new Ai1wm_Not_Readable_Exception( sprintf( __( 'Unable to read file: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
@@ -821,11 +824,45 @@ function ai1wm_read( $handle, $filesize ) {
821
  return $read_result;
822
  }
823
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
824
  /**
825
  * Closes a file handle
826
  *
827
  * @param resource $handle File handle to close
828
- * @return bool
829
  */
830
  function ai1wm_close( $handle ) {
831
  return @fclose( $handle );
@@ -834,13 +871,35 @@ function ai1wm_close( $handle ) {
834
  /**
835
  * Deletes a file
836
  *
837
- * @param string $file Path to file to delete
838
- * @return bool
839
  */
840
  function ai1wm_unlink( $file ) {
841
  return @unlink( $file );
842
  }
843
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
844
  /**
845
  * Copies one file's contents to another
846
  *
@@ -862,8 +921,8 @@ function ai1wm_copy( $source_file, $destination_file ) {
862
  *
863
  * This method supports files > 2GB on PHP x86
864
  *
865
- * @param string $file_path Path to the file
866
- * @param bool $as_string Return the filesize as string instead of BigInteger
867
  *
868
  * @return mixed Math_BigInteger|string|null
869
  */
@@ -934,8 +993,8 @@ function ai1wm_disable_jetpack_photon() {
934
  /**
935
  * Verify secret key
936
  *
937
- * @param string $secret_key Secret key
938
- * @return bool
939
  * @throws Ai1wm_Not_Valid_Secret_Key_Exception
940
  */
941
  function ai1wm_verify_secret_key( $secret_key ) {
275
  /**
276
  * Get current site name
277
  *
278
+ * @param integer $blog_id Blog ID
279
  * @return string
280
  */
281
+ function ai1wm_site_name( $blog_id = null ) {
282
+ return parse_url( get_site_url( $blog_id ), PHP_URL_HOST );
283
  }
284
 
285
  /**
286
  * Get archive file name
287
  *
288
+ * @param integer $blog_id Blog ID
289
  * @return string
290
  */
291
+ function ai1wm_archive_file( $blog_id = null ) {
292
  $name = array();
293
 
294
  // Add domain
295
+ $name[] = parse_url( get_site_url( $blog_id ), PHP_URL_HOST );
296
 
297
  // Add path
298
+ if ( ( $path = explode( '/', parse_url( get_site_url( $blog_id ), PHP_URL_PATH ) ) ) ) {
299
  foreach ( $path as $directory ) {
300
  if ( $directory ) {
301
  $name[] = $directory;
318
  /**
319
  * Get archive folder name
320
  *
321
+ * @param integer $blog_id Blog ID
322
  * @return string
323
  */
324
+ function ai1wm_archive_folder( $blog_id = null ) {
325
  $name = array();
326
 
327
  // Add domain
328
+ $name[] = parse_url( get_site_url( $blog_id ), PHP_URL_HOST );
329
 
330
  // Add path
331
+ if ( ( $path = explode( '/', parse_url( get_site_url( $blog_id ), PHP_URL_PATH ) ) ) ) {
332
  foreach ( $path as $directory ) {
333
  if ( $directory ) {
334
  $name[] = $directory;
769
  /**
770
  * Opens a file in specified mode
771
  *
772
+ * @param string $file Path to the file to open
773
+ * @param string $mode Mode in which to open the file
774
  * @return resource
775
+ * @throws Ai1wm_Not_Accessible_Exception
776
  */
777
  function ai1wm_open( $file, $mode ) {
778
+ $file_handle = @fopen( $file, $mode );
779
  if ( false === $file_handle ) {
780
+ throw new Ai1wm_Not_Accessible_Exception( sprintf( __( 'Unable to open %s with mode %s', AI1WM_PLUGIN_NAME ), $file, $mode ) );
781
  }
782
 
783
  return $file_handle;
788
  *
789
  * @param resource $handle File handle to write to
790
  * @param string $content Contents to write to the file
791
+ * @return integer
792
  * @throws Ai1wm_Not_Writable_Exception
793
  * @throws Ai1wm_Quota_Exceeded_Exception
794
  */
795
  function ai1wm_write( $handle, $content ) {
796
+ $write_result = @fwrite( $handle, $content );
797
  if ( false === $write_result ) {
798
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
799
  throw new Ai1wm_Not_Writable_Exception( sprintf( __( 'Unable to write to: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
810
  *
811
  * @param resource $handle File handle to read from
812
  * @param string $filesize File size
813
+ * @return integer
814
  * @throws Ai1wm_Not_Readable_Exception
815
  */
816
  function ai1wm_read( $handle, $filesize ) {
817
+ $read_result = @fread( $handle, $filesize );
818
  if ( false === $read_result ) {
819
  if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
820
  throw new Ai1wm_Not_Readable_Exception( sprintf( __( 'Unable to read file: %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
824
  return $read_result;
825
  }
826
 
827
+ /**
828
+ * Seeks on a file pointer
829
+ *
830
+ * @param string $handle File handle to seeks
831
+ * @return integer
832
+ */
833
+ function ai1wm_seek( $handle, $offset, $mode = SEEK_SET ) {
834
+ $seek_result = @fseek( $handle, $offset, $mode );
835
+ if ( -1 === $seek_result ) {
836
+ if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
837
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( __( 'Unable to seek to offset %d on %s', AI1WM_PLUGIN_NAME ), $offset, $meta['uri'] ) );
838
+ }
839
+ }
840
+
841
+ return $seek_result;
842
+ }
843
+
844
+ /**
845
+ * Tells on a file pointer
846
+ *
847
+ * @param string $handle File handle to tells
848
+ * @return integer
849
+ */
850
+ function ai1wm_tell( $handle ) {
851
+ $tell_result = @ftell( $handle );
852
+ if ( false === $tell_result ) {
853
+ if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
854
+ throw new Ai1wm_Not_Tellable_Exception( sprintf( __( 'Unable to get current pointer position of %s', AI1WM_PLUGIN_NAME ), $meta['uri'] ) );
855
+ }
856
+ }
857
+
858
+ return $tell_result;
859
+ }
860
+
861
  /**
862
  * Closes a file handle
863
  *
864
  * @param resource $handle File handle to close
865
+ * @return boolean
866
  */
867
  function ai1wm_close( $handle ) {
868
  return @fclose( $handle );
871
  /**
872
  * Deletes a file
873
  *
874
+ * @param string $file Path to file to delete
875
+ * @return boolean
876
  */
877
  function ai1wm_unlink( $file ) {
878
  return @unlink( $file );
879
  }
880
 
881
+ /**
882
+ * Sets modification time of a file
883
+ *
884
+ * @param string $file Path to file to change modification time
885
+ * @param integer $time File modification time
886
+ * @return boolean
887
+ */
888
+ function ai1wm_touch( $file, $mtime ) {
889
+ return @touch( $file, $mtime );
890
+ }
891
+
892
+ /**
893
+ * Changes file mode
894
+ *
895
+ * @param string $file Path to file to change mode
896
+ * @param integer $time File mode
897
+ * @return boolean
898
+ */
899
+ function ai1wm_chmod( $file, $mode ) {
900
+ return @chmod( $file, $mode );
901
+ }
902
+
903
  /**
904
  * Copies one file's contents to another
905
  *
921
  *
922
  * This method supports files > 2GB on PHP x86
923
  *
924
+ * @param string $file_path Path to the file
925
+ * @param boolean $as_string Return the filesize as string instead of BigInteger
926
  *
927
  * @return mixed Math_BigInteger|string|null
928
  */
993
  /**
994
  * Verify secret key
995
  *
996
+ * @param string $secret_key Secret key
997
+ * @return boolean
998
  * @throws Ai1wm_Not_Valid_Secret_Key_Exception
999
  */
1000
  function ai1wm_verify_secret_key( $secret_key ) {
lib/controller/class-ai1wm-backups-controller.php CHANGED
@@ -39,29 +39,42 @@ class Ai1wm_Backups_Controller {
39
  }
40
 
41
  public static function delete( $params = array() ) {
42
- $response = array( 'errors' => array() );
43
 
44
  // Set params
45
  if ( empty( $params ) ) {
46
  $params = stripslashes_deep( $_POST );
47
  }
48
 
 
 
 
 
 
 
49
  // Set archive
50
  $archive = null;
51
  if ( isset( $params['archive'] ) ) {
52
  $archive = trim( $params['archive'] );
53
  }
54
 
 
 
 
 
 
 
 
55
  $model = new Ai1wm_Backups;
56
 
57
  try {
58
  // Delete file
59
  $model->delete_file( $archive );
60
  } catch ( Exception $e ) {
61
- $response['errors'][] = $e->getMessage();
62
  }
63
 
64
- echo json_encode( $response );
65
  exit;
66
  }
67
  }
39
  }
40
 
41
  public static function delete( $params = array() ) {
42
+ $errors = array();
43
 
44
  // Set params
45
  if ( empty( $params ) ) {
46
  $params = stripslashes_deep( $_POST );
47
  }
48
 
49
+ // Set secret key
50
+ $secret_key = null;
51
+ if ( isset( $params['secret_key'] ) ) {
52
+ $secret_key = trim( $params['secret_key'] );
53
+ }
54
+
55
  // Set archive
56
  $archive = null;
57
  if ( isset( $params['archive'] ) ) {
58
  $archive = trim( $params['archive'] );
59
  }
60
 
61
+ try {
62
+ // Ensure that unauthorized people cannot access delete action
63
+ ai1wm_verify_secret_key( $secret_key );
64
+ } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
65
+ exit;
66
+ }
67
+
68
  $model = new Ai1wm_Backups;
69
 
70
  try {
71
  // Delete file
72
  $model->delete_file( $archive );
73
  } catch ( Exception $e ) {
74
+ $errors[] = $e->getMessage();
75
  }
76
 
77
+ echo json_encode( array( 'errors' => $errors ) );
78
  exit;
79
  }
80
  }
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -52,14 +52,13 @@ class Ai1wm_Export_Controller {
52
  // Set secret key
53
  $secret_key = null;
54
  if ( isset( $params['secret_key'] ) ) {
55
- $secret_key = $params['secret_key'];
56
  }
57
 
58
  try {
59
  // Ensure that unauthorized people cannot access export action
60
  ai1wm_verify_secret_key( $secret_key );
61
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
62
- Ai1wm_Log::error( $e->getMessage() );
63
  exit;
64
  }
65
 
52
  // Set secret key
53
  $secret_key = null;
54
  if ( isset( $params['secret_key'] ) ) {
55
+ $secret_key = trim( $params['secret_key'] );
56
  }
57
 
58
  try {
59
  // Ensure that unauthorized people cannot access export action
60
  ai1wm_verify_secret_key( $secret_key );
61
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
 
62
  exit;
63
  }
64
 
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -32,36 +32,49 @@ class Ai1wm_Feedback_Controller {
32
  $params = stripslashes_deep( $_POST );
33
  }
34
 
35
- // Set Type
 
 
 
 
 
 
36
  $type = null;
37
  if ( isset( $params['ai1wm_type'] ) ) {
38
  $type = trim( $params['ai1wm_type'] );
39
  }
40
 
41
- // Set E-mail
42
  $email = null;
43
  if ( isset( $params['ai1wm_email'] ) ) {
44
  $email = trim( $params['ai1wm_email'] );
45
  }
46
 
47
- // Set Message
48
  $message = null;
49
  if ( isset( $params['ai1wm_message'] ) ) {
50
  $message = trim( $params['ai1wm_message'] );
51
  }
52
 
53
- // Set Terms
54
  $terms = false;
55
  if ( isset( $params['ai1wm_terms'] ) ) {
56
  $terms = (bool) $params['ai1wm_terms'];
57
  }
58
 
 
 
 
 
 
 
 
59
  $model = new Ai1wm_Feedback;
60
 
61
- // Send Feedback
62
- $response = $model->add( $type, $email, $message, $terms );
63
 
64
- echo json_encode( $response );
65
  exit;
66
  }
67
  }
32
  $params = stripslashes_deep( $_POST );
33
  }
34
 
35
+ // Set secret key
36
+ $secret_key = null;
37
+ if ( isset( $params['secret_key'] ) ) {
38
+ $secret_key = trim( $params['secret_key'] );
39
+ }
40
+
41
+ // Set type
42
  $type = null;
43
  if ( isset( $params['ai1wm_type'] ) ) {
44
  $type = trim( $params['ai1wm_type'] );
45
  }
46
 
47
+ // Set e-mail
48
  $email = null;
49
  if ( isset( $params['ai1wm_email'] ) ) {
50
  $email = trim( $params['ai1wm_email'] );
51
  }
52
 
53
+ // Set message
54
  $message = null;
55
  if ( isset( $params['ai1wm_message'] ) ) {
56
  $message = trim( $params['ai1wm_message'] );
57
  }
58
 
59
+ // Set terms
60
  $terms = false;
61
  if ( isset( $params['ai1wm_terms'] ) ) {
62
  $terms = (bool) $params['ai1wm_terms'];
63
  }
64
 
65
+ try {
66
+ // Ensure that unauthorized people cannot access feedback action
67
+ ai1wm_verify_secret_key( $secret_key );
68
+ } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
69
+ exit;
70
+ }
71
+
72
  $model = new Ai1wm_Feedback;
73
 
74
+ // Send feedback
75
+ $errors = $model->add( $type, $email, $message, $terms );
76
 
77
+ echo json_encode( array( 'errors' => $errors ) );
78
  exit;
79
  }
80
  }
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -52,14 +52,13 @@ class Ai1wm_Import_Controller {
52
  // Set secret key
53
  $secret_key = null;
54
  if ( isset( $params['secret_key'] ) ) {
55
- $secret_key = $params['secret_key'];
56
  }
57
 
58
  try {
59
  // Ensure that unauthorized people cannot access import action
60
  ai1wm_verify_secret_key( $secret_key );
61
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
62
- Ai1wm_Log::error( $e->getMessage() );
63
  exit;
64
  }
65
 
52
  // Set secret key
53
  $secret_key = null;
54
  if ( isset( $params['secret_key'] ) ) {
55
+ $secret_key = trim( $params['secret_key'] );
56
  }
57
 
58
  try {
59
  // Ensure that unauthorized people cannot access import action
60
  ai1wm_verify_secret_key( $secret_key );
61
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
 
62
  exit;
63
  }
64
 
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -384,11 +384,13 @@ class Ai1wm_Main_Controller {
384
  'ajax' => array(
385
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
386
  ),
 
387
  ) );
388
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_report', array(
389
  'ajax' => array(
390
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
391
  ),
 
392
  ) );
393
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_export', array(
394
  'ajax' => array(
@@ -445,11 +447,13 @@ class Ai1wm_Main_Controller {
445
  'ajax' => array(
446
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
447
  ),
 
448
  ) );
449
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', array(
450
  'ajax' => array(
451
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
452
  ),
 
453
  ) );
454
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_import', array(
455
  'ajax' => array(
@@ -515,16 +519,19 @@ class Ai1wm_Main_Controller {
515
  'ajax' => array(
516
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
517
  ),
 
518
  ) );
519
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_report', array(
520
  'ajax' => array(
521
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
522
  ),
 
523
  ) );
524
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_backups', array(
525
  'ajax' => array(
526
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_backups' ) ),
527
  ),
 
528
  ) );
529
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_import', array(
530
  'ajax' => array(
@@ -619,24 +626,23 @@ class Ai1wm_Main_Controller {
619
  add_action( 'wp_ajax_nopriv_ai1wm_import', 'Ai1wm_Import_Controller::import' );
620
  add_action( 'wp_ajax_nopriv_ai1wm_status', 'Ai1wm_Status_Controller::status' );
621
  add_action( 'wp_ajax_nopriv_ai1wm_resolve', 'Ai1wm_Resolve_Controller::resolve' );
 
 
 
622
 
623
  // Private actions
624
  add_action( 'wp_ajax_ai1wm_export', 'Ai1wm_Export_Controller::export' );
625
  add_action( 'wp_ajax_ai1wm_import', 'Ai1wm_Import_Controller::import' );
626
  add_action( 'wp_ajax_ai1wm_status', 'Ai1wm_Status_Controller::status' );
627
  add_action( 'wp_ajax_ai1wm_resolve', 'Ai1wm_Resolve_Controller::resolve' );
 
 
 
628
 
629
  // Update
630
  if ( current_user_can( 'update_plugins' ) ) {
631
  add_action( 'wp_ajax_ai1wm_updater', 'Ai1wm_Updater_Controller::updater' );
632
  }
633
-
634
- // Delete backup, send feedback and report problem
635
- if ( current_user_can( 'export' ) || current_user_can( 'import' ) ) {
636
- add_action( 'wp_ajax_ai1wm_backups', 'Ai1wm_Backups_Controller::delete' );
637
- add_action( 'wp_ajax_ai1wm_feedback', 'Ai1wm_Feedback_Controller::feedback' );
638
- add_action( 'wp_ajax_ai1wm_report', 'Ai1wm_Report_Controller::report' );
639
- }
640
  }
641
 
642
  /**
384
  'ajax' => array(
385
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
386
  ),
387
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
388
  ) );
389
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_report', array(
390
  'ajax' => array(
391
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
392
  ),
393
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
394
  ) );
395
  wp_localize_script( 'ai1wm-js-export', 'ai1wm_export', array(
396
  'ajax' => array(
447
  'ajax' => array(
448
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
449
  ),
450
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
451
  ) );
452
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', array(
453
  'ajax' => array(
454
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
455
  ),
456
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
457
  ) );
458
  wp_localize_script( 'ai1wm-js-import', 'ai1wm_import', array(
459
  'ajax' => array(
519
  'ajax' => array(
520
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_feedback' ) ),
521
  ),
522
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
523
  ) );
524
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_report', array(
525
  'ajax' => array(
526
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_report' ) ),
527
  ),
528
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
529
  ) );
530
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_backups', array(
531
  'ajax' => array(
532
  'url' => wp_make_link_relative( admin_url( 'admin-ajax.php?action=ai1wm_backups' ) ),
533
  ),
534
+ 'secret_key' => get_option( AI1WM_SECRET_KEY ),
535
  ) );
536
  wp_localize_script( 'ai1wm-js-backups', 'ai1wm_import', array(
537
  'ajax' => array(
626
  add_action( 'wp_ajax_nopriv_ai1wm_import', 'Ai1wm_Import_Controller::import' );
627
  add_action( 'wp_ajax_nopriv_ai1wm_status', 'Ai1wm_Status_Controller::status' );
628
  add_action( 'wp_ajax_nopriv_ai1wm_resolve', 'Ai1wm_Resolve_Controller::resolve' );
629
+ add_action( 'wp_ajax_nopriv_ai1wm_backups', 'Ai1wm_Backups_Controller::delete' );
630
+ add_action( 'wp_ajax_nopriv_ai1wm_feedback', 'Ai1wm_Feedback_Controller::feedback' );
631
+ add_action( 'wp_ajax_nopriv_ai1wm_report', 'Ai1wm_Report_Controller::report' );
632
 
633
  // Private actions
634
  add_action( 'wp_ajax_ai1wm_export', 'Ai1wm_Export_Controller::export' );
635
  add_action( 'wp_ajax_ai1wm_import', 'Ai1wm_Import_Controller::import' );
636
  add_action( 'wp_ajax_ai1wm_status', 'Ai1wm_Status_Controller::status' );
637
  add_action( 'wp_ajax_ai1wm_resolve', 'Ai1wm_Resolve_Controller::resolve' );
638
+ add_action( 'wp_ajax_ai1wm_backups', 'Ai1wm_Backups_Controller::delete' );
639
+ add_action( 'wp_ajax_ai1wm_feedback', 'Ai1wm_Feedback_Controller::feedback' );
640
+ add_action( 'wp_ajax_ai1wm_report', 'Ai1wm_Report_Controller::report' );
641
 
642
  // Update
643
  if ( current_user_can( 'update_plugins' ) ) {
644
  add_action( 'wp_ajax_ai1wm_updater', 'Ai1wm_Updater_Controller::updater' );
645
  }
 
 
 
 
 
 
 
646
  }
647
 
648
  /**
lib/controller/class-ai1wm-report-controller.php CHANGED
@@ -32,30 +32,43 @@ class Ai1wm_Report_Controller {
32
  $params = stripslashes_deep( $_POST );
33
  }
34
 
35
- // Set E-mail
 
 
 
 
 
 
36
  $email = null;
37
  if ( isset( $params['ai1wm_email'] ) ) {
38
  $email = trim( $params['ai1wm_email'] );
39
  }
40
 
41
- // Set Message
42
  $message = null;
43
  if ( isset( $params['ai1wm_message'] ) ) {
44
  $message = trim( $params['ai1wm_message'] );
45
  }
46
 
47
- // Set Terms
48
  $terms = false;
49
  if ( isset( $params['ai1wm_terms'] ) ) {
50
  $terms = (bool) $params['ai1wm_terms'];
51
  }
52
 
 
 
 
 
 
 
 
53
  $model = new Ai1wm_Report;
54
 
55
- // Send Report
56
- $response = $model->add( $email, $message, $terms );
57
 
58
- echo json_encode( $response );
59
  exit;
60
  }
61
  }
32
  $params = stripslashes_deep( $_POST );
33
  }
34
 
35
+ // Set secret key
36
+ $secret_key = null;
37
+ if ( isset( $params['secret_key'] ) ) {
38
+ $secret_key = trim( $params['secret_key'] );
39
+ }
40
+
41
+ // Set e-mail
42
  $email = null;
43
  if ( isset( $params['ai1wm_email'] ) ) {
44
  $email = trim( $params['ai1wm_email'] );
45
  }
46
 
47
+ // Set message
48
  $message = null;
49
  if ( isset( $params['ai1wm_message'] ) ) {
50
  $message = trim( $params['ai1wm_message'] );
51
  }
52
 
53
+ // Set terms
54
  $terms = false;
55
  if ( isset( $params['ai1wm_terms'] ) ) {
56
  $terms = (bool) $params['ai1wm_terms'];
57
  }
58
 
59
+ try {
60
+ // Ensure that unauthorized people cannot access report action
61
+ ai1wm_verify_secret_key( $secret_key );
62
+ } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
63
+ exit;
64
+ }
65
+
66
  $model = new Ai1wm_Report;
67
 
68
+ // Send report
69
+ $errors = $model->add( $email, $message, $terms );
70
 
71
+ echo json_encode( array( 'errors' => $errors ) );
72
  exit;
73
  }
74
  }
lib/controller/class-ai1wm-resolve-controller.php CHANGED
@@ -35,14 +35,13 @@ class Ai1wm_Resolve_Controller {
35
  // Set secret key
36
  $secret_key = null;
37
  if ( isset( $params['secret_key'] ) ) {
38
- $secret_key = $params['secret_key'];
39
  }
40
 
41
  try {
42
  // Ensure that unauthorized people cannot access resolve action
43
  ai1wm_verify_secret_key( $secret_key );
44
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
45
- Ai1wm_Log::error( $e->getMessage() );
46
  exit;
47
  }
48
 
35
  // Set secret key
36
  $secret_key = null;
37
  if ( isset( $params['secret_key'] ) ) {
38
+ $secret_key = trim( $params['secret_key'] );
39
  }
40
 
41
  try {
42
  // Ensure that unauthorized people cannot access resolve action
43
  ai1wm_verify_secret_key( $secret_key );
44
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
 
45
  exit;
46
  }
47
 
lib/controller/class-ai1wm-status-controller.php CHANGED
@@ -35,14 +35,13 @@ class Ai1wm_Status_Controller {
35
  // Set secret key
36
  $secret_key = null;
37
  if ( isset( $params['secret_key'] ) ) {
38
- $secret_key = $params['secret_key'];
39
  }
40
 
41
  try {
42
  // Ensure that unauthorized people cannot access status action
43
  ai1wm_verify_secret_key( $secret_key );
44
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
45
- Ai1wm_Log::error( $e->getMessage() );
46
  exit;
47
  }
48
 
35
  // Set secret key
36
  $secret_key = null;
37
  if ( isset( $params['secret_key'] ) ) {
38
+ $secret_key = trim( $params['secret_key'] );
39
  }
40
 
41
  try {
42
  // Ensure that unauthorized people cannot access status action
43
  ai1wm_verify_secret_key( $secret_key );
44
  } catch ( Ai1wm_Not_Valid_Secret_Key_Exception $e ) {
 
45
  exit;
46
  }
47
 
lib/model/class-ai1wm-backups.php CHANGED
@@ -68,18 +68,9 @@ class Ai1wm_Backups {
68
  * @return boolean
69
  */
70
  public function delete_file( $file ) {
71
- if ( empty( $file ) ) {
72
- throw new Ai1wm_Backups_Exception( __( 'File name is not specified.', AI1WM_PLUGIN_NAME ) );
73
- } else if ( ! unlink( AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $file ) ) {
74
- throw new Ai1wm_Backups_Exception(
75
- sprintf(
76
- __( 'Unable to delete <strong>"%s"</strong> file.', AI1WM_PLUGIN_NAME ),
77
- AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $file
78
- )
79
- );
80
  }
81
-
82
- return true;
83
  }
84
 
85
  /**
68
  * @return boolean
69
  */
70
  public function delete_file( $file ) {
71
+ if ( ( $basename = basename( $file ) ) ) {
72
+ return @unlink( AI1WM_BACKUPS_PATH . DIRECTORY_SEPARATOR . $basename );
 
 
 
 
 
 
 
73
  }
 
 
74
  }
75
 
76
  /**
lib/model/class-ai1wm-extensions.php CHANGED
@@ -76,7 +76,7 @@ class Ai1wm_Extensions {
76
  'about' => AI1WMME_PLUGIN_ABOUT,
77
  'basename' => AI1WMME_PLUGIN_BASENAME,
78
  'version' => AI1WMME_VERSION,
79
- 'requires' => '3.30',
80
  'short' => AI1WMME_PLUGIN_SHORT,
81
  );
82
  }
76
  'about' => AI1WMME_PLUGIN_ABOUT,
77
  'basename' => AI1WMME_PLUGIN_BASENAME,
78
  'version' => AI1WMME_VERSION,
79
+ 'requires' => '3.33',
80
  'short' => AI1WMME_PLUGIN_SHORT,
81
  );
82
  }
lib/model/class-ai1wm-feedback.php CHANGED
@@ -28,10 +28,10 @@ class Ai1wm_Feedback {
28
  /**
29
  * Submit customer feedback to ServMask.com
30
  *
31
- * @param string $type Feedback Type
32
- * @param string $email User E-mail
33
- * @param string $message User Message
34
- * @param integer $terms User Accept Terms
35
  *
36
  * @return array
37
  */
@@ -64,6 +64,6 @@ class Ai1wm_Feedback {
64
  }
65
  }
66
 
67
- return array( 'errors' => $errors );
68
  }
69
  }
28
  /**
29
  * Submit customer feedback to ServMask.com
30
  *
31
+ * @param string $type Feedback type
32
+ * @param string $email User e-mail
33
+ * @param string $message User message
34
+ * @param integer $terms User accept terms
35
  *
36
  * @return array
37
  */
64
  }
65
  }
66
 
67
+ return $errors;
68
  }
69
  }
lib/model/class-ai1wm-report.php CHANGED
@@ -28,9 +28,9 @@ class Ai1wm_Report {
28
  /**
29
  * Submit customer report to ServMask.com
30
  *
31
- * @param string $email User E-mail
32
- * @param string $message User Message
33
- * @param integer $terms User Accept Terms
34
  *
35
  * @return array
36
  */
@@ -60,6 +60,6 @@ class Ai1wm_Report {
60
  }
61
  }
62
 
63
- return array( 'errors' => $errors );
64
  }
65
  }
28
  /**
29
  * Submit customer report to ServMask.com
30
  *
31
+ * @param string $email User e-mail
32
+ * @param string $message User message
33
+ * @param integer $terms User accept terms
34
  *
35
  * @return array
36
  */
60
  }
61
  }
62
 
63
+ return $errors;
64
  }
65
  }
lib/model/export/class-ai1wm-export-content.php CHANGED
@@ -27,25 +27,18 @@ class Ai1wm_Export_Content {
27
 
28
  public static function execute( $params ) {
29
 
30
- // Set current filesize
31
- if ( isset( $params['current_filesize'] ) ) {
32
- $current_filesize = (int) $params['current_filesize'];
33
  } else {
34
- $current_filesize = 0;
35
  }
36
 
37
- // Set content offset
38
- if ( isset( $params['content_offset'] ) ) {
39
- $content_offset = (int) $params['content_offset'];
40
  } else {
41
- $content_offset = 0;
42
- }
43
-
44
- // Set filemap offset
45
- if ( isset( $params['filemap_offset'] ) ) {
46
- $filemap_offset = (int) $params['filemap_offset'];
47
- } else {
48
- $filemap_offset = 0;
49
  }
50
 
51
  // Get total files count
@@ -62,20 +55,21 @@ class Ai1wm_Export_Content {
62
  $total_files_size = 1;
63
  }
64
 
65
- // Get processed files
66
- if ( isset( $params['processed'] ) ) {
67
- $processed = (int) $params['processed'];
68
  } else {
69
- $processed = 0;
70
  }
71
 
72
  // What percent of files have we processed?
73
- $progress = (int) ( ( $processed / $total_files_size ) * 100 );
74
 
75
  // Set progress
76
- if ( empty( $content_offset ) ) {
77
- Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
78
- }
 
79
 
80
  // Start time
81
  $start = microtime( true );
@@ -84,56 +78,35 @@ class Ai1wm_Export_Content {
84
  $filemap = ai1wm_open( ai1wm_filemap_path( $params ), 'r' );
85
 
86
  // Set filemap pointer at the current index
87
- if ( fseek( $filemap, $filemap_offset ) !== -1 ) {
88
 
89
  // Get archive
90
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
91
 
 
92
  while ( $path = trim( fgets( $filemap ) ) ) {
93
- try {
94
-
95
- // Add file to archive
96
- if ( ( $current_offset = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path, $current_filesize, $content_offset, 10 ) ) ) {
97
-
98
- // What percent of files have we processed?
99
- if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
100
- $progress = (int) ( ( $processed / $total_files_size ) * 100 );
101
- }
102
-
103
- // Set progress
104
- Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
105
 
106
- // Set current filesize
107
- $current_filesize = $archive->get_current_filesize();
 
108
 
109
- // Set content offset
110
- $content_offset = $current_offset;
111
-
112
- break;
113
- }
114
-
115
- // Increment processed files
116
- if ( empty( $content_offset ) ) {
117
- $processed += $archive->get_current_filesize();
118
- }
119
 
120
- // Set current filesize
121
- $current_filesize = 0;
122
 
123
- // Set content offset
124
- $content_offset = 0;
125
 
126
- // Set filemap offset
127
- $filemap_offset = ftell( $filemap );
128
-
129
- } catch ( Ai1wm_Quota_Exceeded_Exception $e ) {
130
- throw new Exception( 'Out of disk space.' );
131
- } catch ( Exception $e ) {
132
- // Skip bad file permissions
133
- }
134
 
135
  // More than 10 seconds have passed, break and do another request
136
  if ( ( microtime( true ) - $start ) > 10 ) {
 
137
  break;
138
  }
139
  }
@@ -145,37 +118,31 @@ class Ai1wm_Export_Content {
145
  // End of the filemap?
146
  if ( feof( $filemap ) ) {
147
 
148
- // Unset current filesize
149
- unset( $params['current_filesize'] );
150
-
151
- // Unset content offset
152
- unset( $params['content_offset'] );
153
 
154
- // Unset filemap offset
155
- unset( $params['filemap_offset'] );
156
 
157
- // Unset processed files
158
- unset( $params['processed'] );
159
 
160
  // Unset completed flag
161
  unset( $params['completed'] );
162
 
163
  } else {
164
 
165
- // Set current filesize
166
- $params['current_filesize'] = $current_filesize;
167
-
168
- // Set content offset
169
- $params['content_offset'] = $content_offset;
170
 
171
- // Set filemap offset
172
- $params['filemap_offset'] = $filemap_offset;
173
 
174
- // Set processed files
175
- $params['processed'] = $processed;
176
 
177
  // Set completed flag
178
- $params['completed'] = false;
179
  }
180
 
181
  // Close the filemap file
27
 
28
  public static function execute( $params ) {
29
 
30
+ // Set file bytes offset
31
+ if ( isset( $params['file_bytes_offset'] ) ) {
32
+ $file_bytes_offset = (int) $params['file_bytes_offset'];
33
  } else {
34
+ $file_bytes_offset = 0;
35
  }
36
 
37
+ // Set filemap bytes offset
38
+ if ( isset( $params['filemap_bytes_offset'] ) ) {
39
+ $filemap_bytes_offset = (int) $params['filemap_bytes_offset'];
40
  } else {
41
+ $filemap_bytes_offset = 0;
 
 
 
 
 
 
 
42
  }
43
 
44
  // Get total files count
55
  $total_files_size = 1;
56
  }
57
 
58
+ // Get processed files size
59
+ if ( isset( $params['processed_files_size'] ) ) {
60
+ $processed_files_size = (int) $params['processed_files_size'];
61
  } else {
62
+ $processed_files_size = 0;
63
  }
64
 
65
  // What percent of files have we processed?
66
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
67
 
68
  // Set progress
69
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
70
+
71
+ // Flag to hold if file data has been processed
72
+ $completed = true;
73
 
74
  // Start time
75
  $start = microtime( true );
78
  $filemap = ai1wm_open( ai1wm_filemap_path( $params ), 'r' );
79
 
80
  // Set filemap pointer at the current index
81
+ if ( fseek( $filemap, $filemap_bytes_offset ) !== -1 ) {
82
 
83
  // Get archive
84
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
85
 
86
+ // Loop over files
87
  while ( $path = trim( fgets( $filemap ) ) ) {
88
+ $file_bytes_written = 0;
 
 
 
 
 
 
 
 
 
 
 
89
 
90
+ // Add file to archive
91
+ if ( ( $completed = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path, $file_bytes_written, $file_bytes_offset, 10 ) ) ) {
92
+ $file_bytes_offset = 0;
93
 
94
+ // Set filemap bytes offset
95
+ $filemap_bytes_offset = ftell( $filemap );
96
+ }
 
 
 
 
 
 
 
97
 
98
+ // Increment processed files size
99
+ $processed_files_size += $file_bytes_written;
100
 
101
+ // What percent of files have we processed?
102
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
103
 
104
+ // Set progress
105
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
 
 
 
 
 
 
106
 
107
  // More than 10 seconds have passed, break and do another request
108
  if ( ( microtime( true ) - $start ) > 10 ) {
109
+ $completed = false;
110
  break;
111
  }
112
  }
118
  // End of the filemap?
119
  if ( feof( $filemap ) ) {
120
 
121
+ // Unset file bytes offset
122
+ unset( $params['file_bytes_offset'] );
 
 
 
123
 
124
+ // Unset filemap bytes offset
125
+ unset( $params['filemap_bytes_offset'] );
126
 
127
+ // Unset processed files size
128
+ unset( $params['processed_files_size'] );
129
 
130
  // Unset completed flag
131
  unset( $params['completed'] );
132
 
133
  } else {
134
 
135
+ // Set file bytes offset
136
+ $params['file_bytes_offset'] = $file_bytes_offset;
 
 
 
137
 
138
+ // Set filemap bytes offset
139
+ $params['filemap_bytes_offset'] = $filemap_bytes_offset;
140
 
141
+ // Set processed files size
142
+ $params['processed_files_size'] = $processed_files_size;
143
 
144
  // Set completed flag
145
+ $params['completed'] = $completed;
146
  }
147
 
148
  // Close the filemap file
lib/model/export/class-ai1wm-export-download.php CHANGED
@@ -39,10 +39,19 @@ class Ai1wm_Export_Download {
39
  // Rename archive file
40
  if ( rename( ai1wm_archive_path( $params ), ai1wm_download_path( $params ) ) ) {
41
 
 
 
 
 
 
 
 
 
 
42
  // Set archive details
43
  $link = ai1wm_backups_url( $params );
44
  $size = ai1wm_download_size( $params );
45
- $name = ai1wm_site_name();
46
 
47
  // Set progress
48
  Ai1wm_Status::download(
39
  // Rename archive file
40
  if ( rename( ai1wm_archive_path( $params ), ai1wm_download_path( $params ) ) ) {
41
 
42
+ $blog_id = null;
43
+
44
+ // Get subsite Blog ID
45
+ if ( isset( $params['options']['sites'] ) && ( $sites = $params['options']['sites'] ) ) {
46
+ if ( count( $sites ) === 1 ) {
47
+ $blog_id = array_shift( $sites );
48
+ }
49
+ }
50
+
51
  // Set archive details
52
  $link = ai1wm_backups_url( $params );
53
  $size = ai1wm_download_size( $params );
54
+ $name = ai1wm_site_name( $blog_id );
55
 
56
  // Set progress
57
  Ai1wm_Status::download(
lib/model/export/class-ai1wm-export-init.php CHANGED
@@ -27,9 +27,18 @@ class Ai1wm_Export_Init {
27
 
28
  public static function execute( $params ) {
29
 
 
 
 
 
 
 
 
 
 
30
  // Set archive
31
  if ( empty( $params['archive'] ) ) {
32
- $params['archive'] = ai1wm_archive_file();
33
  }
34
 
35
  // Set storage
27
 
28
  public static function execute( $params ) {
29
 
30
+ $blog_id = null;
31
+
32
+ // Get subsite Blog ID
33
+ if ( isset( $params['options']['sites'] ) && ( $sites = $params['options']['sites'] ) ) {
34
+ if ( count( $sites ) === 1 ) {
35
+ $blog_id = array_shift( $sites );
36
+ }
37
+ }
38
+
39
  // Set archive
40
  if ( empty( $params['archive'] ) ) {
41
+ $params['archive'] = ai1wm_archive_file( $blog_id );
42
  }
43
 
44
  // Set storage
lib/model/import/class-ai1wm-import-content.php CHANGED
@@ -37,18 +37,18 @@ class Ai1wm_Import_Content {
37
  // Close handle
38
  ai1wm_close( $handle );
39
 
40
- // Set content offset
41
- if ( isset( $params['content_offset'] ) ) {
42
- $content_offset = (int) $params['content_offset'];
43
  } else {
44
- $content_offset = 0;
45
  }
46
 
47
- // Set archive offset
48
- if ( isset( $params['archive_offset'] ) ) {
49
- $archive_offset = (int) $params['archive_offset'];
50
  } else {
51
- $archive_offset = 0;
52
  }
53
 
54
  // Get total files count
@@ -65,20 +65,21 @@ class Ai1wm_Import_Content {
65
  $total_files_size = 1;
66
  }
67
 
68
- // Get processed files
69
- if ( isset( $params['processed'] ) ) {
70
- $processed = (int) $params['processed'];
71
  } else {
72
- $processed = 0;
73
  }
74
 
75
  // What percent of files have we processed?
76
- $progress = (int) ( ( $processed / $total_files_size ) * 100 );
77
 
78
  // Set progress
79
- if ( empty( $content_offset ) ) {
80
- Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
81
- }
 
82
 
83
  // Start time
84
  $start = microtime( true );
@@ -87,7 +88,7 @@ class Ai1wm_Import_Content {
87
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
88
 
89
  // Set the file pointer to the one that we have saved
90
- $archive->set_file_pointer( null, $archive_offset );
91
 
92
  $old_paths = array();
93
  $new_paths = array();
@@ -139,58 +140,39 @@ class Ai1wm_Import_Content {
139
  }
140
 
141
  while ( $archive->has_not_reached_eof() ) {
142
- try {
143
-
144
- // Exclude WordPress files
145
- $exclude_files = array_keys( _get_dropins() );
146
-
147
- // Exclude plugin files
148
- $exclude_files = array_merge( $exclude_files, array(
149
- AI1WM_PACKAGE_NAME,
150
- AI1WM_MULTISITE_NAME,
151
- AI1WM_DATABASE_NAME,
152
- AI1WM_MUPLUGINS_NAME,
153
- ) );
154
-
155
- // Extract a file from archive to WP_CONTENT_DIR
156
- if ( ( $current_offset = $archive->extract_one_file_to( WP_CONTENT_DIR, $exclude_files, $old_paths, $new_paths, $content_offset, 10 ) ) ) {
157
-
158
- // What percent of files have we processed?
159
- if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
160
- $progress = (int) ( ( $processed / $total_files_size ) * 100 );
161
- }
162
-
163
- // Set progress
164
- Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
165
-
166
- // Set content offset
167
- $content_offset = $current_offset;
168
-
169
- // Set archive offset
170
- $archive_offset = $archive->get_file_pointer();
171
-
172
- break;
173
- }
174
 
175
- // Increment processed files
176
- if ( empty( $content_offset ) ) {
177
- $processed += $archive->get_current_filesize();
178
- }
179
 
180
- // Set content offset
181
- $content_offset = 0;
182
 
183
- // Set archive offset
184
- $archive_offset = $archive->get_file_pointer();
185
 
186
- } catch ( Ai1wm_Quota_Exceeded_Exception $e ) {
187
- throw new Exception( 'Out of disk space.' );
188
- } catch ( Exception $e ) {
189
- // Skip bad file permissions
190
- }
191
 
192
  // More than 10 seconds have passed, break and do another request
193
  if ( ( microtime( true ) - $start ) > 10 ) {
 
194
  break;
195
  }
196
  }
@@ -198,31 +180,31 @@ class Ai1wm_Import_Content {
198
  // End of the archive?
199
  if ( $archive->has_reached_eof() ) {
200
 
201
- // Unset content offset
202
- unset( $params['content_offset'] );
203
 
204
- // Unset archive offset
205
- unset( $params['archive_offset'] );
206
 
207
- // Unset processed files
208
- unset( $params['processed'] );
209
 
210
  // Unset completed flag
211
  unset( $params['completed'] );
212
 
213
  } else {
214
 
215
- // Set content offset
216
- $params['content_offset'] = $content_offset;
217
 
218
- // Set archive offset
219
- $params['archive_offset'] = $archive_offset;
220
 
221
- // Set processed files
222
- $params['processed'] = $processed;
223
 
224
  // Set completed flag
225
- $params['completed'] = false;
226
  }
227
 
228
  // Close the archive file
37
  // Close handle
38
  ai1wm_close( $handle );
39
 
40
+ // Set file bytes offset
41
+ if ( isset( $params['file_bytes_offset'] ) ) {
42
+ $file_bytes_offset = (int) $params['file_bytes_offset'];
43
  } else {
44
+ $file_bytes_offset = 0;
45
  }
46
 
47
+ // Set archive bytes offset
48
+ if ( isset( $params['archive_bytes_offset'] ) ) {
49
+ $archive_bytes_offset = (int) $params['archive_bytes_offset'];
50
  } else {
51
+ $archive_bytes_offset = 0;
52
  }
53
 
54
  // Get total files count
65
  $total_files_size = 1;
66
  }
67
 
68
+ // Get processed files size
69
+ if ( isset( $params['processed_files_size'] ) ) {
70
+ $processed_files_size = (int) $params['processed_files_size'];
71
  } else {
72
+ $processed_files_size = 0;
73
  }
74
 
75
  // What percent of files have we processed?
76
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
77
 
78
  // Set progress
79
+ Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
80
+
81
+ // Flag to hold if file data has been processed
82
+ $completed = true;
83
 
84
  // Start time
85
  $start = microtime( true );
88
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
89
 
90
  // Set the file pointer to the one that we have saved
91
+ $archive->set_file_pointer( $archive_bytes_offset );
92
 
93
  $old_paths = array();
94
  $new_paths = array();
140
  }
141
 
142
  while ( $archive->has_not_reached_eof() ) {
143
+ $file_bytes_written = 0;
144
+
145
+ // Exclude WordPress files
146
+ $exclude_files = array_keys( _get_dropins() );
147
+
148
+ // Exclude plugin files
149
+ $exclude_files = array_merge( $exclude_files, array(
150
+ AI1WM_PACKAGE_NAME,
151
+ AI1WM_MULTISITE_NAME,
152
+ AI1WM_DATABASE_NAME,
153
+ AI1WM_MUPLUGINS_NAME,
154
+ ) );
155
+
156
+ // Extract a file from archive to WP_CONTENT_DIR
157
+ if ( ( $completed = $archive->extract_one_file_to( WP_CONTENT_DIR, $exclude_files, $old_paths, $new_paths, $file_bytes_written, $file_bytes_offset, 10 ) ) ) {
158
+ $file_bytes_offset = 0;
159
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
 
161
+ // Set archive bytes offset
162
+ $archive_bytes_offset = $archive->get_file_pointer();
 
 
163
 
164
+ // Increment processed files size
165
+ $processed_files_size += $file_bytes_written;
166
 
167
+ // What percent of files have we processed?
168
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
169
 
170
+ // Set progress
171
+ Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
 
 
 
172
 
173
  // More than 10 seconds have passed, break and do another request
174
  if ( ( microtime( true ) - $start ) > 10 ) {
175
+ $completed = false;
176
  break;
177
  }
178
  }
180
  // End of the archive?
181
  if ( $archive->has_reached_eof() ) {
182
 
183
+ // Unset file bytes offset
184
+ unset( $params['file_bytes_offset'] );
185
 
186
+ // Unset archive bytes offset
187
+ unset( $params['archive_bytes_offset'] );
188
 
189
+ // Unset processed files size
190
+ unset( $params['processed_files_size'] );
191
 
192
  // Unset completed flag
193
  unset( $params['completed'] );
194
 
195
  } else {
196
 
197
+ // Set file bytes offset
198
+ $params['file_bytes_offset'] = $file_bytes_offset;
199
 
200
+ // Set archive bytes offset
201
+ $params['archive_bytes_offset'] = $archive_bytes_offset;
202
 
203
+ // Set processed files size
204
+ $params['processed_files_size'] = $processed_files_size;
205
 
206
  // Set completed flag
207
+ $params['completed'] = $completed;
208
  }
209
 
210
  // Close the archive file
lib/model/import/class-ai1wm-import-validate.php CHANGED
@@ -27,18 +27,18 @@ class Ai1wm_Import_Validate {
27
 
28
  public static function execute( $params ) {
29
 
30
- // Set content offset
31
- if ( isset( $params['content_offset'] ) ) {
32
- $content_offset = (int) $params['content_offset'];
33
  } else {
34
- $content_offset = 0;
35
  }
36
 
37
- // Set archive offset
38
- if ( isset( $params['archive_offset'] ) ) {
39
- $archive_offset = (int) $params['archive_offset'];
40
  } else {
41
- $archive_offset = 0;
42
  }
43
 
44
  // Set progress
@@ -48,7 +48,7 @@ class Ai1wm_Import_Validate {
48
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
49
 
50
  // Set the file pointer to the one that we have saved
51
- $archive->set_file_pointer( null, $archive_offset );
52
 
53
  // Validate the archive file consistency
54
  if ( ! $archive->is_valid() ) {
@@ -69,7 +69,7 @@ class Ai1wm_Import_Validate {
69
 
70
  // Check file size of the archive
71
  if ( false === $size ) {
72
- throw new Ai1wm_Not_Accesible_Exception(
73
  sprintf( __( 'Unable to get the file size of <strong>%s</strong>', AI1WM_PLUGIN_NAME ), $name )
74
  );
75
  }
@@ -91,25 +91,19 @@ class Ai1wm_Import_Validate {
91
  );
92
  }
93
 
 
 
 
94
  if ( $archive->has_not_reached_eof() ) {
 
95
 
96
  // Unpack package.json, multisite.json and database.sql files
97
- if ( ( $current_offset = $archive->extract_by_files_array( ai1wm_storage_path( $params ), array( AI1WM_PACKAGE_NAME, AI1WM_MULTISITE_NAME, AI1WM_DATABASE_NAME ), $content_offset, 10 ) ) ) {
98
-
99
- // Set content offset
100
- $content_offset = $current_offset;
101
-
102
- // Set archive offset
103
- $archive_offset = $archive->get_file_pointer();
104
-
105
- } else {
106
-
107
- // Set content offset
108
- $content_offset = 0;
109
-
110
- // Set archive offset
111
- $archive_offset = $archive->get_file_pointer();
112
  }
 
 
 
113
  }
114
 
115
  // End of the archive?
@@ -122,25 +116,25 @@ class Ai1wm_Import_Validate {
122
  );
123
  }
124
 
125
- // Unset content offset
126
- unset( $params['content_offset'] );
127
 
128
- // Unset archive offset
129
- unset( $params['archive_offset'] );
130
 
131
  // Unset completed flag
132
  unset( $params['completed'] );
133
 
134
  } else {
135
 
136
- // Set content offset
137
- $params['content_offset'] = $content_offset;
138
 
139
- // Set archive offset
140
- $params['archive_offset'] = $archive_offset;
141
 
142
  // Set completed flag
143
- $params['completed'] = false;
144
  }
145
 
146
  // Close the archive file
27
 
28
  public static function execute( $params ) {
29
 
30
+ // Set file bytes offset
31
+ if ( isset( $params['file_bytes_offset'] ) ) {
32
+ $file_bytes_offset = (int) $params['file_bytes_offset'];
33
  } else {
34
+ $file_bytes_offset = 0;
35
  }
36
 
37
+ // Set archive bytes offset
38
+ if ( isset( $params['archive_bytes_offset'] ) ) {
39
+ $archive_bytes_offset = (int) $params['archive_bytes_offset'];
40
  } else {
41
+ $archive_bytes_offset = 0;
42
  }
43
 
44
  // Set progress
48
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
49
 
50
  // Set the file pointer to the one that we have saved
51
+ $archive->set_file_pointer( $archive_bytes_offset );
52
 
53
  // Validate the archive file consistency
54
  if ( ! $archive->is_valid() ) {
69
 
70
  // Check file size of the archive
71
  if ( false === $size ) {
72
+ throw new Ai1wm_Not_Accessible_Exception(
73
  sprintf( __( 'Unable to get the file size of <strong>%s</strong>', AI1WM_PLUGIN_NAME ), $name )
74
  );
75
  }
91
  );
92
  }
93
 
94
+ // Flag to hold if file data has been processed
95
+ $completed = true;
96
+
97
  if ( $archive->has_not_reached_eof() ) {
98
+ $file_bytes_written = 0;
99
 
100
  // Unpack package.json, multisite.json and database.sql files
101
+ if ( ( $completed = $archive->extract_by_files_array( ai1wm_storage_path( $params ), array( AI1WM_PACKAGE_NAME, AI1WM_MULTISITE_NAME, AI1WM_DATABASE_NAME ), $file_bytes_written, $file_bytes_offset, 10 ) ) ) {
102
+ $file_bytes_offset = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  }
104
+
105
+ // Set archive bytes offset
106
+ $archive_bytes_offset = $archive->get_file_pointer();
107
  }
108
 
109
  // End of the archive?
116
  );
117
  }
118
 
119
+ // Unset file bytes offset
120
+ unset( $params['file_bytes_offset'] );
121
 
122
+ // Unset archive bytes offset
123
+ unset( $params['archive_bytes_offset'] );
124
 
125
  // Unset completed flag
126
  unset( $params['completed'] );
127
 
128
  } else {
129
 
130
+ // Set file bytes offset
131
+ $params['file_bytes_offset'] = $file_bytes_offset;
132
 
133
+ // Set archive bytes offset
134
+ $params['archive_bytes_offset'] = $archive_bytes_offset;
135
 
136
  // Set completed flag
137
+ $params['completed'] = $completed;
138
  }
139
 
140
  // Close the archive file
lib/vendor/servmask/archiver/class-ai1wm-archiver.php CHANGED
@@ -25,46 +25,12 @@
25
 
26
  abstract class Ai1wm_Archiver {
27
 
28
- /**
29
- * Header block format of a file
30
- *
31
- * Field Name Offset Length Contents
32
- * name 0 255 filename (no path, no slash)
33
- * size 255 14 size of file contents
34
- * mtime 269 12 last modification time
35
- * prefix 281 4096 path name, no trailing slashes
36
- *
37
- * @type string
38
- */
39
- protected $block_format = array(
40
- 'a255', // filename
41
- 'a14', // size of file contents
42
- 'a12', // last time modified
43
- 'a4096', // path
44
- );
45
-
46
- public function get_block_format() {
47
- return $this->block_format;
48
- }
49
-
50
- public function set_block_format( $block_format ) {
51
- $this->block_format = $block_format;
52
- }
53
-
54
  /**
55
  * Filename including path to the file
56
  *
57
  * @type string
58
  */
59
- protected $filename = null;
60
-
61
- public function get_filename() {
62
- return $this->filename;
63
- }
64
-
65
- public function set_filename( $filename ) {
66
- $this->filename = $filename;
67
- }
68
 
69
  /**
70
  * Handle to the file
@@ -73,162 +39,132 @@ abstract class Ai1wm_Archiver {
73
  */
74
  protected $file_handle = null;
75
 
76
- public function get_file_handle() {
77
- return $this->file_handle;
78
- }
79
-
80
- public function set_file_handle( $file_handle ) {
81
- $this->file_handle = $file_handle;
82
- }
83
-
84
  /**
85
- * Current file size
 
 
 
 
 
 
86
  *
87
- * @type int
88
  */
89
- protected $current_filesize = null;
90
-
91
- public function get_current_filesize() {
92
- return $this->current_filesize;
93
- }
94
-
95
- public function set_current_filesize( $current_filesize ) {
96
- $this->current_filesize = $current_filesize;
97
- }
98
 
99
  /**
100
- * End Of File block string
101
  *
102
  * @type string
103
  */
104
  protected $eof = null;
105
 
106
- public function get_eof() {
107
- return $this->eof;
108
- }
109
-
110
- public function set_eof( $eof ) {
111
- $this->eof = $eof;
112
- }
113
-
114
  /**
115
  * Default constructor
116
  *
117
  * Initializes filename and end of file block
118
  *
119
- * @param string $filename Archive file
 
120
  */
121
- public function __construct( $filename, $write = false ) {
122
- // initialize file
123
- $this->filename = $filename;
124
 
125
- // initialize end of file
126
  $this->eof = pack( 'a4377', '' );
127
 
128
- // open file for writing or reading
129
  if ( $write ) {
130
- $this->file_handle = $this->open_file_for_writing( $filename );
 
 
 
 
 
 
 
 
131
  } else {
132
- $this->file_handle = $this->open_file_for_reading( $filename );
 
 
 
133
  }
134
  }
135
 
136
  /**
137
- * Open the archive for reading
138
- *
139
- * @param string $file File to open
140
  *
141
- * @return resource
142
- * @throws \Ai1wm_Not_Accesible_Exception
143
- */
144
- protected function open_file_for_reading( $file ) {
145
- return $this->open_file_in_mode( $file, 'rb' );
146
- }
147
-
148
- /**
149
- * Open the archive for writing/appending
150
  *
151
- * @param string $file File to open
152
  *
153
- * @return resource
154
- * @throws \Ai1wm_Not_Accesible_Exception
155
  */
156
- protected function open_file_for_writing( $file ) {
157
- return $this->open_file_in_mode( $file, 'ab' );
 
 
158
  }
159
 
160
  /**
161
- * Open the archive for writing and truncate the file if it exist
162
  *
163
- * @param string $file File to open
164
  *
165
- * @return resource
166
- * @throws \Ai1wm_Not_Accesible_Exception
167
  */
168
- protected function open_file_for_overwriting( $file ) {
169
- return $this->open_file_in_mode( $file, 'wb' );
170
- }
 
 
171
 
172
- /**
173
- * Opens file in the passed mode
174
- *
175
- * @param string $file File to be opened
176
- * @param string $mode Mode to openthe file in
177
- *
178
- * @return resource
179
- * @throws \Ai1wm_Not_Accesible_Exception
180
- */
181
- protected function open_file_in_mode( $file, $mode ) {
182
- return ai1wm_open( $file, $mode );
183
  }
184
 
185
  /**
186
- * Write data to a handle and check if the data has been written
187
- *
188
- * @param resource $handle File handle
189
- * @param string $data Data to be written - binary
190
  *
 
191
  * @throws \Ai1wm_Not_Writable_Exception
192
- */
193
- protected function write_to_handle( $handle, $data ) {
194
- return ai1wm_write( $handle, $data );
195
- }
196
-
197
- /**
198
- * Read data from a handle
199
- *
200
- * @param resource $handle File handle
201
- * @param int $size Size of data to be read in bytes
202
- *
203
- * @return string Content that was read
204
- * @throws \Ai1wm_Not_Readable_Exception
205
- */
206
- protected function read_from_handle( $handle, $size ) {
207
- return ai1wm_read( $handle, $size );
208
- }
209
-
210
- /**
211
- * Appends end of file block to the archive
212
  *
213
- * @throws \Ai1wm_Not_Writable_Exception
214
  */
215
  protected function append_eof() {
216
- return $this->write_to_handle( $this->file_handle, $this->eof );
 
 
 
 
 
 
 
 
 
 
 
 
217
  }
218
 
219
  /**
220
- * Validate file
221
  *
222
- * return bool
223
  */
224
  public function is_valid() {
225
- $offset = ftell( $this->file_handle );
226
-
227
- // set file offset
228
- if ( fseek( $this->file_handle, -4377, SEEK_END ) !== -1 ) {
229
- if ( ai1wm_read( $this->file_handle, 4377 ) === $this->eof ) {
230
- if ( fseek( $this->file_handle, $offset, SEEK_SET ) !== -1 ) {
231
- return true;
232
  }
233
  }
234
  }
@@ -242,16 +178,16 @@ abstract class Ai1wm_Archiver {
242
  * We either close the file or append the end of file block if complete argument is set to tru
243
  *
244
  * @param bool $complete Flag to append end of file block
245
- * @return void
246
  *
 
247
  */
248
  public function close( $complete = false ) {
249
- // are we done appending to the file?
250
  if ( true === $complete ) {
251
  $this->append_eof();
252
  }
253
 
254
- // close the file
255
- ai1wm_close( $this->file_handle );
256
  }
257
  }
25
 
26
  abstract class Ai1wm_Archiver {
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  /**
29
  * Filename including path to the file
30
  *
31
  * @type string
32
  */
33
+ protected $file_name = null;
 
 
 
 
 
 
 
 
34
 
35
  /**
36
  * Handle to the file
39
  */
40
  protected $file_handle = null;
41
 
 
 
 
 
 
 
 
 
42
  /**
43
+ * Header block format of a file
44
+ *
45
+ * Field Name Offset Length Contents
46
+ * name 0 255 filename (no path, no slash)
47
+ * size 255 14 size of file contents
48
+ * mtime 269 12 last modification time
49
+ * prefix 281 4096 path name, no trailing slashes
50
  *
51
+ * @type array
52
  */
53
+ protected $block_format = array(
54
+ 'a255', // filename
55
+ 'a14', // size of file contents
56
+ 'a12', // last time modified
57
+ 'a4096', // path
58
+ );
 
 
 
59
 
60
  /**
61
+ * End of file block string
62
  *
63
  * @type string
64
  */
65
  protected $eof = null;
66
 
 
 
 
 
 
 
 
 
67
  /**
68
  * Default constructor
69
  *
70
  * Initializes filename and end of file block
71
  *
72
+ * @param string $file_name Archive file
73
+ * @param bool $write Read/write mode
74
  */
75
+ public function __construct( $file_name, $write = false ) {
76
+ $this->file_name = $file_name;
 
77
 
78
+ // Initialize end of file block
79
  $this->eof = pack( 'a4377', '' );
80
 
81
+ // Open archive file
82
  if ( $write ) {
83
+ // Open archive file for writing
84
+ if ( ( $this->file_handle = @fopen( $file_name, 'cb' ) ) === false ) {
85
+ throw new Ai1wm_Not_Accessible_Exception( sprintf( 'Unable to open file for writing. File: %s', $this->file_name ) );
86
+ }
87
+
88
+ // Seek to end of archive file
89
+ if ( @fseek( $this->file_handle, 0, SEEK_END ) === -1 ) {
90
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to end of file. File: %s', $this->file_name ) );
91
+ }
92
  } else {
93
+ // Open archive file for reading
94
+ if ( ( $this->file_handle = @fopen( $file_name, 'rb' ) ) === false ) {
95
+ throw new Ai1wm_Not_Accessible_Exception( sprintf( 'Unable to open file for reading. File: %s', $this->file_name ) );
96
+ }
97
  }
98
  }
99
 
100
  /**
101
+ * Set current file pointer
 
 
102
  *
103
+ * @param int $offset Archive offset
 
 
 
 
 
 
 
 
104
  *
105
+ * @throws \Ai1wm_Not_Seekable_Exception
106
  *
107
+ * @return void
 
108
  */
109
+ public function set_file_pointer( $offset ) {
110
+ if ( @fseek( $this->file_handle, $offset, SEEK_CUR ) === -1 ) {
111
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $offset ) );
112
+ }
113
  }
114
 
115
  /**
116
+ * Get current file pointer
117
  *
118
+ * @throws \Ai1wm_Not_Tellable_Exception
119
  *
120
+ * @return int
 
121
  */
122
+ public function get_file_pointer() {
123
+ $offset = 0;
124
+ if ( ( $offset = @ftell( $this->file_handle ) ) === false ) {
125
+ throw new Ai1wm_Not_Tellable_Exception( sprintf( 'Unable to tell offset on file. File: %s', $this->file_name ) );
126
+ }
127
 
128
+ return $offset;
 
 
 
 
 
 
 
 
 
 
129
  }
130
 
131
  /**
132
+ * Appends end of file block to the archive file
 
 
 
133
  *
134
+ * @throws \Ai1wm_Not_Seekable_Exception
135
  * @throws \Ai1wm_Not_Writable_Exception
136
+ * @throws \Ai1wm_Quota_Exceeded_Exception
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  *
138
+ * @return void
139
  */
140
  protected function append_eof() {
141
+ // Seek to end of archive file
142
+ if ( @fseek( $this->file_handle, 0, SEEK_END ) === -1 ) {
143
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to end of file. File: %s', $this->file_name ) );
144
+ }
145
+
146
+ // Write end of file block
147
+ if ( ( $file_bytes = @fwrite( $this->file_handle, $this->eof ) ) !== false ) {
148
+ if ( strlen( $this->eof ) !== $file_bytes ) {
149
+ throw new Ai1wm_Quota_Exceeded_Exception( sprintf( 'Out of disk space. Unable to write end of block to file. File: %s', $this->file_name ) );
150
+ }
151
+ } else {
152
+ throw new Ai1wm_Not_Writable_Exception( sprintf( 'Unable to write end of block to file. File: %s', $this->file_name ) );
153
+ }
154
  }
155
 
156
  /**
157
+ * Validate archive file
158
  *
159
+ * @return bool
160
  */
161
  public function is_valid() {
162
+ if ( ( $offset = @ftell( $this->file_handle ) ) !== false ) {
163
+ if ( @fseek( $this->file_handle, -4377, SEEK_END ) !== -1 ) {
164
+ if ( @fread( $this->file_handle, 4377 ) === $this->eof ) {
165
+ if ( @fseek( $this->file_handle, $offset, SEEK_SET ) !== -1 ) {
166
+ return true;
167
+ }
 
168
  }
169
  }
170
  }
178
  * We either close the file or append the end of file block if complete argument is set to tru
179
  *
180
  * @param bool $complete Flag to append end of file block
 
181
  *
182
+ * @return void
183
  */
184
  public function close( $complete = false ) {
185
+ // Are we done appending to the file?
186
  if ( true === $complete ) {
187
  $this->append_eof();
188
  }
189
 
190
+ // Close the file
191
+ @fclose( $this->file_handle );
192
  }
193
  }
lib/vendor/servmask/archiver/class-ai1wm-compressor.php CHANGED
@@ -28,128 +28,177 @@ class Ai1wm_Compressor extends Ai1wm_Archiver {
28
  /**
29
  * Overloaded constructor that opens the passed file for writing
30
  *
31
- * @param string $file File to use as archive
32
  */
33
- public function __construct( $file ) {
34
- // call parent, to initialize variables
35
- parent::__construct( $file, true );
36
  }
37
 
38
  /**
39
  * Add a file to the archive
40
  *
41
- * @param string $file File to add to the archive
42
- * @param string $new_filename Write the file with a different name
43
- * @param int $current_filesize File size
44
- * @param int $offset File offset
45
- * @param int $timeout Process timeout
46
  *
47
- * @throws \Ai1wm_Not_Accesible_Exception
48
- * @throws \Ai1wm_Not_Readable_Exception
49
  * @throws \Ai1wm_Not_Writable_Exception
 
 
 
50
  */
51
- public function add_file( $file, $new_filename = '', $current_filesize = 0, $offset = 0, $timeout = 0 ) {
52
- // open the file for reading in binary mode
53
- $handle = $this->open_file_for_reading( $file );
54
-
55
- // set file offset or set file header
56
- if ( $offset ) {
57
- // set file offset
58
- fseek( $handle, $offset, SEEK_SET );
59
-
60
- // set file size
61
- $this->current_filesize = $current_filesize;
62
- } else {
63
- // get file block header of the file we are trying to archive
64
- $block = $this->get_file_block( $file, $new_filename );
65
-
66
- // write file block header to our archive file
67
- $this->write_to_handle( $this->file_handle, $block );
68
- }
69
 
70
- // set file size
71
- $current_filesize = $this->get_current_filesize() - $offset;
72
 
73
- // start time
74
  $start = microtime( true );
75
 
76
- // read the file in 512KB chunks
77
- while ( $current_filesize > 0 ) {
78
- // read the file in chunks of 512KB
79
- $chunk_size = $current_filesize > 512000 ? 512000 : $current_filesize;
80
-
81
- // read the file in chunks of 512KB
82
- $content = $this->read_from_handle( $handle, $chunk_size );
83
-
84
- // remove the amount of bytes we read
85
- $current_filesize -= $chunk_size;
86
-
87
- // write file contents
88
- $this->write_to_handle( $this->file_handle, $content );
89
-
90
- // time elapsed
91
- if ( $timeout ) {
92
- if ( ( microtime( true ) - $start ) > $timeout ) {
93
- // set file offset
94
- $offset = ftell( $handle );
95
 
96
- // close the handle
97
- ai1wm_close( $handle );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- // get file offset
100
- return $offset;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  }
102
  }
 
 
 
103
  }
104
 
105
- // close the handle
106
- ai1wm_close( $handle );
107
  }
108
 
109
  /**
110
  * Generate binary block header for a file
111
  *
112
- * @param string $file Filename to generate block header for
113
- * @param string $new_filename Write the file with a different name
114
  *
115
- * @return string
116
- * @throws \Ai1wm_Not_Accesible_Exception
117
  */
118
- private function get_file_block( $file, $new_filename = '' ) {
119
- // get stats about the file
120
- $stat = stat( $file );
121
- if ( false === $stat ) {
122
- // unable to get file data
123
- throw new Ai1wm_Not_Accesible_Exception( __( 'Unable to get properties of file ' . $file, AI1WM_PLUGIN_NAME ) );
124
- }
125
 
126
- // get path details
127
- $pathinfo = pathinfo( $file );
128
 
129
- if ( ! empty( $new_filename ) ) {
130
- // get path details
131
- $pathinfo = pathinfo( $new_filename );
132
- }
 
 
 
 
 
 
 
 
133
 
134
- // filename of the file we are accessing
135
- $name = $pathinfo['basename'];
136
 
137
- // size in bytes of the file
138
- $size = $stat['7'];
139
 
140
- // last time the file was modified
141
- $date = $stat['9'];
142
 
143
- // current file size
144
- $this->current_filesize = $size;
 
 
 
 
145
 
146
- // replace DIRECTORY_SEPARATOR with / in path, we want to always have /
147
- $path = str_replace( DIRECTORY_SEPARATOR, '/', $pathinfo['dirname'] );
 
 
 
 
 
 
 
148
 
149
- // concatenate block format parts
150
- $format = implode( '', $this->block_format );
 
 
151
 
152
- // pack file data into binary string
153
- return pack( $format, $name, $size, $date, $path );
154
  }
155
  }
28
  /**
29
  * Overloaded constructor that opens the passed file for writing
30
  *
31
+ * @param string $file_name File to use as archive
32
  */
33
+ public function __construct( $file_name ) {
34
+ // Call parent, to initialize variables
35
+ parent::__construct( $file_name, true );
36
  }
37
 
38
  /**
39
  * Add a file to the archive
40
  *
41
+ * @param string $file_name File to add to the archive
42
+ * @param string $new_file_name Write the file with a different name
43
+ * @param int $file_written File written (in bytes)
44
+ * @param int $file_offset File offset (in bytes)
45
+ * @param int $timeout Process timeout (in seconds)
46
  *
47
+ * @throws \Ai1wm_Not_Seekable_Exception
 
48
  * @throws \Ai1wm_Not_Writable_Exception
49
+ * @throws \Ai1wm_Quota_Exceeded_Exception
50
+ *
51
+ * @return bool
52
  */
53
+ public function add_file( $file_name, $new_file_name = '', &$file_written = 0, &$file_offset = 0, $timeout = 0 ) {
54
+ $file_written = 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
+ // Flag to hold if file data has been processed
57
+ $completed = true;
58
 
59
+ // Start time
60
  $start = microtime( true );
61
 
62
+ // Open the file for reading in binary mode
63
+ if ( ( $file_handle = @fopen( $file_name, 'rb' ) ) !== false ) {
64
+ $file_bytes = 0;
65
+
66
+ // Get header block
67
+ if ( ( $block = $this->get_file_block( $file_name, $new_file_name ) ) ) {
68
+
69
+ // Write header block
70
+ if ( $file_offset === 0 ) {
71
+ if ( ( $file_bytes = @fwrite( $this->file_handle, $block ) ) !== false ) {
72
+ if ( strlen( $block ) !== $file_bytes ) {
73
+ throw new Ai1wm_Quota_Exceeded_Exception( sprintf( 'Out of disk space. Unable to write header to file. File: %s', $this->file_name ) );
74
+ }
75
+ } else {
76
+ throw new Ai1wm_Not_Writable_Exception( sprintf( 'Unable to write header to file. File: %s', $this->file_name ) );
77
+ }
78
+ }
 
 
79
 
80
+ // Set file offset
81
+ if ( @fseek( $file_handle, $file_offset, SEEK_SET ) !== -1 ) {
82
+
83
+ // Read the file in 512KB chunks
84
+ while ( false === @feof( $file_handle ) ) {
85
+
86
+ // Read the file in chunks of 512KB
87
+ if ( ( $file_content = @fread( $file_handle, 512000 ) ) !== false ) {
88
+ if ( ( $file_bytes = @fwrite( $this->file_handle, $file_content ) ) !== false ) {
89
+ if ( strlen( $file_content ) !== $file_bytes ) {
90
+ throw new Ai1wm_Quota_Exceeded_Exception( sprintf( 'Out of disk space. Unable to write content to file. File: %s', $this->file_name ) );
91
+ }
92
+ } else {
93
+ throw new Ai1wm_Not_Writable_Exception( sprintf( 'Unable to write content to file. File: %s', $this->file_name ) );
94
+ }
95
+
96
+ // Set file written
97
+ $file_written += $file_bytes;
98
+ }
99
+
100
+ // Time elapsed
101
+ if ( $timeout ) {
102
+ if ( ( microtime( true ) - $start ) > $timeout ) {
103
+ $completed = false;
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ }
109
 
110
+ // Set file offset
111
+ $file_offset += $file_written;
112
+
113
+ // Write file size to file header
114
+ if ( ( $block = $this->get_file_size_block( $file_offset ) ) ) {
115
+
116
+ // Seek to beginning of file size
117
+ if ( @fseek( $this->file_handle, - $file_offset - 4096 - 12 - 14, SEEK_CUR ) === -1 ) {
118
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, - $file_offset - 4096 - 12 - 14 ) );
119
+ }
120
+
121
+ // Write file size to file header
122
+ if ( ( $file_bytes = @fwrite( $this->file_handle, $block ) ) !== false ) {
123
+ if ( strlen( $block ) !== $file_bytes ) {
124
+ throw new Ai1wm_Quota_Exceeded_Exception( sprintf( 'Out of disk space. Unable to write size to file. File: %s', $this->file_name ) );
125
+ }
126
+ } else {
127
+ throw new Ai1wm_Not_Writable_Exception( sprintf( 'Unable to write size to file. File: %s', $this->file_name ) );
128
+ }
129
+
130
+ // Seek to end of file content
131
+ if ( @fseek( $this->file_handle, + $file_offset + 4096 + 12, SEEK_CUR ) === -1 ) {
132
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, + $file_offset + 4096 + 12 ) );
133
+ }
134
  }
135
  }
136
+
137
+ // Close the handle
138
+ @fclose( $file_handle );
139
  }
140
 
141
+ return $completed;
 
142
  }
143
 
144
  /**
145
  * Generate binary block header for a file
146
  *
147
+ * @param string $file_name Filename to generate block header for
148
+ * @param string $new_file_name Write the file with a different name
149
  *
150
+ * @return mixed
 
151
  */
152
+ private function get_file_block( $file_name, $new_file_name = '' ) {
153
+ $block = false;
 
 
 
 
 
154
 
155
+ // Get stats about the file
156
+ if ( ( $stat = @stat( $file_name ) ) !== false ) {
157
 
158
+ // Get path details
159
+ if ( empty( $new_file_name ) ) {
160
+ $pathinfo = pathinfo( $file_name );
161
+ } else {
162
+ $pathinfo = pathinfo( $new_file_name );
163
+ }
164
+
165
+ // Filename of the file we are accessing
166
+ $name = $pathinfo['basename'];
167
+
168
+ // Size in bytes of the file
169
+ $size = $stat['size'];
170
 
171
+ // Last time the file was modified
172
+ $date = $stat['mtime'];
173
 
174
+ // Replace DIRECTORY_SEPARATOR with / in path, we want to always have /
175
+ $path = str_replace( DIRECTORY_SEPARATOR, '/', $pathinfo['dirname'] );
176
 
177
+ // Concatenate block format parts
178
+ $format = implode( '', $this->block_format );
179
 
180
+ // Pack file data into binary string
181
+ $block = pack( $format, $name, $size, $date, $path );
182
+ }
183
+
184
+ return $block;
185
+ }
186
 
187
+ /**
188
+ * Generate file size binary block header for a file
189
+ *
190
+ * @param int $file_size File size
191
+ *
192
+ * @return string
193
+ */
194
+ public function get_file_size_block( $file_size ) {
195
+ $block = false;
196
 
197
+ // Pack file data into binary string
198
+ if ( isset( $this->block_format[1] ) ) {
199
+ $block = pack( $this->block_format[1], $file_size );
200
+ }
201
 
202
+ return $block;
 
203
  }
204
  }
lib/vendor/servmask/archiver/class-ai1wm-extractor.php CHANGED
@@ -42,48 +42,54 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
42
  /**
43
  * Overloaded constructor that opens the passed file for reading
44
  *
45
- * @param string $file File to use as archive
46
  */
47
- public function __construct( $file ) {
48
- // call parent, to initialize variables
49
- parent::__construct( $file );
50
  }
51
 
52
  /**
53
  * Get the total files count in an archive
54
  *
55
- * @return int Total files count in the archive
56
- * @throws \Ai1wm_Not_Accesible_Exception
57
- * @throws \Ai1wm_Not_Readable_Exception
58
  */
59
  public function get_total_files_count() {
60
  if ( is_null( $this->total_files_count ) ) {
61
- // set poisition to the beginning of the file
62
- fseek( $this->file_handle, SEEK_SET, 0 );
63
 
64
- // total files count
65
  $this->total_files_count = 0;
66
 
67
- // total files size
68
  $this->total_files_size = 0;
69
 
70
- while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
71
- // end block has been reached
 
 
 
 
 
 
 
72
  if ( $block === $this->eof ) {
73
  continue;
74
  }
75
 
76
- // get file data from the block
77
- $data = $this->get_data_from_block( $block );
78
 
79
- // we have a file, increment the count
80
- $this->total_files_count += 1;
81
 
82
- // we have a file, increment the size
83
- $this->total_files_size += $data['size'];
84
 
85
- // skip file content so we can move forward to the next file
86
- $this->set_file_pointer( $this->file_handle, $data['size'] );
 
 
 
87
  }
88
  }
89
 
@@ -93,284 +99,375 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
93
  /**
94
  * Get the total files size in an archive
95
  *
96
- * @return int Total files size in the archive
97
- * @throws \Ai1wm_Not_Accesible_Exception
98
- * @throws \Ai1wm_Not_Readable_Exception
99
  */
100
  public function get_total_files_size() {
101
  if ( is_null( $this->total_files_size ) ) {
102
- // set poisition to the beginning of the file
103
- fseek( $this->file_handle, SEEK_SET, 0 );
104
 
105
- // total files count
106
  $this->total_files_count = 0;
107
 
108
- // total files size
109
  $this->total_files_size = 0;
110
 
111
- while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
112
- // end block has been reached
 
 
 
 
 
 
 
113
  if ( $block === $this->eof ) {
114
  continue;
115
  }
116
 
117
- // get file data from the block
118
- $data = $this->get_data_from_block( $block );
119
 
120
- // we have a file, increment the count
121
- $this->total_files_count += 1;
122
 
123
- // we have a file, increment the size
124
- $this->total_files_size += $data['size'];
125
 
126
- // skip file content so we can move forward to the next file
127
- $this->set_file_pointer( $this->file_handle, $data['size'] );
 
 
 
128
  }
129
  }
130
 
131
  return $this->total_files_size;
132
  }
133
 
134
- public function extract_one_file_to( $location, $exclude = array(), $old_paths = array(), $new_paths = array(), $offset = 0, $timeout = 0 ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  if ( false === is_dir( $location ) ) {
136
- throw new Ai1wm_Not_Readable_Exception( sprintf( __( '%s doesn\'t exist', AI1WM_PLUGIN_NAME ), $location ) );
137
  }
138
 
139
- $block = $this->read_from_handle( $this->file_handle, 4377 );
 
140
 
141
- // we reached end of file, set the pointer to the end of the file so that feof returns true
142
- if ( $block === $this->eof ) {
143
- @fseek( $this->file_handle, 1, SEEK_END );
144
- @fgetc( $this->file_handle );
145
- return;
146
  }
147
 
148
- // get file data from header block
149
- $data = $this->get_data_from_block( $block );
150
 
151
- // set filename
152
- if ( $data['path'] === '.' ) {
153
- $filename = $data['filename'];
154
- } else {
155
- $filename = $data['path'] . '/' . $data['filename'];
156
- }
157
 
158
- // we need to build the path
159
- $path = str_replace( '/', DIRECTORY_SEPARATOR, $data['path'] );
160
 
161
- // we need to build the path for the file
162
- $filename = str_replace( '/', DIRECTORY_SEPARATOR, $filename );
163
 
164
- // should we skip this file?
165
- for ( $i = 0; $i < count( $exclude ); $i++ ) {
166
- if ( strpos( $filename . DIRECTORY_SEPARATOR, $exclude[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
167
- $this->set_file_pointer( $this->file_handle, $data['size'] );
168
- return;
169
- }
170
- }
171
 
172
- // replace extract paths
173
- for ( $i = 0; $i < count( $old_paths ); $i++ ) {
174
- if ( strpos( $path . DIRECTORY_SEPARATOR, $old_paths[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
175
- $path = substr_replace( $path, $new_paths[ $i ], 0, strlen( $old_paths[ $i ] ) );
176
- break;
177
- }
178
- }
179
 
180
- $directory = $location . DIRECTORY_SEPARATOR . $path;
 
181
 
182
- // check if location doesn't exist, then create it
183
- if ( false === is_dir( $directory ) ) {
184
- mkdir( $directory, $this->get_permissions_for_directory(), true );
185
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
 
187
- try {
188
- // we have a match, let's extract the file
189
- if ( ( $offset = $this->extract_to( $location . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . basename( $filename ), $data, $offset, $timeout ) ) ) {
190
- return $offset;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  }
192
- } catch ( Exception $e ) {
193
- // we don't have file permissions, skip file content
194
- $this->set_file_pointer( $this->file_handle, $data['size'] );
195
  }
 
 
196
  }
197
 
198
  /**
199
  * Extract specific files from archive
200
  *
201
- * @param string $location Location where to extract files
202
- * @param array $files Files to extract
203
- * @param array $offset File offset
204
- * @param int $timeout Process timeout
 
 
 
 
 
 
205
  */
206
- public function extract_by_files_array( $location, $files = array(), $offset = 0, $timeout = 0 ) {
207
  if ( false === is_dir( $location ) ) {
208
- throw new Ai1wm_Not_Readable_Exception( sprintf( __( '%s doesn\'t exist', AI1WM_PLUGIN_NAME ), $location ) );
209
  }
210
 
211
- // start time
 
 
 
212
  $start = microtime( true );
213
 
214
- // we read until we reached the end of the file, or the files we were looking for were found
215
- while ( ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) ) {
216
- // end block has been reached and we still have files to extract
217
- // that means the files don't exist in the archive
 
 
 
 
 
 
 
218
  if ( $block === $this->eof ) {
219
- // we reached end of file, set the pointer to the end of the file so that feof returns true
 
220
  @fseek( $this->file_handle, 1, SEEK_END );
221
- @fgetc( $this->file_handle );
222
- return;
223
- }
224
 
225
- $data = $this->get_data_from_block( $block );
 
226
 
227
- // set filename
228
- if ( $data['path'] === '.' ) {
229
- $filename = $data['filename'];
230
  } else {
231
- $filename = $data['path'] . '/' . $data['filename'];
232
- }
233
 
234
- // we need to build the path
235
- $path = str_replace( '/', DIRECTORY_SEPARATOR, $data['path'] );
236
 
237
- // we need to build the path for the file
238
- $filename = str_replace( '/', DIRECTORY_SEPARATOR, $filename );
239
 
240
- // set include flag
241
- $include = false;
242
 
243
- // files to extract
244
- for ( $i = 0; $i < count( $files ); $i++ ) {
245
- if ( strpos( $filename . DIRECTORY_SEPARATOR, $files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
246
- $include = true;
247
- break;
248
- }
249
- }
250
 
251
- // do we have a match?
252
- if ( $include ) {
253
- $directory = $location . DIRECTORY_SEPARATOR . $path;
254
 
255
- // check if location doesn't exist, then create it
256
- if ( false === is_dir( $directory ) ) {
257
- mkdir( $directory, $this->get_permissions_for_directory(), true );
258
- }
259
 
260
- try {
261
- // we have a match, let's extract the file and remove it from the array
262
- if ( ( $offset = $this->extract_to( $location . DIRECTORY_SEPARATOR . $filename, $data, $offset, $timeout ) ) ) {
263
- return $offset;
 
 
264
  }
265
- } catch ( Exception $e ) {
266
- // we don't have file permissions, skip file content
267
- $this->set_file_pointer( $this->file_handle, $data['size'] );
268
- }
269
- } else {
270
- // we don't have a match, skip file content
271
- $this->set_file_pointer( $this->file_handle, $data['size'] );
272
- }
273
 
274
- // time elapsed
275
- if ( $timeout ) {
276
- if ( ( microtime( true ) - $start ) > $timeout ) {
277
- break;
278
- }
279
- }
280
- }
281
- }
282
 
283
- public function set_file_pointer( $handle = null, $offset = 0 ) {
284
- // if null is used, we use the archive handle
285
- if ( is_null( $handle ) ) {
286
- $handle = $this->file_handle;
287
- }
288
 
289
- // set position to current location plus offset
290
- $result = fseek( $handle, $offset, SEEK_CUR );
291
- if ( -1 === $result ) {
292
- if ( ( $meta = stream_get_meta_data( $handle ) ) ) {
293
- throw new Ai1wm_Not_Accesible_Exception( sprintf( __( 'Unable to seek to offset %d on %s', AI1WM_PLUGIN_NAME ), $offset, $meta['uri'] ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  }
295
  }
 
 
296
  }
297
 
298
- private function extract_to( $file, $data, $offset = 0, $timeout = 0 ) {
299
- // should the extract overwrite the file if it exists?
300
- if ( $offset ) {
301
- $handle = $this->open_file_for_writing( $file );
302
- } else {
303
- $handle = $this->open_file_for_overwriting( $file );
304
- }
 
 
 
 
 
 
 
 
 
 
 
305
 
306
- // get data file pointer
307
- $data_file_pointer = $this->get_file_pointer();
308
 
309
- // set data file pointer
310
- $this->set_file_pointer( $this->file_handle, $offset );
311
 
312
- // set file size
313
- $data['size'] -= $offset;
 
 
 
 
314
 
315
- // start time
316
- $start = microtime( true );
317
 
318
- // is the filesize more than 0 bytes?
319
- while ( $data['size'] > 0 ) {
320
- // read the file in chunks of 512KB
321
- $chunk_size = $data['size'] > 512000 ? 512000 : $data['size'];
322
 
323
- // read the file in chunks of 512KB from archiver
324
- $content = $this->read_from_handle( $this->file_handle, $chunk_size );
325
 
326
- // remove the amount of bytes we read
327
- $data['size'] -= $chunk_size;
328
 
329
- // write file contents
330
- $this->write_to_handle( $handle, $content );
 
331
 
332
- // time elapsed
333
- if ( $timeout ) {
334
- if ( ( microtime( true ) - $start ) > $timeout ) {
335
- // set file offset
336
- $offset = $this->get_file_pointer() - $data_file_pointer;
337
 
338
- // set file pointer
339
- $this->set_file_pointer( $this->file_handle, -$offset );
340
 
341
- // rewind file pointer
342
- $this->set_file_pointer( $this->file_handle, -4377 );
 
 
 
 
343
 
344
- // close the handle
345
- ai1wm_close( $handle );
 
346
 
347
- // get file offset
348
- return $offset;
 
 
 
 
349
  }
350
  }
351
- }
352
 
353
- // close the handle
354
- ai1wm_close( $handle );
355
 
356
- // let's apply last modified date
357
- $this->set_mtime_of_file( $file, $data['mtime'] );
358
 
359
- // all files should chmoded to 644
360
- $this->set_file_mode( $file, $this->get_permissions_for_file() );
361
 
362
- return 0;
363
- }
364
 
365
- private function set_mtime_of_file( $file, $mtime ) {
366
- return @touch( $file, $mtime );
367
- }
368
 
369
- private function set_file_mode( $file, $mode = 0644 ) {
370
- return @chmod( $file, $mode );
 
 
 
 
 
371
  }
372
 
 
 
 
 
 
 
 
373
  private function get_data_from_block( $block ) {
 
 
374
  // prepare our array keys to unpack
375
  $format = array(
376
  $this->block_format[0] . 'filename/',
@@ -380,15 +477,27 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
380
  );
381
  $format = implode( '', $format );
382
 
383
- $data = unpack( $format, $block );
 
 
 
 
 
 
 
384
 
385
- $data['filename'] = trim( $data['filename'] );
386
- $data['size'] = trim( $data['size'] );
387
- $data['mtime'] = trim( $data['mtime'] );
388
- $data['path'] = trim( $data['path'] );
389
 
390
- // current file size
391
- $this->current_filesize = $data['size'];
 
 
 
 
 
 
 
392
 
393
  return $data;
394
  }
@@ -400,7 +509,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
400
  * @return bool
401
  */
402
  public function has_reached_eof() {
403
- return feof( $this->file_handle );
404
  }
405
 
406
  /**
@@ -410,33 +519,13 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
410
  * @return bool
411
  */
412
  public function has_not_reached_eof() {
413
- return ! feof( $this->file_handle );
414
- }
415
-
416
- /**
417
- * Get current file pointer
418
- *
419
- * return int
420
- */
421
- public function get_file_pointer() {
422
- $result = ftell( $this->file_handle );
423
-
424
- if ( false === $result ) {
425
- throw new Ai1wm_Not_Accesible_Exception(
426
- sprintf(
427
- __( 'Unable to get current pointer position of %s', AI1WM_PLUGIN_NAME ),
428
- $this->filename
429
- )
430
- );
431
- }
432
-
433
- return $result;
434
  }
435
 
436
  /**
437
  * Get directory permissions
438
  *
439
- * return int
440
  */
441
  public function get_permissions_for_directory() {
442
  if ( defined( 'FS_CHMOD_DIR' ) ) {
@@ -449,7 +538,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
449
  /**
450
  * Get file permissions
451
  *
452
- * return int
453
  */
454
  public function get_permissions_for_file() {
455
  if ( defined( 'FS_CHMOD_FILE' ) ) {
@@ -458,5 +547,4 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
458
 
459
  return 0644;
460
  }
461
-
462
  }
42
  /**
43
  * Overloaded constructor that opens the passed file for reading
44
  *
45
+ * @param string $file_name File to use as archive
46
  */
47
+ public function __construct( $file_name ) {
48
+ // Call parent, to initialize variables
49
+ parent::__construct( $file_name );
50
  }
51
 
52
  /**
53
  * Get the total files count in an archive
54
  *
55
+ * @return int
 
 
56
  */
57
  public function get_total_files_count() {
58
  if ( is_null( $this->total_files_count ) ) {
 
 
59
 
60
+ // Total files count
61
  $this->total_files_count = 0;
62
 
63
+ // Total files size
64
  $this->total_files_size = 0;
65
 
66
+ // Seek to beginning of archive file
67
+ if ( @fseek( $this->file_handle, 0, SEEK_SET ) === -1 ) {
68
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to beginning of file. File: %s', $this->file_name ) );
69
+ }
70
+
71
+ // Loop over files
72
+ while ( $block = @fread( $this->file_handle, 4377 ) ) {
73
+
74
+ // End block has been reached
75
  if ( $block === $this->eof ) {
76
  continue;
77
  }
78
 
79
+ // Get file data from the block
80
+ if ( ( $data = $this->get_data_from_block( $block ) ) ) {
81
 
82
+ // We have a file, increment the count
83
+ $this->total_files_count += 1;
84
 
85
+ // We have a file, increment the size
86
+ $this->total_files_size += $data['size'];
87
 
88
+ // Skip file content so we can move forward to the next file
89
+ if ( @fseek( $this->file_handle, $data['size'], SEEK_CUR ) === -1 ) {
90
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $data['size'] ) );
91
+ }
92
+ }
93
  }
94
  }
95
 
99
  /**
100
  * Get the total files size in an archive
101
  *
102
+ * @return int
 
 
103
  */
104
  public function get_total_files_size() {
105
  if ( is_null( $this->total_files_size ) ) {
 
 
106
 
107
+ // Total files count
108
  $this->total_files_count = 0;
109
 
110
+ // Total files size
111
  $this->total_files_size = 0;
112
 
113
+ // Seek to beginning of archive file
114
+ if ( @fseek( $this->file_handle, 0, SEEK_SET ) === -1 ) {
115
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to beginning of file. File: %s', $this->file_name ) );
116
+ }
117
+
118
+ // Loop over files
119
+ while ( $block = @fread( $this->file_handle, 4377 ) ) {
120
+
121
+ // End block has been reached
122
  if ( $block === $this->eof ) {
123
  continue;
124
  }
125
 
126
+ // Get file data from the block
127
+ if ( ( $data = $this->get_data_from_block( $block ) ) ) {
128
 
129
+ // We have a file, increment the count
130
+ $this->total_files_count += 1;
131
 
132
+ // We have a file, increment the size
133
+ $this->total_files_size += $data['size'];
134
 
135
+ // Skip file content so we can move forward to the next file
136
+ if ( @fseek( $this->file_handle, $data['size'], SEEK_CUR ) === -1 ) {
137
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $data['size'] ) );
138
+ }
139
+ }
140
  }
141
  }
142
 
143
  return $this->total_files_size;
144
  }
145
 
146
+ /**
147
+ * Extract one file to location
148
+ *
149
+ * @param string $location Destination path
150
+ * @param array $exclude Files to exclude
151
+ * @param array $old_paths Old replace paths
152
+ * @param array $new_paths New replace paths
153
+ * @param int $file_written File written (in bytes)
154
+ * @param int $file_offset File offset (in bytes)
155
+ * @param int $timeout Process timeout (in seconds)
156
+ *
157
+ * @throws \Ai1wm_Not_Directory_Exception
158
+ * @throws \Ai1wm_Not_Seekable_Exception
159
+ *
160
+ * @return bool
161
+ */
162
+ public function extract_one_file_to( $location, $exclude = array(), $old_paths = array(), $new_paths = array(), &$file_written = 0, &$file_offset = 0, $timeout = 0 ) {
163
  if ( false === is_dir( $location ) ) {
164
+ throw new Ai1wm_Not_Directory_Exception( sprintf( 'Location is not a directory: %s', $location ) );
165
  }
166
 
167
+ // Flag to hold if file data has been processed
168
+ $completed = true;
169
 
170
+ // Seek to file offset to archive file
171
+ if ( $file_offset > 0 ) {
172
+ if ( @fseek( $this->file_handle, - $file_offset - 4377, SEEK_CUR ) === -1 ) {
173
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, - $file_offset - 4377 ) );
174
+ }
175
  }
176
 
177
+ // Read file header block
178
+ if ( ( $block = @fread( $this->file_handle, 4377 ) ) ) {
179
 
180
+ // We reached end of file, set the pointer to the end of the file so that feof returns true
181
+ if ( $block === $this->eof ) {
 
 
 
 
182
 
183
+ // Seek to end of archive file minus 1 byte
184
+ @fseek( $this->file_handle, 1, SEEK_END );
185
 
186
+ // Read 1 character
187
+ @fgetc( $this->file_handle );
188
 
189
+ } else {
 
 
 
 
 
 
190
 
191
+ // Get file header data from the block
192
+ if ( ( $data = $this->get_data_from_block( $block ) ) ) {
 
 
 
 
 
193
 
194
+ // Set file name
195
+ $file_name = $data['filename'];
196
 
197
+ // Set file size
198
+ $file_size = $data['size'];
199
+
200
+ // Set file mtime
201
+ $file_mtime = $data['mtime'];
202
+
203
+ // Set file path
204
+ $file_path = $data['path'];
205
+
206
+ // Set should exclude file
207
+ $should_exclude_file = false;
208
+
209
+ // Should we skip this file?
210
+ for ( $i = 0; $i < count( $exclude ); $i++ ) {
211
+ if ( strpos( $file_name . DIRECTORY_SEPARATOR, $exclude[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
212
+ $should_exclude_file = true;
213
+ break;
214
+ }
215
+ }
216
 
217
+ // Do we have a match?
218
+ if ( $should_exclude_file === false ) {
219
+
220
+ // Replace extract paths
221
+ for ( $i = 0; $i < count( $old_paths ); $i++ ) {
222
+ if ( strpos( $file_path . DIRECTORY_SEPARATOR, $old_paths[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
223
+ $file_path = substr_replace( $file_path, $new_paths[ $i ], 0, strlen( $old_paths[ $i ] ) );
224
+ break;
225
+ }
226
+ }
227
+
228
+ // Check if location doesn't exist, then create it
229
+ if ( false === is_dir( $location . DIRECTORY_SEPARATOR . $file_path ) ) {
230
+ @mkdir( $location . DIRECTORY_SEPARATOR . $file_path, $this->get_permissions_for_directory(), true );
231
+ }
232
+
233
+ $file_written = 0;
234
+
235
+ // We have a match, let's extract the file
236
+ if ( ( $completed = $this->extract_to( $location . DIRECTORY_SEPARATOR . $file_name, $file_size, $file_mtime, $file_written, $file_offset, $timeout ) ) ) {
237
+ $file_offset = 0;
238
+ }
239
+ } else {
240
+
241
+ // We don't have a match, skip file content
242
+ if ( @fseek( $this->file_handle, $file_size, SEEK_CUR ) === -1 ) {
243
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $file_size ) );
244
+ }
245
+ }
246
+ }
247
  }
 
 
 
248
  }
249
+
250
+ return $completed;
251
  }
252
 
253
  /**
254
  * Extract specific files from archive
255
  *
256
+ * @param string $location Location where to extract files
257
+ * @param array $files Files to extract
258
+ * @param int $file_written File written (in bytes)
259
+ * @param int $file_offset File offset (in bytes)
260
+ * @param int $timeout Process timeout (in seconds)
261
+ *
262
+ * @throws \Ai1wm_Not_Directory_Exception
263
+ * @throws \Ai1wm_Not_Seekable_Exception
264
+ *
265
+ * @return bool
266
  */
267
+ public function extract_by_files_array( $location, $files = array(), &$file_written = 0, &$file_offset = 0, $timeout = 0 ) {
268
  if ( false === is_dir( $location ) ) {
269
+ throw new Ai1wm_Not_Directory_Exception( sprintf( 'Location is not a directory: %s', $location ) );
270
  }
271
 
272
+ // Flag to hold if file data has been processed
273
+ $completed = true;
274
+
275
+ // Start time
276
  $start = microtime( true );
277
 
278
+ // Seek to file offset to archive file
279
+ if ( $file_offset > 0 ) {
280
+ if ( @fseek( $this->file_handle, - $file_offset - 4377, SEEK_CUR ) === -1 ) {
281
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, - $file_offset - 4377 ) );
282
+ }
283
+ }
284
+
285
+ // We read until we reached the end of the file, or the files we were looking for were found
286
+ while ( ( $block = @fread( $this->file_handle, 4377 ) ) ) {
287
+
288
+ // We reached end of file, set the pointer to the end of the file so that feof returns true
289
  if ( $block === $this->eof ) {
290
+
291
+ // Seek to end of archive file minus 1 byte
292
  @fseek( $this->file_handle, 1, SEEK_END );
 
 
 
293
 
294
+ // Read 1 character
295
+ @fgetc( $this->file_handle );
296
 
 
 
 
297
  } else {
 
 
298
 
299
+ // Get file header data from the block
300
+ if ( ( $data = $this->get_data_from_block( $block ) ) ) {
301
 
302
+ // Set file name
303
+ $file_name = $data['filename'];
304
 
305
+ // Set file size
306
+ $file_size = $data['size'];
307
 
308
+ // Set file mtime
309
+ $file_mtime = $data['mtime'];
 
 
 
 
 
310
 
311
+ // Set file path
312
+ $file_path = $data['path'];
 
313
 
314
+ // Set should include file
315
+ $should_include_file = false;
 
 
316
 
317
+ // Should be extract this file?
318
+ for ( $i = 0; $i < count( $files ); $i++ ) {
319
+ if ( strpos( $file_name . DIRECTORY_SEPARATOR, $files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
320
+ $should_include_file = true;
321
+ break;
322
+ }
323
  }
 
 
 
 
 
 
 
 
324
 
325
+ // Do we have a match?
326
+ if ( $should_include_file === true ) {
 
 
 
 
 
 
327
 
328
+ // Check if location doesn't exist, then create it
329
+ if ( false === is_dir( $location . DIRECTORY_SEPARATOR . $file_path ) ) {
330
+ @mkdir( $location . DIRECTORY_SEPARATOR . $file_path, $this->get_permissions_for_directory(), true );
331
+ }
 
332
 
333
+ $file_written = 0;
334
+
335
+ // We have a match, let's extract the file and remove it from the array
336
+ if ( ( $completed = $this->extract_to( $location . DIRECTORY_SEPARATOR . $file_name, $file_size, $file_mtime, $file_written, $file_offset, $timeout ) ) ) {
337
+ $file_offset = 0;
338
+ }
339
+ } else {
340
+
341
+ // We don't have a match, skip file content
342
+ if ( @fseek( $this->file_handle, $file_size, SEEK_CUR ) === -1 ) {
343
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $file_size ) );
344
+ }
345
+ }
346
+
347
+ // Time elapsed
348
+ if ( $timeout ) {
349
+ if ( ( microtime( true ) - $start ) > $timeout ) {
350
+ $completed = false;
351
+ break;
352
+ }
353
+ }
354
+ }
355
  }
356
  }
357
+
358
+ return $completed;
359
  }
360
 
361
+ /**
362
+ * Extract file to
363
+ *
364
+ * @param string $file_name File name
365
+ * @param array $file_size File size (in bytes)
366
+ * @param array $file_mtime File modified time (in seconds)
367
+ * @param int $file_written File written (in bytes)
368
+ * @param int $file_offset File offset (in bytes)
369
+ * @param int $timeout Process timeout (in seconds)
370
+ *
371
+ * @throws \Ai1wm_Not_Seekable_Exception
372
+ * @throws \Ai1wm_Not_Readable_Exception
373
+ * @throws \Ai1wm_Quota_Exceeded_Exception
374
+ *
375
+ * @return bool
376
+ */
377
+ private function extract_to( $file_name, $file_size, $file_mtime, &$file_written = 0, &$file_offset = 0, $timeout = 0 ) {
378
+ $file_written = 0;
379
 
380
+ // Flag to hold if file data has been processed
381
+ $completed = true;
382
 
383
+ // Start time
384
+ $start = microtime( true );
385
 
386
+ // Seek to file offset to archive file
387
+ if ( $file_offset > 0 ) {
388
+ if ( @fseek( $this->file_handle, $file_offset, SEEK_CUR ) === -1 ) {
389
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $file_size ) );
390
+ }
391
+ }
392
 
393
+ // Set file size
394
+ $file_size -= $file_offset;
395
 
396
+ // Should the extract overwrite the file if it exists?
397
+ if ( ( $file_handle = @fopen( $file_name, ( $file_offset === 0 ? 'wb' : 'ab' ) ) ) !== false ) {
398
+ $file_bytes = 0;
 
399
 
400
+ // Is the filesize more than 0 bytes?
401
+ while ( $file_size > 0 ) {
402
 
403
+ // Read the file in chunks of 512KB
404
+ $chunk_size = $file_size > 512000 ? 512000 : $file_size;
405
 
406
+ // Read data chunk by chunk from archive file
407
+ if ( $chunk_size > 0 ) {
408
+ $file_content = null;
409
 
410
+ // Read the file in chunks of 512KB from archiver
411
+ if ( ( $file_content = @fread( $this->file_handle, $chunk_size ) ) === false ) {
412
+ throw new Ai1wm_Not_Readable_Exception( sprintf( 'Unable to read content from file. File: %s', $this->file_name ) );
413
+ }
 
414
 
415
+ // Remove the amount of bytes we read
416
+ $file_size -= $chunk_size;
417
 
418
+ // Write file contents
419
+ if ( ( $file_bytes = @fwrite( $file_handle, $file_content ) ) !== false ) {
420
+ if ( strlen( $file_content ) !== $file_bytes ) {
421
+ throw new Ai1wm_Quota_Exceeded_Exception( sprintf( 'Out of disk space. Unable to write content to file. File: %s', $file_name ) );
422
+ }
423
+ }
424
 
425
+ // Set file written
426
+ $file_written += $chunk_size;
427
+ }
428
 
429
+ // Time elapsed
430
+ if ( $timeout ) {
431
+ if ( ( microtime( true ) - $start ) > $timeout ) {
432
+ $completed = false;
433
+ break;
434
+ }
435
  }
436
  }
 
437
 
438
+ // Set file offset
439
+ $file_offset += $file_written;
440
 
441
+ // Close the handle
442
+ @fclose( $file_handle );
443
 
444
+ // Let's apply last modified date
445
+ @touch( $file_name, $file_mtime );
446
 
447
+ // All files should chmoded to 644
448
+ @chmod( $file_name, $this->get_permissions_for_file() );
449
 
450
+ } else {
 
 
451
 
452
+ // We don't have file permissions, skip file content
453
+ if ( @fseek( $this->file_handle, $file_size, SEEK_CUR ) === -1 ) {
454
+ throw new Ai1wm_Not_Seekable_Exception( sprintf( 'Unable to seek to offset on file. File: %s Offset: %d', $this->file_name, $file_size ) );
455
+ }
456
+ }
457
+
458
+ return $completed;
459
  }
460
 
461
+ /**
462
+ * Get file header data from the block
463
+ *
464
+ * @param string $block Binary file header
465
+ *
466
+ * @return array
467
+ */
468
  private function get_data_from_block( $block ) {
469
+ $data = false;
470
+
471
  // prepare our array keys to unpack
472
  $format = array(
473
  $this->block_format[0] . 'filename/',
477
  );
478
  $format = implode( '', $format );
479
 
480
+ // Unpack file header data
481
+ if ( ( $data = unpack( $format, $block ) ) ) {
482
+
483
+ // Set file details
484
+ $data['filename'] = trim( $data['filename'] );
485
+ $data['size'] = trim( $data['size'] );
486
+ $data['mtime'] = trim( $data['mtime'] );
487
+ $data['path'] = trim( $data['path'] );
488
 
489
+ // Set file name
490
+ $data['filename'] = ( $data['path'] === '.' ? $data['filename'] : $data['path'] . DIRECTORY_SEPARATOR . $data['filename'] );
 
 
491
 
492
+ // Set file path
493
+ $data['path'] = ( $data['path'] === '.' ? null : $data['path'] );
494
+
495
+ // Replace forward slash with current directory separator
496
+ $data['filename'] = str_replace( '/', DIRECTORY_SEPARATOR, $data['filename'] );
497
+
498
+ // Replace forward slash with current directory separator
499
+ $data['path'] = str_replace( '/', DIRECTORY_SEPARATOR, $data['path'] );
500
+ }
501
 
502
  return $data;
503
  }
509
  * @return bool
510
  */
511
  public function has_reached_eof() {
512
+ return @feof( $this->file_handle );
513
  }
514
 
515
  /**
519
  * @return bool
520
  */
521
  public function has_not_reached_eof() {
522
+ return ! @feof( $this->file_handle );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
523
  }
524
 
525
  /**
526
  * Get directory permissions
527
  *
528
+ * @return int
529
  */
530
  public function get_permissions_for_directory() {
531
  if ( defined( 'FS_CHMOD_DIR' ) ) {
538
  /**
539
  * Get file permissions
540
  *
541
+ * @return int
542
  */
543
  public function get_permissions_for_file() {
544
  if ( defined( 'FS_CHMOD_FILE' ) ) {
547
 
548
  return 0644;
549
  }
 
550
  }
lib/view/assets/javascript/backups.min.js CHANGED
@@ -94,7 +94,10 @@
94
  url: ai1wm_backups.ajax.url,
95
  type: 'POST',
96
  dataType: 'json',
97
- data: { 'archive': self.data('archive') },
 
 
 
98
  dataFilter: function dataFilter(data, type) {
99
  return Util.json(data);
100
  },
@@ -187,7 +190,12 @@
187
  type: 'POST',
188
  dataType: 'json',
189
  async: false,
190
- data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
191
  dataFilter: function dataFilter(data, type) {
192
  return Util.json(data);
193
  },
@@ -390,7 +398,13 @@
390
  type: 'POST',
391
  dataType: 'json',
392
  async: false,
393
- data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
 
394
  dataFilter: function dataFilter(data, type) {
395
  return Util.json(data);
396
  },
94
  url: ai1wm_backups.ajax.url,
95
  type: 'POST',
96
  dataType: 'json',
97
+ data: {
98
+ 'secret_key': ai1wm_backups.secret_key,
99
+ 'archive': self.data('archive')
100
+ },
101
  dataFilter: function dataFilter(data, type) {
102
  return Util.json(data);
103
  },
190
  type: 'POST',
191
  dataType: 'json',
192
  async: false,
193
+ data: {
194
+ 'secret_key': ai1wm_report.secret_key,
195
+ 'ai1wm_email': email,
196
+ 'ai1wm_message': message,
197
+ 'ai1wm_terms': +terms
198
+ },
199
  dataFilter: function dataFilter(data, type) {
200
  return Util.json(data);
201
  },
398
  type: 'POST',
399
  dataType: 'json',
400
  async: false,
401
+ data: {
402
+ 'secret_key': ai1wm_feedback.secret_key,
403
+ 'ai1wm_type': type,
404
+ 'ai1wm_email': email,
405
+ 'ai1wm_message': message,
406
+ 'ai1wm_terms': +terms
407
+ },
408
  dataFilter: function dataFilter(data, type) {
409
  return Util.json(data);
410
  },
lib/view/assets/javascript/export.min.js CHANGED
@@ -170,7 +170,12 @@
170
  type: 'POST',
171
  dataType: 'json',
172
  async: false,
173
- data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
174
  dataFilter: function dataFilter(data, type) {
175
  return Util.json(data);
176
  },
@@ -373,7 +378,13 @@
373
  type: 'POST',
374
  dataType: 'json',
375
  async: false,
376
- data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
 
377
  dataFilter: function dataFilter(data, type) {
378
  return Util.json(data);
379
  },
170
  type: 'POST',
171
  dataType: 'json',
172
  async: false,
173
+ data: {
174
+ 'secret_key': ai1wm_report.secret_key,
175
+ 'ai1wm_email': email,
176
+ 'ai1wm_message': message,
177
+ 'ai1wm_terms': +terms
178
+ },
179
  dataFilter: function dataFilter(data, type) {
180
  return Util.json(data);
181
  },
378
  type: 'POST',
379
  dataType: 'json',
380
  async: false,
381
+ data: {
382
+ 'secret_key': ai1wm_feedback.secret_key,
383
+ 'ai1wm_type': type,
384
+ 'ai1wm_email': email,
385
+ 'ai1wm_message': message,
386
+ 'ai1wm_terms': +terms
387
+ },
388
  dataFilter: function dataFilter(data, type) {
389
  return Util.json(data);
390
  },
lib/view/assets/javascript/import.min.js CHANGED
@@ -144,7 +144,12 @@
144
  type: 'POST',
145
  dataType: 'json',
146
  async: false,
147
- data: { 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
148
  dataFilter: function dataFilter(data, type) {
149
  return Util.json(data);
150
  },
@@ -347,7 +352,13 @@
347
  type: 'POST',
348
  dataType: 'json',
349
  async: false,
350
- data: { 'ai1wm_type': type, 'ai1wm_email': email, 'ai1wm_message': message, 'ai1wm_terms': +terms },
 
 
 
 
 
 
351
  dataFilter: function dataFilter(data, type) {
352
  return Util.json(data);
353
  },
144
  type: 'POST',
145
  dataType: 'json',
146
  async: false,
147
+ data: {
148
+ 'secret_key': ai1wm_report.secret_key,
149
+ 'ai1wm_email': email,
150
+ 'ai1wm_message': message,
151
+ 'ai1wm_terms': +terms
152
+ },
153
  dataFilter: function dataFilter(data, type) {
154
  return Util.json(data);
155
  },
352
  type: 'POST',
353
  dataType: 'json',
354
  async: false,
355
+ data: {
356
+ 'secret_key': ai1wm_feedback.secret_key,
357
+ 'ai1wm_type': type,
358
+ 'ai1wm_email': email,
359
+ 'ai1wm_message': message,
360
+ 'ai1wm_terms': +terms
361
+ },
362
  dataFilter: function dataFilter(data, type) {
363
  return Util.json(data);
364
  },
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: yani.iliev, bangelov, pimjitsawang
3
  Tags: move, transfer, copy, migrate, backup, clone, restore, db migration, wordpress migration, website migration, database export, database import, apoyo, sauvegarde, di riserva, バックアップ
4
  Requires at least: 3.3
5
  Tested up to: 4.8
6
- Stable tag: 6.50
7
  License: GPLv2 or later
8
 
9
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
@@ -90,6 +90,20 @@ Alternatively you can download the plugin using the download button on this page
90
  3. Plugin Menu
91
 
92
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  = 6.50 =
94
  **Fixed**
95
 
3
  Tags: move, transfer, copy, migrate, backup, clone, restore, db migration, wordpress migration, website migration, database export, database import, apoyo, sauvegarde, di riserva, バックアップ
4
  Requires at least: 3.3
5
  Tested up to: 4.8
6
+ Stable tag: 6.51
7
  License: GPLv2 or later
8
 
9
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
90
  3. Plugin Menu
91
 
92
  == Changelog ==
93
+ = 6.51 =
94
+ **Added**
95
+
96
+ * Validation on leave feedback, report issue and delete backup actions
97
+ * More descriptive wpress file names on export
98
+
99
+ **Changed**
100
+
101
+ * Remove "Unable to authenticate with secret key" message
102
+
103
+ **Fixed**
104
+
105
+ * Wrong file size in wpress file on export
106
+
107
  = 6.50 =
108
  **Fixed**
109