Astra Starter Sites - Version 1.3.15

Version Description

Download this release

Release Info

Developer vrundakansara
Plugin Icon Astra Starter Sites
Version 1.3.15
Comparing to
See all releases

Code changes from version 1.3.14 to 1.3.15

astra-sites.php CHANGED
@@ -1,54 +1,54 @@
1
- <?php
2
- /**
3
- * Plugin Name: Astra Starter Sites
4
- * Plugin URI: http://www.wpastra.com/pro/
5
- * Description: Import free sites build with Astra theme.
6
- * Version: 1.3.14
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.14' );
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
4
+ * Plugin URI: http://www.wpastra.com/pro/
5
+ * Description: Import free sites build with Astra theme.
6
+ * Version: 1.3.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.3.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;
inc/assets/css/admin.css CHANGED
@@ -1,791 +1,791 @@
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
- margin-right: 220px;
229
- }
230
-
231
- .filters-wrap {
232
- display: inline-block;
233
- }
234
- .spinner-wrap {
235
- text-align: center;
236
- }
237
- .spinner-wrap .spinner {
238
- float: none;
239
- }
240
- .hide-me {
241
- display: none !important;
242
- }
243
- #astra-sites-admin {
244
- height: 100vh;
245
- }
246
- .install-theme-info > .notice {
247
- margin: 5px 0 10px 0;
248
- }
249
-
250
- .astra-sites-suggestions:before {
251
- border: 5px dashed #ccc;
252
- position: absolute;
253
- left: 0;
254
- right: 0;
255
- top: 0;
256
- bottom: 0px;
257
- }
258
-
259
- .astra-sites-suggestions {
260
- min-height: 280px;
261
- border: none !important;
262
- }
263
-
264
- .astra-sites-suggestions a {
265
- border: none;
266
- outline: none;
267
- }
268
-
269
- .astra-sites-suggestions .inner {
270
- border: 6px solid #24282e !important;
271
- padding: 27% 10% 50% 10%;
272
- text-align: center;
273
- position: absolute;
274
- left: 0;
275
- right: 0;
276
- top: 0;
277
- background: #33383d;
278
- bottom: 0;
279
- color: #eee;
280
- cursor: auto;
281
- }
282
-
283
- .astra-sites-suggestions .inner a {
284
- color: #00b9eb;
285
- }
286
-
287
- .astra-sites-suggestions p {
288
- font-size: 1rem;
289
- margin: 0;
290
- }
291
-
292
- .astra-notice {
293
- margin: 2em 2em 0em 0em;
294
- }
295
-
296
- .no-themes .description {
297
- display: block;
298
- }
299
-
300
- /**
301
- * Responsive Button UI
302
- */
303
- .astra-sites-preview .wp-full-overlay-footer .devices button.active:before,
304
- .astra-sites-preview .wp-full-overlay-footer .devices button:hover:before {
305
- color: #0073aa;
306
- }
307
- .astra-sites-preview .wp-full-overlay-footer .devices button:before {
308
- color: #c1c1c1;
309
- }
310
- .astra-sites-preview .wp-full-overlay-footer .devices button:hover {
311
- background-color: transparent;
312
- }
313
- .astra-sites-preview .wp-full-overlay-footer .devices button {
314
- border: none;
315
- }
316
- .astra-sites-preview .wp-full-overlay-footer .devices button:focus,
317
- .astra-sites-preview .wp-full-overlay-footer .devices button.active:hover {
318
- border-bottom-color: transparent;
319
- background-color: transparent;
320
- }
321
- .not-click-able {
322
- pointer-events: none !important;
323
- }
324
- body.page-builder-selected .select-page-builder,
325
- body.loading-content .select-page-builder {
326
- display: none;
327
- }
328
- .select-page-builder .up-arrow {
329
- -webkit-transform: rotate(90deg);
330
- -moz-transform: rotate(90deg);
331
- -ms-transform: rotate(90deg);
332
- transform: rotate(90deg);
333
- display: inline-block;
334
- font-size: 1.5em;
335
- color: #797979;
336
- vertical-align: middle;
337
- margin-right: 10px;
338
- -webkit-transition: all linear 0.6s;
339
- -moz-transition: all linear 0.6s;
340
- -ms-transition: all linear 0.6s;
341
- transition: all linear 0.6s;
342
- -webkit-animation-duration: 1s;
343
- animation-duration: 1s;
344
- -webkit-animation-fill-mode: both;
345
- animation-fill-mode: both;
346
- -webkit-animation-timing-function: ease-in-out;
347
- animation-timing-function: ease-in-out;
348
- animation-iteration-count: infinite;
349
- -webkit-animation-iteration-count: infinite;
350
- animation-name: bounce;
351
- -moz-animation-name: bounce;
352
- }
353
- .select-page-builder {
354
- margin-left: 6em;
355
- }
356
-
357
- .select-page-builder img {
358
- max-width: 100%;
359
- }
360
-
361
- .select-page-builder .note-wrap {
362
- position: absolute;
363
- padding: 40px 0;
364
- margin-left: 170px;
365
- right: 0;
366
- left: 0;
367
- }
368
-
369
- .select-page-builder h3 {
370
- margin: 0;
371
- font-size: 2em;
372
- }
373
- .select-page-builder {
374
- margin: -20px 0 0 -5px;
375
- position: absolute;
376
- }
377
- .select-page-builder .note {
378
- margin-left: 1.5em;
379
- }
380
-
381
- @keyframes bounce {
382
- 0%,
383
- 100%,
384
- 20%,
385
- 50%,
386
- 80% {
387
- -webkit-transform: translateY(-0px) rotate(90deg);
388
- -moz-transform: translateY(-0px) rotate(90deg);
389
- -ms-transform: translateY(-0px) rotate(90deg);
390
- transform: translateY(-0px) rotate(90deg);
391
- }
392
- 40% {
393
- -webkit-transform: translateY(-2px) rotate(90deg);
394
- -moz-transform: translateY(-2px) rotate(90deg);
395
- -ms-transform: translateY(-2px) rotate(90deg);
396
- transform: translateY(-2px) rotate(90deg);
397
- }
398
- 60% {
399
- -webkit-transform: translateY(-1px) rotate(90deg);
400
- -moz-transform: translateY(-1px) rotate(90deg);
401
- -ms-transform: translateY(-1px) rotate(90deg);
402
- transform: translateY(-1px) rotate(90deg);
403
- }
404
- }
405
-
406
- /**
407
- * Processing Animation
408
- */
409
- .astra-demo-import.disabled {
410
- pointer-events: none;
411
- }
412
- .astra-demo-import.button.updating-message:before,
413
- .astra-demo-import.button.installing:before {
414
- -webkit-animation: cssAnimation .72s ease infinite;
415
- -moz-animation: cssAnimation .72s ease infinite;
416
- -o-animation: cssAnimation .72s ease infinite;
417
- -ms-animation: cssAnimation .72s ease infinite;
418
- animation: cssAnimation .72s ease infinite;
419
- }
420
-
421
- @-webkit-keyframes cssAnimation {
422
- from {
423
- -webkit-transform: rotate(0);
424
- -moz-transform: rotate(0);
425
- -o-transform: rotate(0);
426
- -ms-transform: rotate(0);
427
- transform: rotate(0);
428
- }
429
- to {
430
- -webkit-transform: rotate(360deg);
431
- -moz-transform: rotate(360deg);
432
- -o-transform: rotate(360deg);
433
- -ms-transform: rotate(360deg);
434
- transform: rotate(360deg);
435
- }
436
- }
437
- @-moz-keyframes cssAnimation {
438
- from {
439
- -webkit-transform: rotate(0);
440
- -moz-transform: rotate(0);
441
- -o-transform: rotate(0);
442
- -ms-transform: rotate(0);
443
- transform: rotate(0);
444
- }
445
- to {
446
- -webkit-transform: rotate(360deg);
447
- -moz-transform: rotate(360deg);
448
- -o-transform: rotate(360deg);
449
- -ms-transform: rotate(360deg);
450
- transform: rotate(360deg);
451
- }
452
- }
453
- @-o-keyframes cssAnimation {
454
- from {
455
- -webkit-transform: rotate(0);
456
- -moz-transform: rotate(0);
457
- -o-transform: rotate(0);
458
- -ms-transform: rotate(0);
459
- transform: rotate(0);
460
- }
461
- to {
462
- -webkit-transform: rotate(360deg);
463
- -moz-transform: rotate(360deg);
464
- -o-transform: rotate(360deg);
465
- -ms-transform: rotate(360deg);
466
- transform: rotate(360deg);
467
- }
468
- }
469
-
470
- #astra-sites-filters {
471
- display: inline-block;
472
- width: 100%;
473
- }
474
-
475
- .astra-site-down {
476
- padding: 1em 2em;
477
- margin-top: 1em;
478
- }
479
-
480
- #astra-sites-menu-page .nav-tab-wrapper {
481
- border: none;
482
- }
483
-
484
- #astra-sites-filters .wp-filter {
485
- margin-top: 0;
486
- }
487
-
488
- /**
489
- * Welcome Screen
490
- */
491
- .astra-sites-welcome {
492
- padding: 10em 0;
493
- text-align: center;
494
- }
495
- .astra-sites-welcome .inner {
496
- margin: 0 auto;
497
- display: inline-block;
498
- max-width: 700px;
499
- background: #fff;
500
- padding: 3em;
501
- }
502
-
503
- .astra-sites-welcome h1 {
504
- font-size: 2.5em;
505
- margin-bottom: 1em;
506
- }
507
-
508
- .astra-sites-welcome p {
509
- font-size: 1rem;
510
- }
511
-
512
- .astra-sites-welcome select {
513
- padding: 5px;
514
- height: 100%;
515
- }
516
-
517
- .astra-sites-welcome .submit {
518
- text-align: center;
519
- margin: 0;
520
- padding: 0;
521
- margin-left: .5em;
522
- }
523
-
524
- .astra-sites-welcome .disabled {
525
- pointer-events: none;
526
- }
527
-
528
- .astra-site-page-builder {
529
- opacity: 0;
530
- visibility: hidden;
531
- }
532
-
533
- .astra-sites-third-party-required-plugins-wrap .notice {
534
- margin: 0;
535
- }
536
-
537
- .required-plugins-list,
538
- .astra-sites-third-party-required-plugins {
539
- margin-left: 2em;
540
- margin-top: .5em;
541
- margin-bottom: .5em;
542
- list-style-type: disc;
543
- }
544
-
545
- .astra-sites-third-party-required-plugins .plugin-card,
546
- .required-plugins-list .plugin-card {
547
- background: transparent;
548
- border: none;
549
- margin: 0;
550
- line-height: 2;
551
- float: none;
552
- width: 100%;
553
- }
554
-
555
- .required-plugins-list .spinner {
556
- float: none;
557
- margin: 0;
558
- }
559
-
560
- .astra-site-import-process-wrap {
561
- display: flex;
562
- align-items: center;
563
- margin-top: -2px;
564
- z-index: 999999;
565
- position: relative;
566
- border-radius: 3px;
567
- overflow: hidden;
568
- }
569
-
570
- .astra-sites-result-preview .astra-site-import-process-wrap progress {
571
- background: #eeeeee;
572
- }
573
-
574
- .astra-sites-result-preview .astra-site-import-process-wrap progress::-webkit-progress-value {
575
- background: #0185ba;
576
- }
577
-
578
- .astra-site-import-process-wrap progress {
579
- padding: 0px;
580
- border: 0 none;
581
- background: #0085bd;
582
- border-radius: 5px;
583
- height: 4px;
584
- flex: 1;
585
- }
586
-
587
- .astra-sites-result-preview .dashicons {
588
- vertical-align: text-bottom;
589
- }
590
-
591
- .astra-site-import-process-wrap progress::-webkit-progress-value {
592
- background: #00679b;
593
- }
594
-
595
- .astra-site-import-process-wrap progress::-webkit-progress-bar {
596
- background: transparent;
597
- }
598
-
599
- .theme-browser .theme .site-preview > .theme-screenshot {
600
- transition: all linear 5s;
601
- background-position: center top;
602
- background-size: cover;
603
- background-repeat: no-repeat;
604
- }
605
- .theme-browser .theme .site-preview > .theme-screenshot:hover {
606
- background-position: center bottom;
607
- background-size: cover;
608
- }
609
-
610
- .astra-sites-tooltip-icon {
611
- cursor: pointer;
612
- }
613
-
614
- .astra-sites-preview .disabled {
615
- pointer-events: none;
616
- }
617
-
618
- .astra-sites-preview input[type="checkbox"].disabled {
619
- background: #eeeeee;
620
- opacity: 1;
621
- color: #fff;
622
- box-shadow: none;
623
- border-color: #b4b9be;
624
- }
625
-
626
- .astra-sites-tooltip-icon .dashicons {
627
- color: #757575;
628
- font-size: 15px;
629
- vertical-align: middle;
630
- height: auto;
631
- }
632
-
633
- #astra-sites-welcome-form-inline {
634
- position: absolute;
635
- right: 1em;
636
- top: 0;
637
- border-radius: 0;
638
- line-height: 1.7;
639
- padding: 0px 5px 2px 5px;
640
- outline: 2px solid transparent;
641
- outline-offset: 0;
642
- background: #fafafa;
643
- border: 1px solid #ccc;
644
- color: #72777c;
645
- font-weight: normal;
646
- font-size: 10px;
647
- font-size: 13px;
648
- line-height: 26px;
649
- height: 28px;
650
- cursor: pointer;
651
- }
652
-
653
- #astra-sites-welcome-form-inline select,
654
- #astra-sites-welcome-form-inline select:focus {
655
- border: none;
656
- outline: none;
657
- box-shadow: none;
658
- color: #72777c;
659
- }
660
-
661
- #astra-sites-menu-page .wp-full-overlay-main:before {
662
- content: '';
663
- display: none;
664
- }
665
-
666
- .theme-screenshot-wrap {
667
- overflow: hidden;
668
- max-height: 300px;
669
- margin: 15px 0;
670
- border: 1px solid #ccc;
671
- }
672
-
673
- .astra-sites-preview .install-theme-info .theme-screenshot {
674
- width: 100%;
675
- border: none;
676
- margin: 0;
677
- }
678
-
679
- #astra-sites-welcome-form #submit {
680
- padding: 0em 4rem;
681
- }
682
-
683
- .page-builders li {
684
- cursor: pointer;
685
- display: inline-block;
686
- padding: 1em;
687
- }
688
-
689
- .page-builders [type=radio] {
690
- position: absolute;
691
- opacity: 0;
692
- width: 0;
693
- height: 0;
694
- }
695
-
696
- .page-builders [type=radio] + img {
697
- cursor: pointer;
698
- opacity: .9;
699
- border: 3px solid transparent;
700
- border-radius: 10px;
701
- transition: all linear 0.2s;
702
- }
703
-
704
- .page-builders [type=radio]:hover + img,
705
- .page-builders [type=radio]:checked + img {
706
- opacity: 1;
707
- }
708
-
709
- .astra-sites-page-builder-notice {
710
- text-align: center;
711
- margin: 1em 0 2em 0;
712
- }
713
-
714
- .current-importing-status-wrap {
715
- font-size: 1rem;
716
- }
717
-
718
- .current-importing-status-wrap hr {
719
- border-color: #f1f1f1;
720
- }
721
-
722
- .astra-sites-result-preview {
723
- position: absolute;
724
- left: 0;
725
- right: 0;
726
- top: 0;
727
- bottom: 0;
728
- background: #fff;
729
- overflow-y: auto;
730
- }
731
-
732
- .astra-sites-result-preview .button {
733
- margin-top: 1em;
734
- }
735
-
736
- .astra-sites-result-preview .inner {
737
- margin: 0 auto;
738
- max-width: 700px;
739
- padding: 5em 0;
740
- }
741
-
742
- .astra-sites-result-preview h2 {
743
- font-size: 2rem;
744
- }
745
-
746
- .astra-sites-result-preview p {
747
- font-size: 1rem;
748
- }
749
-
750
- .current-importing-status {
751
- font-size: 1rem;
752
- background: #eeeeee;
753
- padding: 1em 1.5em;
754
- }
755
-
756
- .current-importing-status-title {
757
- margin-bottom: .5em;
758
- }
759
-
760
- .appearance_page_astra-sites .rotating {
761
- height: auto;
762
- animation: rotation 2s infinite linear;
763
- width: auto;
764
- color: #c1c1c1;
765
- }
766
-
767
- @-webkit-keyframes rotation {
768
- from {
769
- -webkit-transform: rotate(0deg);
770
- }
771
- to {
772
- -webkit-transform: rotate(359deg);
773
- }
774
- }
775
- .import-time {
776
- display: inline-block;
777
- background: #0185ba;
778
- color: #fff;
779
- padding: 2px 10px;
780
- border-radius: 3px;
781
- animation: astra-scale 0.5s alternate infinite ease-in;
782
- }
783
-
784
- @keyframes astra-scale {
785
- 0% {transform: scale(1);}
786
- 100% {transform: scale(1.03);}
787
- }
788
-
789
- .current-importing-status p {
790
- margin: 0;
791
  }
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
+ margin-right: 220px;
229
+ }
230
+
231
+ .filters-wrap {
232
+ display: inline-block;
233
+ }
234
+ .spinner-wrap {
235
+ text-align: center;
236
+ }
237
+ .spinner-wrap .spinner {
238
+ float: none;
239
+ }
240
+ .hide-me {
241
+ display: none !important;
242
+ }
243
+ #astra-sites-admin {
244
+ height: 100vh;
245
+ }
246
+ .install-theme-info > .notice {
247
+ margin: 5px 0 10px 0;
248
+ }
249
+
250
+ .astra-sites-suggestions:before {
251
+ border: 5px dashed #ccc;
252
+ position: absolute;
253
+ left: 0;
254
+ right: 0;
255
+ top: 0;
256
+ bottom: 0px;
257
+ }
258
+
259
+ .astra-sites-suggestions {
260
+ min-height: 280px;
261
+ border: none !important;
262
+ }
263
+
264
+ .astra-sites-suggestions a {
265
+ border: none;
266
+ outline: none;
267
+ }
268
+
269
+ .astra-sites-suggestions .inner {
270
+ border: 6px solid #24282e !important;
271
+ padding: 27% 10% 50% 10%;
272
+ text-align: center;
273
+ position: absolute;
274
+ left: 0;
275
+ right: 0;
276
+ top: 0;
277
+ background: #33383d;
278
+ bottom: 0;
279
+ color: #eee;
280
+ cursor: auto;
281
+ }
282
+
283
+ .astra-sites-suggestions .inner a {
284
+ color: #00b9eb;
285
+ }
286
+
287
+ .astra-sites-suggestions p {
288
+ font-size: 1rem;
289
+ margin: 0;
290
+ }
291
+
292
+ .astra-notice {
293
+ margin: 2em 2em 0em 0em;
294
+ }
295
+
296
+ .no-themes .description {
297
+ display: block;
298
+ }
299
+
300
+ /**
301
+ * Responsive Button UI
302
+ */
303
+ .astra-sites-preview .wp-full-overlay-footer .devices button.active:before,
304
+ .astra-sites-preview .wp-full-overlay-footer .devices button:hover:before {
305
+ color: #0073aa;
306
+ }
307
+ .astra-sites-preview .wp-full-overlay-footer .devices button:before {
308
+ color: #c1c1c1;
309
+ }
310
+ .astra-sites-preview .wp-full-overlay-footer .devices button:hover {
311
+ background-color: transparent;
312
+ }
313
+ .astra-sites-preview .wp-full-overlay-footer .devices button {
314
+ border: none;
315
+ }
316
+ .astra-sites-preview .wp-full-overlay-footer .devices button:focus,
317
+ .astra-sites-preview .wp-full-overlay-footer .devices button.active:hover {
318
+ border-bottom-color: transparent;
319
+ background-color: transparent;
320
+ }
321
+ .not-click-able {
322
+ pointer-events: none !important;
323
+ }
324
+ body.page-builder-selected .select-page-builder,
325
+ body.loading-content .select-page-builder {
326
+ display: none;
327
+ }
328
+ .select-page-builder .up-arrow {
329
+ -webkit-transform: rotate(90deg);
330
+ -moz-transform: rotate(90deg);
331
+ -ms-transform: rotate(90deg);
332
+ transform: rotate(90deg);
333
+ display: inline-block;
334
+ font-size: 1.5em;
335
+ color: #797979;
336
+ vertical-align: middle;
337
+ margin-right: 10px;
338
+ -webkit-transition: all linear 0.6s;
339
+ -moz-transition: all linear 0.6s;
340
+ -ms-transition: all linear 0.6s;
341
+ transition: all linear 0.6s;
342
+ -webkit-animation-duration: 1s;
343
+ animation-duration: 1s;
344
+ -webkit-animation-fill-mode: both;
345
+ animation-fill-mode: both;
346
+ -webkit-animation-timing-function: ease-in-out;
347
+ animation-timing-function: ease-in-out;
348
+ animation-iteration-count: infinite;
349
+ -webkit-animation-iteration-count: infinite;
350
+ animation-name: bounce;
351
+ -moz-animation-name: bounce;
352
+ }
353
+ .select-page-builder {
354
+ margin-left: 6em;
355
+ }
356
+
357
+ .select-page-builder img {
358
+ max-width: 100%;
359
+ }
360
+
361
+ .select-page-builder .note-wrap {
362
+ position: absolute;
363
+ padding: 40px 0;
364
+ margin-left: 170px;
365
+ right: 0;
366
+ left: 0;
367
+ }
368
+
369
+ .select-page-builder h3 {
370
+ margin: 0;
371
+ font-size: 2em;
372
+ }
373
+ .select-page-builder {
374
+ margin: -20px 0 0 -5px;
375
+ position: absolute;
376
+ }
377
+ .select-page-builder .note {
378
+ margin-left: 1.5em;
379
+ }
380
+
381
+ @keyframes bounce {
382
+ 0%,
383
+ 100%,
384
+ 20%,
385
+ 50%,
386
+ 80% {
387
+ -webkit-transform: translateY(-0px) rotate(90deg);
388
+ -moz-transform: translateY(-0px) rotate(90deg);
389
+ -ms-transform: translateY(-0px) rotate(90deg);
390
+ transform: translateY(-0px) rotate(90deg);
391
+ }
392
+ 40% {
393
+ -webkit-transform: translateY(-2px) rotate(90deg);
394
+ -moz-transform: translateY(-2px) rotate(90deg);
395
+ -ms-transform: translateY(-2px) rotate(90deg);
396
+ transform: translateY(-2px) rotate(90deg);
397
+ }
398
+ 60% {
399
+ -webkit-transform: translateY(-1px) rotate(90deg);
400
+ -moz-transform: translateY(-1px) rotate(90deg);
401
+ -ms-transform: translateY(-1px) rotate(90deg);
402
+ transform: translateY(-1px) rotate(90deg);
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Processing Animation
408
+ */
409
+ .astra-demo-import.disabled {
410
+ pointer-events: none;
411
+ }
412
+ .astra-demo-import.button.updating-message:before,
413
+ .astra-demo-import.button.installing:before {
414
+ -webkit-animation: cssAnimation .72s ease infinite;
415
+ -moz-animation: cssAnimation .72s ease infinite;
416
+ -o-animation: cssAnimation .72s ease infinite;
417
+ -ms-animation: cssAnimation .72s ease infinite;
418
+ animation: cssAnimation .72s ease infinite;
419
+ }
420
+
421
+ @-webkit-keyframes cssAnimation {
422
+ from {
423
+ -webkit-transform: rotate(0);
424
+ -moz-transform: rotate(0);
425
+ -o-transform: rotate(0);
426
+ -ms-transform: rotate(0);
427
+ transform: rotate(0);
428
+ }
429
+ to {
430
+ -webkit-transform: rotate(360deg);
431
+ -moz-transform: rotate(360deg);
432
+ -o-transform: rotate(360deg);
433
+ -ms-transform: rotate(360deg);
434
+ transform: rotate(360deg);
435
+ }
436
+ }
437
+ @-moz-keyframes cssAnimation {
438
+ from {
439
+ -webkit-transform: rotate(0);
440
+ -moz-transform: rotate(0);
441
+ -o-transform: rotate(0);
442
+ -ms-transform: rotate(0);
443
+ transform: rotate(0);
444
+ }
445
+ to {
446
+ -webkit-transform: rotate(360deg);
447
+ -moz-transform: rotate(360deg);
448
+ -o-transform: rotate(360deg);
449
+ -ms-transform: rotate(360deg);
450
+ transform: rotate(360deg);
451
+ }
452
+ }
453
+ @-o-keyframes cssAnimation {
454
+ from {
455
+ -webkit-transform: rotate(0);
456
+ -moz-transform: rotate(0);
457
+ -o-transform: rotate(0);
458
+ -ms-transform: rotate(0);
459
+ transform: rotate(0);
460
+ }
461
+ to {
462
+ -webkit-transform: rotate(360deg);
463
+ -moz-transform: rotate(360deg);
464
+ -o-transform: rotate(360deg);
465
+ -ms-transform: rotate(360deg);
466
+ transform: rotate(360deg);
467
+ }
468
+ }
469
+
470
+ #astra-sites-filters {
471
+ display: inline-block;
472
+ width: 100%;
473
+ }
474
+
475
+ .astra-site-down {
476
+ padding: 1em 2em;
477
+ margin-top: 1em;
478
+ }
479
+
480
+ #astra-sites-menu-page .nav-tab-wrapper {
481
+ border: none;
482
+ }
483
+
484
+ #astra-sites-filters .wp-filter {
485
+ margin-top: 0;
486
+ }
487
+
488
+ /**
489
+ * Welcome Screen
490
+ */
491
+ .astra-sites-welcome {
492
+ padding: 10em 0;
493
+ text-align: center;
494
+ }
495
+ .astra-sites-welcome .inner {
496
+ margin: 0 auto;
497
+ display: inline-block;
498
+ max-width: 700px;
499
+ background: #fff;
500
+ padding: 3em;
501
+ }
502
+
503
+ .astra-sites-welcome h1 {
504
+ font-size: 2.5em;
505
+ margin-bottom: 1em;
506
+ }
507
+
508
+ .astra-sites-welcome p {
509
+ font-size: 1rem;
510
+ }
511
+
512
+ .astra-sites-welcome select {
513
+ padding: 5px;
514
+ height: 100%;
515
+ }
516
+
517
+ .astra-sites-welcome .submit {
518
+ text-align: center;
519
+ margin: 0;
520
+ padding: 0;
521
+ margin-left: .5em;
522
+ }
523
+
524
+ .astra-sites-welcome .disabled {
525
+ pointer-events: none;
526
+ }
527
+
528
+ .astra-site-page-builder {
529
+ opacity: 0;
530
+ visibility: hidden;
531
+ }
532
+
533
+ .astra-sites-third-party-required-plugins-wrap .notice {
534
+ margin: 0;
535
+ }
536
+
537
+ .required-plugins-list,
538
+ .astra-sites-third-party-required-plugins {
539
+ margin-left: 2em;
540
+ margin-top: .5em;
541
+ margin-bottom: .5em;
542
+ list-style-type: disc;
543
+ }
544
+
545
+ .astra-sites-third-party-required-plugins .plugin-card,
546
+ .required-plugins-list .plugin-card {
547
+ background: transparent;
548
+ border: none;
549
+ margin: 0;
550
+ line-height: 2;
551
+ float: none;
552
+ width: 100%;
553
+ }
554
+
555
+ .required-plugins-list .spinner {
556
+ float: none;
557
+ margin: 0;
558
+ }
559
+
560
+ .astra-site-import-process-wrap {
561
+ display: flex;
562
+ align-items: center;
563
+ margin-top: -2px;
564
+ z-index: 999999;
565
+ position: relative;
566
+ border-radius: 3px;
567
+ overflow: hidden;
568
+ }
569
+
570
+ .astra-sites-result-preview .astra-site-import-process-wrap progress {
571
+ background: #eeeeee;
572
+ }
573
+
574
+ .astra-sites-result-preview .astra-site-import-process-wrap progress::-webkit-progress-value {
575
+ background: #0185ba;
576
+ }
577
+
578
+ .astra-site-import-process-wrap progress {
579
+ padding: 0px;
580
+ border: 0 none;
581
+ background: #0085bd;
582
+ border-radius: 5px;
583
+ height: 4px;
584
+ flex: 1;
585
+ }
586
+
587
+ .astra-sites-result-preview .dashicons {
588
+ vertical-align: text-bottom;
589
+ }
590
+
591
+ .astra-site-import-process-wrap progress::-webkit-progress-value {
592
+ background: #00679b;
593
+ }
594
+
595
+ .astra-site-import-process-wrap progress::-webkit-progress-bar {
596
+ background: transparent;
597
+ }
598
+
599
+ .theme-browser .theme .site-preview > .theme-screenshot {
600
+ transition: all linear 5s;
601
+ background-position: center top;
602
+ background-size: cover;
603
+ background-repeat: no-repeat;
604
+ }
605
+ .theme-browser .theme .site-preview > .theme-screenshot:hover {
606
+ background-position: center bottom;
607
+ background-size: cover;
608
+ }
609
+
610
+ .astra-sites-tooltip-icon {
611
+ cursor: pointer;
612
+ }
613
+
614
+ .astra-sites-preview .disabled {
615
+ pointer-events: none;
616
+ }
617
+
618
+ .astra-sites-preview input[type="checkbox"].disabled {
619
+ background: #eeeeee;
620
+ opacity: 1;
621
+ color: #fff;
622
+ box-shadow: none;
623
+ border-color: #b4b9be;
624
+ }
625
+
626
+ .astra-sites-tooltip-icon .dashicons {
627
+ color: #757575;
628
+ font-size: 15px;
629
+ vertical-align: middle;
630
+ height: auto;
631
+ }
632
+
633
+ #astra-sites-welcome-form-inline {
634
+ position: absolute;
635
+ right: 1em;
636
+ top: 0;
637
+ border-radius: 0;
638
+ line-height: 1.7;
639
+ padding: 0px 5px 2px 5px;
640
+ outline: 2px solid transparent;
641
+ outline-offset: 0;
642
+ background: #fafafa;
643
+ border: 1px solid #ccc;
644
+ color: #72777c;
645
+ font-weight: normal;
646
+ font-size: 10px;
647
+ font-size: 13px;
648
+ line-height: 26px;
649
+ height: 28px;
650
+ cursor: pointer;
651
+ }
652
+
653
+ #astra-sites-welcome-form-inline select,
654
+ #astra-sites-welcome-form-inline select:focus {
655
+ border: none;
656
+ outline: none;
657
+ box-shadow: none;
658
+ color: #72777c;
659
+ }
660
+
661
+ #astra-sites-menu-page .wp-full-overlay-main:before {
662
+ content: '';
663
+ display: none;
664
+ }
665
+
666
+ .theme-screenshot-wrap {
667
+ overflow: hidden;
668
+ max-height: 300px;
669
+ margin: 15px 0;
670
+ border: 1px solid #ccc;
671
+ }
672
+
673
+ .astra-sites-preview .install-theme-info .theme-screenshot {
674
+ width: 100%;
675
+ border: none;
676
+ margin: 0;
677
+ }
678
+
679
+ #astra-sites-welcome-form #submit {
680
+ padding: 0em 4rem;
681
+ }
682
+
683
+ .page-builders li {
684
+ cursor: pointer;
685
+ display: inline-block;
686
+ padding: 1em;
687
+ }
688
+
689
+ .page-builders [type=radio] {
690
+ position: absolute;
691
+ opacity: 0;
692
+ width: 0;
693
+ height: 0;
694
+ }
695
+
696
+ .page-builders [type=radio] + img {
697
+ cursor: pointer;
698
+ opacity: .9;
699
+ border: 3px solid transparent;
700
+ border-radius: 10px;
701
+ transition: all linear 0.2s;
702
+ }
703
+
704
+ .page-builders [type=radio]:hover + img,
705
+ .page-builders [type=radio]:checked + img {
706
+ opacity: 1;
707
+ }
708
+
709
+ .astra-sites-page-builder-notice {
710
+ text-align: center;
711
+ margin: 1em 0 2em 0;
712
+ }
713
+
714
+ .current-importing-status-wrap {
715
+ font-size: 1rem;
716
+ }
717
+
718
+ .current-importing-status-wrap hr {
719
+ border-color: #f1f1f1;
720
+ }
721
+
722
+ .astra-sites-result-preview {
723
+ position: absolute;
724
+ left: 0;
725
+ right: 0;
726
+ top: 0;
727
+ bottom: 0;
728
+ background: #fff;
729
+ overflow-y: auto;
730
+ }
731
+
732
+ .astra-sites-result-preview .button {
733
+ margin-top: 1em;
734
+ }
735
+
736
+ .astra-sites-result-preview .inner {
737
+ margin: 0 auto;
738
+ max-width: 700px;
739
+ padding: 5em 0;
740
+ }
741
+
742
+ .astra-sites-result-preview h2 {
743
+ font-size: 2rem;
744
+ }
745
+
746
+ .astra-sites-result-preview p {
747
+ font-size: 1rem;
748
+ }
749
+
750
+ .current-importing-status {
751
+ font-size: 1rem;
752
+ background: #eeeeee;
753
+ padding: 1em 1.5em;
754
+ }
755
+
756
+ .current-importing-status-title {
757
+ margin-bottom: .5em;
758
+ }
759
+
760
+ .appearance_page_astra-sites .rotating {
761
+ height: auto;
762
+ animation: rotation 2s infinite linear;
763
+ width: auto;
764
+ color: #c1c1c1;
765
+ }
766
+
767
+ @-webkit-keyframes rotation {
768
+ from {
769
+ -webkit-transform: rotate(0deg);
770
+ }
771
+ to {
772
+ -webkit-transform: rotate(359deg);
773
+ }
774
+ }
775
+ .import-time {
776
+ display: inline-block;
777
+ background: #0185ba;
778
+ color: #fff;
779
+ padding: 2px 10px;
780
+ border-radius: 3px;
781
+ animation: astra-scale 0.5s alternate infinite ease-in;
782
+ }
783
+
784
+ @keyframes astra-scale {
785
+ 0% {transform: scale(1);}
786
+ 100% {transform: scale(1.03);}
787
+ }
788
+
789
+ .current-importing-status p {
790
+ margin: 0;
791
  }
inc/assets/css/install-theme.css CHANGED
@@ -1,21 +1,21 @@
1
- .processing:before {
2
- margin: 0 3px 0px 0px;
3
- }
4
- .processing:before {
5
- animation: rotation 2s infinite linear;
6
- }
7
- .processing:before {
8
- color: #f56e28;
9
- content: "\f463";
10
- }
11
- .processing:before {
12
- display: inline-block;
13
- font: normal 20px/1 dashicons;
14
- -webkit-font-smoothing: antialiased;
15
- -moz-osx-font-smoothing: grayscale;
16
- vertical-align: top;
17
- }
18
- #astra-theme-activation-nag a {
19
- box-shadow: none;
20
- outline: none;
21
  }
1
+ .processing:before {
2
+ margin: 0 3px 0px 0px;
3
+ }
4
+ .processing:before {
5
+ animation: rotation 2s infinite linear;
6
+ }
7
+ .processing:before {
8
+ color: #f56e28;
9
+ content: "\f463";
10
+ }
11
+ .processing:before {
12
+ display: inline-block;
13
+ font: normal 20px/1 dashicons;
14
+ -webkit-font-smoothing: antialiased;
15
+ -moz-osx-font-smoothing: grayscale;
16
+ vertical-align: top;
17
+ }
18
+ #astra-theme-activation-nag a {
19
+ box-shadow: none;
20
+ outline: none;
21
  }
inc/assets/js/admin-page.js CHANGED
@@ -1,1863 +1,1872 @@
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
- var process_bars = document.getElementsByClassName( 'astra-site-import-process' );
111
- for ( var i = 0; i < process_bars.length; i++ ) {
112
- process_bars[i].value = progress_bar;
113
- }
114
- AstraSitesAdmin._log_title( 'Importing Content.. ' + progress );
115
- }
116
- }
117
- },
118
- render: function () {
119
- var types = Object.keys( this.complete );
120
- var complete = 0;
121
- var total = 0;
122
-
123
- for (var i = types.length - 1; i >= 0; i--) {
124
- var type = types[i];
125
- this.updateProgress( type, this.complete[ type ], this.data.count[ type ] );
126
-
127
- complete += this.complete[ type ];
128
- total += this.data.count[ type ];
129
- }
130
-
131
- this.updateProgress( 'total', complete, total );
132
- }
133
- };
134
-
135
- AstraSitesAdmin = {
136
-
137
- reset_remaining_posts: 0,
138
- reset_remaining_wp_forms: 0,
139
- reset_remaining_terms: 0,
140
- reset_processed_posts: 0,
141
- reset_processed_wp_forms: 0,
142
- reset_processed_terms: 0,
143
- site_imported_data: null,
144
-
145
- backup_taken: false,
146
-
147
- current_site: [],
148
- current_screen: '',
149
-
150
- templateData: {},
151
-
152
- log_file : '',
153
- customizer_data : '',
154
- wxr_url : '',
155
- wpforms_url : '',
156
- options_data : '',
157
- widgets_data : '',
158
- import_start_time : '',
159
- import_end_time : '',
160
-
161
- init: function()
162
- {
163
- this._resetPagedCount();
164
- this._bind();
165
- },
166
-
167
- /**
168
- * Debugging.
169
- *
170
- * @param {mixed} data Mixed data.
171
- */
172
- _log: function( data ) {
173
-
174
- if( astraSitesAdmin.debug ) {
175
-
176
- var date = new Date();
177
- var time = date.toLocaleTimeString();
178
-
179
- if (typeof data == 'object') {
180
- console.log('%c ' + JSON.stringify( data ) + ' ' + time, 'background: #ededed; color: #444');
181
- } else {
182
- console.log('%c ' + data + ' ' + time, 'background: #ededed; color: #444');
183
- }
184
-
185
-
186
- }
187
- },
188
-
189
- _log_title: function( data, append ) {
190
-
191
- var markup = '<p>' + data + '</p>';
192
- if (typeof data == 'object' ) {
193
- var markup = '<p>' + JSON.stringify( data ) + '</p>';
194
- }
195
-
196
- if ( append ) {
197
- $('.current-importing-status-title').append( markup );
198
- } else {
199
- $('.current-importing-status-title').html( markup );
200
- }
201
- },
202
-
203
- /**
204
- * Binds events for the Astra Sites.
205
- *
206
- * @since 1.0.0
207
- * @access private
208
- * @method _bind
209
- */
210
- _bind: function()
211
- {
212
- $( document ).on( 'click' , '.astra-sites-reset-data .checkbox', AstraSitesAdmin._toggle_reset_notice );
213
- $( document ).on( 'click' , '.page-builders li', AstraSitesAdmin._toggle_reset_notice );
214
- $( document ).on('click' , '#astra-sites-welcome-form .submit', AstraSitesAdmin._show_page_builder_notice);
215
- $( document ).on('click' , '#astra-sites-welcome-form li', AstraSitesAdmin._show_next_button);
216
- $( document ).on('change' , '#astra-sites-welcome-form-inline select', AstraSitesAdmin._change_page_builder);
217
- $( document ).on('click' , '.astra-sites-tooltip-icon', AstraSitesAdmin._toggle_tooltip);
218
- $( document ).on('click' , '.astra-sites-advanced-options-button', AstraSitesAdmin._toggle_advanced_options);
219
-
220
- $( document ).on('click' , '.astra-import-settings', AstraSitesAdmin._import_settings);
221
- $( document ).on('click' , '.devices button', AstraSitesAdmin._previewDevice);
222
- $( document ).on('click' , '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSitesAdmin._preview);
223
- $( document ).on('click' , '.next-theme', AstraSitesAdmin._nextTheme);
224
- $( document ).on('click' , '.previous-theme', AstraSitesAdmin._previousTheme);
225
- $( document ).on('click' , '.collapse-sidebar', AstraSitesAdmin._collapse);
226
- $( document ).on('click' , '.astra-demo-import', AstraSitesAdmin._importDemo);
227
-
228
- $( document ).on('astra-sites-install-and-activate-required-plugins-done' , AstraSitesAdmin._process_import );
229
-
230
- $( document ).on('click' , '.install-now', AstraSitesAdmin._installNow);
231
- $( document ).on('click' , '.close-full-overlay', AstraSitesAdmin._fullOverlay);
232
- $( document ).on('click' , '.activate-now', AstraSitesAdmin._activateNow);
233
- $( document ).on('wp-plugin-installing' , AstraSitesAdmin._pluginInstalling);
234
- $( document ).on('wp-plugin-install-error' , AstraSitesAdmin._installError);
235
- $( document ).on('wp-plugin-install-success' , AstraSitesAdmin._installSuccess);
236
-
237
- $( document ).on( 'astra-sites-import-set-site-data-done' , AstraSitesAdmin._resetData );
238
- $( document ).on( 'astra-sites-reset-data' , AstraSitesAdmin._backup_before_rest_options );
239
- $( document ).on( 'astra-sites-backup-settings-before-reset-done' , AstraSitesAdmin._reset_customizer_data );
240
- $( document ).on( 'astra-sites-reset-customizer-data-done' , AstraSitesAdmin._reset_site_options );
241
- $( document ).on( 'astra-sites-reset-site-options-done' , AstraSitesAdmin._reset_widgets_data );
242
- $( document ).on( 'astra-sites-reset-widgets-data-done' , AstraSitesAdmin._reset_terms );
243
- $( document ).on( 'astra-sites-delete-terms-done' , AstraSitesAdmin._reset_wp_forms );
244
- $( document ).on( 'astra-sites-delete-wp-forms-done' , AstraSitesAdmin._reset_posts );
245
-
246
- $( document ).on('astra-sites-reset-data-done' , AstraSitesAdmin._recheck_backup_options );
247
- $( document ).on('astra-sites-backup-settings-done' , AstraSitesAdmin._importWPForms );
248
- $( document ).on('astra-sites-import-wpforms-done' , AstraSitesAdmin._importCustomizerSettings );
249
- $( document ).on('astra-sites-import-customizer-settings-done' , AstraSitesAdmin._importXML );
250
- $( document ).on('astra-sites-import-xml-done' , AstraSitesAdmin._importSiteOptions );
251
- $( document ).on('astra-sites-import-options-done' , AstraSitesAdmin._importWidgets );
252
- $( document ).on('astra-sites-import-widgets-done' , AstraSitesAdmin._importEnd );
253
-
254
- },
255
-
256
- _show_next_button: function() {
257
- $( this ).parents('.page-builders').find('img').removeClass('wp-ui-highlight');
258
- $( this ).find('img').addClass('wp-ui-highlight');
259
-
260
- $('#submit').parent().removeClass('submit');
261
- $('#submit').removeClass('disabled');
262
- $('.astra-sites-page-builder-notice').hide();
263
- },
264
-
265
- _show_page_builder_notice: function() {
266
- $('.astra-sites-page-builder-notice').show();
267
- },
268
-
269
- _change_page_builder: function() {
270
- $(this).closest('form').submit();
271
- },
272
-
273
- _toggle_tooltip: function( event ) {
274
- event.preventDefault();
275
- var tip_id = $( this ).data('tip-id') || '';
276
- if( tip_id && $( '#' + tip_id ).length ) {
277
- $( '#' + tip_id ).toggle();
278
- }
279
- },
280
-
281
- _toggle_advanced_options: function( event ) {
282
- event.preventDefault();
283
- $('.astra-sites-advanced-options').toggle();
284
- },
285
-
286
- _resetData: function( event ) {
287
- event.preventDefault();
288
-
289
- if ( $( '.astra-sites-reset-data' ).find('.checkbox').is(':checked') ) {
290
- $(document).trigger( 'astra-sites-reset-data' );
291
- } else {
292
- $(document).trigger( 'astra-sites-reset-data-done' );
293
- }
294
- },
295
-
296
- _reset_customizer_data: function() {
297
- $.ajax({
298
- url : astraSitesAdmin.ajaxurl,
299
- type : 'POST',
300
- data : {
301
- action : 'astra-sites-reset-customizer-data'
302
- },
303
- beforeSend: function() {
304
- AstraSitesAdmin._log_title( 'Reseting Customizer Data..' );
305
- },
306
- })
307
- .fail(function( jqXHR ){
308
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
309
- })
310
- .done(function ( data ) {
311
- AstraSitesAdmin._log_title( 'Complete Resetting Customizer Data..' );
312
- $(document).trigger( 'astra-sites-reset-customizer-data-done' );
313
- });
314
- },
315
-
316
- _reset_site_options: function() {
317
- // Site Options.
318
- $.ajax({
319
- url : astraSitesAdmin.ajaxurl,
320
- type : 'POST',
321
- data : {
322
- action : 'astra-sites-reset-site-options'
323
- },
324
- beforeSend: function() {
325
- AstraSitesAdmin._log_title( 'Reseting Site Options..' );
326
- },
327
- })
328
- .fail(function( jqXHR ){
329
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
330
- })
331
- .done(function ( data ) {
332
- AstraSitesAdmin._log_title( 'Complete Reseting Site Options..' );
333
- $(document).trigger( 'astra-sites-reset-site-options-done' );
334
- });
335
- },
336
-
337
- _reset_widgets_data: function() {
338
- // Widgets.
339
- $.ajax({
340
- url : astraSitesAdmin.ajaxurl,
341
- type : 'POST',
342
- data : {
343
- action : 'astra-sites-reset-widgets-data'
344
- },
345
- beforeSend: function() {
346
- AstraSitesAdmin._log_title( 'Reseting Widgets..' );
347
- },
348
- })
349
- .fail(function( jqXHR ){
350
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
351
- })
352
- .done(function ( data ) {
353
- AstraSitesAdmin._log_title( 'Complete Reseting Widgets..' );
354
- $(document).trigger( 'astra-sites-reset-widgets-data-done' );
355
- });
356
- },
357
-
358
- _reset_posts: function() {
359
- if( AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
360
-
361
- AstraSitesAdmin.reset_remaining_posts = AstraSitesAdmin.site_imported_data['reset_posts'].length;
362
-
363
- $.each( AstraSitesAdmin.site_imported_data['reset_posts'], function(index, post_id) {
364
-
365
- AstraSitesAdmin._log_title( 'Deleting Posts..' );
366
-
367
- AstraSitesAjaxQueue.add({
368
- url: astraSitesAdmin.ajaxurl,
369
- type: 'POST',
370
- data: {
371
- action : 'astra-sites-delete-posts',
372
- post_id : post_id,
373
- },
374
- success: function( result ){
375
-
376
- if( AstraSitesAdmin.reset_processed_posts < AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
377
- AstraSitesAdmin.reset_processed_posts+=1;
378
- }
379
-
380
- AstraSitesAdmin._log_title( 'Deleting Post ' + AstraSitesAdmin.reset_processed_posts + ' of ' + AstraSitesAdmin.site_imported_data['reset_posts'].length + '<br/>' + result.data );
381
-
382
- AstraSitesAdmin.reset_remaining_posts-=1;
383
- if( 0 == AstraSitesAdmin.reset_remaining_posts ) {
384
- $(document).trigger( 'astra-sites-delete-posts-done' );
385
- $(document).trigger( 'astra-sites-reset-data-done' );
386
- }
387
- }
388
- });
389
- });
390
- AstraSitesAjaxQueue.run();
391
-
392
- } else {
393
- $(document).trigger( 'astra-sites-delete-posts-done' );
394
- $(document).trigger( 'astra-sites-reset-data-done' );
395
- }
396
- },
397
-
398
- _reset_wp_forms: function() {
399
-
400
- if( AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
401
- AstraSitesAdmin.reset_remaining_wp_forms = AstraSitesAdmin.site_imported_data['reset_wp_forms'].length;
402
-
403
- $.each( AstraSitesAdmin.site_imported_data['reset_wp_forms'], function(index, post_id) {
404
- AstraSitesAdmin._log_title( 'Deleting WP Forms..' );
405
- AstraSitesAjaxQueue.add({
406
- url: astraSitesAdmin.ajaxurl,
407
- type: 'POST',
408
- data: {
409
- action : 'astra-sites-delete-wp-forms',
410
- post_id : post_id,
411
- },
412
- success: function( result ){
413
-
414
- if( AstraSitesAdmin.reset_processed_wp_forms < AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
415
- AstraSitesAdmin.reset_processed_wp_forms+=1;
416
- }
417
-
418
- AstraSitesAdmin._log_title( 'Deleting Form ' + AstraSitesAdmin.reset_processed_wp_forms + ' of ' + AstraSitesAdmin.site_imported_data['reset_wp_forms'].length + '<br/>' + result.data );
419
-
420
- AstraSitesAdmin.reset_remaining_wp_forms-=1;
421
- if( 0 == AstraSitesAdmin.reset_remaining_wp_forms ) {
422
- $(document).trigger( 'astra-sites-delete-wp-forms-done' );
423
- }
424
- }
425
- });
426
- });
427
- AstraSitesAjaxQueue.run();
428
-
429
- } else {
430
- $(document).trigger( 'astra-sites-delete-wp-forms-done' );
431
- }
432
- },
433
-
434
-
435
- _reset_terms: function() {
436
-
437
-
438
- if( AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
439
- AstraSitesAdmin.reset_remaining_terms = AstraSitesAdmin.site_imported_data['reset_terms'].length;
440
-
441
- $.each( AstraSitesAdmin.site_imported_data['reset_terms'], function(index, term_id) {
442
- AstraSitesAdmin._log_title( 'Deleting Terms..' );
443
- AstraSitesAjaxQueue.add({
444
- url: astraSitesAdmin.ajaxurl,
445
- type: 'POST',
446
- data: {
447
- action : 'astra-sites-delete-terms',
448
- term_id : term_id,
449
- },
450
- success: function( result ){
451
- if( AstraSitesAdmin.reset_processed_terms < AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
452
- AstraSitesAdmin.reset_processed_terms+=1;
453
- }
454
-
455
- AstraSitesAdmin._log_title( 'Deleting Term ' + AstraSitesAdmin.reset_processed_terms + ' of ' + AstraSitesAdmin.site_imported_data['reset_terms'].length + '<br/>' + result.data );
456
-
457
- AstraSitesAdmin.reset_remaining_terms-=1;
458
- if( 0 == AstraSitesAdmin.reset_remaining_terms ) {
459
- $(document).trigger( 'astra-sites-delete-terms-done' );
460
- }
461
- }
462
- });
463
- });
464
- AstraSitesAjaxQueue.run();
465
-
466
- } else {
467
- $(document).trigger( 'astra-sites-delete-terms-done' );
468
- }
469
-
470
- },
471
-
472
- _toggle_reset_notice: function() {
473
- if ( $( this ).is(':checked') ) {
474
- $('#astra-sites-tooltip-reset-data').show();
475
- } else {
476
- $('#astra-sites-tooltip-reset-data').hide();
477
- }
478
- },
479
-
480
- _backup_before_rest_options: function() {
481
- AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-before-reset-done' );
482
- AstraSitesAdmin.backup_taken = true;
483
- },
484
-
485
- _recheck_backup_options: function() {
486
- AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-done' );
487
- AstraSitesAdmin.backup_taken = true;
488
- },
489
-
490
- _backupOptions: function( trigger_name ) {
491
- $.ajax({
492
- url : astraSitesAdmin.ajaxurl,
493
- type : 'POST',
494
- data : {
495
- action : 'astra-sites-backup-settings',
496
- },
497
- beforeSend: function() {
498
- AstraSitesAdmin._log_title( 'Processing Customizer Settings Backup..' );
499
- },
500
- })
501
- .fail(function( jqXHR ){
502
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
503
- })
504
- .done(function ( data ) {
505
-
506
- // 1. Pass - Import Customizer Options.
507
- AstraSitesAdmin._log_title( 'Customizer Settings Backup Done..' );
508
-
509
- // Custom trigger.
510
- $(document).trigger( trigger_name );
511
- });
512
- },
513
-
514
- _import_settings: function( event ) {
515
- event.preventDefault();
516
-
517
- var btn = $(this);
518
-
519
- btn.addClass('updating-message');
520
-
521
-
522
- $.ajax({
523
- url : astraSitesAdmin.ajaxurl,
524
- type : 'POST',
525
- dataType: 'json',
526
- data : {
527
- action : 'astra-sites-import-customizer-settings',
528
- customizer_data : AstraSitesAdmin.current_site['astra-site-customizer-data'],
529
- },
530
- beforeSend: function() {
531
- AstraSitesAdmin._log_title( 'Importing Customizer Settings..' );
532
- },
533
- })
534
- .fail(function( jqXHR ){
535
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
536
- })
537
- .done(function ( customizer_data ) {
538
-
539
- btn.removeClass( 'updating-message' );
540
-
541
- // 1. Fail - Import Customizer Options.
542
- if( false === customizer_data.success ) {
543
- AstraSitesAdmin._log_title( customizer_data.data );
544
- } else {
545
-
546
- // 1. Pass - Import Customizer Options.
547
- AstraSitesAdmin._log_title( 'Imported Customizer Settings..' );
548
-
549
- $(document).trigger( 'astra-sites-import-customizer-settings-done' );
550
- }
551
- });
552
- },
553
-
554
- /**
555
- * 5. Import Complete.
556
- */
557
- _importEnd: function( event ) {
558
-
559
- $.ajax({
560
- url : astraSitesAdmin.ajaxurl,
561
- type : 'POST',
562
- dataType: 'json',
563
- data : {
564
- action : 'astra-sites-import-end',
565
- },
566
- beforeSend: function() {
567
- AstraSitesAdmin._log_title( 'Import Complete!' );
568
- }
569
- })
570
- .fail(function( jqXHR ){
571
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
572
- })
573
- .done(function ( data ) {
574
-
575
- // 5. Fail - Import Complete.
576
- if( false === data.success ) {
577
- AstraSitesAdmin._log_title( data.data );
578
- } else {
579
-
580
- $('body').removeClass('importing-site');
581
- $('.previous-theme, .next-theme').removeClass('disabled');
582
-
583
- var date = new Date();
584
-
585
- AstraSitesAdmin.import_end_time = new Date();
586
- var diff = ( AstraSitesAdmin.import_end_time.getTime() - AstraSitesAdmin.import_start_time.getTime() );
587
-
588
- var time = '';
589
- var seconds = Math.floor( diff / 1000 );
590
- var minutes = Math.floor( seconds / 60 );
591
- var hours = Math.floor( minutes / 60 );
592
-
593
- minutes = minutes - ( hours * 60 );
594
- seconds = seconds - ( minutes * 60 );
595
-
596
- if( hours ) {
597
- time += hours + ' Hours ';
598
- }
599
- if( minutes ) {
600
- time += minutes + ' Minutes ';
601
- }
602
- if( seconds ) {
603
- time += seconds + ' Seconds';
604
- }
605
-
606
- var output = '<h2>Done 🎉</h2>';
607
- output += '<p>Your starter site has been imported successfully in '+time+'! Now go ahead, customize the text, images, and design to make it yours!</p>';
608
- output += '<p>You can now start making changes according to your requirements.</p>';
609
- output += '<p><a class="button button-primary button-hero" href="'+astraSitesAdmin.siteURL+'" target="_blank">View Site <i class="dashicons dashicons-external"></i></a></p>';
610
-
611
- $('.rotating,.current-importing-status-wrap,.notice-warning').remove();
612
- $('.astra-sites-result-preview .inner').html(output);
613
-
614
- // 5. Pass - Import Complete.
615
- AstraSitesAdmin._importSuccessButton();
616
- }
617
- });
618
- },
619
-
620
- /**
621
- * 4. Import Widgets.
622
- */
623
- _importWidgets: function( event ) {
624
- if ( AstraSitesAdmin._is_process_widgets() ) {
625
- $.ajax({
626
- url : astraSitesAdmin.ajaxurl,
627
- type : 'POST',
628
- dataType: 'json',
629
- data : {
630
- action : 'astra-sites-import-widgets',
631
- widgets_data : AstraSitesAdmin.widgets_data,
632
- },
633
- beforeSend: function() {
634
- AstraSitesAdmin._log_title( 'Importing Widgets..' );
635
- },
636
- })
637
- .fail(function( jqXHR ){
638
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
639
- })
640
- .done(function ( widgets_data ) {
641
-
642
- // 4. Fail - Import Widgets.
643
- if( false === widgets_data.success ) {
644
- AstraSitesAdmin._log_title( widgets_data.data );
645
-
646
- } else {
647
-
648
- // 4. Pass - Import Widgets.
649
- AstraSitesAdmin._log_title( 'Imported Widgets!' );
650
- $(document).trigger( 'astra-sites-import-widgets-done' );
651
- }
652
- });
653
- } else {
654
- $(document).trigger( 'astra-sites-import-widgets-done' );
655
- }
656
- },
657
-
658
- /**
659
- * 3. Import Site Options.
660
- */
661
- _importSiteOptions: function( event ) {
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-options',
670
- options_data : AstraSitesAdmin.options_data,
671
- },
672
- beforeSend: function() {
673
- AstraSitesAdmin._log_title( 'Importing Options..' );
674
- $('.astra-demo-import .percent').html('');
675
- },
676
- })
677
- .fail(function( jqXHR ){
678
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
679
- })
680
- .done(function ( options_data ) {
681
-
682
- // 3. Fail - Import Site Options.
683
- if( false === options_data.success ) {
684
- AstraSitesAdmin._log_title( options_data );
685
- } else {
686
-
687
- // 3. Pass - Import Site Options.
688
- $(document).trigger( 'astra-sites-import-options-done' );
689
- }
690
- });
691
- } else {
692
- $(document).trigger( 'astra-sites-import-options-done' );
693
- }
694
- },
695
-
696
- /**
697
- * 2. Prepare XML Data.
698
- */
699
- _importXML: function() {
700
-
701
- if ( AstraSitesAdmin._is_process_xml() ) {
702
- $.ajax({
703
- url : astraSitesAdmin.ajaxurl,
704
- type : 'POST',
705
- dataType: 'json',
706
- data : {
707
- action : 'astra-sites-import-prepare-xml',
708
- wxr_url : AstraSitesAdmin.current_site['astra-site-wxr-path'],
709
- },
710
- beforeSend: function() {
711
- $('.astra-site-import-process-wrap').show();
712
- AstraSitesAdmin._log_title( 'Importing Content..' );
713
- },
714
- })
715
- .fail(function( jqXHR ){
716
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
717
- })
718
- .done(function ( xml_data ) {
719
-
720
- // 2. Fail - Prepare XML Data.
721
- if( false === xml_data.success ) {
722
- AstraSitesAdmin._log_title( xml_data );
723
- var error_msg = xml_data.data.error || xml_data.data;
724
- AstraSitesAdmin._log_title( error_msg );
725
-
726
- } else {
727
-
728
- // 2. Pass - Prepare XML Data.
729
-
730
- // Import XML though Event Source.
731
- AstraSSEImport.data = xml_data.data;
732
- AstraSSEImport.render();
733
-
734
- $('.current-importing-status-description').html('').show();
735
-
736
- $('.astra-sites-result-preview .inner').append('<div class="astra-site-import-process-wrap"><progress class="astra-site-import-process" max="100" value="0"></progress></div>');
737
-
738
- var evtSource = new EventSource( AstraSSEImport.data.url );
739
- evtSource.onmessage = function ( message ) {
740
- var data = JSON.parse( message.data );
741
- switch ( data.action ) {
742
- case 'updateDelta':
743
-
744
- AstraSSEImport.updateDelta( data.type, data.delta );
745
- break;
746
-
747
- case 'complete':
748
- evtSource.close();
749
-
750
- $('.current-importing-status-description').hide();
751
-
752
- document.getElementsByClassName("astra-site-import-process").value = '100';
753
-
754
- $('.astra-site-import-process-wrap').hide();
755
-
756
- $(document).trigger( 'astra-sites-import-xml-done' );
757
-
758
- break;
759
- }
760
- };
761
- evtSource.addEventListener( 'log', function ( message ) {
762
- var data = JSON.parse( message.data );
763
- var message = data.message || '';
764
- if( message && 'info' === data.level ) {
765
- message = message.replace(/"/g, function(letter) {
766
- return '';
767
- });
768
- $('.current-importing-status-description').html( message );
769
- }
770
- });
771
- }
772
- });
773
- } else {
774
- $(document).trigger( 'astra-sites-import-xml-done' );
775
- }
776
-
777
-
778
- },
779
-
780
- _is_process_xml: function() {
781
- if ( $( '.astra-sites-import-xml' ).find('.checkbox').is(':checked') ) {
782
- return true;
783
- }
784
- return false;
785
- },
786
-
787
- _is_process_customizer: function() {
788
- if ( $( '.astra-sites-import-customizer' ).find('.checkbox').is(':checked') ) {
789
- return true;
790
- }
791
- return false;
792
- },
793
-
794
- _is_process_widgets: function() {
795
- if ( $( '.astra-sites-import-widgets' ).find('.checkbox').is(':checked') ) {
796
- return true;
797
- }
798
- return false;
799
- },
800
-
801
- /**
802
- * 1. Import WPForms Options.
803
- */
804
- _importWPForms: function( event ) {
805
- if ( AstraSitesAdmin._is_process_customizer() ) {
806
- $.ajax({
807
- url : astraSitesAdmin.ajaxurl,
808
- type : 'POST',
809
- dataType: 'json',
810
- data : {
811
- action : 'astra-sites-import-wpforms',
812
- wpforms_url : AstraSitesAdmin.wpforms_url,
813
- },
814
- beforeSend: function() {
815
- AstraSitesAdmin._log_title( 'Importing WP Forms..' );
816
- },
817
- })
818
- .fail(function( jqXHR ){
819
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
820
- })
821
- .done(function ( forms ) {
822
-
823
- // 1. Fail - Import WPForms Options.
824
- if( false === forms.success ) {
825
- AstraSitesAdmin._log_title( forms.data );
826
- } else {
827
-
828
- // 1. Pass - Import Customizer Options.
829
- $(document).trigger( 'astra-sites-import-wpforms-done' );
830
- }
831
- });
832
- } else {
833
- $(document).trigger( 'astra-sites-import-wpforms-done' );
834
- }
835
- },
836
-
837
- /**
838
- * 1. Import Customizer Options.
839
- */
840
- _importCustomizerSettings: function( event ) {
841
- if ( AstraSitesAdmin._is_process_customizer() ) {
842
- $.ajax({
843
- url : astraSitesAdmin.ajaxurl,
844
- type : 'POST',
845
- dataType: 'json',
846
- data : {
847
- action : 'astra-sites-import-customizer-settings',
848
- customizer_data : AstraSitesAdmin.customizer_data,
849
- },
850
- beforeSend: function() {
851
- },
852
- })
853
- .fail(function( jqXHR ){
854
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
855
- })
856
- .done(function ( customizer_data ) {
857
-
858
- // 1. Fail - Import Customizer Options.
859
- if( false === customizer_data.success ) {
860
- AstraSitesAdmin._log_title( customizer_data.data );
861
- } else {
862
-
863
- // 1. Pass - Import Customizer Options.
864
- $(document).trigger( 'astra-sites-import-customizer-settings-done' );
865
- }
866
- });
867
- } else {
868
- $(document).trigger( 'astra-sites-import-customizer-settings-done' );
869
- }
870
-
871
- },
872
-
873
- /**
874
- * Import Success Button.
875
- *
876
- * @param {string} data Error message.
877
- */
878
- _importSuccessButton: function() {
879
-
880
- $('.astra-demo-import').removeClass('updating-message installing')
881
- .removeAttr('data-import')
882
- .addClass('view-site')
883
- .removeClass('astra-demo-import')
884
- .text( astraSitesAdmin.strings.viewSite )
885
- .attr('target', '_blank')
886
- .append('<i class="dashicons dashicons-external"></i>')
887
- .attr('href', astraSitesAdmin.siteURL );
888
- },
889
-
890
- /**
891
- * Preview Device
892
- */
893
- _previewDevice: function( event ) {
894
- var device = $( event.currentTarget ).data( 'device' );
895
-
896
- $('.theme-install-overlay')
897
- .removeClass( 'preview-desktop preview-tablet preview-mobile' )
898
- .addClass( 'preview-' + device )
899
- .data( 'current-preview-device', device );
900
-
901
- AstraSitesAdmin._tooglePreviewDeviceButtons( device );
902
- },
903
-
904
- /**
905
- * Toggle Preview Buttons
906
- */
907
- _tooglePreviewDeviceButtons: function( newDevice ) {
908
- var $devices = $( '.wp-full-overlay-footer .devices' );
909
-
910
- $devices.find( 'button' )
911
- .removeClass( 'active' )
912
- .attr( 'aria-pressed', false );
913
-
914
- $devices.find( 'button.preview-' + newDevice )
915
- .addClass( 'active' )
916
- .attr( 'aria-pressed', true );
917
- },
918
-
919
- /**
920
- * Import Error Button.
921
- *
922
- * @param {string} data Error message.
923
- */
924
- _importFailMessage: function( message, from ) {
925
-
926
- $('.astra-demo-import')
927
- .addClass('go-pro button-primary')
928
- .removeClass('updating-message installing')
929
- .removeAttr('data-import')
930
- .attr('target', '_blank')
931
- .append('<i class="dashicons dashicons-external"></i>')
932
- .removeClass('astra-demo-import');
933
-
934
- // Add the doc link due to import log file not generated.
935
- if( 'undefined' === from ) {
936
-
937
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailedBtnSmall );
938
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailedBtnLarge );
939
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
940
-
941
- // Add the import log file link.
942
- } else {
943
-
944
- $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
945
- $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
946
-
947
- // Add the import log file link.
948
- if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
949
- $('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
950
- } else {
951
- $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
952
- }
953
- }
954
-
955
- var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
956
- output += ' <p>'+message+'</p>';
957
- output += ' <button type="button" class="notice-dismiss">';
958
- output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
959
- output += ' </button>';
960
- output += '</div>';
961
-
962
- // Fail Notice.
963
- $('.install-theme-info').append( output );
964
-
965
- // !important to add trigger.
966
- // Which reinitialize the dismiss error message events.
967
- $(document).trigger('wp-updates-notice-added');
968
- },
969
-
970
-
971
- /**
972
- * Install Now
973
- */
974
- _installNow: function(event)
975
- {
976
- event.preventDefault();
977
-
978
- var $button = jQuery( event.target ),
979
- $document = jQuery(document);
980
-
981
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
982
- return;
983
- }
984
-
985
- AstraSitesAdmin._log_title( 'Installing Required Plugin..' );
986
-
987
- if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
988
- wp.updates.requestFilesystemCredentials( event );
989
-
990
- $document.on( 'credential-modal-cancel', function() {
991
- var $message = $( '.install-now.updating-message' );
992
-
993
- $message
994
- .removeClass( 'updating-message' )
995
- .text( wp.updates.l10n.installNow );
996
-
997
- wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
998
- } );
999
- }
1000
-
1001
- AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( $button.data( 'name' ) ) );
1002
-
1003
- wp.updates.installPlugin( {
1004
- slug: $button.data( 'slug' )
1005
- } );
1006
- },
1007
-
1008
- ucwords: function( str ) {
1009
- if( ! str ) {
1010
- return '';
1011
- }
1012
-
1013
- str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
1014
- return letter.toUpperCase();
1015
- });
1016
-
1017
- str = str.replace(/-/g, function(letter) {
1018
- return ' ';
1019
- });
1020
-
1021
- return str;
1022
- },
1023
-
1024
- /**
1025
- * Install Success
1026
- */
1027
- _installSuccess: function( event, response ) {
1028
-
1029
- event.preventDefault();
1030
-
1031
-
1032
- var $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val();
1033
-
1034
- var $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1035
-
1036
- // Transform the 'Install' button into an 'Activate' button.
1037
- var $init = $( '.plugin-card-' + response.slug ).data('init');
1038
- var $name = $( '.plugin-card-' + response.slug ).data('name');
1039
-
1040
- // Reset not installed plugins list.
1041
- var pluginsList = astraSitesAdmin.requiredPlugins.notinstalled;
1042
- astraSitesAdmin.requiredPlugins.notinstalled = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1043
-
1044
- // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
1045
- setTimeout( function() {
1046
-
1047
- AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords($name) );
1048
-
1049
- $.ajax({
1050
- url: astraSitesAdmin.ajaxurl,
1051
- type: 'POST',
1052
- data: {
1053
- 'action' : 'astra-required-plugin-activate',
1054
- 'init' : $init,
1055
- 'options' : $siteOptions,
1056
- 'enabledExtensions' : $enabledExtensions,
1057
- },
1058
- })
1059
- .done(function (result) {
1060
-
1061
- if( result.success ) {
1062
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1063
-
1064
- AstraSitesAdmin._log_title( 'Installed Plugin - ' + AstraSitesAdmin.ucwords($name) );
1065
-
1066
- // Reset not installed plugins list.
1067
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1068
-
1069
- // Enable Demo Import Button
1070
- AstraSitesAdmin._enable_demo_import_button();
1071
-
1072
- }
1073
- });
1074
-
1075
- }, 1200 );
1076
-
1077
- },
1078
-
1079
- /**
1080
- * Plugin Installation Error.
1081
- */
1082
- _installError: function( event, response ) {
1083
-
1084
- var $card = $( '.plugin-card-' + response.slug );
1085
- var $name = $card.data('name');
1086
-
1087
- AstraSitesAdmin._log_title( response.errorMessage + ' ' + AstraSitesAdmin.ucwords($name) );
1088
-
1089
-
1090
- $card
1091
- .removeClass( 'button-primary' )
1092
- .addClass( 'disabled' )
1093
- .html( wp.updates.l10n.installFailedShort );
1094
-
1095
- },
1096
-
1097
- /**
1098
- * Installing Plugin
1099
- */
1100
- _pluginInstalling: function(event, args) {
1101
- event.preventDefault();
1102
-
1103
- var $card = $( '.plugin-card-' + args.slug );
1104
- var $name = $card.data('name');
1105
-
1106
- AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( $name ));
1107
-
1108
- $card.addClass('updating-message');
1109
-
1110
- },
1111
-
1112
- /**
1113
- * Render Demo Preview
1114
- */
1115
- _activateNow: function( eventn ) {
1116
-
1117
- event.preventDefault();
1118
-
1119
- var $button = jQuery( event.target ),
1120
- $init = $button.data( 'init' ),
1121
- $slug = $button.data( 'slug' );
1122
- $name = $button.data( 'name' );
1123
-
1124
- if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
1125
- return;
1126
- }
1127
-
1128
- AstraSitesAdmin._log_title( 'Activating Plugin - ' + AstraSitesAdmin.ucwords( $name ) );
1129
-
1130
- $button.addClass('updating-message button-primary')
1131
- .html( astraSitesAdmin.strings.btnActivating );
1132
-
1133
- var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
1134
- var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1135
-
1136
- $.ajax({
1137
- url: astraSitesAdmin.ajaxurl,
1138
- type: 'POST',
1139
- data: {
1140
- 'action' : 'astra-required-plugin-activate',
1141
- 'init' : $init,
1142
- 'options' : $siteOptions,
1143
- 'enabledExtensions' : $enabledExtensions,
1144
- },
1145
- })
1146
- .done(function (result) {
1147
-
1148
- if( result.success ) {
1149
-
1150
- AstraSitesAdmin._log_title( 'Activated Plugin - ' + AstraSitesAdmin.ucwords($name) );
1151
-
1152
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1153
-
1154
- // Reset not installed plugins list.
1155
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( $slug, pluginsList );
1156
-
1157
- $button.removeClass( 'button-primary install-now activate-now updating-message' )
1158
- .attr('disabled', 'disabled')
1159
- .addClass('disabled')
1160
- .text( astraSitesAdmin.strings.btnActive );
1161
-
1162
- // Enable Demo Import Button
1163
- AstraSitesAdmin._enable_demo_import_button();
1164
-
1165
- }
1166
-
1167
- })
1168
- .fail(function () {
1169
- });
1170
-
1171
- },
1172
-
1173
- /**
1174
- * Full Overlay
1175
- */
1176
- _fullOverlay: function (event) {
1177
- event.preventDefault();
1178
-
1179
- // Import process is started?
1180
- // And Closing the window? Then showing the warning confirm message.
1181
- if( $('body').hasClass('importing-site') && ! confirm( astraSitesAdmin.strings.warningBeforeCloseWindow ) ) {
1182
- return;
1183
- }
1184
-
1185
- $('body').removeClass('importing-site');
1186
- $('.previous-theme, .next-theme').removeClass('disabled');
1187
- $('.theme-install-overlay').css('display', 'none');
1188
- $('.theme-install-overlay').remove();
1189
- $('.theme-preview-on').removeClass('theme-preview-on');
1190
- $('html').removeClass('astra-site-preview-on');
1191
- },
1192
-
1193
- /**
1194
- * Bulk Plugin Active & Install
1195
- */
1196
- _bulkPluginInstallActivate: function()
1197
- {
1198
- if( 0 === astraSitesAdmin.requiredPlugins.length ) {
1199
- return;
1200
- }
1201
-
1202
- var not_installed = astraSitesAdmin.requiredPlugins.notinstalled || '';
1203
- var activate_plugins = astraSitesAdmin.requiredPlugins.inactive || '';
1204
-
1205
- // First Install Bulk.
1206
- if( not_installed.length > 0 ) {
1207
- AstraSitesAdmin._installAllPlugins( not_installed );
1208
- }
1209
-
1210
- // Second Activate Bulk.
1211
- if( activate_plugins.length > 0 ) {
1212
- AstraSitesAdmin._activateAllPlugins( activate_plugins );
1213
- }
1214
-
1215
- if( activate_plugins.length <= 0 && not_installed.length <= 0 ) {
1216
- AstraSitesAdmin._enable_demo_import_button();
1217
- }
1218
-
1219
- },
1220
-
1221
- /**
1222
- * Activate All Plugins.
1223
- */
1224
- _activateAllPlugins: function( activate_plugins ) {
1225
-
1226
- AstraSitesAdmin._log_title( 'Activating Required Plugins..' );
1227
-
1228
- $.each( activate_plugins, function(index, single_plugin) {
1229
-
1230
- var $card = $( '.plugin-card-' + single_plugin.slug ),
1231
- $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val(),
1232
- $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1233
-
1234
-
1235
- AstraSitesAjaxQueue.add({
1236
- url: astraSitesAdmin.ajaxurl,
1237
- type: 'POST',
1238
- data: {
1239
- 'action' : 'astra-required-plugin-activate',
1240
- 'init' : single_plugin.init,
1241
- 'options' : $siteOptions,
1242
- 'enabledExtensions' : $enabledExtensions,
1243
- },
1244
- success: function( result ){
1245
-
1246
- if( result.success ) {
1247
-
1248
- var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1249
-
1250
- // Reset not installed plugins list.
1251
- astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( single_plugin.slug, pluginsList );
1252
-
1253
- // Enable Demo Import Button
1254
- AstraSitesAdmin._enable_demo_import_button();
1255
- } else {
1256
- }
1257
- }
1258
- });
1259
- });
1260
- AstraSitesAjaxQueue.run();
1261
- },
1262
-
1263
- /**
1264
- * Install All Plugins.
1265
- */
1266
- _installAllPlugins: function( not_installed ) {
1267
-
1268
- AstraSitesAdmin._log_title( 'Installing Required Plugins..' );
1269
-
1270
- $.each( not_installed, function(index, single_plugin) {
1271
-
1272
- AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( single_plugin.name ));
1273
-
1274
- var $card = $( '.plugin-card-' + single_plugin.slug );
1275
-
1276
- // Add each plugin activate request in Ajax queue.
1277
- // @see wp-admin/js/updates.js
1278
- wp.updates.queue.push( {
1279
- action: 'install-plugin', // Required action.
1280
- data: {
1281
- slug: single_plugin.slug
1282
- }
1283
- } );
1284
- });
1285
-
1286
- // Required to set queue.
1287
- wp.updates.queueChecker();
1288
- },
1289
-
1290
- /**
1291
- * Fires when a nav item is clicked.
1292
- *
1293
- * @since 1.0
1294
- * @access private
1295
- * @method _importDemo
1296
- */
1297
- _importDemo: function(event) {
1298
- event.preventDefault();
1299
-
1300
- var date = new Date();
1301
-
1302
- AstraSitesAdmin.import_start_time = new Date();
1303
-
1304
- var disabled = $(this).attr('data-import');
1305
-
1306
- if ( typeof disabled !== 'undefined' && disabled === 'disabled' || $this.hasClass('disabled') ) {
1307
-
1308
- $('.astra-demo-import').addClass('updating-message installing')
1309
- .text( wp.updates.l10n.installing );
1310
-
1311
- $('.astra-sites-result-preview').show();
1312
- var output = '<div class="current-importing-status-title"></div><div class="current-importing-status-description"></div>';
1313
- $('.current-importing-status').html( output );
1314
-
1315
- /**
1316
- * Process Bulk Plugin Install & Activate
1317
- */
1318
- AstraSitesAdmin._bulkPluginInstallActivate();
1319
- }
1320
- },
1321
-
1322
- _process_import: function() {
1323
-
1324
- var $theme = $('.astra-sites-preview').find('.wp-full-overlay-header'),
1325
- apiURL = $theme.data('demo-api') || '';
1326
-
1327
- $('body').addClass('importing-site');
1328
- $('.previous-theme, .next-theme').addClass('disabled');
1329
-
1330
- // Remove all notices before import start.
1331
- $('.install-theme-info > .notice').remove();
1332
-
1333
- $('.astra-demo-import').attr('data-import', 'disabled')
1334
- .addClass('updating-message installing')
1335
- .text( astraSitesAdmin.strings.importingDemo );
1336
-
1337
- // Site Import by API URL.
1338
- if( apiURL ) {
1339
- AstraSitesAdmin._importSite( apiURL );
1340
- }
1341
-
1342
- },
1343
-
1344
- /**
1345
- * Start Import Process by API URL.
1346
- *
1347
- * @param {string} apiURL Site API URL.
1348
- */
1349
- _importSite: function( apiURL ) {
1350
-
1351
- AstraSitesAdmin._log_title( 'Started Importing..' );
1352
-
1353
- // 1. Request Site Import
1354
- $.ajax({
1355
- url : astraSitesAdmin.ajaxurl,
1356
- type : 'POST',
1357
- dataType: 'json',
1358
- data : {
1359
- 'action' : 'astra-sites-import-set-site-data',
1360
- 'api_url' : apiURL,
1361
- },
1362
- })
1363
- .fail(function( jqXHR ){
1364
- AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
1365
- })
1366
- .done(function ( demo_data ) {
1367
-
1368
- // 1. Fail - Request Site Import
1369
- if( false === demo_data.success ) {
1370
-
1371
-
1372
- } else {
1373
-
1374
- // Set log file URL.
1375
- if( 'log_file' in demo_data.data ){
1376
- AstraSitesAdmin.log_file_url = decodeURIComponent( demo_data.data.log_file ) || '';
1377
- }
1378
-
1379
- // 1. Pass - Request Site Import
1380
- AstraSitesAdmin.customizer_data = JSON.stringify( demo_data.data['astra-site-customizer-data'] ) || '';
1381
- AstraSitesAdmin.wxr_url = encodeURI( demo_data.data['astra-site-wxr-path'] ) || '';
1382
- AstraSitesAdmin.wpforms_url = encodeURI( demo_data.data['astra-site-wpforms-path'] ) || '';
1383
- AstraSitesAdmin.options_data = JSON.stringify( demo_data.data['astra-site-options-data'] ) || '';
1384
- AstraSitesAdmin.widgets_data = JSON.stringify( demo_data.data['astra-site-widgets-data'] ) || '';
1385
-
1386
- $(document).trigger( 'astra-sites-import-set-site-data-done' );
1387
- }
1388
-
1389
- });
1390
-
1391
- },
1392
-
1393
- /**
1394
- * Collapse Sidebar.
1395
- */
1396
- _collapse: function() {
1397
- event.preventDefault();
1398
-
1399
- overlay = jQuery('.wp-full-overlay');
1400
-
1401
- if (overlay.hasClass('expanded')) {
1402
- overlay.removeClass('expanded');
1403
- overlay.addClass('collapsed');
1404
- return;
1405
- }
1406
-
1407
- if (overlay.hasClass('collapsed')) {
1408
- overlay.removeClass('collapsed');
1409
- overlay.addClass('expanded');
1410
- return;
1411
- }
1412
- },
1413
-
1414
- /**
1415
- * Previous Theme.
1416
- */
1417
- _previousTheme: function (event) {
1418
- event.preventDefault();
1419
-
1420
- currentDemo = jQuery('.theme-preview-on');
1421
- currentDemo.removeClass('theme-preview-on');
1422
- prevDemo = currentDemo.prev('.theme');
1423
- prevDemo.addClass('theme-preview-on');
1424
-
1425
- var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1426
-
1427
- if( AstraSitesAPI._stored_data ) {
1428
- var site_data = AstraSitesAdmin._get_site_details( site_id );
1429
-
1430
-
1431
- if( site_data ) {
1432
- // Set current site details.
1433
- AstraSitesAdmin.current_site = site_data;
1434
- }
1435
- }
1436
-
1437
- AstraSitesAdmin._renderDemoPreview(prevDemo);
1438
- },
1439
-
1440
- /**
1441
- * Next Theme.
1442
- */
1443
- _nextTheme: function (event) {
1444
- event.preventDefault();
1445
- currentDemo = jQuery('.theme-preview-on')
1446
- currentDemo.removeClass('theme-preview-on');
1447
- nextDemo = currentDemo.next('.theme');
1448
- nextDemo.addClass('theme-preview-on');
1449
-
1450
- var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1451
-
1452
- if( AstraSitesAPI._stored_data ) {
1453
- var site_data = AstraSitesAdmin._get_site_details( site_id );
1454
-
1455
- if( site_data ) {
1456
- // Set current site details.
1457
- AstraSitesAdmin.current_site = site_data;
1458
- }
1459
- }
1460
-
1461
- AstraSitesAdmin._renderDemoPreview( nextDemo );
1462
- },
1463
-
1464
- _set_current_screen: function( screen ) {
1465
- AstraSitesAdmin.current_screen = screen;
1466
- var old_screen = $('.astra-sites-preview').attr( 'screen' ) || '';
1467
-
1468
-
1469
- if( old_screen ) {
1470
- $('.astra-sites-preview').removeClass( 'screen-' + old_screen );
1471
- }
1472
-
1473
- $('.astra-sites-preview').attr( 'screen', screen );
1474
- $('.astra-sites-preview').addClass( 'screen-' + screen );
1475
- },
1476
-
1477
- /**
1478
- * Individual Site Preview
1479
- *
1480
- * On click on image, more link & preview button.
1481
- */
1482
- _preview: function( event ) {
1483
-
1484
- event.preventDefault();
1485
-
1486
- var site_id = $(this).parents('.site-single').data('demo-id') || '';
1487
-
1488
- if( AstraSitesAPI._stored_data ) {
1489
- var site_data = AstraSitesAdmin._get_site_details( site_id );
1490
-
1491
- if( site_data ) {
1492
- // Set current site details.
1493
- AstraSitesAdmin.current_site = site_data;
1494
-
1495
- // Set current screen.
1496
- AstraSitesAdmin._set_current_screen( 'get-started' );
1497
- }
1498
- }
1499
-
1500
- var self = $(this).parents('.theme');
1501
- self.addClass('theme-preview-on');
1502
-
1503
- $('html').addClass('astra-site-preview-on');
1504
-
1505
- AstraSitesAdmin._renderDemoPreview( self );
1506
- },
1507
-
1508
- _get_site_details: function( site_id ) {
1509
- var all_sites = AstraSitesAPI._stored_data['astra-sites'] || [];
1510
-
1511
- if( ! all_sites ) {
1512
- return false;
1513
- }
1514
-
1515
- var single_site = all_sites.filter(function (site) { return site.id == site_id });
1516
- if( ! single_site ) {
1517
- return false;
1518
- }
1519
-
1520
- if( ! $.isArray( single_site ) ) {
1521
- return false;
1522
- }
1523
-
1524
- return single_site[0];
1525
- },
1526
-
1527
- /**
1528
- * Check Next Previous Buttons.
1529
- */
1530
- _checkNextPrevButtons: function() {
1531
- currentDemo = jQuery('.theme-preview-on');
1532
- nextDemo = currentDemo.nextAll('.theme').length;
1533
- prevDemo = currentDemo.prevAll('.theme').length;
1534
-
1535
- if (nextDemo == 0) {
1536
- jQuery('.next-theme').addClass('disabled');
1537
- } else if (nextDemo != 0) {
1538
- jQuery('.next-theme').removeClass('disabled');
1539
- }
1540
-
1541
- if (prevDemo == 0) {
1542
- jQuery('.previous-theme').addClass('disabled');
1543
- } else if (prevDemo != 0) {
1544
- jQuery('.previous-theme').removeClass('disabled');
1545
- }
1546
-
1547
- return;
1548
- },
1549
-
1550
- /**
1551
- * Render Demo Preview
1552
- */
1553
- _renderDemoPreview: function(anchor) {
1554
-
1555
- var demoId = anchor.data('demo-id') || '',
1556
- apiURL = anchor.data('demo-api') || '',
1557
- demoType = anchor.data('demo-type') || '',
1558
- demoURL = anchor.data('demo-url') || '',
1559
- screenshot = anchor.data('screenshot') || '',
1560
- demo_name = anchor.data('demo-name') || '',
1561
- demo_slug = anchor.data('demo-slug') || '',
1562
- content = anchor.data('content') || '',
1563
- requiredPlugins = anchor.data('required-plugins') || '',
1564
- astraSiteOptions = anchor.find('.astra-site-options').val() || '';
1565
- astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
1566
-
1567
- var template = wp.template('astra-site-preview');
1568
-
1569
- templateData = [{
1570
- id : demoId,
1571
- astra_demo_type : demoType,
1572
- astra_demo_url : demoURL,
1573
- demo_api : apiURL,
1574
- screenshot : screenshot,
1575
- demo_name : demo_name,
1576
- slug : demo_slug,
1577
- content : content,
1578
- required_plugins : JSON.stringify(requiredPlugins),
1579
- astra_site_options : astraSiteOptions,
1580
- astra_enabled_extensions : astraEnabledExtensions,
1581
- }];
1582
-
1583
- // delete any earlier fullscreen preview before we render new one.
1584
- $('.theme-install-overlay').remove();
1585
-
1586
- $('#astra-sites-menu-page').append(template(templateData[0]));
1587
- $('.theme-install-overlay').css('display', 'block');
1588
- AstraSitesAdmin._checkNextPrevButtons();
1589
-
1590
- var desc = $('.theme-details');
1591
- var descHeight = parseInt( desc.outerHeight() );
1592
- var descBtn = $('.theme-details-read-more');
1593
-
1594
- // Check is site imported recently and set flag.
1595
- $.ajax({
1596
- url : astraSitesAdmin.ajaxurl,
1597
- type : 'POST',
1598
- data : {
1599
- action : 'astra-sites-set-reset-data',
1600
- },
1601
- })
1602
- .done(function ( response ) {
1603
- if( response.success ) {
1604
- AstraSitesAdmin.site_imported_data = response.data;
1605
- }
1606
- });
1607
-
1608
- if( $.isArray( requiredPlugins ) ) {
1609
-
1610
- if( descHeight >= 55 ) {
1611
-
1612
- // Show button.
1613
- descBtn.css( 'display', 'inline-block' );
1614
-
1615
- // Set height upto 3 line.
1616
- desc.css( 'height', 57 );
1617
-
1618
- // Button Click.
1619
- descBtn.click(function(event) {
1620
-
1621
- if( descBtn.hasClass('open') ) {
1622
- desc.animate({ height: 57 },
1623
- 300, function() {
1624
- descBtn.removeClass('open');
1625
- descBtn.html( astraSitesAdmin.strings.DescExpand );
1626
- });
1627
- } else {
1628
- desc.animate({ height: descHeight },
1629
- 300, function() {
1630
- descBtn.addClass('open');
1631
- descBtn.html( astraSitesAdmin.strings.DescCollapse );
1632
- });
1633
- }
1634
-
1635
- });
1636
- }
1637
-
1638
- // or
1639
- var $pluginsFilter = $( '#plugin-filter' ),
1640
- data = {
1641
- action : 'astra-required-plugins',
1642
- _ajax_nonce : astraSitesAdmin._ajax_nonce,
1643
- required_plugins : requiredPlugins
1644
- };
1645
-
1646
- // Add disabled class from import button.
1647
- $('.astra-demo-import')
1648
- .addClass('disabled not-click-able')
1649
- .removeAttr('data-import');
1650
-
1651
- $('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
1652
-
1653
- // Required Required.
1654
- $.ajax({
1655
- url : astraSitesAdmin.ajaxurl,
1656
- type : 'POST',
1657
- data : data,
1658
- })
1659
- .fail(function( jqXHR ){
1660
-
1661
- // Remove loader.
1662
- $('.required-plugins').removeClass('loading').html('');
1663
-
1664
- })
1665
- .done(function ( response ) {
1666
- required_plugins = response.data['required_plugins'];
1667
-
1668
- if( response.data['third_party_required_plugins'].length ) {
1669
- $('.astra-demo-import').removeClass('button-primary').addClass('disabled');
1670
-
1671
- $('.astra-sites-third-party-required-plugins-wrap').remove();
1672
- var template = wp.template('astra-sites-third-party-required-plugins');
1673
- $('.astra-sites-advanced-options-wrap').html( template( response.data['third_party_required_plugins'] ) );
1674
- } else {
1675
- // Release disabled class from import button.
1676
- $('.astra-demo-import')
1677
- .removeClass('disabled not-click-able')
1678
- .attr('data-import', 'disabled');
1679
- }
1680
-
1681
- // Remove loader.
1682
- $('.required-plugins').removeClass('loading').html('');
1683
- $('.required-plugins-list').html('');
1684
-
1685
- /**
1686
- * Count remaining plugins.
1687
- * @type number
1688
- */
1689
- var remaining_plugins = 0;
1690
-
1691
- /**
1692
- * Not Installed
1693
- *
1694
- * List of not installed required plugins.
1695
- */
1696
- if ( typeof required_plugins.notinstalled !== 'undefined' ) {
1697
-
1698
- // Add not have installed plugins count.
1699
- remaining_plugins += parseInt( required_plugins.notinstalled.length );
1700
-
1701
- $( required_plugins.notinstalled ).each(function( index, plugin ) {
1702
- $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1703
- });
1704
- }
1705
-
1706
- /**
1707
- * Inactive
1708
- *
1709
- * List of not inactive required plugins.
1710
- */
1711
- if ( typeof required_plugins.inactive !== 'undefined' ) {
1712
-
1713
- // Add inactive plugins count.
1714
- remaining_plugins += parseInt( required_plugins.inactive.length );
1715
-
1716
- $( required_plugins.inactive ).each(function( index, plugin ) {
1717
- $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1718
- });
1719
- }
1720
-
1721
- /**
1722
- * Active
1723
- *
1724
- * List of not active required plugins.
1725
- */
1726
- if ( typeof required_plugins.active !== 'undefined' ) {
1727
-
1728
- $( required_plugins.active ).each(function( index, plugin ) {
1729
- $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1730
- });
1731
- }
1732
-
1733
- /**
1734
- * Enable Demo Import Button
1735
- * @type number
1736
- */
1737
- astraSitesAdmin.requiredPlugins = required_plugins;
1738
- });
1739
-
1740
- } else {
1741
-
1742
- // Enable Demo Import Button
1743
- AstraSitesAdmin._enable_demo_import_button( demoType );
1744
- $('.astra-sites-advanced-options-wrap').remove();
1745
- }
1746
-
1747
- return;
1748
- },
1749
-
1750
- /**
1751
- * Enable Demo Import Button.
1752
- */
1753
- _enable_demo_import_button: function( type ) {
1754
-
1755
- type = ( undefined !== type ) ? type : 'free';
1756
-
1757
- $('.install-theme-info .theme-details .site-description').remove();
1758
-
1759
- switch( type ) {
1760
-
1761
- case 'free':
1762
-
1763
- var notinstalled = astraSitesAdmin.requiredPlugins.notinstalled || 0;
1764
- var inactive = astraSitesAdmin.requiredPlugins.inactive || 0;
1765
-
1766
- if( notinstalled.length === inactive.length ) {
1767
-
1768
- // XML reader not available notice.
1769
- if( astraSitesAdmin.XMLReaderDisabled ) {
1770
- if( ! $('.install-theme-info .astra-sites-xml-notice').length ) {
1771
- $('.install-theme-info').prepend( astraSitesAdmin.strings.warningXMLReader );
1772
- }
1773
- $('.astra-demo-import')
1774
- .removeClass('installing updating-message')
1775
- .addClass('disabled')
1776
- .text( astraSitesAdmin.strings.importDemo );
1777
- } else {
1778
- $(document).trigger( 'astra-sites-install-and-activate-required-plugins-done' );
1779
- }
1780
- }
1781
- break;
1782
-
1783
- case 'upgrade':
1784
- var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1785
-
1786
- $('.astra-demo-import')
1787
- .addClass('go-pro button-primary')
1788
- .removeClass('astra-demo-import')
1789
- .attr('target', '_blank')
1790
- .attr('href', astraSitesAdmin.getUpgradeURL + demo_slug )
1791
- .text( astraSitesAdmin.getUpgradeText )
1792
- .append('<i class="dashicons dashicons-external"></i>');
1793
- break;
1794
-
1795
- default:
1796
- var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1797
-
1798
- $('.astra-demo-import')
1799
- .addClass('go-pro button-primary')
1800
- .removeClass('astra-demo-import')
1801
- .attr('target', '_blank')
1802
- .attr('href', astraSitesAdmin.getProURL )
1803
- .text( astraSitesAdmin.getProText )
1804
- .append('<i class="dashicons dashicons-external"></i>');
1805
-
1806
- $('.wp-full-overlay-header').find('.go-pro').remove();
1807
-
1808
- if( false == astraSitesAdmin.isWhiteLabeled ) {
1809
- if( astraSitesAdmin.isPro ) {
1810
- $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-inactive-site-description') );
1811
- } else {
1812
- $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-site-description') );
1813
- }
1814
- }
1815
-
1816
- break;
1817
- }
1818
-
1819
- },
1820
-
1821
- /**
1822
- * Update Page Count.
1823
- */
1824
- _updatedPagedCount: function() {
1825
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
1826
- jQuery('body').attr('data-astra-demo-paged', paged + 1);
1827
- window.setTimeout(function () {
1828
- jQuery('body').data('scrolling', false);
1829
- }, 800);
1830
- },
1831
-
1832
- /**
1833
- * Reset Page Count.
1834
- */
1835
- _resetPagedCount: function() {
1836
-
1837
- $('body').addClass('loading-content');
1838
- $('body').attr('data-astra-demo-last-request', '1');
1839
- $('body').attr('data-astra-demo-paged', '1');
1840
- $('body').attr('data-astra-demo-search', '');
1841
- $('body').attr('data-scrolling', false);
1842
-
1843
- },
1844
-
1845
- /**
1846
- * Remove plugin from the queue.
1847
- */
1848
- _removePluginFromQueue: function( removeItem, pluginsList ) {
1849
- return jQuery.grep(pluginsList, function( value ) {
1850
- return value.slug != removeItem;
1851
- });
1852
- }
1853
-
1854
- };
1855
-
1856
- /**
1857
- * Initialize AstraSitesAdmin
1858
- */
1859
- $(function(){
1860
- AstraSitesAdmin.init();
1861
- });
1862
-
 
 
 
 
 
 
 
 
 
1863
  })(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
+ var process_bars = document.getElementsByClassName( 'astra-site-import-process' );
111
+ for ( var i = 0; i < process_bars.length; i++ ) {
112
+ process_bars[i].value = progress_bar;
113
+ }
114
+ AstraSitesAdmin._log_title( 'Importing Content.. ' + progress );
115
+ }
116
+ }
117
+ },
118
+ render: function () {
119
+ var types = Object.keys( this.complete );
120
+ var complete = 0;
121
+ var total = 0;
122
+
123
+ for (var i = types.length - 1; i >= 0; i--) {
124
+ var type = types[i];
125
+ this.updateProgress( type, this.complete[ type ], this.data.count[ type ] );
126
+
127
+ complete += this.complete[ type ];
128
+ total += this.data.count[ type ];
129
+ }
130
+
131
+ this.updateProgress( 'total', complete, total );
132
+ }
133
+ };
134
+
135
+ AstraSitesAdmin = {
136
+
137
+ reset_remaining_posts: 0,
138
+ reset_remaining_wp_forms: 0,
139
+ reset_remaining_terms: 0,
140
+ reset_processed_posts: 0,
141
+ reset_processed_wp_forms: 0,
142
+ reset_processed_terms: 0,
143
+ site_imported_data: null,
144
+
145
+ backup_taken: false,
146
+
147
+ current_site: [],
148
+ current_screen: '',
149
+
150
+ templateData: {},
151
+
152
+ log_file : '',
153
+ customizer_data : '',
154
+ wxr_url : '',
155
+ wpforms_url : '',
156
+ options_data : '',
157
+ widgets_data : '',
158
+ import_start_time : '',
159
+ import_end_time : '',
160
+
161
+ init: function()
162
+ {
163
+ this._resetPagedCount();
164
+ this._bind();
165
+ },
166
+
167
+ /**
168
+ * Debugging.
169
+ *
170
+ * @param {mixed} data Mixed data.
171
+ */
172
+ _log: function( data ) {
173
+
174
+ if( astraSitesAdmin.debug ) {
175
+
176
+ var date = new Date();
177
+ var time = date.toLocaleTimeString();
178
+
179
+ if (typeof data == 'object') {
180
+ console.log('%c ' + JSON.stringify( data ) + ' ' + time, 'background: #ededed; color: #444');
181
+ } else {
182
+ console.log('%c ' + data + ' ' + time, 'background: #ededed; color: #444');
183
+ }
184
+
185
+
186
+ }
187
+ },
188
+
189
+ _log_title: function( data, append ) {
190
+
191
+ var markup = '<p>' + data + '</p>';
192
+ if (typeof data == 'object' ) {
193
+ var markup = '<p>' + JSON.stringify( data ) + '</p>';
194
+ }
195
+
196
+ if ( append ) {
197
+ $('.current-importing-status-title').append( markup );
198
+ } else {
199
+ $('.current-importing-status-title').html( markup );
200
+ }
201
+ },
202
+
203
+ /**
204
+ * Binds events for the Astra Sites.
205
+ *
206
+ * @since 1.0.0
207
+ * @access private
208
+ * @method _bind
209
+ */
210
+ _bind: function()
211
+ {
212
+ $( document ).on( 'click' , '.astra-sites-reset-data .checkbox', AstraSitesAdmin._toggle_reset_notice );
213
+ $( document ).on( 'click' , '.page-builders li', AstraSitesAdmin._toggle_reset_notice );
214
+ $( document ).on('click' , '#astra-sites-welcome-form .submit', AstraSitesAdmin._show_page_builder_notice);
215
+ $( document ).on('click' , '#astra-sites-welcome-form li', AstraSitesAdmin._show_next_button);
216
+ $( document ).on('change' , '#astra-sites-welcome-form-inline select', AstraSitesAdmin._change_page_builder);
217
+ $( document ).on('click' , '.astra-sites-tooltip-icon', AstraSitesAdmin._toggle_tooltip);
218
+ $( document ).on('click' , '.astra-sites-advanced-options-button', AstraSitesAdmin._toggle_advanced_options);
219
+
220
+ $( document ).on('click' , '.astra-import-settings', AstraSitesAdmin._import_settings);
221
+ $( document ).on('click' , '.devices button', AstraSitesAdmin._previewDevice);
222
+ $( document ).on('click' , '.theme-browser .theme-screenshot, .theme-browser .more-details, .theme-browser .install-theme-preview', AstraSitesAdmin._preview);
223
+ $( document ).on('click' , '.next-theme', AstraSitesAdmin._nextTheme);
224
+ $( document ).on('click' , '.previous-theme', AstraSitesAdmin._previousTheme);
225
+ $( document ).on('click' , '.collapse-sidebar', AstraSitesAdmin._collapse);
226
+ $( document ).on('click' , '.astra-demo-import', AstraSitesAdmin._importDemo);
227
+
228
+ $( document ).on('astra-sites-install-and-activate-required-plugins-done' , AstraSitesAdmin._process_import );
229
+
230
+ $( document ).on('click' , '.install-now', AstraSitesAdmin._installNow);
231
+ $( document ).on('click' , '.close-full-overlay', AstraSitesAdmin._fullOverlay);
232
+ $( document ).on('click' , '.activate-now', AstraSitesAdmin._activateNow);
233
+ $( document ).on('wp-plugin-installing' , AstraSitesAdmin._pluginInstalling);
234
+ $( document ).on('wp-plugin-install-error' , AstraSitesAdmin._installError);
235
+ $( document ).on('wp-plugin-install-success' , AstraSitesAdmin._installSuccess);
236
+
237
+ $( document ).on( 'astra-sites-import-set-site-data-done' , AstraSitesAdmin._resetData );
238
+ $( document ).on( 'astra-sites-reset-data' , AstraSitesAdmin._backup_before_rest_options );
239
+ $( document ).on( 'astra-sites-backup-settings-before-reset-done' , AstraSitesAdmin._reset_customizer_data );
240
+ $( document ).on( 'astra-sites-reset-customizer-data-done' , AstraSitesAdmin._reset_site_options );
241
+ $( document ).on( 'astra-sites-reset-site-options-done' , AstraSitesAdmin._reset_widgets_data );
242
+ $( document ).on( 'astra-sites-reset-widgets-data-done' , AstraSitesAdmin._reset_terms );
243
+ $( document ).on( 'astra-sites-delete-terms-done' , AstraSitesAdmin._reset_wp_forms );
244
+ $( document ).on( 'astra-sites-delete-wp-forms-done' , AstraSitesAdmin._reset_posts );
245
+
246
+ $( document ).on('astra-sites-reset-data-done' , AstraSitesAdmin._recheck_backup_options );
247
+ $( document ).on('astra-sites-backup-settings-done' , AstraSitesAdmin._importWPForms );
248
+ $( document ).on('astra-sites-import-wpforms-done' , AstraSitesAdmin._importCustomizerSettings );
249
+ $( document ).on('astra-sites-import-customizer-settings-done' , AstraSitesAdmin._importXML );
250
+ $( document ).on('astra-sites-import-xml-done' , AstraSitesAdmin._importSiteOptions );
251
+ $( document ).on('astra-sites-import-options-done' , AstraSitesAdmin._importWidgets );
252
+ $( document ).on('astra-sites-import-widgets-done' , AstraSitesAdmin._importEnd );
253
+
254
+ },
255
+
256
+ _show_next_button: function() {
257
+ $( this ).parents('.page-builders').find('img').removeClass('wp-ui-highlight');
258
+ $( this ).find('img').addClass('wp-ui-highlight');
259
+
260
+ $('#submit').parent().removeClass('submit');
261
+ $('#submit').removeClass('disabled');
262
+ $('.astra-sites-page-builder-notice').hide();
263
+ },
264
+
265
+ _show_page_builder_notice: function() {
266
+ $('.astra-sites-page-builder-notice').show();
267
+ },
268
+
269
+ _change_page_builder: function() {
270
+ $(this).closest('form').submit();
271
+ },
272
+
273
+ _toggle_tooltip: function( event ) {
274
+ event.preventDefault();
275
+ var tip_id = $( this ).data('tip-id') || '';
276
+ if( tip_id && $( '#' + tip_id ).length ) {
277
+ $( '#' + tip_id ).toggle();
278
+ }
279
+ },
280
+
281
+ _toggle_advanced_options: function( event ) {
282
+ event.preventDefault();
283
+ $('.astra-sites-advanced-options').toggle();
284
+ },
285
+
286
+ _resetData: function( event ) {
287
+ event.preventDefault();
288
+
289
+ if ( $( '.astra-sites-reset-data' ).find('.checkbox').is(':checked') ) {
290
+ $(document).trigger( 'astra-sites-reset-data' );
291
+ } else {
292
+ $(document).trigger( 'astra-sites-reset-data-done' );
293
+ }
294
+ },
295
+
296
+ _reset_customizer_data: function() {
297
+ $.ajax({
298
+ url : astraSitesAdmin.ajaxurl,
299
+ type : 'POST',
300
+ data : {
301
+ action : 'astra-sites-reset-customizer-data'
302
+ },
303
+ beforeSend: function() {
304
+ AstraSitesAdmin._log_title( 'Reseting Customizer Data..' );
305
+ },
306
+ })
307
+ .fail(function( jqXHR ){
308
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
309
+ })
310
+ .done(function ( data ) {
311
+ AstraSitesAdmin._log_title( 'Complete Resetting Customizer Data..' );
312
+ $(document).trigger( 'astra-sites-reset-customizer-data-done' );
313
+ });
314
+ },
315
+
316
+ _reset_site_options: function() {
317
+ // Site Options.
318
+ $.ajax({
319
+ url : astraSitesAdmin.ajaxurl,
320
+ type : 'POST',
321
+ data : {
322
+ action : 'astra-sites-reset-site-options'
323
+ },
324
+ beforeSend: function() {
325
+ AstraSitesAdmin._log_title( 'Reseting Site Options..' );
326
+ },
327
+ })
328
+ .fail(function( jqXHR ){
329
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
330
+ })
331
+ .done(function ( data ) {
332
+ AstraSitesAdmin._log_title( 'Complete Reseting Site Options..' );
333
+ $(document).trigger( 'astra-sites-reset-site-options-done' );
334
+ });
335
+ },
336
+
337
+ _reset_widgets_data: function() {
338
+ // Widgets.
339
+ $.ajax({
340
+ url : astraSitesAdmin.ajaxurl,
341
+ type : 'POST',
342
+ data : {
343
+ action : 'astra-sites-reset-widgets-data'
344
+ },
345
+ beforeSend: function() {
346
+ AstraSitesAdmin._log_title( 'Reseting Widgets..' );
347
+ },
348
+ })
349
+ .fail(function( jqXHR ){
350
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
351
+ })
352
+ .done(function ( data ) {
353
+ AstraSitesAdmin._log_title( 'Complete Reseting Widgets..' );
354
+ $(document).trigger( 'astra-sites-reset-widgets-data-done' );
355
+ });
356
+ },
357
+
358
+ _reset_posts: function() {
359
+ if( AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
360
+
361
+ AstraSitesAdmin.reset_remaining_posts = AstraSitesAdmin.site_imported_data['reset_posts'].length;
362
+
363
+ $.each( AstraSitesAdmin.site_imported_data['reset_posts'], function(index, post_id) {
364
+
365
+ AstraSitesAdmin._log_title( 'Deleting Posts..' );
366
+
367
+ AstraSitesAjaxQueue.add({
368
+ url: astraSitesAdmin.ajaxurl,
369
+ type: 'POST',
370
+ data: {
371
+ action : 'astra-sites-delete-posts',
372
+ post_id : post_id,
373
+ },
374
+ success: function( result ){
375
+
376
+ if( AstraSitesAdmin.reset_processed_posts < AstraSitesAdmin.site_imported_data['reset_posts'].length ) {
377
+ AstraSitesAdmin.reset_processed_posts+=1;
378
+ }
379
+
380
+ AstraSitesAdmin._log_title( 'Deleting Post ' + AstraSitesAdmin.reset_processed_posts + ' of ' + AstraSitesAdmin.site_imported_data['reset_posts'].length + '<br/>' + result.data );
381
+
382
+ AstraSitesAdmin.reset_remaining_posts-=1;
383
+ if( 0 == AstraSitesAdmin.reset_remaining_posts ) {
384
+ $(document).trigger( 'astra-sites-delete-posts-done' );
385
+ $(document).trigger( 'astra-sites-reset-data-done' );
386
+ }
387
+ }
388
+ });
389
+ });
390
+ AstraSitesAjaxQueue.run();
391
+
392
+ } else {
393
+ $(document).trigger( 'astra-sites-delete-posts-done' );
394
+ $(document).trigger( 'astra-sites-reset-data-done' );
395
+ }
396
+ },
397
+
398
+ _reset_wp_forms: function() {
399
+
400
+ if( AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
401
+ AstraSitesAdmin.reset_remaining_wp_forms = AstraSitesAdmin.site_imported_data['reset_wp_forms'].length;
402
+
403
+ $.each( AstraSitesAdmin.site_imported_data['reset_wp_forms'], function(index, post_id) {
404
+ AstraSitesAdmin._log_title( 'Deleting WP Forms..' );
405
+ AstraSitesAjaxQueue.add({
406
+ url: astraSitesAdmin.ajaxurl,
407
+ type: 'POST',
408
+ data: {
409
+ action : 'astra-sites-delete-wp-forms',
410
+ post_id : post_id,
411
+ },
412
+ success: function( result ){
413
+
414
+ if( AstraSitesAdmin.reset_processed_wp_forms < AstraSitesAdmin.site_imported_data['reset_wp_forms'].length ) {
415
+ AstraSitesAdmin.reset_processed_wp_forms+=1;
416
+ }
417
+
418
+ AstraSitesAdmin._log_title( 'Deleting Form ' + AstraSitesAdmin.reset_processed_wp_forms + ' of ' + AstraSitesAdmin.site_imported_data['reset_wp_forms'].length + '<br/>' + result.data );
419
+
420
+ AstraSitesAdmin.reset_remaining_wp_forms-=1;
421
+ if( 0 == AstraSitesAdmin.reset_remaining_wp_forms ) {
422
+ $(document).trigger( 'astra-sites-delete-wp-forms-done' );
423
+ }
424
+ }
425
+ });
426
+ });
427
+ AstraSitesAjaxQueue.run();
428
+
429
+ } else {
430
+ $(document).trigger( 'astra-sites-delete-wp-forms-done' );
431
+ }
432
+ },
433
+
434
+
435
+ _reset_terms: function() {
436
+
437
+
438
+ if( AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
439
+ AstraSitesAdmin.reset_remaining_terms = AstraSitesAdmin.site_imported_data['reset_terms'].length;
440
+
441
+ $.each( AstraSitesAdmin.site_imported_data['reset_terms'], function(index, term_id) {
442
+ AstraSitesAdmin._log_title( 'Deleting Terms..' );
443
+ AstraSitesAjaxQueue.add({
444
+ url: astraSitesAdmin.ajaxurl,
445
+ type: 'POST',
446
+ data: {
447
+ action : 'astra-sites-delete-terms',
448
+ term_id : term_id,
449
+ },
450
+ success: function( result ){
451
+ if( AstraSitesAdmin.reset_processed_terms < AstraSitesAdmin.site_imported_data['reset_terms'].length ) {
452
+ AstraSitesAdmin.reset_processed_terms+=1;
453
+ }
454
+
455
+ AstraSitesAdmin._log_title( 'Deleting Term ' + AstraSitesAdmin.reset_processed_terms + ' of ' + AstraSitesAdmin.site_imported_data['reset_terms'].length + '<br/>' + result.data );
456
+
457
+ AstraSitesAdmin.reset_remaining_terms-=1;
458
+ if( 0 == AstraSitesAdmin.reset_remaining_terms ) {
459
+ $(document).trigger( 'astra-sites-delete-terms-done' );
460
+ }
461
+ }
462
+ });
463
+ });
464
+ AstraSitesAjaxQueue.run();
465
+
466
+ } else {
467
+ $(document).trigger( 'astra-sites-delete-terms-done' );
468
+ }
469
+
470
+ },
471
+
472
+ _toggle_reset_notice: function() {
473
+ if ( $( this ).is(':checked') ) {
474
+ $('#astra-sites-tooltip-reset-data').show();
475
+ } else {
476
+ $('#astra-sites-tooltip-reset-data').hide();
477
+ }
478
+ },
479
+
480
+ _backup_before_rest_options: function() {
481
+ AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-before-reset-done' );
482
+ AstraSitesAdmin.backup_taken = true;
483
+ },
484
+
485
+ _recheck_backup_options: function() {
486
+ AstraSitesAdmin._backupOptions( 'astra-sites-backup-settings-done' );
487
+ AstraSitesAdmin.backup_taken = true;
488
+ },
489
+
490
+ _backupOptions: function( trigger_name ) {
491
+ $.ajax({
492
+ url : astraSitesAdmin.ajaxurl,
493
+ type : 'POST',
494
+ data : {
495
+ action : 'astra-sites-backup-settings',
496
+ },
497
+ beforeSend: function() {
498
+ AstraSitesAdmin._log_title( 'Processing Customizer Settings Backup..' );
499
+ },
500
+ })
501
+ .fail(function( jqXHR ){
502
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
503
+ })
504
+ .done(function ( data ) {
505
+
506
+ // 1. Pass - Import Customizer Options.
507
+ AstraSitesAdmin._log_title( 'Customizer Settings Backup Done..' );
508
+
509
+ // Custom trigger.
510
+ $(document).trigger( trigger_name );
511
+ });
512
+ },
513
+
514
+ _import_settings: function( event ) {
515
+ event.preventDefault();
516
+
517
+ var btn = $(this);
518
+
519
+ btn.addClass('updating-message');
520
+
521
+
522
+ $.ajax({
523
+ url : astraSitesAdmin.ajaxurl,
524
+ type : 'POST',
525
+ dataType: 'json',
526
+ data : {
527
+ action : 'astra-sites-import-customizer-settings',
528
+ customizer_data : AstraSitesAdmin.current_site['astra-site-customizer-data'],
529
+ },
530
+ beforeSend: function() {
531
+ AstraSitesAdmin._log_title( 'Importing Customizer Settings..' );
532
+ },
533
+ })
534
+ .fail(function( jqXHR ){
535
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
536
+ })
537
+ .done(function ( customizer_data ) {
538
+
539
+ btn.removeClass( 'updating-message' );
540
+
541
+ // 1. Fail - Import Customizer Options.
542
+ if( false === customizer_data.success ) {
543
+ AstraSitesAdmin._log_title( customizer_data.data );
544
+ } else {
545
+
546
+ // 1. Pass - Import Customizer Options.
547
+ AstraSitesAdmin._log_title( 'Imported Customizer Settings..' );
548
+
549
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
550
+ }
551
+ });
552
+ },
553
+
554
+ /**
555
+ * 5. Import Complete.
556
+ */
557
+ _importEnd: function( event ) {
558
+
559
+ $.ajax({
560
+ url : astraSitesAdmin.ajaxurl,
561
+ type : 'POST',
562
+ dataType: 'json',
563
+ data : {
564
+ action : 'astra-sites-import-end',
565
+ },
566
+ beforeSend: function() {
567
+ AstraSitesAdmin._log_title( 'Import Complete!' );
568
+ }
569
+ })
570
+ .fail(function( jqXHR ){
571
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
572
+ })
573
+ .done(function ( data ) {
574
+
575
+ // 5. Fail - Import Complete.
576
+ if( false === data.success ) {
577
+ AstraSitesAdmin._log_title( data.data );
578
+ } else {
579
+
580
+ $('body').removeClass('importing-site');
581
+ $('.previous-theme, .next-theme').removeClass('disabled');
582
+
583
+ var date = new Date();
584
+
585
+ AstraSitesAdmin.import_end_time = new Date();
586
+ var diff = ( AstraSitesAdmin.import_end_time.getTime() - AstraSitesAdmin.import_start_time.getTime() );
587
+
588
+ var time = '';
589
+ var seconds = Math.floor( diff / 1000 );
590
+ var minutes = Math.floor( seconds / 60 );
591
+ var hours = Math.floor( minutes / 60 );
592
+
593
+ minutes = minutes - ( hours * 60 );
594
+ seconds = seconds - ( minutes * 60 );
595
+
596
+ if( hours ) {
597
+ time += hours + ' Hours ';
598
+ }
599
+ if( minutes ) {
600
+ time += minutes + ' Minutes ';
601
+ }
602
+ if( seconds ) {
603
+ time += seconds + ' Seconds';
604
+ }
605
+
606
+ var output = '<h2>Done 🎉</h2>';
607
+ output += '<p>Your starter site has been imported successfully in '+time+'! Now go ahead, customize the text, images, and design to make it yours!</p>';
608
+ output += '<p>You can now start making changes according to your requirements.</p>';
609
+ output += '<p><a class="button button-primary button-hero" href="'+astraSitesAdmin.siteURL+'" target="_blank">View Site <i class="dashicons dashicons-external"></i></a></p>';
610
+
611
+ $('.rotating,.current-importing-status-wrap,.notice-warning').remove();
612
+ $('.astra-sites-result-preview .inner').html(output);
613
+
614
+ // 5. Pass - Import Complete.
615
+ AstraSitesAdmin._importSuccessButton();
616
+ }
617
+ });
618
+ },
619
+
620
+ /**
621
+ * 4. Import Widgets.
622
+ */
623
+ _importWidgets: function( event ) {
624
+ if ( AstraSitesAdmin._is_process_widgets() ) {
625
+ $.ajax({
626
+ url : astraSitesAdmin.ajaxurl,
627
+ type : 'POST',
628
+ dataType: 'json',
629
+ data : {
630
+ action : 'astra-sites-import-widgets',
631
+ widgets_data : AstraSitesAdmin.widgets_data,
632
+ },
633
+ beforeSend: function() {
634
+ AstraSitesAdmin._log_title( 'Importing Widgets..' );
635
+ },
636
+ })
637
+ .fail(function( jqXHR ){
638
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
639
+ })
640
+ .done(function ( widgets_data ) {
641
+
642
+ // 4. Fail - Import Widgets.
643
+ if( false === widgets_data.success ) {
644
+ AstraSitesAdmin._log_title( widgets_data.data );
645
+
646
+ } else {
647
+
648
+ // 4. Pass - Import Widgets.
649
+ AstraSitesAdmin._log_title( 'Imported Widgets!' );
650
+ $(document).trigger( 'astra-sites-import-widgets-done' );
651
+ }
652
+ });
653
+ } else {
654
+ $(document).trigger( 'astra-sites-import-widgets-done' );
655
+ }
656
+ },
657
+
658
+ /**
659
+ * 3. Import Site Options.
660
+ */
661
+ _importSiteOptions: function( event ) {
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-options',
670
+ options_data : AstraSitesAdmin.options_data,
671
+ },
672
+ beforeSend: function() {
673
+ AstraSitesAdmin._log_title( 'Importing Options..' );
674
+ $('.astra-demo-import .percent').html('');
675
+ },
676
+ })
677
+ .fail(function( jqXHR ){
678
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
679
+ })
680
+ .done(function ( options_data ) {
681
+
682
+ // 3. Fail - Import Site Options.
683
+ if( false === options_data.success ) {
684
+ AstraSitesAdmin._log_title( options_data );
685
+ } else {
686
+
687
+ // 3. Pass - Import Site Options.
688
+ $(document).trigger( 'astra-sites-import-options-done' );
689
+ }
690
+ });
691
+ } else {
692
+ $(document).trigger( 'astra-sites-import-options-done' );
693
+ }
694
+ },
695
+
696
+ /**
697
+ * 2. Prepare XML Data.
698
+ */
699
+ _importXML: function() {
700
+
701
+ if ( AstraSitesAdmin._is_process_xml() ) {
702
+ $.ajax({
703
+ url : astraSitesAdmin.ajaxurl,
704
+ type : 'POST',
705
+ dataType: 'json',
706
+ data : {
707
+ action : 'astra-sites-import-prepare-xml',
708
+ wxr_url : AstraSitesAdmin.current_site['astra-site-wxr-path'],
709
+ },
710
+ beforeSend: function() {
711
+ $('.astra-site-import-process-wrap').show();
712
+ AstraSitesAdmin._log_title( 'Importing Content..' );
713
+ },
714
+ })
715
+ .fail(function( jqXHR ){
716
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
717
+ })
718
+ .done(function ( xml_data ) {
719
+
720
+ // 2. Fail - Prepare XML Data.
721
+ if( false === xml_data.success ) {
722
+ AstraSitesAdmin._log_title( xml_data );
723
+ var error_msg = xml_data.data.error || xml_data.data;
724
+ AstraSitesAdmin._log_title( error_msg );
725
+
726
+ } else {
727
+
728
+ var xml_processing = $('.astra-demo-import').attr( 'data-xml-processing' );
729
+
730
+ if( 'yes' === xml_processing ) {
731
+ return;
732
+ }
733
+
734
+ $('.astra-demo-import').attr( 'data-xml-processing', 'yes' );
735
+
736
+ // 2. Pass - Prepare XML Data.
737
+
738
+ // Import XML though Event Source.
739
+ AstraSSEImport.data = xml_data.data;
740
+ AstraSSEImport.render();
741
+
742
+ $('.current-importing-status-description').html('').show();
743
+
744
+ $('.astra-sites-result-preview .inner').append('<div class="astra-site-import-process-wrap"><progress class="astra-site-import-process" max="100" value="0"></progress></div>');
745
+
746
+ var evtSource = new EventSource( AstraSSEImport.data.url );
747
+ evtSource.onmessage = function ( message ) {
748
+ var data = JSON.parse( message.data );
749
+ switch ( data.action ) {
750
+ case 'updateDelta':
751
+
752
+ AstraSSEImport.updateDelta( data.type, data.delta );
753
+ break;
754
+
755
+ case 'complete':
756
+ evtSource.close();
757
+
758
+ $('.current-importing-status-description').hide();
759
+ $('.astra-demo-import').removeAttr( 'data-xml-processing' );
760
+
761
+ document.getElementsByClassName("astra-site-import-process").value = '100';
762
+
763
+ $('.astra-site-import-process-wrap').hide();
764
+
765
+ $(document).trigger( 'astra-sites-import-xml-done' );
766
+
767
+ break;
768
+ }
769
+ };
770
+ evtSource.addEventListener( 'log', function ( message ) {
771
+ var data = JSON.parse( message.data );
772
+ var message = data.message || '';
773
+ if( message && 'info' === data.level ) {
774
+ message = message.replace(/"/g, function(letter) {
775
+ return '';
776
+ });
777
+ $('.current-importing-status-description').html( message );
778
+ }
779
+ });
780
+ }
781
+ });
782
+ } else {
783
+ $(document).trigger( 'astra-sites-import-xml-done' );
784
+ }
785
+
786
+
787
+ },
788
+
789
+ _is_process_xml: function() {
790
+ if ( $( '.astra-sites-import-xml' ).find('.checkbox').is(':checked') ) {
791
+ return true;
792
+ }
793
+ return false;
794
+ },
795
+
796
+ _is_process_customizer: function() {
797
+ if ( $( '.astra-sites-import-customizer' ).find('.checkbox').is(':checked') ) {
798
+ return true;
799
+ }
800
+ return false;
801
+ },
802
+
803
+ _is_process_widgets: function() {
804
+ if ( $( '.astra-sites-import-widgets' ).find('.checkbox').is(':checked') ) {
805
+ return true;
806
+ }
807
+ return false;
808
+ },
809
+
810
+ /**
811
+ * 1. Import WPForms Options.
812
+ */
813
+ _importWPForms: function( event ) {
814
+ if ( AstraSitesAdmin._is_process_customizer() ) {
815
+ $.ajax({
816
+ url : astraSitesAdmin.ajaxurl,
817
+ type : 'POST',
818
+ dataType: 'json',
819
+ data : {
820
+ action : 'astra-sites-import-wpforms',
821
+ wpforms_url : AstraSitesAdmin.wpforms_url,
822
+ },
823
+ beforeSend: function() {
824
+ AstraSitesAdmin._log_title( 'Importing WP Forms..' );
825
+ },
826
+ })
827
+ .fail(function( jqXHR ){
828
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
829
+ })
830
+ .done(function ( forms ) {
831
+
832
+ // 1. Fail - Import WPForms Options.
833
+ if( false === forms.success ) {
834
+ AstraSitesAdmin._log_title( forms.data );
835
+ } else {
836
+
837
+ // 1. Pass - Import Customizer Options.
838
+ $(document).trigger( 'astra-sites-import-wpforms-done' );
839
+ }
840
+ });
841
+ } else {
842
+ $(document).trigger( 'astra-sites-import-wpforms-done' );
843
+ }
844
+ },
845
+
846
+ /**
847
+ * 1. Import Customizer Options.
848
+ */
849
+ _importCustomizerSettings: function( event ) {
850
+ if ( AstraSitesAdmin._is_process_customizer() ) {
851
+ $.ajax({
852
+ url : astraSitesAdmin.ajaxurl,
853
+ type : 'POST',
854
+ dataType: 'json',
855
+ data : {
856
+ action : 'astra-sites-import-customizer-settings',
857
+ customizer_data : AstraSitesAdmin.customizer_data,
858
+ },
859
+ beforeSend: function() {
860
+ },
861
+ })
862
+ .fail(function( jqXHR ){
863
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText, true );
864
+ })
865
+ .done(function ( customizer_data ) {
866
+
867
+ // 1. Fail - Import Customizer Options.
868
+ if( false === customizer_data.success ) {
869
+ AstraSitesAdmin._log_title( customizer_data.data );
870
+ } else {
871
+
872
+ // 1. Pass - Import Customizer Options.
873
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
874
+ }
875
+ });
876
+ } else {
877
+ $(document).trigger( 'astra-sites-import-customizer-settings-done' );
878
+ }
879
+
880
+ },
881
+
882
+ /**
883
+ * Import Success Button.
884
+ *
885
+ * @param {string} data Error message.
886
+ */
887
+ _importSuccessButton: function() {
888
+
889
+ $('.astra-demo-import').removeClass('updating-message installing')
890
+ .removeAttr('data-import')
891
+ .addClass('view-site')
892
+ .removeClass('astra-demo-import')
893
+ .text( astraSitesAdmin.strings.viewSite )
894
+ .attr('target', '_blank')
895
+ .append('<i class="dashicons dashicons-external"></i>')
896
+ .attr('href', astraSitesAdmin.siteURL );
897
+ },
898
+
899
+ /**
900
+ * Preview Device
901
+ */
902
+ _previewDevice: function( event ) {
903
+ var device = $( event.currentTarget ).data( 'device' );
904
+
905
+ $('.theme-install-overlay')
906
+ .removeClass( 'preview-desktop preview-tablet preview-mobile' )
907
+ .addClass( 'preview-' + device )
908
+ .data( 'current-preview-device', device );
909
+
910
+ AstraSitesAdmin._tooglePreviewDeviceButtons( device );
911
+ },
912
+
913
+ /**
914
+ * Toggle Preview Buttons
915
+ */
916
+ _tooglePreviewDeviceButtons: function( newDevice ) {
917
+ var $devices = $( '.wp-full-overlay-footer .devices' );
918
+
919
+ $devices.find( 'button' )
920
+ .removeClass( 'active' )
921
+ .attr( 'aria-pressed', false );
922
+
923
+ $devices.find( 'button.preview-' + newDevice )
924
+ .addClass( 'active' )
925
+ .attr( 'aria-pressed', true );
926
+ },
927
+
928
+ /**
929
+ * Import Error Button.
930
+ *
931
+ * @param {string} data Error message.
932
+ */
933
+ _importFailMessage: function( message, from ) {
934
+
935
+ $('.astra-demo-import')
936
+ .addClass('go-pro button-primary')
937
+ .removeClass('updating-message installing')
938
+ .removeAttr('data-import')
939
+ .attr('target', '_blank')
940
+ .append('<i class="dashicons dashicons-external"></i>')
941
+ .removeClass('astra-demo-import');
942
+
943
+ // Add the doc link due to import log file not generated.
944
+ if( 'undefined' === from ) {
945
+
946
+ $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailedBtnSmall );
947
+ $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailedBtnLarge );
948
+ $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
949
+
950
+ // Add the import log file link.
951
+ } else {
952
+
953
+ $('.wp-full-overlay-header .go-pro').text( astraSitesAdmin.strings.importFailBtn );
954
+ $('.wp-full-overlay-footer .go-pro').text( astraSitesAdmin.strings.importFailBtnLarge )
955
+
956
+ // Add the import log file link.
957
+ if( 'undefined' !== AstraSitesAdmin.log_file_url ) {
958
+ $('.go-pro').attr('href', AstraSitesAdmin.log_file_url );
959
+ } else {
960
+ $('.go-pro').attr('href', astraSitesAdmin.log.serverConfiguration );
961
+ }
962
+ }
963
+
964
+ var output = '<div class="astra-api-error notice notice-error notice-alt is-dismissible">';
965
+ output += ' <p>'+message+'</p>';
966
+ output += ' <button type="button" class="notice-dismiss">';
967
+ output += ' <span class="screen-reader-text">'+commonL10n.dismiss+'</span>';
968
+ output += ' </button>';
969
+ output += '</div>';
970
+
971
+ // Fail Notice.
972
+ $('.install-theme-info').append( output );
973
+
974
+ // !important to add trigger.
975
+ // Which reinitialize the dismiss error message events.
976
+ $(document).trigger('wp-updates-notice-added');
977
+ },
978
+
979
+
980
+ /**
981
+ * Install Now
982
+ */
983
+ _installNow: function(event)
984
+ {
985
+ event.preventDefault();
986
+
987
+ var $button = jQuery( event.target ),
988
+ $document = jQuery(document);
989
+
990
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
991
+ return;
992
+ }
993
+
994
+ AstraSitesAdmin._log_title( 'Installing Required Plugin..' );
995
+
996
+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
997
+ wp.updates.requestFilesystemCredentials( event );
998
+
999
+ $document.on( 'credential-modal-cancel', function() {
1000
+ var $message = $( '.install-now.updating-message' );
1001
+
1002
+ $message
1003
+ .removeClass( 'updating-message' )
1004
+ .text( wp.updates.l10n.installNow );
1005
+
1006
+ wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' );
1007
+ } );
1008
+ }
1009
+
1010
+ AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( $button.data( 'name' ) ) );
1011
+
1012
+ wp.updates.installPlugin( {
1013
+ slug: $button.data( 'slug' )
1014
+ } );
1015
+ },
1016
+
1017
+ ucwords: function( str ) {
1018
+ if( ! str ) {
1019
+ return '';
1020
+ }
1021
+
1022
+ str = str.toLowerCase().replace(/\b[a-z]/g, function(letter) {
1023
+ return letter.toUpperCase();
1024
+ });
1025
+
1026
+ str = str.replace(/-/g, function(letter) {
1027
+ return ' ';
1028
+ });
1029
+
1030
+ return str;
1031
+ },
1032
+
1033
+ /**
1034
+ * Install Success
1035
+ */
1036
+ _installSuccess: function( event, response ) {
1037
+
1038
+ event.preventDefault();
1039
+
1040
+
1041
+ var $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val();
1042
+
1043
+ var $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1044
+
1045
+ // Transform the 'Install' button into an 'Activate' button.
1046
+ var $init = $( '.plugin-card-' + response.slug ).data('init');
1047
+ var $name = $( '.plugin-card-' + response.slug ).data('name');
1048
+
1049
+ // Reset not installed plugins list.
1050
+ var pluginsList = astraSitesAdmin.requiredPlugins.notinstalled;
1051
+ astraSitesAdmin.requiredPlugins.notinstalled = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1052
+
1053
+ // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
1054
+ setTimeout( function() {
1055
+
1056
+ AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords($name) );
1057
+
1058
+ $.ajax({
1059
+ url: astraSitesAdmin.ajaxurl,
1060
+ type: 'POST',
1061
+ data: {
1062
+ 'action' : 'astra-required-plugin-activate',
1063
+ 'init' : $init,
1064
+ 'options' : $siteOptions,
1065
+ 'enabledExtensions' : $enabledExtensions,
1066
+ },
1067
+ })
1068
+ .done(function (result) {
1069
+
1070
+ if( result.success ) {
1071
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1072
+
1073
+ AstraSitesAdmin._log_title( 'Installed Plugin - ' + AstraSitesAdmin.ucwords($name) );
1074
+
1075
+ // Reset not installed plugins list.
1076
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( response.slug, pluginsList );
1077
+
1078
+ // Enable Demo Import Button
1079
+ AstraSitesAdmin._enable_demo_import_button();
1080
+
1081
+ }
1082
+ });
1083
+
1084
+ }, 1200 );
1085
+
1086
+ },
1087
+
1088
+ /**
1089
+ * Plugin Installation Error.
1090
+ */
1091
+ _installError: function( event, response ) {
1092
+
1093
+ var $card = $( '.plugin-card-' + response.slug );
1094
+ var $name = $card.data('name');
1095
+
1096
+ AstraSitesAdmin._log_title( response.errorMessage + ' ' + AstraSitesAdmin.ucwords($name) );
1097
+
1098
+
1099
+ $card
1100
+ .removeClass( 'button-primary' )
1101
+ .addClass( 'disabled' )
1102
+ .html( wp.updates.l10n.installFailedShort );
1103
+
1104
+ },
1105
+
1106
+ /**
1107
+ * Installing Plugin
1108
+ */
1109
+ _pluginInstalling: function(event, args) {
1110
+ event.preventDefault();
1111
+
1112
+ var $card = $( '.plugin-card-' + args.slug );
1113
+ var $name = $card.data('name');
1114
+
1115
+ AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( $name ));
1116
+
1117
+ $card.addClass('updating-message');
1118
+
1119
+ },
1120
+
1121
+ /**
1122
+ * Render Demo Preview
1123
+ */
1124
+ _activateNow: function( eventn ) {
1125
+
1126
+ event.preventDefault();
1127
+
1128
+ var $button = jQuery( event.target ),
1129
+ $init = $button.data( 'init' ),
1130
+ $slug = $button.data( 'slug' );
1131
+ $name = $button.data( 'name' );
1132
+
1133
+ if ( $button.hasClass( 'updating-message' ) || $button.hasClass( 'button-disabled' ) ) {
1134
+ return;
1135
+ }
1136
+
1137
+ AstraSitesAdmin._log_title( 'Activating Plugin - ' + AstraSitesAdmin.ucwords( $name ) );
1138
+
1139
+ $button.addClass('updating-message button-primary')
1140
+ .html( astraSitesAdmin.strings.btnActivating );
1141
+
1142
+ var $siteOptions = jQuery( '.wp-full-overlay-header').find('.astra-site-options').val();
1143
+ var $enabledExtensions = jQuery( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1144
+
1145
+ $.ajax({
1146
+ url: astraSitesAdmin.ajaxurl,
1147
+ type: 'POST',
1148
+ data: {
1149
+ 'action' : 'astra-required-plugin-activate',
1150
+ 'init' : $init,
1151
+ 'options' : $siteOptions,
1152
+ 'enabledExtensions' : $enabledExtensions,
1153
+ },
1154
+ })
1155
+ .done(function (result) {
1156
+
1157
+ if( result.success ) {
1158
+
1159
+ AstraSitesAdmin._log_title( 'Activated Plugin - ' + AstraSitesAdmin.ucwords($name) );
1160
+
1161
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1162
+
1163
+ // Reset not installed plugins list.
1164
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( $slug, pluginsList );
1165
+
1166
+ $button.removeClass( 'button-primary install-now activate-now updating-message' )
1167
+ .attr('disabled', 'disabled')
1168
+ .addClass('disabled')
1169
+ .text( astraSitesAdmin.strings.btnActive );
1170
+
1171
+ // Enable Demo Import Button
1172
+ AstraSitesAdmin._enable_demo_import_button();
1173
+
1174
+ }
1175
+
1176
+ })
1177
+ .fail(function () {
1178
+ });
1179
+
1180
+ },
1181
+
1182
+ /**
1183
+ * Full Overlay
1184
+ */
1185
+ _fullOverlay: function (event) {
1186
+ event.preventDefault();
1187
+
1188
+ // Import process is started?
1189
+ // And Closing the window? Then showing the warning confirm message.
1190
+ if( $('body').hasClass('importing-site') && ! confirm( astraSitesAdmin.strings.warningBeforeCloseWindow ) ) {
1191
+ return;
1192
+ }
1193
+
1194
+ $('body').removeClass('importing-site');
1195
+ $('.previous-theme, .next-theme').removeClass('disabled');
1196
+ $('.theme-install-overlay').css('display', 'none');
1197
+ $('.theme-install-overlay').remove();
1198
+ $('.theme-preview-on').removeClass('theme-preview-on');
1199
+ $('html').removeClass('astra-site-preview-on');
1200
+ },
1201
+
1202
+ /**
1203
+ * Bulk Plugin Active & Install
1204
+ */
1205
+ _bulkPluginInstallActivate: function()
1206
+ {
1207
+ if( 0 === astraSitesAdmin.requiredPlugins.length ) {
1208
+ return;
1209
+ }
1210
+
1211
+ var not_installed = astraSitesAdmin.requiredPlugins.notinstalled || '';
1212
+ var activate_plugins = astraSitesAdmin.requiredPlugins.inactive || '';
1213
+
1214
+ // First Install Bulk.
1215
+ if( not_installed.length > 0 ) {
1216
+ AstraSitesAdmin._installAllPlugins( not_installed );
1217
+ }
1218
+
1219
+ // Second Activate Bulk.
1220
+ if( activate_plugins.length > 0 ) {
1221
+ AstraSitesAdmin._activateAllPlugins( activate_plugins );
1222
+ }
1223
+
1224
+ if( activate_plugins.length <= 0 && not_installed.length <= 0 ) {
1225
+ AstraSitesAdmin._enable_demo_import_button();
1226
+ }
1227
+
1228
+ },
1229
+
1230
+ /**
1231
+ * Activate All Plugins.
1232
+ */
1233
+ _activateAllPlugins: function( activate_plugins ) {
1234
+
1235
+ AstraSitesAdmin._log_title( 'Activating Required Plugins..' );
1236
+
1237
+ $.each( activate_plugins, function(index, single_plugin) {
1238
+
1239
+ var $card = $( '.plugin-card-' + single_plugin.slug ),
1240
+ $siteOptions = $( '.wp-full-overlay-header').find('.astra-site-options').val(),
1241
+ $enabledExtensions = $( '.wp-full-overlay-header').find('.astra-enabled-extensions').val();
1242
+
1243
+
1244
+ AstraSitesAjaxQueue.add({
1245
+ url: astraSitesAdmin.ajaxurl,
1246
+ type: 'POST',
1247
+ data: {
1248
+ 'action' : 'astra-required-plugin-activate',
1249
+ 'init' : single_plugin.init,
1250
+ 'options' : $siteOptions,
1251
+ 'enabledExtensions' : $enabledExtensions,
1252
+ },
1253
+ success: function( result ){
1254
+
1255
+ if( result.success ) {
1256
+
1257
+ var pluginsList = astraSitesAdmin.requiredPlugins.inactive;
1258
+
1259
+ // Reset not installed plugins list.
1260
+ astraSitesAdmin.requiredPlugins.inactive = AstraSitesAdmin._removePluginFromQueue( single_plugin.slug, pluginsList );
1261
+
1262
+ // Enable Demo Import Button
1263
+ AstraSitesAdmin._enable_demo_import_button();
1264
+ } else {
1265
+ }
1266
+ }
1267
+ });
1268
+ });
1269
+ AstraSitesAjaxQueue.run();
1270
+ },
1271
+
1272
+ /**
1273
+ * Install All Plugins.
1274
+ */
1275
+ _installAllPlugins: function( not_installed ) {
1276
+
1277
+ AstraSitesAdmin._log_title( 'Installing Required Plugins..' );
1278
+
1279
+ $.each( not_installed, function(index, single_plugin) {
1280
+
1281
+ AstraSitesAdmin._log_title( 'Installing Plugin - ' + AstraSitesAdmin.ucwords( single_plugin.name ));
1282
+
1283
+ var $card = $( '.plugin-card-' + single_plugin.slug );
1284
+
1285
+ // Add each plugin activate request in Ajax queue.
1286
+ // @see wp-admin/js/updates.js
1287
+ wp.updates.queue.push( {
1288
+ action: 'install-plugin', // Required action.
1289
+ data: {
1290
+ slug: single_plugin.slug
1291
+ }
1292
+ } );
1293
+ });
1294
+
1295
+ // Required to set queue.
1296
+ wp.updates.queueChecker();
1297
+ },
1298
+
1299
+ /**
1300
+ * Fires when a nav item is clicked.
1301
+ *
1302
+ * @since 1.0
1303
+ * @access private
1304
+ * @method _importDemo
1305
+ */
1306
+ _importDemo: function(event) {
1307
+ event.preventDefault();
1308
+
1309
+ var date = new Date();
1310
+
1311
+ AstraSitesAdmin.import_start_time = new Date();
1312
+
1313
+ var disabled = $(this).attr('data-import');
1314
+
1315
+ if ( typeof disabled !== 'undefined' && disabled === 'disabled' || $this.hasClass('disabled') ) {
1316
+
1317
+ $('.astra-demo-import').addClass('updating-message installing')
1318
+ .text( wp.updates.l10n.installing );
1319
+
1320
+ $('.astra-sites-result-preview').show();
1321
+ var output = '<div class="current-importing-status-title"></div><div class="current-importing-status-description"></div>';
1322
+ $('.current-importing-status').html( output );
1323
+
1324
+ /**
1325
+ * Process Bulk Plugin Install & Activate
1326
+ */
1327
+ AstraSitesAdmin._bulkPluginInstallActivate();
1328
+ }
1329
+ },
1330
+
1331
+ _process_import: function() {
1332
+
1333
+ var $theme = $('.astra-sites-preview').find('.wp-full-overlay-header'),
1334
+ apiURL = $theme.data('demo-api') || '';
1335
+
1336
+ $('body').addClass('importing-site');
1337
+ $('.previous-theme, .next-theme').addClass('disabled');
1338
+
1339
+ // Remove all notices before import start.
1340
+ $('.install-theme-info > .notice').remove();
1341
+
1342
+ $('.astra-demo-import').attr('data-import', 'disabled')
1343
+ .addClass('updating-message installing')
1344
+ .text( astraSitesAdmin.strings.importingDemo );
1345
+
1346
+ // Site Import by API URL.
1347
+ if( apiURL ) {
1348
+ AstraSitesAdmin._importSite( apiURL );
1349
+ }
1350
+
1351
+ },
1352
+
1353
+ /**
1354
+ * Start Import Process by API URL.
1355
+ *
1356
+ * @param {string} apiURL Site API URL.
1357
+ */
1358
+ _importSite: function( apiURL ) {
1359
+
1360
+ AstraSitesAdmin._log_title( 'Started Importing..' );
1361
+
1362
+ // 1. Request Site Import
1363
+ $.ajax({
1364
+ url : astraSitesAdmin.ajaxurl,
1365
+ type : 'POST',
1366
+ dataType: 'json',
1367
+ data : {
1368
+ 'action' : 'astra-sites-import-set-site-data',
1369
+ 'api_url' : apiURL,
1370
+ },
1371
+ })
1372
+ .fail(function( jqXHR ){
1373
+ AstraSitesAdmin._log_title( jqXHR.status + ' ' + jqXHR.responseText + ' ' + jqXHR.statusText, true );
1374
+ })
1375
+ .done(function ( demo_data ) {
1376
+
1377
+ // 1. Fail - Request Site Import
1378
+ if( false === demo_data.success ) {
1379
+
1380
+
1381
+ } else {
1382
+
1383
+ // Set log file URL.
1384
+ if( 'log_file' in demo_data.data ){
1385
+ AstraSitesAdmin.log_file_url = decodeURIComponent( demo_data.data.log_file ) || '';
1386
+ }
1387
+
1388
+ // 1. Pass - Request Site Import
1389
+ AstraSitesAdmin.customizer_data = JSON.stringify( demo_data.data['astra-site-customizer-data'] ) || '';
1390
+ AstraSitesAdmin.wxr_url = encodeURI( demo_data.data['astra-site-wxr-path'] ) || '';
1391
+ AstraSitesAdmin.wpforms_url = encodeURI( demo_data.data['astra-site-wpforms-path'] ) || '';
1392
+ AstraSitesAdmin.options_data = JSON.stringify( demo_data.data['astra-site-options-data'] ) || '';
1393
+ AstraSitesAdmin.widgets_data = JSON.stringify( demo_data.data['astra-site-widgets-data'] ) || '';
1394
+
1395
+ $(document).trigger( 'astra-sites-import-set-site-data-done' );
1396
+ }
1397
+
1398
+ });
1399
+
1400
+ },
1401
+
1402
+ /**
1403
+ * Collapse Sidebar.
1404
+ */
1405
+ _collapse: function() {
1406
+ event.preventDefault();
1407
+
1408
+ overlay = jQuery('.wp-full-overlay');
1409
+
1410
+ if (overlay.hasClass('expanded')) {
1411
+ overlay.removeClass('expanded');
1412
+ overlay.addClass('collapsed');
1413
+ return;
1414
+ }
1415
+
1416
+ if (overlay.hasClass('collapsed')) {
1417
+ overlay.removeClass('collapsed');
1418
+ overlay.addClass('expanded');
1419
+ return;
1420
+ }
1421
+ },
1422
+
1423
+ /**
1424
+ * Previous Theme.
1425
+ */
1426
+ _previousTheme: function (event) {
1427
+ event.preventDefault();
1428
+
1429
+ currentDemo = jQuery('.theme-preview-on');
1430
+ currentDemo.removeClass('theme-preview-on');
1431
+ prevDemo = currentDemo.prev('.theme');
1432
+ prevDemo.addClass('theme-preview-on');
1433
+
1434
+ var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1435
+
1436
+ if( AstraSitesAPI._stored_data ) {
1437
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1438
+
1439
+
1440
+ if( site_data ) {
1441
+ // Set current site details.
1442
+ AstraSitesAdmin.current_site = site_data;
1443
+ }
1444
+ }
1445
+
1446
+ AstraSitesAdmin._renderDemoPreview(prevDemo);
1447
+ },
1448
+
1449
+ /**
1450
+ * Next Theme.
1451
+ */
1452
+ _nextTheme: function (event) {
1453
+ event.preventDefault();
1454
+ currentDemo = jQuery('.theme-preview-on')
1455
+ currentDemo.removeClass('theme-preview-on');
1456
+ nextDemo = currentDemo.next('.theme');
1457
+ nextDemo.addClass('theme-preview-on');
1458
+
1459
+ var site_id = $(this).parents('.wp-full-overlay-header').data('demo-id') || '';
1460
+
1461
+ if( AstraSitesAPI._stored_data ) {
1462
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1463
+
1464
+ if( site_data ) {
1465
+ // Set current site details.
1466
+ AstraSitesAdmin.current_site = site_data;
1467
+ }
1468
+ }
1469
+
1470
+ AstraSitesAdmin._renderDemoPreview( nextDemo );
1471
+ },
1472
+
1473
+ _set_current_screen: function( screen ) {
1474
+ AstraSitesAdmin.current_screen = screen;
1475
+ var old_screen = $('.astra-sites-preview').attr( 'screen' ) || '';
1476
+
1477
+
1478
+ if( old_screen ) {
1479
+ $('.astra-sites-preview').removeClass( 'screen-' + old_screen );
1480
+ }
1481
+
1482
+ $('.astra-sites-preview').attr( 'screen', screen );
1483
+ $('.astra-sites-preview').addClass( 'screen-' + screen );
1484
+ },
1485
+
1486
+ /**
1487
+ * Individual Site Preview
1488
+ *
1489
+ * On click on image, more link & preview button.
1490
+ */
1491
+ _preview: function( event ) {
1492
+
1493
+ event.preventDefault();
1494
+
1495
+ var site_id = $(this).parents('.site-single').data('demo-id') || '';
1496
+
1497
+ if( AstraSitesAPI._stored_data ) {
1498
+ var site_data = AstraSitesAdmin._get_site_details( site_id );
1499
+
1500
+ if( site_data ) {
1501
+ // Set current site details.
1502
+ AstraSitesAdmin.current_site = site_data;
1503
+
1504
+ // Set current screen.
1505
+ AstraSitesAdmin._set_current_screen( 'get-started' );
1506
+ }
1507
+ }
1508
+
1509
+ var self = $(this).parents('.theme');
1510
+ self.addClass('theme-preview-on');
1511
+
1512
+ $('html').addClass('astra-site-preview-on');
1513
+
1514
+ AstraSitesAdmin._renderDemoPreview( self );
1515
+ },
1516
+
1517
+ _get_site_details: function( site_id ) {
1518
+ var all_sites = AstraSitesAPI._stored_data['astra-sites'] || [];
1519
+
1520
+ if( ! all_sites ) {
1521
+ return false;
1522
+ }
1523
+
1524
+ var single_site = all_sites.filter(function (site) { return site.id == site_id });
1525
+ if( ! single_site ) {
1526
+ return false;
1527
+ }
1528
+
1529
+ if( ! $.isArray( single_site ) ) {
1530
+ return false;
1531
+ }
1532
+
1533
+ return single_site[0];
1534
+ },
1535
+
1536
+ /**
1537
+ * Check Next Previous Buttons.
1538
+ */
1539
+ _checkNextPrevButtons: function() {
1540
+ currentDemo = jQuery('.theme-preview-on');
1541
+ nextDemo = currentDemo.nextAll('.theme').length;
1542
+ prevDemo = currentDemo.prevAll('.theme').length;
1543
+
1544
+ if (nextDemo == 0) {
1545
+ jQuery('.next-theme').addClass('disabled');
1546
+ } else if (nextDemo != 0) {
1547
+ jQuery('.next-theme').removeClass('disabled');
1548
+ }
1549
+
1550
+ if (prevDemo == 0) {
1551
+ jQuery('.previous-theme').addClass('disabled');
1552
+ } else if (prevDemo != 0) {
1553
+ jQuery('.previous-theme').removeClass('disabled');
1554
+ }
1555
+
1556
+ return;
1557
+ },
1558
+
1559
+ /**
1560
+ * Render Demo Preview
1561
+ */
1562
+ _renderDemoPreview: function(anchor) {
1563
+
1564
+ var demoId = anchor.data('demo-id') || '',
1565
+ apiURL = anchor.data('demo-api') || '',
1566
+ demoType = anchor.data('demo-type') || '',
1567
+ demoURL = anchor.data('demo-url') || '',
1568
+ screenshot = anchor.data('screenshot') || '',
1569
+ demo_name = anchor.data('demo-name') || '',
1570
+ demo_slug = anchor.data('demo-slug') || '',
1571
+ content = anchor.data('content') || '',
1572
+ requiredPlugins = anchor.data('required-plugins') || '',
1573
+ astraSiteOptions = anchor.find('.astra-site-options').val() || '';
1574
+ astraEnabledExtensions = anchor.find('.astra-enabled-extensions').val() || '';
1575
+
1576
+ var template = wp.template('astra-site-preview');
1577
+
1578
+ templateData = [{
1579
+ id : demoId,
1580
+ astra_demo_type : demoType,
1581
+ astra_demo_url : demoURL,
1582
+ demo_api : apiURL,
1583
+ screenshot : screenshot,
1584
+ demo_name : demo_name,
1585
+ slug : demo_slug,
1586
+ content : content,
1587
+ required_plugins : JSON.stringify(requiredPlugins),
1588
+ astra_site_options : astraSiteOptions,
1589
+ astra_enabled_extensions : astraEnabledExtensions,
1590
+ }];
1591
+
1592
+ // delete any earlier fullscreen preview before we render new one.
1593
+ $('.theme-install-overlay').remove();
1594
+
1595
+ $('#astra-sites-menu-page').append(template(templateData[0]));
1596
+ $('.theme-install-overlay').css('display', 'block');
1597
+ AstraSitesAdmin._checkNextPrevButtons();
1598
+
1599
+ var desc = $('.theme-details');
1600
+ var descHeight = parseInt( desc.outerHeight() );
1601
+ var descBtn = $('.theme-details-read-more');
1602
+
1603
+ // Check is site imported recently and set flag.
1604
+ $.ajax({
1605
+ url : astraSitesAdmin.ajaxurl,
1606
+ type : 'POST',
1607
+ data : {
1608
+ action : 'astra-sites-set-reset-data',
1609
+ },
1610
+ })
1611
+ .done(function ( response ) {
1612
+ if( response.success ) {
1613
+ AstraSitesAdmin.site_imported_data = response.data;
1614
+ }
1615
+ });
1616
+
1617
+ if( $.isArray( requiredPlugins ) ) {
1618
+
1619
+ if( descHeight >= 55 ) {
1620
+
1621
+ // Show button.
1622
+ descBtn.css( 'display', 'inline-block' );
1623
+
1624
+ // Set height upto 3 line.
1625
+ desc.css( 'height', 57 );
1626
+
1627
+ // Button Click.
1628
+ descBtn.click(function(event) {
1629
+
1630
+ if( descBtn.hasClass('open') ) {
1631
+ desc.animate({ height: 57 },
1632
+ 300, function() {
1633
+ descBtn.removeClass('open');
1634
+ descBtn.html( astraSitesAdmin.strings.DescExpand );
1635
+ });
1636
+ } else {
1637
+ desc.animate({ height: descHeight },
1638
+ 300, function() {
1639
+ descBtn.addClass('open');
1640
+ descBtn.html( astraSitesAdmin.strings.DescCollapse );
1641
+ });
1642
+ }
1643
+
1644
+ });
1645
+ }
1646
+
1647
+ // or
1648
+ var $pluginsFilter = $( '#plugin-filter' ),
1649
+ data = {
1650
+ action : 'astra-required-plugins',
1651
+ _ajax_nonce : astraSitesAdmin._ajax_nonce,
1652
+ required_plugins : requiredPlugins
1653
+ };
1654
+
1655
+ // Add disabled class from import button.
1656
+ $('.astra-demo-import')
1657
+ .addClass('disabled not-click-able')
1658
+ .removeAttr('data-import');
1659
+
1660
+ $('.required-plugins').addClass('loading').html('<span class="spinner is-active"></span>');
1661
+
1662
+ // Required Required.
1663
+ $.ajax({
1664
+ url : astraSitesAdmin.ajaxurl,
1665
+ type : 'POST',
1666
+ data : data,
1667
+ })
1668
+ .fail(function( jqXHR ){
1669
+
1670
+ // Remove loader.
1671
+ $('.required-plugins').removeClass('loading').html('');
1672
+
1673
+ })
1674
+ .done(function ( response ) {
1675
+ required_plugins = response.data['required_plugins'];
1676
+
1677
+ if( response.data['third_party_required_plugins'].length ) {
1678
+ $('.astra-demo-import').removeClass('button-primary').addClass('disabled');
1679
+
1680
+ $('.astra-sites-third-party-required-plugins-wrap').remove();
1681
+ var template = wp.template('astra-sites-third-party-required-plugins');
1682
+ $('.astra-sites-advanced-options-wrap').html( template( response.data['third_party_required_plugins'] ) );
1683
+ } else {
1684
+ // Release disabled class from import button.
1685
+ $('.astra-demo-import')
1686
+ .removeClass('disabled not-click-able')
1687
+ .attr('data-import', 'disabled');
1688
+ }
1689
+
1690
+ // Remove loader.
1691
+ $('.required-plugins').removeClass('loading').html('');
1692
+ $('.required-plugins-list').html('');
1693
+
1694
+ /**
1695
+ * Count remaining plugins.
1696
+ * @type number
1697
+ */
1698
+ var remaining_plugins = 0;
1699
+
1700
+ /**
1701
+ * Not Installed
1702
+ *
1703
+ * List of not installed required plugins.
1704
+ */
1705
+ if ( typeof required_plugins.notinstalled !== 'undefined' ) {
1706
+
1707
+ // Add not have installed plugins count.
1708
+ remaining_plugins += parseInt( required_plugins.notinstalled.length );
1709
+
1710
+ $( required_plugins.notinstalled ).each(function( index, plugin ) {
1711
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1712
+ });
1713
+ }
1714
+
1715
+ /**
1716
+ * Inactive
1717
+ *
1718
+ * List of not inactive required plugins.
1719
+ */
1720
+ if ( typeof required_plugins.inactive !== 'undefined' ) {
1721
+
1722
+ // Add inactive plugins count.
1723
+ remaining_plugins += parseInt( required_plugins.inactive.length );
1724
+
1725
+ $( required_plugins.inactive ).each(function( index, plugin ) {
1726
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1727
+ });
1728
+ }
1729
+
1730
+ /**
1731
+ * Active
1732
+ *
1733
+ * List of not active required plugins.
1734
+ */
1735
+ if ( typeof required_plugins.active !== 'undefined' ) {
1736
+
1737
+ $( required_plugins.active ).each(function( index, plugin ) {
1738
+ $('.required-plugins-list').append('<li class="plugin-card plugin-card-'+plugin.slug+'" data-slug="'+plugin.slug+'" data-init="'+plugin.init+'" data-name="'+plugin.name+'">'+plugin.name+'</li>');
1739
+ });
1740
+ }
1741
+
1742
+ /**
1743
+ * Enable Demo Import Button
1744
+ * @type number
1745
+ */
1746
+ astraSitesAdmin.requiredPlugins = required_plugins;
1747
+ });
1748
+
1749
+ } else {
1750
+
1751
+ // Enable Demo Import Button
1752
+ AstraSitesAdmin._enable_demo_import_button( demoType );
1753
+ $('.astra-sites-advanced-options-wrap').remove();
1754
+ }
1755
+
1756
+ return;
1757
+ },
1758
+
1759
+ /**
1760
+ * Enable Demo Import Button.
1761
+ */
1762
+ _enable_demo_import_button: function( type ) {
1763
+
1764
+ type = ( undefined !== type ) ? type : 'free';
1765
+
1766
+ $('.install-theme-info .theme-details .site-description').remove();
1767
+
1768
+ switch( type ) {
1769
+
1770
+ case 'free':
1771
+
1772
+ var notinstalled = astraSitesAdmin.requiredPlugins.notinstalled || 0;
1773
+ var inactive = astraSitesAdmin.requiredPlugins.inactive || 0;
1774
+
1775
+ if( notinstalled.length === inactive.length ) {
1776
+
1777
+ // XML reader not available notice.
1778
+ if( astraSitesAdmin.XMLReaderDisabled ) {
1779
+ if( ! $('.install-theme-info .astra-sites-xml-notice').length ) {
1780
+ $('.install-theme-info').prepend( astraSitesAdmin.strings.warningXMLReader );
1781
+ }
1782
+ $('.astra-demo-import')
1783
+ .removeClass('installing updating-message')
1784
+ .addClass('disabled')
1785
+ .text( astraSitesAdmin.strings.importDemo );
1786
+ } else {
1787
+ $(document).trigger( 'astra-sites-install-and-activate-required-plugins-done' );
1788
+ }
1789
+ }
1790
+ break;
1791
+
1792
+ case 'upgrade':
1793
+ var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1794
+
1795
+ $('.astra-demo-import')
1796
+ .addClass('go-pro button-primary')
1797
+ .removeClass('astra-demo-import')
1798
+ .attr('target', '_blank')
1799
+ .attr('href', astraSitesAdmin.getUpgradeURL + demo_slug )
1800
+ .text( astraSitesAdmin.getUpgradeText )
1801
+ .append('<i class="dashicons dashicons-external"></i>');
1802
+ break;
1803
+
1804
+ default:
1805
+ var demo_slug = $('.wp-full-overlay-header').attr('data-demo-slug');
1806
+
1807
+ $('.astra-demo-import')
1808
+ .addClass('go-pro button-primary')
1809
+ .removeClass('astra-demo-import')
1810
+ .attr('target', '_blank')
1811
+ .attr('href', astraSitesAdmin.getProURL )
1812
+ .text( astraSitesAdmin.getProText )
1813
+ .append('<i class="dashicons dashicons-external"></i>');
1814
+
1815
+ $('.wp-full-overlay-header').find('.go-pro').remove();
1816
+
1817
+ if( false == astraSitesAdmin.isWhiteLabeled ) {
1818
+ if( astraSitesAdmin.isPro ) {
1819
+ $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-inactive-site-description') );
1820
+ } else {
1821
+ $('.install-theme-info .theme-details').prepend( wp.template('astra-sites-pro-site-description') );
1822
+ }
1823
+ }
1824
+
1825
+ break;
1826
+ }
1827
+
1828
+ },
1829
+
1830
+ /**
1831
+ * Update Page Count.
1832
+ */
1833
+ _updatedPagedCount: function() {
1834
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
1835
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
1836
+ window.setTimeout(function () {
1837
+ jQuery('body').data('scrolling', false);
1838
+ }, 800);
1839
+ },
1840
+
1841
+ /**
1842
+ * Reset Page Count.
1843
+ */
1844
+ _resetPagedCount: function() {
1845
+
1846
+ $('body').addClass('loading-content');
1847
+ $('body').attr('data-astra-demo-last-request', '1');
1848
+ $('body').attr('data-astra-demo-paged', '1');
1849
+ $('body').attr('data-astra-demo-search', '');
1850
+ $('body').attr('data-scrolling', false);
1851
+
1852
+ },
1853
+
1854
+ /**
1855
+ * Remove plugin from the queue.
1856
+ */
1857
+ _removePluginFromQueue: function( removeItem, pluginsList ) {
1858
+ return jQuery.grep(pluginsList, function( value ) {
1859
+ return value.slug != removeItem;
1860
+ });
1861
+ }
1862
+
1863
+ };
1864
+
1865
+ /**
1866
+ * Initialize AstraSitesAdmin
1867
+ */
1868
+ $(function(){
1869
+ AstraSitesAdmin.init();
1870
+ });
1871
+
1872
  })(jQuery);
inc/assets/js/astra-sites-api.js CHANGED
@@ -1,59 +1,59 @@
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, callback ) {
16
-
17
- var params = {
18
- method: 'GET',
19
- cache: 'default',
20
- };
21
-
22
- if( astraRenderGrid.headers ) {
23
- params['headers'] = astraRenderGrid.headers;
24
- }
25
-
26
- fetch( AstraSitesAPI._api_url + args.slug, params).then(response => {
27
- if ( response.status === 200 ) {
28
- return response.json().then(items => ({
29
- items : items,
30
- items_count : response.headers.get( 'x-wp-total' ),
31
- item_pages : response.headers.get( 'x-wp-totalpages' ),
32
- }))
33
- } else {
34
- $(document).trigger( 'astra-sites-api-request-error' );
35
- return response.json();
36
- }
37
- })
38
- .then(data => {
39
- if( 'object' === typeof data ) {
40
- data['args'] = args;
41
- if( data.args.id ) {
42
- AstraSitesAPI._stored_data[ args.id ] = $.merge( AstraSitesAPI._stored_data[ data.args.id ], data.items );
43
- }
44
-
45
- if( 'undefined' !== typeof args.trigger && '' !== args.trigger ) {
46
- $(document).trigger( args.trigger, [data] );
47
- }
48
-
49
- if( callback && typeof callback == "function"){
50
- callback( data );
51
- }
52
- }
53
- });
54
-
55
- },
56
-
57
- };
58
-
59
- })(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, callback ) {
16
+
17
+ var params = {
18
+ method: 'GET',
19
+ cache: 'default',
20
+ };
21
+
22
+ if( astraRenderGrid.headers ) {
23
+ params['headers'] = astraRenderGrid.headers;
24
+ }
25
+
26
+ fetch( AstraSitesAPI._api_url + args.slug, params).then(response => {
27
+ if ( response.status === 200 ) {
28
+ return response.json().then(items => ({
29
+ items : items,
30
+ items_count : response.headers.get( 'x-wp-total' ),
31
+ item_pages : response.headers.get( 'x-wp-totalpages' ),
32
+ }))
33
+ } else {
34
+ $(document).trigger( 'astra-sites-api-request-error' );
35
+ return response.json();
36
+ }
37
+ })
38
+ .then(data => {
39
+ if( 'object' === typeof data ) {
40
+ data['args'] = args;
41
+ if( data.args.id ) {
42
+ AstraSitesAPI._stored_data[ args.id ] = $.merge( AstraSitesAPI._stored_data[ data.args.id ], data.items );
43
+ }
44
+
45
+ if( 'undefined' !== typeof args.trigger && '' !== args.trigger ) {
46
+ $(document).trigger( args.trigger, [data] );
47
+ }
48
+
49
+ if( callback && typeof callback == "function"){
50
+ callback( data );
51
+ }
52
+ }
53
+ });
54
+
55
+ },
56
+
57
+ };
58
+
59
+ })(jQuery);
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/fetch.umd.js CHANGED
@@ -1,531 +1,531 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
- typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
- (factory((global.WHATWGFetch = {})));
5
- }(this, (function (exports) { 'use strict';
6
-
7
- var support = {
8
- searchParams: 'URLSearchParams' in self,
9
- iterable: 'Symbol' in self && 'iterator' in Symbol,
10
- blob:
11
- 'FileReader' in self &&
12
- 'Blob' in self &&
13
- (function() {
14
- try {
15
- new Blob();
16
- return true
17
- } catch (e) {
18
- return false
19
- }
20
- })(),
21
- formData: 'FormData' in self,
22
- arrayBuffer: 'ArrayBuffer' in self
23
- };
24
-
25
- function isDataView(obj) {
26
- return obj && DataView.prototype.isPrototypeOf(obj)
27
- }
28
-
29
- if (support.arrayBuffer) {
30
- var viewClasses = [
31
- '[object Int8Array]',
32
- '[object Uint8Array]',
33
- '[object Uint8ClampedArray]',
34
- '[object Int16Array]',
35
- '[object Uint16Array]',
36
- '[object Int32Array]',
37
- '[object Uint32Array]',
38
- '[object Float32Array]',
39
- '[object Float64Array]'
40
- ];
41
-
42
- var isArrayBufferView =
43
- ArrayBuffer.isView ||
44
- function(obj) {
45
- return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
46
- };
47
- }
48
-
49
- function normalizeName(name) {
50
- if (typeof name !== 'string') {
51
- name = String(name);
52
- }
53
- if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
54
- throw new TypeError('Invalid character in header field name')
55
- }
56
- return name.toLowerCase()
57
- }
58
-
59
- function normalizeValue(value) {
60
- if (typeof value !== 'string') {
61
- value = String(value);
62
- }
63
- return value
64
- }
65
-
66
- // Build a destructive iterator for the value list
67
- function iteratorFor(items) {
68
- var iterator = {
69
- next: function() {
70
- var value = items.shift();
71
- return {done: value === undefined, value: value}
72
- }
73
- };
74
-
75
- if (support.iterable) {
76
- iterator[Symbol.iterator] = function() {
77
- return iterator
78
- };
79
- }
80
-
81
- return iterator
82
- }
83
-
84
- function Headers(headers) {
85
- this.map = {};
86
-
87
- if (headers instanceof Headers) {
88
- headers.forEach(function(value, name) {
89
- this.append(name, value);
90
- }, this);
91
- } else if (Array.isArray(headers)) {
92
- headers.forEach(function(header) {
93
- this.append(header[0], header[1]);
94
- }, this);
95
- } else if (headers) {
96
- Object.getOwnPropertyNames(headers).forEach(function(name) {
97
- this.append(name, headers[name]);
98
- }, this);
99
- }
100
- }
101
-
102
- Headers.prototype.append = function(name, value) {
103
- name = normalizeName(name);
104
- value = normalizeValue(value);
105
- var oldValue = this.map[name];
106
- this.map[name] = oldValue ? oldValue + ', ' + value : value;
107
- };
108
-
109
- Headers.prototype['delete'] = function(name) {
110
- delete this.map[normalizeName(name)];
111
- };
112
-
113
- Headers.prototype.get = function(name) {
114
- name = normalizeName(name);
115
- return this.has(name) ? this.map[name] : null
116
- };
117
-
118
- Headers.prototype.has = function(name) {
119
- return this.map.hasOwnProperty(normalizeName(name))
120
- };
121
-
122
- Headers.prototype.set = function(name, value) {
123
- this.map[normalizeName(name)] = normalizeValue(value);
124
- };
125
-
126
- Headers.prototype.forEach = function(callback, thisArg) {
127
- for (var name in this.map) {
128
- if (this.map.hasOwnProperty(name)) {
129
- callback.call(thisArg, this.map[name], name, this);
130
- }
131
- }
132
- };
133
-
134
- Headers.prototype.keys = function() {
135
- var items = [];
136
- this.forEach(function(value, name) {
137
- items.push(name);
138
- });
139
- return iteratorFor(items)
140
- };
141
-
142
- Headers.prototype.values = function() {
143
- var items = [];
144
- this.forEach(function(value) {
145
- items.push(value);
146
- });
147
- return iteratorFor(items)
148
- };
149
-
150
- Headers.prototype.entries = function() {
151
- var items = [];
152
- this.forEach(function(value, name) {
153
- items.push([name, value]);
154
- });
155
- return iteratorFor(items)
156
- };
157
-
158
- if (support.iterable) {
159
- Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
160
- }
161
-
162
- function consumed(body) {
163
- if (body.bodyUsed) {
164
- return Promise.reject(new TypeError('Already read'))
165
- }
166
- body.bodyUsed = true;
167
- }
168
-
169
- function fileReaderReady(reader) {
170
- return new Promise(function(resolve, reject) {
171
- reader.onload = function() {
172
- resolve(reader.result);
173
- };
174
- reader.onerror = function() {
175
- reject(reader.error);
176
- };
177
- })
178
- }
179
-
180
- function readBlobAsArrayBuffer(blob) {
181
- var reader = new FileReader();
182
- var promise = fileReaderReady(reader);
183
- reader.readAsArrayBuffer(blob);
184
- return promise
185
- }
186
-
187
- function readBlobAsText(blob) {
188
- var reader = new FileReader();
189
- var promise = fileReaderReady(reader);
190
- reader.readAsText(blob);
191
- return promise
192
- }
193
-
194
- function readArrayBufferAsText(buf) {
195
- var view = new Uint8Array(buf);
196
- var chars = new Array(view.length);
197
-
198
- for (var i = 0; i < view.length; i++) {
199
- chars[i] = String.fromCharCode(view[i]);
200
- }
201
- return chars.join('')
202
- }
203
-
204
- function bufferClone(buf) {
205
- if (buf.slice) {
206
- return buf.slice(0)
207
- } else {
208
- var view = new Uint8Array(buf.byteLength);
209
- view.set(new Uint8Array(buf));
210
- return view.buffer
211
- }
212
- }
213
-
214
- function Body() {
215
- this.bodyUsed = false;
216
-
217
- this._initBody = function(body) {
218
- this._bodyInit = body;
219
- if (!body) {
220
- this._bodyText = '';
221
- } else if (typeof body === 'string') {
222
- this._bodyText = body;
223
- } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
224
- this._bodyBlob = body;
225
- } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
226
- this._bodyFormData = body;
227
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
228
- this._bodyText = body.toString();
229
- } else if (support.arrayBuffer && support.blob && isDataView(body)) {
230
- this._bodyArrayBuffer = bufferClone(body.buffer);
231
- // IE 10-11 can't handle a DataView body.
232
- this._bodyInit = new Blob([this._bodyArrayBuffer]);
233
- } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
234
- this._bodyArrayBuffer = bufferClone(body);
235
- } else {
236
- this._bodyText = body = Object.prototype.toString.call(body);
237
- }
238
-
239
- if (!this.headers.get('content-type')) {
240
- if (typeof body === 'string') {
241
- this.headers.set('content-type', 'text/plain;charset=UTF-8');
242
- } else if (this._bodyBlob && this._bodyBlob.type) {
243
- this.headers.set('content-type', this._bodyBlob.type);
244
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
245
- this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
246
- }
247
- }
248
- };
249
-
250
- if (support.blob) {
251
- this.blob = function() {
252
- var rejected = consumed(this);
253
- if (rejected) {
254
- return rejected
255
- }
256
-
257
- if (this._bodyBlob) {
258
- return Promise.resolve(this._bodyBlob)
259
- } else if (this._bodyArrayBuffer) {
260
- return Promise.resolve(new Blob([this._bodyArrayBuffer]))
261
- } else if (this._bodyFormData) {
262
- throw new Error('could not read FormData body as blob')
263
- } else {
264
- return Promise.resolve(new Blob([this._bodyText]))
265
- }
266
- };
267
-
268
- this.arrayBuffer = function() {
269
- if (this._bodyArrayBuffer) {
270
- return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
271
- } else {
272
- return this.blob().then(readBlobAsArrayBuffer)
273
- }
274
- };
275
- }
276
-
277
- this.text = function() {
278
- var rejected = consumed(this);
279
- if (rejected) {
280
- return rejected
281
- }
282
-
283
- if (this._bodyBlob) {
284
- return readBlobAsText(this._bodyBlob)
285
- } else if (this._bodyArrayBuffer) {
286
- return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
287
- } else if (this._bodyFormData) {
288
- throw new Error('could not read FormData body as text')
289
- } else {
290
- return Promise.resolve(this._bodyText)
291
- }
292
- };
293
-
294
- if (support.formData) {
295
- this.formData = function() {
296
- return this.text().then(decode)
297
- };
298
- }
299
-
300
- this.json = function() {
301
- return this.text().then(JSON.parse)
302
- };
303
-
304
- return this
305
- }
306
-
307
- // HTTP methods whose capitalization should be normalized
308
- var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
309
-
310
- function normalizeMethod(method) {
311
- var upcased = method.toUpperCase();
312
- return methods.indexOf(upcased) > -1 ? upcased : method
313
- }
314
-
315
- function Request(input, options) {
316
- options = options || {};
317
- var body = options.body;
318
-
319
- if (input instanceof Request) {
320
- if (input.bodyUsed) {
321
- throw new TypeError('Already read')
322
- }
323
- this.url = input.url;
324
- this.credentials = input.credentials;
325
- if (!options.headers) {
326
- this.headers = new Headers(input.headers);
327
- }
328
- this.method = input.method;
329
- this.mode = input.mode;
330
- this.signal = input.signal;
331
- if (!body && input._bodyInit != null) {
332
- body = input._bodyInit;
333
- input.bodyUsed = true;
334
- }
335
- } else {
336
- this.url = String(input);
337
- }
338
-
339
- this.credentials = options.credentials || this.credentials || 'same-origin';
340
- if (options.headers || !this.headers) {
341
- this.headers = new Headers(options.headers);
342
- }
343
- this.method = normalizeMethod(options.method || this.method || 'GET');
344
- this.mode = options.mode || this.mode || null;
345
- this.signal = options.signal || this.signal;
346
- this.referrer = null;
347
-
348
- if ((this.method === 'GET' || this.method === 'HEAD') && body) {
349
- throw new TypeError('Body not allowed for GET or HEAD requests')
350
- }
351
- this._initBody(body);
352
- }
353
-
354
- Request.prototype.clone = function() {
355
- return new Request(this, {body: this._bodyInit})
356
- };
357
-
358
- function decode(body) {
359
- var form = new FormData();
360
- body
361
- .trim()
362
- .split('&')
363
- .forEach(function(bytes) {
364
- if (bytes) {
365
- var split = bytes.split('=');
366
- var name = split.shift().replace(/\+/g, ' ');
367
- var value = split.join('=').replace(/\+/g, ' ');
368
- form.append(decodeURIComponent(name), decodeURIComponent(value));
369
- }
370
- });
371
- return form
372
- }
373
-
374
- function parseHeaders(rawHeaders) {
375
- var headers = new Headers();
376
- // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
377
- // https://tools.ietf.org/html/rfc7230#section-3.2
378
- var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
379
- preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
380
- var parts = line.split(':');
381
- var key = parts.shift().trim();
382
- if (key) {
383
- var value = parts.join(':').trim();
384
- headers.append(key, value);
385
- }
386
- });
387
- return headers
388
- }
389
-
390
- Body.call(Request.prototype);
391
-
392
- function Response(bodyInit, options) {
393
- if (!options) {
394
- options = {};
395
- }
396
-
397
- this.type = 'default';
398
- this.status = options.status === undefined ? 200 : options.status;
399
- this.ok = this.status >= 200 && this.status < 300;
400
- this.statusText = 'statusText' in options ? options.statusText : 'OK';
401
- this.headers = new Headers(options.headers);
402
- this.url = options.url || '';
403
- this._initBody(bodyInit);
404
- }
405
-
406
- Body.call(Response.prototype);
407
-
408
- Response.prototype.clone = function() {
409
- return new Response(this._bodyInit, {
410
- status: this.status,
411
- statusText: this.statusText,
412
- headers: new Headers(this.headers),
413
- url: this.url
414
- })
415
- };
416
-
417
- Response.error = function() {
418
- var response = new Response(null, {status: 0, statusText: ''});
419
- response.type = 'error';
420
- return response
421
- };
422
-
423
- var redirectStatuses = [301, 302, 303, 307, 308];
424
-
425
- Response.redirect = function(url, status) {
426
- if (redirectStatuses.indexOf(status) === -1) {
427
- throw new RangeError('Invalid status code')
428
- }
429
-
430
- return new Response(null, {status: status, headers: {location: url}})
431
- };
432
-
433
- exports.DOMException = self.DOMException;
434
- try {
435
- new exports.DOMException();
436
- } catch (err) {
437
- exports.DOMException = function(message, name) {
438
- this.message = message;
439
- this.name = name;
440
- var error = Error(message);
441
- this.stack = error.stack;
442
- };
443
- exports.DOMException.prototype = Object.create(Error.prototype);
444
- exports.DOMException.prototype.constructor = exports.DOMException;
445
- }
446
-
447
- function fetch(input, init) {
448
- return new Promise(function(resolve, reject) {
449
- var request = new Request(input, init);
450
-
451
- if (request.signal && request.signal.aborted) {
452
- return reject(new exports.DOMException('Aborted', 'AbortError'))
453
- }
454
-
455
- var xhr = new XMLHttpRequest();
456
-
457
- function abortXhr() {
458
- xhr.abort();
459
- }
460
-
461
- xhr.onload = function() {
462
- var options = {
463
- status: xhr.status,
464
- statusText: xhr.statusText,
465
- headers: parseHeaders(xhr.getAllResponseHeaders() || '')
466
- };
467
- options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
468
- var body = 'response' in xhr ? xhr.response : xhr.responseText;
469
- resolve(new Response(body, options));
470
- };
471
-
472
- xhr.onerror = function() {
473
- reject(new TypeError('Network request failed'));
474
- };
475
-
476
- xhr.ontimeout = function() {
477
- reject(new TypeError('Network request failed'));
478
- };
479
-
480
- xhr.onabort = function() {
481
- reject(new exports.DOMException('Aborted', 'AbortError'));
482
- };
483
-
484
- xhr.open(request.method, request.url, true);
485
-
486
- if (request.credentials === 'include') {
487
- xhr.withCredentials = true;
488
- } else if (request.credentials === 'omit') {
489
- xhr.withCredentials = false;
490
- }
491
-
492
- if ('responseType' in xhr && support.blob) {
493
- xhr.responseType = 'blob';
494
- }
495
-
496
- request.headers.forEach(function(value, name) {
497
- xhr.setRequestHeader(name, value);
498
- });
499
-
500
- if (request.signal) {
501
- request.signal.addEventListener('abort', abortXhr);
502
-
503
- xhr.onreadystatechange = function() {
504
- // DONE (success or failure)
505
- if (xhr.readyState === 4) {
506
- request.signal.removeEventListener('abort', abortXhr);
507
- }
508
- };
509
- }
510
-
511
- xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
512
- })
513
- }
514
-
515
- fetch.polyfill = true;
516
-
517
- if (!self.fetch) {
518
- self.fetch = fetch;
519
- self.Headers = Headers;
520
- self.Request = Request;
521
- self.Response = Response;
522
- }
523
-
524
- exports.Headers = Headers;
525
- exports.Request = Request;
526
- exports.Response = Response;
527
- exports.fetch = fetch;
528
-
529
- Object.defineProperty(exports, '__esModule', { value: true });
530
-
531
- })));
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (factory((global.WHATWGFetch = {})));
5
+ }(this, (function (exports) { 'use strict';
6
+
7
+ var support = {
8
+ searchParams: 'URLSearchParams' in self,
9
+ iterable: 'Symbol' in self && 'iterator' in Symbol,
10
+ blob:
11
+ 'FileReader' in self &&
12
+ 'Blob' in self &&
13
+ (function() {
14
+ try {
15
+ new Blob();
16
+ return true
17
+ } catch (e) {
18
+ return false
19
+ }
20
+ })(),
21
+ formData: 'FormData' in self,
22
+ arrayBuffer: 'ArrayBuffer' in self
23
+ };
24
+
25
+ function isDataView(obj) {
26
+ return obj && DataView.prototype.isPrototypeOf(obj)
27
+ }
28
+
29
+ if (support.arrayBuffer) {
30
+ var viewClasses = [
31
+ '[object Int8Array]',
32
+ '[object Uint8Array]',
33
+ '[object Uint8ClampedArray]',
34
+ '[object Int16Array]',
35
+ '[object Uint16Array]',
36
+ '[object Int32Array]',
37
+ '[object Uint32Array]',
38
+ '[object Float32Array]',
39
+ '[object Float64Array]'
40
+ ];
41
+
42
+ var isArrayBufferView =
43
+ ArrayBuffer.isView ||
44
+ function(obj) {
45
+ return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1
46
+ };
47
+ }
48
+
49
+ function normalizeName(name) {
50
+ if (typeof name !== 'string') {
51
+ name = String(name);
52
+ }
53
+ if (/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(name)) {
54
+ throw new TypeError('Invalid character in header field name')
55
+ }
56
+ return name.toLowerCase()
57
+ }
58
+
59
+ function normalizeValue(value) {
60
+ if (typeof value !== 'string') {
61
+ value = String(value);
62
+ }
63
+ return value
64
+ }
65
+
66
+ // Build a destructive iterator for the value list
67
+ function iteratorFor(items) {
68
+ var iterator = {
69
+ next: function() {
70
+ var value = items.shift();
71
+ return {done: value === undefined, value: value}
72
+ }
73
+ };
74
+
75
+ if (support.iterable) {
76
+ iterator[Symbol.iterator] = function() {
77
+ return iterator
78
+ };
79
+ }
80
+
81
+ return iterator
82
+ }
83
+
84
+ function Headers(headers) {
85
+ this.map = {};
86
+
87
+ if (headers instanceof Headers) {
88
+ headers.forEach(function(value, name) {
89
+ this.append(name, value);
90
+ }, this);
91
+ } else if (Array.isArray(headers)) {
92
+ headers.forEach(function(header) {
93
+ this.append(header[0], header[1]);
94
+ }, this);
95
+ } else if (headers) {
96
+ Object.getOwnPropertyNames(headers).forEach(function(name) {
97
+ this.append(name, headers[name]);
98
+ }, this);
99
+ }
100
+ }
101
+
102
+ Headers.prototype.append = function(name, value) {
103
+ name = normalizeName(name);
104
+ value = normalizeValue(value);
105
+ var oldValue = this.map[name];
106
+ this.map[name] = oldValue ? oldValue + ', ' + value : value;
107
+ };
108
+
109
+ Headers.prototype['delete'] = function(name) {
110
+ delete this.map[normalizeName(name)];
111
+ };
112
+
113
+ Headers.prototype.get = function(name) {
114
+ name = normalizeName(name);
115
+ return this.has(name) ? this.map[name] : null
116
+ };
117
+
118
+ Headers.prototype.has = function(name) {
119
+ return this.map.hasOwnProperty(normalizeName(name))
120
+ };
121
+
122
+ Headers.prototype.set = function(name, value) {
123
+ this.map[normalizeName(name)] = normalizeValue(value);
124
+ };
125
+
126
+ Headers.prototype.forEach = function(callback, thisArg) {
127
+ for (var name in this.map) {
128
+ if (this.map.hasOwnProperty(name)) {
129
+ callback.call(thisArg, this.map[name], name, this);
130
+ }
131
+ }
132
+ };
133
+
134
+ Headers.prototype.keys = function() {
135
+ var items = [];
136
+ this.forEach(function(value, name) {
137
+ items.push(name);
138
+ });
139
+ return iteratorFor(items)
140
+ };
141
+
142
+ Headers.prototype.values = function() {
143
+ var items = [];
144
+ this.forEach(function(value) {
145
+ items.push(value);
146
+ });
147
+ return iteratorFor(items)
148
+ };
149
+
150
+ Headers.prototype.entries = function() {
151
+ var items = [];
152
+ this.forEach(function(value, name) {
153
+ items.push([name, value]);
154
+ });
155
+ return iteratorFor(items)
156
+ };
157
+
158
+ if (support.iterable) {
159
+ Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
160
+ }
161
+
162
+ function consumed(body) {
163
+ if (body.bodyUsed) {
164
+ return Promise.reject(new TypeError('Already read'))
165
+ }
166
+ body.bodyUsed = true;
167
+ }
168
+
169
+ function fileReaderReady(reader) {
170
+ return new Promise(function(resolve, reject) {
171
+ reader.onload = function() {
172
+ resolve(reader.result);
173
+ };
174
+ reader.onerror = function() {
175
+ reject(reader.error);
176
+ };
177
+ })
178
+ }
179
+
180
+ function readBlobAsArrayBuffer(blob) {
181
+ var reader = new FileReader();
182
+ var promise = fileReaderReady(reader);
183
+ reader.readAsArrayBuffer(blob);
184
+ return promise
185
+ }
186
+
187
+ function readBlobAsText(blob) {
188
+ var reader = new FileReader();
189
+ var promise = fileReaderReady(reader);
190
+ reader.readAsText(blob);
191
+ return promise
192
+ }
193
+
194
+ function readArrayBufferAsText(buf) {
195
+ var view = new Uint8Array(buf);
196
+ var chars = new Array(view.length);
197
+
198
+ for (var i = 0; i < view.length; i++) {
199
+ chars[i] = String.fromCharCode(view[i]);
200
+ }
201
+ return chars.join('')
202
+ }
203
+
204
+ function bufferClone(buf) {
205
+ if (buf.slice) {
206
+ return buf.slice(0)
207
+ } else {
208
+ var view = new Uint8Array(buf.byteLength);
209
+ view.set(new Uint8Array(buf));
210
+ return view.buffer
211
+ }
212
+ }
213
+
214
+ function Body() {
215
+ this.bodyUsed = false;
216
+
217
+ this._initBody = function(body) {
218
+ this._bodyInit = body;
219
+ if (!body) {
220
+ this._bodyText = '';
221
+ } else if (typeof body === 'string') {
222
+ this._bodyText = body;
223
+ } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
224
+ this._bodyBlob = body;
225
+ } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
226
+ this._bodyFormData = body;
227
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
228
+ this._bodyText = body.toString();
229
+ } else if (support.arrayBuffer && support.blob && isDataView(body)) {
230
+ this._bodyArrayBuffer = bufferClone(body.buffer);
231
+ // IE 10-11 can't handle a DataView body.
232
+ this._bodyInit = new Blob([this._bodyArrayBuffer]);
233
+ } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
234
+ this._bodyArrayBuffer = bufferClone(body);
235
+ } else {
236
+ this._bodyText = body = Object.prototype.toString.call(body);
237
+ }
238
+
239
+ if (!this.headers.get('content-type')) {
240
+ if (typeof body === 'string') {
241
+ this.headers.set('content-type', 'text/plain;charset=UTF-8');
242
+ } else if (this._bodyBlob && this._bodyBlob.type) {
243
+ this.headers.set('content-type', this._bodyBlob.type);
244
+ } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
245
+ this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
246
+ }
247
+ }
248
+ };
249
+
250
+ if (support.blob) {
251
+ this.blob = function() {
252
+ var rejected = consumed(this);
253
+ if (rejected) {
254
+ return rejected
255
+ }
256
+
257
+ if (this._bodyBlob) {
258
+ return Promise.resolve(this._bodyBlob)
259
+ } else if (this._bodyArrayBuffer) {
260
+ return Promise.resolve(new Blob([this._bodyArrayBuffer]))
261
+ } else if (this._bodyFormData) {
262
+ throw new Error('could not read FormData body as blob')
263
+ } else {
264
+ return Promise.resolve(new Blob([this._bodyText]))
265
+ }
266
+ };
267
+
268
+ this.arrayBuffer = function() {
269
+ if (this._bodyArrayBuffer) {
270
+ return consumed(this) || Promise.resolve(this._bodyArrayBuffer)
271
+ } else {
272
+ return this.blob().then(readBlobAsArrayBuffer)
273
+ }
274
+ };
275
+ }
276
+
277
+ this.text = function() {
278
+ var rejected = consumed(this);
279
+ if (rejected) {
280
+ return rejected
281
+ }
282
+
283
+ if (this._bodyBlob) {
284
+ return readBlobAsText(this._bodyBlob)
285
+ } else if (this._bodyArrayBuffer) {
286
+ return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer))
287
+ } else if (this._bodyFormData) {
288
+ throw new Error('could not read FormData body as text')
289
+ } else {
290
+ return Promise.resolve(this._bodyText)
291
+ }
292
+ };
293
+
294
+ if (support.formData) {
295
+ this.formData = function() {
296
+ return this.text().then(decode)
297
+ };
298
+ }
299
+
300
+ this.json = function() {
301
+ return this.text().then(JSON.parse)
302
+ };
303
+
304
+ return this
305
+ }
306
+
307
+ // HTTP methods whose capitalization should be normalized
308
+ var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT'];
309
+
310
+ function normalizeMethod(method) {
311
+ var upcased = method.toUpperCase();
312
+ return methods.indexOf(upcased) > -1 ? upcased : method
313
+ }
314
+
315
+ function Request(input, options) {
316
+ options = options || {};
317
+ var body = options.body;
318
+
319
+ if (input instanceof Request) {
320
+ if (input.bodyUsed) {
321
+ throw new TypeError('Already read')
322
+ }
323
+ this.url = input.url;
324
+ this.credentials = input.credentials;
325
+ if (!options.headers) {
326
+ this.headers = new Headers(input.headers);
327
+ }
328
+ this.method = input.method;
329
+ this.mode = input.mode;
330
+ this.signal = input.signal;
331
+ if (!body && input._bodyInit != null) {
332
+ body = input._bodyInit;
333
+ input.bodyUsed = true;
334
+ }
335
+ } else {
336
+ this.url = String(input);
337
+ }
338
+
339
+ this.credentials = options.credentials || this.credentials || 'same-origin';
340
+ if (options.headers || !this.headers) {
341
+ this.headers = new Headers(options.headers);
342
+ }
343
+ this.method = normalizeMethod(options.method || this.method || 'GET');
344
+ this.mode = options.mode || this.mode || null;
345
+ this.signal = options.signal || this.signal;
346
+ this.referrer = null;
347
+
348
+ if ((this.method === 'GET' || this.method === 'HEAD') && body) {
349
+ throw new TypeError('Body not allowed for GET or HEAD requests')
350
+ }
351
+ this._initBody(body);
352
+ }
353
+
354
+ Request.prototype.clone = function() {
355
+ return new Request(this, {body: this._bodyInit})
356
+ };
357
+
358
+ function decode(body) {
359
+ var form = new FormData();
360
+ body
361
+ .trim()
362
+ .split('&')
363
+ .forEach(function(bytes) {
364
+ if (bytes) {
365
+ var split = bytes.split('=');
366
+ var name = split.shift().replace(/\+/g, ' ');
367
+ var value = split.join('=').replace(/\+/g, ' ');
368
+ form.append(decodeURIComponent(name), decodeURIComponent(value));
369
+ }
370
+ });
371
+ return form
372
+ }
373
+
374
+ function parseHeaders(rawHeaders) {
375
+ var headers = new Headers();
376
+ // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space
377
+ // https://tools.ietf.org/html/rfc7230#section-3.2
378
+ var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' ');
379
+ preProcessedHeaders.split(/\r?\n/).forEach(function(line) {
380
+ var parts = line.split(':');
381
+ var key = parts.shift().trim();
382
+ if (key) {
383
+ var value = parts.join(':').trim();
384
+ headers.append(key, value);
385
+ }
386
+ });
387
+ return headers
388
+ }
389
+
390
+ Body.call(Request.prototype);
391
+
392
+ function Response(bodyInit, options) {
393
+ if (!options) {
394
+ options = {};
395
+ }
396
+
397
+ this.type = 'default';
398
+ this.status = options.status === undefined ? 200 : options.status;
399
+ this.ok = this.status >= 200 && this.status < 300;
400
+ this.statusText = 'statusText' in options ? options.statusText : 'OK';
401
+ this.headers = new Headers(options.headers);
402
+ this.url = options.url || '';
403
+ this._initBody(bodyInit);
404
+ }
405
+
406
+ Body.call(Response.prototype);
407
+
408
+ Response.prototype.clone = function() {
409
+ return new Response(this._bodyInit, {
410
+ status: this.status,
411
+ statusText: this.statusText,
412
+ headers: new Headers(this.headers),
413
+ url: this.url
414
+ })
415
+ };
416
+
417
+ Response.error = function() {
418
+ var response = new Response(null, {status: 0, statusText: ''});
419
+ response.type = 'error';
420
+ return response
421
+ };
422
+
423
+ var redirectStatuses = [301, 302, 303, 307, 308];
424
+
425
+ Response.redirect = function(url, status) {
426
+ if (redirectStatuses.indexOf(status) === -1) {
427
+ throw new RangeError('Invalid status code')
428
+ }
429
+
430
+ return new Response(null, {status: status, headers: {location: url}})
431
+ };
432
+
433
+ exports.DOMException = self.DOMException;
434
+ try {
435
+ new exports.DOMException();
436
+ } catch (err) {
437
+ exports.DOMException = function(message, name) {
438
+ this.message = message;
439
+ this.name = name;
440
+ var error = Error(message);
441
+ this.stack = error.stack;
442
+ };
443
+ exports.DOMException.prototype = Object.create(Error.prototype);
444
+ exports.DOMException.prototype.constructor = exports.DOMException;
445
+ }
446
+
447
+ function fetch(input, init) {
448
+ return new Promise(function(resolve, reject) {
449
+ var request = new Request(input, init);
450
+
451
+ if (request.signal && request.signal.aborted) {
452
+ return reject(new exports.DOMException('Aborted', 'AbortError'))
453
+ }
454
+
455
+ var xhr = new XMLHttpRequest();
456
+
457
+ function abortXhr() {
458
+ xhr.abort();
459
+ }
460
+
461
+ xhr.onload = function() {
462
+ var options = {
463
+ status: xhr.status,
464
+ statusText: xhr.statusText,
465
+ headers: parseHeaders(xhr.getAllResponseHeaders() || '')
466
+ };
467
+ options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL');
468
+ var body = 'response' in xhr ? xhr.response : xhr.responseText;
469
+ resolve(new Response(body, options));
470
+ };
471
+
472
+ xhr.onerror = function() {
473
+ reject(new TypeError('Network request failed'));
474
+ };
475
+
476
+ xhr.ontimeout = function() {
477
+ reject(new TypeError('Network request failed'));
478
+ };
479
+
480
+ xhr.onabort = function() {
481
+ reject(new exports.DOMException('Aborted', 'AbortError'));
482
+ };
483
+
484
+ xhr.open(request.method, request.url, true);
485
+
486
+ if (request.credentials === 'include') {
487
+ xhr.withCredentials = true;
488
+ } else if (request.credentials === 'omit') {
489
+ xhr.withCredentials = false;
490
+ }
491
+
492
+ if ('responseType' in xhr && support.blob) {
493
+ xhr.responseType = 'blob';
494
+ }
495
+
496
+ request.headers.forEach(function(value, name) {
497
+ xhr.setRequestHeader(name, value);
498
+ });
499
+
500
+ if (request.signal) {
501
+ request.signal.addEventListener('abort', abortXhr);
502
+
503
+ xhr.onreadystatechange = function() {
504
+ // DONE (success or failure)
505
+ if (xhr.readyState === 4) {
506
+ request.signal.removeEventListener('abort', abortXhr);
507
+ }
508
+ };
509
+ }
510
+
511
+ xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit);
512
+ })
513
+ }
514
+
515
+ fetch.polyfill = true;
516
+
517
+ if (!self.fetch) {
518
+ self.fetch = fetch;
519
+ self.Headers = Headers;
520
+ self.Request = Request;
521
+ self.Response = Response;
522
+ }
523
+
524
+ exports.Headers = Headers;
525
+ exports.Request = Request;
526
+ exports.Response = Response;
527
+ exports.fetch = fetch;
528
+
529
+ Object.defineProperty(exports, '__esModule', { value: true });
530
+
531
+ })));
inc/assets/js/install-theme.js CHANGED
@@ -1,128 +1,128 @@
1
- (function($){
2
-
3
- AstraSitesInstallTheme = {
4
-
5
- /**
6
- * Init
7
- */
8
- init: function() {
9
- this._auto_close_notice();
10
- this._bind();
11
- },
12
-
13
- /**
14
- * Binds events for the Astra Sites.
15
- *
16
- * @since 1.3.2
17
- *
18
- * @access private
19
- * @method _bind
20
- */
21
- _bind: function()
22
- {
23
- $( document ).on( 'click', '.astra-sites-theme-not-installed', AstraSitesInstallTheme._install_and_activate );
24
- $( document ).on( 'click', '.astra-sites-theme-installed-but-inactive', AstraSitesInstallTheme._activateTheme );
25
- $( document ).on('wp-theme-install-success' , AstraSitesInstallTheme._activateTheme);
26
- },
27
-
28
- /**
29
- * Close Getting Started Notice
30
- *
31
- * @param {object} event
32
- * @return void
33
- */
34
- _auto_close_notice: function() {
35
-
36
- if( $( '.astra-sites-getting-started-btn' ).length ) {
37
- $.ajax({
38
- url: AstraSitesInstallThemeVars.ajaxurl,
39
- type: 'POST',
40
- data: {
41
- 'action' : 'astra-sites-getting-started-notice'
42
- },
43
- })
44
- .done(function (result) {
45
- });
46
- }
47
-
48
- },
49
-
50
- /**
51
- * Activate Theme
52
- *
53
- * @since 1.3.2
54
- */
55
- _activateTheme: function( event, response ) {
56
- event.preventDefault();
57
-
58
- $('#astra-theme-activation-nag a').addClass('processing');
59
-
60
- if( response ) {
61
- $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.installed );
62
- } else {
63
- $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.activating );
64
- }
65
-
66
- // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
67
- setTimeout( function() {
68
-
69
- $.ajax({
70
- url: AstraSitesInstallThemeVars.ajaxurl,
71
- type: 'POST',
72
- data: {
73
- 'action' : 'astra-sites-activate-theme'
74
- },
75
- })
76
- .done(function (result) {
77
- if( result.success ) {
78
- $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.activated );
79
-
80
- setTimeout(function() {
81
- location.reload();
82
- }, 1000);
83
- }
84
-
85
- });
86
-
87
- }, 3000 );
88
-
89
- },
90
-
91
- /**
92
- * Install and activate
93
- *
94
- * @since 1.3.2
95
- *
96
- * @param {object} event Current event.
97
- * @return void
98
- */
99
- _install_and_activate: function(event ) {
100
- event.preventDefault();
101
- var theme_slug = $(this).data('theme-slug') || '';
102
- var btn = $( event.target );
103
-
104
- if ( btn.hasClass( 'processing' ) ) {
105
- return;
106
- }
107
-
108
- btn.text( AstraSitesInstallThemeVars.installing ).addClass('processing');
109
-
110
- if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
111
- wp.updates.requestFilesystemCredentials( event );
112
- }
113
-
114
- wp.updates.installTheme( {
115
- slug: theme_slug
116
- });
117
- }
118
-
119
- };
120
-
121
- /**
122
- * Initialize
123
- */
124
- $(function(){
125
- AstraSitesInstallTheme.init();
126
- });
127
-
128
  })(jQuery);
1
+ (function($){
2
+
3
+ AstraSitesInstallTheme = {
4
+
5
+ /**
6
+ * Init
7
+ */
8
+ init: function() {
9
+ this._auto_close_notice();
10
+ this._bind();
11
+ },
12
+
13
+ /**
14
+ * Binds events for the Astra Sites.
15
+ *
16
+ * @since 1.3.2
17
+ *
18
+ * @access private
19
+ * @method _bind
20
+ */
21
+ _bind: function()
22
+ {
23
+ $( document ).on( 'click', '.astra-sites-theme-not-installed', AstraSitesInstallTheme._install_and_activate );
24
+ $( document ).on( 'click', '.astra-sites-theme-installed-but-inactive', AstraSitesInstallTheme._activateTheme );
25
+ $( document ).on('wp-theme-install-success' , AstraSitesInstallTheme._activateTheme);
26
+ },
27
+
28
+ /**
29
+ * Close Getting Started Notice
30
+ *
31
+ * @param {object} event
32
+ * @return void
33
+ */
34
+ _auto_close_notice: function() {
35
+
36
+ if( $( '.astra-sites-getting-started-btn' ).length ) {
37
+ $.ajax({
38
+ url: AstraSitesInstallThemeVars.ajaxurl,
39
+ type: 'POST',
40
+ data: {
41
+ 'action' : 'astra-sites-getting-started-notice'
42
+ },
43
+ })
44
+ .done(function (result) {
45
+ });
46
+ }
47
+
48
+ },
49
+
50
+ /**
51
+ * Activate Theme
52
+ *
53
+ * @since 1.3.2
54
+ */
55
+ _activateTheme: function( event, response ) {
56
+ event.preventDefault();
57
+
58
+ $('#astra-theme-activation-nag a').addClass('processing');
59
+
60
+ if( response ) {
61
+ $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.installed );
62
+ } else {
63
+ $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.activating );
64
+ }
65
+
66
+ // WordPress adds "Activate" button after waiting for 1000ms. So we will run our activation after that.
67
+ setTimeout( function() {
68
+
69
+ $.ajax({
70
+ url: AstraSitesInstallThemeVars.ajaxurl,
71
+ type: 'POST',
72
+ data: {
73
+ 'action' : 'astra-sites-activate-theme'
74
+ },
75
+ })
76
+ .done(function (result) {
77
+ if( result.success ) {
78
+ $('#astra-theme-activation-nag a').text( AstraSitesInstallThemeVars.activated );
79
+
80
+ setTimeout(function() {
81
+ location.reload();
82
+ }, 1000);
83
+ }
84
+
85
+ });
86
+
87
+ }, 3000 );
88
+
89
+ },
90
+
91
+ /**
92
+ * Install and activate
93
+ *
94
+ * @since 1.3.2
95
+ *
96
+ * @param {object} event Current event.
97
+ * @return void
98
+ */
99
+ _install_and_activate: function(event ) {
100
+ event.preventDefault();
101
+ var theme_slug = $(this).data('theme-slug') || '';
102
+ var btn = $( event.target );
103
+
104
+ if ( btn.hasClass( 'processing' ) ) {
105
+ return;
106
+ }
107
+
108
+ btn.text( AstraSitesInstallThemeVars.installing ).addClass('processing');
109
+
110
+ if ( wp.updates.shouldRequestFilesystemCredentials && ! wp.updates.ajaxLocked ) {
111
+ wp.updates.requestFilesystemCredentials( event );
112
+ }
113
+
114
+ wp.updates.installTheme( {
115
+ slug: theme_slug
116
+ });
117
+ }
118
+
119
+ };
120
+
121
+ /**
122
+ * Initialize
123
+ */
124
+ $(function(){
125
+ AstraSitesInstallTheme.init();
126
+ });
127
+
128
  })(jQuery);
inc/assets/js/render-grid.js CHANGED
@@ -1,706 +1,706 @@
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
- _first_time_loaded : true,
22
-
23
- init: function()
24
- {
25
- this._resetPagedCount();
26
- this._bind();
27
- this._loadPageBuilders();
28
- },
29
-
30
- /**
31
- * Binds events for the Astra Sites.
32
- *
33
- * @since 1.0.0
34
- * @access private
35
- * @method _bind
36
- */
37
- _bind: function()
38
- {
39
- $( document ).on('astra-sites-api-request-error' , AstraRender._addSuggestionBox );
40
- $( document ).on('astra-sites-api-request-fail' , AstraRender._addSuggestionBox );
41
- $( document ).on('astra-api-post-loaded-on-scroll' , AstraRender._reinitGridScrolled );
42
- $( document ).on('astra-api-post-loaded' , AstraRender._reinitGrid );
43
- $( document ).on('astra-api-page-builder-loaded' , AstraRender._addPageBuilders );
44
- $( document ).on('astra-api-category-loaded' , AstraRender._loadFirstGrid );
45
-
46
- // Event's for API request.
47
- $( document ).on('click' , '.filter-links a', AstraRender._filterClick );
48
- $( document ).on('keyup input' , '#wp-filter-search-input', AstraRender._search );
49
- $( document ).on('scroll' , AstraRender._scroll );
50
- $( document ).on('astra-sites-api-request-fail', AstraRender._site_unreachable );
51
- },
52
-
53
- /**
54
- * Website is Down
55
- *
56
- * @since 1.2.11
57
- * @return null
58
- */
59
- _site_unreachable: function( event, jqXHR, textStatus, args ) {
60
- event.preventDefault();
61
- if ( 'astra-site-page-builder' === args.id ) {
62
- $('#astra-sites-admin').html( wp.template('astra-site-down') )
63
- }
64
- },
65
-
66
- /**
67
- * On Filter Clicked
68
- *
69
- * Prepare Before API Request:
70
- * - Empty search input field to avoid search term on filter click.
71
- * - Remove Inline Height
72
- * - Added 'hide-me' class to hide the 'No more sites!' string.
73
- * - Added 'loading-content' for body.
74
- * - Show spinner.
75
- */
76
- _filterClick: function( event ) {
77
-
78
- event.preventDefault();
79
-
80
- if( $( this ).parents('.astra-site-category').length && ! $('body').hasClass('page-builder-selected') ) {
81
- return;
82
- }
83
-
84
- $(this).parents('.filter-links').find('a').removeClass('current');
85
- $(this).addClass('current');
86
-
87
- // Prepare Before Search.
88
- $('.no-more-demos').addClass('hide-me');
89
- $('.astra-sites-suggestions').remove();
90
-
91
- // Empty the search input only click on category filter not on page builder filter.
92
- if( $(this).parents('.filter-links').hasClass('astra-site-category') ) {
93
- $('#wp-filter-search-input').val('');
94
- }
95
- $('#astra-sites').hide().css('height', '');
96
-
97
- $('body').addClass('loading-content');
98
- $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
99
-
100
- // Show sites.
101
- AstraRender._showSites();
102
- },
103
-
104
- /**
105
- * Search Site.
106
- *
107
- * Prepare Before API Request:
108
- * - Remove Inline Height
109
- * - Added 'hide-me' class to hide the 'No more sites!' string.
110
- * - Added 'loading-content' for body.
111
- * - Show spinner.
112
- */
113
- _search: function() {
114
-
115
- if( ! $('body').hasClass('page-builder-selected') ) {
116
- return;
117
- }
118
-
119
- $this = jQuery('#wp-filter-search-input').val();
120
-
121
- // Prepare Before Search.
122
- $('#astra-sites').hide().css('height', '');
123
- $('.no-more-demos').addClass('hide-me');
124
- $('.astra-sites-suggestions').remove();
125
-
126
- $('body').addClass('loading-content');
127
- $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
128
-
129
- window.clearTimeout(AstraRender._ref);
130
- AstraRender._ref = window.setTimeout(function () {
131
- AstraRender._ref = null;
132
-
133
- AstraRender._resetPagedCount();
134
- jQuery('body').addClass('loading-content');
135
- jQuery('body').attr('data-astra-demo-search', $this);
136
-
137
- AstraRender._showSites();
138
-
139
- }, 500);
140
-
141
- },
142
-
143
- /**
144
- * On Scroll
145
- */
146
- _scroll: function(event) {
147
-
148
- if( ! $('body').hasClass('page-builder-selected') ) {
149
- return;
150
- }
151
-
152
- if( ! $('body').hasClass('listed-all-sites') ) {
153
-
154
- var scrollDistance = jQuery(window).scrollTop();
155
-
156
- var themesBottom = Math.abs(jQuery(window).height() - jQuery('#astra-sites').offset().top - jQuery('#astra-sites').height());
157
- themesBottom = themesBottom - 100;
158
-
159
- ajaxLoading = jQuery('body').data('scrolling');
160
-
161
- if (scrollDistance > themesBottom && ajaxLoading == false) {
162
- AstraRender._updatedPagedCount();
163
-
164
- if( ! $('#astra-sites .no-themes').length ) {
165
- $('#astra-sites-admin').find('.spinner').addClass('is-active');
166
- }
167
-
168
- jQuery('body').data('scrolling', true);
169
-
170
- /**
171
- * @see _reinitGridScrolled() which called in trigger 'astra-api-post-loaded-on-scroll'
172
- */
173
- AstraRender._showSites( false, 'astra-api-post-loaded-on-scroll' );
174
- }
175
- }
176
- },
177
-
178
- _apiAddParam_status: function() {
179
- if( astraRenderGrid.sites && astraRenderGrid.sites.status ) {
180
- AstraRender._api_params['status'] = astraRenderGrid.sites.status;
181
- }
182
- },
183
-
184
- // Add 'search'
185
- _apiAddParam_search: function() {
186
- var search_val = jQuery('#wp-filter-search-input').val() || '';
187
- if( '' !== search_val ) {
188
- AstraRender._api_params['search'] = search_val;
189
- }
190
- },
191
-
192
- _apiAddParam_per_page: function() {
193
- // Add 'per_page'
194
- var per_page_val = 30;
195
- if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
196
- per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
197
- }
198
- AstraRender._api_params['per_page'] = per_page_val;
199
- },
200
-
201
- _apiAddParam_astra_site_category: function() {
202
- // Add 'astra-site-category'
203
- var selected_category_id = jQuery('.filter-links.astra-site-category').find('.current').data('group') || '';
204
- if( '' !== selected_category_id && 'all' !== selected_category_id ) {
205
- AstraRender._api_params['astra-site-category'] = selected_category_id;
206
- } else if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
207
- if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
208
- AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include.join(',');
209
- } else {
210
- AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include;
211
- }
212
- }
213
- },
214
-
215
- _apiAddParam_astra_site_page_builder: function() {
216
- // Add 'astra-site-page-builder'
217
- var selected_page_builder_id = jQuery('.filter-links.astra-site-page-builder').find('.current').data('group') || '';
218
- if( '' !== selected_page_builder_id && 'all' !== selected_page_builder_id ) {
219
- AstraRender._api_params['astra-site-page-builder'] = selected_page_builder_id;
220
- } else if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
221
- if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
222
- AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include.join(',');
223
- } else {
224
- AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include;
225
- }
226
- }
227
- },
228
-
229
- _apiAddParam_page: function() {
230
- // Add 'page'
231
- var page_val = parseInt(jQuery('body').attr('data-astra-demo-paged')) || 1;
232
- AstraRender._api_params['page'] = page_val;
233
- },
234
-
235
- _apiAddParam_purchase_key: function() {
236
- if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
237
- AstraRender._api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
238
- }
239
- },
240
-
241
- _apiAddParam_site_url: function() {
242
- if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
243
- AstraRender._api_params['site_url'] = astraRenderGrid.sites.site_url;
244
- }
245
- },
246
-
247
- /**
248
- * Show Sites
249
- *
250
- * Params E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
251
- *
252
- * @param {Boolean} resetPagedCount Reset Paged Count.
253
- * @param {String} trigger Filtered Trigger.
254
- */
255
- _showSites: function( resetPagedCount, trigger ) {
256
-
257
- if( undefined === resetPagedCount ) {
258
- resetPagedCount = true
259
- }
260
-
261
- if( undefined === trigger ) {
262
- trigger = 'astra-api-post-loaded';
263
- }
264
-
265
- if( resetPagedCount ) {
266
- AstraRender._resetPagedCount();
267
- }
268
-
269
- // Add Params for API request.
270
- AstraRender._api_params = {};
271
-
272
- AstraRender._apiAddParam_status();
273
- AstraRender._apiAddParam_search();
274
- AstraRender._apiAddParam_per_page();
275
- AstraRender._apiAddParam_astra_site_category();
276
- AstraRender._apiAddParam_page();
277
- AstraRender._apiAddParam_astra_site_page_builder();
278
- AstraRender._apiAddParam_site_url();
279
- AstraRender._apiAddParam_purchase_key();
280
-
281
- // API Request.
282
- var api_post = {
283
- id: 'astra-sites',
284
- slug: 'astra-sites?' + decodeURIComponent( $.param( AstraRender._api_params ) ),
285
- trigger: trigger,
286
- };
287
-
288
- AstraSitesAPI._api_request( api_post );
289
-
290
- },
291
-
292
- /**
293
- * Get Category Params
294
- *
295
- * @since 1.2.4
296
- * @param {string} category_slug Category Slug.
297
- * @return {mixed} Add `include=<category-ids>` in API request.
298
- */
299
- _getPageBuilderParams: function()
300
- {
301
- var _params = {};
302
-
303
- if( astraRenderGrid.default_page_builder ) {
304
- _params['search'] = astraRenderGrid.default_page_builder;
305
- }
306
-
307
- if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
308
- _params['purchase_key'] = astraRenderGrid.sites.purchase_key;
309
- }
310
-
311
- if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
312
- _params['site_url'] = astraRenderGrid.sites.site_url;
313
- }
314
-
315
- if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
316
- if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
317
- _params['include'] = astraRenderGrid['page-builders'].include.join(',');
318
- } else {
319
- _params['include'] = astraRenderGrid['page-builders'].include;
320
- }
321
- }
322
-
323
- var decoded_params = decodeURIComponent( $.param( _params ) );
324
-
325
- if( decoded_params.length ) {
326
- return '/?' + decoded_params;
327
- }
328
-
329
- return '/';
330
- },
331
-
332
- /**
333
- * Get Category Params
334
- *
335
- * @param {string} category_slug Category Slug.
336
- * @return {mixed} Add `include=<category-ids>` in API request.
337
- */
338
- _getCategoryParams: function( category_slug ) {
339
-
340
- var _params = {};
341
-
342
- if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
343
- if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
344
- _params['include'] = astraRenderGrid['categories'].include.join(',');
345
- } else {
346
- _params['include'] = astraRenderGrid['categories'].include;
347
- }
348
- }
349
-
350
- var decoded_params = decodeURIComponent( $.param( _params ) );
351
-
352
- if( decoded_params.length ) {
353
- return '/?' + decoded_params;
354
- }
355
-
356
- return '/';
357
- },
358
-
359
- /**
360
- * Get All Select Status
361
- *
362
- * @param {string} category_slug Category Slug.
363
- * @return {boolean} Return true/false.
364
- */
365
- _getCategoryAllSelectStatus: function( category_slug ) {
366
-
367
- // Has category?
368
- if( category_slug in astraRenderGrid.settings ) {
369
-
370
- // Has `all` in stored list?
371
- if( $.inArray('all', astraRenderGrid.settings[ category_slug ]) === -1 ) {
372
- return false;
373
- }
374
- }
375
-
376
- return true;
377
- },
378
-
379
- /**
380
- * Show Filters
381
- */
382
- _loadPageBuilders: function() {
383
-
384
- // Is Welcome screen?
385
- // Then pre-send the API request to avoid the loader.
386
- if( $('.astra-sites-welcome').length ) {
387
-
388
- var plugins = $('.astra-sites-welcome').attr( 'data-plugins' ) || '';
389
- var plugins = plugins.split(",");
390
-
391
- // Also, Send page builder request with `/?search=` parameter. Because, We send the selected page builder request
392
- // Which does not cached due to extra parameter `/?search=`. For that we initially send all these requests.
393
- $.each(plugins, function( key, plugin) {
394
- var category_slug = 'astra-site-page-builder';
395
- var category = {
396
- slug : category_slug + '/?search=' + plugin,
397
- id : category_slug,
398
- class : category_slug,
399
- trigger : '',
400
- wrapper_class : 'filter-links',
401
- show_all : false,
402
- };
403
-
404
- // Pre-Send `sites` request for each active page builder to avoid the loader.
405
- AstraSitesAPI._api_request( category, function( data ) {
406
- if( data.items ) {
407
-
408
- var per_page_val = 30;
409
- if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
410
- per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
411
- }
412
-
413
- var api_params = {
414
- per_page : per_page_val,
415
- page : 1,
416
- };
417
- // Load `all` sites from each page builder.
418
- $.each(data.items, function(index, item) {
419
-
420
- if( item.id ) {
421
- api_params['astra-site-page-builder'] = item.id;
422
-
423
- // API Request.
424
- var api_post = {
425
- id: 'astra-sites',
426
- slug: 'astra-sites?' + decodeURIComponent( $.param( api_params ) ),
427
- };
428
-
429
- AstraSitesAPI._api_request( api_post );
430
- }
431
- });
432
- }
433
- });
434
-
435
- } );
436
-
437
- // Pre-Send `category` request to avoid the loader.
438
- var category_slug = 'astra-site-category';
439
- var category = {
440
- slug : category_slug + '/',
441
- id : category_slug,
442
- class : category_slug,
443
- trigger : '',
444
- wrapper_class : 'filter-links',
445
- show_all : false,
446
- };
447
- AstraSitesAPI._api_request( category );
448
-
449
- // Load `sites` from selected page builder.
450
- } else {
451
- var category_slug = 'astra-site-page-builder';
452
- var category = {
453
- slug : category_slug + AstraRender._getPageBuilderParams(),
454
- id : category_slug,
455
- class : category_slug,
456
- trigger : 'astra-api-page-builder-loaded',
457
- wrapper_class : 'filter-links',
458
- show_all : false,
459
- };
460
-
461
- AstraSitesAPI._api_request( category );
462
- }
463
- },
464
-
465
- /**
466
- * Load First Grid.
467
- *
468
- * This is triggered after all category loaded.
469
- *
470
- * @param {object} event Event Object.
471
- */
472
- _loadFirstGrid: function( event, data ) {
473
-
474
- event.preventDefault();
475
-
476
- if( $('#' + data.args.id).length ) {
477
- var template = wp.template('astra-site-filters');
478
- $('#' + data.args.id).html(template( data ));
479
-
480
- if( 'true' === $('body').attr( 'data-default-page-builder-selected' ) ) {
481
- $('#' + data.args.id).find('li:first a').addClass('current');
482
- AstraRender._showSites();
483
- } else {
484
- $('body').removeClass('loading-content');
485
- if( ! $('#astra-sites-admin .astra-site-select-page-builder').length ) {
486
- $('#astra-sites-admin').append( wp.template( 'astra-site-select-page-builder' ) );
487
- }
488
- }
489
- } else {
490
- AstraRender._showSites();
491
- }
492
-
493
- },
494
-
495
- /**
496
- * Append filters.
497
- *
498
- * @param {object} event Object.
499
- * @param {object} data API response data.
500
- */
501
- _addPageBuilders: function( event, data ) {
502
- event.preventDefault();
503
-
504
- if( $('#' + data.args.id).length ) {
505
- var template = wp.template('astra-site-filters');
506
- $('#' + data.args.id).html(template( data ));
507
-
508
- if( 1 === parseInt( data.items_count ) ) {
509
- $('body').attr( 'data-default-page-builder-selected', true );
510
- $('#' + data.args.id).find('li:first a').addClass('current');
511
- }
512
- }
513
-
514
- /**
515
- * Categories
516
- */
517
- var category_slug = 'astra-site-category';
518
- var category = {
519
- slug : category_slug + AstraRender._getCategoryParams( category_slug ),
520
- id : category_slug,
521
- class : category_slug,
522
- trigger : 'astra-api-category-loaded',
523
- wrapper_class : 'filter-links',
524
- show_all : AstraRender._getCategoryAllSelectStatus( category_slug ),
525
- };
526
-
527
- AstraSitesAPI._api_request( category );
528
-
529
- },
530
-
531
-
532
- /**
533
- * Append sites on scroll.
534
- *
535
- * @param {object} event Object.
536
- * @param {object} data API response data.
537
- */
538
- _reinitGridScrolled: function( event, data ) {
539
-
540
- var template = wp.template('astra-sites-list');
541
-
542
- if( data.items.length > 0 ) {
543
-
544
- $('body').removeClass( 'loading-content' );
545
- $('.filter-count .count').text( data.items_count );
546
-
547
- setTimeout(function() {
548
- jQuery('#astra-sites').append(template( data ));
549
-
550
- AstraRender._imagesLoaded();
551
- }, 800);
552
- } else {
553
- $('body').addClass('listed-all-sites');
554
- }
555
-
556
- },
557
-
558
- /**
559
- * Update Astra sites list.
560
- *
561
- * @param {object} event Object.
562
- * @param {object} data API response data.
563
- */
564
- _reinitGrid: function( event, data ) {
565
-
566
- var template = wp.template('astra-sites-list');
567
-
568
- $('body').addClass( 'page-builder-selected' );
569
- $('body').removeClass( 'loading-content' );
570
- $('.filter-count .count').text( data.items_count );
571
-
572
- jQuery('body').attr('data-astra-demo-last-request', data.items_count);
573
-
574
- jQuery('#astra-sites').show().html(template( data ));
575
-
576
- AstraRender._imagesLoaded();
577
-
578
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
579
-
580
- if( data.items_count <= 0 ) {
581
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
582
- $('.no-more-demos').addClass('hide-me');
583
- $('.astra-sites-suggestions').remove();
584
-
585
- } else {
586
- $('body').removeClass('listed-all-sites');
587
- }
588
-
589
- // Re-Send `categories` sites request to avoid the loader.
590
- var categories = AstraSitesAPI._stored_data['astra-site-category'];
591
- if( categories && AstraRender._first_time_loaded ) {
592
-
593
- var per_page_val = 30;
594
- if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
595
- per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
596
- }
597
-
598
- var api_params = {
599
- per_page : per_page_val,
600
- };
601
-
602
- var page_builder_id = $('#astra-site-page-builder').find('.current').data('group') || '';
603
-
604
- $.each( categories, function( index, category ) {
605
-
606
- api_params['astra-site-category'] = category.id;
607
-
608
- api_params['page'] = 1;
609
-
610
- if( page_builder_id ) {
611
- api_params['astra-site-page-builder'] = page_builder_id;
612
- }
613
-
614
- if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
615
- api_params['site_url'] = astraRenderGrid.sites.site_url;
616
- }
617
- if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
618
- api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
619
- }
620
-
621
- // API Request.
622
- var api_post = {
623
- id: 'astra-sites',
624
- slug: 'astra-sites?' + decodeURIComponent( $.param( api_params ) ),
625
- };
626
-
627
- AstraSitesAPI._api_request( api_post );
628
- } );
629
-
630
- AstraRender._first_time_loaded = false;
631
- }
632
-
633
- },
634
-
635
- /**
636
- * Check image loaded with function `imagesLoaded()`
637
- */
638
- _imagesLoaded: function() {
639
-
640
- var self = jQuery('#sites-filter.execute-only-one-time a');
641
-
642
- $('.astra-sites-grid').imagesLoaded()
643
- .always( function( instance ) {
644
- if( jQuery( window ).outerWidth() > AstraRender._breakpoint ) {
645
- // $('#astra-sites').masonry('reload');
646
- }
647
-
648
- $('#astra-sites-admin').find('.spinner').removeClass('is-active');
649
- })
650
- .progress( function( instance, image ) {
651
- var result = image.isLoaded ? 'loaded' : 'broken';
652
- });
653
-
654
- },
655
-
656
- /**
657
- * Add Suggestion Box
658
- */
659
- _addSuggestionBox: function() {
660
- $('#astra-sites-admin').find('.spinner').removeClass('is-active').addClass('hide-me');
661
-
662
- $('#astra-sites-admin').find('.no-more-demos').removeClass('hide-me');
663
- var template = wp.template('astra-sites-suggestions');
664
- if( ! $( '.astra-sites-suggestions').length ) {
665
- $('#astra-sites').append( template );
666
- }
667
- },
668
-
669
- /**
670
- * Update Page Count.
671
- */
672
- _updatedPagedCount: function() {
673
- paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
674
- jQuery('body').attr('data-astra-demo-paged', paged + 1);
675
- window.setTimeout(function () {
676
- jQuery('body').data('scrolling', false);
677
- }, 800);
678
- },
679
-
680
- /**
681
- * Reset Page Count.
682
- */
683
- _resetPagedCount: function() {
684
-
685
- jQuery('body').attr('data-astra-demo-last-request', '1');
686
- jQuery('body').attr('data-astra-demo-paged', '1');
687
- jQuery('body').attr('data-astra-demo-search', '');
688
- jQuery('body').attr('data-scrolling', false);
689
-
690
- },
691
-
692
- // Returns if a value is an array
693
- _isArray: function(value) {
694
- return value && typeof value === 'object' && value.constructor === Array;
695
- }
696
-
697
- };
698
-
699
- /**
700
- * Initialize AstraRender
701
- */
702
- $(function(){
703
- AstraRender.init();
704
- });
705
-
706
  })(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
+ _first_time_loaded : true,
22
+
23
+ init: function()
24
+ {
25
+ this._resetPagedCount();
26
+ this._bind();
27
+ this._loadPageBuilders();
28
+ },
29
+
30
+ /**
31
+ * Binds events for the Astra Sites.
32
+ *
33
+ * @since 1.0.0
34
+ * @access private
35
+ * @method _bind
36
+ */
37
+ _bind: function()
38
+ {
39
+ $( document ).on('astra-sites-api-request-error' , AstraRender._addSuggestionBox );
40
+ $( document ).on('astra-sites-api-request-fail' , AstraRender._addSuggestionBox );
41
+ $( document ).on('astra-api-post-loaded-on-scroll' , AstraRender._reinitGridScrolled );
42
+ $( document ).on('astra-api-post-loaded' , AstraRender._reinitGrid );
43
+ $( document ).on('astra-api-page-builder-loaded' , AstraRender._addPageBuilders );
44
+ $( document ).on('astra-api-category-loaded' , AstraRender._loadFirstGrid );
45
+
46
+ // Event's for API request.
47
+ $( document ).on('click' , '.filter-links a', AstraRender._filterClick );
48
+ $( document ).on('keyup input' , '#wp-filter-search-input', AstraRender._search );
49
+ $( document ).on('scroll' , AstraRender._scroll );
50
+ $( document ).on('astra-sites-api-request-fail', AstraRender._site_unreachable );
51
+ },
52
+
53
+ /**
54
+ * Website is Down
55
+ *
56
+ * @since 1.2.11
57
+ * @return null
58
+ */
59
+ _site_unreachable: function( event, jqXHR, textStatus, args ) {
60
+ event.preventDefault();
61
+ if ( 'astra-site-page-builder' === args.id ) {
62
+ $('#astra-sites-admin').html( wp.template('astra-site-down') )
63
+ }
64
+ },
65
+
66
+ /**
67
+ * On Filter Clicked
68
+ *
69
+ * Prepare Before API Request:
70
+ * - Empty search input field to avoid search term on filter click.
71
+ * - Remove Inline Height
72
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
73
+ * - Added 'loading-content' for body.
74
+ * - Show spinner.
75
+ */
76
+ _filterClick: function( event ) {
77
+
78
+ event.preventDefault();
79
+
80
+ if( $( this ).parents('.astra-site-category').length && ! $('body').hasClass('page-builder-selected') ) {
81
+ return;
82
+ }
83
+
84
+ $(this).parents('.filter-links').find('a').removeClass('current');
85
+ $(this).addClass('current');
86
+
87
+ // Prepare Before Search.
88
+ $('.no-more-demos').addClass('hide-me');
89
+ $('.astra-sites-suggestions').remove();
90
+
91
+ // Empty the search input only click on category filter not on page builder filter.
92
+ if( $(this).parents('.filter-links').hasClass('astra-site-category') ) {
93
+ $('#wp-filter-search-input').val('');
94
+ }
95
+ $('#astra-sites').hide().css('height', '');
96
+
97
+ $('body').addClass('loading-content');
98
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
99
+
100
+ // Show sites.
101
+ AstraRender._showSites();
102
+ },
103
+
104
+ /**
105
+ * Search Site.
106
+ *
107
+ * Prepare Before API Request:
108
+ * - Remove Inline Height
109
+ * - Added 'hide-me' class to hide the 'No more sites!' string.
110
+ * - Added 'loading-content' for body.
111
+ * - Show spinner.
112
+ */
113
+ _search: function() {
114
+
115
+ if( ! $('body').hasClass('page-builder-selected') ) {
116
+ return;
117
+ }
118
+
119
+ $this = jQuery('#wp-filter-search-input').val();
120
+
121
+ // Prepare Before Search.
122
+ $('#astra-sites').hide().css('height', '');
123
+ $('.no-more-demos').addClass('hide-me');
124
+ $('.astra-sites-suggestions').remove();
125
+
126
+ $('body').addClass('loading-content');
127
+ $('#astra-sites-admin').find('.spinner').removeClass('hide-me');
128
+
129
+ window.clearTimeout(AstraRender._ref);
130
+ AstraRender._ref = window.setTimeout(function () {
131
+ AstraRender._ref = null;
132
+
133
+ AstraRender._resetPagedCount();
134
+ jQuery('body').addClass('loading-content');
135
+ jQuery('body').attr('data-astra-demo-search', $this);
136
+
137
+ AstraRender._showSites();
138
+
139
+ }, 500);
140
+
141
+ },
142
+
143
+ /**
144
+ * On Scroll
145
+ */
146
+ _scroll: function(event) {
147
+
148
+ if( ! $('body').hasClass('page-builder-selected') ) {
149
+ return;
150
+ }
151
+
152
+ if( ! $('body').hasClass('listed-all-sites') ) {
153
+
154
+ var scrollDistance = jQuery(window).scrollTop();
155
+
156
+ var themesBottom = Math.abs(jQuery(window).height() - jQuery('#astra-sites').offset().top - jQuery('#astra-sites').height());
157
+ themesBottom = themesBottom - 100;
158
+
159
+ ajaxLoading = jQuery('body').data('scrolling');
160
+
161
+ if (scrollDistance > themesBottom && ajaxLoading == false) {
162
+ AstraRender._updatedPagedCount();
163
+
164
+ if( ! $('#astra-sites .no-themes').length ) {
165
+ $('#astra-sites-admin').find('.spinner').addClass('is-active');
166
+ }
167
+
168
+ jQuery('body').data('scrolling', true);
169
+
170
+ /**
171
+ * @see _reinitGridScrolled() which called in trigger 'astra-api-post-loaded-on-scroll'
172
+ */
173
+ AstraRender._showSites( false, 'astra-api-post-loaded-on-scroll' );
174
+ }
175
+ }
176
+ },
177
+
178
+ _apiAddParam_status: function() {
179
+ if( astraRenderGrid.sites && astraRenderGrid.sites.status ) {
180
+ AstraRender._api_params['status'] = astraRenderGrid.sites.status;
181
+ }
182
+ },
183
+
184
+ // Add 'search'
185
+ _apiAddParam_search: function() {
186
+ var search_val = jQuery('#wp-filter-search-input').val() || '';
187
+ if( '' !== search_val ) {
188
+ AstraRender._api_params['search'] = search_val;
189
+ }
190
+ },
191
+
192
+ _apiAddParam_per_page: function() {
193
+ // Add 'per_page'
194
+ var per_page_val = 30;
195
+ if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
196
+ per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
197
+ }
198
+ AstraRender._api_params['per_page'] = per_page_val;
199
+ },
200
+
201
+ _apiAddParam_astra_site_category: function() {
202
+ // Add 'astra-site-category'
203
+ var selected_category_id = jQuery('.filter-links.astra-site-category').find('.current').data('group') || '';
204
+ if( '' !== selected_category_id && 'all' !== selected_category_id ) {
205
+ AstraRender._api_params['astra-site-category'] = selected_category_id;
206
+ } else if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
207
+ if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
208
+ AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include.join(',');
209
+ } else {
210
+ AstraRender._api_params['astra-site-category'] = astraRenderGrid['categories'].include;
211
+ }
212
+ }
213
+ },
214
+
215
+ _apiAddParam_astra_site_page_builder: function() {
216
+ // Add 'astra-site-page-builder'
217
+ var selected_page_builder_id = jQuery('.filter-links.astra-site-page-builder').find('.current').data('group') || '';
218
+ if( '' !== selected_page_builder_id && 'all' !== selected_page_builder_id ) {
219
+ AstraRender._api_params['astra-site-page-builder'] = selected_page_builder_id;
220
+ } else if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
221
+ if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
222
+ AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include.join(',');
223
+ } else {
224
+ AstraRender._api_params['astra-site-page-builder'] = astraRenderGrid['page-builders'].include;
225
+ }
226
+ }
227
+ },
228
+
229
+ _apiAddParam_page: function() {
230
+ // Add 'page'
231
+ var page_val = parseInt(jQuery('body').attr('data-astra-demo-paged')) || 1;
232
+ AstraRender._api_params['page'] = page_val;
233
+ },
234
+
235
+ _apiAddParam_purchase_key: function() {
236
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
237
+ AstraRender._api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
238
+ }
239
+ },
240
+
241
+ _apiAddParam_site_url: function() {
242
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
243
+ AstraRender._api_params['site_url'] = astraRenderGrid.sites.site_url;
244
+ }
245
+ },
246
+
247
+ /**
248
+ * Show Sites
249
+ *
250
+ * Params E.g. per_page=<page-id>&astra-site-category=<category-ids>&astra-site-page-builder=<page-builder-ids>&page=<page>
251
+ *
252
+ * @param {Boolean} resetPagedCount Reset Paged Count.
253
+ * @param {String} trigger Filtered Trigger.
254
+ */
255
+ _showSites: function( resetPagedCount, trigger ) {
256
+
257
+ if( undefined === resetPagedCount ) {
258
+ resetPagedCount = true
259
+ }
260
+
261
+ if( undefined === trigger ) {
262
+ trigger = 'astra-api-post-loaded';
263
+ }
264
+
265
+ if( resetPagedCount ) {
266
+ AstraRender._resetPagedCount();
267
+ }
268
+
269
+ // Add Params for API request.
270
+ AstraRender._api_params = {};
271
+
272
+ AstraRender._apiAddParam_status();
273
+ AstraRender._apiAddParam_search();
274
+ AstraRender._apiAddParam_per_page();
275
+ AstraRender._apiAddParam_astra_site_category();
276
+ AstraRender._apiAddParam_page();
277
+ AstraRender._apiAddParam_astra_site_page_builder();
278
+ AstraRender._apiAddParam_site_url();
279
+ AstraRender._apiAddParam_purchase_key();
280
+
281
+ // API Request.
282
+ var api_post = {
283
+ id: 'astra-sites',
284
+ slug: 'astra-sites?' + decodeURIComponent( $.param( AstraRender._api_params ) ),
285
+ trigger: trigger,
286
+ };
287
+
288
+ AstraSitesAPI._api_request( api_post );
289
+
290
+ },
291
+
292
+ /**
293
+ * Get Category Params
294
+ *
295
+ * @since 1.2.4
296
+ * @param {string} category_slug Category Slug.
297
+ * @return {mixed} Add `include=<category-ids>` in API request.
298
+ */
299
+ _getPageBuilderParams: function()
300
+ {
301
+ var _params = {};
302
+
303
+ if( astraRenderGrid.default_page_builder ) {
304
+ _params['search'] = astraRenderGrid.default_page_builder;
305
+ }
306
+
307
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
308
+ _params['purchase_key'] = astraRenderGrid.sites.purchase_key;
309
+ }
310
+
311
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
312
+ _params['site_url'] = astraRenderGrid.sites.site_url;
313
+ }
314
+
315
+ if( astraRenderGrid.sites && astraRenderGrid['page-builders'].include ) {
316
+ if( AstraRender._isArray( astraRenderGrid['page-builders'].include ) ) {
317
+ _params['include'] = astraRenderGrid['page-builders'].include.join(',');
318
+ } else {
319
+ _params['include'] = astraRenderGrid['page-builders'].include;
320
+ }
321
+ }
322
+
323
+ var decoded_params = decodeURIComponent( $.param( _params ) );
324
+
325
+ if( decoded_params.length ) {
326
+ return '/?' + decoded_params;
327
+ }
328
+
329
+ return '/';
330
+ },
331
+
332
+ /**
333
+ * Get Category Params
334
+ *
335
+ * @param {string} category_slug Category Slug.
336
+ * @return {mixed} Add `include=<category-ids>` in API request.
337
+ */
338
+ _getCategoryParams: function( category_slug ) {
339
+
340
+ var _params = {};
341
+
342
+ if( astraRenderGrid.sites && astraRenderGrid['categories'].include ) {
343
+ if( AstraRender._isArray( astraRenderGrid['categories'].include ) ) {
344
+ _params['include'] = astraRenderGrid['categories'].include.join(',');
345
+ } else {
346
+ _params['include'] = astraRenderGrid['categories'].include;
347
+ }
348
+ }
349
+
350
+ var decoded_params = decodeURIComponent( $.param( _params ) );
351
+
352
+ if( decoded_params.length ) {
353
+ return '/?' + decoded_params;
354
+ }
355
+
356
+ return '/';
357
+ },
358
+
359
+ /**
360
+ * Get All Select Status
361
+ *
362
+ * @param {string} category_slug Category Slug.
363
+ * @return {boolean} Return true/false.
364
+ */
365
+ _getCategoryAllSelectStatus: function( category_slug ) {
366
+
367
+ // Has category?
368
+ if( category_slug in astraRenderGrid.settings ) {
369
+
370
+ // Has `all` in stored list?
371
+ if( $.inArray('all', astraRenderGrid.settings[ category_slug ]) === -1 ) {
372
+ return false;
373
+ }
374
+ }
375
+
376
+ return true;
377
+ },
378
+
379
+ /**
380
+ * Show Filters
381
+ */
382
+ _loadPageBuilders: function() {
383
+
384
+ // Is Welcome screen?
385
+ // Then pre-send the API request to avoid the loader.
386
+ if( $('.astra-sites-welcome').length ) {
387
+
388
+ var plugins = $('.astra-sites-welcome').attr( 'data-plugins' ) || '';
389
+ var plugins = plugins.split(",");
390
+
391
+ // Also, Send page builder request with `/?search=` parameter. Because, We send the selected page builder request
392
+ // Which does not cached due to extra parameter `/?search=`. For that we initially send all these requests.
393
+ $.each(plugins, function( key, plugin) {
394
+ var category_slug = 'astra-site-page-builder';
395
+ var category = {
396
+ slug : category_slug + '/?search=' + plugin,
397
+ id : category_slug,
398
+ class : category_slug,
399
+ trigger : '',
400
+ wrapper_class : 'filter-links',
401
+ show_all : false,
402
+ };
403
+
404
+ // Pre-Send `sites` request for each active page builder to avoid the loader.
405
+ AstraSitesAPI._api_request( category, function( data ) {
406
+ if( data.items ) {
407
+
408
+ var per_page_val = 30;
409
+ if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
410
+ per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
411
+ }
412
+
413
+ var api_params = {
414
+ per_page : per_page_val,
415
+ page : 1,
416
+ };
417
+ // Load `all` sites from each page builder.
418
+ $.each(data.items, function(index, item) {
419
+
420
+ if( item.id ) {
421
+ api_params['astra-site-page-builder'] = item.id;
422
+
423
+ // API Request.
424
+ var api_post = {
425
+ id: 'astra-sites',
426
+ slug: 'astra-sites?' + decodeURIComponent( $.param( api_params ) ),
427
+ };
428
+
429
+ AstraSitesAPI._api_request( api_post );
430
+ }
431
+ });
432
+ }
433
+ });
434
+
435
+ } );
436
+
437
+ // Pre-Send `category` request to avoid the loader.
438
+ var category_slug = 'astra-site-category';
439
+ var category = {
440
+ slug : category_slug + '/',
441
+ id : category_slug,
442
+ class : category_slug,
443
+ trigger : '',
444
+ wrapper_class : 'filter-links',
445
+ show_all : false,
446
+ };
447
+ AstraSitesAPI._api_request( category );
448
+
449
+ // Load `sites` from selected page builder.
450
+ } else {
451
+ var category_slug = 'astra-site-page-builder';
452
+ var category = {
453
+ slug : category_slug + AstraRender._getPageBuilderParams(),
454
+ id : category_slug,
455
+ class : category_slug,
456
+ trigger : 'astra-api-page-builder-loaded',
457
+ wrapper_class : 'filter-links',
458
+ show_all : false,
459
+ };
460
+
461
+ AstraSitesAPI._api_request( category );
462
+ }
463
+ },
464
+
465
+ /**
466
+ * Load First Grid.
467
+ *
468
+ * This is triggered after all category loaded.
469
+ *
470
+ * @param {object} event Event Object.
471
+ */
472
+ _loadFirstGrid: function( event, data ) {
473
+
474
+ event.preventDefault();
475
+
476
+ if( $('#' + data.args.id).length ) {
477
+ var template = wp.template('astra-site-filters');
478
+ $('#' + data.args.id).html(template( data ));
479
+
480
+ if( 'true' === $('body').attr( 'data-default-page-builder-selected' ) ) {
481
+ $('#' + data.args.id).find('li:first a').addClass('current');
482
+ AstraRender._showSites();
483
+ } else {
484
+ $('body').removeClass('loading-content');
485
+ if( ! $('#astra-sites-admin .astra-site-select-page-builder').length ) {
486
+ $('#astra-sites-admin').append( wp.template( 'astra-site-select-page-builder' ) );
487
+ }
488
+ }
489
+ } else {
490
+ AstraRender._showSites();
491
+ }
492
+
493
+ },
494
+
495
+ /**
496
+ * Append filters.
497
+ *
498
+ * @param {object} event Object.
499
+ * @param {object} data API response data.
500
+ */
501
+ _addPageBuilders: function( event, data ) {
502
+ event.preventDefault();
503
+
504
+ if( $('#' + data.args.id).length ) {
505
+ var template = wp.template('astra-site-filters');
506
+ $('#' + data.args.id).html(template( data ));
507
+
508
+ if( 1 === parseInt( data.items_count ) ) {
509
+ $('body').attr( 'data-default-page-builder-selected', true );
510
+ $('#' + data.args.id).find('li:first a').addClass('current');
511
+ }
512
+ }
513
+
514
+ /**
515
+ * Categories
516
+ */
517
+ var category_slug = 'astra-site-category';
518
+ var category = {
519
+ slug : category_slug + AstraRender._getCategoryParams( category_slug ),
520
+ id : category_slug,
521
+ class : category_slug,
522
+ trigger : 'astra-api-category-loaded',
523
+ wrapper_class : 'filter-links',
524
+ show_all : AstraRender._getCategoryAllSelectStatus( category_slug ),
525
+ };
526
+
527
+ AstraSitesAPI._api_request( category );
528
+
529
+ },
530
+
531
+
532
+ /**
533
+ * Append sites on scroll.
534
+ *
535
+ * @param {object} event Object.
536
+ * @param {object} data API response data.
537
+ */
538
+ _reinitGridScrolled: function( event, data ) {
539
+
540
+ var template = wp.template('astra-sites-list');
541
+
542
+ if( data.items.length > 0 ) {
543
+
544
+ $('body').removeClass( 'loading-content' );
545
+ $('.filter-count .count').text( data.items_count );
546
+
547
+ setTimeout(function() {
548
+ jQuery('#astra-sites').append(template( data ));
549
+
550
+ AstraRender._imagesLoaded();
551
+ }, 800);
552
+ } else {
553
+ $('body').addClass('listed-all-sites');
554
+ }
555
+
556
+ },
557
+
558
+ /**
559
+ * Update Astra sites list.
560
+ *
561
+ * @param {object} event Object.
562
+ * @param {object} data API response data.
563
+ */
564
+ _reinitGrid: function( event, data ) {
565
+
566
+ var template = wp.template('astra-sites-list');
567
+
568
+ $('body').addClass( 'page-builder-selected' );
569
+ $('body').removeClass( 'loading-content' );
570
+ $('.filter-count .count').text( data.items_count );
571
+
572
+ jQuery('body').attr('data-astra-demo-last-request', data.items_count);
573
+
574
+ jQuery('#astra-sites').show().html(template( data ));
575
+
576
+ AstraRender._imagesLoaded();
577
+
578
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
579
+
580
+ if( data.items_count <= 0 ) {
581
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
582
+ $('.no-more-demos').addClass('hide-me');
583
+ $('.astra-sites-suggestions').remove();
584
+
585
+ } else {
586
+ $('body').removeClass('listed-all-sites');
587
+ }
588
+
589
+ // Re-Send `categories` sites request to avoid the loader.
590
+ var categories = AstraSitesAPI._stored_data['astra-site-category'];
591
+ if( categories && AstraRender._first_time_loaded ) {
592
+
593
+ var per_page_val = 30;
594
+ if( astraRenderGrid.sites && astraRenderGrid.sites["par-page"] ) {
595
+ per_page_val = parseInt( astraRenderGrid.sites["par-page"] );
596
+ }
597
+
598
+ var api_params = {
599
+ per_page : per_page_val,
600
+ };
601
+
602
+ var page_builder_id = $('#astra-site-page-builder').find('.current').data('group') || '';
603
+
604
+ $.each( categories, function( index, category ) {
605
+
606
+ api_params['astra-site-category'] = category.id;
607
+
608
+ api_params['page'] = 1;
609
+
610
+ if( page_builder_id ) {
611
+ api_params['astra-site-page-builder'] = page_builder_id;
612
+ }
613
+
614
+ if( astraRenderGrid.sites && astraRenderGrid.sites.site_url ) {
615
+ api_params['site_url'] = astraRenderGrid.sites.site_url;
616
+ }
617
+ if( astraRenderGrid.sites && astraRenderGrid.sites.purchase_key ) {
618
+ api_params['purchase_key'] = astraRenderGrid.sites.purchase_key;
619
+ }
620
+
621
+ // API Request.
622
+ var api_post = {
623
+ id: 'astra-sites',
624
+ slug: 'astra-sites?' + decodeURIComponent( $.param( api_params ) ),
625
+ };
626
+
627
+ AstraSitesAPI._api_request( api_post );
628
+ } );
629
+
630
+ AstraRender._first_time_loaded = false;
631
+ }
632
+
633
+ },
634
+
635
+ /**
636
+ * Check image loaded with function `imagesLoaded()`
637
+ */
638
+ _imagesLoaded: function() {
639
+
640
+ var self = jQuery('#sites-filter.execute-only-one-time a');
641
+
642
+ $('.astra-sites-grid').imagesLoaded()
643
+ .always( function( instance ) {
644
+ if( jQuery( window ).outerWidth() > AstraRender._breakpoint ) {
645
+ // $('#astra-sites').masonry('reload');
646
+ }
647
+
648
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active');
649
+ })
650
+ .progress( function( instance, image ) {
651
+ var result = image.isLoaded ? 'loaded' : 'broken';
652
+ });
653
+
654
+ },
655
+
656
+ /**
657
+ * Add Suggestion Box
658
+ */
659
+ _addSuggestionBox: function() {
660
+ $('#astra-sites-admin').find('.spinner').removeClass('is-active').addClass('hide-me');
661
+
662
+ $('#astra-sites-admin').find('.no-more-demos').removeClass('hide-me');
663
+ var template = wp.template('astra-sites-suggestions');
664
+ if( ! $( '.astra-sites-suggestions').length ) {
665
+ $('#astra-sites').append( template );
666
+ }
667
+ },
668
+
669
+ /**
670
+ * Update Page Count.
671
+ */
672
+ _updatedPagedCount: function() {
673
+ paged = parseInt(jQuery('body').attr('data-astra-demo-paged'));
674
+ jQuery('body').attr('data-astra-demo-paged', paged + 1);
675
+ window.setTimeout(function () {
676
+ jQuery('body').data('scrolling', false);
677
+ }, 800);
678
+ },
679
+
680
+ /**
681
+ * Reset Page Count.
682
+ */
683
+ _resetPagedCount: function() {
684
+
685
+ jQuery('body').attr('data-astra-demo-last-request', '1');
686
+ jQuery('body').attr('data-astra-demo-paged', '1');
687
+ jQuery('body').attr('data-astra-demo-search', '');
688
+ jQuery('body').attr('data-scrolling', false);
689
+
690
+ },
691
+
692
+ // Returns if a value is an array
693
+ _isArray: function(value) {
694
+ return value && typeof value === 'object' && value.constructor === Array;
695
+ }
696
+
697
+ };
698
+
699
+ /**
700
+ * Initialize AstraRender
701
+ */
702
+ $(function(){
703
+ AstraRender.init();
704
+ });
705
+
706
  })(jQuery);
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.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-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-logger.php CHANGED
@@ -1,139 +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
- $this->messages[] = array(
132
- 'timestamp' => time(),
133
- 'level' => $level,
134
- 'message' => $message,
135
- 'context' => $context,
136
- );
137
- }
138
- }
139
- 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,43 +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
- $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
- }
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/lib/astra-notices/notices.js CHANGED
@@ -1,94 +1,94 @@
1
- /**
2
- * Customizer controls toggles
3
- *
4
- * @package Astra
5
- */
6
-
7
- ( function( $ ) {
8
-
9
- /**
10
- * Helper class for the main Customizer interface.
11
- *
12
- * @since 1.0.0
13
- * @class ASTCustomizer
14
- */
15
- AstraNotices = {
16
-
17
- /**
18
- * Initializes our custom logic for the Customizer.
19
- *
20
- * @since 1.0.0
21
- * @method init
22
- */
23
- init: function()
24
- {
25
- this._bind();
26
- },
27
-
28
- /**
29
- * Binds events for the Astra Portfolio.
30
- *
31
- * @since 1.0.0
32
- * @access private
33
- * @method _bind
34
- */
35
- _bind: function()
36
- {
37
- $( document ).on('click', '.astra-notice-close', AstraNotices._dismissNoticeNew );
38
- $( document ).on('click', '.astra-notice .notice-dismiss', AstraNotices._dismissNotice );
39
- },
40
-
41
- _dismissNotice: function( event ) {
42
- event.preventDefault();
43
-
44
- var repeat_notice_after = $( this ).parents('.astra-notice').data( 'repeat-notice-after' ) || '';
45
- var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
46
-
47
- AstraNotices._ajax( notice_id, repeat_notice_after );
48
- },
49
-
50
- _dismissNoticeNew: function( event ) {
51
- event.preventDefault();
52
-
53
- var repeat_notice_after = $( this ).attr( 'data-repeat-notice-after' ) || '';
54
- var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
55
-
56
- var $el = $( this ).parents('.astra-notice');
57
- $el.fadeTo( 100, 0, function() {
58
- $el.slideUp( 100, function() {
59
- $el.remove();
60
- });
61
- });
62
-
63
- AstraNotices._ajax( notice_id, repeat_notice_after );
64
-
65
- var link = $( this ).attr( 'href' ) || '';
66
- var target = $( this ).attr( 'target' ) || '';
67
- if( '' !== link && '_blank' === target ) {
68
- window.open(link , '_blank');
69
- }
70
- },
71
-
72
- _ajax: function( notice_id, repeat_notice_after ) {
73
-
74
- if( '' === notice_id ) {
75
- return;
76
- }
77
-
78
- $.ajax({
79
- url: ajaxurl,
80
- type: 'POST',
81
- data: {
82
- action : 'astra-notice-dismiss',
83
- notice_id : notice_id,
84
- repeat_notice_after : parseInt( repeat_notice_after ),
85
- },
86
- });
87
-
88
- }
89
- };
90
-
91
- $( function() {
92
- AstraNotices.init();
93
- } );
94
  } )( jQuery );
1
+ /**
2
+ * Customizer controls toggles
3
+ *
4
+ * @package Astra
5
+ */
6
+
7
+ ( function( $ ) {
8
+
9
+ /**
10
+ * Helper class for the main Customizer interface.
11
+ *
12
+ * @since 1.0.0
13
+ * @class ASTCustomizer
14
+ */
15
+ AstraNotices = {
16
+
17
+ /**
18
+ * Initializes our custom logic for the Customizer.
19
+ *
20
+ * @since 1.0.0
21
+ * @method init
22
+ */
23
+ init: function()
24
+ {
25
+ this._bind();
26
+ },
27
+
28
+ /**
29
+ * Binds events for the Astra Portfolio.
30
+ *
31
+ * @since 1.0.0
32
+ * @access private
33
+ * @method _bind
34
+ */
35
+ _bind: function()
36
+ {
37
+ $( document ).on('click', '.astra-notice-close', AstraNotices._dismissNoticeNew );
38
+ $( document ).on('click', '.astra-notice .notice-dismiss', AstraNotices._dismissNotice );
39
+ },
40
+
41
+ _dismissNotice: function( event ) {
42
+ event.preventDefault();
43
+
44
+ var repeat_notice_after = $( this ).parents('.astra-notice').data( 'repeat-notice-after' ) || '';
45
+ var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
46
+
47
+ AstraNotices._ajax( notice_id, repeat_notice_after );
48
+ },
49
+
50
+ _dismissNoticeNew: function( event ) {
51
+ event.preventDefault();
52
+
53
+ var repeat_notice_after = $( this ).attr( 'data-repeat-notice-after' ) || '';
54
+ var notice_id = $( this ).parents('.astra-notice').attr( 'id' ) || '';
55
+
56
+ var $el = $( this ).parents('.astra-notice');
57
+ $el.fadeTo( 100, 0, function() {
58
+ $el.slideUp( 100, function() {
59
+ $el.remove();
60
+ });
61
+ });
62
+
63
+ AstraNotices._ajax( notice_id, repeat_notice_after );
64
+
65
+ var link = $( this ).attr( 'href' ) || '';
66
+ var target = $( this ).attr( 'target' ) || '';
67
+ if( '' !== link && '_blank' === target ) {
68
+ window.open(link , '_blank');
69
+ }
70
+ },
71
+
72
+ _ajax: function( notice_id, repeat_notice_after ) {
73
+
74
+ if( '' === notice_id ) {
75
+ return;
76
+ }
77
+
78
+ $.ajax({
79
+ url: ajaxurl,
80
+ type: 'POST',
81
+ data: {
82
+ action : 'astra-notice-dismiss',
83
+ notice_id : notice_id,
84
+ repeat_notice_after : parseInt( repeat_notice_after ),
85
+ },
86
+ });
87
+
88
+ }
89
+ };
90
+
91
+ $( function() {
92
+ AstraNotices.init();
93
+ } );
94
  } )( jQuery );
languages/astra-sites.pot CHANGED
@@ -1,833 +1,833 @@
1
- # Copyright (C) 2019 Brainstorm Force
2
- # This file is distributed under the same license as the Astra Starter Sites package.
3
- msgid ""
4
- msgstr ""
5
- "Project-Id-Version: Astra Starter Sites 1.3.13\n"
6
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
- "POT-Creation-Date: 2019-06-04 10:21:28+00:00\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=utf-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
12
- "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
- "Language-Team: LANGUAGE <LL@li.org>\n"
14
- "Language: en\n"
15
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
16
- "X-Poedit-Country: United States\n"
17
- "X-Poedit-SourceCharset: UTF-8\n"
18
- "X-Poedit-KeywordsList: "
19
- "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
20
- "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
21
- "X-Poedit-Basepath: ../\n"
22
- "X-Poedit-SearchPath-0: .\n"
23
- "X-Poedit-Bookmarks: \n"
24
- "X-Textdomain-Support: yes\n"
25
- "X-Generator: grunt-wp-i18n1.0.0\n"
26
-
27
- #: astra-sites.php:18
28
- msgid "Astra Sites"
29
- msgstr ""
30
-
31
- #: inc/classes/class-astra-sites-importer-log.php:255
32
- msgid "Enabled"
33
- msgstr ""
34
-
35
- #: inc/classes/class-astra-sites-importer-log.php:258
36
- msgid "Disabled"
37
- msgstr ""
38
-
39
- #: inc/classes/class-astra-sites-importer-log.php:343
40
- #: inc/classes/class-astra-sites-importer-log.php:400
41
- msgid "Yes"
42
- msgstr ""
43
-
44
- #: inc/classes/class-astra-sites-importer-log.php:346
45
- #: inc/classes/class-astra-sites-importer-log.php:403
46
- msgid "No"
47
- msgstr ""
48
-
49
- #: inc/classes/class-astra-sites-importer.php:126
50
- msgid "You have not \"customize\" access to import the Astra site."
51
- msgstr ""
52
-
53
- #: inc/classes/class-astra-sites-importer.php:150
54
- msgid "Request site API URL is empty. Try again!"
55
- msgstr ""
56
-
57
- #: inc/classes/class-astra-sites-importer.php:250
58
- msgid "Customizer data is empty!"
59
- msgstr ""
60
-
61
- #: inc/classes/class-astra-sites-importer.php:264
62
- msgid ""
63
- "If XMLReader is not available, it imports all other settings and only skips "
64
- "XML import. This creates an incomplete website. We should bail early and "
65
- "not import anything if this is not present."
66
- msgstr ""
67
-
68
- #: inc/classes/class-astra-sites-importer.php:282
69
- msgid "There was an error downloading the XML file."
70
- msgstr ""
71
-
72
- #: inc/classes/class-astra-sites-importer.php:288
73
- msgid "Invalid site XML file!"
74
- msgstr ""
75
-
76
- #: inc/classes/class-astra-sites-importer.php:315
77
- msgid "Site options are empty!"
78
- msgstr ""
79
-
80
- #: inc/classes/class-astra-sites-importer.php:345
81
- msgid "Widget data is empty!"
82
- msgstr ""
83
-
84
- #: inc/classes/class-astra-sites-page.php:85
85
- #. translators: %1$s is the admin page URL, %2$s is product name.
86
- msgid ""
87
- "Thank you for choosing %1$s! Check the library of <a "
88
- "class=\"astra-sites-getting-started-btn\" href=\"%2$s\">ready starter sites "
89
- "here »</a>"
90
- msgstr ""
91
-
92
- #: inc/classes/class-astra-sites-page.php:184
93
- msgid "Required XMLReader PHP extension is missing on your server!"
94
- msgstr ""
95
-
96
- #: inc/classes/class-astra-sites-page.php:186
97
- #. translators: %s is the white label name.
98
- msgid ""
99
- "%s import requires XMLReader extension to be installed. Please contact your "
100
- "web hosting provider and ask them to install and activate the XMLReader PHP "
101
- "extension."
102
- msgstr ""
103
-
104
- #: inc/classes/class-astra-sites-page.php:248
105
- msgid "Settings saved successfully."
106
- msgstr ""
107
-
108
- #: inc/classes/class-astra-sites-page.php:278
109
- msgid "Select Page Builder"
110
- msgstr ""
111
-
112
- #: inc/classes/class-astra-sites-page.php:279
113
- msgid ""
114
- "Astra offers starter sites that can be imported in one click. These "
115
- "templates are available in few different page builders. Please choose your "
116
- "preferred page builder from the list below."
117
- msgstr ""
118
-
119
- #: inc/classes/class-astra-sites-page.php:286
120
- msgid "Gutenberg"
121
- msgstr ""
122
-
123
- #: inc/classes/class-astra-sites-page.php:293
124
- #: inc/classes/class-astra-sites-page.php:331
125
- msgid "Elementor"
126
- msgstr ""
127
-
128
- #: inc/classes/class-astra-sites-page.php:300
129
- #: inc/classes/class-astra-sites-page.php:332
130
- msgid "Beaver Builder"
131
- msgstr ""
132
-
133
- #: inc/classes/class-astra-sites-page.php:306
134
- #: inc/classes/class-astra-sites-page.php:333
135
- msgid "Brizy"
136
- msgstr ""
137
-
138
- #: inc/classes/class-astra-sites-page.php:311
139
- msgid "Please select your favorite page builder to continue.."
140
- msgstr ""
141
-
142
- #: inc/classes/class-astra-sites-page.php:313 inc/includes/admin-page.php:158
143
- msgid "Next"
144
- msgstr ""
145
-
146
- #: inc/classes/class-astra-sites-page.php:323
147
- msgid "Astra Starter Sites - Your Library of 100+ Ready Templates!"
148
- msgstr ""
149
-
150
- #: inc/classes/class-astra-sites-page.php:330
151
- msgid "Block Editor (Gutenberg)"
152
- msgstr ""
153
-
154
- #. Plugin Name of the plugin/theme
155
- msgid "Astra Starter Sites"
156
- msgstr ""
157
-
158
- #: inc/classes/class-astra-sites-white-label.php:187
159
- #. translators: %1$s product name
160
- msgid "%1$s Branding"
161
- msgstr ""
162
-
163
- #: inc/classes/class-astra-sites.php:98
164
- msgid "Theme Activated"
165
- msgstr ""
166
-
167
- #: inc/classes/class-astra-sites.php:162
168
- #. translators: 1: theme.php file
169
- msgid ""
170
- "<p>Astra Theme needs to be active for you to use currently installed "
171
- "\"%1$s\" plugin. <a href=\"#\" class=\"%3$s\" "
172
- "data-theme-slug=\"astra\">Install & Activate Now</a></p>"
173
- msgstr ""
174
-
175
- #: inc/classes/class-astra-sites.php:227
176
- msgid "See Library"
177
- msgstr ""
178
-
179
- #: inc/classes/class-astra-sites.php:262
180
- msgid "Installed! Activating.."
181
- msgstr ""
182
-
183
- #: inc/classes/class-astra-sites.php:263
184
- msgid "Activating.."
185
- msgstr ""
186
-
187
- #: inc/classes/class-astra-sites.php:264
188
- msgid "Activated! Reloading.."
189
- msgstr ""
190
-
191
- #: inc/classes/class-astra-sites.php:265
192
- msgid "Installing.."
193
- msgstr ""
194
-
195
- #: inc/classes/class-astra-sites.php:298
196
- msgid "Page Builder"
197
- msgstr ""
198
-
199
- #: inc/classes/class-astra-sites.php:303
200
- msgid "Categories"
201
- msgstr ""
202
-
203
- #: inc/classes/class-astra-sites.php:344
204
- msgid "Get Agency Bundle"
205
- msgstr ""
206
-
207
- #: inc/classes/class-astra-sites.php:346
208
- msgid "Upgrade"
209
- msgstr ""
210
-
211
- #: inc/classes/class-astra-sites.php:353
212
- #. translators: %s are HTML tags.
213
- msgid ""
214
- "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
215
- "Sites import requires XMLReader extension to be installed. Please contact "
216
- "your web hosting provider and ask them to install and activate the "
217
- "XMLReader PHP extension."
218
- msgstr ""
219
-
220
- #: inc/classes/class-astra-sites.php:354
221
- msgid ""
222
- "Warning! Astra Site Import process is not complete. Don't close the window "
223
- "until import process complete. Do you still want to leave the window?"
224
- msgstr ""
225
-
226
- #: inc/classes/class-astra-sites.php:355
227
- msgid "Error!"
228
- msgstr ""
229
-
230
- #: inc/classes/class-astra-sites.php:356
231
- msgid "Error! Read Possibilities."
232
- msgstr ""
233
-
234
- #: inc/classes/class-astra-sites.php:358
235
- msgid "Done! View Site"
236
- msgstr ""
237
-
238
- #: inc/classes/class-astra-sites.php:359
239
- msgid "Activating"
240
- msgstr ""
241
-
242
- #: inc/classes/class-astra-sites.php:360
243
- msgid "Active"
244
- msgstr ""
245
-
246
- #: inc/classes/class-astra-sites.php:361
247
- msgid "Import failed."
248
- msgstr ""
249
-
250
- #: inc/classes/class-astra-sites.php:362
251
- msgid "Import failed. See error log."
252
- msgstr ""
253
-
254
- #: inc/classes/class-astra-sites.php:363
255
- msgid "Import This Site"
256
- msgstr ""
257
-
258
- #: inc/classes/class-astra-sites.php:364 inc/classes/class-astra-sites.php:380
259
- msgid "Importing.."
260
- msgstr ""
261
-
262
- #: inc/classes/class-astra-sites.php:365 inc/includes/admin-page.php:178
263
- msgid "Read more"
264
- msgstr ""
265
-
266
- #: inc/classes/class-astra-sites.php:366
267
- msgid "Hide"
268
- msgstr ""
269
-
270
- #: inc/classes/class-astra-sites.php:367
271
- msgid "There was a problem receiving a response from server."
272
- msgstr ""
273
-
274
- #: inc/classes/class-astra-sites.php:368 inc/includes/admin-page.php:408
275
- msgid "No Demos found, Try a different search."
276
- msgstr ""
277
-
278
- #: inc/classes/class-astra-sites.php:371
279
- msgid "Installing plugin "
280
- msgstr ""
281
-
282
- #: inc/classes/class-astra-sites.php:372
283
- msgid "Plugin installed!"
284
- msgstr ""
285
-
286
- #: inc/classes/class-astra-sites.php:373
287
- msgid "Activating plugin "
288
- msgstr ""
289
-
290
- #: inc/classes/class-astra-sites.php:374
291
- msgid "Plugin activated "
292
- msgstr ""
293
-
294
- #: inc/classes/class-astra-sites.php:375
295
- msgid "Bulk plugin activation..."
296
- msgstr ""
297
-
298
- #: inc/classes/class-astra-sites.php:376
299
- msgid "Plugin activate - "
300
- msgstr ""
301
-
302
- #: inc/classes/class-astra-sites.php:377
303
- msgid "Error! While activating plugin - "
304
- msgstr ""
305
-
306
- #: inc/classes/class-astra-sites.php:378
307
- msgid "Bulk plugin installation..."
308
- msgstr ""
309
-
310
- #: inc/classes/class-astra-sites.php:379
311
- msgid "Site API "
312
- msgstr ""
313
-
314
- #: inc/classes/class-astra-sites.php:381
315
- msgid "Processing requests..."
316
- msgstr ""
317
-
318
- #: inc/classes/class-astra-sites.php:382
319
- msgid "Importing \"Customizer Settings\"..."
320
- msgstr ""
321
-
322
- #: inc/classes/class-astra-sites.php:383
323
- msgid "Imported customizer settings!"
324
- msgstr ""
325
-
326
- #: inc/classes/class-astra-sites.php:384
327
- msgid "Importing \"Contact Forms\"..."
328
- msgstr ""
329
-
330
- #: inc/classes/class-astra-sites.php:385
331
- msgid "Imported Contact Forms!"
332
- msgstr ""
333
-
334
- #: inc/classes/class-astra-sites.php:386
335
- msgid "Preparing \"XML\" Data..."
336
- msgstr ""
337
-
338
- #: inc/classes/class-astra-sites.php:387
339
- msgid "Set XML data!"
340
- msgstr ""
341
-
342
- #: inc/classes/class-astra-sites.php:388
343
- msgid "Importing \"XML\"..."
344
- msgstr ""
345
-
346
- #: inc/classes/class-astra-sites.php:389
347
- msgid "Imported XML!"
348
- msgstr ""
349
-
350
- #: inc/classes/class-astra-sites.php:390
351
- msgid "Importing \"Options\"..."
352
- msgstr ""
353
-
354
- #: inc/classes/class-astra-sites.php:391
355
- msgid "Imported Options!"
356
- msgstr ""
357
-
358
- #: inc/classes/class-astra-sites.php:392
359
- msgid "Importing \"Widgets\"..."
360
- msgstr ""
361
-
362
- #: inc/classes/class-astra-sites.php:393
363
- msgid "Imported Widgets!"
364
- msgstr ""
365
-
366
- #: inc/classes/class-astra-sites.php:395
367
- msgid "View site: "
368
- msgstr ""
369
-
370
- #: inc/classes/class-astra-sites.php:396
371
- msgid "Getting Site Information.."
372
- msgstr ""
373
-
374
- #: inc/classes/class-astra-sites.php:397
375
- msgid "Importing Customizer Settings.."
376
- msgstr ""
377
-
378
- #: inc/classes/class-astra-sites.php:398
379
- msgid "Importing Contact Forms.."
380
- msgstr ""
381
-
382
- #: inc/classes/class-astra-sites.php:399
383
- msgid "Setting up import data.."
384
- msgstr ""
385
-
386
- #: inc/classes/class-astra-sites.php:400
387
- msgid "Importing Content.."
388
- msgstr ""
389
-
390
- #: inc/classes/class-astra-sites.php:401
391
- msgid "Importing Site Options.."
392
- msgstr ""
393
-
394
- #: inc/classes/class-astra-sites.php:402
395
- msgid "Importing Widgets.."
396
- msgstr ""
397
-
398
- #: inc/classes/class-astra-sites.php:403
399
- msgid "Import Complete.."
400
- msgstr ""
401
-
402
- #: inc/classes/class-astra-sites.php:404
403
- msgid "Previewing "
404
- msgstr ""
405
-
406
- #: inc/classes/class-astra-sites.php:405
407
- msgid "See Error Log &rarr;"
408
- msgstr ""
409
-
410
- #: inc/classes/class-astra-sites.php:439
411
- msgid "No plugin specified"
412
- msgstr ""
413
-
414
- #: inc/classes/class-astra-sites.php:468
415
- msgid "Plugin Activated"
416
- msgstr ""
417
-
418
- #: inc/importers/batch-processing/helpers/class-wp-background-process.php:433
419
- msgid "Every %d Minutes"
420
- msgstr ""
421
-
422
- #: inc/importers/class-widgets-importer.php:83
423
- msgid "Import data could not be read. Please try a different file."
424
- msgstr ""
425
-
426
- #: inc/importers/class-widgets-importer.php:127
427
- msgid "Widget area does not exist in theme (using Inactive)"
428
- msgstr ""
429
-
430
- #: inc/importers/class-widgets-importer.php:149
431
- msgid "Site does not support widget"
432
- msgstr ""
433
-
434
- #: inc/importers/class-widgets-importer.php:185
435
- msgid "Widget already exists"
436
- msgstr ""
437
-
438
- #: inc/importers/class-widgets-importer.php:254
439
- msgid "Imported"
440
- msgstr ""
441
-
442
- #: inc/importers/class-widgets-importer.php:257
443
- msgid "Imported to Inactive"
444
- msgstr ""
445
-
446
- #: inc/importers/class-widgets-importer.php:263
447
- msgid "No Title"
448
- msgstr ""
449
-
450
- #: inc/importers/wxr-importer/class-astra-wxr-importer.php:307
451
- msgid "Import complete!"
452
- msgstr ""
453
-
454
- #: inc/importers/wxr-importer/class-wxr-importer.php:131
455
- msgid "Could not open the file for parsing"
456
- msgstr ""
457
-
458
- #: inc/importers/wxr-importer/class-wxr-importer.php:167
459
- #: inc/importers/wxr-importer/class-wxr-importer.php:283
460
- #: inc/importers/wxr-importer/class-wxr-importer.php:356
461
- msgid ""
462
- "This WXR file (version %1$s) is newer than the importer (version %2$s) and "
463
- "may not be supported. Please consider updating."
464
- msgstr ""
465
-
466
- #: inc/importers/wxr-importer/class-wxr-importer.php:504
467
- msgid "The file does not exist, please try again."
468
- msgstr ""
469
-
470
- #: inc/importers/wxr-importer/class-wxr-importer.php:564
471
- msgid "Invalid author mapping"
472
- msgstr ""
473
-
474
- #: inc/importers/wxr-importer/class-wxr-importer.php:665
475
- msgid "Cannot import auto-draft posts"
476
- msgstr ""
477
-
478
- #: inc/importers/wxr-importer/class-wxr-importer.php:753
479
- msgid "Failed to import \"%1$s\": Invalid post type %2$s"
480
- msgstr ""
481
-
482
- #: inc/importers/wxr-importer/class-wxr-importer.php:763
483
- msgid "%1$s \"%2$s\" already exists."
484
- msgstr ""
485
-
486
- #: inc/importers/wxr-importer/class-wxr-importer.php:857
487
- msgid "Skipping attachment \"%s\", fetching attachments disabled"
488
- msgstr ""
489
-
490
- #: inc/importers/wxr-importer/class-wxr-importer.php:878
491
- msgid "Failed to import \"%1$s\" (%2$s)"
492
- msgstr ""
493
-
494
- #: inc/importers/wxr-importer/class-wxr-importer.php:910
495
- #: inc/importers/wxr-importer/class-wxr-importer.php:1755
496
- msgid "Imported \"%1$s\" (%2$s)"
497
- msgstr ""
498
-
499
- #: inc/importers/wxr-importer/class-wxr-importer.php:915
500
- msgid "Post %1$d remapped to %2$d"
501
- msgstr ""
502
-
503
- #: inc/importers/wxr-importer/class-wxr-importer.php:1062
504
- msgid "Invalid file type"
505
- msgstr ""
506
-
507
- #: inc/importers/wxr-importer/class-wxr-importer.php:1560
508
- msgid "Failed to import user \"%s\""
509
- msgstr ""
510
-
511
- #: inc/importers/wxr-importer/class-wxr-importer.php:1581
512
- msgid "Imported user \"%s\""
513
- msgstr ""
514
-
515
- #: inc/importers/wxr-importer/class-wxr-importer.php:1585
516
- msgid "User %1$d remapped to %2$d"
517
- msgstr ""
518
-
519
- #: inc/importers/wxr-importer/class-wxr-importer.php:1731
520
- msgid "Failed to import %1$s %2$s"
521
- msgstr ""
522
-
523
- #: inc/importers/wxr-importer/class-wxr-importer.php:1760
524
- msgid "Term %1$d remapped to %2$d"
525
- msgstr ""
526
-
527
- #: inc/importers/wxr-importer/class-wxr-importer.php:1813
528
- msgid "Remote server returned %1$d %2$s for %3$s"
529
- msgstr ""
530
-
531
- #: inc/importers/wxr-importer/class-wxr-importer.php:1826
532
- msgid "Remote file is incorrect size"
533
- msgstr ""
534
-
535
- #: inc/importers/wxr-importer/class-wxr-importer.php:1831
536
- msgid "Zero size file downloaded"
537
- msgstr ""
538
-
539
- #: inc/importers/wxr-importer/class-wxr-importer.php:1837
540
- msgid "Remote file is too large, limit is %s"
541
- msgstr ""
542
-
543
- #: inc/importers/wxr-importer/class-wxr-importer.php:1859
544
- msgid "Running post-processing for post %d"
545
- msgstr ""
546
-
547
- #: inc/importers/wxr-importer/class-wxr-importer.php:1872
548
- msgid "Could not find the post parent for \"%1$s\" (post #%2$d)"
549
- msgstr ""
550
-
551
- #: inc/importers/wxr-importer/class-wxr-importer.php:1877
552
- msgid "Post %1$d was imported with parent %2$d, but could not be found"
553
- msgstr ""
554
-
555
- #: inc/importers/wxr-importer/class-wxr-importer.php:1891
556
- msgid "Could not find the author for \"%1$s\" (post #%2$d)"
557
- msgstr ""
558
-
559
- #: inc/importers/wxr-importer/class-wxr-importer.php:1896
560
- msgid "Post %1$d was imported with author \"%2$s\", but could not be found"
561
- msgstr ""
562
-
563
- #: inc/importers/wxr-importer/class-wxr-importer.php:1922
564
- msgid "Post %d was marked for post-processing, but none was required."
565
- msgstr ""
566
-
567
- #: inc/importers/wxr-importer/class-wxr-importer.php:1933
568
- msgid "Could not update \"%1$s\" (post #%2$d) with mapped data"
569
- msgstr ""
570
-
571
- #: inc/importers/wxr-importer/class-wxr-importer.php:1978
572
- msgid "Could not find the menu object for \"%1$s\" (post #%2$d)"
573
- msgstr ""
574
-
575
- #: inc/importers/wxr-importer/class-wxr-importer.php:1983
576
- msgid ""
577
- "Post %1$d was imported with object \"%2$d\" of type \"%3$s\", but could not "
578
- "be found"
579
- msgstr ""
580
-
581
- #: inc/importers/wxr-importer/class-wxr-importer.php:2005
582
- msgid "Could not find the comment parent for comment #%d"
583
- msgstr ""
584
-
585
- #: inc/importers/wxr-importer/class-wxr-importer.php:2009
586
- msgid "Comment %1$d was imported with parent %2$d, but could not be found"
587
- msgstr ""
588
-
589
- #: inc/importers/wxr-importer/class-wxr-importer.php:2023
590
- msgid "Could not find the author for comment #%d"
591
- msgstr ""
592
-
593
- #: inc/importers/wxr-importer/class-wxr-importer.php:2027
594
- msgid "Comment %1$d was imported with author %2$d, but could not be found"
595
- msgstr ""
596
-
597
- #: inc/importers/wxr-importer/class-wxr-importer.php:2044
598
- msgid "Could not update comment #%d with mapped data"
599
- msgstr ""
600
-
601
- #: inc/includes/admin-page.php:41
602
- msgid "Search Sites"
603
- msgstr ""
604
-
605
- #: inc/includes/admin-page.php:42
606
- msgid "Search Sites..."
607
- msgstr ""
608
-
609
- #: inc/includes/admin-page.php:71
610
- msgid "Liked this demo?"
611
- msgstr ""
612
-
613
- #: inc/includes/admin-page.php:75
614
- #. translators: %s is pricing page link
615
- msgid ""
616
- "It is a premium website demo which is available only with the Agency "
617
- "Bundles <a href=\"%s\" target=\"_blank\">Buy Now!</a>"
618
- msgstr ""
619
-
620
- #: inc/includes/admin-page.php:81
621
- #. translators: %s is article link
622
- msgid ""
623
- "Already own an Agency Bundle? Read an article to know how you can <a "
624
- "href=\"%s\" target=\"_blank\">import a premium website demo</a>."
625
- msgstr ""
626
-
627
- #: inc/includes/admin-page.php:92
628
- msgid "You are just 2 minutes away from importing this demo!"
629
- msgstr ""
630
-
631
- #: inc/includes/admin-page.php:93
632
- msgid ""
633
- "It is a premium website demo and you need to activate the license to access "
634
- "it."
635
- msgstr ""
636
-
637
- #: inc/includes/admin-page.php:97
638
- #. translators: %s is article link
639
- msgid ""
640
- "Learn how you can <a href=\"%s\" target=\"_blank\">activate the license</a> "
641
- "of the Astra Premium Sites plugin."
642
- msgstr ""
643
-
644
- #: inc/includes/admin-page.php:109
645
- msgid "Required Plugin Missing"
646
- msgstr ""
647
-
648
- #: inc/includes/admin-page.php:110
649
- msgid ""
650
- "This starter site requires premium plugins. As these are third party "
651
- "premium plugins, you'll need to purchase, install and activate them first."
652
- msgstr ""
653
-
654
- #: inc/includes/admin-page.php:129
655
- msgid "Select Your Favorite Page Builder"
656
- msgstr ""
657
-
658
- #: inc/includes/admin-page.php:132
659
- msgid "Sites List.."
660
- msgstr ""
661
-
662
- #: inc/includes/admin-page.php:156
663
- msgid "Close"
664
- msgstr ""
665
-
666
- #: inc/includes/admin-page.php:157
667
- msgid "Previous"
668
- msgstr ""
669
-
670
- #: inc/includes/admin-page.php:159 inc/includes/admin-page.php:160
671
- #: inc/includes/admin-page.php:245 inc/includes/admin-page.php:252
672
- msgid "Import Site"
673
- msgstr ""
674
-
675
- #: inc/includes/admin-page.php:187
676
- msgid "Install Required Plugins"
677
- msgstr ""
678
-
679
- #: inc/includes/admin-page.php:199
680
- msgid ""
681
- "Customizer is what gives a design to the website; and selecting this option "
682
- "replaces your current design with a new one."
683
- msgstr ""
684
-
685
- #: inc/includes/admin-page.php:200
686
- msgid ""
687
- "Backup of current customizer settings will be stored in "
688
- "\"wp-content/astra-sites\" directory, just in case if you want to restore "
689
- "it later."
690
- msgstr ""
691
-
692
- #: inc/includes/admin-page.php:210
693
- msgid ""
694
- "Selecting this option will import dummy pages, posts, images and menus. If "
695
- "you do not want to import dummy content, please uncheck this option."
696
- msgstr ""
697
-
698
- #: inc/includes/admin-page.php:226
699
- msgid ""
700
- "WARNING: Selecting this option will delete data from your current website. "
701
- "Choose this option only if this is intended."
702
- msgstr ""
703
-
704
- #: inc/includes/admin-page.php:231
705
- msgid "Advanced Options"
706
- msgstr ""
707
-
708
- #: inc/includes/admin-page.php:236
709
- msgid "Required Plugins"
710
- msgstr ""
711
-
712
- #: inc/includes/admin-page.php:258
713
- msgid "Collapse"
714
- msgstr ""
715
-
716
- #: inc/includes/admin-page.php:264
717
- msgid "Enter desktop preview mode"
718
- msgstr ""
719
-
720
- #: inc/includes/admin-page.php:267
721
- msgid "Enter tablet preview mode"
722
- msgstr ""
723
-
724
- #: inc/includes/admin-page.php:270
725
- msgid "Enter mobile preview mode"
726
- msgstr ""
727
-
728
- #: inc/includes/admin-page.php:278 inc/includes/admin-page.php:400
729
- msgid "Preview"
730
- msgstr ""
731
-
732
- #: inc/includes/admin-page.php:281
733
- msgid "We're importing your website."
734
- msgstr ""
735
-
736
- #: inc/includes/admin-page.php:282
737
- msgid ""
738
- "The process can take anywhere between 2 to 10 minutes depending on the size "
739
- "of the website and speed of connection."
740
- msgstr ""
741
-
742
- #: inc/includes/admin-page.php:283
743
- msgid ""
744
- "Please do not close this browser window until the site is imported "
745
- "completely."
746
- msgstr ""
747
-
748
- #: inc/includes/admin-page.php:306
749
- #. translators: %1$s & %2$s are a Demo API URL
750
- msgid ""
751
- "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
752
- "unreachable from your site.</p>"
753
- msgstr ""
754
-
755
- #: inc/includes/admin-page.php:308
756
- msgid ""
757
- "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
758
- "temporary issues. No kidding!</p>"
759
- msgstr ""
760
-
761
- #: inc/includes/admin-page.php:310
762
- msgid ""
763
- "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
764
- "to your server administrator and check if demo server is being blocked by "
765
- "the firewall!</p>"
766
- msgstr ""
767
-
768
- #: inc/includes/admin-page.php:313
769
- #. translators: %1$s is a support link
770
- msgid ""
771
- "<p>If that does not help, please open up a <a href=\"%1$s\" "
772
- "target=\"_blank\">Support Ticket</a> and we will be glad take a closer look "
773
- "for you.</p>"
774
- msgstr ""
775
-
776
- #: inc/includes/admin-page.php:325
777
- msgid "Under Maintenance.."
778
- msgstr ""
779
-
780
- #: inc/includes/admin-page.php:326
781
- msgid ""
782
- "If you are seeing this message, most likely our servers are under routine "
783
- "maintenance and we will be back shortly. "
784
- msgstr ""
785
-
786
- #: inc/includes/admin-page.php:327
787
- msgid ""
788
- "In rare case, it is possible your website is having trouble connecting with "
789
- "ours. If you need help, please feel free to get in touch with us from our "
790
- "website."
791
- msgstr ""
792
-
793
- #: inc/includes/admin-page.php:412 inc/includes/admin-page.php:430
794
- #. translators: %1$s External Link
795
- msgid ""
796
- "Don't see a site that you would like to import?<br><a target=\"_blank\" "
797
- "href=\"%1$s\">Please suggest us!</a>"
798
- msgstr ""
799
-
800
- #: inc/includes/white-label.php:29
801
- msgid "Plugin Name:"
802
- msgstr ""
803
-
804
- #: inc/includes/white-label.php:34
805
- msgid "Plugin Description:"
806
- msgstr ""
807
-
808
- #. Plugin URI of the plugin/theme
809
- msgid "http://www.wpastra.com/pro/"
810
- msgstr ""
811
-
812
- #. Description of the plugin/theme
813
- msgid "Import free sites build with Astra theme."
814
- msgstr ""
815
-
816
- #. Author of the plugin/theme
817
- msgid "Brainstorm Force"
818
- msgstr ""
819
-
820
- #. Author URI of the plugin/theme
821
- msgid "http://www.brainstormforce.com"
822
- msgstr ""
823
-
824
- #: inc/classes/class-astra-sites-importer-log.php:276
825
- #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
826
- msgctxt "Recommended Memory Limit"
827
- msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
828
- msgstr ""
829
-
830
- #: inc/classes/class-astra-sites-importer-log.php:357
831
- msgctxt "PHP Version"
832
- msgid "We recommend to use php 5.4 or higher"
833
  msgstr ""
1
+ # Copyright (C) 2019 Brainstorm Force
2
+ # This file is distributed under the same license as the Astra Starter Sites package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Astra Starter Sites 1.3.15\n"
6
+ "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/astra-sites\n"
7
+ "POT-Creation-Date: 2019-06-20 10:37:00+00:00\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=utf-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2019-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <LL@li.org>\n"
14
+ "Language: en\n"
15
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
16
+ "X-Poedit-Country: United States\n"
17
+ "X-Poedit-SourceCharset: UTF-8\n"
18
+ "X-Poedit-KeywordsList: "
19
+ "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_"
20
+ "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n"
21
+ "X-Poedit-Basepath: ../\n"
22
+ "X-Poedit-SearchPath-0: .\n"
23
+ "X-Poedit-Bookmarks: \n"
24
+ "X-Textdomain-Support: yes\n"
25
+ "X-Generator: grunt-wp-i18n1.0.0\n"
26
+
27
+ #: astra-sites.php:18
28
+ msgid "Astra Sites"
29
+ msgstr ""
30
+
31
+ #: inc/classes/class-astra-sites-importer-log.php:255
32
+ msgid "Enabled"
33
+ msgstr ""
34
+
35
+ #: inc/classes/class-astra-sites-importer-log.php:258
36
+ msgid "Disabled"
37
+ msgstr ""
38
+
39
+ #: inc/classes/class-astra-sites-importer-log.php:343
40
+ #: inc/classes/class-astra-sites-importer-log.php:400
41
+ msgid "Yes"
42
+ msgstr ""
43
+
44
+ #: inc/classes/class-astra-sites-importer-log.php:346
45
+ #: inc/classes/class-astra-sites-importer-log.php:403
46
+ msgid "No"
47
+ msgstr ""
48
+
49
+ #: inc/classes/class-astra-sites-importer.php:126
50
+ msgid "You have not \"customize\" access to import the Astra site."
51
+ msgstr ""
52
+
53
+ #: inc/classes/class-astra-sites-importer.php:150
54
+ msgid "Request site API URL is empty. Try again!"
55
+ msgstr ""
56
+
57
+ #: inc/classes/class-astra-sites-importer.php:250
58
+ msgid "Customizer data is empty!"
59
+ msgstr ""
60
+
61
+ #: inc/classes/class-astra-sites-importer.php:264
62
+ msgid ""
63
+ "If XMLReader is not available, it imports all other settings and only skips "
64
+ "XML import. This creates an incomplete website. We should bail early and "
65
+ "not import anything if this is not present."
66
+ msgstr ""
67
+
68
+ #: inc/classes/class-astra-sites-importer.php:282
69
+ msgid "There was an error downloading the XML file."
70
+ msgstr ""
71
+
72
+ #: inc/classes/class-astra-sites-importer.php:288
73
+ msgid "Invalid site XML file!"
74
+ msgstr ""
75
+
76
+ #: inc/classes/class-astra-sites-importer.php:315
77
+ msgid "Site options are empty!"
78
+ msgstr ""
79
+
80
+ #: inc/classes/class-astra-sites-importer.php:345
81
+ msgid "Widget data is empty!"
82
+ msgstr ""
83
+
84
+ #: inc/classes/class-astra-sites-page.php:85
85
+ #. translators: %1$s is the admin page URL, %2$s is product name.
86
+ msgid ""
87
+ "Thank you for choosing %1$s! Check the library of <a "
88
+ "class=\"astra-sites-getting-started-btn\" href=\"%2$s\">ready starter sites "
89
+ "here »</a>"
90
+ msgstr ""
91
+
92
+ #: inc/classes/class-astra-sites-page.php:184
93
+ msgid "Required XMLReader PHP extension is missing on your server!"
94
+ msgstr ""
95
+
96
+ #: inc/classes/class-astra-sites-page.php:186
97
+ #. translators: %s is the white label name.
98
+ msgid ""
99
+ "%s import requires XMLReader extension to be installed. Please contact your "
100
+ "web hosting provider and ask them to install and activate the XMLReader PHP "
101
+ "extension."
102
+ msgstr ""
103
+
104
+ #: inc/classes/class-astra-sites-page.php:248
105
+ msgid "Settings saved successfully."
106
+ msgstr ""
107
+
108
+ #: inc/classes/class-astra-sites-page.php:278
109
+ msgid "Select Page Builder"
110
+ msgstr ""
111
+
112
+ #: inc/classes/class-astra-sites-page.php:279
113
+ msgid ""
114
+ "Astra offers starter sites that can be imported in one click. These "
115
+ "templates are available in few different page builders. Please choose your "
116
+ "preferred page builder from the list below."
117
+ msgstr ""
118
+
119
+ #: inc/classes/class-astra-sites-page.php:286
120
+ msgid "Gutenberg"
121
+ msgstr ""
122
+
123
+ #: inc/classes/class-astra-sites-page.php:293
124
+ #: inc/classes/class-astra-sites-page.php:331
125
+ msgid "Elementor"
126
+ msgstr ""
127
+
128
+ #: inc/classes/class-astra-sites-page.php:300
129
+ #: inc/classes/class-astra-sites-page.php:332
130
+ msgid "Beaver Builder"
131
+ msgstr ""
132
+
133
+ #: inc/classes/class-astra-sites-page.php:306
134
+ #: inc/classes/class-astra-sites-page.php:333
135
+ msgid "Brizy"
136
+ msgstr ""
137
+
138
+ #: inc/classes/class-astra-sites-page.php:311
139
+ msgid "Please select your favorite page builder to continue.."
140
+ msgstr ""
141
+
142
+ #: inc/classes/class-astra-sites-page.php:313 inc/includes/admin-page.php:158
143
+ msgid "Next"
144
+ msgstr ""
145
+
146
+ #: inc/classes/class-astra-sites-page.php:323
147
+ msgid "Astra Starter Sites - Your Library of 100+ Ready Templates!"
148
+ msgstr ""
149
+
150
+ #: inc/classes/class-astra-sites-page.php:330
151
+ msgid "Block Editor (Gutenberg)"
152
+ msgstr ""
153
+
154
+ #. Plugin Name of the plugin/theme
155
+ msgid "Astra Starter Sites"
156
+ msgstr ""
157
+
158
+ #: inc/classes/class-astra-sites-white-label.php:187
159
+ #. translators: %1$s product name
160
+ msgid "%1$s Branding"
161
+ msgstr ""
162
+
163
+ #: inc/classes/class-astra-sites.php:98
164
+ msgid "Theme Activated"
165
+ msgstr ""
166
+
167
+ #: inc/classes/class-astra-sites.php:162
168
+ #. translators: 1: theme.php file
169
+ msgid ""
170
+ "<p>Astra Theme needs to be active for you to use currently installed "
171
+ "\"%1$s\" plugin. <a href=\"#\" class=\"%3$s\" "
172
+ "data-theme-slug=\"astra\">Install & Activate Now</a></p>"
173
+ msgstr ""
174
+
175
+ #: inc/classes/class-astra-sites.php:227
176
+ msgid "See Library"
177
+ msgstr ""
178
+
179
+ #: inc/classes/class-astra-sites.php:262
180
+ msgid "Installed! Activating.."
181
+ msgstr ""
182
+
183
+ #: inc/classes/class-astra-sites.php:263
184
+ msgid "Activating.."
185
+ msgstr ""
186
+
187
+ #: inc/classes/class-astra-sites.php:264
188
+ msgid "Activated! Reloading.."
189
+ msgstr ""
190
+
191
+ #: inc/classes/class-astra-sites.php:265
192
+ msgid "Installing.."
193
+ msgstr ""
194
+
195
+ #: inc/classes/class-astra-sites.php:298
196
+ msgid "Page Builder"
197
+ msgstr ""
198
+
199
+ #: inc/classes/class-astra-sites.php:303
200
+ msgid "Categories"
201
+ msgstr ""
202
+
203
+ #: inc/classes/class-astra-sites.php:344
204
+ msgid "Get Agency Bundle"
205
+ msgstr ""
206
+
207
+ #: inc/classes/class-astra-sites.php:346
208
+ msgid "Upgrade"
209
+ msgstr ""
210
+
211
+ #: inc/classes/class-astra-sites.php:353
212
+ #. translators: %s are HTML tags.
213
+ msgid ""
214
+ "%1$sRequired XMLReader PHP extension is missing on your server!%2$sAstra "
215
+ "Sites import requires XMLReader extension to be installed. Please contact "
216
+ "your web hosting provider and ask them to install and activate the "
217
+ "XMLReader PHP extension."
218
+ msgstr ""
219
+
220
+ #: inc/classes/class-astra-sites.php:354
221
+ msgid ""
222
+ "Warning! Astra Site Import process is not complete. Don't close the window "
223
+ "until import process complete. Do you still want to leave the window?"
224
+ msgstr ""
225
+
226
+ #: inc/classes/class-astra-sites.php:355
227
+ msgid "Error!"
228
+ msgstr ""
229
+
230
+ #: inc/classes/class-astra-sites.php:356
231
+ msgid "Error! Read Possibilities."
232
+ msgstr ""
233
+
234
+ #: inc/classes/class-astra-sites.php:358
235
+ msgid "Done! View Site"
236
+ msgstr ""
237
+
238
+ #: inc/classes/class-astra-sites.php:359
239
+ msgid "Activating"
240
+ msgstr ""
241
+
242
+ #: inc/classes/class-astra-sites.php:360
243
+ msgid "Active"
244
+ msgstr ""
245
+
246
+ #: inc/classes/class-astra-sites.php:361
247
+ msgid "Import failed."
248
+ msgstr ""
249
+
250
+ #: inc/classes/class-astra-sites.php:362
251
+ msgid "Import failed. See error log."
252
+ msgstr ""
253
+
254
+ #: inc/classes/class-astra-sites.php:363
255
+ msgid "Import This Site"
256
+ msgstr ""
257
+
258
+ #: inc/classes/class-astra-sites.php:364 inc/classes/class-astra-sites.php:380
259
+ msgid "Importing.."
260
+ msgstr ""
261
+
262
+ #: inc/classes/class-astra-sites.php:365 inc/includes/admin-page.php:178
263
+ msgid "Read more"
264
+ msgstr ""
265
+
266
+ #: inc/classes/class-astra-sites.php:366
267
+ msgid "Hide"
268
+ msgstr ""
269
+
270
+ #: inc/classes/class-astra-sites.php:367
271
+ msgid "There was a problem receiving a response from server."
272
+ msgstr ""
273
+
274
+ #: inc/classes/class-astra-sites.php:368 inc/includes/admin-page.php:408
275
+ msgid "No Demos found, Try a different search."
276
+ msgstr ""
277
+
278
+ #: inc/classes/class-astra-sites.php:371
279
+ msgid "Installing plugin "
280
+ msgstr ""
281
+
282
+ #: inc/classes/class-astra-sites.php:372
283
+ msgid "Plugin installed!"
284
+ msgstr ""
285
+
286
+ #: inc/classes/class-astra-sites.php:373
287
+ msgid "Activating plugin "
288
+ msgstr ""
289
+
290
+ #: inc/classes/class-astra-sites.php:374
291
+ msgid "Plugin activated "
292
+ msgstr ""
293
+
294
+ #: inc/classes/class-astra-sites.php:375
295
+ msgid "Bulk plugin activation..."
296
+ msgstr ""
297
+
298
+ #: inc/classes/class-astra-sites.php:376
299
+ msgid "Plugin activate - "
300
+ msgstr ""
301
+
302
+ #: inc/classes/class-astra-sites.php:377
303
+ msgid "Error! While activating plugin - "
304
+ msgstr ""
305
+
306
+ #: inc/classes/class-astra-sites.php:378
307
+ msgid "Bulk plugin installation..."
308
+ msgstr ""
309
+
310
+ #: inc/classes/class-astra-sites.php:379
311
+ msgid "Site API "
312
+ msgstr ""
313
+
314
+ #: inc/classes/class-astra-sites.php:381
315
+ msgid "Processing requests..."
316
+ msgstr ""
317
+
318
+ #: inc/classes/class-astra-sites.php:382
319
+ msgid "Importing \"Customizer Settings\"..."
320
+ msgstr ""
321
+
322
+ #: inc/classes/class-astra-sites.php:383
323
+ msgid "Imported customizer settings!"
324
+ msgstr ""
325
+
326
+ #: inc/classes/class-astra-sites.php:384
327
+ msgid "Importing \"Contact Forms\"..."
328
+ msgstr ""
329
+
330
+ #: inc/classes/class-astra-sites.php:385
331
+ msgid "Imported Contact Forms!"
332
+ msgstr ""
333
+
334
+ #: inc/classes/class-astra-sites.php:386
335
+ msgid "Preparing \"XML\" Data..."
336
+ msgstr ""
337
+
338
+ #: inc/classes/class-astra-sites.php:387
339
+ msgid "Set XML data!"
340
+ msgstr ""
341
+
342
+ #: inc/classes/class-astra-sites.php:388
343
+ msgid "Importing \"XML\"..."
344
+ msgstr ""
345
+
346
+ #: inc/classes/class-astra-sites.php:389
347
+ msgid "Imported XML!"
348
+ msgstr ""
349
+
350
+ #: inc/classes/class-astra-sites.php:390
351
+ msgid "Importing \"Options\"..."
352
+ msgstr ""
353
+
354
+ #: inc/classes/class-astra-sites.php:391
355
+ msgid "Imported Options!"
356
+ msgstr ""
357
+
358
+ #: inc/classes/class-astra-sites.php:392
359
+ msgid "Importing \"Widgets\"..."
360
+ msgstr ""
361
+
362
+ #: inc/classes/class-astra-sites.php:393
363
+ msgid "Imported Widgets!"
364
+ msgstr ""
365
+
366
+ #: inc/classes/class-astra-sites.php:395
367
+ msgid "View site: "
368
+ msgstr ""
369
+
370
+ #: inc/classes/class-astra-sites.php:396
371
+ msgid "Getting Site Information.."
372
+ msgstr ""
373
+
374
+ #: inc/classes/class-astra-sites.php:397
375
+ msgid "Importing Customizer Settings.."
376
+ msgstr ""
377
+
378
+ #: inc/classes/class-astra-sites.php:398
379
+ msgid "Importing Contact Forms.."
380
+ msgstr ""
381
+
382
+ #: inc/classes/class-astra-sites.php:399
383
+ msgid "Setting up import data.."
384
+ msgstr ""
385
+
386
+ #: inc/classes/class-astra-sites.php:400
387
+ msgid "Importing Content.."
388
+ msgstr ""
389
+
390
+ #: inc/classes/class-astra-sites.php:401
391
+ msgid "Importing Site Options.."
392
+ msgstr ""
393
+
394
+ #: inc/classes/class-astra-sites.php:402
395
+ msgid "Importing Widgets.."
396
+ msgstr ""
397
+
398
+ #: inc/classes/class-astra-sites.php:403
399
+ msgid "Import Complete.."
400
+ msgstr ""
401
+
402
+ #: inc/classes/class-astra-sites.php:404
403
+ msgid "Previewing "
404
+ msgstr ""
405
+
406
+ #: inc/classes/class-astra-sites.php:405
407
+ msgid "See Error Log &rarr;"
408
+ msgstr ""
409
+
410
+ #: inc/classes/class-astra-sites.php:439
411
+ msgid "No plugin specified"
412
+ msgstr ""
413
+
414
+ #: inc/classes/class-astra-sites.php:468
415
+ msgid "Plugin Activated"
416
+ msgstr ""
417
+
418
+ #: inc/importers/batch-processing/helpers/class-wp-background-process.php:433
419
+ msgid "Every %d Minutes"
420
+ msgstr ""
421
+
422
+ #: inc/importers/class-widgets-importer.php:83
423
+ msgid "Import data could not be read. Please try a different file."
424
+ msgstr ""
425
+
426
+ #: inc/importers/class-widgets-importer.php:127
427
+ msgid "Widget area does not exist in theme (using Inactive)"
428
+ msgstr ""
429
+
430
+ #: inc/importers/class-widgets-importer.php:149
431
+ msgid "Site does not support widget"
432
+ msgstr ""
433
+
434
+ #: inc/importers/class-widgets-importer.php:185
435
+ msgid "Widget already exists"
436
+ msgstr ""
437
+
438
+ #: inc/importers/class-widgets-importer.php:254
439
+ msgid "Imported"
440
+ msgstr ""
441
+
442
+ #: inc/importers/class-widgets-importer.php:257
443
+ msgid "Imported to Inactive"
444
+ msgstr ""
445
+
446
+ #: inc/importers/class-widgets-importer.php:263
447
+ msgid "No Title"
448
+ msgstr ""
449
+
450
+ #: inc/importers/wxr-importer/class-astra-wxr-importer.php:307
451
+ msgid "Import complete!"
452
+ msgstr ""
453
+
454
+ #: inc/importers/wxr-importer/class-wxr-importer.php:131
455
+ msgid "Could not open the file for parsing"
456
+ msgstr ""
457
+
458
+ #: inc/importers/wxr-importer/class-wxr-importer.php:167
459
+ #: inc/importers/wxr-importer/class-wxr-importer.php:283
460
+ #: inc/importers/wxr-importer/class-wxr-importer.php:356
461
+ msgid ""
462
+ "This WXR file (version %1$s) is newer than the importer (version %2$s) and "
463
+ "may not be supported. Please consider updating."
464
+ msgstr ""
465
+
466
+ #: inc/importers/wxr-importer/class-wxr-importer.php:504
467
+ msgid "The file does not exist, please try again."
468
+ msgstr ""
469
+
470
+ #: inc/importers/wxr-importer/class-wxr-importer.php:564
471
+ msgid "Invalid author mapping"
472
+ msgstr ""
473
+
474
+ #: inc/importers/wxr-importer/class-wxr-importer.php:665
475
+ msgid "Cannot import auto-draft posts"
476
+ msgstr ""
477
+
478
+ #: inc/importers/wxr-importer/class-wxr-importer.php:753
479
+ msgid "Failed to import \"%1$s\": Invalid post type %2$s"
480
+ msgstr ""
481
+
482
+ #: inc/importers/wxr-importer/class-wxr-importer.php:763
483
+ msgid "%1$s \"%2$s\" already exists."
484
+ msgstr ""
485
+
486
+ #: inc/importers/wxr-importer/class-wxr-importer.php:857
487
+ msgid "Skipping attachment \"%s\", fetching attachments disabled"
488
+ msgstr ""
489
+
490
+ #: inc/importers/wxr-importer/class-wxr-importer.php:878
491
+ msgid "Failed to import \"%1$s\" (%2$s)"
492
+ msgstr ""
493
+
494
+ #: inc/importers/wxr-importer/class-wxr-importer.php:910
495
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1755
496
+ msgid "Imported \"%1$s\" (%2$s)"
497
+ msgstr ""
498
+
499
+ #: inc/importers/wxr-importer/class-wxr-importer.php:915
500
+ msgid "Post %1$d remapped to %2$d"
501
+ msgstr ""
502
+
503
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1062
504
+ msgid "Invalid file type"
505
+ msgstr ""
506
+
507
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1560
508
+ msgid "Failed to import user \"%s\""
509
+ msgstr ""
510
+
511
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1581
512
+ msgid "Imported user \"%s\""
513
+ msgstr ""
514
+
515
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1585
516
+ msgid "User %1$d remapped to %2$d"
517
+ msgstr ""
518
+
519
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1731
520
+ msgid "Failed to import %1$s %2$s"
521
+ msgstr ""
522
+
523
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1760
524
+ msgid "Term %1$d remapped to %2$d"
525
+ msgstr ""
526
+
527
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1813
528
+ msgid "Remote server returned %1$d %2$s for %3$s"
529
+ msgstr ""
530
+
531
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1826
532
+ msgid "Remote file is incorrect size"
533
+ msgstr ""
534
+
535
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1831
536
+ msgid "Zero size file downloaded"
537
+ msgstr ""
538
+
539
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1837
540
+ msgid "Remote file is too large, limit is %s"
541
+ msgstr ""
542
+
543
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1859
544
+ msgid "Running post-processing for post %d"
545
+ msgstr ""
546
+
547
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1872
548
+ msgid "Could not find the post parent for \"%1$s\" (post #%2$d)"
549
+ msgstr ""
550
+
551
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1877
552
+ msgid "Post %1$d was imported with parent %2$d, but could not be found"
553
+ msgstr ""
554
+
555
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1891
556
+ msgid "Could not find the author for \"%1$s\" (post #%2$d)"
557
+ msgstr ""
558
+
559
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1896
560
+ msgid "Post %1$d was imported with author \"%2$s\", but could not be found"
561
+ msgstr ""
562
+
563
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1922
564
+ msgid "Post %d was marked for post-processing, but none was required."
565
+ msgstr ""
566
+
567
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1933
568
+ msgid "Could not update \"%1$s\" (post #%2$d) with mapped data"
569
+ msgstr ""
570
+
571
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1978
572
+ msgid "Could not find the menu object for \"%1$s\" (post #%2$d)"
573
+ msgstr ""
574
+
575
+ #: inc/importers/wxr-importer/class-wxr-importer.php:1983
576
+ msgid ""
577
+ "Post %1$d was imported with object \"%2$d\" of type \"%3$s\", but could not "
578
+ "be found"
579
+ msgstr ""
580
+
581
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2005
582
+ msgid "Could not find the comment parent for comment #%d"
583
+ msgstr ""
584
+
585
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2009
586
+ msgid "Comment %1$d was imported with parent %2$d, but could not be found"
587
+ msgstr ""
588
+
589
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2023
590
+ msgid "Could not find the author for comment #%d"
591
+ msgstr ""
592
+
593
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2027
594
+ msgid "Comment %1$d was imported with author %2$d, but could not be found"
595
+ msgstr ""
596
+
597
+ #: inc/importers/wxr-importer/class-wxr-importer.php:2044
598
+ msgid "Could not update comment #%d with mapped data"
599
+ msgstr ""
600
+
601
+ #: inc/includes/admin-page.php:41
602
+ msgid "Search Sites"
603
+ msgstr ""
604
+
605
+ #: inc/includes/admin-page.php:42
606
+ msgid "Search Sites..."
607
+ msgstr ""
608
+
609
+ #: inc/includes/admin-page.php:71
610
+ msgid "Liked this demo?"
611
+ msgstr ""
612
+
613
+ #: inc/includes/admin-page.php:75
614
+ #. translators: %s is pricing page link
615
+ msgid ""
616
+ "It is a premium website demo which is available only with the Agency "
617
+ "Bundles <a href=\"%s\" target=\"_blank\">Buy Now!</a>"
618
+ msgstr ""
619
+
620
+ #: inc/includes/admin-page.php:81
621
+ #. translators: %s is article link
622
+ msgid ""
623
+ "Already own an Agency Bundle? Read an article to know how you can <a "
624
+ "href=\"%s\" target=\"_blank\">import a premium website demo</a>."
625
+ msgstr ""
626
+
627
+ #: inc/includes/admin-page.php:92
628
+ msgid "You are just 2 minutes away from importing this demo!"
629
+ msgstr ""
630
+
631
+ #: inc/includes/admin-page.php:93
632
+ msgid ""
633
+ "It is a premium website demo and you need to activate the license to access "
634
+ "it."
635
+ msgstr ""
636
+
637
+ #: inc/includes/admin-page.php:97
638
+ #. translators: %s is article link
639
+ msgid ""
640
+ "Learn how you can <a href=\"%s\" target=\"_blank\">activate the license</a> "
641
+ "of the Astra Premium Sites plugin."
642
+ msgstr ""
643
+
644
+ #: inc/includes/admin-page.php:109
645
+ msgid "Required Plugin Missing"
646
+ msgstr ""
647
+
648
+ #: inc/includes/admin-page.php:110
649
+ msgid ""
650
+ "This starter site requires premium plugins. As these are third party "
651
+ "premium plugins, you'll need to purchase, install and activate them first."
652
+ msgstr ""
653
+
654
+ #: inc/includes/admin-page.php:129
655
+ msgid "Select Your Favorite Page Builder"
656
+ msgstr ""
657
+
658
+ #: inc/includes/admin-page.php:132
659
+ msgid "Sites List.."
660
+ msgstr ""
661
+
662
+ #: inc/includes/admin-page.php:156
663
+ msgid "Close"
664
+ msgstr ""
665
+
666
+ #: inc/includes/admin-page.php:157
667
+ msgid "Previous"
668
+ msgstr ""
669
+
670
+ #: inc/includes/admin-page.php:159 inc/includes/admin-page.php:160
671
+ #: inc/includes/admin-page.php:245 inc/includes/admin-page.php:252
672
+ msgid "Import Site"
673
+ msgstr ""
674
+
675
+ #: inc/includes/admin-page.php:187
676
+ msgid "Install Required Plugins"
677
+ msgstr ""
678
+
679
+ #: inc/includes/admin-page.php:199
680
+ msgid ""
681
+ "Customizer is what gives a design to the website; and selecting this option "
682
+ "replaces your current design with a new one."
683
+ msgstr ""
684
+
685
+ #: inc/includes/admin-page.php:200
686
+ msgid ""
687
+ "Backup of current customizer settings will be stored in "
688
+ "\"wp-content/astra-sites\" directory, just in case if you want to restore "
689
+ "it later."
690
+ msgstr ""
691
+
692
+ #: inc/includes/admin-page.php:210
693
+ msgid ""
694
+ "Selecting this option will import dummy pages, posts, images and menus. If "
695
+ "you do not want to import dummy content, please uncheck this option."
696
+ msgstr ""
697
+
698
+ #: inc/includes/admin-page.php:226
699
+ msgid ""
700
+ "WARNING: Selecting this option will delete data from your current website. "
701
+ "Choose this option only if this is intended."
702
+ msgstr ""
703
+
704
+ #: inc/includes/admin-page.php:231
705
+ msgid "Advanced Options"
706
+ msgstr ""
707
+
708
+ #: inc/includes/admin-page.php:236
709
+ msgid "Required Plugins"
710
+ msgstr ""
711
+
712
+ #: inc/includes/admin-page.php:258
713
+ msgid "Collapse"
714
+ msgstr ""
715
+
716
+ #: inc/includes/admin-page.php:264
717
+ msgid "Enter desktop preview mode"
718
+ msgstr ""
719
+
720
+ #: inc/includes/admin-page.php:267
721
+ msgid "Enter tablet preview mode"
722
+ msgstr ""
723
+
724
+ #: inc/includes/admin-page.php:270
725
+ msgid "Enter mobile preview mode"
726
+ msgstr ""
727
+
728
+ #: inc/includes/admin-page.php:278 inc/includes/admin-page.php:400
729
+ msgid "Preview"
730
+ msgstr ""
731
+
732
+ #: inc/includes/admin-page.php:281
733
+ msgid "We're importing your website."
734
+ msgstr ""
735
+
736
+ #: inc/includes/admin-page.php:282
737
+ msgid ""
738
+ "The process can take anywhere between 2 to 10 minutes depending on the size "
739
+ "of the website and speed of connection."
740
+ msgstr ""
741
+
742
+ #: inc/includes/admin-page.php:283
743
+ msgid ""
744
+ "Please do not close this browser window until the site is imported "
745
+ "completely."
746
+ msgstr ""
747
+
748
+ #: inc/includes/admin-page.php:306
749
+ #. translators: %1$s & %2$s are a Demo API URL
750
+ msgid ""
751
+ "<p> It seems the demo data server, <i><a href=\"%1$s\">%2$s</a></i> is "
752
+ "unreachable from your site.</p>"
753
+ msgstr ""
754
+
755
+ #: inc/includes/admin-page.php:308
756
+ msgid ""
757
+ "<p class=\"left-margin\"> 1. Sometimes, simple page reload fixes any "
758
+ "temporary issues. No kidding!</p>"
759
+ msgstr ""
760
+
761
+ #: inc/includes/admin-page.php:310
762
+ msgid ""
763
+ "<p class=\"left-margin\"> 2. If that does not work, you will need to talk "
764
+ "to your server administrator and check if demo server is being blocked by "
765
+ "the firewall!</p>"
766
+ msgstr ""
767
+
768
+ #: inc/includes/admin-page.php:313
769
+ #. translators: %1$s is a support link
770
+ msgid ""
771
+ "<p>If that does not help, please open up a <a href=\"%1$s\" "
772
+ "target=\"_blank\">Support Ticket</a> and we will be glad take a closer look "
773
+ "for you.</p>"
774
+ msgstr ""
775
+
776
+ #: inc/includes/admin-page.php:325
777
+ msgid "Under Maintenance.."
778
+ msgstr ""
779
+
780
+ #: inc/includes/admin-page.php:326
781
+ msgid ""
782
+ "If you are seeing this message, most likely our servers are under routine "
783
+ "maintenance and we will be back shortly. "
784
+ msgstr ""
785
+
786
+ #: inc/includes/admin-page.php:327
787
+ msgid ""
788
+ "In rare case, it is possible your website is having trouble connecting with "
789
+ "ours. If you need help, please feel free to get in touch with us from our "
790
+ "website."
791
+ msgstr ""
792
+
793
+ #: inc/includes/admin-page.php:412 inc/includes/admin-page.php:430
794
+ #. translators: %1$s External Link
795
+ msgid ""
796
+ "Don't see a site that you would like to import?<br><a target=\"_blank\" "
797
+ "href=\"%1$s\">Please suggest us!</a>"
798
+ msgstr ""
799
+
800
+ #: inc/includes/white-label.php:29
801
+ msgid "Plugin Name:"
802
+ msgstr ""
803
+
804
+ #: inc/includes/white-label.php:34
805
+ msgid "Plugin Description:"
806
+ msgstr ""
807
+
808
+ #. Plugin URI of the plugin/theme
809
+ msgid "http://www.wpastra.com/pro/"
810
+ msgstr ""
811
+
812
+ #. Description of the plugin/theme
813
+ msgid "Import free sites build with Astra theme."
814
+ msgstr ""
815
+
816
+ #. Author of the plugin/theme
817
+ msgid "Brainstorm Force"
818
+ msgstr ""
819
+
820
+ #. Author URI of the plugin/theme
821
+ msgid "http://www.brainstormforce.com"
822
+ msgstr ""
823
+
824
+ #: inc/classes/class-astra-sites-importer-log.php:276
825
+ #. translators: %1$s Memory Limit, %2$s Recommended memory limit.
826
+ msgctxt "Recommended Memory Limit"
827
+ msgid "Current memory limit %1$s. We recommend setting memory to at least %2$s."
828
+ msgstr ""
829
+
830
+ #: inc/classes/class-astra-sites-importer-log.php:357
831
+ msgctxt "PHP Version"
832
+ msgid "We recommend to use php 5.4 or higher"
833
  msgstr ""
readme.txt CHANGED
@@ -1,345 +1,348 @@
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.2.1
8
- Stable tag: 1.3.14
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.14 - 13-June-2019
121
- - New: Added Support for Learndash WooCommerce integration plugin.
122
-
123
- v1.3.13 - 5-June-2019
124
- - New: Added LearnDash plugin support for the LearnDash demo sites.
125
-
126
- v1.3.12 - 14-May-2019
127
- - Improvement: Added compatibility for below WordPress 5.1.
128
-
129
- v1.3.11 - 13-May-2019
130
- - Improvement: Added compatibility to WordPress 5.2.
131
-
132
- v1.3.10 - 13-May-2019
133
- - Improvement: Added LarnDash plugin support for LarnDash demos.
134
- - Fix: SVG images are not importing in media library.
135
- - Fix: Images not uploaded due to timeout issue.
136
-
137
- v1.3.9 - 29-April-2019
138
- - Fix: Fatal error for below WordPress version 5.1.0.
139
-
140
- v1.3.8 - 26-April-2019
141
- - Improvement: Improve logic for importing images.
142
- - Fix: Implemented better caching technique for Astra Sites.
143
-
144
- v1.3.7 - 23-April-2019
145
- - Fix: Compatibility to WP Forms in Header and Footer of the demo site for Elementor.
146
-
147
- v1.3.6 - 19-April-2019
148
- - Fix: After Import UAG - Post Grid categories do not retain issue fixed
149
- - Fix: Premium Sites not importing due to invalid URL error.
150
-
151
- v1.3.5 - 18-April-2019
152
- - Improvement: Updated page builder selection screen UI.
153
- - Improvement: Showing import process on separate window. In which we can see all the current import process.
154
- - Improvement: Added one time welcome notice after plugin install and activate.
155
- - Improvement: Used fetch() instead of AJAX to load the Astra Sites. Also, Caching the Astra sites response and initially showing 30 sites.
156
-
157
- v1.3.4 - 16-April-2019
158
- - Hot Fix: Sites not visible for import.
159
-
160
- v1.3.3 - 2-April-2019
161
- - Improvement: Added compatibility for WP Forms pro version.
162
- - Fix: PHP error while importing customizer settings.
163
-
164
- v1.3.2 - 1-April-2019
165
- - Improvement: One click install and activate Astra theme on click on admin notice.
166
-
167
- v1.3.1 - 28-March-2019
168
- - Improvement: Set the max height for the website image from the website preview window.
169
-
170
- v1.3.0 - 26-March-2019
171
- - 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.
172
- - New: Display page builder selection only once on the first load of Astra Sites.
173
- - New: Take a backup of customizer options before importing new settings.
174
- - New: Allow to reset the previously imported site when importing multiple Astra sites.
175
-
176
- v1.2.15 - 14-March-2019
177
- - Improvement: Admin page UI improvements.
178
- - Improvement: Added filter `astra_sites_page_title` to change the page title.
179
-
180
- v1.2.14 - 13-March-2019
181
- - Improvement: Added support for the WPForms plugin.
182
-
183
- v1.2.13 - 12-March-2019
184
- - Improvement: Improved logic to download images in the Elementor templates.
185
- - Improvement: Added description of the Agency sites when license is not activated.
186
- - Fix: Incorrect images was set after batch process complete.
187
-
188
- v1.2.12 - 29-Jan-2019
189
- - Fix: Gutenberg render markup is invalid due to encoded characterless e.g. <, > are decoded into HTML tag.
190
-
191
- v1.2.11 - 24-Jan-2019
192
- - Improvement: Display a maintenance message if the Astra Sites API is unreachable.
193
- - Fix: EventSource abort the import process if default charset is not UTF-8.
194
-
195
- v1.2.10 - 4-Jan-2019
196
- - Fix: Astra Sites not accessible due to incorrect query parameters.
197
-
198
- v1.2.9 - 17-Dec-2018
199
- - Fix: XML not import due to getting different MIME file types on different PHP versions.
200
-
201
- v1.2.8 - 14-Dec-2018
202
- - Improvement: Added admin notice if XMLReader is not installed. XMLReader is required to import the XML of the website.
203
- - Fix: XML not import due to improved verification of MIME file types in WordPress v5.0.1.
204
-
205
- v1.2.7 - 12-July-2018
206
- - Improvement: Added page builder and category filter support to show selected page builder with selected categories.
207
- - Improvement: Added filter `astra_sites_show_filters` to enable/disable the filter list from admin page.
208
-
209
- v1.2.6 - 9-July-2018
210
- - 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.
211
-
212
- v1.2.5 - 5-July-2018
213
- - Fix: Normalize Elementor post meta by using `wp_slash` to avoid the unslashing data.
214
-
215
- v1.2.4 - 29-June-2018
216
- - Improvement: Removed custom license validation form and used Graupi in-build license validation form.
217
- - Improvement: Set default page builders depends on the packaged purchase.
218
-
219
- v1.2.3 - 13-June-2018
220
- - Improvement: Added windows EDGE browser support for importing the sites.
221
- - Improvement: The log file was not created if server does not support the file handling functions.
222
- - Fix: Load WXR importer on init to avoid redirect loop when loading WooCommerce importer.
223
- - Fix: Clear the Astra Pro plugin cache after site import.
224
-
225
- v1.2.2 - 26-March-2018
226
- - Fix: Correctly load the Elementor Pro 2.0 compatibility class for beta versions.
227
-
228
- v1.2.1 - 23-March-2018
229
- - Improvement: Clear the Astra Pro plugin cache after site import.
230
-
231
- v1.2.0 - 22-March-2018
232
- - Improvement: Added compatibility for Elemetor version 2.0.0. Older versions throw the PHP warning for function process_element_export_import_content().
233
-
234
- v1.1.9 - 12-March-2018
235
- - Fix: String `Select Your Favorite Page Builder` jerk while loading the sites.
236
-
237
- v1.1.8 - 5-March-2018
238
- - Improvements: Updated processing button animation while installation/activating plugin and importing site.
239
- - Improvements: Updated suggestion box message.
240
- - Fix: PHP fatal errors for WXR importer classes `WXR_Import_Info`, `WXR_Importer`, `WP_Importer_Logger_ServerSentEvents` and `WP_Importer_Logger`.
241
-
242
- v1.1.7 - 2-February-2018
243
- - 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.
244
-
245
- v1.1.6 - 22-January-2018
246
- - New: Added filter `astra_sites_xml_import_options` to change the XML import options.
247
- - Fix: Astra Pro plugin 'Custom Layouts' & 'Page Headers' not setting right display location due to different page, tax, category ids.
248
- - Fix: WooCommerce shop, checkout cart page ids not setting issue.
249
- - Fix: After site import updated demo url from the nav menus.
250
-
251
- v1.1.5 - 11-January-2018
252
- - New: Added SVG file support for importing the SVG images.
253
-
254
- v1.1.4 - 28-Dec-2017
255
- - Improvement: Importing WooCommerce product category images.
256
- - Improvement: Retain WooCommerce cart, checkout & my account pages when importing the ready WooCommerce sites.
257
- - Fix: Disabled WooCommerce plugin setup wizard after plugin install & activate.
258
-
259
- v1.1.3 - 20-Dec-2017
260
- - Improvement: Retain WooCommerce shop page when importing the ready WooCommerce sites.
261
-
262
- v1.1.2 - 24-Nov-2017
263
- - Fix: Handling plugin installation errors.
264
-
265
- v1.1.1 - 23-Nov-2017
266
- - New: Change the api url for Astra sites to https://websitedemos.net/ from https://sites.wpastra.com/
267
-
268
- v1.1.0 - 21-Nov-2017
269
- - New: Import the site content using Event Source (SSE) which ensures faithful imports.
270
- - New: Divided the site import process in separate AJAX calls to reduce the possibility of timeouts.
271
- - New: Generated the import log file. It will be displayed in the UI if the import fails.
272
- - Improvement: Validate all the possible errors.
273
- - Improvement: Updated Astra sites HTML grid structure for WordPress v4.9 compatibility.
274
- - Enhancement: Updated plugin name from Astra Sites - Lite with Astra Starter Sites.
275
-
276
- v1.0.14 - 9-Nov-2017
277
- - New: All the linked images on the Astra Sites will be downloaded to your site, No more loading images from external URLs.
278
- - New: Added suggestion box at as the last column in when listing sites so that you can add a suggest the sites you want.
279
- - New: Added site responsive preview buttons.
280
- - Improvement: Search string will not be removed when switching the page builder when scrolling through sites.
281
- - Improvement: Loading 15 sites instead of 6 Astra sites in the first load.
282
- - Improvement: Removed LazyLoad which is not useful in admin back-end for showing Astra Sites.
283
-
284
- v1.0.13 - 9-Oct-2017
285
- - New: Browsing the Astra Sites in the Admin panel is not faster with JS rendering.
286
-
287
- v1.0.12 - 29-Sept-2017
288
- - New: Added White Label support from <a href="https://wpastra.com/pro/">Astra Pro</a>.
289
- - Improvement: Don't display sites from both the page builders in the same view.
290
- - Fix: Astra Sites admin area not working in the Firefox.
291
-
292
- v1.0.11 - 22-Sept-2017
293
- - New: Single click Install & activate required plugins.
294
- - New: Added filter `astra_sites_menu_item` for adding extra tabs in admin page.
295
- - New: Added back image import feature for `elementor` page builder. In batch image import we import all images from astra site into client site.
296
- - Improvement: Updated JS code with object prototype.
297
- - Fix: Screen bounce on retina devices.
298
-
299
- v1.0.10 - 11-Sept-2017
300
- - Improvement: Added support for retina logo import.
301
- - Fix: Site logo image not displayed in customizer.
302
- - Fix: Updated `Astra Agency` purchase link.
303
-
304
- v1.0.9 - 8-Sept-2017
305
- - New: Added page builder categories for listing sites as per page builder.
306
-
307
- v1.0.8 - 6-Sept-2017
308
- - Fix: Beaver Builder option import.
309
- - Enhancement: Disabled dismiss-able notice visible once for each user.
310
- - Enhancement: Showing error message for for user who have not `manage_plugins` capability.
311
-
312
- v1.0.7 - 1-Sept-2017
313
- - Fix: Custom Menu widget not setting imported widget.
314
-
315
- v1.0.6 - 30-Aug-2017
316
- - New: Addd custom menu for Astra Sites.
317
- - Fix: Validate site options before storing in database.
318
-
319
- v1.0.5 - 29-Aug-2017
320
- - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
321
- - Enhancement: Plugin name updated from `Astra Sites` with `Astra Free Sites`.
322
- - Fix: PHP error while ignoring users.
323
-
324
- v1.0.4 - 21-Aug-2017
325
- - New: Added filter `astra_sites_api_params` for adding extra params in api call.
326
- - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
327
- - New: Added filter `astra_sites_category_hide_empty` for showing categories which are not set for any site.
328
-
329
- v1.0.3 - 11-Aug-2017
330
- - Fix: Avoided Astra users from site import process.
331
-
332
- v1.0.2 - 09-Aug-2017
333
- - Fix: Listing appropriate next and previous Astra sites.
334
- - Enhancement: Listing Astra sites though AJAX API call.
335
-
336
- v1.0.1 - 04-Aug-2017
337
- - New: Added Elementor plugin options support.
338
- - New: Added Customizer CSS support.
339
- - Enhancement: Avoided Lite Plugin version if Pro version is Installed. Now added support for Beaver Builder Plugin (Lite Version).
340
- - Enhancement: Astra sites API call validated before import.
341
- - Enhancement: Site logo imported from Astra sites.
342
- - Fix: Bug where widgets created with SiteOrigin plugin were not being imported.
343
-
344
- v1.0.0
345
- - 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.2
8
+ Stable tag: 1.3.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 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.15 - 20-June-2019
121
+ - Fix: Importing pages, post twice from the import process.
122
+
123
+ v1.3.14 - 14-June-2019
124
+ - Improvement: Added Support for Learndash WooCommerce integration plugin.
125
+
126
+ v1.3.13 - 5-June-2019
127
+ - New: Added LearnDash plugin support for the LearnDash demo sites.
128
+
129
+ v1.3.12 - 14-May-2019
130
+ - Improvement: Added compatibility for below WordPress 5.1.
131
+
132
+ v1.3.11 - 13-May-2019
133
+ - Improvement: Added compatibility to WordPress 5.2.
134
+
135
+ v1.3.10 - 13-May-2019
136
+ - Improvement: Added LarnDash plugin support for LarnDash demos.
137
+ - Fix: SVG images are not importing in media library.
138
+ - Fix: Images not uploaded due to timeout issue.
139
+
140
+ v1.3.9 - 29-April-2019
141
+ - Fix: Fatal error for below WordPress version 5.1.0.
142
+
143
+ v1.3.8 - 26-April-2019
144
+ - Improvement: Improve logic for importing images.
145
+ - Fix: Implemented better caching technique for Astra Sites.
146
+
147
+ v1.3.7 - 23-April-2019
148
+ - Fix: Compatibility to WP Forms in Header and Footer of the demo site for Elementor.
149
+
150
+ v1.3.6 - 19-April-2019
151
+ - Fix: After Import UAG - Post Grid categories do not retain issue fixed
152
+ - Fix: Premium Sites not importing due to invalid URL error.
153
+
154
+ v1.3.5 - 18-April-2019
155
+ - Improvement: Updated page builder selection screen UI.
156
+ - Improvement: Showing import process on separate window. In which we can see all the current import process.
157
+ - Improvement: Added one time welcome notice after plugin install and activate.
158
+ - Improvement: Used fetch() instead of AJAX to load the Astra Sites. Also, Caching the Astra sites response and initially showing 30 sites.
159
+
160
+ v1.3.4 - 16-April-2019
161
+ - Hot Fix: Sites not visible for import.
162
+
163
+ v1.3.3 - 2-April-2019
164
+ - Improvement: Added compatibility for WP Forms pro version.
165
+ - Fix: PHP error while importing customizer settings.
166
+
167
+ v1.3.2 - 1-April-2019
168
+ - Improvement: One click install and activate Astra theme on click on admin notice.
169
+
170
+ v1.3.1 - 28-March-2019
171
+ - Improvement: Set the max height for the website image from the website preview window.
172
+
173
+ v1.3.0 - 26-March-2019
174
+ - 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.
175
+ - New: Display page builder selection only once on the first load of Astra Sites.
176
+ - New: Take a backup of customizer options before importing new settings.
177
+ - New: Allow to reset the previously imported site when importing multiple Astra sites.
178
+
179
+ v1.2.15 - 14-March-2019
180
+ - Improvement: Admin page UI improvements.
181
+ - Improvement: Added filter `astra_sites_page_title` to change the page title.
182
+
183
+ v1.2.14 - 13-March-2019
184
+ - Improvement: Added support for the WPForms plugin.
185
+
186
+ v1.2.13 - 12-March-2019
187
+ - Improvement: Improved logic to download images in the Elementor templates.
188
+ - Improvement: Added description of the Agency sites when license is not activated.
189
+ - Fix: Incorrect images was set after batch process complete.
190
+
191
+ v1.2.12 - 29-Jan-2019
192
+ - Fix: Gutenberg render markup is invalid due to encoded characterless e.g. <, > are decoded into HTML tag.
193
+
194
+ v1.2.11 - 24-Jan-2019
195
+ - Improvement: Display a maintenance message if the Astra Sites API is unreachable.
196
+ - Fix: EventSource abort the import process if default charset is not UTF-8.
197
+
198
+ v1.2.10 - 4-Jan-2019
199
+ - Fix: Astra Sites not accessible due to incorrect query parameters.
200
+
201
+ v1.2.9 - 17-Dec-2018
202
+ - Fix: XML not import due to getting different MIME file types on different PHP versions.
203
+
204
+ v1.2.8 - 14-Dec-2018
205
+ - Improvement: Added admin notice if XMLReader is not installed. XMLReader is required to import the XML of the website.
206
+ - Fix: XML not import due to improved verification of MIME file types in WordPress v5.0.1.
207
+
208
+ v1.2.7 - 12-July-2018
209
+ - Improvement: Added page builder and category filter support to show selected page builder with selected categories.
210
+ - Improvement: Added filter `astra_sites_show_filters` to enable/disable the filter list from admin page.
211
+
212
+ v1.2.6 - 9-July-2018
213
+ - 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.
214
+
215
+ v1.2.5 - 5-July-2018
216
+ - Fix: Normalize Elementor post meta by using `wp_slash` to avoid the unslashing data.
217
+
218
+ v1.2.4 - 29-June-2018
219
+ - Improvement: Removed custom license validation form and used Graupi in-build license validation form.
220
+ - Improvement: Set default page builders depends on the packaged purchase.
221
+
222
+ v1.2.3 - 13-June-2018
223
+ - Improvement: Added windows EDGE browser support for importing the sites.
224
+ - Improvement: The log file was not created if server does not support the file handling functions.
225
+ - Fix: Load WXR importer on init to avoid redirect loop when loading WooCommerce importer.
226
+ - Fix: Clear the Astra Pro plugin cache after site import.
227
+
228
+ v1.2.2 - 26-March-2018
229
+ - Fix: Correctly load the Elementor Pro 2.0 compatibility class for beta versions.
230
+
231
+ v1.2.1 - 23-March-2018
232
+ - Improvement: Clear the Astra Pro plugin cache after site import.
233
+
234
+ v1.2.0 - 22-March-2018
235
+ - Improvement: Added compatibility for Elemetor version 2.0.0. Older versions throw the PHP warning for function process_element_export_import_content().
236
+
237
+ v1.1.9 - 12-March-2018
238
+ - Fix: String `Select Your Favorite Page Builder` jerk while loading the sites.
239
+
240
+ v1.1.8 - 5-March-2018
241
+ - Improvements: Updated processing button animation while installation/activating plugin and importing site.
242
+ - Improvements: Updated suggestion box message.
243
+ - Fix: PHP fatal errors for WXR importer classes `WXR_Import_Info`, `WXR_Importer`, `WP_Importer_Logger_ServerSentEvents` and `WP_Importer_Logger`.
244
+
245
+ v1.1.7 - 2-February-2018
246
+ - 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.
247
+
248
+ v1.1.6 - 22-January-2018
249
+ - New: Added filter `astra_sites_xml_import_options` to change the XML import options.
250
+ - Fix: Astra Pro plugin 'Custom Layouts' & 'Page Headers' not setting right display location due to different page, tax, category ids.
251
+ - Fix: WooCommerce shop, checkout cart page ids not setting issue.
252
+ - Fix: After site import updated demo url from the nav menus.
253
+
254
+ v1.1.5 - 11-January-2018
255
+ - New: Added SVG file support for importing the SVG images.
256
+
257
+ v1.1.4 - 28-Dec-2017
258
+ - Improvement: Importing WooCommerce product category images.
259
+ - Improvement: Retain WooCommerce cart, checkout & my account pages when importing the ready WooCommerce sites.
260
+ - Fix: Disabled WooCommerce plugin setup wizard after plugin install & activate.
261
+
262
+ v1.1.3 - 20-Dec-2017
263
+ - Improvement: Retain WooCommerce shop page when importing the ready WooCommerce sites.
264
+
265
+ v1.1.2 - 24-Nov-2017
266
+ - Fix: Handling plugin installation errors.
267
+
268
+ v1.1.1 - 23-Nov-2017
269
+ - New: Change the api url for Astra sites to https://websitedemos.net/ from https://sites.wpastra.com/
270
+
271
+ v1.1.0 - 21-Nov-2017
272
+ - New: Import the site content using Event Source (SSE) which ensures faithful imports.
273
+ - New: Divided the site import process in separate AJAX calls to reduce the possibility of timeouts.
274
+ - New: Generated the import log file. It will be displayed in the UI if the import fails.
275
+ - Improvement: Validate all the possible errors.
276
+ - Improvement: Updated Astra sites HTML grid structure for WordPress v4.9 compatibility.
277
+ - Enhancement: Updated plugin name from Astra Sites - Lite with Astra Starter Sites.
278
+
279
+ v1.0.14 - 9-Nov-2017
280
+ - New: All the linked images on the Astra Sites will be downloaded to your site, No more loading images from external URLs.
281
+ - New: Added suggestion box at as the last column in when listing sites so that you can add a suggest the sites you want.
282
+ - New: Added site responsive preview buttons.
283
+ - Improvement: Search string will not be removed when switching the page builder when scrolling through sites.
284
+ - Improvement: Loading 15 sites instead of 6 Astra sites in the first load.
285
+ - Improvement: Removed LazyLoad which is not useful in admin back-end for showing Astra Sites.
286
+
287
+ v1.0.13 - 9-Oct-2017
288
+ - New: Browsing the Astra Sites in the Admin panel is not faster with JS rendering.
289
+
290
+ v1.0.12 - 29-Sept-2017
291
+ - New: Added White Label support from <a href="https://wpastra.com/pro/">Astra Pro</a>.
292
+ - Improvement: Don't display sites from both the page builders in the same view.
293
+ - Fix: Astra Sites admin area not working in the Firefox.
294
+
295
+ v1.0.11 - 22-Sept-2017
296
+ - New: Single click Install & activate required plugins.
297
+ - New: Added filter `astra_sites_menu_item` for adding extra tabs in admin page.
298
+ - New: Added back image import feature for `elementor` page builder. In batch image import we import all images from astra site into client site.
299
+ - Improvement: Updated JS code with object prototype.
300
+ - Fix: Screen bounce on retina devices.
301
+
302
+ v1.0.10 - 11-Sept-2017
303
+ - Improvement: Added support for retina logo import.
304
+ - Fix: Site logo image not displayed in customizer.
305
+ - Fix: Updated `Astra Agency` purchase link.
306
+
307
+ v1.0.9 - 8-Sept-2017
308
+ - New: Added page builder categories for listing sites as per page builder.
309
+
310
+ v1.0.8 - 6-Sept-2017
311
+ - Fix: Beaver Builder option import.
312
+ - Enhancement: Disabled dismiss-able notice visible once for each user.
313
+ - Enhancement: Showing error message for for user who have not `manage_plugins` capability.
314
+
315
+ v1.0.7 - 1-Sept-2017
316
+ - Fix: Custom Menu widget not setting imported widget.
317
+
318
+ v1.0.6 - 30-Aug-2017
319
+ - New: Addd custom menu for Astra Sites.
320
+ - Fix: Validate site options before storing in database.
321
+
322
+ v1.0.5 - 29-Aug-2017
323
+ - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
324
+ - Enhancement: Plugin name updated from `Astra Sites` with `Astra Free Sites`.
325
+ - Fix: PHP error while ignoring users.
326
+
327
+ v1.0.4 - 21-Aug-2017
328
+ - New: Added filter `astra_sites_api_params` for adding extra params in api call.
329
+ - New: Added filter `astra_sites_api_args` for adding extra arguments in api call.
330
+ - New: Added filter `astra_sites_category_hide_empty` for showing categories which are not set for any site.
331
+
332
+ v1.0.3 - 11-Aug-2017
333
+ - Fix: Avoided Astra users from site import process.
334
+
335
+ v1.0.2 - 09-Aug-2017
336
+ - Fix: Listing appropriate next and previous Astra sites.
337
+ - Enhancement: Listing Astra sites though AJAX API call.
338
+
339
+ v1.0.1 - 04-Aug-2017
340
+ - New: Added Elementor plugin options support.
341
+ - New: Added Customizer CSS support.
342
+ - Enhancement: Avoided Lite Plugin version if Pro version is Installed. Now added support for Beaver Builder Plugin (Lite Version).
343
+ - Enhancement: Astra sites API call validated before import.
344
+ - Enhancement: Site logo imported from Astra sites.
345
+ - Fix: Bug where widgets created with SiteOrigin plugin were not being imported.
346
+
347
+ v1.0.0
348
+ - Initial release