Astra Starter Sites - Version 1.3.0

Version Description

Download this release

Release Info

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

Code changes from version 1.2.15 to 1.3.0

Files changed (36) hide show
  1. astra-sites.php +54 -54
  2. inc/assets/css/admin.css +637 -475
  3. inc/assets/js/admin-page.js +1814 -1438
  4. inc/assets/js/astra-sites-api.js +64 -56
  5. inc/assets/js/astra-sites-notices.js +20 -20
  6. inc/assets/js/eventsource.js +673 -673
  7. inc/assets/js/eventsource.min.js +5 -5
  8. inc/assets/js/render-grid.js +596 -591
  9. inc/classes/class-astra-sites-importer-log.php +601 -510
  10. inc/classes/class-astra-sites-importer.php +573 -407
  11. inc/classes/class-astra-sites-page.php +360 -294
  12. inc/classes/class-astra-sites-white-label.php +239 -238
  13. inc/classes/class-astra-sites.php +518 -471
  14. inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php +299 -302
  15. inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php +261 -263
  16. inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php +125 -126
  17. inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php +111 -113
  18. inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php +137 -139
  19. inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php +97 -98
  20. inc/importers/batch-processing/class-astra-sites-batch-processing.php +209 -209
  21. inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php +263 -280
  22. inc/importers/batch-processing/helpers/class-wp-async-request.php +164 -164
  23. inc/importers/batch-processing/helpers/class-wp-background-process-astra.php +65 -67
  24. inc/importers/batch-processing/helpers/class-wp-background-process.php +513 -513
  25. inc/importers/class-astra-customizer-import.php +88 -88
  26. inc/importers/class-astra-site-options-import.php +289 -287
  27. inc/importers/class-astra-sites-helper.php +311 -311
  28. inc/importers/class-widgets-importer.php +278 -278
  29. inc/importers/wxr-importer/class-astra-wxr-importer.php +441 -416
  30. inc/importers/wxr-importer/class-logger.php +139 -142
  31. inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php +43 -46
  32. inc/importers/wxr-importer/class-wxr-import-info.php +20 -20
  33. inc/importers/wxr-importer/class-wxr-importer.php +2300 -2300
  34. inc/includes/admin-page.php +401 -348
  35. languages/astra-sites.pot +774 -720
  36. readme.txt +295 -288
astra-sites.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
4
- * Plugin URI: http://www.wpastra.com/pro/
5
- * Description: Import free sites build with Astra theme.
6
- * Version: 1.2.15
7
- * Author: Brainstorm Force
8
- * Author URI: http://www.brainstormforce.com
9
- * Text Domain: astra-sites
10
- *
11
- * @package Astra Sites
12
- */
13
-
14
- /**
15
- * Set constants.
16
- */
17
- if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
18
- define( 'ASTRA_SITES_NAME', __( 'Astra Sites', 'astra-sites' ) );
19
- }
20
-
21
- if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
- define( 'ASTRA_SITES_VER', '1.2.15' );
23
- }
24
-
25
- if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
26
- define( 'ASTRA_SITES_FILE', __FILE__ );
27
- }
28
-
29
- if ( ! defined( 'ASTRA_SITES_BASE' ) ) {
30
- define( 'ASTRA_SITES_BASE', plugin_basename( ASTRA_SITES_FILE ) );
31
- }
32
-
33
- if ( ! defined( 'ASTRA_SITES_DIR' ) ) {
34
- define( 'ASTRA_SITES_DIR', plugin_dir_path( ASTRA_SITES_FILE ) );
35
- }
36
-
37
- if ( ! defined( 'ASTRA_SITES_URI' ) ) {
38
- define( 'ASTRA_SITES_URI', plugins_url( '/', ASTRA_SITES_FILE ) );
39
- }
40
-
41
- if ( ! function_exists( 'astra_sites_setup' ) ) :
42
-
43
- /**
44
- * Astra Sites Setup
45
- *
46
- * @since 1.0.5
47
- */
48
- function astra_sites_setup() {
49
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites.php';
50
- }
51
-
52
- add_action( 'plugins_loaded', 'astra_sites_setup' );
53
-
54
- endif;
1
+ <?php
2
+ /**
3
+ * Plugin Name: Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates
4
+ * Plugin URI: http://www.wpastra.com/pro/
5
+ * Description: Import free sites build with Astra theme.
6
+ * Version: 1.3.0
7
+ * Author: Brainstorm Force
8
+ * Author URI: http://www.brainstormforce.com
9
+ * Text Domain: astra-sites
10
+ *
11
+ * @package Astra Sites
12
+ */
13
+
14
+ /**
15
+ * Set constants.
16
+ */
17
+ if ( ! defined( 'ASTRA_SITES_NAME' ) ) {
18
+ define( 'ASTRA_SITES_NAME', __( 'Astra Sites', 'astra-sites' ) );
19
+ }
20
+
21
+ if ( ! defined( 'ASTRA_SITES_VER' ) ) {
22
+ define( 'ASTRA_SITES_VER', '1.3.0' );
23
+ }
24
+
25
+ if ( ! defined( 'ASTRA_SITES_FILE' ) ) {
26
+ define( 'ASTRA_SITES_FILE', __FILE__ );
27
+ }
28
+
29
+ if ( ! defined( 'ASTRA_SITES_BASE' ) ) {
30
+ define( 'ASTRA_SITES_BASE', plugin_basename( ASTRA_SITES_FILE ) );
31
+ }
32
+
33
+ if ( ! defined( 'ASTRA_SITES_DIR' ) ) {
34
+ define( 'ASTRA_SITES_DIR', plugin_dir_path( ASTRA_SITES_FILE ) );
35
+ }
36
+
37
+ if ( ! defined( 'ASTRA_SITES_URI' ) ) {
38
+ define( 'ASTRA_SITES_URI', plugins_url( '/', ASTRA_SITES_FILE ) );
39
+ }
40
+
41
+ if ( ! function_exists( 'astra_sites_setup' ) ) :
42
+
43
+ /**
44
+ * Astra Sites Setup
45
+ *
46
+ * @since 1.0.5
47
+ */
48
+ function astra_sites_setup() {
49
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites.php';
50
+ }
51
+
52
+ add_action( 'plugins_loaded', 'astra_sites_setup' );
53
+
54
+ endif;
inc/assets/css/admin.css CHANGED
@@ -1,476 +1,638 @@
1
- .wrap .status,
2
- .wrap .site-type {
3
- position: absolute;
4
- z-index: 1;
5
- color: #fff;
6
- padding: 0.5em 1em;
7
- top: -0.5em;
8
- text-transform: uppercase;
9
- }
10
- .wrap .status,
11
- .wrap .site-type.premium {
12
- background: #0073aa;
13
- }
14
- .wrap .status {
15
- left: -0.5em;
16
- }
17
- .wrap .site-type.premium {
18
- right: -0.5em;
19
- }
20
-
21
- .wrap .status.publish,
22
- .wrap .site-type.free {
23
- display: none;
24
- }
25
-
26
- .install-theme-info .site-type {
27
- display: none;
28
- }
29
-
30
- .theme {
31
- position: relative;
32
- }
33
- .wrap .astra-sites-preview .site-type.premium {
34
- display: block;
35
- display: none;
36
- position: relative;
37
- margin: 0.5em 0em 1em 0em;
38
- top: 0;
39
- left: 0;
40
- text-align: center;
41
- }
42
-
43
- .theme-details-read-more.open {
44
- margin: 0.5em 0 0 0;
45
- }
46
-
47
- .astra-sites-preview .theme-screenshot {
48
- width: 100%;
49
- }
50
-
51
- .install-theme-info .site-type.premium {
52
- display: none;
53
- }
54
-
55
- /**
56
- * Required Plugins
57
- */
58
- .required-plugins.loading {
59
- text-align: center;
60
- }
61
- .required-plugins button {
62
- float: right;
63
- }
64
- .required-plugins .plugin-card {
65
- float: none;
66
- width: 100%;
67
- border: none;
68
- margin: 0 0 0.8em 0;
69
- display: flex;
70
- justify-content: space-between;
71
- align-items: center;
72
- transition: background ease 0.8s;
73
- }
74
- .required-plugins .plugin-card.plugin-card-update-failed {
75
- flex-wrap: wrap;
76
- }
77
- .required-plugins .spinner {
78
- float: none;
79
- margin: 0;
80
- }
81
-
82
- .expanded .wp-full-overlay-footer {
83
- height: 111px;
84
- }
85
-
86
- .wp-full-overlay-footer .view-site,
87
- .wp-full-overlay-footer .go-pro,
88
- .wp-full-overlay-footer .astra-demo-import {
89
- width: 100%;
90
- text-align: center;
91
- }
92
-
93
- .wp-core-ui .wp-full-overlay-footer .button.button-hero,
94
- .wp-core-ui .wp-full-overlay-footer .button-group.button-hero .button {
95
- padding: 0 10px 1px;
96
- }
97
-
98
- .wp-full-overlay-footer .installing:before {
99
- vertical-align: text-bottom;
100
- }
101
-
102
- .required-plugins-wrap h4 {
103
- margin: 1em 0 0.5em 0;
104
- padding: 0.5em 0;
105
- transition: all ease 0.3s;
106
- }
107
-
108
- /**
109
- * Read more link
110
- */
111
- .wp-core-ui .theme-details-read-more:focus,
112
- .wp-core-ui .theme-details-read-more:hover {
113
- outline: none;
114
- box-shadow: none;
115
- }
116
- .wp-core-ui .theme-details-read-more {
117
- margin: 10px 0;
118
- display: none;
119
- text-decoration: none;
120
- }
121
-
122
- /**
123
- * Go pro.
124
- */
125
- .wp-core-ui .go-pro.button[disabled] {
126
- background-color: #fcb92c !important;
127
- color: white !important;
128
- box-shadow: 1px 0 #eab23a !important;
129
- text-shadow: 1px 0 #6b4e13 !important;
130
- border-color: #e2a932 !important;
131
- cursor: pointer;
132
- }
133
- .wp-core-ui .view-site .dashicons,
134
- .wp-core-ui .go-pro .dashicons {
135
- font-size: 1rem;
136
- vertical-align: middle;
137
- }
138
-
139
- /**
140
- * Errors
141
- */
142
- .plugin-card-update-failed .notice {
143
- margin-top: 1.5em;
144
- }
145
-
146
- .no-themes {
147
- margin-top: 40px;
148
- }
149
-
150
- .no-themes p {
151
- font-size: 15px;
152
- }
153
-
154
- .no-themes .left-margin {
155
- margin-left: 30px;
156
- }
157
-
158
- /**
159
- *
160
- */
161
- .astra-sites-preview .wp-full-overlay-sidebar-content {
162
- bottom: 100px;
163
- }
164
-
165
- .footer-import-button-wrap {
166
- padding: 10px 20px;
167
- }
168
-
169
- .footer-import-button-wrap .button {
170
- margin: 0;
171
- }
172
-
173
- .astra-sites-preview.expanded .wp-full-overlay-footer {
174
- left: initial;
175
- }
176
-
177
- /**
178
- * Menu Page
179
- */
180
- .astra-sites-title {
181
- float: left;
182
- font-size: 23px;
183
- font-weight: 400;
184
- margin: 0 0 6px 0px;
185
- padding: 0;
186
- line-height: 29px;
187
- }
188
-
189
- #astra-sites-menu-page {
190
- margin-top: 10px;
191
- }
192
-
193
- /**
194
- * API Error
195
- */
196
- .astra-api-error {
197
- margin: 0 0 0.5em 0;
198
- }
199
-
200
- /**
201
- * Grid
202
- */
203
- .wp-filter .search-form {
204
- margin-left: 1em;
205
- }
206
- .wp-filter .search-form input[type="search"] {
207
- width: 200px;
208
- font-size: 13px;
209
- padding: 5px 10px;
210
- }
211
- .section-left {
212
- display: inline-block;
213
- }
214
- .section-right {
215
- float: right;
216
- }
217
- .filter-count {
218
- min-width: 3em;
219
- }
220
- .astra-site-preview-on {
221
- overflow: hidden;
222
- }
223
-
224
- .appearance_page_astra-sites .notice {
225
- margin-left: 0;
226
- width: auto;
227
- float: none;
228
- }
229
- .filters-wrap {
230
- display: inline-block;
231
- }
232
- .spinner-wrap {
233
- text-align: center;
234
- }
235
- .spinner-wrap .spinner {
236
- float: none;
237
- }
238
- .hide-me {
239
- display: none !important;
240
- }
241
- #astra-sites-admin {
242
- height: 100vh;
243
- }
244
- .install-theme-info > .notice {
245
- margin: 5px 0 10px 0;
246
- }
247
-
248
- .astra-sites-suggestions:before {
249
- border: 5px dashed #ccc;
250
- position: absolute;
251
- left: 0;
252
- right: 0;
253
- top: 0;
254
- bottom: 0px;
255
- }
256
-
257
- .astra-sites-suggestions {
258
- min-height: 280px;
259
- border: none !important;
260
- }
261
-
262
- .astra-sites-suggestions a {
263
- border: none;
264
- outline: none;
265
- }
266
-
267
- .astra-sites-suggestions .inner {
268
- border: 6px solid #24282e !important;
269
- padding: 27% 10% 50% 10%;
270
- text-align: center;
271
- position: absolute;
272
- left: 0;
273
- right: 0;
274
- top: 0;
275
- background: #33383d;
276
- bottom: 0;
277
- color: #eee;
278
- cursor: auto;
279
- }
280
-
281
- .astra-sites-suggestions .inner a {
282
- color: #00b9eb;
283
- }
284
-
285
- .astra-sites-suggestions p {
286
- font-size: 1rem;
287
- margin: 0;
288
- }
289
-
290
- .astra-notice {
291
- margin: 2em 2em 0em 0em;
292
- }
293
-
294
- .no-themes .description {
295
- display: block;
296
- }
297
-
298
- /**
299
- * Responsive Button UI
300
- */
301
- .astra-sites-preview .wp-full-overlay-footer .devices button.active:before,
302
- .astra-sites-preview .wp-full-overlay-footer .devices button:hover:before {
303
- color: #0073aa;
304
- }
305
- .astra-sites-preview .wp-full-overlay-footer .devices button:before {
306
- color: #c1c1c1;
307
- }
308
- .astra-sites-preview .wp-full-overlay-footer .devices button:hover {
309
- background-color: transparent;
310
- }
311
- .astra-sites-preview .wp-full-overlay-footer .devices button {
312
- border: none;
313
- }
314
- .astra-sites-preview .wp-full-overlay-footer .devices button:focus,
315
- .astra-sites-preview .wp-full-overlay-footer .devices button.active:hover {
316
- border-bottom-color: transparent;
317
- background-color: transparent;
318
- }
319
- .not-click-able {
320
- pointer-events: none !important;
321
- }
322
- body.page-builder-selected .select-page-builder,
323
- body.loading-content .select-page-builder {
324
- display: none;
325
- }
326
- .select-page-builder .up-arrow {
327
- -webkit-transform: rotate(90deg);
328
- -moz-transform: rotate(90deg);
329
- -ms-transform: rotate(90deg);
330
- transform: rotate(90deg);
331
- display: inline-block;
332
- font-size: 1.5em;
333
- color: #797979;
334
- vertical-align: middle;
335
- margin-right: 10px;
336
- -webkit-transition: all linear 0.6s;
337
- -moz-transition: all linear 0.6s;
338
- -ms-transition: all linear 0.6s;
339
- transition: all linear 0.6s;
340
- -webkit-animation-duration: 1s;
341
- animation-duration: 1s;
342
- -webkit-animation-fill-mode: both;
343
- animation-fill-mode: both;
344
- -webkit-animation-timing-function: ease-in-out;
345
- animation-timing-function: ease-in-out;
346
- animation-iteration-count: infinite;
347
- -webkit-animation-iteration-count: infinite;
348
- animation-name: bounce;
349
- -moz-animation-name: bounce;
350
- }
351
- .select-page-builder {
352
- margin-left: 6em;
353
- }
354
-
355
- .select-page-builder img {
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%,
381
- 100%,
382
- 20%,
383
- 50%,
384
- 80% {
385
- -webkit-transform: translateY(-0px) rotate(90deg);
386
- -moz-transform: translateY(-0px) rotate(90deg);
387
- -ms-transform: translateY(-0px) rotate(90deg);
388
- transform: translateY(-0px) rotate(90deg);
389
- }
390
- 40% {
391
- -webkit-transform: translateY(-2px) rotate(90deg);
392
- -moz-transform: translateY(-2px) rotate(90deg);
393
- -ms-transform: translateY(-2px) rotate(90deg);
394
- transform: translateY(-2px) rotate(90deg);
395
- }
396
- 60% {
397
- -webkit-transform: translateY(-1px) rotate(90deg);
398
- -moz-transform: translateY(-1px) rotate(90deg);
399
- -ms-transform: translateY(-1px) rotate(90deg);
400
- transform: translateY(-1px) rotate(90deg);
401
- }
402
- }
403
-
404
- /**
405
- * Processing Animation
406
- */
407
- .astra-demo-import.disabled {
408
- pointer-events: none;
409
- }
410
- .astra-demo-import.button.updating-message:before,
411
- .astra-demo-import.button.installing:before {
412
- -webkit-animation: cssAnimation .72s ease infinite;
413
- -moz-animation: cssAnimation .72s ease infinite;
414
- -o-animation: cssAnimation .72s ease infinite;
415
- -ms-animation: cssAnimation .72s ease infinite;
416
- animation: cssAnimation .72s ease infinite;
417
- }
418
-
419
- @-webkit-keyframes cssAnimation {
420
- from {
421
- -webkit-transform: rotate(0);
422
- -moz-transform: rotate(0);
423
- -o-transform: rotate(0);
424
- -ms-transform: rotate(0);
425
- transform: rotate(0);
426
- }
427
- to {
428
- -webkit-transform: rotate(360deg);
429
- -moz-transform: rotate(360deg);
430
- -o-transform: rotate(360deg);
431
- -ms-transform: rotate(360deg);
432
- transform: rotate(360deg);
433
- }
434
- }
435
- @-moz-keyframes cssAnimation {
436
- from {
437
- -webkit-transform: rotate(0);
438
- -moz-transform: rotate(0);
439
- -o-transform: rotate(0);
440
- -ms-transform: rotate(0);
441
- transform: rotate(0);
442
- }
443
- to {
444
- -webkit-transform: rotate(360deg);
445
- -moz-transform: rotate(360deg);
446
- -o-transform: rotate(360deg);
447
- -ms-transform: rotate(360deg);
448
- transform: rotate(360deg);
449
- }
450
- }
451
- @-o-keyframes cssAnimation {
452
- from {
453
- -webkit-transform: rotate(0);
454
- -moz-transform: rotate(0);
455
- -o-transform: rotate(0);
456
- -ms-transform: rotate(0);
457
- transform: rotate(0);
458
- }
459
- to {
460
- -webkit-transform: rotate(360deg);
461
- -moz-transform: rotate(360deg);
462
- -o-transform: rotate(360deg);
463
- -ms-transform: rotate(360deg);
464
- transform: rotate(360deg);
465
- }
466
- }
467
-
468
- #astra-sites-filters {
469
- display: inline-block;
470
- width: 100%;
471
- }
472
-
473
- .astra-site-down {
474
- padding: 1em 2em;
475
- margin-top: 1em;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
  }
1
+ .wrap .status,
2
+ .wrap .site-type {
3
+ position: absolute;
4
+ z-index: 1;
5
+ color: #fff;
6
+ padding: 0.5em 1em;
7
+ top: -0.5em;
8
+ text-transform: uppercase;
9
+ }
10
+ .wrap .status,
11
+ .wrap .site-type.premium {
12
+ background: #0073aa;
13
+ }
14
+ .wrap .status {
15
+ left: -0.5em;
16
+ }
17
+ .wrap .site-type.premium {
18
+ right: -0.5em;
19
+ }
20
+
21
+ .wrap .status.publish,
22
+ .wrap .site-type.free {
23
+ display: none;
24
+ }
25
+
26
+ .install-theme-info .site-type {
27
+ display: none;
28
+ }
29
+
30
+ .theme {
31
+ position: relative;
32
+ }
33
+ .wrap .astra-sites-preview .site-type.premium {
34
+ display: block;
35
+ display: none;
36
+ position: relative;
37
+ margin: 0.5em 0em 1em 0em;
38
+ top: 0;
39
+ left: 0;
40
+ text-align: center;
41
+ }
42
+
43
+ .theme-details-read-more.open {
44
+ margin: 0.5em 0 0 0;
45
+ }
46
+
47
+ .astra-sites-preview .theme-screenshot {
48
+ width: 100%;
49
+ }
50
+
51
+ .install-theme-info .site-type.premium {
52
+ display: none;
53
+ }
54
+
55
+ /**
56
+ * Required Plugins
57
+ */
58
+ .required-plugins.loading {
59
+ text-align: center;
60
+ }
61
+ .required-plugins button {
62
+ float: right;
63
+ }
64
+ .required-plugins .plugin-card {
65
+ float: none;
66
+ width: 100%;
67
+ border: none;
68
+ margin: 0 0 0.8em 0;
69
+ display: flex;
70
+ justify-content: space-between;
71
+ align-items: center;
72
+ transition: background ease 0.8s;
73
+ }
74
+ .required-plugins .plugin-card.plugin-card-update-failed {
75
+ flex-wrap: wrap;
76
+ }
77
+ .required-plugins .spinner {
78
+ float: none;
79
+ margin: 0;
80
+ }
81
+
82
+ .expanded .wp-full-overlay-footer {
83
+ height: 111px;
84
+ }
85
+
86
+ .wp-full-overlay-footer .view-site,
87
+ .wp-full-overlay-footer .go-pro,
88
+ .wp-full-overlay-footer .astra-demo-import {
89
+ width: 100%;
90
+ text-align: center;
91
+ }
92
+
93
+ .wp-core-ui .wp-full-overlay-footer .button.button-hero,
94
+ .wp-core-ui .wp-full-overlay-footer .button-group.button-hero .button {
95
+ padding: 0 10px 1px;
96
+ }
97
+
98
+ .wp-full-overlay-footer .installing:before {
99
+ vertical-align: text-bottom;
100
+ }
101
+
102
+ .astra-sites-advanced-options-wrap h4 {
103
+ margin: 1em 0 0.5em 0;
104
+ padding: 0.5em 0;
105
+ transition: all ease 0.3s;
106
+ }
107
+
108
+ /**
109
+ * Read more link
110
+ */
111
+ .wp-core-ui .theme-details-read-more:focus,
112
+ .wp-core-ui .theme-details-read-more:hover {
113
+ outline: none;
114
+ box-shadow: none;
115
+ }
116
+ .wp-core-ui .theme-details-read-more {
117
+ margin: 10px 0;
118
+ display: none;
119
+ text-decoration: none;
120
+ }
121
+
122
+ /**
123
+ * Go pro.
124
+ */
125
+ .wp-core-ui .go-pro.button[disabled] {
126
+ background-color: #fcb92c !important;
127
+ color: white !important;
128
+ box-shadow: 1px 0 #eab23a !important;
129
+ text-shadow: 1px 0 #6b4e13 !important;
130
+ border-color: #e2a932 !important;
131
+ cursor: pointer;
132
+ }
133
+ .wp-core-ui .view-site .dashicons,
134
+ .wp-core-ui .go-pro .dashicons {
135
+ font-size: 1rem;
136
+ vertical-align: middle;
137
+ }
138
+
139
+ /**
140
+ * Errors
141
+ */
142
+ .plugin-card-update-failed .notice {
143
+ margin-top: 1.5em;
144
+ }
145
+
146
+ .no-themes {
147
+ margin-top: 40px;
148
+ }
149
+
150
+ .no-themes p {
151
+ font-size: 15px;
152
+ }
153
+
154
+ .no-themes .left-margin {
155
+ margin-left: 30px;
156
+ }
157
+
158
+ /**
159
+ *
160
+ */
161
+ .astra-sites-preview .wp-full-overlay-sidebar-content {
162
+ bottom: 100px;
163
+ }
164
+
165
+ .footer-import-button-wrap {
166
+ padding: 10px 20px;
167
+ }
168
+
169
+ .footer-import-button-wrap .button {
170
+ margin: 0;
171
+ }
172
+
173
+ .astra-sites-preview.expanded .wp-full-overlay-footer {
174
+ left: initial;
175
+ }
176
+
177
+ /**
178
+ * Menu Page
179
+ */
180
+ .astra-sites-title {
181
+ float: left;
182
+ font-size: 23px;
183
+ font-weight: 400;
184
+ margin: 0 0 6px 0px;
185
+ padding: 0;
186
+ line-height: 29px;
187
+ }
188
+
189
+ #astra-sites-menu-page {
190
+ margin-top: 10px;
191
+ }
192
+
193
+ /**
194
+ * API Error
195
+ */
196
+ .astra-api-error {
197
+ margin: 0 0 0.5em 0;
198
+ }
199
+
200
+ /**
201
+ * Grid
202
+ */
203
+ .wp-filter .search-form {
204
+ margin-left: 1em;
205
+ }
206
+ .wp-filter .search-form input[type="search"] {
207
+ width: 200px;
208
+ font-size: 13px;
209
+ padding: 5px 10px;
210
+ }
211
+ .section-left {
212
+ display: inline-block;
213
+ }
214
+ .section-right {
215
+ float: right;
216
+ }
217
+ .filter-count {
218
+ min-width: 3em;
219
+ }
220
+ .astra-site-preview-on {
221
+ overflow: hidden;
222
+ }
223
+
224
+ .appearance_page_astra-sites .notice {
225
+ margin-left: 0;
226
+ width: auto;
227
+ float: none;
228
+ }
229
+ .filters-wrap {
230
+ display: inline-block;
231
+ }
232
+ .spinner-wrap {
233
+ text-align: center;
234
+ }
235
+ .spinner-wrap .spinner {
236
+ float: none;
237
+ }
238
+ .hide-me {
239
+ display: none !important;
240
+ }
241
+ #astra-sites-admin {
242
+ height: 100vh;
243
+ }
244
+ .install-theme-info > .notice {
245
+ margin: 5px 0 10px 0;
246
+ }
247
+
248
+ .astra-sites-suggestions:before {
249
+ border: 5px dashed #ccc;
250
+ position: absolute;
251
+ left: 0;
252
+ right: 0;
253
+ top: 0;
254
+ bottom: 0px;
255
+ }
256
+
257
+ .astra-sites-suggestions {
258
+ min-height: 280px;
259
+ border: none !important;
260
+ }
261
+
262
+ .astra-sites-suggestions a {
263
+ border: none;
264
+ outline: none;
265
+ }
266
+
267
+ .astra-sites-suggestions .inner {
268
+ border: 6px solid #24282e !important;
269
+ padding: 27% 10% 50% 10%;
270
+ text-align: center;
271
+ position: absolute;
272
+ left: 0;
273
+ right: 0;
274
+ top: 0;
275
+ background: #33383d;
276
+ bottom: 0;
277
+ color: #eee;
278
+ cursor: auto;
279
+ }
280
+
281
+ .astra-sites-suggestions .inner a {
282
+ color: #00b9eb;
283
+ }
284
+
285
+ .astra-sites-suggestions p {
286
+ font-size: 1rem;
287
+ margin: 0;
288
+ }
289
+
290
+ .astra-notice {
291
+ margin: 2em 2em 0em 0em;
292
+ }
293
+
294
+ .no-themes .description {
295
+ display: block;
296
+ }
297
+
298
+ /**
299
+ * Responsive Button UI
300
+ */
301
+ .astra-sites-preview .wp-full-overlay-footer .devices button.active:before,
302
+ .astra-sites-preview .wp-full-overlay-footer .devices button:hover:before {
303
+ color: #0073aa;
304
+ }
305
+ .astra-sites-preview .wp-full-overlay-footer .devices button:before {
306
+ color: #c1c1c1;
307
+ }
308
+ .astra-sites-preview .wp-full-overlay-footer .devices button:hover {
309
+ background-color: transparent;
310
+ }
311
+ .astra-sites-preview .wp-full-overlay-footer .devices button {
312
+ border: none;
313
+ }
314
+ .astra-sites-preview .wp-full-overlay-footer .devices button:focus,
315
+ .astra-sites-preview .wp-full-overlay-footer .devices button.active:hover {
316
+ border-bottom-color: transparent;
317
+ background-color: transparent;
318
+ }
319
+ .not-click-able {
320
+ pointer-events: none !important;
321
+ }
322
+ body.page-builder-selected .select-page-builder,
323
+ body.loading-content .select-page-builder {
324
+ display: none;
325
+ }
326
+ .select-page-builder .up-arrow {
327
+ -webkit-transform: rotate(90deg);
328
+ -moz-transform: rotate(90deg);
329
+ -ms-transform: rotate(90deg);
330
+ transform: rotate(90deg);
331
+ display: inline-block;
332
+ font-size: 1.5em;
333
+ color: #797979;
334
+ vertical-align: middle;
335
+ margin-right: 10px;
336
+ -webkit-transition: all linear 0.6s;
337
+ -moz-transition: all linear 0.6s;
338
+ -ms-transition: all linear 0.6s;
339
+ transition: all linear 0.6s;
340
+ -webkit-animation-duration: 1s;
341
+ animation-duration: 1s;
342
+ -webkit-animation-fill-mode: both;
343
+ animation-fill-mode: both;
344
+ -webkit-animation-timing-function: ease-in-out;
345
+ animation-timing-function: ease-in-out;
346
+ animation-iteration-count: infinite;
347
+ -webkit-animation-iteration-count: infinite;
348
+ animation-name: bounce;
349
+ -moz-animation-name: bounce;
350
+ }
351
+ .select-page-builder {
352
+ margin-left: 6em;
353
+ }
354
+
355
+ .select-page-builder img {
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%,
381
+ 100%,
382
+ 20%,
383
+ 50%,
384
+ 80% {
385
+ -webkit-transform: translateY(-0px) rotate(90deg);
386
+ -moz-transform: translateY(-0px) rotate(90deg);
387
+ -ms-transform: translateY(-0px) rotate(90deg);
388
+ transform: translateY(-0px) rotate(90deg);
389
+ }
390
+ 40% {
391
+ -webkit-transform: translateY(-2px) rotate(90deg);
392
+ -moz-transform: translateY(-2px) rotate(90deg);
393
+ -ms-transform: translateY(-2px) rotate(90deg);
394
+ transform: translateY(-2px) rotate(90deg);
395
+ }
396
+ 60% {
397
+ -webkit-transform: translateY(-1px) rotate(90deg);
398
+ -moz-transform: translateY(-1px) rotate(90deg);
399
+ -ms-transform: translateY(-1px) rotate(90deg);
400
+ transform: translateY(-1px) rotate(90deg);
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Processing Animation
406
+ */
407
+ .astra-demo-import.disabled {
408
+ pointer-events: none;
409
+ }
410
+ .astra-demo-import.button.updating-message:before,
411
+ .astra-demo-import.button.installing:before {
412
+ -webkit-animation: cssAnimation .72s ease infinite;
413
+ -moz-animation: cssAnimation .72s ease infinite;
414
+ -o-animation: cssAnimation .72s ease infinite;
415
+ -ms-animation: cssAnimation .72s ease infinite;
416
+ animation: cssAnimation .72s ease infinite;
417
+ }
418
+
419
+ @-webkit-keyframes cssAnimation {
420
+ from {
421
+ -webkit-transform: rotate(0);
422
+ -moz-transform: rotate(0);
423
+ -o-transform: rotate(0);
424
+ -ms-transform: rotate(0);
425
+ transform: rotate(0);
426
+ }
427
+ to {
428
+ -webkit-transform: rotate(360deg);
429
+ -moz-transform: rotate(360deg);
430
+ -o-transform: rotate(360deg);
431
+ -ms-transform: rotate(360deg);
432
+ transform: rotate(360deg);
433
+ }
434
+ }
435
+ @-moz-keyframes cssAnimation {
436
+ from {
437
+ -webkit-transform: rotate(0);
438
+ -moz-transform: rotate(0);
439
+ -o-transform: rotate(0);
440
+ -ms-transform: rotate(0);
441
+ transform: rotate(0);
442
+ }
443
+ to {
444
+ -webkit-transform: rotate(360deg);
445
+ -moz-transform: rotate(360deg);
446
+ -o-transform: rotate(360deg);
447
+ -ms-transform: rotate(360deg);
448
+ transform: rotate(360deg);
449
+ }
450
+ }
451
+ @-o-keyframes cssAnimation {
452
+ from {
453
+ -webkit-transform: rotate(0);
454
+ -moz-transform: rotate(0);
455
+ -o-transform: rotate(0);
456
+ -ms-transform: rotate(0);
457
+ transform: rotate(0);
458
+ }
459
+ to {
460
+ -webkit-transform: rotate(360deg);
461
+ -moz-transform: rotate(360deg);
462
+ -o-transform: rotate(360deg);
463
+ -ms-transform: rotate(360deg);
464
+ transform: rotate(360deg);
465
+ }
466
+ }
467
+
468
+ #astra-sites-filters {
469
+ display: inline-block;
470
+ width: 100%;
471
+ }
472
+
473
+ .astra-site-down {
474
+ padding: 1em 2em;
475
+ margin-top: 1em;
476
+ }
477
+
478
+ #astra-sites-menu-page .nav-tab-wrapper {
479
+ border: none;
480
+ }
481
+
482
+ #astra-sites-filters .wp-filter {
483
+ margin-top: 0;
484
+ }
485
+
486
+ /**
487
+ * Welcome Screen
488
+ */
489
+ .astra-sites-welcome {
490
+ padding: 10em 0;
491
+ text-align: center;
492
+ }
493
+ .astra-sites-welcome .inner {
494
+ margin: 0 auto;
495
+ display: inline-block;
496
+ max-width: 700px;
497
+ background: #fff;
498
+ padding: 3em;
499
+ }
500
+
501
+ .astra-sites-welcome h1 {
502
+ font-size: 2.5em;
503
+ margin-bottom: 1em;
504
+ }
505
+
506
+ .astra-sites-welcome p.description {
507
+ font-size: 1rem;
508
+ margin-bottom: 2em;
509
+ }
510
+
511
+ .astra-sites-welcome select {
512
+ padding: 5px;
513
+ height: 100%;
514
+ }
515
+
516
+ .astra-sites-welcome p.submit {
517
+ text-align: center;
518
+ margin: 0;
519
+ padding: 0;
520
+ margin-left: .5em;
521
+ }
522
+
523
+ .astra-sites-welcome .fields {
524
+ display: flex;
525
+ vertical-align: middle;
526
+ align-items: center;
527
+ justify-content: center;
528
+ }
529
+
530
+ .astra-sites-welcome #submit {
531
+ line-height: 1;
532
+ padding: .5rem 1rem;
533
+ height: auto;
534
+ }
535
+
536
+ .astra-site-page-builder {
537
+ opacity: 0;
538
+ visibility: hidden;
539
+ }
540
+
541
+ .required-plugins-list {
542
+ margin-left: 2em;
543
+ margin-top: .5em;
544
+ margin-bottom: .5em;
545
+ list-style-type: disc;
546
+ }
547
+
548
+ .required-plugins-list .plugin-card {
549
+ background: transparent;
550
+ border: none;
551
+ margin: 0;
552
+ line-height: 2;
553
+ float: none;
554
+ width: 100%;
555
+ }
556
+
557
+ .required-plugins-list .spinner {
558
+ float: none;
559
+ margin: 0;
560
+ }
561
+
562
+ #astra-site-import-process-wrap {
563
+ display: flex;
564
+ align-items: center;
565
+ margin-top: -2px;
566
+ z-index: 999999;
567
+ position: relative;
568
+ border-radius: 3px;
569
+ overflow: hidden;
570
+ }
571
+ #astra-site-import-process-wrap progress {
572
+ padding: 0px;
573
+ border: 0 none;
574
+ background: #0085bd;
575
+ border-radius: 5px;
576
+ height: 4px;
577
+ flex: 1;
578
+ }
579
+
580
+ #astra-site-import-process-wrap progress::-webkit-progress-value {
581
+ background: #00679b;
582
+ }
583
+ #astra-site-import-process-wrap progress::-webkit-progress-bar {
584
+ background: transparent;
585
+ }
586
+
587
+ .theme-browser .theme .site-preview > .theme-screenshot {
588
+ transition: all linear .7s;
589
+ background-position: center top;
590
+ background-size: cover;
591
+ background-repeat: no-repeat;
592
+ }
593
+ .theme-browser .theme .site-preview > .theme-screenshot:hover {
594
+ background-position: center bottom;
595
+ background-size: cover;
596
+ }
597
+
598
+ .astra-sites-tooltip-icon {
599
+ cursor: pointer;
600
+ }
601
+
602
+ .astra-sites-tooltip-icon .dashicons {
603
+ color: #5d5d5d;
604
+ font-size: 18px;
605
+ }
606
+
607
+ #astra-sites-welcome-form-inline {
608
+ position: absolute;
609
+ right: 1em;
610
+ top: 0;
611
+ border-radius: 0;
612
+ line-height: 1.7;
613
+ padding: 0px 5px 2px 5px;
614
+ outline: 2px solid transparent;
615
+ outline-offset: 0;
616
+ background: #fafafa;
617
+ border: 1px solid #ccc;
618
+ color: #72777c;
619
+ font-weight: normal;
620
+ font-size: 10px;
621
+ font-size: 13px;
622
+ line-height: 26px;
623
+ height: 28px;
624
+ cursor: pointer;
625
+ }
626
+
627
+ #astra-sites-welcome-form-inline select,
628
+ #astra-sites-welcome-form-inline select:focus {
629
+ border: none;
630
+ outline: none;
631
+ box-shadow: none;
632
+ color: #72777c;
633
+ }
634
+
635
+ #astra-sites-menu-page .wp-full-overlay-main:before {
636
+ content: '';
637
+ display: none;
638
  }
inc/assets/js/admin-page.js CHANGED
@@ -1,1439 +1,1815 @@
1
- /**
2
- * AJAX Request Queue
3
- *
4
- * - add()
5
- * - remove()
6
- * - run()
7
- * - stop()
8
- *
9
- * @since 1.0.0
10
- */
11
- var AstraSitesAjaxQueue = (function() {
12
-
13
- var requests = [];
14
-
15
- return {
16
-
17
- /**
18
- * Add AJAX request
19
- *
20
- * @since 1.0.0
21
- */
22
- add: function(opt) {
23
- requests.push(opt);
24
- },
25
-
26
- /**
27
- * Remove AJAX request
28
- *
29
- * @since 1.0.0
30
- */
31
- remove: function(opt) {
32
- if( jQuery.inArray(opt, requests) > -1 )
33
- requests.splice($.inArray(opt, requests), 1);
34
- },
35
-
36
- /**
37
- * Run / Process AJAX request
38
- *
39
- * @since 1.0.0
40
- */
41
- run: function() {
42
- var self = this,
43
- oriSuc;
44
-
45
- if( requests.length ) {
46
- oriSuc = requests[0].complete;
47
-
48
- requests[0].complete = function() {
49
- if( typeof(oriSuc) === 'function' ) oriSuc();
50
- requests.shift();
51
- self.run.apply(self, []);
52
- };
53
-
54
- jQuery.ajax(requests[0]);
55
-
56
- } else {
57
-
58
- self.tid = setTimeout(function() {
59
- self.run.apply(self, []);
60
- }, 1000);
61
- }
62
- },
63
-
64
- /**
65
- * Stop AJAX request
66
- *
67
- * @since 1.0.0
68
- */
69
- stop: function() {
70
-
71
- requests = [];
72
- clearTimeout(this.tid);
73
- }
74
- };
75
-
76
- }());
77
-
78
- (function($){
79
-
80
- var AstraSSEImport = {
81
- complete: {
82
- posts: 0,
83
- media: 0,
84
- users: 0,
85
- comments: 0,
86
- terms: 0,
87
- },
88
-
89
- updateDelta: function (type, delta) {
90
- this.complete[ type ] += delta;
91
-
92
- var self = this;
93
- requestAnimationFrame(function () {
94
- self.render();
95
- });
96
- },
97
- updateProgress: function ( type, complete, total ) {
98
- var text = complete + '/' + total;
99
-
100
- if( 'undefined' !== type && 'undefined' !== text ) {
101
- total = parseInt( total, 10 );
102
- if ( 0 === total || isNaN( total ) ) {
103
- total = 1;
104
- }
105
- var percent = parseInt( complete, 10 ) / total;
106
- var progress = Math.round( percent * 100 ) + '%';
107
- var progress_bar = percent * 100;
108
- }
109
- },
110
- render: function () {
111
- var types = Object.keys( this.complete );
112
- var complete = 0;
113
- var total = 0;
114
-
115
- for (var i = types.length - 1; i >= 0; i--) {
116
- var type = types[i];
117
- this.updateProgress( type, this.complete[ type ], this.data.count[ type ] );
118
-
119
- complete += this.complete[ type ];
120
- total += this.data.count[ type ];
121
- }
122
-
123
- this.updateProgress( 'total', complete, total );
124
- }
125
- };
126
-
127
- AstraSitesAdmin = {
128
-
129
- log_file : '',
130
- customizer_data : '',
131
- wxr_url : '',
132
- wpforms_url : '',
133
- options_data : '',
134
- widgets_data : '',
135
-
136
- init: function()
137
- {
138
- this._resetPagedCount();
139
- this._bind();
140
- },
141
-
142
- /**
143
- * Debugging.
144
- *
145
- * @param {mixed} data Mixed data.
146
- */
147
- _log: function( data ) {
148
-
149
- if( astraSitesAdmin.debug ) {
150
-
151
- var date = new Date();
152
- var time = date.toLocaleTimeString();
153
-
154
- if (typeof data == 'object') {
155
- console.log('%c ' + JSON.stringify( data ) + ' ' + time, 'background: #ededed; color: #444');
156
- } else {
157
- console.log('%c ' + data + ' ' + time, 'background: #ededed; color: #444');
158
- }
159
-
160
-
161
- }
162
- },
163
-
164
- /**
165
- * Binds events for the Astra Sites.
166
- *
167
- * @since 1.0.0
168
- * @access private
169
- * @method _bind
170
- */
171
- _bind: function()
172
- {
173
- $( document ).on('click' , '.devices button', AstraSitesAdmin._previewDevice);
174
- $( document ).on('click' , '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSitesAdmin._preview);
175
- $( document ).on('click' , '.next-theme', AstraSitesAdmin._nextTheme);
176
- $( document ).on('click' , '.previous-theme', AstraSitesAdmin._previousTheme);
177
- $( document ).on('click' , '.collapse-sidebar', AstraSitesAdmin._collapse);
178
- $( document ).on('click' , '.astra-demo-import', AstraSitesAdmin._importDemo);
179
- $( document ).on('click' , '.install-now', AstraSitesAdmin._installNow);
180
- $( document ).on('click' , '.close-full-overlay', AstraSitesAdmin._fullOverlay);
181
- $( document ).on('click' , '.activate-now', AstraSitesAdmin._activateNow);
182
- $( document ).on('wp-plugin-installing' , AstraSitesAdmin._pluginInstalling);
183
- $( document ).on('wp-plugin-install-error' , AstraSitesAdmin._installError);
184
- $( document ).on('wp-plugin-install-success' , AstraSitesAdmin._installSuccess);
185
-
186
- $( document ).on('astra-sites-import-set-site-data-done' , AstraSitesAdmin._importWPForms );
187
- $( document ).on('astra-sites-import-wpforms-done' , AstraSitesAdmin._importCustomizerSettings );
188
- $( document ).on('astra-sites-import-customizer-settings-done' , AstraSitesAdmin._importPrepareXML );
189
- $( document ).on('astra-sites-import-xml-done' , AstraSitesAdmin._importSiteOptions );
190
- $( document ).on('astra-sites-import-options-done' , AstraSitesAdmin._importWidgets );
191
- $( document ).on('astra-sites-import-widgets-done' , AstraSitesAdmin._importEnd );
192
- },
193
-
194
- /**
195
- * 5. Import Complete.
196
- */
197
- _importEnd: function( event ) {
198
-
199
- $.ajax({
200
- url : astraSitesAdmin.ajaxurl,
201
- type : 'POST',
202
- dataType: 'json',
203
- data : {
204
- action : 'astra-sites-import-end',
205
- },
206
- beforeSend: function() {
207
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importComplete );
208
- }
209
- })
210
- .fail(function( jqXHR ){
211
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
212
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
213
- })
214
- .done(function ( data ) {
215
-
216
- // 5. Fail - Import Complete.
217
- if( false === data.success ) {
218
- AstraSitesAdmin._importFailMessage( data.data );
219
- AstraSitesAdmin._log( data.data );
220
- } else {
221
-
222
- $('body').removeClass('importing-site');
223
- $('.previous-theme, .next-theme').removeClass('disabled');
224
-
225
- // 5. Pass - Import Complete.
226
- AstraSitesAdmin._importSuccessMessage();
227
- AstraSitesAdmin._log( astraSitesAdmin.log.success + ' ' + astraSitesAdmin.siteURL );
228
- }
229
- });
230
- },
231
-
232
- /**
233
- * 4. Import Widgets.
234
- */
235
- _importWidgets: function( event ) {
236
-
237
- $.ajax({
238
- url : astraSitesAdmin.ajaxurl,
239
- type : 'POST',
240
- dataType: 'json',
241
- data : {
242
- action : 'astra-sites-import-widgets',
243
- widgets_data : AstraSitesAdmin.widgets_data,
244
- },
245
- beforeSend: function() {
246
- AstraSitesAdmin._log( astraSitesAdmin.log.importWidgets );
247
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingWidgets );
248
- },
249
- })
250
- .fail(function( jqXHR ){
251
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
252
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
253
- })
254
- .done(function ( widgets_data ) {
255
-
256
- // 4. Fail - Import Widgets.
257
- if( false === widgets_data.success ) {
258
- AstraSitesAdmin._importFailMessage( widgets_data.data );
259
- AstraSitesAdmin._log( widgets_data.data );
260
-
261
- } else {
262
-
263
- // 4. Pass - Import Widgets.
264
- AstraSitesAdmin._log( astraSitesAdmin.log.importWidgetsSuccess );
265
- $(document).trigger( 'astra-sites-import-widgets-done' );
266
- }
267
- });
268
- },
269
-
270
- /**
271
- * 3. Import Site Options.
272
- */
273
- _importSiteOptions: function( event ) {
274
-
275
- $.ajax({
276
- url : astraSitesAdmin.ajaxurl,
277
- type : 'POST',
278
- dataType: 'json',
279
- data : {
280
- action : 'astra-sites-import-options',
281
- options_data : AstraSitesAdmin.options_data,
282
- },
283
- beforeSend: function() {
284
- AstraSitesAdmin._log( astraSitesAdmin.log.importOptions );
285
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingOptions );
286
- },
287
- })
288
- .fail(function( jqXHR ){
289
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
290
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
291
- })
292
- .done(function ( options_data ) {
293
-
294
- // 3. Fail - Import Site Options.
295
- if( false === options_data.success ) {
296
- AstraSitesAdmin._log( options_data );
297
- AstraSitesAdmin._importFailMessage( options_data.data );
298
- AstraSitesAdmin._log( options_data.data );
299
-
300
- } else {
301
-
302
- // 3. Pass - Import Site Options.
303
- AstraSitesAdmin._log( astraSitesAdmin.log.importOptionsSuccess );
304
- $(document).trigger( 'astra-sites-import-options-done' );
305
- }
306
- });
307
- },
308
-
309
- /**
310
- * 2. Prepare XML Data.
311
- */
312
- _importPrepareXML: function( event ) {
313
-
314
- $.ajax({
315
- url : astraSitesAdmin.ajaxurl,
316
- type : 'POST',
317
- dataType: 'json',
318
- data : {
319
- action : 'astra-sites-import-prepare-xml',
320
- wxr_url : AstraSitesAdmin.wxr_url,
321
- },
322
- beforeSend: function() {
323
- AstraSitesAdmin._log( astraSitesAdmin.log.importXMLPrepare );
324
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importXMLPreparing );
325
- },
326
- })
327
- .fail(function( jqXHR ){
328
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
329
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
330
- })
331
- .done(function ( xml_data ) {
332
-
333
- // 2. Fail - Prepare XML Data.
334
- if( false === xml_data.success ) {
335
- AstraSitesAdmin._log( xml_data );
336
- var error_msg = xml_data.data.error || xml_data.data;
337
- AstraSitesAdmin._importFailMessage( error_msg );
338
- AstraSitesAdmin._log( error_msg );
339
-
340
- } else {
341
-
342
- // 2. Pass - Prepare XML Data.
343
- AstraSitesAdmin._log( astraSitesAdmin.log.importXMLPrepareSuccess );
344
-
345
- // Import XML though Event Source.
346
- AstraSSEImport.data = xml_data.data;
347
- AstraSSEImport.render();
348
-
349
- AstraSitesAdmin._log( astraSitesAdmin.log.importXML );
350
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingXML );
351
-
352
- var evtSource = new EventSource( AstraSSEImport.data.url );
353
- evtSource.onmessage = function ( message ) {
354
- var data = JSON.parse( message.data );
355
- switch ( data.action ) {
356
- case 'updateDelta':
357
- AstraSSEImport.updateDelta( data.type, data.delta );
358
- break;
359
-
360
- case 'complete':
361
- evtSource.close();
362
-
363
- // 2. Pass - Import XML though "Source Event".
364
- AstraSitesAdmin._log( astraSitesAdmin.log.importXMLSuccess );
365
- AstraSitesAdmin._log( '----- SSE - XML import Complete -----' );
366
-
367
- $(document).trigger( 'astra-sites-import-xml-done' );
368
-
369
- break;
370
- }
371
- };
372
- evtSource.addEventListener( 'log', function ( message ) {
373
- var data = JSON.parse( message.data );
374
- AstraSitesAdmin._log( data.level + ' ' + data.message );
375
- });
376
- }
377
- });
378
- },
379
-
380
- /**
381
- * 1. Import WPForms Options.
382
- */
383
- _importWPForms: function( event ) {
384
-
385
- $.ajax({
386
- url : astraSitesAdmin.ajaxurl,
387
- type : 'POST',
388
- dataType: 'json',
389
- data : {
390
- action : 'astra-sites-import-wpforms',
391
- wpforms_url : AstraSitesAdmin.wpforms_url,
392
- },
393
- beforeSend: function() {
394
- AstraSitesAdmin._log( astraSitesAdmin.log.importWPForms );
395
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingWPForms );
396
- },
397
- })
398
- .fail(function( jqXHR ){
399
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
400
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
401
- })
402
- .done(function ( forms ) {
403
-
404
- // 1. Fail - Import WPForms Options.
405
- if( false === forms.success ) {
406
- AstraSitesAdmin._importFailMessage( forms.data );
407
- AstraSitesAdmin._log( forms.data );
408
- } else {
409
-
410
- // 1. Pass - Import Customizer Options.
411
- AstraSitesAdmin._log( astraSitesAdmin.log.importWPFormsSuccess );
412
-
413
- $(document).trigger( 'astra-sites-import-wpforms-done' );
414
- }
415
- });
416
- },
417
-
418
- /**
419
- * 1. Import Customizer Options.
420
- */
421
- _importCustomizerSettings: function( event ) {
422
-
423
- $.ajax({
424
- url : astraSitesAdmin.ajaxurl,
425
- type : 'POST',
426
- dataType: 'json',
427
- data : {
428
- action : 'astra-sites-import-customizer-settings',
429
- customizer_data : AstraSitesAdmin.customizer_data,
430
- },
431
- beforeSend: function() {
432
- AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizer );
433
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingCustomizer );
434
- },
435
- })
436
- .fail(function( jqXHR ){
437
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
438
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
439
- })
440
- .done(function ( customizer_data ) {
441
-
442
- // 1. Fail - Import Customizer Options.
443
- if( false === customizer_data.success ) {
444
- AstraSitesAdmin._importFailMessage( customizer_data.data );
445
- AstraSitesAdmin._log( customizer_data.data );
446
- } else {
447
-
448
- // 1. Pass - Import Customizer Options.
449
- AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizerSuccess );
450
-
451
- $(document).trigger( 'astra-sites-import-customizer-settings-done' );
452
- }
453
- });
454
- },
455
-
456
- /**
457
- * Import Success Button.
458
- *
459
- * @param {string} data Error message.
460
- */
461
- _importSuccessMessage: function() {
462
-
463
- $('.astra-demo-import').removeClass('updating-message installing')
464
- .removeAttr('data-import')
465
- .addClass('view-site')
466
- .removeClass('astra-demo-import')
467
- .text( astraSitesAdmin.strings.viewSite )
468
- .attr('target', '_blank')
469
- .append('<i class="dashicons dashicons-external"></i>')
470
- .attr('href', astraSitesAdmin.siteURL );
471
- },
472
-
473
- /**
474
- * Preview Device
475
- */
476
- _previewDevice: function( event ) {
477
- var device = $( event.currentTarget ).data( 'device' );
478
-
479
- $('.theme-install-overlay')
480
- .removeClass( 'preview-desktop preview-tablet preview-mobile' )
481
- .addClass( 'preview-' + device )
482
- .data( 'current-preview-device', device );
483
-
484
- AstraSitesAdmin._tooglePreviewDeviceButtons( device );
485
- },
486
-
487
- /**
488
- * Toggle Preview Buttons
489
- */
490
- _tooglePreviewDeviceButtons: function( newDevice ) {
491
- var $devices = $( '.wp-full-overlay-footer .devices' );
492
-
493
- $devices.find( 'button' )
494
- .removeClass( 'active' )
495
- .attr( 'aria-pressed', false );
496
-
497
- $devices.find( 'button.preview-' + newDevice )
498
- .addClass( 'active' )
499
- .attr( 'aria-pressed', true );
500
- },
501
-
502
- /**
503
- * Import Error Button.
504
- *
505
- * @param {string} data Error message.
506
- */
507
- _importFailMessage: function( message, from ) {
508
-
509
- $('.astra-demo-import')
510
- .addClass('go-pro button-primary')
511
- .removeClass('updating-message installing')
512
- .removeAttr('data-import')
513
- .attr('target', '_blank')
514
- .append('<i class="dashicons dashicons-external"></i>')
515
- .removeClass('astra-demo-import');
516
-
517
- // Add the doc link due to import log file not generated.
518
- if( 'undefined' === from ) {
519
-
520
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailedBtnSmall );
521
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailedBtnLarge );
522
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
523
-
524
- // Add the import log file link.
525
- } else {
526
-
527
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
528
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
529
-
530
- // Add the import log file link.
531
- if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
532
- $('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
533
- } else {
534
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
535
- }
536
- }
537
-
538
- var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
539
- output += ' <p>'+message+'</p>';
540
- output += ' <button type="button" class="notice-dismiss">';
541
- output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
542
- output += ' </button>';
543
- output += '</div>';
544
-
545
- // Fail Notice.
546
- $('.install-theme-info').append( output );
547
-
548
-
549
- // !important to add trigger.
550
- // Which reinitialize the dismiss error message events.
551
- $(document).trigger('wp-updates-notice-added');
552
- },
553
-
554
-
555
- /**
556
- * Install Now
557
- */
558
- _installNow: function(event)
559
- {
560
- event.preventDefault();
561
-
562
- var $button = jQuery( event.target ),
563
- $document = jQuery(document);
564
-
565
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
566
- return;
567
- }
568
-
569
- if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
570
- wp.updates.requestFilesystemCredentials( event );
571
-
572
- $document.on( 'credential-modal-cancel', function() {
573
- var $message = $( '.install-now.updating-message' );
574
-
575
- $message
576
- .removeClass( 'updating-message' )
577
- .text( wp.updates.l10n.installNow );
578
-
579
- wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
580
- } );
581
- }
582
-
583
- AstraSitesAdmin._log( astraSitesAdmin.log.installingPlugin + ' ' + $button.data( 'slug' ) );
584
-
585
- wp.updates.installPlugin( {
586
- slug: $button.data( 'slug' )
587
- } );
588
- },
589
-
590
- /**
591
- * Install Success
592
- */
593
- _installSuccess: function( event, response ) {
594
-
595
- event.preventDefault();
596
-
597
- AstraSitesAdmin._log( astraSitesAdmin.log.installed + ' ' + response.slug );
598
-
599
- var $message = jQuery( '.plugin-card-' + response.slug ).find( '.button' );
600
- var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
601
- var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
602
-
603
- // Transform the 'Install' button into an 'Activate' button.
604
- var $init = $message.data('init');
605
-
606
- $message.removeClass( 'install-now installed button-disabled updated-message' )
607
- .addClass('updating-message')
608
- .html( astraSitesAdmin.strings.btnActivating );
609
-
610
- // Reset not installed plugins list.
611
- var pluginsList = astraSitesAdmin.requiredPlugins.notinstalled;
612
- astraSitesAdmin.requiredPlugins.notinstalled = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
613
-
614
- // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
615
- setTimeout( function() {
616
-
617
- $.ajax({
618
- url: astraSitesAdmin.ajaxurl,
619
- type: 'POST',
620
- data: {
621
- 'action' : 'astra-required-plugin-activate',
622
- 'init' : $init,
623
- 'options' : $siteOptions,
624
- 'enabledExtensions' : $enabledExtensions,
625
- },
626
- })
627
- .done(function (result) {
628
-
629
- if( result.success ) {
630
-
631
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
632
-
633
- // Reset not installed plugins list.
634
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
635
-
636
- $message.removeClass( 'button-primary install-now activate-now updating-message' )
637
- .attr('disabled', 'disabled')
638
- .addClass('disabled')
639
- .text( astraSitesAdmin.strings.btnActive );
640
-
641
- // Enable Demo Import Button
642
- AstraSitesAdmin._enable_demo_import_button();
643
-
644
- } else {
645
-
646
- $message.removeClass( 'updating-message' );
647
-
648
- }
649
-
650
- });
651
-
652
- }, 1200 );
653
-
654
- },
655
-
656
- /**
657
- * Plugin Installation Error.
658
- */
659
- _installError: function( event, response ) {
660
-
661
- var $card = jQuery( '.plugin-card-' + response.slug );
662
-
663
- AstraSitesAdmin._log( response.errorMessage + ' ' + response.slug );
664
-
665
- $card
666
- .removeClass( 'button-primary' )
667
- .addClass( 'disabled' )
668
- .html( wp.updates.l10n.installFailedShort );
669
-
670
- AstraSitesAdmin._importFailMessage( response.errorMessage );
671
- },
672
-
673
- /**
674
- * Installing Plugin
675
- */
676
- _pluginInstalling: function(event, args) {
677
- event.preventDefault();
678
-
679
- var $card = jQuery( '.plugin-card-' + args.slug );
680
- var $button = $card.find( '.button' );
681
-
682
- AstraSitesAdmin._log( astraSitesAdmin.log.installingPlugin + ' ' + args.slug );
683
-
684
- $card.addClass('updating-message');
685
- $button.addClass('already-started');
686
-
687
- },
688
-
689
- /**
690
- * Render Demo Preview
691
- */
692
- _activateNow: function( eventn ) {
693
-
694
- event.preventDefault();
695
-
696
- var $button = jQuery( event.target ),
697
- $init = $button.data( 'init' ),
698
- $slug = $button.data( 'slug' );
699
-
700
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
701
- return;
702
- }
703
-
704
- AstraSitesAdmin._log( astraSitesAdmin.log.activating + ' ' + $slug );
705
-
706
- $button.addClass('updating-message button-primary')
707
- .html( astraSitesAdmin.strings.btnActivating );
708
-
709
- var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
710
- var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
711
-
712
- $.ajax({
713
- url: astraSitesAdmin.ajaxurl,
714
- type: 'POST',
715
- data: {
716
- 'action' : 'astra-required-plugin-activate',
717
- 'init' : $init,
718
- 'options' : $siteOptions,
719
- 'enabledExtensions' : $enabledExtensions,
720
- },
721
- })
722
- .done(function (result) {
723
-
724
- if( result.success ) {
725
-
726
- AstraSitesAdmin._log( astraSitesAdmin.log.activated + ' ' + $slug );
727
-
728
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
729
-
730
- // Reset not installed plugins list.
731
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( $slug, pluginsList );
732
-
733
- $button.removeClass( 'button-primary install-now activate-now updating-message' )
734
- .attr('disabled', 'disabled')
735
- .addClass('disabled')
736
- .text( astraSitesAdmin.strings.btnActive );
737
-
738
- // Enable Demo Import Button
739
- AstraSitesAdmin._enable_demo_import_button();
740
-
741
- }
742
-
743
- })
744
- .fail(function () {
745
- });
746
-
747
- },
748
-
749
- /**
750
- * Full Overlay
751
- */
752
- _fullOverlay: function (event) {
753
- event.preventDefault();
754
-
755
- // Import process is started?
756
- // And Closing the window? Then showing the warning confirm message.
757
- if( $('body').hasClass('importing-site') && ! confirm( astraSitesAdmin.strings.warningBeforeCloseWindow ) ) {
758
- return;
759
- }
760
-
761
- $('body').removeClass('importing-site');
762
- $('.previous-theme, .next-theme').removeClass('disabled');
763
- $('.theme-install-overlay').css('display', 'none');
764
- $('.theme-install-overlay').remove();
765
- $('.theme-preview-on').removeClass('theme-preview-on');
766
- $('html').removeClass('astra-site-preview-on');
767
- },
768
-
769
- /**
770
- * Bulk Plugin Active & Install
771
- */
772
- _bulkPluginInstallActivate: function()
773
- {
774
- if( 0 === astraSitesAdmin.requiredPlugins.length ) {
775
- return;
776
- }
777
-
778
- jQuery('.required-plugins')
779
- .find('.install-now')
780
- .addClass( 'updating-message' )
781
- .removeClass( 'install-now' )
782
- .text( wp.updates.l10n.installing );
783
-
784
- jQuery('.required-plugins')
785
- .find('.activate-now')
786
- .addClass('updating-message')
787
- .removeClass( 'activate-now' )
788
- .html( astraSitesAdmin.strings.btnActivating );
789
-
790
- var not_installed = astraSitesAdmin.requiredPlugins.notinstalled || '';
791
- var activate_plugins = astraSitesAdmin.requiredPlugins.inactive || '';
792
-
793
- // First Install Bulk.
794
- if( not_installed.length > 0 ) {
795
- AstraSitesAdmin._installAllPlugins( not_installed );
796
- }
797
-
798
- // Second Activate Bulk.
799
- if( activate_plugins.length > 0 ) {
800
- AstraSitesAdmin._activateAllPlugins( activate_plugins );
801
- }
802
-
803
- },
804
-
805
- /**
806
- * Activate All Plugins.
807
- */
808
- _activateAllPlugins: function( activate_plugins ) {
809
-
810
- // Activate ALl Plugins.
811
- AstraSitesAjaxQueue.stop();
812
- AstraSitesAjaxQueue.run();
813
-
814
- AstraSitesAdmin._log( astraSitesAdmin.log.bulkActivation );
815
-
816
- $.each( activate_plugins, function(index, single_plugin) {
817
-
818
- var $card = jQuery( '.plugin-card-' + single_plugin.slug ),
819
- $button = $card.find('.button'),
820
- $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val(),
821
- $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
822
-
823
- $button.addClass('updating-message');
824
-
825
- AstraSitesAjaxQueue.add({
826
- url: astraSitesAdmin.ajaxurl,
827
- type: 'POST',
828
- data: {
829
- 'action' : 'astra-required-plugin-activate',
830
- 'init' : single_plugin.init,
831
- 'options' : $siteOptions,
832
- 'enabledExtensions' : $enabledExtensions,
833
- },
834
- success: function( result ){
835
-
836
- if( result.success ) {
837
-
838
- AstraSitesAdmin._log( astraSitesAdmin.log.activate + ' ' + single_plugin.slug );
839
-
840
- var $card = jQuery( '.plugin-card-' + single_plugin.slug );
841
- var $button = $card.find( '.button' );
842
- if( ! $button.hasClass('already-started') ) {
843
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
844
-
845
- // Reset not installed plugins list.
846
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( single_plugin.slug, pluginsList );
847
- }
848
-
849
- $button.removeClass( 'button-primary install-now activate-now updating-message' )
850
- .attr('disabled', 'disabled')
851
- .addClass('disabled')
852
- .text( astraSitesAdmin.strings.btnActive );
853
-
854
- // Enable Demo Import Button
855
- AstraSitesAdmin._enable_demo_import_button();
856
- } else {
857
- AstraSitesAdmin._log( astraSitesAdmin.log.activationError + ' - ' + single_plugin.slug );
858
- }
859
- }
860
- });
861
- });
862
- },
863
-
864
- /**
865
- * Install All Plugins.
866
- */
867
- _installAllPlugins: function( not_installed ) {
868
-
869
- AstraSitesAdmin._log( astraSitesAdmin.log.bulkInstall );
870
-
871
- $.each( not_installed, function(index, single_plugin) {
872
-
873
- var $card = jQuery( '.plugin-card-' + single_plugin.slug ),
874
- $button = $card.find('.button');
875
-
876
- if( ! $button.hasClass('already-started') ) {
877
-
878
- // Add each plugin activate request in Ajax queue.
879
- // @see wp-admin/js/updates.js
880
- wp.updates.queue.push( {
881
- action: 'install-plugin', // Required action.
882
- data: {
883
- slug: single_plugin.slug
884
- }
885
- } );
886
- }
887
- });
888
-
889
- // Required to set queue.
890
- wp.updates.queueChecker();
891
- },
892
-
893
- /**
894
- * Fires when a nav item is clicked.
895
- *
896
- * @since 1.0
897
- * @access private
898
- * @method _importDemo
899
- */
900
- _importDemo: function()
901
- {
902
- var $this = jQuery(this),
903
- $theme = $this.closest('.astra-sites-preview').find('.wp-full-overlay-header'),
904
- apiURL = $theme.data('demo-api') || '',
905
- plugins = $theme.data('required-plugins');
906
-
907
- var disabled = $this.attr('data-import');
908
-
909
- if ( typeof disabled !== 'undefined' && disabled === 'disabled' || $this.hasClass('disabled') ) {
910
-
911
- $('.astra-demo-import').addClass('updating-message installing')
912
- .text( wp.updates.l10n.installing );
913
-
914
- /**
915
- * Process Bulk Plugin Install & Activate
916
- */
917
- AstraSitesAdmin._bulkPluginInstallActivate();
918
-
919
- return;
920
- }
921
-
922
- // Proceed?
923
- if( ! confirm( astraSitesAdmin.strings.importWarning ) ) {
924
- return;
925
- }
926
-
927
- $('body').addClass('importing-site');
928
- $('.previous-theme, .next-theme').addClass('disabled');
929
-
930
- // Remove all notices before import start.
931
- $('.install-theme-info > .notice').remove();
932
-
933
- $('.astra-demo-import').attr('data-import', 'disabled')
934
- .addClass('updating-message installing')
935
- .text( astraSitesAdmin.strings.importingDemo );
936
-
937
- $this.closest('.theme').focus();
938
-
939
- var $theme = $this.closest('.astra-sites-preview').find('.wp-full-overlay-header');
940
-
941
- var apiURL = $theme.data('demo-api') || '';
942
-
943
- // Site Import by API URL.
944
- if( apiURL ) {
945
- AstraSitesAdmin._importSite( apiURL );
946
- }
947
-
948
- },
949
-
950
- /**
951
- * Start Import Process by API URL.
952
- *
953
- * @param {string} apiURL Site API URL.
954
- */
955
- _importSite: function( apiURL ) {
956
-
957
- AstraSitesAdmin._log( astraSitesAdmin.log.api + ' : ' + apiURL );
958
- AstraSitesAdmin._log( astraSitesAdmin.log.importing );
959
-
960
- $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.gettingData );
961
-
962
- // 1. Request Site Import
963
- $.ajax({
964
- url : astraSitesAdmin.ajaxurl,
965
- type : 'POST',
966
- dataType: 'json',
967
- data : {
968
- 'action' : 'astra-sites-import-set-site-data',
969
- 'api_url' : apiURL,
970
- },
971
- })
972
- .fail(function( jqXHR ){
973
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
974
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
975
- })
976
- .done(function ( demo_data ) {
977
-
978
- // 1. Fail - Request Site Import
979
- if( false === demo_data.success ) {
980
-
981
- AstraSitesAdmin._importFailMessage( demo_data.data );
982
-
983
- } else {
984
-
985
- // Set log file URL.
986
- if( 'log_file' in demo_data.data ){
987
- AstraSitesAdmin.log_file_url = decodeURIComponent( demo_data.data.log_file ) || '';
988
- }
989
-
990
- // 1. Pass - Request Site Import
991
- AstraSitesAdmin._log( astraSitesAdmin.log.processingRequest );
992
-
993
- AstraSitesAdmin.customizer_data = JSON.stringify( demo_data.data['astra-site-customizer-data'] ) || '';
994
- AstraSitesAdmin.wxr_url = encodeURI( demo_data.data['astra-site-wxr-path'] ) || '';
995
- AstraSitesAdmin.wpforms_url = encodeURI( demo_data.data['astra-site-wpforms-path'] ) || '';
996
- AstraSitesAdmin.options_data = JSON.stringify( demo_data.data['astra-site-options-data'] ) || '';
997
- AstraSitesAdmin.widgets_data = JSON.stringify( demo_data.data['astra-site-widgets-data'] ) || '';
998
-
999
- $(document).trigger( 'astra-sites-import-set-site-data-done' );
1000
- }
1001
-
1002
- });
1003
-
1004
- },
1005
-
1006
- /**
1007
- * Collapse Sidebar.
1008
- */
1009
- _collapse: function() {
1010
- event.preventDefault();
1011
-
1012
- overlay = jQuery('.wp-full-overlay');
1013
-
1014
- if (overlay.hasClass('expanded')) {
1015
- overlay.removeClass('expanded');
1016
- overlay.addClass('collapsed');
1017
- return;
1018
- }
1019
-
1020
- if (overlay.hasClass('collapsed')) {
1021
- overlay.removeClass('collapsed');
1022
- overlay.addClass('expanded');
1023
- return;
1024
- }
1025
- },
1026
-
1027
- /**
1028
- * Previous Theme.
1029
- */
1030
- _previousTheme: function (event) {
1031
- event.preventDefault();
1032
-
1033
- currentDemo = jQuery('.theme-preview-on');
1034
- currentDemo.removeClass('theme-preview-on');
1035
- prevDemo = currentDemo.prev('.theme');
1036
- prevDemo.addClass('theme-preview-on');
1037
-
1038
- AstraSitesAdmin._renderDemoPreview(prevDemo);
1039
- },
1040
-
1041
- /**
1042
- * Next Theme.
1043
- */
1044
- _nextTheme: function (event) {
1045
- event.preventDefault();
1046
- currentDemo = jQuery('.theme-preview-on')
1047
- currentDemo.removeClass('theme-preview-on');
1048
- nextDemo = currentDemo.next('.theme');
1049
- nextDemo.addClass('theme-preview-on');
1050
-
1051
- AstraSitesAdmin._renderDemoPreview( nextDemo );
1052
- },
1053
-
1054
- /**
1055
- * Individual Site Preview
1056
- *
1057
- * On click on image, more link & preview button.
1058
- */
1059
- _preview: function( event ) {
1060
-
1061
- event.preventDefault();
1062
-
1063
- var self = jQuery(this).parents('.theme');
1064
- self.addClass('theme-preview-on');
1065
-
1066
- jQuery('html').addClass('astra-site-preview-on');
1067
-
1068
- AstraSitesAdmin._renderDemoPreview( self );
1069
- },
1070
-
1071
- /**
1072
- * Check Next Previous Buttons.
1073
- */
1074
- _checkNextPrevButtons: function() {
1075
- currentDemo = jQuery('.theme-preview-on');
1076
- nextDemo = currentDemo.nextAll('.theme').length;
1077
- prevDemo = currentDemo.prevAll('.theme').length;
1078
-
1079
- if (nextDemo == 0) {
1080
- jQuery('.next-theme').addClass('disabled');
1081
- } else if (nextDemo != 0) {
1082
- jQuery('.next-theme').removeClass('disabled');
1083
- }
1084
-
1085
- if (prevDemo == 0) {
1086
- jQuery('.previous-theme').addClass('disabled');
1087
- } else if (prevDemo != 0) {
1088
- jQuery('.previous-theme').removeClass('disabled');
1089
- }
1090
-
1091
- return;
1092
- },
1093
-
1094
- /**
1095
- * Render Demo Preview
1096
- */
1097
- _renderDemoPreview: function(anchor) {
1098
-
1099
- var demoId = anchor.data('id') || '',
1100
- apiURL = anchor.data('demo-api') || '',
1101
- demoType = anchor.data('demo-type') || '',
1102
- demoURL = anchor.data('demo-url') || '',
1103
- screenshot = anchor.data('screenshot') || '',
1104
- demo_name = anchor.data('demo-name') || '',
1105
- demo_slug = anchor.data('demo-slug') || '',
1106
- content = anchor.data('content') || '',
1107
- requiredPlugins = anchor.data('required-plugins') || '',
1108
- astraSiteOptions = anchor.find('.astra-site-options').val() || '';
1109
- astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
1110
-
1111
- AstraSitesAdmin._log( astraSitesAdmin.log.preview + ' "' + demo_name + '" URL : ' + demoURL );
1112
-
1113
- var template = wp.template('astra-site-preview');
1114
-
1115
- templateData = [{
1116
- id : demoId,
1117
- astra_demo_type : demoType,
1118
- astra_demo_url : demoURL,
1119
- demo_api : apiURL,
1120
- screenshot : screenshot,
1121
- demo_name : demo_name,
1122
- slug : demo_slug,
1123
- content : content,
1124
- required_plugins : JSON.stringify(requiredPlugins),
1125
- astra_site_options : astraSiteOptions,
1126
- astra_enabled_extensions : astraEnabledExtensions,
1127
- }];
1128
-
1129
- // delete any earlier fullscreen preview before we render new one.
1130
- jQuery('.theme-install-overlay').remove();
1131
-
1132
- jQuery('#astra-sites-menu-page').append(template(templateData[0]));
1133
- jQuery('.theme-install-overlay').css('display', 'block');
1134
- AstraSitesAdmin._checkNextPrevButtons();
1135
-
1136
- var desc = jQuery('.theme-details');
1137
- var descHeight = parseInt( desc.outerHeight() );
1138
- var descBtn = jQuery('.theme-details-read-more');
1139
-
1140
- if( $.isArray( requiredPlugins ) ) {
1141
-
1142
- if( descHeight >= 55 ) {
1143
-
1144
- // Show button.
1145
- descBtn.css( 'display', 'inline-block' );
1146
-
1147
- // Set height upto 3 line.
1148
- desc.css( 'height', 57 );
1149
-
1150
- // Button Click.
1151
- descBtn.click(function(event) {
1152
-
1153
- if( descBtn.hasClass('open') ) {
1154
- desc.animate({ height: 57 },
1155
- 300, function() {
1156
- descBtn.removeClass('open');
1157
- descBtn.html( astraSitesAdmin.strings.DescExpand );
1158
- });
1159
- } else {
1160
- desc.animate({ height: descHeight },
1161
- 300, function() {
1162
- descBtn.addClass('open');
1163
- descBtn.html( astraSitesAdmin.strings.DescCollapse );
1164
- });
1165
- }
1166
-
1167
- });
1168
- }
1169
-
1170
- // or
1171
- var $pluginsFilter = jQuery( '#plugin-filter' ),
1172
- data = {
1173
- action : 'astra-required-plugins',
1174
- _ajax_nonce : astraSitesAdmin._ajax_nonce,
1175
- required_plugins : requiredPlugins
1176
- };
1177
-
1178
- // Add disabled class from import button.
1179
- $('.astra-demo-import')
1180
- .addClass('disabled not-click-able')
1181
- .removeAttr('data-import');
1182
-
1183
- $('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
1184
-
1185
- // Required Required.
1186
- $.ajax({
1187
- url : astraSitesAdmin.ajaxurl,
1188
- type : 'POST',
1189
- data : data,
1190
- })
1191
- .fail(function( jqXHR ){
1192
-
1193
- // Remove loader.
1194
- jQuery('.required-plugins').removeClass('loading').html('');
1195
-
1196
- AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText, 'plugins' );
1197
- AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
1198
- })
1199
- .done(function ( response ) {
1200
-
1201
- // Release disabled class from import button.
1202
- $('.astra-demo-import')
1203
- .removeClass('disabled not-click-able')
1204
- .attr('data-import', 'disabled');
1205
-
1206
- // Remove loader.
1207
- $('.required-plugins').removeClass('loading').html('');
1208
-
1209
- /**
1210
- * Count remaining plugins.
1211
- * @type number
1212
- */
1213
- var remaining_plugins = 0;
1214
-
1215
- /**
1216
- * Not Installed
1217
- *
1218
- * List of not installed required plugins.
1219
- */
1220
- if ( typeof response.data.notinstalled !== 'undefined' ) {
1221
-
1222
- // Add not have installed plugins count.
1223
- remaining_plugins += parseInt( response.data.notinstalled.length );
1224
-
1225
- jQuery( response.data.notinstalled ).each(function( index, plugin ) {
1226
-
1227
- var output = '<div class="plugin-card ';
1228
- output += ' plugin-card-'+plugin.slug+'"';
1229
- output += ' data-slug="'+plugin.slug+'"';
1230
- output += ' data-init="'+plugin.init+'">';
1231
- output += ' <span class="title">'+plugin.name+'</span>';
1232
- output += ' <button class="button install-now"';
1233
- output += ' data-init="' + plugin.init + '"';
1234
- output += ' data-slug="' + plugin.slug + '"';
1235
- output += ' data-name="' + plugin.name + '">';
1236
- output += wp.updates.l10n.installNow;
1237
- output += ' </button>';
1238
- // output += ' <span class="dashicons-no dashicons"></span>';
1239
- output += '</div>';
1240
-
1241
- jQuery('.required-plugins').append(output);
1242
-
1243
- });
1244
- }
1245
-
1246
- /**
1247
- * Inactive
1248
- *
1249
- * List of not inactive required plugins.
1250
- */
1251
- if ( typeof response.data.inactive !== 'undefined' ) {
1252
-
1253
- // Add inactive plugins count.
1254
- remaining_plugins += parseInt( response.data.inactive.length );
1255
-
1256
- jQuery( response.data.inactive ).each(function( index, plugin ) {
1257
-
1258
- var output = '<div class="plugin-card ';
1259
- output += ' plugin-card-'+plugin.slug+'"';
1260
- output += ' data-slug="'+plugin.slug+'"';
1261
- output += ' data-init="'+plugin.init+'">';
1262
- output += ' <span class="title">'+plugin.name+'</span>';
1263
- output += ' <button class="button activate-now button-primary"';
1264
- output += ' data-init="' + plugin.init + '"';
1265
- output += ' data-slug="' + plugin.slug + '"';
1266
- output += ' data-name="' + plugin.name + '">';
1267
- output += wp.updates.l10n.activatePlugin;
1268
- output += ' </button>';
1269
- // output += ' <span class="dashicons-no dashicons"></span>';
1270
- output += '</div>';
1271
-
1272
- jQuery('.required-plugins').append(output);
1273
-
1274
- });
1275
- }
1276
-
1277
- /**
1278
- * Active
1279
- *
1280
- * List of not active required plugins.
1281
- */
1282
- if ( typeof response.data.active !== 'undefined' ) {
1283
-
1284
- jQuery( response.data.active ).each(function( index, plugin ) {
1285
-
1286
- var output = '<div class="plugin-card ';
1287
- output += ' plugin-card-'+plugin.slug+'"';
1288
- output += ' data-slug="'+plugin.slug+'"';
1289
- output += ' data-init="'+plugin.init+'">';
1290
- output += ' <span class="title">'+plugin.name+'</span>';
1291
- output += ' <button class="button disabled"';
1292
- output += ' data-slug="' + plugin.slug + '"';
1293
- output += ' data-name="' + plugin.name + '">';
1294
- output += astraSitesAdmin.strings.btnActive;
1295
- output += ' </button>';
1296
- // output += ' <span class="dashicons-yes dashicons"></span>';
1297
- output += '</div>';
1298
-
1299
- jQuery('.required-plugins').append(output);
1300
-
1301
- });
1302
- }
1303
-
1304
- /**
1305
- * Enable Demo Import Button
1306
- * @type number
1307
- */
1308
- astraSitesAdmin.requiredPlugins = response.data;
1309
- AstraSitesAdmin._enable_demo_import_button();
1310
-
1311
- });
1312
-
1313
- } else {
1314
-
1315
- // Enable Demo Import Button
1316
- AstraSitesAdmin._enable_demo_import_button( demoType );
1317
- jQuery('.required-plugins-wrap').remove();
1318
- }
1319
-
1320
- return;
1321
- },
1322
-
1323
- /**
1324
- * Enable Demo Import Button.
1325
- */
1326
- _enable_demo_import_button: function( type ) {
1327
-
1328
- type = ( undefined !== type ) ? type : 'free';
1329
-
1330
- $('.install-theme-info .theme-details .site-description').remove();
1331
-
1332
- switch( type ) {
1333
-
1334
- case 'free':
1335
- var all_buttons = parseInt( jQuery( '.plugin-card .button' ).length ) || 0,
1336
- disabled_buttons = parseInt( jQuery( '.plugin-card .button.disabled' ).length ) || 0;
1337
-
1338
- if( all_buttons === disabled_buttons ) {
1339
-
1340
- // XML reader not available notice.
1341
- if( astraSitesAdmin.XMLReaderDisabled ) {
1342
- if( ! $('.install-theme-info .astra-sites-xml-notice').length ) {
1343
- $('.install-theme-info').prepend( astraSitesAdmin.strings.warningXMLReader );
1344
- }
1345
- $('.astra-demo-import')
1346
- .removeClass('installing updating-message')
1347
- .addClass('disabled')
1348
- .text( astraSitesAdmin.strings.importDemo );
1349
- } else {
1350
- $('.astra-demo-import')
1351
- .removeAttr('data-import')
1352
- .removeClass('installing updating-message')
1353
- .addClass('button-primary')
1354
- .text( astraSitesAdmin.strings.importDemo );
1355
- }
1356
- }
1357
-
1358
- break;
1359
-
1360
- case 'upgrade':
1361
- var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
1362
-
1363
- jQuery('.astra-demo-import')
1364
- .addClass('go-pro button-primary')
1365
- .removeClass('astra-demo-import')
1366
- .attr('target', '_blank')
1367
- .attr('href', astraSitesAdmin.getUpgradeURL + demo_slug )
1368
- .text( astraSitesAdmin.getUpgradeText )
1369
- .append('<i class="dashicons dashicons-external"></i>');
1370
-
1371
- break;
1372
-
1373
- default:
1374
- var demo_slug = jQuery('.wp-full-overlay-header').attr('data-demo-slug');
1375
-
1376
- jQuery('.astra-demo-import')
1377
- .addClass('go-pro button-primary')
1378
- .removeClass('astra-demo-import')
1379
- .attr('target', '_blank')
1380
- .attr('href', astraSitesAdmin.getProURL )
1381
- .text( astraSitesAdmin.getProText )
1382
- .append('<i class="dashicons dashicons-external"></i>');
1383
-
1384
- if( false == astraSitesAdmin.isWhiteLabeled ) {
1385
- if( astraSitesAdmin.isPro ) {
1386
- $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-inactive-site-description') );
1387
- } else {
1388
- $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-site-description') );
1389
- }
1390
- }
1391
-
1392
- break;
1393
- }
1394
-
1395
- },
1396
-
1397
- /**
1398
- * Update Page Count.
1399
- */
1400
- _updatedPagedCount: function() {
1401
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
1402
- jQuery('body').attr('data-astra-demo-paged', paged + 1);
1403
- window.setTimeout(function () {
1404
- jQuery('body').data('scrolling', false);
1405
- }, 800);
1406
- },
1407
-
1408
- /**
1409
- * Reset Page Count.
1410
- */
1411
- _resetPagedCount: function() {
1412
-
1413
- $('body').addClass('loading-content');
1414
- $('body').attr('data-astra-demo-last-request', '1');
1415
- $('body').attr('data-astra-demo-paged', '1');
1416
- $('body').attr('data-astra-demo-search', '');
1417
- $('body').attr('data-scrolling', false);
1418
-
1419
- },
1420
-
1421
- /**
1422
- * Remove plugin from the queue.
1423
- */
1424
- _removePluginFromQueue: function( removeItem, pluginsList ) {
1425
- return jQuery.grep(pluginsList, function( value ) {
1426
- return value.slug != removeItem;
1427
- });
1428
- }
1429
-
1430
- };
1431
-
1432
- /**
1433
- * Initialize AstraSitesAdmin
1434
- */
1435
- $(function(){
1436
- AstraSitesAdmin.init();
1437
- });
1438
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1439
  })(jQuery);
1
+ /**
2
+ * AJAX Request Queue
3
+ *
4
+ * - add()
5
+ * - remove()
6
+ * - run()
7
+ * - stop()
8
+ *
9
+ * @since 1.0.0
10
+ */
11
+ var AstraSitesAjaxQueue = (function() {
12
+
13
+ var requests = [];
14
+
15
+ return {
16
+
17
+ /**
18
+ * Add AJAX request
19
+ *
20
+ * @since 1.0.0
21
+ */
22
+ add: function(opt) {
23
+ requests.push(opt);
24
+ },
25
+
26
+ /**
27
+ * Remove AJAX request
28
+ *
29
+ * @since 1.0.0
30
+ */
31
+ remove: function(opt) {
32
+ if( jQuery.inArray(opt, requests) > -1 )
33
+ requests.splice($.inArray(opt, requests), 1);
34
+ },
35
+
36
+ /**
37
+ * Run / Process AJAX request
38
+ *
39
+ * @since 1.0.0
40
+ */
41
+ run: function() {
42
+ var self = this,
43
+ oriSuc;
44
+
45
+ if( requests.length ) {
46
+ oriSuc = requests[0].complete;
47
+
48
+ requests[0].complete = function() {
49
+ if( typeof(oriSuc) === 'function' ) oriSuc();
50
+ requests.shift();
51
+ self.run.apply(self, []);
52
+ };
53
+
54
+ jQuery.ajax(requests[0]);
55
+
56
+ } else {
57
+
58
+ self.tid = setTimeout(function() {
59
+ self.run.apply(self, []);
60
+ }, 1000);
61
+ }
62
+ },
63
+
64
+ /**
65
+ * Stop AJAX request
66
+ *
67
+ * @since 1.0.0
68
+ */
69
+ stop: function() {
70
+
71
+ requests = [];
72
+ clearTimeout(this.tid);
73
+ }
74
+ };
75
+
76
+ }());
77
+
78
+ (function($){
79
+
80
+ var AstraSSEImport = {
81
+ complete: {
82
+ posts: 0,
83
+ media: 0,
84
+ users: 0,
85
+ comments: 0,
86
+ terms: 0,
87
+ },
88
+
89
+ updateDelta: function (type, delta) {
90
+ this.complete[ type ] += delta;
91
+
92
+ var self = this;
93
+ requestAnimationFrame(function () {
94
+ self.render();
95
+ });
96
+ },
97
+ updateProgress: function ( type, complete, total ) {
98
+ var text = complete + '/' + total;
99
+
100
+ if( 'undefined' !== type && 'undefined' !== text ) {
101
+ total = parseInt( total, 10 );
102
+ if ( 0 === total || isNaN( total ) ) {
103
+ total = 1;
104
+ }
105
+ var percent = parseInt( complete, 10 ) / total;
106
+ var progress = Math.round( percent * 100 ) + '%';
107
+ var progress_bar = percent * 100;
108
+
109
+ if( progress_bar <= 100 ) {
110
+ document.getElementById( 'astra-site-import-process' ).value = progress_bar;
111
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingXML + ' '+progress );
112
+ }
113
+ }
114
+ },
115
+ render: function () {
116
+ var types = Object.keys( this.complete );
117
+ var complete = 0;
118
+ var total = 0;
119
+
120
+
121
+ for (var i = types.length - 1; i >= 0; i--) {
122
+ var type = types[i];
123
+ this.updateProgress( type, this.complete[ type ], this.data.count[ type ] );
124
+
125
+ complete += this.complete[ type ];
126
+ total += this.data.count[ type ];
127
+ }
128
+
129
+ this.updateProgress( 'total', complete, total );
130
+ }
131
+ };
132
+
133
+ AstraSitesAdmin = {
134
+
135
+ reset_remaining_posts: 0,
136
+ reset_remaining_wp_forms: 0,
137
+ reset_remaining_terms: 0,
138
+ reset_processed_posts: 0,
139
+ reset_processed_wp_forms: 0,
140
+ reset_processed_terms: 0,
141
+ site_imported_data: null,
142
+
143
+ backup_taken: false,
144
+
145
+ current_site: [],
146
+ current_screen: '',
147
+
148
+ templateData: {},
149
+
150
+ log_file : '',
151
+ customizer_data : '',
152
+ wxr_url : '',
153
+ wpforms_url : '',
154
+ options_data : '',
155
+ widgets_data : '',
156
+
157
+ init: function()
158
+ {
159
+ this._resetPagedCount();
160
+ this._bind();
161
+ },
162
+
163
+ /**
164
+ * Debugging.
165
+ *
166
+ * @param {mixed} data Mixed data.
167
+ */
168
+ _log: function( data ) {
169
+
170
+ if( astraSitesAdmin.debug ) {
171
+
172
+ var date = new Date();
173
+ var time = date.toLocaleTimeString();
174
+
175
+ if (typeof data == 'object') {
176
+ console.log('%c ' + JSON.stringify( data ) + ' ' + time, 'background: #ededed; color: #444');
177
+ } else {
178
+ console.log('%c ' + data + ' ' + time, 'background: #ededed; color: #444');
179
+ }
180
+
181
+
182
+ }
183
+ },
184
+
185
+ /**
186
+ * Binds events for the Astra Sites.
187
+ *
188
+ * @since 1.0.0
189
+ * @access private
190
+ * @method _bind
191
+ */
192
+ _bind: function()
193
+ {
194
+ $( document ).on( 'click' , '.astra-sites-reset-data .checkbox', AstraSitesAdmin._toggle_reset_notice );
195
+ $( document ).on('change' , '#astra-sites-welcome-form-inline select', AstraSitesAdmin._change_page_builder);
196
+ $( document ).on('click' , '.astra-sites-tooltip-icon', AstraSitesAdmin._toggle_tooltip);
197
+ $( document ).on('click' , '.astra-sites-advanced-options-button', AstraSitesAdmin._toggle_advanced_options);
198
+
199
+ $( document ).on('click' , '.astra-import-settings', AstraSitesAdmin._import_settings);
200
+ $( document ).on('click' , '.devices button', AstraSitesAdmin._previewDevice);
201
+ $( document ).on('click' , '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSitesAdmin._preview);
202
+ $( document ).on('click' , '.next-theme', AstraSitesAdmin._nextTheme);
203
+ $( document ).on('click' , '.previous-theme', AstraSitesAdmin._previousTheme);
204
+ $( document ).on('click' , '.collapse-sidebar', AstraSitesAdmin._collapse);
205
+ $( document ).on('click' , '.astra-demo-import', AstraSitesAdmin._importDemo);
206
+
207
+ $( document ).on('astra-sites-install-and-activate-required-plugins-done' , AstraSitesAdmin._process_import );
208
+
209
+ $( document ).on('click' , '.install-now', AstraSitesAdmin._installNow);
210
+ $( document ).on('click' , '.close-full-overlay', AstraSitesAdmin._fullOverlay);
211
+ $( document ).on('click' , '.activate-now', AstraSitesAdmin._activateNow);
212
+ $( document ).on('wp-plugin-installing' , AstraSitesAdmin._pluginInstalling);
213
+ $( document ).on('wp-plugin-install-error' , AstraSitesAdmin._installError);
214
+ $( document ).on('wp-plugin-install-success' , AstraSitesAdmin._installSuccess);
215
+
216
+ $( document ).on( 'astra-sites-import-set-site-data-done' , AstraSitesAdmin._resetData );
217
+ $( document ).on( 'astra-sites-reset-data' , AstraSitesAdmin._backup_before_rest_options );
218
+ $( document ).on( 'astra-sites-backup-settings-before-reset-done' , AstraSitesAdmin._reset_customizer_data );
219
+ $( document ).on( 'astra-sites-reset-customizer-data-done' , AstraSitesAdmin._reset_site_options );
220
+ $( document ).on( 'astra-sites-reset-site-options-done' , AstraSitesAdmin._reset_widgets_data );
221
+ $( document ).on( 'astra-sites-reset-widgets-data-done' , AstraSitesAdmin._reset_terms );
222
+ $( document ).on( 'astra-sites-delete-terms-done' , AstraSitesAdmin._reset_wp_forms );
223
+ $( document ).on( 'astra-sites-delete-wp-forms-done' , AstraSitesAdmin._reset_posts );
224
+
225
+ $( document ).on('astra-sites-reset-data-done' , AstraSitesAdmin._recheck_backup_options );
226
+ $( document ).on('astra-sites-backup-settings-done' , AstraSitesAdmin._importWPForms );
227
+ $( document ).on('astra-sites-import-wpforms-done' , AstraSitesAdmin._importCustomizerSettings );
228
+ $( document ).on('astra-sites-import-customizer-settings-done' , AstraSitesAdmin._importXML );
229
+ $( document ).on('astra-sites-import-xml-done' , AstraSitesAdmin._importSiteOptions );
230
+ $( document ).on('astra-sites-import-options-done' , AstraSitesAdmin._importWidgets );
231
+ $( document ).on('astra-sites-import-widgets-done' , AstraSitesAdmin._importEnd );
232
+
233
+ },
234
+
235
+ _change_page_builder: function() {
236
+ $(this).closest('form').submit();
237
+ },
238
+
239
+ _toggle_tooltip: function( event ) {
240
+ event.preventDefault();
241
+ var tip_id = $( this ).data('tip-id') || '';
242
+ if( tip_id && $( '#' + tip_id ).length ) {
243
+ $( '#' + tip_id ).toggle();
244
+ }
245
+ },
246
+
247
+ _toggle_advanced_options: function( event ) {
248
+ event.preventDefault();
249
+ $('.astra-sites-advanced-options').toggle();
250
+ },
251
+
252
+ _resetData: function( event ) {
253
+ event.preventDefault();
254
+
255
+ if ( $( '.astra-sites-reset-data' ).find('.checkbox').is(':checked') ) {
256
+ $(document).trigger( 'astra-sites-reset-data' );
257
+ } else {
258
+ $(document).trigger( 'astra-sites-reset-data-done' );
259
+ }
260
+ },
261
+
262
+ _reset_customizer_data() {
263
+ $.ajax({
264
+ url : astraSitesAdmin.ajaxurl,
265
+ type : 'POST',
266
+ data : {
267
+ action : 'astra-sites-reset-customizer-data'
268
+ },
269
+ beforeSend: function() {
270
+ AstraSitesAdmin._log( 'Reseting Customizer Data' );
271
+ $('.button-hero.astra-demo-import').text( 'Reseting Customizer Data' );
272
+ },
273
+ })
274
+ .fail(function( jqXHR ){
275
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
276
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
277
+ })
278
+ .done(function ( data ) {
279
+ $(document).trigger( 'astra-sites-reset-customizer-data-done' );
280
+ });
281
+ },
282
+
283
+ _reset_site_options: function() {
284
+ // Site Options.
285
+ $.ajax({
286
+ url : astraSitesAdmin.ajaxurl,
287
+ type : 'POST',
288
+ data : {
289
+ action : 'astra-sites-reset-site-options'
290
+ },
291
+ beforeSend: function() {
292
+ AstraSitesAdmin._log( 'Reseting Site Options' );
293
+ $('.button-hero.astra-demo-import').text( 'Reseting Site Options' );
294
+ },
295
+ })
296
+ .fail(function( jqXHR ){
297
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
298
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
299
+ })
300
+ .done(function ( data ) {
301
+
302
+
303
+ $(document).trigger( 'astra-sites-reset-site-options-done' );
304
+ });
305
+ },
306
+
307
+ _reset_widgets_data: function() {
308
+ // Widgets.
309
+ $.ajax({
310
+ url : astraSitesAdmin.ajaxurl,
311
+ type : 'POST',
312
+ data : {
313
+ action : 'astra-sites-reset-widgets-data'
314
+ },
315
+ beforeSend: function() {
316
+ AstraSitesAdmin._log( 'Reseting Widgets' );
317
+ $('.button-hero.astra-demo-import').text( 'Reseting Widgets' );
318
+ },
319
+ })
320
+ .fail(function( jqXHR ){
321
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
322
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
323
+ })
324
+ .done(function ( data ) {
325
+ AstraSitesAdmin._log( data );
326
+ $(document).trigger( 'astra-sites-reset-widgets-data-done' );
327
+ });
328
+ },
329
+
330
+ _reset_posts: function() {
331
+ if( AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
332
+
333
+ AstraSitesAdmin.reset_remaining_posts = AstraSitesAdmin.site_imported_data['reset_posts'].length;
334
+
335
+ // Delete all posts.
336
+ // AstraSitesAjaxQueue.stop();
337
+ // AstraSitesAjaxQueue.run();
338
+
339
+ $.each( AstraSitesAdmin.site_imported_data['reset_posts'], function(index, post_id) {
340
+ AstraSitesAjaxQueue.add({
341
+ url: astraSitesAdmin.ajaxurl,
342
+ type: 'POST',
343
+ data: {
344
+ action : 'astra-sites-delete-posts',
345
+ post_id : post_id,
346
+ },
347
+ success: function( result ){
348
+
349
+ if( AstraSitesAdmin.reset_processed_posts < AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
350
+ AstraSitesAdmin.reset_processed_posts+=1;
351
+ }
352
+
353
+ $('.button-hero.astra-demo-import').text( 'Deleting Item ' + AstraSitesAdmin.reset_processed_posts + ' of ' + AstraSitesAdmin.site_imported_data['reset_posts'].length );
354
+ AstraSitesAdmin.reset_remaining_posts-=1;
355
+ if( 0 == AstraSitesAdmin.reset_remaining_posts ) {
356
+ $(document).trigger( 'astra-sites-delete-posts-done' );
357
+ $(document).trigger( 'astra-sites-reset-data-done' );
358
+ }
359
+ }
360
+ });
361
+ });
362
+ AstraSitesAjaxQueue.run();
363
+
364
+ } else {
365
+ $(document).trigger( 'astra-sites-delete-posts-done' );
366
+ $(document).trigger( 'astra-sites-reset-data-done' );
367
+ }
368
+ },
369
+
370
+ _reset_wp_forms: function() {
371
+
372
+ AstraSitesAdmin._log( AstraSitesAdmin.site_imported_data['reset_wp_forms'] );
373
+ AstraSitesAdmin._log( AstraSitesAdmin.site_imported_data['reset_wp_forms'].length );
374
+
375
+ if( AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
376
+ AstraSitesAdmin.reset_remaining_wp_forms = AstraSitesAdmin.site_imported_data['reset_wp_forms'].length;
377
+
378
+ $.each( AstraSitesAdmin.site_imported_data['reset_wp_forms'], function(index, post_id) {
379
+ AstraSitesAdmin._log( 'WP Form ID: ' + post_id );
380
+ AstraSitesAjaxQueue.add({
381
+ url: astraSitesAdmin.ajaxurl,
382
+ type: 'POST',
383
+ data: {
384
+ action : 'astra-sites-delete-wp-forms',
385
+ post_id : post_id,
386
+ },
387
+ success: function( result ){
388
+ AstraSitesAdmin._log( 'WP Forms Results' );
389
+ AstraSitesAdmin._log( result );
390
+ if( AstraSitesAdmin.reset_processed_wp_forms < AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
391
+ AstraSitesAdmin.reset_processed_wp_forms+=1;
392
+ }
393
+
394
+ $('.button-hero.astra-demo-import').text( 'Deleting Form ' + AstraSitesAdmin.reset_processed_wp_forms + ' of ' + AstraSitesAdmin.site_imported_data['reset_wp_forms'].length );
395
+ AstraSitesAdmin.reset_remaining_wp_forms-=1;
396
+ if( 0 == AstraSitesAdmin.reset_remaining_wp_forms ) {
397
+ $(document).trigger( 'astra-sites-delete-wp-forms-done' );
398
+ }
399
+ }
400
+ });
401
+ });
402
+ AstraSitesAjaxQueue.run();
403
+
404
+ } else {
405
+ $(document).trigger( 'astra-sites-delete-wp-forms-done' );
406
+ }
407
+ },
408
+
409
+
410
+ _reset_terms: function() {
411
+
412
+ AstraSitesAdmin._log( AstraSitesAdmin.site_imported_data['reset_terms'] );
413
+ AstraSitesAdmin._log( AstraSitesAdmin.site_imported_data['reset_terms'].length );
414
+
415
+ if( AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
416
+ AstraSitesAdmin.reset_remaining_terms = AstraSitesAdmin.site_imported_data['reset_terms'].length;
417
+
418
+ $.each( AstraSitesAdmin.site_imported_data['reset_terms'], function(index, term_id) {
419
+ AstraSitesAjaxQueue.add({
420
+ url: astraSitesAdmin.ajaxurl,
421
+ type: 'POST',
422
+ data: {
423
+ action : 'astra-sites-delete-terms',
424
+ term_id : term_id,
425
+ },
426
+ success: function( result ){
427
+ if( AstraSitesAdmin.reset_processed_terms < AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
428
+ AstraSitesAdmin.reset_processed_terms+=1;
429
+ }
430
+ AstraSitesAdmin._log( result );
431
+ $('.button-hero.astra-demo-import').text( 'Deleting Term ' + AstraSitesAdmin.reset_processed_terms + ' of ' + AstraSitesAdmin.site_imported_data['reset_terms'].length );
432
+ AstraSitesAdmin.reset_remaining_terms-=1;
433
+ AstraSitesAdmin._log( AstraSitesAdmin.reset_remaining_terms );
434
+ if( 0 == AstraSitesAdmin.reset_remaining_terms ) {
435
+ $(document).trigger( 'astra-sites-delete-terms-done' );
436
+ }
437
+ }
438
+ });
439
+ });
440
+ AstraSitesAjaxQueue.run();
441
+
442
+ } else {
443
+ $(document).trigger( 'astra-sites-delete-terms-done' );
444
+ }
445
+
446
+ },
447
+
448
+ _toggle_reset_notice: function() {
449
+ if ( $( this ).is(':checked') ) {
450
+ $('#astra-sites-tooltip-reset-data').show();
451
+ } else {
452
+ $('#astra-sites-tooltip-reset-data').hide();
453
+ }
454
+ },
455
+
456
+ _backup_before_rest_options: function() {
457
+ AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-before-reset-done' );
458
+ AstraSitesAdmin.backup_taken = true;
459
+ },
460
+
461
+ _recheck_backup_options: function() {
462
+ AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-done' );
463
+ AstraSitesAdmin.backup_taken = true;
464
+ },
465
+
466
+ _backupOptions: function( trigger_name ) {
467
+ $.ajax({
468
+ url : astraSitesAdmin.ajaxurl,
469
+ type : 'POST',
470
+ data : {
471
+ action : 'astra-sites-backup-settings',
472
+ },
473
+ beforeSend: function() {
474
+ AstraSitesAdmin._log( astraSitesAdmin.log.importWPForms );
475
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.backupCustomizer );
476
+ },
477
+ })
478
+ .fail(function( jqXHR ){
479
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
480
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
481
+ })
482
+ .done(function ( data ) {
483
+
484
+ // 1. Pass - Import Customizer Options.
485
+ AstraSitesAdmin._log( astraSitesAdmin.log.backupCustomizerSuccess );
486
+
487
+ // Custom trigger.
488
+ $(document).trigger( trigger_name );
489
+ });
490
+ },
491
+
492
+ _import_settings: function( event ) {
493
+ event.preventDefault();
494
+
495
+ var btn = $(this);
496
+
497
+ btn.addClass('updating-message');
498
+
499
+
500
+ $.ajax({
501
+ url : astraSitesAdmin.ajaxurl,
502
+ type : 'POST',
503
+ dataType: 'json',
504
+ data : {
505
+ action : 'astra-sites-import-customizer-settings',
506
+ customizer_data : AstraSitesAdmin.current_site['astra-site-customizer-data'],
507
+ },
508
+ beforeSend: function() {
509
+ AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizer );
510
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingCustomizer );
511
+ },
512
+ })
513
+ .fail(function( jqXHR ){
514
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
515
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
516
+ })
517
+ .done(function ( customizer_data ) {
518
+
519
+ btn.removeClass( 'updating-message' );
520
+
521
+ // 1. Fail - Import Customizer Options.
522
+ if( false === customizer_data.success ) {
523
+ AstraSitesAdmin._importFailMessage( customizer_data.data );
524
+ AstraSitesAdmin._log( customizer_data.data );
525
+ } else {
526
+
527
+ // 1. Pass - Import Customizer Options.
528
+ AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizerSuccess );
529
+
530
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
531
+ }
532
+ });
533
+ },
534
+
535
+ /**
536
+ * 5. Import Complete.
537
+ */
538
+ _importEnd: function( event ) {
539
+
540
+ $.ajax({
541
+ url : astraSitesAdmin.ajaxurl,
542
+ type : 'POST',
543
+ dataType: 'json',
544
+ data : {
545
+ action : 'astra-sites-import-end',
546
+ },
547
+ beforeSend: function() {
548
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importComplete );
549
+ }
550
+ })
551
+ .fail(function( jqXHR ){
552
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
553
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
554
+ })
555
+ .done(function ( data ) {
556
+
557
+ // 5. Fail - Import Complete.
558
+ if( false === data.success ) {
559
+ AstraSitesAdmin._importFailMessage( data.data );
560
+ AstraSitesAdmin._log( data.data );
561
+ } else {
562
+
563
+ $('body').removeClass('importing-site');
564
+ $('.previous-theme, .next-theme').removeClass('disabled');
565
+
566
+ // 5. Pass - Import Complete.
567
+ AstraSitesAdmin._importSuccessMessage();
568
+ AstraSitesAdmin._log( astraSitesAdmin.log.success + ' ' + astraSitesAdmin.siteURL );
569
+ }
570
+ });
571
+ },
572
+
573
+ /**
574
+ * 4. Import Widgets.
575
+ */
576
+ _importWidgets: function( event ) {
577
+ if ( AstraSitesAdmin._is_process_widgets() ) {
578
+ $.ajax({
579
+ url : astraSitesAdmin.ajaxurl,
580
+ type : 'POST',
581
+ dataType: 'json',
582
+ data : {
583
+ action : 'astra-sites-import-widgets',
584
+ widgets_data : AstraSitesAdmin.widgets_data,
585
+ },
586
+ beforeSend: function() {
587
+ AstraSitesAdmin._log( astraSitesAdmin.log.importWidgets );
588
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingWidgets );
589
+ },
590
+ })
591
+ .fail(function( jqXHR ){
592
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
593
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
594
+ })
595
+ .done(function ( widgets_data ) {
596
+
597
+ // 4. Fail - Import Widgets.
598
+ if( false === widgets_data.success ) {
599
+ AstraSitesAdmin._importFailMessage( widgets_data.data );
600
+ AstraSitesAdmin._log( widgets_data.data );
601
+
602
+ } else {
603
+
604
+ // 4. Pass - Import Widgets.
605
+ AstraSitesAdmin._log( astraSitesAdmin.log.importWidgetsSuccess );
606
+ $(document).trigger( 'astra-sites-import-widgets-done' );
607
+ }
608
+ });
609
+ } else {
610
+ $(document).trigger( 'astra-sites-import-widgets-done' );
611
+ }
612
+ },
613
+
614
+ /**
615
+ * 3. Import Site Options.
616
+ */
617
+ _importSiteOptions: function( event ) {
618
+
619
+ if ( AstraSitesAdmin._is_process_xml() ) {
620
+ $.ajax({
621
+ url : astraSitesAdmin.ajaxurl,
622
+ type : 'POST',
623
+ dataType: 'json',
624
+ data : {
625
+ action : 'astra-sites-import-options',
626
+ options_data : AstraSitesAdmin.options_data,
627
+ },
628
+ beforeSend: function() {
629
+ AstraSitesAdmin._log( astraSitesAdmin.log.importOptions );
630
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingOptions );
631
+ $('.astra-demo-import .percent').html('');
632
+ },
633
+ })
634
+ .fail(function( jqXHR ){
635
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
636
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
637
+ })
638
+ .done(function ( options_data ) {
639
+
640
+ // 3. Fail - Import Site Options.
641
+ if( false === options_data.success ) {
642
+ AstraSitesAdmin._log( options_data );
643
+ AstraSitesAdmin._importFailMessage( options_data.data );
644
+ AstraSitesAdmin._log( options_data.data );
645
+
646
+ } else {
647
+
648
+ // 3. Pass - Import Site Options.
649
+ AstraSitesAdmin._log( astraSitesAdmin.log.importOptionsSuccess );
650
+ $(document).trigger( 'astra-sites-import-options-done' );
651
+ }
652
+ });
653
+ } else {
654
+ $(document).trigger( 'astra-sites-import-options-done' );
655
+ }
656
+ },
657
+
658
+ /**
659
+ * 2. Prepare XML Data.
660
+ */
661
+ _importXML: function() {
662
+
663
+ if ( AstraSitesAdmin._is_process_xml() ) {
664
+ $.ajax({
665
+ url : astraSitesAdmin.ajaxurl,
666
+ type : 'POST',
667
+ dataType: 'json',
668
+ data : {
669
+ action : 'astra-sites-import-prepare-xml',
670
+ wxr_url : AstraSitesAdmin.current_site['astra-site-wxr-path'],
671
+ },
672
+ beforeSend: function() {
673
+ $('#astra-site-import-process-wrap').show();
674
+ AstraSitesAdmin._log( astraSitesAdmin.log.importXMLPrepare );
675
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importXMLPreparing );
676
+ },
677
+ })
678
+ .fail(function( jqXHR ){
679
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
680
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
681
+ })
682
+ .done(function ( xml_data ) {
683
+
684
+
685
+ // 2. Fail - Prepare XML Data.
686
+ if( false === xml_data.success ) {
687
+ AstraSitesAdmin._log( xml_data );
688
+ var error_msg = xml_data.data.error || xml_data.data;
689
+ AstraSitesAdmin._importFailMessage( error_msg );
690
+ AstraSitesAdmin._log( error_msg );
691
+
692
+ } else {
693
+
694
+ // 2. Pass - Prepare XML Data.
695
+ AstraSitesAdmin._log( astraSitesAdmin.log.importXMLPrepareSuccess );
696
+
697
+ // Import XML though Event Source.
698
+ AstraSSEImport.data = xml_data.data;
699
+ AstraSSEImport.render();
700
+
701
+ AstraSitesAdmin._log( astraSitesAdmin.log.importXML );
702
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingXML );
703
+
704
+ var evtSource = new EventSource( AstraSSEImport.data.url );
705
+ evtSource.onmessage = function ( message ) {
706
+ var data = JSON.parse( message.data );
707
+ switch ( data.action ) {
708
+ case 'updateDelta':
709
+ AstraSSEImport.updateDelta( data.type, data.delta );
710
+ break;
711
+
712
+ case 'complete':
713
+ evtSource.close();
714
+
715
+ // 2. Pass - Import XML though "Source Event".
716
+ AstraSitesAdmin._log( astraSitesAdmin.log.importXMLSuccess );
717
+ AstraSitesAdmin._log( '----- SSE - XML import Complete -----' );
718
+
719
+ document.getElementById( 'astra-site-import-process' ).value = 100;
720
+
721
+
722
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingXML + ' (100%)' );
723
+
724
+ $('#astra-site-import-process-wrap').hide();
725
+
726
+ $(document).trigger( 'astra-sites-import-xml-done' );
727
+
728
+ break;
729
+ }
730
+ };
731
+ evtSource.addEventListener( 'log', function ( message ) {
732
+ var data = JSON.parse( message.data );
733
+ AstraSitesAdmin._log( data.level + ' ' + data.message );
734
+ });
735
+ }
736
+ });
737
+ } else {
738
+ $(document).trigger( 'astra-sites-import-xml-done' );
739
+ }
740
+
741
+
742
+ },
743
+
744
+ _is_process_xml: function() {
745
+ if ( $( '.astra-sites-import-xml' ).find('.checkbox').is(':checked') ) {
746
+ return true;
747
+ }
748
+ return false;
749
+ },
750
+
751
+ _is_process_customizer: function() {
752
+ if ( $( '.astra-sites-import-customizer' ).find('.checkbox').is(':checked') ) {
753
+ return true;
754
+ }
755
+ return false;
756
+ },
757
+
758
+ _is_process_widgets: function() {
759
+ if ( $( '.astra-sites-import-widgets' ).find('.checkbox').is(':checked') ) {
760
+ return true;
761
+ }
762
+ return false;
763
+ },
764
+
765
+ /**
766
+ * 1. Import WPForms Options.
767
+ */
768
+ _importWPForms: function( event ) {
769
+ if ( AstraSitesAdmin._is_process_customizer() ) {
770
+ $.ajax({
771
+ url : astraSitesAdmin.ajaxurl,
772
+ type : 'POST',
773
+ dataType: 'json',
774
+ data : {
775
+ action : 'astra-sites-import-wpforms',
776
+ wpforms_url : AstraSitesAdmin.wpforms_url,
777
+ },
778
+ beforeSend: function() {
779
+ AstraSitesAdmin._log( astraSitesAdmin.log.importWPForms );
780
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingWPForms );
781
+ },
782
+ })
783
+ .fail(function( jqXHR ){
784
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
785
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
786
+ })
787
+ .done(function ( forms ) {
788
+
789
+ // 1. Fail - Import WPForms Options.
790
+ if( false === forms.success ) {
791
+ AstraSitesAdmin._importFailMessage( forms.data );
792
+ AstraSitesAdmin._log( forms.data );
793
+ } else {
794
+
795
+ // 1. Pass - Import Customizer Options.
796
+ AstraSitesAdmin._log( astraSitesAdmin.log.importWPFormsSuccess );
797
+
798
+ $(document).trigger( 'astra-sites-import-wpforms-done' );
799
+ }
800
+ });
801
+ } else {
802
+ $(document).trigger( 'astra-sites-import-wpforms-done' );
803
+ }
804
+ },
805
+
806
+ /**
807
+ * 1. Import Customizer Options.
808
+ */
809
+ _importCustomizerSettings: function( event ) {
810
+ if ( AstraSitesAdmin._is_process_customizer() ) {
811
+ $.ajax({
812
+ url : astraSitesAdmin.ajaxurl,
813
+ type : 'POST',
814
+ dataType: 'json',
815
+ data : {
816
+ action : 'astra-sites-import-customizer-settings',
817
+ customizer_data : AstraSitesAdmin.customizer_data,
818
+ },
819
+ beforeSend: function() {
820
+ AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizer );
821
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.importingCustomizer );
822
+ },
823
+ })
824
+ .fail(function( jqXHR ){
825
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText );
826
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
827
+ })
828
+ .done(function ( customizer_data ) {
829
+
830
+ // 1. Fail - Import Customizer Options.
831
+ if( false === customizer_data.success ) {
832
+ AstraSitesAdmin._importFailMessage( customizer_data.data );
833
+ AstraSitesAdmin._log( customizer_data.data );
834
+ } else {
835
+
836
+ // 1. Pass - Import Customizer Options.
837
+ AstraSitesAdmin._log( astraSitesAdmin.log.importCustomizerSuccess );
838
+
839
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
840
+ }
841
+ });
842
+ } else {
843
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
844
+ }
845
+
846
+ },
847
+
848
+ /**
849
+ * Import Success Button.
850
+ *
851
+ * @param {string} data Error message.
852
+ */
853
+ _importSuccessMessage: function() {
854
+
855
+ $('.astra-demo-import').removeClass('updating-message installing')
856
+ .removeAttr('data-import')
857
+ .addClass('view-site')
858
+ .removeClass('astra-demo-import')
859
+ .text( astraSitesAdmin.strings.viewSite )
860
+ .attr('target', '_blank')
861
+ .append('<i class="dashicons dashicons-external"></i>')
862
+ .attr('href', astraSitesAdmin.siteURL );
863
+ },
864
+
865
+ /**
866
+ * Preview Device
867
+ */
868
+ _previewDevice: function( event ) {
869
+ var device = $( event.currentTarget ).data( 'device' );
870
+
871
+ $('.theme-install-overlay')
872
+ .removeClass( 'preview-desktop preview-tablet preview-mobile' )
873
+ .addClass( 'preview-' + device )
874
+ .data( 'current-preview-device', device );
875
+
876
+ AstraSitesAdmin._tooglePreviewDeviceButtons( device );
877
+ },
878
+
879
+ /**
880
+ * Toggle Preview Buttons
881
+ */
882
+ _tooglePreviewDeviceButtons: function( newDevice ) {
883
+ var $devices = $( '.wp-full-overlay-footer .devices' );
884
+
885
+ $devices.find( 'button' )
886
+ .removeClass( 'active' )
887
+ .attr( 'aria-pressed', false );
888
+
889
+ $devices.find( 'button.preview-' + newDevice )
890
+ .addClass( 'active' )
891
+ .attr( 'aria-pressed', true );
892
+ },
893
+
894
+ /**
895
+ * Import Error Button.
896
+ *
897
+ * @param {string} data Error message.
898
+ */
899
+ _importFailMessage: function( message, from ) {
900
+
901
+ $('.astra-demo-import')
902
+ .addClass('go-pro button-primary')
903
+ .removeClass('updating-message installing')
904
+ .removeAttr('data-import')
905
+ .attr('target', '_blank')
906
+ .append('<i class="dashicons dashicons-external"></i>')
907
+ .removeClass('astra-demo-import');
908
+
909
+ // Add the doc link due to import log file not generated.
910
+ if( 'undefined' === from ) {
911
+
912
+ $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailedBtnSmall );
913
+ $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailedBtnLarge );
914
+ $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
915
+
916
+ // Add the import log file link.
917
+ } else {
918
+
919
+ $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
920
+ $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
921
+
922
+ // Add the import log file link.
923
+ if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
924
+ $('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
925
+ } else {
926
+ $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
927
+ }
928
+ }
929
+
930
+ var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
931
+ output += ' <p>'+message+'</p>';
932
+ output += ' <button type="button" class="notice-dismiss">';
933
+ output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
934
+ output += ' </button>';
935
+ output += '</div>';
936
+
937
+ // Fail Notice.
938
+ $('.install-theme-info').append( output );
939
+
940
+
941
+ // !important to add trigger.
942
+ // Which reinitialize the dismiss error message events.
943
+ $(document).trigger('wp-updates-notice-added');
944
+ },
945
+
946
+
947
+ /**
948
+ * Install Now
949
+ */
950
+ _installNow: function(event)
951
+ {
952
+ event.preventDefault();
953
+
954
+ var $button = jQuery( event.target ),
955
+ $document = jQuery(document);
956
+
957
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
958
+ return;
959
+ }
960
+
961
+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
962
+ wp.updates.requestFilesystemCredentials( event );
963
+
964
+ $document.on( 'credential-modal-cancel', function() {
965
+ var $message = $( '.install-now.updating-message' );
966
+
967
+ $message
968
+ .removeClass( 'updating-message' )
969
+ .text( wp.updates.l10n.installNow );
970
+
971
+ wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
972
+ } );
973
+ }
974
+
975
+ AstraSitesAdmin._log( astraSitesAdmin.log.installingPlugin + ' ' + $button.data( 'slug' ) );
976
+
977
+ wp.updates.installPlugin( {
978
+ slug: $button.data( 'slug' )
979
+ } );
980
+ },
981
+
982
+ /**
983
+ * Install Success
984
+ */
985
+ _installSuccess: function( event, response ) {
986
+
987
+ event.preventDefault();
988
+
989
+ AstraSitesAdmin._log( astraSitesAdmin.log.installed + ' ' + response.slug );
990
+
991
+ var $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val();
992
+ var $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
993
+
994
+ // Transform the 'Install' button into an 'Activate' button.
995
+ var $init = $( '.plugin-card-' + response.slug ).data('init');
996
+
997
+ // Reset not installed plugins list.
998
+ var pluginsList = astraSitesAdmin.requiredPlugins.notinstalled;
999
+ astraSitesAdmin.requiredPlugins.notinstalled = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1000
+
1001
+ // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
1002
+ setTimeout( function() {
1003
+
1004
+ $.ajax({
1005
+ url: astraSitesAdmin.ajaxurl,
1006
+ type: 'POST',
1007
+ data: {
1008
+ 'action' : 'astra-required-plugin-activate',
1009
+ 'init' : $init,
1010
+ 'options' : $siteOptions,
1011
+ 'enabledExtensions' : $enabledExtensions,
1012
+ },
1013
+ })
1014
+ .done(function (result) {
1015
+
1016
+ if( result.success ) {
1017
+
1018
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1019
+
1020
+ // Reset not installed plugins list.
1021
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1022
+
1023
+ // Enable Demo Import Button
1024
+ AstraSitesAdmin._enable_demo_import_button();
1025
+
1026
+ }
1027
+ });
1028
+
1029
+ }, 1200 );
1030
+
1031
+ },
1032
+
1033
+ /**
1034
+ * Plugin Installation Error.
1035
+ */
1036
+ _installError: function( event, response ) {
1037
+
1038
+ var $card = $( '.plugin-card-' + response.slug );
1039
+
1040
+ AstraSitesAdmin._log( response.errorMessage + ' ' + response.slug );
1041
+
1042
+ $card
1043
+ .removeClass( 'button-primary' )
1044
+ .addClass( 'disabled' )
1045
+ .html( wp.updates.l10n.installFailedShort );
1046
+
1047
+ AstraSitesAdmin._importFailMessage( response.errorMessage );
1048
+ },
1049
+
1050
+ /**
1051
+ * Installing Plugin
1052
+ */
1053
+ _pluginInstalling: function(event, args) {
1054
+ event.preventDefault();
1055
+
1056
+ var $card = $( '.plugin-card-' + args.slug );
1057
+
1058
+ AstraSitesAdmin._log( astraSitesAdmin.log.installingPlugin + ' ' + args.slug );
1059
+
1060
+ $card.addClass('updating-message');
1061
+
1062
+ },
1063
+
1064
+ /**
1065
+ * Render Demo Preview
1066
+ */
1067
+ _activateNow: function( eventn ) {
1068
+
1069
+ event.preventDefault();
1070
+
1071
+ var $button = jQuery( event.target ),
1072
+ $init = $button.data( 'init' ),
1073
+ $slug = $button.data( 'slug' );
1074
+
1075
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
1076
+ return;
1077
+ }
1078
+
1079
+ AstraSitesAdmin._log( astraSitesAdmin.log.activating + ' ' + $slug );
1080
+
1081
+ $button.addClass('updating-message button-primary')
1082
+ .html( astraSitesAdmin.strings.btnActivating );
1083
+
1084
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
1085
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1086
+
1087
+ $.ajax({
1088
+ url: astraSitesAdmin.ajaxurl,
1089
+ type: 'POST',
1090
+ data: {
1091
+ 'action' : 'astra-required-plugin-activate',
1092
+ 'init' : $init,
1093
+ 'options' : $siteOptions,
1094
+ 'enabledExtensions' : $enabledExtensions,
1095
+ },
1096
+ })
1097
+ .done(function (result) {
1098
+
1099
+ if( result.success ) {
1100
+
1101
+ AstraSitesAdmin._log( astraSitesAdmin.log.activated + ' ' + $slug );
1102
+
1103
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1104
+
1105
+ // Reset not installed plugins list.
1106
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( $slug, pluginsList );
1107
+
1108
+ $button.removeClass( 'button-primary install-now activate-now updating-message' )
1109
+ .attr('disabled', 'disabled')
1110
+ .addClass('disabled')
1111
+ .text( astraSitesAdmin.strings.btnActive );
1112
+
1113
+ // Enable Demo Import Button
1114
+ AstraSitesAdmin._enable_demo_import_button();
1115
+
1116
+ }
1117
+
1118
+ })
1119
+ .fail(function () {
1120
+ });
1121
+
1122
+ },
1123
+
1124
+ /**
1125
+ * Full Overlay
1126
+ */
1127
+ _fullOverlay: function (event) {
1128
+ event.preventDefault();
1129
+
1130
+ // Import process is started?
1131
+ // And Closing the window? Then showing the warning confirm message.
1132
+ if( $('body').hasClass('importing-site') && ! confirm( astraSitesAdmin.strings.warningBeforeCloseWindow ) ) {
1133
+ return;
1134
+ }
1135
+
1136
+ $('body').removeClass('importing-site');
1137
+ $('.previous-theme, .next-theme').removeClass('disabled');
1138
+ $('.theme-install-overlay').css('display', 'none');
1139
+ $('.theme-install-overlay').remove();
1140
+ $('.theme-preview-on').removeClass('theme-preview-on');
1141
+ $('html').removeClass('astra-site-preview-on');
1142
+ },
1143
+
1144
+ /**
1145
+ * Bulk Plugin Active & Install
1146
+ */
1147
+ _bulkPluginInstallActivate: function()
1148
+ {
1149
+ if( 0 === astraSitesAdmin.requiredPlugins.length ) {
1150
+ return;
1151
+ }
1152
+
1153
+ var not_installed = astraSitesAdmin.requiredPlugins.notinstalled || '';
1154
+ var activate_plugins = astraSitesAdmin.requiredPlugins.inactive || '';
1155
+
1156
+ // First Install Bulk.
1157
+ if( not_installed.length > 0 ) {
1158
+ AstraSitesAdmin._installAllPlugins( not_installed );
1159
+ }
1160
+
1161
+ // Second Activate Bulk.
1162
+ if( activate_plugins.length > 0 ) {
1163
+ AstraSitesAdmin._activateAllPlugins( activate_plugins );
1164
+ }
1165
+
1166
+ if( activate_plugins.length <= 0 && not_installed.length <= 0 ) {
1167
+ AstraSitesAdmin._enable_demo_import_button();
1168
+ }
1169
+
1170
+ },
1171
+
1172
+ /**
1173
+ * Activate All Plugins.
1174
+ */
1175
+ _activateAllPlugins: function( activate_plugins ) {
1176
+
1177
+ AstraSitesAdmin._log( astraSitesAdmin.log.bulkActivation );
1178
+
1179
+ $.each( activate_plugins, function(index, single_plugin) {
1180
+
1181
+ var $card = $( '.plugin-card-' + single_plugin.slug ),
1182
+ $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val(),
1183
+ $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1184
+
1185
+ AstraSitesAjaxQueue.add({
1186
+ url: astraSitesAdmin.ajaxurl,
1187
+ type: 'POST',
1188
+ data: {
1189
+ 'action' : 'astra-required-plugin-activate',
1190
+ 'init' : single_plugin.init,
1191
+ 'options' : $siteOptions,
1192
+ 'enabledExtensions' : $enabledExtensions,
1193
+ },
1194
+ success: function( result ){
1195
+
1196
+ if( result.success ) {
1197
+
1198
+ AstraSitesAdmin._log( astraSitesAdmin.log.activate + ' ' + single_plugin.slug );
1199
+
1200
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1201
+
1202
+ // Reset not installed plugins list.
1203
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( single_plugin.slug, pluginsList );
1204
+
1205
+ // Enable Demo Import Button
1206
+ AstraSitesAdmin._enable_demo_import_button();
1207
+ } else {
1208
+ AstraSitesAdmin._log( astraSitesAdmin.log.activationError + ' - ' + single_plugin.slug );
1209
+ }
1210
+ }
1211
+ });
1212
+ });
1213
+ AstraSitesAjaxQueue.run();
1214
+ },
1215
+
1216
+ /**
1217
+ * Install All Plugins.
1218
+ */
1219
+ _installAllPlugins: function( not_installed ) {
1220
+
1221
+ AstraSitesAdmin._log( astraSitesAdmin.log.bulkInstall );
1222
+
1223
+ $.each( not_installed, function(index, single_plugin) {
1224
+
1225
+ var $card = $( '.plugin-card-' + single_plugin.slug );
1226
+
1227
+ // Add each plugin activate request in Ajax queue.
1228
+ // @see wp-admin/js/updates.js
1229
+ wp.updates.queue.push( {
1230
+ action: 'install-plugin', // Required action.
1231
+ data: {
1232
+ slug: single_plugin.slug
1233
+ }
1234
+ } );
1235
+ });
1236
+
1237
+ // Required to set queue.
1238
+ wp.updates.queueChecker();
1239
+ },
1240
+
1241
+ /**
1242
+ * Fires when a nav item is clicked.
1243
+ *
1244
+ * @since 1.0
1245
+ * @access private
1246
+ * @method _importDemo
1247
+ */
1248
+ _importDemo: function(event) {
1249
+ event.preventDefault();
1250
+
1251
+ var disabled = $(this).attr('data-import');
1252
+
1253
+ if ( typeof disabled !== 'undefined' && disabled === 'disabled' || $this.hasClass('disabled') ) {
1254
+
1255
+ $('.astra-demo-import').addClass('updating-message installing')
1256
+ .text( wp.updates.l10n.installing );
1257
+
1258
+ /**
1259
+ * Process Bulk Plugin Install & Activate
1260
+ */
1261
+ AstraSitesAdmin._bulkPluginInstallActivate();
1262
+ }
1263
+ },
1264
+
1265
+ _process_import() {
1266
+
1267
+ var $theme = $('.astra-sites-preview').find('.wp-full-overlay-header'),
1268
+ apiURL = $theme.data('demo-api') || '';
1269
+
1270
+ $('body').addClass('importing-site');
1271
+ $('.previous-theme, .next-theme').addClass('disabled');
1272
+
1273
+ // Remove all notices before import start.
1274
+ $('.install-theme-info > .notice').remove();
1275
+
1276
+ $('.astra-demo-import').attr('data-import', 'disabled')
1277
+ .addClass('updating-message installing')
1278
+ .text( astraSitesAdmin.strings.importingDemo );
1279
+
1280
+ // Site Import by API URL.
1281
+ if( apiURL ) {
1282
+ AstraSitesAdmin._importSite( apiURL );
1283
+ }
1284
+
1285
+ },
1286
+
1287
+ /**
1288
+ * Start Import Process by API URL.
1289
+ *
1290
+ * @param {string} apiURL Site API URL.
1291
+ */
1292
+ _importSite: function( apiURL ) {
1293
+
1294
+ AstraSitesAdmin._log( astraSitesAdmin.log.api + ' : ' + apiURL );
1295
+ AstraSitesAdmin._log( astraSitesAdmin.log.importing );
1296
+
1297
+ $('.button-hero.astra-demo-import').text( astraSitesAdmin.log.gettingData );
1298
+
1299
+ // 1. Request Site Import
1300
+ $.ajax({
1301
+ url : astraSitesAdmin.ajaxurl,
1302
+ type : 'POST',
1303
+ dataType: 'json',
1304
+ data : {
1305
+ 'action' : 'astra-sites-import-set-site-data',
1306
+ 'api_url' : apiURL,
1307
+ },
1308
+ })
1309
+ .fail(function( jqXHR ){
1310
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
1311
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText );
1312
+ })
1313
+ .done(function ( demo_data ) {
1314
+
1315
+ // 1. Fail - Request Site Import
1316
+ if( false === demo_data.success ) {
1317
+
1318
+ AstraSitesAdmin._importFailMessage( demo_data.data );
1319
+
1320
+ } else {
1321
+
1322
+ // Set log file URL.
1323
+ if( 'log_file' in demo_data.data ){
1324
+ AstraSitesAdmin.log_file_url = decodeURIComponent( demo_data.data.log_file ) || '';
1325
+ }
1326
+
1327
+ // 1. Pass - Request Site Import
1328
+ AstraSitesAdmin._log( astraSitesAdmin.log.processingRequest );
1329
+
1330
+ AstraSitesAdmin.customizer_data = JSON.stringify( demo_data.data['astra-site-customizer-data'] ) || '';
1331
+ AstraSitesAdmin.wxr_url = encodeURI( demo_data.data['astra-site-wxr-path'] ) || '';
1332
+ AstraSitesAdmin.wpforms_url = encodeURI( demo_data.data['astra-site-wpforms-path'] ) || '';
1333
+ AstraSitesAdmin.options_data = JSON.stringify( demo_data.data['astra-site-options-data'] ) || '';
1334
+ AstraSitesAdmin.widgets_data = JSON.stringify( demo_data.data['astra-site-widgets-data'] ) || '';
1335
+
1336
+ $(document).trigger( 'astra-sites-import-set-site-data-done' );
1337
+ }
1338
+
1339
+ });
1340
+
1341
+ },
1342
+
1343
+ /**
1344
+ * Collapse Sidebar.
1345
+ */
1346
+ _collapse: function() {
1347
+ event.preventDefault();
1348
+
1349
+ overlay = jQuery('.wp-full-overlay');
1350
+
1351
+ if (overlay.hasClass('expanded')) {
1352
+ overlay.removeClass('expanded');
1353
+ overlay.addClass('collapsed');
1354
+ return;
1355
+ }
1356
+
1357
+ if (overlay.hasClass('collapsed')) {
1358
+ overlay.removeClass('collapsed');
1359
+ overlay.addClass('expanded');
1360
+ return;
1361
+ }
1362
+ },
1363
+
1364
+ /**
1365
+ * Previous Theme.
1366
+ */
1367
+ _previousTheme: function (event) {
1368
+ event.preventDefault();
1369
+
1370
+ currentDemo = jQuery('.theme-preview-on');
1371
+ currentDemo.removeClass('theme-preview-on');
1372
+ prevDemo = currentDemo.prev('.theme');
1373
+ prevDemo.addClass('theme-preview-on');
1374
+
1375
+ var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1376
+
1377
+ if( AstraSitesAPI._stored_data ) {
1378
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1379
+
1380
+
1381
+ if( site_data ) {
1382
+ // Set current site details.
1383
+ AstraSitesAdmin.current_site = site_data;
1384
+ }
1385
+ }
1386
+
1387
+ AstraSitesAdmin._renderDemoPreview(prevDemo);
1388
+ },
1389
+
1390
+ /**
1391
+ * Next Theme.
1392
+ */
1393
+ _nextTheme: function (event) {
1394
+ event.preventDefault();
1395
+ currentDemo = jQuery('.theme-preview-on')
1396
+ currentDemo.removeClass('theme-preview-on');
1397
+ nextDemo = currentDemo.next('.theme');
1398
+ nextDemo.addClass('theme-preview-on');
1399
+
1400
+ var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1401
+
1402
+ if( AstraSitesAPI._stored_data ) {
1403
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1404
+
1405
+
1406
+
1407
+ if( site_data ) {
1408
+ // Set current site details.
1409
+ AstraSitesAdmin.current_site = site_data;
1410
+ }
1411
+ }
1412
+
1413
+ AstraSitesAdmin._renderDemoPreview( nextDemo );
1414
+ },
1415
+
1416
+ _set_current_screen: function( screen ) {
1417
+ AstraSitesAdmin.current_screen = screen;
1418
+ var old_screen = $('.astra-sites-preview').attr( 'screen' ) || '';
1419
+
1420
+
1421
+ if( old_screen ) {
1422
+ $('.astra-sites-preview').removeClass( 'screen-' + old_screen );
1423
+ }
1424
+
1425
+ $('.astra-sites-preview').attr( 'screen', screen );
1426
+ $('.astra-sites-preview').addClass( 'screen-' + screen );
1427
+ },
1428
+
1429
+ /**
1430
+ * Individual Site Preview
1431
+ *
1432
+ * On click on image, more link & preview button.
1433
+ */
1434
+ _preview: function( event ) {
1435
+
1436
+ event.preventDefault();
1437
+
1438
+ var site_id = $(this).parents('.site-single').data('demo-id') || '';
1439
+
1440
+ if( AstraSitesAPI._stored_data ) {
1441
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1442
+
1443
+ if( site_data ) {
1444
+ // Set current site details.
1445
+ AstraSitesAdmin.current_site = site_data;
1446
+
1447
+ // Set current screen.
1448
+ AstraSitesAdmin._set_current_screen( 'get-started' );
1449
+ }
1450
+ }
1451
+
1452
+ var self = $(this).parents('.theme');
1453
+ self.addClass('theme-preview-on');
1454
+
1455
+ $('html').addClass('astra-site-preview-on');
1456
+
1457
+ AstraSitesAdmin._renderDemoPreview( self );
1458
+ },
1459
+
1460
+ _get_site_details: function( site_id ) {
1461
+ var all_sites = AstraSitesAPI._stored_data['astra-sites'] || [];
1462
+
1463
+ if( ! all_sites ) {
1464
+ return false;
1465
+ }
1466
+
1467
+ var single_site = all_sites.filter(function (site) { return site.id == site_id });
1468
+ if( ! single_site ) {
1469
+ return false;
1470
+ }
1471
+
1472
+ if( ! $.isArray( single_site ) ) {
1473
+ return false;
1474
+ }
1475
+
1476
+ return single_site[0];
1477
+ },
1478
+
1479
+ /**
1480
+ * Check Next Previous Buttons.
1481
+ */
1482
+ _checkNextPrevButtons: function() {
1483
+ currentDemo = jQuery('.theme-preview-on');
1484
+ nextDemo = currentDemo.nextAll('.theme').length;
1485
+ prevDemo = currentDemo.prevAll('.theme').length;
1486
+
1487
+ if (nextDemo == 0) {
1488
+ jQuery('.next-theme').addClass('disabled');
1489
+ } else if (nextDemo != 0) {
1490
+ jQuery('.next-theme').removeClass('disabled');
1491
+ }
1492
+
1493
+ if (prevDemo == 0) {
1494
+ jQuery('.previous-theme').addClass('disabled');
1495
+ } else if (prevDemo != 0) {
1496
+ jQuery('.previous-theme').removeClass('disabled');
1497
+ }
1498
+
1499
+ return;
1500
+ },
1501
+
1502
+ /**
1503
+ * Render Demo Preview
1504
+ */
1505
+ _renderDemoPreview: function(anchor) {
1506
+
1507
+ var demoId = anchor.data('demo-id') || '',
1508
+ apiURL = anchor.data('demo-api') || '',
1509
+ demoType = anchor.data('demo-type') || '',
1510
+ demoURL = anchor.data('demo-url') || '',
1511
+ screenshot = anchor.data('screenshot') || '',
1512
+ demo_name = anchor.data('demo-name') || '',
1513
+ demo_slug = anchor.data('demo-slug') || '',
1514
+ content = anchor.data('content') || '',
1515
+ requiredPlugins = anchor.data('required-plugins') || '',
1516
+ astraSiteOptions = anchor.find('.astra-site-options').val() || '';
1517
+ astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
1518
+
1519
+ AstraSitesAdmin._log( astraSitesAdmin.log.preview + ' "' + demo_name + '" URL : ' + demoURL );
1520
+
1521
+
1522
+ var template = wp.template('astra-site-preview');
1523
+
1524
+ templateData = [{
1525
+ id : demoId,
1526
+ astra_demo_type : demoType,
1527
+ astra_demo_url : demoURL,
1528
+ demo_api : apiURL,
1529
+ screenshot : screenshot,
1530
+ demo_name : demo_name,
1531
+ slug : demo_slug,
1532
+ content : content,
1533
+ required_plugins : JSON.stringify(requiredPlugins),
1534
+ astra_site_options : astraSiteOptions,
1535
+ astra_enabled_extensions : astraEnabledExtensions,
1536
+ }];
1537
+
1538
+ // return;
1539
+
1540
+ // delete any earlier fullscreen preview before we render new one.
1541
+ $('.theme-install-overlay').remove();
1542
+
1543
+ $('#astra-sites-menu-page').append(template(templateData[0]));
1544
+ $('.theme-install-overlay').css('display', 'block');
1545
+ AstraSitesAdmin._checkNextPrevButtons();
1546
+
1547
+ var desc = $('.theme-details');
1548
+ var descHeight = parseInt( desc.outerHeight() );
1549
+ var descBtn = $('.theme-details-read-more');
1550
+
1551
+ // Check is site imported recently and set flag.
1552
+ $.ajax({
1553
+ url : astraSitesAdmin.ajaxurl,
1554
+ type : 'POST',
1555
+ data : {
1556
+ action : 'astra-sites-set-reset-data',
1557
+ },
1558
+ })
1559
+ .done(function ( response ) {
1560
+ AstraSitesAdmin._log( response );
1561
+ if( response.success ) {
1562
+ AstraSitesAdmin.site_imported_data = response.data;
1563
+ }
1564
+ });
1565
+
1566
+ if( $.isArray( requiredPlugins ) ) {
1567
+
1568
+ if( descHeight >= 55 ) {
1569
+
1570
+ // Show button.
1571
+ descBtn.css( 'display', 'inline-block' );
1572
+
1573
+ // Set height upto 3 line.
1574
+ desc.css( 'height', 57 );
1575
+
1576
+ // Button Click.
1577
+ descBtn.click(function(event) {
1578
+
1579
+ if( descBtn.hasClass('open') ) {
1580
+ desc.animate({ height: 57 },
1581
+ 300, function() {
1582
+ descBtn.removeClass('open');
1583
+ descBtn.html( astraSitesAdmin.strings.DescExpand );
1584
+ });
1585
+ } else {
1586
+ desc.animate({ height: descHeight },
1587
+ 300, function() {
1588
+ descBtn.addClass('open');
1589
+ descBtn.html( astraSitesAdmin.strings.DescCollapse );
1590
+ });
1591
+ }
1592
+
1593
+ });
1594
+ }
1595
+
1596
+ // or
1597
+ var $pluginsFilter = $( '#plugin-filter' ),
1598
+ data = {
1599
+ action : 'astra-required-plugins',
1600
+ _ajax_nonce : astraSitesAdmin._ajax_nonce,
1601
+ required_plugins : requiredPlugins
1602
+ };
1603
+
1604
+ // Add disabled class from import button.
1605
+ $('.astra-demo-import')
1606
+ .addClass('disabled not-click-able')
1607
+ .removeAttr('data-import');
1608
+
1609
+ $('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
1610
+
1611
+ // Required Required.
1612
+ $.ajax({
1613
+ url : astraSitesAdmin.ajaxurl,
1614
+ type : 'POST',
1615
+ data : data,
1616
+ })
1617
+ .fail(function( jqXHR ){
1618
+
1619
+ // Remove loader.
1620
+ $('.required-plugins').removeClass('loading').html('');
1621
+
1622
+ AstraSitesAdmin._importFailMessage( jqXHR.status + ' ' + jqXHR.responseText, 'plugins' );
1623
+ AstraSitesAdmin._log( jqXHR.status + ' ' + jqXHR.responseText );
1624
+ })
1625
+ .done(function ( response ) {
1626
+
1627
+
1628
+ // Release disabled class from import button.
1629
+ $('.astra-demo-import')
1630
+ .removeClass('disabled not-click-able')
1631
+ .attr('data-import', 'disabled');
1632
+
1633
+ // Remove loader.
1634
+ $('.required-plugins').removeClass('loading').html('');
1635
+ $('.required-plugins-list').html('');
1636
+
1637
+ /**
1638
+ * Count remaining plugins.
1639
+ * @type number
1640
+ */
1641
+ var remaining_plugins = 0;
1642
+
1643
+ /**
1644
+ * Not Installed
1645
+ *
1646
+ * List of not installed required plugins.
1647
+ */
1648
+ if ( typeof response.data.notinstalled !== 'undefined' ) {
1649
+
1650
+ // Add not have installed plugins count.
1651
+ remaining_plugins += parseInt( response.data.notinstalled.length );
1652
+
1653
+ $( response.data.notinstalled ).each(function( index, plugin ) {
1654
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'">'+plugin.name+'</li>');
1655
+ });
1656
+ }
1657
+
1658
+ /**
1659
+ * Inactive
1660
+ *
1661
+ * List of not inactive required plugins.
1662
+ */
1663
+ if ( typeof response.data.inactive !== 'undefined' ) {
1664
+
1665
+ // Add inactive plugins count.
1666
+ remaining_plugins += parseInt( response.data.inactive.length );
1667
+
1668
+ $( response.data.inactive ).each(function( index, plugin ) {
1669
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'">'+plugin.name+'</li>');
1670
+ });
1671
+ }
1672
+
1673
+ /**
1674
+ * Active
1675
+ *
1676
+ * List of not active required plugins.
1677
+ */
1678
+ if ( typeof response.data.active !== 'undefined' ) {
1679
+
1680
+ $( response.data.active ).each(function( index, plugin ) {
1681
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'">'+plugin.name+'</li>');
1682
+ });
1683
+ }
1684
+
1685
+ /**
1686
+ * Enable Demo Import Button
1687
+ * @type number
1688
+ */
1689
+ astraSitesAdmin.requiredPlugins = response.data;
1690
+ });
1691
+
1692
+ } else {
1693
+
1694
+ // Enable Demo Import Button
1695
+ AstraSitesAdmin._enable_demo_import_button( demoType );
1696
+ $('.astra-sites-advanced-options-wrap').remove();
1697
+ }
1698
+
1699
+ return;
1700
+ },
1701
+
1702
+ /**
1703
+ * Enable Demo Import Button.
1704
+ */
1705
+ _enable_demo_import_button: function( type ) {
1706
+
1707
+ type = ( undefined !== type ) ? type : 'free';
1708
+
1709
+ $('.install-theme-info .theme-details .site-description').remove();
1710
+
1711
+ switch( type ) {
1712
+
1713
+ case 'free':
1714
+
1715
+ var notinstalled = astraSitesAdmin.requiredPlugins.notinstalled || 0;
1716
+ var inactive = astraSitesAdmin.requiredPlugins.inactive || 0;
1717
+
1718
+ if( notinstalled.length === inactive.length ) {
1719
+
1720
+ // XML reader not available notice.
1721
+ if( astraSitesAdmin.XMLReaderDisabled ) {
1722
+ if( ! $('.install-theme-info .astra-sites-xml-notice').length ) {
1723
+ $('.install-theme-info').prepend( astraSitesAdmin.strings.warningXMLReader );
1724
+ }
1725
+ $('.astra-demo-import')
1726
+ .removeClass('installing updating-message')
1727
+ .addClass('disabled')
1728
+ .text( astraSitesAdmin.strings.importDemo );
1729
+ } else {
1730
+ $(document).trigger( 'astra-sites-install-and-activate-required-plugins-done' );
1731
+ }
1732
+ }
1733
+
1734
+ break;
1735
+
1736
+ case 'upgrade':
1737
+ var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1738
+
1739
+ $('.astra-demo-import')
1740
+ .addClass('go-pro button-primary')
1741
+ .removeClass('astra-demo-import')
1742
+ .attr('target', '_blank')
1743
+ .attr('href', astraSitesAdmin.getUpgradeURL + demo_slug )
1744
+ .text( astraSitesAdmin.getUpgradeText )
1745
+ .append('<i class="dashicons dashicons-external"></i>');
1746
+
1747
+ break;
1748
+
1749
+ default:
1750
+ var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1751
+
1752
+ $('.astra-demo-import')
1753
+ .addClass('go-pro button-primary')
1754
+ .removeClass('astra-demo-import')
1755
+ .attr('target', '_blank')
1756
+ .attr('href', astraSitesAdmin.getProURL )
1757
+ .text( astraSitesAdmin.getProText )
1758
+ .append('<i class="dashicons dashicons-external"></i>');
1759
+
1760
+ if( false == astraSitesAdmin.isWhiteLabeled ) {
1761
+ if( astraSitesAdmin.isPro ) {
1762
+ $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-inactive-site-description') );
1763
+ } else {
1764
+ $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-site-description') );
1765
+ }
1766
+ }
1767
+
1768
+ break;
1769
+ }
1770
+
1771
+ },
1772
+
1773
+ /**
1774
+ * Update Page Count.
1775
+ */
1776
+ _updatedPagedCount: function() {
1777
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
1778
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
1779
+ window.setTimeout(function () {
1780
+ jQuery('body').data('scrolling', false);
1781
+ }, 800);
1782
+ },
1783
+
1784
+ /**
1785
+ * Reset Page Count.
1786
+ */
1787
+ _resetPagedCount: function() {
1788
+
1789
+ $('body').addClass('loading-content');
1790
+ $('body').attr('data-astra-demo-last-request', '1');
1791
+ $('body').attr('data-astra-demo-paged', '1');
1792
+ $('body').attr('data-astra-demo-search', '');
1793
+ $('body').attr('data-scrolling', false);
1794
+
1795
+ },
1796
+
1797
+ /**
1798
+ * Remove plugin from the queue.
1799
+ */
1800
+ _removePluginFromQueue: function( removeItem, pluginsList ) {
1801
+ return jQuery.grep(pluginsList, function( value ) {
1802
+ return value.slug != removeItem;
1803
+ });
1804
+ }
1805
+
1806
+ };
1807
+
1808
+ /**
1809
+ * Initialize AstraSitesAdmin
1810
+ */
1811
+ $(function(){
1812
+ AstraSitesAdmin.init();
1813
+ });
1814
+
1815
  })(jQuery);
inc/assets/js/astra-sites-api.js CHANGED
@@ -1,57 +1,65 @@
1
-
2
- (function($){
3
-
4
- AstraSitesAPI = {
5
-
6
- _api_url : astraSitesApi.ApiURL,
7
-
8
- /**
9
- * API Request
10
- */
11
- _api_request: function( args ) {
12
-
13
- // Set API Request Data.
14
- var data = {
15
- url: AstraSitesAPI._api_url + args.slug,
16
- };
17
-
18
- if( astraRenderGrid.headers ) {
19
- data.headers = astraRenderGrid.headers;
20
- }
21
-
22
- $.ajax( data )
23
- .done(function( items, status, XHR ) {
24
-
25
- if( 'success' === status && XHR.getResponseHeader('x-wp-total') ) {
26
-
27
- var data = {
28
- args : args,
29
- items : items,
30
- items_count : XHR.getResponseHeader('x-wp-total') || 0,
31
- };
32
-
33
- if( 'undefined' !== args.trigger && '' !== args.trigger ) {
34
- $(document).trigger( args.trigger, [data] );
35
- }
36
-
37
- } else {
38
- $(document).trigger( 'astra-sites-api-request-error' );
39
- }
40
-
41
- })
42
- .fail(function( jqXHR, textStatus ) {
43
-
44
- $(document).trigger( 'astra-sites-api-request-fail', [jqXHR, textStatus, args] );
45
-
46
- })
47
- .always(function() {
48
-
49
- $(document).trigger( 'astra-sites-api-request-always' );
50
-
51
- });
52
-
53
- },
54
-
55
- };
56
-
 
 
 
 
 
 
 
 
57
  })(jQuery);
1
+ (function($){
2
+
3
+ AstraSitesAPI = {
4
+
5
+ _api_url : astraSitesApi.ApiURL,
6
+ _stored_data : {
7
+ 'astra-site-category' : [],
8
+ 'astra-site-page-builder': [],
9
+ 'astra-sites' : [],
10
+ },
11
+
12
+ /**
13
+ * API Request
14
+ */
15
+ _api_request: function( args ) {
16
+
17
+ // Set API Request Data.
18
+ var data = {
19
+ url: AstraSitesAPI._api_url + args.slug,
20
+ };
21
+
22
+ if( astraRenderGrid.headers ) {
23
+ data.headers = astraRenderGrid.headers;
24
+ }
25
+
26
+ $.ajax( data )
27
+ .done(function( items, status, XHR ) {
28
+
29
+ if( 'success' === status && XHR.getResponseHeader('x-wp-total') ) {
30
+
31
+ if( args.id ) {
32
+ AstraSitesAPI._stored_data[ args.id ] = $.merge( AstraSitesAPI._stored_data[ args.id ], items );
33
+ }
34
+
35
+ var data = {
36
+ args : args,
37
+ items : items,
38
+ items_count : XHR.getResponseHeader('x-wp-total') || 0,
39
+ };
40
+
41
+ if( 'undefined' !== args.trigger && '' !== args.trigger ) {
42
+ $(document).trigger( args.trigger, [data] );
43
+ }
44
+
45
+ } else {
46
+ $(document).trigger( 'astra-sites-api-request-error' );
47
+ }
48
+
49
+ })
50
+ .fail(function( jqXHR, textStatus ) {
51
+
52
+ $(document).trigger( 'astra-sites-api-request-fail', [jqXHR, textStatus, args] );
53
+
54
+ })
55
+ .always(function() {
56
+
57
+ $(document).trigger( 'astra-sites-api-request-always' );
58
+
59
+ });
60
+
61
+ },
62
+
63
+ };
64
+
65
  })(jQuery);
inc/assets/js/astra-sites-notices.js CHANGED
@@ -1,21 +1,21 @@
1
- jQuery(document).ready(function ($) {
2
-
3
- jQuery( '.astra-notice.is-dismissible .notice-dismiss' ).on( 'click', function() {
4
- var $id = jQuery( this ).attr( 'id' ) || '';
5
- var $time = jQuery( this ).attr( 'dismissible-time' ) || '';
6
- var $meta = jQuery( this ).attr( 'dismissible-meta' ) || '';
7
-
8
- jQuery.ajax({
9
- url: ajaxurl,
10
- type: 'POST',
11
- data: {
12
- action : 'astra-notices',
13
- id : $id,
14
- meta : $meta,
15
- time : $time,
16
- },
17
- });
18
-
19
- });
20
-
21
  });
1
+ jQuery(document).ready(function ($) {
2
+
3
+ jQuery( '.astra-notice.is-dismissible .notice-dismiss' ).on( 'click', function() {
4
+ var $id = jQuery( this ).attr( 'id' ) || '';
5
+ var $time = jQuery( this ).attr( 'dismissible-time' ) || '';
6
+ var $meta = jQuery( this ).attr( 'dismissible-meta' ) || '';
7
+
8
+ jQuery.ajax({
9
+ url: ajaxurl,
10
+ type: 'POST',
11
+ data: {
12
+ action : 'astra-notices',
13
+ id : $id,
14
+ meta : $meta,
15
+ time : $time,
16
+ },
17
+ });
18
+
19
+ });
20
+
21
  });
inc/assets/js/eventsource.js CHANGED
@@ -1,673 +1,673 @@
1
- /** @license
2
- * eventsource.js
3
- * Available under MIT License (MIT)
4
- * https://github.com/Yaffle/EventSource/
5
- */
6
-
7
- /*jslint indent: 2, vars: true, plusplus: true */
8
- /*global setTimeout, clearTimeout */
9
-
10
- (function (global) {
11
- "use strict";
12
-
13
- var setTimeout = global.setTimeout;
14
- var clearTimeout = global.clearTimeout;
15
- var XMLHttpRequest = global.XMLHttpRequest;
16
- var XDomainRequest = global.XDomainRequest;
17
- var NativeEventSource = global.EventSource;
18
- var document = global.document;
19
-
20
- if (Object.create == null) {
21
- Object.create = function (C) {
22
- function F(){}
23
- F.prototype = C;
24
- return new F();
25
- };
26
- }
27
-
28
- var k = function () {
29
- };
30
-
31
- function XHRWrapper(xhr) {
32
- this.withCredentials = false;
33
- this.responseType = "";
34
- this.readyState = 0;
35
- this.status = 0;
36
- this.statusText = "";
37
- this.responseText = "";
38
- this.onprogress = k;
39
- this.onreadystatechange = k;
40
- this._contentType = "";
41
- this._xhr = xhr;
42
- this._sendTimeout = 0;
43
- this._abort = k;
44
- }
45
-
46
- XHRWrapper.prototype.open = function (method, url) {
47
- this._abort(true);
48
-
49
- var that = this;
50
- var xhr = this._xhr;
51
- var state = 1;
52
- var timeout = 0;
53
-
54
- this._abort = function (silent) {
55
- if (that._sendTimeout !== 0) {
56
- clearTimeout(that._sendTimeout);
57
- that._sendTimeout = 0;
58
- }
59
- if (state === 1 || state === 2 || state === 3) {
60
- state = 4;
61
- xhr.onload = k;
62
- xhr.onerror = k;
63
- xhr.onabort = k;
64
- xhr.onprogress = k;
65
- xhr.onreadystatechange = k;
66
- // IE 8 - 9: XDomainRequest#abort() does not fire any event
67
- // Opera < 10: XMLHttpRequest#abort() does not fire any event
68
- xhr.abort();
69
- if (timeout !== 0) {
70
- clearTimeout(timeout);
71
- timeout = 0;
72
- }
73
- if (!silent) {
74
- that.readyState = 4;
75
- that.onreadystatechange();
76
- }
77
- }
78
- state = 0;
79
- };
80
-
81
- var onStart = function () {
82
- if (state === 1) {
83
- //state = 2;
84
- var status = 0;
85
- var statusText = "";
86
- var contentType = undefined;
87
- if (!("contentType" in xhr)) {
88
- try {
89
- status = xhr.status;
90
- statusText = xhr.statusText;
91
- contentType = xhr.getResponseHeader("Content-Type");
92
- } catch (error) {
93
- // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
94
- // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
95
- // https://bugs.webkit.org/show_bug.cgi?id=29121
96
- status = 0;
97
- statusText = "";
98
- contentType = undefined;
99
- // Firefox < 14, Chrome ?, Safari ?
100
- // https://bugs.webkit.org/show_bug.cgi?id=29658
101
- // https://bugs.webkit.org/show_bug.cgi?id=77854
102
- }
103
- } else {
104
- status = 200;
105
- statusText = "OK";
106
- contentType = xhr.contentType;
107
- }
108
- if (status !== 0) {
109
- state = 2;
110
- that.readyState = 2;
111
- that.status = status;
112
- that.statusText = statusText;
113
- that._contentType = contentType;
114
- that.onreadystatechange();
115
- }
116
- }
117
- };
118
- var onProgress = function () {
119
- onStart();
120
- if (state === 2 || state === 3) {
121
- state = 3;
122
- var responseText = "";
123
- try {
124
- responseText = xhr.responseText;
125
- } catch (error) {
126
- // IE 8 - 9 with XMLHttpRequest
127
- }
128
- that.readyState = 3;
129
- that.responseText = responseText;
130
- that.onprogress();
131
- }
132
- };
133
- var onFinish = function () {
134
- // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
135
- // IE 8 fires "onload" without "onprogress"
136
- onProgress();
137
- if (state === 1 || state === 2 || state === 3) {
138
- state = 4;
139
- if (timeout !== 0) {
140
- clearTimeout(timeout);
141
- timeout = 0;
142
- }
143
- that.readyState = 4;
144
- that.onreadystatechange();
145
- }
146
- };
147
- var onReadyStateChange = function () {
148
- if (xhr != undefined) { // Opera 12
149
- if (xhr.readyState === 4) {
150
- onFinish();
151
- } else if (xhr.readyState === 3) {
152
- onProgress();
153
- } else if (xhr.readyState === 2) {
154
- onStart();
155
- }
156
- }
157
- };
158
- var onTimeout = function () {
159
- timeout = setTimeout(function () {
160
- onTimeout();
161
- }, 500);
162
- if (xhr.readyState === 3) {
163
- onProgress();
164
- }
165
- };
166
-
167
- // XDomainRequest#abort removes onprogress, onerror, onload
168
- xhr.onload = onFinish;
169
- xhr.onerror = onFinish;
170
- // improper fix to match Firefox behaviour, but it is better than just ignore abort
171
- // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
172
- // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
173
- // https://code.google.com/p/chromium/issues/detail?id=153570
174
- // IE 8 fires "onload" without "onprogress
175
- xhr.onabort = onFinish;
176
-
177
- // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
178
- if (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype)) {
179
- xhr.onprogress = onProgress;
180
- }
181
-
182
- // IE 8 - 9 (XMLHTTPRequest)
183
- // Opera < 12
184
- // Firefox < 3.5
185
- // Firefox 3.5 - 3.6 - ? < 9.0
186
- // onprogress is not fired sometimes or delayed
187
- // see also #64
188
- xhr.onreadystatechange = onReadyStateChange;
189
-
190
- if ("contentType" in xhr) {
191
- url += (url.indexOf("?", 0) === -1 ? "?" : "&") + "padding=true";
192
- }
193
- xhr.open(method, url, true);
194
-
195
- if ("readyState" in xhr) {
196
- // workaround for Opera 12 issue with "progress" events
197
- // #91
198
- timeout = setTimeout(function () {
199
- onTimeout();
200
- }, 0);
201
- }
202
- };
203
- XHRWrapper.prototype.abort = function () {
204
- this._abort(false);
205
- };
206
- XHRWrapper.prototype.getResponseHeader = function (name) {
207
- return this._contentType;
208
- };
209
- XHRWrapper.prototype.setRequestHeader = function (name, value) {
210
- var xhr = this._xhr;
211
- if ("setRequestHeader" in xhr) {
212
- xhr.setRequestHeader(name, value);
213
- }
214
- };
215
- XHRWrapper.prototype.send = function () {
216
- // loading indicator in Safari < ? (6), Chrome < 14, Firefox
217
- if (!("ontimeout" in XMLHttpRequest.prototype) &&
218
- document != undefined &&
219
- document.readyState != undefined &&
220
- document.readyState !== "complete") {
221
- var that = this;
222
- that._sendTimeout = setTimeout(function () {
223
- that._sendTimeout = 0;
224
- that.send();
225
- }, 4);
226
- return;
227
- }
228
-
229
- var xhr = this._xhr;
230
- // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
231
- xhr.withCredentials = this.withCredentials;
232
- xhr.responseType = this.responseType;
233
- try {
234
- // xhr.send(); throws "Not enough arguments" in Firefox 3.0
235
- xhr.send(undefined);
236
- } catch (error1) {
237
- // Safari 5.1.7, Opera 12
238
- throw error1;
239
- }
240
- };
241
-
242
- function XHRTransport(xhr) {
243
- this._xhr = new XHRWrapper(xhr);
244
- }
245
-
246
- XHRTransport.prototype.open = function (onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
247
- var xhr = this._xhr;
248
- xhr.open("GET", url);
249
- var offset = 0;
250
- xhr.onprogress = function () {
251
- var responseText = xhr.responseText;
252
- var chunk = responseText.slice(offset);
253
- offset += chunk.length;
254
- onProgressCallback(chunk);
255
- };
256
- xhr.onreadystatechange = function () {
257
- if (xhr.readyState === 2) {
258
- var status = xhr.status;
259
- var statusText = xhr.statusText;
260
- var contentType = xhr.getResponseHeader("Content-Type");
261
- onStartCallback(status, statusText, contentType);
262
- } else if (xhr.readyState === 4) {
263
- onFinishCallback();
264
- }
265
- };
266
- xhr.withCredentials = withCredentials;
267
- xhr.responseType = "text";
268
- for (var name in headers) {
269
- if (Object.prototype.hasOwnProperty.call(headers, name)) {
270
- xhr.setRequestHeader(name, headers[name]);
271
- }
272
- }
273
- xhr.send();
274
- };
275
-
276
- XHRTransport.prototype.cancel = function () {
277
- var xhr = this._xhr;
278
- xhr.abort();
279
- };
280
-
281
- function EventTarget() {
282
- this._listeners = Object.create(null);
283
- }
284
-
285
- function throwError(e) {
286
- setTimeout(function () {
287
- throw e;
288
- }, 0);
289
- }
290
-
291
- EventTarget.prototype.dispatchEvent = function (event) {
292
- event.target = this;
293
- var typeListeners = this._listeners[event.type];
294
- if (typeListeners != undefined) {
295
- var length = typeListeners.length;
296
- for (var i = 0; i < length; i += 1) {
297
- var listener = typeListeners[i];
298
- try {
299
- if (typeof listener.handleEvent === "function") {
300
- listener.handleEvent(event);
301
- } else {
302
- listener.call(this, event);
303
- }
304
- } catch (e) {
305
- throwError(e);
306
- }
307
- }
308
- }
309
- };
310
- EventTarget.prototype.addEventListener = function (type, listener) {
311
- type = String(type);
312
- var listeners = this._listeners;
313
- var typeListeners = listeners[type];
314
- if (typeListeners == undefined) {
315
- typeListeners = [];
316
- listeners[type] = typeListeners;
317
- }
318
- var found = false;
319
- for (var i = 0; i < typeListeners.length; i += 1) {
320
- if (typeListeners[i] === listener) {
321
- found = true;
322
- }
323
- }
324
- if (!found) {
325
- typeListeners.push(listener);
326
- }
327
- };
328
- EventTarget.prototype.removeEventListener = function (type, listener) {
329
- type = String(type);
330
- var listeners = this._listeners;
331
- var typeListeners = listeners[type];
332
- if (typeListeners != undefined) {
333
- var filtered = [];
334
- for (var i = 0; i < typeListeners.length; i += 1) {
335
- if (typeListeners[i] !== listener) {
336
- filtered.push(typeListeners[i]);
337
- }
338
- }
339
- if (filtered.length === 0) {
340
- delete listeners[type];
341
- } else {
342
- listeners[type] = filtered;
343
- }
344
- }
345
- };
346
-
347
- function Event(type) {
348
- this.type = type;
349
- this.target = undefined;
350
- }
351
-
352
- function MessageEvent(type, options) {
353
- Event.call(this, type);
354
- this.data = options.data;
355
- this.lastEventId = options.lastEventId;
356
- }
357
-
358
- MessageEvent.prototype = Object.create(Event.prototype);
359
-
360
- var WAITING = -1;
361
- var CONNECTING = 0;
362
- var OPEN = 1;
363
- var CLOSED = 2;
364
-
365
- var AFTER_CR = -1;
366
- var FIELD_START = 0;
367
- var FIELD = 1;
368
- var VALUE_START = 2;
369
- var VALUE = 3;
370
-
371
- var contentTypeRegExp = /^text\/event\-stream;?(\s*charset\=utf\-8)?$/i;
372
-
373
- var MINIMUM_DURATION = 1000;
374
- var MAXIMUM_DURATION = 18000000;
375
-
376
- var parseDuration = function (value, def) {
377
- var n = parseInt(value, 10);
378
- if (n !== n) {
379
- n = def;
380
- }
381
- return clampDuration(n);
382
- };
383
- var clampDuration = function (n) {
384
- return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
385
- };
386
-
387
- var fire = function (that, f, event) {
388
- try {
389
- if (typeof f === "function") {
390
- f.call(that, event);
391
- }
392
- } catch (e) {
393
- throwError(e);
394
- }
395
- };
396
-
397
- function EventSourcePolyfill(url, options) {
398
- EventTarget.call(this);
399
-
400
- this.onopen = undefined;
401
- this.onmessage = undefined;
402
- this.onerror = undefined;
403
-
404
- this.url = undefined;
405
- this.readyState = undefined;
406
- this.withCredentials = undefined;
407
-
408
- this._close = undefined;
409
-
410
- start(this, url, options);
411
- }
412
-
413
- function start(es, url, options) {
414
- url = String(url);
415
- var withCredentials = options != undefined && Boolean(options.withCredentials);
416
-
417
- var initialRetry = clampDuration(1000);
418
- var heartbeatTimeout = clampDuration(45000);
419
-
420
- var lastEventId = "";
421
- var retry = initialRetry;
422
- var wasActivity = false;
423
- var headers = options != undefined && options.headers != undefined ? JSON.parse(JSON.stringify(options.headers)) : undefined;
424
- var CurrentTransport = options != undefined && options.Transport != undefined ? options.Transport : (XDomainRequest != undefined ? XDomainRequest : XMLHttpRequest);
425
- var transport = new XHRTransport(new CurrentTransport());
426
- var timeout = 0;
427
- var currentState = WAITING;
428
- var dataBuffer = "";
429
- var lastEventIdBuffer = "";
430
- var eventTypeBuffer = "";
431
-
432
- var textBuffer = "";
433
- var state = FIELD_START;
434
- var fieldStart = 0;
435
- var valueStart = 0;
436
-
437
- var onStart = function (status, statusText, contentType) {
438
- if (currentState === CONNECTING) {
439
- if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
440
- currentState = OPEN;
441
- wasActivity = true;
442
- retry = initialRetry;
443
- es.readyState = OPEN;
444
- var event = new Event("open");
445
- es.dispatchEvent(event);
446
- fire(es, es.onopen, event);
447
- } else {
448
- var message = "";
449
- if (status !== 200) {
450
- if (statusText) {
451
- statusText = statusText.replace(/\s+/g, " ");
452
- }
453
- message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
454
- } else {
455
- message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
456
- }
457
- throwError(new Error(message));
458
- close();
459
- var event = new Event("error");
460
- es.dispatchEvent(event);
461
- fire(es, es.onerror, event);
462
- }
463
- }
464
- };
465
-
466
- var onProgress = function (textChunk) {
467
- if (currentState === OPEN) {
468
- var n = -1;
469
- for (var i = 0; i < textChunk.length; i += 1) {
470
- var c = textChunk.charCodeAt(i);
471
- if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
472
- n = i;
473
- }
474
- }
475
- var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
476
- textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
477
- if (chunk !== "") {
478
- wasActivity = true;
479
- }
480
- for (var position = 0; position < chunk.length; position += 1) {
481
- var c = chunk.charCodeAt(position);
482
- if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
483
- state = FIELD_START;
484
- } else {
485
- if (state === AFTER_CR) {
486
- state = FIELD_START;
487
- }
488
- if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
489
- if (state !== FIELD_START) {
490
- if (state === FIELD) {
491
- valueStart = position + 1;
492
- }
493
- var field = chunk.slice(fieldStart, valueStart - 1);
494
- var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
495
- if (field === "data") {
496
- dataBuffer += "\n";
497
- dataBuffer += value;
498
- } else if (field === "id") {
499
- lastEventIdBuffer = value;
500
- } else if (field === "event") {
501
- eventTypeBuffer = value;
502
- } else if (field === "retry") {
503
- initialRetry = parseDuration(value, initialRetry);
504
- retry = initialRetry;
505
- } else if (field === "heartbeatTimeout") {
506
- heartbeatTimeout = parseDuration(value, heartbeatTimeout);
507
- if (timeout !== 0) {
508
- clearTimeout(timeout);
509
- timeout = setTimeout(function () {
510
- onTimeout();
511
- }, heartbeatTimeout);
512
- }
513
- }
514
- }
515
- if (state === FIELD_START) {
516
- if (dataBuffer !== "") {
517
- lastEventId = lastEventIdBuffer;
518
- if (eventTypeBuffer === "") {
519
- eventTypeBuffer = "message";
520
- }
521
- var event = new MessageEvent(eventTypeBuffer, {
522
- data: dataBuffer.slice(1),
523
- lastEventId: lastEventIdBuffer
524
- });
525
- es.dispatchEvent(event);
526
- if (eventTypeBuffer === "message") {
527
- fire(es, es.onmessage, event);
528
- }
529
- if (currentState === CLOSED) {
530
- return;
531
- }
532
- }
533
- dataBuffer = "";
534
- eventTypeBuffer = "";
535
- }
536
- state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
537
- } else {
538
- if (state === FIELD_START) {
539
- fieldStart = position;
540
- state = FIELD;
541
- }
542
- if (state === FIELD) {
543
- if (c === ":".charCodeAt(0)) {
544
- valueStart = position + 1;
545
- state = VALUE_START;
546
- }
547
- } else if (state === VALUE_START) {
548
- state = VALUE;
549
- }
550
- }
551
- }
552
- }
553
- }
554
- };
555
-
556
- var onFinish = function () {
557
- if (currentState === OPEN || currentState === CONNECTING) {
558
- currentState = WAITING;
559
- if (timeout !== 0) {
560
- clearTimeout(timeout);
561
- timeout = 0;
562
- }
563
- timeout = setTimeout(function () {
564
- onTimeout();
565
- }, retry);
566
- retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
567
-
568
- es.readyState = CONNECTING;
569
- var event = new Event("error");
570
- es.dispatchEvent(event);
571
- fire(es, es.onerror, event);
572
- }
573
- };
574
-
575
- var close = function () {
576
- currentState = CLOSED;
577
- transport.cancel();
578
- if (timeout !== 0) {
579
- clearTimeout(timeout);
580
- timeout = 0;
581
- }
582
- es.readyState = CLOSED;
583
- };
584
-
585
- var onTimeout = function () {
586
- timeout = 0;
587
-
588
- if (currentState !== WAITING) {
589
- if (!wasActivity) {
590
- throwError(new Error("No activity within " + heartbeatTimeout + " milliseconds. Reconnecting."));
591
- transport.cancel();
592
- } else {
593
- wasActivity = false;
594
- timeout = setTimeout(function () {
595
- onTimeout();
596
- }, heartbeatTimeout);
597
- }
598
- return;
599
- }
600
-
601
- wasActivity = false;
602
- timeout = setTimeout(function () {
603
- onTimeout();
604
- }, heartbeatTimeout);
605
-
606
- currentState = CONNECTING;
607
- dataBuffer = "";
608
- eventTypeBuffer = "";
609
- lastEventIdBuffer = lastEventId;
610
- textBuffer = "";
611
- fieldStart = 0;
612
- valueStart = 0;
613
- state = FIELD_START;
614
-
615
- // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
616
- // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
617
- var requestURL = url;
618
- if (url.slice(0, 5) !== "data:" &&
619
- url.slice(0, 5) !== "blob:") {
620
- requestURL = url + (url.indexOf("?", 0) === -1 ? "?" : "&") + "lastEventId=" + encodeURIComponent(lastEventId);
621
- }
622
- var requestHeaders = {};
623
- requestHeaders["Accept"] = "text/event-stream";
624
- if (headers != undefined) {
625
- for (var name in headers) {
626
- if (Object.prototype.hasOwnProperty.call(headers, name)) {
627
- requestHeaders[name] = headers[name];
628
- }
629
- }
630
- }
631
- try {
632
- transport.open(onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
633
- } catch (error) {
634
- close();
635
- throw error;
636
- }
637
- };
638
-
639
- es.url = url;
640
- es.readyState = CONNECTING;
641
- es.withCredentials = withCredentials;
642
- es._close = close;
643
-
644
- onTimeout();
645
- }
646
-
647
- EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
648
- EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
649
- EventSourcePolyfill.prototype.OPEN = OPEN;
650
- EventSourcePolyfill.prototype.CLOSED = CLOSED;
651
- EventSourcePolyfill.prototype.close = function () {
652
- this._close();
653
- };
654
-
655
- EventSourcePolyfill.CONNECTING = CONNECTING;
656
- EventSourcePolyfill.OPEN = OPEN;
657
- EventSourcePolyfill.CLOSED = CLOSED;
658
- EventSourcePolyfill.prototype.withCredentials = undefined;
659
-
660
- global.EventSourcePolyfill = EventSourcePolyfill;
661
- global.NativeEventSource = NativeEventSource;
662
-
663
- if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
664
- // Why replace a native EventSource ?
665
- // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
666
- // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
667
- // https://code.google.com/p/chromium/issues/detail?id=260144
668
- // https://code.google.com/p/chromium/issues/detail?id=225654
669
- // ...
670
- global.EventSource = EventSourcePolyfill;
671
- }
672
-
673
- }(typeof window !== 'undefined' ? window : this));
1
+ /** @license
2
+ * eventsource.js
3
+ * Available under MIT License (MIT)
4
+ * https://github.com/Yaffle/EventSource/
5
+ */
6
+
7
+ /*jslint indent: 2, vars: true, plusplus: true */
8
+ /*global setTimeout, clearTimeout */
9
+
10
+ (function (global) {
11
+ "use strict";
12
+
13
+ var setTimeout = global.setTimeout;
14
+ var clearTimeout = global.clearTimeout;
15
+ var XMLHttpRequest = global.XMLHttpRequest;
16
+ var XDomainRequest = global.XDomainRequest;
17
+ var NativeEventSource = global.EventSource;
18
+ var document = global.document;
19
+
20
+ if (Object.create == null) {
21
+ Object.create = function (C) {
22
+ function F(){}
23
+ F.prototype = C;
24
+ return new F();
25
+ };
26
+ }
27
+
28
+ var k = function () {
29
+ };
30
+
31
+ function XHRWrapper(xhr) {
32
+ this.withCredentials = false;
33
+ this.responseType = "";
34
+ this.readyState = 0;
35
+ this.status = 0;
36
+ this.statusText = "";
37
+ this.responseText = "";
38
+ this.onprogress = k;
39
+ this.onreadystatechange = k;
40
+ this._contentType = "";
41
+ this._xhr = xhr;
42
+ this._sendTimeout = 0;
43
+ this._abort = k;
44
+ }
45
+
46
+ XHRWrapper.prototype.open = function (method, url) {
47
+ this._abort(true);
48
+
49
+ var that = this;
50
+ var xhr = this._xhr;
51
+ var state = 1;
52
+ var timeout = 0;
53
+
54
+ this._abort = function (silent) {
55
+ if (that._sendTimeout !== 0) {
56
+ clearTimeout(that._sendTimeout);
57
+ that._sendTimeout = 0;
58
+ }
59
+ if (state === 1 || state === 2 || state === 3) {
60
+ state = 4;
61
+ xhr.onload = k;
62
+ xhr.onerror = k;
63
+ xhr.onabort = k;
64
+ xhr.onprogress = k;
65
+ xhr.onreadystatechange = k;
66
+ // IE 8 - 9: XDomainRequest#abort() does not fire any event
67
+ // Opera < 10: XMLHttpRequest#abort() does not fire any event
68
+ xhr.abort();
69
+ if (timeout !== 0) {
70
+ clearTimeout(timeout);
71
+ timeout = 0;
72
+ }
73
+ if (!silent) {
74
+ that.readyState = 4;
75
+ that.onreadystatechange();
76
+ }
77
+ }
78
+ state = 0;
79
+ };
80
+
81
+ var onStart = function () {
82
+ if (state === 1) {
83
+ //state = 2;
84
+ var status = 0;
85
+ var statusText = "";
86
+ var contentType = undefined;
87
+ if (!("contentType" in xhr)) {
88
+ try {
89
+ status = xhr.status;
90
+ statusText = xhr.statusText;
91
+ contentType = xhr.getResponseHeader("Content-Type");
92
+ } catch (error) {
93
+ // IE < 10 throws exception for `xhr.status` when xhr.readyState === 2 || xhr.readyState === 3
94
+ // Opera < 11 throws exception for `xhr.status` when xhr.readyState === 2
95
+ // https://bugs.webkit.org/show_bug.cgi?id=29121
96
+ status = 0;
97
+ statusText = "";
98
+ contentType = undefined;
99
+ // Firefox < 14, Chrome ?, Safari ?
100
+ // https://bugs.webkit.org/show_bug.cgi?id=29658
101
+ // https://bugs.webkit.org/show_bug.cgi?id=77854
102
+ }
103
+ } else {
104
+ status = 200;
105
+ statusText = "OK";
106
+ contentType = xhr.contentType;
107
+ }
108
+ if (status !== 0) {
109
+ state = 2;
110
+ that.readyState = 2;
111
+ that.status = status;
112
+ that.statusText = statusText;
113
+ that._contentType = contentType;
114
+ that.onreadystatechange();
115
+ }
116
+ }
117
+ };
118
+ var onProgress = function () {
119
+ onStart();
120
+ if (state === 2 || state === 3) {
121
+ state = 3;
122
+ var responseText = "";
123
+ try {
124
+ responseText = xhr.responseText;
125
+ } catch (error) {
126
+ // IE 8 - 9 with XMLHttpRequest
127
+ }
128
+ that.readyState = 3;
129
+ that.responseText = responseText;
130
+ that.onprogress();
131
+ }
132
+ };
133
+ var onFinish = function () {
134
+ // Firefox 52 fires "readystatechange" (xhr.readyState === 4) without final "readystatechange" (xhr.readyState === 3)
135
+ // IE 8 fires "onload" without "onprogress"
136
+ onProgress();
137
+ if (state === 1 || state === 2 || state === 3) {
138
+ state = 4;
139
+ if (timeout !== 0) {
140
+ clearTimeout(timeout);
141
+ timeout = 0;
142
+ }
143
+ that.readyState = 4;
144
+ that.onreadystatechange();
145
+ }
146
+ };
147
+ var onReadyStateChange = function () {
148
+ if (xhr != undefined) { // Opera 12
149
+ if (xhr.readyState === 4) {
150
+ onFinish();
151
+ } else if (xhr.readyState === 3) {
152
+ onProgress();
153
+ } else if (xhr.readyState === 2) {
154
+ onStart();
155
+ }
156
+ }
157
+ };
158
+ var onTimeout = function () {
159
+ timeout = setTimeout(function () {
160
+ onTimeout();
161
+ }, 500);
162
+ if (xhr.readyState === 3) {
163
+ onProgress();
164
+ }
165
+ };
166
+
167
+ // XDomainRequest#abort removes onprogress, onerror, onload
168
+ xhr.onload = onFinish;
169
+ xhr.onerror = onFinish;
170
+ // improper fix to match Firefox behaviour, but it is better than just ignore abort
171
+ // see https://bugzilla.mozilla.org/show_bug.cgi?id=768596
172
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=880200
173
+ // https://code.google.com/p/chromium/issues/detail?id=153570
174
+ // IE 8 fires "onload" without "onprogress
175
+ xhr.onabort = onFinish;
176
+
177
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=736723
178
+ if (!("sendAsBinary" in XMLHttpRequest.prototype) && !("mozAnon" in XMLHttpRequest.prototype)) {
179
+ xhr.onprogress = onProgress;
180
+ }
181
+
182
+ // IE 8 - 9 (XMLHTTPRequest)
183
+ // Opera < 12
184
+ // Firefox < 3.5
185
+ // Firefox 3.5 - 3.6 - ? < 9.0
186
+ // onprogress is not fired sometimes or delayed
187
+ // see also #64
188
+ xhr.onreadystatechange = onReadyStateChange;
189
+
190
+ if ("contentType" in xhr) {
191
+ url += (url.indexOf("?", 0) === -1 ? "?" : "&") + "padding=true";
192
+ }
193
+ xhr.open(method, url, true);
194
+
195
+ if ("readyState" in xhr) {
196
+ // workaround for Opera 12 issue with "progress" events
197
+ // #91
198
+ timeout = setTimeout(function () {
199
+ onTimeout();
200
+ }, 0);
201
+ }
202
+ };
203
+ XHRWrapper.prototype.abort = function () {
204
+ this._abort(false);
205
+ };
206
+ XHRWrapper.prototype.getResponseHeader = function (name) {
207
+ return this._contentType;
208
+ };
209
+ XHRWrapper.prototype.setRequestHeader = function (name, value) {
210
+ var xhr = this._xhr;
211
+ if ("setRequestHeader" in xhr) {
212
+ xhr.setRequestHeader(name, value);
213
+ }
214
+ };
215
+ XHRWrapper.prototype.send = function () {
216
+ // loading indicator in Safari < ? (6), Chrome < 14, Firefox
217
+ if (!("ontimeout" in XMLHttpRequest.prototype) &&
218
+ document != undefined &&
219
+ document.readyState != undefined &&
220
+ document.readyState !== "complete") {
221
+ var that = this;
222
+ that._sendTimeout = setTimeout(function () {
223
+ that._sendTimeout = 0;
224
+ that.send();
225
+ }, 4);
226
+ return;
227
+ }
228
+
229
+ var xhr = this._xhr;
230
+ // withCredentials should be set after "open" for Safari and Chrome (< 19 ?)
231
+ xhr.withCredentials = this.withCredentials;
232
+ xhr.responseType = this.responseType;
233
+ try {
234
+ // xhr.send(); throws "Not enough arguments" in Firefox 3.0
235
+ xhr.send(undefined);
236
+ } catch (error1) {
237
+ // Safari 5.1.7, Opera 12
238
+ throw error1;
239
+ }
240
+ };
241
+
242
+ function XHRTransport(xhr) {
243
+ this._xhr = new XHRWrapper(xhr);
244
+ }
245
+
246
+ XHRTransport.prototype.open = function (onStartCallback, onProgressCallback, onFinishCallback, url, withCredentials, headers) {
247
+ var xhr = this._xhr;
248
+ xhr.open("GET", url);
249
+ var offset = 0;
250
+ xhr.onprogress = function () {
251
+ var responseText = xhr.responseText;
252
+ var chunk = responseText.slice(offset);
253
+ offset += chunk.length;
254
+ onProgressCallback(chunk);
255
+ };
256
+ xhr.onreadystatechange = function () {
257
+ if (xhr.readyState === 2) {
258
+ var status = xhr.status;
259
+ var statusText = xhr.statusText;
260
+ var contentType = xhr.getResponseHeader("Content-Type");
261
+ onStartCallback(status, statusText, contentType);
262
+ } else if (xhr.readyState === 4) {
263
+ onFinishCallback();
264
+ }
265
+ };
266
+ xhr.withCredentials = withCredentials;
267
+ xhr.responseType = "text";
268
+ for (var name in headers) {
269
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
270
+ xhr.setRequestHeader(name, headers[name]);
271
+ }
272
+ }
273
+ xhr.send();
274
+ };
275
+
276
+ XHRTransport.prototype.cancel = function () {
277
+ var xhr = this._xhr;
278
+ xhr.abort();
279
+ };
280
+
281
+ function EventTarget() {
282
+ this._listeners = Object.create(null);
283
+ }
284
+
285
+ function throwError(e) {
286
+ setTimeout(function () {
287
+ throw e;
288
+ }, 0);
289
+ }
290
+
291
+ EventTarget.prototype.dispatchEvent = function (event) {
292
+ event.target = this;
293
+ var typeListeners = this._listeners[event.type];
294
+ if (typeListeners != undefined) {
295
+ var length = typeListeners.length;
296
+ for (var i = 0; i < length; i += 1) {
297
+ var listener = typeListeners[i];
298
+ try {
299
+ if (typeof listener.handleEvent === "function") {
300
+ listener.handleEvent(event);
301
+ } else {
302
+ listener.call(this, event);
303
+ }
304
+ } catch (e) {
305
+ throwError(e);
306
+ }
307
+ }
308
+ }
309
+ };
310
+ EventTarget.prototype.addEventListener = function (type, listener) {
311
+ type = String(type);
312
+ var listeners = this._listeners;
313
+ var typeListeners = listeners[type];
314
+ if (typeListeners == undefined) {
315
+ typeListeners = [];
316
+ listeners[type] = typeListeners;
317
+ }
318
+ var found = false;
319
+ for (var i = 0; i < typeListeners.length; i += 1) {
320
+ if (typeListeners[i] === listener) {
321
+ found = true;
322
+ }
323
+ }
324
+ if (!found) {
325
+ typeListeners.push(listener);
326
+ }
327
+ };
328
+ EventTarget.prototype.removeEventListener = function (type, listener) {
329
+ type = String(type);
330
+ var listeners = this._listeners;
331
+ var typeListeners = listeners[type];
332
+ if (typeListeners != undefined) {
333
+ var filtered = [];
334
+ for (var i = 0; i < typeListeners.length; i += 1) {
335
+ if (typeListeners[i] !== listener) {
336
+ filtered.push(typeListeners[i]);
337
+ }
338
+ }
339
+ if (filtered.length === 0) {
340
+ delete listeners[type];
341
+ } else {
342
+ listeners[type] = filtered;
343
+ }
344
+ }
345
+ };
346
+
347
+ function Event(type) {
348
+ this.type = type;
349
+ this.target = undefined;
350
+ }
351
+
352
+ function MessageEvent(type, options) {
353
+ Event.call(this, type);
354
+ this.data = options.data;
355
+ this.lastEventId = options.lastEventId;
356
+ }
357
+
358
+ MessageEvent.prototype = Object.create(Event.prototype);
359
+
360
+ var WAITING = -1;
361
+ var CONNECTING = 0;
362
+ var OPEN = 1;
363
+ var CLOSED = 2;
364
+
365
+ var AFTER_CR = -1;
366
+ var FIELD_START = 0;
367
+ var FIELD = 1;
368
+ var VALUE_START = 2;
369
+ var VALUE = 3;
370
+
371
+ var contentTypeRegExp = /^text\/event\-stream;?(\s*charset\=utf\-8)?$/i;
372
+
373
+ var MINIMUM_DURATION = 1000;
374
+ var MAXIMUM_DURATION = 18000000;
375
+
376
+ var parseDuration = function (value, def) {
377
+ var n = parseInt(value, 10);
378
+ if (n !== n) {
379
+ n = def;
380
+ }
381
+ return clampDuration(n);
382
+ };
383
+ var clampDuration = function (n) {
384
+ return Math.min(Math.max(n, MINIMUM_DURATION), MAXIMUM_DURATION);
385
+ };
386
+
387
+ var fire = function (that, f, event) {
388
+ try {
389
+ if (typeof f === "function") {
390
+ f.call(that, event);
391
+ }
392
+ } catch (e) {
393
+ throwError(e);
394
+ }
395
+ };
396
+
397
+ function EventSourcePolyfill(url, options) {
398
+ EventTarget.call(this);
399
+
400
+ this.onopen = undefined;
401
+ this.onmessage = undefined;
402
+ this.onerror = undefined;
403
+
404
+ this.url = undefined;
405
+ this.readyState = undefined;
406
+ this.withCredentials = undefined;
407
+
408
+ this._close = undefined;
409
+
410
+ start(this, url, options);
411
+ }
412
+
413
+ function start(es, url, options) {
414
+ url = String(url);
415
+ var withCredentials = options != undefined && Boolean(options.withCredentials);
416
+
417
+ var initialRetry = clampDuration(1000);
418
+ var heartbeatTimeout = clampDuration(45000);
419
+
420
+ var lastEventId = "";
421
+ var retry = initialRetry;
422
+ var wasActivity = false;
423
+ var headers = options != undefined && options.headers != undefined ? JSON.parse(JSON.stringify(options.headers)) : undefined;
424
+ var CurrentTransport = options != undefined && options.Transport != undefined ? options.Transport : (XDomainRequest != undefined ? XDomainRequest : XMLHttpRequest);
425
+ var transport = new XHRTransport(new CurrentTransport());
426
+ var timeout = 0;
427
+ var currentState = WAITING;
428
+ var dataBuffer = "";
429
+ var lastEventIdBuffer = "";
430
+ var eventTypeBuffer = "";
431
+
432
+ var textBuffer = "";
433
+ var state = FIELD_START;
434
+ var fieldStart = 0;
435
+ var valueStart = 0;
436
+
437
+ var onStart = function (status, statusText, contentType) {
438
+ if (currentState === CONNECTING) {
439
+ if (status === 200 && contentType != undefined && contentTypeRegExp.test(contentType)) {
440
+ currentState = OPEN;
441
+ wasActivity = true;
442
+ retry = initialRetry;
443
+ es.readyState = OPEN;
444
+ var event = new Event("open");
445
+ es.dispatchEvent(event);
446
+ fire(es, es.onopen, event);
447
+ } else {
448
+ var message = "";
449
+ if (status !== 200) {
450
+ if (statusText) {
451
+ statusText = statusText.replace(/\s+/g, " ");
452
+ }
453
+ message = "EventSource's response has a status " + status + " " + statusText + " that is not 200. Aborting the connection.";
454
+ } else {
455
+ message = "EventSource's response has a Content-Type specifying an unsupported type: " + (contentType == undefined ? "-" : contentType.replace(/\s+/g, " ")) + ". Aborting the connection.";
456
+ }
457
+ throwError(new Error(message));
458
+ close();
459
+ var event = new Event("error");
460
+ es.dispatchEvent(event);
461
+ fire(es, es.onerror, event);
462
+ }
463
+ }
464
+ };
465
+
466
+ var onProgress = function (textChunk) {
467
+ if (currentState === OPEN) {
468
+ var n = -1;
469
+ for (var i = 0; i < textChunk.length; i += 1) {
470
+ var c = textChunk.charCodeAt(i);
471
+ if (c === "\n".charCodeAt(0) || c === "\r".charCodeAt(0)) {
472
+ n = i;
473
+ }
474
+ }
475
+ var chunk = (n !== -1 ? textBuffer : "") + textChunk.slice(0, n + 1);
476
+ textBuffer = (n === -1 ? textBuffer : "") + textChunk.slice(n + 1);
477
+ if (chunk !== "") {
478
+ wasActivity = true;
479
+ }
480
+ for (var position = 0; position < chunk.length; position += 1) {
481
+ var c = chunk.charCodeAt(position);
482
+ if (state === AFTER_CR && c === "\n".charCodeAt(0)) {
483
+ state = FIELD_START;
484
+ } else {
485
+ if (state === AFTER_CR) {
486
+ state = FIELD_START;
487
+ }
488
+ if (c === "\r".charCodeAt(0) || c === "\n".charCodeAt(0)) {
489
+ if (state !== FIELD_START) {
490
+ if (state === FIELD) {
491
+ valueStart = position + 1;
492
+ }
493
+ var field = chunk.slice(fieldStart, valueStart - 1);
494
+ var value = chunk.slice(valueStart + (valueStart < position && chunk.charCodeAt(valueStart) === " ".charCodeAt(0) ? 1 : 0), position);
495
+ if (field === "data") {
496
+ dataBuffer += "\n";
497
+ dataBuffer += value;
498
+ } else if (field === "id") {
499
+ lastEventIdBuffer = value;
500
+ } else if (field === "event") {
501
+ eventTypeBuffer = value;
502
+ } else if (field === "retry") {
503
+ initialRetry = parseDuration(value, initialRetry);
504
+ retry = initialRetry;
505
+ } else if (field === "heartbeatTimeout") {
506
+ heartbeatTimeout = parseDuration(value, heartbeatTimeout);
507
+ if (timeout !== 0) {
508
+ clearTimeout(timeout);
509
+ timeout = setTimeout(function () {
510
+ onTimeout();
511
+ }, heartbeatTimeout);
512
+ }
513
+ }
514
+ }
515
+ if (state === FIELD_START) {
516
+ if (dataBuffer !== "") {
517
+ lastEventId = lastEventIdBuffer;
518
+ if (eventTypeBuffer === "") {
519
+ eventTypeBuffer = "message";
520
+ }
521
+ var event = new MessageEvent(eventTypeBuffer, {
522
+ data: dataBuffer.slice(1),
523
+ lastEventId: lastEventIdBuffer
524
+ });
525
+ es.dispatchEvent(event);
526
+ if (eventTypeBuffer === "message") {
527
+ fire(es, es.onmessage, event);
528
+ }
529
+ if (currentState === CLOSED) {
530
+ return;
531
+ }
532
+ }
533
+ dataBuffer = "";
534
+ eventTypeBuffer = "";
535
+ }
536
+ state = c === "\r".charCodeAt(0) ? AFTER_CR : FIELD_START;
537
+ } else {
538
+ if (state === FIELD_START) {
539
+ fieldStart = position;
540
+ state = FIELD;
541
+ }
542
+ if (state === FIELD) {
543
+ if (c === ":".charCodeAt(0)) {
544
+ valueStart = position + 1;
545
+ state = VALUE_START;
546
+ }
547
+ } else if (state === VALUE_START) {
548
+ state = VALUE;
549
+ }
550
+ }
551
+ }
552
+ }
553
+ }
554
+ };
555
+
556
+ var onFinish = function () {
557
+ if (currentState === OPEN || currentState === CONNECTING) {
558
+ currentState = WAITING;
559
+ if (timeout !== 0) {
560
+ clearTimeout(timeout);
561
+ timeout = 0;
562
+ }
563
+ timeout = setTimeout(function () {
564
+ onTimeout();
565
+ }, retry);
566
+ retry = clampDuration(Math.min(initialRetry * 16, retry * 2));
567
+
568
+ es.readyState = CONNECTING;
569
+ var event = new Event("error");
570
+ es.dispatchEvent(event);
571
+ fire(es, es.onerror, event);
572
+ }
573
+ };
574
+
575
+ var close = function () {
576
+ currentState = CLOSED;
577
+ transport.cancel();
578
+ if (timeout !== 0) {
579
+ clearTimeout(timeout);
580
+ timeout = 0;
581
+ }
582
+ es.readyState = CLOSED;
583
+ };
584
+
585
+ var onTimeout = function () {
586
+ timeout = 0;
587
+
588
+ if (currentState !== WAITING) {
589
+ if (!wasActivity) {
590
+ throwError(new Error("No activity within " + heartbeatTimeout + " milliseconds. Reconnecting."));
591
+ transport.cancel();
592
+ } else {
593
+ wasActivity = false;
594
+ timeout = setTimeout(function () {
595
+ onTimeout();
596
+ }, heartbeatTimeout);
597
+ }
598
+ return;
599
+ }
600
+
601
+ wasActivity = false;
602
+ timeout = setTimeout(function () {
603
+ onTimeout();
604
+ }, heartbeatTimeout);
605
+
606
+ currentState = CONNECTING;
607
+ dataBuffer = "";
608
+ eventTypeBuffer = "";
609
+ lastEventIdBuffer = lastEventId;
610
+ textBuffer = "";
611
+ fieldStart = 0;
612
+ valueStart = 0;
613
+ state = FIELD_START;
614
+
615
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=428916
616
+ // Request header field Last-Event-ID is not allowed by Access-Control-Allow-Headers.
617
+ var requestURL = url;
618
+ if (url.slice(0, 5) !== "data:" &&
619
+ url.slice(0, 5) !== "blob:") {
620
+ requestURL = url + (url.indexOf("?", 0) === -1 ? "?" : "&") + "lastEventId=" + encodeURIComponent(lastEventId);
621
+ }
622
+ var requestHeaders = {};
623
+ requestHeaders["Accept"] = "text/event-stream";
624
+ if (headers != undefined) {
625
+ for (var name in headers) {
626
+ if (Object.prototype.hasOwnProperty.call(headers, name)) {
627
+ requestHeaders[name] = headers[name];
628
+ }
629
+ }
630
+ }
631
+ try {
632
+ transport.open(onStart, onProgress, onFinish, requestURL, withCredentials, requestHeaders);
633
+ } catch (error) {
634
+ close();
635
+ throw error;
636
+ }
637
+ };
638
+
639
+ es.url = url;
640
+ es.readyState = CONNECTING;
641
+ es.withCredentials = withCredentials;
642
+ es._close = close;
643
+
644
+ onTimeout();
645
+ }
646
+
647
+ EventSourcePolyfill.prototype = Object.create(EventTarget.prototype);
648
+ EventSourcePolyfill.prototype.CONNECTING = CONNECTING;
649
+ EventSourcePolyfill.prototype.OPEN = OPEN;
650
+ EventSourcePolyfill.prototype.CLOSED = CLOSED;
651
+ EventSourcePolyfill.prototype.close = function () {
652
+ this._close();
653
+ };
654
+
655
+ EventSourcePolyfill.CONNECTING = CONNECTING;
656
+ EventSourcePolyfill.OPEN = OPEN;
657
+ EventSourcePolyfill.CLOSED = CLOSED;
658
+ EventSourcePolyfill.prototype.withCredentials = undefined;
659
+
660
+ global.EventSourcePolyfill = EventSourcePolyfill;
661
+ global.NativeEventSource = NativeEventSource;
662
+
663
+ if (XMLHttpRequest != undefined && (NativeEventSource == undefined || !("withCredentials" in NativeEventSource.prototype))) {
664
+ // Why replace a native EventSource ?
665
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=444328
666
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=831392
667
+ // https://code.google.com/p/chromium/issues/detail?id=260144
668
+ // https://code.google.com/p/chromium/issues/detail?id=225654
669
+ // ...
670
+ global.EventSource = EventSourcePolyfill;
671
+ }
672
+
673
+ }(typeof window !== 'undefined' ? window : this));
inc/assets/js/eventsource.min.js CHANGED
@@ -1,6 +1,6 @@
1
- /** @license
2
- * eventsource.js
3
- * Available under MIT License (MIT)
4
- * https://github.com/Yaffle/EventSource/
5
- */
6
  !function(a){"use strict";function b(a){this.withCredentials=!1,this.responseType="",this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=p,this.onreadystatechange=p,this._contentType="",this._xhr=a,this._sendTimeout=0,this._abort=p}function c(a){this._xhr=new b(a)}function d(){this._listeners=Object.create(null)}function e(a){j(function(){throw a},0)}function f(a){this.type=a,this.target=void 0}function g(a,b){f.call(this,a),this.data=b.data,this.lastEventId=b.lastEventId}function h(a,b){d.call(this),this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this._close=void 0,i(this,a,b)}function i(a,b,d){b=String(b);var h=void 0!=d&&Boolean(d.withCredentials),i=D(1e3),n=D(45e3),o="",p=i,A=!1,B=void 0!=d&&void 0!=d.headers?JSON.parse(JSON.stringify(d.headers)):void 0,F=void 0!=d&&void 0!=d.Transport?d.Transport:void 0!=m?m:l,G=new c(new F),H=0,I=q,J="",K="",L="",M="",N=v,O=0,P=0,Q=function(b,c,d){if(I===r)if(200===b&&void 0!=d&&z.test(d)){I=s,A=!0,p=i,a.readyState=s;var g=new f("open");a.dispatchEvent(g),E(a,a.onopen,g)}else{var h="";200!==b?(c&&(c=c.replace(/\s+/g," ")),h="EventSource's response has a status "+b+" "+c+" that is not 200. Aborting the connection."):h="EventSource's response has a Content-Type specifying an unsupported type: "+(void 0==d?"-":d.replace(/\s+/g," "))+". Aborting the connection.",e(new Error(h)),T();var g=new f("error");a.dispatchEvent(g),E(a,a.onerror,g)}},R=function(b){if(I===s){for(var c=-1,d=0;d<b.length;d+=1){var e=b.charCodeAt(d);(e==="\n".charCodeAt(0)||e==="\r".charCodeAt(0))&&(c=d)}var f=(-1!==c?M:"")+b.slice(0,c+1);M=(-1===c?M:"")+b.slice(c+1),""!==f&&(A=!0);for(var h=0;h<f.length;h+=1){var e=f.charCodeAt(h);if(N===u&&e==="\n".charCodeAt(0))N=v;else if(N===u&&(N=v),e==="\r".charCodeAt(0)||e==="\n".charCodeAt(0)){if(N!==v){N===w&&(P=h+1);var l=f.slice(O,P-1),m=f.slice(P+(h>P&&f.charCodeAt(P)===" ".charCodeAt(0)?1:0),h);"data"===l?(J+="\n",J+=m):"id"===l?K=m:"event"===l?L=m:"retry"===l?(i=C(m,i),p=i):"heartbeatTimeout"===l&&(n=C(m,n),0!==H&&(k(H),H=j(function(){U()},n)))}if(N===v){if(""!==J){o=K,""===L&&(L="message");var q=new g(L,{data:J.slice(1),lastEventId:K});if(a.dispatchEvent(q),"message"===L&&E(a,a.onmessage,q),I===t)return}J="",L=""}N=e==="\r".charCodeAt(0)?u:v}else N===v&&(O=h,N=w),N===w?e===":".charCodeAt(0)&&(P=h+1,N=x):N===x&&(N=y)}}},S=function(){if(I===s||I===r){I=q,0!==H&&(k(H),H=0),H=j(function(){U()},p),p=D(Math.min(16*i,2*p)),a.readyState=r;var b=new f("error");a.dispatchEvent(b),E(a,a.onerror,b)}},T=function(){I=t,G.cancel(),0!==H&&(k(H),H=0),a.readyState=t},U=function(){if(H=0,I!==q)return void(A?(A=!1,H=j(function(){U()},n)):(e(new Error("No activity within "+n+" milliseconds. Reconnecting.")),G.cancel()));A=!1,H=j(function(){U()},n),I=r,J="",L="",K=o,M="",O=0,P=0,N=v;var a=b;"data:"!==b.slice(0,5)&&"blob:"!==b.slice(0,5)&&(a=b+(-1===b.indexOf("?",0)?"?":"&")+"lastEventId="+encodeURIComponent(o));var c={};if(c.Accept="text/event-stream",void 0!=B)for(var d in B)Object.prototype.hasOwnProperty.call(B,d)&&(c[d]=B[d]);try{G.open(Q,R,S,a,h,c)}catch(f){throw T(),f}};a.url=b,a.readyState=r,a.withCredentials=h,a._close=T,U()}var j=a.setTimeout,k=a.clearTimeout,l=a.XMLHttpRequest,m=a.XDomainRequest,n=a.EventSource,o=a.document;null==Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b});var p=function(){};b.prototype.open=function(a,b){this._abort(!0);var c=this,d=this._xhr,e=1,f=0;this._abort=function(a){0!==c._sendTimeout&&(k(c._sendTimeout),c._sendTimeout=0),(1===e||2===e||3===e)&&(e=4,d.onload=p,d.onerror=p,d.onabort=p,d.onprogress=p,d.onreadystatechange=p,d.abort(),0!==f&&(k(f),f=0),a||(c.readyState=4,c.onreadystatechange())),e=0};var g=function(){if(1===e){var a=0,b="",f=void 0;if("contentType"in d)a=200,b="OK",f=d.contentType;else try{a=d.status,b=d.statusText,f=d.getResponseHeader("Content-Type")}catch(g){a=0,b="",f=void 0}0!==a&&(e=2,c.readyState=2,c.status=a,c.statusText=b,c._contentType=f,c.onreadystatechange())}},h=function(){if(g(),2===e||3===e){e=3;var a="";try{a=d.responseText}catch(b){}c.readyState=3,c.responseText=a,c.onprogress()}},i=function(){h(),(1===e||2===e||3===e)&&(e=4,0!==f&&(k(f),f=0),c.readyState=4,c.onreadystatechange())},m=function(){void 0!=d&&(4===d.readyState?i():3===d.readyState?h():2===d.readyState&&g())},n=function(){f=j(function(){n()},500),3===d.readyState&&h()};d.onload=i,d.onerror=i,d.onabort=i,"sendAsBinary"in l.prototype||"mozAnon"in l.prototype||(d.onprogress=h),d.onreadystatechange=m,"contentType"in d&&(b+=(-1===b.indexOf("?",0)?"?":"&")+"padding=true"),d.open(a,b,!0),"readyState"in d&&(f=j(function(){n()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(a){return this._contentType},b.prototype.setRequestHeader=function(a,b){var c=this._xhr;"setRequestHeader"in c&&c.setRequestHeader(a,b)},b.prototype.send=function(){if(!("ontimeout"in l.prototype)&&void 0!=o&&void 0!=o.readyState&&"complete"!==o.readyState){var a=this;return void(a._sendTimeout=j(function(){a._sendTimeout=0,a.send()},4))}var b=this._xhr;b.withCredentials=this.withCredentials,b.responseType=this.responseType;try{b.send(void 0)}catch(c){throw c}},c.prototype.open=function(a,b,c,d,e,f){var g=this._xhr;g.open("GET",d);var h=0;g.onprogress=function(){var a=g.responseText,c=a.slice(h);h+=c.length,b(c)},g.onreadystatechange=function(){if(2===g.readyState){var b=g.status,d=g.statusText,e=g.getResponseHeader("Content-Type");a(b,d,e)}else 4===g.readyState&&c()},g.withCredentials=e,g.responseType="text";for(var i in f)Object.prototype.hasOwnProperty.call(f,i)&&g.setRequestHeader(i,f[i]);g.send()},c.prototype.cancel=function(){var a=this._xhr;a.abort()},d.prototype.dispatchEvent=function(a){a.target=this;var b=this._listeners[a.type];if(void 0!=b)for(var c=b.length,d=0;c>d;d+=1){var f=b[d];try{"function"==typeof f.handleEvent?f.handleEvent(a):f.call(this,a)}catch(g){e(g)}}},d.prototype.addEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];void 0==d&&(d=[],c[a]=d);for(var e=!1,f=0;f<d.length;f+=1)d[f]===b&&(e=!0);e||d.push(b)},d.prototype.removeEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];if(void 0!=d){for(var e=[],f=0;f<d.length;f+=1)d[f]!==b&&e.push(d[f]);0===e.length?delete c[a]:c[a]=e}},g.prototype=Object.create(f.prototype);var q=-1,r=0,s=1,t=2,u=-1,v=0,w=1,x=2,y=3,z=/^text\/event\-stream;?(\s*charset\=utf\-8)?$/i,A=1e3,B=18e6,C=function(a,b){var c=parseInt(a,10);return c!==c&&(c=b),D(c)},D=function(a){return Math.min(Math.max(a,A),B)},E=function(a,b,c){try{"function"==typeof b&&b.call(a,c)}catch(d){e(d)}};h.prototype=Object.create(d.prototype),h.prototype.CONNECTING=r,h.prototype.OPEN=s,h.prototype.CLOSED=t,h.prototype.close=function(){this._close()},h.CONNECTING=r,h.OPEN=s,h.CLOSED=t,h.prototype.withCredentials=void 0,a.EventSourcePolyfill=h,a.NativeEventSource=n,void 0==l||void 0!=n&&"withCredentials"in n.prototype||(a.EventSource=h)}("undefined"!=typeof window?window:this);
1
+ /** @license
2
+ * eventsource.js
3
+ * Available under MIT License (MIT)
4
+ * https://github.com/Yaffle/EventSource/
5
+ */
6
  !function(a){"use strict";function b(a){this.withCredentials=!1,this.responseType="",this.readyState=0,this.status=0,this.statusText="",this.responseText="",this.onprogress=p,this.onreadystatechange=p,this._contentType="",this._xhr=a,this._sendTimeout=0,this._abort=p}function c(a){this._xhr=new b(a)}function d(){this._listeners=Object.create(null)}function e(a){j(function(){throw a},0)}function f(a){this.type=a,this.target=void 0}function g(a,b){f.call(this,a),this.data=b.data,this.lastEventId=b.lastEventId}function h(a,b){d.call(this),this.onopen=void 0,this.onmessage=void 0,this.onerror=void 0,this.url=void 0,this.readyState=void 0,this.withCredentials=void 0,this._close=void 0,i(this,a,b)}function i(a,b,d){b=String(b);var h=void 0!=d&&Boolean(d.withCredentials),i=D(1e3),n=D(45e3),o="",p=i,A=!1,B=void 0!=d&&void 0!=d.headers?JSON.parse(JSON.stringify(d.headers)):void 0,F=void 0!=d&&void 0!=d.Transport?d.Transport:void 0!=m?m:l,G=new c(new F),H=0,I=q,J="",K="",L="",M="",N=v,O=0,P=0,Q=function(b,c,d){if(I===r)if(200===b&&void 0!=d&&z.test(d)){I=s,A=!0,p=i,a.readyState=s;var g=new f("open");a.dispatchEvent(g),E(a,a.onopen,g)}else{var h="";200!==b?(c&&(c=c.replace(/\s+/g," ")),h="EventSource's response has a status "+b+" "+c+" that is not 200. Aborting the connection."):h="EventSource's response has a Content-Type specifying an unsupported type: "+(void 0==d?"-":d.replace(/\s+/g," "))+". Aborting the connection.",e(new Error(h)),T();var g=new f("error");a.dispatchEvent(g),E(a,a.onerror,g)}},R=function(b){if(I===s){for(var c=-1,d=0;d<b.length;d+=1){var e=b.charCodeAt(d);(e==="\n".charCodeAt(0)||e==="\r".charCodeAt(0))&&(c=d)}var f=(-1!==c?M:"")+b.slice(0,c+1);M=(-1===c?M:"")+b.slice(c+1),""!==f&&(A=!0);for(var h=0;h<f.length;h+=1){var e=f.charCodeAt(h);if(N===u&&e==="\n".charCodeAt(0))N=v;else if(N===u&&(N=v),e==="\r".charCodeAt(0)||e==="\n".charCodeAt(0)){if(N!==v){N===w&&(P=h+1);var l=f.slice(O,P-1),m=f.slice(P+(h>P&&f.charCodeAt(P)===" ".charCodeAt(0)?1:0),h);"data"===l?(J+="\n",J+=m):"id"===l?K=m:"event"===l?L=m:"retry"===l?(i=C(m,i),p=i):"heartbeatTimeout"===l&&(n=C(m,n),0!==H&&(k(H),H=j(function(){U()},n)))}if(N===v){if(""!==J){o=K,""===L&&(L="message");var q=new g(L,{data:J.slice(1),lastEventId:K});if(a.dispatchEvent(q),"message"===L&&E(a,a.onmessage,q),I===t)return}J="",L=""}N=e==="\r".charCodeAt(0)?u:v}else N===v&&(O=h,N=w),N===w?e===":".charCodeAt(0)&&(P=h+1,N=x):N===x&&(N=y)}}},S=function(){if(I===s||I===r){I=q,0!==H&&(k(H),H=0),H=j(function(){U()},p),p=D(Math.min(16*i,2*p)),a.readyState=r;var b=new f("error");a.dispatchEvent(b),E(a,a.onerror,b)}},T=function(){I=t,G.cancel(),0!==H&&(k(H),H=0),a.readyState=t},U=function(){if(H=0,I!==q)return void(A?(A=!1,H=j(function(){U()},n)):(e(new Error("No activity within "+n+" milliseconds. Reconnecting.")),G.cancel()));A=!1,H=j(function(){U()},n),I=r,J="",L="",K=o,M="",O=0,P=0,N=v;var a=b;"data:"!==b.slice(0,5)&&"blob:"!==b.slice(0,5)&&(a=b+(-1===b.indexOf("?",0)?"?":"&")+"lastEventId="+encodeURIComponent(o));var c={};if(c.Accept="text/event-stream",void 0!=B)for(var d in B)Object.prototype.hasOwnProperty.call(B,d)&&(c[d]=B[d]);try{G.open(Q,R,S,a,h,c)}catch(f){throw T(),f}};a.url=b,a.readyState=r,a.withCredentials=h,a._close=T,U()}var j=a.setTimeout,k=a.clearTimeout,l=a.XMLHttpRequest,m=a.XDomainRequest,n=a.EventSource,o=a.document;null==Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b});var p=function(){};b.prototype.open=function(a,b){this._abort(!0);var c=this,d=this._xhr,e=1,f=0;this._abort=function(a){0!==c._sendTimeout&&(k(c._sendTimeout),c._sendTimeout=0),(1===e||2===e||3===e)&&(e=4,d.onload=p,d.onerror=p,d.onabort=p,d.onprogress=p,d.onreadystatechange=p,d.abort(),0!==f&&(k(f),f=0),a||(c.readyState=4,c.onreadystatechange())),e=0};var g=function(){if(1===e){var a=0,b="",f=void 0;if("contentType"in d)a=200,b="OK",f=d.contentType;else try{a=d.status,b=d.statusText,f=d.getResponseHeader("Content-Type")}catch(g){a=0,b="",f=void 0}0!==a&&(e=2,c.readyState=2,c.status=a,c.statusText=b,c._contentType=f,c.onreadystatechange())}},h=function(){if(g(),2===e||3===e){e=3;var a="";try{a=d.responseText}catch(b){}c.readyState=3,c.responseText=a,c.onprogress()}},i=function(){h(),(1===e||2===e||3===e)&&(e=4,0!==f&&(k(f),f=0),c.readyState=4,c.onreadystatechange())},m=function(){void 0!=d&&(4===d.readyState?i():3===d.readyState?h():2===d.readyState&&g())},n=function(){f=j(function(){n()},500),3===d.readyState&&h()};d.onload=i,d.onerror=i,d.onabort=i,"sendAsBinary"in l.prototype||"mozAnon"in l.prototype||(d.onprogress=h),d.onreadystatechange=m,"contentType"in d&&(b+=(-1===b.indexOf("?",0)?"?":"&")+"padding=true"),d.open(a,b,!0),"readyState"in d&&(f=j(function(){n()},0))},b.prototype.abort=function(){this._abort(!1)},b.prototype.getResponseHeader=function(a){return this._contentType},b.prototype.setRequestHeader=function(a,b){var c=this._xhr;"setRequestHeader"in c&&c.setRequestHeader(a,b)},b.prototype.send=function(){if(!("ontimeout"in l.prototype)&&void 0!=o&&void 0!=o.readyState&&"complete"!==o.readyState){var a=this;return void(a._sendTimeout=j(function(){a._sendTimeout=0,a.send()},4))}var b=this._xhr;b.withCredentials=this.withCredentials,b.responseType=this.responseType;try{b.send(void 0)}catch(c){throw c}},c.prototype.open=function(a,b,c,d,e,f){var g=this._xhr;g.open("GET",d);var h=0;g.onprogress=function(){var a=g.responseText,c=a.slice(h);h+=c.length,b(c)},g.onreadystatechange=function(){if(2===g.readyState){var b=g.status,d=g.statusText,e=g.getResponseHeader("Content-Type");a(b,d,e)}else 4===g.readyState&&c()},g.withCredentials=e,g.responseType="text";for(var i in f)Object.prototype.hasOwnProperty.call(f,i)&&g.setRequestHeader(i,f[i]);g.send()},c.prototype.cancel=function(){var a=this._xhr;a.abort()},d.prototype.dispatchEvent=function(a){a.target=this;var b=this._listeners[a.type];if(void 0!=b)for(var c=b.length,d=0;c>d;d+=1){var f=b[d];try{"function"==typeof f.handleEvent?f.handleEvent(a):f.call(this,a)}catch(g){e(g)}}},d.prototype.addEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];void 0==d&&(d=[],c[a]=d);for(var e=!1,f=0;f<d.length;f+=1)d[f]===b&&(e=!0);e||d.push(b)},d.prototype.removeEventListener=function(a,b){a=String(a);var c=this._listeners,d=c[a];if(void 0!=d){for(var e=[],f=0;f<d.length;f+=1)d[f]!==b&&e.push(d[f]);0===e.length?delete c[a]:c[a]=e}},g.prototype=Object.create(f.prototype);var q=-1,r=0,s=1,t=2,u=-1,v=0,w=1,x=2,y=3,z=/^text\/event\-stream;?(\s*charset\=utf\-8)?$/i,A=1e3,B=18e6,C=function(a,b){var c=parseInt(a,10);return c!==c&&(c=b),D(c)},D=function(a){return Math.min(Math.max(a,A),B)},E=function(a,b,c){try{"function"==typeof b&&b.call(a,c)}catch(d){e(d)}};h.prototype=Object.create(d.prototype),h.prototype.CONNECTING=r,h.prototype.OPEN=s,h.prototype.CLOSED=t,h.prototype.close=function(){this._close()},h.CONNECTING=r,h.OPEN=s,h.CLOSED=t,h.prototype.withCredentials=void 0,a.EventSourcePolyfill=h,a.NativeEventSource=n,void 0==l||void 0!=n&&"withCredentials"in n.prototype||(a.EventSource=h)}("undefined"!=typeof window?window:this);
inc/assets/js/render-grid.js CHANGED
@@ -1,592 +1,597 @@
1
- (function($){
2
-
3
- AstraRender = {
4
-
5
- _ref : null,
6
-
7
- /**
8
- * _api_params = {
9
- * 'search' : '',
10
- * 'per_page' : '',
11
- * 'astra-site-category' : '',
12
- * 'astra-site-page-builder' : '',
13
- * 'page' : '',
14
- * };
15
- *
16
- * E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
17
- */
18
- _api_params : {},
19
- _breakpoint : 768,
20
- _has_default_page_builder : false,
21
-
22
- init: function()
23
- {
24
- this._resetPagedCount();
25
- this._bind();
26
- this._loadPageBuilders();
27
- },
28
-
29
- /**
30
- * Binds events for the Astra Sites.
31
- *
32
- * @since 1.0.0
33
- * @access private
34
- * @method _bind
35
- */
36
- _bind: function()
37
- {
38
- $( document ).on('astra-sites-api-request-error' , AstraRender._addSuggestionBox );
39
- $( document ).on('astra-sites-api-request-fail' , AstraRender._addSuggestionBox );
40
- $( document ).on('astra-api-post-loaded-on-scroll' , AstraRender._reinitGridScrolled );
41
- $( document ).on('astra-api-post-loaded' , AstraRender._reinitGrid );
42
- $( document ).on('astra-api-page-builder-loaded' , AstraRender._addPageBuilders );
43
- $( document ).on('astra-api-category-loaded' , AstraRender._loadFirstGrid );
44
-
45
- // Event's for API request.
46
- $( document ).on('click' , '.filter-links a', AstraRender._filterClick );
47
- $( document ).on('keyup input' , '#wp-filter-search-input', AstraRender._search );
48
- $( document ).on('scroll' , AstraRender._scroll );
49
- $( document ).on('astra-sites-api-request-fail', AstraRender._site_unreachable );
50
- },
51
-
52
- /**
53
- * Website is Down
54
- *
55
- * @since 1.2.11
56
- * @return null
57
- */
58
- _site_unreachable: function( event, jqXHR, textStatus, args ) {
59
- event.preventDefault();
60
- if ( 'astra-site-page-builder' === args.id ) {
61
- $('#astra-sites-admin').html( wp.template('astra-site-down') )
62
- }
63
- },
64
-
65
- /**
66
- * On Filter Clicked
67
- *
68
- * Prepare Before API Request:
69
- * - Empty search input field to avoid search term on filter click.
70
- * - Remove Inline Height
71
- * - Added 'hide-me' class to hide the 'No more sites!' string.
72
- * - Added 'loading-content' for body.
73
- * - Show spinner.
74
- */
75
- _filterClick: function( event ) {
76
-
77
- event.preventDefault();
78
-
79
- if( $( this ).parents('.astra-site-category').length && ! $('body').hasClass('page-builder-selected') ) {
80
- return;
81
- }
82
-
83
- $(this).parents('.filter-links').find('a').removeClass('current');
84
- $(this).addClass('current');
85
-
86
- // Prepare Before Search.
87
- $('.no-more-demos').addClass('hide-me');
88
- $('.astra-sites-suggestions').remove();
89
-
90
- // Empty the search input only click on category filter not on page builder filter.
91
- if( $(this).parents('.filter-links').hasClass('astra-site-category') ) {
92
- $('#wp-filter-search-input').val('');
93
- }
94
- $('#astra-sites').hide().css('height', '');
95
-
96
- $('body').addClass('loading-content');
97
- $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
98
-
99
- // Show sites.
100
- AstraRender._showSites();
101
- },
102
-
103
- /**
104
- * Search Site.
105
- *
106
- * Prepare Before API Request:
107
- * - Remove Inline Height
108
- * - Added 'hide-me' class to hide the 'No more sites!' string.
109
- * - Added 'loading-content' for body.
110
- * - Show spinner.
111
- */
112
- _search: function() {
113
-
114
- if( ! $('body').hasClass('page-builder-selected') ) {
115
- return;
116
- }
117
-
118
- $this = jQuery('#wp-filter-search-input').val();
119
-
120
- // Prepare Before Search.
121
- $('#astra-sites').hide().css('height', '');
122
- $('.no-more-demos').addClass('hide-me');
123
- $('.astra-sites-suggestions').remove();
124
-
125
- $('body').addClass('loading-content');
126
- $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
127
-
128
- window.clearTimeout(AstraRender._ref);
129
- AstraRender._ref = window.setTimeout(function () {
130
- AstraRender._ref = null;
131
-
132
- AstraRender._resetPagedCount();
133
- jQuery('body').addClass('loading-content');
134
- jQuery('body').attr('data-astra-demo-search', $this);
135
-
136
- AstraRender._showSites();
137
-
138
- }, 500);
139
-
140
- },
141
-
142
- /**
143
- * On Scroll
144
- */
145
- _scroll: function(event) {
146
-
147
- if( ! $('body').hasClass('page-builder-selected') ) {
148
- return;
149
- }
150
-
151
- if( ! $('body').hasClass('listed-all-sites') ) {
152
-
153
- var scrollDistance = jQuery(window).scrollTop();
154
-
155
- var themesBottom = Math.abs(jQuery(window).height() - jQuery('#astra-sites').offset().top - jQuery('#astra-sites').height());
156
- themesBottom = themesBottom - 100;
157
-
158
- ajaxLoading = jQuery('body').data('scrolling');
159
-
160
- if (scrollDistance > themesBottom && ajaxLoading == false) {
161
- AstraRender._updatedPagedCount();
162
-
163
- if( ! $('#astra-sites .no-themes').length ) {
164
- $('#astra-sites-admin').find('.spinner').addClass('is-active');
165
- }
166
-
167
- jQuery('body').data('scrolling', true);
168
-
169
- /**
170
- * @see _reinitGridScrolled() which called in trigger 'astra-api-post-loaded-on-scroll'
171
- */
172
- AstraRender._showSites( false, 'astra-api-post-loaded-on-scroll' );
173
- }
174
- }
175
- },
176
-
177
- _apiAddParam_status: function() {
178
- if( astraRenderGrid.sites && astraRenderGrid.sites.status ) {
179
- AstraRender._api_params['status'] = astraRenderGrid.sites.status;
180
- }
181
- },
182
-
183
- // Add 'search'
184
- _apiAddParam_search: function() {
185
- var search_val = jQuery('#wp-filter-search-input').val() || '';
186
- if( '' !== search_val ) {
187
- AstraRender._api_params['search'] = search_val;
188
- }
189
- },
190
-
191
- _apiAddParam_per_page: function() {
192
- // Add 'per_page'
193
- var per_page_val = 15;
194
- if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
195
- per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
196
- }
197
- AstraRender._api_params['per_page'] = per_page_val;
198
- },
199
-
200
- _apiAddParam_astra_site_category: function() {
201
- // Add 'astra-site-category'
202
- var selected_category_id = jQuery('.filter-links.astra-site-category').find('.current').data('group') || '';
203
- if( '' !== selected_category_id && 'all' !== selected_category_id ) {
204
- AstraRender._api_params['astra-site-category'] = selected_category_id;
205
- } else if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
206
- if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
207
- AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include.join(',');
208
- } else {
209
- AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include;
210
- }
211
- }
212
- },
213
-
214
- _apiAddParam_astra_site_page_builder: function() {
215
- // Add 'astra-site-page-builder'
216
- var selected_page_builder_id = jQuery('.filter-links.astra-site-page-builder').find('.current').data('group') || '';
217
- if( '' !== selected_page_builder_id && 'all' !== selected_page_builder_id ) {
218
- AstraRender._api_params['astra-site-page-builder'] = selected_page_builder_id;
219
- } else if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
220
- if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
221
- AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include.join(',');
222
- } else {
223
- AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include;
224
- }
225
- }
226
- },
227
-
228
- _apiAddParam_page: function() {
229
- // Add 'page'
230
- var page_val = parseInt(jQuery('body').attr('data-astra-demo-paged')) || 1;
231
- AstraRender._api_params['page'] = page_val;
232
- },
233
-
234
- _apiAddParam_purchase_key: function() {
235
- if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
236
- AstraRender._api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
237
- }
238
- },
239
-
240
- _apiAddParam_site_url: function() {
241
- if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
242
- AstraRender._api_params['site_url'] = astraRenderGrid.sites.site_url;
243
- }
244
- },
245
-
246
- /**
247
- * Show Sites
248
- *
249
- * Params E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
250
- *
251
- * @param {Boolean} resetPagedCount Reset Paged Count.
252
- * @param {String} trigger Filtered Trigger.
253
- */
254
- _showSites: function( resetPagedCount, trigger ) {
255
-
256
- if( undefined === resetPagedCount ) {
257
- resetPagedCount = true
258
- }
259
-
260
- if( undefined === trigger ) {
261
- trigger = 'astra-api-post-loaded';
262
- }
263
-
264
- if( resetPagedCount ) {
265
- AstraRender._resetPagedCount();
266
- }
267
-
268
- // Add Params for API request.
269
- AstraRender._api_params = {};
270
-
271
- AstraRender._apiAddParam_status();
272
- AstraRender._apiAddParam_search();
273
- AstraRender._apiAddParam_per_page();
274
- AstraRender._apiAddParam_astra_site_category();
275
- AstraRender._apiAddParam_astra_site_page_builder();
276
- AstraRender._apiAddParam_page();
277
- AstraRender._apiAddParam_site_url();
278
- AstraRender._apiAddParam_purchase_key();
279
-
280
- // API Request.
281
- var api_post = {
282
- slug: 'astra-sites?' + decodeURIComponent( $.param( AstraRender._api_params ) ),
283
- trigger: trigger,
284
- };
285
-
286
- AstraSitesAPI._api_request( api_post );
287
-
288
- },
289
-
290
- /**
291
- * Get Category Params
292
- *
293
- * @since 1.2.4
294
- * @param {string} category_slug Category Slug.
295
- * @return {mixed} Add `include=<category-ids>` in API request.
296
- */
297
- _getPageBuilderParams: function()
298
- {
299
- var _params = {};
300
-
301
- if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
302
- _params['purchase_key'] = astraRenderGrid.sites.purchase_key;
303
- }
304
-
305
- if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
306
- _params['site_url'] = astraRenderGrid.sites.site_url;
307
- }
308
-
309
- if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
310
- if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
311
- _params['include'] = astraRenderGrid['page-builders'].include.join(',');
312
- } else {
313
- _params['include'] = astraRenderGrid['page-builders'].include;
314
- }
315
- }
316
-
317
- var decoded_params = decodeURIComponent( $.param( _params ) );
318
-
319
- if( decoded_params.length ) {
320
- return '/?' + decoded_params;
321
- }
322
-
323
- return '/';
324
- },
325
-
326
- /**
327
- * Get Category Params
328
- *
329
- * @param {string} category_slug Category Slug.
330
- * @return {mixed} Add `include=<category-ids>` in API request.
331
- */
332
- _getCategoryParams: function( category_slug ) {
333
-
334
- var _params = {};
335
-
336
- if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
337
- if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
338
- _params['include'] = astraRenderGrid['categories'].include.join(',');
339
- } else {
340
- _params['include'] = astraRenderGrid['categories'].include;
341
- }
342
- }
343
-
344
- var decoded_params = decodeURIComponent( $.param( _params ) );
345
-
346
- if( decoded_params.length ) {
347
- return '/?' + decoded_params;
348
- }
349
-
350
- return '/';
351
- },
352
-
353
- /**
354
- * Get All Select Status
355
- *
356
- * @param {string} category_slug Category Slug.
357
- * @return {boolean} Return true/false.
358
- */
359
- _getCategoryAllSelectStatus: function( category_slug ) {
360
-
361
- // Has category?
362
- if( category_slug in astraRenderGrid.settings ) {
363
-
364
- // Has `all` in stored list?
365
- if( $.inArray('all', astraRenderGrid.settings[ category_slug ]) === -1 ) {
366
- return false;
367
- }
368
- }
369
-
370
- return true;
371
- },
372
-
373
- /**
374
- * Show Filters
375
- */
376
- _loadPageBuilders: function() {
377
-
378
- /**
379
- * Page Builder
380
- */
381
- var category_slug = 'astra-site-page-builder';
382
- var category = {
383
- slug : category_slug + AstraRender._getPageBuilderParams(),
384
- id : category_slug,
385
- class : category_slug,
386
- trigger : 'astra-api-page-builder-loaded',
387
- wrapper_class : 'filter-links',
388
- show_all : false,
389
- };
390
-
391
- AstraSitesAPI._api_request( category );
392
- },
393
-
394
- /**
395
- * Load First Grid.
396
- *
397
- * This is triggered after all category loaded.
398
- *
399
- * @param {object} event Event Object.
400
- */
401
- _loadFirstGrid: function( event, data ) {
402
-
403
- event.preventDefault();
404
-
405
- if( $('#' + data.args.id).length ) {
406
- var template = wp.template('astra-site-filters');
407
- $('#' + data.args.id).html(template( data ));
408
-
409
- if( 'true' === $('body').attr( 'data-default-page-builder-selected' ) ) {
410
- $('#' + data.args.id).find('li:first a').addClass('current');
411
- AstraRender._showSites();
412
- } else {
413
- $('body').removeClass('loading-content');
414
- if( ! $('#astra-sites-admin .astra-site-select-page-builder').length ) {
415
- $('#astra-sites-admin').append( wp.template( 'astra-site-select-page-builder' ) );
416
- }
417
- }
418
- } else {
419
- AstraRender._showSites();
420
- }
421
-
422
- },
423
-
424
- /**
425
- * Append filters.
426
- *
427
- * @param {object} event Object.
428
- * @param {object} data API response data.
429
- */
430
- _addPageBuilders: function( event, data ) {
431
- event.preventDefault();
432
-
433
- if( $('#' + data.args.id).length ) {
434
- var template = wp.template('astra-site-filters');
435
- $('#' + data.args.id).html(template( data ));
436
-
437
- if( 1 === parseInt( data.items_count ) ) {
438
- $('body').attr( 'data-default-page-builder-selected', true );
439
- $('#' + data.args.id).find('li:first a').addClass('current');
440
- }
441
- }
442
-
443
- /**
444
- * Categories
445
- */
446
- var category_slug = 'astra-site-category';
447
- var category = {
448
- slug : category_slug + AstraRender._getCategoryParams( category_slug ),
449
- id : category_slug,
450
- class : category_slug,
451
- trigger : 'astra-api-category-loaded',
452
- wrapper_class : 'filter-links',
453
- show_all : AstraRender._getCategoryAllSelectStatus( category_slug ),
454
- };
455
-
456
- AstraSitesAPI._api_request( category );
457
-
458
- },
459
-
460
-
461
- /**
462
- * Append sites on scroll.
463
- *
464
- * @param {object} event Object.
465
- * @param {object} data API response data.
466
- */
467
- _reinitGridScrolled: function( event, data ) {
468
-
469
- var template = wp.template('astra-sites-list');
470
-
471
- if( data.items.length > 0 ) {
472
-
473
- $('body').removeClass( 'loading-content' );
474
- $('.filter-count .count').text( data.items_count );
475
-
476
- setTimeout(function() {
477
- jQuery('#astra-sites').append(template( data ));
478
-
479
- AstraRender._imagesLoaded();
480
- }, 800);
481
- } else {
482
- $('body').addClass('listed-all-sites');
483
- }
484
-
485
- },
486
-
487
- /**
488
- * Update Astra sites list.
489
- *
490
- * @param {object} event Object.
491
- * @param {object} data API response data.
492
- */
493
- _reinitGrid: function( event, data ) {
494
-
495
- var template = wp.template('astra-sites-list');
496
-
497
- $('body').addClass( 'page-builder-selected' );
498
- $('body').removeClass( 'loading-content' );
499
- $('.filter-count .count').text( data.items_count );
500
-
501
- jQuery('body').attr('data-astra-demo-last-request', data.items_count);
502
-
503
- jQuery('#astra-sites').show().html(template( data ));
504
-
505
- AstraRender._imagesLoaded();
506
-
507
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
508
-
509
- if( data.items_count <= 0 ) {
510
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
511
- $('.no-more-demos').addClass('hide-me');
512
- $('.astra-sites-suggestions').remove();
513
-
514
- } else {
515
- $('body').removeClass('listed-all-sites');
516
- }
517
-
518
-
519
- },
520
-
521
- /**
522
- * Check image loaded with function `imagesLoaded()`
523
- */
524
- _imagesLoaded: function() {
525
-
526
- var self = jQuery('#sites-filter.execute-only-one-time a');
527
-
528
- $('.astra-sites-grid').imagesLoaded()
529
- .always( function( instance ) {
530
- if( jQuery( window ).outerWidth() > AstraRender._breakpoint ) {
531
- // $('#astra-sites').masonry('reload');
532
- }
533
-
534
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
535
- })
536
- .progress( function( instance, image ) {
537
- var result = image.isLoaded ? 'loaded' : 'broken';
538
- });
539
-
540
- },
541
-
542
- /**
543
- * Add Suggestion Box
544
- */
545
- _addSuggestionBox: function() {
546
- $('#astra-sites-admin').find('.spinner').removeClass('is-active').addClass('hide-me');
547
-
548
- $('#astra-sites-admin').find('.no-more-demos').removeClass('hide-me');
549
- var template = wp.template('astra-sites-suggestions');
550
- if( ! $( '.astra-sites-suggestions').length ) {
551
- $('#astra-sites').append( template );
552
- }
553
- },
554
-
555
- /**
556
- * Update Page Count.
557
- */
558
- _updatedPagedCount: function() {
559
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
560
- jQuery('body').attr('data-astra-demo-paged', paged + 1);
561
- window.setTimeout(function () {
562
- jQuery('body').data('scrolling', false);
563
- }, 800);
564
- },
565
-
566
- /**
567
- * Reset Page Count.
568
- */
569
- _resetPagedCount: function() {
570
-
571
- jQuery('body').attr('data-astra-demo-last-request', '1');
572
- jQuery('body').attr('data-astra-demo-paged', '1');
573
- jQuery('body').attr('data-astra-demo-search', '');
574
- jQuery('body').attr('data-scrolling', false);
575
-
576
- },
577
-
578
- // Returns if a value is an array
579
- _isArray: function(value) {
580
- return value && typeof value === 'object' && value.constructor === Array;
581
- }
582
-
583
- };
584
-
585
- /**
586
- * Initialize AstraRender
587
- */
588
- $(function(){
589
- AstraRender.init();
590
- });
591
-
 
 
 
 
 
592
  })(jQuery);
1
+ (function($){
2
+
3
+ AstraRender = {
4
+
5
+ _ref : null,
6
+
7
+ /**
8
+ * _api_params = {
9
+ * 'search' : '',
10
+ * 'per_page' : '',
11
+ * 'astra-site-category' : '',
12
+ * 'astra-site-page-builder' : '',
13
+ * 'page' : '',
14
+ * };
15
+ *
16
+ * E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
17
+ */
18
+ _api_params : {},
19
+ _breakpoint : 768,
20
+ _has_default_page_builder : false,
21
+
22
+ init: function()
23
+ {
24
+ this._resetPagedCount();
25
+ this._bind();
26
+ this._loadPageBuilders();
27
+ },
28
+
29
+ /**
30
+ * Binds events for the Astra Sites.
31
+ *
32
+ * @since 1.0.0
33
+ * @access private
34
+ * @method _bind
35
+ */
36
+ _bind: function()
37
+ {
38
+ $( document ).on('astra-sites-api-request-error' , AstraRender._addSuggestionBox );
39
+ $( document ).on('astra-sites-api-request-fail' , AstraRender._addSuggestionBox );
40
+ $( document ).on('astra-api-post-loaded-on-scroll' , AstraRender._reinitGridScrolled );
41
+ $( document ).on('astra-api-post-loaded' , AstraRender._reinitGrid );
42
+ $( document ).on('astra-api-page-builder-loaded' , AstraRender._addPageBuilders );
43
+ $( document ).on('astra-api-category-loaded' , AstraRender._loadFirstGrid );
44
+
45
+ // Event's for API request.
46
+ $( document ).on('click' , '.filter-links a', AstraRender._filterClick );
47
+ $( document ).on('keyup input' , '#wp-filter-search-input', AstraRender._search );
48
+ $( document ).on('scroll' , AstraRender._scroll );
49
+ $( document ).on('astra-sites-api-request-fail', AstraRender._site_unreachable );
50
+ },
51
+
52
+ /**
53
+ * Website is Down
54
+ *
55
+ * @since 1.2.11
56
+ * @return null
57
+ */
58
+ _site_unreachable: function( event, jqXHR, textStatus, args ) {
59
+ event.preventDefault();
60
+ if ( 'astra-site-page-builder' === args.id ) {
61
+ $('#astra-sites-admin').html( wp.template('astra-site-down') )
62
+ }
63
+ },
64
+
65
+ /**
66
+ * On Filter Clicked
67
+ *
68
+ * Prepare Before API Request:
69
+ * - Empty search input field to avoid search term on filter click.
70
+ * - Remove Inline Height
71
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
72
+ * - Added 'loading-content' for body.
73
+ * - Show spinner.
74
+ */
75
+ _filterClick: function( event ) {
76
+
77
+ event.preventDefault();
78
+
79
+ if( $( this ).parents('.astra-site-category').length && ! $('body').hasClass('page-builder-selected') ) {
80
+ return;
81
+ }
82
+
83
+ $(this).parents('.filter-links').find('a').removeClass('current');
84
+ $(this).addClass('current');
85
+
86
+ // Prepare Before Search.
87
+ $('.no-more-demos').addClass('hide-me');
88
+ $('.astra-sites-suggestions').remove();
89
+
90
+ // Empty the search input only click on category filter not on page builder filter.
91
+ if( $(this).parents('.filter-links').hasClass('astra-site-category') ) {
92
+ $('#wp-filter-search-input').val('');
93
+ }
94
+ $('#astra-sites').hide().css('height', '');
95
+
96
+ $('body').addClass('loading-content');
97
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
98
+
99
+ // Show sites.
100
+ AstraRender._showSites();
101
+ },
102
+
103
+ /**
104
+ * Search Site.
105
+ *
106
+ * Prepare Before API Request:
107
+ * - Remove Inline Height
108
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
109
+ * - Added 'loading-content' for body.
110
+ * - Show spinner.
111
+ */
112
+ _search: function() {
113
+
114
+ if( ! $('body').hasClass('page-builder-selected') ) {
115
+ return;
116
+ }
117
+
118
+ $this = jQuery('#wp-filter-search-input').val();
119
+
120
+ // Prepare Before Search.
121
+ $('#astra-sites').hide().css('height', '');
122
+ $('.no-more-demos').addClass('hide-me');
123
+ $('.astra-sites-suggestions').remove();
124
+
125
+ $('body').addClass('loading-content');
126
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
127
+
128
+ window.clearTimeout(AstraRender._ref);
129
+ AstraRender._ref = window.setTimeout(function () {
130
+ AstraRender._ref = null;
131
+
132
+ AstraRender._resetPagedCount();
133
+ jQuery('body').addClass('loading-content');
134
+ jQuery('body').attr('data-astra-demo-search', $this);
135
+
136
+ AstraRender._showSites();
137
+
138
+ }, 500);
139
+
140
+ },
141
+
142
+ /**
143
+ * On Scroll
144
+ */
145
+ _scroll: function(event) {
146
+
147
+ if( ! $('body').hasClass('page-builder-selected') ) {
148
+ return;
149
+ }
150
+
151
+ if( ! $('body').hasClass('listed-all-sites') ) {
152
+
153
+ var scrollDistance = jQuery(window).scrollTop();
154
+
155
+ var themesBottom = Math.abs(jQuery(window).height() - jQuery('#astra-sites').offset().top - jQuery('#astra-sites').height());
156
+ themesBottom = themesBottom - 100;
157
+
158
+ ajaxLoading = jQuery('body').data('scrolling');
159
+
160
+ if (scrollDistance > themesBottom && ajaxLoading == false) {
161
+ AstraRender._updatedPagedCount();
162
+
163
+ if( ! $('#astra-sites .no-themes').length ) {
164
+ $('#astra-sites-admin').find('.spinner').addClass('is-active');
165
+ }
166
+
167
+ jQuery('body').data('scrolling', true);
168
+
169
+ /**
170
+ * @see _reinitGridScrolled() which called in trigger 'astra-api-post-loaded-on-scroll'
171
+ */
172
+ AstraRender._showSites( false, 'astra-api-post-loaded-on-scroll' );
173
+ }
174
+ }
175
+ },
176
+
177
+ _apiAddParam_status: function() {
178
+ if( astraRenderGrid.sites && astraRenderGrid.sites.status ) {
179
+ AstraRender._api_params['status'] = astraRenderGrid.sites.status;
180
+ }
181
+ },
182
+
183
+ // Add 'search'
184
+ _apiAddParam_search: function() {
185
+ var search_val = jQuery('#wp-filter-search-input').val() || '';
186
+ if( '' !== search_val ) {
187
+ AstraRender._api_params['search'] = search_val;
188
+ }
189
+ },
190
+
191
+ _apiAddParam_per_page: function() {
192
+ // Add 'per_page'
193
+ var per_page_val = 15;
194
+ if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
195
+ per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
196
+ }
197
+ AstraRender._api_params['per_page'] = per_page_val;
198
+ },
199
+
200
+ _apiAddParam_astra_site_category: function() {
201
+ // Add 'astra-site-category'
202
+ var selected_category_id = jQuery('.filter-links.astra-site-category').find('.current').data('group') || '';
203
+ if( '' !== selected_category_id && 'all' !== selected_category_id ) {
204
+ AstraRender._api_params['astra-site-category'] = selected_category_id;
205
+ } else if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
206
+ if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
207
+ AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include.join(',');
208
+ } else {
209
+ AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include;
210
+ }
211
+ }
212
+ },
213
+
214
+ _apiAddParam_astra_site_page_builder: function() {
215
+ // Add 'astra-site-page-builder'
216
+ var selected_page_builder_id = jQuery('.filter-links.astra-site-page-builder').find('.current').data('group') || '';
217
+ if( '' !== selected_page_builder_id && 'all' !== selected_page_builder_id ) {
218
+ AstraRender._api_params['astra-site-page-builder'] = selected_page_builder_id;
219
+ } else if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
220
+ if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
221
+ AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include.join(',');
222
+ } else {
223
+ AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include;
224
+ }
225
+ }
226
+ },
227
+
228
+ _apiAddParam_page: function() {
229
+ // Add 'page'
230
+ var page_val = parseInt(jQuery('body').attr('data-astra-demo-paged')) || 1;
231
+ AstraRender._api_params['page'] = page_val;
232
+ },
233
+
234
+ _apiAddParam_purchase_key: function() {
235
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
236
+ AstraRender._api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
237
+ }
238
+ },
239
+
240
+ _apiAddParam_site_url: function() {
241
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
242
+ AstraRender._api_params['site_url'] = astraRenderGrid.sites.site_url;
243
+ }
244
+ },
245
+
246
+ /**
247
+ * Show Sites
248
+ *
249
+ * Params E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
250
+ *
251
+ * @param {Boolean} resetPagedCount Reset Paged Count.
252
+ * @param {String} trigger Filtered Trigger.
253
+ */
254
+ _showSites: function( resetPagedCount, trigger ) {
255
+
256
+ if( undefined === resetPagedCount ) {
257
+ resetPagedCount = true
258
+ }
259
+
260
+ if( undefined === trigger ) {
261
+ trigger = 'astra-api-post-loaded';
262
+ }
263
+
264
+ if( resetPagedCount ) {
265
+ AstraRender._resetPagedCount();
266
+ }
267
+
268
+ // Add Params for API request.
269
+ AstraRender._api_params = {};
270
+
271
+ AstraRender._apiAddParam_status();
272
+ AstraRender._apiAddParam_search();
273
+ AstraRender._apiAddParam_per_page();
274
+ AstraRender._apiAddParam_astra_site_category();
275
+ AstraRender._apiAddParam_astra_site_page_builder();
276
+ AstraRender._apiAddParam_page();
277
+ AstraRender._apiAddParam_site_url();
278
+ AstraRender._apiAddParam_purchase_key();
279
+
280
+ // API Request.
281
+ var api_post = {
282
+ id: 'astra-sites',
283
+ slug: 'astra-sites?' + decodeURIComponent( $.param( AstraRender._api_params ) ),
284
+ trigger: trigger,
285
+ };
286
+
287
+ AstraSitesAPI._api_request( api_post );
288
+
289
+ },
290
+
291
+ /**
292
+ * Get Category Params
293
+ *
294
+ * @since 1.2.4
295
+ * @param {string} category_slug Category Slug.
296
+ * @return {mixed} Add `include=<category-ids>` in API request.
297
+ */
298
+ _getPageBuilderParams: function()
299
+ {
300
+ var _params = {};
301
+
302
+ if( astraRenderGrid.default_page_builder ) {
303
+ _params['search'] = astraRenderGrid.default_page_builder;
304
+ }
305
+
306
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
307
+ _params['purchase_key'] = astraRenderGrid.sites.purchase_key;
308
+ }
309
+
310
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
311
+ _params['site_url'] = astraRenderGrid.sites.site_url;
312
+ }
313
+
314
+ if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
315
+ if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
316
+ _params['include'] = astraRenderGrid['page-builders'].include.join(',');
317
+ } else {
318
+ _params['include'] = astraRenderGrid['page-builders'].include;
319
+ }
320
+ }
321
+
322
+ var decoded_params = decodeURIComponent( $.param( _params ) );
323
+
324
+ if( decoded_params.length ) {
325
+ return '/?' + decoded_params;
326
+ }
327
+
328
+ return '/';
329
+ },
330
+
331
+ /**
332
+ * Get Category Params
333
+ *
334
+ * @param {string} category_slug Category Slug.
335
+ * @return {mixed} Add `include=<category-ids>` in API request.
336
+ */
337
+ _getCategoryParams: function( category_slug ) {
338
+
339
+ var _params = {};
340
+
341
+ if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
342
+ if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
343
+ _params['include'] = astraRenderGrid['categories'].include.join(',');
344
+ } else {
345
+ _params['include'] = astraRenderGrid['categories'].include;
346
+ }
347
+ }
348
+
349
+ var decoded_params = decodeURIComponent( $.param( _params ) );
350
+
351
+ if( decoded_params.length ) {
352
+ return '/?' + decoded_params;
353
+ }
354
+
355
+ return '/';
356
+ },
357
+
358
+ /**
359
+ * Get All Select Status
360
+ *
361
+ * @param {string} category_slug Category Slug.
362
+ * @return {boolean} Return true/false.
363
+ */
364
+ _getCategoryAllSelectStatus: function( category_slug ) {
365
+
366
+ // Has category?
367
+ if( category_slug in astraRenderGrid.settings ) {
368
+
369
+ // Has `all` in stored list?
370
+ if( $.inArray('all', astraRenderGrid.settings[ category_slug ]) === -1 ) {
371
+ return false;
372
+ }
373
+ }
374
+
375
+ return true;
376
+ },
377
+
378
+ /**
379
+ * Show Filters
380
+ */
381
+ _loadPageBuilders: function() {
382
+
383
+ /**
384
+ * Page Builder
385
+ */
386
+ var category_slug = 'astra-site-page-builder';
387
+ var category = {
388
+ slug : category_slug + AstraRender._getPageBuilderParams(),
389
+ id : category_slug,
390
+ class : category_slug,
391
+ trigger : 'astra-api-page-builder-loaded',
392
+ wrapper_class : 'filter-links',
393
+ show_all : false,
394
+ };
395
+
396
+ AstraSitesAPI._api_request( category );
397
+ },
398
+
399
+ /**
400
+ * Load First Grid.
401
+ *
402
+ * This is triggered after all category loaded.
403
+ *
404
+ * @param {object} event Event Object.
405
+ */
406
+ _loadFirstGrid: function( event, data ) {
407
+
408
+ event.preventDefault();
409
+
410
+ if( $('#' + data.args.id).length ) {
411
+ var template = wp.template('astra-site-filters');
412
+ $('#' + data.args.id).html(template( data ));
413
+
414
+ if( 'true' === $('body').attr( 'data-default-page-builder-selected' ) ) {
415
+ $('#' + data.args.id).find('li:first a').addClass('current');
416
+ AstraRender._showSites();
417
+ } else {
418
+ $('body').removeClass('loading-content');
419
+ if( ! $('#astra-sites-admin .astra-site-select-page-builder').length ) {
420
+ $('#astra-sites-admin').append( wp.template( 'astra-site-select-page-builder' ) );
421
+ }
422
+ }
423
+ } else {
424
+ AstraRender._showSites();
425
+ }
426
+
427
+ },
428
+
429
+ /**
430
+ * Append filters.
431
+ *
432
+ * @param {object} event Object.
433
+ * @param {object} data API response data.
434
+ */
435
+ _addPageBuilders: function( event, data ) {
436
+ event.preventDefault();
437
+
438
+ if( $('#' + data.args.id).length ) {
439
+ var template = wp.template('astra-site-filters');
440
+ $('#' + data.args.id).html(template( data ));
441
+
442
+ if( 1 === parseInt( data.items_count ) ) {
443
+ $('body').attr( 'data-default-page-builder-selected', true );
444
+ $('#' + data.args.id).find('li:first a').addClass('current');
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Categories
450
+ */
451
+ var category_slug = 'astra-site-category';
452
+ var category = {
453
+ slug : category_slug + AstraRender._getCategoryParams( category_slug ),
454
+ id : category_slug,
455
+ class : category_slug,
456
+ trigger : 'astra-api-category-loaded',
457
+ wrapper_class : 'filter-links',
458
+ show_all : AstraRender._getCategoryAllSelectStatus( category_slug ),
459
+ };
460
+
461
+ AstraSitesAPI._api_request( category );
462
+
463
+ },
464
+
465
+
466
+ /**
467
+ * Append sites on scroll.
468
+ *
469
+ * @param {object} event Object.
470
+ * @param {object} data API response data.
471
+ */
472
+ _reinitGridScrolled: function( event, data ) {
473
+
474
+ var template = wp.template('astra-sites-list');
475
+
476
+ if( data.items.length > 0 ) {
477
+
478
+ $('body').removeClass( 'loading-content' );
479
+ $('.filter-count .count').text( data.items_count );
480
+
481
+ setTimeout(function() {
482
+ jQuery('#astra-sites').append(template( data ));
483
+
484
+ AstraRender._imagesLoaded();
485
+ }, 800);
486
+ } else {
487
+ $('body').addClass('listed-all-sites');
488
+ }
489
+
490
+ },
491
+
492
+ /**
493
+ * Update Astra sites list.
494
+ *
495
+ * @param {object} event Object.
496
+ * @param {object} data API response data.
497
+ */
498
+ _reinitGrid: function( event, data ) {
499
+
500
+ var template = wp.template('astra-sites-list');
501
+
502
+ $('body').addClass( 'page-builder-selected' );
503
+ $('body').removeClass( 'loading-content' );
504
+ $('.filter-count .count').text( data.items_count );
505
+
506
+ jQuery('body').attr('data-astra-demo-last-request', data.items_count);
507
+
508
+ jQuery('#astra-sites').show().html(template( data ));
509
+
510
+ AstraRender._imagesLoaded();
511
+
512
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
513
+
514
+ if( data.items_count <= 0 ) {
515
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
516
+ $('.no-more-demos').addClass('hide-me');
517
+ $('.astra-sites-suggestions').remove();
518
+
519
+ } else {
520
+ $('body').removeClass('listed-all-sites');
521
+ }
522
+
523
+
524
+ },
525
+
526
+ /**
527
+ * Check image loaded with function `imagesLoaded()`
528
+ */
529
+ _imagesLoaded: function() {
530
+
531
+ var self = jQuery('#sites-filter.execute-only-one-time a');
532
+
533
+ $('.astra-sites-grid').imagesLoaded()
534
+ .always( function( instance ) {
535
+ if( jQuery( window ).outerWidth() > AstraRender._breakpoint ) {
536
+ // $('#astra-sites').masonry('reload');
537
+ }
538
+
539
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
540
+ })
541
+ .progress( function( instance, image ) {
542
+ var result = image.isLoaded ? 'loaded' : 'broken';
543
+ });
544
+
545
+ },
546
+
547
+ /**
548
+ * Add Suggestion Box
549
+ */
550
+ _addSuggestionBox: function() {
551
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active').addClass('hide-me');
552
+
553
+ $('#astra-sites-admin').find('.no-more-demos').removeClass('hide-me');
554
+ var template = wp.template('astra-sites-suggestions');
555
+ if( ! $( '.astra-sites-suggestions').length ) {
556
+ $('#astra-sites').append( template );
557
+ }
558
+ },
559
+
560
+ /**
561
+ * Update Page Count.
562
+ */
563
+ _updatedPagedCount: function() {
564
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
565
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
566
+ window.setTimeout(function () {
567
+ jQuery('body').data('scrolling', false);
568
+ }, 800);
569
+ },
570
+
571
+ /**
572
+ * Reset Page Count.
573
+ */
574
+ _resetPagedCount: function() {
575
+
576
+ jQuery('body').attr('data-astra-demo-last-request', '1');
577
+ jQuery('body').attr('data-astra-demo-paged', '1');
578
+ jQuery('body').attr('data-astra-demo-search', '');
579
+ jQuery('body').attr('data-scrolling', false);
580
+
581
+ },
582
+
583
+ // Returns if a value is an array
584
+ _isArray: function(value) {
585
+ return value && typeof value === 'object' && value.constructor === Array;
586
+ }
587
+
588
+ };
589
+
590
+ /**
591
+ * Initialize AstraRender
592
+ */
593
+ $(function(){
594
+ AstraRender.init();
595
+ });
596
+
597
  })(jQuery);
inc/classes/class-astra-sites-importer-log.php CHANGED
@@ -1,510 +1,601 @@
1
- <?php
2
- /**
3
- * Astra Sites Importer Log
4
- *
5
- * @since 1.1.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites_Importer_Log' ) ) :
12
-
13
- /**
14
- * Astra Sites Importer
15
- */
16
- class Astra_Sites_Importer_Log {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.0
22
- * @var (Object) Class object
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Log File
28
- *
29
- * @since 1.1.0
30
- * @var (Object) Class object
31
- */
32
- private static $log_file = null;
33
-
34
- /**
35
- * Set Instance
36
- *
37
- * @since 1.1.0
38
- *
39
- * @return object Class object.
40
- */
41
- public static function get_instance() {
42
- if ( ! isset( self::$_instance ) ) {
43
- self::$_instance = new self;
44
- }
45
-
46
- return self::$_instance;
47
- }
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @since 1.1.0
53
- */
54
- private function __construct() {
55
-
56
- // Check file read/write permissions.
57
- add_action( 'admin_init', array( $this, 'has_file_read_write' ) );
58
-
59
- }
60
-
61
- /**
62
- * Check file read/write permissions and process.
63
- *
64
- * @since 1.1.0
65
- * @return null
66
- */
67
- function has_file_read_write() {
68
-
69
- // Get user credentials for WP file-system API.
70
- $astra_sites_import = wp_nonce_url( admin_url( 'themes.php?page=astra-sites' ), 'astra-import' );
71
- if ( false === ( $creds = request_filesystem_credentials( $astra_sites_import, '', false, false, null ) ) ) {
72
- return;
73
- }
74
-
75
- // Set log file.
76
- self::set_log_file();
77
-
78
- // Initial AJAX Import Hooks.
79
- add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 );
80
- add_action( 'astra_sites_import_customizer_settings', array( $this, 'start_customizer' ) );
81
- add_action( 'astra_sites_import_prepare_xml_data', array( $this, 'start_xml' ) );
82
- add_action( 'astra_sites_import_options', array( $this, 'start_options' ) );
83
- add_action( 'astra_sites_import_widgets', array( $this, 'start_widgets' ) );
84
- add_action( 'astra_sites_import_complete', array( $this, 'start_end' ) );
85
-
86
- // Hooks in between the process of import.
87
- add_filter( 'wie_import_results', array( $this, 'widgets_data' ) );
88
- add_action( 'astra_sites_import_xml_log', array( $this, 'xml_log' ), 10, 3 );
89
- }
90
-
91
- /**
92
- * Add log file URL in UI response.
93
- *
94
- * @since 1.1.0
95
- */
96
- public static function add_log_file_url() {
97
-
98
- $upload_dir = self::log_dir();
99
- $upload_path = trailingslashit( $upload_dir['url'] );
100
- $file_abs_url = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
101
- $file_url = $upload_path . basename( $file_abs_url );
102
-
103
- return array(
104
- 'abs_url' => $file_abs_url,
105
- 'url' => $file_url,
106
- );
107
- }
108
-
109
- /**
110
- * XML Log.
111
- *
112
- * @since 1.1.0
113
- * @param string $level Level (Debug, Info etc.).
114
- * @param string $message Message.
115
- * @param string $context Context.
116
- * @return void
117
- */
118
- function xml_log( $level = '', $message = '', $context = '' ) {
119
- Astra_Sites_Importer_Log::add( $message );
120
- }
121
-
122
- /**
123
- * Current Time for log.
124
- *
125
- * @since 1.1.0
126
- * @return string Current time with time zone.
127
- */
128
- public static function current_time() {
129
- return date( 'H:i:s' ) . ' ' . date_default_timezone_get();
130
- }
131
-
132
- /**
133
- * Import Start
134
- *
135
- * @since 1.1.0
136
- * @param array $data Import Data.
137
- * @param string $demo_api_uri Import site API URL.
138
- * @return void
139
- */
140
- function start( $data = array(), $demo_api_uri = '' ) {
141
-
142
- Astra_Sites_Importer_Log::add( '# System Details: ' );
143
- Astra_Sites_Importer_Log::add( "Debug Mode \t\t: " . self::get_debug_mode() );
144
- Astra_Sites_Importer_Log::add( "Operating System \t: " . self::get_os() );
145
- Astra_Sites_Importer_Log::add( "Software \t\t: " . self::get_software() );
146
- Astra_Sites_Importer_Log::add( "MySQL version \t\t: " . self::get_mysql_version() );
147
- Astra_Sites_Importer_Log::add( "XML Reader \t\t: " . self::get_xmlreader_status() );
148
- Astra_Sites_Importer_Log::add( "PHP Version \t\t: " . self::get_php_version() );
149
- Astra_Sites_Importer_Log::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() );
150
- Astra_Sites_Importer_Log::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() );
151
- Astra_Sites_Importer_Log::add( "PHP Extension GD \t: " . self::get_php_extension_gd() );
152
- Astra_Sites_Importer_Log::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() );
153
- Astra_Sites_Importer_Log::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) );
154
- Astra_Sites_Importer_Log::add( "Memory Limit \t\t: " . self::get_memory_limit() );
155
- Astra_Sites_Importer_Log::add( "Timezone \t\t: " . self::get_timezone() );
156
- Astra_Sites_Importer_Log::add( PHP_EOL . '-----' . PHP_EOL );
157
- Astra_Sites_Importer_Log::add( 'Importing Started! - ' . self::current_time() );
158
-
159
- Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
160
- Astra_Sites_Importer_Log::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' );
161
- Astra_Sites_Importer_Log::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL );
162
- Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
163
-
164
- }
165
-
166
- /**
167
- * Start Customizer Import
168
- *
169
- * @since 1.1.0
170
- * @return void
171
- */
172
- function start_customizer() {
173
- Astra_Sites_Importer_Log::add( PHP_EOL . '1. Imported "Customizer Settings" - ' . self::current_time() );
174
- Astra_Sites_Importer_Log::add( PHP_EOL . '---' );
175
- }
176
-
177
- /**
178
- * Start XML Import
179
- *
180
- * @since 1.1.0
181
- * @return void
182
- */
183
- function start_xml() {
184
- Astra_Sites_Importer_Log::add( PHP_EOL . '2. Importing "XML" - ' . self::current_time() );
185
- }
186
-
187
- /**
188
- * Start Options Import
189
- *
190
- * @since 1.1.0
191
- * @return void
192
- */
193
- function start_options() {
194
- Astra_Sites_Importer_Log::add( PHP_EOL . '---' );
195
- Astra_Sites_Importer_Log::add( PHP_EOL . '3. Imported "Site Options" - ' . self::current_time() );
196
- Astra_Sites_Importer_Log::add( PHP_EOL . '---' );
197
- }
198
-
199
- /**
200
- * Start Widgets Import
201
- *
202
- * @since 1.1.0
203
- * @return void
204
- */
205
- function start_widgets() {
206
- Astra_Sites_Importer_Log::add( PHP_EOL . '4. Importing "Widgets" - ' . self::current_time() );
207
- }
208
-
209
- /**
210
- * End Import Process
211
- *
212
- * @since 1.1.0
213
- * @return void
214
- */
215
- function start_end() {
216
- Astra_Sites_Importer_Log::add( PHP_EOL . '---' );
217
- Astra_Sites_Importer_Log::add( PHP_EOL . 'Import Complete! - ' . self::current_time() );
218
-
219
- // Delete Log file.
220
- delete_option( 'astra_sites_recent_import_log_file' );
221
- }
222
-
223
- /**
224
- * Log Widget Import Data.
225
- *
226
- * @since 1.1.0
227
- * @param array $results Widget import info in array.
228
- * @return void
229
- */
230
- function widgets_data( $results = array() ) {
231
-
232
- if ( is_array( $results ) ) {
233
- foreach ( $results as $sidebar_key => $widgets ) {
234
- Astra_Sites_Importer_Log::add( 'Sidebar: ' . $sidebar_key );
235
- foreach ( $widgets['widgets'] as $widget_key => $widget ) {
236
- if ( isset( $widget['name'] ) && isset( $widget['message'] ) ) {
237
- Astra_Sites_Importer_Log::add( 'Widget: "' . $widget['name'] . '" - ' . $widget['message'] );
238
- }
239
- }
240
- }
241
- }
242
- }
243
-
244
- /**
245
- * Get an instance of WP_Filesystem_Direct.
246
- *
247
- * @since 1.1.0
248
- * @return object A WP_Filesystem_Direct instance.
249
- */
250
- static public function get_filesystem() {
251
- global $wp_filesystem;
252
-
253
- require_once ABSPATH . '/wp-admin/includes/file.php';
254
-
255
- WP_Filesystem();
256
-
257
- return $wp_filesystem;
258
- }
259
-
260
- /**
261
- * Get Log File
262
- *
263
- * @since 1.1.0
264
- * @return string log file URL.
265
- */
266
- public static function get_log_file() {
267
- return self::$log_file;
268
- }
269
-
270
- /**
271
- * Log file directory
272
- *
273
- * @since 1.1.0
274
- * @param string $dir_name Directory Name.
275
- * @return array Uploads directory array.
276
- */
277
- public static function log_dir( $dir_name = 'astra-sites' ) {
278
-
279
- $upload_dir = wp_upload_dir();
280
-
281
- // Build the paths.
282
- $dir_info = array(
283
- 'path' => $upload_dir['basedir'] . '/' . $dir_name . '/',
284
- 'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/',
285
- );
286
-
287
- // Create the upload dir if it doesn't exist.
288
- if ( ! file_exists( $dir_info['path'] ) ) {
289
-
290
- // Create the directory.
291
- wp_mkdir_p( $dir_info['path'] );
292
-
293
- // Add an index file for security.
294
- self::get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' );
295
- }
296
-
297
- return $dir_info;
298
- }
299
-
300
- /**
301
- * Set log file
302
- *
303
- * @since 1.1.0
304
- */
305
- public static function set_log_file() {
306
-
307
- $upload_dir = self::log_dir();
308
-
309
- $upload_path = trailingslashit( $upload_dir['path'] );
310
-
311
- // File format e.g. 'import-31-Oct-2017-06-39-12.txt'.
312
- self::$log_file = $upload_path . 'import-' . date( 'd-M-Y-h-i-s' ) . '.txt';
313
-
314
- if ( ! get_option( 'astra_sites_recent_import_log_file', false ) ) {
315
- update_option( 'astra_sites_recent_import_log_file', self::$log_file );
316
- }
317
- }
318
-
319
- /**
320
- * Write content to a file.
321
- *
322
- * @since 1.1.0
323
- * @param string $content content to be saved to the file.
324
- */
325
- public static function add( $content ) {
326
-
327
- if ( get_option( 'astra_sites_recent_import_log_file', false ) ) {
328
- $log_file = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
329
- } else {
330
- $log_file = self::$log_file;
331
- }
332
-
333
- $existing_data = '';
334
- if ( file_exists( $log_file ) ) {
335
- $existing_data = self::get_filesystem()->get_contents( $log_file );
336
- }
337
-
338
- // Style separator.
339
- $separator = PHP_EOL;
340
-
341
- self::get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE );
342
- }
343
-
344
- /**
345
- * Debug Mode
346
- *
347
- * @since 1.1.0
348
- * @return string Enabled for Debug mode ON and Disabled for Debug mode Off.
349
- */
350
- public static function get_debug_mode() {
351
- if ( WP_DEBUG ) {
352
- return __( 'Enabled', 'astra-sites' );
353
- }
354
-
355
- return __( 'Disabled', 'astra-sites' );
356
- }
357
-
358
- /**
359
- * Memory Limit
360
- *
361
- * @since 1.1.0
362
- * @return string Memory limit.
363
- */
364
- public static function get_memory_limit() {
365
-
366
- $required_memory = '64M';
367
- $memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
368
- $memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory );
369
-
370
- if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) {
371
- return sprintf(
372
- /* translators: %1$s Memory Limit, %2$s Recommended memory limit. */
373
- _x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ),
374
- WP_MEMORY_LIMIT,
375
- $required_memory
376
- );
377
- }
378
-
379
- return WP_MEMORY_LIMIT;
380
- }
381
-
382
- /**
383
- * Timezone
384
- *
385
- * @since 1.1.0
386
- * @see https://codex.wordpress.org/Option_Reference/
387
- *
388
- * @return string Current timezone.
389
- */
390
- public static function get_timezone() {
391
- $timezone = get_option( 'timezone_string' );
392
-
393
- if ( ! $timezone ) {
394
- return get_option( 'gmt_offset' );
395
- }
396
-
397
- return $timezone;
398
- }
399
-
400
- /**
401
- * Operating System
402
- *
403
- * @since 1.1.0
404
- * @return string Current Operating System.
405
- */
406
- public static function get_os() {
407
- return PHP_OS;
408
- }
409
-
410
- /**
411
- * Server Software
412
- *
413
- * @since 1.1.0
414
- * @return string Current Server Software.
415
- */
416
- public static function get_software() {
417
- return $_SERVER['SERVER_SOFTWARE'];
418
- }
419
-
420
- /**
421
- * MySql Version
422
- *
423
- * @since 1.1.0
424
- * @return string Current MySql Version.
425
- */
426
- public static function get_mysql_version() {
427
- global $wpdb;
428
- return $wpdb->db_version();
429
- }
430
-
431
- /**
432
- * XML Reader
433
- *
434
- * @since 1.2.8
435
- * @return string Current XML Reader status.
436
- */
437
- public static function get_xmlreader_status() {
438
-
439
- if ( class_exists( 'XMLReader' ) ) {
440
- return __( 'Yes', 'astra-sites' );
441
- }
442
-
443
- return __( 'No', 'astra-sites' );
444
- }
445
-
446
- /**
447
- * PHP Version
448
- *
449
- * @since 1.1.0
450
- * @return string Current PHP Version.
451
- */
452
- public static function get_php_version() {
453
- if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
454
- return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' );
455
- }
456
- return PHP_VERSION;
457
- }
458
-
459
- /**
460
- * PHP Max Input Vars
461
- *
462
- * @since 1.1.0
463
- * @return string Current PHP Max Input Vars
464
- */
465
- public static function get_php_max_input_vars() {
466
- return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
467
- }
468
-
469
- /**
470
- * PHP Max Post Size
471
- *
472
- * @since 1.1.0
473
- * @return string Current PHP Max Post Size
474
- */
475
- public static function get_php_max_post_size() {
476
- return ini_get( 'post_max_size' );
477
- }
478
-
479
- /**
480
- * PHP Max Execution Time
481
- *
482
- * @since 1.1.0
483
- * @return string Current Max Execution Time
484
- */
485
- public static function get_max_execution_time() {
486
- return ini_get( 'max_execution_time' );
487
- }
488
-
489
- /**
490
- * PHP GD Extension
491
- *
492
- * @since 1.1.0
493
- * @return string Current PHP GD Extension
494
- */
495
- public static function get_php_extension_gd() {
496
- if ( extension_loaded( 'gd' ) ) {
497
- return __( 'Yes', 'astra-sites' );
498
- }
499
-
500
- return __( 'No', 'astra-sites' );
501
- }
502
-
503
- }
504
-
505
- /**
506
- * Kicking this off by calling 'get_instance()' method
507
- */
508
- Astra_Sites_Importer_Log::get_instance();
509
-
510
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Astra Sites Importer Log
4
+ *
5
+ * @since 1.1.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Importer_Log' ) ) :
12
+
13
+ /**
14
+ * Astra Sites Importer
15
+ */
16
+ class Astra_Sites_Importer_Log {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.0
22
+ * @var (Object) Class object
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Log File
28
+ *
29
+ * @since 1.1.0
30
+ * @var (Object) Class object
31
+ */
32
+ private static $log_file = null;
33
+
34
+ /**
35
+ * Set Instance
36
+ *
37
+ * @since 1.1.0
38
+ *
39
+ * @return object Class object.
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! isset( self::$_instance ) ) {
43
+ self::$_instance = new self;
44
+ }
45
+
46
+ return self::$_instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @since 1.1.0
53
+ */
54
+ private function __construct() {
55
+
56
+ // Check file read/write permissions.
57
+ add_action( 'admin_init', array( $this, 'has_file_read_write' ) );
58
+
59
+ }
60
+
61
+ /**
62
+ * Check file read/write permissions and process.
63
+ *
64
+ * @since 1.1.0
65
+ * @return null
66
+ */
67
+ function has_file_read_write() {
68
+
69
+ // Get user credentials for WP file-system API.
70
+ $astra_sites_import = wp_nonce_url( admin_url( 'themes.php?page=astra-sites' ), 'astra-import' );
71
+ if ( false === ( $creds = request_filesystem_credentials( $astra_sites_import, '', false, false, null ) ) ) {
72
+ return;
73
+ }
74
+
75
+ // Set log file.
76
+ self::set_log_file();
77
+
78
+ // Initial AJAX Import Hooks.
79
+ add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 );
80
+ add_action( 'astra_sites_import_customizer_settings', array( $this, 'start_customizer' ) );
81
+ add_action( 'astra_sites_import_prepare_xml_data', array( $this, 'start_xml' ) );
82
+ add_action( 'astra_sites_import_options', array( $this, 'start_options' ) );
83
+ add_action( 'astra_sites_import_widgets', array( $this, 'start_widgets' ) );
84
+ add_action( 'astra_sites_import_complete', array( $this, 'start_end' ) );
85
+
86
+ add_action( 'wxr_importer.processed.post', array( $this, 'track_post' ) );
87
+ add_action( 'wxr_importer.processed.term', array( $this, 'track_term' ) );
88
+
89
+ // Delete..
90
+ add_action( 'astra_sites_reset_customizer_data', array( $this, 'reset_customizer_data' ) );
91
+ add_action( 'astra_sites_reset_site_options', array( $this, 'reset_site_options' ) );
92
+ add_action( 'astra_sites_reset_widgets_data', array( $this, 'reset_widgets_data' ) );
93
+ add_action( 'astra_sites_delete_imported_posts', array( $this, 'delete_imported_posts' ) );
94
+ add_action( 'astra_sites_delete_imported_wp_forms', array( $this, 'delete_imported_wp_forms' ) );
95
+ add_action( 'astra_sites_delete_imported_terms', array( $this, 'delete_imported_terms' ), 10, 2 );
96
+ }
97
+
98
+ /**
99
+ * Add log file URL in UI response.
100
+ *
101
+ * @since 1.1.0
102
+ */
103
+ public static function add_log_file_url() {
104
+
105
+ $upload_dir = self::log_dir();
106
+ $upload_path = trailingslashit( $upload_dir['url'] );
107
+ $file_abs_url = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
108
+ $file_url = $upload_path . basename( $file_abs_url );
109
+
110
+ return array(
111
+ 'abs_url' => $file_abs_url,
112
+ 'url' => $file_url,
113
+ );
114
+ }
115
+
116
+ /**
117
+ * Current Time for log.
118
+ *
119
+ * @since 1.1.0
120
+ * @return string Current time with time zone.
121
+ */
122
+ public static function current_time() {
123
+ return date( 'H:i:s' ) . ' ' . date_default_timezone_get();
124
+ }
125
+
126
+ /**
127
+ * Import Start
128
+ *
129
+ * @since 1.1.0
130
+ * @param array $data Import Data.
131
+ * @param string $demo_api_uri Import site API URL.
132
+ * @return void
133
+ */
134
+ function start( $data = array(), $demo_api_uri = '' ) {
135
+
136
+ Astra_Sites_Importer_Log::add( '==== Started ====' );
137
+
138
+ Astra_Sites_Importer_Log::add( '# System Details: ' );
139
+ Astra_Sites_Importer_Log::add( "Debug Mode \t\t: " . self::get_debug_mode() );
140
+ Astra_Sites_Importer_Log::add( "Operating System \t: " . self::get_os() );
141
+ Astra_Sites_Importer_Log::add( "Software \t\t: " . self::get_software() );
142
+ Astra_Sites_Importer_Log::add( "MySQL version \t\t: " . self::get_mysql_version() );
143
+ Astra_Sites_Importer_Log::add( "XML Reader \t\t: " . self::get_xmlreader_status() );
144
+ Astra_Sites_Importer_Log::add( "PHP Version \t\t: " . self::get_php_version() );
145
+ Astra_Sites_Importer_Log::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() );
146
+ Astra_Sites_Importer_Log::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() );
147
+ Astra_Sites_Importer_Log::add( "PHP Extension GD \t: " . self::get_php_extension_gd() );
148
+ Astra_Sites_Importer_Log::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() );
149
+ Astra_Sites_Importer_Log::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) );
150
+ Astra_Sites_Importer_Log::add( "Memory Limit \t\t: " . self::get_memory_limit() );
151
+ Astra_Sites_Importer_Log::add( "Timezone \t\t: " . self::get_timezone() );
152
+ Astra_Sites_Importer_Log::add( PHP_EOL . '-----' . PHP_EOL );
153
+ Astra_Sites_Importer_Log::add( 'Importing Started! - ' . self::current_time() );
154
+
155
+ Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
156
+ Astra_Sites_Importer_Log::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' );
157
+ Astra_Sites_Importer_Log::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL );
158
+ Astra_Sites_Importer_Log::add( '---' . PHP_EOL );
159
+
160
+ }
161
+
162
+ /**
163
+ * Track Post
164
+ *
165
+ * @since 1.3.0
166
+ *
167
+ * @param int $post_id Post ID.
168
+ * @return void
169
+ */
170
+ function track_post( $post_id ) {
171
+ Astra_Sites_Importer_Log::add( '==== INSERTED - Post ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id ) );
172
+ }
173
+
174
+ /**
175
+ * Track Term
176
+ *
177
+ * @since 1.3.0
178
+ *
179
+ * @param int $term_id Term ID.
180
+ * @return void
181
+ */
182
+ function track_term( $term_id ) {
183
+ $term = get_term( $term_id );
184
+ if ( $term ) {
185
+ Astra_Sites_Importer_Log::add( '==== INSERTED - Term ' . $term_id . ' - ' . json_encode( $term ) );
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Reset Customizer Data
191
+ *
192
+ * @since 1.3.0
193
+ *
194
+ * @param array $data Customizer Data.
195
+ * @return void
196
+ */
197
+ function reset_customizer_data( $data ) {
198
+ if ( $data ) {
199
+ Astra_Sites_Importer_Log::add( '==== DELETED - CUSTOMIZER SETTINGS ' . json_encode( $data ) );
200
+ }
201
+ }
202
+
203
+ /**
204
+ * Reset Site Options
205
+ *
206
+ * @since 1.3.0
207
+ *
208
+ * @param array $data Site options.
209
+ * @return void
210
+ */
211
+ function reset_site_options( $data ) {
212
+ if ( $data ) {
213
+ Astra_Sites_Importer_Log::add( '==== DELETED - SITE OPTIONS ' . json_encode( $data ) );
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Reset Widgets Data
219
+ *
220
+ * @since 1.3.0
221
+ *
222
+ * @param array $old_widgets Old Widgets.
223
+ * @return void
224
+ */
225
+ function reset_widgets_data( $old_widgets ) {
226
+ if ( $old_widgets ) {
227
+ Astra_Sites_Importer_Log::add( '==== DELETED - WIDGETS ' . json_encode( $old_widgets ) );
228
+ }
229
+ }
230
+
231
+ /**
232
+ * Delete Imported Posts
233
+ *
234
+ * @since 1.3.0
235
+ *
236
+ * @param int $post_id Post ID.
237
+ * @return void
238
+ */
239
+ function delete_imported_posts( $post_id ) {
240
+ Astra_Sites_Importer_Log::add( '==== DELETED - POST ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id ) );
241
+ }
242
+
243
+ /**
244
+ * Delete Imported WP Forms
245
+ *
246
+ * @since 1.3.0
247
+ *
248
+ * @param int $form_id Form ID.
249
+ * @return void
250
+ */
251
+ function delete_imported_wp_forms( $form_id ) {
252
+ Astra_Sites_Importer_Log::add( '==== DELETED - FORM ID ' . $form_id . ' - ' . get_post_type( $form_id ) . ' - ' . get_the_title( $form_id ) );
253
+ }
254
+
255
+ /**
256
+ * Delete Imported Terms
257
+ *
258
+ * @since 1.3.0
259
+ *
260
+ * @param int $term_id Term ID.
261
+ * @param array $term Term array.
262
+ * @return void
263
+ */
264
+ function delete_imported_terms( $term_id, $term ) {
265
+ Astra_Sites_Importer_Log::add( '==== DELETED - TERM ID ' . $term_id . ' - ' . json_encode( $term ) );
266
+ }
267
+
268
+ /**
269
+ * Start Customizer Import
270
+ *
271
+ * @since 1.3.0
272
+ *
273
+ * @param array $data Customizer Data.
274
+ * @return void
275
+ */
276
+ function start_customizer( $data ) {
277
+ if ( $data ) {
278
+ Astra_Sites_Importer_Log::add( '==== IMPORTED - CUSTOMIZER SETTINGS ' . json_encode( $data ) );
279
+ }
280
+ }
281
+
282
+ /**
283
+ * Start XML Import
284
+ *
285
+ * @param string $xml XML file URL.
286
+ * @since 1.3.0
287
+ * @return void
288
+ */
289
+ function start_xml( $xml ) {
290
+ Astra_Sites_Importer_Log::add( '==== IMPORTING from XML ' . $xml );
291
+ }
292
+
293
+ /**
294
+ * Start Options Import
295
+ *
296
+ * @since 1.3.0
297
+ *
298
+ * @param array $data Site options.
299
+ * @return void
300
+ */
301
+ function start_options( $data ) {
302
+ if ( $data ) {
303
+ Astra_Sites_Importer_Log::add( '==== IMPORTED - SITE OPTIONS ' . json_encode( $data ) );
304
+ }
305
+ }
306
+
307
+ /**
308
+ * Start Widgets Import
309
+ *
310
+ * @since 1.3.0
311
+ *
312
+ * @param array $old_widgets Widgets Data.
313
+ * @return void
314
+ */
315
+ function start_widgets( $old_widgets ) {
316
+ if ( $old_widgets ) {
317
+ Astra_Sites_Importer_Log::add( '==== IMPORTED - WIDGETS ' . json_encode( $old_widgets ) );
318
+ }
319
+ }
320
+
321
+ /**
322
+ * End Import Process
323
+ *
324
+ * @since 1.3.0
325
+ *
326
+ * @return void
327
+ */
328
+ function start_end() {
329
+ Astra_Sites_Importer_Log::add( '==== Complete ====' );
330
+
331
+ // Delete Log file.
332
+ delete_option( 'astra_sites_recent_import_log_file' );
333
+ }
334
+
335
+ /**
336
+ * Get an instance of WP_Filesystem_Direct.
337
+ *
338
+ * @since 1.1.0
339
+ * @return object A WP_Filesystem_Direct instance.
340
+ */
341
+ static public function get_filesystem() {
342
+ global $wp_filesystem;
343
+
344
+ require_once ABSPATH . '/wp-admin/includes/file.php';
345
+
346
+ WP_Filesystem();
347
+
348
+ return $wp_filesystem;
349
+ }
350
+
351
+ /**
352
+ * Get Log File
353
+ *
354
+ * @since 1.1.0
355
+ * @return string log file URL.
356
+ */
357
+ public static function get_log_file() {
358
+ return self::$log_file;
359
+ }
360
+
361
+ /**
362
+ * Log file directory
363
+ *
364
+ * @since 1.1.0
365
+ * @param string $dir_name Directory Name.
366
+ * @return array Uploads directory array.
367
+ */
368
+ public static function log_dir( $dir_name = 'astra-sites' ) {
369
+
370
+ $upload_dir = wp_upload_dir();
371
+
372
+ // Build the paths.
373
+ $dir_info = array(
374
+ 'path' => $upload_dir['basedir'] . '/' . $dir_name . '/',
375
+ 'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/',
376
+ );
377
+
378
+ // Create the upload dir if it doesn't exist.
379
+ if ( ! file_exists( $dir_info['path'] ) ) {
380
+
381
+ // Create the directory.
382
+ wp_mkdir_p( $dir_info['path'] );
383
+
384
+ // Add an index file for security.
385
+ self::get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' );
386
+ }
387
+
388
+ return $dir_info;
389
+ }
390
+
391
+ /**
392
+ * Set log file
393
+ *
394
+ * @since 1.1.0
395
+ */
396
+ public static function set_log_file() {
397
+
398
+ $upload_dir = self::log_dir();
399
+
400
+ $upload_path = trailingslashit( $upload_dir['path'] );
401
+
402
+ // File format e.g. 'import-31-Oct-2017-06-39-12.txt'.
403
+ self::$log_file = $upload_path . 'import-' . date( 'd-M-Y-h-i-s' ) . '.txt';
404
+
405
+ if ( ! get_option( 'astra_sites_recent_import_log_file', false ) ) {
406
+ update_option( 'astra_sites_recent_import_log_file', self::$log_file );
407
+ }
408
+ }
409
+
410
+ /**
411
+ * Write content to a file.
412
+ *
413
+ * @since 1.1.0
414
+ * @param string $content content to be saved to the file.
415
+ */
416
+ public static function add( $content ) {
417
+
418
+ if ( get_option( 'astra_sites_recent_import_log_file', false ) ) {
419
+ $log_file = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
420
+ } else {
421
+ $log_file = self::$log_file;
422
+ }
423
+
424
+ $existing_data = '';
425
+ if ( file_exists( $log_file ) ) {
426
+ $existing_data = self::get_filesystem()->get_contents( $log_file );
427
+ }
428
+
429
+ // Style separator.
430
+ $separator = PHP_EOL;
431
+
432
+ self::get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE );
433
+ }
434
+
435
+ /**
436
+ * Debug Mode
437
+ *
438
+ * @since 1.1.0
439
+ * @return string Enabled for Debug mode ON and Disabled for Debug mode Off.
440
+ */
441
+ public static function get_debug_mode() {
442
+ if ( WP_DEBUG ) {
443
+ return __( 'Enabled', 'astra-sites' );
444
+ }
445
+
446
+ return __( 'Disabled', 'astra-sites' );
447
+ }
448
+
449
+ /**
450
+ * Memory Limit
451
+ *
452
+ * @since 1.1.0
453
+ * @return string Memory limit.
454
+ */
455
+ public static function get_memory_limit() {
456
+
457
+ $required_memory = '64M';
458
+ $memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
459
+ $memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory );
460
+
461
+ if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) {
462
+ return sprintf(
463
+ /* translators: %1$s Memory Limit, %2$s Recommended memory limit. */
464
+ _x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ),
465
+ WP_MEMORY_LIMIT,
466
+ $required_memory
467
+ );
468
+ }
469
+
470
+ return WP_MEMORY_LIMIT;
471
+ }
472
+
473
+ /**
474
+ * Timezone
475
+ *
476
+ * @since 1.1.0
477
+ * @see https://codex.wordpress.org/Option_Reference/
478
+ *
479
+ * @return string Current timezone.
480
+ */
481
+ public static function get_timezone() {
482
+ $timezone = get_option( 'timezone_string' );
483
+
484
+ if ( ! $timezone ) {
485
+ return get_option( 'gmt_offset' );
486
+ }
487
+
488
+ return $timezone;
489
+ }
490
+
491
+ /**
492
+ * Operating System
493
+ *
494
+ * @since 1.1.0
495
+ * @return string Current Operating System.
496
+ */
497
+ public static function get_os() {
498
+ return PHP_OS;
499
+ }
500
+
501
+ /**
502
+ * Server Software
503
+ *
504
+ * @since 1.1.0
505
+ * @return string Current Server Software.
506
+ */
507
+ public static function get_software() {
508
+ return $_SERVER['SERVER_SOFTWARE'];
509
+ }
510
+
511
+ /**
512
+ * MySql Version
513
+ *
514
+ * @since 1.1.0
515
+ * @return string Current MySql Version.
516
+ */
517
+ public static function get_mysql_version() {
518
+ global $wpdb;
519
+ return $wpdb->db_version();
520
+ }
521
+
522
+ /**
523
+ * XML Reader
524
+ *
525
+ * @since 1.2.8
526
+ * @return string Current XML Reader status.
527
+ */
528
+ public static function get_xmlreader_status() {
529
+
530
+ if ( class_exists( 'XMLReader' ) ) {
531
+ return __( 'Yes', 'astra-sites' );
532
+ }
533
+
534
+ return __( 'No', 'astra-sites' );
535
+ }
536
+
537
+ /**
538
+ * PHP Version
539
+ *
540
+ * @since 1.1.0
541
+ * @return string Current PHP Version.
542
+ */
543
+ public static function get_php_version() {
544
+ if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
545
+ return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' );
546
+ }
547
+ return PHP_VERSION;
548
+ }
549
+
550
+ /**
551
+ * PHP Max Input Vars
552
+ *
553
+ * @since 1.1.0
554
+ * @return string Current PHP Max Input Vars
555
+ */
556
+ public static function get_php_max_input_vars() {
557
+ return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
558
+ }
559
+
560
+ /**
561
+ * PHP Max Post Size
562
+ *
563
+ * @since 1.1.0
564
+ * @return string Current PHP Max Post Size
565
+ */
566
+ public static function get_php_max_post_size() {
567
+ return ini_get( 'post_max_size' );
568
+ }
569
+
570
+ /**
571
+ * PHP Max Execution Time
572
+ *
573
+ * @since 1.1.0
574
+ * @return string Current Max Execution Time
575
+ */
576
+ public static function get_max_execution_time() {
577
+ return ini_get( 'max_execution_time' );
578
+ }
579
+
580
+ /**
581
+ * PHP GD Extension
582
+ *
583
+ * @since 1.1.0
584
+ * @return string Current PHP GD Extension
585
+ */
586
+ public static function get_php_extension_gd() {
587
+ if ( extension_loaded( 'gd' ) ) {
588
+ return __( 'Yes', 'astra-sites' );
589
+ }
590
+
591
+ return __( 'No', 'astra-sites' );
592
+ }
593
+
594
+ }
595
+
596
+ /**
597
+ * Kicking this off by calling 'get_instance()' method
598
+ */
599
+ Astra_Sites_Importer_Log::get_instance();
600
+
601
+ endif;
inc/classes/class-astra-sites-importer.php CHANGED
@@ -1,407 +1,573 @@
1
- <?php
2
- /**
3
- * Astra Sites Importer
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
12
-
13
- /**
14
- * Astra Sites Importer
15
- */
16
- class Astra_Sites_Importer {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.0
22
- * @var (Object) Class object
23
- */
24
- public static $_instance = null;
25
-
26
- /**
27
- * Set Instance
28
- *
29
- * @since 1.0.0
30
- *
31
- * @return object Class object.
32
- */
33
- public static function get_instance() {
34
- if ( ! isset( self::$_instance ) ) {
35
- self::$_instance = new self;
36
- }
37
-
38
- return self::$_instance;
39
- }
40
-
41
- /**
42
- * Constructor.
43
- *
44
- * @since 1.0.0
45
- */
46
- public function __construct() {
47
-
48
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
49
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
50
- require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
51
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
52
- require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
53
-
54
- // Import AJAX.
55
- add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
56
- add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
57
- add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
58
- add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
59
- add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
60
- add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
61
- add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
62
-
63
- // Hooks in AJAX.
64
- add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
65
- add_action( 'init', array( $this, 'load_importer' ) );
66
-
67
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
68
-
69
- add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
70
- }
71
-
72
- /**
73
- * Load WordPress WXR importer.
74
- */
75
- public function load_importer() {
76
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
77
- }
78
-
79
- /**
80
- * Start Site Import
81
- *
82
- * @since 1.1.0
83
- * @return void
84
- */
85
- function import_start() {
86
-
87
- if ( ! current_user_can( 'customize' ) ) {
88
- wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
89
- }
90
-
91
- $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
92
-
93
- if ( ! empty( $demo_api_uri ) ) {
94
-
95
- $demo_data = self::get_astra_single_demo( $demo_api_uri );
96
-
97
- update_option( 'astra_sites_import_data', $demo_data );
98
-
99
- if ( is_wp_error( $demo_data ) ) {
100
- wp_send_json_error( $demo_data->get_error_message() );
101
- } else {
102
- $log_file = Astra_Sites_Importer_Log::add_log_file_url();
103
- if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
104
- $demo_data['log_file'] = $log_file['url'];
105
- }
106
- do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
107
- }
108
-
109
- wp_send_json_success( $demo_data );
110
-
111
- } else {
112
- wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
113
- }
114
-
115
- }
116
-
117
- /**
118
- * Import WP Forms
119
- *
120
- * @since 1.2.14
121
- *
122
- * @return void
123
- */
124
- function import_wpforms() {
125
-
126
- $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
127
- $ids_mapping = array();
128
-
129
- if ( ! empty( $wpforms_url ) ) {
130
-
131
- // Download XML file.
132
- $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
133
-
134
- if ( $xml_path['success'] ) {
135
- if ( isset( $xml_path['data']['file'] ) ) {
136
-
137
- $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
138
-
139
- if ( 'json' === $ext ) {
140
- $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
141
-
142
- if ( ! empty( $forms ) ) {
143
-
144
- foreach ( $forms as $form ) {
145
- $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
146
- $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
147
-
148
- $new_id = post_exists( $title );
149
-
150
- if ( ! $new_id ) {
151
- $new_id = wp_insert_post(
152
- array(
153
- 'post_title' => $title,
154
- 'post_status' => 'publish',
155
- 'post_type' => 'wpforms',
156
- 'post_excerpt' => $desc,
157
- )
158
- );
159
- }
160
-
161
- if ( $new_id ) {
162
-
163
- // ID mapping.
164
- $ids_mapping[ $form['id'] ] = $new_id;
165
-
166
- $form['id'] = $new_id;
167
- wp_update_post(
168
- array(
169
- 'ID' => $new_id,
170
- 'post_content' => wpforms_encode( $form ),
171
- )
172
- );
173
- }
174
- }
175
- }
176
- }
177
- }
178
- }
179
- }
180
-
181
- update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
182
-
183
- wp_send_json_success( $ids_mapping );
184
- }
185
-
186
- /**
187
- * Import Customizer Settings.
188
- *
189
- * @since 1.0.14
190
- * @return void
191
- */
192
- function import_customizer_settings() {
193
-
194
- do_action( 'astra_sites_import_customizer_settings' );
195
-
196
- $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : '';
197
-
198
- if ( isset( $customizer_data ) ) {
199
-
200
- Astra_Customizer_Import::instance()->import( $customizer_data );
201
- wp_send_json_success( $customizer_data );
202
-
203
- } else {
204
- wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
205
- }
206
-
207
- }
208
-
209
- /**
210
- * Prepare XML Data.
211
- *
212
- * @since 1.1.0
213
- * @return void
214
- */
215
- function prepare_xml_data() {
216
-
217
- do_action( 'astra_sites_import_prepare_xml_data' );
218
-
219
- if ( ! class_exists( 'XMLReader' ) ) {
220
- wp_send_json_error( __( 'If XMLReader is not available, it imports all other settings and only skips XML import. This creates an incomplete website. We should bail early and not import anything if this is not present.', 'astra-sites' ) );
221
- }
222
-
223
- $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
224
-
225
- if ( isset( $wxr_url ) ) {
226
-
227
- // Download XML file.
228
- $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
229
-
230
- if ( $xml_path['success'] ) {
231
- if ( isset( $xml_path['data']['file'] ) ) {
232
- $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
233
- $data['xml'] = $xml_path['data'];
234
- wp_send_json_success( $data );
235
- } else {
236
- wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
237
- }
238
- } else {
239
- wp_send_json_error( $xml_path['data'] );
240
- }
241
- } else {
242
- wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
243
- }
244
-
245
- }
246
-
247
- /**
248
- * Import Options.
249
- *
250
- * @since 1.0.14
251
- * @return void
252
- */
253
- function import_options() {
254
-
255
- do_action( 'astra_sites_import_options' );
256
-
257
- $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
258
-
259
- if ( isset( $options_data ) ) {
260
- $options_importer = Astra_Site_Options_Import::instance();
261
- $options_importer->import_options( $options_data );
262
- wp_send_json_success( $options_data );
263
- } else {
264
- wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
265
- }
266
-
267
- }
268
-
269
- /**
270
- * Import Widgets.
271
- *
272
- * @since 1.0.14
273
- * @return void
274
- */
275
- function import_widgets() {
276
-
277
- do_action( 'astra_sites_import_widgets' );
278
-
279
- $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
280
-
281
- if ( isset( $widgets_data ) ) {
282
- $widgets_importer = Astra_Widget_Importer::instance();
283
- $status = $widgets_importer->import_widgets_data( $widgets_data );
284
- wp_send_json_success( $widgets_data );
285
- } else {
286
- wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
287
- }
288
-
289
- }
290
-
291
- /**
292
- * Import End.
293
- *
294
- * @since 1.0.14
295
- * @return void
296
- */
297
- function import_end() {
298
- do_action( 'astra_sites_import_complete' );
299
- }
300
-
301
-
302
- /**
303
- * Get single demo.
304
- *
305
- * @since 1.0.0
306
- *
307
- * @param (String) $demo_api_uri API URL of a demo.
308
- *
309
- * @return (Array) $astra_demo_data demo data for the demo.
310
- */
311
- public static function get_astra_single_demo( $demo_api_uri ) {
312
-
313
- // default values.
314
- $remote_args = array();
315
- $defaults = array(
316
- 'id' => '',
317
- 'astra-site-widgets-data' => '',
318
- 'astra-site-customizer-data' => '',
319
- 'astra-site-options-data' => '',
320
- 'astra-post-data-mapping' => '',
321
- 'astra-site-wxr-path' => '',
322
- 'astra-site-wpforms-path' => '',
323
- 'astra-enabled-extensions' => '',
324
- 'astra-custom-404' => '',
325
- 'required-plugins' => '',
326
- );
327
-
328
- $api_args = apply_filters(
329
- 'astra_sites_api_args',
330
- array(
331
- 'timeout' => 15,
332
- )
333
- );
334
-
335
- // Use this for premium demos.
336
- $request_params = apply_filters(
337
- 'astra_sites_api_params',
338
- array(
339
- 'purchase_key' => '',
340
- 'site_url' => '',
341
- )
342
- );
343
-
344
- $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
345
-
346
- // API Call.
347
- $response = wp_remote_get( $demo_api_uri, $api_args );
348
-
349
- if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 == $response->status ) ) {
350
- if ( isset( $response->status ) ) {
351
- $data = json_decode( $response, true );
352
- } else {
353
- return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
354
- }
355
- } else {
356
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
357
- }
358
-
359
- $data = json_decode( wp_remote_retrieve_body( $response ), true );
360
-
361
- if ( ! isset( $data['code'] ) ) {
362
- $remote_args['id'] = $data['id'];
363
- $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
364
- $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
365
- $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
366
- $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
367
- $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
368
- $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
369
- $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
370
- $remote_args['astra-custom-404'] = $data['astra-custom-404'];
371
- $remote_args['required-plugins'] = $data['required-plugins'];
372
- }
373
-
374
- // Merge remote demo and defaults.
375
- return wp_parse_args( $remote_args, $defaults );
376
- }
377
-
378
- /**
379
- * Clear Cache.
380
- *
381
- * @since 1.0.9
382
- */
383
- public function clear_cache() {
384
- // Clear 'Elementor' file cache.
385
- if ( class_exists( '\Elementor\Plugin' ) ) {
386
- Elementor\Plugin::$instance->posts_css_manager->clear_cache();
387
- }
388
-
389
- // Clear 'Builder Builder' cache.
390
- if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
391
- FLBuilderModel::delete_asset_cache_for_all_posts();
392
- }
393
-
394
- // Clear 'Astra Addon' cache.
395
- if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
396
- Astra_Minify::refresh_assets();
397
- }
398
- }
399
-
400
- }
401
-
402
- /**
403
- * Kicking this off by calling 'get_instance()' method
404
- */
405
- Astra_Sites_Importer::get_instance();
406
-
407
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Astra Sites Importer
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Importer' ) ) :
12
+
13
+ /**
14
+ * Astra Sites Importer
15
+ */
16
+ class Astra_Sites_Importer {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Class object
23
+ */
24
+ public static $_instance = null;
25
+
26
+ /**
27
+ * Set Instance
28
+ *
29
+ * @since 1.0.0
30
+ *
31
+ * @return object Class object.
32
+ */
33
+ public static function get_instance() {
34
+ if ( ! isset( self::$_instance ) ) {
35
+ self::$_instance = new self;
36
+ }
37
+
38
+ return self::$_instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor.
43
+ *
44
+ * @since 1.0.0
45
+ */
46
+ public function __construct() {
47
+
48
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
49
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
50
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-widgets-importer.php';
51
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
52
+ require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
53
+
54
+ // Import AJAX.
55
+ add_action( 'wp_ajax_astra-sites-import-set-site-data', array( $this, 'import_start' ) );
56
+ add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
57
+ add_action( 'wp_ajax_astra-sites-import-customizer-settings', array( $this, 'import_customizer_settings' ) );
58
+ add_action( 'wp_ajax_astra-sites-import-prepare-xml', array( $this, 'prepare_xml_data' ) );
59
+ add_action( 'wp_ajax_astra-sites-import-options', array( $this, 'import_options' ) );
60
+ add_action( 'wp_ajax_astra-sites-import-widgets', array( $this, 'import_widgets' ) );
61
+ add_action( 'wp_ajax_astra-sites-import-end', array( $this, 'import_end' ) );
62
+
63
+ // Hooks in AJAX.
64
+ add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
65
+ add_action( 'init', array( $this, 'load_importer' ) );
66
+
67
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
68
+
69
+ add_action( 'astra_sites_image_import_complete', array( $this, 'clear_cache' ) );
70
+
71
+ // Reset Customizer Data.
72
+ add_action( 'wp_ajax_astra-sites-reset-customizer-data', array( $this, 'reset_customizer_data' ) );
73
+ add_action( 'wp_ajax_astra-sites-reset-site-options', array( $this, 'reset_site_options' ) );
74
+ add_action( 'wp_ajax_astra-sites-reset-widgets-data', array( $this, 'reset_widgets_data' ) );
75
+
76
+ // Reset Post & Terms.
77
+ add_action( 'wp_ajax_astra-sites-delete-posts', array( $this, 'delete_imported_posts' ) );
78
+ add_action( 'wp_ajax_astra-sites-delete-wp-forms', array( $this, 'delete_imported_wp_forms' ) );
79
+ add_action( 'wp_ajax_astra-sites-delete-terms', array( $this, 'delete_imported_terms' ) );
80
+ }
81
+
82
+ /**
83
+ * Load WordPress WXR importer.
84
+ */
85
+ public function load_importer() {
86
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-astra-wxr-importer.php';
87
+ }
88
+
89
+ /**
90
+ * Start Site Import
91
+ *
92
+ * @since 1.1.0
93
+ * @return void
94
+ */
95
+ function import_start() {
96
+
97
+ if ( ! current_user_can( 'customize' ) ) {
98
+ wp_send_json_error( __( 'You have not "customize" access to import the Astra site.', 'astra-sites' ) );
99
+ }
100
+
101
+ $demo_api_uri = isset( $_POST['api_url'] ) ? esc_url( $_POST['api_url'] ) : '';
102
+
103
+ if ( ! empty( $demo_api_uri ) ) {
104
+
105
+ $demo_data = self::get_astra_single_demo( $demo_api_uri );
106
+
107
+ update_option( 'astra_sites_import_data', $demo_data );
108
+
109
+ if ( is_wp_error( $demo_data ) ) {
110
+ wp_send_json_error( $demo_data->get_error_message() );
111
+ } else {
112
+ $log_file = Astra_Sites_Importer_Log::add_log_file_url();
113
+ if ( isset( $log_file['url'] ) && ! empty( $log_file['url'] ) ) {
114
+ $demo_data['log_file'] = $log_file['url'];
115
+ }
116
+ do_action( 'astra_sites_import_start', $demo_data, $demo_api_uri );
117
+ }
118
+
119
+ wp_send_json_success( $demo_data );
120
+
121
+ } else {
122
+ wp_send_json_error( __( 'Request site API URL is empty. Try again!', 'astra-sites' ) );
123
+ }
124
+
125
+ }
126
+
127
+ /**
128
+ * Import WP Forms
129
+ *
130
+ * @since 1.2.14
131
+ *
132
+ * @return void
133
+ */
134
+ function import_wpforms() {
135
+
136
+ $wpforms_url = ( isset( $_REQUEST['wpforms_url'] ) ) ? urldecode( $_REQUEST['wpforms_url'] ) : '';
137
+ $ids_mapping = array();
138
+
139
+ if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
140
+
141
+ // Download XML file.
142
+ $xml_path = Astra_Sites_Helper::download_file( $wpforms_url );
143
+
144
+ if ( $xml_path['success'] ) {
145
+ if ( isset( $xml_path['data']['file'] ) ) {
146
+
147
+ $ext = strtolower( pathinfo( $xml_path['data']['file'], PATHINFO_EXTENSION ) );
148
+
149
+ if ( 'json' === $ext ) {
150
+ $forms = json_decode( file_get_contents( $xml_path['data']['file'] ), true );
151
+
152
+ if ( ! empty( $forms ) ) {
153
+
154
+ foreach ( $forms as $form ) {
155
+ $title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
156
+ $desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
157
+
158
+ $new_id = post_exists( $title );
159
+
160
+ if ( ! $new_id ) {
161
+ $new_id = wp_insert_post(
162
+ array(
163
+ 'post_title' => $title,
164
+ 'post_status' => 'publish',
165
+ 'post_type' => 'wpforms',
166
+ 'post_excerpt' => $desc,
167
+ )
168
+ );
169
+
170
+ // Set meta for tracking the post.
171
+ update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
172
+ Astra_Sites_Image_Importer::log( '==== INSERTED - WP Form ' . $new_id );
173
+ }
174
+
175
+ if ( $new_id ) {
176
+
177
+ // ID mapping.
178
+ $ids_mapping[ $form['id'] ] = $new_id;
179
+
180
+ $form['id'] = $new_id;
181
+ wp_update_post(
182
+ array(
183
+ 'ID' => $new_id,
184
+ 'post_content' => wpforms_encode( $form ),
185
+ )
186
+ );
187
+ }
188
+ }
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+ update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping );
196
+
197
+ wp_send_json_success( $ids_mapping );
198
+ }
199
+
200
+ /**
201
+ * Import Customizer Settings.
202
+ *
203
+ * @since 1.0.14
204
+ * @return void
205
+ */
206
+ function import_customizer_settings() {
207
+
208
+ $customizer_data = ( isset( $_POST['customizer_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['customizer_data'] ), 1 ) : '';
209
+
210
+ do_action( 'astra_sites_import_customizer_settings', $customizer_data );
211
+
212
+ if ( ! empty( $customizer_data ) ) {
213
+
214
+ // Set meta for tracking the post.
215
+ Astra_Sites_Image_Importer::log( 'Customizer Data ' . stripslashes( $customizer_data ) );
216
+ update_option( '_astra_sites_old_customizer_data', $customizer_data );
217
+
218
+ Astra_Customizer_Import::instance()->import( $customizer_data );
219
+
220
+ wp_send_json_success( $customizer_data );
221
+
222
+ } else {
223
+ wp_send_json_error( __( 'Customizer data is empty!', 'astra-sites' ) );
224
+ }
225
+
226
+ }
227
+
228
+ /**
229
+ * Prepare XML Data.
230
+ *
231
+ * @since 1.1.0
232
+ * @return void
233
+ */
234
+ function prepare_xml_data() {
235
+
236
+ if ( ! class_exists( 'XMLReader' ) ) {
237
+ wp_send_json_error( __( 'If XMLReader is not available, it imports all other settings and only skips XML import. This creates an incomplete website. We should bail early and not import anything if this is not present.', 'astra-sites' ) );
238
+ }
239
+
240
+ $wxr_url = ( isset( $_REQUEST['wxr_url'] ) ) ? urldecode( $_REQUEST['wxr_url'] ) : '';
241
+
242
+ do_action( 'astra_sites_import_prepare_xml_data', $wxr_url );
243
+
244
+ if ( isset( $wxr_url ) ) {
245
+
246
+ // Download XML file.
247
+ $xml_path = Astra_Sites_Helper::download_file( $wxr_url );
248
+
249
+ if ( $xml_path['success'] ) {
250
+ if ( isset( $xml_path['data']['file'] ) ) {
251
+ $data = Astra_WXR_Importer::instance()->get_xml_data( $xml_path['data']['file'] );
252
+ $data['xml'] = $xml_path['data'];
253
+ wp_send_json_success( $data );
254
+ } else {
255
+ wp_send_json_error( __( 'There was an error downloading the XML file.', 'astra-sites' ) );
256
+ }
257
+ } else {
258
+ wp_send_json_error( $xml_path['data'] );
259
+ }
260
+ } else {
261
+ wp_send_json_error( __( 'Invalid site XML file!', 'astra-sites' ) );
262
+ }
263
+
264
+ }
265
+
266
+ /**
267
+ * Import Options.
268
+ *
269
+ * @since 1.0.14
270
+ * @return void
271
+ */
272
+ function import_options() {
273
+
274
+ $options_data = ( isset( $_POST['options_data'] ) ) ? (array) json_decode( stripcslashes( $_POST['options_data'] ), 1 ) : '';
275
+
276
+ do_action( 'astra_sites_import_options', $options_data );
277
+
278
+ if ( ! empty( $options_data ) ) {
279
+
280
+ // Set meta for tracking the post.
281
+ if ( is_array( $options_data ) ) {
282
+ Astra_Sites_Image_Importer::log( 'Site Options Data ' . json_encode( $options_data ) );
283
+ update_option( '_astra_sites_old_site_options', $options_data );
284
+ }
285
+
286
+ $options_importer = Astra_Site_Options_Import::instance();
287
+ $options_importer->import_options( $options_data );
288
+ wp_send_json_success( $options_data );
289
+ } else {
290
+ wp_send_json_error( __( 'Site options are empty!', 'astra-sites' ) );
291
+ }
292
+
293
+ }
294
+
295
+ /**
296
+ * Import Widgets.
297
+ *
298
+ * @since 1.0.14
299
+ * @return void
300
+ */
301
+ function import_widgets() {
302
+
303
+ $widgets_data = ( isset( $_POST['widgets_data'] ) ) ? (object) json_decode( stripcslashes( $_POST['widgets_data'] ) ) : '';
304
+
305
+ do_action( 'astra_sites_import_widgets', $widgets_data );
306
+
307
+ if ( ! empty( $widgets_data ) ) {
308
+
309
+ $widgets_importer = Astra_Widget_Importer::instance();
310
+ $status = $widgets_importer->import_widgets_data( $widgets_data );
311
+
312
+ // Set meta for tracking the post.
313
+ if ( is_object( $widgets_data ) ) {
314
+ $widgets_data = (array) $widgets_data;
315
+ Astra_Sites_Image_Importer::log( 'Widget Data ' . json_encode( $widgets_data ) );
316
+ update_option( '_astra_sites_old_widgets_data', $widgets_data );
317
+ }
318
+
319
+ wp_send_json_success( $widgets_data );
320
+ } else {
321
+ wp_send_json_error( __( 'Widget data is empty!', 'astra-sites' ) );
322
+ }
323
+
324
+ }
325
+
326
+ /**
327
+ * Import End.
328
+ *
329
+ * @since 1.0.14
330
+ * @return void
331
+ */
332
+ function import_end() {
333
+ do_action( 'astra_sites_import_complete' );
334
+ }
335
+
336
+
337
+ /**
338
+ * Get single demo.
339
+ *
340
+ * @since 1.0.0
341
+ *
342
+ * @param (String) $demo_api_uri API URL of a demo.
343
+ *
344
+ * @return (Array) $astra_demo_data demo data for the demo.
345
+ */
346
+ public static function get_astra_single_demo( $demo_api_uri ) {
347
+
348
+ // default values.
349
+ $remote_args = array();
350
+ $defaults = array(
351
+ 'id' => '',
352
+ 'astra-site-widgets-data' => '',
353
+ 'astra-site-customizer-data' => '',
354
+ 'astra-site-options-data' => '',
355
+ 'astra-post-data-mapping' => '',
356
+ 'astra-site-wxr-path' => '',
357
+ 'astra-site-wpforms-path' => '',
358
+ 'astra-enabled-extensions' => '',
359
+ 'astra-custom-404' => '',
360
+ 'required-plugins' => '',
361
+ );
362
+
363
+ $api_args = apply_filters(
364
+ 'astra_sites_api_args',
365
+ array(
366
+ 'timeout' => 15,
367
+ )
368
+ );
369
+
370
+ // Use this for premium demos.
371
+ $request_params = apply_filters(
372
+ 'astra_sites_api_params',
373
+ array(
374
+ 'purchase_key' => '',
375
+ 'site_url' => '',
376
+ )
377
+ );
378
+
379
+ $demo_api_uri = add_query_arg( $request_params, $demo_api_uri );
380
+
381
+ // API Call.
382
+ $response = wp_remote_get( $demo_api_uri, $api_args );
383
+
384
+ if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 == $response->status ) ) {
385
+ if ( isset( $response->status ) ) {
386
+ $data = json_decode( $response, true );
387
+ } else {
388
+ return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
389
+ }
390
+ } else {
391
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
392
+ }
393
+
394
+ $data = json_decode( wp_remote_retrieve_body( $response ), true );
395
+
396
+ if ( ! isset( $data['code'] ) ) {
397
+ $remote_args['id'] = $data['id'];
398
+ $remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
399
+ $remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
400
+ $remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
401
+ $remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
402
+ $remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
403
+ $remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
404
+ $remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
405
+ $remote_args['astra-custom-404'] = $data['astra-custom-404'];
406
+ $remote_args['required-plugins'] = $data['required-plugins'];
407
+ }
408
+
409
+ // Merge remote demo and defaults.
410
+ return wp_parse_args( $remote_args, $defaults );
411
+ }
412
+
413
+ /**
414
+ * Clear Cache.
415
+ *
416
+ * @since 1.0.9
417
+ */
418
+ public function clear_cache() {
419
+ // Clear 'Elementor' file cache.
420
+ if ( class_exists( '\Elementor\Plugin' ) ) {
421
+ Elementor\Plugin::$instance->posts_css_manager->clear_cache();
422
+ }
423
+
424
+ // Clear 'Builder Builder' cache.
425
+ if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
426
+ FLBuilderModel::delete_asset_cache_for_all_posts();
427
+ }
428
+
429
+ // Clear 'Astra Addon' cache.
430
+ if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
431
+ Astra_Minify::refresh_assets();
432
+ }
433
+
434
+ }
435
+
436
+ /**
437
+ * Reset customizer data
438
+ *
439
+ * @since 1.3.0
440
+ * @return void
441
+ */
442
+ function reset_customizer_data() {
443
+ do_action( 'astra_sites_reset_customizer_data', get_option( 'astra-settings', array() ) );
444
+
445
+ delete_option( 'astra-settings' );
446
+
447
+ wp_send_json_success();
448
+ }
449
+
450
+ /**
451
+ * Reset site options
452
+ *
453
+ * @since 1.3.0
454
+ * @return void
455
+ */
456
+ function reset_site_options() {
457
+
458
+ $options = get_option( '_astra_sites_old_site_options', array() );
459
+
460
+ do_action( 'astra_sites_reset_site_options', $options );
461
+
462
+ if ( $options ) {
463
+ foreach ( $options as $option_key => $option_value ) {
464
+ delete_option( $option_key );
465
+ }
466
+ }
467
+
468
+ wp_send_json_success();
469
+ }
470
+
471
+ /**
472
+ * Reset widgets data
473
+ *
474
+ * @since 1.3.0
475
+ * @return void
476
+ */
477
+ function reset_widgets_data() {
478
+ $old_widgets = get_option( '_astra_sites_old_widgets_data', array() );
479
+
480
+ do_action( 'astra_sites_reset_widgets_data', $old_widgets );
481
+
482
+ if ( $old_widgets ) {
483
+ $sidebars_widgets = get_option( 'sidebars_widgets', array() );
484
+
485
+ foreach ( $old_widgets as $sidebar_id => $widgets ) {
486
+
487
+ if ( $widgets ) {
488
+ foreach ( $widgets as $widget_key => $widget_data ) {
489
+
490
+ if ( isset( $sidebars_widgets['wp_inactive_widgets'] ) ) {
491
+ if ( ! in_array( $widget_key, $sidebars_widgets['wp_inactive_widgets'] ) ) {
492
+ Astra_Sites_Image_Importer::log( '==== IN ACTIVATE - Widget ' . $widget_key );
493
+ $sidebars_widgets['wp_inactive_widgets'][] = $widget_key;
494
+ }
495
+ }
496
+ }
497
+ }
498
+ }
499
+
500
+ update_option( 'sidebars_widgets', $sidebars_widgets );
501
+ }
502
+
503
+ wp_send_json_success();
504
+ }
505
+
506
+ /**
507
+ * Delete imported posts
508
+ *
509
+ * @since 1.3.0
510
+ * @return void
511
+ */
512
+ function delete_imported_posts() {
513
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
514
+
515
+ do_action( 'astra_sites_delete_imported_posts', $post_id );
516
+
517
+ if ( $post_id ) {
518
+ wp_delete_post( $post_id, true );
519
+ }
520
+
521
+ /* translators: %s is the post ID */
522
+ wp_send_json_success( sprintf( __( 'Post ID %s deleted!', 'astra-sites' ), $post_id ) );
523
+ }
524
+
525
+ /**
526
+ * Delete imported WP forms
527
+ *
528
+ * @since 1.3.0
529
+ * @return void
530
+ */
531
+ function delete_imported_wp_forms() {
532
+ $post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : '';
533
+
534
+ do_action( 'astra_sites_delete_imported_wp_forms', $post_id );
535
+
536
+ if ( $post_id ) {
537
+ wp_delete_post( $post_id, true );
538
+ }
539
+
540
+ /* translators: %s is the form ID */
541
+ wp_send_json_success( sprintf( __( 'Form ID %s deleted!', 'astra-sites' ), $post_id ) );
542
+ }
543
+
544
+ /**
545
+ * Delete imported terms
546
+ *
547
+ * @since 1.3.0
548
+ * @return void
549
+ */
550
+ function delete_imported_terms() {
551
+
552
+ $term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : '';
553
+
554
+ if ( $term_id ) {
555
+ $term = get_term( $term_id );
556
+ if ( $term ) {
557
+ do_action( 'astra_sites_delete_imported_terms', $term_id, $term );
558
+ wp_delete_term( $term_id, $term->taxonomy );
559
+ }
560
+ }
561
+
562
+ /* translators: %s is the term ID */
563
+ wp_send_json_success( sprintf( __( 'Term ID %s deleted!', 'astra-sites' ), $term_id ) );
564
+ }
565
+
566
+ }
567
+
568
+ /**
569
+ * Kicking this off by calling 'get_instance()' method
570
+ */
571
+ Astra_Sites_Importer::get_instance();
572
+
573
+ endif;
inc/classes/class-astra-sites-page.php CHANGED
@@ -1,294 +1,360 @@
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
- add_action( 'admin_notices', __CLASS__ . '::notices' );
97
- }
98
-
99
- /**
100
- * Admin notice
101
- *
102
- * @since 1.2.8
103
- */
104
- public static function notices() {
105
-
106
- if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
107
- return;
108
- }
109
-
110
- if ( ! class_exists( 'XMLReader' ) ) {
111
- ?>
112
- <div class="notice astra-sites-xml-notice notice-error">
113
- <p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
114
- <?php /* translators: %s is the white label name. */ ?>
115
- <p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), self::$menu_page_title ); ?></p>
116
- </div>
117
- <?php
118
- }
119
- }
120
-
121
- /**
122
- * Save All admin settings here
123
- */
124
- static public function save_settings() {
125
-
126
- // Only admins can save settings.
127
- if ( ! current_user_can( 'manage_options' ) ) {
128
- return;
129
- }
130
-
131
- // Let extensions hook into saving.
132
- do_action( 'astra_sites_save_settings' );
133
- }
134
-
135
- /**
136
- * Init Nav Menu
137
- *
138
- * @param mixed $action Action name.
139
- * @since 1.0.6
140
- */
141
- static public function init_nav_menu( $action = '' ) {
142
-
143
- if ( '' !== $action ) {
144
- self::render_tab_menu( $action );
145
- }
146
- }
147
-
148
- /**
149
- * Render tab menu
150
- *
151
- * @param mixed $action Action name.
152
- * @since 1.0.6
153
- */
154
- static public function render_tab_menu( $action = '' ) {
155
- ?>
156
- <div id="astra-sites-menu-page">
157
- <?php self::render( $action ); ?>
158
- </div>
159
- <?php
160
- }
161
-
162
- /**
163
- * View actions
164
- *
165
- * @since 1.0.11
166
- */
167
- static public function get_view_actions() {
168
-
169
- if ( empty( self::$view_actions ) ) {
170
-
171
- self::$view_actions = apply_filters(
172
- 'astra_sites_menu_item',
173
- array()
174
- );
175
- }
176
-
177
- return self::$view_actions;
178
- }
179
-
180
- /**
181
- * Prints HTML content for tabs
182
- *
183
- * @param mixed $action Action name.
184
- * @since 1.0.6
185
- */
186
- static public function render( $action ) {
187
-
188
- ?>
189
- <div class="nav-tab-wrapper">
190
- <h1 class='astra-sites-title'> <?php echo esc_html( self::$menu_page_title ); ?> </h1>
191
- <?php
192
- $view_actions = self::get_view_actions();
193
-
194
- foreach ( $view_actions as $slug => $data ) {
195
-
196
- if ( ! $data['show'] ) {
197
- continue;
198
- }
199
-
200
- $url = self::get_page_url( $slug );
201
-
202
- if ( $slug == self::$parent_page_slug ) {
203
- update_option( 'astra_parent_page_url', $url );
204
- }
205
-
206
- $active = ( $slug == $action ) ? 'nav-tab-active' : '';
207
- ?>
208
- <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
209
- <?php } ?>
210
- </div><!-- .nav-tab-wrapper -->
211
-
212
- <?php
213
- // Settings update message.
214
- if ( isset( $_REQUEST['message'] ) && ( 'saved' == $_REQUEST['message'] || 'saved_ext' == $_REQUEST['message'] ) ) {
215
- ?>
216
- <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
217
- <?php
218
- }
219
-
220
- }
221
-
222
- /**
223
- * Get and return page URL
224
- *
225
- * @param string $menu_slug Menu name.
226
- * @since 1.0.6
227
- * @return string page url
228
- */
229
- static public function get_page_url( $menu_slug ) {
230
-
231
- $parent_page = self::$default_menu_position;
232
-
233
- if ( strpos( $parent_page, '?' ) !== false ) {
234
- $query_var = '&page=' . self::$plugin_slug;
235
- } else {
236
- $query_var = '?page=' . self::$plugin_slug;
237
- }
238
-
239
- $parent_page_url = admin_url( $parent_page . $query_var );
240
-
241
- $url = $parent_page_url . '&action=' . $menu_slug;
242
-
243
- return esc_url( $url );
244
- }
245
-
246
- /**
247
- * Add main menu
248
- *
249
- * @since 1.0.6
250
- */
251
- static public function add_admin_menu() {
252
-
253
- $parent_page = self::$default_menu_position;
254
- $page_title = self::$menu_page_title;
255
- $capability = 'manage_options';
256
- $page_menu_slug = self::$plugin_slug;
257
- $page_menu_func = __CLASS__ . '::menu_callback';
258
-
259
- add_theme_page( $page_title, $page_title, $capability, $page_menu_slug, $page_menu_func );
260
- }
261
-
262
- /**
263
- * Menu callback
264
- *
265
- * @since 1.0.6
266
- */
267
- static public function menu_callback() {
268
-
269
- $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : self::$current_slug;
270
-
271
- $active_tab = str_replace( '_', '-', $current_slug );
272
- $current_slug = str_replace( '-', '_', $current_slug );
273
-
274
- ?>
275
- <div class="astra-sites-menu-page-wrapper">
276
- <?php self::init_nav_menu( $active_tab ); ?>
277
- <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
278
- </div>
279
- <?php
280
- }
281
-
282
- /**
283
- * Include general page
284
- *
285
- * @since 1.0.6
286
- */
287
- static public function general_page() {
288
- require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
289
- }
290
- }
291
-
292
- new Astra_Sites_Page;
293
-
294
- }// 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
+ public $view_actions = array();
27
+
28
+ /**
29
+ * Member Variable
30
+ *
31
+ * @var instance
32
+ */
33
+ private static $instance;
34
+
35
+ /**
36
+ * Initiator
37
+ *
38
+ * @since 1.3.0
39
+ */
40
+ public static function get_instance() {
41
+ if ( ! isset( self::$instance ) ) {
42
+ self::$instance = new self;
43
+ }
44
+ return self::$instance;
45
+ }
46
+
47
+ /**
48
+ * Constructor
49
+ *
50
+ * @since 1.3.0
51
+ */
52
+ public function __construct() {
53
+
54
+ if ( ! is_admin() ) {
55
+ return;
56
+ }
57
+
58
+ add_action( 'after_setup_theme', array( $this, 'init_admin_settings' ), 99 );
59
+ add_action( 'admin_init', array( $this, 'save_page_builder' ) );
60
+ }
61
+
62
+ /**
63
+ * Save Page Builder
64
+ *
65
+ * @return void
66
+ */
67
+ function save_page_builder() {
68
+
69
+ // Only admins can save settings.
70
+ if ( ! current_user_can( 'manage_options' ) ) {
71
+ return;
72
+ }
73
+
74
+ // Make sure we have a valid nonce.
75
+ if ( isset( $_REQUEST['astra-sites-page-builder'] ) && wp_verify_nonce( $_REQUEST['astra-sites-page-builder'], 'astra-sites-welcome-screen' ) ) {
76
+
77
+ // Stored Settings.
78
+ $stored_data = $this->get_settings();
79
+
80
+ // New settings.
81
+ $new_data = array(
82
+ 'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
83
+ );
84
+
85
+ // Merge settings.
86
+ $data = wp_parse_args( $new_data, $stored_data );
87
+
88
+ // Update settings.
89
+ update_option( 'astra_sites_settings', $data );
90
+
91
+ wp_redirect( admin_url( '/themes.php?page=astra-sites' ) );
92
+ }
93
+ }
94
+
95
+ /**
96
+ * Get single setting value
97
+ *
98
+ * @param string $key Setting key.
99
+ * @param mixed $defaults Setting value.
100
+ * @return mixed Stored setting value.
101
+ */
102
+ function get_setting( $key = '', $defaults = '' ) {
103
+
104
+ $settings = $this->get_settings();
105
+
106
+ if ( empty( $settings ) ) {
107
+ return $defaults;
108
+ }
109
+
110
+ if ( array_key_exists( $key, $settings ) ) {
111
+ return $settings[ $key ];
112
+ }
113
+
114
+ return $defaults;
115
+ }
116
+
117
+ /**
118
+ * Get Settings
119
+ *
120
+ * @return array Stored settings.
121
+ */
122
+ function get_settings() {
123
+
124
+ $defaults = array(
125
+ 'page_builder' => '',
126
+ );
127
+
128
+ $stored_data = get_option( 'astra_sites_settings', $defaults );
129
+
130
+ return wp_parse_args( $stored_data, $defaults );
131
+ }
132
+
133
+ /**
134
+ * Admin settings init
135
+ */
136
+ public function init_admin_settings() {
137
+ add_action( 'admin_menu', array( $this, 'add_admin_menu' ), 100 );
138
+ add_action( 'admin_notices', array( $this, 'notices' ) );
139
+ add_action( 'astra_sites_menu_general_action', array( $this, 'general_page' ) );
140
+ }
141
+
142
+ /**
143
+ * Admin notice
144
+ *
145
+ * @since 1.2.8
146
+ */
147
+ public function notices() {
148
+
149
+ if ( 'appearance_page_astra-sites' !== get_current_screen()->id ) {
150
+ return;
151
+ }
152
+
153
+ if ( ! class_exists( 'XMLReader' ) ) {
154
+ ?>
155
+ <div class="notice astra-sites-xml-notice notice-error">
156
+ <p><b><?php _e( 'Required XMLReader PHP extension is missing on your server!', 'astra-sites' ); ?></b></p>
157
+ <?php /* translators: %s is the white label name. */ ?>
158
+ <p><?php printf( __( '%s import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), ASTRA_SITES_NAME ); ?></p>
159
+ </div>
160
+ <?php
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Init Nav Menu
166
+ *
167
+ * @param mixed $action Action name.
168
+ * @since 1.0.6
169
+ */
170
+ public function init_nav_menu( $action = '' ) {
171
+
172
+ if ( '' !== $action ) {
173
+ $this->render_tab_menu( $action );
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Render tab menu
179
+ *
180
+ * @param mixed $action Action name.
181
+ * @since 1.0.6
182
+ */
183
+ public function render_tab_menu( $action = '' ) {
184
+ ?>
185
+ <div id="astra-sites-menu-page">
186
+ <?php $this->render( $action ); ?>
187
+ </div>
188
+ <?php
189
+ }
190
+
191
+ /**
192
+ * View actions
193
+ *
194
+ * @since 1.0.11
195
+ */
196
+ public function get_view_actions() {
197
+
198
+ if ( empty( $this->view_actions ) ) {
199
+
200
+ $this->view_actions = apply_filters(
201
+ 'astra_sites_menu_item',
202
+ array()
203
+ );
204
+ }
205
+
206
+ return $this->view_actions;
207
+ }
208
+
209
+ /**
210
+ * Prints HTML content for tabs
211
+ *
212
+ * @param mixed $action Action name.
213
+ * @since 1.0.6
214
+ */
215
+ public function render( $action ) {
216
+
217
+ // Settings update message.
218
+ if ( isset( $_REQUEST['message'] ) && ( 'saved' == $_REQUEST['message'] || 'saved_ext' == $_REQUEST['message'] ) ) {
219
+ ?>
220
+ <span id="message" class="notice notice-success is-dismissive"><p> <?php esc_html_e( 'Settings saved successfully.', 'astra-sites' ); ?> </p></span>
221
+ <?php
222
+ }
223
+
224
+ $default_page_builder = $this->get_setting( 'page_builder' );
225
+
226
+ if ( empty( $default_page_builder ) ) {
227
+ ?>
228
+ <div class="astra-sites-welcome">
229
+ <div class="inner">
230
+ <form id="astra-sites-welcome-form" enctype="multipart/form-data" method="post">
231
+ <h1>Select Page Builder</h1>
232
+ <p class="description">Select your favorite page builder to import sites or individual pages.</p>
233
+ <div class="fields">
234
+ <select name="page_builder" required="required">
235
+ <option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
236
+ <option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
237
+ <option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
238
+ <option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
239
+ </select>
240
+ <?php submit_button( __( 'Next', 'astra-sites' ) ); ?>
241
+ </div>
242
+ <input type="hidden" name="message" value="saved" />
243
+ <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
244
+ </form>
245
+ </div>
246
+ </div>
247
+ <?php } else { ?>
248
+ <?php
249
+ $page_title = apply_filters( 'astra_sites_page_title', __( 'Astra Starter Sites - Your Library of 100+ Ready Templates!', 'astra-sites' ) );
250
+ ?>
251
+ <div class="nav-tab-wrapper">
252
+ <h1 class='astra-sites-title'> <?php echo esc_html( $page_title ); ?> </h1>
253
+ <form id="astra-sites-welcome-form-inline" enctype="multipart/form-data" method="post">
254
+ <div class="fields">
255
+ <select name="page_builder" required="required">
256
+ <option value="gutenberg" <?php selected( $default_page_builder, 'gutenberg' ); ?>><?php _e( 'Block Editor (Gutenberg)', 'astra-sites' ); ?></option>
257
+ <option value="elementor" <?php selected( $default_page_builder, 'elementor' ); ?>><?php _e( 'Elementor', 'astra-sites' ); ?></option>
258
+ <option value="beaver-builder" <?php selected( $default_page_builder, 'beaver-builder' ); ?>><?php _e( 'Beaver Builder', 'astra-sites' ); ?></option>
259
+ <option value="brizy" <?php selected( $default_page_builder, 'brizy' ); ?>><?php _e( 'Brizy', 'astra-sites' ); ?></option>
260
+ </select>
261
+ </div>
262
+ <input type="hidden" name="message" value="saved" />
263
+ <?php wp_nonce_field( 'astra-sites-welcome-screen', 'astra-sites-page-builder' ); ?>
264
+ </form>
265
+ <?php
266
+ $view_actions = $this->get_view_actions();
267
+
268
+ foreach ( $view_actions as $slug => $data ) {
269
+
270
+ if ( ! $data['show'] ) {
271
+ continue;
272
+ }
273
+
274
+ $url = $this->get_page_url( $slug );
275
+
276
+ if ( 'general' == $slug ) {
277
+ update_option( 'astra_parent_page_url', $url );
278
+ }
279
+
280
+ $active = ( $slug == $action ) ? 'nav-tab-active' : '';
281
+ ?>
282
+ <a class='nav-tab <?php echo esc_attr( $active ); ?>' href='<?php echo esc_url( $url ); ?>'> <?php echo esc_html( $data['label'] ); ?> </a>
283
+ <?php } ?>
284
+ </div><!-- .nav-tab-wrapper -->
285
+ <?php
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Get and return page URL
291
+ *
292
+ * @param string $menu_slug Menu name.
293
+ * @since 1.0.6
294
+ * @return string page url
295
+ */
296
+ public function get_page_url( $menu_slug ) {
297
+
298
+ $parent_page = 'themes.php';
299
+
300
+ if ( strpos( $parent_page, '?' ) !== false ) {
301
+ $query_var = '&page=astra-sites';
302
+ } else {
303
+ $query_var = '?page=astra-sites';
304
+ }
305
+
306
+ $parent_page_url = admin_url( $parent_page . $query_var );
307
+
308
+ $url = $parent_page_url . '&action=' . $menu_slug;
309
+
310
+ return esc_url( $url );
311
+ }
312
+
313
+ /**
314
+ * Add main menu
315
+ *
316
+ * @since 1.0.6
317
+ */
318
+ public function add_admin_menu() {
319
+ $page_title = apply_filters( 'astra_sites_menu_page_title', __( 'Astra Sites', 'astra-sites' ) );
320
+
321
+ $page = add_theme_page( $page_title, $page_title, 'manage_options', 'astra-sites', array( $this, 'menu_callback' ) );
322
+ }
323
+
324
+ /**
325
+ * Menu callback
326
+ *
327
+ * @since 1.0.6
328
+ */
329
+ public function menu_callback() {
330
+
331
+ $current_slug = isset( $_GET['action'] ) ? esc_attr( $_GET['action'] ) : 'general';
332
+
333
+ $active_tab = str_replace( '_', '-', $current_slug );
334
+ $current_slug = str_replace( '-', '_', $current_slug );
335
+
336
+ ?>
337
+ <div class="astra-sites-menu-page-wrapper">
338
+ <?php $this->init_nav_menu( $active_tab ); ?>
339
+ <?php do_action( 'astra_sites_menu_' . esc_attr( $current_slug ) . '_action' ); ?>
340
+ </div>
341
+ <?php
342
+ }
343
+
344
+ /**
345
+ * Include general page
346
+ *
347
+ * @since 1.0.6
348
+ */
349
+ public function general_page() {
350
+ $default_page_builder = $this->get_setting( 'page_builder' );
351
+ if ( empty( $default_page_builder ) || isset( $_GET['change-page-builder'] ) ) {
352
+ return;
353
+ }
354
+ require_once ASTRA_SITES_DIR . 'inc/includes/admin-page.php';
355
+ }
356
+ }
357
+
358
+ Astra_Sites_Page::get_instance();
359
+
360
+ }// End if.
inc/classes/class-astra-sites-white-label.php CHANGED
@@ -1,238 +1,239 @@
1
- <?php
2
- /**
3
- * Astra Sites White Label
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.12
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
10
-
11
- /**
12
- * Astra_Sites_White_Label
13
- *
14
- * @since 1.0.12
15
- */
16
- class Astra_Sites_White_Label {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.12
22
- *
23
- * @var object Class Object.
24
- * @access private
25
- */
26
- private static $instance;
27
-
28
- /**
29
- * Member Variable
30
- *
31
- * @since 1.0.12
32
- *
33
- * @var array branding
34
- * @access private
35
- */
36
- private static $branding;
37
-
38
- /**
39
- * Settings
40
- *
41
- * @since 1.2.11
42
- *
43
- * @var array settings
44
- *
45
- * @access private
46
- */
47
- private $settings;
48
-
49
- /**
50
- * Initiator
51
- *
52
- * @since 1.0.12
53
- *
54
- * @return object initialized object of class.
55
- */
56
- public static function get_instance() {
57
- if ( ! isset( self::$instance ) ) {
58
- self::$instance = new self;
59
- }
60
- return self::$instance;
61
- }
62
-
63
- /**
64
- * Constructor
65
- *
66
- * @since 1.0.12
67
- */
68
- public function __construct() {
69
- add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
70
- add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
71
- add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
72
- add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
73
-
74
- // Display the link with the plugin meta.
75
- if ( is_admin() ) {
76
- add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
77
- }
78
- }
79
-
80
- /**
81
- * White labels the plugins page.
82
- *
83
- * @since 1.0.12
84
- *
85
- * @param array $plugins Plugins Array.
86
- * @return array
87
- */
88
- function plugins_page( $plugins ) {
89
-
90
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
91
- return $plugins;
92
- }
93
-
94
- if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
95
- return $plugins;
96
- }
97
-
98
- // Set White Labels.
99
- $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
100
- $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
101
- $author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
102
- $author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
103
-
104
- if ( ! empty( $name ) ) {
105
- $plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
106
-
107
- // Remove Plugin URI if Agency White Label name is set.
108
- $plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
109
- }
110
-
111
- if ( ! empty( $description ) ) {
112
- $plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
113
- }
114
-
115
- if ( ! empty( $author ) ) {
116
- $plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
117
- }
118
-
119
- if ( ! empty( $author_uri ) ) {
120
- $plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
121
- }
122
-
123
- return $plugins;
124
- }
125
-
126
- /**
127
- * Remove a "view details" link from the plugin list table
128
- *
129
- * @since 1.0.12
130
- *
131
- * @param array $plugin_meta List of links.
132
- * @param string $plugin_file Relative path to the main plugin file from the plugins directory.
133
- * @param array $plugin_data Data from the plugin headers.
134
- * @return array
135
- */
136
- public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
137
-
138
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
139
- return $plugin_meta;
140
- }
141
-
142
- // Set White Labels.
143
- if ( ASTRA_SITES_BASE == $plugin_file ) {
144
-
145
- $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
146
- $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
147
-
148
- // Remove Plugin URI if Agency White Label name is set.
149
- if ( ! empty( $name ) ) {
150
- unset( $plugin_meta[2] );
151
- }
152
- }
153
-
154
- return $plugin_meta;
155
- }
156
-
157
- /**
158
- * Add White Label setting's
159
- *
160
- * @since 1.0.12
161
- *
162
- * @param array $settings White label setting.
163
- * @return array
164
- */
165
- public static function settings( $settings = array() ) {
166
-
167
- $settings['astra-sites'] = array(
168
- 'name' => '',
169
- 'description' => '',
170
- );
171
-
172
- return $settings;
173
- }
174
-
175
- /**
176
- * Add White Label form
177
- *
178
- * @since 1.0.12
179
- *
180
- * @param array $settings White label setting.
181
- * @return void
182
- */
183
- public static function add_white_lavel_form( $settings = array() ) {
184
-
185
- /* translators: %1$s product name */
186
- $plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
187
-
188
- require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
189
- }
190
-
191
- /**
192
- * Page Title
193
- *
194
- * @since 1.0.12
195
- *
196
- * @param string $title Page Title.
197
- * @return string Filtered Page Title.
198
- */
199
- function page_title( $title ) {
200
-
201
- if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
202
- $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
203
- if ( ! empty( $astra_sites_name ) ) {
204
- $title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
205
- }
206
- }
207
-
208
- return $title;
209
- }
210
-
211
- /**
212
- * Is Astra sites White labeled
213
- *
214
- * @since 1.2.13
215
- *
216
- * @return string
217
- */
218
- function is_white_labeled() {
219
- if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
220
- return false;
221
- }
222
-
223
- $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
224
- if ( empty( $astra_sites_name ) ) {
225
- return false;
226
- }
227
-
228
- return true;
229
- }
230
-
231
- }
232
-
233
- /**
234
- * Kicking this off by calling 'get_instance()' method
235
- */
236
- Astra_Sites_White_Label::get_instance();
237
-
238
- endif;
 
1
+ <?php
2
+ /**
3
+ * Astra Sites White Label
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.12
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_White_Label
13
+ *
14
+ * @since 1.0.12
15
+ */
16
+ class Astra_Sites_White_Label {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.12
22
+ *
23
+ * @var object Class Object.
24
+ * @access private
25
+ */
26
+ private static $instance;
27
+
28
+ /**
29
+ * Member Variable
30
+ *
31
+ * @since 1.0.12
32
+ *
33
+ * @var array branding
34
+ * @access private
35
+ */
36
+ private static $branding;
37
+
38
+ /**
39
+ * Settings
40
+ *
41
+ * @since 1.2.11
42
+ *
43
+ * @var array settings
44
+ *
45
+ * @access private
46
+ */
47
+ private $settings;
48
+
49
+ /**
50
+ * Initiator
51
+ *
52
+ * @since 1.0.12
53
+ *
54
+ * @return object initialized object of class.
55
+ */
56
+ public static function get_instance() {
57
+ if ( ! isset( self::$instance ) ) {
58
+ self::$instance = new self;
59
+ }
60
+ return self::$instance;
61
+ }
62
+
63
+ /**
64
+ * Constructor
65
+ *
66
+ * @since 1.0.12
67
+ */
68
+ public function __construct() {
69
+ add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
70
+ add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
71
+ add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_lavel_form' );
72
+ add_filter( 'astra_sites_menu_page_title', array( $this, 'page_title' ) );
73
+ add_filter( 'astra_sites_page_title', array( $this, 'page_title' ) );
74
+
75
+ // Display the link with the plugin meta.
76
+ if ( is_admin() ) {
77
+ add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
78
+ }
79
+ }
80
+
81
+ /**
82
+ * White labels the plugins page.
83
+ *
84
+ * @since 1.0.12
85
+ *
86
+ * @param array $plugins Plugins Array.
87
+ * @return array
88
+ */
89
+ function plugins_page( $plugins ) {
90
+
91
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
92
+ return $plugins;
93
+ }
94
+
95
+ if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
96
+ return $plugins;
97
+ }
98
+
99
+ // Set White Labels.
100
+ $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
101
+ $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
102
+ $author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
103
+ $author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
104
+
105
+ if ( ! empty( $name ) ) {
106
+ $plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
107
+
108
+ // Remove Plugin URI if Agency White Label name is set.
109
+ $plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
110
+ }
111
+
112
+ if ( ! empty( $description ) ) {
113
+ $plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
114
+ }
115
+
116
+ if ( ! empty( $author ) ) {
117
+ $plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
118
+ }
119
+
120
+ if ( ! empty( $author_uri ) ) {
121
+ $plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
122
+ }
123
+
124
+ return $plugins;
125
+ }
126
+
127
+ /**
128
+ * Remove a "view details" link from the plugin list table
129
+ *
130
+ * @since 1.0.12
131
+ *
132
+ * @param array $plugin_meta List of links.
133
+ * @param string $plugin_file Relative path to the main plugin file from the plugins directory.
134
+ * @param array $plugin_data Data from the plugin headers.
135
+ * @return array
136
+ */
137
+ public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
138
+
139
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
140
+ return $plugin_meta;
141
+ }
142
+
143
+ // Set White Labels.
144
+ if ( ASTRA_SITES_BASE == $plugin_file ) {
145
+
146
+ $name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
147
+ $description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
148
+
149
+ // Remove Plugin URI if Agency White Label name is set.
150
+ if ( ! empty( $name ) ) {
151
+ unset( $plugin_meta[2] );
152
+ }
153
+ }
154
+
155
+ return $plugin_meta;
156
+ }
157
+
158
+ /**
159
+ * Add White Label setting's
160
+ *
161
+ * @since 1.0.12
162
+ *
163
+ * @param array $settings White label setting.
164
+ * @return array
165
+ */
166
+ public static function settings( $settings = array() ) {
167
+
168
+ $settings['astra-sites'] = array(
169
+ 'name' => '',
170
+ 'description' => '',
171
+ );
172
+
173
+ return $settings;
174
+ }
175
+
176
+ /**
177
+ * Add White Label form
178
+ *
179
+ * @since 1.0.12
180
+ *
181
+ * @param array $settings White label setting.
182
+ * @return void
183
+ */
184
+ public static function add_white_lavel_form( $settings = array() ) {
185
+
186
+ /* translators: %1$s product name */
187
+ $plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
188
+
189
+ require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
190
+ }
191
+
192
+ /**
193
+ * Page Title
194
+ *
195
+ * @since 1.0.12
196
+ *
197
+ * @param string $title Page Title.
198
+ * @return string Filtered Page Title.
199
+ */
200
+ function page_title( $title ) {
201
+
202
+ if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
203
+ $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
204
+ if ( ! empty( $astra_sites_name ) ) {
205
+ $title = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
206
+ }
207
+ }
208
+
209
+ return $title;
210
+ }
211
+
212
+ /**
213
+ * Is Astra sites White labeled
214
+ *
215
+ * @since 1.2.13
216
+ *
217
+ * @return string
218
+ */
219
+ function is_white_labeled() {
220
+ if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
221
+ return false;
222
+ }
223
+
224
+ $astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
225
+ if ( empty( $astra_sites_name ) ) {
226
+ return false;
227
+ }
228
+
229
+ return true;
230
+ }
231
+
232
+ }
233
+
234
+ /**
235
+ * Kicking this off by calling 'get_instance()' method
236
+ */
237
+ Astra_Sites_White_Label::get_instance();
238
+
239
+ endif;
inc/classes/class-astra-sites.php CHANGED
@@ -1,471 +1,518 @@
1
- <?php
2
- /**
3
- * Astra Sites
4
- *
5
- * @since 1.0.0
6
- * @package Astra Sites
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- if ( ! class_exists( 'Astra_Sites' ) ) :
12
-
13
- /**
14
- * Astra_Sites
15
- */
16
- class Astra_Sites {
17
-
18
- /**
19
- * API URL which is used to get the response from.
20
- *
21
- * @since 1.0.0
22
- * @var (String) URL
23
- */
24
- public static $api_url;
25
-
26
- /**
27
- * Instance of Astra_Sites
28
- *
29
- * @since 1.0.0
30
- * @var (Object) Astra_Sites
31
- */
32
- private static $_instance = null;
33
-
34
- /**
35
- * Instance of Astra_Sites.
36
- *
37
- * @since 1.0.0
38
- *
39
- * @return object Class object.
40
- */
41
- public static function get_instance() {
42
- if ( ! isset( self::$_instance ) ) {
43
- self::$_instance = new self;
44
- }
45
-
46
- return self::$_instance;
47
- }
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @since 1.0.0
53
- */
54
- private function __construct() {
55
-
56
- self::set_api_url();
57
-
58
- $this->includes();
59
-
60
- add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
61
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
62
- add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
63
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
64
-
65
- // AJAX.
66
- add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
67
- add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
68
- }
69
-
70
- /**
71
- * Add Admin Notice.
72
- */
73
- function add_notice() {
74
-
75
- Astra_Sites_Notices::add_notice(
76
- array(
77
- 'id' => 'astra-theme-activation-nag',
78
- 'type' => 'error',
79
- 'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
80
- /* translators: 1: theme.php file*/
81
- 'message' => sprintf( __( 'Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="%2$s">Install & Activate Now</a>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ) ),
82
- 'dismissible' => true,
83
- 'dismissible-time' => WEEK_IN_SECONDS,
84
- )
85
- );
86
-
87
- }
88
-
89
- /**
90
- * Loads textdomain for the plugin.
91
- *
92
- * @since 1.0.1
93
- */
94
- function load_textdomain() {
95
- load_plugin_textdomain( 'astra-sites' );
96
- }
97
-
98
- /**
99
- * Admin Notices
100
- *
101
- * @since 1.0.5
102
- * @return void
103
- */
104
- function admin_notices() {
105
-
106
- if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
107
- return;
108
- }
109
-
110
- add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
111
- }
112
-
113
- /**
114
- * Show action links on the plugin screen.
115
- *
116
- * @param mixed $links Plugin Action links.
117
- * @return array
118
- */
119
- function action_links( $links ) {
120
- $action_links = array(
121
- 'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
122
- );
123
-
124
- return array_merge( $action_links, $links );
125
- }
126
-
127
- /**
128
- * Setter for $api_url
129
- *
130
- * @since 1.0.0
131
- */
132
- public static function set_api_url() {
133
-
134
- self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
135
-
136
- }
137
-
138
- /**
139
- * Enqueue admin scripts.
140
- *
141
- * @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
142
- *
143
- * @since 1.0.0
144
- *
145
- * @param string $hook Current hook name.
146
- * @return void
147
- */
148
- public function admin_enqueue( $hook = '' ) {
149
-
150
- if ( 'appearance_page_astra-sites' !== $hook ) {
151
- return;
152
- }
153
-
154
- global $is_IE, $is_edge;
155
-
156
- if ( $is_IE || $is_edge ) {
157
- wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
158
- }
159
-
160
- // API.
161
- wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery' ), ASTRA_SITES_VER, true );
162
-
163
- // Admin Page.
164
- wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true );
165
- wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
166
- wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true );
167
-
168
- $data = apply_filters(
169
- 'astra_sites_localize_vars',
170
- array(
171
- 'ApiURL' => self::$api_url,
172
- 'filters' => array(
173
- 'page_builder' => array(
174
- 'title' => __( 'Page Builder', 'astra-sites' ),
175
- 'slug' => 'astra-site-page-builder',
176
- 'trigger' => 'astra-api-category-loaded',
177
- ),
178
- 'categories' => array(
179
- 'title' => __( 'Categories', 'astra-sites' ),
180
- 'slug' => 'astra-site-category',
181
- 'trigger' => 'astra-api-category-loaded',
182
- ),
183
- ),
184
- )
185
- );
186
- wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data );
187
-
188
- // Use this for premium demos.
189
- $request_params = apply_filters(
190
- 'astra_sites_api_params',
191
- array(
192
- 'purchase_key' => '',
193
- 'site_url' => '',
194
- 'par-page' => 15,
195
- )
196
- );
197
-
198
- $data = apply_filters(
199
- 'astra_sites_render_localize_vars',
200
- array(
201
- 'sites' => $request_params,
202
- 'page-builders' => array(),
203
- 'categories' => array(),
204
- 'settings' => array(),
205
- )
206
- );
207
-
208
- wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data );
209
-
210
- $data = apply_filters(
211
- 'astra_sites_localize_vars',
212
- array(
213
- 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
214
- 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
215
- 'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(),
216
- 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
217
- 'siteURL' => site_url(),
218
- 'getProText' => __( 'Get Agency Bundle', 'astra-sites' ),
219
- 'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
220
- 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ),
221
- 'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
222
- '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
223
- 'requiredPlugins' => array(),
224
- 'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false,
225
- 'strings' => array(
226
- /* translators: %s are HTML tags. */
227
- 'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '<div class="notice astra-sites-xml-notice notice-error"><p><b>', '</b></p><p>', '</p></div>' ),
228
- 'warningBeforeCloseWindow' => __( 'Warning! Astra Site Import process is not complete. Don\'t close the window until import process complete. Do you still want to leave the window?', 'astra-sites' ),
229
- 'importFailedBtnSmall' => __( 'Error!', 'astra-sites' ),
230
- 'importFailedBtnLarge' => __( 'Error! Read Possibilities.', 'astra-sites' ),
231
- 'importFailedURL' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=import-failed' ),
232
- 'viewSite' => __( 'Done! View Site', 'astra-sites' ),
233
- 'btnActivating' => __( 'Activating', 'astra-sites' ) . '&hellip;',
234
- 'btnActive' => __( 'Active', 'astra-sites' ),
235
- 'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
236
- 'importFailBtnLarge' => __( 'Import failed. See error log.', 'astra-sites' ),
237
- 'importDemo' => __( 'Import This Site', 'astra-sites' ),
238
- 'importingDemo' => __( 'Importing..', 'astra-sites' ),
239
- 'DescExpand' => __( 'Read more', 'astra-sites' ) . '&hellip;',
240
- 'DescCollapse' => __( 'Hide', 'astra-sites' ),
241
- 'responseError' => __( 'There was a problem receiving a response from server.', 'astra-sites' ),
242
- 'searchNoFound' => __( 'No Demos found, Try a different search.', 'astra-sites' ),
243
- 'importWarning' => __( "Executing Demo Import will make your site similar as ours. Please bear in mind -\n\n1. It is recommended to run import on a fresh WordPress installation.\n\n2. Importing site does not delete any pages or posts. However, it can overwrite your existing content.\n\n3. Copyrighted media will not be imported. Instead it will be replaced with placeholders.", 'astra-sites' ),
244
- ),
245
- 'log' => array(
246
- 'installingPlugin' => __( 'Installing plugin ', 'astra-sites' ),
247
- 'installed' => __( 'Successfully plugin installed!', 'astra-sites' ),
248
- 'activating' => __( 'Activating plugin ', 'astra-sites' ),
249
- 'activated' => __( 'Successfully plugin activated ', 'astra-sites' ),
250
- 'bulkActivation' => __( 'Bulk plugin activation...', 'astra-sites' ),
251
- 'activate' => __( 'Successfully plugin activate - ', 'astra-sites' ),
252
- 'activationError' => __( 'Error! While activating plugin - ', 'astra-sites' ),
253
- 'bulkInstall' => __( 'Bulk plugin installation...', 'astra-sites' ),
254
- 'api' => __( 'Site API ', 'astra-sites' ),
255
- 'importing' => __( 'Importing..', 'astra-sites' ),
256
- 'processingRequest' => __( 'Processing requests...', 'astra-sites' ),
257
- 'importCustomizer' => __( '1) Importing "Customizer Settings"...', 'astra-sites' ),
258
- 'importCustomizerSuccess' => __( 'Successfully imported customizer settings!', 'astra-sites' ),
259
- 'importWPForms' => __( '2) Importing "WPForms"...', 'astra-sites' ),
260
- 'importWPFormsSuccess' => __( 'Successfully imported WPForms!', 'astra-sites' ),
261
- 'importXMLPrepare' => __( '3) Preparing "XML" Data...', 'astra-sites' ),
262
- 'importXMLPrepareSuccess' => __( 'Successfully set XML data!', 'astra-sites' ),
263
- 'importXML' => __( '4) Importing "XML"...', 'astra-sites' ),
264
- 'importXMLSuccess' => __( 'Successfully imported XML!', 'astra-sites' ),
265
- 'importOptions' => __( '5) Importing "Options"...', 'astra-sites' ),
266
- 'importOptionsSuccess' => __( 'Successfully imported Options!', 'astra-sites' ),
267
- 'importWidgets' => __( '6) Importing "Widgets"...', 'astra-sites' ),
268
- 'importWidgetsSuccess' => __( 'Successfully imported Widgets!', 'astra-sites' ),
269
- 'serverConfiguration' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' ),
270
- 'success' => __( 'Site imported successfully! visit : ', 'astra-sites' ),
271
- 'gettingData' => __( 'Getting Site Information..', 'astra-sites' ),
272
- 'importingCustomizer' => __( 'Importing Customizer Settings..', 'astra-sites' ),
273
- 'importingWPForms' => __( 'Importing WP Forms..', 'astra-sites' ),
274
- 'importXMLPreparing' => __( 'Setting up import data..', 'astra-sites' ),
275
- 'importingXML' => __( 'Importing Pages, Posts & Media..', 'astra-sites' ),
276
- 'importingOptions' => __( 'Importing Site Options..', 'astra-sites' ),
277
- 'importingWidgets' => __( 'Importing Widgets..', 'astra-sites' ),
278
- 'importComplete' => __( 'Import Complete..', 'astra-sites' ),
279
- 'preview' => __( 'Previewing ', 'astra-sites' ),
280
- 'importLogText' => __( 'See Error Log &rarr;', 'astra-sites' ),
281
- ),
282
- )
283
- );
284
-
285
- wp_localize_script( 'astra-sites-admin-page', 'astraSitesAdmin', $data );
286
-
287
- }
288
-
289
- /**
290
- * Load all the required files in the importer.
291
- *
292
- * @since 1.0.0
293
- */
294
- private function includes() {
295
-
296
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-notices.php';
297
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
298
- require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
299
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-white-label.php';
300
- require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
301
-
302
- }
303
-
304
- /**
305
- * Required Plugin Activate
306
- *
307
- * @since 1.0.0
308
- */
309
- public function required_plugin_activate() {
310
-
311
- if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
312
- wp_send_json_error(
313
- array(
314
- 'success' => false,
315
- 'message' => __( 'No plugin specified', 'astra-sites' ),
316
- )
317
- );
318
- }
319
-
320
- $data = array();
321
- $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
322
- $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
323
- $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
324
-
325
- $data['astra_site_options'] = $astra_site_options;
326
- $data['enabled_extensions'] = $enabled_extensions;
327
-
328
- $activate = activate_plugin( $plugin_init, '', false, true );
329
-
330
- if ( is_wp_error( $activate ) ) {
331
- wp_send_json_error(
332
- array(
333
- 'success' => false,
334
- 'message' => $activate->get_error_message(),
335
- )
336
- );
337
- }
338
-
339
- do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
340
-
341
- wp_send_json_success(
342
- array(
343
- 'success' => true,
344
- 'message' => __( 'Plugin Successfully Activated', 'astra-sites' ),
345
- )
346
- );
347
-
348
- }
349
-
350
- /**
351
- * Required Plugin
352
- *
353
- * @since 1.0.0
354
- * @return void
355
- */
356
- public function required_plugin() {
357
-
358
- // Verify Nonce.
359
- check_ajax_referer( 'astra-sites', '_ajax_nonce' );
360
-
361
- $response = array(
362
- 'active' => array(),
363
- 'inactive' => array(),
364
- 'notinstalled' => array(),
365
- );
366
-
367
- if ( ! current_user_can( 'customize' ) ) {
368
- wp_send_json_error( $response );
369
- }
370
-
371
- $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
372
-
373
- if ( count( $required_plugins ) > 0 ) {
374
- foreach ( $required_plugins as $key => $plugin ) {
375
-
376
- /**
377
- * Has Pro Version Support?
378
- * And
379
- * Is Pro Version Installed?
380
- */
381
- $plugin_pro = self::pro_plugin_exist( $plugin['init'] );
382
- if ( $plugin_pro ) {
383
-
384
- // Pro - Active.
385
- if ( is_plugin_active( $plugin_pro['init'] ) ) {
386
- $response['active'][] = $plugin_pro;
387
-
388
- // Pro - Inactive.
389
- } else {
390
- $response['inactive'][] = $plugin_pro;
391
- }
392
- } else {
393
-
394
- // Lite - Installed but Inactive.
395
- if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) {
396
-
397
- $response['inactive'][] = $plugin;
398
-
399
- // Lite - Not Installed.
400
- } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) {
401
-
402
- $response['notinstalled'][] = $plugin;
403
-
404
- // Lite - Active.
405
- } else {
406
- $response['active'][] = $plugin;
407
- }
408
- }
409
- }
410
- }
411
-
412
- // Send response.
413
- wp_send_json_success( $response );
414
- }
415
-
416
- /**
417
- * Has Pro Version Support?
418
- * And
419
- * Is Pro Version Installed?
420
- *
421
- * Check Pro plugin version exist of requested plugin lite version.
422
- *
423
- * Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist?
424
- * If yes then we only 'Activate' Agency Version. [We couldn't install agency version.]
425
- * Else we 'Activate' or 'Install' Lite Version.
426
- *
427
- * @since 1.0.1
428
- *
429
- * @param string $lite_version Lite version init file.
430
- * @return mixed Return false if not installed or not supported by us
431
- * else return 'Pro' version details.
432
- */
433
- public static function pro_plugin_exist( $lite_version = '' ) {
434
-
435
- // Lite init => Pro init.
436
- $plugins = apply_filters(
437
- 'astra_sites_pro_plugin_exist',
438
- array(
439
- 'beaver-builder-lite-version/fl-builder.php' => array(
440
- 'slug' => 'bb-plugin',
441
- 'init' => 'bb-plugin/fl-builder.php',
442
- 'name' => 'Beaver Builder Plugin',
443
- ),
444
- 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array(
445
- 'slug' => 'bb-ultimate-addon',
446
- 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
447
- 'name' => 'Ultimate Addon for Beaver Builder',
448
- ),
449
- ),
450
- $lite_version
451
- );
452
-
453
- if ( isset( $plugins[ $lite_version ] ) ) {
454
-
455
- // Pro plugin directory exist?
456
- if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) {
457
- return $plugins[ $lite_version ];
458
- }
459
- }
460
-
461
- return false;
462
- }
463
-
464
- }
465
-
466
- /**
467
- * Kicking this off by calling 'get_instance()' method
468
- */
469
- Astra_Sites::get_instance();
470
-
471
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Astra Sites
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Sites
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ if ( ! class_exists( 'Astra_Sites' ) ) :
12
+
13
+ /**
14
+ * Astra_Sites
15
+ */
16
+ class Astra_Sites {
17
+
18
+ /**
19
+ * API URL which is used to get the response from.
20
+ *
21
+ * @since 1.0.0
22
+ * @var (String) URL
23
+ */
24
+ public static $api_url;
25
+
26
+ /**
27
+ * Instance of Astra_Sites
28
+ *
29
+ * @since 1.0.0
30
+ * @var (Object) Astra_Sites
31
+ */
32
+ private static $_instance = null;
33
+
34
+ /**
35
+ * Instance of Astra_Sites.
36
+ *
37
+ * @since 1.0.0
38
+ *
39
+ * @return object Class object.
40
+ */
41
+ public static function get_instance() {
42
+ if ( ! isset( self::$_instance ) ) {
43
+ self::$_instance = new self;
44
+ }
45
+
46
+ return self::$_instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor.
51
+ *
52
+ * @since 1.0.0
53
+ */
54
+ private function __construct() {
55
+
56
+ self::set_api_url();
57
+
58
+ $this->includes();
59
+
60
+ add_action( 'admin_notices', array( $this, 'add_notice' ), 1 );
61
+ add_action( 'admin_notices', array( $this, 'admin_notices' ) );
62
+ add_action( 'plugins_loaded', array( $this, 'load_textdomain' ) );
63
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue' ) );
64
+
65
+ // AJAX.
66
+ add_action( 'wp_ajax_astra-required-plugins', array( $this, 'required_plugin' ) );
67
+ add_action( 'wp_ajax_astra-required-plugin-activate', array( $this, 'required_plugin_activate' ) );
68
+ add_action( 'wp_ajax_astra-sites-backup-settings', array( $this, 'backup_settings' ) );
69
+ add_action( 'wp_ajax_astra-sites-set-reset-data', array( $this, 'set_reset_data' ) );
70
+ }
71
+
72
+ /**
73
+ * Set reset data
74
+ */
75
+ function set_reset_data() {
76
+ if ( ! current_user_can( 'manage_options' ) ) {
77
+ return;
78
+ }
79
+
80
+ global $wpdb;
81
+
82
+ $post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_post'" );
83
+ $form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" );
84
+ $term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" );
85
+
86
+ wp_send_json_success(
87
+ array(
88
+ 'reset_posts' => $post_ids,
89
+ 'reset_wp_forms' => $form_ids,
90
+ 'reset_terms' => $term_ids,
91
+ )
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Backup our existing settings.
97
+ */
98
+ function backup_settings() {
99
+ if ( ! current_user_can( 'manage_options' ) ) {
100
+ return;
101
+ }
102
+
103
+ $file_name = 'astra-sites-backup-' . date( 'd-M-Y-h-i-s' ) . '.json';
104
+ $old_settings = get_option( 'astra-settings', array() );
105
+ $upload_dir = Astra_Sites_Importer_Log::get_instance()->log_dir();
106
+ $upload_path = trailingslashit( $upload_dir['path'] );
107
+ $log_file = $upload_path . $file_name;
108
+ $file_system = Astra_Sites_Importer_Log::get_instance()->get_filesystem();
109
+
110
+ // If file system fails? Then take a backup in site option.
111
+ if ( false == $file_system->put_contents( $log_file, json_encode( $old_settings ), FS_CHMOD_FILE ) ) {
112
+ update_option( 'astra_sites_' . $file_name, $old_settings );
113
+ }
114
+
115
+ wp_send_json_success();
116
+ }
117
+
118
+ /**
119
+ * Add Admin Notice.
120
+ */
121
+ function add_notice() {
122
+
123
+ Astra_Sites_Notices::add_notice(
124
+ array(
125
+ 'id' => 'astra-theme-activation-nag',
126
+ 'type' => 'error',
127
+ 'show_if' => ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) ? true : false,
128
+ /* translators: 1: theme.php file*/
129
+ 'message' => sprintf( __( 'Astra Theme needs to be active for you to use currently installed "%1$s" plugin. <a href="%2$s">Install & Activate Now</a>', 'astra-sites' ), ASTRA_SITES_NAME, esc_url( admin_url( 'themes.php?theme=astra' ) ) ),
130
+ 'dismissible' => true,
131
+ 'dismissible-time' => WEEK_IN_SECONDS,
132
+ )
133
+ );
134
+
135
+ }
136
+
137
+ /**
138
+ * Loads textdomain for the plugin.
139
+ *
140
+ * @since 1.0.1
141
+ */
142
+ function load_textdomain() {
143
+ load_plugin_textdomain( 'astra-sites' );
144
+ }
145
+
146
+ /**
147
+ * Admin Notices
148
+ *
149
+ * @since 1.0.5
150
+ * @return void
151
+ */
152
+ function admin_notices() {
153
+
154
+ if ( ! defined( 'ASTRA_THEME_SETTINGS' ) ) {
155
+ return;
156
+ }
157
+
158
+ add_action( 'plugin_action_links_' . ASTRA_SITES_BASE, array( $this, 'action_links' ) );
159
+ }
160
+
161
+ /**
162
+ * Show action links on the plugin screen.
163
+ *
164
+ * @param mixed $links Plugin Action links.
165
+ * @return array
166
+ */
167
+ function action_links( $links ) {
168
+ $action_links = array(
169
+ 'settings' => '<a href="' . admin_url( 'themes.php?page=astra-sites' ) . '" aria-label="' . esc_attr__( 'See Library', 'astra-sites' ) . '">' . esc_html__( 'See Library', 'astra-sites' ) . '</a>',
170
+ );
171
+
172
+ return array_merge( $action_links, $links );
173
+ }
174
+
175
+ /**
176
+ * Setter for $api_url
177
+ *
178
+ * @since 1.0.0
179
+ */
180
+ public static function set_api_url() {
181
+
182
+ self::$api_url = apply_filters( 'astra_sites_api_url', 'https://websitedemos.net/wp-json/wp/v2/' );
183
+
184
+ }
185
+
186
+ /**
187
+ * Enqueue admin scripts.
188
+ *
189
+ * @since 1.0.5 Added 'getUpgradeText' and 'getUpgradeURL' localize variables.
190
+ *
191
+ * @since 1.0.0
192
+ *
193
+ * @param string $hook Current hook name.
194
+ * @return void
195
+ */
196
+ public function admin_enqueue( $hook = '' ) {
197
+
198
+ if ( 'appearance_page_astra-sites' !== $hook ) {
199
+ return;
200
+ }
201
+
202
+ global $is_IE, $is_edge;
203
+
204
+ if ( $is_IE || $is_edge ) {
205
+ wp_enqueue_script( 'astra-sites-eventsource', ASTRA_SITES_URI . 'inc/assets/js/eventsource.min.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
206
+ }
207
+
208
+ // API.
209
+ wp_register_script( 'astra-sites-api', ASTRA_SITES_URI . 'inc/assets/js/astra-sites-api.js', array( 'jquery' ), ASTRA_SITES_VER, true );
210
+
211
+ // Admin Page.
212
+ wp_enqueue_style( 'astra-sites-admin', ASTRA_SITES_URI . 'inc/assets/css/admin.css', ASTRA_SITES_VER, true );
213
+ wp_enqueue_script( 'astra-sites-admin-page', ASTRA_SITES_URI . 'inc/assets/js/admin-page.js', array( 'jquery', 'wp-util', 'updates' ), ASTRA_SITES_VER, true );
214
+ wp_enqueue_script( 'astra-sites-render-grid', ASTRA_SITES_URI . 'inc/assets/js/render-grid.js', array( 'wp-util', 'astra-sites-api', 'imagesloaded', 'jquery' ), ASTRA_SITES_VER, true );
215
+
216
+ $data = apply_filters(
217
+ 'astra_sites_localize_vars',
218
+ array(
219
+ 'ApiURL' => self::$api_url,
220
+ 'filters' => array(
221
+ 'page_builder' => array(
222
+ 'title' => __( 'Page Builder', 'astra-sites' ),
223
+ 'slug' => 'astra-site-page-builder',
224
+ 'trigger' => 'astra-api-category-loaded',
225
+ ),
226
+ 'categories' => array(
227
+ 'title' => __( 'Categories', 'astra-sites' ),
228
+ 'slug' => 'astra-site-category',
229
+ 'trigger' => 'astra-api-category-loaded',
230
+ ),
231
+ ),
232
+ )
233
+ );
234
+ wp_localize_script( 'astra-sites-api', 'astraSitesApi', $data );
235
+
236
+ // Use this for premium demos.
237
+ $request_params = apply_filters(
238
+ 'astra_sites_api_params',
239
+ array(
240
+ 'purchase_key' => '',
241
+ 'site_url' => '',
242
+ 'par-page' => 15,
243
+ )
244
+ );
245
+
246
+ $data = apply_filters(
247
+ 'astra_sites_render_localize_vars',
248
+ array(
249
+ 'sites' => $request_params,
250
+ 'page-builders' => array(),
251
+ 'categories' => array(),
252
+ 'settings' => array(),
253
+ 'default_page_builder' => Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ),
254
+ )
255
+ );
256
+
257
+ wp_localize_script( 'astra-sites-render-grid', 'astraRenderGrid', $data );
258
+
259
+ $data = apply_filters(
260
+ 'astra_sites_localize_vars',
261
+ array(
262
+ 'debug' => ( ( defined( 'WP_DEBUG' ) && WP_DEBUG ) || isset( $_GET['debug'] ) ) ? true : false,
263
+ 'isPro' => defined( 'ASTRA_PRO_SITES_NAME' ) ? true : false,
264
+ 'isWhiteLabeled' => Astra_Sites_White_Label::get_instance()->is_white_labeled(),
265
+ 'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ),
266
+ 'siteURL' => site_url(),
267
+ 'getProText' => __( 'Get Agency Bundle', 'astra-sites' ),
268
+ 'getProURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
269
+ 'getUpgradeText' => __( 'Upgrade', 'astra-sites' ),
270
+ 'getUpgradeURL' => esc_url( 'https://wpastra.com/agency/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=wp-dashboard' ),
271
+ '_ajax_nonce' => wp_create_nonce( 'astra-sites' ),
272
+ 'requiredPlugins' => array(),
273
+ 'XMLReaderDisabled' => ! class_exists( 'XMLReader' ) ? true : false,
274
+ 'strings' => array(
275
+ /* translators: %s are HTML tags. */
276
+ 'warningXMLReader' => sprintf( __( '%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra Sites import requires XMLReader extension to be installed. Please contact your web hosting provider and ask them to install and activate the XMLReader PHP extension.', 'astra-sites' ), '<div class="notice astra-sites-xml-notice notice-error"><p><b>', '</b></p><p>', '</p></div>' ),
277
+ 'warningBeforeCloseWindow' => __( 'Warning! Astra Site Import process is not complete. Don\'t close the window until import process complete. Do you still want to leave the window?', 'astra-sites' ),
278
+ 'importFailedBtnSmall' => __( 'Error!', 'astra-sites' ),
279
+ 'importFailedBtnLarge' => __( 'Error! Read Possibilities.', 'astra-sites' ),
280
+ 'importFailedURL' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=import-failed' ),
281
+ 'viewSite' => __( 'Done! View Site', 'astra-sites' ),
282
+ 'btnActivating' => __( 'Activating', 'astra-sites' ) . '&hellip;',
283
+ 'btnActive' => __( 'Active', 'astra-sites' ),
284
+ 'importFailBtn' => __( 'Import failed.', 'astra-sites' ),
285
+ 'importFailBtnLarge' => __( 'Import failed. See error log.', 'astra-sites' ),
286
+ 'importDemo' => __( 'Import This Site', 'astra-sites' ),
287
+ 'importingDemo' => __( 'Importing..', 'astra-sites' ),
288
+ 'DescExpand' => __( 'Read more', 'astra-sites' ) . '&hellip;',
289
+ 'DescCollapse' => __( 'Hide', 'astra-sites' ),
290
+ 'responseError' => __( 'There was a problem receiving a response from server.', 'astra-sites' ),
291
+ 'searchNoFound' => __( 'No Demos found, Try a different search.', 'astra-sites' ),
292
+ ),
293
+ 'log' => array(
294
+ 'installingPlugin' => __( 'Installing plugin ', 'astra-sites' ),
295
+ 'installed' => __( 'Successfully plugin installed!', 'astra-sites' ),
296
+ 'activating' => __( 'Activating plugin ', 'astra-sites' ),
297
+ 'activated' => __( 'Successfully plugin activated ', 'astra-sites' ),
298
+ 'bulkActivation' => __( 'Bulk plugin activation...', 'astra-sites' ),
299
+ 'activate' => __( 'Successfully plugin activate - ', 'astra-sites' ),
300
+ 'activationError' => __( 'Error! While activating plugin - ', 'astra-sites' ),
301
+ 'bulkInstall' => __( 'Bulk plugin installation...', 'astra-sites' ),
302
+ 'api' => __( 'Site API ', 'astra-sites' ),
303
+ 'importing' => __( 'Importing..', 'astra-sites' ),
304
+ 'processingRequest' => __( 'Processing requests...', 'astra-sites' ),
305
+ 'importCustomizer' => __( '2) Importing "Customizer Settings"...', 'astra-sites' ),
306
+ 'importCustomizerSuccess' => __( 'Successfully imported customizer settings!', 'astra-sites' ),
307
+ 'importWPForms' => __( '3) Importing "Contact Forms"...', 'astra-sites' ),
308
+ 'importWPFormsSuccess' => __( 'Successfully imported Contact Forms!', 'astra-sites' ),
309
+ 'importXMLPrepare' => __( '4) Preparing "XML" Data...', 'astra-sites' ),
310
+ 'importXMLPrepareSuccess' => __( 'Successfully set XML data!', 'astra-sites' ),
311
+ 'importXML' => __( '5) Importing "XML"...', 'astra-sites' ),
312
+ 'importXMLSuccess' => __( 'Successfully imported XML!', 'astra-sites' ),
313
+ 'importOptions' => __( '6) Importing "Options"...', 'astra-sites' ),
314
+ 'importOptionsSuccess' => __( 'Successfully imported Options!', 'astra-sites' ),
315
+ 'importWidgets' => __( '7) Importing "Widgets"...', 'astra-sites' ),
316
+ 'importWidgetsSuccess' => __( 'Successfully imported Widgets!', 'astra-sites' ),
317
+ 'serverConfiguration' => esc_url( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' ),
318
+ 'success' => __( 'Site imported successfully! visit : ', 'astra-sites' ),
319
+ 'gettingData' => __( 'Getting Site Information..', 'astra-sites' ),
320
+ 'importingCustomizer' => __( 'Importing Customizer Settings..', 'astra-sites' ),
321
+ 'importingWPForms' => __( 'Importing Contact Forms..', 'astra-sites' ),
322
+ 'importXMLPreparing' => __( 'Setting up import data..', 'astra-sites' ),
323
+ 'importingXML' => __( 'Importing Content..', 'astra-sites' ),
324
+ 'importingOptions' => __( 'Importing Site Options..', 'astra-sites' ),
325
+ 'importingWidgets' => __( 'Importing Widgets..', 'astra-sites' ),
326
+ 'importComplete' => __( 'Import Complete..', 'astra-sites' ),
327
+ 'preview' => __( 'Previewing ', 'astra-sites' ),
328
+ 'importLogText' => __( 'See Error Log &rarr;', 'astra-sites' ),
329
+ ),
330
+ )
331
+ );
332
+
333
+ wp_localize_script( 'astra-sites-admin-page', 'astraSitesAdmin', $data );
334
+
335
+ }
336
+
337
+ /**
338
+ * Load all the required files in the importer.
339
+ *
340
+ * @since 1.0.0
341
+ */
342
+ private function includes() {
343
+
344
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-notices.php';
345
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-page.php';
346
+ require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/class-astra-sites-compatibility.php';
347
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-white-label.php';
348
+ require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer.php';
349
+ }
350
+
351
+ /**
352
+ * Required Plugin Activate
353
+ *
354
+ * @since 1.0.0
355
+ */
356
+ public function required_plugin_activate() {
357
+
358
+ if ( ! current_user_can( 'install_plugins' ) || ! isset( $_POST['init'] ) || ! $_POST['init'] ) {
359
+ wp_send_json_error(
360
+ array(
361
+ 'success' => false,
362
+ 'message' => __( 'No plugin specified', 'astra-sites' ),
363
+ )
364
+ );
365
+ }
366
+
367
+ $data = array();
368
+ $plugin_init = ( isset( $_POST['init'] ) ) ? esc_attr( $_POST['init'] ) : '';
369
+ $astra_site_options = ( isset( $_POST['options'] ) ) ? json_decode( stripslashes( $_POST['options'] ) ) : '';
370
+ $enabled_extensions = ( isset( $_POST['enabledExtensions'] ) ) ? json_decode( stripslashes( $_POST['enabledExtensions'] ) ) : '';
371
+
372
+ $data['astra_site_options'] = $astra_site_options;
373
+ $data['enabled_extensions'] = $enabled_extensions;
374
+
375
+ $activate = activate_plugin( $plugin_init, '', false, true );
376
+
377
+ if ( is_wp_error( $activate ) ) {
378
+ wp_send_json_error(
379
+ array(
380
+ 'success' => false,
381
+ 'message' => $activate->get_error_message(),
382
+ )
383
+ );
384
+ }
385
+
386
+ do_action( 'astra_sites_after_plugin_activation', $plugin_init, $data );
387
+
388
+ wp_send_json_success(
389
+ array(
390
+ 'success' => true,
391
+ 'message' => __( 'Plugin Successfully Activated', 'astra-sites' ),
392
+ )
393
+ );
394
+
395
+ }
396
+
397
+ /**
398
+ * Required Plugin
399
+ *
400
+ * @since 1.0.0
401
+ * @return void
402
+ */
403
+ public function required_plugin() {
404
+
405
+ // Verify Nonce.
406
+ check_ajax_referer( 'astra-sites', '_ajax_nonce' );
407
+
408
+ $response = array(
409
+ 'active' => array(),
410
+ 'inactive' => array(),
411
+ 'notinstalled' => array(),
412
+ );
413
+
414
+ if ( ! current_user_can( 'customize' ) ) {
415
+ wp_send_json_error( $response );
416
+ }
417
+
418
+ $required_plugins = ( isset( $_POST['required_plugins'] ) ) ? $_POST['required_plugins'] : array();
419
+
420
+ if ( count( $required_plugins ) > 0 ) {
421
+ foreach ( $required_plugins as $key => $plugin ) {
422
+
423
+ /**
424
+ * Has Pro Version Support?
425
+ * And
426
+ * Is Pro Version Installed?
427
+ */
428
+ $plugin_pro = self::pro_plugin_exist( $plugin['init'] );
429
+ if ( $plugin_pro ) {
430
+
431
+ // Pro - Active.
432
+ if ( is_plugin_active( $plugin_pro['init'] ) ) {
433
+ $response['active'][] = $plugin_pro;
434
+
435
+ // Pro - Inactive.
436
+ } else {
437
+ $response['inactive'][] = $plugin_pro;
438
+ }
439
+ } else {
440
+
441
+ // Lite - Installed but Inactive.
442
+ if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) && is_plugin_inactive( $plugin['init'] ) ) {
443
+
444
+ $response['inactive'][] = $plugin;
445
+
446
+ // Lite - Not Installed.
447
+ } elseif ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin['init'] ) ) {
448
+
449
+ $response['notinstalled'][] = $plugin;
450
+
451
+ // Lite - Active.
452
+ } else {
453
+ $response['active'][] = $plugin;
454
+ }
455
+ }
456
+ }
457
+ }
458
+
459
+ // Send response.
460
+ wp_send_json_success( $response );
461
+ }
462
+
463
+ /**
464
+ * Has Pro Version Support?
465
+ * And
466
+ * Is Pro Version Installed?
467
+ *
468
+ * Check Pro plugin version exist of requested plugin lite version.
469
+ *
470
+ * Eg. If plugin 'BB Lite Version' required to import demo. Then we check the 'BB Agency Version' is exist?
471
+ * If yes then we only 'Activate' Agency Version. [We couldn't install agency version.]
472
+ * Else we 'Activate' or 'Install' Lite Version.
473
+ *
474
+ * @since 1.0.1
475
+ *
476
+ * @param string $lite_version Lite version init file.
477
+ * @return mixed Return false if not installed or not supported by us
478
+ * else return 'Pro' version details.
479
+ */
480
+ public static function pro_plugin_exist( $lite_version = '' ) {
481
+
482
+ // Lite init => Pro init.
483
+ $plugins = apply_filters(
484
+ 'astra_sites_pro_plugin_exist',
485
+ array(
486
+ 'beaver-builder-lite-version/fl-builder.php' => array(
487
+ 'slug' => 'bb-plugin',
488
+ 'init' => 'bb-plugin/fl-builder.php',
489
+ 'name' => 'Beaver Builder Plugin',
490
+ ),
491
+ 'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => array(
492
+ 'slug' => 'bb-ultimate-addon',
493
+ 'init' => 'bb-ultimate-addon/bb-ultimate-addon.php',
494
+ 'name' => 'Ultimate Addon for Beaver Builder',
495
+ ),
496
+ ),
497
+ $lite_version
498
+ );
499
+
500
+ if ( isset( $plugins[ $lite_version ] ) ) {
501
+
502
+ // Pro plugin directory exist?
503
+ if ( file_exists( WP_PLUGIN_DIR . '/' . $plugins[ $lite_version ]['init'] ) ) {
504
+ return $plugins[ $lite_version ];
505
+ }
506
+ }
507
+
508
+ return false;
509
+ }
510
+
511
+ }
512
+
513
+ /**
514
+ * Kicking this off by calling 'get_instance()' method
515
+ */
516
+ Astra_Sites::get_instance();
517
+
518
+ endif;
inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php CHANGED
@@ -1,302 +1,299 @@
1
- <?php
2
- /**
3
- * Astra Sites Compatibility for 'Astra Pro'
4
- *
5
- * @see https://wordpress.org/plugins/astra-pro/
6
- *
7
- * @package Astra Sites
8
- * @since 1.0.0
9
- */
10
-
11
- if ( ! class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) :
12
-
13
- /**
14
- * Astra_Sites_Compatibility_Astra_Pro
15
- *
16
- * @since 1.0.0
17
- */
18
- class Astra_Sites_Compatibility_Astra_Pro {
19
-
20
- /**
21
- * Instance
22
- *
23
- * @access private
24
- * @var object Class object.
25
- * @since 1.0.0
26
- */
27
- private static $instance;
28
-
29
- /**
30
- * Initiator
31
- *
32
- * @since 1.0.0
33
- * @return object initialized object of class.
34
- */
35
- public static function get_instance() {
36
- if ( ! isset( self::$instance ) ) {
37
- self::$instance = new self;
38
- }
39
- return self::$instance;
40
- }
41
-
42
- /**
43
- * Constructor
44
- *
45
- * @since 1.0.0
46
- */
47
- public function __construct() {
48
- add_action( 'astra_sites_after_plugin_activation', array( $this, 'astra_pro' ), 10, 2 );
49
- add_action( 'astra_sites_import_start', array( $this, 'import_enabled_extension' ), 10, 2 );
50
- add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
51
- }
52
-
53
- /**
54
- * Import
55
- *
56
- * @since 1.1.6
57
- * @return void
58
- */
59
- public function import() {
60
- Astra_Sites_Image_Importer::log( '---- Processing Mapping - for Astra Pro ----' );
61
-
62
- self::start_post_mapping();
63
- }
64
-
65
- /**
66
- * Update Site Origin Active Widgets
67
- *
68
- * @since 1.0.0
69
- *
70
- * @param string $plugin_init Plugin init file.
71
- * @param array $data Data.
72
- * @return void
73
- */
74
- function astra_pro( $plugin_init = '', $data = array() ) {
75
-
76
- if ( 'astra-addon/astra-addon.php' === $plugin_init ) {
77
-
78
- $data = json_decode( json_encode( $data ), true );
79
-
80
- if ( isset( $data['enabled_extensions'] ) ) {
81
- $extensions = $data['enabled_extensions'];
82
-
83
- if ( ! empty( $extensions ) ) {
84
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
85
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $extensions );
86
- }
87
- }
88
- }
89
- }
90
- }
91
-
92
- /**
93
- * Import custom 404 section.
94
- *
95
- * @since 1.0.0
96
- * @param array $demo_data Site all data render from API call.
97
- * @param array $demo_api_uri Demo URL.
98
- */
99
- public function import_custom_404( $demo_data = array(), $demo_api_uri = '' ) {
100
-
101
- if ( isset( $demo_data['astra-custom-404'] ) ) {
102
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
103
- $options_404 = $demo_data['astra-custom-404'];
104
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_custom_404', $options_404 );
105
- }
106
- }
107
- }
108
-
109
- /**
110
- * Import settings enabled Astra extensions from the demo.
111
- *
112
- * @since 1.0.0
113
- * @param array $demo_data Site all data render from API call.
114
- * @param array $demo_api_uri Demo URL.
115
- */
116
- public function import_enabled_extension( $demo_data = array(), $demo_api_uri = '' ) {
117
-
118
- if ( isset( $demo_data['astra-enabled-extensions'] ) ) {
119
- if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
120
- Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $demo_data['astra-enabled-extensions'] );
121
- }
122
- }
123
- }
124
-
125
- /**
126
- * Start post meta mapping of Astra Addon
127
- *
128
- * @since 1.1.6
129
- *
130
- * @return null If there is no import option data found.
131
- */
132
- public static function start_post_mapping() {
133
- $demo_data = get_option( 'astra_sites_import_data', array() );
134
- if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
135
- return;
136
- }
137
-
138
- $post_type = 'astra-advanced-hook';
139
- $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
140
- if ( ! empty( $posts ) ) {
141
- foreach ( $posts as $key => $post ) {
142
- $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
143
- if ( is_object( $page ) ) {
144
- self::update_location_rules( $page->ID, 'ast-advanced-hook-location', $post['mapping']['ast-advanced-hook-location'] );
145
- }
146
- }
147
- }
148
-
149
- $post_type = 'astra_adv_header';
150
- $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
151
- if ( ! empty( $posts ) ) {
152
- foreach ( $posts as $key => $post ) {
153
- $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
154
- if ( is_object( $page ) ) {
155
-
156
- self::update_location_rules( $page->ID, 'ast-advanced-headers-location', $post['mapping']['ast-advanced-headers-location'] );
157
- self::update_location_rules( $page->ID, 'ast-advanced-headers-exclusion', $post['mapping']['ast-advanced-headers-exclusion'] );
158
- self::update_header_mapping( $page->ID, 'ast-advanced-headers-design', $post['mapping']['ast-advanced-headers-design'] );
159
- }
160
- }
161
- }
162
- }
163
-
164
- /**
165
- * Update Header Mapping Data
166
- *
167
- * @since 1.1.6
168
- *
169
- * @param int $post_id Post ID.
170
- * @param string $meta_key Post meta key.
171
- * @param array $mapping Mapping array.
172
- * @return void
173
- */
174
- public static function update_header_mapping( $post_id = '', $meta_key = '', $mapping = array() ) {
175
- Astra_Sites_Image_Importer::log( 'Mapping "' . $meta_key . '" for ' . $post_id );
176
-
177
- $headers_old = get_post_meta( $post_id, $meta_key, true );
178
- $headers_new = self::get_header_mapping( $headers_old, $mapping );
179
- update_post_meta( $post_id, $meta_key, $headers_new );
180
- }
181
-
182
- /**
183
- * Update Location Rules
184
- *
185
- * @since 1.1.6
186
- *
187
- * @param int $post_id Post ID.
188
- * @param string $meta_key Post meta key.
189
- * @param array $mapping Mapping array.
190
- * @return void
191
- */
192
- public static function update_location_rules( $post_id = '', $meta_key = '', $mapping = array() ) {
193
- Astra_Sites_Image_Importer::log( 'Mapping "' . $meta_key . '" for ' . $post_id );
194
-
195
- $location_new = self::get_location_mappings( $mapping );
196
- update_post_meta( $post_id, $meta_key, $location_new );
197
- }
198
-
199
- /**
200
- * Get mapping locations.
201
- *
202
- * @since 1.1.6
203
- *
204
- * @param array $location Location data.
205
- * @return array Location mapping data.
206
- */
207
- public static function get_location_mappings( $location = array() ) {
208
- if ( empty( $location ) ) {
209
- return $location;
210
- }
211
-
212
- if ( ! isset( $location['specific'] ) || empty( $location['specific'] ) ) {
213
- return $location;
214
- }
215
-
216
- $mapping = array();
217
-
218
- if ( isset( $location['specific']['post'] ) ) {
219
- foreach ( $location['specific']['post'] as $post_type => $old_post_data ) {
220
- if ( is_array( $old_post_data ) ) {
221
- foreach ( $old_post_data as $post_key => $post ) {
222
- if ( $post_object = get_page_by_path( $post['slug'] ) ) {
223
- $mapping[] = 'post-' . absint( $post_object->ID );
224
- }
225
- }
226
- }
227
- }
228
- }
229
-
230
- if ( isset( $location['specific']['tax'] ) ) {
231
- foreach ( $location['specific']['tax'] as $taxonomy_type => $old_term_data ) {
232
- if ( is_array( $old_term_data ) ) {
233
- foreach ( $old_term_data as $term_key => $term_data ) {
234
- $term = get_term_by( 'slug', $term_data['slug'], $taxonomy_type );
235
- if ( is_object( $term ) ) {
236
- $mapping[] = 'tax-' . absint( $term->term_id );
237
- }
238
- }
239
- }
240
- }
241
- }
242
-
243
- $location['specific'] = $mapping;
244
-
245
- return $location;
246
- }
247
-
248
- /**
249
- * Get advanced header mapping data
250
- *
251
- * @since 1.1.6
252
- *
253
- * @param array $headers_old Header mapping stored data.
254
- * @param array $headers_data Header mapping data.
255
- * @return array Filtered header mapping data.
256
- */
257
- public static function get_header_mapping( $headers_old = array(), $headers_data = array() ) {
258
-
259
- // Set menu location by menu slug.
260
- if ( isset( $headers_data['menus'] ) && ! empty( $headers_data['menus'] ) ) {
261
- foreach ( $headers_data['menus'] as $header_option_name => $menu_data ) {
262
- $term = get_term_by( 'slug', $menu_data['slug'], 'nav_menu' );
263
- if ( is_object( $term ) ) {
264
- $headers_old[ $header_option_name ] = $term->term_id;
265
- }
266
- }
267
- }
268
-
269
- // Set image ID & URL after importing these on website.
270
- if ( isset( $headers_data['images'] ) && ! empty( $headers_data['images'] ) ) {
271
- foreach ( $headers_data['images'] as $key => $image_data ) {
272
- if ( isset( $image_data['image'] ) && ! empty( $image_data['image'] ) ) {
273
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image_data['image'] );
274
-
275
- $headers_old[ $image_data['key_map']['url'] ] = $downloaded_image['url'];
276
- $headers_old[ $image_data['key_map']['id'] ] = $downloaded_image['id'];
277
- }
278
- }
279
- }
280
-
281
- return $headers_old;
282
- }
283
-
284
- /**
285
- * Clear Cache
286
- *
287
- * @since 1.2.3
288
- * @return void
289
- */
290
- function clear_cache() {
291
- if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
292
- Astra_Minify::refresh_assets();
293
- }
294
- }
295
- }
296
-
297
- /**
298
- * Kicking this off by calling 'get_instance()' method
299
- */
300
- Astra_Sites_Compatibility_Astra_Pro::get_instance();
301
-
302
- endif;
1
+ <?php
2
+ /**
3
+ * Astra Sites Compatibility for 'Astra Pro'
4
+ *
5
+ * @see https://wordpress.org/plugins/astra-pro/
6
+ *
7
+ * @package Astra Sites
8
+ * @since 1.0.0
9
+ */
10
+
11
+ if ( ! class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) :
12
+
13
+ /**
14
+ * Astra_Sites_Compatibility_Astra_Pro
15
+ *
16
+ * @since 1.0.0
17
+ */
18
+ class Astra_Sites_Compatibility_Astra_Pro {
19
+
20
+ /**
21
+ * Instance
22
+ *
23
+ * @access private
24
+ * @var object Class object.
25
+ * @since 1.0.0
26
+ */
27
+ private static $instance;
28
+
29
+ /**
30
+ * Initiator
31
+ *
32
+ * @since 1.0.0
33
+ * @return object initialized object of class.
34
+ */
35
+ public static function get_instance() {
36
+ if ( ! isset( self::$instance ) ) {
37
+ self::$instance = new self;
38
+ }
39
+ return self::$instance;
40
+ }
41
+
42
+ /**
43
+ * Constructor
44
+ *
45
+ * @since 1.0.0
46
+ */
47
+ public function __construct() {
48
+ add_action( 'astra_sites_after_plugin_activation', array( $this, 'astra_pro' ), 10, 2 );
49
+ add_action( 'astra_sites_import_start', array( $this, 'import_enabled_extension' ), 10, 2 );
50
+ add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
51
+ }
52
+
53
+ /**
54
+ * Import
55
+ *
56
+ * @since 1.1.6
57
+ * @return void
58
+ */
59
+ public function import() {
60
+ Astra_Sites_Image_Importer::log( '---- Processing Mapping - for Astra Pro ----' );
61
+ self::start_post_mapping();
62
+ }
63
+
64
+ /**
65
+ * Update Site Origin Active Widgets
66
+ *
67
+ * @since 1.0.0
68
+ *
69
+ * @param string $plugin_init Plugin init file.
70
+ * @param array $data Data.
71
+ * @return void
72
+ */
73
+ function astra_pro( $plugin_init = '', $data = array() ) {
74
+
75
+ if ( 'astra-addon/astra-addon.php' === $plugin_init ) {
76
+
77
+ $data = json_decode( json_encode( $data ), true );
78
+
79
+ if ( isset( $data['enabled_extensions'] ) ) {
80
+ $extensions = $data['enabled_extensions'];
81
+
82
+ if ( ! empty( $extensions ) ) {
83
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
84
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $extensions );
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Import custom 404 section.
93
+ *
94
+ * @since 1.0.0
95
+ * @param array $demo_data Site all data render from API call.
96
+ * @param array $demo_api_uri Demo URL.
97
+ */
98
+ public function import_custom_404( $demo_data = array(), $demo_api_uri = '' ) {
99
+
100
+ if ( isset( $demo_data['astra-custom-404'] ) ) {
101
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
102
+ $options_404 = $demo_data['astra-custom-404'];
103
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_custom_404', $options_404 );
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Import settings enabled Astra extensions from the demo.
110
+ *
111
+ * @since 1.0.0
112
+ * @param array $demo_data Site all data render from API call.
113
+ * @param array $demo_api_uri Demo URL.
114
+ */
115
+ public function import_enabled_extension( $demo_data = array(), $demo_api_uri = '' ) {
116
+
117
+ if ( isset( $demo_data['astra-enabled-extensions'] ) ) {
118
+ if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
119
+ Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $demo_data['astra-enabled-extensions'] );
120
+ }
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Start post meta mapping of Astra Addon
126
+ *
127
+ * @since 1.1.6
128
+ *
129
+ * @return null If there is no import option data found.
130
+ */
131
+ public static function start_post_mapping() {
132
+ $demo_data = get_option( 'astra_sites_import_data', array() );
133
+ if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
134
+ return;
135
+ }
136
+
137
+ $post_type = 'astra-advanced-hook';
138
+ $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
139
+ if ( ! empty( $posts ) ) {
140
+ foreach ( $posts as $key => $post ) {
141
+ $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
142
+ if ( is_object( $page ) ) {
143
+ self::update_location_rules( $page->ID, 'ast-advanced-hook-location', $post['mapping']['ast-advanced-hook-location'] );
144
+ }
145
+ }
146
+ }
147
+
148
+ $post_type = 'astra_adv_header';
149
+ $posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
150
+ if ( ! empty( $posts ) ) {
151
+ foreach ( $posts as $key => $post ) {
152
+ $page = get_page_by_title( $post['post_title'], OBJECT, $post_type );
153
+ if ( is_object( $page ) ) {
154
+
155
+ self::update_location_rules( $page->ID, 'ast-advanced-headers-location', $post['mapping']['ast-advanced-headers-location'] );
156
+ self::update_location_rules( $page->ID, 'ast-advanced-headers-exclusion', $post['mapping']['ast-advanced-headers-exclusion'] );
157
+ self::update_header_mapping( $page->ID, 'ast-advanced-headers-design', $post['mapping']['ast-advanced-headers-design'] );
158
+ }
159
+ }
160
+ }
161
+ }
162
+
163
+ /**
164
+ * Update Header Mapping Data
165
+ *
166
+ * @since 1.1.6
167
+ *
168
+ * @param int $post_id Post ID.
169
+ * @param string $meta_key Post meta key.
170
+ * @param array $mapping Mapping array.
171
+ * @return void
172
+ */
173
+ public static function update_header_mapping( $post_id = '', $meta_key = '', $mapping = array() ) {
174
+ Astra_Sites_Image_Importer::log( 'Mapping "' . $meta_key . '" for ' . $post_id );
175
+ $headers_old = get_post_meta( $post_id, $meta_key, true );
176
+ $headers_new = self::get_header_mapping( $headers_old, $mapping );
177
+ update_post_meta( $post_id, $meta_key, $headers_new );
178
+ }
179
+
180
+ /**
181
+ * Update Location Rules
182
+ *
183
+ * @since 1.1.6
184
+ *
185
+ * @param int $post_id Post ID.
186
+ * @param string $meta_key Post meta key.
187
+ * @param array $mapping Mapping array.
188
+ * @return void
189
+ */
190
+ public static function update_location_rules( $post_id = '', $meta_key = '', $mapping = array() ) {
191
+ Astra_Sites_Image_Importer::log( 'Mapping "' . $meta_key . '" for ' . $post_id );
192
+ $location_new = self::get_location_mappings( $mapping );
193
+ update_post_meta( $post_id, $meta_key, $location_new );
194
+ }
195
+
196
+ /**
197
+ * Get mapping locations.
198
+ *
199
+ * @since 1.1.6
200
+ *
201
+ * @param array $location Location data.
202
+ * @return array Location mapping data.
203
+ */
204
+ public static function get_location_mappings( $location = array() ) {
205
+ if ( empty( $location ) ) {
206
+ return $location;
207
+ }
208
+
209
+ if ( ! isset( $location['specific'] ) || empty( $location['specific'] ) ) {
210
+ return $location;
211
+ }
212
+
213
+ $mapping = array();
214
+
215
+ if ( isset( $location['specific']['post'] ) ) {
216
+ foreach ( $location['specific']['post'] as $post_type => $old_post_data ) {
217
+ if ( is_array( $old_post_data ) ) {
218
+ foreach ( $old_post_data as $post_key => $post ) {
219
+ if ( $post_object = get_page_by_path( $post['slug'] ) ) {
220
+ $mapping[] = 'post-' . absint( $post_object->ID );
221
+ }
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ if ( isset( $location['specific']['tax'] ) ) {
228
+ foreach ( $location['specific']['tax'] as $taxonomy_type => $old_term_data ) {
229
+ if ( is_array( $old_term_data ) ) {
230
+ foreach ( $old_term_data as $term_key => $term_data ) {
231
+ $term = get_term_by( 'slug', $term_data['slug'], $taxonomy_type );
232
+ if ( is_object( $term ) ) {
233
+ $mapping[] = 'tax-' . absint( $term->term_id );
234
+ }
235
+ }
236
+ }
237
+ }
238
+ }
239
+
240
+ $location['specific'] = $mapping;
241
+
242
+ return $location;
243
+ }
244
+
245
+ /**
246
+ * Get advanced header mapping data
247
+ *
248
+ * @since 1.1.6
249
+ *
250
+ * @param array $headers_old Header mapping stored data.
251
+ * @param array $headers_data Header mapping data.
252
+ * @return array Filtered header mapping data.
253
+ */
254
+ public static function get_header_mapping( $headers_old = array(), $headers_data = array() ) {
255
+
256
+ // Set menu location by menu slug.
257
+ if ( isset( $headers_data['menus'] ) && ! empty( $headers_data['menus'] ) ) {
258
+ foreach ( $headers_data['menus'] as $header_option_name => $menu_data ) {
259
+ $term = get_term_by( 'slug', $menu_data['slug'], 'nav_menu' );
260
+ if ( is_object( $term ) ) {
261
+ $headers_old[ $header_option_name ] = $term->term_id;
262
+ }
263
+ }
264
+ }
265
+
266
+ // Set image ID & URL after importing these on website.
267
+ if ( isset( $headers_data['images'] ) && ! empty( $headers_data['images'] ) ) {
268
+ foreach ( $headers_data['images'] as $key => $image_data ) {
269
+ if ( isset( $image_data['image'] ) && ! empty( $image_data['image'] ) ) {
270
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image_data['image'] );
271
+
272
+ $headers_old[ $image_data['key_map']['url'] ] = $downloaded_image['url'];
273
+ $headers_old[ $image_data['key_map']['id'] ] = $downloaded_image['id'];
274
+ }
275
+ }
276
+ }
277
+
278
+ return $headers_old;
279
+ }
280
+
281
+ /**
282
+ * Clear Cache
283
+ *
284
+ * @since 1.2.3
285
+ * @return void
286
+ */
287
+ function clear_cache() {
288
+ if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
289
+ Astra_Minify::refresh_assets();
290
+ }
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Kicking this off by calling 'get_instance()' method
296
+ */
297
+ Astra_Sites_Compatibility_Astra_Pro::get_instance();
298
+
299
+ endif;
 
 
 
inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php CHANGED
@@ -1,263 +1,261 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Beaver_Builder
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing_Beaver_Builder {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.14
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.0.14
45
- */
46
- public function __construct() {
47
- }
48
-
49
- /**
50
- * Import
51
- *
52
- * @since 1.0.14
53
- * @return void
54
- */
55
- public function import() {
56
-
57
- Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
58
-
59
- if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
60
- return;
61
- }
62
-
63
- $post_types = FLBuilderModel::get_post_types( 'post-types' );
64
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
65
- return;
66
- }
67
-
68
- $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
69
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
70
- return;
71
- }
72
-
73
- foreach ( $post_ids as $post_id ) {
74
- $is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
75
- if ( $is_bb_post ) {
76
- $this->import_single_post( $post_id );
77
- }
78
- }
79
- }
80
-
81
- /**
82
- * Update post meta.
83
- *
84
- * @param integer $post_id Post ID.
85
- * @return void
86
- */
87
- public function import_single_post( $post_id = 0 ) {
88
-
89
- Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
90
-
91
- if ( ! empty( $post_id ) ) {
92
-
93
- // Get page builder data.
94
- $data = get_post_meta( $post_id, '_fl_builder_data', true );
95
-
96
- if ( ! empty( $data ) ) {
97
- foreach ( $data as $key => $el ) {
98
-
99
- // Update 'row' images.
100
- if ( 'row' === $el->type ) {
101
- $data[ $key ]->settings = self::update_row( $el->settings );
102
- }
103
-
104
- // Update 'module' images.
105
- if ( 'module' === $el->type ) {
106
- $data[ $key ]->settings = self::update_module( $el->settings );
107
- }
108
-
109
- // Update 'column' images.
110
- if ( 'column' === $el->type ) {
111
- $data[ $key ]->settings = self::update_column( $el->settings );
112
- }
113
- }
114
-
115
- // Update page builder data.
116
- update_post_meta( $post_id, '_fl_builder_data', $data );
117
- update_post_meta( $post_id, '_fl_builder_draft', $data );
118
-
119
- // Clear all cache.
120
- FLBuilderModel::delete_asset_cache_for_all_posts();
121
- }
122
- }
123
-
124
- }
125
-
126
- /**
127
- * Import Module Images.
128
- *
129
- * @param object $settings Module settings object.
130
- * @return object
131
- */
132
- public static function update_module( $settings ) {
133
-
134
- // 1) Set photos.
135
- $settings = self::import_photo( $settings );
136
-
137
- /**
138
- * 2) Set `$settings->data` for Only type 'image-icon'
139
- *
140
- * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
141
- */
142
- if (
143
- isset( $settings->data ) &&
144
- isset( $settings->photo ) && ! empty( $settings->photo ) &&
145
- 'image-icon' === $settings->type
146
- ) {
147
- $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
148
- }
149
-
150
- // 3) Set `list item` module images.
151
- if ( isset( $settings->add_list_item ) ) {
152
- foreach ( $settings->add_list_item as $key => $value ) {
153
- $settings->add_list_item[ $key ] = self::import_photo( $value );
154
- }
155
- }
156
-
157
- // 4) Set `list item` module images.
158
- if ( isset( $settings->text ) ) {
159
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
160
- if ( $ids_mapping ) {
161
-
162
- // Keep old data in temp.
163
- $updated_data = $settings->text;
164
-
165
- // Update WP form IDs.
166
- foreach ( $ids_mapping as $old_id => $new_id ) {
167
- $updated_data = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $updated_data );
168
- }
169
-
170
- // Update modified data.
171
- $settings->text = $updated_data;
172
- }
173
- }
174
-
175
- return $settings;
176
- }
177
-
178
- /**
179
- * Import Column Images.
180
- *
181
- * @param object $settings Column settings object.
182
- * @return object
183
- */
184
- public static function update_column( $settings ) {
185
-
186
- // 1) Set BG Images.
187
- $settings = self::import_bg_image( $settings );
188
-
189
- return $settings;
190
- }
191
-
192
- /**
193
- * Import Row Images.
194
- *
195
- * @param object $settings Row settings object.
196
- * @return object
197
- */
198
- public static function update_row( $settings ) {
199
-
200
- // 1) Set BG Images.
201
- $settings = self::import_bg_image( $settings );
202
-
203
- return $settings;
204
- }
205
-
206
- /**
207
- * Helper: Import BG Images.
208
- *
209
- * @param object $settings Row settings object.
210
- * @return object
211
- */
212
- public static function import_bg_image( $settings ) {
213
-
214
- if (
215
- ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
216
- ) {
217
- $image = array(
218
- 'url' => $settings->bg_image_src,
219
- 'id' => $settings->bg_image,
220
- );
221
-
222
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
223
-
224
- $settings->bg_image_src = $downloaded_image['url'];
225
- $settings->bg_image = $downloaded_image['id'];
226
- }
227
-
228
- return $settings;
229
- }
230
-
231
- /**
232
- * Helper: Import Photo.
233
- *
234
- * @param object $settings Row settings object.
235
- * @return object
236
- */
237
- public static function import_photo( $settings ) {
238
-
239
- if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
240
-
241
- $image = array(
242
- 'url' => $settings->photo_src,
243
- 'id' => $settings->photo,
244
- );
245
-
246
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
247
-
248
- $settings->photo_src = $downloaded_image['url'];
249
- $settings->photo = $downloaded_image['id'];
250
- }
251
-
252
- return $settings;
253
- }
254
-
255
-
256
- }
257
-
258
- /**
259
- * Kicking this off by calling 'get_instance()' method
260
- */
261
- Astra_Sites_Batch_Processing_Beaver_Builder::get_instance();
262
-
263
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Beaver_Builder
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Beaver_Builder {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.14
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.0.14
45
+ */
46
+ public function __construct() {
47
+ }
48
+
49
+ /**
50
+ * Import
51
+ *
52
+ * @since 1.0.14
53
+ * @return void
54
+ */
55
+ public function import() {
56
+
57
+ Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
58
+ if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
59
+ return;
60
+ }
61
+
62
+ $post_types = FLBuilderModel::get_post_types( 'post-types' );
63
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
64
+ return;
65
+ }
66
+
67
+ $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
68
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
69
+ return;
70
+ }
71
+
72
+ foreach ( $post_ids as $post_id ) {
73
+ $is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
74
+ if ( $is_bb_post ) {
75
+ $this->import_single_post( $post_id );
76
+ }
77
+ }
78
+ }
79
+
80
+ /**
81
+ * Update post meta.
82
+ *
83
+ * @param integer $post_id Post ID.
84
+ * @return void
85
+ */
86
+ public function import_single_post( $post_id = 0 ) {
87
+
88
+ Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
89
+ if ( ! empty( $post_id ) ) {
90
+
91
+ // Get page builder data.
92
+ $data = get_post_meta( $post_id, '_fl_builder_data', true );
93
+
94
+ if ( ! empty( $data ) ) {
95
+ foreach ( $data as $key => $el ) {
96
+
97
+ // Update 'row' images.
98
+ if ( 'row' === $el->type ) {
99
+ $data[ $key ]->settings = self::update_row( $el->settings );
100
+ }
101
+
102
+ // Update 'module' images.
103
+ if ( 'module' === $el->type ) {
104
+ $data[ $key ]->settings = self::update_module( $el->settings );
105
+ }
106
+
107
+ // Update 'column' images.
108
+ if ( 'column' === $el->type ) {
109
+ $data[ $key ]->settings = self::update_column( $el->settings );
110
+ }
111
+ }
112
+
113
+ // Update page builder data.
114
+ update_post_meta( $post_id, '_fl_builder_data', $data );
115
+ update_post_meta( $post_id, '_fl_builder_draft', $data );
116
+
117
+ // Clear all cache.
118
+ FLBuilderModel::delete_asset_cache_for_all_posts();
119
+ }
120
+ }
121
+
122
+ }
123
+
124
+ /**
125
+ * Import Module Images.
126
+ *
127
+ * @param object $settings Module settings object.
128
+ * @return object
129
+ */
130
+ public static function update_module( $settings ) {
131
+
132
+ // 1) Set photos.
133
+ $settings = self::import_photo( $settings );
134
+
135
+ /**
136
+ * 2) Set `$settings->data` for Only type 'image-icon'
137
+ *
138
+ * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
139
+ */
140
+ if (
141
+ isset( $settings->data ) &&
142
+ isset( $settings->photo ) && ! empty( $settings->photo ) &&
143
+ 'image-icon' === $settings->type
144
+ ) {
145
+ $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
146
+ }
147
+
148
+ // 3) Set `list item` module images.
149
+ if ( isset( $settings->add_list_item ) ) {
150
+ foreach ( $settings->add_list_item as $key => $value ) {
151
+ $settings->add_list_item[ $key ] = self::import_photo( $value );
152
+ }
153
+ }
154
+
155
+ // 4) Set `list item` module images.
156
+ if ( isset( $settings->text ) ) {
157
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
158
+ if ( $ids_mapping ) {
159
+
160
+ // Keep old data in temp.
161
+ $updated_data = $settings->text;
162
+
163
+ // Update WP form IDs.
164
+ foreach ( $ids_mapping as $old_id => $new_id ) {
165
+ $updated_data = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $updated_data );
166
+ }
167
+
168
+ // Update modified data.
169
+ $settings->text = $updated_data;
170
+ }
171
+ }
172
+
173
+ return $settings;
174
+ }
175
+
176
+ /**
177
+ * Import Column Images.
178
+ *
179
+ * @param object $settings Column settings object.
180
+ * @return object
181
+ */
182
+ public static function update_column( $settings ) {
183
+
184
+ // 1) Set BG Images.
185
+ $settings = self::import_bg_image( $settings );
186
+
187
+ return $settings;
188
+ }
189
+
190
+ /**
191
+ * Import Row Images.
192
+ *
193
+ * @param object $settings Row settings object.
194
+ * @return object
195
+ */
196
+ public static function update_row( $settings ) {
197
+
198
+ // 1) Set BG Images.
199
+ $settings = self::import_bg_image( $settings );
200
+
201
+ return $settings;
202
+ }
203
+
204
+ /**
205
+ * Helper: Import BG Images.
206
+ *
207
+ * @param object $settings Row settings object.
208
+ * @return object
209
+ */
210
+ public static function import_bg_image( $settings ) {
211
+
212
+ if (
213
+ ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
214
+ ) {
215
+ $image = array(
216
+ 'url' => $settings->bg_image_src,
217
+ 'id' => $settings->bg_image,
218
+ );
219
+
220
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
221
+
222
+ $settings->bg_image_src = $downloaded_image['url'];
223
+ $settings->bg_image = $downloaded_image['id'];
224
+ }
225
+
226
+ return $settings;
227
+ }
228
+
229
+ /**
230
+ * Helper: Import Photo.
231
+ *
232
+ * @param object $settings Row settings object.
233
+ * @return object
234
+ */
235
+ public static function import_photo( $settings ) {
236
+
237
+ if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
238
+
239
+ $image = array(
240
+ 'url' => $settings->photo_src,
241
+ 'id' => $settings->photo,
242
+ );
243
+
244
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
245
+
246
+ $settings->photo_src = $downloaded_image['url'];
247
+ $settings->photo = $downloaded_image['id'];
248
+ }
249
+
250
+ return $settings;
251
+ }
252
+
253
+
254
+ }
255
+
256
+ /**
257
+ * Kicking this off by calling 'get_instance()' method
258
+ */
259
+ Astra_Sites_Batch_Processing_Beaver_Builder::get_instance();
260
+
261
+ endif;
 
 
inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php CHANGED
@@ -1,126 +1,125 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.2.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) :
10
-
11
- /**
12
- * Astra Sites Batch Processing Brizy
13
- *
14
- * @since 1.2.14
15
- */
16
- class Astra_Sites_Batch_Processing_Brizy {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.2.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.2.14
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.2.14
45
- */
46
- public function __construct() {}
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.2.14
52
- * @return void
53
- */
54
- public function import() {
55
-
56
- Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for "Brizy" ----' );
57
-
58
- if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) {
59
- return;
60
- }
61
-
62
- $post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' );
63
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
64
- return;
65
- }
66
-
67
- $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
68
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
69
- return;
70
- }
71
-
72
- foreach ( $post_ids as $post_id ) {
73
- $is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true );
74
- if ( $is_brizy_post ) {
75
- $this->import_single_post( $post_id );
76
- }
77
- }
78
- }
79
-
80
- /**
81
- * Update post meta.
82
- *
83
- * @param integer $post_id Post ID.
84
- * @return void
85
- */
86
- public function import_single_post( $post_id = 0 ) {
87
-
88
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
89
-
90
- // Empty mapping? Then return.
91
- if ( empty( $ids_mapping ) ) {
92
- return;
93
- }
94
-
95
- $json_value = null;
96
-
97
- $post = Brizy_Editor_Post::get( (int) $post_id );
98
- $data = $post->storage()->get( Brizy_Editor_Post::BRIZY_POST, false );
99
-
100
- // Decode current data.
101
- $json_value = base64_decode( $data['editor_data'] );
102
-
103
- // Update WPForm IDs.
104
- foreach ( $ids_mapping as $old_id => $new_id ) {
105
- $json_value = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $json_value );
106
- }
107
-
108
- // Encode modified data.
109
- $data['editor_data'] = base64_encode( $json_value );
110
-
111
- $post->set_editor_data( $json_value );
112
-
113
- $post->storage()->set( Brizy_Editor_Post::BRIZY_POST, $data );
114
-
115
- $post->compile_page();
116
- $post->save();
117
- }
118
-
119
- }
120
-
121
- /**
122
- * Kicking this off by calling 'get_instance()' method
123
- */
124
- Astra_Sites_Batch_Processing_Brizy::get_instance();
125
-
126
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.2.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) :
10
+
11
+ /**
12
+ * Astra Sites Batch Processing Brizy
13
+ *
14
+ * @since 1.2.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Brizy {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.2.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.2.14
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.2.14
45
+ */
46
+ public function __construct() {}
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.2.14
52
+ * @return void
53
+ */
54
+ public function import() {
55
+
56
+ Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for "Brizy" ----' );
57
+ if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) {
58
+ return;
59
+ }
60
+
61
+ $post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' );
62
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
63
+ return;
64
+ }
65
+
66
+ $post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
67
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
68
+ return;
69
+ }
70
+
71
+ foreach ( $post_ids as $post_id ) {
72
+ $is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true );
73
+ if ( $is_brizy_post ) {
74
+ $this->import_single_post( $post_id );
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Update post meta.
81
+ *
82
+ * @param integer $post_id Post ID.
83
+ * @return void
84
+ */
85
+ public function import_single_post( $post_id = 0 ) {
86
+
87
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
88
+
89
+ // Empty mapping? Then return.
90
+ if ( empty( $ids_mapping ) ) {
91
+ return;
92
+ }
93
+
94
+ $json_value = null;
95
+
96
+ $post = Brizy_Editor_Post::get( (int) $post_id );
97
+ $data = $post->storage()->get( Brizy_Editor_Post::BRIZY_POST, false );
98
+
99
+ // Decode current data.
100
+ $json_value = base64_decode( $data['editor_data'] );
101
+
102
+ // Update WPForm IDs.
103
+ foreach ( $ids_mapping as $old_id => $new_id ) {
104
+ $json_value = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $json_value );
105
+ }
106
+
107
+ // Encode modified data.
108
+ $data['editor_data'] = base64_encode( $json_value );
109
+
110
+ $post->set_editor_data( $json_value );
111
+
112
+ $post->storage()->set( Brizy_Editor_Post::BRIZY_POST, $data );
113
+
114
+ $post->compile_page();
115
+ $post->save();
116
+ }
117
+
118
+ }
119
+
120
+ /**
121
+ * Kicking this off by calling 'get_instance()' method
122
+ */
123
+ Astra_Sites_Batch_Processing_Brizy::get_instance();
124
+
125
+ endif;
 
inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php CHANGED
@@ -1,113 +1,111 @@
1
- <?php
2
- /**
3
- * Elementor Importer
4
- *
5
- * @package Astra Sites
6
- */
7
-
8
- namespace Elementor\TemplateLibrary;
9
-
10
- if ( ! defined( 'ABSPATH' ) ) {
11
- exit; // Exit if accessed directly.
12
- }
13
-
14
- // If plugin - 'Elementor' not exist then return.
15
- if ( ! class_exists( '\Elementor\Plugin' ) ) {
16
- return;
17
- }
18
-
19
- use Elementor\Core\Base\Document;
20
- use Elementor\DB;
21
- use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
22
- use Elementor\Core\Settings\Manager as SettingsManager;
23
- use Elementor\Core\Settings\Page\Model;
24
- use Elementor\Editor;
25
- use Elementor\Plugin;
26
- use Elementor\Settings;
27
- use Elementor\Utils;
28
-
29
- /**
30
- * Elementor template library local source.
31
- *
32
- * Elementor template library local source handler class is responsible for
33
- * handling local Elementor templates saved by the user locally on his site.
34
- *
35
- * @since 1.2.13 Added compatibility for Elemetnor v2.5.0
36
- * @since 1.0.0
37
- */
38
- class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
39
-
40
- /**
41
- * Import
42
- *
43
- * @since 1.0.14
44
- * @return void
45
- */
46
- public function import() {
47
-
48
- \Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Elementor ----' );
49
-
50
- $post_types = get_option( 'elementor_cpt_support', array( 'page', 'post' ) );
51
- if ( empty( $post_types ) && ! is_array( $post_types ) ) {
52
- return;
53
- }
54
-
55
- $post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types );
56
- if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
57
- return;
58
- }
59
-
60
- foreach ( $post_ids as $post_id ) {
61
- $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true );
62
- if ( $is_elementor_post ) {
63
- $this->import_single_post( $post_id );
64
- }
65
- }
66
- }
67
- /**
68
- * Update post meta.
69
- *
70
- * @since 1.0.14
71
- * @param integer $post_id Post ID.
72
- * @return void
73
- */
74
- public function import_single_post( $post_id = 0 ) {
75
-
76
- \Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
77
-
78
- if ( ! empty( $post_id ) ) {
79
-
80
- $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
81
-
82
- if ( empty( $hotlink_imported ) ) {
83
-
84
- $data = get_post_meta( $post_id, '_elementor_data', true );
85
-
86
- if ( ! empty( $data ) ) {
87
-
88
- // Update WP form IDs.
89
- $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
90
- if ( $ids_mapping ) {
91
- foreach ( $ids_mapping as $old_id => $new_id ) {
92
- $data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data );
93
- }
94
- }
95
-
96
- $data = add_magic_quotes( $data );
97
- $data = json_decode( $data, true );
98
-
99
- // Import the data.
100
- $content = $this->process_export_import_content( $content, 'on_import' );
101
-
102
- // Update processed meta.
103
- update_metadata( 'post', $post_id, '_elementor_data', $data );
104
- update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
105
-
106
- // !important, Clear the cache after images import.
107
- Plugin::$instance->posts_css_manager->clear_cache();
108
-
109
- }
110
- }
111
- }
112
- }
113
- }
1
+ <?php
2
+ /**
3
+ * Elementor Importer
4
+ *
5
+ * @package Astra Sites
6
+ */
7
+
8
+ namespace Elementor\TemplateLibrary;
9
+
10
+ if ( ! defined( 'ABSPATH' ) ) {
11
+ exit; // Exit if accessed directly.
12
+ }
13
+
14
+ // If plugin - 'Elementor' not exist then return.
15
+ if ( ! class_exists( '\Elementor\Plugin' ) ) {
16
+ return;
17
+ }
18
+
19
+ use Elementor\Core\Base\Document;
20
+ use Elementor\DB;
21
+ use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
22
+ use Elementor\Core\Settings\Manager as SettingsManager;
23
+ use Elementor\Core\Settings\Page\Model;
24
+ use Elementor\Editor;
25
+ use Elementor\Plugin;
26
+ use Elementor\Settings;
27
+ use Elementor\Utils;
28
+
29
+ /**
30
+ * Elementor template library local source.
31
+ *
32
+ * Elementor template library local source handler class is responsible for
33
+ * handling local Elementor templates saved by the user locally on his site.
34
+ *
35
+ * @since 1.2.13 Added compatibility for Elemetnor v2.5.0
36
+ * @since 1.0.0
37
+ */
38
+ class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
39
+
40
+ /**
41
+ * Import
42
+ *
43
+ * @since 1.0.14
44
+ * @return void
45
+ */
46
+ public function import() {
47
+
48
+ // \Astra_Sites_Image_Importer::log( '---- Processing WordPress Posts / Pages - for Elementor ----' );
49
+ $post_types = get_option( 'elementor_cpt_support', array( 'page', 'post' ) );
50
+ if ( empty( $post_types ) && ! is_array( $post_types ) ) {
51
+ return;
52
+ }
53
+
54
+ $post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types );
55
+ if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
56
+ return;
57
+ }
58
+
59
+ foreach ( $post_ids as $post_id ) {
60
+ $is_elementor_post = get_post_meta( $post_id, '_elementor_version', true );
61
+ if ( $is_elementor_post ) {
62
+ $this->import_single_post( $post_id );
63
+ }
64
+ }
65
+ }
66
+ /**
67
+ * Update post meta.
68
+ *
69
+ * @since 1.0.14
70
+ * @param integer $post_id Post ID.
71
+ * @return void
72
+ */
73
+ public function import_single_post( $post_id = 0 ) {
74
+
75
+ // \Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
76
+ if ( ! empty( $post_id ) ) {
77
+
78
+ $hotlink_imported = get_post_meta( $post_id, '_astra_sites_hotlink_imported', true );
79
+
80
+ if ( empty( $hotlink_imported ) ) {
81
+
82
+ $data = get_post_meta( $post_id, '_elementor_data', true );
83
+
84
+ if ( ! empty( $data ) ) {
85
+
86
+ // Update WP form IDs.
87
+ $ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
88
+ if ( $ids_mapping ) {
89
+ foreach ( $ids_mapping as $old_id => $new_id ) {
90
+ $data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data );
91
+ }
92
+ }
93
+
94
+ $data = add_magic_quotes( $data );
95
+ $data = json_decode( $data, true );
96
+
97
+ // Import the data.
98
+ $data = $this->process_export_import_content( $data, 'on_import' );
99
+
100
+ // Update processed meta.
101
+ update_metadata( 'post', $post_id, '_elementor_data', $data );
102
+ update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
103
+
104
+ // !important, Clear the cache after images import.
105
+ Plugin::$instance->posts_css_manager->clear_cache();
106
+
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
 
 
inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php CHANGED
@@ -1,139 +1,137 @@
1
- <?php
2
- /**
3
- * Misc batch import tasks.
4
- *
5
- * @package Astra Sites
6
- * @since 1.1.6
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Misc' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Misc
13
- *
14
- * @since 1.1.6
15
- */
16
- class Astra_Sites_Batch_Processing_Misc {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.1.6
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.1.6
31
- * @return object initialized object of class.
32
- */
33
- public static function get_instance() {
34
-
35
- if ( ! isset( self::$instance ) ) {
36
- self::$instance = new self;
37
- }
38
- return self::$instance;
39
- }
40
-
41
- /**
42
- * Constructor
43
- *
44
- * @since 1.1.6
45
- */
46
- public function __construct() {}
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.1.6
52
- * @return void
53
- */
54
- public function import() {
55
-
56
- Astra_Sites_Image_Importer::log( '---- Processing MISC ----' );
57
-
58
- self::fix_nav_menus();
59
- }
60
-
61
- /**
62
- * Import Module Images.
63
- *
64
- * @return object
65
- */
66
- public static function fix_nav_menus() {
67
- // Not found site data, then return.
68
- $demo_data = get_option( 'astra_sites_import_data', array() );
69
- if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
70
- return;
71
- }
72
-
73
- // Not found/empty XML URL, then return.
74
- $xml_url = ( isset( $demo_data['astra-site-wxr-path'] ) ) ? esc_url( $demo_data['astra-site-wxr-path'] ) : '';
75
- if ( empty( $xml_url ) ) {
76
- return;
77
- }
78
-
79
- // Not empty site URL, then return.
80
- $site_url = strpos( $xml_url, '/wp-content' );
81
- if ( false === $site_url ) {
82
- return;
83
- }
84
-
85
- // Get remote site URL.
86
- $site_url = substr( $xml_url, 0, $site_url );
87
-
88
- $post_ids = self::get_menu_post_ids();
89
- if ( is_array( $post_ids ) ) {
90
- foreach ( $post_ids as $post_id ) {
91
- Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
92
-
93
- $menu_url = get_post_meta( $post_id, '_menu_item_url', true );
94
-
95
- if ( $menu_url ) {
96
- $menu_url = str_replace( $site_url, site_url(), $menu_url );
97
- update_post_meta( $post_id, '_menu_item_url', $menu_url );
98
- }
99
- }
100
- }
101
- }
102
-
103
- /**
104
- * Get all post id's
105
- *
106
- * @since 1.1.6
107
- *
108
- * @return array
109
- */
110
- public static function get_menu_post_ids() {
111
-
112
- $args = array(
113
- 'post_type' => 'nav_menu_item',
114
-
115
- // Query performance optimization.
116
- 'fields' => 'ids',
117
- 'no_found_rows' => true,
118
- 'post_status' => 'any',
119
- );
120
-
121
- $query = new WP_Query( $args );
122
-
123
- // Have posts?
124
- if ( $query->have_posts() ) :
125
-
126
- return $query->posts;
127
-
128
- endif;
129
- return null;
130
- }
131
-
132
- }
133
-
134
- /**
135
- * Kicking this off by calling 'get_instance()' method
136
- */
137
- Astra_Sites_Batch_Processing_Misc::get_instance();
138
-
139
- endif;
1
+ <?php
2
+ /**
3
+ * Misc batch import tasks.
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.1.6
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Misc' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Misc
13
+ *
14
+ * @since 1.1.6
15
+ */
16
+ class Astra_Sites_Batch_Processing_Misc {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.1.6
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.1.6
31
+ * @return object initialized object of class.
32
+ */
33
+ public static function get_instance() {
34
+
35
+ if ( ! isset( self::$instance ) ) {
36
+ self::$instance = new self;
37
+ }
38
+ return self::$instance;
39
+ }
40
+
41
+ /**
42
+ * Constructor
43
+ *
44
+ * @since 1.1.6
45
+ */
46
+ public function __construct() {}
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.1.6
52
+ * @return void
53
+ */
54
+ public function import() {
55
+
56
+ Astra_Sites_Image_Importer::log( '---- Processing MISC ----' );
57
+ self::fix_nav_menus();
58
+ }
59
+
60
+ /**
61
+ * Import Module Images.
62
+ *
63
+ * @return object
64
+ */
65
+ public static function fix_nav_menus() {
66
+ // Not found site data, then return.
67
+ $demo_data = get_option( 'astra_sites_import_data', array() );
68
+ if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
69
+ return;
70
+ }
71
+
72
+ // Not found/empty XML URL, then return.
73
+ $xml_url = ( isset( $demo_data['astra-site-wxr-path'] ) ) ? esc_url( $demo_data['astra-site-wxr-path'] ) : '';
74
+ if ( empty( $xml_url ) ) {
75
+ return;
76
+ }
77
+
78
+ // Not empty site URL, then return.
79
+ $site_url = strpos( $xml_url, '/wp-content' );
80
+ if ( false === $site_url ) {
81
+ return;
82
+ }
83
+
84
+ // Get remote site URL.
85
+ $site_url = substr( $xml_url, 0, $site_url );
86
+
87
+ $post_ids = self::get_menu_post_ids();
88
+ if ( is_array( $post_ids ) ) {
89
+ foreach ( $post_ids as $post_id ) {
90
+ Astra_Sites_Image_Importer::log( 'Post ID: ' . $post_id );
91
+ $menu_url = get_post_meta( $post_id, '_menu_item_url', true );
92
+
93
+ if ( $menu_url ) {
94
+ $menu_url = str_replace( $site_url, site_url(), $menu_url );
95
+ update_post_meta( $post_id, '_menu_item_url', $menu_url );
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Get all post id's
103
+ *
104
+ * @since 1.1.6
105
+ *
106
+ * @return array
107
+ */
108
+ public static function get_menu_post_ids() {
109
+
110
+ $args = array(
111
+ 'post_type' => 'nav_menu_item',
112
+
113
+ // Query performance optimization.
114
+ 'fields' => 'ids',
115
+ 'no_found_rows' => true,
116
+ 'post_status' => 'any',
117
+ );
118
+
119
+ $query = new WP_Query( $args );
120
+
121
+ // Have posts?
122
+ if ( $query->have_posts() ) :
123
+
124
+ return $query->posts;
125
+
126
+ endif;
127
+ return null;
128
+ }
129
+
130
+ }
131
+
132
+ /**
133
+ * Kicking this off by calling 'get_instance()' method
134
+ */
135
+ Astra_Sites_Batch_Processing_Misc::get_instance();
136
+
137
+ endif;
 
 
inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php CHANGED
@@ -1,98 +1,97 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing_Widgets
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing_Widgets {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.14
22
- * @access private
23
- * @var object Class object.
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Initiator
29
- *
30
- * @since 1.0.14
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.14
44
- */
45
- public function __construct() {
46
- }
47
-
48
- /**
49
- * Import
50
- *
51
- * @since 1.0.14
52
- * @return void
53
- */
54
- public function import() {
55
- $this->widget_media_image();
56
- }
57
-
58
- /**
59
- * Widget Media Image
60
- *
61
- * @since 1.0.14
62
- * @return void
63
- */
64
- public function widget_media_image() {
65
-
66
- $data = get_option( 'widget_media_image', null );
67
-
68
- Astra_Sites_Image_Importer::log( '---- Processing Images from Widgets -----' );
69
-
70
- foreach ( $data as $key => $value ) {
71
-
72
- if (
73
- isset( $value['url'] ) &&
74
- isset( $value['attachment_id'] )
75
- ) {
76
-
77
- $image = array(
78
- 'url' => $value['url'],
79
- 'id' => $value['attachment_id'],
80
- );
81
-
82
- $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
83
-
84
- $data[ $key ]['url'] = $downloaded_image['url'];
85
- $data[ $key ]['attachment_id'] = $downloaded_image['id'];
86
- }
87
- }
88
-
89
- update_option( 'widget_media_image', $data );
90
- }
91
- }
92
-
93
- /**
94
- * Kicking this off by calling 'get_instance()' method
95
- */
96
- Astra_Sites_Batch_Processing_Widgets::get_instance();
97
-
98
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing_Widgets
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing_Widgets {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.14
22
+ * @access private
23
+ * @var object Class object.
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Initiator
29
+ *
30
+ * @since 1.0.14
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.14
44
+ */
45
+ public function __construct() {
46
+ }
47
+
48
+ /**
49
+ * Import
50
+ *
51
+ * @since 1.0.14
52
+ * @return void
53
+ */
54
+ public function import() {
55
+ $this->widget_media_image();
56
+ }
57
+
58
+ /**
59
+ * Widget Media Image
60
+ *
61
+ * @since 1.0.14
62
+ * @return void
63
+ */
64
+ public function widget_media_image() {
65
+
66
+ $data = get_option( 'widget_media_image', null );
67
+
68
+ Astra_Sites_Image_Importer::log( '---- Processing Images from Widgets -----' );
69
+ foreach ( $data as $key => $value ) {
70
+
71
+ if (
72
+ isset( $value['url'] ) &&
73
+ isset( $value['attachment_id'] )
74
+ ) {
75
+
76
+ $image = array(
77
+ 'url' => $value['url'],
78
+ 'id' => $value['attachment_id'],
79
+ );
80
+
81
+ $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
82
+
83
+ $data[ $key ]['url'] = $downloaded_image['url'];
84
+ $data[ $key ]['attachment_id'] = $downloaded_image['id'];
85
+ }
86
+ }
87
+
88
+ update_option( 'widget_media_image', $data );
89
+ }
90
+ }
91
+
92
+ /**
93
+ * Kicking this off by calling 'get_instance()' method
94
+ */
95
+ Astra_Sites_Batch_Processing_Widgets::get_instance();
96
+
97
+ endif;
 
inc/importers/batch-processing/class-astra-sites-batch-processing.php CHANGED
@@ -1,209 +1,209 @@
1
- <?php
2
- /**
3
- * Batch Processing
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.14
7
- */
8
-
9
- if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) :
10
-
11
- /**
12
- * Astra_Sites_Batch_Processing
13
- *
14
- * @since 1.0.14
15
- */
16
- class Astra_Sites_Batch_Processing {
17
-
18
- /**
19
- * Instance
20
- *
21
- * @since 1.0.14
22
- * @var object Class object.
23
- * @access private
24
- */
25
- private static $instance;
26
-
27
- /**
28
- * Process All
29
- *
30
- * @since 1.0.14
31
- * @var object Class object.
32
- * @access public
33
- */
34
- public static $process_all;
35
-
36
- /**
37
- * Initiator
38
- *
39
- * @since 1.0.14
40
- * @return object initialized object of class.
41
- */
42
- public static function get_instance() {
43
- if ( ! isset( self::$instance ) ) {
44
- self::$instance = new self;
45
- }
46
- return self::$instance;
47
- }
48
-
49
- /**
50
- * Constructor
51
- *
52
- * @since 1.0.14
53
- */
54
- public function __construct() {
55
-
56
- // Core Helpers - Image.
57
- // @todo This file is required for Elementor.
58
- // Once we implement our logic for updating elementor data then we'll delete this file.
59
- require_once ABSPATH . 'wp-admin/includes/image.php';
60
-
61
- // Core Helpers - Image Downloader.
62
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php';
63
-
64
- // Core Helpers - Batch Processing.
65
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-async-request.php';
66
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process.php';
67
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process-astra.php';
68
-
69
- // Prepare Widgets.
70
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php';
71
-
72
- // Prepare Page Builders.
73
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php';
74
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php';
75
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php';
76
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php';
77
-
78
- // Prepare Misc.
79
- require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php';
80
-
81
- self::$process_all = new WP_Background_Process_Astra();
82
-
83
- // Start image importing after site import complete.
84
- add_filter( 'astra_sites_image_importer_skip_image', array( $this, 'skip_image' ), 10, 2 );
85
- add_action( 'astra_sites_import_complete', array( $this, 'start_process' ) );
86
- }
87
-
88
- /**
89
- * Skip Image from Batch Processing.
90
- *
91
- * @since 1.0.14
92
- *
93
- * @param boolean $can_process Batch process image status.
94
- * @param array $attachment Batch process image input.
95
- * @return boolean
96
- */
97
- function skip_image( $can_process, $attachment ) {
98
-
99
- if ( isset( $attachment['url'] ) && ! empty( $attachment['url'] ) ) {
100
- if (
101
- strpos( $attachment['url'], 'brainstormforce.com' ) !== false ||
102
- strpos( $attachment['url'], 'wpastra.com' ) !== false ||
103
- strpos( $attachment['url'], 'sharkz.in' ) !== false ||
104
- strpos( $attachment['url'], 'websitedemos.net' ) !== false
105
- ) {
106
- return false;
107
- }
108
- }
109
-
110
- return true;
111
- }
112
-
113
- /**
114
- * Start Image Import
115
- *
116
- * @since 1.0.14
117
- *
118
- * @return void
119
- */
120
- public function start_process() {
121
-
122
- Astra_Sites_Image_Importer::log( '=================== ' . Astra_Sites_White_Label::get_instance()->page_title( ASTRA_SITES_NAME ) . ' - Importing Images for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ') ===================' );
123
-
124
- // Add "widget" in import [queue].
125
- if ( class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) {
126
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Widgets::get_instance() );
127
- }
128
-
129
- // Add "gutenberg" in import [queue].
130
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Gutenberg::get_instance() );
131
-
132
- // Add "brizy" in import [queue].
133
- if ( is_plugin_active( 'brizy/brizy.php' ) ) {
134
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Brizy::get_instance() );
135
- }
136
-
137
- // Add "bb-plugin" in import [queue].
138
- // Add "beaver-builder-lite-version" in import [queue].
139
- if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
140
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Beaver_Builder::get_instance() );
141
- }
142
-
143
- // Add "elementor" in import [queue].
144
- // @todo Remove required `allow_url_fopen` support.
145
- if ( ini_get( 'allow_url_fopen' ) ) {
146
- if ( is_plugin_active( 'elementor/elementor.php' ) ) {
147
- $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor();
148
- self::$process_all->push_to_queue( $import );
149
- }
150
- } else {
151
- Astra_Sites_Image_Importer::log( 'Couldn\'t not import image due to allow_url_fopen() is disabled!' );
152
- }
153
-
154
- // Add "astra-addon" in import [queue].
155
- if ( is_plugin_active( 'astra-addon/astra-addon.php' ) ) {
156
- if ( class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) {
157
- self::$process_all->push_to_queue( Astra_Sites_Compatibility_Astra_Pro::get_instance() );
158
- }
159
- }
160
-
161
- // Add "misc" in import [queue].
162
- self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Misc::get_instance() );
163
-
164
- // Dispatch Queue.
165
- self::$process_all->save()->dispatch();
166
- }
167
-
168
- /**
169
- * Get all post id's
170
- *
171
- * @since 1.0.14
172
- *
173
- * @param array $post_types Post types.
174
- * @return array
175
- */
176
- public static function get_pages( $post_types = array() ) {
177
-
178
- if ( $post_types ) {
179
- $args = array(
180
- 'post_type' => $post_types,
181
-
182
- // Query performance optimization.
183
- 'fields' => 'ids',
184
- 'no_found_rows' => true,
185
- 'post_status' => 'publish',
186
- 'posts_per_page' => -1,
187
- );
188
-
189
- $query = new WP_Query( $args );
190
-
191
- // Have posts?
192
- if ( $query->have_posts() ) :
193
-
194
- return $query->posts;
195
-
196
- endif;
197
- }
198
-
199
- return null;
200
- }
201
-
202
- }
203
-
204
- /**
205
- * Kicking this off by calling 'get_instance()' method
206
- */
207
- Astra_Sites_Batch_Processing::get_instance();
208
-
209
- endif;
1
+ <?php
2
+ /**
3
+ * Batch Processing
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.14
7
+ */
8
+
9
+ if ( ! class_exists( 'Astra_Sites_Batch_Processing' ) ) :
10
+
11
+ /**
12
+ * Astra_Sites_Batch_Processing
13
+ *
14
+ * @since 1.0.14
15
+ */
16
+ class Astra_Sites_Batch_Processing {
17
+
18
+ /**
19
+ * Instance
20
+ *
21
+ * @since 1.0.14
22
+ * @var object Class object.
23
+ * @access private
24
+ */
25
+ private static $instance;
26
+
27
+ /**
28
+ * Process All
29
+ *
30
+ * @since 1.0.14
31
+ * @var object Class object.
32
+ * @access public
33
+ */
34
+ public static $process_all;
35
+
36
+ /**
37
+ * Initiator
38
+ *
39
+ * @since 1.0.14
40
+ * @return object initialized object of class.
41
+ */
42
+ public static function get_instance() {
43
+ if ( ! isset( self::$instance ) ) {
44
+ self::$instance = new self;
45
+ }
46
+ return self::$instance;
47
+ }
48
+
49
+ /**
50
+ * Constructor
51
+ *
52
+ * @since 1.0.14
53
+ */
54
+ public function __construct() {
55
+
56
+ // Core Helpers - Image.
57
+ // @todo This file is required for Elementor.
58
+ // Once we implement our logic for updating elementor data then we'll delete this file.
59
+ require_once ABSPATH . 'wp-admin/includes/image.php';
60
+
61
+ // Core Helpers - Image Downloader.
62
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php';
63
+
64
+ // Core Helpers - Batch Processing.
65
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-async-request.php';
66
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process.php';
67
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/helpers/class-wp-background-process-astra.php';
68
+
69
+ // Prepare Widgets.
70
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-widgets.php';
71
+
72
+ // Prepare Page Builders.
73
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-beaver-builder.php';
74
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-elementor.php';
75
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-gutenberg.php';
76
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-brizy.php';
77
+
78
+ // Prepare Misc.
79
+ require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing-misc.php';
80
+
81
+ self::$process_all = new WP_Background_Process_Astra();
82
+
83
+ // Start image importing after site import complete.
84
+ add_filter( 'astra_sites_image_importer_skip_image', array( $this, 'skip_image' ), 10, 2 );
85
+ add_action( 'astra_sites_import_complete', array( $this, 'start_process' ) );
86
+ }
87
+
88
+ /**
89
+ * Skip Image from Batch Processing.
90
+ *
91
+ * @since 1.0.14
92
+ *
93
+ * @param boolean $can_process Batch process image status.
94
+ * @param array $attachment Batch process image input.
95
+ * @return boolean
96
+ */
97
+ function skip_image( $can_process, $attachment ) {
98
+
99
+ if ( isset( $attachment['url'] ) && ! empty( $attachment['url'] ) ) {
100
+ if (
101
+ strpos( $attachment['url'], 'brainstormforce.com' ) !== false ||
102
+ strpos( $attachment['url'], 'wpastra.com' ) !== false ||
103
+ strpos( $attachment['url'], 'sharkz.in' ) !== false ||
104
+ strpos( $attachment['url'], 'websitedemos.net' ) !== false
105
+ ) {
106
+ return false;
107
+ }
108
+ }
109
+
110
+ return true;
111
+ }
112
+
113
+ /**
114
+ * Start Image Import
115
+ *
116
+ * @since 1.0.14
117
+ *
118
+ * @return void
119
+ */
120
+ public function start_process() {
121
+
122
+ Astra_Sites_Image_Importer::log( '=================== ' . Astra_Sites_White_Label::get_instance()->page_title( ASTRA_SITES_NAME ) . ' - Importing Images for Blog name \'' . get_bloginfo( 'name' ) . '\' (' . get_current_blog_id() . ') ===================' );
123
+
124
+ // Add "widget" in import [queue].
125
+ if ( class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) {
126
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Widgets::get_instance() );
127
+ }
128
+
129
+ // Add "gutenberg" in import [queue].
130
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Gutenberg::get_instance() );
131
+
132
+ // Add "brizy" in import [queue].
133
+ if ( is_plugin_active( 'brizy/brizy.php' ) ) {
134
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Brizy::get_instance() );
135
+ }
136
+
137
+ // Add "bb-plugin" in import [queue].
138
+ // Add "beaver-builder-lite-version" in import [queue].
139
+ if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
140
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Beaver_Builder::get_instance() );
141
+ }
142
+
143
+ // Add "elementor" in import [queue].
144
+ // @todo Remove required `allow_url_fopen` support.
145
+ if ( ini_get( 'allow_url_fopen' ) ) {
146
+ if ( is_plugin_active( 'elementor/elementor.php' ) ) {
147
+ $import = new \Elementor\TemplateLibrary\Astra_Sites_Batch_Processing_Elementor();
148
+ self::$process_all->push_to_queue( $import );
149
+ }
150
+ } else {
151
+ Astra_Sites_Image_Importer::log( 'Couldn\'t not import image due to allow_url_fopen() is disabled!' );
152
+ }
153
+
154
+ // Add "astra-addon" in import [queue].
155
+ if ( is_plugin_active( 'astra-addon/astra-addon.php' ) ) {
156
+ if ( class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) {
157
+ self::$process_all->push_to_queue( Astra_Sites_Compatibility_Astra_Pro::get_instance() );
158
+ }
159
+ }
160
+
161
+ // Add "misc" in import [queue].
162
+ self::$process_all->push_to_queue( Astra_Sites_Batch_Processing_Misc::get_instance() );
163
+
164
+ // Dispatch Queue.
165
+ self::$process_all->save()->dispatch();
166
+ }
167
+
168
+ /**
169
+ * Get all post id's
170
+ *
171
+ * @since 1.0.14
172
+ *
173
+ * @param array $post_types Post types.
174
+ * @return array
175
+ */
176
+ public static function get_pages( $post_types = array() ) {
177
+
178
+ if ( $post_types ) {
179
+ $args = array(
180
+ 'post_type' => $post_types,
181
+
182
+ // Query performance optimization.
183
+ 'fields' => 'ids',
184
+ 'no_found_rows' => true,
185
+ 'post_status' => 'publish',
186
+ 'posts_per_page' => -1,
187
+ );
188
+
189
+ $query = new WP_Query( $args );
190
+
191
+ // Have posts?
192
+ if ( $query->have_posts() ) :
193
+
194
+ return $query->posts;
195
+
196
+ endif;
197
+ }
198
+
199
+ return null;
200
+ }
201
+
202
+ }
203
+
204
+ /**
205
+ * Kicking this off by calling 'get_instance()' method
206
+ */
207
+ Astra_Sites_Batch_Processing::get_instance();
208
+
209
+ endif;
inc/importers/batch-processing/helpers/class-astra-sites-image-importer.php CHANGED
@@ -1,280 +1,263 @@
1
- <?php
2
- /**
3
- * Image Importer
4
- *
5
- * => How to use?
6
- *
7
- * $image = array(
8
- * 'url' => '<image-url>',
9
- * 'id' => '<image-id>',
10
- * );
11
- *
12
- * $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
13
- *
14
- * @package Astra Sites
15
- * @since 1.0.14
16
- */
17
-
18
- if ( ! class_exists( 'Astra_Sites_Image_Importer' ) ) :
19
-
20
- /**
21
- * Astra Sites Image Importer
22
- *
23
- * @since 1.0.14
24
- */
25
- class Astra_Sites_Image_Importer {
26
-
27
- /**
28
- * Instance
29
- *
30
- * @since 1.0.14
31
- * @var object Class object.
32
- * @access private
33
- */
34
- private static $instance;
35
-
36
- /**
37
- * Images IDs
38
- *
39
- * @var array The Array of already image IDs.
40
- * @since 1.0.14
41
- */
42
- private $already_imported_ids = array();
43
-
44
- /**
45
- * Initiator
46
- *
47
- * @since 1.0.14
48
- * @return object initialized object of class.
49
- */
50
- public static function get_instance() {
51
- if ( ! isset( self::$instance ) ) {
52
- self::$instance = new self;
53
- }
54
- return self::$instance;
55
- }
56
-
57
- /**
58
- * Constructor
59
- *
60
- * @since 1.0.14
61
- */
62
- public function __construct() {
63
-
64
- if ( ! function_exists( 'WP_Filesystem' ) ) {
65
- require_once ABSPATH . 'wp-admin/includes/file.php';
66
- }
67
-
68
- WP_Filesystem();
69
- }
70
-
71
- /**
72
- * Process Image Download
73
- *
74
- * @since 1.0.14
75
- * @param array $attachments Attachment array.
76
- * @return array Attachment array.
77
- */
78
- public function process( $attachments ) {
79
-
80
- $downloaded_images = array();
81
-
82
- foreach ( $attachments as $key => $attachment ) {
83
- $downloaded_images[] = $this->import( $attachment );
84
- }
85
-
86
- return $downloaded_images;
87
- }
88
-
89
- /**
90
- * Get Hash Image.
91
- *
92
- * @since 1.0.14
93
- * @param string $attachment_url Attachment URL.
94
- * @return string Hash string.
95
- */
96
- private function get_hash_image( $attachment_url ) {
97
- return sha1( $attachment_url );
98
- }
99
-
100
- /**
101
- * Get Saved Image.
102
- *
103
- * @since 1.0.14
104
- * @param string $attachment Attachment Data.
105
- * @return string Hash string.
106
- */
107
- private function get_saved_image( $attachment ) {
108
-
109
- if ( apply_filters( 'astra_sites_image_importer_skip_image', false, $attachment ) ) {
110
-
111
- Astra_Sites_Image_Importer::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
112
-
113
- return $attachment;
114
- }
115
-
116
- global $wpdb;
117
-
118
- // Already imported? Then return!
119
- if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
120
-
121
- Astra_Sites_Image_Importer::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
122
-
123
- return $this->already_imported_ids[ $attachment['id'] ];
124
- }
125
-
126
- // 1. Is already imported in Batch Import Process?
127
- $post_id = $wpdb->get_var(
128
- $wpdb->prepare(
129
- 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
130
- WHERE `meta_key` = \'_astra_sites_image_hash\'
131
- AND `meta_value` = %s
132
- ;',
133
- $this->get_hash_image( $attachment['url'] )
134
- )
135
- );
136
-
137
- // 2. Is image already imported though XML?
138
- if ( empty( $post_id ) ) {
139
-
140
- // Get file name without extension.
141
- // To check it exist in attachment.
142
- $filename = basename( $attachment['url'] );
143
-
144
- $post_id = $wpdb->get_var(
145
- $wpdb->prepare(
146
- 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
147
- WHERE `meta_key` = \'_wp_attached_file\'
148
- AND `meta_value` LIKE %s
149
- ;',
150
- '%' . $filename . '%'
151
- )
152
- );
153
-
154
- $post_id = $wpdb->get_var(
155
- $wpdb->prepare(
156
- "SELECT post_id FROM {$wpdb->postmeta}
157
- WHERE meta_key = '_wp_attached_file'
158
- AND meta_value LIKE %s",
159
- '%' . $filename . '%'
160
- )
161
- );
162
-
163
- Astra_Sites_Image_Importer::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
164
- }
165
-
166
- if ( $post_id ) {
167
- $new_attachment = array(
168
- 'id' => $post_id,
169
- 'url' => wp_get_attachment_url( $post_id ),
170
- );
171
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
172
-
173
- return $new_attachment;
174
- }
175
-
176
- return false;
177
- }
178
-
179
- /**
180
- * Import Image
181
- *
182
- * @since 1.0.14
183
- * @param array $attachment Attachment array.
184
- * @return array Attachment array.
185
- */
186
- public function import( $attachment ) {
187
-
188
- $saved_image = $this->get_saved_image( $attachment );
189
- if ( $saved_image ) {
190
- return $saved_image;
191
- }
192
-
193
- $file_content = wp_remote_retrieve_body(
194
- wp_safe_remote_get(
195
- $attachment['url'],
196
- array(
197
- 'timeout' => '60',
198
- 'sslverify' => false,
199
- )
200
- )
201
- );
202
-
203
- // Empty file content?
204
- if ( empty( $file_content ) ) {
205
-
206
- Astra_Sites_Image_Importer::log( 'Download (✕) Replace (✕) - ' . $attachment['url'] );
207
- Astra_Sites_Image_Importer::log( 'Error: Failed wp_remote_retrieve_body().' );
208
-
209
- return $attachment;
210
- }
211
-
212
- // Extract the file name and extension from the URL.
213
- $filename = basename( $attachment['url'] );
214
-
215
- $upload = wp_upload_bits(
216
- $filename,
217
- null,
218
- $file_content
219
- );
220
-
221
- $post = array(
222
- 'post_title' => $filename,
223
- 'guid' => $upload['url'],
224
- );
225
-
226
- $info = wp_check_filetype( $upload['file'] );
227
- if ( $info ) {
228
- $post['post_mime_type'] = $info['type'];
229
- } else {
230
- // For now just return the origin attachment.
231
- return $attachment;
232
- }
233
-
234
- $post_id = wp_insert_attachment( $post, $upload['file'] );
235
- wp_update_attachment_metadata(
236
- $post_id,
237
- wp_generate_attachment_metadata( $post_id, $upload['file'] )
238
- );
239
- update_post_meta( $post_id, '_astra_sites_image_hash', $this->get_hash_image( $attachment['url'] ) );
240
-
241
- $new_attachment = array(
242
- 'id' => $post_id,
243
- 'url' => $upload['url'],
244
- );
245
-
246
- Astra_Sites_Image_Importer::log( 'Download (✓) Replace (✓) - ' . $attachment['url'] );
247
-
248
- $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
249
-
250
- return $new_attachment;
251
- }
252
-
253
- /**
254
- * Debugging Log.
255
- *
256
- * @since 1.0.14
257
- * @param mixed $log Log data.
258
- * @return void
259
- */
260
- public static function log( $log ) {
261
-
262
- if ( ! WP_DEBUG_LOG ) {
263
- return;
264
- }
265
-
266
- if ( is_array( $log ) || is_object( $log ) ) {
267
- error_log( print_r( $log, true ) );
268
- } else {
269
- error_log( $log );
270
- }
271
- }
272
-
273
- }
274
-
275
- /**
276
- * Kicking this off by calling 'get_instance()' method
277
- */
278
- Astra_Sites_Image_Importer::get_instance();
279
-
280
- endif;
1
+ <?php
2
+ /**
3
+ * Image Importer
4
+ *
5
+ * => How to use?
6
+ *
7
+ * $image = array(
8
+ * 'url' => '<image-url>',
9
+ * 'id' => '<image-id>',
10
+ * );
11
+ *
12
+ * $downloaded_image = Astra_Sites_Image_Importer::get_instance()->import( $image );
13
+ *
14
+ * @package Astra Sites
15
+ * @since 1.0.14
16
+ */
17
+
18
+ if ( ! class_exists( 'Astra_Sites_Image_Importer' ) ) :
19
+
20
+ /**
21
+ * Astra Sites Image Importer
22
+ *
23
+ * @since 1.0.14
24
+ */
25
+ class Astra_Sites_Image_Importer {
26
+
27
+ /**
28
+ * Instance
29
+ *
30
+ * @since 1.0.14
31
+ * @var object Class object.
32
+ * @access private
33
+ */
34
+ private static $instance;
35
+
36
+ /**
37
+ * Images IDs
38
+ *
39
+ * @var array The Array of already image IDs.
40
+ * @since 1.0.14
41
+ */
42
+ private $already_imported_ids = array();
43
+
44
+ /**
45
+ * Initiator
46
+ *
47
+ * @since 1.0.14
48
+ * @return object initialized object of class.
49
+ */
50
+ public static function get_instance() {
51
+ if ( ! isset( self::$instance ) ) {
52
+ self::$instance = new self;
53
+ }
54
+ return self::$instance;
55
+ }
56
+
57
+ /**
58
+ * Constructor
59
+ *
60
+ * @since 1.0.14
61
+ */
62
+ public function __construct() {
63
+
64
+ if ( ! function_exists( 'WP_Filesystem' ) ) {
65
+ require_once ABSPATH . 'wp-admin/includes/file.php';
66
+ }
67
+
68
+ WP_Filesystem();
69
+ }
70
+
71
+ /**
72
+ * Process Image Download
73
+ *
74
+ * @since 1.0.14
75
+ * @param array $attachments Attachment array.
76
+ * @return array Attachment array.
77
+ */
78
+ public function process( $attachments ) {
79
+
80
+ $downloaded_images = array();
81
+
82
+ foreach ( $attachments as $key => $attachment ) {
83
+ $downloaded_images[] = $this->import( $attachment );
84
+ }
85
+
86
+ return $downloaded_images;
87
+ }
88
+
89
+ /**
90
+ * Get Hash Image.
91
+ *
92
+ * @since 1.0.14
93
+ * @param string $attachment_url Attachment URL.
94
+ * @return string Hash string.
95
+ */
96
+ private function get_hash_image( $attachment_url ) {
97
+ return sha1( $attachment_url );
98
+ }
99
+
100
+ /**
101
+ * Get Saved Image.
102
+ *
103
+ * @since 1.0.14
104
+ * @param string $attachment Attachment Data.
105
+ * @return string Hash string.
106
+ */
107
+ private function get_saved_image( $attachment ) {
108
+
109
+ if ( apply_filters( 'astra_sites_image_importer_skip_image', false, $attachment ) ) {
110
+ Astra_Sites_Image_Importer::log( 'BATCH - SKIP Image - {from filter} - ' . $attachment['url'] . ' - Filter name `astra_sites_image_importer_skip_image`.' );
111
+ return $attachment;
112
+ }
113
+
114
+ global $wpdb;
115
+
116
+ // Already imported? Then return!
117
+ if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
118
+ Astra_Sites_Image_Importer::log( 'BATCH - SKIP Image {already imported from batch process} - ' . $attachment['url'] . ' - already imported.' );
119
+ return $this->already_imported_ids[ $attachment['id'] ];
120
+ }
121
+
122
+ // 1. Is already imported in Batch Import Process?
123
+ $post_id = $wpdb->get_var(
124
+ $wpdb->prepare(
125
+ 'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
126
+ WHERE `meta_key` = \'_astra_sites_image_hash\'
127
+ AND `meta_value` = %s
128
+ ;',
129
+ $this->get_hash_image( $attachment['url'] )
130
+ )
131
+ );
132
+
133
+ // 2. Is image already imported though XML?
134
+ if ( empty( $post_id ) ) {
135
+
136
+ // Get file name without extension.
137
+ // To check it exist in attachment.
138
+ $filename = basename( $attachment['url'] );
139
+
140
+ $post_id = $wpdb->get_var(
141
+ $wpdb->prepare(
142
+ "SELECT post_id FROM {$wpdb->postmeta}
143
+ WHERE meta_key = '_wp_attached_file'
144
+ AND meta_value LIKE %s",
145
+ '%' . $filename . '%'
146
+ )
147
+ );
148
+
149
+ Astra_Sites_Image_Importer::log( 'BATCH - SKIP Image {already imported from xml} - ' . $attachment['url'] );
150
+ }
151
+
152
+ if ( $post_id ) {
153
+ $new_attachment = array(
154
+ 'id' => $post_id,
155
+ 'url' => wp_get_attachment_url( $post_id ),
156
+ );
157
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
158
+
159
+ return $new_attachment;
160
+ }
161
+
162
+ return false;
163
+ }
164
+
165
+ /**
166
+ * Import Image
167
+ *
168
+ * @since 1.0.14
169
+ * @param array $attachment Attachment array.
170
+ * @return array Attachment array.
171
+ */
172
+ public function import( $attachment ) {
173
+
174
+ $saved_image = $this->get_saved_image( $attachment );
175
+ if ( $saved_image ) {
176
+ return $saved_image;
177
+ }
178
+
179
+ $file_content = wp_remote_retrieve_body(
180
+ wp_safe_remote_get(
181
+ $attachment['url'],
182
+ array(
183
+ 'timeout' => '60',
184
+ 'sslverify' => false,
185
+ )
186
+ )
187
+ );
188
+
189
+ // Empty file content?
190
+ if ( empty( $file_content ) ) {
191
+ Astra_Sites_Image_Importer::log( 'BATCH - FAIL Image {Error: Failed wp_remote_retrieve_body} - ' . $attachment['url'] );
192
+ return $attachment;
193
+ }
194
+
195
+ // Extract the file name and extension from the URL.
196
+ $filename = basename( $attachment['url'] );
197
+
198
+ $upload = wp_upload_bits(
199
+ $filename,
200
+ null,
201
+ $file_content
202
+ );
203
+
204
+ $post = array(
205
+ 'post_title' => $filename,
206
+ 'guid' => $upload['url'],
207
+ );
208
+
209
+ $info = wp_check_filetype( $upload['file'] );
210
+ if ( $info ) {
211
+ $post['post_mime_type'] = $info['type'];
212
+ } else {
213
+ // For now just return the origin attachment.
214
+ return $attachment;
215
+ }
216
+
217
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
218
+ wp_update_attachment_metadata(
219
+ $post_id,
220
+ wp_generate_attachment_metadata( $post_id, $upload['file'] )
221
+ );
222
+ update_post_meta( $post_id, '_astra_sites_image_hash', $this->get_hash_image( $attachment['url'] ) );
223
+
224
+ $new_attachment = array(
225
+ 'id' => $post_id,
226
+ 'url' => $upload['url'],
227
+ );
228
+
229
+ Astra_Sites_Image_Importer::log( 'BATCH - SUCCESS Image {Imported Successfully} - ' . $new_attachment['url'] );
230
+
231
+ $this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
232
+
233
+ return $new_attachment;
234
+ }
235
+
236
+ /**
237
+ * Debugging Log.
238
+ *
239
+ * @since 1.0.14
240
+ * @param mixed $log Log data.
241
+ * @return void
242
+ */
243
+ public static function log( $log ) {
244
+
245
+ if ( ! WP_DEBUG_LOG ) {
246
+ return;
247
+ }
248
+
249
+ if ( is_array( $log ) || is_object( $log ) ) {
250
+ error_log( print_r( $log, true ) );
251
+ } else {
252
+ error_log( $log );
253
+ }
254
+ }
255
+
256
+ }
257
+
258
+ /**
259
+ * Kicking this off by calling 'get_instance()' method
260
+ */
261
+ Astra_Sites_Image_Importer::get_instance();
262
+
263
+ endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/importers/batch-processing/helpers/class-wp-async-request.php CHANGED
@@ -1,164 +1,164 @@
1
- <?php
2
- /**
3
- * WP Async Request
4
- *
5
- * @see https://github.com/A5hleyRich/wp-background-processing/
6
- * @package WP-Background-Processing
7
- */
8
-
9
- if ( ! class_exists( 'WP_Async_Request' ) ) {
10
-
11
- /**
12
- * Abstract WP_Async_Request class.
13
- *
14
- * @abstract
15
- */
16
- abstract class WP_Async_Request {
17
-
18
- /**
19
- * Prefix
20
- *
21
- * (default value: 'wp')
22
- *
23
- * @var string
24
- * @access protected
25
- */
26
- protected $prefix = 'wp';
27
-
28
- /**
29
- * Action
30
- *
31
- * (default value: 'async_request')
32
- *
33
- * @var string
34
- * @access protected
35
- */
36
- protected $action = 'async_request';
37
-
38
- /**
39
- * Identifier
40
- *
41
- * @var mixed
42
- * @access protected
43
- */
44
- protected $identifier;
45
-
46
- /**
47
- * Data
48
- *
49
- * (default value: array())
50
- *
51
- * @var array
52
- * @access protected
53
- */
54
- protected $data = array();
55
-
56
- /**
57
- * Initiate new async request
58
- */
59
- public function __construct() {
60
- $this->identifier = $this->prefix . '_' . $this->action;
61
-
62
- add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
63
- add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
64
- }
65
-
66
- /**
67
- * Set data used during the request
68
- *
69
- * @param array $data Data.
70
- *
71
- * @return $this
72
- */
73
- public function data( $data ) {
74
- $this->data = $data;
75
-
76
- return $this;
77
- }
78
-
79
- /**
80
- * Dispatch the async request
81
- *
82
- * @return array|WP_Error
83
- */
84
- public function dispatch() {
85
- $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
86
- $args = $this->get_post_args();
87
-
88
- return wp_remote_post( esc_url_raw( $url ), $args );
89
- }
90
-
91
- /**
92
- * Get query args
93
- *
94
- * @return array
95
- */
96
- protected function get_query_args() {
97
- if ( property_exists( $this, 'query_args' ) ) {
98
- return $this->query_args;
99
- }
100
-
101
- return array(
102
- 'action' => $this->identifier,
103
- 'nonce' => wp_create_nonce( $this->identifier ),
104
- );
105
- }
106
-
107
- /**
108
- * Get query URL
109
- *
110
- * @return string
111
- */
112
- protected function get_query_url() {
113
- if ( property_exists( $this, 'query_url' ) ) {
114
- return $this->query_url;
115
- }
116
-
117
- return admin_url( 'admin-ajax.php' );
118
- }
119
-
120
- /**
121
- * Get post args
122
- *
123
- * @return array
124
- */
125
- protected function get_post_args() {
126
- if ( property_exists( $this, 'post_args' ) ) {
127
- return $this->post_args;
128
- }
129
-
130
- return array(
131
- 'timeout' => 0.01,
132
- 'blocking' => false,
133
- 'body' => $this->data,
134
- 'cookies' => $_COOKIE,
135
- 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
136
- );
137
- }
138
-
139
- /**
140
- * Maybe handle
141
- *
142
- * Check for correct nonce and pass to handler.
143
- */
144
- public function maybe_handle() {
145
- // Don't lock up other requests while processing.
146
- session_write_close();
147
-
148
- check_ajax_referer( $this->identifier, 'nonce' );
149
-
150
- $this->handle();
151
-
152
- wp_die();
153
- }
154
-
155
- /**
156
- * Handle
157
- *
158
- * Override this method to perform any actions required
159
- * during the async request.
160
- */
161
- abstract protected function handle();
162
-
163
- }
164
- }
1
+ <?php
2
+ /**
3
+ * WP Async Request
4
+ *
5
+ * @see https://github.com/A5hleyRich/wp-background-processing/
6
+ * @package WP-Background-Processing
7
+ */
8
+
9
+ if ( ! class_exists( 'WP_Async_Request' ) ) {
10
+
11
+ /**
12
+ * Abstract WP_Async_Request class.
13
+ *
14
+ * @abstract
15
+ */
16
+ abstract class WP_Async_Request {
17
+
18
+ /**
19
+ * Prefix
20
+ *
21
+ * (default value: 'wp')
22
+ *
23
+ * @var string
24
+ * @access protected
25
+ */
26
+ protected $prefix = 'wp';
27
+
28
+ /**
29
+ * Action
30
+ *
31
+ * (default value: 'async_request')
32
+ *
33
+ * @var string
34
+ * @access protected
35
+ */
36
+ protected $action = 'async_request';
37
+
38
+ /**
39
+ * Identifier
40
+ *
41
+ * @var mixed
42
+ * @access protected
43
+ */
44
+ protected $identifier;
45
+
46
+ /**
47
+ * Data
48
+ *
49
+ * (default value: array())
50
+ *
51
+ * @var array
52
+ * @access protected
53
+ */
54
+ protected $data = array();
55
+
56
+ /**
57
+ * Initiate new async request
58
+ */
59
+ public function __construct() {
60
+ $this->identifier = $this->prefix . '_' . $this->action;
61
+
62
+ add_action( 'wp_ajax_' . $this->identifier, array( $this, 'maybe_handle' ) );
63
+ add_action( 'wp_ajax_nopriv_' . $this->identifier, array( $this, 'maybe_handle' ) );
64
+ }
65
+
66
+ /**
67
+ * Set data used during the request
68
+ *
69
+ * @param array $data Data.
70
+ *
71
+ * @return $this
72
+ */
73
+ public function data( $data ) {
74
+ $this->data = $data;
75
+
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Dispatch the async request
81
+ *
82
+ * @return array|WP_Error
83
+ */
84
+ public function dispatch() {
85
+ $url = add_query_arg( $this->get_query_args(), $this->get_query_url() );
86
+ $args = $this->get_post_args();
87
+
88
+ return wp_remote_post( esc_url_raw( $url ), $args );
89
+ }
90
+
91
+ /**
92
+ * Get query args
93
+ *
94
+ * @return array
95
+ */
96
+ protected function get_query_args() {
97
+ if ( property_exists( $this, 'query_args' ) ) {
98
+ return $this->query_args;
99
+ }
100
+
101
+ return array(
102
+ 'action' => $this->identifier,
103
+ 'nonce' => wp_create_nonce( $this->identifier ),
104
+ );
105
+ }
106
+
107
+ /**
108
+ * Get query URL
109
+ *
110
+ * @return string
111
+ */
112
+ protected function get_query_url() {
113
+ if ( property_exists( $this, 'query_url' ) ) {
114
+ return $this->query_url;
115
+ }
116
+
117
+ return admin_url( 'admin-ajax.php' );
118
+ }
119
+
120
+ /**
121
+ * Get post args
122
+ *
123
+ * @return array
124
+ */
125
+ protected function get_post_args() {
126
+ if ( property_exists( $this, 'post_args' ) ) {
127
+ return $this->post_args;
128
+ }
129
+
130
+ return array(
131
+ 'timeout' => 0.01,
132
+ 'blocking' => false,
133
+ 'body' => $this->data,
134
+ 'cookies' => $_COOKIE,
135
+ 'sslverify' => apply_filters( 'https_local_ssl_verify', false ),
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Maybe handle
141
+ *
142
+ * Check for correct nonce and pass to handler.
143
+ */
144
+ public function maybe_handle() {
145
+ // Don't lock up other requests while processing.
146
+ session_write_close();
147
+
148
+ check_ajax_referer( $this->identifier, 'nonce' );
149
+
150
+ $this->handle();
151
+
152
+ wp_die();
153
+ }
154
+
155
+ /**
156
+ * Handle
157
+ *
158
+ * Override this method to perform any actions required
159
+ * during the async request.
160
+ */
161
+ abstract protected function handle();
162
+
163
+ }
164
+ }
inc/importers/batch-processing/helpers/class-wp-background-process-astra.php CHANGED
@@ -1,67 +1,65 @@
1
- <?php
2
- /**
3
- * Image Background Process
4
- *
5
- * @package Astra Sites
6
- * @since 1.0.11
7
- */
8
-
9
- if ( class_exists( 'WP_Background_Process' ) ) :
10
-
11
- /**
12
- * Image Background Process
13
- *
14
- * @since 1.0.11
15
- */
16
- class WP_Background_Process_Astra extends WP_Background_Process {
17
-
18
- /**
19
- * Image Process
20
- *
21
- * @var string
22
- */
23
- protected $action = 'image_process';
24
-
25
- /**
26
- * Task
27
- *
28
- * Override this method to perform any actions required on each
29
- * queue item. Return the modified item for further processing
30
- * in the next pass through. Or, return false to remove the
31
- * item from the queue.
32
- *
33
- * @since 1.0.11
34
- *
35
- * @param object $process Queue item object.
36
- * @return mixed
37
- */
38
- protected function task( $process ) {
39
-
40
- if ( method_exists( $process, 'import' ) ) {
41
- $process->import();
42
- }
43
-
44
- return false;
45
- }
46
-
47
- /**
48
- * Complete
49
- *
50
- * Override if applicable, but ensure that the below actions are
51
- * performed, or, call parent::complete().
52
- *
53
- * @since 1.0.11
54
- */
55
- protected function complete() {
56
-
57
- Astra_Sites_Image_Importer::log( '=================== ' . Astra_Sites_White_Label::get_instance()->page_title( ASTRA_SITES_NAME ) . ' - Importing Images Complete ===================' );
58
-
59
- parent::complete();
60
-
61
- do_action( 'astra_sites_image_import_complete' );
62
-
63
- }
64
-
65
- }
66
-
67
- endif;
1
+ <?php
2
+ /**
3
+ * Image Background Process
4
+ *
5
+ * @package Astra Sites
6
+ * @since 1.0.11
7
+ */
8
+
9
+ if ( class_exists( 'WP_Background_Process' ) ) :
10
+
11
+ /**
12
+ * Image Background Process
13
+ *
14
+ * @since 1.0.11
15
+ */
16
+ class WP_Background_Process_Astra extends WP_Background_Process {
17
+
18
+ /**
19
+ * Image Process
20
+ *
21
+ * @var string
22
+ */
23
+ protected $action = 'image_process';
24
+
25
+ /**
26
+ * Task
27
+ *
28
+ * Override this method to perform any actions required on each
29
+ * queue item. Return the modified item for further processing
30
+ * in the next pass through. Or, return false to remove the
31
+ * item from the queue.
32
+ *
33
+ * @since 1.0.11
34
+ *
35
+ * @param object $process Queue item object.
36
+ * @return mixed
37
+ */
38
+ protected function task( $process ) {
39
+
40
+ if ( method_exists( $process, 'import' ) ) {
41
+ $process->import();
42
+ }
43
+
44
+ return false;
45
+ }
46
+
47
+ /**
48
+ * Complete
49
+ *
50
+ * Override if applicable, but ensure that the below actions are
51
+ * performed, or, call parent::complete().
52
+ *
53
+ * @since 1.0.11
54
+ */
55
+ protected function complete() {
56
+
57
+ parent::complete();
58
+
59
+ do_action( 'astra_sites_image_import_complete' );
60
+
61
+ }
62
+
63
+ }
64
+
65
+ endif;
 
 
inc/importers/batch-processing/helpers/class-wp-background-process.php CHANGED
@@ -1,513 +1,513 @@
1
- <?php
2
- /**
3
- * WP Background Process
4
- *
5
- * @see https://github.com/A5hleyRich/wp-background-processing/
6
- * @package WP-Background-Processing
7
- */
8
-
9
- if ( ! class_exists( 'WP_Background_Process' ) ) {
10
-
11
- /**
12
- * Abstract WP_Background_Process class.
13
- *
14
- * @abstract
15
- * @extends WP_Async_Request
16
- */
17
- abstract class WP_Background_Process extends WP_Async_Request {
18
-
19
- /**
20
- * Action
21
- *
22
- * (default value: 'background_process')
23
- *
24
- * @var string
25
- * @access protected
26
- */
27
- protected $action = 'background_process';
28
-
29
- /**
30
- * Start time of current process.
31
- *
32
- * (default value: 0)
33
- *
34
- * @var int
35
- * @access protected
36
- */
37
- protected $start_time = 0;
38
-
39
- /**
40
- * Cron_hook_identifier
41
- *
42
- * @var mixed
43
- * @access protected
44
- */
45
- protected $cron_hook_identifier;
46
-
47
- /**
48
- * Cron_interval_identifier
49
- *
50
- * @var mixed
51
- * @access protected
52
- */
53
- protected $cron_interval_identifier;
54
-
55
- /**
56
- * Initiate new background process
57
- */
58
- public function __construct() {
59
- parent::__construct();
60
-
61
- $this->cron_hook_identifier = $this->identifier . '_cron';
62
- $this->cron_interval_identifier = $this->identifier . '_cron_interval';
63
-
64
- add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
65
- add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
66
- }
67
-
68
- /**
69
- * Dispatch
70
- *
71
- * @return mixed dispatch event.
72
- */
73
- public function dispatch() {
74
- // Schedule the cron healthcheck.
75
- $this->schedule_event();
76
-
77
- // Perform remote post.
78
- return parent::dispatch();
79
- }
80
-
81
- /**
82
- * Push to queue
83
- *
84
- * @param mixed $data Data.
85
- *
86
- * @return $this
87
- */
88
- public function push_to_queue( $data ) {
89
- $this->data[] = $data;
90
-
91
- return $this;
92
- }
93
-
94
- /**
95
- * Save queue
96
- *
97
- * @return $this
98
- */
99
- public function save() {
100
- $key = $this->generate_key();
101
-
102
- if ( ! empty( $this->data ) ) {
103
- update_site_option( $key, $this->data );
104
- }
105
-
106
- return $this;
107
- }
108
-
109
- /**
110
- * Update queue
111
- *
112
- * @param string $key Key.
113
- * @param array $data Data.
114
- *
115
- * @return $this
116
- */
117
- public function update( $key, $data ) {
118
- if ( ! empty( $data ) ) {
119
- update_site_option( $key, $data );
120
- }
121
-
122
- return $this;
123
- }
124
-
125
- /**
126
- * Delete queue
127
- *
128
- * @param string $key Key.
129
- *
130
- * @return $this
131
- */
132
- public function delete( $key ) {
133
- delete_site_option( $key );
134
-
135
- return $this;
136
- }
137
-
138
- /**
139
- * Generate key
140
- *
141
- * Generates a unique key based on microtime. Queue items are
142
- * given a unique key so that they can be merged upon save.
143
- *
144
- * @param int $length Length.
145
- *
146
- * @return string
147
- */
148
- protected function generate_key( $length = 64 ) {
149
- $unique = md5( microtime() . rand() );
150
- $prepend = $this->identifier . '_batch_';
151
-
152
- return substr( $prepend . $unique, 0, $length );
153
- }
154
-
155
- /**
156
- * Maybe process queue
157
- *
158
- * Checks whether data exists within the queue and that
159
- * the process is not already running.
160
- */
161
- public function maybe_handle() {
162
- // Don't lock up other requests while processing.
163
- session_write_close();
164
-
165
- if ( $this->is_process_running() ) {
166
- // Background process already running.
167
- wp_die();
168
- }
169
-
170
- if ( $this->is_queue_empty() ) {
171
- // No data to process.
172
- wp_die();
173
- }
174
-
175
- check_ajax_referer( $this->identifier, 'nonce' );
176
-
177
- $this->handle();
178
-
179
- wp_die();
180
- }
181
-
182
- /**
183
- * Is queue empty
184
- *
185
- * @return bool
186
- */
187
- protected function is_queue_empty() {
188
- global $wpdb;
189
-
190
- $table = $wpdb->options;
191
- $column = 'option_name';
192
-
193
- if ( is_multisite() ) {
194
- $table = $wpdb->sitemeta;
195
- $column = 'meta_key';
196
- }
197
-
198
- $key = $this->identifier . '_batch_%';
199
-
200
- $count = $wpdb->get_var(
201
- $wpdb->prepare(
202
- "
203
- SELECT COUNT(*)
204
- FROM {$table}
205
- WHERE {$column} LIKE %s
206
- ", $key
207
- )
208
- );
209
-
210
- return ( $count > 0 ) ? false : true;
211
- }
212
-
213
- /**
214
- * Is process running
215
- *
216
- * Check whether the current process is already running
217
- * in a background process.
218
- */
219
- protected function is_process_running() {
220
- if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
221
- // Process already running.
222
- return true;
223
- }
224
-
225
- return false;
226
- }
227
-
228
- /**
229
- * Lock process
230
- *
231
- * Lock the process so that multiple instances can't run simultaneously.
232
- * Override if applicable, but the duration should be greater than that
233
- * defined in the time_exceeded() method.
234
- */
235
- protected function lock_process() {
236
- $this->start_time = time(); // Set start time of current process.
237
-
238
- $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
239
- $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
240
-
241
- set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
242
- }
243
-
244
- /**
245
- * Unlock process
246
- *
247
- * Unlock the process so that other instances can spawn.
248
- *
249
- * @return $this
250
- */
251
- protected function unlock_process() {
252
- delete_site_transient( $this->identifier . '_process_lock' );
253
-
254
- return $this;
255
- }
256
-
257
- /**
258
- * Get batch
259
- *
260
- * @return stdClass Return the first batch from the queue
261
- */
262
- protected function get_batch() {
263
- global $wpdb;
264
-
265
- $table = $wpdb->options;
266
- $column = 'option_name';
267
- $key_column = 'option_id';
268
- $value_column = 'option_value';
269
-
270
- if ( is_multisite() ) {
271
- $table = $wpdb->sitemeta;
272
- $column = 'meta_key';
273
- $key_column = 'meta_id';
274
- $value_column = 'meta_value';
275
- }
276
-
277
- $key = $this->identifier . '_batch_%';
278
-
279
- $query = $wpdb->get_row(
280
- $wpdb->prepare(
281
- "
282
- SELECT *
283
- FROM {$table}
284
- WHERE {$column} LIKE %s
285
- ORDER BY {$key_column} ASC
286
- LIMIT 1
287
- ", $key
288
- )
289
- );
290
-
291
- $batch = new stdClass();
292
- $batch->key = $query->$column;
293
- $batch->data = maybe_unserialize( $query->$value_column );
294
-
295
- return $batch;
296
- }
297
-
298
- /**
299
- * Handle
300
- *
301
- * Pass each queue item to the task handler, while remaining
302
- * within server memory and time limit constraints.
303
- */
304
- protected function handle() {
305
- $this->lock_process();
306
-
307
- do {
308
- $batch = $this->get_batch();
309
-
310
- foreach ( $batch->data as $key => $value ) {
311
- $task = $this->task( $value );
312
-
313
- if ( false !== $task ) {
314
- $batch->data[ $key ] = $task;
315
- } else {
316
- unset( $batch->data[ $key ] );
317
- }
318
-
319
- if ( $this->time_exceeded() || $this->memory_exceeded() ) {
320
- // Batch limits reached.
321
- break;
322
- }
323
- }
324
-
325
- // Update or delete current batch.
326
- if ( ! empty( $batch->data ) ) {
327
- $this->update( $batch->key, $batch->data );
328
- } else {
329
- $this->delete( $batch->key );
330
- }
331
- } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
332
-
333
- $this->unlock_process();
334
-
335
- // Start next batch or complete process.
336
- if ( ! $this->is_queue_empty() ) {
337
- $this->dispatch();
338
- } else {
339
- $this->complete();
340
- }
341
-
342
- wp_die();
343
- }
344
-
345
- /**
346
- * Memory exceeded
347
- *
348
- * Ensures the batch process never exceeds 90%
349
- * of the maximum WordPress memory.
350
- *
351
- * @return bool
352
- */
353
- protected function memory_exceeded() {
354
- $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
355
- $current_memory = memory_get_usage( true );
356
- $return = false;
357
-
358
- if ( $current_memory >= $memory_limit ) {
359
- $return = true;
360
- }
361
-
362
- return apply_filters( $this->identifier . '_memory_exceeded', $return );
363
- }
364
-
365
- /**
366
- * Get memory limit
367
- *
368
- * @return int
369
- */
370
- protected function get_memory_limit() {
371
- if ( function_exists( 'ini_get' ) ) {
372
- $memory_limit = ini_get( 'memory_limit' );
373
- } else {
374
- // Sensible default.
375
- $memory_limit = '128M';
376
- }
377
-
378
- if ( ! $memory_limit || -1 === $memory_limit ) {
379
- // Unlimited, set to 32GB.
380
- $memory_limit = '32000M';
381
- }
382
-
383
- return intval( $memory_limit ) * 1024 * 1024;
384
- }
385
-
386
- /**
387
- * Time exceeded.
388
- *
389
- * Ensures the batch never exceeds a sensible time limit.
390
- * A timeout limit of 30s is common on shared hosting.
391
- *
392
- * @return bool
393
- */
394
- protected function time_exceeded() {
395
- $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
396
- $return = false;
397
-
398
- if ( time() >= $finish ) {
399
- $return = true;
400
- }
401
-
402
- return apply_filters( $this->identifier . '_time_exceeded', $return );
403
- }
404
-
405
- /**
406
- * Complete.
407
- *
408
- * Override if applicable, but ensure that the below actions are
409
- * performed, or, call parent::complete().
410
- */
411
- protected function complete() {
412
- // Unschedule the cron healthcheck.
413
- $this->clear_scheduled_event();
414
- }
415
-
416
- /**
417
- * Schedule cron healthcheck
418
- *
419
- * @access public
420
- * @param mixed $schedules Schedules.
421
- * @return mixed
422
- */
423
- public function schedule_cron_healthcheck( $schedules ) {
424
- $interval = apply_filters( $this->identifier . '_cron_interval', 5 );
425
-
426
- if ( property_exists( $this, 'cron_interval' ) ) {
427
- $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval_identifier );
428
- }
429
-
430
- // Adds every 5 minutes to the existing schedules.
431
- $schedules[ $this->identifier . '_cron_interval' ] = array(
432
- 'interval' => MINUTE_IN_SECONDS * $interval,
433
- 'display' => sprintf( __( 'Every %d Minutes', 'astra-sites' ), $interval ),
434
- );
435
-
436
- return $schedules;
437
- }
438
-
439
- /**
440
- * Handle cron healthcheck
441
- *
442
- * Restart the background process if not already running
443
- * and data exists in the queue.
444
- */
445
- public function handle_cron_healthcheck() {
446
- if ( $this->is_process_running() ) {
447
- // Background process already running.
448
- exit;
449
- }
450
-
451
- if ( $this->is_queue_empty() ) {
452
- // No data to process.
453
- $this->clear_scheduled_event();
454
- exit;
455
- }
456
-
457
- $this->handle();
458
-
459
- exit;
460
- }
461
-
462
- /**
463
- * Schedule event
464
- */
465
- protected function schedule_event() {
466
- if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
467
- wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
468
- }
469
- }
470
-
471
- /**
472
- * Clear scheduled event
473
- */
474
- protected function clear_scheduled_event() {
475
- $timestamp = wp_next_scheduled( $this->cron_hook_identifier );
476
-
477
- if ( $timestamp ) {
478
- wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
479
- }
480
- }
481
-
482
- /**
483
- * Cancel Process
484
- *
485
- * Stop processing queue items, clear cronjob and delete batch.
486
- */
487
- public function cancel_process() {
488
- if ( ! $this->is_queue_empty() ) {
489
- $batch = $this->get_batch();
490
-
491
- $this->delete( $batch->key );
492
-
493
- wp_clear_scheduled_hook( $this->cron_hook_identifier );
494
- }
495
-
496
- }
497
-
498
- /**
499
- * Task
500
- *
501
- * Override this method to perform any actions required on each
502
- * queue item. Return the modified item for further processing
503
- * in the next pass through. Or, return false to remove the
504
- * item from the queue.
505
- *
506
- * @param mixed $item Queue item to iterate over.
507
- *
508
- * @return mixed
509
- */
510
- abstract protected function task( $item );
511
-
512
- }
513
- }
1
+ <?php
2
+ /**
3
+ * WP Background Process
4
+ *
5
+ * @see https://github.com/A5hleyRich/wp-background-processing/
6
+ * @package WP-Background-Processing
7
+ */
8
+
9
+ if ( ! class_exists( 'WP_Background_Process' ) ) {
10
+
11
+ /**
12
+ * Abstract WP_Background_Process class.
13
+ *
14
+ * @abstract
15
+ * @extends WP_Async_Request
16
+ */
17
+ abstract class WP_Background_Process extends WP_Async_Request {
18
+
19
+ /**
20
+ * Action
21
+ *
22
+ * (default value: 'background_process')
23
+ *
24
+ * @var string
25
+ * @access protected
26
+ */
27
+ protected $action = 'background_process';
28
+
29
+ /**
30
+ * Start time of current process.
31
+ *
32
+ * (default value: 0)
33
+ *
34
+ * @var int
35
+ * @access protected
36
+ */
37
+ protected $start_time = 0;
38
+
39
+ /**
40
+ * Cron_hook_identifier
41
+ *
42
+ * @var mixed
43
+ * @access protected
44
+ */
45
+ protected $cron_hook_identifier;
46
+
47
+ /**
48
+ * Cron_interval_identifier
49
+ *
50
+ * @var mixed
51
+ * @access protected
52
+ */
53
+ protected $cron_interval_identifier;
54
+
55
+ /**
56
+ * Initiate new background process
57
+ */
58
+ public function __construct() {
59
+ parent::__construct();
60
+
61
+ $this->cron_hook_identifier = $this->identifier . '_cron';
62
+ $this->cron_interval_identifier = $this->identifier . '_cron_interval';
63
+
64
+ add_action( $this->cron_hook_identifier, array( $this, 'handle_cron_healthcheck' ) );
65
+ add_filter( 'cron_schedules', array( $this, 'schedule_cron_healthcheck' ) );
66
+ }
67
+
68
+ /**
69
+ * Dispatch
70
+ *
71
+ * @return mixed dispatch event.
72
+ */
73
+ public function dispatch() {
74
+ // Schedule the cron healthcheck.
75
+ $this->schedule_event();
76
+
77
+ // Perform remote post.
78
+ return parent::dispatch();
79
+ }
80
+
81
+ /**
82
+ * Push to queue
83
+ *
84
+ * @param mixed $data Data.
85
+ *
86
+ * @return $this
87
+ */
88
+ public function push_to_queue( $data ) {
89
+ $this->data[] = $data;
90
+
91
+ return $this;
92
+ }
93
+
94
+ /**
95
+ * Save queue
96
+ *
97
+ * @return $this
98
+ */
99
+ public function save() {
100
+ $key = $this->generate_key();
101
+
102
+ if ( ! empty( $this->data ) ) {
103
+ update_site_option( $key, $this->data );
104
+ }
105
+
106
+ return $this;
107
+ }
108
+
109
+ /**
110
+ * Update queue
111
+ *
112
+ * @param string $key Key.
113
+ * @param array $data Data.
114
+ *
115
+ * @return $this
116
+ */
117
+ public function update( $key, $data ) {
118
+ if ( ! empty( $data ) ) {
119
+ update_site_option( $key, $data );
120
+ }
121
+
122
+ return $this;
123
+ }
124
+
125
+ /**
126
+ * Delete queue
127
+ *
128
+ * @param string $key Key.
129
+ *
130
+ * @return $this
131
+ */
132
+ public function delete( $key ) {
133
+ delete_site_option( $key );
134
+
135
+ return $this;
136
+ }
137
+
138
+ /**
139
+ * Generate key
140
+ *
141
+ * Generates a unique key based on microtime. Queue items are
142
+ * given a unique key so that they can be merged upon save.
143
+ *
144
+ * @param int $length Length.
145
+ *
146
+ * @return string
147
+ */
148
+ protected function generate_key( $length = 64 ) {
149
+ $unique = md5( microtime() . rand() );
150
+ $prepend = $this->identifier . '_batch_';
151
+
152
+ return substr( $prepend . $unique, 0, $length );
153
+ }
154
+
155
+ /**
156
+ * Maybe process queue
157
+ *
158
+ * Checks whether data exists within the queue and that
159
+ * the process is not already running.
160
+ */
161
+ public function maybe_handle() {
162
+ // Don't lock up other requests while processing.
163
+ session_write_close();
164
+
165
+ if ( $this->is_process_running() ) {
166
+ // Background process already running.
167
+ wp_die();
168
+ }
169
+
170
+ if ( $this->is_queue_empty() ) {
171
+ // No data to process.
172
+ wp_die();
173
+ }
174
+
175
+ check_ajax_referer( $this->identifier, 'nonce' );
176
+
177
+ $this->handle();
178
+
179
+ wp_die();
180
+ }
181
+
182
+ /**
183
+ * Is queue empty
184
+ *
185
+ * @return bool
186
+ */
187
+ protected function is_queue_empty() {
188
+ global $wpdb;
189
+
190
+ $table = $wpdb->options;
191
+ $column = 'option_name';
192
+
193
+ if ( is_multisite() ) {
194
+ $table = $wpdb->sitemeta;
195
+ $column = 'meta_key';
196
+ }
197
+
198
+ $key = $this->identifier . '_batch_%';
199
+
200
+ $count = $wpdb->get_var(
201
+ $wpdb->prepare(
202
+ "
203
+ SELECT COUNT(*)
204
+ FROM {$table}
205
+ WHERE {$column} LIKE %s
206
+ ", $key
207
+ )
208
+ );
209
+
210
+ return ( $count > 0 ) ? false : true;
211
+ }
212
+
213
+ /**
214
+ * Is process running
215
+ *
216
+ * Check whether the current process is already running
217
+ * in a background process.
218
+ */
219
+ protected function is_process_running() {
220
+ if ( get_site_transient( $this->identifier . '_process_lock' ) ) {
221
+ // Process already running.
222
+ return true;
223
+ }
224
+
225
+ return false;
226
+ }
227
+
228
+ /**
229
+ * Lock process
230
+ *
231
+ * Lock the process so that multiple instances can't run simultaneously.
232
+ * Override if applicable, but the duration should be greater than that
233
+ * defined in the time_exceeded() method.
234
+ */
235
+ protected function lock_process() {
236
+ $this->start_time = time(); // Set start time of current process.
237
+
238
+ $lock_duration = ( property_exists( $this, 'queue_lock_time' ) ) ? $this->queue_lock_time : 60; // 1 minute
239
+ $lock_duration = apply_filters( $this->identifier . '_queue_lock_time', $lock_duration );
240
+
241
+ set_site_transient( $this->identifier . '_process_lock', microtime(), $lock_duration );
242
+ }
243
+
244
+ /**
245
+ * Unlock process
246
+ *
247
+ * Unlock the process so that other instances can spawn.
248
+ *
249
+ * @return $this
250
+ */
251
+ protected function unlock_process() {
252
+ delete_site_transient( $this->identifier . '_process_lock' );
253
+
254
+ return $this;
255
+ }
256
+
257
+ /**
258
+ * Get batch
259
+ *
260
+ * @return stdClass Return the first batch from the queue
261
+ */
262
+ protected function get_batch() {
263
+ global $wpdb;
264
+
265
+ $table = $wpdb->options;
266
+ $column = 'option_name';
267
+ $key_column = 'option_id';
268
+ $value_column = 'option_value';
269
+
270
+ if ( is_multisite() ) {
271
+ $table = $wpdb->sitemeta;
272
+ $column = 'meta_key';
273
+ $key_column = 'meta_id';
274
+ $value_column = 'meta_value';
275
+ }
276
+
277
+ $key = $this->identifier . '_batch_%';
278
+
279
+ $query = $wpdb->get_row(
280
+ $wpdb->prepare(
281
+ "
282
+ SELECT *
283
+ FROM {$table}
284
+ WHERE {$column} LIKE %s
285
+ ORDER BY {$key_column} ASC
286
+ LIMIT 1
287
+ ", $key
288
+ )
289
+ );
290
+
291
+ $batch = new stdClass();
292
+ $batch->key = $query->$column;
293
+ $batch->data = maybe_unserialize( $query->$value_column );
294
+
295
+ return $batch;
296
+ }
297
+
298
+ /**
299
+ * Handle
300
+ *
301
+ * Pass each queue item to the task handler, while remaining
302
+ * within server memory and time limit constraints.
303
+ */
304
+ protected function handle() {
305
+ $this->lock_process();
306
+
307
+ do {
308
+ $batch = $this->get_batch();
309
+
310
+ foreach ( $batch->data as $key => $value ) {
311
+ $task = $this->task( $value );
312
+
313
+ if ( false !== $task ) {
314
+ $batch->data[ $key ] = $task;
315
+ } else {
316
+ unset( $batch->data[ $key ] );
317
+ }
318
+
319
+ if ( $this->time_exceeded() || $this->memory_exceeded() ) {
320
+ // Batch limits reached.
321
+ break;
322
+ }
323
+ }
324
+
325
+ // Update or delete current batch.
326
+ if ( ! empty( $batch->data ) ) {
327
+ $this->update( $batch->key, $batch->data );
328
+ } else {
329
+ $this->delete( $batch->key );
330
+ }
331
+ } while ( ! $this->time_exceeded() && ! $this->memory_exceeded() && ! $this->is_queue_empty() );
332
+
333
+ $this->unlock_process();
334
+
335
+ // Start next batch or complete process.
336
+ if ( ! $this->is_queue_empty() ) {
337
+ $this->dispatch();
338
+ } else {
339
+ $this->complete();
340
+ }
341
+
342
+ wp_die();
343
+ }
344
+
345
+ /**
346
+ * Memory exceeded
347
+ *
348
+ * Ensures the batch process never exceeds 90%
349
+ * of the maximum WordPress memory.
350
+ *
351
+ * @return bool
352
+ */
353
+ protected function memory_exceeded() {
354
+ $memory_limit = $this->get_memory_limit() * 0.9; // 90% of max memory
355
+ $current_memory = memory_get_usage( true );
356
+ $return = false;
357
+
358
+ if ( $current_memory >= $memory_limit ) {
359
+ $return = true;
360
+ }
361
+
362
+ return apply_filters( $this->identifier . '_memory_exceeded', $return );
363
+ }
364
+
365
+ /**
366
+ * Get memory limit
367
+ *
368
+ * @return int
369
+ */
370
+ protected function get_memory_limit() {
371
+ if ( function_exists( 'ini_get' ) ) {
372
+ $memory_limit = ini_get( 'memory_limit' );
373
+ } else {
374
+ // Sensible default.
375
+ $memory_limit = '128M';
376
+ }
377
+
378
+ if ( ! $memory_limit || -1 === $memory_limit ) {
379
+ // Unlimited, set to 32GB.
380
+ $memory_limit = '32000M';
381
+ }
382
+
383
+ return intval( $memory_limit ) * 1024 * 1024;
384
+ }
385
+
386
+ /**
387
+ * Time exceeded.
388
+ *
389
+ * Ensures the batch never exceeds a sensible time limit.
390
+ * A timeout limit of 30s is common on shared hosting.
391
+ *
392
+ * @return bool
393
+ */
394
+ protected function time_exceeded() {
395
+ $finish = $this->start_time + apply_filters( $this->identifier . '_default_time_limit', 20 ); // 20 seconds
396
+ $return = false;
397
+
398
+ if ( time() >= $finish ) {
399
+ $return = true;
400
+ }
401
+
402
+ return apply_filters( $this->identifier . '_time_exceeded', $return );
403
+ }
404
+
405
+ /**
406
+ * Complete.
407
+ *
408
+ * Override if applicable, but ensure that the below actions are
409
+ * performed, or, call parent::complete().
410
+ */
411
+ protected function complete() {
412
+ // Unschedule the cron healthcheck.
413
+ $this->clear_scheduled_event();
414
+ }
415
+
416
+ /**
417
+ * Schedule cron healthcheck
418
+ *
419
+ * @access public
420
+ * @param mixed $schedules Schedules.
421
+ * @return mixed
422
+ */
423
+ public function schedule_cron_healthcheck( $schedules ) {
424
+ $interval = apply_filters( $this->identifier . '_cron_interval', 5 );
425
+
426
+ if ( property_exists( $this, 'cron_interval' ) ) {
427
+ $interval = apply_filters( $this->identifier . '_cron_interval', $this->cron_interval_identifier );
428
+ }
429
+
430
+ // Adds every 5 minutes to the existing schedules.
431
+ $schedules[ $this->identifier . '_cron_interval' ] = array(
432
+ 'interval' => MINUTE_IN_SECONDS * $interval,
433
+ 'display' => sprintf( __( 'Every %d Minutes', 'astra-sites' ), $interval ),
434
+ );
435
+
436
+ return $schedules;
437
+ }
438
+
439
+ /**
440
+ * Handle cron healthcheck
441
+ *
442
+ * Restart the background process if not already running
443
+ * and data exists in the queue.
444
+ */
445
+ public function handle_cron_healthcheck() {
446
+ if ( $this->is_process_running() ) {
447
+ // Background process already running.
448
+ exit;
449
+ }
450
+
451
+ if ( $this->is_queue_empty() ) {
452
+ // No data to process.
453
+ $this->clear_scheduled_event();
454
+ exit;
455
+ }
456
+
457
+ $this->handle();
458
+
459
+ exit;
460
+ }
461
+
462
+ /**
463
+ * Schedule event
464
+ */
465
+ protected function schedule_event() {
466
+ if ( ! wp_next_scheduled( $this->cron_hook_identifier ) ) {
467
+ wp_schedule_event( time(), $this->cron_interval_identifier, $this->cron_hook_identifier );
468
+ }
469
+ }
470
+
471
+ /**
472
+ * Clear scheduled event
473
+ */
474
+ protected function clear_scheduled_event() {
475
+ $timestamp = wp_next_scheduled( $this->cron_hook_identifier );
476
+
477
+ if ( $timestamp ) {
478
+ wp_unschedule_event( $timestamp, $this->cron_hook_identifier );
479
+ }
480
+ }
481
+
482
+ /**
483
+ * Cancel Process
484
+ *
485
+ * Stop processing queue items, clear cronjob and delete batch.
486
+ */
487
+ public function cancel_process() {
488
+ if ( ! $this->is_queue_empty() ) {
489
+ $batch = $this->get_batch();
490
+
491
+ $this->delete( $batch->key );
492
+
493
+ wp_clear_scheduled_hook( $this->cron_hook_identifier );
494
+ }
495
+
496
+ }
497
+
498
+ /**
499
+ * Task
500
+ *
501
+ * Override this method to perform any actions required on each
502
+ * queue item. Return the modified item for further processing
503
+ * in the next pass through. Or, return false to remove the
504
+ * item from the queue.
505
+ *
506
+ * @param mixed $item Queue item to iterate over.
507
+ *
508
+ * @return mixed
509
+ */
510
+ abstract protected function task( $item );
511
+
512
+ }
513
+ }
inc/importers/class-astra-customizer-import.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
- /**
3
- * Customizer Data importer class.
4
- *
5
- * @since 1.0.0
6
- * @package Astra Addon
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Customizer Data importer class.
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_Customizer_Import {
17
-
18
- /**
19
- * Instance of Astra_Customizer_Import
20
- *
21
- * @since 1.0.0
22
- * @var Astra_Customizer_Import
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Instantiate Astra_Customizer_Import
28
- *
29
- * @since 1.0.0
30
- * @return (Object) Astra_Customizer_Import
31
- */
32
- public static function instance() {
33
-
34
- if ( ! isset( self::$_instance ) ) {
35
- self::$_instance = new self;
36
- }
37
-
38
- return self::$_instance;
39
- }
40
-
41
- /**
42
- * Import customizer options.
43
- *
44
- * @since 1.0.0
45
- *
46
- * @param (Array) $options customizer options from the demo.
47
- */
48
- public function import( $options ) {
49
-
50
- // Update Astra Theme customizer settings.
51
- if ( isset( $options['astra-settings'] ) ) {
52
- self::_import_settings( $options['astra-settings'] );
53
- }
54
-
55
- // Add Custom CSS.
56
- if ( isset( $options['custom-css'] ) ) {
57
- wp_update_custom_css_post( $options['custom-css'] );
58
- }
59
-
60
- }
61
-
62
- /**
63
- * Import Astra Setting's
64
- *
65
- * Download & Import images from Astra Customizer Settings.
66
- *
67
- * @since 1.0.10
68
- *
69
- * @param array $options Astra Customizer setting array.
70
- * @return void
71
- */
72
- static public function _import_settings( $options = array() ) {
73
- foreach ( $options as $key => $val ) {
74
-
75
- if ( Astra_Sites_Helper::_is_image_url( $val ) ) {
76
-
77
- $data = Astra_Sites_Helper::_sideload_image( $val );
78
-
79
- if ( ! is_wp_error( $data ) ) {
80
- $options[ $key ] = $data->url;
81
- }
82
- }
83
- }
84
-
85
- // Updated settings.
86
- update_option( 'astra-settings', $options );
87
- }
88
- }
1
+ <?php
2
+ /**
3
+ * Customizer Data importer class.
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Addon
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Customizer Data importer class.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Customizer_Import {
17
+
18
+ /**
19
+ * Instance of Astra_Customizer_Import
20
+ *
21
+ * @since 1.0.0
22
+ * @var Astra_Customizer_Import
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Instantiate Astra_Customizer_Import
28
+ *
29
+ * @since 1.0.0
30
+ * @return (Object) Astra_Customizer_Import
31
+ */
32
+ public static function instance() {
33
+
34
+ if ( ! isset( self::$_instance ) ) {
35
+ self::$_instance = new self;
36
+ }
37
+
38
+ return self::$_instance;
39
+ }
40
+
41
+ /**
42
+ * Import customizer options.
43
+ *
44
+ * @since 1.0.0
45
+ *
46
+ * @param (Array) $options customizer options from the demo.
47
+ */
48
+ public function import( $options ) {
49
+
50
+ // Update Astra Theme customizer settings.
51
+ if ( isset( $options['astra-settings'] ) ) {
52
+ self::_import_settings( $options['astra-settings'] );
53
+ }
54
+
55
+ // Add Custom CSS.
56
+ if ( isset( $options['custom-css'] ) ) {
57
+ wp_update_custom_css_post( $options['custom-css'] );
58
+ }
59
+
60
+ }
61
+
62
+ /**
63
+ * Import Astra Setting's
64
+ *
65
+ * Download & Import images from Astra Customizer Settings.
66
+ *
67
+ * @since 1.0.10
68
+ *
69
+ * @param array $options Astra Customizer setting array.
70
+ * @return void
71
+ */
72
+ static public function _import_settings( $options = array() ) {
73
+ foreach ( $options as $key => $val ) {
74
+
75
+ if ( Astra_Sites_Helper::_is_image_url( $val ) ) {
76
+
77
+ $data = Astra_Sites_Helper::_sideload_image( $val );
78
+
79
+ if ( ! is_wp_error( $data ) ) {
80
+ $options[ $key ] = $data->url;
81
+ }
82
+ }
83
+ }
84
+
85
+ // Updated settings.
86
+ update_option( 'astra-settings', $options );
87
+ }
88
+ }
inc/importers/class-astra-site-options-import.php CHANGED
@@ -1,287 +1,289 @@
1
- <?php
2
- /**
3
- * Customizer Site options importer class.
4
- *
5
- * @since 1.0.0
6
- * @package Astra Addon
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Customizer Site options importer class.
13
- *
14
- * @since 1.0.0
15
- */
16
- class Astra_Site_Options_Import {
17
-
18
- /**
19
- * Instance of Astra_Site_Options_Importer
20
- *
21
- * @since 1.0.0
22
- * @var (Object) Astra_Site_Options_Importer
23
- */
24
- private static $_instance = null;
25
-
26
- /**
27
- * Instanciate Astra_Site_Options_Importer
28
- *
29
- * @since 1.0.0
30
- * @return (Object) Astra_Site_Options_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
- * Site Options
42
- *
43
- * @since 1.0.2
44
- *
45
- * @return array List of defined array.
46
- */
47
- private static function site_options() {
48
- return array(
49
- 'custom_logo',
50
- 'nav_menu_locations',
51
- 'show_on_front',
52
- 'page_on_front',
53
- 'page_for_posts',
54
-
55
- // Plugin: SiteOrigin Widgets Bundle.
56
- 'siteorigin_widgets_active',
57
-
58
- // Plugin: Elementor.
59
- 'elementor_container_width',
60
- 'elementor_cpt_support',
61
- 'elementor_css_print_method',
62
- 'elementor_default_generic_fonts',
63
- 'elementor_disable_color_schemes',
64
- 'elementor_disable_typography_schemes',
65
- 'elementor_editor_break_lines',
66
- 'elementor_exclude_user_roles',
67
- 'elementor_global_image_lightbox',
68
- 'elementor_page_title_selector',
69
- 'elementor_scheme_color',
70
- 'elementor_scheme_color-picker',
71
- 'elementor_scheme_typography',
72
- 'elementor_space_between_widgets',
73
- 'elementor_stretched_section_container',
74
-
75
- // Plugin: Beaver Builder.
76
- '_fl_builder_enabled_icons',
77
- '_fl_builder_enabled_modules',
78
- '_fl_builder_post_types',
79
- '_fl_builder_color_presets',
80
- '_fl_builder_services',
81
- '_fl_builder_settings',
82
- '_fl_builder_user_access',
83
- '_fl_builder_enabled_templates',
84
-
85
- // Plugin: WooCommerce.
86
- // Pages.
87
- 'woocommerce_shop_page_title',
88
- 'woocommerce_cart_page_title',
89
- 'woocommerce_checkout_page_title',
90
- 'woocommerce_myaccount_page_title',
91
- 'woocommerce_edit_address_page_title',
92
- 'woocommerce_view_order_page_title',
93
- 'woocommerce_change_password_page_title',
94
- 'woocommerce_logout_page_title',
95
- 'woocommerce_enable_guest_checkout',
96
- 'woocommerce_enable_checkout_login_reminder',
97
- 'woocommerce_enable_signup_and_login_from_checkout',
98
- 'woocommerce_enable_myaccount_registration',
99
- 'woocommerce_registration_generate_username',
100
-
101
- // Plugin: WPForms.
102
- 'wpforms_settings',
103
-
104
- // Categories.
105
- 'woocommerce_product_cat',
106
- );
107
- }
108
-
109
- /**
110
- * Import site options.
111
- *
112
- * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
113
- *
114
- * @since 1.0.0
115
- *
116
- * @param (Array) $options Array of site options to be imported from the demo.
117
- */
118
- public function import_options( $options = array() ) {
119
-
120
- if ( ! isset( $options ) ) {
121
- return;
122
- }
123
-
124
- foreach ( $options as $option_name => $option_value ) {
125
-
126
- // Is option exist in defined array site_options()?
127
- if ( null !== $option_value ) {
128
-
129
- // Is option exist in defined array site_options()?
130
- if ( in_array( $option_name, self::site_options() ) ) {
131
-
132
- switch ( $option_name ) {
133
-
134
- // Set WooCommerce page ID by page Title.
135
- case 'woocommerce_shop_page_title':
136
- case 'woocommerce_cart_page_title':
137
- case 'woocommerce_checkout_page_title':
138
- case 'woocommerce_myaccount_page_title':
139
- case 'woocommerce_edit_address_page_title':
140
- case 'woocommerce_view_order_page_title':
141
- case 'woocommerce_change_password_page_title':
142
- case 'woocommerce_logout_page_title':
143
- $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
144
- break;
145
-
146
- case 'page_for_posts':
147
- case 'page_on_front':
148
- $this->update_page_id_by_option_value( $option_name, $option_value );
149
- break;
150
-
151
- // nav menu locations.
152
- case 'nav_menu_locations':
153
- $this->set_nav_menu_locations( $option_value );
154
- break;
155
-
156
- // import WooCommerce category images.
157
- case 'woocommerce_product_cat':
158
- $this->set_woocommerce_product_cat( $option_value );
159
- break;
160
-
161
- // insert logo.
162
- case 'custom_logo':
163
- $this->insert_logo( $option_value );
164
- break;
165
-
166
- default:
167
- update_option( $option_name, $option_value );
168
- break;
169
- }
170
- }
171
- }
172
- }
173
- }
174
-
175
- /**
176
- * Update post option
177
- *
178
- * @since 1.0.2
179
- *
180
- * @param string $option_name Option name.
181
- * @param mixed $option_value Option value.
182
- * @return void
183
- */
184
- private function update_page_id_by_option_value( $option_name, $option_value ) {
185
- $page = get_page_by_title( $option_value );
186
- if ( is_object( $page ) ) {
187
- update_option( $option_name, $page->ID );
188
- }
189
- }
190
-
191
- /**
192
- * Update WooCommerce page ids.
193
- *
194
- * @since 1.1.6
195
- *
196
- * @param string $option_name Option name.
197
- * @param mixed $option_value Option value.
198
- * @return void
199
- */
200
- private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
201
- $option_name = str_replace( '_title', '_id', $option_name );
202
- $this->update_page_id_by_option_value( $option_name, $option_value );
203
- }
204
-
205
- /**
206
- * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
207
- * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
208
- * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
209
- *
210
- * @since 1.0.0
211
- * @param array $nav_menu_locations Array of nav menu locations.
212
- */
213
- private function set_nav_menu_locations( $nav_menu_locations = array() ) {
214
-
215
- $menu_locations = array();
216
-
217
- // Update menu locations.
218
- if ( isset( $nav_menu_locations ) ) {
219
-
220
- foreach ( $nav_menu_locations as $menu => $value ) {
221
-
222
- $term = get_term_by( 'slug', $value, 'nav_menu' );
223
-
224
- if ( is_object( $term ) ) {
225
- $menu_locations[ $menu ] = $term->term_id;
226
- }
227
- }
228
-
229
- set_theme_mod( 'nav_menu_locations', $menu_locations );
230
- }
231
- }
232
-
233
- /**
234
- * Set WooCommerce category images.
235
- *
236
- * @since 1.1.4
237
- *
238
- * @param array $cats Array of categories.
239
- */
240
- private function set_woocommerce_product_cat( $cats = array() ) {
241
-
242
- $menu_locations = array();
243
-
244
- if ( isset( $cats ) ) {
245
-
246
- foreach ( $cats as $key => $cat ) {
247
-
248
- if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
249
-
250
- $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
251
-
252
- if ( ! is_wp_error( $image ) ) {
253
-
254
- if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
255
-
256
- $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
257
-
258
- if ( is_object( $term ) ) {
259
- update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
260
- }
261
- }
262
- }
263
- }
264
- }
265
- }
266
- }
267
-
268
- /**
269
- * Insert Logo By URL
270
- *
271
- * @since 1.0.0
272
- * @param string $image_url Logo URL.
273
- * @return void
274
- */
275
- private function insert_logo( $image_url = '' ) {
276
-
277
- $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
278
-
279
- if ( ! is_wp_error( $data ) ) {
280
-
281
- if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
282
- set_theme_mod( 'custom_logo', $data->attachment_id );
283
- }
284
- }
285
- }
286
-
287
- }
 
 
1
+ <?php
2
+ /**
3
+ * Customizer Site options importer class.
4
+ *
5
+ * @since 1.0.0
6
+ * @package Astra Addon
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Customizer Site options importer class.
13
+ *
14
+ * @since 1.0.0
15
+ */
16
+ class Astra_Site_Options_Import {
17
+
18
+ /**
19
+ * Instance of Astra_Site_Options_Importer
20
+ *
21
+ * @since 1.0.0
22
+ * @var (Object) Astra_Site_Options_Importer
23
+ */
24
+ private static $_instance = null;
25
+
26
+ /**
27
+ * Instanciate Astra_Site_Options_Importer
28
+ *
29
+ * @since 1.0.0
30
+ * @return (Object) Astra_Site_Options_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
+ * Site Options
42
+ *
43
+ * @since 1.0.2
44
+ *
45
+ * @return array List of defined array.
46
+ */
47
+ private static function site_options() {
48
+ return array(
49
+ 'custom_logo',
50
+ 'nav_menu_locations',
51
+ 'show_on_front',
52
+ 'page_on_front',
53
+ 'page_for_posts',
54
+
55
+ // Plugin: SiteOrigin Widgets Bundle.
56
+ 'siteorigin_widgets_active',
57
+
58
+ // Plugin: Elementor.
59
+ 'elementor_container_width',
60
+ 'elementor_cpt_support',
61
+ 'elementor_css_print_method',
62
+ 'elementor_default_generic_fonts',
63
+ 'elementor_disable_color_schemes',
64
+ 'elementor_disable_typography_schemes',
65
+ 'elementor_editor_break_lines',
66
+ 'elementor_exclude_user_roles',
67
+ 'elementor_global_image_lightbox',
68
+ 'elementor_page_title_selector',
69
+ 'elementor_scheme_color',
70
+ 'elementor_scheme_color-picker',
71
+ 'elementor_scheme_typography',
72
+ 'elementor_space_between_widgets',
73
+ 'elementor_stretched_section_container',
74
+
75
+ // Plugin: Beaver Builder.
76
+ '_fl_builder_enabled_icons',
77
+ '_fl_builder_enabled_modules',
78
+ '_fl_builder_post_types',
79
+ '_fl_builder_color_presets',
80
+ '_fl_builder_services',
81
+ '_fl_builder_settings',
82
+ '_fl_builder_user_access',
83
+ '_fl_builder_enabled_templates',
84
+
85
+ // Plugin: WooCommerce.
86
+ // Pages.
87
+ 'woocommerce_shop_page_title',
88
+ 'woocommerce_cart_page_title',
89
+ 'woocommerce_checkout_page_title',
90
+ 'woocommerce_myaccount_page_title',
91
+ 'woocommerce_edit_address_page_title',
92
+ 'woocommerce_view_order_page_title',
93
+ 'woocommerce_change_password_page_title',
94
+ 'woocommerce_logout_page_title',
95
+
96
+ // Account & Privacy.
97
+ 'woocommerce_enable_guest_checkout',
98
+ 'woocommerce_enable_checkout_login_reminder',
99
+ 'woocommerce_enable_signup_and_login_from_checkout',
100
+ 'woocommerce_enable_myaccount_registration',
101
+ 'woocommerce_registration_generate_username',
102
+
103
+ // Plugin: WPForms.
104
+ 'wpforms_settings',
105
+
106
+ // Categories.
107
+ 'woocommerce_product_cat',
108
+ );
109
+ }
110
+
111
+ /**
112
+ * Import site options.
113
+ *
114
+ * @since 1.0.2 Updated option if exist in defined option array 'site_options()'.
115
+ *
116
+ * @since 1.0.0
117
+ *
118
+ * @param (Array) $options Array of site options to be imported from the demo.
119
+ */
120
+ public function import_options( $options = array() ) {
121
+
122
+ if ( ! isset( $options ) ) {
123
+ return;
124
+ }
125
+
126
+ foreach ( $options as $option_name => $option_value ) {
127
+
128
+ // Is option exist in defined array site_options()?
129
+ if ( null !== $option_value ) {
130
+
131
+ // Is option exist in defined array site_options()?
132
+ if ( in_array( $option_name, self::site_options() ) ) {
133
+
134
+ switch ( $option_name ) {
135
+
136
+ // Set WooCommerce page ID by page Title.
137
+ case 'woocommerce_shop_page_title':
138
+ case 'woocommerce_cart_page_title':
139
+ case 'woocommerce_checkout_page_title':
140
+ case 'woocommerce_myaccount_page_title':
141
+ case 'woocommerce_edit_address_page_title':
142
+ case 'woocommerce_view_order_page_title':
143
+ case 'woocommerce_change_password_page_title':
144
+ case 'woocommerce_logout_page_title':
145
+ $this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
146
+ break;
147
+
148
+ case 'page_for_posts':
149
+ case 'page_on_front':
150
+ $this->update_page_id_by_option_value( $option_name, $option_value );
151
+ break;
152
+
153
+ // nav menu locations.
154
+ case 'nav_menu_locations':
155
+ $this->set_nav_menu_locations( $option_value );
156
+ break;
157
+
158
+ // import WooCommerce category images.
159
+ case 'woocommerce_product_cat':
160
+ $this->set_woocommerce_product_cat( $option_value );
161
+ break;
162
+
163
+ // insert logo.
164
+ case 'custom_logo':
165
+ $this->insert_logo( $option_value );
166
+ break;
167
+
168
+ default:
169
+ update_option( $option_name, $option_value );
170
+ break;
171
+ }
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Update post option
179
+ *
180
+ * @since 1.0.2
181
+ *
182
+ * @param string $option_name Option name.
183
+ * @param mixed $option_value Option value.
184
+ * @return void
185
+ */
186
+ private function update_page_id_by_option_value( $option_name, $option_value ) {
187
+ $page = get_page_by_title( $option_value );
188
+ if ( is_object( $page ) ) {
189
+ update_option( $option_name, $page->ID );
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Update WooCommerce page ids.
195
+ *
196
+ * @since 1.1.6
197
+ *
198
+ * @param string $option_name Option name.
199
+ * @param mixed $option_value Option value.
200
+ * @return void
201
+ */
202
+ private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
203
+ $option_name = str_replace( '_title', '_id', $option_name );
204
+ $this->update_page_id_by_option_value( $option_name, $option_value );
205
+ }
206
+
207
+ /**
208
+ * In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
209
+ * In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
210
+ * In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
211
+ *
212
+ * @since 1.0.0
213
+ * @param array $nav_menu_locations Array of nav menu locations.
214
+ */
215
+ private function set_nav_menu_locations( $nav_menu_locations = array() ) {
216
+
217
+ $menu_locations = array();
218
+
219
+ // Update menu locations.
220
+ if ( isset( $nav_menu_locations ) ) {
221
+
222
+ foreach ( $nav_menu_locations as $menu => $value ) {
223
+
224
+ $term = get_term_by( 'slug', $value, 'nav_menu' );
225
+
226
+ if ( is_object( $term ) ) {
227
+ $menu_locations[ $menu ] = $term->term_id;
228
+ }
229
+ }
230
+
231
+ set_theme_mod( 'nav_menu_locations', $menu_locations );
232
+ }
233
+ }
234
+
235
+ /**
236
+ * Set WooCommerce category images.
237
+ *
238
+ * @since 1.1.4
239
+ *
240
+ * @param array $cats Array of categories.
241
+ */
242
+ private function set_woocommerce_product_cat( $cats = array() ) {
243
+
244
+ $menu_locations = array();
245
+
246
+ if ( isset( $cats ) ) {
247
+
248
+ foreach ( $cats as $key => $cat ) {
249
+
250
+ if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
251
+
252
+ $image = (object) Astra_Sites_Helper::_sideload_image( $cat['thumbnail_src'] );
253
+
254
+ if ( ! is_wp_error( $image ) ) {
255
+
256
+ if ( isset( $image->attachment_id ) && ! empty( $image->attachment_id ) ) {
257
+
258
+ $term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
259
+
260
+ if ( is_object( $term ) ) {
261
+ update_term_meta( $term->term_id, 'thumbnail_id', $image->attachment_id );
262
+ }
263
+ }
264
+ }
265
+ }
266
+ }
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Insert Logo By URL
272
+ *
273
+ * @since 1.0.0
274
+ * @param string $image_url Logo URL.
275
+ * @return void
276
+ */
277
+ private function insert_logo( $image_url = '' ) {
278
+
279
+ $data = (object) Astra_Sites_Helper::_sideload_image( $image_url );
280
+
281
+ if ( ! is_wp_error( $data ) ) {
282
+
283
+ if ( isset( $data->attachment_id ) && ! empty( $data->attachment_id ) ) {
284
+ set_theme_mod( 'custom_logo', $data->attachment_id );
285
+ }
286
+ }
287
+ }
288
+
289
+ }
inc/importers/class-astra-sites-helper.php CHANGED
@@ -1,311 +1,311 @@
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
- 'mimes' => array(
207
- 'xml' => 'text/xml',
208
- 'json' => 'text/plain',
209
- ),
210
- );
211
-
212
- // Move the temporary file into the uploads directory.
213
- $results = wp_handle_sideload( $file_args, $overrides );
214
-
215
- if ( isset( $results['error'] ) ) {
216
- return array(
217
- 'success' => false,
218
- 'data' => $results,
219
- );
220
- }
221
-
222
- // Success.
223
- return array(
224
- 'success' => true,
225
- 'data' => $results,
226
- );
227
- }
228
-
229
- /**
230
- * Downloads an image from the specified URL.
231
- *
232
- * Taken from the core media_sideload_image() function and
233
- * modified to return an array of data instead of html.
234
- *
235
- * @since 1.0.10
236
- *
237
- * @param string $file The image file path.
238
- * @return array An array of image data.
239
- */
240
- static public function _sideload_image( $file ) {
241
- $data = new stdClass();
242
-
243
- if ( ! function_exists( 'media_handle_sideload' ) ) {
244
- require_once( ABSPATH . 'wp-admin/includes/media.php' );
245
- require_once( ABSPATH . 'wp-admin/includes/file.php' );
246
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
247
- }
248
-
249
- if ( ! empty( $file ) ) {
250
-
251
- // Set variables for storage, fix file filename for query strings.
252
- preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
253
- $file_array = array();
254
- $file_array['name'] = basename( $matches[0] );
255
-
256
- // Download file to temp location.
257
- $file_array['tmp_name'] = download_url( $file );
258
-
259
- // If error storing temporarily, return the error.
260
- if ( is_wp_error( $file_array['tmp_name'] ) ) {
261
- return $file_array['tmp_name'];
262
- }
263
-
264
- // Do the validation and storage stuff.
265
- $id = media_handle_sideload( $file_array, 0 );
266
-
267
- // If error storing permanently, unlink.
268
- if ( is_wp_error( $id ) ) {
269
- unlink( $file_array['tmp_name'] );
270
- return $id;
271
- }
272
-
273
- // Build the object to return.
274
- $meta = wp_get_attachment_metadata( $id );
275
- $data->attachment_id = $id;
276
- $data->url = wp_get_attachment_url( $id );
277
- $data->thumbnail_url = wp_get_attachment_thumb_url( $id );
278
- $data->height = $meta['height'];
279
- $data->width = $meta['width'];
280
- }
281
-
282
- return $data;
283
- }
284
-
285
- /**
286
- * Checks to see whether a string is an image url or not.
287
- *
288
- * @since 1.0.10
289
- *
290
- * @param string $string The string to check.
291
- * @return bool Whether the string is an image url or not.
292
- */
293
- static public function _is_image_url( $string = '' ) {
294
- if ( is_string( $string ) ) {
295
-
296
- if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
297
- return true;
298
- }
299
- }
300
-
301
- return false;
302
- }
303
-
304
- }
305
-
306
- /**
307
- * Kicking this off by calling 'get_instance()' method
308
- */
309
- Astra_Sites_Helper::get_instance();
310
-
311
- 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
+ 'mimes' => array(
207
+ 'xml' => 'text/xml',
208
+ 'json' => 'text/plain',
209
+ ),
210
+ );
211
+
212
+ // Move the temporary file into the uploads directory.
213
+ $results = wp_handle_sideload( $file_args, $overrides );
214
+
215
+ if ( isset( $results['error'] ) ) {
216
+ return array(
217
+ 'success' => false,
218
+ 'data' => $results,
219
+ );
220
+ }
221
+
222
+ // Success.
223
+ return array(
224
+ 'success' => true,
225
+ 'data' => $results,
226
+ );
227
+ }
228
+
229
+ /**
230
+ * Downloads an image from the specified URL.
231
+ *
232
+ * Taken from the core media_sideload_image() function and
233
+ * modified to return an array of data instead of html.
234
+ *
235
+ * @since 1.0.10
236
+ *
237
+ * @param string $file The image file path.
238
+ * @return array An array of image data.
239
+ */
240
+ static public function _sideload_image( $file ) {
241
+ $data = new stdClass();
242
+
243
+ if ( ! function_exists( 'media_handle_sideload' ) ) {
244
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
245
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
246
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
247
+ }
248
+
249
+ if ( ! empty( $file ) ) {
250
+
251
+ // Set variables for storage, fix file filename for query strings.
252
+ preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
253
+ $file_array = array();
254
+ $file_array['name'] = basename( $matches[0] );
255
+
256
+ // Download file to temp location.
257
+ $file_array['tmp_name'] = download_url( $file );
258
+
259
+ // If error storing temporarily, return the error.
260
+ if ( is_wp_error( $file_array['tmp_name'] ) ) {
261
+ return $file_array['tmp_name'];
262
+ }
263
+
264
+ // Do the validation and storage stuff.
265
+ $id = media_handle_sideload( $file_array, 0 );
266
+
267
+ // If error storing permanently, unlink.
268
+ if ( is_wp_error( $id ) ) {
269
+ unlink( $file_array['tmp_name'] );
270
+ return $id;
271
+ }
272
+
273
+ // Build the object to return.
274
+ $meta = wp_get_attachment_metadata( $id );
275
+ $data->attachment_id = $id;
276
+ $data->url = wp_get_attachment_url( $id );
277
+ $data->thumbnail_url = wp_get_attachment_thumb_url( $id );
278
+ $data->height = $meta['height'];
279
+ $data->width = $meta['width'];
280
+ }
281
+
282
+ return $data;
283
+ }
284
+
285
+ /**
286
+ * Checks to see whether a string is an image url or not.
287
+ *
288
+ * @since 1.0.10
289
+ *
290
+ * @param string $string The string to check.
291
+ * @return bool Whether the string is an image url or not.
292
+ */
293
+ static public function _is_image_url( $string = '' ) {
294
+ if ( is_string( $string ) ) {
295
+
296
+ if ( preg_match( '/\.(jpg|jpeg|png|gif)/i', $string ) ) {
297
+ return true;
298
+ }
299
+ }
300
+
301
+ return false;
302
+ }
303
+
304
+ }
305
+
306
+ /**
307
+ * Kicking this off by calling 'get_instance()' method
308
+ */
309
+ Astra_Sites_Helper::get_instance();
310
+
311
+ endif;
inc/importers/class-widgets-importer.php CHANGED
@@ -1,278 +1,278 @@
1
- <?php
2
- /**
3
- * Widget Data exporter class.
4
- *
5
- * @package Astra Addon
6
- * @see - https://wordpress.org/plugins/widget-importer-exporter/
7
- */
8
-
9
- defined( 'ABSPATH' ) or exit;
10
-
11
- /**
12
- * Widget Data exporter class.
13
- *
14
- * @see - https://wordpress.org/plugins/widget-importer-exporter/
15
- */
16
- class Astra_Widget_Importer {
17
-
18
- /**
19
- * Instance of Astra_Widget_Importer
20
- *
21
- * @var Astra_Widget_Importer
22
- */
23
- private static $_instance = null;
24
-
25
- public static function instance() {
26
-
27
- if ( ! isset( self::$_instance ) ) {
28
- self::$_instance = new self;
29
- }
30
-
31
- return self::$_instance;
32
- }
33
-
34
- /**
35
- * Available widgets
36
- *
37
- * Gather site's widgets into array with ID base, name, etc.
38
- * Used by export and import functions.
39
- *
40
- * @since 0.4
41
- * @global array $wp_registered_widget_updates
42
- * @return array Widget information
43
- */
44
- function wie_available_widgets() {
45
-
46
- global $wp_registered_widget_controls;
47
-
48
- $widget_controls = $wp_registered_widget_controls;
49
-
50
- $available_widgets = array();
51
-
52
- foreach ( $widget_controls as $widget ) {
53
-
54
- if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) { // no dupes
55
-
56
- $available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
57
- $available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
58
-
59
- }
60
- }
61
-
62
- return apply_filters( 'wie_available_widgets', $available_widgets );
63
- }
64
-
65
- /**
66
- * Import widget JSON data
67
- *
68
- * @since 0.4
69
- * @global array $wp_registered_sidebars
70
- *
71
- * @param object $data JSON widget data from .wie file
72
- *
73
- * @return array Results array
74
- */
75
- function import_widgets_data( $data ) {
76
-
77
- global $wp_registered_sidebars;
78
-
79
- // Have valid data?
80
- // If no data or could not decode
81
- if ( empty( $data ) || ! is_object( $data ) ) {
82
- wp_die(
83
- esc_html__( 'Import data could not be read. Please try a different file.', 'astra-sites' ),
84
- '',
85
- array(
86
- 'back_link' => true,
87
- )
88
- );
89
- }
90
-
91
- // Hook before import
92
- do_action( 'wie_before_import' );
93
- $data = apply_filters( 'wie_import_data', $data );
94
-
95
- // Get all available widgets site supports
96
- $available_widgets = $this->wie_available_widgets();
97
-
98
- // Get all existing widget instances
99
- $widget_instances = array();
100
- foreach ( $available_widgets as $widget_data ) {
101
- $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
102
- }
103
-
104
- // Begin results
105
- $results = array();
106
-
107
- // Loop import data's sidebars
108
- foreach ( $data as $sidebar_id => $widgets ) {
109
-
110
- // Skip inactive widgets
111
- // (should not be in export file)
112
- if ( 'wp_inactive_widgets' == $sidebar_id ) {
113
- continue;
114
- }
115
-
116
- // Check if sidebar is available on this site
117
- // Otherwise add widgets to inactive, and say so
118
- if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
119
- $sidebar_available = true;
120
- $use_sidebar_id = $sidebar_id;
121
- $sidebar_message_type = 'success';
122
- $sidebar_message = '';
123
- } else {
124
- $sidebar_available = false;
125
- $use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme
126
- $sidebar_message_type = 'error';
127
- $sidebar_message = esc_html__( 'Widget area does not exist in theme (using Inactive)', 'astra-sites' );
128
- }
129
-
130
- // Result for sidebar
131
- $results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID
132
- $results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
133
- $results[ $sidebar_id ]['message'] = $sidebar_message;
134
- $results[ $sidebar_id ]['widgets'] = array();
135
-
136
- // Loop widgets
137
- foreach ( $widgets as $widget_instance_id => $widget ) {
138
-
139
- $fail = false;
140
-
141
- // Get id_base (remove -# from end) and instance ID number
142
- $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
143
- $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
144
-
145
- // Does site support this widget?
146
- if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
147
- $fail = true;
148
- $widget_message_type = 'error';
149
- $widget_message = esc_html__( 'Site does not support widget', 'astra-sites' ); // explain why widget not imported
150
- }
151
-
152
- // Filter to modify settings object before conversion to array and import
153
- // Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below)
154
- // Ideally the newer wie_widget_settings_array below will be used instead of this
155
- $widget = apply_filters( 'wie_widget_settings', $widget ); // object
156
-
157
- // Convert multidimensional objects to multidimensional arrays
158
- // Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
159
- // Without this, they are imported as objects and cause fatal error on Widgets page
160
- // If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
161
- // It is probably much more likely that arrays are used than objects, however
162
- $widget = json_decode( wp_json_encode( $widget ), true );
163
-
164
- // Filter to modify settings array
165
- // This is preferred over the older wie_widget_settings filter above
166
- // Do before identical check because changes may make it identical to end result (such as URL replacements)
167
- $widget = apply_filters( 'wie_widget_settings_array', $widget );
168
-
169
- // Does widget with identical settings already exist in same sidebar?
170
- if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
171
-
172
- // Get existing widgets in this sidebar
173
- $sidebars_widgets = get_option( 'sidebars_widgets' );
174
- $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // check Inactive if that's where will go
175
-
176
- // Loop widgets with ID base
177
- $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
178
- foreach ( $single_widget_instances as $check_id => $check_widget ) {
179
-
180
- // Is widget in same sidebar and has identical settings?
181
- if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
182
-
183
- $fail = true;
184
- $widget_message_type = 'warning';
185
- $widget_message = esc_html__( 'Widget already exists', 'astra-sites' ); // explain why widget not imported
186
-
187
- break;
188
-
189
- }
190
- }
191
- }
192
-
193
- // No failure
194
- if ( ! $fail ) {
195
-
196
- // Add widget instance
197
- $single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time
198
- $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array(
199
- '_multiwidget' => 1,
200
- ); // start fresh if have to
201
- $single_widget_instances[] = $widget; // add it
202
-
203
- // Get the key it was given
204
- end( $single_widget_instances );
205
- $new_instance_id_number = key( $single_widget_instances );
206
-
207
- // If key is 0, make it 1
208
- // When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it)
209
- if ( '0' === strval( $new_instance_id_number ) ) {
210
- $new_instance_id_number = 1;
211
- $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
212
- unset( $single_widget_instances[0] );
213
- }
214
-
215
- // Move _multiwidget to end of array for uniformity
216
- if ( isset( $single_widget_instances['_multiwidget'] ) ) {
217
- $multiwidget = $single_widget_instances['_multiwidget'];
218
- unset( $single_widget_instances['_multiwidget'] );
219
- $single_widget_instances['_multiwidget'] = $multiwidget;
220
- }
221
-
222
- // Update option with new widget
223
- $result = update_option( 'widget_' . $id_base, $single_widget_instances );
224
-
225
- // Assign widget instance to sidebar
226
- $sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time
227
-
228
- // Avoid rarely fatal error when the option is an empty string
229
- // https://github.com/churchthemes/widget-importer-exporter/pull/11
230
- if ( ! $sidebars_widgets ) {
231
- $sidebars_widgets = array();
232
- }
233
-
234
- $new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance
235
- $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // add new instance to sidebar
236
- update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data
237
-
238
- // After widget import action
239
- $after_widget_import = array(
240
- 'sidebar' => $use_sidebar_id,
241
- 'sidebar_old' => $sidebar_id,
242
- 'widget' => $widget,
243
- 'widget_type' => $id_base,
244
- 'widget_id' => $new_instance_id,
245
- 'widget_id_old' => $widget_instance_id,
246
- 'widget_id_num' => $new_instance_id_number,
247
- 'widget_id_num_old' => $instance_id_number,
248
- );
249
- do_action( 'wie_after_widget_import', $after_widget_import );
250
-
251
- // Success message
252
- if ( $sidebar_available ) {
253
- $widget_message_type = 'success';
254
- $widget_message = esc_html__( 'Imported', 'astra-sites' );
255
- } else {
256
- $widget_message_type = 'warning';
257
- $widget_message = esc_html__( 'Imported to Inactive', 'astra-sites' );
258
- }
259
- }// End if().
260
-
261
- // Result for widget instance
262
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // widget name or ID if name not available (not supported by site)
263
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'astra-sites' ); // show "No Title" if widget instance is untitled
264
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
265
- $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
266
-
267
- }// End foreach().
268
- }// End foreach().
269
-
270
- // Hook after import
271
- do_action( 'wie_after_import' );
272
-
273
- // Return results
274
- return apply_filters( 'wie_import_results', $results );
275
-
276
- }
277
-
278
- }
1
+ <?php
2
+ /**
3
+ * Widget Data exporter class.
4
+ *
5
+ * @package Astra Addon
6
+ * @see - https://wordpress.org/plugins/widget-importer-exporter/
7
+ */
8
+
9
+ defined( 'ABSPATH' ) or exit;
10
+
11
+ /**
12
+ * Widget Data exporter class.
13
+ *
14
+ * @see - https://wordpress.org/plugins/widget-importer-exporter/
15
+ */
16
+ class Astra_Widget_Importer {
17
+
18
+ /**
19
+ * Instance of Astra_Widget_Importer
20
+ *
21
+ * @var Astra_Widget_Importer
22
+ */
23
+ private static $_instance = null;
24
+
25
+ public static function instance() {
26
+
27
+ if ( ! isset( self::$_instance ) ) {
28
+ self::$_instance = new self;
29
+ }
30
+
31
+ return self::$_instance;
32
+ }
33
+
34
+ /**
35
+ * Available widgets
36
+ *
37
+ * Gather site's widgets into array with ID base, name, etc.
38
+ * Used by export and import functions.
39
+ *
40
+ * @since 0.4
41
+ * @global array $wp_registered_widget_updates
42
+ * @return array Widget information
43
+ */
44
+ function wie_available_widgets() {
45
+
46
+ global $wp_registered_widget_controls;
47
+
48
+ $widget_controls = $wp_registered_widget_controls;
49
+
50
+ $available_widgets = array();
51
+
52
+ foreach ( $widget_controls as $widget ) {
53
+
54
+ if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) { // no dupes
55
+
56
+ $available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
57
+ $available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
58
+
59
+ }
60
+ }
61
+
62
+ return apply_filters( 'wie_available_widgets', $available_widgets );
63
+ }
64
+
65
+ /**
66
+ * Import widget JSON data
67
+ *
68
+ * @since 0.4
69
+ * @global array $wp_registered_sidebars
70
+ *
71
+ * @param object $data JSON widget data from .wie file
72
+ *
73
+ * @return array Results array
74
+ */
75
+ function import_widgets_data( $data ) {
76
+
77
+ global $wp_registered_sidebars;
78
+
79
+ // Have valid data?
80
+ // If no data or could not decode
81
+ if ( empty( $data ) || ! is_object( $data ) ) {
82
+ wp_die(
83
+ esc_html__( 'Import data could not be read. Please try a different file.', 'astra-sites' ),
84
+ '',
85
+ array(
86
+ 'back_link' => true,
87
+ )
88
+ );
89
+ }
90
+
91
+ // Hook before import
92
+ do_action( 'wie_before_import' );
93
+ $data = apply_filters( 'wie_import_data', $data );
94
+
95
+ // Get all available widgets site supports
96
+ $available_widgets = $this->wie_available_widgets();
97
+
98
+ // Get all existing widget instances
99
+ $widget_instances = array();
100
+ foreach ( $available_widgets as $widget_data ) {
101
+ $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
102
+ }
103
+
104
+ // Begin results
105
+ $results = array();
106
+
107
+ // Loop import data's sidebars
108
+ foreach ( $data as $sidebar_id => $widgets ) {
109
+
110
+ // Skip inactive widgets
111
+ // (should not be in export file)
112
+ if ( 'wp_inactive_widgets' == $sidebar_id ) {
113
+ continue;
114
+ }
115
+
116
+ // Check if sidebar is available on this site
117
+ // Otherwise add widgets to inactive, and say so
118
+ if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
119
+ $sidebar_available = true;
120
+ $use_sidebar_id = $sidebar_id;
121
+ $sidebar_message_type = 'success';
122
+ $sidebar_message = '';
123
+ } else {
124
+ $sidebar_available = false;
125
+ $use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme
126
+ $sidebar_message_type = 'error';
127
+ $sidebar_message = esc_html__( 'Widget area does not exist in theme (using Inactive)', 'astra-sites' );
128
+ }
129
+
130
+ // Result for sidebar
131
+ $results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID
132
+ $results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
133
+ $results[ $sidebar_id ]['message'] = $sidebar_message;
134
+ $results[ $sidebar_id ]['widgets'] = array();
135
+
136
+ // Loop widgets
137
+ foreach ( $widgets as $widget_instance_id => $widget ) {
138
+
139
+ $fail = false;
140
+
141
+ // Get id_base (remove -# from end) and instance ID number
142
+ $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
143
+ $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
144
+
145
+ // Does site support this widget?
146
+ if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
147
+ $fail = true;
148
+ $widget_message_type = 'error';
149
+ $widget_message = esc_html__( 'Site does not support widget', 'astra-sites' ); // explain why widget not imported
150
+ }
151
+
152
+ // Filter to modify settings object before conversion to array and import
153
+ // Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below)
154
+ // Ideally the newer wie_widget_settings_array below will be used instead of this
155
+ $widget = apply_filters( 'wie_widget_settings', $widget ); // object
156
+
157
+ // Convert multidimensional objects to multidimensional arrays
158
+ // Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
159
+ // Without this, they are imported as objects and cause fatal error on Widgets page
160
+ // If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
161
+ // It is probably much more likely that arrays are used than objects, however
162
+ $widget = json_decode( wp_json_encode( $widget ), true );
163
+
164
+ // Filter to modify settings array
165
+ // This is preferred over the older wie_widget_settings filter above
166
+ // Do before identical check because changes may make it identical to end result (such as URL replacements)
167
+ $widget = apply_filters( 'wie_widget_settings_array', $widget );
168
+
169
+ // Does widget with identical settings already exist in same sidebar?
170
+ if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
171
+
172
+ // Get existing widgets in this sidebar
173
+ $sidebars_widgets = get_option( 'sidebars_widgets' );
174
+ $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // check Inactive if that's where will go
175
+
176
+ // Loop widgets with ID base
177
+ $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
178
+ foreach ( $single_widget_instances as $check_id => $check_widget ) {
179
+
180
+ // Is widget in same sidebar and has identical settings?
181
+ if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
182
+
183
+ $fail = true;
184
+ $widget_message_type = 'warning';
185
+ $widget_message = esc_html__( 'Widget already exists', 'astra-sites' ); // explain why widget not imported
186
+
187
+ break;
188
+
189
+ }
190
+ }
191
+ }
192
+
193
+ // No failure
194
+ if ( ! $fail ) {
195
+
196
+ // Add widget instance
197
+ $single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time
198
+ $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array(
199
+ '_multiwidget' => 1,
200
+ ); // start fresh if have to
201
+ $single_widget_instances[] = $widget; // add it
202
+
203
+ // Get the key it was given
204
+ end( $single_widget_instances );
205
+ $new_instance_id_number = key( $single_widget_instances );
206
+
207
+ // If key is 0, make it 1
208
+ // When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it)
209
+ if ( '0' === strval( $new_instance_id_number ) ) {
210
+ $new_instance_id_number = 1;
211
+ $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
212
+ unset( $single_widget_instances[0] );
213
+ }
214
+
215
+ // Move _multiwidget to end of array for uniformity
216
+ if ( isset( $single_widget_instances['_multiwidget'] ) ) {
217
+ $multiwidget = $single_widget_instances['_multiwidget'];
218
+ unset( $single_widget_instances['_multiwidget'] );
219
+ $single_widget_instances['_multiwidget'] = $multiwidget;
220
+ }
221
+
222
+ // Update option with new widget
223
+ $result = update_option( 'widget_' . $id_base, $single_widget_instances );
224
+
225
+ // Assign widget instance to sidebar
226
+ $sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time
227
+
228
+ // Avoid rarely fatal error when the option is an empty string
229
+ // https://github.com/churchthemes/widget-importer-exporter/pull/11
230
+ if ( ! $sidebars_widgets ) {
231
+ $sidebars_widgets = array();
232
+ }
233
+
234
+ $new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance
235
+ $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // add new instance to sidebar
236
+ update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data
237
+
238
+ // After widget import action
239
+ $after_widget_import = array(
240
+ 'sidebar' => $use_sidebar_id,
241
+ 'sidebar_old' => $sidebar_id,
242
+ 'widget' => $widget,
243
+ 'widget_type' => $id_base,
244
+ 'widget_id' => $new_instance_id,
245
+ 'widget_id_old' => $widget_instance_id,
246
+ 'widget_id_num' => $new_instance_id_number,
247
+ 'widget_id_num_old' => $instance_id_number,
248
+ );
249
+ do_action( 'wie_after_widget_import', $after_widget_import );
250
+
251
+ // Success message
252
+ if ( $sidebar_available ) {
253
+ $widget_message_type = 'success';
254
+ $widget_message = esc_html__( 'Imported', 'astra-sites' );
255
+ } else {
256
+ $widget_message_type = 'warning';
257
+ $widget_message = esc_html__( 'Imported to Inactive', 'astra-sites' );
258
+ }
259
+ }// End if().
260
+
261
+ // Result for widget instance
262
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // widget name or ID if name not available (not supported by site)
263
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'astra-sites' ); // show "No Title" if widget instance is untitled
264
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
265
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
266
+
267
+ }// End foreach().
268
+ }// End foreach().
269
+
270
+ // Hook after import
271
+ do_action( 'wie_after_import' );
272
+
273
+ // Return results
274
+ return apply_filters( 'wie_import_results', $results );
275
+
276
+ }
277
+
278
+ }
inc/importers/wxr-importer/class-astra-wxr-importer.php CHANGED
@@ -1,416 +1,441 @@
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
- require_once ABSPATH . '/wp-admin/includes/class-wp-importer.php';
48
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
49
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
50
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
51
- require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
52
-
53
- add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
54
- add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
55
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
56
- add_filter( 'wxr_importer.pre_process.post', array( $this, 'gutenberg_content_fix' ), 10, 4 );
57
-
58
- if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
59
- add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types_5_1_0' ), 10, 5 );
60
- } else {
61
- add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types' ), 10, 4 );
62
- }
63
-
64
- }
65
-
66
- /**
67
- * Gutenberg Content Data Fix
68
- *
69
- * Gutenberg encode the page content. In import process the encoded characterless e.g. <, > are
70
- * decoded into HTML tag and it break the Gutenberg render markup.
71
- *
72
- * Note: We have not check the post is created with Gutenberg or not. We have imported other sites
73
- * and confirm that this works for every other page builders too.
74
- *
75
- * @since 1.2.12
76
- *
77
- * @param array $data Post data. (Return empty to skip.).
78
- * @param array $meta Meta data.
79
- * @param array $comments Comments on the post.
80
- * @param array $terms Terms on the post.
81
- */
82
- function gutenberg_content_fix( $data, $meta, $comments, $terms ) {
83
- if ( isset( $data['post_content'] ) ) {
84
- $data['post_content'] = wp_slash( $data['post_content'] );
85
- }
86
- return $data;
87
- }
88
-
89
- /**
90
- * Different MIME type of different PHP version
91
- *
92
- * Filters the "real" file type of the given file.
93
- *
94
- * @since 1.2.9
95
- *
96
- * @param array $defaults File data array containing 'ext', 'type', and
97
- * 'proper_filename' keys.
98
- * @param string $file Full path to the file.
99
- * @param string $filename The name of the file (may differ from $file due to
100
- * $file being in a tmp directory).
101
- * @param array $mimes Key is the file extension with value as the mime type.
102
- * @param string $real_mime Real MIME type of the uploaded file.
103
- */
104
- function real_mime_types_5_1_0( $defaults, $file, $filename, $mimes, $real_mime ) {
105
- return $this->real_mimes( $defaults, $filename );
106
- }
107
-
108
- /**
109
- * Different MIME type of different PHP version
110
- *
111
- * Filters the "real" file type of the given file.
112
- *
113
- * @since 1.2.9
114
- *
115
- * @param array $defaults File data array containing 'ext', 'type', and
116
- * 'proper_filename' keys.
117
- * @param string $file Full path to the file.
118
- * @param string $filename The name of the file (may differ from $file due to
119
- * $file being in a tmp directory).
120
- * @param array $mimes Key is the file extension with value as the mime type.
121
- */
122
- function real_mime_types( $defaults, $file, $filename, $mimes ) {
123
- return $this->real_mimes( $defaults, $filename );
124
- }
125
-
126
- /**
127
- * Real Mime Type
128
- *
129
- * @since 1.2.15
130
- *
131
- * @param array $defaults File data array containing 'ext', 'type', and
132
- * 'proper_filename' keys.
133
- * @param string $filename The name of the file (may differ from $file due to
134
- * $file being in a tmp directory).
135
- */
136
- function real_mimes( $defaults, $filename ) {
137
-
138
- // Set EXT and real MIME type only for the file name `wxr.xml`.
139
- if ( 'wxr.xml' == $filename ) {
140
- $defaults['ext'] = 'xml';
141
- $defaults['type'] = 'text/xml';
142
- }
143
-
144
- // Set EXT and real MIME type only for the file name `wpforms.json`.
145
- if ( 'wpforms.json' == $filename ) {
146
- $defaults['ext'] = 'json';
147
- $defaults['type'] = 'text/plain';
148
- }
149
-
150
- return $defaults;
151
- }
152
-
153
- /**
154
- * Constructor.
155
- *
156
- * @since 1.1.0
157
- */
158
- function sse_import() {
159
-
160
- // Start the event stream.
161
- header( 'Content-Type: text/event-stream, charset=UTF-8' );
162
-
163
- // Turn off PHP output compression.
164
- $previous = error_reporting( error_reporting() ^ E_WARNING );
165
- ini_set( 'output_buffering', 'off' );
166
- ini_set( 'zlib.output_compression', false );
167
- error_reporting( $previous );
168
-
169
- if ( $GLOBALS['is_nginx'] ) {
170
- // Setting this header instructs Nginx to disable fastcgi_buffering
171
- // and disable gzip for this request.
172
- header( 'X-Accel-Buffering: no' );
173
- header( 'Content-Encoding: none' );
174
- }
175
-
176
- $xml_url = urldecode( $_REQUEST['xml_url'] );
177
- if ( empty( $xml_url ) ) {
178
- exit;
179
- }
180
-
181
- // 2KB padding for IE
182
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
183
-
184
- // Time to run the import!
185
- set_time_limit( 0 );
186
-
187
- // Ensure we're not buffered.
188
- wp_ob_end_flush_all();
189
- flush();
190
-
191
- // Are we allowed to create users?
192
- add_filter( 'wxr_importer.pre_process.user', '__return_null' );
193
-
194
- // Keep track of our progress.
195
- add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
196
- add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
197
- add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
198
- add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
199
- add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
200
- add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
201
- add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
202
- add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
203
- add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
204
- add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
205
- add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
206
- // Flush once more.
207
- flush();
208
-
209
- $importer = $this->get_importer();
210
- $response = $importer->import( $xml_url );
211
-
212
- // Let the browser know we're done.
213
- $complete = array(
214
- 'action' => 'complete',
215
- 'error' => false,
216
- );
217
- if ( is_wp_error( $response ) ) {
218
- $complete['error'] = $response->get_error_message();
219
- }
220
-
221
- $this->emit_sse_message( $complete );
222
- exit;
223
- }
224
-
225
- /**
226
- * Add .xml files as supported format in the uploader.
227
- *
228
- * @since 1.1.5 Added SVG file support.
229
- *
230
- * @since 1.0.0
231
- *
232
- * @param array $mimes Already supported mime types.
233
- */
234
- public function custom_upload_mimes( $mimes ) {
235
-
236
- // Allow SVG files.
237
- $mimes['svg'] = 'image/svg+xml';
238
- $mimes['svgz'] = 'image/svg+xml';
239
-
240
- // Allow XML files.
241
- $mimes['xml'] = 'text/xml';
242
-
243
- // Allow JSON files.
244
- $mimes['json'] = 'application/json';
245
-
246
- return $mimes;
247
- }
248
-
249
- /**
250
- * Start the xml import.
251
- *
252
- * @since 1.0.0
253
- *
254
- * @param (String) $path Absolute path to the XML file.
255
- */
256
- public function get_xml_data( $path ) {
257
-
258
- $args = array(
259
- 'action' => 'astra-wxr-import',
260
- 'id' => '1',
261
- 'xml_url' => $path,
262
- );
263
- $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
264
-
265
- $data = $this->get_data( $path );
266
-
267
- return array(
268
- 'count' => array(
269
- 'posts' => $data->post_count,
270
- 'media' => $data->media_count,
271
- 'users' => count( $data->users ),
272
- 'comments' => $data->comment_count,
273
- 'terms' => $data->term_count,
274
- ),
275
- 'url' => $url,
276
- 'strings' => array(
277
- 'complete' => __( 'Import complete!', 'astra-sites' ),
278
- ),
279
- );
280
- }
281
-
282
- /**
283
- * Get XML data.
284
- *
285
- * @since 1.1.0
286
- * @param string $url Downloaded XML file absolute URL.
287
- * @return array XML file data.
288
- */
289
- function get_data( $url ) {
290
- $importer = $this->get_importer();
291
- $data = $importer->get_preliminary_information( $url );
292
- if ( is_wp_error( $data ) ) {
293
- return $data;
294
- }
295
- return $data;
296
- }
297
-
298
- /**
299
- * Get Importer
300
- *
301
- * @since 1.1.0
302
- * @return object Importer object.
303
- */
304
- public function get_importer() {
305
- $options = apply_filters(
306
- 'astra_sites_xml_import_options',
307
- array(
308
- 'fetch_attachments' => true,
309
- 'default_author' => get_current_user_id(),
310
- )
311
- );
312
-
313
- $importer = new WXR_Importer( $options );
314
- $logger = new WP_Importer_Logger_ServerSentEvents();
315
-
316
- $importer->set_logger( $logger );
317
- return $importer;
318
- }
319
-
320
- /**
321
- * Send message when a post has been imported.
322
- *
323
- * @since 1.1.0
324
- * @param int $id Post ID.
325
- * @param array $data Post data saved to the DB.
326
- */
327
- public function imported_post( $id, $data ) {
328
- $this->emit_sse_message(
329
- array(
330
- 'action' => 'updateDelta',
331
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
332
- 'delta' => 1,
333
- )
334
- );
335
- }
336
-
337
- /**
338
- * Send message when a post is marked as already imported.
339
- *
340
- * @since 1.1.0
341
- * @param array $data Post data saved to the DB.
342
- */
343
- public function already_imported_post( $data ) {
344
- $this->emit_sse_message(
345
- array(
346
- 'action' => 'updateDelta',
347
- 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
348
- 'delta' => 1,
349
- )
350
- );
351
- }
352
-
353
- /**
354
- * Send message when a comment has been imported.
355
- *
356
- * @since 1.1.0
357
- */
358
- public function imported_comment() {
359
- $this->emit_sse_message(
360
- array(
361
- 'action' => 'updateDelta',
362
- 'type' => 'comments',
363
- 'delta' => 1,
364
- )
365
- );
366
- }
367
-
368
- /**
369
- * Send message when a term has been imported.
370
- *
371
- * @since 1.1.0
372
- */
373
- public function imported_term() {
374
- $this->emit_sse_message(
375
- array(
376
- 'action' => 'updateDelta',
377
- 'type' => 'terms',
378
- 'delta' => 1,
379
- )
380
- );
381
- }
382
-
383
- /**
384
- * Send message when a user has been imported.
385
- *
386
- * @since 1.1.0
387
- */
388
- public function imported_user() {
389
- $this->emit_sse_message(
390
- array(
391
- 'action' => 'updateDelta',
392
- 'type' => 'users',
393
- 'delta' => 1,
394
- )
395
- );
396
- }
397
-
398
- /**
399
- * Emit a Server-Sent Events message.
400
- *
401
- * @since 1.1.0
402
- * @param mixed $data Data to be JSON-encoded and sent in the message.
403
- */
404
- public function emit_sse_message( $data ) {
405
- echo "event: message\n";
406
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
407
-
408
- // Extra padding.
409
- echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
410
-
411
- flush();
412
- }
413
-
414
- }
415
-
416
- 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
+ require_once ABSPATH . '/wp-admin/includes/class-wp-importer.php';
48
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-logger.php';
49
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php';
50
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-importer.php';
51
+ require_once ASTRA_SITES_DIR . 'inc/importers/wxr-importer/class-wxr-import-info.php';
52
+
53
+ add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
54
+ add_action( 'wp_ajax_astra-wxr-import', array( $this, 'sse_import' ) );
55
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
56
+ add_filter( 'wxr_importer.pre_process.post', array( $this, 'gutenberg_content_fix' ), 10, 4 );
57
+
58
+ if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
59
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types_5_1_0' ), 10, 5 );
60
+ } else {
61
+ add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_mime_types' ), 10, 4 );
62
+ }
63
+
64
+ }
65
+
66
+ /**
67
+ * Track Imported Post
68
+ *
69
+ * @param int $post_id Post ID.
70
+ * @return void
71
+ */
72
+ function track_post( $post_id ) {
73
+ update_post_meta( $post_id, '_astra_sites_imported_post', true );
74
+ }
75
+
76
+ /**
77
+ * Track Imported Term
78
+ *
79
+ * @param int $term_id Term ID.
80
+ * @return void
81
+ */
82
+ function track_term( $term_id ) {
83
+ update_term_meta( $term_id, '_astra_sites_imported_term', true );
84
+ }
85
+
86
+ /**
87
+ * Gutenberg Content Data Fix
88
+ *
89
+ * Gutenberg encode the page content. In import process the encoded characterless e.g. <, > are
90
+ * decoded into HTML tag and it break the Gutenberg render markup.
91
+ *
92
+ * Note: We have not check the post is created with Gutenberg or not. We have imported other sites
93
+ * and confirm that this works for every other page builders too.
94
+ *
95
+ * @since 1.2.12
96
+ *
97
+ * @param array $data Post data. (Return empty to skip.).
98
+ * @param array $meta Meta data.
99
+ * @param array $comments Comments on the post.
100
+ * @param array $terms Terms on the post.
101
+ */
102
+ function gutenberg_content_fix( $data, $meta, $comments, $terms ) {
103
+ if ( isset( $data['post_content'] ) ) {
104
+ $data['post_content'] = wp_slash( $data['post_content'] );
105
+ }
106
+ return $data;
107
+ }
108
+
109
+ /**
110
+ * Different MIME type of different PHP version
111
+ *
112
+ * Filters the "real" file type of the given file.
113
+ *
114
+ * @since 1.2.9
115
+ *
116
+ * @param array $defaults File data array containing 'ext', 'type', and
117
+ * 'proper_filename' keys.
118
+ * @param string $file Full path to the file.
119
+ * @param string $filename The name of the file (may differ from $file due to
120
+ * $file being in a tmp directory).
121
+ * @param array $mimes Key is the file extension with value as the mime type.
122
+ * @param string $real_mime Real MIME type of the uploaded file.
123
+ */
124
+ function real_mime_types_5_1_0( $defaults, $file, $filename, $mimes, $real_mime ) {
125
+ return $this->real_mimes( $defaults, $filename );
126
+ }
127
+
128
+ /**
129
+ * Different MIME type of different PHP version
130
+ *
131
+ * Filters the "real" file type of the given file.
132
+ *
133
+ * @since 1.2.9
134
+ *
135
+ * @param array $defaults File data array containing 'ext', 'type', and
136
+ * 'proper_filename' keys.
137
+ * @param string $file Full path to the file.
138
+ * @param string $filename The name of the file (may differ from $file due to
139
+ * $file being in a tmp directory).
140
+ * @param array $mimes Key is the file extension with value as the mime type.
141
+ */
142
+ function real_mime_types( $defaults, $file, $filename, $mimes ) {
143
+ return $this->real_mimes( $defaults, $filename );
144
+ }
145
+
146
+ /**
147
+ * Real Mime Type
148
+ *
149
+ * @since 1.2.15
150
+ *
151
+ * @param array $defaults File data array containing 'ext', 'type', and
152
+ * 'proper_filename' keys.
153
+ * @param string $filename The name of the file (may differ from $file due to
154
+ * $file being in a tmp directory).
155
+ */
156
+ function real_mimes( $defaults, $filename ) {
157
+
158
+ // Set EXT and real MIME type only for the file name `wxr.xml`.
159
+ if ( 'wxr.xml' == $filename ) {
160
+ $defaults['ext'] = 'xml';
161
+ $defaults['type'] = 'text/xml';
162
+ }
163
+
164
+ // Set EXT and real MIME type only for the file name `wpforms.json`.
165
+ if ( 'wpforms.json' == $filename ) {
166
+ $defaults['ext'] = 'json';
167
+ $defaults['type'] = 'text/plain';
168
+ }
169
+
170
+ return $defaults;
171
+ }
172
+
173
+ /**
174
+ * Constructor.
175
+ *
176
+ * @since 1.1.0
177
+ */
178
+ function sse_import() {
179
+
180
+ // Start the event stream.
181
+ header( 'Content-Type: text/event-stream, charset=UTF-8' );
182
+
183
+ // Turn off PHP output compression.
184
+ $previous = error_reporting( error_reporting() ^ E_WARNING );
185
+ ini_set( 'output_buffering', 'off' );
186
+ ini_set( 'zlib.output_compression', false );
187
+ error_reporting( $previous );
188
+
189
+ if ( $GLOBALS['is_nginx'] ) {
190
+ // Setting this header instructs Nginx to disable fastcgi_buffering
191
+ // and disable gzip for this request.
192
+ header( 'X-Accel-Buffering: no' );
193
+ header( 'Content-Encoding: none' );
194
+ }
195
+
196
+ $xml_url = urldecode( $_REQUEST['xml_url'] );
197
+ if ( empty( $xml_url ) ) {
198
+ exit;
199
+ }
200
+
201
+ // 2KB padding for IE
202
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
203
+
204
+ // Time to run the import!
205
+ set_time_limit( 0 );
206
+
207
+ // Ensure we're not buffered.
208
+ wp_ob_end_flush_all();
209
+ flush();
210
+
211
+ // Are we allowed to create users?
212
+ add_filter( 'wxr_importer.pre_process.user', '__return_null' );
213
+
214
+ // Keep track of our progress.
215
+ add_action( 'wxr_importer.processed.post', array( $this, 'imported_post' ), 10, 2 );
216
+ add_action( 'wxr_importer.process_failed.post', array( $this, 'imported_post' ), 10, 2 );
217
+ add_action( 'wxr_importer.process_already_imported.post', array( $this, 'already_imported_post' ), 10, 2 );
218
+ add_action( 'wxr_importer.process_skipped.post', array( $this, 'already_imported_post' ), 10, 2 );
219
+ add_action( 'wxr_importer.processed.comment', array( $this, 'imported_comment' ) );
220
+ add_action( 'wxr_importer.process_already_imported.comment', array( $this, 'imported_comment' ) );
221
+ add_action( 'wxr_importer.processed.term', array( $this, 'imported_term' ) );
222
+ add_action( 'wxr_importer.process_failed.term', array( $this, 'imported_term' ) );
223
+ add_action( 'wxr_importer.process_already_imported.term', array( $this, 'imported_term' ) );
224
+ add_action( 'wxr_importer.processed.user', array( $this, 'imported_user' ) );
225
+ add_action( 'wxr_importer.process_failed.user', array( $this, 'imported_user' ) );
226
+
227
+ // Keep track of our progress.
228
+ add_action( 'wxr_importer.processed.post', array( $this, 'track_post' ) );
229
+ add_action( 'wxr_importer.processed.term', array( $this, 'track_term' ) );
230
+
231
+ // Flush once more.
232
+ flush();
233
+
234
+ $importer = $this->get_importer();
235
+ $response = $importer->import( $xml_url );
236
+
237
+ // Let the browser know we're done.
238
+ $complete = array(
239
+ 'action' => 'complete',
240
+ 'error' => false,
241
+ );
242
+ if ( is_wp_error( $response ) ) {
243
+ $complete['error'] = $response->get_error_message();
244
+ }
245
+
246
+ $this->emit_sse_message( $complete );
247
+ exit;
248
+ }
249
+
250
+ /**
251
+ * Add .xml files as supported format in the uploader.
252
+ *
253
+ * @since 1.1.5 Added SVG file support.
254
+ *
255
+ * @since 1.0.0
256
+ *
257
+ * @param array $mimes Already supported mime types.
258
+ */
259
+ public function custom_upload_mimes( $mimes ) {
260
+
261
+ // Allow SVG files.
262
+ $mimes['svg'] = 'image/svg+xml';
263
+ $mimes['svgz'] = 'image/svg+xml';
264
+
265
+ // Allow XML files.
266
+ $mimes['xml'] = 'text/xml';
267
+
268
+ // Allow JSON files.
269
+ $mimes['json'] = 'application/json';
270
+
271
+ return $mimes;
272
+ }
273
+
274
+ /**
275
+ * Start the xml import.
276
+ *
277
+ * @since 1.0.0
278
+ *
279
+ * @param (String) $path Absolute path to the XML file.
280
+ */
281
+ public function get_xml_data( $path ) {
282
+
283
+ $args = array(
284
+ 'action' => 'astra-wxr-import',
285
+ 'id' => '1',
286
+ 'xml_url' => $path,
287
+ );
288
+ $url = add_query_arg( urlencode_deep( $args ), admin_url( 'admin-ajax.php' ) );
289
+
290
+ $data = $this->get_data( $path );
291
+
292
+ return array(
293
+ 'count' => array(
294
+ 'posts' => $data->post_count,
295
+ 'media' => $data->media_count,
296
+ 'users' => count( $data->users ),
297
+ 'comments' => $data->comment_count,
298
+ 'terms' => $data->term_count,
299
+ ),
300
+ 'url' => $url,
301
+ 'strings' => array(
302
+ 'complete' => __( 'Import complete!', 'astra-sites' ),
303
+ ),
304
+ );
305
+ }
306
+
307
+ /**
308
+ * Get XML data.
309
+ *
310
+ * @since 1.1.0
311
+ * @param string $url Downloaded XML file absolute URL.
312
+ * @return array XML file data.
313
+ */
314
+ function get_data( $url ) {
315
+ $importer = $this->get_importer();
316
+ $data = $importer->get_preliminary_information( $url );
317
+ if ( is_wp_error( $data ) ) {
318
+ return $data;
319
+ }
320
+ return $data;
321
+ }
322
+
323
+ /**
324
+ * Get Importer
325
+ *
326
+ * @since 1.1.0
327
+ * @return object Importer object.
328
+ */
329
+ public function get_importer() {
330
+ $options = apply_filters(
331
+ 'astra_sites_xml_import_options',
332
+ array(
333
+ 'fetch_attachments' => true,
334
+ 'default_author' => get_current_user_id(),
335
+ )
336
+ );
337
+
338
+ $importer = new WXR_Importer( $options );
339
+ $logger = new WP_Importer_Logger_ServerSentEvents();
340
+
341
+ $importer->set_logger( $logger );
342
+ return $importer;
343
+ }
344
+
345
+ /**
346
+ * Send message when a post has been imported.
347
+ *
348
+ * @since 1.1.0
349
+ * @param int $id Post ID.
350
+ * @param array $data Post data saved to the DB.
351
+ */
352
+ public function imported_post( $id, $data ) {
353
+ $this->emit_sse_message(
354
+ array(
355
+ 'action' => 'updateDelta',
356
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
357
+ 'delta' => 1,
358
+ )
359
+ );
360
+ }
361
+
362
+ /**
363
+ * Send message when a post is marked as already imported.
364
+ *
365
+ * @since 1.1.0
366
+ * @param array $data Post data saved to the DB.
367
+ */
368
+ public function already_imported_post( $data ) {
369
+ $this->emit_sse_message(
370
+ array(
371
+ 'action' => 'updateDelta',
372
+ 'type' => ( 'attachment' === $data['post_type'] ) ? 'media' : 'posts',
373
+ 'delta' => 1,
374
+ )
375
+ );
376
+ }
377
+
378
+ /**
379
+ * Send message when a comment has been imported.
380
+ *
381
+ * @since 1.1.0
382
+ */
383
+ public function imported_comment() {
384
+ $this->emit_sse_message(
385
+ array(
386
+ 'action' => 'updateDelta',
387
+ 'type' => 'comments',
388
+ 'delta' => 1,
389
+ )
390
+ );
391
+ }
392
+
393
+ /**
394
+ * Send message when a term has been imported.
395
+ *
396
+ * @since 1.1.0
397
+ */
398
+ public function imported_term() {
399
+ $this->emit_sse_message(
400
+ array(
401
+ 'action' => 'updateDelta',
402
+ 'type' => 'terms',
403
+ 'delta' => 1,
404
+ )
405
+ );
406
+ }
407
+
408
+ /**
409
+ * Send message when a user has been imported.
410
+ *
411
+ * @since 1.1.0
412
+ */
413
+ public function imported_user() {
414
+ $this->emit_sse_message(
415
+ array(
416
+ 'action' => 'updateDelta',
417
+ 'type' => 'users',
418
+ 'delta' => 1,
419
+ )
420
+ );
421
+ }
422
+
423
+ /**
424
+ * Emit a Server-Sent Events message.
425
+ *
426
+ * @since 1.1.0
427
+ * @param mixed $data Data to be JSON-encoded and sent in the message.
428
+ */
429
+ public function emit_sse_message( $data ) {
430
+ echo "event: message\n";
431
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
432
+
433
+ // Extra padding.
434
+ echo ':' . str_repeat( ' ', 2048 ) . "\n\n";
435
+
436
+ flush();
437
+ }
438
+
439
+ }
440
+
441
+ Astra_WXR_Importer::instance();
inc/importers/wxr-importer/class-logger.php CHANGED
@@ -1,142 +1,139 @@
1
- <?php
2
-
3
- /**
4
- * Describes a logger instance
5
- *
6
- * Based on PSR-3: http://www.php-fig.org/psr/psr-3/
7
- *
8
- * The message MUST be a string or object implementing __toString().
9
- *
10
- * The message MAY contain placeholders in the form: {foo} where foo
11
- * will be replaced by the context data in key "foo".
12
- *
13
- * The context array can contain arbitrary data, the only assumption that
14
- * can be made by implementors is that if an Exception instance is given
15
- * to produce a stack trace, it MUST be in a key named "exception".
16
- *
17
- * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
18
- * for the full interface specification.
19
- */
20
- if( ! class_exists( 'WP_Importer_Logger' ) ) :
21
- class WP_Importer_Logger {
22
- /**
23
- * System is unusable.
24
- *
25
- * @param string $message
26
- * @param array $context
27
- * @return null
28
- */
29
- public function emergency( $message, array $context = array() ) {
30
- return $this->log( 'emergency', $message, $context );
31
- }
32
-
33
- /**
34
- * Action must be taken immediately.
35
- *
36
- * Example: Entire website down, database unavailable, etc. This should
37
- * trigger the SMS alerts and wake you up.
38
- *
39
- * @param string $message
40
- * @param array $context
41
- * @return null
42
- */
43
- public function alert( $message, array $context = array() ) {
44
- return $this->log( 'alert', $message, $context );
45
- }
46
-
47
- /**
48
- * Critical conditions.
49
- *
50
- * Example: Application component unavailable, unexpected exception.
51
- *
52
- * @param string $message
53
- * @param array $context
54
- * @return null
55
- */
56
- public function critical( $message, array $context = array() ) {
57
- return $this->log( 'critical', $message, $context );
58
- }
59
-
60
- /**
61
- * Runtime errors that do not require immediate action but should typically
62
- * be logged and monitored.
63
- *
64
- * @param string $message
65
- * @param array $context
66
- * @return null
67
- */
68
- public function error( $message, array $context = array() ) {
69
- return $this->log( 'error', $message, $context );
70
- }
71
-
72
- /**
73
- * Exceptional occurrences that are not errors.
74
- *
75
- * Example: Use of deprecated APIs, poor use of an API, undesirable things
76
- * that are not necessarily wrong.
77
- *
78
- * @param string $message
79
- * @param array $context
80
- * @return null
81
- */
82
- public function warning( $message, array $context = array() ) {
83
- return $this->log( 'warning', $message, $context );
84
- }
85
-
86
- /**
87
- * Normal but significant events.
88
- *
89
- * @param string $message
90
- * @param array $context
91
- * @return null
92
- */
93
- public function notice( $message, array $context = array() ) {
94
- return $this->log( 'notice', $message, $context );
95
- }
96
-
97
- /**
98
- * Interesting events.
99
- *
100
- * Example: User logs in, SQL logs.
101
- *
102
- * @param string $message
103
- * @param array $context
104
- * @return null
105
- */
106
- public function info( $message, array $context = array() ) {
107
- return $this->log( 'info', $message, $context );
108
- }
109
-
110
- /**
111
- * Detailed debug information.
112
- *
113
- * @param string $message
114
- * @param array $context
115
- * @return null
116
- */
117
- public function debug( $message, array $context = array() ) {
118
- return $this->log( 'debug', $message, $context );
119
- }
120
-
121
- /**
122
- * Logs with an arbitrary level.
123
- *
124
- * @param mixed $level
125
- * @param string $message
126
- * @param array $context
127
- * @return null
128
- */
129
- public function log( $level, $message, array $context = array() ) {
130
-
131
- // Log
132
- do_action( 'astra_sites_import_xml_log', $level, $message, $context );
133
-
134
- $this->messages[] = array(
135
- 'timestamp' => time(),
136
- 'level' => $level,
137
- 'message' => $message,
138
- 'context' => $context,
139
- );
140
- }
141
- }
142
- endif;
1
+ <?php
2
+
3
+ /**
4
+ * Describes a logger instance
5
+ *
6
+ * Based on PSR-3: http://www.php-fig.org/psr/psr-3/
7
+ *
8
+ * The message MUST be a string or object implementing __toString().
9
+ *
10
+ * The message MAY contain placeholders in the form: {foo} where foo
11
+ * will be replaced by the context data in key "foo".
12
+ *
13
+ * The context array can contain arbitrary data, the only assumption that
14
+ * can be made by implementors is that if an Exception instance is given
15
+ * to produce a stack trace, it MUST be in a key named "exception".
16
+ *
17
+ * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
18
+ * for the full interface specification.
19
+ */
20
+ if( ! class_exists( 'WP_Importer_Logger' ) ) :
21
+ class WP_Importer_Logger {
22
+ /**
23
+ * System is unusable.
24
+ *
25
+ * @param string $message
26
+ * @param array $context
27
+ * @return null
28
+ */
29
+ public function emergency( $message, array $context = array() ) {
30
+ return $this->log( 'emergency', $message, $context );
31
+ }
32
+
33
+ /**
34
+ * Action must be taken immediately.
35
+ *
36
+ * Example: Entire website down, database unavailable, etc. This should
37
+ * trigger the SMS alerts and wake you up.
38
+ *
39
+ * @param string $message
40
+ * @param array $context
41
+ * @return null
42
+ */
43
+ public function alert( $message, array $context = array() ) {
44
+ return $this->log( 'alert', $message, $context );
45
+ }
46
+
47
+ /**
48
+ * Critical conditions.
49
+ *
50
+ * Example: Application component unavailable, unexpected exception.
51
+ *
52
+ * @param string $message
53
+ * @param array $context
54
+ * @return null
55
+ */
56
+ public function critical( $message, array $context = array() ) {
57
+ return $this->log( 'critical', $message, $context );
58
+ }
59
+
60
+ /**
61
+ * Runtime errors that do not require immediate action but should typically
62
+ * be logged and monitored.
63
+ *
64
+ * @param string $message
65
+ * @param array $context
66
+ * @return null
67
+ */
68
+ public function error( $message, array $context = array() ) {
69
+ return $this->log( 'error', $message, $context );
70
+ }
71
+
72
+ /**
73
+ * Exceptional occurrences that are not errors.
74
+ *
75
+ * Example: Use of deprecated APIs, poor use of an API, undesirable things
76
+ * that are not necessarily wrong.
77
+ *
78
+ * @param string $message
79
+ * @param array $context
80
+ * @return null
81
+ */
82
+ public function warning( $message, array $context = array() ) {
83
+ return $this->log( 'warning', $message, $context );
84
+ }
85
+
86
+ /**
87
+ * Normal but significant events.
88
+ *
89
+ * @param string $message
90
+ * @param array $context
91
+ * @return null
92
+ */
93
+ public function notice( $message, array $context = array() ) {
94
+ return $this->log( 'notice', $message, $context );
95
+ }
96
+
97
+ /**
98
+ * Interesting events.
99
+ *
100
+ * Example: User logs in, SQL logs.
101
+ *
102
+ * @param string $message
103
+ * @param array $context
104
+ * @return null
105
+ */
106
+ public function info( $message, array $context = array() ) {
107
+ return $this->log( 'info', $message, $context );
108
+ }
109
+
110
+ /**
111
+ * Detailed debug information.
112
+ *
113
+ * @param string $message
114
+ * @param array $context
115
+ * @return null
116
+ */
117
+ public function debug( $message, array $context = array() ) {
118
+ return $this->log( 'debug', $message, $context );
119
+ }
120
+
121
+ /**
122
+ * Logs with an arbitrary level.
123
+ *
124
+ * @param mixed $level
125
+ * @param string $message
126
+ * @param array $context
127
+ * @return null
128
+ */
129
+ public function log( $level, $message, array $context = array() ) {
130
+
131
+ $this->messages[] = array(
132
+ 'timestamp' => time(),
133
+ 'level' => $level,
134
+ 'message' => $message,
135
+ 'context' => $context,
136
+ );
137
+ }
138
+ }
139
+ endif;
 
 
 
inc/importers/wxr-importer/class-wp-importer-logger-serversentevents.php CHANGED
@@ -1,46 +1,43 @@
1
- <?php
2
-
3
- if ( ! class_exists( 'WP_Importer_Logger_ServerSentEvents' ) && class_exists( 'WP_Importer_Logger' ) ) {
4
-
5
- class WP_Importer_Logger_ServerSentEvents extends WP_Importer_Logger {
6
-
7
- /**
8
- * Logs with an arbitrary level.
9
- *
10
- * @param mixed $level
11
- * @param string $message
12
- * @param array $context
13
- * @return null
14
- */
15
- public function log( $level, $message, array $context = array() ) {
16
-
17
- // Log
18
- do_action( 'astra_sites_import_xml_log', $level, $message, $context );
19
-
20
- $data = compact( 'level', 'message' );
21
-
22
- switch ( $level ) {
23
- case 'emergency':
24
- case 'alert':
25
- case 'critical':
26
- case 'error':
27
- case 'warning':
28
- case 'notice':
29
- case 'info':
30
- echo "event: log\n";
31
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
32
- flush();
33
- break;
34
-
35
- case 'debug':
36
- if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
37
- echo "event: log\n";
38
- echo 'data: ' . wp_json_encode( $data ) . "\n\n";
39
- flush();
40
- break;
41
- }
42
- break;
43
- }
44
- }
45
- }
46
- }
1
+ <?php
2
+
3
+ if ( ! class_exists( 'WP_Importer_Logger_ServerSentEvents' ) && class_exists( 'WP_Importer_Logger' ) ) {
4
+
5
+ class WP_Importer_Logger_ServerSentEvents extends WP_Importer_Logger {
6
+
7
+ /**
8
+ * Logs with an arbitrary level.
9
+ *
10
+ * @param mixed $level
11
+ * @param string $message
12
+ * @param array $context
13
+ * @return null
14
+ */
15
+ public function log( $level, $message, array $context = array() ) {
16
+
17
+ $data = compact( 'level', 'message' );
18
+
19
+ switch ( $level ) {
20
+ case 'emergency':
21
+ case 'alert':
22
+ case 'critical':
23
+ case 'error':
24
+ case 'warning':
25
+ case 'notice':
26
+ case 'info':
27
+ echo "event: log\n";
28
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
29
+ flush();
30
+ break;
31
+
32
+ case 'debug':
33
+ if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
34
+ echo "event: log\n";
35
+ echo 'data: ' . wp_json_encode( $data ) . "\n\n";
36
+ flush();
37
+ break;
38
+ }
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ }
 
 
 
inc/importers/wxr-importer/class-wxr-import-info.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
-
3
- if ( ! class_exists( 'WXR_Import_Info' ) ) {
4
-
5
- class WXR_Import_Info {
6
- public $home;
7
- public $siteurl;
8
-
9
- public $title;
10
-
11
- public $users = array();
12
- public $post_count = 0;
13
- public $media_count = 0;
14
- public $comment_count = 0;
15
- public $term_count = 0;
16
-
17
- public $generator = '';
18
- public $version;
19
- }
20
-
21
  }
1
+ <?php
2
+
3
+ if ( ! class_exists( 'WXR_Import_Info' ) ) {
4
+
5
+ class WXR_Import_Info {
6
+ public $home;
7
+ public $siteurl;
8
+
9
+ public $title;
10
+
11
+ public $users = array();
12
+ public $post_count = 0;
13
+ public $media_count = 0;
14
+ public $comment_count = 0;
15
+ public $term_count = 0;
16
+
17
+ public $generator = '';
18
+ public $version;
19
+ }
20
+
21
  }
inc/importers/wxr-importer/class-wxr-importer.php CHANGED
@@ -1,2301 +1,2301 @@
1
- <?php
2
-
3
- if( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
4
- class WXR_Importer extends WP_Importer {
5
- /**
6
- * Maximum supported WXR version
7
- */
8
- const MAX_WXR_VERSION = 1.2;
9
-
10
- /**
11
- * Regular expression for checking if a post references an attachment
12
- *
13
- * Note: This is a quick, weak check just to exclude text-only posts. More
14
- * vigorous checking is done later to verify.
15
- */
16
- const REGEX_HAS_ATTACHMENT_REFS = '!
17
- (
18
- # Match anything with an image or attachment class
19
- class=[\'"].*?\b(wp-image-\d+|attachment-[\w\-]+)\b
20
- |
21
- # Match anything that looks like an upload URL
22
- src=[\'"][^\'"]*(
23
- [0-9]{4}/[0-9]{2}/[^\'"]+\.(jpg|jpeg|png|gif)
24
- |
25
- content/uploads[^\'"]+
26
- )[\'"]
27
- )!ix';
28
-
29
- /**
30
- * Version of WXR we're importing.
31
- *
32
- * Defaults to 1.0 for compatibility. Typically overridden by a
33
- * `<wp:wxr_version>` tag at the start of the file.
34
- *
35
- * @var string
36
- */
37
- protected $version = '1.0';
38
-
39
- // information to import from WXR file
40
- protected $categories = array();
41
- protected $tags = array();
42
- protected $base_url = '';
43
-
44
- // TODO: REMOVE THESE
45
- protected $processed_terms = array();
46
- protected $processed_posts = array();
47
- protected $processed_menu_items = array();
48
- protected $menu_item_orphans = array();
49
- protected $missing_menu_items = array();
50
-
51
- // NEW STYLE
52
- protected $mapping = array();
53
- protected $requires_remapping = array();
54
- protected $exists = array();
55
- protected $user_slug_override = array();
56
-
57
- protected $url_remap = array();
58
- protected $featured_images = array();
59
-
60
- /**
61
- * Logger instance.
62
- *
63
- * @var WP_Importer_Logger
64
- */
65
- protected $logger;
66
-
67
- /**
68
- * Constructor
69
- *
70
- * @param array $options {
71
- * @var bool $prefill_existing_posts Should we prefill `post_exists` calls? (True prefills and uses more memory, false checks once per imported post and takes longer. Default is true.)
72
- * @var bool $prefill_existing_comments Should we prefill `comment_exists` calls? (True prefills and uses more memory, false checks once per imported comment and takes longer. Default is true.)
73
- * @var bool $prefill_existing_terms Should we prefill `term_exists` calls? (True prefills and uses more memory, false checks once per imported term and takes longer. Default is true.)
74
- * @var bool $update_attachment_guids Should attachment GUIDs be updated to the new URL? (True updates the GUID, which keeps compatibility with v1, false doesn't update, and allows deduplication and reimporting. Default is false.)
75
- * @var bool $fetch_attachments Fetch attachments from the remote server. (True fetches and creates attachment posts, false skips attachments. Default is false.)
76
- * @var bool $aggressive_url_search Should we search/replace for URLs aggressively? (True searches all posts' content for old URLs and replaces, false checks for `<img class="wp-image-*">` only. Default is false.)
77
- * @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.)
78
- * }
79
- */
80
- public function __construct( $options = array() ) {
81
- // Initialize some important variables
82
- $empty_types = array(
83
- 'post' => array(),
84
- 'comment' => array(),
85
- 'term' => array(),
86
- 'user' => array(),
87
- );
88
-
89
- $this->mapping = $empty_types;
90
- $this->mapping['user_slug'] = array();
91
- $this->mapping['term_id'] = array();
92
- $this->requires_remapping = $empty_types;
93
- $this->exists = $empty_types;
94
-
95
- $this->options = wp_parse_args( $options, array(
96
- 'prefill_existing_posts' => true,
97
- 'prefill_existing_comments' => true,
98
- 'prefill_existing_terms' => true,
99
- 'update_attachment_guids' => false,
100
- 'fetch_attachments' => false,
101
- 'aggressive_url_search' => false,
102
- 'default_author' => null,
103
- ) );
104
- }
105
-
106
- public function set_logger( $logger ) {
107
- $this->logger = $logger;
108
- }
109
-
110
- /**
111
- * Get a stream reader for the file.
112
- *
113
- * @param string $file Path to the XML file.
114
- * @return XMLReader|WP_Error Reader instance on success, error otherwise.
115
- */
116
- protected function get_reader( $file ) {
117
- // Avoid loading external entities for security
118
- $old_value = null;
119
- if ( function_exists( 'libxml_disable_entity_loader' ) ) {
120
- // $old_value = libxml_disable_entity_loader( true );
121
- }
122
-
123
- $reader = new XMLReader();
124
- $status = $reader->open( $file );
125
-
126
- if ( ! is_null( $old_value ) ) {
127
- // libxml_disable_entity_loader( $old_value );
128
- }
129
-
130
- if ( ! $status ) {
131
- return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
132
- }
133
-
134
- return $reader;
135
- }
136
-
137
- /**
138
- * The main controller for the actual import stage.
139
- *
140
- * @param string $file Path to the WXR file for importing
141
- */
142
- public function get_preliminary_information( $file ) {
143
- // Let's run the actual importer now, woot
144
- $reader = $this->get_reader( $file );
145
- if ( is_wp_error( $reader ) ) {
146
- return $reader;
147
- }
148
-
149
- // Set the version to compatibility mode first
150
- $this->version = '1.0';
151
-
152
- // Start parsing!
153
- $data = new WXR_Import_Info();
154
- while ( $reader->read() ) {
155
- // Only deal with element opens
156
- if ( $reader->nodeType !== XMLReader::ELEMENT ) {
157
- continue;
158
- }
159
-
160
- switch ( $reader->name ) {
161
- case 'wp:wxr_version':
162
- // Upgrade to the correct version
163
- $this->version = $reader->readString();
164
-
165
- if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
166
- $this->logger->warning( sprintf(
167
- __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
168
- $this->version,
169
- self::MAX_WXR_VERSION
170
- ) );
171
- }
172
-
173
- // Handled everything in this node, move on to the next
174
- $reader->next();
175
- break;
176
-
177
- case 'generator':
178
- $data->generator = $reader->readString();
179
- $reader->next();
180
- break;
181
-
182
- case 'title':
183
- $data->title = $reader->readString();
184
- $reader->next();
185
- break;
186
-
187
- case 'wp:base_site_url':
188
- $data->siteurl = $reader->readString();
189
- $reader->next();
190
- break;
191
-
192
- case 'wp:base_blog_url':
193
- $data->home = $reader->readString();
194
- $reader->next();
195
- break;
196
-
197
- case 'wp:author':
198
- $node = $reader->expand();
199
-
200
- $parsed = $this->parse_author_node( $node );
201
- if ( is_wp_error( $parsed ) ) {
202
- $this->log_error( $parsed );
203
-
204
- // Skip the rest of this post
205
- $reader->next();
206
- break;
207
- }
208
-
209
- $data->users[] = $parsed;
210
-
211
- // Handled everything in this node, move on to the next
212
- $reader->next();
213
- break;
214
-
215
- case 'item':
216
- $node = $reader->expand();
217
- $parsed = $this->parse_post_node( $node );
218
- if ( is_wp_error( $parsed ) ) {
219
- $this->log_error( $parsed );
220
-
221
- // Skip the rest of this post
222
- $reader->next();
223
- break;
224
- }
225
-
226
- if ( $parsed['data']['post_type'] === 'attachment' ) {
227
- $data->media_count++;
228
- } else {
229
- $data->post_count++;
230
- }
231
- $data->comment_count += count( $parsed['comments'] );
232
-
233
- // Handled everything in this node, move on to the next
234
- $reader->next();
235
- break;
236
-
237
- case 'wp:category':
238
- case 'wp:tag':
239
- case 'wp:term':
240
- $data->term_count++;
241
-
242
- // Handled everything in this node, move on to the next
243
- $reader->next();
244
- break;
245
- }// End switch().
246
- }// End while().
247
-
248
- $data->version = $this->version;
249
-
250
- return $data;
251
- }
252
-
253
- /**
254
- * The main controller for the actual import stage.
255
- *
256
- * @param string $file Path to the WXR file for importing
257
- */
258
- public function parse_authors( $file ) {
259
- // Let's run the actual importer now, woot
260
- $reader = $this->get_reader( $file );
261
- if ( is_wp_error( $reader ) ) {
262
- return $reader;
263
- }
264
-
265
- // Set the version to compatibility mode first
266
- $this->version = '1.0';
267
-
268
- // Start parsing!
269
- $authors = array();
270
- while ( $reader->read() ) {
271
- // Only deal with element opens
272
- if ( $reader->nodeType !== XMLReader::ELEMENT ) {
273
- continue;
274
- }
275
-
276
- switch ( $reader->name ) {
277
- case 'wp:wxr_version':
278
- // Upgrade to the correct version
279
- $this->version = $reader->readString();
280
-
281
- if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
282
- $this->logger->warning( sprintf(
283
- __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
284
- $this->version,
285
- self::MAX_WXR_VERSION
286
- ) );
287
- }
288
-
289
- // Handled everything in this node, move on to the next
290
- $reader->next();
291
- break;
292
-
293
- case 'wp:author':
294
- $node = $reader->expand();
295
-
296
- $parsed = $this->parse_author_node( $node );
297
- if ( is_wp_error( $parsed ) ) {
298
- $this->log_error( $parsed );
299
-
300
- // Skip the rest of this post
301
- $reader->next();
302
- break;
303
- }
304
-
305
- $authors[] = $parsed;
306
-
307
- // Handled everything in this node, move on to the next
308
- $reader->next();
309
- break;
310
- }
311
- }// End while().
312
-
313
- return $authors;
314
- }
315
-
316
- /**
317
- * The main controller for the actual import stage.
318
- *
319
- * @param string $file Path to the WXR file for importing
320
- */
321
- public function import( $file ) {
322
- add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
323
- add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
324
-
325
- $result = $this->import_start( $file );
326
- if ( is_wp_error( $result ) ) {
327
- return $result;
328
- }
329
-
330
- // Let's run the actual importer now, woot
331
- $reader = $this->get_reader( $file );
332
- if ( is_wp_error( $reader ) ) {
333
- return $reader;
334
- }
335
-
336
- // Set the version to compatibility mode first
337
- $this->version = '1.0';
338
-
339
- // Reset other variables
340
- $this->base_url = '';
341
-
342
- // Start parsing!
343
- while ( $reader->read() ) {
344
- // Only deal with element opens
345
- if ( $reader->nodeType !== XMLReader::ELEMENT ) {
346
- continue;
347
- }
348
-
349
- switch ( $reader->name ) {
350
- case 'wp:wxr_version':
351
- // Upgrade to the correct version
352
- $this->version = $reader->readString();
353
-
354
- if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
355
- $this->logger->warning( sprintf(
356
- __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
357
- $this->version,
358
- self::MAX_WXR_VERSION
359
- ) );
360
- }
361
-
362
- // Handled everything in this node, move on to the next
363
- $reader->next();
364
- break;
365
-
366
- case 'wp:base_site_url':
367
- $this->base_url = $reader->readString();
368
-
369
- // Handled everything in this node, move on to the next
370
- $reader->next();
371
- break;
372
-
373
- case 'item':
374
- $node = $reader->expand();
375
- $parsed = $this->parse_post_node( $node );
376
- if ( is_wp_error( $parsed ) ) {
377
- $this->log_error( $parsed );
378
-
379
- // Skip the rest of this post
380
- $reader->next();
381
- break;
382
- }
383
-
384
- $this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
385
-
386
- // Handled everything in this node, move on to the next
387
- $reader->next();
388
- break;
389
-
390
- case 'wp:author':
391
- $node = $reader->expand();
392
-
393
- $parsed = $this->parse_author_node( $node );
394
- if ( is_wp_error( $parsed ) ) {
395
- $this->log_error( $parsed );
396
-
397
- // Skip the rest of this post
398
- $reader->next();
399
- break;
400
- }
401
-
402
- $status = $this->process_author( $parsed['data'], $parsed['meta'] );
403
- if ( is_wp_error( $status ) ) {
404
- $this->log_error( $status );
405
- }
406
-
407
- // Handled everything in this node, move on to the next
408
- $reader->next();
409
- break;
410
-
411
- case 'wp:category':
412
- $node = $reader->expand();
413
-
414
- $parsed = $this->parse_term_node( $node, 'category' );
415
- if ( is_wp_error( $parsed ) ) {
416
- $this->log_error( $parsed );
417
-
418
- // Skip the rest of this post
419
- $reader->next();
420
- break;
421
- }
422
-
423
- $status = $this->process_term( $parsed['data'], $parsed['meta'] );
424
-
425
- // Handled everything in this node, move on to the next
426
- $reader->next();
427
- break;
428
-
429
- case 'wp:tag':
430
- $node = $reader->expand();
431
-
432
- $parsed = $this->parse_term_node( $node, 'tag' );
433
- if ( is_wp_error( $parsed ) ) {
434
- $this->log_error( $parsed );
435
-
436
- // Skip the rest of this post
437
- $reader->next();
438
- break;
439
- }
440
-
441
- $status = $this->process_term( $parsed['data'], $parsed['meta'] );
442
-
443
- // Handled everything in this node, move on to the next
444
- $reader->next();
445
- break;
446
-
447
- case 'wp:term':
448
- $node = $reader->expand();
449
-
450
- $parsed = $this->parse_term_node( $node );
451
- if ( is_wp_error( $parsed ) ) {
452
- $this->log_error( $parsed );
453
-
454
- // Skip the rest of this post
455
- $reader->next();
456
- break;
457
- }
458
-
459
- $status = $this->process_term( $parsed['data'], $parsed['meta'] );
460
-
461
- // Handled everything in this node, move on to the next
462
- $reader->next();
463
- break;
464
-
465
- default:
466
- // Skip this node, probably handled by something already
467
- break;
468
- }// End switch().
469
- }// End while().
470
-
471
- // Now that we've done the main processing, do any required
472
- // post-processing and remapping.
473
- $this->post_process();
474
-
475
- if ( $this->options['aggressive_url_search'] ) {
476
- $this->replace_attachment_urls_in_content();
477
- }
478
- // $this->remap_featured_images();
479
- $this->import_end();
480
- }
481
-
482
- /**
483
- * Log an error instance to the logger.
484
- *
485
- * @param WP_Error $error Error instance to log.
486
- */
487
- protected function log_error( WP_Error $error ) {
488
- $this->logger->warning( $error->get_error_message() );
489
-
490
- // Log the data as debug info too
491
- $data = $error->get_error_data();
492
- if ( ! empty( $data ) ) {
493
- $this->logger->debug( var_export( $data, true ) );
494
- }
495
- }
496
-
497
- /**
498
- * Parses the WXR file and prepares us for the task of processing parsed data
499
- *
500
- * @param string $file Path to the WXR file for importing
501
- */
502
- protected function import_start( $file ) {
503
- if ( ! is_file( $file ) ) {
504
- return new WP_Error( 'wxr_importer.file_missing', __( 'The file does not exist, please try again.', 'wordpress-importer' ) );
505
- }
506
-
507
- // Suspend bunches of stuff in WP core
508
- wp_defer_term_counting( true );
509
- wp_defer_comment_counting( true );
510
- wp_suspend_cache_invalidation( true );
511
-
512
- // Prefill exists calls if told to
513
- if ( $this->options['prefill_existing_posts'] ) {
514
- $this->prefill_existing_posts();
515
- }
516
- if ( $this->options['prefill_existing_comments'] ) {
517
- $this->prefill_existing_comments();
518
- }
519
- if ( $this->options['prefill_existing_terms'] ) {
520
- $this->prefill_existing_terms();
521
- }
522
-
523
- /**
524
- * Begin the import.
525
- *
526
- * Fires before the import process has begun. If you need to suspend
527
- * caching or heavy processing on hooks, do so here.
528
- */
529
- do_action( 'import_start' );
530
- }
531
-
532
- /**
533
- * Performs post-import cleanup of files and the cache
534
- */
535
- protected function import_end() {
536
- // Re-enable stuff in core
537
- wp_suspend_cache_invalidation( false );
538
- wp_cache_flush();
539
- foreach ( get_taxonomies() as $tax ) {
540
- delete_option( "{$tax}_children" );
541
- _get_term_hierarchy( $tax );
542
- }
543
-
544
- wp_defer_term_counting( false );
545
- wp_defer_comment_counting( false );
546
-
547
- /**
548
- * Complete the import.
549
- *
550
- * Fires after the import process has finished. If you need to update
551
- * your cache or re-enable processing, do so here.
552
- */
553
- do_action( 'import_end' );
554
- }
555
-
556
- /**
557
- * Set the user mapping.
558
- *
559
- * @param array $mapping List of map arrays (containing `old_slug`, `old_id`, `new_id`)
560
- */
561
- public function set_user_mapping( $mapping ) {
562
- foreach ( $mapping as $map ) {
563
- if ( empty( $map['old_slug'] ) || empty( $map['old_id'] ) || empty( $map['new_id'] ) ) {
564
- $this->logger->warning( __( 'Invalid author mapping', 'wordpress-importer' ) );
565
- $this->logger->debug( var_export( $map, true ) );
566
- continue;
567
- }
568
-
569
- $old_slug = $map['old_slug'];
570
- $old_id = $map['old_id'];
571
- $new_id = $map['new_id'];
572
-
573
- $this->mapping['user'][ $old_id ] = $new_id;
574
- $this->mapping['user_slug'][ $old_slug ] = $new_id;
575
- }
576
- }
577
-
578
- /**
579
- * Set the user slug overrides.
580
- *
581
- * Allows overriding the slug in the import with a custom/renamed version.
582
- *
583
- * @param string[] $overrides Map of old slug to new slug.
584
- */
585
- public function set_user_slug_overrides( $overrides ) {
586
- foreach ( $overrides as $original => $renamed ) {
587
- $this->user_slug_override[ $original ] = $renamed;
588
- }
589
- }
590
-
591
- /**
592
- * Parse a post node into post data.
593
- *
594
- * @param DOMElement $node Parent node of post data (typically `item`).
595
- * @return array|WP_Error Post data array on success, error otherwise.
596
- */
597
- protected function parse_post_node( $node ) {
598
- $data = array();
599
- $meta = array();
600
- $comments = array();
601
- $terms = array();
602
-
603
- foreach ( $node->childNodes as $child ) {
604
- // We only care about child elements
605
- if ( $child->nodeType !== XML_ELEMENT_NODE ) {
606
- continue;
607
- }
608
-
609
- switch ( $child->tagName ) {
610
- case 'wp:post_type':
611
- $data['post_type'] = $child->textContent;
612
- break;
613
-
614
- case 'title':
615
- $data['post_title'] = $child->textContent;
616
- break;
617
-
618
- case 'guid':
619
- $data['guid'] = $child->textContent;
620
- break;
621
-
622
- case 'dc:creator':
623
- $data['post_author'] = $child->textContent;
624
- break;
625
-
626
- case 'content:encoded':
627
- $data['post_content'] = $child->textContent;
628
- break;
629
-
630
- case 'excerpt:encoded':
631
- $data['post_excerpt'] = $child->textContent;
632
- break;
633
-
634
- case 'wp:post_id':
635
- $data['post_id'] = $child->textContent;
636
- break;
637
-
638
- case 'wp:post_date':
639
- $data['post_date'] = $child->textContent;
640
- break;
641
-
642
- case 'wp:post_date_gmt':
643
- $data['post_date_gmt'] = $child->textContent;
644
- break;
645
-
646
- case 'wp:comment_status':
647
- $data['comment_status'] = $child->textContent;
648
- break;
649
-
650
- case 'wp:ping_status':
651
- $data['ping_status'] = $child->textContent;
652
- break;
653
-
654
- case 'wp:post_name':
655
- $data['post_name'] = $child->textContent;
656
- break;
657
-
658
- case 'wp:status':
659
- $data['post_status'] = $child->textContent;
660
-
661
- if ( $data['post_status'] === 'auto-draft' ) {
662
- // Bail now
663
- return new WP_Error(
664
- 'wxr_importer.post.cannot_import_draft',
665
- __( 'Cannot import auto-draft posts' ),
666
- $data
667
- );
668
- }
669
- break;
670
-
671
- case 'wp:post_parent':
672
- $data['post_parent'] = $child->textContent;
673
- break;
674
-
675
- case 'wp:menu_order':
676
- $data['menu_order'] = $child->textContent;
677
- break;
678
-
679
- case 'wp:post_password':
680
- $data['post_password'] = $child->textContent;
681
- break;
682
-
683
- case 'wp:is_sticky':
684
- $data['is_sticky'] = $child->textContent;
685
- break;
686
-
687
- case 'wp:attachment_url':
688
- $data['attachment_url'] = $child->textContent;
689
- break;
690
-
691
- case 'wp:postmeta':
692
- $meta_item = $this->parse_meta_node( $child );
693
- if ( ! empty( $meta_item ) ) {
694
- $meta[] = $meta_item;
695
- }
696
- break;
697
-
698
- case 'wp:comment':
699
- $comment_item = $this->parse_comment_node( $child );
700
- if ( ! empty( $comment_item ) ) {
701
- $comments[] = $comment_item;
702
- }
703
- break;
704
-
705
- case 'category':
706
- $term_item = $this->parse_category_node( $child );
707
- if ( ! empty( $term_item ) ) {
708
- $terms[] = $term_item;
709
- }
710
- break;
711
- }// End switch().
712
- }// End foreach().
713
-
714
- return compact( 'data', 'meta', 'comments', 'terms' );
715
- }
716
-
717
- /**
718
- * Create new posts based on import information
719
- *
720
- * Posts marked as having a parent which doesn't exist will become top level items.
721
- * Doesn't create a new post if: the post type doesn't exist, the given post ID
722
- * is already noted as imported or a post with the same title and date already exists.
723
- * Note that new/updated terms, comments and meta are imported for the last of the above.
724
- */
725
- protected function process_post( $data, $meta, $comments, $terms ) {
726
- /**
727
- * Pre-process post data.
728
- *
729
- * @param array $data Post data. (Return empty to skip.)
730
- * @param array $meta Meta data.
731
- * @param array $comments Comments on the post.
732
- * @param array $terms Terms on the post.
733
- */
734
- $data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
735
- if ( empty( $data ) ) {
736
- return false;
737
- }
738
-
739
- $original_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
740
- $parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
741
- $author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
742
-
743
- // Have we already processed this?
744
- if ( isset( $this->mapping['post'][ $original_id ] ) ) {
745
- return;
746
- }
747
-
748
- $post_type_object = get_post_type_object( $data['post_type'] );
749
-
750
- // Is this type even valid?
751
- if ( ! $post_type_object ) {
752
- $this->logger->warning( sprintf(
753
- __( 'Failed to import "%1$s": Invalid post type %2$s', 'wordpress-importer' ),
754
- $data['post_title'],
755
- $data['post_type']
756
- ) );
757
- return false;
758
- }
759
-
760
- $post_exists = $this->post_exists( $data );
761
- if ( $post_exists ) {
762
- $this->logger->info( sprintf(
763
- __( '%1$s "%2$s" already exists.', 'wordpress-importer' ),
764
- $post_type_object->labels->singular_name,
765
- $data['post_title']
766
- ) );
767
-
768
- /**
769
- * Post processing already imported.
770
- *
771
- * @param array $data Raw data imported for the post.
772
- */
773
- do_action( 'wxr_importer.process_already_imported.post', $data );
774
-
775
- // Even though this post already exists, new comments might need importing
776
- $this->process_comments( $comments, $original_id, $data, $post_exists );
777
-
778
- return false;
779
- }
780
-
781
- // Map the parent post, or mark it as one we need to fix
782
- $requires_remapping = false;
783
- if ( $parent_id ) {
784
- if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
785
- $data['post_parent'] = $this->mapping['post'][ $parent_id ];
786
- } else {
787
- $meta[] = array(
788
- 'key' => '_wxr_import_parent',
789
- 'value' => $parent_id,
790
- );
791
- $requires_remapping = true;
792
-
793
- $data['post_parent'] = 0;
794
- }
795
- }
796
-
797
- // Map the author, or mark it as one we need to fix
798
- $author = sanitize_user( $data['post_author'], true );
799
- if ( empty( $author ) ) {
800
- // Missing or invalid author, use default if available.
801
- $data['post_author'] = $this->options['default_author'];
802
- } elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
803
- $data['post_author'] = $this->mapping['user_slug'][ $author ];
804
- } else {
805
- $meta[] = array(
806
- 'key' => '_wxr_import_user_slug',
807
- 'value' => $author,
808
- );
809
- $requires_remapping = true;
810
-
811
- $data['post_author'] = (int) get_current_user_id();
812
- }
813
-
814
- // Does the post look like it contains attachment images?
815
- if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
816
- $meta[] = array(
817
- 'key' => '_wxr_import_has_attachment_refs',
818
- 'value' => true,
819
- );
820
- $requires_remapping = true;
821
- }
822
-
823
- // Whitelist to just the keys we allow
824
- $postdata = array(
825
- 'import_id' => $data['post_id'],
826
- );
827
- $allowed = array(
828
- 'post_author' => true,
829
- 'post_date' => true,
830
- 'post_date_gmt' => true,
831
- 'post_content' => true,
832
- 'post_excerpt' => true,
833
- 'post_title' => true,
834
- 'post_status' => true,
835
- 'post_name' => true,
836
- 'comment_status' => true,
837
- 'ping_status' => true,
838
- 'guid' => true,
839
- 'post_parent' => true,
840
- 'menu_order' => true,
841
- 'post_type' => true,
842
- 'post_password' => true,
843
- );
844
- foreach ( $data as $key => $value ) {
845
- if ( ! isset( $allowed[ $key ] ) ) {
846
- continue;
847
- }
848
-
849
- $postdata[ $key ] = $data[ $key ];
850
- }
851
-
852
- $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $data );
853
-
854
- if ( 'attachment' === $postdata['post_type'] ) {
855
- if ( ! $this->options['fetch_attachments'] ) {
856
- $this->logger->notice( sprintf(
857
- __( 'Skipping attachment "%s", fetching attachments disabled' ),
858
- $data['post_title']
859
- ) );
860
- /**
861
- * Post processing skipped.
862
- *
863
- * @param array $data Raw data imported for the post.
864
- * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
865
- */
866
- do_action( 'wxr_importer.process_skipped.post', $data, $meta );
867
- return false;
868
- }
869
- $remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
870
- $post_id = $this->process_attachment( $postdata, $meta, $remote_url );
871
- } else {
872
- $post_id = wp_insert_post( $postdata, true );
873
- do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
874
- }
875
-
876
- if ( is_wp_error( $post_id ) ) {
877
- $this->logger->error( sprintf(
878
- __( 'Failed to import "%1$s" (%2$s)', 'wordpress-importer' ),
879
- $data['post_title'],
880
- $post_type_object->labels->singular_name
881
- ) );
882
- $this->logger->debug( $post_id->get_error_message() );
883
-
884
- /**
885
- * Post processing failed.
886
- *
887
- * @param WP_Error $post_id Error object.
888
- * @param array $data Raw data imported for the post.
889
- * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
890
- * @param array $comments Raw comment data, already processed by {@see process_comments}.
891
- * @param array $terms Raw term data, already processed.
892
- */
893
- do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
894
- return false;
895
- }
896
-
897
- // Ensure stickiness is handled correctly too
898
- if ( $data['is_sticky'] === '1' ) {
899
- stick_post( $post_id );
900
- }
901
-
902
- // map pre-import ID to local ID
903
- $this->mapping['post'][ $original_id ] = (int) $post_id;
904
- if ( $requires_remapping ) {
905
- $this->requires_remapping['post'][ $post_id ] = true;
906
- }
907
- $this->mark_post_exists( $data, $post_id );
908
-
909
- $this->logger->info( sprintf(
910
- __( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
911
- $data['post_title'],
912
- $post_type_object->labels->singular_name
913
- ) );
914
- $this->logger->debug( sprintf(
915
- __( 'Post %1$d remapped to %2$d', 'wordpress-importer' ),
916
- $original_id,
917
- $post_id
918
- ) );
919
-
920
- // Handle the terms too
921
- $terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
922
-
923
- if ( ! empty( $terms ) ) {
924
- $term_ids = array();
925
- foreach ( $terms as $term ) {
926
- $taxonomy = $term['taxonomy'];
927
- $key = sha1( $taxonomy . ':' . $term['slug'] );
928
-
929
- if ( isset( $this->mapping['term'][ $key ] ) ) {
930
- $term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
931
- } else {
932
- $meta[] = array(
933
- 'key' => '_wxr_import_term',
934
- 'value' => $term,
935
- );
936
- $requires_remapping = true;
937
- }
938
- }
939
-
940
- foreach ( $term_ids as $tax => $ids ) {
941
- $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
942
- do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $data );
943
- }
944
- }
945
-
946
- $this->process_comments( $comments, $post_id, $data );
947
- $this->process_post_meta( $meta, $post_id, $data );
948
-
949
- if ( 'nav_menu_item' === $data['post_type'] ) {
950
- $this->process_menu_item_meta( $post_id, $data, $meta );
951
- }
952
-
953
- /**
954
- * Post processing completed.
955
- *
956
- * @param int $post_id New post ID.
957
- * @param array $data Raw data imported for the post.
958
- * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
959
- * @param array $comments Raw comment data, already processed by {@see process_comments}.
960
- * @param array $terms Raw term data, already processed.
961
- */
962
- do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
963
- }
964
-
965
- /**
966
- * Attempt to create a new menu item from import data
967
- *
968
- * Fails for draft, orphaned menu items and those without an associated nav_menu
969
- * or an invalid nav_menu term. If the post type or term object which the menu item
970
- * represents doesn't exist then the menu item will not be imported (waits until the
971
- * end of the import to retry again before discarding).
972
- *
973
- * @param array $item Menu item details from WXR file
974
- */
975
- protected function process_menu_item_meta( $post_id, $data, $meta ) {
976
-
977
- $item_type = get_post_meta( $post_id, '_menu_item_type', true );
978
- $original_object_id = get_post_meta( $post_id, '_menu_item_object_id', true );
979
- $object_id = null;
980
-
981
- $this->logger->debug( sprintf( 'Processing menu item %s', $item_type ) );
982
-
983
- $requires_remapping = false;
984
- switch ( $item_type ) {
985
- case 'taxonomy':
986
- if ( isset( $this->mapping['term_id'][ $original_object_id ] ) ) {
987
- $object_id = $this->mapping['term_id'][ $original_object_id ];
988
- } else {
989
- add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
990
- $requires_remapping = true;
991
- }
992
- break;
993
-
994
- case 'post_type':
995
- if ( isset( $this->mapping['post'][ $original_object_id ] ) ) {
996
- $object_id = $this->mapping['post'][ $original_object_id ];
997
- } else {
998
- add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
999
- $requires_remapping = true;
1000
- }
1001
- break;
1002
-
1003
- case 'custom':
1004
- // Custom refers to itself, wonderfully easy.
1005
- $object_id = $post_id;
1006
- break;
1007
-
1008
- default:
1009
- // associated object is missing or not imported yet, we'll retry later
1010
- $this->missing_menu_items[] = $item;
1011
- $this->logger->debug( 'Unknown menu item type' );
1012
- break;
1013
- }
1014
-
1015
- if ( $requires_remapping ) {
1016
- $this->requires_remapping['post'][ $post_id ] = true;
1017
- }
1018
-
1019
- if ( empty( $object_id ) ) {
1020
- // Nothing needed here.
1021
- return;
1022
- }
1023
-
1024
- $this->logger->debug( sprintf( 'Menu item %d mapped to %d', $original_object_id, $object_id ) );
1025
- update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $object_id ) );
1026
- }
1027
-
1028
- /**
1029
- * If fetching attachments is enabled then attempt to create a new attachment
1030
- *
1031
- * @param array $post Attachment post details from WXR
1032
- * @param string $url URL to fetch attachment from
1033
- * @return int|WP_Error Post ID on success, WP_Error otherwise
1034
- */
1035
- protected function process_attachment( $post, $meta, $remote_url ) {
1036
- // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
1037
- // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
1038
- $post['upload_date'] = $post['post_date'];
1039
- foreach ( $meta as $meta_item ) {
1040
- if ( $meta_item['key'] !== '_wp_attached_file' ) {
1041
- continue;
1042
- }
1043
-
1044
- if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_item['value'], $matches ) ) {
1045
- $post['upload_date'] = $matches[0];
1046
- }
1047
- break;
1048
- }
1049
-
1050
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1051
- if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
1052
- $remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
1053
- }
1054
-
1055
- $upload = $this->fetch_remote_file( $remote_url, $post );
1056
- if ( is_wp_error( $upload ) ) {
1057
- return $upload;
1058
- }
1059
-
1060
- $info = wp_check_filetype( $upload['file'] );
1061
- if ( ! $info ) {
1062
- return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) );
1063
- }
1064
-
1065
- $post['post_mime_type'] = $info['type'];
1066
-
1067
- // WP really likes using the GUID for display. Allow updating it.
1068
- // See https://core.trac.wordpress.org/ticket/33386
1069
- if ( $this->options['update_attachment_guids'] ) {
1070
- $post['guid'] = $upload['url'];
1071
- }
1072
-
1073
- // as per wp-admin/includes/upload.php
1074
- $post_id = wp_insert_attachment( $post, $upload['file'] );
1075
- if ( is_wp_error( $post_id ) ) {
1076
- return $post_id;
1077
- }
1078
-
1079
- $attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
1080
- wp_update_attachment_metadata( $post_id, $attachment_metadata );
1081
-
1082
- // Map this image URL later if we need to
1083
- $this->url_remap[ $remote_url ] = $upload['url'];
1084
-
1085
- // If we have a HTTPS URL, ensure the HTTP URL gets replaced too
1086
- if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
1087
- $insecure_url = 'http' . substr( $remote_url, 5 );
1088
- $this->url_remap[ $insecure_url ] = $upload['url'];
1089
- }
1090
-
1091
- if ( $this->options['aggressive_url_search'] ) {
1092
- // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1093
- /*
1094
- if ( preg_match( '!^image/!', $info['type'] ) ) {
1095
- $parts = pathinfo( $remote_url );
1096
- $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1097
-
1098
- $parts_new = pathinfo( $upload['url'] );
1099
- $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1100
-
1101
- $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1102
- }*/
1103
- }
1104
-
1105
- return $post_id;
1106
- }
1107
-
1108
- /**
1109
- * Parse a meta node into meta data.
1110
- *
1111
- * @param DOMElement $node Parent node of meta data (typically `wp:postmeta` or `wp:commentmeta`).
1112
- * @return array|null Meta data array on success, or null on error.
1113
- */
1114
- protected function parse_meta_node( $node ) {
1115
- foreach ( $node->childNodes as $child ) {
1116
- // We only care about child elements
1117
- if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1118
- continue;
1119
- }
1120
-
1121
- switch ( $child->tagName ) {
1122
- case 'wp:meta_key':
1123
- $key = $child->textContent;
1124
- break;
1125
-
1126
- case 'wp:meta_value':
1127
- $value = $child->textContent;
1128
- break;
1129
- }
1130
- }
1131
-
1132
- if ( empty( $key ) || empty( $value ) ) {
1133
- return null;
1134
- }
1135
-
1136
- return compact( 'key', 'value' );
1137
- }
1138
-
1139
- /**
1140
- * Process and import post meta items.
1141
- *
1142
- * @param array $meta List of meta data arrays
1143
- * @param int $post_id Post to associate with
1144
- * @param array $post Post data
1145
- * @return int|WP_Error Number of meta items imported on success, error otherwise.
1146
- */
1147
- protected function process_post_meta( $meta, $post_id, $post ) {
1148
- if ( empty( $meta ) ) {
1149
- return true;
1150
- }
1151
-
1152
- foreach ( $meta as $meta_item ) {
1153
- /**
1154
- * Pre-process post meta data.
1155
- *
1156
- * @param array $meta_item Meta data. (Return empty to skip.)
1157
- * @param int $post_id Post the meta is attached to.
1158
- */
1159
- $meta_item = apply_filters( 'wxr_importer.pre_process.post_meta', $meta_item, $post_id );
1160
- if ( empty( $meta_item ) ) {
1161
- return false;
1162
- }
1163
-
1164
- $key = apply_filters( 'import_post_meta_key', $meta_item['key'], $post_id, $post );
1165
- $value = false;
1166
-
1167
- if ( '_edit_last' === $key ) {
1168
- $value = intval( $meta_item['value'] );
1169
- if ( ! isset( $this->mapping['user'][ $value ] ) ) {
1170
- // Skip!
1171
- continue;
1172
- }
1173
-
1174
- $value = $this->mapping['user'][ $value ];
1175
- }
1176
-
1177
- if ( $key ) {
1178
- // export gets meta straight from the DB so could have a serialized string
1179
- if ( ! $value ) {
1180
- $value = maybe_unserialize( $meta_item['value'] );
1181
- }
1182
-
1183
- add_post_meta( $post_id, $key, $value );
1184
- do_action( 'import_post_meta', $post_id, $key, $value );
1185
-
1186
- // if the post has a featured image, take note of this in case of remap
1187
- if ( '_thumbnail_id' === $key ) {
1188
- $this->featured_images[ $post_id ] = (int) $value;
1189
- }
1190
- }
1191
- }// End foreach().
1192
-
1193
- return true;
1194
- }
1195
-
1196
- /**
1197
- * Parse a comment node into comment data.
1198
- *
1199
- * @param DOMElement $node Parent node of comment data (typically `wp:comment`).
1200
- * @return array Comment data array.
1201
- */
1202
- protected function parse_comment_node( $node ) {
1203
- $data = array(
1204
- 'commentmeta' => array(),
1205
- );
1206
-
1207
- foreach ( $node->childNodes as $child ) {
1208
- // We only care about child elements
1209
- if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1210
- continue;
1211
- }
1212
-
1213
- switch ( $child->tagName ) {
1214
- case 'wp:comment_id':
1215
- $data['comment_id'] = $child->textContent;
1216
- break;
1217
- case 'wp:comment_author':
1218
- $data['comment_author'] = $child->textContent;
1219
- break;
1220
-
1221
- case 'wp:comment_author_email':
1222
- $data['comment_author_email'] = $child->textContent;
1223
- break;
1224
-
1225
- case 'wp:comment_author_IP':
1226
- $data['comment_author_IP'] = $child->textContent;
1227
- break;
1228
-
1229
- case 'wp:comment_author_url':
1230
- $data['comment_author_url'] = $child->textContent;
1231
- break;
1232
-
1233
- case 'wp:comment_user_id':
1234
- $data['comment_user_id'] = $child->textContent;
1235
- break;
1236
-
1237
- case 'wp:comment_date':
1238
- $data['comment_date'] = $child->textContent;
1239
- break;
1240
-
1241
- case 'wp:comment_date_gmt':
1242
- $data['comment_date_gmt'] = $child->textContent;
1243
- break;
1244
-
1245
- case 'wp:comment_content':
1246
- $data['comment_content'] = $child->textContent;
1247
- break;
1248
-
1249
- case 'wp:comment_approved':
1250
- $data['comment_approved'] = $child->textContent;
1251
- break;
1252
-
1253
- case 'wp:comment_type':
1254
- $data['comment_type'] = $child->textContent;
1255
- break;
1256
-
1257
- case 'wp:comment_parent':
1258
- $data['comment_parent'] = $child->textContent;
1259
- break;
1260
-
1261
- case 'wp:commentmeta':
1262
- $meta_item = $this->parse_meta_node( $child );
1263
- if ( ! empty( $meta_item ) ) {
1264
- $data['commentmeta'][] = $meta_item;
1265
- }
1266
- break;
1267
- }// End switch().
1268
- }// End foreach().
1269
-
1270
- return $data;
1271
- }
1272
-
1273
- /**
1274
- * Process and import comment data.
1275
- *
1276
- * @param array $comments List of comment data arrays.
1277
- * @param int $post_id Post to associate with.
1278
- * @param array $post Post data.
1279
- * @return int|WP_Error Number of comments imported on success, error otherwise.
1280
- */
1281
- protected function process_comments( $comments, $post_id, $post, $post_exists = false ) {
1282
-
1283
- $comments = apply_filters( 'wp_import_post_comments', $comments, $post_id, $post );
1284
- if ( empty( $comments ) ) {
1285
- return 0;
1286
- }
1287
-
1288
- $num_comments = 0;
1289
-
1290
- // Sort by ID to avoid excessive remapping later
1291
- usort( $comments, array( $this, 'sort_comments_by_id' ) );
1292
-
1293
- foreach ( $comments as $key => $comment ) {
1294
- /**
1295
- * Pre-process comment data
1296
- *
1297
- * @param array $comment Comment data. (Return empty to skip.)
1298
- * @param int $post_id Post the comment is attached to.
1299
- */
1300
- $comment = apply_filters( 'wxr_importer.pre_process.comment', $comment, $post_id );
1301
- if ( empty( $comment ) ) {
1302
- return false;
1303
- }
1304
-
1305
- $original_id = isset( $comment['comment_id'] ) ? (int) $comment['comment_id'] : 0;
1306
- $parent_id = isset( $comment['comment_parent'] ) ? (int) $comment['comment_parent'] : 0;
1307
- $author_id = isset( $comment['comment_user_id'] ) ? (int) $comment['comment_user_id'] : 0;
1308
-
1309
- // if this is a new post we can skip the comment_exists() check
1310
- // TODO: Check comment_exists for performance
1311
- if ( $post_exists ) {
1312
- $existing = $this->comment_exists( $comment );
1313
- if ( $existing ) {
1314
-
1315
- /**
1316
- * Comment processing already imported.
1317
- *
1318
- * @param array $comment Raw data imported for the comment.
1319
- */
1320
- do_action( 'wxr_importer.process_already_imported.comment', $comment );
1321
-
1322
- $this->mapping['comment'][ $original_id ] = $existing;
1323
- continue;
1324
- }
1325
- }
1326
-
1327
- // Remove meta from the main array
1328
- $meta = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
1329
- unset( $comment['commentmeta'] );
1330
-
1331
- // Map the parent comment, or mark it as one we need to fix
1332
- $requires_remapping = false;
1333
- if ( $parent_id ) {
1334
- if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
1335
- $comment['comment_parent'] = $this->mapping['comment'][ $parent_id ];
1336
- } else {
1337
- // Prepare for remapping later
1338
- $meta[] = array(
1339
- 'key' => '_wxr_import_parent',
1340
- 'value' => $parent_id,
1341
- );
1342
- $requires_remapping = true;
1343
-
1344
- // Wipe the parent for now
1345
- $comment['comment_parent'] = 0;
1346
- }
1347
- }
1348
-
1349
- // Map the author, or mark it as one we need to fix
1350
- if ( $author_id ) {
1351
- if ( isset( $this->mapping['user'][ $author_id ] ) ) {
1352
- $comment['user_id'] = $this->mapping['user'][ $author_id ];
1353
- } else {
1354
- // Prepare for remapping later
1355
- $meta[] = array(
1356
- 'key' => '_wxr_import_user',
1357
- 'value' => $author_id,
1358
- );
1359
- $requires_remapping = true;
1360
-
1361
- // Wipe the user for now
1362
- $comment['user_id'] = 0;
1363
- }
1364
- }
1365
-
1366
- // Run standard core filters
1367
- $comment['comment_post_ID'] = $post_id;
1368
- $comment = wp_filter_comment( $comment );
1369
-
1370
- // wp_insert_comment expects slashed data
1371
- $comment_id = wp_insert_comment( wp_slash( $comment ) );
1372
- $this->mapping['comment'][ $original_id ] = $comment_id;
1373
- if ( $requires_remapping ) {
1374
- $this->requires_remapping['comment'][ $comment_id ] = true;
1375
- }
1376
- $this->mark_comment_exists( $comment, $comment_id );
1377
-
1378
- /**
1379
- * Comment has been imported.
1380
- *
1381
- * @param int $comment_id New comment ID
1382
- * @param array $comment Comment inserted (`comment_id` item refers to the original ID)
1383
- * @param int $post_id Post parent of the comment
1384
- * @param array $post Post data
1385
- */
1386
- do_action( 'wp_import_insert_comment', $comment_id, $comment, $post_id, $post );
1387
-
1388
- // Process the meta items
1389
- foreach ( $meta as $meta_item ) {
1390
- $value = maybe_unserialize( $meta_item['value'] );
1391
- add_comment_meta( $comment_id, wp_slash( $meta_item['key'] ), wp_slash( $value ) );
1392
- }
1393
-
1394
- /**
1395
- * Post processing completed.
1396
- *
1397
- * @param int $post_id New post ID.
1398
- * @param array $comment Raw data imported for the comment.
1399
- * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
1400
- * @param array $post_id Parent post ID.
1401
- */
1402
- do_action( 'wxr_importer.processed.comment', $comment_id, $comment, $meta, $post_id );
1403
-
1404
- $num_comments++;
1405
- }// End foreach().
1406
-
1407
- return $num_comments;
1408
- }
1409
-
1410
- protected function parse_category_node( $node ) {
1411
- $data = array(
1412
- // Default taxonomy to "category", since this is a `<category>` tag
1413
- 'taxonomy' => 'category',
1414
- );
1415
- $meta = array();
1416
-
1417
- if ( $node->hasAttribute( 'domain' ) ) {
1418
- $data['taxonomy'] = $node->getAttribute( 'domain' );
1419
- }
1420
- if ( $node->hasAttribute( 'nicename' ) ) {
1421
- $data['slug'] = $node->getAttribute( 'nicename' );
1422
- }
1423
-
1424
- $data['name'] = $node->textContent;
1425
-
1426
- if ( empty( $data['slug'] ) ) {
1427
- return null;
1428
- }
1429
-
1430
- // Just for extra compatibility
1431
- if ( $data['taxonomy'] === 'tag' ) {
1432
- $data['taxonomy'] = 'post_tag';
1433
- }
1434
-
1435
- return $data;
1436
- }
1437
-
1438
- /**
1439
- * Callback for `usort` to sort comments by ID
1440
- *
1441
- * @param array $a Comment data for the first comment
1442
- * @param array $b Comment data for the second comment
1443
- * @return int
1444
- */
1445
- public static function sort_comments_by_id( $a, $b ) {
1446
- if ( empty( $a['comment_id'] ) ) {
1447
- return 1;
1448
- }
1449
-
1450
- if ( empty( $b['comment_id'] ) ) {
1451
- return -1;
1452
- }
1453
-
1454
- return $a['comment_id'] - $b['comment_id'];
1455
- }
1456
-
1457
- protected function parse_author_node( $node ) {
1458
- $data = array();
1459
- $meta = array();
1460
- foreach ( $node->childNodes as $child ) {
1461
- // We only care about child elements
1462
- if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1463
- continue;
1464
- }
1465
-
1466
- switch ( $child->tagName ) {
1467
- case 'wp:author_login':
1468
- $data['user_login'] = $child->textContent;
1469
- break;
1470
-
1471
- case 'wp:author_id':
1472
- $data['ID'] = $child->textContent;
1473
- break;
1474
-
1475
- case 'wp:author_email':
1476
- $data['user_email'] = $child->textContent;
1477
- break;
1478
-
1479
- case 'wp:author_display_name':
1480
- $data['display_name'] = $child->textContent;
1481
- break;
1482
-
1483
- case 'wp:author_first_name':
1484
- $data['first_name'] = $child->textContent;
1485
- break;
1486
-
1487
- case 'wp:author_last_name':
1488
- $data['last_name'] = $child->textContent;
1489
- break;
1490
- }
1491
- }
1492
-
1493
- return compact( 'data', 'meta' );
1494
- }
1495
-
1496
- protected function process_author( $data, $meta ) {
1497
- /**
1498
- * Pre-process user data.
1499
- *
1500
- * @param array $data User data. (Return empty to skip.)
1501
- * @param array $meta Meta data.
1502
- */
1503
- $data = apply_filters( 'wxr_importer.pre_process.user', $data, $meta );
1504
- if ( empty( $data ) ) {
1505
- return false;
1506
- }
1507
-
1508
- // Have we already handled this user?
1509
- $original_id = isset( $data['ID'] ) ? $data['ID'] : 0;
1510
- $original_slug = $data['user_login'];
1511
-
1512
- if ( isset( $this->mapping['user'][ $original_id ] ) ) {
1513
- $existing = $this->mapping['user'][ $original_id ];
1514
-
1515
- // Note the slug mapping if we need to too
1516
- if ( ! isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
1517
- $this->mapping['user_slug'][ $original_slug ] = $existing;
1518
- }
1519
-
1520
- return false;
1521
- }
1522
-
1523
- if ( isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
1524
- $existing = $this->mapping['user_slug'][ $original_slug ];
1525
-
1526
- // Ensure we note the mapping too
1527
- $this->mapping['user'][ $original_id ] = $existing;
1528
-
1529
- return false;
1530
- }
1531
-
1532
- // Allow overriding the user's slug
1533
- $login = $original_slug;
1534
- if ( isset( $this->user_slug_override[ $login ] ) ) {
1535
- $login = $this->user_slug_override[ $login ];
1536
- }
1537
-
1538
- $userdata = array(
1539
- 'user_login' => sanitize_user( $login, true ),
1540
- 'user_pass' => wp_generate_password(),
1541
- );
1542
-
1543
- $allowed = array(
1544
- 'user_email' => true,
1545
- 'display_name' => true,
1546
- 'first_name' => true,
1547
- 'last_name' => true,
1548
- );
1549
- foreach ( $data as $key => $value ) {
1550
- if ( ! isset( $allowed[ $key ] ) ) {
1551
- continue;
1552
- }
1553
-
1554
- $userdata[ $key ] = $data[ $key ];
1555
- }
1556
-
1557
- $user_id = wp_insert_user( wp_slash( $userdata ) );
1558
- if ( is_wp_error( $user_id ) ) {
1559
- $this->logger->error( sprintf(
1560
- __( 'Failed to import user "%s"', 'wordpress-importer' ),
1561
- $userdata['user_login']
1562
- ) );
1563
- $this->logger->debug( $user_id->get_error_message() );
1564
-
1565
- /**
1566
- * User processing failed.
1567
- *
1568
- * @param WP_Error $user_id Error object.
1569
- * @param array $userdata Raw data imported for the user.
1570
- */
1571
- do_action( 'wxr_importer.process_failed.user', $user_id, $userdata );
1572
- return false;
1573
- }
1574
-
1575
- if ( $original_id ) {
1576
- $this->mapping['user'][ $original_id ] = $user_id;
1577
- }
1578
- $this->mapping['user_slug'][ $original_slug ] = $user_id;
1579
-
1580
- $this->logger->info( sprintf(
1581
- __( 'Imported user "%s"', 'wordpress-importer' ),
1582
- $userdata['user_login']
1583
- ) );
1584
- $this->logger->debug( sprintf(
1585
- __( 'User %1$d remapped to %2$d', 'wordpress-importer' ),
1586
- $original_id,
1587
- $user_id
1588
- ) );
1589
-
1590
- // TODO: Implement meta handling once WXR includes it
1591
- /**
1592
- * User processing completed.
1593
- *
1594
- * @param int $user_id New user ID.
1595
- * @param array $userdata Raw data imported for the user.
1596
- */
1597
- do_action( 'wxr_importer.processed.user', $user_id, $userdata );
1598
- }
1599
-
1600
- protected function parse_term_node( $node, $type = 'term' ) {
1601
- $data = array();
1602
- $meta = array();
1603
-
1604
- $tag_name = array(
1605
- 'id' => 'wp:term_id',
1606
- 'taxonomy' => 'wp:term_taxonomy',
1607
- 'slug' => 'wp:term_slug',
1608
- 'parent' => 'wp:term_parent',
1609
- 'name' => 'wp:term_name',
1610
- 'description' => 'wp:term_description',
1611
- );
1612
- $taxonomy = null;
1613
-
1614
- // Special casing!
1615
- switch ( $type ) {
1616
- case 'category':
1617
- $tag_name['slug'] = 'wp:category_nicename';
1618
- $tag_name['parent'] = 'wp:category_parent';
1619
- $tag_name['name'] = 'wp:cat_name';
1620
- $tag_name['description'] = 'wp:category_description';
1621
- $tag_name['taxonomy'] = null;
1622
-
1623
- $data['taxonomy'] = 'category';
1624
- break;
1625
-
1626
- case 'tag':
1627
- $tag_name['slug'] = 'wp:tag_slug';
1628
- $tag_name['parent'] = null;
1629
- $tag_name['name'] = 'wp:tag_name';
1630
- $tag_name['description'] = 'wp:tag_description';
1631
- $tag_name['taxonomy'] = null;
1632
-
1633
- $data['taxonomy'] = 'post_tag';
1634
- break;
1635
- }
1636
-
1637
- foreach ( $node->childNodes as $child ) {
1638
- // We only care about child elements
1639
- if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1640
- continue;
1641
- }
1642
-
1643
- $key = array_search( $child->tagName, $tag_name );
1644
- if ( $key ) {
1645
- $data[ $key ] = $child->textContent;
1646
- }
1647
- }
1648
-
1649
- if ( empty( $data['taxonomy'] ) ) {
1650
- return null;
1651
- }
1652
-
1653
- // Compatibility with WXR 1.0
1654
- if ( $data['taxonomy'] === 'tag' ) {
1655
- $data['taxonomy'] = 'post_tag';
1656
- }
1657
-
1658
- return compact( 'data', 'meta' );
1659
- }
1660
-
1661
- protected function process_term( $data, $meta ) {
1662
- /**
1663
- * Pre-process term data.
1664
- *
1665
- * @param array $data Term data. (Return empty to skip.)
1666
- * @param array $meta Meta data.
1667
- */
1668
- $data = apply_filters( 'wxr_importer.pre_process.term', $data, $meta );
1669
- if ( empty( $data ) ) {
1670
- return false;
1671
- }
1672
-
1673
- $original_id = isset( $data['id'] ) ? (int) $data['id'] : 0;
1674
- $parent_id = isset( $data['parent'] ) ? (int) $data['parent'] : 0;
1675
-
1676
- $mapping_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
1677
- $existing = $this->term_exists( $data );
1678
- if ( $existing ) {
1679
-
1680
- /**
1681
- * Term processing already imported.
1682
- *
1683
- * @param array $data Raw data imported for the term.
1684
- */
1685
- do_action( 'wxr_importer.process_already_imported.term', $data );
1686
-
1687
- $this->mapping['term'][ $mapping_key ] = $existing;
1688
- $this->mapping['term_id'][ $original_id ] = $existing;
1689
- return false;
1690
- }
1691
-
1692
- // WP really likes to repeat itself in export files
1693
- if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
1694
- return false;
1695
- }
1696
-
1697
- $termdata = array();
1698
- $allowed = array(
1699
- 'slug' => true,
1700
- 'description' => true,
1701
- );
1702
-
1703
- // Map the parent comment, or mark it as one we need to fix
1704
- // TODO: add parent mapping and remapping
1705
- /*
1706
- $requires_remapping = false;
1707
- if ( $parent_id ) {
1708
- if ( isset( $this->mapping['term'][ $parent_id ] ) ) {
1709
- $data['parent'] = $this->mapping['term'][ $parent_id ];
1710
- } else {
1711
- // Prepare for remapping later
1712
- $meta[] = array( 'key' => '_wxr_import_parent', 'value' => $parent_id );
1713
- $requires_remapping = true;
1714
-
1715
- // Wipe the parent for now
1716
- $data['parent'] = 0;
1717
- }
1718
- }*/
1719
-
1720
- foreach ( $data as $key => $value ) {
1721
- if ( ! isset( $allowed[ $key ] ) ) {
1722
- continue;
1723
- }
1724
-
1725
- $termdata[ $key ] = $data[ $key ];
1726
- }
1727
-
1728
- $result = wp_insert_term( $data['name'], $data['taxonomy'], $termdata );
1729
- if ( is_wp_error( $result ) ) {
1730
- $this->logger->warning( sprintf(
1731
- __( 'Failed to import %1$s %2$s', 'wordpress-importer' ),
1732
- $data['taxonomy'],
1733
- $data['name']
1734
- ) );
1735
- $this->logger->debug( $result->get_error_message() );
1736
- do_action( 'wp_import_insert_term_failed', $result, $data );
1737
-
1738
- /**
1739
- * Term processing failed.
1740
- *
1741
- * @param WP_Error $result Error object.
1742
- * @param array $data Raw data imported for the term.
1743
- * @param array $meta Meta data supplied for the term.
1744
- */
1745
- do_action( 'wxr_importer.process_failed.term', $result, $data, $meta );
1746
- return false;
1747
- }
1748
-
1749
- $term_id = $result['term_id'];
1750
-
1751
- $this->mapping['term'][ $mapping_key ] = $term_id;
1752
- $this->mapping['term_id'][ $original_id ] = $term_id;
1753
-
1754
- $this->logger->info( sprintf(
1755
- __( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
1756
- $data['name'],
1757
- $data['taxonomy']
1758
- ) );
1759
- $this->logger->debug( sprintf(
1760
- __( 'Term %1$d remapped to %2$d', 'wordpress-importer' ),
1761
- $original_id,
1762
- $term_id
1763
- ) );
1764
-
1765
- do_action( 'wp_import_insert_term', $term_id, $data );
1766
-
1767
- /**
1768
- * Term processing completed.
1769
- *
1770
- * @param int $term_id New term ID.
1771
- * @param array $data Raw data imported for the term.
1772
- */
1773
- do_action( 'wxr_importer.processed.term', $term_id, $data );
1774
- }
1775
-
1776
- /**
1777
- * Attempt to download a remote file attachment
1778
- *
1779
- * @param string $url URL of item to fetch
1780
- * @param array $post Attachment details
1781
- * @return array|WP_Error Local file location details on success, WP_Error otherwise
1782
- */
1783
- protected function fetch_remote_file( $url, $post ) {
1784
- // extract the file name and extension from the url
1785
- $file_name = basename( $url );
1786
-
1787
- // get placeholder file in the upload dir with a unique, sanitized filename
1788
- $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1789
- if ( $upload['error'] ) {
1790
- return new WP_Error( 'upload_dir_error', $upload['error'] );
1791
- }
1792
-
1793
- // fetch the remote url and write it to the placeholder file
1794
- $response = wp_remote_get( $url, array(
1795
- 'stream' => true,
1796
- 'filename' => $upload['file'],
1797
- ) );
1798
-
1799
- // request failed
1800
- if ( is_wp_error( $response ) ) {
1801
- unlink( $upload['file'] );
1802
- return $response;
1803
- }
1804
-
1805
- $code = (int) wp_remote_retrieve_response_code( $response );
1806
-
1807
- // make sure the fetch was successful
1808
- if ( $code !== 200 ) {
1809
- unlink( $upload['file'] );
1810
- return new WP_Error(
1811
- 'import_file_error',
1812
- sprintf(
1813
- __( 'Remote server returned %1$d %2$s for %3$s', 'wordpress-importer' ),
1814
- $code,
1815
- get_status_header_desc( $code ),
1816
- $url
1817
- )
1818
- );
1819
- }
1820
-
1821
- $filesize = filesize( $upload['file'] );
1822
- $headers = wp_remote_retrieve_headers( $response );
1823
-
1824
- if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
1825
- unlink( $upload['file'] );
1826
- return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'wordpress-importer' ) );
1827
- }
1828
-
1829
- if ( 0 === $filesize ) {
1830
- unlink( $upload['file'] );
1831
- return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) );
1832
- }
1833
-
1834
- $max_size = (int) $this->max_attachment_size();
1835
- if ( ! empty( $max_size ) && $filesize > $max_size ) {
1836
- unlink( $upload['file'] );
1837
- $message = sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) );
1838
- return new WP_Error( 'import_file_error', $message );
1839
- }
1840
-
1841
- return $upload;
1842
- }
1843
-
1844
- protected function post_process() {
1845
- // Time to tackle any left-over bits
1846
- if ( ! empty( $this->requires_remapping['post'] ) ) {
1847
- $this->post_process_posts( $this->requires_remapping['post'] );
1848
- }
1849
- if ( ! empty( $this->requires_remapping['comment'] ) ) {
1850
- $this->post_process_comments( $this->requires_remapping['comment'] );
1851
- }
1852
- }
1853
-
1854
- protected function post_process_posts( $todo ) {
1855
- foreach ( $todo as $post_id => $_ ) {
1856
- $this->logger->debug( sprintf(
1857
- // Note: title intentionally not used to skip extra processing
1858
- // for when debug logging is off
1859
- __( 'Running post-processing for post %d', 'wordpress-importer' ),
1860
- $post_id
1861
- ) );
1862
-
1863
- $data = array();
1864
-
1865
- $parent_id = get_post_meta( $post_id, '_wxr_import_parent', true );
1866
- if ( ! empty( $parent_id ) ) {
1867
- // Have we imported the parent now?
1868
- if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
1869
- $data['post_parent'] = $this->mapping['post'][ $parent_id ];
1870
- } else {
1871
- $this->logger->warning( sprintf(
1872
- __( 'Could not find the post parent for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1873
- get_the_title( $post_id ),
1874
- $post_id
1875
- ) );
1876
- $this->logger->debug( sprintf(
1877
- __( 'Post %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
1878
- $post_id,
1879
- $parent_id
1880
- ) );
1881
- }
1882
- }
1883
-
1884
- $author_slug = get_post_meta( $post_id, '_wxr_import_user_slug', true );
1885
- if ( ! empty( $author_slug ) ) {
1886
- // Have we imported the user now?
1887
- if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
1888
- $data['post_author'] = $this->mapping['user_slug'][ $author_slug ];
1889
- } else {
1890
- $this->logger->warning( sprintf(
1891
- __( 'Could not find the author for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1892
- get_the_title( $post_id ),
1893
- $post_id
1894
- ) );
1895
- $this->logger->debug( sprintf(
1896
- __( 'Post %1$d was imported with author "%2$s", but could not be found', 'wordpress-importer' ),
1897
- $post_id,
1898
- $author_slug
1899
- ) );
1900
- }
1901
- }
1902
-
1903
- $has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
1904
- if ( ! empty( $has_attachments ) ) {
1905
- $post = get_post( $post_id );
1906
- $content = $post->post_content;
1907
-
1908
- // Replace all the URLs we've got
1909
- $new_content = str_replace( array_keys( $this->url_remap ), $this->url_remap, $content );
1910
- if ( $new_content !== $content ) {
1911
- $data['post_content'] = $new_content;
1912
- }
1913
- }
1914
-
1915
- if ( get_post_type( $post_id ) === 'nav_menu_item' ) {
1916
- $this->post_process_menu_item( $post_id );
1917
- }
1918
-
1919
- // Do we have updates to make?
1920
- if ( empty( $data ) ) {
1921
- $this->logger->debug( sprintf(
1922
- __( 'Post %d was marked for post-processing, but none was required.', 'wordpress-importer' ),
1923
- $post_id
1924
- ) );
1925
- continue;
1926
- }
1927
-
1928
- // Run the update
1929
- $data['ID'] = $post_id;
1930
- $result = wp_update_post( $data, true );
1931
- if ( is_wp_error( $result ) ) {
1932
- $this->logger->warning( sprintf(
1933
- __( 'Could not update "%1$s" (post #%2$d) with mapped data', 'wordpress-importer' ),
1934
- get_the_title( $post_id ),
1935
- $post_id
1936
- ) );
1937
- $this->logger->debug( $result->get_error_message() );
1938
- continue;
1939
- }
1940
-
1941
- // Clear out our temporary meta keys
1942
- delete_post_meta( $post_id, '_wxr_import_parent' );
1943
- delete_post_meta( $post_id, '_wxr_import_user_slug' );
1944
- delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
1945
- }// End foreach().
1946
- }
1947
-
1948
- protected function post_process_menu_item( $post_id ) {
1949
- $menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
1950
- if ( empty( $menu_object_id ) ) {
1951
- // No processing needed!
1952
- return;
1953
- }
1954
-
1955
- $menu_item_type = get_post_meta( $post_id, '_menu_item_type', true );
1956
- switch ( $menu_item_type ) {
1957
- case 'taxonomy':
1958
- if ( isset( $this->mapping['term_id'][ $menu_object_id ] ) ) {
1959
- $menu_object = $this->mapping['term_id'][ $menu_object_id ];
1960
- }
1961
- break;
1962
-
1963
- case 'post_type':
1964
- if ( isset( $this->mapping['post'][ $menu_object_id ] ) ) {
1965
- $menu_object = $this->mapping['post'][ $menu_object_id ];
1966
- }
1967
- break;
1968
-
1969
- default:
1970
- // Cannot handle this.
1971
- return;
1972
- }
1973
-
1974
- if ( ! empty( $menu_object ) ) {
1975
- update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
1976
- } else {
1977
- $this->logger->warning( sprintf(
1978
- __( 'Could not find the menu object for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1979
- get_the_title( $post_id ),
1980
- $post_id
1981
- ) );
1982
- $this->logger->debug( sprintf(
1983
- __( 'Post %1$d was imported with object "%2$d" of type "%3$s", but could not be found', 'wordpress-importer' ),
1984
- $post_id,
1985
- $menu_object_id,
1986
- $menu_item_type
1987
- ) );
1988
- }
1989
-
1990
- delete_post_meta( $post_id, '_wxr_import_menu_item' );
1991
- }
1992
-
1993
-
1994
- protected function post_process_comments( $todo ) {
1995
- foreach ( $todo as $comment_id => $_ ) {
1996
- $data = array();
1997
-
1998
- $parent_id = get_comment_meta( $comment_id, '_wxr_import_parent', true );
1999
- if ( ! empty( $parent_id ) ) {
2000
- // Have we imported the parent now?
2001
- if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
2002
- $data['comment_parent'] = $this->mapping['comment'][ $parent_id ];
2003
- } else {
2004
- $this->logger->warning( sprintf(
2005
- __( 'Could not find the comment parent for comment #%d', 'wordpress-importer' ),
2006
- $comment_id
2007
- ) );
2008
- $this->logger->debug( sprintf(
2009
- __( 'Comment %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
2010
- $comment_id,
2011
- $parent_id
2012
- ) );
2013
- }
2014
- }
2015
-
2016
- $author_id = get_comment_meta( $comment_id, '_wxr_import_user', true );
2017
- if ( ! empty( $author_id ) ) {
2018
- // Have we imported the user now?
2019
- if ( isset( $this->mapping['user'][ $author_id ] ) ) {
2020
- $data['user_id'] = $this->mapping['user'][ $author_id ];
2021
- } else {
2022
- $this->logger->warning( sprintf(
2023
- __( 'Could not find the author for comment #%d', 'wordpress-importer' ),
2024
- $comment_id
2025
- ) );
2026
- $this->logger->debug( sprintf(
2027
- __( 'Comment %1$d was imported with author %2$d, but could not be found', 'wordpress-importer' ),
2028
- $comment_id,
2029
- $author_id
2030
- ) );
2031
- }
2032
- }
2033
-
2034
- // Do we have updates to make?
2035
- if ( empty( $data ) ) {
2036
- continue;
2037
- }
2038
-
2039
- // Run the update
2040
- $data['comment_ID'] = $comment_ID;
2041
- $result = wp_update_comment( wp_slash( $data ) );
2042
- if ( empty( $result ) ) {
2043
- $this->logger->warning( sprintf(
2044
- __( 'Could not update comment #%d with mapped data', 'wordpress-importer' ),
2045
- $comment_id
2046
- ) );
2047
- continue;
2048
- }
2049
-
2050
- // Clear out our temporary meta keys
2051
- delete_comment_meta( $comment_id, '_wxr_import_parent' );
2052
- delete_comment_meta( $comment_id, '_wxr_import_user' );
2053
- }// End foreach().
2054
- }
2055
-
2056
- /**
2057
- * Use stored mapping information to update old attachment URLs
2058
- */
2059
- protected function replace_attachment_urls_in_content() {
2060
- global $wpdb;
2061
- // make sure we do the longest urls first, in case one is a substring of another
2062
- uksort( $this->url_remap, array( $this, 'cmpr_strlen' ) );
2063
-
2064
- foreach ( $this->url_remap as $from_url => $to_url ) {
2065
- // remap urls in post_content
2066
- $query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url );
2067
- $wpdb->query( $query );
2068
-
2069
- // remap enclosure urls
2070
- $query = $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url );
2071
- $result = $wpdb->query( $query );
2072
- }
2073
- }
2074
-
2075
- /**
2076
- * Update _thumbnail_id meta to new, imported attachment IDs
2077
- */
2078
- function remap_featured_images() {
2079
- // cycle through posts that have a featured image
2080
- foreach ( $this->featured_images as $post_id => $value ) {
2081
- if ( isset( $this->processed_posts[ $value ] ) ) {
2082
- $new_id = $this->processed_posts[ $value ];
2083
-
2084
- // only update if there's a difference
2085
- if ( $new_id !== $value ) {
2086
- update_post_meta( $post_id, '_thumbnail_id', $new_id );
2087
- }
2088
- }
2089
- }
2090
- }
2091
-
2092
- /**
2093
- * Decide if the given meta key maps to information we will want to import
2094
- *
2095
- * @param string $key The meta key to check
2096
- * @return string|bool The key if we do want to import, false if not
2097
- */
2098
- public function is_valid_meta_key( $key ) {
2099
- // skip attachment metadata since we'll regenerate it from scratch
2100
- // skip _edit_lock as not relevant for import
2101
- if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) {
2102
- return false;
2103
- }
2104
-
2105
- return $key;
2106
- }
2107
-
2108
- /**
2109
- * Decide what the maximum file size for downloaded attachments is.
2110
- * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
2111
- *
2112
- * @return int Maximum attachment file size to import
2113
- */
2114
- protected function max_attachment_size() {
2115
- return apply_filters( 'import_attachment_size_limit', 0 );
2116
- }
2117
-
2118
- /**
2119
- * Added to http_request_timeout filter to force timeout at 60 seconds during import
2120
- *
2121
- * @access protected
2122
- * @return int 60
2123
- */
2124
- function bump_request_timeout( $val ) {
2125
- return 60;
2126
- }
2127
-
2128
- // return the difference in length between two strings
2129
- function cmpr_strlen( $a, $b ) {
2130
- return strlen( $b ) - strlen( $a );
2131
- }
2132
-
2133
- /**
2134
- * Prefill existing post data.
2135
- *
2136
- * This preloads all GUIDs into memory, allowing us to avoid hitting the
2137
- * database when we need to check for existence. With larger imports, this
2138
- * becomes prohibitively slow to perform SELECT queries on each.
2139
- *
2140
- * By preloading all this data into memory, it's a constant-time lookup in
2141
- * PHP instead. However, this does use a lot more memory, so for sites doing
2142
- * small imports onto a large site, it may be a better tradeoff to use
2143
- * on-the-fly checking instead.
2144
- */
2145
- protected function prefill_existing_posts() {
2146
- global $wpdb;
2147
- $posts = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts}" );
2148
-
2149
- foreach ( $posts as $item ) {
2150
- $this->exists['post'][ $item->guid ] = $item->ID;
2151
- }
2152
- }
2153
-
2154
- /**
2155
- * Does the post exist?
2156
- *
2157
- * @param array $data Post data to check against.
2158
- * @return int|bool Existing post ID if it exists, false otherwise.
2159
- */
2160
- protected function post_exists( $data ) {
2161
- // Constant-time lookup if we prefilled
2162
- $exists_key = $data['guid'];
2163
-
2164
- if ( $this->options['prefill_existing_posts'] ) {
2165
- return isset( $this->exists['post'][ $exists_key ] ) ? $this->exists['post'][ $exists_key ] : false;
2166
- }
2167
-
2168
- // No prefilling, but might have already handled it
2169
- if ( isset( $this->exists['post'][ $exists_key ] ) ) {
2170
- return $this->exists['post'][ $exists_key ];
2171
- }
2172
-
2173
- // Still nothing, try post_exists, and cache it
2174
- $exists = post_exists( $data['post_title'], $data['post_content'], $data['post_date'] );
2175
- $this->exists['post'][ $exists_key ] = $exists;
2176
-
2177
- return $exists;
2178
- }
2179
-
2180
- /**
2181
- * Mark the post as existing.
2182
- *
2183
- * @param array $data Post data to mark as existing.
2184
- * @param int $post_id Post ID.
2185
- */
2186
- protected function mark_post_exists( $data, $post_id ) {
2187
- $exists_key = $data['guid'];
2188
- $this->exists['post'][ $exists_key ] = $post_id;
2189
- }
2190
-
2191
- /**
2192
- * Prefill existing comment data.
2193
- *
2194
- * @see self::prefill_existing_posts() for justification of why this exists.
2195
- */
2196
- protected function prefill_existing_comments() {
2197
- global $wpdb;
2198
- $posts = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_date FROM {$wpdb->comments}" );
2199
-
2200
- foreach ( $posts as $item ) {
2201
- $exists_key = sha1( $item->comment_author . ':' . $item->comment_date );
2202
- $this->exists['comment'][ $exists_key ] = $item->comment_ID;
2203
- }
2204
- }
2205
-
2206
- /**
2207
- * Does the comment exist?
2208
- *
2209
- * @param array $data Comment data to check against.
2210
- * @return int|bool Existing comment ID if it exists, false otherwise.
2211
- */
2212
- protected function comment_exists( $data ) {
2213
- $exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
2214
-
2215
- // Constant-time lookup if we prefilled
2216
- if ( $this->options['prefill_existing_comments'] ) {
2217
- return isset( $this->exists['comment'][ $exists_key ] ) ? $this->exists['comment'][ $exists_key ] : false;
2218
- }
2219
-
2220
- // No prefilling, but might have already handled it
2221
- if ( isset( $this->exists['comment'][ $exists_key ] ) ) {
2222
- return $this->exists['comment'][ $exists_key ];
2223
- }
2224
-
2225
- // Still nothing, try comment_exists, and cache it
2226
- $exists = comment_exists( $data['comment_author'], $data['comment_date'] );
2227
- $this->exists['comment'][ $exists_key ] = $exists;
2228
-
2229
- return $exists;
2230
- }
2231
-
2232
- /**
2233
- * Mark the comment as existing.
2234
- *
2235
- * @param array $data Comment data to mark as existing.
2236
- * @param int $comment_id Comment ID.
2237
- */
2238
- protected function mark_comment_exists( $data, $comment_id ) {
2239
- $exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
2240
- $this->exists['comment'][ $exists_key ] = $comment_id;
2241
- }
2242
-
2243
- /**
2244
- * Prefill existing term data.
2245
- *
2246
- * @see self::prefill_existing_posts() for justification of why this exists.
2247
- */
2248
- protected function prefill_existing_terms() {
2249
- global $wpdb;
2250
- $query = "SELECT t.term_id, tt.taxonomy, t.slug FROM {$wpdb->terms} AS t";
2251
- $query .= " JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id";
2252
- $terms = $wpdb->get_results( $query );
2253
-
2254
- foreach ( $terms as $item ) {
2255
- $exists_key = sha1( $item->taxonomy . ':' . $item->slug );
2256
- $this->exists['term'][ $exists_key ] = $item->term_id;
2257
- }
2258
- }
2259
-
2260
- /**
2261
- * Does the term exist?
2262
- *
2263
- * @param array $data Term data to check against.
2264
- * @return int|bool Existing term ID if it exists, false otherwise.
2265
- */
2266
- protected function term_exists( $data ) {
2267
- $exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
2268
-
2269
- // Constant-time lookup if we prefilled
2270
- if ( $this->options['prefill_existing_terms'] ) {
2271
- return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
2272
- }
2273
-
2274
- // No prefilling, but might have already handled it
2275
- if ( isset( $this->exists['term'][ $exists_key ] ) ) {
2276
- return $this->exists['term'][ $exists_key ];
2277
- }
2278
-
2279
- // Still nothing, try comment_exists, and cache it
2280
- $exists = term_exists( $data['slug'], $data['taxonomy'] );
2281
- if ( is_array( $exists ) ) {
2282
- $exists = $exists['term_id'];
2283
- }
2284
-
2285
- $this->exists['term'][ $exists_key ] = $exists;
2286
-
2287
- return $exists;
2288
- }
2289
-
2290
- /**
2291
- * Mark the term as existing.
2292
- *
2293
- * @param array $data Term data to mark as existing.
2294
- * @param int $term_id Term ID.
2295
- */
2296
- protected function mark_term_exists( $data, $term_id ) {
2297
- $exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
2298
- $this->exists['term'][ $exists_key ] = $term_id;
2299
- }
2300
- }
2301
  endif;
1
+ <?php
2
+
3
+ if( ! class_exists( 'WXR_Importer' ) && class_exists( 'WP_Importer' ) ) :
4
+ class WXR_Importer extends WP_Importer {
5
+ /**
6
+ * Maximum supported WXR version
7
+ */
8
+ const MAX_WXR_VERSION = 1.2;
9
+
10
+ /**
11
+ * Regular expression for checking if a post references an attachment
12
+ *
13
+ * Note: This is a quick, weak check just to exclude text-only posts. More
14
+ * vigorous checking is done later to verify.
15
+ */
16
+ const REGEX_HAS_ATTACHMENT_REFS = '!
17
+ (
18
+ # Match anything with an image or attachment class
19
+ class=[\'"].*?\b(wp-image-\d+|attachment-[\w\-]+)\b
20
+ |
21
+ # Match anything that looks like an upload URL
22
+ src=[\'"][^\'"]*(
23
+ [0-9]{4}/[0-9]{2}/[^\'"]+\.(jpg|jpeg|png|gif)
24
+ |
25
+ content/uploads[^\'"]+
26
+ )[\'"]
27
+ )!ix';
28
+
29
+ /**
30
+ * Version of WXR we're importing.
31
+ *
32
+ * Defaults to 1.0 for compatibility. Typically overridden by a
33
+ * `<wp:wxr_version>` tag at the start of the file.
34
+ *
35
+ * @var string
36
+ */
37
+ protected $version = '1.0';
38
+
39
+ // information to import from WXR file
40
+ protected $categories = array();
41
+ protected $tags = array();
42
+ protected $base_url = '';
43
+
44
+ // TODO: REMOVE THESE
45
+ protected $processed_terms = array();
46
+ protected $processed_posts = array();
47
+ protected $processed_menu_items = array();
48
+ protected $menu_item_orphans = array();
49
+ protected $missing_menu_items = array();
50
+
51
+ // NEW STYLE
52
+ protected $mapping = array();
53
+ protected $requires_remapping = array();
54
+ protected $exists = array();
55
+ protected $user_slug_override = array();
56
+
57
+ protected $url_remap = array();
58
+ protected $featured_images = array();
59
+
60
+ /**
61
+ * Logger instance.
62
+ *
63
+ * @var WP_Importer_Logger
64
+ */
65
+ protected $logger;
66
+
67
+ /**
68
+ * Constructor
69
+ *
70
+ * @param array $options {
71
+ * @var bool $prefill_existing_posts Should we prefill `post_exists` calls? (True prefills and uses more memory, false checks once per imported post and takes longer. Default is true.)
72
+ * @var bool $prefill_existing_comments Should we prefill `comment_exists` calls? (True prefills and uses more memory, false checks once per imported comment and takes longer. Default is true.)
73
+ * @var bool $prefill_existing_terms Should we prefill `term_exists` calls? (True prefills and uses more memory, false checks once per imported term and takes longer. Default is true.)
74
+ * @var bool $update_attachment_guids Should attachment GUIDs be updated to the new URL? (True updates the GUID, which keeps compatibility with v1, false doesn't update, and allows deduplication and reimporting. Default is false.)
75
+ * @var bool $fetch_attachments Fetch attachments from the remote server. (True fetches and creates attachment posts, false skips attachments. Default is false.)
76
+ * @var bool $aggressive_url_search Should we search/replace for URLs aggressively? (True searches all posts' content for old URLs and replaces, false checks for `<img class="wp-image-*">` only. Default is false.)
77
+ * @var int $default_author User ID to use if author is missing or invalid. (Default is null, which leaves posts unassigned.)
78
+ * }
79
+ */
80
+ public function __construct( $options = array() ) {
81
+ // Initialize some important variables
82
+ $empty_types = array(
83
+ 'post' => array(),
84
+ 'comment' => array(),
85
+ 'term' => array(),
86
+ 'user' => array(),
87
+ );
88
+
89
+ $this->mapping = $empty_types;
90
+ $this->mapping['user_slug'] = array();
91
+ $this->mapping['term_id'] = array();
92
+ $this->requires_remapping = $empty_types;
93
+ $this->exists = $empty_types;
94
+
95
+ $this->options = wp_parse_args( $options, array(
96
+ 'prefill_existing_posts' => true,
97
+ 'prefill_existing_comments' => true,
98
+ 'prefill_existing_terms' => true,
99
+ 'update_attachment_guids' => false,
100
+ 'fetch_attachments' => false,
101
+ 'aggressive_url_search' => false,
102
+ 'default_author' => null,
103
+ ) );
104
+ }
105
+
106
+ public function set_logger( $logger ) {
107
+ $this->logger = $logger;
108
+ }
109
+
110
+ /**
111
+ * Get a stream reader for the file.
112
+ *
113
+ * @param string $file Path to the XML file.
114
+ * @return XMLReader|WP_Error Reader instance on success, error otherwise.
115
+ */
116
+ protected function get_reader( $file ) {
117
+ // Avoid loading external entities for security
118
+ $old_value = null;
119
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
120
+ // $old_value = libxml_disable_entity_loader( true );
121
+ }
122
+
123
+ $reader = new XMLReader();
124
+ $status = $reader->open( $file );
125
+
126
+ if ( ! is_null( $old_value ) ) {
127
+ // libxml_disable_entity_loader( $old_value );
128
+ }
129
+
130
+ if ( ! $status ) {
131
+ return new WP_Error( 'wxr_importer.cannot_parse', __( 'Could not open the file for parsing', 'wordpress-importer' ) );
132
+ }
133
+
134
+ return $reader;
135
+ }
136
+
137
+ /**
138
+ * The main controller for the actual import stage.
139
+ *
140
+ * @param string $file Path to the WXR file for importing
141
+ */
142
+ public function get_preliminary_information( $file ) {
143
+ // Let's run the actual importer now, woot
144
+ $reader = $this->get_reader( $file );
145
+ if ( is_wp_error( $reader ) ) {
146
+ return $reader;
147
+ }
148
+
149
+ // Set the version to compatibility mode first
150
+ $this->version = '1.0';
151
+
152
+ // Start parsing!
153
+ $data = new WXR_Import_Info();
154
+ while ( $reader->read() ) {
155
+ // Only deal with element opens
156
+ if ( $reader->nodeType !== XMLReader::ELEMENT ) {
157
+ continue;
158
+ }
159
+
160
+ switch ( $reader->name ) {
161
+ case 'wp:wxr_version':
162
+ // Upgrade to the correct version
163
+ $this->version = $reader->readString();
164
+
165
+ if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
166
+ $this->logger->warning( sprintf(
167
+ __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
168
+ $this->version,
169
+ self::MAX_WXR_VERSION
170
+ ) );
171
+ }
172
+
173
+ // Handled everything in this node, move on to the next
174
+ $reader->next();
175
+ break;
176
+
177
+ case 'generator':
178
+ $data->generator = $reader->readString();
179
+ $reader->next();
180
+ break;
181
+
182
+ case 'title':
183
+ $data->title = $reader->readString();
184
+ $reader->next();
185
+ break;
186
+
187
+ case 'wp:base_site_url':
188
+ $data->siteurl = $reader->readString();
189
+ $reader->next();
190
+ break;
191
+
192
+ case 'wp:base_blog_url':
193
+ $data->home = $reader->readString();
194
+ $reader->next();
195
+ break;
196
+
197
+ case 'wp:author':
198
+ $node = $reader->expand();
199
+
200
+ $parsed = $this->parse_author_node( $node );
201
+ if ( is_wp_error( $parsed ) ) {
202
+ $this->log_error( $parsed );
203
+
204
+ // Skip the rest of this post
205
+ $reader->next();
206
+ break;
207
+ }
208
+
209
+ $data->users[] = $parsed;
210
+
211
+ // Handled everything in this node, move on to the next
212
+ $reader->next();
213
+ break;
214
+
215
+ case 'item':
216
+ $node = $reader->expand();
217
+ $parsed = $this->parse_post_node( $node );
218
+ if ( is_wp_error( $parsed ) ) {
219
+ $this->log_error( $parsed );
220
+
221
+ // Skip the rest of this post
222
+ $reader->next();
223
+ break;
224
+ }
225
+
226
+ if ( $parsed['data']['post_type'] === 'attachment' ) {
227
+ $data->media_count++;
228
+ } else {
229
+ $data->post_count++;
230
+ }
231
+ $data->comment_count += count( $parsed['comments'] );
232
+
233
+ // Handled everything in this node, move on to the next
234
+ $reader->next();
235
+ break;
236
+
237
+ case 'wp:category':
238
+ case 'wp:tag':
239
+ case 'wp:term':
240
+ $data->term_count++;
241
+
242
+ // Handled everything in this node, move on to the next
243
+ $reader->next();
244
+ break;
245
+ }// End switch().
246
+ }// End while().
247
+
248
+ $data->version = $this->version;
249
+
250
+ return $data;
251
+ }
252
+
253
+ /**
254
+ * The main controller for the actual import stage.
255
+ *
256
+ * @param string $file Path to the WXR file for importing
257
+ */
258
+ public function parse_authors( $file ) {
259
+ // Let's run the actual importer now, woot
260
+ $reader = $this->get_reader( $file );
261
+ if ( is_wp_error( $reader ) ) {
262
+ return $reader;
263
+ }
264
+
265
+ // Set the version to compatibility mode first
266
+ $this->version = '1.0';
267
+
268
+ // Start parsing!
269
+ $authors = array();
270
+ while ( $reader->read() ) {
271
+ // Only deal with element opens
272
+ if ( $reader->nodeType !== XMLReader::ELEMENT ) {
273
+ continue;
274
+ }
275
+
276
+ switch ( $reader->name ) {
277
+ case 'wp:wxr_version':
278
+ // Upgrade to the correct version
279
+ $this->version = $reader->readString();
280
+
281
+ if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
282
+ $this->logger->warning( sprintf(
283
+ __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
284
+ $this->version,
285
+ self::MAX_WXR_VERSION
286
+ ) );
287
+ }
288
+
289
+ // Handled everything in this node, move on to the next
290
+ $reader->next();
291
+ break;
292
+
293
+ case 'wp:author':
294
+ $node = $reader->expand();
295
+
296
+ $parsed = $this->parse_author_node( $node );
297
+ if ( is_wp_error( $parsed ) ) {
298
+ $this->log_error( $parsed );
299
+
300
+ // Skip the rest of this post
301
+ $reader->next();
302
+ break;
303
+ }
304
+
305
+ $authors[] = $parsed;
306
+
307
+ // Handled everything in this node, move on to the next
308
+ $reader->next();
309
+ break;
310
+ }
311
+ }// End while().
312
+
313
+ return $authors;
314
+ }
315
+
316
+ /**
317
+ * The main controller for the actual import stage.
318
+ *
319
+ * @param string $file Path to the WXR file for importing
320
+ */
321
+ public function import( $file ) {
322
+ add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
323
+ add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
324
+
325
+ $result = $this->import_start( $file );
326
+ if ( is_wp_error( $result ) ) {
327
+ return $result;
328
+ }
329
+
330
+ // Let's run the actual importer now, woot
331
+ $reader = $this->get_reader( $file );
332
+ if ( is_wp_error( $reader ) ) {
333
+ return $reader;
334
+ }
335
+
336
+ // Set the version to compatibility mode first
337
+ $this->version = '1.0';
338
+
339
+ // Reset other variables
340
+ $this->base_url = '';
341
+
342
+ // Start parsing!
343
+ while ( $reader->read() ) {
344
+ // Only deal with element opens
345
+ if ( $reader->nodeType !== XMLReader::ELEMENT ) {
346
+ continue;
347
+ }
348
+
349
+ switch ( $reader->name ) {
350
+ case 'wp:wxr_version':
351
+ // Upgrade to the correct version
352
+ $this->version = $reader->readString();
353
+
354
+ if ( version_compare( $this->version, self::MAX_WXR_VERSION, '>' ) ) {
355
+ $this->logger->warning( sprintf(
356
+ __( 'This WXR file (version %1$s) is newer than the importer (version %2$s) and may not be supported. Please consider updating.', 'wordpress-importer' ),
357
+ $this->version,
358
+ self::MAX_WXR_VERSION
359
+ ) );
360
+ }
361
+
362
+ // Handled everything in this node, move on to the next
363
+ $reader->next();
364
+ break;
365
+
366
+ case 'wp:base_site_url':
367
+ $this->base_url = $reader->readString();
368
+
369
+ // Handled everything in this node, move on to the next
370
+ $reader->next();
371
+ break;
372
+
373
+ case 'item':
374
+ $node = $reader->expand();
375
+ $parsed = $this->parse_post_node( $node );
376
+ if ( is_wp_error( $parsed ) ) {
377
+ $this->log_error( $parsed );
378
+
379
+ // Skip the rest of this post
380
+ $reader->next();
381
+ break;
382
+ }
383
+
384
+ $this->process_post( $parsed['data'], $parsed['meta'], $parsed['comments'], $parsed['terms'] );
385
+
386
+ // Handled everything in this node, move on to the next
387
+ $reader->next();
388
+ break;
389
+
390
+ case 'wp:author':
391
+ $node = $reader->expand();
392
+
393
+ $parsed = $this->parse_author_node( $node );
394
+ if ( is_wp_error( $parsed ) ) {
395
+ $this->log_error( $parsed );
396
+
397
+ // Skip the rest of this post
398
+ $reader->next();
399
+ break;
400
+ }
401
+
402
+ $status = $this->process_author( $parsed['data'], $parsed['meta'] );
403
+ if ( is_wp_error( $status ) ) {
404
+ $this->log_error( $status );
405
+ }
406
+
407
+ // Handled everything in this node, move on to the next
408
+ $reader->next();
409
+ break;
410
+
411
+ case 'wp:category':
412
+ $node = $reader->expand();
413
+
414
+ $parsed = $this->parse_term_node( $node, 'category' );
415
+ if ( is_wp_error( $parsed ) ) {
416
+ $this->log_error( $parsed );
417
+
418
+ // Skip the rest of this post
419
+ $reader->next();
420
+ break;
421
+ }
422
+
423
+ $status = $this->process_term( $parsed['data'], $parsed['meta'] );
424
+
425
+ // Handled everything in this node, move on to the next
426
+ $reader->next();
427
+ break;
428
+
429
+ case 'wp:tag':
430
+ $node = $reader->expand();
431
+
432
+ $parsed = $this->parse_term_node( $node, 'tag' );
433
+ if ( is_wp_error( $parsed ) ) {
434
+ $this->log_error( $parsed );
435
+
436
+ // Skip the rest of this post
437
+ $reader->next();
438
+ break;
439
+ }
440
+
441
+ $status = $this->process_term( $parsed['data'], $parsed['meta'] );
442
+
443
+ // Handled everything in this node, move on to the next
444
+ $reader->next();
445
+ break;
446
+
447
+ case 'wp:term':
448
+ $node = $reader->expand();
449
+
450
+ $parsed = $this->parse_term_node( $node );
451
+ if ( is_wp_error( $parsed ) ) {
452
+ $this->log_error( $parsed );
453
+
454
+ // Skip the rest of this post
455
+ $reader->next();
456
+ break;
457
+ }
458
+
459
+ $status = $this->process_term( $parsed['data'], $parsed['meta'] );
460
+
461
+ // Handled everything in this node, move on to the next
462
+ $reader->next();
463
+ break;
464
+
465
+ default:
466
+ // Skip this node, probably handled by something already
467
+ break;
468
+ }// End switch().
469
+ }// End while().
470
+
471
+ // Now that we've done the main processing, do any required
472
+ // post-processing and remapping.
473
+ $this->post_process();
474
+
475
+ if ( $this->options['aggressive_url_search'] ) {
476
+ $this->replace_attachment_urls_in_content();
477
+ }
478
+ // $this->remap_featured_images();
479
+ $this->import_end();
480
+ }
481
+
482
+ /**
483
+ * Log an error instance to the logger.
484
+ *
485
+ * @param WP_Error $error Error instance to log.
486
+ */
487
+ protected function log_error( WP_Error $error ) {
488
+ $this->logger->warning( $error->get_error_message() );
489
+
490
+ // Log the data as debug info too
491
+ $data = $error->get_error_data();
492
+ if ( ! empty( $data ) ) {
493
+ $this->logger->debug( var_export( $data, true ) );
494
+ }
495
+ }
496
+
497
+ /**
498
+ * Parses the WXR file and prepares us for the task of processing parsed data
499
+ *
500
+ * @param string $file Path to the WXR file for importing
501
+ */
502
+ protected function import_start( $file ) {
503
+ if ( ! is_file( $file ) ) {
504
+ return new WP_Error( 'wxr_importer.file_missing', __( 'The file does not exist, please try again.', 'wordpress-importer' ) );
505
+ }
506
+
507
+ // Suspend bunches of stuff in WP core
508
+ wp_defer_term_counting( true );
509
+ wp_defer_comment_counting( true );
510
+ wp_suspend_cache_invalidation( true );
511
+
512
+ // Prefill exists calls if told to
513
+ if ( $this->options['prefill_existing_posts'] ) {
514
+ $this->prefill_existing_posts();
515
+ }
516
+ if ( $this->options['prefill_existing_comments'] ) {
517
+ $this->prefill_existing_comments();
518
+ }
519
+ if ( $this->options['prefill_existing_terms'] ) {
520
+ $this->prefill_existing_terms();
521
+ }
522
+
523
+ /**
524
+ * Begin the import.
525
+ *
526
+ * Fires before the import process has begun. If you need to suspend
527
+ * caching or heavy processing on hooks, do so here.
528
+ */
529
+ do_action( 'import_start' );
530
+ }
531
+
532
+ /**
533
+ * Performs post-import cleanup of files and the cache
534
+ */
535
+ protected function import_end() {
536
+ // Re-enable stuff in core
537
+ wp_suspend_cache_invalidation( false );
538
+ wp_cache_flush();
539
+ foreach ( get_taxonomies() as $tax ) {
540
+ delete_option( "{$tax}_children" );
541
+ _get_term_hierarchy( $tax );
542
+ }
543
+
544
+ wp_defer_term_counting( false );
545
+ wp_defer_comment_counting( false );
546
+
547
+ /**
548
+ * Complete the import.
549
+ *
550
+ * Fires after the import process has finished. If you need to update
551
+ * your cache or re-enable processing, do so here.
552
+ */
553
+ do_action( 'import_end' );
554
+ }
555
+
556
+ /**
557
+ * Set the user mapping.
558
+ *
559
+ * @param array $mapping List of map arrays (containing `old_slug`, `old_id`, `new_id`)
560
+ */
561
+ public function set_user_mapping( $mapping ) {
562
+ foreach ( $mapping as $map ) {
563
+ if ( empty( $map['old_slug'] ) || empty( $map['old_id'] ) || empty( $map['new_id'] ) ) {
564
+ $this->logger->warning( __( 'Invalid author mapping', 'wordpress-importer' ) );
565
+ $this->logger->debug( var_export( $map, true ) );
566
+ continue;
567
+ }
568
+
569
+ $old_slug = $map['old_slug'];
570
+ $old_id = $map['old_id'];
571
+ $new_id = $map['new_id'];
572
+
573
+ $this->mapping['user'][ $old_id ] = $new_id;
574
+ $this->mapping['user_slug'][ $old_slug ] = $new_id;
575
+ }
576
+ }
577
+
578
+ /**
579
+ * Set the user slug overrides.
580
+ *
581
+ * Allows overriding the slug in the import with a custom/renamed version.
582
+ *
583
+ * @param string[] $overrides Map of old slug to new slug.
584
+ */
585
+ public function set_user_slug_overrides( $overrides ) {
586
+ foreach ( $overrides as $original => $renamed ) {
587
+ $this->user_slug_override[ $original ] = $renamed;
588
+ }
589
+ }
590
+
591
+ /**
592
+ * Parse a post node into post data.
593
+ *
594
+ * @param DOMElement $node Parent node of post data (typically `item`).
595
+ * @return array|WP_Error Post data array on success, error otherwise.
596
+ */
597
+ protected function parse_post_node( $node ) {
598
+ $data = array();
599
+ $meta = array();
600
+ $comments = array();
601
+ $terms = array();
602
+
603
+ foreach ( $node->childNodes as $child ) {
604
+ // We only care about child elements
605
+ if ( $child->nodeType !== XML_ELEMENT_NODE ) {
606
+ continue;
607
+ }
608
+
609
+ switch ( $child->tagName ) {
610
+ case 'wp:post_type':
611
+ $data['post_type'] = $child->textContent;
612
+ break;
613
+
614
+ case 'title':
615
+ $data['post_title'] = $child->textContent;
616
+ break;
617
+
618
+ case 'guid':
619
+ $data['guid'] = $child->textContent;
620
+ break;
621
+
622
+ case 'dc:creator':
623
+ $data['post_author'] = $child->textContent;
624
+ break;
625
+
626
+ case 'content:encoded':
627
+ $data['post_content'] = $child->textContent;
628
+ break;
629
+
630
+ case 'excerpt:encoded':
631
+ $data['post_excerpt'] = $child->textContent;
632
+ break;
633
+
634
+ case 'wp:post_id':
635
+ $data['post_id'] = $child->textContent;
636
+ break;
637
+
638
+ case 'wp:post_date':
639
+ $data['post_date'] = $child->textContent;
640
+ break;
641
+
642
+ case 'wp:post_date_gmt':
643
+ $data['post_date_gmt'] = $child->textContent;
644
+ break;
645
+
646
+ case 'wp:comment_status':
647
+ $data['comment_status'] = $child->textContent;
648
+ break;
649
+
650
+ case 'wp:ping_status':
651
+ $data['ping_status'] = $child->textContent;
652
+ break;
653
+
654
+ case 'wp:post_name':
655
+ $data['post_name'] = $child->textContent;
656
+ break;
657
+
658
+ case 'wp:status':
659
+ $data['post_status'] = $child->textContent;
660
+
661
+ if ( $data['post_status'] === 'auto-draft' ) {
662
+ // Bail now
663
+ return new WP_Error(
664
+ 'wxr_importer.post.cannot_import_draft',
665
+ __( 'Cannot import auto-draft posts' ),
666
+ $data
667
+ );
668
+ }
669
+ break;
670
+
671
+ case 'wp:post_parent':
672
+ $data['post_parent'] = $child->textContent;
673
+ break;
674
+
675
+ case 'wp:menu_order':
676
+ $data['menu_order'] = $child->textContent;
677
+ break;
678
+
679
+ case 'wp:post_password':
680
+ $data['post_password'] = $child->textContent;
681
+ break;
682
+
683
+ case 'wp:is_sticky':
684
+ $data['is_sticky'] = $child->textContent;
685
+ break;
686
+
687
+ case 'wp:attachment_url':
688
+ $data['attachment_url'] = $child->textContent;
689
+ break;
690
+
691
+ case 'wp:postmeta':
692
+ $meta_item = $this->parse_meta_node( $child );
693
+ if ( ! empty( $meta_item ) ) {
694
+ $meta[] = $meta_item;
695
+ }
696
+ break;
697
+
698
+ case 'wp:comment':
699
+ $comment_item = $this->parse_comment_node( $child );
700
+ if ( ! empty( $comment_item ) ) {
701
+ $comments[] = $comment_item;
702
+ }
703
+ break;
704
+
705
+ case 'category':
706
+ $term_item = $this->parse_category_node( $child );
707
+ if ( ! empty( $term_item ) ) {
708
+ $terms[] = $term_item;
709
+ }
710
+ break;
711
+ }// End switch().
712
+ }// End foreach().
713
+
714
+ return compact( 'data', 'meta', 'comments', 'terms' );
715
+ }
716
+
717
+ /**
718
+ * Create new posts based on import information
719
+ *
720
+ * Posts marked as having a parent which doesn't exist will become top level items.
721
+ * Doesn't create a new post if: the post type doesn't exist, the given post ID
722
+ * is already noted as imported or a post with the same title and date already exists.
723
+ * Note that new/updated terms, comments and meta are imported for the last of the above.
724
+ */
725
+ protected function process_post( $data, $meta, $comments, $terms ) {
726
+ /**
727
+ * Pre-process post data.
728
+ *
729
+ * @param array $data Post data. (Return empty to skip.)
730
+ * @param array $meta Meta data.
731
+ * @param array $comments Comments on the post.
732
+ * @param array $terms Terms on the post.
733
+ */
734
+ $data = apply_filters( 'wxr_importer.pre_process.post', $data, $meta, $comments, $terms );
735
+ if ( empty( $data ) ) {
736
+ return false;
737
+ }
738
+
739
+ $original_id = isset( $data['post_id'] ) ? (int) $data['post_id'] : 0;
740
+ $parent_id = isset( $data['post_parent'] ) ? (int) $data['post_parent'] : 0;
741
+ $author_id = isset( $data['post_author'] ) ? (int) $data['post_author'] : 0;
742
+
743
+ // Have we already processed this?
744
+ if ( isset( $this->mapping['post'][ $original_id ] ) ) {
745
+ return;
746
+ }
747
+
748
+ $post_type_object = get_post_type_object( $data['post_type'] );
749
+
750
+ // Is this type even valid?
751
+ if ( ! $post_type_object ) {
752
+ $this->logger->warning( sprintf(
753
+ __( 'Failed to import "%1$s": Invalid post type %2$s', 'wordpress-importer' ),
754
+ $data['post_title'],
755
+ $data['post_type']
756
+ ) );
757
+ return false;
758
+ }
759
+
760
+ $post_exists = $this->post_exists( $data );
761
+ if ( $post_exists ) {
762
+ $this->logger->info( sprintf(
763
+ __( '%1$s "%2$s" already exists.', 'wordpress-importer' ),
764
+ $post_type_object->labels->singular_name,
765
+ $data['post_title']
766
+ ) );
767
+
768
+ /**
769
+ * Post processing already imported.
770
+ *
771
+ * @param array $data Raw data imported for the post.
772
+ */
773
+ do_action( 'wxr_importer.process_already_imported.post', $data );
774
+
775
+ // Even though this post already exists, new comments might need importing
776
+ $this->process_comments( $comments, $original_id, $data, $post_exists );
777
+
778
+ return false;
779
+ }
780
+
781
+ // Map the parent post, or mark it as one we need to fix
782
+ $requires_remapping = false;
783
+ if ( $parent_id ) {
784
+ if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
785
+ $data['post_parent'] = $this->mapping['post'][ $parent_id ];
786
+ } else {
787
+ $meta[] = array(
788
+ 'key' => '_wxr_import_parent',
789
+ 'value' => $parent_id,
790
+ );
791
+ $requires_remapping = true;
792
+
793
+ $data['post_parent'] = 0;
794
+ }
795
+ }
796
+
797
+ // Map the author, or mark it as one we need to fix
798
+ $author = sanitize_user( $data['post_author'], true );
799
+ if ( empty( $author ) ) {
800
+ // Missing or invalid author, use default if available.
801
+ $data['post_author'] = $this->options['default_author'];
802
+ } elseif ( isset( $this->mapping['user_slug'][ $author ] ) ) {
803
+ $data['post_author'] = $this->mapping['user_slug'][ $author ];
804
+ } else {
805
+ $meta[] = array(
806
+ 'key' => '_wxr_import_user_slug',
807
+ 'value' => $author,
808
+ );
809
+ $requires_remapping = true;
810
+
811
+ $data['post_author'] = (int) get_current_user_id();
812
+ }
813
+
814
+ // Does the post look like it contains attachment images?
815
+ if ( preg_match( self::REGEX_HAS_ATTACHMENT_REFS, $data['post_content'] ) ) {
816
+ $meta[] = array(
817
+ 'key' => '_wxr_import_has_attachment_refs',
818
+ 'value' => true,
819
+ );
820
+ $requires_remapping = true;
821
+ }
822
+
823
+ // Whitelist to just the keys we allow
824
+ $postdata = array(
825
+ 'import_id' => $data['post_id'],
826
+ );
827
+ $allowed = array(
828
+ 'post_author' => true,
829
+ 'post_date' => true,
830
+ 'post_date_gmt' => true,
831
+ 'post_content' => true,
832
+ 'post_excerpt' => true,
833
+ 'post_title' => true,
834
+ 'post_status' => true,
835
+ 'post_name' => true,
836
+ 'comment_status' => true,
837
+ 'ping_status' => true,
838
+ 'guid' => true,
839
+ 'post_parent' => true,
840
+ 'menu_order' => true,
841
+ 'post_type' => true,
842
+ 'post_password' => true,
843
+ );
844
+ foreach ( $data as $key => $value ) {
845
+ if ( ! isset( $allowed[ $key ] ) ) {
846
+ continue;
847
+ }
848
+
849
+ $postdata[ $key ] = $data[ $key ];
850
+ }
851
+
852
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $data );
853
+
854
+ if ( 'attachment' === $postdata['post_type'] ) {
855
+ if ( ! $this->options['fetch_attachments'] ) {
856
+ $this->logger->notice( sprintf(
857
+ __( 'Skipping attachment "%s", fetching attachments disabled' ),
858
+ $data['post_title']
859
+ ) );
860
+ /**
861
+ * Post processing skipped.
862
+ *
863
+ * @param array $data Raw data imported for the post.
864
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
865
+ */
866
+ do_action( 'wxr_importer.process_skipped.post', $data, $meta );
867
+ return false;
868
+ }
869
+ $remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
870
+ $post_id = $this->process_attachment( $postdata, $meta, $remote_url );
871
+ } else {
872
+ $post_id = wp_insert_post( $postdata, true );
873
+ do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
874
+ }
875
+
876
+ if ( is_wp_error( $post_id ) ) {
877
+ $this->logger->error( sprintf(
878
+ __( 'Failed to import "%1$s" (%2$s)', 'wordpress-importer' ),
879
+ $data['post_title'],
880
+ $post_type_object->labels->singular_name
881
+ ) );
882
+ $this->logger->debug( $post_id->get_error_message() );
883
+
884
+ /**
885
+ * Post processing failed.
886
+ *
887
+ * @param WP_Error $post_id Error object.
888
+ * @param array $data Raw data imported for the post.
889
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
890
+ * @param array $comments Raw comment data, already processed by {@see process_comments}.
891
+ * @param array $terms Raw term data, already processed.
892
+ */
893
+ do_action( 'wxr_importer.process_failed.post', $post_id, $data, $meta, $comments, $terms );
894
+ return false;
895
+ }
896
+
897
+ // Ensure stickiness is handled correctly too
898
+ if ( $data['is_sticky'] === '1' ) {
899
+ stick_post( $post_id );
900
+ }
901
+
902
+ // map pre-import ID to local ID
903
+ $this->mapping['post'][ $original_id ] = (int) $post_id;
904
+ if ( $requires_remapping ) {
905
+ $this->requires_remapping['post'][ $post_id ] = true;
906
+ }
907
+ $this->mark_post_exists( $data, $post_id );
908
+
909
+ $this->logger->info( sprintf(
910
+ __( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
911
+ $data['post_title'],
912
+ $post_type_object->labels->singular_name
913
+ ) );
914
+ $this->logger->debug( sprintf(
915
+ __( 'Post %1$d remapped to %2$d', 'wordpress-importer' ),
916
+ $original_id,
917
+ $post_id
918
+ ) );
919
+
920
+ // Handle the terms too
921
+ $terms = apply_filters( 'wp_import_post_terms', $terms, $post_id, $data );
922
+
923
+ if ( ! empty( $terms ) ) {
924
+ $term_ids = array();
925
+ foreach ( $terms as $term ) {
926
+ $taxonomy = $term['taxonomy'];
927
+ $key = sha1( $taxonomy . ':' . $term['slug'] );
928
+
929
+ if ( isset( $this->mapping['term'][ $key ] ) ) {
930
+ $term_ids[ $taxonomy ][] = (int) $this->mapping['term'][ $key ];
931
+ } else {
932
+ $meta[] = array(
933
+ 'key' => '_wxr_import_term',
934
+ 'value' => $term,
935
+ );
936
+ $requires_remapping = true;
937
+ }
938
+ }
939
+
940
+ foreach ( $term_ids as $tax => $ids ) {
941
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
942
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $data );
943
+ }
944
+ }
945
+
946
+ $this->process_comments( $comments, $post_id, $data );
947
+ $this->process_post_meta( $meta, $post_id, $data );
948
+
949
+ if ( 'nav_menu_item' === $data['post_type'] ) {
950
+ $this->process_menu_item_meta( $post_id, $data, $meta );
951
+ }
952
+
953
+ /**
954
+ * Post processing completed.
955
+ *
956
+ * @param int $post_id New post ID.
957
+ * @param array $data Raw data imported for the post.
958
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
959
+ * @param array $comments Raw comment data, already processed by {@see process_comments}.
960
+ * @param array $terms Raw term data, already processed.
961
+ */
962
+ do_action( 'wxr_importer.processed.post', $post_id, $data, $meta, $comments, $terms );
963
+ }
964
+
965
+ /**
966
+ * Attempt to create a new menu item from import data
967
+ *
968
+ * Fails for draft, orphaned menu items and those without an associated nav_menu
969
+ * or an invalid nav_menu term. If the post type or term object which the menu item
970
+ * represents doesn't exist then the menu item will not be imported (waits until the
971
+ * end of the import to retry again before discarding).
972
+ *
973
+ * @param array $item Menu item details from WXR file
974
+ */
975
+ protected function process_menu_item_meta( $post_id, $data, $meta ) {
976
+
977
+ $item_type = get_post_meta( $post_id, '_menu_item_type', true );
978
+ $original_object_id = get_post_meta( $post_id, '_menu_item_object_id', true );
979
+ $object_id = null;
980
+
981
+ $this->logger->debug( sprintf( 'Processing menu item %s', $item_type ) );
982
+
983
+ $requires_remapping = false;
984
+ switch ( $item_type ) {
985
+ case 'taxonomy':
986
+ if ( isset( $this->mapping['term_id'][ $original_object_id ] ) ) {
987
+ $object_id = $this->mapping['term_id'][ $original_object_id ];
988
+ } else {
989
+ add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
990
+ $requires_remapping = true;
991
+ }
992
+ break;
993
+
994
+ case 'post_type':
995
+ if ( isset( $this->mapping['post'][ $original_object_id ] ) ) {
996
+ $object_id = $this->mapping['post'][ $original_object_id ];
997
+ } else {
998
+ add_post_meta( $post_id, '_wxr_import_menu_item', wp_slash( $original_object_id ) );
999
+ $requires_remapping = true;
1000
+ }
1001
+ break;
1002
+
1003
+ case 'custom':
1004
+ // Custom refers to itself, wonderfully easy.
1005
+ $object_id = $post_id;
1006
+ break;
1007
+
1008
+ default:
1009
+ // associated object is missing or not imported yet, we'll retry later
1010
+ $this->missing_menu_items[] = $item;
1011
+ $this->logger->debug( 'Unknown menu item type' );
1012
+ break;
1013
+ }
1014
+
1015
+ if ( $requires_remapping ) {
1016
+ $this->requires_remapping['post'][ $post_id ] = true;
1017
+ }
1018
+
1019
+ if ( empty( $object_id ) ) {
1020
+ // Nothing needed here.
1021
+ return;
1022
+ }
1023
+
1024
+ $this->logger->debug( sprintf( 'Menu item %d mapped to %d', $original_object_id, $object_id ) );
1025
+ update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $object_id ) );
1026
+ }
1027
+
1028
+ /**
1029
+ * If fetching attachments is enabled then attempt to create a new attachment
1030
+ *
1031
+ * @param array $post Attachment post details from WXR
1032
+ * @param string $url URL to fetch attachment from
1033
+ * @return int|WP_Error Post ID on success, WP_Error otherwise
1034
+ */
1035
+ protected function process_attachment( $post, $meta, $remote_url ) {
1036
+ // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
1037
+ // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
1038
+ $post['upload_date'] = $post['post_date'];
1039
+ foreach ( $meta as $meta_item ) {
1040
+ if ( $meta_item['key'] !== '_wp_attached_file' ) {
1041
+ continue;
1042
+ }
1043
+
1044
+ if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta_item['value'], $matches ) ) {
1045
+ $post['upload_date'] = $matches[0];
1046
+ }
1047
+ break;
1048
+ }
1049
+
1050
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1051
+ if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
1052
+ $remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
1053
+ }
1054
+
1055
+ $upload = $this->fetch_remote_file( $remote_url, $post );
1056
+ if ( is_wp_error( $upload ) ) {
1057
+ return $upload;
1058
+ }
1059
+
1060
+ $info = wp_check_filetype( $upload['file'] );
1061
+ if ( ! $info ) {
1062
+ return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'wordpress-importer' ) );
1063
+ }
1064
+
1065
+ $post['post_mime_type'] = $info['type'];
1066
+
1067
+ // WP really likes using the GUID for display. Allow updating it.
1068
+ // See https://core.trac.wordpress.org/ticket/33386
1069
+ if ( $this->options['update_attachment_guids'] ) {
1070
+ $post['guid'] = $upload['url'];
1071
+ }
1072
+
1073
+ // as per wp-admin/includes/upload.php
1074
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
1075
+ if ( is_wp_error( $post_id ) ) {
1076
+ return $post_id;
1077
+ }
1078
+
1079
+ $attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
1080
+ wp_update_attachment_metadata( $post_id, $attachment_metadata );
1081
+
1082
+ // Map this image URL later if we need to
1083
+ $this->url_remap[ $remote_url ] = $upload['url'];
1084
+
1085
+ // If we have a HTTPS URL, ensure the HTTP URL gets replaced too
1086
+ if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
1087
+ $insecure_url = 'http' . substr( $remote_url, 5 );
1088
+ $this->url_remap[ $insecure_url ] = $upload['url'];
1089
+ }
1090
+
1091
+ if ( $this->options['aggressive_url_search'] ) {
1092
+ // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1093
+ /*
1094
+ if ( preg_match( '!^image/!', $info['type'] ) ) {
1095
+ $parts = pathinfo( $remote_url );
1096
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1097
+
1098
+ $parts_new = pathinfo( $upload['url'] );
1099
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1100
+
1101
+ $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1102
+ }*/
1103
+ }
1104
+
1105
+ return $post_id;
1106
+ }
1107
+
1108
+ /**
1109
+ * Parse a meta node into meta data.
1110
+ *
1111
+ * @param DOMElement $node Parent node of meta data (typically `wp:postmeta` or `wp:commentmeta`).
1112
+ * @return array|null Meta data array on success, or null on error.
1113
+ */
1114
+ protected function parse_meta_node( $node ) {
1115
+ foreach ( $node->childNodes as $child ) {
1116
+ // We only care about child elements
1117
+ if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1118
+ continue;
1119
+ }
1120
+
1121
+ switch ( $child->tagName ) {
1122
+ case 'wp:meta_key':
1123
+ $key = $child->textContent;
1124
+ break;
1125
+
1126
+ case 'wp:meta_value':
1127
+ $value = $child->textContent;
1128
+ break;
1129
+ }
1130
+ }
1131
+
1132
+ if ( empty( $key ) || empty( $value ) ) {
1133
+ return null;
1134
+ }
1135
+
1136
+ return compact( 'key', 'value' );
1137
+ }
1138
+
1139
+ /**
1140
+ * Process and import post meta items.
1141
+ *
1142
+ * @param array $meta List of meta data arrays
1143
+ * @param int $post_id Post to associate with
1144
+ * @param array $post Post data
1145
+ * @return int|WP_Error Number of meta items imported on success, error otherwise.
1146
+ */
1147
+ protected function process_post_meta( $meta, $post_id, $post ) {
1148
+ if ( empty( $meta ) ) {
1149
+ return true;
1150
+ }
1151
+
1152
+ foreach ( $meta as $meta_item ) {
1153
+ /**
1154
+ * Pre-process post meta data.
1155
+ *
1156
+ * @param array $meta_item Meta data. (Return empty to skip.)
1157
+ * @param int $post_id Post the meta is attached to.
1158
+ */
1159
+ $meta_item = apply_filters( 'wxr_importer.pre_process.post_meta', $meta_item, $post_id );
1160
+ if ( empty( $meta_item ) ) {
1161
+ return false;
1162
+ }
1163
+
1164
+ $key = apply_filters( 'import_post_meta_key', $meta_item['key'], $post_id, $post );
1165
+ $value = false;
1166
+
1167
+ if ( '_edit_last' === $key ) {
1168
+ $value = intval( $meta_item['value'] );
1169
+ if ( ! isset( $this->mapping['user'][ $value ] ) ) {
1170
+ // Skip!
1171
+ continue;
1172
+ }
1173
+
1174
+ $value = $this->mapping['user'][ $value ];
1175
+ }
1176
+
1177
+ if ( $key ) {
1178
+ // export gets meta straight from the DB so could have a serialized string
1179
+ if ( ! $value ) {
1180
+ $value = maybe_unserialize( $meta_item['value'] );
1181
+ }
1182
+
1183
+ add_post_meta( $post_id, $key, $value );
1184
+ do_action( 'import_post_meta', $post_id, $key, $value );
1185
+
1186
+ // if the post has a featured image, take note of this in case of remap
1187
+ if ( '_thumbnail_id' === $key ) {
1188
+ $this->featured_images[ $post_id ] = (int) $value;
1189
+ }
1190
+ }
1191
+ }// End foreach().
1192
+
1193
+ return true;
1194
+ }
1195
+
1196
+ /**
1197
+ * Parse a comment node into comment data.
1198
+ *
1199
+ * @param DOMElement $node Parent node of comment data (typically `wp:comment`).
1200
+ * @return array Comment data array.
1201
+ */
1202
+ protected function parse_comment_node( $node ) {
1203
+ $data = array(
1204
+ 'commentmeta' => array(),
1205
+ );
1206
+
1207
+ foreach ( $node->childNodes as $child ) {
1208
+ // We only care about child elements
1209
+ if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1210
+ continue;
1211
+ }
1212
+
1213
+ switch ( $child->tagName ) {
1214
+ case 'wp:comment_id':
1215
+ $data['comment_id'] = $child->textContent;
1216
+ break;
1217
+ case 'wp:comment_author':
1218
+ $data['comment_author'] = $child->textContent;
1219
+ break;
1220
+
1221
+ case 'wp:comment_author_email':
1222
+ $data['comment_author_email'] = $child->textContent;
1223
+ break;
1224
+
1225
+ case 'wp:comment_author_IP':
1226
+ $data['comment_author_IP'] = $child->textContent;
1227
+ break;
1228
+
1229
+ case 'wp:comment_author_url':
1230
+ $data['comment_author_url'] = $child->textContent;
1231
+ break;
1232
+
1233
+ case 'wp:comment_user_id':
1234
+ $data['comment_user_id'] = $child->textContent;
1235
+ break;
1236
+
1237
+ case 'wp:comment_date':
1238
+ $data['comment_date'] = $child->textContent;
1239
+ break;
1240
+
1241
+ case 'wp:comment_date_gmt':
1242
+ $data['comment_date_gmt'] = $child->textContent;
1243
+ break;
1244
+
1245
+ case 'wp:comment_content':
1246
+ $data['comment_content'] = $child->textContent;
1247
+ break;
1248
+
1249
+ case 'wp:comment_approved':
1250
+ $data['comment_approved'] = $child->textContent;
1251
+ break;
1252
+
1253
+ case 'wp:comment_type':
1254
+ $data['comment_type'] = $child->textContent;
1255
+ break;
1256
+
1257
+ case 'wp:comment_parent':
1258
+ $data['comment_parent'] = $child->textContent;
1259
+ break;
1260
+
1261
+ case 'wp:commentmeta':
1262
+ $meta_item = $this->parse_meta_node( $child );
1263
+ if ( ! empty( $meta_item ) ) {
1264
+ $data['commentmeta'][] = $meta_item;
1265
+ }
1266
+ break;
1267
+ }// End switch().
1268
+ }// End foreach().
1269
+
1270
+ return $data;
1271
+ }
1272
+
1273
+ /**
1274
+ * Process and import comment data.
1275
+ *
1276
+ * @param array $comments List of comment data arrays.
1277
+ * @param int $post_id Post to associate with.
1278
+ * @param array $post Post data.
1279
+ * @return int|WP_Error Number of comments imported on success, error otherwise.
1280
+ */
1281
+ protected function process_comments( $comments, $post_id, $post, $post_exists = false ) {
1282
+
1283
+ $comments = apply_filters( 'wp_import_post_comments', $comments, $post_id, $post );
1284
+ if ( empty( $comments ) ) {
1285
+ return 0;
1286
+ }
1287
+
1288
+ $num_comments = 0;
1289
+
1290
+ // Sort by ID to avoid excessive remapping later
1291
+ usort( $comments, array( $this, 'sort_comments_by_id' ) );
1292
+
1293
+ foreach ( $comments as $key => $comment ) {
1294
+ /**
1295
+ * Pre-process comment data
1296
+ *
1297
+ * @param array $comment Comment data. (Return empty to skip.)
1298
+ * @param int $post_id Post the comment is attached to.
1299
+ */
1300
+ $comment = apply_filters( 'wxr_importer.pre_process.comment', $comment, $post_id );
1301
+ if ( empty( $comment ) ) {
1302
+ return false;
1303
+ }
1304
+
1305
+ $original_id = isset( $comment['comment_id'] ) ? (int) $comment['comment_id'] : 0;
1306
+ $parent_id = isset( $comment['comment_parent'] ) ? (int) $comment['comment_parent'] : 0;
1307
+ $author_id = isset( $comment['comment_user_id'] ) ? (int) $comment['comment_user_id'] : 0;
1308
+
1309
+ // if this is a new post we can skip the comment_exists() check
1310
+ // TODO: Check comment_exists for performance
1311
+ if ( $post_exists ) {
1312
+ $existing = $this->comment_exists( $comment );
1313
+ if ( $existing ) {
1314
+
1315
+ /**
1316
+ * Comment processing already imported.
1317
+ *
1318
+ * @param array $comment Raw data imported for the comment.
1319
+ */
1320
+ do_action( 'wxr_importer.process_already_imported.comment', $comment );
1321
+
1322
+ $this->mapping['comment'][ $original_id ] = $existing;
1323
+ continue;
1324
+ }
1325
+ }
1326
+
1327
+ // Remove meta from the main array
1328
+ $meta = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
1329
+ unset( $comment['commentmeta'] );
1330
+
1331
+ // Map the parent comment, or mark it as one we need to fix
1332
+ $requires_remapping = false;
1333
+ if ( $parent_id ) {
1334
+ if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
1335
+ $comment['comment_parent'] = $this->mapping['comment'][ $parent_id ];
1336
+ } else {
1337
+ // Prepare for remapping later
1338
+ $meta[] = array(
1339
+ 'key' => '_wxr_import_parent',
1340
+ 'value' => $parent_id,
1341
+ );
1342
+ $requires_remapping = true;
1343
+
1344
+ // Wipe the parent for now
1345
+ $comment['comment_parent'] = 0;
1346
+ }
1347
+ }
1348
+
1349
+ // Map the author, or mark it as one we need to fix
1350
+ if ( $author_id ) {
1351
+ if ( isset( $this->mapping['user'][ $author_id ] ) ) {
1352
+ $comment['user_id'] = $this->mapping['user'][ $author_id ];
1353
+ } else {
1354
+ // Prepare for remapping later
1355
+ $meta[] = array(
1356
+ 'key' => '_wxr_import_user',
1357
+ 'value' => $author_id,
1358
+ );
1359
+ $requires_remapping = true;
1360
+
1361
+ // Wipe the user for now
1362
+ $comment['user_id'] = 0;
1363
+ }
1364
+ }
1365
+
1366
+ // Run standard core filters
1367
+ $comment['comment_post_ID'] = $post_id;
1368
+ $comment = wp_filter_comment( $comment );
1369
+
1370
+ // wp_insert_comment expects slashed data
1371
+ $comment_id = wp_insert_comment( wp_slash( $comment ) );
1372
+ $this->mapping['comment'][ $original_id ] = $comment_id;
1373
+ if ( $requires_remapping ) {
1374
+ $this->requires_remapping['comment'][ $comment_id ] = true;
1375
+ }
1376
+ $this->mark_comment_exists( $comment, $comment_id );
1377
+
1378
+ /**
1379
+ * Comment has been imported.
1380
+ *
1381
+ * @param int $comment_id New comment ID
1382
+ * @param array $comment Comment inserted (`comment_id` item refers to the original ID)
1383
+ * @param int $post_id Post parent of the comment
1384
+ * @param array $post Post data
1385
+ */
1386
+ do_action( 'wp_import_insert_comment', $comment_id, $comment, $post_id, $post );
1387
+
1388
+ // Process the meta items
1389
+ foreach ( $meta as $meta_item ) {
1390
+ $value = maybe_unserialize( $meta_item['value'] );
1391
+ add_comment_meta( $comment_id, wp_slash( $meta_item['key'] ), wp_slash( $value ) );
1392
+ }
1393
+
1394
+ /**
1395
+ * Post processing completed.
1396
+ *
1397
+ * @param int $post_id New post ID.
1398
+ * @param array $comment Raw data imported for the comment.
1399
+ * @param array $meta Raw meta data, already processed by {@see process_post_meta}.
1400
+ * @param array $post_id Parent post ID.
1401
+ */
1402
+ do_action( 'wxr_importer.processed.comment', $comment_id, $comment, $meta, $post_id );
1403
+
1404
+ $num_comments++;
1405
+ }// End foreach().
1406
+
1407
+ return $num_comments;
1408
+ }
1409
+
1410
+ protected function parse_category_node( $node ) {
1411
+ $data = array(
1412
+ // Default taxonomy to "category", since this is a `<category>` tag
1413
+ 'taxonomy' => 'category',
1414
+ );
1415
+ $meta = array();
1416
+
1417
+ if ( $node->hasAttribute( 'domain' ) ) {
1418
+ $data['taxonomy'] = $node->getAttribute( 'domain' );
1419
+ }
1420
+ if ( $node->hasAttribute( 'nicename' ) ) {
1421
+ $data['slug'] = $node->getAttribute( 'nicename' );
1422
+ }
1423
+
1424
+ $data['name'] = $node->textContent;
1425
+
1426
+ if ( empty( $data['slug'] ) ) {
1427
+ return null;
1428
+ }
1429
+
1430
+ // Just for extra compatibility
1431
+ if ( $data['taxonomy'] === 'tag' ) {
1432
+ $data['taxonomy'] = 'post_tag';
1433
+ }
1434
+
1435
+ return $data;
1436
+ }
1437
+
1438
+ /**
1439
+ * Callback for `usort` to sort comments by ID
1440
+ *
1441
+ * @param array $a Comment data for the first comment
1442
+ * @param array $b Comment data for the second comment
1443
+ * @return int
1444
+ */
1445
+ public static function sort_comments_by_id( $a, $b ) {
1446
+ if ( empty( $a['comment_id'] ) ) {
1447
+ return 1;
1448
+ }
1449
+
1450
+ if ( empty( $b['comment_id'] ) ) {
1451
+ return -1;
1452
+ }
1453
+
1454
+ return $a['comment_id'] - $b['comment_id'];
1455
+ }
1456
+
1457
+ protected function parse_author_node( $node ) {
1458
+ $data = array();
1459
+ $meta = array();
1460
+ foreach ( $node->childNodes as $child ) {
1461
+ // We only care about child elements
1462
+ if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1463
+ continue;
1464
+ }
1465
+
1466
+ switch ( $child->tagName ) {
1467
+ case 'wp:author_login':
1468
+ $data['user_login'] = $child->textContent;
1469
+ break;
1470
+
1471
+ case 'wp:author_id':
1472
+ $data['ID'] = $child->textContent;
1473
+ break;
1474
+
1475
+ case 'wp:author_email':
1476
+ $data['user_email'] = $child->textContent;
1477
+ break;
1478
+
1479
+ case 'wp:author_display_name':
1480
+ $data['display_name'] = $child->textContent;
1481
+ break;
1482
+
1483
+ case 'wp:author_first_name':
1484
+ $data['first_name'] = $child->textContent;
1485
+ break;
1486
+
1487
+ case 'wp:author_last_name':
1488
+ $data['last_name'] = $child->textContent;
1489
+ break;
1490
+ }
1491
+ }
1492
+
1493
+ return compact( 'data', 'meta' );
1494
+ }
1495
+
1496
+ protected function process_author( $data, $meta ) {
1497
+ /**
1498
+ * Pre-process user data.
1499
+ *
1500
+ * @param array $data User data. (Return empty to skip.)
1501
+ * @param array $meta Meta data.
1502
+ */
1503
+ $data = apply_filters( 'wxr_importer.pre_process.user', $data, $meta );
1504
+ if ( empty( $data ) ) {
1505
+ return false;
1506
+ }
1507
+
1508
+ // Have we already handled this user?
1509
+ $original_id = isset( $data['ID'] ) ? $data['ID'] : 0;
1510
+ $original_slug = $data['user_login'];
1511
+
1512
+ if ( isset( $this->mapping['user'][ $original_id ] ) ) {
1513
+ $existing = $this->mapping['user'][ $original_id ];
1514
+
1515
+ // Note the slug mapping if we need to too
1516
+ if ( ! isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
1517
+ $this->mapping['user_slug'][ $original_slug ] = $existing;
1518
+ }
1519
+
1520
+ return false;
1521
+ }
1522
+
1523
+ if ( isset( $this->mapping['user_slug'][ $original_slug ] ) ) {
1524
+ $existing = $this->mapping['user_slug'][ $original_slug ];
1525
+
1526
+ // Ensure we note the mapping too
1527
+ $this->mapping['user'][ $original_id ] = $existing;
1528
+
1529
+ return false;
1530
+ }
1531
+
1532
+ // Allow overriding the user's slug
1533
+ $login = $original_slug;
1534
+ if ( isset( $this->user_slug_override[ $login ] ) ) {
1535
+ $login = $this->user_slug_override[ $login ];
1536
+ }
1537
+
1538
+ $userdata = array(
1539
+ 'user_login' => sanitize_user( $login, true ),
1540
+ 'user_pass' => wp_generate_password(),
1541
+ );
1542
+
1543
+ $allowed = array(
1544
+ 'user_email' => true,
1545
+ 'display_name' => true,
1546
+ 'first_name' => true,
1547
+ 'last_name' => true,
1548
+ );
1549
+ foreach ( $data as $key => $value ) {
1550
+ if ( ! isset( $allowed[ $key ] ) ) {
1551
+ continue;
1552
+ }
1553
+
1554
+ $userdata[ $key ] = $data[ $key ];
1555
+ }
1556
+
1557
+ $user_id = wp_insert_user( wp_slash( $userdata ) );
1558
+ if ( is_wp_error( $user_id ) ) {
1559
+ $this->logger->error( sprintf(
1560
+ __( 'Failed to import user "%s"', 'wordpress-importer' ),
1561
+ $userdata['user_login']
1562
+ ) );
1563
+ $this->logger->debug( $user_id->get_error_message() );
1564
+
1565
+ /**
1566
+ * User processing failed.
1567
+ *
1568
+ * @param WP_Error $user_id Error object.
1569
+ * @param array $userdata Raw data imported for the user.
1570
+ */
1571
+ do_action( 'wxr_importer.process_failed.user', $user_id, $userdata );
1572
+ return false;
1573
+ }
1574
+
1575
+ if ( $original_id ) {
1576
+ $this->mapping['user'][ $original_id ] = $user_id;
1577
+ }
1578
+ $this->mapping['user_slug'][ $original_slug ] = $user_id;
1579
+
1580
+ $this->logger->info( sprintf(
1581
+ __( 'Imported user "%s"', 'wordpress-importer' ),
1582
+ $userdata['user_login']
1583
+ ) );
1584
+ $this->logger->debug( sprintf(
1585
+ __( 'User %1$d remapped to %2$d', 'wordpress-importer' ),
1586
+ $original_id,
1587
+ $user_id
1588
+ ) );
1589
+
1590
+ // TODO: Implement meta handling once WXR includes it
1591
+ /**
1592
+ * User processing completed.
1593
+ *
1594
+ * @param int $user_id New user ID.
1595
+ * @param array $userdata Raw data imported for the user.
1596
+ */
1597
+ do_action( 'wxr_importer.processed.user', $user_id, $userdata );
1598
+ }
1599
+
1600
+ protected function parse_term_node( $node, $type = 'term' ) {
1601
+ $data = array();
1602
+ $meta = array();
1603
+
1604
+ $tag_name = array(
1605
+ 'id' => 'wp:term_id',
1606
+ 'taxonomy' => 'wp:term_taxonomy',
1607
+ 'slug' => 'wp:term_slug',
1608
+ 'parent' => 'wp:term_parent',
1609
+ 'name' => 'wp:term_name',
1610
+ 'description' => 'wp:term_description',
1611
+ );
1612
+ $taxonomy = null;
1613
+
1614
+ // Special casing!
1615
+ switch ( $type ) {
1616
+ case 'category':
1617
+ $tag_name['slug'] = 'wp:category_nicename';
1618
+ $tag_name['parent'] = 'wp:category_parent';
1619
+ $tag_name['name'] = 'wp:cat_name';
1620
+ $tag_name['description'] = 'wp:category_description';
1621
+ $tag_name['taxonomy'] = null;
1622
+
1623
+ $data['taxonomy'] = 'category';
1624
+ break;
1625
+
1626
+ case 'tag':
1627
+ $tag_name['slug'] = 'wp:tag_slug';
1628
+ $tag_name['parent'] = null;
1629
+ $tag_name['name'] = 'wp:tag_name';
1630
+ $tag_name['description'] = 'wp:tag_description';
1631
+ $tag_name['taxonomy'] = null;
1632
+
1633
+ $data['taxonomy'] = 'post_tag';
1634
+ break;
1635
+ }
1636
+
1637
+ foreach ( $node->childNodes as $child ) {
1638
+ // We only care about child elements
1639
+ if ( $child->nodeType !== XML_ELEMENT_NODE ) {
1640
+ continue;
1641
+ }
1642
+
1643
+ $key = array_search( $child->tagName, $tag_name );
1644
+ if ( $key ) {
1645
+ $data[ $key ] = $child->textContent;
1646
+ }
1647
+ }
1648
+
1649
+ if ( empty( $data['taxonomy'] ) ) {
1650
+ return null;
1651
+ }
1652
+
1653
+ // Compatibility with WXR 1.0
1654
+ if ( $data['taxonomy'] === 'tag' ) {
1655
+ $data['taxonomy'] = 'post_tag';
1656
+ }
1657
+
1658
+ return compact( 'data', 'meta' );
1659
+ }
1660
+
1661
+ protected function process_term( $data, $meta ) {
1662
+ /**
1663
+ * Pre-process term data.
1664
+ *
1665
+ * @param array $data Term data. (Return empty to skip.)
1666
+ * @param array $meta Meta data.
1667
+ */
1668
+ $data = apply_filters( 'wxr_importer.pre_process.term', $data, $meta );
1669
+ if ( empty( $data ) ) {
1670
+ return false;
1671
+ }
1672
+
1673
+ $original_id = isset( $data['id'] ) ? (int) $data['id'] : 0;
1674
+ $parent_id = isset( $data['parent'] ) ? (int) $data['parent'] : 0;
1675
+
1676
+ $mapping_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
1677
+ $existing = $this->term_exists( $data );
1678
+ if ( $existing ) {
1679
+
1680
+ /**
1681
+ * Term processing already imported.
1682
+ *
1683
+ * @param array $data Raw data imported for the term.
1684
+ */
1685
+ do_action( 'wxr_importer.process_already_imported.term', $data );
1686
+
1687
+ $this->mapping['term'][ $mapping_key ] = $existing;
1688
+ $this->mapping['term_id'][ $original_id ] = $existing;
1689
+ return false;
1690
+ }
1691
+
1692
+ // WP really likes to repeat itself in export files
1693
+ if ( isset( $this->mapping['term'][ $mapping_key ] ) ) {
1694
+ return false;
1695
+ }
1696
+
1697
+ $termdata = array();
1698
+ $allowed = array(
1699
+ 'slug' => true,
1700
+ 'description' => true,
1701
+ );
1702
+
1703
+ // Map the parent comment, or mark it as one we need to fix
1704
+ // TODO: add parent mapping and remapping
1705
+ /*
1706
+ $requires_remapping = false;
1707
+ if ( $parent_id ) {
1708
+ if ( isset( $this->mapping['term'][ $parent_id ] ) ) {
1709
+ $data['parent'] = $this->mapping['term'][ $parent_id ];
1710
+ } else {
1711
+ // Prepare for remapping later
1712
+ $meta[] = array( 'key' => '_wxr_import_parent', 'value' => $parent_id );
1713
+ $requires_remapping = true;
1714
+
1715
+ // Wipe the parent for now
1716
+ $data['parent'] = 0;
1717
+ }
1718
+ }*/
1719
+
1720
+ foreach ( $data as $key => $value ) {
1721
+ if ( ! isset( $allowed[ $key ] ) ) {
1722
+ continue;
1723
+ }
1724
+
1725
+ $termdata[ $key ] = $data[ $key ];
1726
+ }
1727
+
1728
+ $result = wp_insert_term( $data['name'], $data['taxonomy'], $termdata );
1729
+ if ( is_wp_error( $result ) ) {
1730
+ $this->logger->warning( sprintf(
1731
+ __( 'Failed to import %1$s %2$s', 'wordpress-importer' ),
1732
+ $data['taxonomy'],
1733
+ $data['name']
1734
+ ) );
1735
+ $this->logger->debug( $result->get_error_message() );
1736
+ do_action( 'wp_import_insert_term_failed', $result, $data );
1737
+
1738
+ /**
1739
+ * Term processing failed.
1740
+ *
1741
+ * @param WP_Error $result Error object.
1742
+ * @param array $data Raw data imported for the term.
1743
+ * @param array $meta Meta data supplied for the term.
1744
+ */
1745
+ do_action( 'wxr_importer.process_failed.term', $result, $data, $meta );
1746
+ return false;
1747
+ }
1748
+
1749
+ $term_id = $result['term_id'];
1750
+
1751
+ $this->mapping['term'][ $mapping_key ] = $term_id;
1752
+ $this->mapping['term_id'][ $original_id ] = $term_id;
1753
+
1754
+ $this->logger->info( sprintf(
1755
+ __( 'Imported "%1$s" (%2$s)', 'wordpress-importer' ),
1756
+ $data['name'],
1757
+ $data['taxonomy']
1758
+ ) );
1759
+ $this->logger->debug( sprintf(
1760
+ __( 'Term %1$d remapped to %2$d', 'wordpress-importer' ),
1761
+ $original_id,
1762
+ $term_id
1763
+ ) );
1764
+
1765
+ do_action( 'wp_import_insert_term', $term_id, $data );
1766
+
1767
+ /**
1768
+ * Term processing completed.
1769
+ *
1770
+ * @param int $term_id New term ID.
1771
+ * @param array $data Raw data imported for the term.
1772
+ */
1773
+ do_action( 'wxr_importer.processed.term', $term_id, $data );
1774
+ }
1775
+
1776
+ /**
1777
+ * Attempt to download a remote file attachment
1778
+ *
1779
+ * @param string $url URL of item to fetch
1780
+ * @param array $post Attachment details
1781
+ * @return array|WP_Error Local file location details on success, WP_Error otherwise
1782
+ */
1783
+ protected function fetch_remote_file( $url, $post ) {
1784
+ // extract the file name and extension from the url
1785
+ $file_name = basename( $url );
1786
+
1787
+ // get placeholder file in the upload dir with a unique, sanitized filename
1788
+ $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1789
+ if ( $upload['error'] ) {
1790
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1791
+ }
1792
+
1793
+ // fetch the remote url and write it to the placeholder file
1794
+ $response = wp_remote_get( $url, array(
1795
+ 'stream' => true,
1796
+ 'filename' => $upload['file'],
1797
+ ) );
1798
+
1799
+ // request failed
1800
+ if ( is_wp_error( $response ) ) {
1801
+ unlink( $upload['file'] );
1802
+ return $response;
1803
+ }
1804
+
1805
+ $code = (int) wp_remote_retrieve_response_code( $response );
1806
+
1807
+ // make sure the fetch was successful
1808
+ if ( $code !== 200 ) {
1809
+ unlink( $upload['file'] );
1810
+ return new WP_Error(
1811
+ 'import_file_error',
1812
+ sprintf(
1813
+ __( 'Remote server returned %1$d %2$s for %3$s', 'wordpress-importer' ),
1814
+ $code,
1815
+ get_status_header_desc( $code ),
1816
+ $url
1817
+ )
1818
+ );
1819
+ }
1820
+
1821
+ $filesize = filesize( $upload['file'] );
1822
+ $headers = wp_remote_retrieve_headers( $response );
1823
+
1824
+ if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
1825
+ unlink( $upload['file'] );
1826
+ return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'wordpress-importer' ) );
1827
+ }
1828
+
1829
+ if ( 0 === $filesize ) {
1830
+ unlink( $upload['file'] );
1831
+ return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'wordpress-importer' ) );
1832
+ }
1833
+
1834
+ $max_size = (int) $this->max_attachment_size();
1835
+ if ( ! empty( $max_size ) && $filesize > $max_size ) {
1836
+ unlink( $upload['file'] );
1837
+ $message = sprintf( __( 'Remote file is too large, limit is %s', 'wordpress-importer' ), size_format( $max_size ) );
1838
+ return new WP_Error( 'import_file_error', $message );
1839
+ }
1840
+
1841
+ return $upload;
1842
+ }
1843
+
1844
+ protected function post_process() {
1845
+ // Time to tackle any left-over bits
1846
+ if ( ! empty( $this->requires_remapping['post'] ) ) {
1847
+ $this->post_process_posts( $this->requires_remapping['post'] );
1848
+ }
1849
+ if ( ! empty( $this->requires_remapping['comment'] ) ) {
1850
+ $this->post_process_comments( $this->requires_remapping['comment'] );
1851
+ }
1852
+ }
1853
+
1854
+ protected function post_process_posts( $todo ) {
1855
+ foreach ( $todo as $post_id => $_ ) {
1856
+ $this->logger->debug( sprintf(
1857
+ // Note: title intentionally not used to skip extra processing
1858
+ // for when debug logging is off
1859
+ __( 'Running post-processing for post %d', 'wordpress-importer' ),
1860
+ $post_id
1861
+ ) );
1862
+
1863
+ $data = array();
1864
+
1865
+ $parent_id = get_post_meta( $post_id, '_wxr_import_parent', true );
1866
+ if ( ! empty( $parent_id ) ) {
1867
+ // Have we imported the parent now?
1868
+ if ( isset( $this->mapping['post'][ $parent_id ] ) ) {
1869
+ $data['post_parent'] = $this->mapping['post'][ $parent_id ];
1870
+ } else {
1871
+ $this->logger->warning( sprintf(
1872
+ __( 'Could not find the post parent for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1873
+ get_the_title( $post_id ),
1874
+ $post_id
1875
+ ) );
1876
+ $this->logger->debug( sprintf(
1877
+ __( 'Post %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
1878
+ $post_id,
1879
+ $parent_id
1880
+ ) );
1881
+ }
1882
+ }
1883
+
1884
+ $author_slug = get_post_meta( $post_id, '_wxr_import_user_slug', true );
1885
+ if ( ! empty( $author_slug ) ) {
1886
+ // Have we imported the user now?
1887
+ if ( isset( $this->mapping['user_slug'][ $author_slug ] ) ) {
1888
+ $data['post_author'] = $this->mapping['user_slug'][ $author_slug ];
1889
+ } else {
1890
+ $this->logger->warning( sprintf(
1891
+ __( 'Could not find the author for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1892
+ get_the_title( $post_id ),
1893
+ $post_id
1894
+ ) );
1895
+ $this->logger->debug( sprintf(
1896
+ __( 'Post %1$d was imported with author "%2$s", but could not be found', 'wordpress-importer' ),
1897
+ $post_id,
1898
+ $author_slug
1899
+ ) );
1900
+ }
1901
+ }
1902
+
1903
+ $has_attachments = get_post_meta( $post_id, '_wxr_import_has_attachment_refs', true );
1904
+ if ( ! empty( $has_attachments ) ) {
1905
+ $post = get_post( $post_id );
1906
+ $content = $post->post_content;
1907
+
1908
+ // Replace all the URLs we've got
1909
+ $new_content = str_replace( array_keys( $this->url_remap ), $this->url_remap, $content );
1910
+ if ( $new_content !== $content ) {
1911
+ $data['post_content'] = $new_content;
1912
+ }
1913
+ }
1914
+
1915
+ if ( get_post_type( $post_id ) === 'nav_menu_item' ) {
1916
+ $this->post_process_menu_item( $post_id );
1917
+ }
1918
+
1919
+ // Do we have updates to make?
1920
+ if ( empty( $data ) ) {
1921
+ $this->logger->debug( sprintf(
1922
+ __( 'Post %d was marked for post-processing, but none was required.', 'wordpress-importer' ),
1923
+ $post_id
1924
+ ) );
1925
+ continue;
1926
+ }
1927
+
1928
+ // Run the update
1929
+ $data['ID'] = $post_id;
1930
+ $result = wp_update_post( $data, true );
1931
+ if ( is_wp_error( $result ) ) {
1932
+ $this->logger->warning( sprintf(
1933
+ __( 'Could not update "%1$s" (post #%2$d) with mapped data', 'wordpress-importer' ),
1934
+ get_the_title( $post_id ),
1935
+ $post_id
1936
+ ) );
1937
+ $this->logger->debug( $result->get_error_message() );
1938
+ continue;
1939
+ }
1940
+
1941
+ // Clear out our temporary meta keys
1942
+ delete_post_meta( $post_id, '_wxr_import_parent' );
1943
+ delete_post_meta( $post_id, '_wxr_import_user_slug' );
1944
+ delete_post_meta( $post_id, '_wxr_import_has_attachment_refs' );
1945
+ }// End foreach().
1946
+ }
1947
+
1948
+ protected function post_process_menu_item( $post_id ) {
1949
+ $menu_object_id = get_post_meta( $post_id, '_wxr_import_menu_item', true );
1950
+ if ( empty( $menu_object_id ) ) {
1951
+ // No processing needed!
1952
+ return;
1953
+ }
1954
+
1955
+ $menu_item_type = get_post_meta( $post_id, '_menu_item_type', true );
1956
+ switch ( $menu_item_type ) {
1957
+ case 'taxonomy':
1958
+ if ( isset( $this->mapping['term_id'][ $menu_object_id ] ) ) {
1959
+ $menu_object = $this->mapping['term_id'][ $menu_object_id ];
1960
+ }
1961
+ break;
1962
+
1963
+ case 'post_type':
1964
+ if ( isset( $this->mapping['post'][ $menu_object_id ] ) ) {
1965
+ $menu_object = $this->mapping['post'][ $menu_object_id ];
1966
+ }
1967
+ break;
1968
+
1969
+ default:
1970
+ // Cannot handle this.
1971
+ return;
1972
+ }
1973
+
1974
+ if ( ! empty( $menu_object ) ) {
1975
+ update_post_meta( $post_id, '_menu_item_object_id', wp_slash( $menu_object ) );
1976
+ } else {
1977
+ $this->logger->warning( sprintf(
1978
+ __( 'Could not find the menu object for "%1$s" (post #%2$d)', 'wordpress-importer' ),
1979
+ get_the_title( $post_id ),
1980
+ $post_id
1981
+ ) );
1982
+ $this->logger->debug( sprintf(
1983
+ __( 'Post %1$d was imported with object "%2$d" of type "%3$s", but could not be found', 'wordpress-importer' ),
1984
+ $post_id,
1985
+ $menu_object_id,
1986
+ $menu_item_type
1987
+ ) );
1988
+ }
1989
+
1990
+ delete_post_meta( $post_id, '_wxr_import_menu_item' );
1991
+ }
1992
+
1993
+
1994
+ protected function post_process_comments( $todo ) {
1995
+ foreach ( $todo as $comment_id => $_ ) {
1996
+ $data = array();
1997
+
1998
+ $parent_id = get_comment_meta( $comment_id, '_wxr_import_parent', true );
1999
+ if ( ! empty( $parent_id ) ) {
2000
+ // Have we imported the parent now?
2001
+ if ( isset( $this->mapping['comment'][ $parent_id ] ) ) {
2002
+ $data['comment_parent'] = $this->mapping['comment'][ $parent_id ];
2003
+ } else {
2004
+ $this->logger->warning( sprintf(
2005
+ __( 'Could not find the comment parent for comment #%d', 'wordpress-importer' ),
2006
+ $comment_id
2007
+ ) );
2008
+ $this->logger->debug( sprintf(
2009
+ __( 'Comment %1$d was imported with parent %2$d, but could not be found', 'wordpress-importer' ),
2010
+ $comment_id,
2011
+ $parent_id
2012
+ ) );
2013
+ }
2014
+ }
2015
+
2016
+ $author_id = get_comment_meta( $comment_id, '_wxr_import_user', true );
2017
+ if ( ! empty( $author_id ) ) {
2018
+ // Have we imported the user now?
2019
+ if ( isset( $this->mapping['user'][ $author_id ] ) ) {
2020
+ $data['user_id'] = $this->mapping['user'][ $author_id ];
2021
+ } else {
2022
+ $this->logger->warning( sprintf(
2023
+ __( 'Could not find the author for comment #%d', 'wordpress-importer' ),
2024
+ $comment_id
2025
+ ) );
2026
+ $this->logger->debug( sprintf(
2027
+ __( 'Comment %1$d was imported with author %2$d, but could not be found', 'wordpress-importer' ),
2028
+ $comment_id,
2029
+ $author_id
2030
+ ) );
2031
+ }
2032
+ }
2033
+
2034
+ // Do we have updates to make?
2035
+ if ( empty( $data ) ) {
2036
+ continue;
2037
+ }
2038
+
2039
+ // Run the update
2040
+ $data['comment_ID'] = $comment_ID;
2041
+ $result = wp_update_comment( wp_slash( $data ) );
2042
+ if ( empty( $result ) ) {
2043
+ $this->logger->warning( sprintf(
2044
+ __( 'Could not update comment #%d with mapped data', 'wordpress-importer' ),
2045
+ $comment_id
2046
+ ) );
2047
+ continue;
2048
+ }
2049
+
2050
+ // Clear out our temporary meta keys
2051
+ delete_comment_meta( $comment_id, '_wxr_import_parent' );
2052
+ delete_comment_meta( $comment_id, '_wxr_import_user' );
2053
+ }// End foreach().
2054
+ }
2055
+
2056
+ /**
2057
+ * Use stored mapping information to update old attachment URLs
2058
+ */
2059
+ protected function replace_attachment_urls_in_content() {
2060
+ global $wpdb;
2061
+ // make sure we do the longest urls first, in case one is a substring of another
2062
+ uksort( $this->url_remap, array( $this, 'cmpr_strlen' ) );
2063
+
2064
+ foreach ( $this->url_remap as $from_url => $to_url ) {
2065
+ // remap urls in post_content
2066
+ $query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url );
2067
+ $wpdb->query( $query );
2068
+
2069
+ // remap enclosure urls
2070
+ $query = $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url );
2071
+ $result = $wpdb->query( $query );
2072
+ }
2073
+ }
2074
+
2075
+ /**
2076
+ * Update _thumbnail_id meta to new, imported attachment IDs
2077
+ */
2078
+ function remap_featured_images() {
2079
+ // cycle through posts that have a featured image
2080
+ foreach ( $this->featured_images as $post_id => $value ) {
2081
+ if ( isset( $this->processed_posts[ $value ] ) ) {
2082
+ $new_id = $this->processed_posts[ $value ];
2083
+
2084
+ // only update if there's a difference
2085
+ if ( $new_id !== $value ) {
2086
+ update_post_meta( $post_id, '_thumbnail_id', $new_id );
2087
+ }
2088
+ }
2089
+ }
2090
+ }
2091
+
2092
+ /**
2093
+ * Decide if the given meta key maps to information we will want to import
2094
+ *
2095
+ * @param string $key The meta key to check
2096
+ * @return string|bool The key if we do want to import, false if not
2097
+ */
2098
+ public function is_valid_meta_key( $key ) {
2099
+ // skip attachment metadata since we'll regenerate it from scratch
2100
+ // skip _edit_lock as not relevant for import
2101
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) {
2102
+ return false;
2103
+ }
2104
+
2105
+ return $key;
2106
+ }
2107
+
2108
+ /**
2109
+ * Decide what the maximum file size for downloaded attachments is.
2110
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
2111
+ *
2112
+ * @return int Maximum attachment file size to import
2113
+ */
2114
+ protected function max_attachment_size() {
2115
+ return apply_filters( 'import_attachment_size_limit', 0 );
2116
+ }
2117
+
2118
+ /**
2119
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
2120
+ *
2121
+ * @access protected
2122
+ * @return int 60
2123
+ */
2124
+ function bump_request_timeout( $val ) {
2125
+ return 60;
2126
+ }
2127
+
2128
+ // return the difference in length between two strings
2129
+ function cmpr_strlen( $a, $b ) {
2130
+ return strlen( $b ) - strlen( $a );
2131
+ }
2132
+
2133
+ /**
2134
+ * Prefill existing post data.
2135
+ *
2136
+ * This preloads all GUIDs into memory, allowing us to avoid hitting the
2137
+ * database when we need to check for existence. With larger imports, this
2138
+ * becomes prohibitively slow to perform SELECT queries on each.
2139
+ *
2140
+ * By preloading all this data into memory, it's a constant-time lookup in
2141
+ * PHP instead. However, this does use a lot more memory, so for sites doing
2142
+ * small imports onto a large site, it may be a better tradeoff to use
2143
+ * on-the-fly checking instead.
2144
+ */
2145
+ protected function prefill_existing_posts() {
2146
+ global $wpdb;
2147
+ $posts = $wpdb->get_results( "SELECT ID, guid FROM {$wpdb->posts}" );
2148
+
2149
+ foreach ( $posts as $item ) {
2150
+ $this->exists['post'][ $item->guid ] = $item->ID;
2151
+ }
2152
+ }
2153
+
2154
+ /**
2155
+ * Does the post exist?
2156
+ *
2157
+ * @param array $data Post data to check against.
2158
+ * @return int|bool Existing post ID if it exists, false otherwise.
2159
+ */
2160
+ protected function post_exists( $data ) {
2161
+ // Constant-time lookup if we prefilled
2162
+ $exists_key = $data['guid'];
2163
+
2164
+ if ( $this->options['prefill_existing_posts'] ) {
2165
+ return isset( $this->exists['post'][ $exists_key ] ) ? $this->exists['post'][ $exists_key ] : false;
2166
+ }
2167
+
2168
+ // No prefilling, but might have already handled it
2169
+ if ( isset( $this->exists['post'][ $exists_key ] ) ) {
2170
+ return $this->exists['post'][ $exists_key ];
2171
+ }
2172
+
2173
+ // Still nothing, try post_exists, and cache it
2174
+ $exists = post_exists( $data['post_title'], $data['post_content'], $data['post_date'] );
2175
+ $this->exists['post'][ $exists_key ] = $exists;
2176
+
2177
+ return $exists;
2178
+ }
2179
+
2180
+ /**
2181
+ * Mark the post as existing.
2182
+ *
2183
+ * @param array $data Post data to mark as existing.
2184
+ * @param int $post_id Post ID.
2185
+ */
2186
+ protected function mark_post_exists( $data, $post_id ) {
2187
+ $exists_key = $data['guid'];
2188
+ $this->exists['post'][ $exists_key ] = $post_id;
2189
+ }
2190
+
2191
+ /**
2192
+ * Prefill existing comment data.
2193
+ *
2194
+ * @see self::prefill_existing_posts() for justification of why this exists.
2195
+ */
2196
+ protected function prefill_existing_comments() {
2197
+ global $wpdb;
2198
+ $posts = $wpdb->get_results( "SELECT comment_ID, comment_author, comment_date FROM {$wpdb->comments}" );
2199
+
2200
+ foreach ( $posts as $item ) {
2201
+ $exists_key = sha1( $item->comment_author . ':' . $item->comment_date );
2202
+ $this->exists['comment'][ $exists_key ] = $item->comment_ID;
2203
+ }
2204
+ }
2205
+
2206
+ /**
2207
+ * Does the comment exist?
2208
+ *
2209
+ * @param array $data Comment data to check against.
2210
+ * @return int|bool Existing comment ID if it exists, false otherwise.
2211
+ */
2212
+ protected function comment_exists( $data ) {
2213
+ $exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
2214
+
2215
+ // Constant-time lookup if we prefilled
2216
+ if ( $this->options['prefill_existing_comments'] ) {
2217
+ return isset( $this->exists['comment'][ $exists_key ] ) ? $this->exists['comment'][ $exists_key ] : false;
2218
+ }
2219
+
2220
+ // No prefilling, but might have already handled it
2221
+ if ( isset( $this->exists['comment'][ $exists_key ] ) ) {
2222
+ return $this->exists['comment'][ $exists_key ];
2223
+ }
2224
+
2225
+ // Still nothing, try comment_exists, and cache it
2226
+ $exists = comment_exists( $data['comment_author'], $data['comment_date'] );
2227
+ $this->exists['comment'][ $exists_key ] = $exists;
2228
+
2229
+ return $exists;
2230
+ }
2231
+
2232
+ /**
2233
+ * Mark the comment as existing.
2234
+ *
2235
+ * @param array $data Comment data to mark as existing.
2236
+ * @param int $comment_id Comment ID.
2237
+ */
2238
+ protected function mark_comment_exists( $data, $comment_id ) {
2239
+ $exists_key = sha1( $data['comment_author'] . ':' . $data['comment_date'] );
2240
+ $this->exists['comment'][ $exists_key ] = $comment_id;
2241
+ }
2242
+
2243
+ /**
2244
+ * Prefill existing term data.
2245
+ *
2246
+ * @see self::prefill_existing_posts() for justification of why this exists.
2247
+ */
2248
+ protected function prefill_existing_terms() {
2249
+ global $wpdb;
2250
+ $query = "SELECT t.term_id, tt.taxonomy, t.slug FROM {$wpdb->terms} AS t";
2251
+ $query .= " JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id";
2252
+ $terms = $wpdb->get_results( $query );
2253
+
2254
+ foreach ( $terms as $item ) {
2255
+ $exists_key = sha1( $item->taxonomy . ':' . $item->slug );
2256
+ $this->exists['term'][ $exists_key ] = $item->term_id;
2257
+ }
2258
+ }
2259
+
2260
+ /**
2261
+ * Does the term exist?
2262
+ *
2263
+ * @param array $data Term data to check against.
2264
+ * @return int|bool Existing term ID if it exists, false otherwise.
2265
+ */
2266
+ protected function term_exists( $data ) {
2267
+ $exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
2268
+
2269
+ // Constant-time lookup if we prefilled
2270
+ if ( $this->options['prefill_existing_terms'] ) {
2271
+ return isset( $this->exists['term'][ $exists_key ] ) ? $this->exists['term'][ $exists_key ] : false;
2272
+ }
2273
+
2274
+ // No prefilling, but might have already handled it
2275
+ if ( isset( $this->exists['term'][ $exists_key ] ) ) {
2276
+ return $this->exists['term'][ $exists_key ];
2277
+ }
2278
+
2279
+ // Still nothing, try comment_exists, and cache it
2280
+ $exists = term_exists( $data['slug'], $data['taxonomy'] );
2281
+ if ( is_array( $exists ) ) {
2282
+ $exists = $exists['term_id'];
2283
+ }
2284
+
2285
+ $this->exists['term'][ $exists_key ] = $exists;
2286
+
2287
+ return $exists;
2288
+ }
2289
+
2290
+ /**
2291
+ * Mark the term as existing.
2292
+ *
2293
+ * @param array $data Term data to mark as existing.
2294
+ * @param int $term_id Term ID.
2295
+ */
2296
+ protected function mark_term_exists( $data, $term_id ) {
2297
+ $exists_key = sha1( $data['taxonomy'] . ':' . $data['slug'] );
2298
+ $this->exists['term'][ $exists_key ] = $term_id;
2299
+ }
2300
+ }
2301
  endif;
inc/includes/admin-page.php CHANGED
@@ -1,348 +1,401 @@
1
- <?php
2
- /**
3
- * Shortcode Markup
4
- *
5
- * TMPL - Single Demo Preview
6
- * TMPL - No more demos
7
- * TMPL - Filters
8
- * TMPL - List
9
- *
10
- * @package Astra Sites
11
- * @since 1.0.0
12
- */
13
-
14
- defined( 'ABSPATH' ) or exit;
15
- ?>
16
-
17
- <div class="wrap" id="astra-sites-admin">
18
-
19
- <div id="astra-sites-filters">
20
-
21
- <?php if ( apply_filters( 'astra_sites_show_filters', true ) ) { ?>
22
- <div class="wp-filter hide-if-no-js">
23
- <div class="section-left">
24
-
25
- <!-- All Filters -->
26
- <div class="filter-count">
27
- <span class="count"></span>
28
- </div>
29
- <div class="filters-wrap">
30
- <div id="astra-site-page-builder"></div>
31
- </div>
32
-
33
- </div>
34
-
35
- <div class="section-right">
36
-
37
- <div class="filters-wrap">
38
- <div id="astra-site-category"></div>
39
- </div>
40
-
41
- <div class="search-form">
42
- <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'astra-sites' ); ?> </label>
43
- <input placeholder="<?php _e( 'Search Sites...', 'astra-sites' ); ?>" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
44
- </div>
45
-
46
- </div>
47
- </div>
48
- <?php } ?>
49
-
50
- </div>
51
-
52
- <?php do_action( 'astra_sites_before_site_grid' ); ?>
53
-
54
- <div class="theme-browser rendered">
55
- <div id="astra-sites" class="themes wp-clearfix"></div>
56
- </div>
57
-
58
- <div class="spinner-wrap">
59
- <span class="spinner"></span>
60
- </div>
61
-
62
- <?php do_action( 'astra_sites_after_site_grid' ); ?>
63
-
64
- </div>
65
-
66
- <?php
67
- /**
68
- * TMPL - Pro Site Description
69
- */
70
- ?>
71
- <script type="text/template" id="tmpl-astra-sites-pro-site-description">
72
- <p><?php _e( 'Liked this demo?', 'astra-sites' ); ?></p>
73
- <p>
74
- <?php
75
- /* translators: %s is pricing page link */
76
- printf( __( 'It is a premium website demo which is available only with the Agency Bundles <a href="%s" target="_blank">Buy Now!</a>', 'astra-sites' ), 'https://wpastra.com/pricing/' );
77
- ?>
78
- </p>
79
- <p>
80
- <?php
81
- /* translators: %s is article link */
82
- printf( __( 'Already own an Agency Bundle? Read an article to know how you can <a href="%s" target="_blank">import a premium website demo</a>.', 'astra-sites' ), 'https://wpastra.com/docs/import-astra-agency-website-demos/' );
83
- ?>
84
- </p>
85
- </script>
86
-
87
- <?php
88
- /**
89
- * TMPL - Pro Site Description for Inactive license
90
- */
91
- ?>
92
- <script type="text/template" id="tmpl-astra-sites-pro-inactive-site-description">
93
- <p><?php _e( 'You are just 2 minutes away from importing this demo!', 'astra-sites' ); ?></p>
94
- <p><?php _e( 'It is a premium website demo and you need to activate the license to access it.', 'astra-sites' ); ?></p>
95
- <p>
96
- <?php
97
- /* translators: %s is article link */
98
- printf( __( 'Learn how you can <a href="%s" target="_blank">activate the license</a> of the Astra Premium Sites plugin.', 'astra-sites' ), 'https://wpastra.com/docs/activate-license-for-astra-premium-sites-plugin/' );
99
- ?>
100
- </p>
101
- </script>
102
-
103
- <?php
104
- /**
105
- * TMPL - Single Demo Preview
106
- */
107
- ?>
108
- <script type="text/template" id="tmpl-astra-site-select-page-builder">
109
- <div class="select-page-builder">
110
- <div class="note-wrap">
111
- <h3>
112
- <span class="up-arrow dashicons dashicons-editor-break"></span>
113
- <div class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></div>
114
- </h3>
115
- </div>
116
- <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' ); ?>" />
117
- </div>
118
- </script>
119
-
120
- <?php
121
- /**
122
- * TMPL - Single Demo Preview
123
- */
124
- ?>
125
- <script type="text/template" id="tmpl-astra-site-preview">
126
- <div class="astra-sites-preview theme-install-overlay wp-full-overlay expanded">
127
- <div class="wp-full-overlay-sidebar">
128
- <div class="wp-full-overlay-header"
129
- data-demo-id="{{{data.id}}}"
130
- data-demo-type="{{{data.astra_demo_type}}}"
131
- data-demo-url="{{{data.astra_demo_url}}}"
132
- data-demo-api="{{{data.demo_api}}}"
133
- data-demo-name="{{{data.demo_name}}}"
134
- data-demo-slug="{{{data.slug}}}"
135
- data-screenshot="{{{data.screenshot}}}"
136
- data-content="{{{data.content}}}"
137
- data-required-plugins="{{data.required_plugins}}">
138
- <input type="hidden" class="astra-site-options" value="{{data.astra_site_options}}" >
139
- <input type="hidden" class="astra-enabled-extensions" value="{{data.astra_enabled_extensions}}" >
140
- <button class="close-full-overlay"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'astra-sites' ); ?></span></button>
141
- <button class="previous-theme"><span class="screen-reader-text"><?php esc_html_e( 'Previous', 'astra-sites' ); ?></span></button>
142
- <button class="next-theme"><span class="screen-reader-text"><?php esc_html_e( 'Next', 'astra-sites' ); ?></span></button>
143
- <a class="button hide-if-no-customize astra-demo-import" href="#" data-import="disabled"><?php esc_html_e( 'Install Plugins', 'astra-sites' ); ?></a>
144
-
145
- </div>
146
- <div class="wp-full-overlay-sidebar-content">
147
- <div class="install-theme-info">
148
-
149
- <span class="site-type {{{data.astra_demo_type}}}">{{{data.astra_demo_type}}}</span>
150
- <h3 class="theme-name">{{{data.demo_name}}}</h3>
151
-
152
- <# if ( data.screenshot.length ) { #>
153
- <img class="theme-screenshot" src="{{{data.screenshot}}}" alt="">
154
- <# } #>
155
-
156
- <div class="theme-details">
157
- {{{data.content}}}
158
- </div>
159
- <a href="#" class="theme-details-read-more"><?php _e( 'Read more', 'astra-sites' ); ?> &hellip;</a>
160
-
161
- <div class="required-plugins-wrap">
162
- <h4><?php _e( 'Required Plugins', 'astra-sites' ); ?> </h4>
163
- <div class="required-plugins"></div>
164
- </div>
165
- </div>
166
- </div>
167
-
168
- <div class="wp-full-overlay-footer">
169
- <div class="footer-import-button-wrap">
170
- <a class="button button-hero hide-if-no-customize astra-demo-import" href="#" data-import="disabled">
171
- <?php esc_html_e( 'Install Plugins', 'astra-sites' ); ?>
172
- </a>
173
- </div>
174
- <button type="button" class="collapse-sidebar button" aria-expanded="true"
175
- aria-label="Collapse Sidebar">
176
- <span class="collapse-sidebar-arrow"></span>
177
- <span class="collapse-sidebar-label"><?php esc_html_e( 'Collapse', 'astra-sites' ); ?></span>
178
- </button>
179
-
180
- <div class="devices-wrapper">
181
- <div class="devices">
182
- <button type="button" class="preview-desktop active" aria-pressed="true" data-device="desktop">
183
- <span class="screen-reader-text"><?php _e( 'Enter desktop preview mode', 'astra-sites' ); ?></span>
184
- </button>
185
- <button type="button" class="preview-tablet" aria-pressed="false" data-device="tablet">
186
- <span class="screen-reader-text"><?php _e( 'Enter tablet preview mode', 'astra-sites' ); ?></span>
187
- </button>
188
- <button type="button" class="preview-mobile" aria-pressed="false" data-device="mobile">
189
- <span class="screen-reader-text"><?php _e( 'Enter mobile preview mode', 'astra-sites' ); ?></span>
190
- </button>
191
- </div>
192
- </div>
193
-
194
- </div>
195
- </div>
196
- <div class="wp-full-overlay-main">
197
- <iframe src="{{{data.astra_demo_url}}}" title="<?php esc_attr_e( 'Preview', 'astra-sites' ); ?>"></iframe>
198
- </div>
199
- </div>
200
- </script>
201
-
202
- <?php
203
- /**
204
- * TMPL - No more demos
205
- */
206
- ?>
207
- <script type="text/template" id="tmpl-astra-site-api-request-failed">
208
- <div class="no-themes">
209
- <?php
210
-
211
- /* translators: %1$s & %2$s are a Demo API URL */
212
- printf( __( '<p> It seems the demo data server, <i><a href="%1$s">%2$s</a></i> is unreachable from your site.</p>', 'astra-sites' ), esc_url( Astra_Sites::$api_url ), esc_url( Astra_Sites::$api_url ) );
213
-
214
- _e( '<p class="left-margin"> 1. Sometimes, simple page reload fixes any temporary issues. No kidding!</p>', 'astra-sites' );
215
-
216
- _e( '<p class="left-margin"> 2. If that does not work, you will need to talk to your server administrator and check if demo server is being blocked by the firewall!</p>', 'astra-sites' );
217
-
218
- /* translators: %1$s is a support link */
219
- printf( __( '<p>If that does not help, please open up a <a href="%1$s" target="_blank">Support Ticket</a> and we will be glad take a closer look for you.</p>', 'astra-sites' ), esc_url( 'https://wpastra.com/support/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=api-request-failed' ) );
220
- ?>
221
- </div>
222
- </script>
223
-
224
- <?php
225
- /**
226
- * TMPL - Site Down
227
- */
228
- ?>
229
- <script type="text/template" id="tmpl-astra-site-down">
230
- <div class="postbox astra-site-down">
231
- <h2><?php _e( 'Under Maintenance..', 'astra-sites' ); ?></h2>
232
- <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly. ', 'astra-sites' ); ?></p>
233
- <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website.', 'astra-sites' ); ?></p>
234
- </div>
235
- </script>
236
-
237
- <?php
238
- /**
239
- * TMPL - Filters
240
- */
241
- ?>
242
- <script type="text/template" id="tmpl-astra-site-filters">
243
-
244
- <# if ( data ) { #>
245
-
246
- <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
247
-
248
- <# if ( data.args.show_all ) { #>
249
- <li>
250
- <a href="#" data-group="all"> All </a>
251
- </li>
252
- <# } #>
253
-
254
- <# for ( key in data.items ) { #>
255
- <# if ( data.items[ key ].count ) { #>
256
- <li>
257
- <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}">
258
- {{ data.items[ key ].name }}
259
- </a>
260
- </li>
261
- <# } #>
262
- <# } #>
263
-
264
- </ul>
265
- <# } #>
266
- </script>
267
-
268
- <?php
269
- /**
270
- * TMPL - List
271
- */
272
- ?>
273
- <script type="text/template" id="tmpl-astra-sites-list">
274
-
275
- <# if ( data.items.length ) { #>
276
- <# for ( key in data.items ) { #>
277
-
278
- <div class="theme astra-theme site-single {{ data.items[ key ].status }}" tabindex="0" aria-describedby="astra-theme-action astra-theme-name"
279
- data-demo-id="{{{ data.items[ key ].id }}}"
280
- data-demo-type="{{{ data.items[ key ]['astra-site-type'] }}}"
281
- data-demo-url="{{{ data.items[ key ]['astra-site-url'] }}}"
282
- data-demo-api="{{{ data.items[ key ]['_links']['self'][0]['href'] }}}"
283
- data-demo-name="{{{ data.items[ key ].title.rendered }}}"
284
- data-demo-slug="{{{ data.items[ key ].slug }}}"
285
- data-screenshot="{{{ data.items[ key ]['featured-image-url'] }}}"
286
- data-content="{{{ data.items[ key ].content.rendered }}}"
287
- data-required-plugins="{{ JSON.stringify( data.items[ key ]['required-plugins'] ) }}"
288
- data-groups=["{{ data.items[ key ].tags }}"]>
289
- <input type="hidden" class="astra-site-options" value="{{ JSON.stringify(data.items[ key ]['astra-site-options-data'] ) }}" />
290
- <input type="hidden" class="astra-enabled-extensions" value="{{ JSON.stringify(data.items[ key ]['astra-enabled-extensions'] ) }}" />
291
-
292
- <div class="inner">
293
- <span class="site-preview" data-href="{{ data.items[ key ]['astra-site-url'] }}?TB_iframe=true&width=600&height=550" data-title="{{ data.items[ key ].title.rendered }}">
294
- <div class="theme-screenshot">
295
- <# if( '' !== data.items[ key ]['featured-image-url'] ) { #>
296
- <img src="{{ data.items[ key ]['featured-image-url'] }}" />
297
- <# } #>
298
- </div>
299
- </span>
300
- <span class="more-details"> <?php esc_html_e( 'Details &amp; Preview', 'astra-sites' ); ?> </span>
301
- <# if ( data.items[ key ]['astra-site-type'] ) { #>
302
- <# var type = ( data.items[ key ]['astra-site-type'] !== 'premium' ) ? ( data.items[ key ]['astra-site-type'] ) : 'agency'; #>
303
- <span class="site-type {{data.items[ key ]['astra-site-type']}}">{{ type }}</span>
304
- <# } #>
305
- <# if ( data.items[ key ].status ) { #>
306
- <span class="status {{data.items[ key ].status}}">{{data.items[ key ].status}}</span>
307
- <# } #>
308
- <div class="theme-id-container">
309
- <h3 class="theme-name" id="astra-theme-name"> {{{ data.items[ key ].title.rendered }}} </h3>
310
- <div class="theme-actions">
311
- <button class="button preview install-theme-preview"><?php esc_html_e( 'Preview', 'astra-sites' ); ?></button>
312
- </div>
313
- </div>
314
- </div>
315
- </div>
316
- <# } #>
317
- <# } else { #>
318
- <p class="no-themes" style="display:block;">
319
- <?php _e( 'No Demos found, Try a different search.', 'astra-sites' ); ?>
320
- <span class="description">
321
- <?php
322
- /* translators: %1$s External Link */
323
- printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
324
- ?>
325
- </span>
326
- </p>
327
- <# } #>
328
- </script>
329
-
330
- <?php
331
- /**
332
- * TMPL - List
333
- */
334
- ?>
335
- <script type="text/template" id="tmpl-astra-sites-suggestions">
336
- <div class="theme astra-theme site-single astra-sites-suggestions">
337
- <div class="inner">
338
- <p>
339
- <?php
340
- /* translators: %1$s External Link */
341
- printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
342
- ?>
343
- </p>
344
- </div>
345
- </div>
346
- </script>
347
- <?php
348
- wp_print_admin_notice_templates();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Shortcode Markup
4
+ *
5
+ * TMPL - Single Demo Preview
6
+ * TMPL - No more demos
7
+ * TMPL - Filters
8
+ * TMPL - List
9
+ *
10
+ * @package Astra Sites
11
+ * @since 1.0.0
12
+ */
13
+
14
+ defined( 'ABSPATH' ) or exit;
15
+ ?>
16
+
17
+ <div class="wrap" id="astra-sites-admin">
18
+
19
+ <div id="astra-sites-filters">
20
+
21
+ <?php if ( apply_filters( 'astra_sites_show_filters', true ) ) { ?>
22
+ <div class="wp-filter hide-if-no-js">
23
+ <div class="section-left">
24
+
25
+ <!-- All Filters -->
26
+ <div class="filter-count">
27
+ <span class="count"></span>
28
+ </div>
29
+ <div class="filters-wrap" style="display: none;">
30
+ <div id="astra-site-page-builder"></div>
31
+ </div>
32
+ <div class="filters-wrap">
33
+ <div id="astra-site-category"></div>
34
+ </div>
35
+
36
+ </div>
37
+
38
+ <div class="section-right">
39
+
40
+ <div class="search-form">
41
+ <label class="screen-reader-text" for="wp-filter-search-input"><?php _e( 'Search Sites', 'astra-sites' ); ?> </label>
42
+ <input placeholder="<?php _e( 'Search Sites...', 'astra-sites' ); ?>" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
43
+ </div>
44
+
45
+ </div>
46
+ </div>
47
+ <?php } ?>
48
+
49
+ </div>
50
+
51
+ <?php do_action( 'astra_sites_before_site_grid' ); ?>
52
+
53
+ <div class="theme-browser rendered">
54
+ <div id="astra-sites" class="themes wp-clearfix"></div>
55
+ </div>
56
+
57
+ <div class="spinner-wrap">
58
+ <span class="spinner"></span>
59
+ </div>
60
+
61
+ <?php do_action( 'astra_sites_after_site_grid' ); ?>
62
+
63
+ </div>
64
+
65
+ <?php
66
+ /**
67
+ * TMPL - Pro Site Description
68
+ */
69
+ ?>
70
+ <script type="text/template" id="tmpl-astra-sites-pro-site-description">
71
+ <p><?php _e( 'Liked this demo?', 'astra-sites' ); ?></p>
72
+ <p>
73
+ <?php
74
+ /* translators: %s is pricing page link */
75
+ printf( __( 'It is a premium website demo which is available only with the Agency Bundles <a href="%s" target="_blank">Buy Now!</a>', 'astra-sites' ), 'https://wpastra.com/pricing/' );
76
+ ?>
77
+ </p>
78
+ <p>
79
+ <?php
80
+ /* translators: %s is article link */
81
+ printf( __( 'Already own an Agency Bundle? Read an article to know how you can <a href="%s" target="_blank">import a premium website demo</a>.', 'astra-sites' ), 'https://wpastra.com/docs/import-astra-agency-website-demos/' );
82
+ ?>
83
+ </p>
84
+ </script>
85
+
86
+ <?php
87
+ /**
88
+ * TMPL - Pro Site Description for Inactive license
89
+ */
90
+ ?>
91
+ <script type="text/template" id="tmpl-astra-sites-pro-inactive-site-description">
92
+ <p><?php _e( 'You are just 2 minutes away from importing this demo!', 'astra-sites' ); ?></p>
93
+ <p><?php _e( 'It is a premium website demo and you need to activate the license to access it.', 'astra-sites' ); ?></p>
94
+ <p>
95
+ <?php
96
+ /* translators: %s is article link */
97
+ printf( __( 'Learn how you can <a href="%s" target="_blank">activate the license</a> of the Astra Premium Sites plugin.', 'astra-sites' ), 'https://wpastra.com/docs/activate-license-for-astra-premium-sites-plugin/' );
98
+ ?>
99
+ </p>
100
+ </script>
101
+
102
+ <?php
103
+ /**
104
+ * TMPL - Single Demo Preview
105
+ */
106
+ ?>
107
+ <script type="text/template" id="tmpl-astra-site-select-page-builder">
108
+ <div class="select-page-builder">
109
+ <div class="note-wrap">
110
+ <h3>
111
+ <span class="up-arrow dashicons dashicons-editor-break"></span>
112
+ <div class="note"><?php _e( 'Select Your Favorite Page Builder', 'astra-sites' ); ?></div>
113
+ </h3>
114
+ </div>
115
+ <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' ); ?>" />
116
+ </div>
117
+ </script>
118
+
119
+ <?php
120
+ /**
121
+ * TMPL - Single Demo Preview
122
+ */
123
+ ?>
124
+ <script type="text/template" id="tmpl-astra-site-preview">
125
+ <div class="astra-sites-preview theme-install-overlay wp-full-overlay expanded">
126
+ <div class="wp-full-overlay-sidebar">
127
+ <div class="wp-full-overlay-header"
128
+ data-demo-id="{{{data.id}}}"
129
+ data-demo-type="{{{data.astra_demo_type}}}"
130
+ data-demo-url="{{{data.astra_demo_url}}}"
131
+ data-demo-api="{{{data.demo_api}}}"
132
+ data-demo-name="{{{data.demo_name}}}"
133
+ data-demo-slug="{{{data.slug}}}"
134
+ data-screenshot="{{{data.screenshot}}}"
135
+ data-content="{{{data.content}}}"
136
+ data-required-plugins="{{data.required_plugins}}">
137
+ <input type="hidden" class="astra-site-options" value="{{data.astra_site_options}}" >
138
+ <input type="hidden" class="astra-enabled-extensions" value="{{data.astra_enabled_extensions}}" >
139
+ <button class="close-full-overlay"><span class="screen-reader-text"><?php esc_html_e( 'Close', 'astra-sites' ); ?></span></button>
140
+ <button class="previous-theme"><span class="screen-reader-text"><?php esc_html_e( 'Previous', 'astra-sites' ); ?></span></button>
141
+ <button class="next-theme"><span class="screen-reader-text"><?php esc_html_e( 'Next', 'astra-sites' ); ?></span></button>
142
+ <!-- <a class="button hide-if-no-customize astra-site-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a> -->
143
+ <a class="button hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled"><?php esc_html_e( 'Import Site', 'astra-sites' ); ?></a>
144
+
145
+ </div>
146
+ <div class="wp-full-overlay-sidebar-content">
147
+ <div class="install-theme-info">
148
+
149
+ <span class="site-type {{{data.astra_demo_type}}}">{{{data.astra_demo_type}}}</span>
150
+ <h3 class="theme-name">{{{data.demo_name}}}</h3>
151
+
152
+ <# if ( data.screenshot.length ) { #>
153
+ <img class="theme-screenshot" src="{{{data.screenshot}}}" alt="">
154
+ <# } #>
155
+
156
+ <div class="theme-details">
157
+ {{{data.content}}}
158
+ </div>
159
+ <a href="#" class="theme-details-read-more"><?php _e( 'Read more', 'astra-sites' ); ?> &hellip;</a>
160
+
161
+ <div class="astra-sites-advanced-options-wrap">
162
+
163
+ <h4><?php _e( 'Plugins Used in This Starter Site', 'astra-sites' ); ?></h4>
164
+ <ul class="required-plugins-list"><span class="spinner is-active"></span></ul>
165
+ <p><?php _e( 'These plugins will be installed when you import this site.', 'astra-sites' ); ?></p>
166
+
167
+ <hr style="border-top: 1px solid #eee;border-bottom: none;margin-top: 1em;">
168
+
169
+ <div class="astra-sites-advanced-options">
170
+
171
+ <ul class="astra-site-contents">
172
+ <li class="astra-sites-import-customizer">
173
+ <label>
174
+ <input type="checkbox" name="customizer" checked="checked" class="checkbox">
175
+ <strong>Import Customizer Settings</strong>
176
+ <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-customizer-settings"><span class="dashicons dashicons-editor-help"></span></span>
177
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-customizer-settings" style="display: none;"><p><?php _e( 'Customizer is what gives a design to the website; and selecting this option replaces your current design with a new one. <br/>Backup of current customizer settings will be stored in "wp-content/astra-sites" directory, just in case if you want to restore it later.', 'astra-sites' ); ?></p></div>
178
+ </label>
179
+ </li>
180
+ <li class="astra-sites-import-xml">
181
+ <label>
182
+ <input type="checkbox" name="xml" checked="checked" class="checkbox">
183
+ <strong>Import Content</strong>
184
+ </label>
185
+ <span class="astra-sites-tooltip-icon" data-tip-id="astra-sites-tooltip-site-content"><span class="dashicons dashicons-editor-help"></span></span>
186
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-site-content" style="display: none;"><p><?php _e( 'Selecting this option will import dummy pages, posts, images and menus. If you do not want to import dummy content, please uncheck this option.', 'astra-sites' ); ?></p></div>
187
+ </li>
188
+ <li class="astra-sites-import-widgets">
189
+ <label>
190
+ <input type="checkbox" name="widgets" checked="checked" class="checkbox">
191
+ <strong>Import Widgets</strong>
192
+ </label>
193
+ </li>
194
+ </ul>
195
+ </div>
196
+
197
+ <ul>
198
+ <li class="astra-sites-reset-data">
199
+ <label>
200
+ <input type="checkbox" name="reset" class="checkbox">
201
+ <strong>Delete Previously Imported Site</strong>
202
+ <div class="astra-sites-tooltip-message" id="astra-sites-tooltip-reset-data" style="display: none;"><p><?php _e( 'WARNING: Selecting this option will delete data from your current website. Choose this option only if this is intended.', 'astra-sites' ); ?></p></div>
203
+ </label>
204
+ </li>
205
+ </ul>
206
+
207
+ <!-- <p><a href="#" class="astra-sites-advanced-options-button"><?php _e( 'Advanced Options', 'astra-sites' ); ?></a></p> -->
208
+
209
+ </div>
210
+
211
+ <!-- <div class="astra-sites-advanced-options">
212
+ <h4><?php _e( 'Required Plugins', 'astra-sites' ); ?> </h4>
213
+ <div class="required-plugins"></div>
214
+ </div> -->
215
+ </div>
216
+ </div>
217
+
218
+ <div class="wp-full-overlay-footer">
219
+ <div class="footer-import-button-wrap">
220
+ <a class="button button-hero hide-if-no-customize button-primary astra-demo-import" href="#" data-import="disabled">
221
+ <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
222
+ <span class="percent"></span>
223
+ </a>
224
+ <div id="astra-site-import-process-wrap" style="display: none;">
225
+ <progress id="astra-site-import-process" max="100" value="0"></progress>
226
+ <!-- <span id="astra-site-import-process-text"></span> -->
227
+ </div>
228
+ <!-- <a class="button button-hero hide-if-no-customize astra-site-import" href="#">
229
+ <?php esc_html_e( 'Import Site', 'astra-sites' ); ?>
230
+ </a> -->
231
+ </div>
232
+ <button type="button" class="collapse-sidebar button" aria-expanded="true"
233
+ aria-label="Collapse Sidebar">
234
+ <span class="collapse-sidebar-arrow"></span>
235
+ <span class="collapse-sidebar-label"><?php esc_html_e( 'Collapse', 'astra-sites' ); ?></span>
236
+ </button>
237
+
238
+ <div class="devices-wrapper">
239
+ <div class="devices">
240
+ <button type="button" class="preview-desktop active" aria-pressed="true" data-device="desktop">
241
+ <span class="screen-reader-text"><?php _e( 'Enter desktop preview mode', 'astra-sites' ); ?></span>
242
+ </button>
243
+ <button type="button" class="preview-tablet" aria-pressed="false" data-device="tablet">
244
+ <span class="screen-reader-text"><?php _e( 'Enter tablet preview mode', 'astra-sites' ); ?></span>
245
+ </button>
246
+ <button type="button" class="preview-mobile" aria-pressed="false" data-device="mobile">
247
+ <span class="screen-reader-text"><?php _e( 'Enter mobile preview mode', 'astra-sites' ); ?></span>
248
+ </button>
249
+ </div>
250
+ </div>
251
+
252
+ </div>
253
+ </div>
254
+ <div class="wp-full-overlay-main">
255
+ <iframe src="{{{data.astra_demo_url}}}" title="<?php esc_attr_e( 'Preview', 'astra-sites' ); ?>"></iframe>
256
+ </div>
257
+ </div>
258
+ </script>
259
+
260
+ <?php
261
+ /**
262
+ * TMPL - No more demos
263
+ */
264
+ ?>
265
+ <script type="text/template" id="tmpl-astra-site-api-request-failed">
266
+ <div class="no-themes">
267
+ <?php
268
+
269
+ /* translators: %1$s & %2$s are a Demo API URL */
270
+ printf( __( '<p> It seems the demo data server, <i><a href="%1$s">%2$s</a></i> is unreachable from your site.</p>', 'astra-sites' ), esc_url( Astra_Sites::$api_url ), esc_url( Astra_Sites::$api_url ) );
271
+
272
+ _e( '<p class="left-margin"> 1. Sometimes, simple page reload fixes any temporary issues. No kidding!</p>', 'astra-sites' );
273
+
274
+ _e( '<p class="left-margin"> 2. If that does not work, you will need to talk to your server administrator and check if demo server is being blocked by the firewall!</p>', 'astra-sites' );
275
+
276
+ /* translators: %1$s is a support link */
277
+ printf( __( '<p>If that does not help, please open up a <a href="%1$s" target="_blank">Support Ticket</a> and we will be glad take a closer look for you.</p>', 'astra-sites' ), esc_url( 'https://wpastra.com/support/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=api-request-failed' ) );
278
+ ?>
279
+ </div>
280
+ </script>
281
+
282
+ <?php
283
+ /**
284
+ * TMPL - Site Down
285
+ */
286
+ ?>
287
+ <script type="text/template" id="tmpl-astra-site-down">
288
+ <div class="postbox astra-site-down">
289
+ <h2><?php _e( 'Under Maintenance..', 'astra-sites' ); ?></h2>
290
+ <p><?php _e( 'If you are seeing this message, most likely our servers are under routine maintenance and we will be back shortly. ', 'astra-sites' ); ?></p>
291
+ <p><?php _e( 'In rare case, it is possible your website is having trouble connecting with ours. If you need help, please feel free to get in touch with us from our website.', 'astra-sites' ); ?></p>
292
+ </div>
293
+ </script>
294
+
295
+ <?php
296
+ /**
297
+ * TMPL - Filters
298
+ */
299
+ ?>
300
+ <script type="text/template" id="tmpl-astra-site-filters">
301
+
302
+ <# if ( data ) { #>
303
+
304
+ <ul class="{{ data.args.wrapper_class }} {{ data.args.class }}">
305
+
306
+ <# if ( data.args.show_all ) { #>
307
+ <li>
308
+ <a href="#" data-group="all"> All </a>
309
+ </li>
310
+ <# } #>
311
+
312
+ <# for ( key in data.items ) { #>
313
+ <# if ( data.items[ key ].count ) { #>
314
+ <li>
315
+ <a href="#" data-group='{{ data.items[ key ].id }}' class="{{ data.items[ key ].name }}">
316
+ {{ data.items[ key ].name }}
317
+ </a>
318
+ </li>
319
+ <# } #>
320
+ <# } #>
321
+
322
+ </ul>
323
+ <# } #>
324
+ </script>
325
+
326
+ <?php
327
+ /**
328
+ * TMPL - List
329
+ */
330
+ ?>
331
+ <script type="text/template" id="tmpl-astra-sites-list">
332
+
333
+ <# if ( data.items.length ) { #>
334
+ <# for ( key in data.items ) { #>
335
+
336
+ <div class="theme astra-theme site-single {{ data.items[ key ].status }}" tabindex="0" aria-describedby="astra-theme-action astra-theme-name"
337
+ data-demo-id="{{{ data.items[ key ].id }}}"
338
+ data-demo-type="{{{ data.items[ key ]['astra-site-type'] }}}"
339
+ data-demo-url="{{{ data.items[ key ]['astra-site-url'] }}}"
340
+ data-demo-api="{{{ data.items[ key ]['_links']['self'][0]['href'] }}}"
341
+ data-demo-name="{{{ data.items[ key ].title.rendered }}}"
342
+ data-demo-slug="{{{ data.items[ key ].slug }}}"
343
+ data-screenshot="{{{ data.items[ key ]['featured-image-url'] }}}"
344
+ data-content="{{{ data.items[ key ].content.rendered }}}"
345
+ data-required-plugins="{{ JSON.stringify( data.items[ key ]['required-plugins'] ) }}"
346
+ data-groups=["{{ data.items[ key ].tags }}"]>
347
+ <input type="hidden" class="astra-site-options" value="{{ JSON.stringify(data.items[ key ]['astra-site-options-data'] ) }}" />
348
+ <input type="hidden" class="astra-enabled-extensions" value="{{ JSON.stringify(data.items[ key ]['astra-enabled-extensions'] ) }}" />
349
+
350
+ <div class="inner">
351
+ <span class="site-preview" data-href="{{ data.items[ key ]['astra-site-url'] }}?TB_iframe=true&width=600&height=550" data-title="{{ data.items[ key ].title.rendered }}">
352
+ <div class="theme-screenshot" style="background-image: url('{{ data.items[ key ]['featured-image-url'] }}');"></div>
353
+ </span>
354
+ <# if ( data.items[ key ]['astra-site-type'] ) { #>
355
+ <# var type = ( data.items[ key ]['astra-site-type'] !== 'premium' ) ? ( data.items[ key ]['astra-site-type'] ) : 'agency'; #>
356
+ <span class="site-type {{data.items[ key ]['astra-site-type']}}">{{ type }}</span>
357
+ <# } #>
358
+ <# if ( data.items[ key ].status ) { #>
359
+ <span class="status {{data.items[ key ].status}}">{{data.items[ key ].status}}</span>
360
+ <# } #>
361
+ <div class="theme-id-container">
362
+ <h3 class="theme-name" id="astra-theme-name"> {{{ data.items[ key ].title.rendered }}} </h3>
363
+ <div class="theme-actions">
364
+ <button class="button-primary button preview install-theme-preview"><?php esc_html_e( 'Preview', 'astra-sites' ); ?></button>
365
+ </div>
366
+ </div>
367
+ </div>
368
+ </div>
369
+ <# } #>
370
+ <# } else { #>
371
+ <p class="no-themes" style="display:block;">
372
+ <?php _e( 'No Demos found, Try a different search.', 'astra-sites' ); ?>
373
+ <span class="description">
374
+ <?php
375
+ /* translators: %1$s External Link */
376
+ printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
377
+ ?>
378
+ </span>
379
+ </p>
380
+ <# } #>
381
+ </script>
382
+
383
+ <?php
384
+ /**
385
+ * TMPL - List
386
+ */
387
+ ?>
388
+ <script type="text/template" id="tmpl-astra-sites-suggestions">
389
+ <div class="theme astra-theme site-single astra-sites-suggestions">
390
+ <div class="inner">
391
+ <p>
392
+ <?php
393
+ /* translators: %1$s External Link */
394
+ printf( __( 'Don\'t see a site that you would like to import?<br><a target="_blank" href="%1$s">Please suggest us!</a>', 'astra-sites' ), esc_url( 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions' ) );
395
+ ?>
396
+ </p>
397
+ </div>
398
+ </div>
399
+ </script>
400
+ <?php
401
+ wp_print_admin_notice_templates();
languages/astra-sites.pot CHANGED
@@ -1,721 +1,775 @@
1
- # Copyright (C) 2019 Brainstorm Force
2
- # This file is distributed under the same license as the Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates package.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: Astra Starter Sites – Elementor, Beaver Builder & "
6
- "Gutenberg Templates 1.2.14\n"
7
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
8
- "POT-Creation-Date: 2019-03-13 08:33:42+00:00\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=utf-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
13
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
- "Language-Team: LANGUAGE <LL@li.org>\n"
15
- "Language: en\n"
16
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
- "X-Poedit-Country: United States\n"
18
- "X-Poedit-SourceCharset: UTF-8\n"
19
- "X-Poedit-KeywordsList: "
20
- "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
21
- "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
22
- "X-Poedit-Basepath: ../\n"
23
- "X-Poedit-SearchPath-0: .\n"
24
- "X-Poedit-Bookmarks: \n"
25
- "X-Textdomain-Support: yes\n"
26
- "X-Generator: grunt-wp-i18n1.0.0\n"
27
-
28
- #: astra-sites.php:18 inc/classes/class-astra-sites-page.php:85
29
- msgid "Astra Sites"
30
- msgstr ""
31
-
32
- #: inc/classes/class-astra-sites-importer-log.php:352
33
- msgid "Enabled"
34
- msgstr ""
35
-
36
- #: inc/classes/class-astra-sites-importer-log.php:355
37
- msgid "Disabled"
38
- msgstr ""
39
-
40
- #: inc/classes/class-astra-sites-importer-log.php:440
41
- #: inc/classes/class-astra-sites-importer-log.php:497
42
- msgid "Yes"
43
- msgstr ""
44
-
45
- #: inc/classes/class-astra-sites-importer-log.php:443
46
- #: inc/classes/class-astra-sites-importer-log.php:500
47
- msgid "No"
48
- msgstr ""
49
-
50
- #: inc/classes/class-astra-sites-importer.php:88
51
- msgid "You have not \"customize\" access to import the Astra site."
52
- msgstr ""
53
-
54
- #: inc/classes/class-astra-sites-importer.php:112
55
- msgid "Request site API URL is empty. Try again!"
56
- msgstr ""
57
-
58
- #: inc/classes/class-astra-sites-importer.php:204
59
- msgid "Customizer data is empty!"
60
- msgstr ""
61
-
62
- #: inc/classes/class-astra-sites-importer.php:220
63
- msgid ""
64
- "If XMLReader is not available, it imports all other settings and only skips "
65
- "XML import. This creates an incomplete website. We should bail early and "
66
- "not import anything if this is not present."
67
- msgstr ""
68
-
69
- #: inc/classes/class-astra-sites-importer.php:236
70
- msgid "There was an error downloading the XML file."
71
- msgstr ""
72
-
73
- #: inc/classes/class-astra-sites-importer.php:242
74
- msgid "Invalid site XML file!"
75
- msgstr ""
76
-
77
- #: inc/classes/class-astra-sites-importer.php:264
78
- msgid "Site options are empty!"
79
- msgstr ""
80
-
81
- #: inc/classes/class-astra-sites-importer.php:286
82
- msgid "Widget data is empty!"
83
- msgstr ""
84
-
85
- #: inc/classes/class-astra-sites-page.php:113
86
- msgid "Required XMLReader PHP extension is missing on your server!"
87
- msgstr ""
88
-
89
- #: inc/classes/class-astra-sites-page.php:115
90
- #. translators: %s is the white label name.
91
- msgid ""
92
- "%s import requires XMLReader extension to be installed. Please contact your "
93
- "web hosting provider and ask them to install and activate the XMLReader PHP "
94
- "extension."
95
- msgstr ""
96
-
97
- #: inc/classes/class-astra-sites-page.php:216
98
- msgid "Settings saved successfully."
99
- msgstr ""
100
-
101
- #: inc/classes/class-astra-sites-white-label.php:186
102
- #. translators: %1$s product name
103
- msgid "%1$s Branding"
104
- msgstr ""
105
-
106
- #: inc/classes/class-astra-sites.php:81
107
- #. translators: 1: theme.php file
108
- msgid ""
109
- "Astra Theme needs to be active for you to use currently installed \"%1$s\" "
110
- "plugin. <a href=\"%2$s\">Install & Activate Now</a>"
111
- msgstr ""
112
-
113
- #: inc/classes/class-astra-sites.php:121
114
- msgid "See Library"
115
- msgstr ""
116
-
117
- #: inc/classes/class-astra-sites.php:174
118
- msgid "Page Builder"
119
- msgstr ""
120
-
121
- #: inc/classes/class-astra-sites.php:179
122
- msgid "Categories"
123
- msgstr ""
124
-
125
- #: inc/classes/class-astra-sites.php:218
126
- msgid "Get Agency Bundle"
127
- msgstr ""
128
-
129
- #: inc/classes/class-astra-sites.php:220
130
- msgid "Upgrade"
131
- msgstr ""
132
-
133
- #: inc/classes/class-astra-sites.php:227
134
- #. translators: %s are HTML tags.
135
- msgid ""
136
- "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
137
- "Sites import requires XMLReader extension to be installed. Please contact "
138
- "your web hosting provider and ask them to install and activate the "
139
- "XMLReader PHP extension."
140
- msgstr ""
141
-
142
- #: inc/classes/class-astra-sites.php:228
143
- msgid ""
144
- "Warning! Astra Site Import process is not complete. Don't close the window "
145
- "until import process complete. Do you still want to leave the window?"
146
- msgstr ""
147
-
148
- #: inc/classes/class-astra-sites.php:229
149
- msgid "Error!"
150
- msgstr ""
151
-
152
- #: inc/classes/class-astra-sites.php:230
153
- msgid "Error! Read Possibilities."
154
- msgstr ""
155
-
156
- #: inc/classes/class-astra-sites.php:232
157
- msgid "Done! View Site"
158
- msgstr ""
159
-
160
- #: inc/classes/class-astra-sites.php:233
161
- msgid "Activating"
162
- msgstr ""
163
-
164
- #: inc/classes/class-astra-sites.php:234
165
- msgid "Active"
166
- msgstr ""
167
-
168
- #: inc/classes/class-astra-sites.php:235
169
- msgid "Import failed."
170
- msgstr ""
171
-
172
- #: inc/classes/class-astra-sites.php:236
173
- msgid "Import failed. See error log."
174
- msgstr ""
175
-
176
- #: inc/classes/class-astra-sites.php:237
177
- msgid "Import This Site"
178
- msgstr ""
179
-
180
- #: inc/classes/class-astra-sites.php:238 inc/classes/class-astra-sites.php:255
181
- msgid "Importing.."
182
- msgstr ""
183
-
184
- #: inc/classes/class-astra-sites.php:239 inc/includes/admin-page.php:159
185
- msgid "Read more"
186
- msgstr ""
187
-
188
- #: inc/classes/class-astra-sites.php:240
189
- msgid "Hide"
190
- msgstr ""
191
-
192
- #: inc/classes/class-astra-sites.php:241
193
- msgid "There was a problem receiving a response from server."
194
- msgstr ""
195
-
196
- #: inc/classes/class-astra-sites.php:242 inc/includes/admin-page.php:319
197
- msgid "No Demos found, Try a different search."
198
- msgstr ""
199
-
200
- #: inc/classes/class-astra-sites.php:243
201
- msgid ""
202
- "Executing Demo Import will make your site similar as ours. Please bear in "
203
- "mind -\n"
204
- "\n"
205
- "1. It is recommended to run import on a fresh WordPress installation.\n"
206
- "\n"
207
- "2. Importing site does not delete any pages or posts. However, it can "
208
- "overwrite your existing content.\n"
209
- "\n"
210
- "3. Copyrighted media will not be imported. Instead it will be replaced with "
211
- "placeholders."
212
- msgstr ""
213
-
214
- #: inc/classes/class-astra-sites.php:246
215
- msgid "Installing plugin "
216
- msgstr ""
217
-
218
- #: inc/classes/class-astra-sites.php:247
219
- msgid "Successfully plugin installed!"
220
- msgstr ""
221
-
222
- #: inc/classes/class-astra-sites.php:248
223
- msgid "Activating plugin "
224
- msgstr ""
225
-
226
- #: inc/classes/class-astra-sites.php:249
227
- msgid "Successfully plugin activated "
228
- msgstr ""
229
-
230
- #: inc/classes/class-astra-sites.php:250
231
- msgid "Bulk plugin activation..."
232
- msgstr ""
233
-
234
- #: inc/classes/class-astra-sites.php:251
235
- msgid "Successfully plugin activate - "
236
- msgstr ""
237
-
238
- #: inc/classes/class-astra-sites.php:252
239
- msgid "Error! While activating plugin - "
240
- msgstr ""
241
-
242
- #: inc/classes/class-astra-sites.php:253
243
- msgid "Bulk plugin installation..."
244
- msgstr ""
245
-
246
- #: inc/classes/class-astra-sites.php:254
247
- msgid "Site API "
248
- msgstr ""
249
-
250
- #: inc/classes/class-astra-sites.php:256
251
- msgid "Processing requests..."
252
- msgstr ""
253
-
254
- #: inc/classes/class-astra-sites.php:257
255
- msgid "1) Importing \"Customizer Settings\"..."
256
- msgstr ""
257
-
258
- #: inc/classes/class-astra-sites.php:258
259
- msgid "Successfully imported customizer settings!"
260
- msgstr ""
261
-
262
- #: inc/classes/class-astra-sites.php:259
263
- msgid "2) Importing \"WPForms\"..."
264
- msgstr ""
265
-
266
- #: inc/classes/class-astra-sites.php:260
267
- msgid "Successfully imported WPForms!"
268
- msgstr ""
269
-
270
- #: inc/classes/class-astra-sites.php:261
271
- msgid "3) Preparing \"XML\" Data..."
272
- msgstr ""
273
-
274
- #: inc/classes/class-astra-sites.php:262
275
- msgid "Successfully set XML data!"
276
- msgstr ""
277
-
278
- #: inc/classes/class-astra-sites.php:263
279
- msgid "4) Importing \"XML\"..."
280
- msgstr ""
281
-
282
- #: inc/classes/class-astra-sites.php:264
283
- msgid "Successfully imported XML!"
284
- msgstr ""
285
-
286
- #: inc/classes/class-astra-sites.php:265
287
- msgid "5) Importing \"Options\"..."
288
- msgstr ""
289
-
290
- #: inc/classes/class-astra-sites.php:266
291
- msgid "Successfully imported Options!"
292
- msgstr ""
293
-
294
- #: inc/classes/class-astra-sites.php:267
295
- msgid "6) Importing \"Widgets\"..."
296
- msgstr ""
297
-
298
- #: inc/classes/class-astra-sites.php:268
299
- msgid "Successfully imported Widgets!"
300
- msgstr ""
301
-
302
- #: inc/classes/class-astra-sites.php:270
303
- msgid "Site imported successfully! visit : "
304
- msgstr ""
305
-
306
- #: inc/classes/class-astra-sites.php:271
307
- msgid "Getting Site Information.."
308
- msgstr ""
309
-
310
- #: inc/classes/class-astra-sites.php:272
311
- msgid "Importing Customizer Settings.."
312
- msgstr ""
313
-
314
- #: inc/classes/class-astra-sites.php:273
315
- msgid "Importing WP Forms.."
316
- msgstr ""
317
-
318
- #: inc/classes/class-astra-sites.php:274
319
- msgid "Setting up import data.."
320
- msgstr ""
321
-
322
- #: inc/classes/class-astra-sites.php:275
323
- msgid "Importing Pages, Posts & Media.."
324
- msgstr ""
325
-
326
- #: inc/classes/class-astra-sites.php:276
327
- msgid "Importing Site Options.."
328
- msgstr ""
329
-
330
- #: inc/classes/class-astra-sites.php:277
331
- msgid "Importing Widgets.."
332
- msgstr ""
333
-
334
- #: inc/classes/class-astra-sites.php:278
335
- msgid "Import Complete.."
336
- msgstr ""
337
-
338
- #: inc/classes/class-astra-sites.php:279
339
- msgid "Previewing "
340
- msgstr ""
341
-
342
- #: inc/classes/class-astra-sites.php:280
343
- msgid "See Error Log &rarr;"
344
- msgstr ""
345
-
346
- #: inc/classes/class-astra-sites.php:315
347
- msgid "No plugin specified"
348
- msgstr ""
349
-
350
- #: inc/classes/class-astra-sites.php:344
351
- msgid "Plugin Successfully Activated"
352
- msgstr ""
353
-
354
- #: inc/importers/batch-processing/helpers/class-wp-background-process.php:433
355
- msgid "Every %d Minutes"
356
- msgstr ""
357
-
358
- #: inc/importers/class-widgets-importer.php:83
359
- msgid "Import data could not be read. Please try a different file."
360
- msgstr ""
361
-
362
- #: inc/importers/class-widgets-importer.php:127
363
- msgid "Widget area does not exist in theme (using Inactive)"
364
- msgstr ""
365
-
366
- #: inc/importers/class-widgets-importer.php:149
367
- msgid "Site does not support widget"
368
- msgstr ""
369
-
370
- #: inc/importers/class-widgets-importer.php:185
371
- msgid "Widget already exists"
372
- msgstr ""
373
-
374
- #: inc/importers/class-widgets-importer.php:254
375
- msgid "Imported"
376
- msgstr ""
377
-
378
- #: inc/importers/class-widgets-importer.php:257
379
- msgid "Imported to Inactive"
380
- msgstr ""
381
-
382
- #: inc/importers/class-widgets-importer.php:263
383
- msgid "No Title"
384
- msgstr ""
385
-
386
- #: inc/importers/wxr-importer/class-astra-wxr-importer.php:239
387
- msgid "Import complete!"
388
- msgstr ""
389
-
390
- #: inc/importers/wxr-importer/class-wxr-importer.php:131
391
- msgid "Could not open the file for parsing"
392
- msgstr ""
393
-
394
- #: inc/importers/wxr-importer/class-wxr-importer.php:167
395
- #: inc/importers/wxr-importer/class-wxr-importer.php:283
396
- #: inc/importers/wxr-importer/class-wxr-importer.php:356
397
- msgid ""
398
- "This WXR file (version %1$s) is newer than the importer (version %2$s) and "
399
- "may not be supported. Please consider updating."
400
- msgstr ""
401
-
402
- #: inc/importers/wxr-importer/class-wxr-importer.php:504
403
- msgid "The file does not exist, please try again."
404
- msgstr ""
405
-
406
- #: inc/importers/wxr-importer/class-wxr-importer.php:564
407
- msgid "Invalid author mapping"
408
- msgstr ""
409
-
410
- #: inc/importers/wxr-importer/class-wxr-importer.php:665
411
- msgid "Cannot import auto-draft posts"
412
- msgstr ""
413
-
414
- #: inc/importers/wxr-importer/class-wxr-importer.php:753
415
- msgid "Failed to import \"%1$s\": Invalid post type %2$s"
416
- msgstr ""
417
-
418
- #: inc/importers/wxr-importer/class-wxr-importer.php:763
419
- msgid "%1$s \"%2$s\" already exists."
420
- msgstr ""
421
-
422
- #: inc/importers/wxr-importer/class-wxr-importer.php:857
423
- msgid "Skipping attachment \"%s\", fetching attachments disabled"
424
- msgstr ""
425
-
426
- #: inc/importers/wxr-importer/class-wxr-importer.php:878
427
- msgid "Failed to import \"%1$s\" (%2$s)"
428
- msgstr ""
429
-
430
- #: inc/importers/wxr-importer/class-wxr-importer.php:910
431
- #: inc/importers/wxr-importer/class-wxr-importer.php:1755
432
- msgid "Imported \"%1$s\" (%2$s)"
433
- msgstr ""
434
-
435
- #: inc/importers/wxr-importer/class-wxr-importer.php:915
436
- msgid "Post %1$d remapped to %2$d"
437
- msgstr ""
438
-
439
- #: inc/importers/wxr-importer/class-wxr-importer.php:1062
440
- msgid "Invalid file type"
441
- msgstr ""
442
-
443
- #: inc/importers/wxr-importer/class-wxr-importer.php:1560
444
- msgid "Failed to import user \"%s\""
445
- msgstr ""
446
-
447
- #: inc/importers/wxr-importer/class-wxr-importer.php:1581
448
- msgid "Imported user \"%s\""
449
- msgstr ""
450
-
451
- #: inc/importers/wxr-importer/class-wxr-importer.php:1585
452
- msgid "User %1$d remapped to %2$d"
453
- msgstr ""
454
-
455
- #: inc/importers/wxr-importer/class-wxr-importer.php:1731
456
- msgid "Failed to import %1$s %2$s"
457
- msgstr ""
458
-
459
- #: inc/importers/wxr-importer/class-wxr-importer.php:1760
460
- msgid "Term %1$d remapped to %2$d"
461
- msgstr ""
462
-
463
- #: inc/importers/wxr-importer/class-wxr-importer.php:1813
464
- msgid "Remote server returned %1$d %2$s for %3$s"
465
- msgstr ""
466
-
467
- #: inc/importers/wxr-importer/class-wxr-importer.php:1826
468
- msgid "Remote file is incorrect size"
469
- msgstr ""
470
-
471
- #: inc/importers/wxr-importer/class-wxr-importer.php:1831
472
- msgid "Zero size file downloaded"
473
- msgstr ""
474
-
475
- #: inc/importers/wxr-importer/class-wxr-importer.php:1837
476
- msgid "Remote file is too large, limit is %s"
477
- msgstr ""
478
-
479
- #: inc/importers/wxr-importer/class-wxr-importer.php:1859
480
- msgid "Running post-processing for post %d"
481
- msgstr ""
482
-
483
- #: inc/importers/wxr-importer/class-wxr-importer.php:1872
484
- msgid "Could not find the post parent for \"%1$s\" (post #%2$d)"
485
- msgstr ""
486
-
487
- #: inc/importers/wxr-importer/class-wxr-importer.php:1877
488
- msgid "Post %1$d was imported with parent %2$d, but could not be found"
489
- msgstr ""
490
-
491
- #: inc/importers/wxr-importer/class-wxr-importer.php:1891
492
- msgid "Could not find the author for \"%1$s\" (post #%2$d)"
493
- msgstr ""
494
-
495
- #: inc/importers/wxr-importer/class-wxr-importer.php:1896
496
- msgid "Post %1$d was imported with author \"%2$s\", but could not be found"
497
- msgstr ""
498
-
499
- #: inc/importers/wxr-importer/class-wxr-importer.php:1922
500
- msgid "Post %d was marked for post-processing, but none was required."
501
- msgstr ""
502
-
503
- #: inc/importers/wxr-importer/class-wxr-importer.php:1933
504
- msgid "Could not update \"%1$s\" (post #%2$d) with mapped data"
505
- msgstr ""
506
-
507
- #: inc/importers/wxr-importer/class-wxr-importer.php:1978
508
- msgid "Could not find the menu object for \"%1$s\" (post #%2$d)"
509
- msgstr ""
510
-
511
- #: inc/importers/wxr-importer/class-wxr-importer.php:1983
512
- msgid ""
513
- "Post %1$d was imported with object \"%2$d\" of type \"%3$s\", but could not "
514
- "be found"
515
- msgstr ""
516
-
517
- #: inc/importers/wxr-importer/class-wxr-importer.php:2005
518
- msgid "Could not find the comment parent for comment #%d"
519
- msgstr ""
520
-
521
- #: inc/importers/wxr-importer/class-wxr-importer.php:2009
522
- msgid "Comment %1$d was imported with parent %2$d, but could not be found"
523
- msgstr ""
524
-
525
- #: inc/importers/wxr-importer/class-wxr-importer.php:2023
526
- msgid "Could not find the author for comment #%d"
527
- msgstr ""
528
-
529
- #: inc/importers/wxr-importer/class-wxr-importer.php:2027
530
- msgid "Comment %1$d was imported with author %2$d, but could not be found"
531
- msgstr ""
532
-
533
- #: inc/importers/wxr-importer/class-wxr-importer.php:2044
534
- msgid "Could not update comment #%d with mapped data"
535
- msgstr ""
536
-
537
- #: inc/includes/admin-page.php:42
538
- msgid "Search Sites"
539
- msgstr ""
540
-
541
- #: inc/includes/admin-page.php:43
542
- msgid "Search Sites..."
543
- msgstr ""
544
-
545
- #: inc/includes/admin-page.php:72
546
- msgid "Liked this demo?"
547
- msgstr ""
548
-
549
- #: inc/includes/admin-page.php:76
550
- #. translators: %s is pricing page link
551
- msgid ""
552
- "It is a premium website demo which is available only with the Agency "
553
- "Bundles <a href=\"%s\" target=\"_blank\">Buy Now!</a>"
554
- msgstr ""
555
-
556
- #: inc/includes/admin-page.php:82
557
- #. translators: %s is article link
558
- msgid ""
559
- "Already own an Agency Bundle? Read an article to know how you can <a "
560
- "href=\"%s\" target=\"_blank\">import a premium website demo</a>."
561
- msgstr ""
562
-
563
- #: inc/includes/admin-page.php:93
564
- msgid "You are just 2 minutes away from importing this demo!"
565
- msgstr ""
566
-
567
- #: inc/includes/admin-page.php:94
568
- msgid ""
569
- "It is a premium website demo and you need to activate the license to access "
570
- "it."
571
- msgstr ""
572
-
573
- #: inc/includes/admin-page.php:98
574
- #. translators: %s is article link
575
- msgid ""
576
- "Learn how you can <a href=\"%s\" target=\"_blank\">activate the license</a> "
577
- "of the Astra Premium Sites plugin."
578
- msgstr ""
579
-
580
- #: inc/includes/admin-page.php:113
581
- msgid "Select Your Favorite Page Builder"
582
- msgstr ""
583
-
584
- #: inc/includes/admin-page.php:116
585
- msgid "Sites List.."
586
- msgstr ""
587
-
588
- #: inc/includes/admin-page.php:140
589
- msgid "Close"
590
- msgstr ""
591
-
592
- #: inc/includes/admin-page.php:141
593
- msgid "Previous"
594
- msgstr ""
595
-
596
- #: inc/includes/admin-page.php:142
597
- msgid "Next"
598
- msgstr ""
599
-
600
- #: inc/includes/admin-page.php:143 inc/includes/admin-page.php:171
601
- msgid "Install Plugins"
602
- msgstr ""
603
-
604
- #: inc/includes/admin-page.php:162
605
- msgid "Required Plugins"
606
- msgstr ""
607
-
608
- #: inc/includes/admin-page.php:177
609
- msgid "Collapse"
610
- msgstr ""
611
-
612
- #: inc/includes/admin-page.php:183
613
- msgid "Enter desktop preview mode"
614
- msgstr ""
615
-
616
- #: inc/includes/admin-page.php:186
617
- msgid "Enter tablet preview mode"
618
- msgstr ""
619
-
620
- #: inc/includes/admin-page.php:189
621
- msgid "Enter mobile preview mode"
622
- msgstr ""
623
-
624
- #: inc/includes/admin-page.php:197 inc/includes/admin-page.php:311
625
- msgid "Preview"
626
- msgstr ""
627
-
628
- #: inc/includes/admin-page.php:212
629
- #. translators: %1$s & %2$s are a Demo API URL
630
- msgid ""
631
- "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
632
- "unreachable from your site.</p>"
633
- msgstr ""
634
-
635
- #: inc/includes/admin-page.php:214
636
- msgid ""
637
- "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
638
- "temporary issues. No kidding!</p>"
639
- msgstr ""
640
-
641
- #: inc/includes/admin-page.php:216
642
- msgid ""
643
- "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
644
- "to your server administrator and check if demo server is being blocked by "
645
- "the firewall!</p>"
646
- msgstr ""
647
-
648
- #: inc/includes/admin-page.php:219
649
- #. translators: %1$s is a support link
650
- msgid ""
651
- "<p>If that does not help, please open up a <a href=\"%1$s\" "
652
- "target=\"_blank\">Support Ticket</a> and we will be glad take a closer look "
653
- "for you.</p>"
654
- msgstr ""
655
-
656
- #: inc/includes/admin-page.php:231
657
- msgid "Under Maintenance.."
658
- msgstr ""
659
-
660
- #: inc/includes/admin-page.php:232
661
- msgid ""
662
- "If you are seeing this message, most likely our servers are under routine "
663
- "maintenance and we will be back shortly. "
664
- msgstr ""
665
-
666
- #: inc/includes/admin-page.php:233
667
- msgid ""
668
- "In rare case, it is possible your website is having trouble connecting with "
669
- "ours. If you need help, please feel free to get in touch with us from our "
670
- "website."
671
- msgstr ""
672
-
673
- #: inc/includes/admin-page.php:300
674
- msgid "Details &amp; Preview"
675
- msgstr ""
676
-
677
- #: inc/includes/admin-page.php:323 inc/includes/admin-page.php:341
678
- #. translators: %1$s External Link
679
- msgid ""
680
- "Don't see a site that you would like to import?<br><a target=\"_blank\" "
681
- "href=\"%1$s\">Please suggest us!</a>"
682
- msgstr ""
683
-
684
- #: inc/includes/white-label.php:29
685
- msgid "Plugin Name:"
686
- msgstr ""
687
-
688
- #: inc/includes/white-label.php:34
689
- msgid "Plugin Description:"
690
- msgstr ""
691
-
692
- #. Plugin Name of the plugin/theme
693
- msgid "Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates"
694
- msgstr ""
695
-
696
- #. Plugin URI of the plugin/theme
697
- msgid "http://www.wpastra.com/pro/"
698
- msgstr ""
699
-
700
- #. Description of the plugin/theme
701
- msgid "Import free sites build with Astra theme."
702
- msgstr ""
703
-
704
- #. Author of the plugin/theme
705
- msgid "Brainstorm Force"
706
- msgstr ""
707
-
708
- #. Author URI of the plugin/theme
709
- msgid "http://www.brainstormforce.com"
710
- msgstr ""
711
-
712
- #: inc/classes/class-astra-sites-importer-log.php:373
713
- #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
714
- msgctxt "Recommended Memory Limit"
715
- msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
716
- msgstr ""
717
-
718
- #: inc/classes/class-astra-sites-importer-log.php:454
719
- msgctxt "PHP Version"
720
- msgid "We recommend to use php 5.4 or higher"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
721
  msgstr ""
1
+ # Copyright (C) 2019 Brainstorm Force
2
+ # This file is distributed under the same license as the Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Astra Starter Sites – Elementor, Beaver Builder & "
6
+ "Gutenberg Templates 1.3.0\n"
7
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
8
+ "POT-Creation-Date: 2019-03-26 14:01:59+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=utf-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: en\n"
16
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
17
+ "X-Poedit-Country: United States\n"
18
+ "X-Poedit-SourceCharset: UTF-8\n"
19
+ "X-Poedit-KeywordsList: "
20
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
21
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
22
+ "X-Poedit-Basepath: ../\n"
23
+ "X-Poedit-SearchPath-0: .\n"
24
+ "X-Poedit-Bookmarks: \n"
25
+ "X-Textdomain-Support: yes\n"
26
+ "X-Generator: grunt-wp-i18n1.0.0\n"
27
+
28
+ #: astra-sites.php:18 inc/classes/class-astra-sites-page.php:319
29
+ msgid "Astra Sites"
30
+ msgstr ""
31
+
32
+ #: inc/classes/class-astra-sites-importer-log.php:443
33
+ msgid "Enabled"
34
+ msgstr ""
35
+
36
+ #: inc/classes/class-astra-sites-importer-log.php:446
37
+ msgid "Disabled"
38
+ msgstr ""
39
+
40
+ #: inc/classes/class-astra-sites-importer-log.php:531
41
+ #: inc/classes/class-astra-sites-importer-log.php:588
42
+ msgid "Yes"
43
+ msgstr ""
44
+
45
+ #: inc/classes/class-astra-sites-importer-log.php:534
46
+ #: inc/classes/class-astra-sites-importer-log.php:591
47
+ msgid "No"
48
+ msgstr ""
49
+
50
+ #: inc/classes/class-astra-sites-importer.php:98
51
+ msgid "You have not \"customize\" access to import the Astra site."
52
+ msgstr ""
53
+
54
+ #: inc/classes/class-astra-sites-importer.php:122
55
+ msgid "Request site API URL is empty. Try again!"
56
+ msgstr ""
57
+
58
+ #: inc/classes/class-astra-sites-importer.php:223
59
+ msgid "Customizer data is empty!"
60
+ msgstr ""
61
+
62
+ #: inc/classes/class-astra-sites-importer.php:237
63
+ msgid ""
64
+ "If XMLReader is not available, it imports all other settings and only skips "
65
+ "XML import. This creates an incomplete website. We should bail early and "
66
+ "not import anything if this is not present."
67
+ msgstr ""
68
+
69
+ #: inc/classes/class-astra-sites-importer.php:255
70
+ msgid "There was an error downloading the XML file."
71
+ msgstr ""
72
+
73
+ #: inc/classes/class-astra-sites-importer.php:261
74
+ msgid "Invalid site XML file!"
75
+ msgstr ""
76
+
77
+ #: inc/classes/class-astra-sites-importer.php:290
78
+ msgid "Site options are empty!"
79
+ msgstr ""
80
+
81
+ #: inc/classes/class-astra-sites-importer.php:321
82
+ msgid "Widget data is empty!"
83
+ msgstr ""
84
+
85
+ #: inc/classes/class-astra-sites-importer.php:522
86
+ #. translators: %s is the post ID
87
+ msgid "Post ID %s deleted!"
88
+ msgstr ""
89
+
90
+ #: inc/classes/class-astra-sites-importer.php:541
91
+ #. translators: %s is the form ID
92
+ msgid "Form ID %s deleted!"
93
+ msgstr ""
94
+
95
+ #: inc/classes/class-astra-sites-importer.php:563
96
+ #. translators: %s is the term ID
97
+ msgid "Term ID %s deleted!"
98
+ msgstr ""
99
+
100
+ #: inc/classes/class-astra-sites-page.php:156
101
+ msgid "Required XMLReader PHP extension is missing on your server!"
102
+ msgstr ""
103
+
104
+ #: inc/classes/class-astra-sites-page.php:158
105
+ #. translators: %s is the white label name.
106
+ msgid ""
107
+ "%s import requires XMLReader extension to be installed. Please contact your "
108
+ "web hosting provider and ask them to install and activate the XMLReader PHP "
109
+ "extension."
110
+ msgstr ""
111
+
112
+ #: inc/classes/class-astra-sites-page.php:220
113
+ msgid "Settings saved successfully."
114
+ msgstr ""
115
+
116
+ #: inc/classes/class-astra-sites-page.php:235
117
+ #: inc/classes/class-astra-sites-page.php:256
118
+ msgid "Block Editor (Gutenberg)"
119
+ msgstr ""
120
+
121
+ #: inc/classes/class-astra-sites-page.php:236
122
+ #: inc/classes/class-astra-sites-page.php:257
123
+ msgid "Elementor"
124
+ msgstr ""
125
+
126
+ #: inc/classes/class-astra-sites-page.php:237
127
+ #: inc/classes/class-astra-sites-page.php:258
128
+ msgid "Beaver Builder"
129
+ msgstr ""
130
+
131
+ #: inc/classes/class-astra-sites-page.php:238
132
+ #: inc/classes/class-astra-sites-page.php:259
133
+ msgid "Brizy"
134
+ msgstr ""
135
+
136
+ #: inc/classes/class-astra-sites-page.php:240 inc/includes/admin-page.php:141
137
+ msgid "Next"
138
+ msgstr ""
139
+
140
+ #: inc/classes/class-astra-sites-page.php:249
141
+ msgid "Astra Starter Sites - Your Library of 100+ Ready Templates!"
142
+ msgstr ""
143
+
144
+ #: inc/classes/class-astra-sites-white-label.php:187
145
+ #. translators: %1$s product name
146
+ msgid "%1$s Branding"
147
+ msgstr ""
148
+
149
+ #: inc/classes/class-astra-sites.php:129
150
+ #. translators: 1: theme.php file
151
+ msgid ""
152
+ "Astra Theme needs to be active for you to use currently installed \"%1$s\" "
153
+ "plugin. <a href=\"%2$s\">Install & Activate Now</a>"
154
+ msgstr ""
155
+
156
+ #: inc/classes/class-astra-sites.php:169
157
+ msgid "See Library"
158
+ msgstr ""
159
+
160
+ #: inc/classes/class-astra-sites.php:222
161
+ msgid "Page Builder"
162
+ msgstr ""
163
+
164
+ #: inc/classes/class-astra-sites.php:227
165
+ msgid "Categories"
166
+ msgstr ""
167
+
168
+ #: inc/classes/class-astra-sites.php:267
169
+ msgid "Get Agency Bundle"
170
+ msgstr ""
171
+
172
+ #: inc/classes/class-astra-sites.php:269
173
+ msgid "Upgrade"
174
+ msgstr ""
175
+
176
+ #: inc/classes/class-astra-sites.php:276
177
+ #. translators: %s are HTML tags.
178
+ msgid ""
179
+ "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
180
+ "Sites import requires XMLReader extension to be installed. Please contact "
181
+ "your web hosting provider and ask them to install and activate the "
182
+ "XMLReader PHP extension."
183
+ msgstr ""
184
+
185
+ #: inc/classes/class-astra-sites.php:277
186
+ msgid ""
187
+ "Warning! Astra Site Import process is not complete. Don't close the window "
188
+ "until import process complete. Do you still want to leave the window?"
189
+ msgstr ""
190
+
191
+ #: inc/classes/class-astra-sites.php:278
192
+ msgid "Error!"
193
+ msgstr ""
194
+
195
+ #: inc/classes/class-astra-sites.php:279
196
+ msgid "Error! Read Possibilities."
197
+ msgstr ""
198
+
199
+ #: inc/classes/class-astra-sites.php:281
200
+ msgid "Done! View Site"
201
+ msgstr ""
202
+
203
+ #: inc/classes/class-astra-sites.php:282
204
+ msgid "Activating"
205
+ msgstr ""
206
+
207
+ #: inc/classes/class-astra-sites.php:283
208
+ msgid "Active"
209
+ msgstr ""
210
+
211
+ #: inc/classes/class-astra-sites.php:284
212
+ msgid "Import failed."
213
+ msgstr ""
214
+
215
+ #: inc/classes/class-astra-sites.php:285
216
+ msgid "Import failed. See error log."
217
+ msgstr ""
218
+
219
+ #: inc/classes/class-astra-sites.php:286
220
+ msgid "Import This Site"
221
+ msgstr ""
222
+
223
+ #: inc/classes/class-astra-sites.php:287 inc/classes/class-astra-sites.php:303
224
+ msgid "Importing.."
225
+ msgstr ""
226
+
227
+ #: inc/classes/class-astra-sites.php:288 inc/includes/admin-page.php:159
228
+ msgid "Read more"
229
+ msgstr ""
230
+
231
+ #: inc/classes/class-astra-sites.php:289
232
+ msgid "Hide"
233
+ msgstr ""
234
+
235
+ #: inc/classes/class-astra-sites.php:290
236
+ msgid "There was a problem receiving a response from server."
237
+ msgstr ""
238
+
239
+ #: inc/classes/class-astra-sites.php:291 inc/includes/admin-page.php:372
240
+ msgid "No Demos found, Try a different search."
241
+ msgstr ""
242
+
243
+ #: inc/classes/class-astra-sites.php:294
244
+ msgid "Installing plugin "
245
+ msgstr ""
246
+
247
+ #: inc/classes/class-astra-sites.php:295
248
+ msgid "Successfully plugin installed!"
249
+ msgstr ""
250
+
251
+ #: inc/classes/class-astra-sites.php:296
252
+ msgid "Activating plugin "
253
+ msgstr ""
254
+
255
+ #: inc/classes/class-astra-sites.php:297
256
+ msgid "Successfully plugin activated "
257
+ msgstr ""
258
+
259
+ #: inc/classes/class-astra-sites.php:298
260
+ msgid "Bulk plugin activation..."
261
+ msgstr ""
262
+
263
+ #: inc/classes/class-astra-sites.php:299
264
+ msgid "Successfully plugin activate - "
265
+ msgstr ""
266
+
267
+ #: inc/classes/class-astra-sites.php:300
268
+ msgid "Error! While activating plugin - "
269
+ msgstr ""
270
+
271
+ #: inc/classes/class-astra-sites.php:301
272
+ msgid "Bulk plugin installation..."
273
+ msgstr ""
274
+
275
+ #: inc/classes/class-astra-sites.php:302
276
+ msgid "Site API "
277
+ msgstr ""
278
+
279
+ #: inc/classes/class-astra-sites.php:304
280
+ msgid "Processing requests..."
281
+ msgstr ""
282
+
283
+ #: inc/classes/class-astra-sites.php:305
284
+ msgid "2) Importing \"Customizer Settings\"..."
285
+ msgstr ""
286
+
287
+ #: inc/classes/class-astra-sites.php:306
288
+ msgid "Successfully imported customizer settings!"
289
+ msgstr ""
290
+
291
+ #: inc/classes/class-astra-sites.php:307
292
+ msgid "3) Importing \"Contact Forms\"..."
293
+ msgstr ""
294
+
295
+ #: inc/classes/class-astra-sites.php:308
296
+ msgid "Successfully imported Contact Forms!"
297
+ msgstr ""
298
+
299
+ #: inc/classes/class-astra-sites.php:309
300
+ msgid "4) Preparing \"XML\" Data..."
301
+ msgstr ""
302
+
303
+ #: inc/classes/class-astra-sites.php:310
304
+ msgid "Successfully set XML data!"
305
+ msgstr ""
306
+
307
+ #: inc/classes/class-astra-sites.php:311
308
+ msgid "5) Importing \"XML\"..."
309
+ msgstr ""
310
+
311
+ #: inc/classes/class-astra-sites.php:312
312
+ msgid "Successfully imported XML!"
313
+ msgstr ""
314
+
315
+ #: inc/classes/class-astra-sites.php:313
316
+ msgid "6) Importing \"Options\"..."
317
+ msgstr ""
318
+
319
+ #: inc/classes/class-astra-sites.php:314
320
+ msgid "Successfully imported Options!"
321
+ msgstr ""
322
+
323
+ #: inc/classes/class-astra-sites.php:315
324
+ msgid "7) Importing \"Widgets\"..."
325
+ msgstr ""
326
+
327
+ #: inc/classes/class-astra-sites.php:316
328
+ msgid "Successfully imported Widgets!"
329
+ msgstr ""
330
+
331
+ #: inc/classes/class-astra-sites.php:318
332
+ msgid "Site imported successfully! visit : "
333
+ msgstr ""
334
+
335
+ #: inc/classes/class-astra-sites.php:319
336
+ msgid "Getting Site Information.."
337
+ msgstr ""
338
+
339
+ #: inc/classes/class-astra-sites.php:320
340
+ msgid "Importing Customizer Settings.."
341
+ msgstr ""
342
+
343
+ #: inc/classes/class-astra-sites.php:321
344
+ msgid "Importing Contact Forms.."
345
+ msgstr ""
346
+
347
+ #: inc/classes/class-astra-sites.php:322
348
+ msgid "Setting up import data.."
349
+ msgstr ""
350
+
351
+ #: inc/classes/class-astra-sites.php:323
352
+ msgid "Importing Content.."
353
+ msgstr ""
354
+
355
+ #: inc/classes/class-astra-sites.php:324
356
+ msgid "Importing Site Options.."
357
+ msgstr ""
358
+
359
+ #: inc/classes/class-astra-sites.php:325
360
+ msgid "Importing Widgets.."
361
+ msgstr ""
362
+
363
+ #: inc/classes/class-astra-sites.php:326
364
+ msgid "Import Complete.."
365
+ msgstr ""
366
+
367
+ #: inc/classes/class-astra-sites.php:327
368
+ msgid "Previewing "
369
+ msgstr ""
370
+
371
+ #: inc/classes/class-astra-sites.php:328
372
+ msgid "See Error Log &rarr;"
373
+ msgstr ""
374
+
375
+ #: inc/classes/class-astra-sites.php:362
376
+ msgid "No plugin specified"
377
+ msgstr ""
378
+
379
+ #: inc/classes/class-astra-sites.php:391
380
+ msgid "Plugin Successfully Activated"
381
+ msgstr ""
382
+
383
+ #: inc/importers/batch-processing/helpers/class-wp-background-process.php:433
384
+ msgid "Every %d Minutes"
385
+ msgstr ""
386
+
387
+ #: inc/importers/class-widgets-importer.php:83
388
+ msgid "Import data could not be read. Please try a different file."
389
+ msgstr ""
390
+
391
+ #: inc/importers/class-widgets-importer.php:127
392
+ msgid "Widget area does not exist in theme (using Inactive)"
393
+ msgstr ""
394
+
395
+ #: inc/importers/class-widgets-importer.php:149
396
+ msgid "Site does not support widget"
397
+ msgstr ""
398
+
399
+ #: inc/importers/class-widgets-importer.php:185
400
+ msgid "Widget already exists"
401
+ msgstr ""
402
+
403
+ #: inc/importers/class-widgets-importer.php:254
404
+ msgid "Imported"
405
+ msgstr ""
406
+
407
+ #: inc/importers/class-widgets-importer.php:257
408
+ msgid "Imported to Inactive"
409
+ msgstr ""
410
+
411
+ #: inc/importers/class-widgets-importer.php:263
412
+ msgid "No Title"
413
+ msgstr ""
414
+
415
+ #: inc/importers/wxr-importer/class-astra-wxr-importer.php:302
416
+ msgid "Import complete!"
417
+ msgstr ""
418
+
419
+ #: inc/importers/wxr-importer/class-wxr-importer.php:131
420
+ msgid "Could not open the file for parsing"
421
+ msgstr ""
422
+
423
+ #: inc/importers/wxr-importer/class-wxr-importer.php:167
424
+ #: inc/importers/wxr-importer/class-wxr-importer.php:283
425
+ #: inc/importers/wxr-importer/class-wxr-importer.php:356
426
+ msgid ""
427
+ "This WXR file (version %1$s) is newer than the importer (version %2$s) and "
428
+ "may not be supported. Please consider updating."
429
+ msgstr ""
430
+
431
+ #: inc/importers/wxr-importer/class-wxr-importer.php:504
432
+ msgid "The file does not exist, please try again."
433
+ msgstr ""
434
+
435
+ #: inc/importers/wxr-importer/class-wxr-importer.php:564
436
+ msgid "Invalid author mapping"
437
+ msgstr ""
438
+
439
+ #: inc/importers/wxr-importer/class-wxr-importer.php:665
440
+ msgid "Cannot import auto-draft posts"
441
+ msgstr ""
442
+
443
+ #: inc/importers/wxr-importer/class-wxr-importer.php:753
444
+ msgid "Failed to import \"%1$s\": Invalid post type %2$s"
445
+ msgstr ""
446
+
447
+ #: inc/importers/wxr-importer/class-wxr-importer.php:763
448
+ msgid "%1$s \"%2$s\" already exists."
449
+ msgstr ""
450
+
451
+ #: inc/importers/wxr-importer/class-wxr-importer.php:857
452
+ msgid "Skipping attachment \"%s\", fetching attachments disabled"
453
+ msgstr ""
454
+
455
+ #: inc/importers/wxr-importer/class-wxr-importer.php:878
456
+ msgid "Failed to import \"%1$s\" (%2$s)"
457
+ msgstr ""
458
+
459
+ #: inc/importers/wxr-importer/class-wxr-importer.php:910
460
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1755
461
+ msgid "Imported \"%1$s\" (%2$s)"
462
+ msgstr ""
463
+
464
+ #: inc/importers/wxr-importer/class-wxr-importer.php:915
465
+ msgid "Post %1$d remapped to %2$d"
466
+ msgstr ""
467
+
468
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1062
469
+ msgid "Invalid file type"
470
+ msgstr ""
471
+
472
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1560
473
+ msgid "Failed to import user \"%s\""
474
+ msgstr ""
475
+
476
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1581
477
+ msgid "Imported user \"%s\""
478
+ msgstr ""
479
+
480
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1585
481
+ msgid "User %1$d remapped to %2$d"
482
+ msgstr ""
483
+
484
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1731
485
+ msgid "Failed to import %1$s %2$s"
486
+ msgstr ""
487
+
488
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1760
489
+ msgid "Term %1$d remapped to %2$d"
490
+ msgstr ""
491
+
492
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1813
493
+ msgid "Remote server returned %1$d %2$s for %3$s"
494
+ msgstr ""
495
+
496
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1826
497
+ msgid "Remote file is incorrect size"
498
+ msgstr ""
499
+
500
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1831
501
+ msgid "Zero size file downloaded"
502
+ msgstr ""
503
+
504
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1837
505
+ msgid "Remote file is too large, limit is %s"
506
+ msgstr ""
507
+
508
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1859
509
+ msgid "Running post-processing for post %d"
510
+ msgstr ""
511
+
512
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1872
513
+ msgid "Could not find the post parent for \"%1$s\" (post #%2$d)"
514
+ msgstr ""
515
+
516
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1877
517
+ msgid "Post %1$d was imported with parent %2$d, but could not be found"
518
+ msgstr ""
519
+
520
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1891
521
+ msgid "Could not find the author for \"%1$s\" (post #%2$d)"
522
+ msgstr ""
523
+
524
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1896
525
+ msgid "Post %1$d was imported with author \"%2$s\", but could not be found"
526
+ msgstr ""
527
+
528
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1922
529
+ msgid "Post %d was marked for post-processing, but none was required."
530
+ msgstr ""
531
+
532
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1933
533
+ msgid "Could not update \"%1$s\" (post #%2$d) with mapped data"
534
+ msgstr ""
535
+
536
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1978
537
+ msgid "Could not find the menu object for \"%1$s\" (post #%2$d)"
538
+ msgstr ""
539
+
540
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1983
541
+ msgid ""
542
+ "Post %1$d was imported with object \"%2$d\" of type \"%3$s\", but could not "
543
+ "be found"
544
+ msgstr ""
545
+
546
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2005
547
+ msgid "Could not find the comment parent for comment #%d"
548
+ msgstr ""
549
+
550
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2009
551
+ msgid "Comment %1$d was imported with parent %2$d, but could not be found"
552
+ msgstr ""
553
+
554
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2023
555
+ msgid "Could not find the author for comment #%d"
556
+ msgstr ""
557
+
558
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2027
559
+ msgid "Comment %1$d was imported with author %2$d, but could not be found"
560
+ msgstr ""
561
+
562
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2044
563
+ msgid "Could not update comment #%d with mapped data"
564
+ msgstr ""
565
+
566
+ #: inc/includes/admin-page.php:41
567
+ msgid "Search Sites"
568
+ msgstr ""
569
+
570
+ #: inc/includes/admin-page.php:42
571
+ msgid "Search Sites..."
572
+ msgstr ""
573
+
574
+ #: inc/includes/admin-page.php:71
575
+ msgid "Liked this demo?"
576
+ msgstr ""
577
+
578
+ #: inc/includes/admin-page.php:75
579
+ #. translators: %s is pricing page link
580
+ msgid ""
581
+ "It is a premium website demo which is available only with the Agency "
582
+ "Bundles <a href=\"%s\" target=\"_blank\">Buy Now!</a>"
583
+ msgstr ""
584
+
585
+ #: inc/includes/admin-page.php:81
586
+ #. translators: %s is article link
587
+ msgid ""
588
+ "Already own an Agency Bundle? Read an article to know how you can <a "
589
+ "href=\"%s\" target=\"_blank\">import a premium website demo</a>."
590
+ msgstr ""
591
+
592
+ #: inc/includes/admin-page.php:92
593
+ msgid "You are just 2 minutes away from importing this demo!"
594
+ msgstr ""
595
+
596
+ #: inc/includes/admin-page.php:93
597
+ msgid ""
598
+ "It is a premium website demo and you need to activate the license to access "
599
+ "it."
600
+ msgstr ""
601
+
602
+ #: inc/includes/admin-page.php:97
603
+ #. translators: %s is article link
604
+ msgid ""
605
+ "Learn how you can <a href=\"%s\" target=\"_blank\">activate the license</a> "
606
+ "of the Astra Premium Sites plugin."
607
+ msgstr ""
608
+
609
+ #: inc/includes/admin-page.php:112
610
+ msgid "Select Your Favorite Page Builder"
611
+ msgstr ""
612
+
613
+ #: inc/includes/admin-page.php:115
614
+ msgid "Sites List.."
615
+ msgstr ""
616
+
617
+ #: inc/includes/admin-page.php:139
618
+ msgid "Close"
619
+ msgstr ""
620
+
621
+ #: inc/includes/admin-page.php:140
622
+ msgid "Previous"
623
+ msgstr ""
624
+
625
+ #: inc/includes/admin-page.php:142 inc/includes/admin-page.php:143
626
+ #: inc/includes/admin-page.php:221 inc/includes/admin-page.php:229
627
+ msgid "Import Site"
628
+ msgstr ""
629
+
630
+ #: inc/includes/admin-page.php:163
631
+ msgid "Plugins Used in This Starter Site"
632
+ msgstr ""
633
+
634
+ #: inc/includes/admin-page.php:165
635
+ msgid "These plugins will be installed when you import this site."
636
+ msgstr ""
637
+
638
+ #: inc/includes/admin-page.php:177
639
+ msgid ""
640
+ "Customizer is what gives a design to the website; and selecting this option "
641
+ "replaces your current design with a new one. <br/>Backup of current "
642
+ "customizer settings will be stored in \"wp-content/astra-sites\" directory, "
643
+ "just in case if you want to restore it later."
644
+ msgstr ""
645
+
646
+ #: inc/includes/admin-page.php:186
647
+ msgid ""
648
+ "Selecting this option will import dummy pages, posts, images and menus. If "
649
+ "you do not want to import dummy content, please uncheck this option."
650
+ msgstr ""
651
+
652
+ #: inc/includes/admin-page.php:202
653
+ msgid ""
654
+ "WARNING: Selecting this option will delete data from your current website. "
655
+ "Choose this option only if this is intended."
656
+ msgstr ""
657
+
658
+ #: inc/includes/admin-page.php:207
659
+ msgid "Advanced Options"
660
+ msgstr ""
661
+
662
+ #: inc/includes/admin-page.php:212
663
+ msgid "Required Plugins"
664
+ msgstr ""
665
+
666
+ #: inc/includes/admin-page.php:235
667
+ msgid "Collapse"
668
+ msgstr ""
669
+
670
+ #: inc/includes/admin-page.php:241
671
+ msgid "Enter desktop preview mode"
672
+ msgstr ""
673
+
674
+ #: inc/includes/admin-page.php:244
675
+ msgid "Enter tablet preview mode"
676
+ msgstr ""
677
+
678
+ #: inc/includes/admin-page.php:247
679
+ msgid "Enter mobile preview mode"
680
+ msgstr ""
681
+
682
+ #: inc/includes/admin-page.php:255 inc/includes/admin-page.php:364
683
+ msgid "Preview"
684
+ msgstr ""
685
+
686
+ #: inc/includes/admin-page.php:270
687
+ #. translators: %1$s & %2$s are a Demo API URL
688
+ msgid ""
689
+ "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
690
+ "unreachable from your site.</p>"
691
+ msgstr ""
692
+
693
+ #: inc/includes/admin-page.php:272
694
+ msgid ""
695
+ "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
696
+ "temporary issues. No kidding!</p>"
697
+ msgstr ""
698
+
699
+ #: inc/includes/admin-page.php:274
700
+ msgid ""
701
+ "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
702
+ "to your server administrator and check if demo server is being blocked by "
703
+ "the firewall!</p>"
704
+ msgstr ""
705
+
706
+ #: inc/includes/admin-page.php:277
707
+ #. translators: %1$s is a support link
708
+ msgid ""
709
+ "<p>If that does not help, please open up a <a href=\"%1$s\" "
710
+ "target=\"_blank\">Support Ticket</a> and we will be glad take a closer look "
711
+ "for you.</p>"
712
+ msgstr ""
713
+
714
+ #: inc/includes/admin-page.php:289
715
+ msgid "Under Maintenance.."
716
+ msgstr ""
717
+
718
+ #: inc/includes/admin-page.php:290
719
+ msgid ""
720
+ "If you are seeing this message, most likely our servers are under routine "
721
+ "maintenance and we will be back shortly. "
722
+ msgstr ""
723
+
724
+ #: inc/includes/admin-page.php:291
725
+ msgid ""
726
+ "In rare case, it is possible your website is having trouble connecting with "
727
+ "ours. If you need help, please feel free to get in touch with us from our "
728
+ "website."
729
+ msgstr ""
730
+
731
+ #: inc/includes/admin-page.php:376 inc/includes/admin-page.php:394
732
+ #. translators: %1$s External Link
733
+ msgid ""
734
+ "Don't see a site that you would like to import?<br><a target=\"_blank\" "
735
+ "href=\"%1$s\">Please suggest us!</a>"
736
+ msgstr ""
737
+
738
+ #: inc/includes/white-label.php:29
739
+ msgid "Plugin Name:"
740
+ msgstr ""
741
+
742
+ #: inc/includes/white-label.php:34
743
+ msgid "Plugin Description:"
744
+ msgstr ""
745
+
746
+ #. Plugin Name of the plugin/theme
747
+ msgid "Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates"
748
+ msgstr ""
749
+
750
+ #. Plugin URI of the plugin/theme
751
+ msgid "http://www.wpastra.com/pro/"
752
+ msgstr ""
753
+
754
+ #. Description of the plugin/theme
755
+ msgid "Import free sites build with Astra theme."
756
+ msgstr ""
757
+
758
+ #. Author of the plugin/theme
759
+ msgid "Brainstorm Force"
760
+ msgstr ""
761
+
762
+ #. Author URI of the plugin/theme
763
+ msgid "http://www.brainstormforce.com"
764
+ msgstr ""
765
+
766
+ #: inc/classes/class-astra-sites-importer-log.php:464
767
+ #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
768
+ msgctxt "Recommended Memory Limit"
769
+ msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
770
+ msgstr ""
771
+
772
+ #: inc/classes/class-astra-sites-importer-log.php:545
773
+ msgctxt "PHP Version"
774
+ msgid "We recommend to use php 5.4 or higher"
775
  msgstr ""
readme.txt CHANGED
@@ -1,288 +1,295 @@
1
- === Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates ===
2
- Contributors: brainstormforce
3
- Donate link: https://wpastra.com/pro/
4
- Tags: Elementor,Beaver Builder,Templates,Gutenberg,Astra Starter Sites
5
- Requires at least: 4.4
6
- Requires PHP: 5.3
7
- Tested up to: 5.1
8
- Stable tag: 1.2.15
9
- License: GPLv2 or later
10
- License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
-
12
- The growing library of 90+ ready-to-use free website templates built for Elementor, Beaver Builder page builder and the default WordPress editor Gutenberg.
13
-
14
- == Description ==
15
-
16
- = FREE TEMPLATES FOR ELEMENTOR, BEAVER BUILDER AND GUTENBERG =
17
-
18
- Create professional designed pixel perfect websites in minutes with the Astra Starter Sites plugin.
19
-
20
- This plugin gives you access to 90+ pre-made full website demos for your favorite page builder such as Elementor, Beaver Builder, Brizy and the WordPress default editor Gutenberg.
21
-
22
- All you need to do is select the demo that suits your needs, import, tweak and go live!
23
-
24
- > I love the fact that the Astra Starter Sites plugin comes with dozens of pre-built sites that were built using Elementor and that can be used to create a full website with one click. - Ben Pines, CMO at Elementor
25
-
26
- > Astra Sites allows anyone to have a beautiful website in under 5 minutes while using all open source software. The theme is free, the plugin is free, it’s almost unbelievable. You have to see it with your own eyes. - Adam Preiser, WPCrafter
27
-
28
- = GET A WEBSITE LIVE IN 5 CLICKS! =
29
-
30
- 1.Install and activate Astra Starter Sites Plugin
31
- 2.Pick a website demo that suits your needs
32
- 3.Install required plugins with a single click
33
- 4.Import the website
34
- 5.Done!
35
-
36
- = FULL WEBSITE TEMPLATES FOR =
37
-
38
- Businesses like restaurants, lawyers, agencies, interior designers, artist shops, brandstore, pet services, charity, plumber, dental clinic, construction, fitness trainer, gardening, makeup artist and a lot more. You can take a look at all of them built with different page builders.
39
-
40
- - [Elementor Free Website Templates](https://wpastra.com/ready-websites/?page-builder=elementor&category=free)
41
- - [Beaver Builder Free Website Templates](https://wpastra.com/ready-websites/?page-builder=beaver-builder&category=free)
42
- - [Gutenberg Free Website Templates](https://wpastra.com/ready-websites/?page-builder=gutenberg&category=free)
43
- - [Brizy Free Website Templates](https://wpastra.com/ready-websites/?page-builder=brizy&category=free)
44
-
45
- You can extend this library with premium ready-to-use website demos by purchasing one of the Agency Bundles, i.e. either the Mini Agency Bundle or the Agency Bundle.
46
-
47
- = WHY PEOPLE LOVE THE ASTRA THEME? =
48
-
49
- Over 200,000+ users are empowering their websites with Astra! From beginners to industry experts, everyone is loving Astra for its performance and ease of use.
50
-
51
- = Here are a few reasons why they love Astra - =
52
-
53
- **Faster Performance** - Built with speed and performance in mind, Astra follows the best coding standards and lets you build faster loading and better performing websites.
54
-
55
- **Easy Customization** - With all the settings managed through the customizer, Astra keeps it simple and gives you lots of options to customize everything with a few clicks.
56
-
57
- **Pixel Perfect Design** - Astra reduces your design time by giving you pixel-perfect FREE ready-to-use websites demos within a huge library of starter sites.
58
-
59
- **Deeper Integrations** - Astra works seamlessly with all WooCommerce plugins, LifterLMS, LearnDash etc. This means that you can create and beautify eCommerce websites and those that offer online courses in minutes.
60
-
61
- Fetch the website, tweak images and content and go live!
62
-
63
- Use this imported site as a base for your project and don't waste time starting from scratch!
64
-
65
- _<a href="https://wpastra.com/ready-websites/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme">See list of all available sites to import »</a>_
66
-
67
- #### Video Walkthrough by Adam from WPCrafter:
68
- [youtube https://www.youtube.com/watch?v=zYbz-jxE9_Q]
69
-
70
- == Installation ==
71
-
72
- 1. Upload the plugin files to the `/wp-content/plugins/astra-sites` directory, or install the plugin through the WordPress plugins screen directly.
73
- 2. Activate the plugin through the 'Plugins' screen in WordPress.
74
- 3. Navigate to Appearance -> Astra Sites to preview and import sites.
75
-
76
- == Frequently Asked Questions ==
77
-
78
- = Will the Astra Starter Sites work with my theme? =
79
-
80
- All the website demos are built using the Astra theme. Therefore, in order to use the Astra Starter Sites plugin and import a ready-to-use website, you will need to have the Astra theme installed.
81
-
82
- = Are all the starter sites free? =
83
-
84
- You get over 90+ FREE ready-to-use websites as of now. There are many more premium website demos that can be accessed when you purchase one of our Agency Bundles.
85
-
86
- = How can I import and install the starter sites? =
87
-
88
- Here is an article that will help you [install and import Astra starter sites](https://wpastra.com/docs/installing-importing-astra-sites/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme) on your website.
89
-
90
-
91
- = Can I import a website demo on an existing website? =
92
-
93
- It is recommended to install and import a website demo on a fresh WordPress installation or a blank website to avoid overriding of settings and page design.
94
-
95
- = Can I deactivate the Astra Starter Sites plugin after importing a website? =
96
-
97
- Yes! The Astra Strater Sites plugin acts as a medium through which you can import and install a website from our cloud server. Once you have the website at your end, you can go ahead and deactivate the plugin.
98
-
99
- = Do I need to install any other plugin before importing a website? =
100
-
101
- You just need to activate the Astra theme and import the website through the Astra Starter Sites plugin. During the process of importing, you will come across a step in which you can install necessary plugins with one click.
102
-
103
- = Will you add more website demos? =
104
-
105
- Yes! We are working on many more free website demos built using Elementor, Beaver Builder, Gutenberg and Brizy.
106
-
107
- = What if I do not find a website for the topic I am looking for? =
108
-
109
- We are open to suggestions and would love to work on topics that our users are looking out for. Please feel free to drop your suggestions through the form [here](https://wpastra.com/sites-suggestions/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme).
110
-
111
-
112
- == Screenshots ==
113
-
114
- 1. Select the demo you want to import.
115
- 2. Install and activate the required plugins.
116
- 3. Import the demo.
117
-
118
- == Changelog ==
119
-
120
- v1.2.15 - 19-March-2019
121
- - Improvement: Added backward compatibility for filter `wp_check_filetype_and_ext` which accepts 5 parameter after WordPress version 5.1.
122
-
123
- v1.2.14 - 13-March-2019
124
- - Improvement: Added support for the WPForms plugin.
125
-
126
- v1.2.13 - 12-March-2019
127
- - Improvement: Improved logic to download images in the Elementor templates.
128
- - Improvement: Added description of the Agency sites when license is not activated.
129
- - Fix: Incorrect images was set after batch process complete.
130
-
131
- v1.2.12 - 29-Jan-2019
132
- - Fix: Gutenberg render markup is invalid due to encoded characterless e.g. <, > are decoded into HTML tag.
133
-
134
- v1.2.11 - 24-Jan-2019
135
- - Improvement: Display a maintenance message if the Astra Sites API is unreachable.
136
- - Fix: EventSource abort the import process if default charset is not UTF-8.
137
-
138
- v1.2.10 - 4-Jan-2019
139
- - Fix: Astra Sites not accessible due to incorrect query parameters.
140
-
141
- v1.2.9 - 17-Dec-2018
142
- - Fix: XML not import due to getting different MIME file types on different PHP versions.
143
-
144
- v1.2.8 - 14-Dec-2018
145
- - Improvement: Added admin notice if XMLReader is not installed. XMLReader is required to import the XML of the website.
146
- - Fix: XML not import due to improved verification of MIME file types in WordPress v5.0.1.
147
-
148
- v1.2.7 - 12-July-2018
149
- - Improvement: Added page builder and category filter support to show selected page builder with selected categories.
150
- - Improvement: Added filter `astra_sites_show_filters` to enable/disable the filter list from admin page.
151
-
152
- v1.2.6 - 9-July-2018
153
- - Fix: We have added `wp_slash` to normalize the Elementor post meta. Elementor have also normalize it. So, We have avoided `wp_slash` while importing sites.
154
-
155
- v1.2.5 - 5-July-2018
156
- - Fix: Normalize Elementor post meta by using `wp_slash` to avoid the unslashing data.
157
-
158
- v1.2.4 - 29-June-2018
159
- - Improvement: Removed custom license validation form and used Graupi in-build license validation form.
160
- - Improvement: Set default page builders depends on the packaged purchase.
161
-
162
- v1.2.3 - 13-June-2018
163
- - Improvement: Added windows EDGE browser support for importing the sites.
164
- - Improvement: The log file was not created if server does not support the file handling functions.
165
- - Fix: Load WXR importer on init to avoid redirect loop when loading WooCommerce importer.
166
- - Fix: Clear the Astra Pro plugin cache after site import.
167
-
168
- v1.2.2 - 26-March-2018
169
- - Fix: Correctly load the Elementor Pro 2.0 compatibility class for beta versions.
170
-
171
- v1.2.1 - 23-March-2018
172
- - Improvement: Clear the Astra Pro plugin cache after site import.
173
-
174
- v1.2.0 - 22-March-2018
175
- - Improvement: Added compatibility for Elemetor version 2.0.0. Older versions throw the PHP warning for function process_element_export_import_content().
176
-
177
- v1.1.9 - 12-March-2018
178
- - Fix: String `Select Your Favorite Page Builder` jerk while loading the sites.
179
-
180
- v1.1.8 - 5-March-2018
181
- - Improvements: Updated processing button animation while installation/activating plugin and importing site.
182
- - Improvements: Updated suggestion box message.
183
- - Fix: PHP fatal errors for WXR importer classes `WXR_Import_Info`, `WXR_Importer`, `WP_Importer_Logger_ServerSentEvents` and `WP_Importer_Logger`.
184
-
185
- v1.1.7 - 2-February-2018
186
- - Improvements: Some users reported confusion in the default option of choosing page builder. We have made UX improvements so users now must select the Page Builder first before selecting any website.
187
-
188
- v1.1.6 - 22-January-2018
189
- - New: Added filter `astra_sites_xml_import_options` to change the XML import options.
190
- - Fix: Astra Pro plugin 'Custom Layouts' & 'Page Headers' not setting right display location due to different page, tax, category ids.
191
- - Fix: WooCommerce shop, checkout cart page ids not setting issue.
192
- - Fix: After site import updated demo url from the nav menus.
193
-
194
- v1.1.5 - 11-January-2018
195
- - New: Added SVG file support for importing the SVG images.
196
-
197
- v1.1.4 - 28-Dec-2017
198
- - Improvement: Importing WooCommerce product category images.
199
- - Improvement: Retain WooCommerce cart, checkout & my account pages when importing the ready WooCommerce sites.
200
- - Fix: Disabled WooCommerce plugin setup wizard after plugin install & activate.
201
-
202
- v1.1.3 - 20-Dec-2017
203
- - Improvement: Retain WooCommerce shop page when importing the ready WooCommerce sites.
204
-
205
- v1.1.2 - 24-Nov-2017
206
- - Fix: Handling plugin installation errors.
207
-
208
- v1.1.1 - 23-Nov-2017
209
- - New: Change the api url for Astra sites to https://websitedemos.net/ from https://sites.wpastra.com/
210
-
211
- v1.1.0 - 21-Nov-2017
212
- - New: Import the site content using Event Source (SSE) which ensures faithful imports.
213
- - New: Divided the site import process in separate AJAX calls to reduce the possibility of timeouts.
214
- - New: Generated the import log file. It will be displayed in the UI if the import fails.
215
- - Improvement: Validate all the possible errors.
216
- - Improvement: Updated Astra sites HTML grid structure for WordPress v4.9 compatibility.
217
- - Enhancement: Updated plugin name from Astra Sites - Lite with Astra Starter Sites.
218
-
219
- v1.0.14 - 9-Nov-2017
220
- - New: All the linked images on the Astra Sites will be downloaded to your site, No more loading images from external URLs.
221
- - New: Added suggestion box at as the last column in when listing sites so that you can add a suggest the sites you want.
222
- - New: Added site responsive preview buttons.
223
- - Improvement: Search string will not be removed when switching the page builder when scrolling through sites.
224
- - Improvement: Loading 15 sites instead of 6 Astra sites in the first load.
225
- - Improvement: Removed LazyLoad which is not useful in admin back-end for showing Astra Sites.
226
-
227
- v1.0.13 - 9-Oct-2017
228
- - New: Browsing the Astra Sites in the Admin panel is not faster with JS rendering.
229
-
230
- v1.0.12 - 29-Sept-2017
231
- - New: Added White Label support from <a href="https://wpastra.com/pro/">Astra Pro</a>.
232
- - Improvement: Don't display sites from both the page builders in the same view.
233
- - Fix: Astra Sites admin area not working in the Firefox.
234
-
235
- v1.0.11 - 22-Sept-2017
236
- - New: Single click Install & activate required plugins.
237
- - New: Added filter `astra_sites_menu_item` for adding extra tabs in admin page.
238
- - New: Added back image import feature for `elementor` page builder. In batch image import we import all images from astra site into client site.
239
- - Improvement: Updated JS code with object prototype.
240
- - Fix: Screen bounce on retina devices.
241
-
242
- v1.0.10 - 11-Sept-2017
243
- - Improvement: Added support for retina logo import.
244
- - Fix: Site logo image not displayed in customizer.
245
- - Fix: Updated `Astra Agency` purchase link.
246
-
247
- v1.0.9 - 8-Sept-2017
248
- - New: Added page builder categories for listing sites as per page builder.
249
-
250
- v1.0.8 - 6-Sept-2017
251
- - Fix: Beaver Builder option import.
252
- - Enhancement: Disabled dismiss-able notice visible once for each user.
253
- - Enhancement: Showing error message for for user who have not `manage_plugins` capability.
254
-
255
- v1.0.7 - 1-Sept-2017
256
- - Fix: Custom Menu widget not setting imported widget.
257
-
258
- v1.0.6 - 30-Aug-2017
259
- - New: Addd custom menu for Astra Sites.
260
- - Fix: Validate site options before storing in database.
261
-
262
- v1.0.5 - 29-Aug-2017
263
- - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
264
- - Enhancement: Plugin name updated from `Astra Sites` with `Astra Free Sites`.
265
- - Fix: PHP error while ignoring users.
266
-
267
- v1.0.4 - 21-Aug-2017
268
- - New: Added filter `astra_sites_api_params` for adding extra params in api call.
269
- - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
270
- - New: Added filter `astra_sites_category_hide_empty` for showing categories which are not set for any site.
271
-
272
- v1.0.3 - 11-Aug-2017
273
- - Fix: Avoided Astra users from site import process.
274
-
275
- v1.0.2 - 09-Aug-2017
276
- - Fix: Listing appropriate next and previous Astra sites.
277
- - Enhancement: Listing Astra sites though AJAX API call.
278
-
279
- v1.0.1 - 04-Aug-2017
280
- - New: Added Elementor plugin options support.
281
- - New: Added Customizer CSS support.
282
- - Enhancement: Avoided Lite Plugin version if Pro version is Installed. Now added support for Beaver Builder Plugin (Lite Version).
283
- - Enhancement: Astra sites API call validated before import.
284
- - Enhancement: Site logo imported from Astra sites.
285
- - Fix: Bug where widgets created with SiteOrigin plugin were not being imported.
286
-
287
- v1.0.0
288
- - Initial release
 
 
 
 
 
 
 
1
+ === Astra Starter Sites – Elementor, Beaver Builder & Gutenberg Templates ===
2
+ Contributors: brainstormforce
3
+ Donate link: https://wpastra.com/pro/
4
+ Tags: Elementor,Beaver Builder,Templates,Gutenberg,Astra Starter Sites
5
+ Requires at least: 4.4
6
+ Requires PHP: 5.3
7
+ Tested up to: 5.1
8
+ Stable tag: 1.3.0
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ The growing library of 90+ ready-to-use free website templates built for Elementor, Beaver Builder page builder and the default WordPress editor Gutenberg.
13
+
14
+ == Description ==
15
+
16
+ = FREE TEMPLATES FOR ELEMENTOR, BEAVER BUILDER AND GUTENBERG =
17
+
18
+ Create professional designed pixel perfect websites in minutes with the Astra Starter Sites plugin.
19
+
20
+ This plugin gives you access to 90+ pre-made full website demos for your favorite page builder such as Elementor, Beaver Builder, Brizy and the WordPress default editor Gutenberg.
21
+
22
+ All you need to do is select the demo that suits your needs, import, tweak and go live!
23
+
24
+ > I love the fact that the Astra Starter Sites plugin comes with dozens of pre-built sites that were built using Elementor and that can be used to create a full website with one click. - Ben Pines, CMO at Elementor
25
+
26
+ > Astra Sites allows anyone to have a beautiful website in under 5 minutes while using all open source software. The theme is free, the plugin is free, it’s almost unbelievable. You have to see it with your own eyes. - Adam Preiser, WPCrafter
27
+
28
+ = GET A WEBSITE LIVE IN 5 CLICKS! =
29
+
30
+ 1.Install and activate Astra Starter Sites Plugin
31
+ 2.Pick a website demo that suits your needs
32
+ 3.Install required plugins with a single click
33
+ 4.Import the website
34
+ 5.Done!
35
+
36
+ = FULL WEBSITE TEMPLATES FOR =
37
+
38
+ Businesses like restaurants, lawyers, agencies, interior designers, artist shops, brandstore, pet services, charity, plumber, dental clinic, construction, fitness trainer, gardening, makeup artist and a lot more. You can take a look at all of them built with different page builders.
39
+
40
+ - [Elementor Free Website Templates](https://wpastra.com/ready-websites/?page-builder=elementor&category=free)
41
+ - [Beaver Builder Free Website Templates](https://wpastra.com/ready-websites/?page-builder=beaver-builder&category=free)
42
+ - [Gutenberg Free Website Templates](https://wpastra.com/ready-websites/?page-builder=gutenberg&category=free)
43
+ - [Brizy Free Website Templates](https://wpastra.com/ready-websites/?page-builder=brizy&category=free)
44
+
45
+ You can extend this library with premium ready-to-use website demos by purchasing one of the Agency Bundles, i.e. either the Mini Agency Bundle or the Agency Bundle.
46
+
47
+ = WHY PEOPLE LOVE THE ASTRA THEME? =
48
+
49
+ Over 200,000+ users are empowering their websites with Astra! From beginners to industry experts, everyone is loving Astra for its performance and ease of use.
50
+
51
+ = Here are a few reasons why they love Astra - =
52
+
53
+ **Faster Performance** - Built with speed and performance in mind, Astra follows the best coding standards and lets you build faster loading and better performing websites.
54
+
55
+ **Easy Customization** - With all the settings managed through the customizer, Astra keeps it simple and gives you lots of options to customize everything with a few clicks.
56
+
57
+ **Pixel Perfect Design** - Astra reduces your design time by giving you pixel-perfect FREE ready-to-use websites demos within a huge library of starter sites.
58
+
59
+ **Deeper Integrations** - Astra works seamlessly with all WooCommerce plugins, LifterLMS, LearnDash etc. This means that you can create and beautify eCommerce websites and those that offer online courses in minutes.
60
+
61
+ Fetch the website, tweak images and content and go live!
62
+
63
+ Use this imported site as a base for your project and don't waste time starting from scratch!
64
+
65
+ _<a href="https://wpastra.com/ready-websites/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme">See list of all available sites to import »</a>_
66
+
67
+ #### Video Walkthrough by Adam from WPCrafter:
68
+ [youtube https://www.youtube.com/watch?v=zYbz-jxE9_Q]
69
+
70
+ == Installation ==
71
+
72
+ 1. Upload the plugin files to the `/wp-content/plugins/astra-sites` directory, or install the plugin through the WordPress plugins screen directly.
73
+ 2. Activate the plugin through the 'Plugins' screen in WordPress.
74
+ 3. Navigate to Appearance -> Astra Sites to preview and import sites.
75
+
76
+ == Frequently Asked Questions ==
77
+
78
+ = Will the Astra Starter Sites work with my theme? =
79
+
80
+ All the website demos are built using the Astra theme. Therefore, in order to use the Astra Starter Sites plugin and import a ready-to-use website, you will need to have the Astra theme installed.
81
+
82
+ = Are all the starter sites free? =
83
+
84
+ You get over 90+ FREE ready-to-use websites as of now. There are many more premium website demos that can be accessed when you purchase one of our Agency Bundles.
85
+
86
+ = How can I import and install the starter sites? =
87
+
88
+ Here is an article that will help you [install and import Astra starter sites](https://wpastra.com/docs/installing-importing-astra-sites/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme) on your website.
89
+
90
+
91
+ = Can I import a website demo on an existing website? =
92
+
93
+ It is recommended to install and import a website demo on a fresh WordPress installation or a blank website to avoid overriding of settings and page design.
94
+
95
+ = Can I deactivate the Astra Starter Sites plugin after importing a website? =
96
+
97
+ Yes! The Astra Strater Sites plugin acts as a medium through which you can import and install a website from our cloud server. Once you have the website at your end, you can go ahead and deactivate the plugin.
98
+
99
+ = Do I need to install any other plugin before importing a website? =
100
+
101
+ You just need to activate the Astra theme and import the website through the Astra Starter Sites plugin. During the process of importing, you will come across a step in which you can install necessary plugins with one click.
102
+
103
+ = Will you add more website demos? =
104
+
105
+ Yes! We are working on many more free website demos built using Elementor, Beaver Builder, Gutenberg and Brizy.
106
+
107
+ = What if I do not find a website for the topic I am looking for? =
108
+
109
+ We are open to suggestions and would love to work on topics that our users are looking out for. Please feel free to drop your suggestions through the form [here](https://wpastra.com/sites-suggestions/?utm_source=wp-repo&utm_medium=link&utm_campaign=readme).
110
+
111
+
112
+ == Screenshots ==
113
+
114
+ 1. Select the page builder of your choice.
115
+ 2. Browse through available Astra sites and select the site that you like.
116
+ 3. Click the import site button to start the import process.
117
+
118
+ == Changelog ==
119
+
120
+ v1.3.0 - 26-March-2019
121
+ - New: Improve the user experience by removing unnecessary steps required in importing a site. Now an Astra site can be imported with just one click.
122
+ - New: Display page builder selection only once on the first load of Astra Sites.
123
+ - New: Take a backup of customizer options before importing new settings.
124
+ - New: Allow to reset the previously imported site when importing multiple Astra sites.
125
+
126
+ v1.2.15 - 14-March-2019
127
+ - Improvement: Admin page UI improvements.
128
+ - Improvement: Added filter `astra_sites_page_title` to change the page title.
129
+
130
+ v1.2.14 - 13-March-2019
131
+ - Improvement: Added support for the WPForms plugin.
132
+
133
+ v1.2.13 - 12-March-2019
134
+ - Improvement: Improved logic to download images in the Elementor templates.
135
+ - Improvement: Added description of the Agency sites when license is not activated.
136
+ - Fix: Incorrect images was set after batch process complete.
137
+
138
+ v1.2.12 - 29-Jan-2019
139
+ - Fix: Gutenberg render markup is invalid due to encoded characterless e.g. <, > are decoded into HTML tag.
140
+
141
+ v1.2.11 - 24-Jan-2019
142
+ - Improvement: Display a maintenance message if the Astra Sites API is unreachable.
143
+ - Fix: EventSource abort the import process if default charset is not UTF-8.
144
+
145
+ v1.2.10 - 4-Jan-2019
146
+ - Fix: Astra Sites not accessible due to incorrect query parameters.
147
+
148
+ v1.2.9 - 17-Dec-2018
149
+ - Fix: XML not import due to getting different MIME file types on different PHP versions.
150
+
151
+ v1.2.8 - 14-Dec-2018
152
+ - Improvement: Added admin notice if XMLReader is not installed. XMLReader is required to import the XML of the website.
153
+ - Fix: XML not import due to improved verification of MIME file types in WordPress v5.0.1.
154
+
155
+ v1.2.7 - 12-July-2018
156
+ - Improvement: Added page builder and category filter support to show selected page builder with selected categories.
157
+ - Improvement: Added filter `astra_sites_show_filters` to enable/disable the filter list from admin page.
158
+
159
+ v1.2.6 - 9-July-2018
160
+ - Fix: We have added `wp_slash` to normalize the Elementor post meta. Elementor have also normalize it. So, We have avoided `wp_slash` while importing sites.
161
+
162
+ v1.2.5 - 5-July-2018
163
+ - Fix: Normalize Elementor post meta by using `wp_slash` to avoid the unslashing data.
164
+
165
+ v1.2.4 - 29-June-2018
166
+ - Improvement: Removed custom license validation form and used Graupi in-build license validation form.
167
+ - Improvement: Set default page builders depends on the packaged purchase.
168
+
169
+ v1.2.3 - 13-June-2018
170
+ - Improvement: Added windows EDGE browser support for importing the sites.
171
+ - Improvement: The log file was not created if server does not support the file handling functions.
172
+ - Fix: Load WXR importer on init to avoid redirect loop when loading WooCommerce importer.
173
+ - Fix: Clear the Astra Pro plugin cache after site import.
174
+
175
+ v1.2.2 - 26-March-2018
176
+ - Fix: Correctly load the Elementor Pro 2.0 compatibility class for beta versions.
177
+
178
+ v1.2.1 - 23-March-2018
179
+ - Improvement: Clear the Astra Pro plugin cache after site import.
180
+
181
+ v1.2.0 - 22-March-2018
182
+ - Improvement: Added compatibility for Elemetor version 2.0.0. Older versions throw the PHP warning for function process_element_export_import_content().
183
+
184
+ v1.1.9 - 12-March-2018
185
+ - Fix: String `Select Your Favorite Page Builder` jerk while loading the sites.
186
+
187
+ v1.1.8 - 5-March-2018
188
+ - Improvements: Updated processing button animation while installation/activating plugin and importing site.
189
+ - Improvements: Updated suggestion box message.
190
+ - Fix: PHP fatal errors for WXR importer classes `WXR_Import_Info`, `WXR_Importer`, `WP_Importer_Logger_ServerSentEvents` and `WP_Importer_Logger`.
191
+
192
+ v1.1.7 - 2-February-2018
193
+ - Improvements: Some users reported confusion in the default option of choosing page builder. We have made UX improvements so users now must select the Page Builder first before selecting any website.
194
+
195
+ v1.1.6 - 22-January-2018
196
+ - New: Added filter `astra_sites_xml_import_options` to change the XML import options.
197
+ - Fix: Astra Pro plugin 'Custom Layouts' & 'Page Headers' not setting right display location due to different page, tax, category ids.
198
+ - Fix: WooCommerce shop, checkout cart page ids not setting issue.
199
+ - Fix: After site import updated demo url from the nav menus.
200
+
201
+ v1.1.5 - 11-January-2018
202
+ - New: Added SVG file support for importing the SVG images.
203
+
204
+ v1.1.4 - 28-Dec-2017
205
+ - Improvement: Importing WooCommerce product category images.
206
+ - Improvement: Retain WooCommerce cart, checkout & my account pages when importing the ready WooCommerce sites.
207
+ - Fix: Disabled WooCommerce plugin setup wizard after plugin install & activate.
208
+
209
+ v1.1.3 - 20-Dec-2017
210
+ - Improvement: Retain WooCommerce shop page when importing the ready WooCommerce sites.
211
+
212
+ v1.1.2 - 24-Nov-2017
213
+ - Fix: Handling plugin installation errors.
214
+
215
+ v1.1.1 - 23-Nov-2017
216
+ - New: Change the api url for Astra sites to https://websitedemos.net/ from https://sites.wpastra.com/
217
+
218
+ v1.1.0 - 21-Nov-2017
219
+ - New: Import the site content using Event Source (SSE) which ensures faithful imports.
220
+ - New: Divided the site import process in separate AJAX calls to reduce the possibility of timeouts.
221
+ - New: Generated the import log file. It will be displayed in the UI if the import fails.
222
+ - Improvement: Validate all the possible errors.
223
+ - Improvement: Updated Astra sites HTML grid structure for WordPress v4.9 compatibility.
224
+ - Enhancement: Updated plugin name from Astra Sites - Lite with Astra Starter Sites.
225
+
226
+ v1.0.14 - 9-Nov-2017
227
+ - New: All the linked images on the Astra Sites will be downloaded to your site, No more loading images from external URLs.
228
+ - New: Added suggestion box at as the last column in when listing sites so that you can add a suggest the sites you want.
229
+ - New: Added site responsive preview buttons.
230
+ - Improvement: Search string will not be removed when switching the page builder when scrolling through sites.
231
+ - Improvement: Loading 15 sites instead of 6 Astra sites in the first load.
232
+ - Improvement: Removed LazyLoad which is not useful in admin back-end for showing Astra Sites.
233
+
234
+ v1.0.13 - 9-Oct-2017
235
+ - New: Browsing the Astra Sites in the Admin panel is not faster with JS rendering.
236
+
237
+ v1.0.12 - 29-Sept-2017
238
+ - New: Added White Label support from <a href="https://wpastra.com/pro/">Astra Pro</a>.
239
+ - Improvement: Don't display sites from both the page builders in the same view.
240
+ - Fix: Astra Sites admin area not working in the Firefox.
241
+
242
+ v1.0.11 - 22-Sept-2017
243
+ - New: Single click Install & activate required plugins.
244
+ - New: Added filter `astra_sites_menu_item` for adding extra tabs in admin page.
245
+ - New: Added back image import feature for `elementor` page builder. In batch image import we import all images from astra site into client site.
246
+ - Improvement: Updated JS code with object prototype.
247
+ - Fix: Screen bounce on retina devices.
248
+
249
+ v1.0.10 - 11-Sept-2017
250
+ - Improvement: Added support for retina logo import.
251
+ - Fix: Site logo image not displayed in customizer.
252
+ - Fix: Updated `Astra Agency` purchase link.
253
+
254
+ v1.0.9 - 8-Sept-2017
255
+ - New: Added page builder categories for listing sites as per page builder.
256
+
257
+ v1.0.8 - 6-Sept-2017
258
+ - Fix: Beaver Builder option import.
259
+ - Enhancement: Disabled dismiss-able notice visible once for each user.
260
+ - Enhancement: Showing error message for for user who have not `manage_plugins` capability.
261
+
262
+ v1.0.7 - 1-Sept-2017
263
+ - Fix: Custom Menu widget not setting imported widget.
264
+
265
+ v1.0.6 - 30-Aug-2017
266
+ - New: Addd custom menu for Astra Sites.
267
+ - Fix: Validate site options before storing in database.
268
+
269
+ v1.0.5 - 29-Aug-2017
270
+ - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
271
+ - Enhancement: Plugin name updated from `Astra Sites` with `Astra Free Sites`.
272
+ - Fix: PHP error while ignoring users.
273
+
274
+ v1.0.4 - 21-Aug-2017
275
+ - New: Added filter `astra_sites_api_params` for adding extra params in api call.
276
+ - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
277
+ - New: Added filter `astra_sites_category_hide_empty` for showing categories which are not set for any site.
278
+
279
+ v1.0.3 - 11-Aug-2017
280
+ - Fix: Avoided Astra users from site import process.
281
+
282
+ v1.0.2 - 09-Aug-2017
283
+ - Fix: Listing appropriate next and previous Astra sites.
284
+ - Enhancement: Listing Astra sites though AJAX API call.
285
+
286
+ v1.0.1 - 04-Aug-2017
287
+ - New: Added Elementor plugin options support.
288
+ - New: Added Customizer CSS support.
289
+ - Enhancement: Avoided Lite Plugin version if Pro version is Installed. Now added support for Beaver Builder Plugin (Lite Version).
290
+ - Enhancement: Astra sites API call validated before import.
291
+ - Enhancement: Site logo imported from Astra sites.
292
+ - Fix: Bug where widgets created with SiteOrigin plugin were not being imported.
293
+
294
+ v1.0.0
295
+ - Initial release