Astra Starter Sites - Version 1.1.9

Version Description

Download this release

Release Info

Developer Nikschavan
Plugin Icon Astra Starter Sites
Version 1.1.9
Comparing to
See all releases

Code changes from version 1.1.8 to 1.1.9

astra-sites.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Astra Starter Sites
4
  * Plugin URI: http://www.wpastra.com/pro/
5
  * Description: Import free sites build with Astra theme.
6
- * Version: 1.1.8
7
  * Author: Brainstorm Force
8
  * Author URI: http://www.brainstormforce.com
9
  * Text Domain: astra-sites
@@ -19,7 +19,7 @@ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
19
  }
20
 
21
  if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
- define( 'ASTRA_SITES_VER', '1.1.8' );
23
  }
24
 
25
  if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
3
  * Plugin Name: Astra Starter Sites
4
  * Plugin URI: http://www.wpastra.com/pro/
5
  * Description: Import free sites build with Astra theme.
6
+ * Version: 1.1.9
7
  * Author: Brainstorm Force
8
  * Author URI: http://www.brainstormforce.com
9
  * Text Domain: astra-sites
19
  }
20
 
21
  if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
+ define( 'ASTRA_SITES_VER', '1.1.9' );
23
  }
24
 
25
  if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
inc/assets/css/admin.css CHANGED
@@ -356,19 +356,25 @@ body.loading-content .select-page-builder {
356
  max-width: 100%;
357
  }
358
 
359
- .select-page-builder h3 {
360
- margin: 0;
361
- font-size: 2em;
362
- display: flex;
363
- align-items: baseline;
364
  position: absolute;
365
  padding: 40px 0;
366
  margin-left: 170px;
 
 
 
 
 
 
 
367
  }
368
  .select-page-builder {
369
  margin: -20px 0 0 -5px;
370
  position: absolute;
371
  }
 
 
 
372
 
373
  @keyframes bounce {
374
  0%,
356
  max-width: 100%;
357
  }
358
 
359
+ .select-page-builder .note-wrap {
 
 
 
 
360
  position: absolute;
361
  padding: 40px 0;
362
  margin-left: 170px;
363
+ right: 0;
364
+ left: 0;
365
+ }
366
+
367
+ .select-page-builder h3 {
368
+ margin: 0;
369
+ font-size: 2em;
370
  }
371
  .select-page-builder {
372
  margin: -20px 0 0 -5px;
373
  position: absolute;
374
  }
375
+ .select-page-builder .note {
376
+ margin-left: 1.5em;
377
+ }
378
 
379
  @keyframes bounce {
380
  0%,
inc/classes/class-astra-sites-page.php CHANGED
@@ -1,270 +1,270 @@
1
- <?php
2
- /**
3
- * Astra Sites Page
4
- *
5
- * @since 1.0.6
6
- * @package Astra Sites
7
- */
8
-
9
- if ( ! defined( 'ABSPATH' ) ) {
10
- exit;
11
- }
12
-
13
- if ( ! class_exists( 'Astra_Sites_Page' ) ) {
14
-
15
- /**
16
- * Astra Admin Settings
17
- */
18
- class Astra_Sites_Page {
19
-
20
- /**
21
- * View all actions
22
- *
23
- * @since 1.0.6
24
- * @var array $view_actions
25
- */
26
- static public $view_actions = array();
27
-
28
- /**
29
- * Menu page title
30
- *
31
- * @since 1.0.6
32
- * @var array $menu_page_title
33
- */
34
- static public $menu_page_title = ASTRA_SITES_NAME;
35
-
36
- /**
37
- * Plugin slug
38
- *
39
- * @since 1.0.6
40
- * @var array $plugin_slug
41
- */
42
- static public $plugin_slug = 'astra-sites';
43
-
44
- /**
45
- * Default Menu position
46
- *
47
- * @since 1.0.6
48
- * @var array $default_menu_position
49
- */
50
- static public $default_menu_position = 'themes.php';
51
-
52
- /**
53
- * Parent Page Slug
54
- *
55
- * @since 1.0.6
56
- * @var array $parent_page_slug
57
- */
58
- static public $parent_page_slug = 'general';
59
-
60
- /**
61
- * Current Slug
62
- *
63
- * @since 1.0.6
64
- * @var array $current_slug
65
- */
66
- static public $current_slug = 'general';
67
-
68
- /**
69
- * Constructor
70
- */
71
- function __construct() {
72
-
73
- if ( ! is_admin() ) {
74
- return;
75
- }
76
-
77
- add_action( 'after_setup_theme', __CLASS__ . '::init_admin_settings', 99 );
78
- }
79
-
80
- /**
81
- * Admin settings init
82
- */
83
- static public function init_admin_settings() {
84
-
85
- self::$menu_page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Sites', 'astra-sites' ) );
86
-
87
- if ( isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], self::$plugin_slug ) !== false ) {
88
-
89
- // Let extensions hook into saving.
90
- self::save_settings();
91
- }
92
-
93
- add_action( 'admin_menu', __CLASS__ . '::add_admin_menu', 100 );
94
-
95
- add_action( 'astra_sites_menu_general_action', __CLASS__ . '::general_page' );
96
- }
97
-
98
- /**
99
- * Save All admin settings here
100
- */
101
- static public function save_settings() {
102
-
103
- // Only admins can save settings.
104
- if ( ! current_user_can( 'manage_options' ) ) {
105
- return;
106
- }
107
-
108
- // Let extensions hook into saving.
109
- do_action( 'astra_sites_save_settings' );
110
- }
111
-
112
- /**
113
- * Init Nav Menu
114
- *
115
- * @param mixed $action Action name.
116
- * @since 1.0.6
117
- */
118
- static public function init_nav_menu( $action = '' ) {
119
-
120
- if ( '' !== $action ) {
121
- self::render_tab_menu( $action );
122
- }
123
- }
124
-
125
- /**
126
- * Render tab menu
127
- *
128
- * @param mixed $action Action name.
129
- * @since 1.0.6
130
- */
131
- static public function render_tab_menu( $action = '' ) {
132
- ?>
133
- <div id="astra-sites-menu-page">
134
- <?php self::render( $action ); ?>
135
- </div>
136
- <?php
137
- }
138
-
139
- /**
140
- * View actions
141
- *
142
- * @since 1.0.11
143
- */
144
- static public function get_view_actions() {
145
-
146
- if ( empty( self::$view_actions ) ) {
147
-
148
- self::$view_actions = apply_filters(
149
- 'astra_sites_menu_item', array()
150
- );
151
- }
152
-
153
- return self::$view_actions;
154
- }
155
-
156
- /**
157
- * Prints HTML content for tabs
158
- *
159
- * @param mixed $action Action name.
160
- * @since 1.0.6
161
- */
162
- static public function render( $action ) {
163
-
164
- ?>
165
- <div class="nav-tab-wrapper">
166
- <h1 class='astra-sites-title'> <?php echo esc_html( self::$menu_page_title ); ?> </h1>
167
- <?php
168
- $view_actions = self::get_view_actions();
169
-
170
- foreach ( $view_actions as $slug => $data ) {
171
-
172
- if ( ! $data['show'] ) {
173
- continue;
174
- }
175
-
176
- $url = self::get_page_url( $slug );
177
-
178
- if ( $slug == self::$parent_page_slug ) {
179
- update_option( 'astra_parent_page_url', $url );
180
- }
181
-
182
- $active = ( $slug == $action ) ? 'nav-tab-active' : '';
183
- ?>
184
- <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
185
- <?php } ?>
186
- </div><!-- .nav-tab-wrapper -->
187
-
188
- <?php
189
- // Settings update message.
190
- if ( isset( $_REQUEST['message'] ) && ( 'saved' == $_REQUEST['message'] || 'saved_ext' == $_REQUEST['message'] ) ) {
191
- ?>
192
- <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
193
- <?php
194
- }
195
-
196
- }
197
-
198
- /**
199
- * Get and return page URL
200
- *
201
- * @param string $menu_slug Menu name.
202
- * @since 1.0.6
203
- * @return string page url
204
- */
205
- static public function get_page_url( $menu_slug ) {
206
-
207
- $parent_page = self::$default_menu_position;
208
-
209
- if ( strpos( $parent_page, '?' ) !== false ) {
210
- $query_var = '&page=' . self::$plugin_slug;
211
- } else {
212
- $query_var = '?page=' . self::$plugin_slug;
213
- }
214
-
215
- $parent_page_url = admin_url( $parent_page . $query_var );
216
-
217
- $url = $parent_page_url . '&action=' . $menu_slug;
218
-
219
- return esc_url( $url );
220
- }
221
-
222
- /**
223
- * Add main menu
224
- *
225
- * @since 1.0.6
226
- */
227
- static public function add_admin_menu() {
228
-
229
- $parent_page = self::$default_menu_position;
230
- $page_title = self::$menu_page_title;
231
- $capability = 'manage_options';
232
- $page_menu_slug = self::$plugin_slug;
233
- $page_menu_func = __CLASS__ . '::menu_callback';
234
-
235
- add_theme_page( $page_title, $page_title, $capability, $page_menu_slug, $page_menu_func );
236
- }
237
-
238
- /**
239
- * Menu callback
240
- *
241
- * @since 1.0.6
242
- */
243
- static public function menu_callback() {
244
-
245
- $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : self::$current_slug;
246
-
247
- $active_tab = str_replace( '_', '-', $current_slug );
248
- $current_slug = str_replace( '-', '_', $current_slug );
249
-
250
- ?>
251
- <div class="astra-sites-menu-page-wrapper">
252
- <?php self::init_nav_menu( $active_tab ); ?>
253
- <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
254
- </div>
255
- <?php
256
- }
257
-
258
- /**
259
- * Include general page
260
- *
261
- * @since 1.0.6
262
- */
263
- static public function general_page() {
264
- require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
265
- }
266
- }
267
-
268
- new Astra_Sites_Page;
269
-
270
- }// End if.
1
+ <?php
2
+ /**
3
+ * Astra Sites Page
4
+ *
5
+ * @since 1.0.6
6
+ * @package Astra Sites
7
+ */
8
+
9
+ if ( ! defined( 'ABSPATH' ) ) {
10
+ exit;
11
+ }
12
+
13
+ if ( ! class_exists( 'Astra_Sites_Page' ) ) {
14
+
15
+ /**
16
+ * Astra Admin Settings
17
+ */
18
+ class Astra_Sites_Page {
19
+
20
+ /**
21
+ * View all actions
22
+ *
23
+ * @since 1.0.6
24
+ * @var array $view_actions
25
+ */
26
+ static public $view_actions = array();
27
+
28
+ /**
29
+ * Menu page title
30
+ *
31
+ * @since 1.0.6
32
+ * @var array $menu_page_title
33
+ */
34
+ static public $menu_page_title = ASTRA_SITES_NAME;
35
+
36
+ /**
37
+ * Plugin slug
38
+ *
39
+ * @since 1.0.6
40
+ * @var array $plugin_slug
41
+ */
42
+ static public $plugin_slug = 'astra-sites';
43
+
44
+ /**
45
+ * Default Menu position
46
+ *
47
+ * @since 1.0.6
48
+ * @var array $default_menu_position
49
+ */
50
+ static public $default_menu_position = 'themes.php';
51
+
52
+ /**
53
+ * Parent Page Slug
54
+ *
55
+ * @since 1.0.6
56
+ * @var array $parent_page_slug
57
+ */
58
+ static public $parent_page_slug = 'general';
59
+
60
+ /**
61
+ * Current Slug
62
+ *
63
+ * @since 1.0.6
64
+ * @var array $current_slug
65
+ */
66
+ static public $current_slug = 'general';
67
+
68
+ /**
69
+ * Constructor
70
+ */
71
+ function __construct() {
72
+
73
+ if ( ! is_admin() ) {
74
+ return;
75
+ }
76
+
77
+ add_action( 'after_setup_theme', __CLASS__ . '::init_admin_settings', 99 );
78
+ }
79
+
80
+ /**
81
+ * Admin settings init
82
+ */
83
+ static public function init_admin_settings() {
84
+
85
+ self::$menu_page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Sites', 'astra-sites' ) );
86
+
87
+ if ( isset( $_REQUEST['page'] ) && strpos( $_REQUEST['page'], self::$plugin_slug ) !== false ) {
88
+
89
+ // Let extensions hook into saving.
90
+ self::save_settings();
91
+ }
92
+
93
+ add_action( 'admin_menu', __CLASS__ . '::add_admin_menu', 100 );
94
+
95
+ add_action( 'astra_sites_menu_general_action', __CLASS__ . '::general_page' );
96
+ }
97
+
98
+ /**
99
+ * Save All admin settings here
100
+ */
101
+ static public function save_settings() {
102
+
103
+ // Only admins can save settings.
104
+ if ( ! current_user_can( 'manage_options' ) ) {
105
+ return;
106
+ }
107
+
108
+ // Let extensions hook into saving.
109
+ do_action( 'astra_sites_save_settings' );
110
+ }
111
+
112
+ /**
113
+ * Init Nav Menu
114
+ *
115
+ * @param mixed $action Action name.
116
+ * @since 1.0.6
117
+ */
118
+ static public function init_nav_menu( $action = '' ) {
119
+
120
+ if ( '' !== $action ) {
121
+ self::render_tab_menu( $action );
122
+ }
123
+ }
124
+
125
+ /**
126
+ * Render tab menu
127
+ *
128
+ * @param mixed $action Action name.
129
+ * @since 1.0.6
130
+ */
131
+ static public function render_tab_menu( $action = '' ) {
132
+ ?>
133
+ <div id="astra-sites-menu-page">
134
+ <?php self::render( $action ); ?>
135
+ </div>
136
+ <?php
137
+ }
138
+
139
+ /**
140
+ * View actions
141
+ *
142
+ * @since 1.0.11
143
+ */
144
+ static public function get_view_actions() {
145
+
146
+ if ( empty( self::$view_actions ) ) {
147
+
148
+ self::$view_actions = apply_filters(
149
+ 'astra_sites_menu_item', array()
150
+ );
151
+ }
152
+
153
+ return self::$view_actions;
154
+ }
155
+
156
+ /**
157
+ * Prints HTML content for tabs
158
+ *
159
+ * @param mixed $action Action name.
160
+ * @since 1.0.6
161
+ */
162
+ static public function render( $action ) {
163
+
164
+ ?>
165
+ <div class="nav-tab-wrapper">
166
+ <h1 class='astra-sites-title'> <?php echo esc_html( self::$menu_page_title ); ?> </h1>
167
+ <?php
168
+ $view_actions = self::get_view_actions();
169
+
170
+ foreach ( $view_actions as $slug => $data ) {
171
+
172
+ if ( ! $data['show'] ) {
173
+ continue;
174
+ }
175
+
176
+ $url = self::get_page_url( $slug );
177
+
178
+ if ( $slug == self::$parent_page_slug ) {
179
+ update_option( 'astra_parent_page_url', $url );
180
+ }
181
+
182
+ $active = ( $slug == $action ) ? 'nav-tab-active' : '';
183
+ ?>
184
+ <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
185
+ <?php } ?>
186
+ </div><!-- .nav-tab-wrapper -->
187
+
188
+ <?php
189
+ // Settings update message.
190
+ if ( isset( $_REQUEST['message'] ) && ( 'saved' == $_REQUEST['message'] || 'saved_ext' == $_REQUEST['message'] ) ) {
191
+ ?>
192
+ <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
193
+ <?php
194
+ }
195
+
196
+ }
197
+
198
+ /**
199
+ * Get and return page URL
200
+ *
201
+ * @param string $menu_slug Menu name.
202
+ * @since 1.0.6
203
+ * @return string page url
204
+ */
205
+ static public function get_page_url( $menu_slug ) {
206
+
207
+ $parent_page = self::$default_menu_position;
208
+
209
+ if ( strpos( $parent_page, '?' ) !== false ) {
210
+ $query_var = '&page=' . self::$plugin_slug;
211
+ } else {
212
+ $query_var = '?page=' . self::$plugin_slug;
213
+ }
214
+
215
+ $parent_page_url = admin_url( $parent_page . $query_var );
216
+
217
+ $url = $parent_page_url . '&action=' . $menu_slug;
218
+
219
+ return esc_url( $url );
220
+ }
221
+
222
+ /**
223
+ * Add main menu
224
+ *
225
+ * @since 1.0.6
226
+ */
227
+ static public function add_admin_menu() {
228
+
229
+ $parent_page = self::$default_menu_position;
230
+ $page_title = self::$menu_page_title;
231
+ $capability = 'manage_options';
232
+ $page_menu_slug = self::$plugin_slug;
233
+ $page_menu_func = __CLASS__ . '::menu_callback';
234
+
235
+ add_theme_page( $page_title, $page_title, $capability, $page_menu_slug, $page_menu_func );
236
+ }
237
+
238
+ /**
239
+ * Menu callback
240
+ *
241
+ * @since 1.0.6
242
+ */
243
+ static public function menu_callback() {
244
+
245
+ $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : self::$current_slug;
246
+
247
+ $active_tab = str_replace( '_', '-', $current_slug );
248
+ $current_slug = str_replace( '-', '_', $current_slug );
249
+
250
+ ?>
251
+ <div class="astra-sites-menu-page-wrapper">
252
+ <?php self::init_nav_menu( $active_tab ); ?>
253
+ <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
254
+ </div>
255
+ <?php
256
+ }
257
+
258
+ /**
259
+ * Include general page
260
+ *
261
+ * @since 1.0.6
262
+ */
263
+ static public function general_page() {
264
+ require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
265
+ }
266
+ }
267
+
268
+ new Astra_Sites_Page;
269
+
270
+ }// End if.
inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php CHANGED
@@ -1,326 +1,326 @@
1
- <?php
2
- /**
3
- * Elementor Images Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.0
7
- */
8
-
9
- namespace Elementor;
10
-
11
- // If plugin - 'Elementor' not exist then return.
12
- if ( ! class_exists( '\Elementor\Plugin' ) ) {
13
- return;
14
- }
15
-
16
- namespace Elementor\TemplateLibrary;
17
-
18
- use Elementor\Core\Settings\Manager as SettingsManager;
19
- use Elementor\TemplateLibrary\Classes\Import_Images;
20
- use Elementor\TemplateLibrary;
21
- use Elementor\TemplateLibrary\Classes;
22
- use Elementor\Api;
23
- use Elementor\PageSettings\Page;
24
-
25
- // For working protected methods defined in.
26
- // file '/elementor/includes/template-library/sources/base.php'.
27
- use Elementor\Plugin;
28
- use Elementor\Utils;
29
-
30
- if ( ! defined( 'ABSPATH' ) ) {
31
- exit; // Exit if accessed directly.
32
- }
33
-
34
- /**
35
- * Astra Source Remote
36
- */
37
- class Astra_Sites_Batch_Processing_Elementor extends Source_Base {
38
-
39
- /**
40
- * Get ID
41
- *
42
- * @since 1.0.4
43
- *
44
- * @return string
45
- */
46
- public function get_id() {
47
- return 'remote';
48
- }
49
-
50
- /**
51
- * Get Title.
52
- *
53
- * @since 1.0.4
54
- *
55
- * @return string
56
- */
57
- public function get_title() {
58
- return __( 'Remote', 'astra-sites' );
59
- }
60
-
61
- /**
62
- * Get Data
63
- *
64
- * @since 1.0.4
65
- *
66
- * @return void
67
- */
68
- public function register_data() {}
69
-
70
- /**
71
- * Get Items
72
- *
73
- * @since 1.0.4
74
- *
75
- * @param array $args Arguments.
76
- * @return array
77
- */
78
- public function get_items( $args = array() ) {
79
- $templates_data = Api::get_templates_data();
80
-
81
- $templates = array();
82
-
83
- if ( ! empty( $templates_data ) ) {
84
- foreach ( $templates_data as $template_data ) {
85
- $templates[] = $this->get_item( $template_data );
86
- }
87
- }
88
-
89
- if ( ! empty( $args ) ) {
90
- $templates = wp_list_filter( $templates, $args );
91
- }
92
-
93
- return $templates;
94
- }
95
-
96
- /**
97
- * Get Item
98
- *
99
- * @param array $template_data Template Data.
100
- *
101
- * @return array
102
- */
103
- public function get_item( $template_data ) {
104
- return array(
105
- 'template_id' => $template_data['id'],
106
- 'source' => $this->get_id(),
107
- 'title' => $template_data['title'],
108
- 'thumbnail' => $template_data['thumbnail'],
109
- 'date' => date( get_option( 'date_format' ), $template_data['tmpl_created'] ),
110
- 'author' => $template_data['author'],
111
- 'categories' => array(),
112
- 'keywords' => array(),
113
- 'isPro' => ( '1' === $template_data['is_pro'] ),
114
- 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ),
115
- 'url' => $template_data['url'],
116
- );
117
- }
118
-
119
- /**
120
- * Template Data
121
- *
122
- * @param boolean $template_data Template Data.
123
- * @return boolean Return false.
124
- */
125
- public function save_item( $template_data ) {
126
- return false;
127
- }
128
-
129
- /**
130
- * Update Item
131
- *
132
- * @param boolean $new_data New Data.
133
- * @return boolean Return false.
134
- */
135
- public function update_item( $new_data ) {
136
- return false;
137
- }
138
-
139
- /**
140
- * Delete Template
141
- *
142
- * @param boolean $template_id Template ID.
143
- * @return boolean Return false.
144
- */
145
- public function delete_template( $template_id ) {
146
- return false;
147
- }
148
-
149
- /**
150
- * Delete Template
151
- *
152
- * @param boolean $template_id Template ID.
153
- * @return boolean Return false.
154
- */
155
- public function export_template( $template_id ) {
156
- return false;
157
- }
158
-
159
- /**
160
- * Get Data
161
- *
162
- * @param array $args Arguments.
163
- * @param string $context Context.
164
- * @return array Data.
165
- */
166
- public function get_data( array $args, $context = 'display' ) {
167
- $data = Api::get_template_content( $args['template_id'] );
168
-
169
- if ( is_wp_error( $data ) ) {
170
- return $data;
171
- }
172
-
173
- // TODO: since 1.5.0 to content container named `content` instead of `data`.
174
- if ( ! empty( $data['data'] ) ) {
175
- $data['content'] = $data['data'];
176
- unset( $data['data'] );
177
- }
178
-
179
- $data['content'] = $this->replace_elements_ids( $data['content'] );
180
- $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' );
181
-
182
- if ( ! empty( $args['page_settings'] ) && ! empty( $data['page_settings'] ) ) {
183
- $page = new Page(
184
- array(
185
- 'settings' => $data['page_settings'],
186
- )
187
- );
188
-
189
- $page_settings_data = $this->process_element_export_import_content( $page, 'on_import' );
190
- $data['page_settings'] = $page_settings_data['settings'];
191
- }
192
-
193
- return $data;
194
- }
195
-
196
- /**
197
- * Replace Elements Ids
198
- *
199
- * @param string $content Context.
200
- * @return array Element.
201
- */
202
- public function replace_elements_ids( $content ) {
203
- return Plugin::$instance->db->iterate_data(
204
- $content, function( $element ) {
205
- $element['id'] = Utils::generate_random_string();
206
-
207
- return $element;
208
- }
209
- );
210
- }
211
-
212
- /**
213
- * Process Import Content.
214
- *
215
- * @param array $content a set of elements.
216
- * @param string $method (on_export|on_import).
217
- *
218
- * @return mixed
219
- */
220
- public function process_export_import_content( $content, $method ) {
221
- return Plugin::$instance->db->iterate_data(
222
- $content, function( $element_data ) use ( $method ) {
223
- $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
224
-
225
- // If the widget/element isn't exist, like a plugin that creates a widget but deactivated.
226
- if ( ! $element ) {
227
- return null;
228
- }
229
-
230
- $instance = new Astra_Sites_Batch_Processing_Elementor();
231
-
232
- return $instance->process_element_export_import_content( $element, $method );
233
- }
234
- );
235
- }
236
-
237
- /**
238
- * Process Element/Export Import Content.
239
- *
240
- * @param \Elementor\Controls_Stack $element Element.
241
- * @param string $method Method.
242
- *
243
- * @return array
244
- */
245
- public function process_element_export_import_content( $element, $method ) {
246
- $element_data = $element->get_data();
247
-
248
- if ( method_exists( $element, $method ) ) {
249
- // TODO: Use the internal element data without parameters.
250
- $element_data = $element->{$method}( $element_data );
251
- }
252
-
253
- foreach ( $element->get_controls() as $control ) {
254
- $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] );
255
-
256
- // If the control isn't exist, like a plugin that creates the control but deactivated.
257
- if ( ! $control_class ) {
258
- return $element_data;
259
- }
260
-
261
- if ( method_exists( $control_class, $method ) ) {
262
- $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ) );
263
- }
264
- }
265
-
266
- return $element_data;
267
- }
268
-
269
- /**
270
- * Import
271
- *
272
- * @since 1.0.14
273
- * @return void
274
- */
275
- public function import() {
276
-
277
- \Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Elementor ----' );
278
-
279
- $post_ids = \Astra_Sites_Batch_Processing::get_pages();
280
- if ( is_array( $post_ids ) ) {
281
- foreach ( $post_ids as $post_id ) {
282
- $this->import_single_post( $post_id );
283
- }
284
- }
285
-
286
- }
287
-
288
- /**
289
- * Update post meta.
290
- *
291
- * @since 1.0.14
292
- * @param integer $post_id Post ID.
293
- * @return void
294
- */
295
- public function import_single_post( $post_id = 0 ) {
296
-
297
- \Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
298
-
299
- if ( ! empty( $post_id ) ) {
300
-
301
- $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
302
-
303
- if ( empty( $hotlink_imported ) ) {
304
-
305
- $data = get_post_meta( $post_id, '_elementor_data', true );
306
-
307
- if ( ! empty( $data ) ) {
308
-
309
- $data = json_decode( $data, true );
310
-
311
- $data = $this->replace_elements_ids( $data );
312
- $data = $this->process_export_import_content( $data, 'on_import' );
313
-
314
- // Update processed meta.
315
- update_metadata( 'post', $post_id, '_elementor_data', $data );
316
- update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
317
-
318
- // !important, Clear the cache after images import.
319
- Plugin::$instance->posts_css_manager->clear_cache();
320
-
321
- }
322
- }
323
- }
324
-
325
- }
326
- }
1
+ <?php
2
+ /**
3
+ * Elementor Images Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.0
7
+ */
8
+
9
+ namespace Elementor;
10
+
11
+ // If plugin - 'Elementor' not exist then return.
12
+ if ( ! class_exists( '\Elementor\Plugin' ) ) {
13
+ return;
14
+ }
15
+
16
+ namespace Elementor\TemplateLibrary;
17
+
18
+ use Elementor\Core\Settings\Manager as SettingsManager;
19
+ use Elementor\TemplateLibrary\Classes\Import_Images;
20
+ use Elementor\TemplateLibrary;
21
+ use Elementor\TemplateLibrary\Classes;
22
+ use Elementor\Api;
23
+ use Elementor\PageSettings\Page;
24
+
25
+ // For working protected methods defined in.
26
+ // file '/elementor/includes/template-library/sources/base.php'.
27
+ use Elementor\Plugin;
28
+ use Elementor\Utils;
29
+
30
+ if ( ! defined( 'ABSPATH' ) ) {
31
+ exit; // Exit if accessed directly.
32
+ }
33
+
34
+ /**
35
+ * Astra Source Remote
36
+ */
37
+ class Astra_Sites_Batch_Processing_Elementor extends Source_Base {
38
+
39
+ /**
40
+ * Get ID
41
+ *
42
+ * @since 1.0.4
43
+ *
44
+ * @return string
45
+ */
46
+ public function get_id() {
47
+ return 'remote';
48
+ }
49
+
50
+ /**
51
+ * Get Title.
52
+ *
53
+ * @since 1.0.4
54
+ *
55
+ * @return string
56
+ */
57
+ public function get_title() {
58
+ return __( 'Remote', 'astra-sites' );
59
+ }
60
+
61
+ /**
62
+ * Get Data
63
+ *
64
+ * @since 1.0.4
65
+ *
66
+ * @return void
67
+ */
68
+ public function register_data() {}
69
+
70
+ /**
71
+ * Get Items
72
+ *
73
+ * @since 1.0.4
74
+ *
75
+ * @param array $args Arguments.
76
+ * @return array
77
+ */
78
+ public function get_items( $args = array() ) {
79
+ $templates_data = Api::get_templates_data();
80
+
81
+ $templates = array();
82
+
83
+ if ( ! empty( $templates_data ) ) {
84
+ foreach ( $templates_data as $template_data ) {
85
+ $templates[] = $this->get_item( $template_data );
86
+ }
87
+ }
88
+
89
+ if ( ! empty( $args ) ) {
90
+ $templates = wp_list_filter( $templates, $args );
91
+ }
92
+
93
+ return $templates;
94
+ }
95
+
96
+ /**
97
+ * Get Item
98
+ *
99
+ * @param array $template_data Template Data.
100
+ *
101
+ * @return array
102
+ */
103
+ public function get_item( $template_data ) {
104
+ return array(
105
+ 'template_id' => $template_data['id'],
106
+ 'source' => $this->get_id(),
107
+ 'title' => $template_data['title'],
108
+ 'thumbnail' => $template_data['thumbnail'],
109
+ 'date' => date( get_option( 'date_format' ), $template_data['tmpl_created'] ),
110
+ 'author' => $template_data['author'],
111
+ 'categories' => array(),
112
+ 'keywords' => array(),
113
+ 'isPro' => ( '1' === $template_data['is_pro'] ),
114
+ 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ),
115
+ 'url' => $template_data['url'],
116
+ );
117
+ }
118
+
119
+ /**
120
+ * Template Data
121
+ *
122
+ * @param boolean $template_data Template Data.
123
+ * @return boolean Return false.
124
+ */
125
+ public function save_item( $template_data ) {
126
+ return false;
127
+ }
128
+
129
+ /**
130
+ * Update Item
131
+ *
132
+ * @param boolean $new_data New Data.
133
+ * @return boolean Return false.
134
+ */
135
+ public function update_item( $new_data ) {
136
+ return false;
137
+ }
138
+
139
+ /**
140
+ * Delete Template
141
+ *
142
+ * @param boolean $template_id Template ID.
143
+ * @return boolean Return false.
144
+ */
145
+ public function delete_template( $template_id ) {
146
+ return false;
147
+ }
148
+
149
+ /**
150
+ * Delete Template
151
+ *
152
+ * @param boolean $template_id Template ID.
153
+ * @return boolean Return false.
154
+ */
155
+ public function export_template( $template_id ) {
156
+ return false;
157
+ }
158
+
159
+ /**
160
+ * Get Data
161
+ *
162
+ * @param array $args Arguments.
163
+ * @param string $context Context.
164
+ * @return array Data.
165
+ */
166
+ public function get_data( array $args, $context = 'display' ) {
167
+ $data = Api::get_template_content( $args['template_id'] );
168
+
169
+ if ( is_wp_error( $data ) ) {
170
+ return $data;
171
+ }
172
+
173
+ // TODO: since 1.5.0 to content container named `content` instead of `data`.
174
+ if ( ! empty( $data['data'] ) ) {
175
+ $data['content'] = $data['data'];
176
+ unset( $data['data'] );
177
+ }
178
+
179
+ $data['content'] = $this->replace_elements_ids( $data['content'] );
180
+ $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' );
181
+
182
+ if ( ! empty( $args['page_settings'] ) && ! empty( $data['page_settings'] ) ) {
183
+ $page = new Page(
184
+ array(
185
+ 'settings' => $data['page_settings'],
186
+ )
187
+ );
188
+
189
+ $page_settings_data = $this->process_element_export_import_content( $page, 'on_import' );
190
+ $data['page_settings'] = $page_settings_data['settings'];
191
+ }
192
+
193
+ return $data;
194
+ }
195
+
196
+ /**
197
+ * Replace Elements Ids
198
+ *
199
+ * @param string $content Context.
200
+ * @return array Element.
201
+ */
202
+ public function replace_elements_ids( $content ) {
203
+ return Plugin::$instance->db->iterate_data(
204
+ $content, function( $element ) {
205
+ $element['id'] = Utils::generate_random_string();
206
+
207
+ return $element;
208
+ }
209
+ );
210
+ }
211
+
212
+ /**
213
+ * Process Import Content.
214
+ *
215
+ * @param array $content a set of elements.
216
+ * @param string $method (on_export|on_import).
217
+ *
218
+ * @return mixed
219
+ */
220
+ public function process_export_import_content( $content, $method ) {
221
+ return Plugin::$instance->db->iterate_data(
222
+ $content, function( $element_data ) use ( $method ) {
223
+ $element = Plugin::$instance->elements_manager->create_element_instance( $element_data );
224
+
225
+ // If the widget/element isn't exist, like a plugin that creates a widget but deactivated.
226
+ if ( ! $element ) {
227
+ return null;
228
+ }
229
+
230
+ $instance = new Astra_Sites_Batch_Processing_Elementor();
231
+
232
+ return $instance->process_element_export_import_content( $element, $method );
233
+ }
234
+ );
235
+ }
236
+
237
+ /**
238
+ * Process Element/Export Import Content.
239
+ *
240
+ * @param \Elementor\Controls_Stack $element Element.
241
+ * @param string $method Method.
242
+ *
243
+ * @return array
244
+ */
245
+ public function process_element_export_import_content( $element, $method ) {
246
+ $element_data = $element->get_data();
247
+
248
+ if ( method_exists( $element, $method ) ) {
249
+ // TODO: Use the internal element data without parameters.
250
+ $element_data = $element->{$method}( $element_data );
251
+ }
252
+
253
+ foreach ( $element->get_controls() as $control ) {
254
+ $control_class = Plugin::$instance->controls_manager->get_control( $control['type'] );
255
+
256
+ // If the control isn't exist, like a plugin that creates the control but deactivated.
257
+ if ( ! $control_class ) {
258
+ return $element_data;
259
+ }
260
+
261
+ if ( method_exists( $control_class, $method ) ) {
262
+ $element_data['settings'][ $control['name'] ] = $control_class->{$method}( $element->get_settings( $control['name'] ) );
263
+ }
264
+ }
265
+
266
+ return $element_data;
267
+ }
268
+
269
+ /**
270
+ * Import
271
+ *
272
+ * @since 1.0.14
273
+ * @return void
274
+ */
275
+ public function import() {
276
+
277
+ \Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Elementor ----' );
278
+
279
+ $post_ids = \Astra_Sites_Batch_Processing::get_pages();
280
+ if ( is_array( $post_ids ) ) {
281
+ foreach ( $post_ids as $post_id ) {
282
+ $this->import_single_post( $post_id );
283
+ }
284
+ }
285
+
286
+ }
287
+
288
+ /**
289
+ * Update post meta.
290
+ *
291
+ * @since 1.0.14
292
+ * @param integer $post_id Post ID.
293
+ * @return void
294
+ */
295
+ public function import_single_post( $post_id = 0 ) {
296
+
297
+ \Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
298
+
299
+ if ( ! empty( $post_id ) ) {
300
+
301
+ $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
302
+
303
+ if ( empty( $hotlink_imported ) ) {
304
+
305
+ $data = get_post_meta( $post_id, '_elementor_data', true );
306
+
307
+ if ( ! empty( $data ) ) {
308
+
309
+ $data = json_decode( $data, true );
310
+
311
+ $data = $this->replace_elements_ids( $data );
312
+ $data = $this->process_export_import_content( $data, 'on_import' );
313
+
314
+ // Update processed meta.
315
+ update_metadata( 'post', $post_id, '_elementor_data', $data );
316
+ update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
317
+
318
+ // !important, Clear the cache after images import.
319
+ Plugin::$instance->posts_css_manager->clear_cache();
320
+
321
+ }
322
+ }
323
+ }
324
+
325
+ }
326
+ }
inc/importers/class-astra-sites-helper.php CHANGED
@@ -1,307 +1,307 @@
1
- <?php
2
- /**
3
- * Astra Site Helper
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Helper
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_Sites_Helper {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @access private
22
- * @var object Instance
23
- * @since 1.0.0
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.0
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$instance ) ) {
35
- self::$instance = new self;
36
- }
37
- return self::$instance;
38
- }
39
-
40
- /**
41
- * Constructor
42
- *
43
- * @since 1.0.0
44
- */
45
- public function __construct() {
46
- add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) );
47
- add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
48
- }
49
-
50
- /**
51
- * Add svg image support
52
- *
53
- * @since 1.1.5
54
- *
55
- * @param array $response Attachment response.
56
- * @param object $attachment Attachment object.
57
- * @param array $meta Attachment meta data.
58
- */
59
- function add_svg_image_support( $response, $attachment, $meta ) {
60
- if ( ! function_exists( 'simplexml_load_file' ) ) {
61
- return $response;
62
- }
63
-
64
- if ( ! empty( $response['sizes'] ) ) {
65
- return $response;
66
- }
67
-
68
- if ( 'image/svg+xml' !== $response['mime'] ) {
69
- return $response;
70
- }
71
-
72
- $svg_path = get_attached_file( $attachment->ID );
73
-
74
- $dimensions = self::get_svg_dimensions( $svg_path );
75
-
76
- $response['sizes'] = array(
77
- 'full' => array(
78
- 'url' => $response['url'],
79
- 'width' => $dimensions->width,
80
- 'height' => $dimensions->height,
81
- 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
82
- ),
83
- );
84
-
85
- return $response;
86
- }
87
-
88
- /**
89
- * Get SVG Dimensions
90
- *
91
- * @since 1.1.5
92
- *
93
- * @param string $svg SVG file path.
94
- * @return array Return SVG file height & width for valid SVG file.
95
- */
96
- public static function get_svg_dimensions( $svg ) {
97
-
98
- $svg = simplexml_load_file( $svg );
99
-
100
- if ( false === $svg ) {
101
- $width = '0';
102
- $height = '0';
103
- } else {
104
- $attributes = $svg->attributes();
105
- $width = (string) $attributes->width;
106
- $height = (string) $attributes->height;
107
- }
108
-
109
- return (object) array(
110
- 'width' => $width,
111
- 'height' => $height,
112
- );
113
- }
114
-
115
- /**
116
- * Custom Menu Widget
117
- *
118
- * In widget export we set the nav menu slug instead of ID.
119
- * So, In import process we check get menu id by slug and set
120
- * it in import widget process.
121
- *
122
- * @since 1.0.7
123
- *
124
- * @param object $all_sidebars Widget data.
125
- * @return object Set custom menu id by slug.
126
- */
127
- function custom_menu_widget( $all_sidebars ) {
128
-
129
- // Get current menu ID & Slugs.
130
- $menu_locations = array();
131
- $nav_menus = (object) wp_get_nav_menus();
132
- if ( isset( $nav_menus ) ) {
133
- foreach ( $nav_menus as $menu_key => $menu ) {
134
- if ( is_object( $menu ) ) {
135
- $menu_locations[ $menu->term_id ] = $menu->slug;
136
- }
137
- }
138
- }
139
-
140
- // Import widget data.
141
- $all_sidebars = (object) $all_sidebars;
142
- foreach ( $all_sidebars as $widgets_key => $widgets ) {
143
- foreach ( $widgets as $widget_key => $widget ) {
144
-
145
- // Found slug in current menu list.
146
- if ( isset( $widget->nav_menu ) ) {
147
- $menu_id = array_search( $widget->nav_menu, $menu_locations );
148
- if ( ! empty( $menu_id ) ) {
149
- $all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id;
150
- }
151
- }
152
- }
153
- }
154
-
155
- return $all_sidebars;
156
- }
157
-
158
- /**
159
- * Download File Into Uploads Directory
160
- *
161
- * @param string $file Download File URL.
162
- * @return array Downloaded file data.
163
- */
164
- public static function download_file( $file = '' ) {
165
-
166
- // Gives us access to the download_url() and wp_handle_sideload() functions.
167
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
168
-
169
- $timeout_seconds = 5;
170
-
171
- // Download file to temp dir.
172
- $temp_file = download_url( $file, $timeout_seconds );
173
-
174
- // WP Error.
175
- if ( is_wp_error( $temp_file ) ) {
176
- return array(
177
- 'success' => false,
178
- 'data' => $temp_file->get_error_message(),
179
- );
180
- }
181
-
182
- // Array based on $_FILE as seen in PHP file uploads.
183
- $file_args = array(
184
- 'name' => basename( $file ),
185
- 'tmp_name' => $temp_file,
186
- 'error' => 0,
187
- 'size' => filesize( $temp_file ),
188
- );
189
-
190
- $overrides = array(
191
-
192
- // Tells WordPress to not look for the POST form
193
- // fields that would normally be present as
194
- // we downloaded the file from a remote server, so there
195
- // will be no form fields
196
- // Default is true.
197
- 'test_form' => false,
198
-
199
- // Setting this to false lets WordPress allow empty files, not recommended.
200
- // Default is true.
201
- 'test_size' => true,
202
-
203
- // A properly uploaded file will pass this test. There should be no reason to override this one.
204
- 'test_upload' => true,
205
-
206
- );
207
-
208
- // Move the temporary file into the uploads directory.
209
- $results = wp_handle_sideload( $file_args, $overrides );
210
-
211
- if ( isset( $results['error'] ) ) {
212
- return array(
213
- 'success' => false,
214
- 'data' => $results,
215
- );
216
- }
217
-
218
- // Success.
219
- return array(
220
- 'success' => true,
221
- 'data' => $results,
222
- );
223
- }
224
-
225
- /**
226
- * Downloads an image from the specified URL.
227
- *
228
- * Taken from the core media_sideload_image() function and
229
- * modified to return an array of data instead of html.
230
- *
231
- * @since 1.0.10
232
- *
233
- * @param string $file The image file path.
234
- * @return array An array of image data.
235
- */
236
- static public function _sideload_image( $file ) {
237
- $data = new stdClass();
238
-
239
- if ( ! function_exists( 'media_handle_sideload' ) ) {
240
- require_once( ABSPATH . 'wp-admin/includes/media.php' );
241
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
242
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
243
- }
244
-
245
- if ( ! empty( $file ) ) {
246
-
247
- // Set variables for storage, fix file filename for query strings.
248
- preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
249
- $file_array = array();
250
- $file_array['name'] = basename( $matches[0] );
251
-
252
- // Download file to temp location.
253
- $file_array['tmp_name'] = download_url( $file );
254
-
255
- // If error storing temporarily, return the error.
256
- if ( is_wp_error( $file_array['tmp_name'] ) ) {
257
- return $file_array['tmp_name'];
258
- }
259
-
260
- // Do the validation and storage stuff.
261
- $id = media_handle_sideload( $file_array, 0 );
262
-
263
- // If error storing permanently, unlink.
264
- if ( is_wp_error( $id ) ) {
265
- unlink( $file_array['tmp_name'] );
266
- return $id;
267
- }
268
-
269
- // Build the object to return.
270
- $meta = wp_get_attachment_metadata( $id );
271
- $data->attachment_id = $id;
272
- $data->url = wp_get_attachment_url( $id );
273
- $data->thumbnail_url = wp_get_attachment_thumb_url( $id );
274
- $data->height = $meta['height'];
275
- $data->width = $meta['width'];
276
- }
277
-
278
- return $data;
279
- }
280
-
281
- /**
282
- * Checks to see whether a string is an image url or not.
283
- *
284
- * @since 1.0.10
285
- *
286
- * @param string $string The string to check.
287
- * @return bool Whether the string is an image url or not.
288
- */
289
- static public function _is_image_url( $string = '' ) {
290
- if ( is_string( $string ) ) {
291
-
292
- if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
293
- return true;
294
- }
295
- }
296
-
297
- return false;
298
- }
299
-
300
- }
301
-
302
- /**
303
- * Kicking this off by calling 'get_instance()' method
304
- */
305
- Astra_Sites_Helper::get_instance();
306
-
307
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Site Helper
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Helper
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Sites_Helper {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @access private
22
+ * @var object Instance
23
+ * @since 1.0.0
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.0
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$instance ) ) {
35
+ self::$instance = new self;
36
+ }
37
+ return self::$instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ public function __construct() {
46
+ add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) );
47
+ add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
48
+ }
49
+
50
+ /**
51
+ * Add svg image support
52
+ *
53
+ * @since 1.1.5
54
+ *
55
+ * @param array $response Attachment response.
56
+ * @param object $attachment Attachment object.
57
+ * @param array $meta Attachment meta data.
58
+ */
59
+ function add_svg_image_support( $response, $attachment, $meta ) {
60
+ if ( ! function_exists( 'simplexml_load_file' ) ) {
61
+ return $response;
62
+ }
63
+
64
+ if ( ! empty( $response['sizes'] ) ) {
65
+ return $response;
66
+ }
67
+
68
+ if ( 'image/svg+xml' !== $response['mime'] ) {
69
+ return $response;
70
+ }
71
+
72
+ $svg_path = get_attached_file( $attachment->ID );
73
+
74
+ $dimensions = self::get_svg_dimensions( $svg_path );
75
+
76
+ $response['sizes'] = array(
77
+ 'full' => array(
78
+ 'url' => $response['url'],
79
+ 'width' => $dimensions->width,
80
+ 'height' => $dimensions->height,
81
+ 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
82
+ ),
83
+ );
84
+
85
+ return $response;
86
+ }
87
+
88
+ /**
89
+ * Get SVG Dimensions
90
+ *
91
+ * @since 1.1.5
92
+ *
93
+ * @param string $svg SVG file path.
94
+ * @return array Return SVG file height & width for valid SVG file.
95
+ */
96
+ public static function get_svg_dimensions( $svg ) {
97
+
98
+ $svg = simplexml_load_file( $svg );
99
+
100
+ if ( false === $svg ) {
101
+ $width = '0';
102
+ $height = '0';
103
+ } else {
104
+ $attributes = $svg->attributes();
105
+ $width = (string) $attributes->width;
106
+ $height = (string) $attributes->height;
107
+ }
108
+
109
+ return (object) array(
110
+ 'width' => $width,
111
+ 'height' => $height,
112
+ );
113
+ }
114
+
115
+ /**
116
+ * Custom Menu Widget
117
+ *
118
+ * In widget export we set the nav menu slug instead of ID.
119
+ * So, In import process we check get menu id by slug and set
120
+ * it in import widget process.
121
+ *
122
+ * @since 1.0.7
123
+ *
124
+ * @param object $all_sidebars Widget data.
125
+ * @return object Set custom menu id by slug.
126
+ */
127
+ function custom_menu_widget( $all_sidebars ) {
128
+
129
+ // Get current menu ID & Slugs.
130
+ $menu_locations = array();
131
+ $nav_menus = (object) wp_get_nav_menus();
132
+ if ( isset( $nav_menus ) ) {
133
+ foreach ( $nav_menus as $menu_key => $menu ) {
134
+ if ( is_object( $menu ) ) {
135
+ $menu_locations[ $menu->term_id ] = $menu->slug;
136
+ }
137
+ }
138
+ }
139
+
140
+ // Import widget data.
141
+ $all_sidebars = (object) $all_sidebars;
142
+ foreach ( $all_sidebars as $widgets_key => $widgets ) {
143
+ foreach ( $widgets as $widget_key => $widget ) {
144
+
145
+ // Found slug in current menu list.
146
+ if ( isset( $widget->nav_menu ) ) {
147
+ $menu_id = array_search( $widget->nav_menu, $menu_locations );
148
+ if ( ! empty( $menu_id ) ) {
149
+ $all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id;
150
+ }
151
+ }
152
+ }
153
+ }
154
+
155
+ return $all_sidebars;
156
+ }
157
+
158
+ /**
159
+ * Download File Into Uploads Directory
160
+ *
161
+ * @param string $file Download File URL.
162
+ * @return array Downloaded file data.
163
+ */
164
+ public static function download_file( $file = '' ) {
165
+
166
+ // Gives us access to the download_url() and wp_handle_sideload() functions.
167
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
168
+
169
+ $timeout_seconds = 5;
170
+
171
+ // Download file to temp dir.
172
+ $temp_file = download_url( $file, $timeout_seconds );
173
+
174
+ // WP Error.
175
+ if ( is_wp_error( $temp_file ) ) {
176
+ return array(
177
+ 'success' => false,
178
+ 'data' => $temp_file->get_error_message(),
179
+ );
180
+ }
181
+
182
+ // Array based on $_FILE as seen in PHP file uploads.
183
+ $file_args = array(
184
+ 'name' => basename( $file ),
185
+ 'tmp_name' => $temp_file,
186
+ 'error' => 0,
187
+ 'size' => filesize( $temp_file ),
188
+ );
189
+
190
+ $overrides = array(
191
+
192
+ // Tells WordPress to not look for the POST form
193
+ // fields that would normally be present as
194
+ // we downloaded the file from a remote server, so there
195
+ // will be no form fields
196
+ // Default is true.
197
+ 'test_form' => false,
198
+
199
+ // Setting this to false lets WordPress allow empty files, not recommended.
200
+ // Default is true.
201
+ 'test_size' => true,
202
+
203
+ // A properly uploaded file will pass this test. There should be no reason to override this one.
204
+ 'test_upload' => true,
205
+
206
+ );
207
+
208
+ // Move the temporary file into the uploads directory.
209
+ $results = wp_handle_sideload( $file_args, $overrides );
210
+
211
+ if ( isset( $results['error'] ) ) {
212
+ return array(
213
+ 'success' => false,
214
+ 'data' => $results,
215
+ );
216
+ }
217
+
218
+ // Success.
219
+ return array(
220
+ 'success' => true,
221
+ 'data' => $results,
222
+ );
223
+ }
224
+
225
+ /**
226
+ * Downloads an image from the specified URL.
227
+ *
228
+ * Taken from the core media_sideload_image() function and
229
+ * modified to return an array of data instead of html.
230
+ *
231
+ * @since 1.0.10
232
+ *
233
+ * @param string $file The image file path.
234
+ * @return array An array of image data.
235
+ */
236
+ static public function _sideload_image( $file ) {
237
+ $data = new stdClass();
238
+
239
+ if ( ! function_exists( 'media_handle_sideload' ) ) {
240
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
241
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
242
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
243
+ }
244
+
245
+ if ( ! empty( $file ) ) {
246
+
247
+ // Set variables for storage, fix file filename for query strings.
248
+ preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
249
+ $file_array = array();
250
+ $file_array['name'] = basename( $matches[0] );
251
+
252
+ // Download file to temp location.
253
+ $file_array['tmp_name'] = download_url( $file );
254
+
255
+ // If error storing temporarily, return the error.
256
+ if ( is_wp_error( $file_array['tmp_name'] ) ) {
257
+ return $file_array['tmp_name'];
258
+ }
259
+
260
+ // Do the validation and storage stuff.
261
+ $id = media_handle_sideload( $file_array, 0 );
262
+
263
+ // If error storing permanently, unlink.
264
+ if ( is_wp_error( $id ) ) {
265
+ unlink( $file_array['tmp_name'] );
266
+ return $id;
267
+ }
268
+
269
+ // Build the object to return.
270
+ $meta = wp_get_attachment_metadata( $id );
271
+ $data->attachment_id = $id;
272
+ $data->url = wp_get_attachment_url( $id );
273
+ $data->thumbnail_url = wp_get_attachment_thumb_url( $id );
274
+ $data->height = $meta['height'];
275
+ $data->width = $meta['width'];
276
+ }
277
+
278
+ return $data;
279
+ }
280
+
281
+ /**
282
+ * Checks to see whether a string is an image url or not.
283
+ *
284
+ * @since 1.0.10
285
+ *
286
+ * @param string $string The string to check.
287
+ * @return bool Whether the string is an image url or not.
288
+ */
289
+ static public function _is_image_url( $string = '' ) {
290
+ if ( is_string( $string ) ) {
291
+
292
+ if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
293
+ return true;
294
+ }
295
+ }
296
+
297
+ return false;
298
+ }
299
+
300
+ }
301
+
302
+ /**
303
+ * Kicking this off by calling 'get_instance()' method
304
+ */
305
+ Astra_Sites_Helper::get_instance();
306
+
307
+ endif;
inc/importers/wxr-importer/class-astra-wxr-importer.php CHANGED
@@ -1,331 +1,331 @@
1
- <?php
2
- /**
3
- * Class Astra WXR Importer
4
- *
5
- * @since 1.0.0
6
- * @package Astra Addon
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Class Astra WXR Importer
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_WXR_Importer {
17
-
18
- /**
19
- * Instance of Astra_WXR_Importer
20
- *
21
- * @since 1.0.0
22
- * @var Astra_WXR_Importer
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Instantiate Astra_WXR_Importer
28
- *
29
- * @since 1.0.0
30
- * @return (Object) Astra_WXR_Importer.
31
- */
32
- public static function instance() {
33
- if ( ! isset( self::$_instance ) ) {
34
- self::$_instance = new self();
35
- }
36
-
37
- return self::$_instance;
38
- }
39
-
40
- /**
41
- * Constructor.
42
- *
43
- * @since 1.0.0
44
- */
45
- private function __construct() {
46
-
47
- if ( ! class_exists( 'WP_Importer' ) ) {
48
- defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
49
- require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
50
- }
51
-
52
- if ( ! class_exists( 'WP_Importer_Logger' ) ) {
53
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
54
- }
55
-
56
- if ( ! class_exists( 'WP_Importer_Logger_ServerSentEvents' ) ) {
57
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
58
- }
59
-
60
- if ( ! class_exists( 'WXR_Importer' ) ) {
61
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
62
- }
63
-
64
- if ( ! class_exists( 'WXR_Import_Info' ) ) {
65
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
66
- }
67
-
68
- add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
69
- add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
70
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
71
- }
72
-
73
- /**
74
- * Constructor.
75
- *
76
- * @since 1.1.0
77
- */
78
- function sse_import() {
79
-
80
- // Start the event stream.
81
- header( 'Content-Type: text/event-stream' );
82
-
83
- // Turn off PHP output compression.
84
- $previous = error_reporting( error_reporting() ^ E_WARNING );
85
- ini_set( 'output_buffering', 'off' );
86
- ini_set( 'zlib.output_compression', false );
87
- error_reporting( $previous );
88
-
89
- if ( $GLOBALS['is_nginx'] ) {
90
- // Setting this header instructs Nginx to disable fastcgi_buffering
91
- // and disable gzip for this request.
92
- header( 'X-Accel-Buffering: no' );
93
- header( 'Content-Encoding: none' );
94
- }
95
-
96
- $xml_url = urldecode( $_REQUEST['xml_url'] );
97
- if ( empty( $xml_url ) ) {
98
- exit;
99
- }
100
-
101
- // 2KB padding for IE
102
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
103
-
104
- // Time to run the import!
105
- set_time_limit( 0 );
106
-
107
- // Ensure we're not buffered.
108
- wp_ob_end_flush_all();
109
- flush();
110
-
111
- // Are we allowed to create users?
112
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
113
-
114
- // Keep track of our progress.
115
- add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
116
- add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
117
- add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
118
- add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
119
- add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
120
- add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
121
- add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
122
- add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
123
- add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
124
- add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
125
- add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
126
- // Flush once more.
127
- flush();
128
-
129
- $importer = $this->get_importer();
130
- $response = $importer->import( $xml_url );
131
-
132
- // Let the browser know we're done.
133
- $complete = array(
134
- 'action' => 'complete',
135
- 'error' => false,
136
- );
137
- if ( is_wp_error( $response ) ) {
138
- $complete['error'] = $response->get_error_message();
139
- }
140
-
141
- $this->emit_sse_message( $complete );
142
- exit;
143
- }
144
-
145
- /**
146
- * Add .xml files as supported format in the uploader.
147
- *
148
- * @since 1.1.5 Added SVG file support.
149
- *
150
- * @since 1.0.0
151
- *
152
- * @param array $mimes Already supported mime types.
153
- */
154
- public function custom_upload_mimes( $mimes ) {
155
-
156
- // Allow SVG files.
157
- $mimes['svg'] = 'image/svg+xml';
158
- $mimes['svgz'] = 'image/svg+xml';
159
-
160
- // Allow XML files.
161
- $mimes['xml'] = 'application/xml';
162
-
163
- return $mimes;
164
- }
165
-
166
- /**
167
- * Start the xml import.
168
- *
169
- * @since 1.0.0
170
- *
171
- * @param (String) $path Absolute path to the XML file.
172
- */
173
- public function get_xml_data( $path ) {
174
-
175
- $args = array(
176
- 'action' => 'astra-wxr-import',
177
- 'id' => '1',
178
- 'xml_url' => $path,
179
- );
180
- $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
181
-
182
- $data = $this->get_data( $path );
183
-
184
- return array(
185
- 'count' => array(
186
- 'posts' => $data->post_count,
187
- 'media' => $data->media_count,
188
- 'users' => count( $data->users ),
189
- 'comments' => $data->comment_count,
190
- 'terms' => $data->term_count,
191
- ),
192
- 'url' => $url,
193
- 'strings' => array(
194
- 'complete' => __( 'Import complete!', 'astra-sites' ),
195
- ),
196
- );
197
- }
198
-
199
- /**
200
- * Get XML data.
201
- *
202
- * @since 1.1.0
203
- * @param string $url Downloaded XML file absolute URL.
204
- * @return array XML file data.
205
- */
206
- function get_data( $url ) {
207
- $importer = $this->get_importer();
208
- $data = $importer->get_preliminary_information( $url );
209
- if ( is_wp_error( $data ) ) {
210
- return $data;
211
- }
212
- return $data;
213
- }
214
-
215
- /**
216
- * Get Importer
217
- *
218
- * @since 1.1.0
219
- * @return object Importer object.
220
- */
221
- public function get_importer() {
222
- $options = apply_filters(
223
- 'astra_sites_xml_import_options', array(
224
- 'fetch_attachments' => true,
225
- 'default_author' => get_current_user_id(),
226
- )
227
- );
228
- $importer = new WXR_Importer( $options );
229
- $logger = new WP_Importer_Logger_ServerSentEvents();
230
-
231
- $importer->set_logger( $logger );
232
- return $importer;
233
- }
234
-
235
- /**
236
- * Send message when a post has been imported.
237
- *
238
- * @since 1.1.0
239
- * @param int $id Post ID.
240
- * @param array $data Post data saved to the DB.
241
- */
242
- public function imported_post( $id, $data ) {
243
- $this->emit_sse_message(
244
- array(
245
- 'action' => 'updateDelta',
246
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
247
- 'delta' => 1,
248
- )
249
- );
250
- }
251
-
252
- /**
253
- * Send message when a post is marked as already imported.
254
- *
255
- * @since 1.1.0
256
- * @param array $data Post data saved to the DB.
257
- */
258
- public function already_imported_post( $data ) {
259
- $this->emit_sse_message(
260
- array(
261
- 'action' => 'updateDelta',
262
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
263
- 'delta' => 1,
264
- )
265
- );
266
- }
267
-
268
- /**
269
- * Send message when a comment has been imported.
270
- *
271
- * @since 1.1.0
272
- */
273
- public function imported_comment() {
274
- $this->emit_sse_message(
275
- array(
276
- 'action' => 'updateDelta',
277
- 'type' => 'comments',
278
- 'delta' => 1,
279
- )
280
- );
281
- }
282
-
283
- /**
284
- * Send message when a term has been imported.
285
- *
286
- * @since 1.1.0
287
- */
288
- public function imported_term() {
289
- $this->emit_sse_message(
290
- array(
291
- 'action' => 'updateDelta',
292
- 'type' => 'terms',
293
- 'delta' => 1,
294
- )
295
- );
296
- }
297
-
298
- /**
299
- * Send message when a user has been imported.
300
- *
301
- * @since 1.1.0
302
- */
303
- public function imported_user() {
304
- $this->emit_sse_message(
305
- array(
306
- 'action' => 'updateDelta',
307
- 'type' => 'users',
308
- 'delta' => 1,
309
- )
310
- );
311
- }
312
-
313
- /**
314
- * Emit a Server-Sent Events message.
315
- *
316
- * @since 1.1.0
317
- * @param mixed $data Data to be JSON-encoded and sent in the message.
318
- */
319
- public function emit_sse_message( $data ) {
320
- echo "event: message\n";
321
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
322
-
323
- // Extra padding.
324
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
325
-
326
- flush();
327
- }
328
-
329
- }
330
-
331
- Astra_WXR_Importer::instance();
1
+ <?php
2
+ /**
3
+ * Class Astra WXR Importer
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Addon
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Class Astra WXR Importer
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_WXR_Importer {
17
+
18
+ /**
19
+ * Instance of Astra_WXR_Importer
20
+ *
21
+ * @since 1.0.0
22
+ * @var Astra_WXR_Importer
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Instantiate Astra_WXR_Importer
28
+ *
29
+ * @since 1.0.0
30
+ * @return (Object) Astra_WXR_Importer.
31
+ */
32
+ public static function instance() {
33
+ if ( ! isset( self::$_instance ) ) {
34
+ self::$_instance = new self();
35
+ }
36
+
37
+ return self::$_instance;
38
+ }
39
+
40
+ /**
41
+ * Constructor.
42
+ *
43
+ * @since 1.0.0
44
+ */
45
+ private function __construct() {
46
+
47
+ if ( ! class_exists( 'WP_Importer' ) ) {
48
+ defined( 'WP_LOAD_IMPORTERS' ) || define( 'WP_LOAD_IMPORTERS', true );
49
+ require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
50
+ }
51
+
52
+ if ( ! class_exists( 'WP_Importer_Logger' ) ) {
53
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
54
+ }
55
+
56
+ if ( ! class_exists( 'WP_Importer_Logger_ServerSentEvents' ) ) {
57
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
58
+ }
59
+
60
+ if ( ! class_exists( 'WXR_Importer' ) ) {
61
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
62
+ }
63
+
64
+ if ( ! class_exists( 'WXR_Import_Info' ) ) {
65
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
66
+ }
67
+
68
+ add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
69
+ add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
70
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
71
+ }
72
+
73
+ /**
74
+ * Constructor.
75
+ *
76
+ * @since 1.1.0
77
+ */
78
+ function sse_import() {
79
+
80
+ // Start the event stream.
81
+ header( 'Content-Type: text/event-stream' );
82
+
83
+ // Turn off PHP output compression.
84
+ $previous = error_reporting( error_reporting() ^ E_WARNING );
85
+ ini_set( 'output_buffering', 'off' );
86
+ ini_set( 'zlib.output_compression', false );
87
+ error_reporting( $previous );
88
+
89
+ if ( $GLOBALS['is_nginx'] ) {
90
+ // Setting this header instructs Nginx to disable fastcgi_buffering
91
+ // and disable gzip for this request.
92
+ header( 'X-Accel-Buffering: no' );
93
+ header( 'Content-Encoding: none' );
94
+ }
95
+
96
+ $xml_url = urldecode( $_REQUEST['xml_url'] );
97
+ if ( empty( $xml_url ) ) {
98
+ exit;
99
+ }
100
+
101
+ // 2KB padding for IE
102
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
103
+
104
+ // Time to run the import!
105
+ set_time_limit( 0 );
106
+
107
+ // Ensure we're not buffered.
108
+ wp_ob_end_flush_all();
109
+ flush();
110
+
111
+ // Are we allowed to create users?
112
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
113
+
114
+ // Keep track of our progress.
115
+ add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
116
+ add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
117
+ add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
118
+ add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
119
+ add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
120
+ add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
121
+ add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
122
+ add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
123
+ add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
124
+ add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
125
+ add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
126
+ // Flush once more.
127
+ flush();
128
+
129
+ $importer = $this->get_importer();
130
+ $response = $importer->import( $xml_url );
131
+
132
+ // Let the browser know we're done.
133
+ $complete = array(
134
+ 'action' => 'complete',
135
+ 'error' => false,
136
+ );
137
+ if ( is_wp_error( $response ) ) {
138
+ $complete['error'] = $response->get_error_message();
139
+ }
140
+
141
+ $this->emit_sse_message( $complete );
142
+ exit;
143
+ }
144
+
145
+ /**
146
+ * Add .xml files as supported format in the uploader.
147
+ *
148
+ * @since 1.1.5 Added SVG file support.
149
+ *
150
+ * @since 1.0.0
151
+ *
152
+ * @param array $mimes Already supported mime types.
153
+ */
154
+ public function custom_upload_mimes( $mimes ) {
155
+
156
+ // Allow SVG files.
157
+ $mimes['svg'] = 'image/svg+xml';
158
+ $mimes['svgz'] = 'image/svg+xml';
159
+
160
+ // Allow XML files.
161
+ $mimes['xml'] = 'application/xml';
162
+
163
+ return $mimes;
164
+ }
165
+
166
+ /**
167
+ * Start the xml import.
168
+ *
169
+ * @since 1.0.0
170
+ *
171
+ * @param (String) $path Absolute path to the XML file.
172
+ */
173
+ public function get_xml_data( $path ) {
174
+
175
+ $args = array(
176
+ 'action' => 'astra-wxr-import',
177
+ 'id' => '1',
178
+ 'xml_url' => $path,
179
+ );
180
+ $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
181
+
182
+ $data = $this->get_data( $path );
183
+
184
+ return array(
185
+ 'count' => array(
186
+ 'posts' => $data->post_count,
187
+ 'media' => $data->media_count,
188
+ 'users' => count( $data->users ),
189
+ 'comments' => $data->comment_count,
190
+ 'terms' => $data->term_count,
191
+ ),
192
+ 'url' => $url,
193
+ 'strings' => array(
194
+ 'complete' => __( 'Import complete!', 'astra-sites' ),
195
+ ),
196
+ );
197
+ }
198
+
199
+ /**
200
+ * Get XML data.
201
+ *
202
+ * @since 1.1.0
203
+ * @param string $url Downloaded XML file absolute URL.
204
+ * @return array XML file data.
205
+ */
206
+ function get_data( $url ) {
207
+ $importer = $this->get_importer();
208
+ $data = $importer->get_preliminary_information( $url );
209
+ if ( is_wp_error( $data ) ) {
210
+ return $data;
211
+ }
212
+ return $data;
213
+ }
214
+
215
+ /**
216
+ * Get Importer
217
+ *
218
+ * @since 1.1.0
219
+ * @return object Importer object.
220
+ */
221
+ public function get_importer() {
222
+ $options = apply_filters(
223
+ 'astra_sites_xml_import_options', array(
224
+ 'fetch_attachments' => true,
225
+ 'default_author' => get_current_user_id(),
226
+ )
227
+ );
228
+ $importer = new WXR_Importer( $options );
229
+ $logger = new WP_Importer_Logger_ServerSentEvents();
230
+
231
+ $importer->set_logger( $logger );
232
+ return $importer;
233
+ }
234
+
235
+ /**
236
+ * Send message when a post has been imported.
237
+ *
238
+ * @since 1.1.0
239
+ * @param int $id Post ID.
240
+ * @param array $data Post data saved to the DB.
241
+ */
242
+ public function imported_post( $id, $data ) {
243
+ $this->emit_sse_message(
244
+ array(
245
+ 'action' => 'updateDelta',
246
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
247
+ 'delta' => 1,
248
+ )
249
+ );
250
+ }
251
+
252
+ /**
253
+ * Send message when a post is marked as already imported.
254
+ *
255
+ * @since 1.1.0
256
+ * @param array $data Post data saved to the DB.
257
+ */
258
+ public function already_imported_post( $data ) {
259
+ $this->emit_sse_message(
260
+ array(
261
+ 'action' => 'updateDelta',
262
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
263
+ 'delta' => 1,
264
+ )
265
+ );
266
+ }
267
+
268
+ /**
269
+ * Send message when a comment has been imported.
270
+ *
271
+ * @since 1.1.0
272
+ */
273
+ public function imported_comment() {
274
+ $this->emit_sse_message(
275
+ array(
276
+ 'action' => 'updateDelta',
277
+ 'type' => 'comments',
278
+ 'delta' => 1,
279
+ )
280
+ );
281
+ }
282
+
283
+ /**
284
+ * Send message when a term has been imported.
285
+ *
286
+ * @since 1.1.0
287
+ */
288
+ public function imported_term() {
289
+ $this->emit_sse_message(
290
+ array(
291
+ 'action' => 'updateDelta',
292
+ 'type' => 'terms',
293
+ 'delta' => 1,
294
+ )
295
+ );
296
+ }
297
+
298
+ /**
299
+ * Send message when a user has been imported.
300
+ *
301
+ * @since 1.1.0
302
+ */
303
+ public function imported_user() {
304
+ $this->emit_sse_message(
305
+ array(
306
+ 'action' => 'updateDelta',
307
+ 'type' => 'users',
308
+ 'delta' => 1,
309
+ )
310
+ );
311
+ }
312
+
313
+ /**
314
+ * Emit a Server-Sent Events message.
315
+ *
316
+ * @since 1.1.0
317
+ * @param mixed $data Data to be JSON-encoded and sent in the message.
318
+ */
319
+ public function emit_sse_message( $data ) {
320
+ echo "event: message\n";
321
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
322
+
323
+ // Extra padding.
324
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
325
+
326
+ flush();
327
+ }
328
+
329
+ }
330
+
331
+ Astra_WXR_Importer::instance();
inc/includes/admin-page.php CHANGED
@@ -53,10 +53,12 @@ defined( 'ABSPATH' ) or exit;
53
  </div>
54
 
55
  <div class="select-page-builder">
56
- <h3>
57
- <span class="up-arrow dashicons dashicons-editor-break"></span>
58
- <span class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></span>
59
- </h3>
 
 
60
  <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/sites-screenshot.jpg' ); ?>" alt="<?php _e( 'Sites List..', 'astra-sites' ); ?>" title="<?php _e( 'Sites List..', 'astra-sites' ); ?>" />
61
  </div>
62
 
53
  </div>
54
 
55
  <div class="select-page-builder">
56
+ <div class="note-wrap">
57
+ <h3>
58
+ <span class="up-arrow dashicons dashicons-editor-break"></span>
59
+ <div class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></div>
60
+ </h3>
61
+ </div>
62
  <img src="<?php echo esc_url( ASTRA_SITES_URI . 'inc/assets/images/sites-screenshot.jpg' ); ?>" alt="<?php _e( 'Sites List..', 'astra-sites' ); ?>" title="<?php _e( 'Sites List..', 'astra-sites' ); ?>" />
63
  </div>
64
 
languages/astra-sites.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the Astra Starter Sites package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Astra Starter Sites 1.1.8\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
- "POT-Creation-Date: 2018-03-05 06:49:12+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -144,7 +144,7 @@ msgstr ""
144
  msgid "Importing.."
145
  msgstr ""
146
 
147
- #: inc/classes/class-astra-sites.php:227 inc/includes/admin-page.php:110
148
  msgid "Read more"
149
  msgstr ""
150
 
@@ -156,7 +156,7 @@ msgstr ""
156
  msgid "There was a problem receiving a response from server."
157
  msgstr ""
158
 
159
- #: inc/classes/class-astra-sites.php:230 inc/includes/admin-page.php:257
160
  msgid "No Demos found, Try a different search."
161
  msgstr ""
162
 
@@ -497,75 +497,75 @@ msgstr ""
497
  msgid "Search Sites..."
498
  msgstr ""
499
 
500
- #: inc/includes/admin-page.php:58
501
  msgid "Select Your Favorite Page Builder"
502
  msgstr ""
503
 
504
- #: inc/includes/admin-page.php:60
505
  msgid "Sites List.."
506
  msgstr ""
507
 
508
- #: inc/includes/admin-page.php:91
509
  msgid "Close"
510
  msgstr ""
511
 
512
- #: inc/includes/admin-page.php:92
513
  msgid "Previous"
514
  msgstr ""
515
 
516
- #: inc/includes/admin-page.php:93
517
  msgid "Next"
518
  msgstr ""
519
 
520
- #: inc/includes/admin-page.php:94 inc/includes/admin-page.php:122
521
  msgid "Install Plugins"
522
  msgstr ""
523
 
524
- #: inc/includes/admin-page.php:113
525
  msgid "Required Plugins"
526
  msgstr ""
527
 
528
- #: inc/includes/admin-page.php:128
529
  msgid "Collapse"
530
  msgstr ""
531
 
532
- #: inc/includes/admin-page.php:134
533
  msgid "Enter desktop preview mode"
534
  msgstr ""
535
 
536
- #: inc/includes/admin-page.php:137
537
  msgid "Enter tablet preview mode"
538
  msgstr ""
539
 
540
- #: inc/includes/admin-page.php:140
541
  msgid "Enter mobile preview mode"
542
  msgstr ""
543
 
544
- #: inc/includes/admin-page.php:148 inc/includes/admin-page.php:249
545
  msgid "Preview"
546
  msgstr ""
547
 
548
- #: inc/includes/admin-page.php:163
549
  #. translators: %1$s & %2$s are a Demo API URL
550
  msgid ""
551
  "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
552
  "unreachable from your site.</p>"
553
  msgstr ""
554
 
555
- #: inc/includes/admin-page.php:165
556
  msgid ""
557
  "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
558
  "temporary issues. No kidding!</p>"
559
  msgstr ""
560
 
561
- #: inc/includes/admin-page.php:167
562
  msgid ""
563
  "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
564
  "to your server administrator and check if demo server is being blocked by "
565
  "the firewall!</p>"
566
  msgstr ""
567
 
568
- #: inc/includes/admin-page.php:170
569
  #. translators: %1$s is a support link
570
  msgid ""
571
  "<p>If that does not help, please open up a <a href=\"%1$s\" "
@@ -573,11 +573,11 @@ msgid ""
573
  "for you.</p>"
574
  msgstr ""
575
 
576
- #: inc/includes/admin-page.php:238
577
  msgid "Details &amp; Preview"
578
  msgstr ""
579
 
580
- #: inc/includes/admin-page.php:261 inc/includes/admin-page.php:279
581
  #. translators: %1$s External Link
582
  msgid ""
583
  "Don't see a site that you would like to import?<br><a target=\"_blank\" "
2
  # This file is distributed under the same license as the Astra Starter Sites package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Astra Starter Sites 1.1.9\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
+ "POT-Creation-Date: 2018-03-12 13:23:13+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=utf-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
144
  msgid "Importing.."
145
  msgstr ""
146
 
147
+ #: inc/classes/class-astra-sites.php:227 inc/includes/admin-page.php:112
148
  msgid "Read more"
149
  msgstr ""
150
 
156
  msgid "There was a problem receiving a response from server."
157
  msgstr ""
158
 
159
+ #: inc/classes/class-astra-sites.php:230 inc/includes/admin-page.php:259
160
  msgid "No Demos found, Try a different search."
161
  msgstr ""
162
 
497
  msgid "Search Sites..."
498
  msgstr ""
499
 
500
+ #: inc/includes/admin-page.php:59
501
  msgid "Select Your Favorite Page Builder"
502
  msgstr ""
503
 
504
+ #: inc/includes/admin-page.php:62
505
  msgid "Sites List.."
506
  msgstr ""
507
 
508
+ #: inc/includes/admin-page.php:93
509
  msgid "Close"
510
  msgstr ""
511
 
512
+ #: inc/includes/admin-page.php:94
513
  msgid "Previous"
514
  msgstr ""
515
 
516
+ #: inc/includes/admin-page.php:95
517
  msgid "Next"
518
  msgstr ""
519
 
520
+ #: inc/includes/admin-page.php:96 inc/includes/admin-page.php:124
521
  msgid "Install Plugins"
522
  msgstr ""
523
 
524
+ #: inc/includes/admin-page.php:115
525
  msgid "Required Plugins"
526
  msgstr ""
527
 
528
+ #: inc/includes/admin-page.php:130
529
  msgid "Collapse"
530
  msgstr ""
531
 
532
+ #: inc/includes/admin-page.php:136
533
  msgid "Enter desktop preview mode"
534
  msgstr ""
535
 
536
+ #: inc/includes/admin-page.php:139
537
  msgid "Enter tablet preview mode"
538
  msgstr ""
539
 
540
+ #: inc/includes/admin-page.php:142
541
  msgid "Enter mobile preview mode"
542
  msgstr ""
543
 
544
+ #: inc/includes/admin-page.php:150 inc/includes/admin-page.php:251
545
  msgid "Preview"
546
  msgstr ""
547
 
548
+ #: inc/includes/admin-page.php:165
549
  #. translators: %1$s & %2$s are a Demo API URL
550
  msgid ""
551
  "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
552
  "unreachable from your site.</p>"
553
  msgstr ""
554
 
555
+ #: inc/includes/admin-page.php:167
556
  msgid ""
557
  "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
558
  "temporary issues. No kidding!</p>"
559
  msgstr ""
560
 
561
+ #: inc/includes/admin-page.php:169
562
  msgid ""
563
  "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
564
  "to your server administrator and check if demo server is being blocked by "
565
  "the firewall!</p>"
566
  msgstr ""
567
 
568
+ #: inc/includes/admin-page.php:172
569
  #. translators: %1$s is a support link
570
  msgid ""
571
  "<p>If that does not help, please open up a <a href=\"%1$s\" "
573
  "for you.</p>"
574
  msgstr ""
575
 
576
+ #: inc/includes/admin-page.php:240
577
  msgid "Details &amp; Preview"
578
  msgstr ""
579
 
580
+ #: inc/includes/admin-page.php:263 inc/includes/admin-page.php:281
581
  #. translators: %1$s External Link
582
  msgid ""
583
  "Don't see a site that you would like to import?<br><a target=\"_blank\" "
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: demo, theme demos, one click import
5
  Requires at least: 4.4
6
  Requires PHP: 5.3
7
  Tested up to: 4.9.1
8
- Stable tag: 1.1.8
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -57,6 +57,9 @@ https://wpastra.com/sites-suggestions/
57
 
58
  == Changelog ==
59
 
 
 
 
60
  v1.1.8 - 5-March-2018
61
  * Improvements: Updated processing button animation while installation/activating plugin and importing site.
62
  * Improvements: Updated suggestion box message.
5
  Requires at least: 4.4
6
  Requires PHP: 5.3
7
  Tested up to: 4.9.1
8
+ Stable tag: 1.1.9
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
57
 
58
  == Changelog ==
59
 
60
+ v1.1.9 - 12-March-2018
61
+ * Fix: String `Select Your Favorite Page Builder` jerk while loading the sites.
62
+
63
  v1.1.8 - 5-March-2018
64
  * Improvements: Updated processing button animation while installation/activating plugin and importing site.
65
  * Improvements: Updated suggestion box message.