All-in-One WP Migration - Version 7.19

Version Description

Added

  • Support for custom upload directory
Download this release

Release Info

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

Code changes from version 7.18 to 7.19

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: 7.18
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: 7.19
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
constants.php CHANGED
@@ -35,7 +35,7 @@ define( 'AI1WM_DEBUG', false );
35
  // ==================
36
  // = Plugin Version =
37
  // ==================
38
- define( 'AI1WM_VERSION', '7.18' );
39
 
40
  // ===============
41
  // = Plugin Name =
@@ -152,10 +152,15 @@ define( 'AI1WM_SETTINGS_NAME', 'settings.json' );
152
  // ==========================
153
  define( 'AI1WM_MULTIPART_NAME', 'multipart.list' );
154
 
155
- // ========================
156
- // = Archive Filemap Name =
157
- // ========================
158
- define( 'AI1WM_FILEMAP_NAME', 'filemap.list' );
 
 
 
 
 
159
 
160
  // =================================
161
  // = Archive Must-Use Plugins Name =
@@ -257,6 +262,16 @@ define( 'AI1WM_SITE_URL', 'siteurl' );
257
  // ============
258
  define( 'AI1WM_HOME_URL', 'home' );
259
 
 
 
 
 
 
 
 
 
 
 
260
  // ==================
261
  // = Active Plugins =
262
  // ==================
35
  // ==================
36
  // = Plugin Version =
37
  // ==================
38
+ define( 'AI1WM_VERSION', '7.19' );
39
 
40
  // ===============
41
  // = Plugin Name =
152
  // ==========================
153
  define( 'AI1WM_MULTIPART_NAME', 'multipart.list' );
154
 
155
+ // =============================
156
+ // = Archive Content List Name =
157
+ // =============================
158
+ define( 'AI1WM_CONTENT_LIST_NAME', 'content.list' );
159
+
160
+ // ===========================
161
+ // = Archive Media List Name =
162
+ // ===========================
163
+ define( 'AI1WM_MEDIA_LIST_NAME', 'media.list' );
164
 
165
  // =================================
166
  // = Archive Must-Use Plugins Name =
262
  // ============
263
  define( 'AI1WM_HOME_URL', 'home' );
264
 
265
+ // ================
266
+ // = Uploads Path =
267
+ // ================
268
+ define( 'AI1WM_UPLOADS_PATH', 'upload_path' );
269
+
270
+ // ====================
271
+ // = Uploads URL Path =
272
+ // ====================
273
+ define( 'AI1WM_UPLOADS_URL_PATH', 'upload_url_path' );
274
+
275
  // ==================
276
  // = Active Plugins =
277
  // ==================
functions.php CHANGED
@@ -121,13 +121,23 @@ function ai1wm_multipart_path( $params ) {
121
  }
122
 
123
  /**
124
- * Get filemap.list absolute path
125
  *
126
  * @param array $params Request parameters
127
  * @return string
128
  */
129
- function ai1wm_filemap_path( $params ) {
130
- return ai1wm_storage_path( $params ) . DIRECTORY_SEPARATOR . AI1WM_FILEMAP_NAME;
 
 
 
 
 
 
 
 
 
 
131
  }
132
 
133
  /**
@@ -189,20 +199,6 @@ function ai1wm_error_path() {
189
  return AI1WM_STORAGE_PATH . DIRECTORY_SEPARATOR . AI1WM_ERROR_NAME;
190
  }
191
 
192
- /**
193
- * Get WordPress content directory
194
- *
195
- * @param string $path Relative path
196
- * @return string
197
- */
198
- function ai1wm_content_path( $path = null ) {
199
- if ( empty( $path ) ) {
200
- return WP_CONTENT_DIR;
201
- }
202
-
203
- return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path;
204
- }
205
-
206
  /**
207
  * Get archive name
208
  *
@@ -220,7 +216,7 @@ function ai1wm_archive_name( $params ) {
220
  * @return string
221
  */
222
  function ai1wm_backup_url( $params ) {
223
- return AI1WM_BACKUPS_URL . '/' . str_replace( DIRECTORY_SEPARATOR, '/', $params['archive'] );
224
  }
225
 
226
  /**
@@ -566,7 +562,7 @@ function ai1wm_storage_folder() {
566
  * @param integer $blog_id Blog ID
567
  * @return boolean
568
  */
569
- function ai1wm_main_site( $blog_id = null ) {
570
  return $blog_id === null || $blog_id === 0 || $blog_id === 1;
571
  }
572
 
@@ -576,8 +572,50 @@ function ai1wm_main_site( $blog_id = null ) {
576
  * @param integer $blog_id Blog ID
577
  * @return string
578
  */
579
- function ai1wm_files_path( $blog_id = null ) {
580
- if ( ai1wm_main_site( $blog_id ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
  return 'uploads';
582
  }
583
 
@@ -585,13 +623,13 @@ function ai1wm_files_path( $blog_id = null ) {
585
  }
586
 
587
  /**
588
- * Get blogs.dir absolute path by blog ID
589
  *
590
  * @param integer $blog_id Blog ID
591
  * @return string
592
  */
593
- function ai1wm_blogsdir_path( $blog_id = null ) {
594
- if ( ai1wm_main_site( $blog_id ) ) {
595
  return 'uploads';
596
  }
597
 
@@ -599,13 +637,13 @@ function ai1wm_blogsdir_path( $blog_id = null ) {
599
  }
600
 
601
  /**
602
- * Get sites absolute path by blog ID
603
  *
604
  * @param integer $blog_id Blog ID
605
  * @return string
606
  */
607
- function ai1wm_sites_path( $blog_id = null ) {
608
- if ( ai1wm_main_site( $blog_id ) ) {
609
  return 'uploads';
610
  }
611
 
@@ -618,12 +656,12 @@ function ai1wm_sites_path( $blog_id = null ) {
618
  * @param integer $blog_id Blog ID
619
  * @return string
620
  */
621
- function ai1wm_files_url( $blog_id = null ) {
622
- if ( ai1wm_main_site( $blog_id ) ) {
623
  return '/wp-content/uploads/';
624
  }
625
 
626
- return "/wp-content/blogs.dir/{$blog_id}/files/";
627
  }
628
 
629
  /**
@@ -632,12 +670,12 @@ function ai1wm_files_url( $blog_id = null ) {
632
  * @param integer $blog_id Blog ID
633
  * @return string
634
  */
635
- function ai1wm_blogsdir_url( $blog_id = null ) {
636
- if ( ai1wm_main_site( $blog_id ) ) {
637
  return '/wp-content/uploads/';
638
  }
639
 
640
- return "/wp-content/blogs.dir/{$blog_id}/";
641
  }
642
 
643
  /**
@@ -646,12 +684,26 @@ function ai1wm_blogsdir_url( $blog_id = null ) {
646
  * @param integer $blog_id Blog ID
647
  * @return string
648
  */
649
- function ai1wm_sites_url( $blog_id = null ) {
650
- if ( ai1wm_main_site( $blog_id ) ) {
651
  return '/wp-content/uploads/';
652
  }
653
 
654
- return "/wp-content/uploads/sites/{$blog_id}/";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
655
  }
656
 
657
  /**
@@ -661,7 +713,7 @@ function ai1wm_sites_url( $blog_id = null ) {
661
  * @return string
662
  */
663
  function ai1wm_servmask_prefix( $blog_id = null ) {
664
- if ( ai1wm_main_site( $blog_id ) ) {
665
  return AI1WM_TABLE_PREFIX;
666
  }
667
 
@@ -678,7 +730,7 @@ function ai1wm_table_prefix( $blog_id = null ) {
678
  global $wpdb;
679
 
680
  // Set base table prefix
681
- if ( ai1wm_main_site( $blog_id ) ) {
682
  return $wpdb->base_prefix;
683
  }
684
 
@@ -1634,7 +1686,33 @@ function ai1wm_get_filters( $tag ) {
1634
  function ai1wm_get_uploads_dir() {
1635
  if ( ( $upload_dir = wp_upload_dir() ) ) {
1636
  if ( isset( $upload_dir['basedir'] ) ) {
1637
- return $upload_dir['basedir'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1638
  }
1639
  }
1640
  }
@@ -1659,3 +1737,33 @@ function ai1wm_basename( $path, $suffix = '' ) {
1659
  function ai1wm_dirname( $path ) {
1660
  return urldecode( dirname( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ) ) );
1661
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  }
122
 
123
  /**
124
+ * Get content.list absolute path
125
  *
126
  * @param array $params Request parameters
127
  * @return string
128
  */
129
+ function ai1wm_content_list_path( $params ) {
130
+ return ai1wm_storage_path( $params ) . DIRECTORY_SEPARATOR . AI1WM_CONTENT_LIST_NAME;
131
+ }
132
+
133
+ /**
134
+ * Get media.list absolute path
135
+ *
136
+ * @param array $params Request parameters
137
+ * @return string
138
+ */
139
+ function ai1wm_media_list_path( $params ) {
140
+ return ai1wm_storage_path( $params ) . DIRECTORY_SEPARATOR . AI1WM_MEDIA_LIST_NAME;
141
  }
142
 
143
  /**
199
  return AI1WM_STORAGE_PATH . DIRECTORY_SEPARATOR . AI1WM_ERROR_NAME;
200
  }
201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  /**
203
  * Get archive name
204
  *
216
  * @return string
217
  */
218
  function ai1wm_backup_url( $params ) {
219
+ return AI1WM_BACKUPS_URL . '/' . ai1wm_replace_directory_separator_with_forward_slash( $params['archive'] );
220
  }
221
 
222
  /**
562
  * @param integer $blog_id Blog ID
563
  * @return boolean
564
  */
565
+ function ai1wm_is_mainsite( $blog_id = null ) {
566
  return $blog_id === null || $blog_id === 0 || $blog_id === 1;
567
  }
568
 
572
  * @param integer $blog_id Blog ID
573
  * @return string
574
  */
575
+ function ai1wm_blog_files_abspath( $blog_id = null ) {
576
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
577
+ return ai1wm_get_uploads_dir();
578
+ }
579
+
580
+ return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'blogs.dir' . DIRECTORY_SEPARATOR . $blog_id . DIRECTORY_SEPARATOR . 'files';
581
+ }
582
+
583
+ /**
584
+ * Get blogs.dir absolute path by blog ID
585
+ *
586
+ * @param integer $blog_id Blog ID
587
+ * @return string
588
+ */
589
+ function ai1wm_blog_blogsdir_abspath( $blog_id = null ) {
590
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
591
+ return ai1wm_get_uploads_dir();
592
+ }
593
+
594
+ return WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'blogs.dir' . DIRECTORY_SEPARATOR . $blog_id;
595
+ }
596
+
597
+ /**
598
+ * Get sites absolute path by blog ID
599
+ *
600
+ * @param integer $blog_id Blog ID
601
+ * @return string
602
+ */
603
+ function ai1wm_blog_sites_abspath( $blog_id = null ) {
604
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
605
+ return ai1wm_get_uploads_dir();
606
+ }
607
+
608
+ return ai1wm_get_uploads_dir() . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . $blog_id;
609
+ }
610
+
611
+ /**
612
+ * Get files relative path by blog ID
613
+ *
614
+ * @param integer $blog_id Blog ID
615
+ * @return string
616
+ */
617
+ function ai1wm_blog_files_relpath( $blog_id = null ) {
618
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
619
  return 'uploads';
620
  }
621
 
623
  }
624
 
625
  /**
626
+ * Get blogs.dir relative path by blog ID
627
  *
628
  * @param integer $blog_id Blog ID
629
  * @return string
630
  */
631
+ function ai1wm_blog_blogsdir_relpath( $blog_id = null ) {
632
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
633
  return 'uploads';
634
  }
635
 
637
  }
638
 
639
  /**
640
+ * Get sites relative path by blog ID
641
  *
642
  * @param integer $blog_id Blog ID
643
  * @return string
644
  */
645
+ function ai1wm_blog_sites_relpath( $blog_id = null ) {
646
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
647
  return 'uploads';
648
  }
649
 
656
  * @param integer $blog_id Blog ID
657
  * @return string
658
  */
659
+ function ai1wm_blog_files_url( $blog_id = null ) {
660
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
661
  return '/wp-content/uploads/';
662
  }
663
 
664
+ return sprintf( '/wp-content/blogs.dir/%d/files/', $blog_id );
665
  }
666
 
667
  /**
670
  * @param integer $blog_id Blog ID
671
  * @return string
672
  */
673
+ function ai1wm_blog_blogsdir_url( $blog_id = null ) {
674
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
675
  return '/wp-content/uploads/';
676
  }
677
 
678
+ return sprintf( '/wp-content/blogs.dir/%d/', $blog_id );
679
  }
680
 
681
  /**
684
  * @param integer $blog_id Blog ID
685
  * @return string
686
  */
687
+ function ai1wm_blog_sites_url( $blog_id = null ) {
688
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
689
  return '/wp-content/uploads/';
690
  }
691
 
692
+ return sprintf( '/wp-content/uploads/sites/%d/', $blog_id );
693
+ }
694
+
695
+ /**
696
+ * Get uploads URL by blog ID
697
+ *
698
+ * @param integer $blog_id Blog ID
699
+ * @return string
700
+ */
701
+ function ai1wm_blog_uploads_url( $blog_id = null ) {
702
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
703
+ return sprintf( '/%s/', ai1wm_get_uploads_path() );
704
+ }
705
+
706
+ return sprintf( '/%s/sites/%d/', ai1wm_get_uploads_path(), $blog_id );
707
  }
708
 
709
  /**
713
  * @return string
714
  */
715
  function ai1wm_servmask_prefix( $blog_id = null ) {
716
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
717
  return AI1WM_TABLE_PREFIX;
718
  }
719
 
730
  global $wpdb;
731
 
732
  // Set base table prefix
733
+ if ( ai1wm_is_mainsite( $blog_id ) ) {
734
  return $wpdb->base_prefix;
735
  }
736
 
1686
  function ai1wm_get_uploads_dir() {
1687
  if ( ( $upload_dir = wp_upload_dir() ) ) {
1688
  if ( isset( $upload_dir['basedir'] ) ) {
1689
+ return untrailingslashit( $upload_dir['basedir'] );
1690
+ }
1691
+ }
1692
+ }
1693
+
1694
+ /**
1695
+ * Get WordPress uploads URL
1696
+ *
1697
+ * @return string
1698
+ */
1699
+ function ai1wm_get_uploads_url() {
1700
+ if ( ( $upload_dir = wp_upload_dir() ) ) {
1701
+ if ( isset( $upload_dir['baseurl'] ) ) {
1702
+ return trailingslashit( $upload_dir['baseurl'] );
1703
+ }
1704
+ }
1705
+ }
1706
+
1707
+ /**
1708
+ * Get WordPress uploads path
1709
+ *
1710
+ * @return string
1711
+ */
1712
+ function ai1wm_get_uploads_path() {
1713
+ if ( ( $upload_dir = wp_upload_dir() ) ) {
1714
+ if ( isset( $upload_dir['basedir'] ) ) {
1715
+ return str_replace( ABSPATH, '', $upload_dir['basedir'] );
1716
  }
1717
  }
1718
  }
1737
  function ai1wm_dirname( $path ) {
1738
  return urldecode( dirname( str_replace( array( '%2F', '%5C' ), '/', urlencode( $path ) ) ) );
1739
  }
1740
+
1741
+ /**
1742
+ * Replace forward slash with current directory separator
1743
+ *
1744
+ * @param string $path Path
1745
+ * @return string
1746
+ */
1747
+ function ai1wm_replace_forward_slash_with_directory_separator( $path ) {
1748
+ return str_replace( '/', DIRECTORY_SEPARATOR, $path );
1749
+ }
1750
+
1751
+ /**
1752
+ * Replace current directory separator with forward slash
1753
+ *
1754
+ * @param string $path Path
1755
+ * @return string
1756
+ */
1757
+ function ai1wm_replace_directory_separator_with_forward_slash( $path ) {
1758
+ return str_replace( DIRECTORY_SEPARATOR, '/', $path );
1759
+ }
1760
+
1761
+ /**
1762
+ * Escape Windows directory separator
1763
+ *
1764
+ * @param string $path Path
1765
+ * @return string
1766
+ */
1767
+ function ai1wm_escape_windows_directory_separator( $path ) {
1768
+ return preg_replace( '/[\\\\]+/', '\\\\\\\\', $path );
1769
+ }
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -152,8 +152,10 @@ class Ai1wm_Main_Controller {
152
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Archive::execute', 10 );
153
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config::execute', 50 );
154
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config_File::execute', 60 );
155
- add_filter( 'ai1wm_export', 'Ai1wm_Export_Enumerate::execute', 100 );
 
156
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Content::execute', 150 );
 
157
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Database::execute', 200 );
158
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Database_File::execute', 220 );
159
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Download::execute', 250 );
152
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Archive::execute', 10 );
153
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config::execute', 50 );
154
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Config_File::execute', 60 );
155
+ add_filter( 'ai1wm_export', 'Ai1wm_Export_Enumerate_Content::execute', 100 );
156
+ add_filter( 'ai1wm_export', 'Ai1wm_Export_Enumerate_Media::execute', 110 );
157
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Content::execute', 150 );
158
+ add_filter( 'ai1wm_export', 'Ai1wm_Export_Media::execute', 160 );
159
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Database::execute', 200 );
160
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Database_File::execute', 220 );
161
  add_filter( 'ai1wm_export', 'Ai1wm_Export_Download::execute', 250 );
lib/model/class-ai1wm-extensions.php CHANGED
@@ -201,7 +201,7 @@ class Ai1wm_Extensions {
201
  'about' => AI1WMME_PLUGIN_ABOUT,
202
  'basename' => AI1WMME_PLUGIN_BASENAME,
203
  'version' => AI1WMME_VERSION,
204
- 'requires' => '3.88',
205
  'short' => AI1WMME_PLUGIN_SHORT,
206
  );
207
  }
201
  'about' => AI1WMME_PLUGIN_ABOUT,
202
  'basename' => AI1WMME_PLUGIN_BASENAME,
203
  'version' => AI1WMME_VERSION,
204
+ 'requires' => '3.91',
205
  'short' => AI1WMME_PLUGIN_SHORT,
206
  );
207
  }
lib/model/export/class-ai1wm-export-config.php CHANGED
@@ -132,7 +132,7 @@ class Ai1wm_Export_Config {
132
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
133
 
134
  // Set WordPress version and content
135
- $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR, 'Plugins' => WP_PLUGIN_DIR, 'Themes' => get_theme_root(), 'Uploads' => ai1wm_get_uploads_dir() );
136
 
137
  // Set database version
138
  $config['Database'] = array( 'Version' => $mysql->version(), 'Charset' => DB_CHARSET, 'Collate' => DB_COLLATE, 'Prefix' => $table_prefix );
@@ -152,6 +152,9 @@ class Ai1wm_Export_Config {
152
  // Set upload path
153
  $config['Uploads'] = get_option( 'upload_path' );
154
 
 
 
 
155
  // Save package.json file
156
  $handle = ai1wm_open( ai1wm_package_path( $params ), 'w' );
157
  ai1wm_write( $handle, json_encode( $config ) );
132
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
133
 
134
  // Set WordPress version and content
135
+ $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR, 'Plugins' => WP_PLUGIN_DIR, 'Themes' => get_theme_root(), 'Uploads' => ai1wm_get_uploads_dir(), 'UploadsURL' => ai1wm_get_uploads_url() );
136
 
137
  // Set database version
138
  $config['Database'] = array( 'Version' => $mysql->version(), 'Charset' => DB_CHARSET, 'Collate' => DB_COLLATE, 'Prefix' => $table_prefix );
152
  // Set upload path
153
  $config['Uploads'] = get_option( 'upload_path' );
154
 
155
+ // Set upload URL path
156
+ $config['UploadsURL'] = get_option( 'upload_url_path' );
157
+
158
  // Save package.json file
159
  $handle = ai1wm_open( ai1wm_package_path( $params ), 'w' );
160
  ai1wm_write( $handle, json_encode( $config ) );
lib/model/export/class-ai1wm-export-content.php CHANGED
@@ -45,11 +45,11 @@ class Ai1wm_Export_Content {
45
  $file_bytes_offset = 0;
46
  }
47
 
48
- // Set filemap bytes offset
49
- if ( isset( $params['filemap_bytes_offset'] ) ) {
50
- $filemap_bytes_offset = (int) $params['filemap_bytes_offset'];
51
  } else {
52
- $filemap_bytes_offset = 0;
53
  }
54
 
55
  // Get processed files size
@@ -86,10 +86,10 @@ class Ai1wm_Export_Content {
86
  $start = microtime( true );
87
 
88
  // Get map file
89
- $filemap = ai1wm_open( ai1wm_filemap_path( $params ), 'r' );
90
 
91
- // Set filemap pointer at the current index
92
- if ( fseek( $filemap, $filemap_bytes_offset ) !== -1 ) {
93
 
94
  // Open the archive file for writing
95
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
@@ -98,15 +98,15 @@ class Ai1wm_Export_Content {
98
  $archive->set_file_pointer( $archive_bytes_offset );
99
 
100
  // Loop over files
101
- while ( $path = trim( fgets( $filemap ) ) ) {
102
  $file_bytes_written = 0;
103
 
104
  // Add file to archive
105
- if ( ( $completed = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $path, $path, $file_bytes_written, $file_bytes_offset ) ) ) {
106
  $file_bytes_offset = 0;
107
 
108
- // Get filemap bytes offset
109
- $filemap_bytes_offset = ftell( $filemap );
110
  }
111
 
112
  // Increment processed files size
@@ -116,7 +116,7 @@ class Ai1wm_Export_Content {
116
  $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
117
 
118
  // Set progress
119
- Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
120
 
121
  // More than 10 seconds have passed, break and do another request
122
  if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
@@ -137,8 +137,8 @@ class Ai1wm_Export_Content {
137
  $archive->close();
138
  }
139
 
140
- // End of the filemap?
141
- if ( feof( $filemap ) ) {
142
 
143
  // Unset archive bytes offset
144
  unset( $params['archive_bytes_offset'] );
@@ -146,8 +146,8 @@ class Ai1wm_Export_Content {
146
  // Unset file bytes offset
147
  unset( $params['file_bytes_offset'] );
148
 
149
- // Unset filemap bytes offset
150
- unset( $params['filemap_bytes_offset'] );
151
 
152
  // Unset processed files size
153
  unset( $params['processed_files_size'] );
@@ -169,8 +169,8 @@ class Ai1wm_Export_Content {
169
  // Set file bytes offset
170
  $params['file_bytes_offset'] = $file_bytes_offset;
171
 
172
- // Set filemap bytes offset
173
- $params['filemap_bytes_offset'] = $filemap_bytes_offset;
174
 
175
  // Set processed files size
176
  $params['processed_files_size'] = $processed_files_size;
@@ -185,8 +185,8 @@ class Ai1wm_Export_Content {
185
  $params['completed'] = $completed;
186
  }
187
 
188
- // Close the filemap file
189
- ai1wm_close( $filemap );
190
 
191
  return $params;
192
  }
45
  $file_bytes_offset = 0;
46
  }
47
 
48
+ // Set content bytes offset
49
+ if ( isset( $params['content_bytes_offset'] ) ) {
50
+ $content_bytes_offset = (int) $params['content_bytes_offset'];
51
  } else {
52
+ $content_bytes_offset = 0;
53
  }
54
 
55
  // Get processed files size
86
  $start = microtime( true );
87
 
88
  // Get map file
89
+ $content_list = ai1wm_open( ai1wm_content_list_path( $params ), 'r' );
90
 
91
+ // Set content pointer at the current index
92
+ if ( fseek( $content_list, $content_bytes_offset ) !== -1 ) {
93
 
94
  // Open the archive file for writing
95
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
98
  $archive->set_file_pointer( $archive_bytes_offset );
99
 
100
  // Loop over files
101
+ while ( $file_path = trim( fgets( $content_list ) ) ) {
102
  $file_bytes_written = 0;
103
 
104
  // Add file to archive
105
+ if ( ( $completed = $archive->add_file( WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $file_path, $file_path, $file_bytes_written, $file_bytes_offset ) ) ) {
106
  $file_bytes_offset = 0;
107
 
108
+ // Get content bytes offset
109
+ $content_bytes_offset = ftell( $content_list );
110
  }
111
 
112
  // Increment processed files size
116
  $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
117
 
118
  // Set progress
119
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d content files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
120
 
121
  // More than 10 seconds have passed, break and do another request
122
  if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
137
  $archive->close();
138
  }
139
 
140
+ // End of the content list?
141
+ if ( feof( $content_list ) ) {
142
 
143
  // Unset archive bytes offset
144
  unset( $params['archive_bytes_offset'] );
146
  // Unset file bytes offset
147
  unset( $params['file_bytes_offset'] );
148
 
149
+ // Unset content bytes offset
150
+ unset( $params['content_bytes_offset'] );
151
 
152
  // Unset processed files size
153
  unset( $params['processed_files_size'] );
169
  // Set file bytes offset
170
  $params['file_bytes_offset'] = $file_bytes_offset;
171
 
172
+ // Set content bytes offset
173
+ $params['content_bytes_offset'] = $content_bytes_offset;
174
 
175
  // Set processed files size
176
  $params['processed_files_size'] = $processed_files_size;
185
  $params['completed'] = $completed;
186
  }
187
 
188
+ // Close the content list file
189
+ ai1wm_close( $content_list );
190
 
191
  return $params;
192
  }
lib/model/export/{class-ai1wm-export-enumerate.php → class-ai1wm-export-enumerate-content.php} RENAMED
@@ -27,10 +27,12 @@ if ( ! defined( 'ABSPATH' ) ) {
27
  die( 'Kangaroos cannot jump here' );
28
  }
29
 
30
- class Ai1wm_Export_Enumerate {
31
 
32
  public static function execute( $params ) {
33
 
 
 
34
  // Get total files count
35
  if ( isset( $params['total_files_count'] ) ) {
36
  $total_files_count = (int) $params['total_files_count'];
@@ -46,10 +48,7 @@ class Ai1wm_Export_Enumerate {
46
  }
47
 
48
  // Set progress
49
- Ai1wm_Status::info( __( 'Retrieving a list of all WordPress files...', AI1WM_PLUGIN_NAME ) );
50
-
51
- // Set exclude filters
52
- $exclude_filters = ai1wm_content_filters();
53
 
54
  // Exclude cache
55
  if ( isset( $params['options']['no_cache'] ) ) {
@@ -72,18 +71,17 @@ class Ai1wm_Export_Enumerate {
72
  }
73
  }
74
 
75
- // Set exclude filters
76
  $exclude_filters = array_merge( $exclude_filters, $inactive_themes );
77
  }
78
 
79
  // Exclude must-use plugins
80
  if ( isset( $params['options']['no_muplugins'] ) ) {
81
- $exclude_filters = array_merge( $exclude_filters, array( 'mu-plugins' ) );
82
  }
83
 
84
  // Exclude plugins
85
  if ( isset( $params['options']['no_plugins'] ) ) {
86
- $exclude_filters = array_merge( $exclude_filters, array( 'plugins' ) );
87
  } else {
88
  $inactive_plugins = array();
89
 
@@ -96,34 +94,39 @@ class Ai1wm_Export_Enumerate {
96
  }
97
  }
98
 
99
- // Set exclude filters
100
  $exclude_filters = array_merge( $exclude_filters, ai1wm_plugin_filters( $inactive_plugins ) );
101
  }
102
 
103
  // Exclude media
104
  if ( isset( $params['options']['no_media'] ) ) {
105
- $exclude_filters = array_merge( $exclude_filters, array( 'uploads', 'blogs.dir' ) );
106
  }
107
 
 
 
108
  // Exclude selected files
109
  if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
110
  $excluded_files = explode( ',', $params['excluded_files'] );
111
  if ( $excluded_files ) {
112
- $exclude_filters = array_merge( $exclude_filters, $excluded_files );
 
 
113
  }
 
 
114
  }
115
 
116
- // Create map file
117
- $filemap = ai1wm_open( ai1wm_filemap_path( $params ), 'w' );
118
 
119
  // Enumerate over content directory
120
- if ( isset( $params['options']['no_media'], $params['options']['no_themes'], $params['options']['no_muplugins'], $params['options']['no_plugins'] ) === false ) {
121
 
122
  // Iterate over content directory
123
  $iterator = new Ai1wm_Recursive_Directory_Iterator( WP_CONTENT_DIR );
124
 
125
- // Exclude uploads, plugins or themes
126
- $iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_content_from_export', $exclude_filters ) );
127
 
128
  // Recursively iterate over content directory
129
  $iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
@@ -131,7 +134,7 @@ class Ai1wm_Export_Enumerate {
131
  // Write path line
132
  foreach ( $iterator as $item ) {
133
  if ( $item->isFile() ) {
134
- if ( ai1wm_write( $filemap, $iterator->getSubPathName() . PHP_EOL ) ) {
135
  $total_files_count++;
136
 
137
  // Add current file size
@@ -142,7 +145,7 @@ class Ai1wm_Export_Enumerate {
142
  }
143
 
144
  // Set progress
145
- Ai1wm_Status::info( __( 'Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME ) );
146
 
147
  // Set total files count
148
  $params['total_files_count'] = $total_files_count;
@@ -150,8 +153,8 @@ class Ai1wm_Export_Enumerate {
150
  // Set total files size
151
  $params['total_files_size'] = $total_files_size;
152
 
153
- // Close the filemap file
154
- ai1wm_close( $filemap );
155
 
156
  return $params;
157
  }
27
  die( 'Kangaroos cannot jump here' );
28
  }
29
 
30
+ class Ai1wm_Export_Enumerate_Content {
31
 
32
  public static function execute( $params ) {
33
 
34
+ $exclude_filters = array( ai1wm_get_uploads_dir() );
35
+
36
  // Get total files count
37
  if ( isset( $params['total_files_count'] ) ) {
38
  $total_files_count = (int) $params['total_files_count'];
48
  }
49
 
50
  // Set progress
51
+ Ai1wm_Status::info( __( 'Retrieving a list of WordPress content files...', AI1WM_PLUGIN_NAME ) );
 
 
 
52
 
53
  // Exclude cache
54
  if ( isset( $params['options']['no_cache'] ) ) {
71
  }
72
  }
73
 
 
74
  $exclude_filters = array_merge( $exclude_filters, $inactive_themes );
75
  }
76
 
77
  // Exclude must-use plugins
78
  if ( isset( $params['options']['no_muplugins'] ) ) {
79
+ $exclude_filters[] = 'mu-plugins';
80
  }
81
 
82
  // Exclude plugins
83
  if ( isset( $params['options']['no_plugins'] ) ) {
84
+ $exclude_filters[] = 'plugins';
85
  } else {
86
  $inactive_plugins = array();
87
 
94
  }
95
  }
96
 
 
97
  $exclude_filters = array_merge( $exclude_filters, ai1wm_plugin_filters( $inactive_plugins ) );
98
  }
99
 
100
  // Exclude media
101
  if ( isset( $params['options']['no_media'] ) ) {
102
+ $exclude_filters[] = 'blogs.dir';
103
  }
104
 
105
+ $user_filters = array();
106
+
107
  // Exclude selected files
108
  if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
109
  $excluded_files = explode( ',', $params['excluded_files'] );
110
  if ( $excluded_files ) {
111
+ foreach ( $excluded_files as $excluded_path ) {
112
+ $user_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
113
+ }
114
  }
115
+
116
+ $exclude_filters = array_merge( $exclude_filters, $user_filters );
117
  }
118
 
119
+ // Create content list file
120
+ $content_list = ai1wm_open( ai1wm_content_list_path( $params ), 'w' );
121
 
122
  // Enumerate over content directory
123
+ if ( isset( $params['options']['no_themes'], $params['options']['no_muplugins'], $params['options']['no_plugins'] ) === false ) {
124
 
125
  // Iterate over content directory
126
  $iterator = new Ai1wm_Recursive_Directory_Iterator( WP_CONTENT_DIR );
127
 
128
+ // Exclude content files
129
+ $iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_content_from_export', ai1wm_content_filters( $exclude_filters ) ) );
130
 
131
  // Recursively iterate over content directory
132
  $iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
134
  // Write path line
135
  foreach ( $iterator as $item ) {
136
  if ( $item->isFile() ) {
137
+ if ( ai1wm_write( $content_list, $iterator->getSubPathname() . PHP_EOL ) ) {
138
  $total_files_count++;
139
 
140
  // Add current file size
145
  }
146
 
147
  // Set progress
148
+ Ai1wm_Status::info( __( 'Done retrieving a list of WordPress content files.', AI1WM_PLUGIN_NAME ) );
149
 
150
  // Set total files count
151
  $params['total_files_count'] = $total_files_count;
153
  // Set total files size
154
  $params['total_files_size'] = $total_files_size;
155
 
156
+ // Close the content list file
157
+ ai1wm_close( $content_list );
158
 
159
  return $params;
160
  }
lib/model/export/class-ai1wm-export-enumerate-media.php ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (C) 2014-2020 ServMask Inc.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
19
+ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
20
+ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
21
+ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
22
+ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
23
+ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
+ */
25
+
26
+ if ( ! defined( 'ABSPATH' ) ) {
27
+ die( 'Kangaroos cannot jump here' );
28
+ }
29
+
30
+ class Ai1wm_Export_Enumerate_Media {
31
+
32
+ public static function execute( $params ) {
33
+
34
+ $exclude_filters = $user_filters = array();
35
+
36
+ // Get total files count
37
+ if ( isset( $params['total_files_count'] ) ) {
38
+ $total_files_count = (int) $params['total_files_count'];
39
+ } else {
40
+ $total_files_count = 0;
41
+ }
42
+
43
+ // Get total files size
44
+ if ( isset( $params['total_files_size'] ) ) {
45
+ $total_files_size = (int) $params['total_files_size'];
46
+ } else {
47
+ $total_files_size = 0;
48
+ }
49
+
50
+ // Set progress
51
+ Ai1wm_Status::info( __( 'Retrieving a list of WordPress media files...', AI1WM_PLUGIN_NAME ) );
52
+
53
+ // Exclude selected files
54
+ if ( isset( $params['options']['exclude_files'], $params['excluded_files'] ) ) {
55
+ $excluded_files = explode( ',', $params['excluded_files'] );
56
+ if ( $excluded_files ) {
57
+ foreach ( $excluded_files as $excluded_path ) {
58
+ $user_filters[] = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . untrailingslashit( $excluded_path );
59
+ }
60
+ }
61
+
62
+ $exclude_filters = array_merge( $exclude_filters, $user_filters );
63
+ }
64
+
65
+ // Create media list file
66
+ $media_list = ai1wm_open( ai1wm_media_list_path( $params ), 'w' );
67
+
68
+ // Enumerate over media directory
69
+ if ( isset( $params['options']['no_media'] ) === false ) {
70
+ if ( is_dir( ai1wm_get_uploads_dir() ) ) {
71
+
72
+ // Iterate over media directory
73
+ $iterator = new Ai1wm_Recursive_Directory_Iterator( ai1wm_get_uploads_dir() );
74
+
75
+ // Exclude media files
76
+ $iterator = new Ai1wm_Recursive_Exclude_Filter( $iterator, apply_filters( 'ai1wm_exclude_media_from_export', $exclude_filters ) );
77
+
78
+ // Recursively iterate over content directory
79
+ $iterator = new Ai1wm_Recursive_Iterator_Iterator( $iterator, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD );
80
+
81
+ // Write path line
82
+ foreach ( $iterator as $item ) {
83
+ if ( $item->isFile() ) {
84
+ if ( ai1wm_write( $media_list, $iterator->getSubPathname() . PHP_EOL ) ) {
85
+ $total_files_count++;
86
+
87
+ // Add current file size
88
+ $total_files_size += $iterator->getSize();
89
+ }
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ // Set progress
96
+ Ai1wm_Status::info( __( 'Done retrieving a list of WordPress media files.', AI1WM_PLUGIN_NAME ) );
97
+
98
+ // Set total files count
99
+ $params['total_files_count'] = $total_files_count;
100
+
101
+ // Set total files size
102
+ $params['total_files_size'] = $total_files_size;
103
+
104
+ // Close the media list file
105
+ ai1wm_close( $media_list );
106
+
107
+ return $params;
108
+ }
109
+ }
lib/model/export/class-ai1wm-export-media.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Copyright (C) 2014-2020 ServMask Inc.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
19
+ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
20
+ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
21
+ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
22
+ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
23
+ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
+ */
25
+
26
+ if ( ! defined( 'ABSPATH' ) ) {
27
+ die( 'Kangaroos cannot jump here' );
28
+ }
29
+
30
+ class Ai1wm_Export_Media {
31
+
32
+ public static function execute( $params ) {
33
+
34
+ // Set archive bytes offset
35
+ if ( isset( $params['archive_bytes_offset'] ) ) {
36
+ $archive_bytes_offset = (int) $params['archive_bytes_offset'];
37
+ } else {
38
+ $archive_bytes_offset = ai1wm_archive_bytes( $params );
39
+ }
40
+
41
+ // Set file bytes offset
42
+ if ( isset( $params['file_bytes_offset'] ) ) {
43
+ $file_bytes_offset = (int) $params['file_bytes_offset'];
44
+ } else {
45
+ $file_bytes_offset = 0;
46
+ }
47
+
48
+ // Set media bytes offset
49
+ if ( isset( $params['media_bytes_offset'] ) ) {
50
+ $media_bytes_offset = (int) $params['media_bytes_offset'];
51
+ } else {
52
+ $media_bytes_offset = 0;
53
+ }
54
+
55
+ // Get processed files size
56
+ if ( isset( $params['processed_files_size'] ) ) {
57
+ $processed_files_size = (int) $params['processed_files_size'];
58
+ } else {
59
+ $processed_files_size = 0;
60
+ }
61
+
62
+ // Get total files size
63
+ if ( isset( $params['total_files_size'] ) ) {
64
+ $total_files_size = (int) $params['total_files_size'];
65
+ } else {
66
+ $total_files_size = 1;
67
+ }
68
+
69
+ // Get total files count
70
+ if ( isset( $params['total_files_count'] ) ) {
71
+ $total_files_count = (int) $params['total_files_count'];
72
+ } else {
73
+ $total_files_count = 1;
74
+ }
75
+
76
+ // What percent of files have we processed?
77
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
78
+
79
+ // Set progress
80
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
81
+
82
+ // Flag to hold if file data has been processed
83
+ $completed = true;
84
+
85
+ // Start time
86
+ $start = microtime( true );
87
+
88
+ // Get media list file
89
+ $media_list = ai1wm_open( ai1wm_media_list_path( $params ), 'r' );
90
+
91
+ // Set media pointer at the current index
92
+ if ( fseek( $media_list, $media_bytes_offset ) !== -1 ) {
93
+
94
+ // Open the archive file for writing
95
+ $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
96
+
97
+ // Set the file pointer to the one that we have saved
98
+ $archive->set_file_pointer( $archive_bytes_offset );
99
+
100
+ // Loop over files
101
+ while ( $file_path = trim( fgets( $media_list ) ) ) {
102
+ $file_bytes_written = 0;
103
+
104
+ // Add file to archive
105
+ if ( ( $completed = $archive->add_file( ai1wm_get_uploads_dir() . DIRECTORY_SEPARATOR . $file_path, 'uploads' . DIRECTORY_SEPARATOR . $file_path, $file_bytes_written, $file_bytes_offset ) ) ) {
106
+ $file_bytes_offset = 0;
107
+
108
+ // Get media bytes offset
109
+ $media_bytes_offset = ftell( $media_list );
110
+ }
111
+
112
+ // Increment processed files size
113
+ $processed_files_size += $file_bytes_written;
114
+
115
+ // What percent of files have we processed?
116
+ $progress = (int) min( ( $processed_files_size / $total_files_size ) * 100, 100 );
117
+
118
+ // Set progress
119
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d media files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
120
+
121
+ // More than 10 seconds have passed, break and do another request
122
+ if ( ( $timeout = apply_filters( 'ai1wm_completed_timeout', 10 ) ) ) {
123
+ if ( ( microtime( true ) - $start ) > $timeout ) {
124
+ $completed = false;
125
+ break;
126
+ }
127
+ }
128
+ }
129
+
130
+ // Get archive bytes offset
131
+ $archive_bytes_offset = $archive->get_file_pointer();
132
+
133
+ // Truncate the archive file
134
+ $archive->truncate();
135
+
136
+ // Close the archive file
137
+ $archive->close();
138
+ }
139
+
140
+ // End of the media list?
141
+ if ( feof( $media_list ) ) {
142
+
143
+ // Unset archive bytes offset
144
+ unset( $params['archive_bytes_offset'] );
145
+
146
+ // Unset file bytes offset
147
+ unset( $params['file_bytes_offset'] );
148
+
149
+ // Unset media bytes offset
150
+ unset( $params['media_bytes_offset'] );
151
+
152
+ // Unset processed files size
153
+ unset( $params['processed_files_size'] );
154
+
155
+ // Unset total files size
156
+ unset( $params['total_files_size'] );
157
+
158
+ // Unset total files count
159
+ unset( $params['total_files_count'] );
160
+
161
+ // Unset completed flag
162
+ unset( $params['completed'] );
163
+
164
+ } else {
165
+
166
+ // Set archive bytes offset
167
+ $params['archive_bytes_offset'] = $archive_bytes_offset;
168
+
169
+ // Set file bytes offset
170
+ $params['file_bytes_offset'] = $file_bytes_offset;
171
+
172
+ // Set media bytes offset
173
+ $params['media_bytes_offset'] = $media_bytes_offset;
174
+
175
+ // Set processed files size
176
+ $params['processed_files_size'] = $processed_files_size;
177
+
178
+ // Set total files size
179
+ $params['total_files_size'] = $total_files_size;
180
+
181
+ // Set total files count
182
+ $params['total_files_count'] = $total_files_count;
183
+
184
+ // Set completed flag
185
+ $params['completed'] = $completed;
186
+ }
187
+
188
+ // Close the media list file
189
+ ai1wm_close( $media_list );
190
+
191
+ return $params;
192
+ }
193
+ }
lib/model/import/class-ai1wm-import-blogs.php CHANGED
@@ -79,6 +79,26 @@ class Ai1wm_Import_Blogs {
79
  $subsite['Stylesheet'] = null;
80
  }
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  // Set blog items
83
  $blogs[] = array(
84
  'Old' => array(
@@ -90,6 +110,9 @@ class Ai1wm_Import_Blogs {
90
  'Plugins' => $subsite['Plugins'],
91
  'Template' => $subsite['Template'],
92
  'Stylesheet' => $subsite['Stylesheet'],
 
 
 
93
  ),
94
  'New' => array(
95
  'BlogID' => null,
@@ -100,6 +123,11 @@ class Ai1wm_Import_Blogs {
100
  'Plugins' => $subsite['Plugins'],
101
  'Template' => $subsite['Template'],
102
  'Stylesheet' => $subsite['Stylesheet'],
 
 
 
 
 
103
  ),
104
  );
105
  } else {
79
  $subsite['Stylesheet'] = null;
80
  }
81
 
82
+ // Set uploads path (backward compatibility)
83
+ if ( empty( $subsite['Uploads'] ) ) {
84
+ $subsite['Uploads'] = null;
85
+ }
86
+
87
+ // Set uploads URL path (backward compatibility)
88
+ if ( empty( $subsite['UploadsURL'] ) ) {
89
+ $subsite['UploadsURL'] = null;
90
+ }
91
+
92
+ // Set uploads path (backward compatibility)
93
+ if ( empty( $subsite['WordPress']['Uploads'] ) ) {
94
+ $subsite['WordPress']['Uploads'] = null;
95
+ }
96
+
97
+ // Set uploads URL path (backward compatibility)
98
+ if ( empty( $subsite['WordPress']['UploadsURL'] ) ) {
99
+ $subsite['WordPress']['UploadsURL'] = null;
100
+ }
101
+
102
  // Set blog items
103
  $blogs[] = array(
104
  'Old' => array(
110
  'Plugins' => $subsite['Plugins'],
111
  'Template' => $subsite['Template'],
112
  'Stylesheet' => $subsite['Stylesheet'],
113
+ 'Uploads' => $subsite['Uploads'],
114
+ 'UploadsURL' => $subsite['UploadsURL'],
115
+ 'WordPress' => $subsite['WordPress'],
116
  ),
117
  'New' => array(
118
  'BlogID' => null,
123
  'Plugins' => $subsite['Plugins'],
124
  'Template' => $subsite['Template'],
125
  'Stylesheet' => $subsite['Stylesheet'],
126
+ 'Uploads' => get_option( 'upload_path' ),
127
+ 'UploadsURL' => get_option( 'upload_url_path' ),
128
+ 'WordPress' => array(
129
+ 'UploadsURL' => ai1wm_get_uploads_url(),
130
+ ),
131
  ),
132
  );
133
  } else {
lib/model/import/class-ai1wm-import-content.php CHANGED
@@ -99,66 +99,69 @@ class Ai1wm_Import_Content {
99
 
100
  // Set extract paths
101
  foreach ( $blogs as $blog ) {
102
- if ( ai1wm_main_site( $blog['Old']['BlogID'] ) === false ) {
103
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
104
  // Old files dir style
105
- $old_paths[] = ai1wm_files_path( $blog['Old']['BlogID'] );
106
- $new_paths[] = ai1wm_files_path( $blog['New']['BlogID'] );
107
 
108
  // Old blogs.dir style
109
- $old_paths[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
110
- $new_paths[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
111
 
112
  // New sites dir style
113
- $old_paths[] = ai1wm_sites_path( $blog['Old']['BlogID'] );
114
- $new_paths[] = ai1wm_files_path( $blog['New']['BlogID'] );
115
  } else {
116
  // Old files dir style
117
- $old_paths[] = ai1wm_files_path( $blog['Old']['BlogID'] );
118
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
119
 
120
  // Old blogs.dir style
121
- $old_paths[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
122
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
123
 
124
  // New sites dir style
125
- $old_paths[] = ai1wm_sites_path( $blog['Old']['BlogID'] );
126
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
127
  }
128
  }
129
  }
130
 
131
  // Set base site extract paths (should be added at the end of arrays)
132
  foreach ( $blogs as $blog ) {
133
- if ( ai1wm_main_site( $blog['Old']['BlogID'] ) === true ) {
134
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
135
  // Old files dir style
136
- $old_paths[] = ai1wm_files_path( $blog['Old']['BlogID'] );
137
- $new_paths[] = ai1wm_files_path( $blog['New']['BlogID'] );
138
 
139
  // Old blogs.dir style
140
- $old_paths[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
141
- $new_paths[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
142
 
143
  // New sites dir style
144
- $old_paths[] = ai1wm_sites_path( $blog['Old']['BlogID'] );
145
- $new_paths[] = ai1wm_files_path( $blog['New']['BlogID'] );
146
  } else {
147
  // Old files dir style
148
- $old_paths[] = ai1wm_files_path( $blog['Old']['BlogID'] );
149
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
150
 
151
  // Old blogs.dir style
152
- $old_paths[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
153
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
154
 
155
  // New sites dir style
156
- $old_paths[] = ai1wm_sites_path( $blog['Old']['BlogID'] );
157
- $new_paths[] = ai1wm_sites_path( $blog['New']['BlogID'] );
158
  }
159
  }
160
  }
161
 
 
 
 
162
  while ( $archive->has_not_reached_eof() ) {
163
  $file_bytes_written = 0;
164
 
99
 
100
  // Set extract paths
101
  foreach ( $blogs as $blog ) {
102
+ if ( ai1wm_is_mainsite( $blog['Old']['BlogID'] ) === false ) {
103
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
104
  // Old files dir style
105
+ $old_paths[] = ai1wm_blog_files_relpath( $blog['Old']['BlogID'] );
106
+ $new_paths[] = ai1wm_blog_files_abspath( $blog['New']['BlogID'] );
107
 
108
  // Old blogs.dir style
109
+ $old_paths[] = ai1wm_blog_blogsdir_relpath( $blog['Old']['BlogID'] );
110
+ $new_paths[] = ai1wm_blog_blogsdir_abspath( $blog['New']['BlogID'] );
111
 
112
  // New sites dir style
113
+ $old_paths[] = ai1wm_blog_sites_relpath( $blog['Old']['BlogID'] );
114
+ $new_paths[] = ai1wm_blog_files_abspath( $blog['New']['BlogID'] );
115
  } else {
116
  // Old files dir style
117
+ $old_paths[] = ai1wm_blog_files_relpath( $blog['Old']['BlogID'] );
118
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
119
 
120
  // Old blogs.dir style
121
+ $old_paths[] = ai1wm_blog_blogsdir_relpath( $blog['Old']['BlogID'] );
122
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
123
 
124
  // New sites dir style
125
+ $old_paths[] = ai1wm_blog_sites_relpath( $blog['Old']['BlogID'] );
126
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
127
  }
128
  }
129
  }
130
 
131
  // Set base site extract paths (should be added at the end of arrays)
132
  foreach ( $blogs as $blog ) {
133
+ if ( ai1wm_is_mainsite( $blog['Old']['BlogID'] ) === true ) {
134
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
135
  // Old files dir style
136
+ $old_paths[] = ai1wm_blog_files_relpath( $blog['Old']['BlogID'] );
137
+ $new_paths[] = ai1wm_blog_files_abspath( $blog['New']['BlogID'] );
138
 
139
  // Old blogs.dir style
140
+ $old_paths[] = ai1wm_blog_blogsdir_relpath( $blog['Old']['BlogID'] );
141
+ $new_paths[] = ai1wm_blog_blogsdir_abspath( $blog['New']['BlogID'] );
142
 
143
  // New sites dir style
144
+ $old_paths[] = ai1wm_blog_sites_relpath( $blog['Old']['BlogID'] );
145
+ $new_paths[] = ai1wm_blog_files_abspath( $blog['New']['BlogID'] );
146
  } else {
147
  // Old files dir style
148
+ $old_paths[] = ai1wm_blog_files_relpath( $blog['Old']['BlogID'] );
149
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
150
 
151
  // Old blogs.dir style
152
+ $old_paths[] = ai1wm_blog_blogsdir_relpath( $blog['Old']['BlogID'] );
153
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
154
 
155
  // New sites dir style
156
+ $old_paths[] = ai1wm_blog_sites_relpath( $blog['Old']['BlogID'] );
157
+ $new_paths[] = ai1wm_blog_sites_abspath( $blog['New']['BlogID'] );
158
  }
159
  }
160
  }
161
 
162
+ $old_paths[] = ai1wm_blog_sites_relpath();
163
+ $new_paths[] = ai1wm_blog_sites_abspath();
164
+
165
  while ( $archive->has_not_reached_eof() ) {
166
  $file_bytes_written = 0;
167
 
lib/model/import/class-ai1wm-import-database.php CHANGED
@@ -83,116 +83,104 @@ class Ai1wm_Import_Database {
83
  // Get Blog URLs
84
  foreach ( $blogs as $blog ) {
85
 
86
- // Get files dir Upload Path
87
- if ( ! in_array( sprintf( "'%s'", trim( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' ) ), $old_replace_raw_values ) ) {
88
- $old_replace_raw_values[] = sprintf( "'%s'", trim( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' ) );
89
- $new_replace_raw_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
90
- }
91
-
92
- // Get sites dir Upload Path
93
- if ( ! in_array( sprintf( "'%s'", trim( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' ) ), $old_replace_raw_values ) ) {
94
- $old_replace_raw_values[] = sprintf( "'%s'", trim( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' ) );
95
- $new_replace_raw_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
96
- }
97
-
98
  // Handle old and new sites dir style
99
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
100
 
101
- // Get plain Upload Path
102
- if ( ! in_array( ai1wm_files_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
103
- $old_replace_values[] = ai1wm_files_url( $blog['Old']['BlogID'] );
104
- $new_replace_values[] = ai1wm_files_url( $blog['New']['BlogID'] );
105
  }
106
 
107
- // Get URL encoded Upload Path
108
- if ( ! in_array( urlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
109
- $old_replace_values[] = urlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) );
110
- $new_replace_values[] = urlencode( ai1wm_files_url( $blog['New']['BlogID'] ) );
111
  }
112
 
113
- // Get URL raw encoded Upload Path
114
- if ( ! in_array( rawurlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
115
- $old_replace_values[] = rawurlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) );
116
- $new_replace_values[] = rawurlencode( ai1wm_files_url( $blog['New']['BlogID'] ) );
117
  }
118
 
119
- // Get JSON escaped Upload Path
120
- if ( ! in_array( addcslashes( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
121
- $old_replace_values[] = addcslashes( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' );
122
- $new_replace_values[] = addcslashes( ai1wm_files_url( $blog['New']['BlogID'] ), '/' );
123
  }
124
 
125
- // Get plain Upload Path
126
- if ( ! in_array( ai1wm_sites_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
127
- $old_replace_values[] = ai1wm_sites_url( $blog['Old']['BlogID'] );
128
- $new_replace_values[] = ai1wm_files_url( $blog['New']['BlogID'] );
129
  }
130
 
131
- // Get URL encoded Upload Path
132
- if ( ! in_array( urlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
133
- $old_replace_values[] = urlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) );
134
- $new_replace_values[] = urlencode( ai1wm_files_url( $blog['New']['BlogID'] ) );
135
  }
136
 
137
- // Get URL raw encoded Upload Path
138
- if ( ! in_array( rawurlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
139
- $old_replace_values[] = rawurlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) );
140
- $new_replace_values[] = rawurlencode( ai1wm_files_url( $blog['New']['BlogID'] ) );
141
  }
142
 
143
- // Get JSON escaped Upload Path
144
- if ( ! in_array( addcslashes( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
145
- $old_replace_values[] = addcslashes( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' );
146
- $new_replace_values[] = addcslashes( ai1wm_files_url( $blog['New']['BlogID'] ), '/' );
147
  }
148
  } else {
149
 
150
- // Get plain Upload Path
151
- if ( ! in_array( ai1wm_files_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
152
- $old_replace_values[] = ai1wm_files_url( $blog['Old']['BlogID'] );
153
- $new_replace_values[] = ai1wm_sites_url( $blog['New']['BlogID'] );
154
  }
155
 
156
- // Get URL encoded Upload Path
157
- if ( ! in_array( urlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
158
- $old_replace_values[] = urlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) );
159
- $new_replace_values[] = urlencode( ai1wm_sites_url( $blog['New']['BlogID'] ) );
160
  }
161
 
162
- // Get URL raw encoded Upload Path
163
- if ( ! in_array( rawurlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
164
- $old_replace_values[] = rawurlencode( ai1wm_files_url( $blog['Old']['BlogID'] ) );
165
- $new_replace_values[] = rawurlencode( ai1wm_sites_url( $blog['New']['BlogID'] ) );
166
  }
167
 
168
- // Get JSON escaped Upload Path
169
- if ( ! in_array( addcslashes( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
170
- $old_replace_values[] = addcslashes( ai1wm_files_url( $blog['Old']['BlogID'] ), '/' );
171
- $new_replace_values[] = addcslashes( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' );
172
  }
173
 
174
- // Get plain Upload Path
175
- if ( ! in_array( ai1wm_sites_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
176
- $old_replace_values[] = ai1wm_sites_url( $blog['Old']['BlogID'] );
177
- $new_replace_values[] = ai1wm_sites_url( $blog['New']['BlogID'] );
178
  }
179
 
180
- // Get URL encoded Upload Path
181
- if ( ! in_array( urlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
182
- $old_replace_values[] = urlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) );
183
- $new_replace_values[] = urlencode( ai1wm_sites_url( $blog['New']['BlogID'] ) );
184
  }
185
 
186
- // Get URL raw encoded Upload Path
187
- if ( ! in_array( rawurlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
188
- $old_replace_values[] = rawurlencode( ai1wm_sites_url( $blog['Old']['BlogID'] ) );
189
- $new_replace_values[] = rawurlencode( ai1wm_sites_url( $blog['New']['BlogID'] ) );
190
  }
191
 
192
- // Get JSON escaped Upload Path
193
- if ( ! in_array( addcslashes( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
194
- $old_replace_values[] = addcslashes( ai1wm_sites_url( $blog['Old']['BlogID'] ), '/' );
195
- $new_replace_values[] = addcslashes( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' );
196
  }
197
  }
198
 
@@ -262,28 +250,28 @@ class Ai1wm_Import_Database {
262
  // Handle old and new sites dir style
263
  if ( ! defined( 'UPLOADBLOGSDIR' ) ) {
264
 
265
- // Add plain Upload URL
266
  if ( ! in_array( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), $old_replace_values ) ) {
267
  $old_replace_values[] = ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] );
268
- $new_replace_values[] = ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['SiteURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] );
269
  }
270
 
271
- // Add URL encoded Upload URL
272
  if ( ! in_array( urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
273
  $old_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
274
- $new_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['SiteURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ) );
275
  }
276
 
277
- // Add URL raw encoded Upload URL
278
  if ( ! in_array( rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
279
  $old_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
280
- $new_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['SiteURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ) );
281
  }
282
 
283
- // Add JSON escaped Upload URL
284
  if ( ! in_array( addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
285
  $old_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' );
286
- $new_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['SiteURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ), '/' );
287
  }
288
  }
289
 
@@ -388,28 +376,28 @@ class Ai1wm_Import_Database {
388
  // Handle old and new sites dir style
389
  if ( ! defined( 'UPLOADBLOGSDIR' ) ) {
390
 
391
- // Add plain Upload URL
392
  if ( ! in_array( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), $old_replace_values ) ) {
393
  $old_replace_values[] = ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] );
394
- $new_replace_values[] = ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['HomeURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] );
395
  }
396
 
397
- // Add URL encoded Upload URL
398
  if ( ! in_array( urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
399
  $old_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
400
- $new_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['HomeURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ) );
401
  }
402
 
403
- // Add URL raw encoded Upload URL
404
  if ( ! in_array( rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
405
  $old_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
406
- $new_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['HomeURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ) );
407
  }
408
 
409
- // Add JSON escaped Upload URL
410
  if ( ! in_array( addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
411
  $old_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' );
412
- $new_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/%s/', untrailingslashit( $blog['New']['HomeURL'] ), trim( ai1wm_sites_url( $blog['New']['BlogID'] ), '/' ) ), $new_schemes[ $i ] ), '/' );
413
  }
414
  }
415
 
@@ -447,6 +435,107 @@ class Ai1wm_Import_Database {
447
  }
448
  }
449
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  }
451
 
452
  $site_urls = array();
@@ -645,6 +734,83 @@ class Ai1wm_Import_Database {
645
  }
646
  }
647
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
648
  // Get WordPress Content Dir
649
  if ( isset( $config['WordPress']['Content'] ) && ( $content_dir = $config['WordPress']['Content'] ) ) {
650
 
@@ -720,6 +886,12 @@ class Ai1wm_Import_Database {
720
  // Get HTTP password
721
  $auth_password = get_option( AI1WM_AUTH_PASSWORD );
722
 
 
 
 
 
 
 
723
  // Get backups labels
724
  $backups_labels = get_option( AI1WM_BACKUPS_LABELS, array() );
725
 
@@ -731,7 +903,7 @@ class Ai1wm_Import_Database {
731
 
732
  // Set site table prefixes
733
  foreach ( $blogs as $blog ) {
734
- if ( ai1wm_main_site( $blog['Old']['BlogID'] ) === false ) {
735
  $old_table_prefixes[] = ai1wm_servmask_prefix( $blog['Old']['BlogID'] );
736
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
737
  }
@@ -745,7 +917,7 @@ class Ai1wm_Import_Database {
745
 
746
  // Set base table prefixes
747
  foreach ( $blogs as $blog ) {
748
- if ( ai1wm_main_site( $blog['Old']['BlogID'] ) === true ) {
749
  $old_table_prefixes[] = ai1wm_servmask_prefix( 'basesite' );
750
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
751
  }
@@ -753,7 +925,7 @@ class Ai1wm_Import_Database {
753
 
754
  // Set main table prefixes
755
  foreach ( $blogs as $blog ) {
756
- if ( ai1wm_main_site( $blog['Old']['BlogID'] ) === true ) {
757
  $old_table_prefixes[] = ai1wm_servmask_prefix( $blog['Old']['BlogID'] );
758
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
759
  }
@@ -847,6 +1019,12 @@ class Ai1wm_Import_Database {
847
  // Set the new HTTP password
848
  update_option( AI1WM_AUTH_PASSWORD, $auth_password );
849
 
 
 
 
 
 
 
850
  // Set the new backups labels
851
  update_option( AI1WM_BACKUPS_LABELS, $backups_labels );
852
 
83
  // Get Blog URLs
84
  foreach ( $blogs as $blog ) {
85
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  // Handle old and new sites dir style
87
  if ( defined( 'UPLOADBLOGSDIR' ) ) {
88
 
89
+ // Get plain Files Path
90
+ if ( ! in_array( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
91
+ $old_replace_values[] = ai1wm_blog_files_url( $blog['Old']['BlogID'] );
92
+ $new_replace_values[] = ai1wm_blog_files_url( $blog['New']['BlogID'] );
93
  }
94
 
95
+ // Get URL encoded Files Path
96
+ if ( ! in_array( urlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
97
+ $old_replace_values[] = urlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) );
98
+ $new_replace_values[] = urlencode( ai1wm_blog_files_url( $blog['New']['BlogID'] ) );
99
  }
100
 
101
+ // Get URL raw encoded Files Path
102
+ if ( ! in_array( rawurlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
103
+ $old_replace_values[] = rawurlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) );
104
+ $new_replace_values[] = rawurlencode( ai1wm_blog_files_url( $blog['New']['BlogID'] ) );
105
  }
106
 
107
+ // Get JSON escaped Files Path
108
+ if ( ! in_array( addcslashes( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
109
+ $old_replace_values[] = addcslashes( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), '/' );
110
+ $new_replace_values[] = addcslashes( ai1wm_blog_files_url( $blog['New']['BlogID'] ), '/' );
111
  }
112
 
113
+ // Get plain Sites Path
114
+ if ( ! in_array( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
115
+ $old_replace_values[] = ai1wm_blog_sites_url( $blog['Old']['BlogID'] );
116
+ $new_replace_values[] = ai1wm_blog_files_url( $blog['New']['BlogID'] );
117
  }
118
 
119
+ // Get URL encoded Sites Path
120
+ if ( ! in_array( urlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
121
+ $old_replace_values[] = urlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) );
122
+ $new_replace_values[] = urlencode( ai1wm_blog_files_url( $blog['New']['BlogID'] ) );
123
  }
124
 
125
+ // Get URL raw encoded Sites Path
126
+ if ( ! in_array( rawurlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
127
+ $old_replace_values[] = rawurlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) );
128
+ $new_replace_values[] = rawurlencode( ai1wm_blog_files_url( $blog['New']['BlogID'] ) );
129
  }
130
 
131
+ // Get JSON escaped Sites Path
132
+ if ( ! in_array( addcslashes( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
133
+ $old_replace_values[] = addcslashes( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), '/' );
134
+ $new_replace_values[] = addcslashes( ai1wm_blog_files_url( $blog['New']['BlogID'] ), '/' );
135
  }
136
  } else {
137
 
138
+ // Get plain Files Path
139
+ if ( ! in_array( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
140
+ $old_replace_values[] = ai1wm_blog_files_url( $blog['Old']['BlogID'] );
141
+ $new_replace_values[] = ai1wm_blog_uploads_url( $blog['New']['BlogID'] );
142
  }
143
 
144
+ // Get URL encoded Files Path
145
+ if ( ! in_array( urlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
146
+ $old_replace_values[] = urlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) );
147
+ $new_replace_values[] = urlencode( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ) );
148
  }
149
 
150
+ // Get URL raw encoded Files Path
151
+ if ( ! in_array( rawurlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
152
+ $old_replace_values[] = rawurlencode( ai1wm_blog_files_url( $blog['Old']['BlogID'] ) );
153
+ $new_replace_values[] = rawurlencode( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ) );
154
  }
155
 
156
+ // Get JSON escaped Files Path
157
+ if ( ! in_array( addcslashes( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
158
+ $old_replace_values[] = addcslashes( ai1wm_blog_files_url( $blog['Old']['BlogID'] ), '/' );
159
+ $new_replace_values[] = addcslashes( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ), '/' );
160
  }
161
 
162
+ // Get plain Sites Path
163
+ if ( ! in_array( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), $old_replace_values ) ) {
164
+ $old_replace_values[] = ai1wm_blog_sites_url( $blog['Old']['BlogID'] );
165
+ $new_replace_values[] = ai1wm_blog_uploads_url( $blog['New']['BlogID'] );
166
  }
167
 
168
+ // Get URL encoded Sites Path
169
+ if ( ! in_array( urlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
170
+ $old_replace_values[] = urlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) );
171
+ $new_replace_values[] = urlencode( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ) );
172
  }
173
 
174
+ // Get URL raw encoded Sites Path
175
+ if ( ! in_array( rawurlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) ), $old_replace_values ) ) {
176
+ $old_replace_values[] = rawurlencode( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ) );
177
+ $new_replace_values[] = rawurlencode( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ) );
178
  }
179
 
180
+ // Get JSON escaped Sites Path
181
+ if ( ! in_array( addcslashes( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), '/' ), $old_replace_values ) ) {
182
+ $old_replace_values[] = addcslashes( ai1wm_blog_sites_url( $blog['Old']['BlogID'] ), '/' );
183
+ $new_replace_values[] = addcslashes( ai1wm_blog_uploads_url( $blog['New']['BlogID'] ), '/' );
184
  }
185
  }
186
 
250
  // Handle old and new sites dir style
251
  if ( ! defined( 'UPLOADBLOGSDIR' ) ) {
252
 
253
+ // Add plain Uploads URL
254
  if ( ! in_array( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), $old_replace_values ) ) {
255
  $old_replace_values[] = ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] );
256
+ $new_replace_values[] = ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] );
257
  }
258
 
259
+ // Add URL encoded Uploads URL
260
  if ( ! in_array( urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
261
  $old_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
262
+ $new_replace_values[] = urlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
263
  }
264
 
265
+ // Add URL raw encoded Uploads URL
266
  if ( ! in_array( rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
267
  $old_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
268
+ $new_replace_values[] = rawurlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
269
  }
270
 
271
+ // Add JSON escaped Uploads URL
272
  if ( ! in_array( addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
273
  $old_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' );
274
+ $new_replace_values[] = addcslashes( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ), '/' );
275
  }
276
  }
277
 
376
  // Handle old and new sites dir style
377
  if ( ! defined( 'UPLOADBLOGSDIR' ) ) {
378
 
379
+ // Add plain Uploads URL
380
  if ( ! in_array( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), $old_replace_values ) ) {
381
  $old_replace_values[] = ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] );
382
+ $new_replace_values[] = ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] );
383
  }
384
 
385
+ // Add URL encoded Uploads URL
386
  if ( ! in_array( urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
387
  $old_replace_values[] = urlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
388
+ $new_replace_values[] = urlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
389
  }
390
 
391
+ // Add URL raw encoded Uploads URL
392
  if ( ! in_array( rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) ), $old_replace_values ) ) {
393
  $old_replace_values[] = rawurlencode( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ) );
394
+ $new_replace_values[] = rawurlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
395
  }
396
 
397
+ // Add JSON escaped Uploads URL
398
  if ( ! in_array( addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
399
  $old_replace_values[] = addcslashes( ai1wm_url_scheme( sprintf( '%s/files/', untrailingslashit( $url ) ), $old_schemes[ $i ] ), '/' );
400
+ $new_replace_values[] = addcslashes( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ), '/' );
401
  }
402
  }
403
 
435
  }
436
  }
437
  }
438
+
439
+ $uploads_urls = array();
440
+
441
+ // Add Uploads URL
442
+ if ( ! empty( $blog['Old']['WordPress']['UploadsURL'] ) ) {
443
+ $uploads_urls[] = $blog['Old']['WordPress']['UploadsURL'];
444
+ }
445
+
446
+ // Get Uploads URL
447
+ foreach ( $uploads_urls as $uploads_url ) {
448
+
449
+ // Get www URL
450
+ if ( stripos( $uploads_url, '//www.' ) !== false ) {
451
+ $uploads_url_www_inversion = str_ireplace( '//www.', '//', $uploads_url );
452
+ } else {
453
+ $uploads_url_www_inversion = str_ireplace( '//', '//www.', $uploads_url );
454
+ }
455
+
456
+ // Replace Uploads URL
457
+ foreach ( array( $uploads_url, $uploads_url_www_inversion ) as $url ) {
458
+
459
+ // Get domain
460
+ $old_domain = parse_url( $url, PHP_URL_HOST );
461
+ $new_domain = parse_url( $blog['New']['WordPress']['UploadsURL'], PHP_URL_HOST );
462
+
463
+ // Get path
464
+ $old_path = parse_url( $url, PHP_URL_PATH );
465
+ $new_path = parse_url( $blog['New']['WordPress']['UploadsURL'], PHP_URL_PATH );
466
+
467
+ // Get scheme
468
+ $new_scheme = parse_url( $blog['New']['WordPress']['UploadsURL'], PHP_URL_SCHEME );
469
+
470
+ // Add domain and path with single quote
471
+ if ( ! in_array( sprintf( "='%s%s", $old_domain, untrailingslashit( $old_path ) ), $old_replace_values ) ) {
472
+ $old_replace_values[] = sprintf( "='%s%s", $old_domain, untrailingslashit( $old_path ) );
473
+ $new_replace_values[] = sprintf( "='%s%s", $new_domain, untrailingslashit( $new_path ) );
474
+ }
475
+
476
+ // Add domain and path with double quote
477
+ if ( ! in_array( sprintf( '="%s%s', $old_domain, untrailingslashit( $old_path ) ), $old_replace_values ) ) {
478
+ $old_replace_values[] = sprintf( '="%s%s', $old_domain, untrailingslashit( $old_path ) );
479
+ $new_replace_values[] = sprintf( '="%s%s', $new_domain, untrailingslashit( $new_path ) );
480
+ }
481
+
482
+ // Set Uploads URL scheme
483
+ $old_schemes = array( 'http', 'https', '' );
484
+ $new_schemes = array( $new_scheme, $new_scheme, '' );
485
+
486
+ // Replace Uploads URL scheme
487
+ for ( $i = 0; $i < count( $old_schemes ); $i++ ) {
488
+
489
+ // Add plain Uploads URL
490
+ if ( ! in_array( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), $old_replace_values ) ) {
491
+ $old_replace_values[] = ai1wm_url_scheme( $url, $old_schemes[ $i ] );
492
+ $new_replace_values[] = ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] );
493
+ }
494
+
495
+ // Add URL encoded Uploads URL
496
+ if ( ! in_array( urlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) ), $old_replace_values ) ) {
497
+ $old_replace_values[] = urlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) );
498
+ $new_replace_values[] = urlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
499
+ }
500
+
501
+ // Add URL raw encoded Uploads URL
502
+ if ( ! in_array( rawurlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) ), $old_replace_values ) ) {
503
+ $old_replace_values[] = rawurlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) );
504
+ $new_replace_values[] = rawurlencode( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ) );
505
+ }
506
+
507
+ // Add JSON escaped Uploads URL
508
+ if ( ! in_array( addcslashes( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
509
+ $old_replace_values[] = addcslashes( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), '/' );
510
+ $new_replace_values[] = addcslashes( ai1wm_url_scheme( $blog['New']['WordPress']['UploadsURL'], $new_schemes[ $i ] ), '/' );
511
+ }
512
+ }
513
+ }
514
+ }
515
+ }
516
+
517
+ // Get plain Sites Path
518
+ if ( ! in_array( ai1wm_blog_sites_url(), $old_replace_values ) ) {
519
+ $old_replace_values[] = ai1wm_blog_sites_url();
520
+ $new_replace_values[] = ai1wm_blog_uploads_url();
521
+ }
522
+
523
+ // Get URL encoded Sites Path
524
+ if ( ! in_array( urlencode( ai1wm_blog_sites_url() ), $old_replace_values ) ) {
525
+ $old_replace_values[] = urlencode( ai1wm_blog_sites_url() );
526
+ $new_replace_values[] = urlencode( ai1wm_blog_uploads_url() );
527
+ }
528
+
529
+ // Get URL raw encoded Sites Path
530
+ if ( ! in_array( rawurlencode( ai1wm_blog_sites_url() ), $old_replace_values ) ) {
531
+ $old_replace_values[] = rawurlencode( ai1wm_blog_sites_url() );
532
+ $new_replace_values[] = rawurlencode( ai1wm_blog_uploads_url() );
533
+ }
534
+
535
+ // Get JSON escaped Sites Path
536
+ if ( ! in_array( addcslashes( ai1wm_blog_sites_url(), '/' ), $old_replace_values ) ) {
537
+ $old_replace_values[] = addcslashes( ai1wm_blog_sites_url(), '/' );
538
+ $new_replace_values[] = addcslashes( ai1wm_blog_uploads_url(), '/' );
539
  }
540
 
541
  $site_urls = array();
734
  }
735
  }
736
 
737
+ $uploads_urls = array();
738
+
739
+ // Add Uploads URL
740
+ if ( ! empty( $config['WordPress']['UploadsURL'] ) ) {
741
+ $uploads_urls[] = $config['WordPress']['UploadsURL'];
742
+ }
743
+
744
+ // Get Uploads URL
745
+ foreach ( $uploads_urls as $uploads_url ) {
746
+
747
+ // Get www URL
748
+ if ( stripos( $uploads_url, '//www.' ) !== false ) {
749
+ $uploads_url_www_inversion = str_ireplace( '//www.', '//', $uploads_url );
750
+ } else {
751
+ $uploads_url_www_inversion = str_ireplace( '//', '//www.', $uploads_url );
752
+ }
753
+
754
+ // Replace Uploads URL
755
+ foreach ( array( $uploads_url, $uploads_url_www_inversion ) as $url ) {
756
+
757
+ // Get domain
758
+ $old_domain = parse_url( $url, PHP_URL_HOST );
759
+ $new_domain = parse_url( ai1wm_get_uploads_url(), PHP_URL_HOST );
760
+
761
+ // Get path
762
+ $old_path = parse_url( $url, PHP_URL_PATH );
763
+ $new_path = parse_url( ai1wm_get_uploads_url(), PHP_URL_PATH );
764
+
765
+ // Get scheme
766
+ $new_scheme = parse_url( ai1wm_get_uploads_url(), PHP_URL_SCHEME );
767
+
768
+ // Add domain and path with single quote
769
+ if ( ! in_array( sprintf( "='%s%s", $old_domain, untrailingslashit( $old_path ) ), $old_replace_values ) ) {
770
+ $old_replace_values[] = sprintf( "='%s%s", $old_domain, untrailingslashit( $old_path ) );
771
+ $new_replace_values[] = sprintf( "='%s%s", $new_domain, untrailingslashit( $new_path ) );
772
+ }
773
+
774
+ // Add domain and path with double quote
775
+ if ( ! in_array( sprintf( '="%s%s', $old_domain, untrailingslashit( $old_path ) ), $old_replace_values ) ) {
776
+ $old_replace_values[] = sprintf( '="%s%s', $old_domain, untrailingslashit( $old_path ) );
777
+ $new_replace_values[] = sprintf( '="%s%s', $new_domain, untrailingslashit( $new_path ) );
778
+ }
779
+
780
+ // Add Uploads URL scheme
781
+ $old_schemes = array( 'http', 'https', '' );
782
+ $new_schemes = array( $new_scheme, $new_scheme, '' );
783
+
784
+ // Replace Uploads URL scheme
785
+ for ( $i = 0; $i < count( $old_schemes ); $i++ ) {
786
+
787
+ // Add plain Uploads URL
788
+ if ( ! in_array( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), $old_replace_values ) ) {
789
+ $old_replace_values[] = ai1wm_url_scheme( $url, $old_schemes[ $i ] );
790
+ $new_replace_values[] = ai1wm_url_scheme( ai1wm_get_uploads_url(), $new_schemes[ $i ] );
791
+ }
792
+
793
+ // Add URL encoded Uploads URL
794
+ if ( ! in_array( urlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) ), $old_replace_values ) ) {
795
+ $old_replace_values[] = urlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) );
796
+ $new_replace_values[] = urlencode( ai1wm_url_scheme( ai1wm_get_uploads_url(), $new_schemes[ $i ] ) );
797
+ }
798
+
799
+ // Add URL raw encoded Uploads URL
800
+ if ( ! in_array( rawurlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) ), $old_replace_values ) ) {
801
+ $old_replace_values[] = rawurlencode( ai1wm_url_scheme( $url, $old_schemes[ $i ] ) );
802
+ $new_replace_values[] = rawurlencode( ai1wm_url_scheme( ai1wm_get_uploads_url(), $new_schemes[ $i ] ) );
803
+ }
804
+
805
+ // Add JSON escaped Uploads URL
806
+ if ( ! in_array( addcslashes( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), '/' ), $old_replace_values ) ) {
807
+ $old_replace_values[] = addcslashes( ai1wm_url_scheme( $url, $old_schemes[ $i ] ), '/' );
808
+ $new_replace_values[] = addcslashes( ai1wm_url_scheme( ai1wm_get_uploads_url(), $new_schemes[ $i ] ), '/' );
809
+ }
810
+ }
811
+ }
812
+ }
813
+
814
  // Get WordPress Content Dir
815
  if ( isset( $config['WordPress']['Content'] ) && ( $content_dir = $config['WordPress']['Content'] ) ) {
816
 
886
  // Get HTTP password
887
  $auth_password = get_option( AI1WM_AUTH_PASSWORD );
888
 
889
+ // Get Uploads Path
890
+ $uploads_path = get_option( AI1WM_UPLOADS_PATH );
891
+
892
+ // Get Uploads URL Path
893
+ $uploads_url_path = get_option( AI1WM_UPLOADS_URL_PATH );
894
+
895
  // Get backups labels
896
  $backups_labels = get_option( AI1WM_BACKUPS_LABELS, array() );
897
 
903
 
904
  // Set site table prefixes
905
  foreach ( $blogs as $blog ) {
906
+ if ( ai1wm_is_mainsite( $blog['Old']['BlogID'] ) === false ) {
907
  $old_table_prefixes[] = ai1wm_servmask_prefix( $blog['Old']['BlogID'] );
908
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
909
  }
917
 
918
  // Set base table prefixes
919
  foreach ( $blogs as $blog ) {
920
+ if ( ai1wm_is_mainsite( $blog['Old']['BlogID'] ) === true ) {
921
  $old_table_prefixes[] = ai1wm_servmask_prefix( 'basesite' );
922
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
923
  }
925
 
926
  // Set main table prefixes
927
  foreach ( $blogs as $blog ) {
928
+ if ( ai1wm_is_mainsite( $blog['Old']['BlogID'] ) === true ) {
929
  $old_table_prefixes[] = ai1wm_servmask_prefix( $blog['Old']['BlogID'] );
930
  $new_table_prefixes[] = ai1wm_table_prefix( $blog['New']['BlogID'] );
931
  }
1019
  // Set the new HTTP password
1020
  update_option( AI1WM_AUTH_PASSWORD, $auth_password );
1021
 
1022
+ // Set the new Uploads Path
1023
+ update_option( AI1WM_UPLOADS_PATH, $uploads_path );
1024
+
1025
+ // Set the new Uploads URL Path
1026
+ update_option( AI1WM_UPLOADS_URL_PATH, $uploads_url_path );
1027
+
1028
  // Set the new backups labels
1029
  update_option( AI1WM_BACKUPS_LABELS, $backups_labels );
1030
 
lib/vendor/servmask/archiver/class-ai1wm-compressor.php CHANGED
@@ -35,7 +35,6 @@ class Ai1wm_Compressor extends Ai1wm_Archiver {
35
  * @param string $file_name File to use as archive
36
  */
37
  public function __construct( $file_name ) {
38
- // Call parent, to initialize variables
39
  parent::__construct( $file_name, true );
40
  }
41
 
@@ -57,10 +56,10 @@ class Ai1wm_Compressor extends Ai1wm_Archiver {
57
  $file_written = 0;
58
 
59
  // Replace forward slash with current directory separator in file name
60
- $file_name = $this->replace_forward_slash_with_directory_separator( $file_name );
61
 
62
  // Escape Windows directory separator in file name
63
- $file_name = $this->escape_windows_directory_separator( $file_name );
64
 
65
  // Flag to hold if file data has been processed
66
  $completed = true;
@@ -185,9 +184,9 @@ class Ai1wm_Compressor extends Ai1wm_Archiver {
185
 
186
  // Replace current directory separator with backward slash in file path
187
  if ( empty( $new_file_name ) ) {
188
- $path = $this->replace_directory_separator_with_forward_slash( ai1wm_dirname( $file_name ) );
189
  } else {
190
- $path = $this->replace_directory_separator_with_forward_slash( ai1wm_dirname( $new_file_name ) );
191
  }
192
 
193
  // Concatenate block format parts
35
  * @param string $file_name File to use as archive
36
  */
37
  public function __construct( $file_name ) {
 
38
  parent::__construct( $file_name, true );
39
  }
40
 
56
  $file_written = 0;
57
 
58
  // Replace forward slash with current directory separator in file name
59
+ $file_name = ai1wm_replace_forward_slash_with_directory_separator( $file_name );
60
 
61
  // Escape Windows directory separator in file name
62
+ $file_name = ai1wm_escape_windows_directory_separator( $file_name );
63
 
64
  // Flag to hold if file data has been processed
65
  $completed = true;
184
 
185
  // Replace current directory separator with backward slash in file path
186
  if ( empty( $new_file_name ) ) {
187
+ $path = ai1wm_replace_directory_separator_with_forward_slash( ai1wm_dirname( $file_name ) );
188
  } else {
189
+ $path = ai1wm_replace_directory_separator_with_forward_slash( ai1wm_dirname( $new_file_name ) );
190
  }
191
 
192
  // Concatenate block format parts
lib/vendor/servmask/archiver/class-ai1wm-extractor.php CHANGED
@@ -169,7 +169,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
169
  }
170
 
171
  // Replace forward slash with current directory separator in location
172
- $location = $this->replace_forward_slash_with_directory_separator( $location );
173
 
174
  // Flag to hold if file data has been processed
175
  $completed = true;
@@ -215,7 +215,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
215
 
216
  // Should we skip this file by name?
217
  for ( $i = 0; $i < count( $exclude_files ); $i++ ) {
218
- if ( strpos( $file_name . DIRECTORY_SEPARATOR, $exclude_files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
219
  $should_exclude_file = true;
220
  break;
221
  }
@@ -234,18 +234,26 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
234
 
235
  // Replace extract paths
236
  for ( $i = 0; $i < count( $old_paths ); $i++ ) {
237
- if ( strpos( $file_path . DIRECTORY_SEPARATOR, $old_paths[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
238
- $file_name = substr_replace( $file_name, $new_paths[ $i ], 0, strlen( $old_paths[ $i ] ) );
239
- $file_path = substr_replace( $file_path, $new_paths[ $i ], 0, strlen( $old_paths[ $i ] ) );
240
  break;
241
  }
242
  }
243
 
244
  // Escape Windows directory separator in file path
245
- $file_path = $this->escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_path );
 
 
 
 
246
 
247
  // Escape Windows directory separator in file name
248
- $file_name = $this->escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_name );
 
 
 
 
249
 
250
  // Check if location doesn't exist, then create it
251
  if ( false === is_dir( $file_path ) ) {
@@ -293,7 +301,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
293
  }
294
 
295
  // Replace forward slash with current directory separator in location
296
- $location = $this->replace_forward_slash_with_directory_separator( $location );
297
 
298
  // Flag to hold if file data has been processed
299
  $completed = true;
@@ -342,7 +350,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
342
 
343
  // Should we extract this file by name?
344
  for ( $i = 0; $i < count( $include_files ); $i++ ) {
345
- if ( strpos( $file_name . DIRECTORY_SEPARATOR, $include_files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
346
  $should_include_file = true;
347
  break;
348
  }
@@ -350,7 +358,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
350
 
351
  // Should we skip this file name?
352
  for ( $i = 0; $i < count( $exclude_files ); $i++ ) {
353
- if ( strpos( $file_name . DIRECTORY_SEPARATOR, $exclude_files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
354
  $should_include_file = false;
355
  break;
356
  }
@@ -368,10 +376,10 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
368
  if ( $should_include_file === true ) {
369
 
370
  // Escape Windows directory separator in file path
371
- $file_path = $this->escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_path );
372
 
373
  // Escape Windows directory separator in file name
374
- $file_name = $this->escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_name );
375
 
376
  // Check if location doesn't exist, then create it
377
  if ( false === is_dir( $file_path ) ) {
@@ -540,10 +548,10 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
540
  $data['path'] = ( $data['path'] === '.' ? '' : $data['path'] );
541
 
542
  // Replace forward slash with current directory separator in file name
543
- $data['filename'] = $this->replace_forward_slash_with_directory_separator( $data['filename'] );
544
 
545
  // Replace forward slash with current directory separator in file path
546
- $data['path'] = $this->replace_forward_slash_with_directory_separator( $data['path'] );
547
  }
548
 
549
  return $data;
169
  }
170
 
171
  // Replace forward slash with current directory separator in location
172
+ $location = ai1wm_replace_forward_slash_with_directory_separator( $location );
173
 
174
  // Flag to hold if file data has been processed
175
  $completed = true;
215
 
216
  // Should we skip this file by name?
217
  for ( $i = 0; $i < count( $exclude_files ); $i++ ) {
218
+ if ( strpos( $file_name . DIRECTORY_SEPARATOR, ai1wm_replace_forward_slash_with_directory_separator( $exclude_files[ $i ] ) . DIRECTORY_SEPARATOR ) === 0 ) {
219
  $should_exclude_file = true;
220
  break;
221
  }
234
 
235
  // Replace extract paths
236
  for ( $i = 0; $i < count( $old_paths ); $i++ ) {
237
+ if ( strpos( $file_path . DIRECTORY_SEPARATOR, ai1wm_replace_forward_slash_with_directory_separator( $old_paths[ $i ] ) . DIRECTORY_SEPARATOR ) === 0 ) {
238
+ $file_name = substr_replace( $file_name, ai1wm_replace_forward_slash_with_directory_separator( $new_paths[ $i ] ), 0, strlen( ai1wm_replace_forward_slash_with_directory_separator( $old_paths[ $i ] ) ) );
239
+ $file_path = substr_replace( $file_path, ai1wm_replace_forward_slash_with_directory_separator( $new_paths[ $i ] ), 0, strlen( ai1wm_replace_forward_slash_with_directory_separator( $old_paths[ $i ] ) ) );
240
  break;
241
  }
242
  }
243
 
244
  // Escape Windows directory separator in file path
245
+ if ( path_is_absolute( $file_path ) ) {
246
+ $file_path = ai1wm_escape_windows_directory_separator( $file_path );
247
+ } else {
248
+ $file_path = ai1wm_escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_path );
249
+ }
250
 
251
  // Escape Windows directory separator in file name
252
+ if ( path_is_absolute( $file_name ) ) {
253
+ $file_name = ai1wm_escape_windows_directory_separator( $file_name );
254
+ } else {
255
+ $file_name = ai1wm_escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_name );
256
+ }
257
 
258
  // Check if location doesn't exist, then create it
259
  if ( false === is_dir( $file_path ) ) {
301
  }
302
 
303
  // Replace forward slash with current directory separator in location
304
+ $location = ai1wm_replace_forward_slash_with_directory_separator( $location );
305
 
306
  // Flag to hold if file data has been processed
307
  $completed = true;
350
 
351
  // Should we extract this file by name?
352
  for ( $i = 0; $i < count( $include_files ); $i++ ) {
353
+ if ( strpos( $file_name . DIRECTORY_SEPARATOR, ai1wm_replace_forward_slash_with_directory_separator( $include_files[ $i ] ) . DIRECTORY_SEPARATOR ) === 0 ) {
354
  $should_include_file = true;
355
  break;
356
  }
358
 
359
  // Should we skip this file name?
360
  for ( $i = 0; $i < count( $exclude_files ); $i++ ) {
361
+ if ( strpos( $file_name . DIRECTORY_SEPARATOR, ai1wm_replace_forward_slash_with_directory_separator( $exclude_files[ $i ] ) . DIRECTORY_SEPARATOR ) === 0 ) {
362
  $should_include_file = false;
363
  break;
364
  }
376
  if ( $should_include_file === true ) {
377
 
378
  // Escape Windows directory separator in file path
379
+ $file_path = ai1wm_escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_path );
380
 
381
  // Escape Windows directory separator in file name
382
+ $file_name = ai1wm_escape_windows_directory_separator( $location . DIRECTORY_SEPARATOR . $file_name );
383
 
384
  // Check if location doesn't exist, then create it
385
  if ( false === is_dir( $file_path ) ) {
548
  $data['path'] = ( $data['path'] === '.' ? '' : $data['path'] );
549
 
550
  // Replace forward slash with current directory separator in file name
551
+ $data['filename'] = ai1wm_replace_forward_slash_with_directory_separator( $data['filename'] );
552
 
553
  // Replace forward slash with current directory separator in file path
554
+ $data['path'] = ai1wm_replace_forward_slash_with_directory_separator( $data['path'] );
555
  }
556
 
557
  return $data;
lib/vendor/servmask/filter/class-ai1wm-recursive-exclude-filter.php CHANGED
@@ -33,13 +33,19 @@ class Ai1wm_Recursive_Exclude_Filter extends RecursiveFilterIterator {
33
 
34
  public function __construct( RecursiveIterator $iterator, $exclude = array() ) {
35
  parent::__construct( $iterator );
36
-
37
- // Set exclude filter
38
- $this->exclude = $exclude;
 
 
39
  }
40
 
41
  public function accept() {
42
- if ( in_array( $this->getInnerIterator()->getSubPathname(), $this->exclude ) ) {
 
 
 
 
43
  return false;
44
  }
45
 
33
 
34
  public function __construct( RecursiveIterator $iterator, $exclude = array() ) {
35
  parent::__construct( $iterator );
36
+ if ( is_array( $exclude ) ) {
37
+ foreach ( $exclude as $path ) {
38
+ $this->exclude[] = ai1wm_replace_forward_slash_with_directory_separator( $path );
39
+ }
40
+ }
41
  }
42
 
43
  public function accept() {
44
+ if ( in_array( ai1wm_replace_forward_slash_with_directory_separator( $this->getInnerIterator()->getSubPathname() ), $this->exclude ) ) {
45
+ return false;
46
+ }
47
+
48
+ if ( in_array( ai1wm_replace_forward_slash_with_directory_separator( $this->getInnerIterator()->getPathname() ), $this->exclude ) ) {
49
  return false;
50
  }
51
 
lib/vendor/servmask/filter/class-ai1wm-recursive-extension-filter.php CHANGED
@@ -33,9 +33,9 @@ class Ai1wm_Recursive_Extension_Filter extends RecursiveFilterIterator {
33
 
34
  public function __construct( RecursiveIterator $iterator, $include = array() ) {
35
  parent::__construct( $iterator );
36
-
37
- // Set include filter
38
- $this->include = $include;
39
  }
40
 
41
  public function accept() {
33
 
34
  public function __construct( RecursiveIterator $iterator, $include = array() ) {
35
  parent::__construct( $iterator );
36
+ if ( is_array( $include ) ) {
37
+ $this->include = $include;
38
+ }
39
  }
40
 
41
  public function accept() {
loader.php CHANGED
@@ -239,12 +239,20 @@ require_once AI1WM_EXPORT_PATH .
239
 
240
  require_once AI1WM_EXPORT_PATH .
241
  DIRECTORY_SEPARATOR .
242
- 'class-ai1wm-export-enumerate.php';
 
 
 
 
243
 
244
  require_once AI1WM_EXPORT_PATH .
245
  DIRECTORY_SEPARATOR .
246
  'class-ai1wm-export-content.php';
247
 
 
 
 
 
248
  require_once AI1WM_EXPORT_PATH .
249
  DIRECTORY_SEPARATOR .
250
  'class-ai1wm-export-database.php';
239
 
240
  require_once AI1WM_EXPORT_PATH .
241
  DIRECTORY_SEPARATOR .
242
+ 'class-ai1wm-export-enumerate-content.php';
243
+
244
+ require_once AI1WM_EXPORT_PATH .
245
+ DIRECTORY_SEPARATOR .
246
+ 'class-ai1wm-export-enumerate-media.php';
247
 
248
  require_once AI1WM_EXPORT_PATH .
249
  DIRECTORY_SEPARATOR .
250
  'class-ai1wm-export-content.php';
251
 
252
+ require_once AI1WM_EXPORT_PATH .
253
+ DIRECTORY_SEPARATOR .
254
+ 'class-ai1wm-export-media.php';
255
+
256
  require_once AI1WM_EXPORT_PATH .
257
  DIRECTORY_SEPARATOR .
258
  'class-ai1wm-export-database.php';
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: move, transfer, copy, migrate, backup, clone, restore, db migration, wordp
4
  Requires at least: 3.3
5
  Tested up to: 5.4
6
  Requires PHP: 5.2.17
7
- Stable tag: 7.18
8
  License: GPLv2 or later
9
 
10
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
@@ -108,6 +108,11 @@ Alternatively you can download the plugin using the download button on this page
108
  All-in-One WP Migration **asks for your consent** to collect **requester's email address** when filling plugin's contact form. [GDPR Compliant Privacy Policy](https://www.iubenda.com/privacy-policy/946881)
109
 
110
  == Changelog ==
 
 
 
 
 
111
  = 7.18 =
112
  **Added**
113
 
4
  Requires at least: 3.3
5
  Tested up to: 5.4
6
  Requires PHP: 5.2.17
7
+ Stable tag: 7.19
8
  License: GPLv2 or later
9
 
10
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
108
  All-in-One WP Migration **asks for your consent** to collect **requester's email address** when filling plugin's contact form. [GDPR Compliant Privacy Policy](https://www.iubenda.com/privacy-policy/946881)
109
 
110
  == Changelog ==
111
+ = 7.19 =
112
+ **Added**
113
+
114
+ * Support for custom upload directory
115
+
116
  = 7.18 =
117
  **Added**
118