ThemeGrill Demo Importer - Version 1.0

Version Description

Download this release

Release Info

Developer ThemeGrill
Plugin Icon 128x128 ThemeGrill Demo Importer
Version 1.0
Comparing to
See all releases

Version 1.0

Files changed (30) hide show
  1. assets/css/demo-importer.css +1 -0
  2. assets/css/demo-importer.scss +154 -0
  3. assets/images/colormag/colormag-free.jpg +0 -0
  4. assets/images/flash/flash-construction.jpg +0 -0
  5. assets/images/flash/flash-default.jpg +0 -0
  6. assets/images/flash/flash-food.jpg +0 -0
  7. assets/images/flash/flash-onepage.jpg +0 -0
  8. assets/images/spacious/spacious-free.jpg +0 -0
  9. assets/js/admin/demo-importer.js +96 -0
  10. assets/js/admin/demo-importer.min.js +1 -0
  11. assets/js/jquery-tiptip/jquery.tipTip.js +191 -0
  12. assets/js/jquery-tiptip/jquery.tipTip.min.js +1 -0
  13. includes/class-demo-importer.php +690 -0
  14. includes/includes/admin/class-demo-installer-skin.php +64 -0
  15. includes/includes/admin/class-demo-upgrader.php +349 -0
  16. includes/includes/admin/views/html-admin-page-importer-previews.php +40 -0
  17. includes/includes/admin/views/html-admin-page-importer-uploaded.php +72 -0
  18. includes/includes/admin/views/html-admin-page-importer-welcome.php +29 -0
  19. includes/includes/admin/views/html-admin-page-importer.php +63 -0
  20. includes/includes/class-customizer-importer.php +176 -0
  21. includes/includes/class-widget-importer.php +237 -0
  22. includes/includes/customize/class-oc-customize-demo-importer-setting.php +24 -0
  23. includes/includes/functions-demo-importer.php +272 -0
  24. includes/includes/importers/class-wxr-importer.php +1232 -0
  25. includes/includes/importers/class-wxr-parsers.php +693 -0
  26. languages/themegrill-demo-importer.pot +485 -0
  27. license.txt +702 -0
  28. readme.txt +44 -0
  29. themegrill-demo-importer.php +190 -0
  30. uninstall.php +18 -0
assets/css/demo-importer.css ADDED
@@ -0,0 +1 @@
 
1
+ .appearance_page_demo-importer .wp-filter{padding:0 20px}.appearance_page_demo-importer .wp-filter .filter-links li>a:focus{box-shadow:none}.theme-browser .theme .theme-actions span.spinner{display:none}.theme-browser .theme .theme-actions.imported,.theme-browser .theme .theme-actions.importing{opacity:1}.theme-browser .theme .theme-actions.imported .button,.theme-browser .theme .theme-actions.importing .button,.theme-browser .theme:not(.active) .theme-actions .preview{display:none;visibility:hidden}.theme-browser .theme:not(.active) .theme-actions.imported .preview{display:block;visibility:visible}.theme-browser .theme .theme-actions.importing span.spinner.is-active{width:auto;display:block;font-size:12px;padding-right:25px;background-position:right center}@media only screen and (max-width:780px){.theme-browser .theme .theme-actions.imported{opacity:0}}.theme .notice,.theme .notice.is-dismissible{left:0;margin:0;position:absolute;right:0;top:0}.theme .notice-success p::before{color:#79ba49;content:'\f147';margin-right:6px;vertical-align:top;display:inline-block;font:400 20px/1 dashicons;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.tips{cursor:help;text-decoration:none}img.tips{padding:5px 0 0}#tiptip_holder{display:none;position:absolute;top:0;left:0;z-index:9999999}#tiptip_holder.tip_top{padding-bottom:5px}#tiptip_holder.tip_top #tiptip_arrow_inner{margin-top:-7px;margin-left:-6px;border-top-color:#333}#tiptip_holder.tip_bottom{padding-top:5px}#tiptip_holder.tip_bottom #tiptip_arrow_inner{margin-top:-5px;margin-left:-6px;border-bottom-color:#333}#tiptip_holder.tip_right{padding-left:5px}#tiptip_holder.tip_right #tiptip_arrow_inner{margin-top:-6px;margin-left:-5px;border-right-color:#333}#tiptip_holder.tip_left{padding-right:5px}#tiptip_holder.tip_left #tiptip_arrow_inner{margin-top:-6px;margin-left:-7px;border-left-color:#333}#tiptip_content{color:#fff;font-size:.8em;max-width:150px;background:#333;text-align:center;border-radius:3px;padding:.618em 1em;box-shadow:0 1px 3px rgba(0,0,0,.2)}#tiptip_content code{padding:1px;background:#888}#tiptip_arrow,#tiptip_arrow_inner{position:absolute;border-color:transparent;border-style:solid;border-width:6px;height:0;width:0}
assets/css/demo-importer.scss ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Styling begins.
3
+ */
4
+ .appearance_page_demo-importer .wp-filter {
5
+ padding: 0 20px;
6
+
7
+ .filter-links li > a:focus {
8
+ box-shadow: none;
9
+ }
10
+ }
11
+
12
+ .theme-browser .theme .theme-actions span.spinner {
13
+ display: none;
14
+ }
15
+
16
+ .theme-browser .theme .theme-actions.imported,
17
+ .theme-browser .theme .theme-actions.importing {
18
+ opacity: 1;
19
+ }
20
+
21
+ .theme-browser .theme .theme-actions.imported .button,
22
+ .theme-browser .theme .theme-actions.importing .button,
23
+ .theme-browser .theme:not( .active ) .theme-actions .preview {
24
+ display: none;
25
+ visibility: hidden;
26
+ }
27
+
28
+ .theme-browser .theme:not( .active ) .theme-actions.imported .preview {
29
+ display: block;
30
+ visibility: visible;
31
+ }
32
+
33
+ .theme-browser .theme .theme-actions.importing span.spinner.is-active {
34
+ width: auto;
35
+ display: block;
36
+ font-size: 12px;
37
+ padding-right: 25px;
38
+ background-position: right center;
39
+ }
40
+
41
+ @media only screen and (max-width: 780px) {
42
+ .theme-browser .theme .theme-actions.imported {
43
+ opacity: 0;
44
+ }
45
+ }
46
+
47
+ /* Position admin messages */
48
+ .theme .notice,
49
+ .theme .notice.is-dismissible {
50
+ left: 0;
51
+ margin: 0;
52
+ position: absolute;
53
+ right: 0;
54
+ top: 0;
55
+ }
56
+
57
+ .theme .notice-success p::before {
58
+ color: #79ba49;
59
+ content: '\f147';
60
+ margin-right: 6px;
61
+ vertical-align: top;
62
+ display: inline-block;
63
+ font: normal 20px/1 'dashicons';
64
+ -webkit-font-smoothing: antialiased;
65
+ -moz-osx-font-smoothing: grayscale;
66
+ }
67
+
68
+ /**
69
+ * Tooltips
70
+ */
71
+ .tips {
72
+ cursor: help;
73
+ text-decoration: none;
74
+ }
75
+
76
+ img.tips {
77
+ padding: 5px 0 0;
78
+ }
79
+
80
+ #tiptip_holder {
81
+ display: none;
82
+ position: absolute;
83
+ top: 0;
84
+ left: 0;
85
+ z-index: 9999999;
86
+ }
87
+
88
+ #tiptip_holder {
89
+ &.tip_top {
90
+ padding-bottom: 5px;
91
+
92
+ #tiptip_arrow_inner {
93
+ margin-top: -7px;
94
+ margin-left: -6px;
95
+ border-top-color: #333;
96
+ }
97
+ }
98
+
99
+ &.tip_bottom {
100
+ padding-top: 5px;
101
+
102
+ #tiptip_arrow_inner {
103
+ margin-top: -5px;
104
+ margin-left: -6px;
105
+ border-bottom-color: #333;
106
+ }
107
+ }
108
+
109
+ &.tip_right {
110
+ padding-left: 5px;
111
+
112
+ #tiptip_arrow_inner {
113
+ margin-top: -6px;
114
+ margin-left: -5px;
115
+ border-right-color: #333;
116
+ }
117
+ }
118
+
119
+ &.tip_left {
120
+ padding-right: 5px;
121
+
122
+ #tiptip_arrow_inner {
123
+ margin-top: -6px;
124
+ margin-left: -7px;
125
+ border-left-color: #333;
126
+ }
127
+ }
128
+ }
129
+
130
+ #tiptip_content {
131
+ color: #fff;
132
+ font-size: 0.8em;
133
+ max-width: 150px;
134
+ background: #333;
135
+ text-align: center;
136
+ border-radius: 3px;
137
+ padding: 0.618em 1em;
138
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
139
+
140
+ code {
141
+ padding: 1px;
142
+ background: #888;
143
+ }
144
+ }
145
+
146
+ #tiptip_arrow,
147
+ #tiptip_arrow_inner {
148
+ position: absolute;
149
+ border-color: transparent;
150
+ border-style: solid;
151
+ border-width: 6px;
152
+ height: 0;
153
+ width: 0;
154
+ }
assets/images/colormag/colormag-free.jpg ADDED
Binary file
assets/images/flash/flash-construction.jpg ADDED
Binary file
assets/images/flash/flash-default.jpg ADDED
Binary file
assets/images/flash/flash-food.jpg ADDED
Binary file
assets/images/flash/flash-onepage.jpg ADDED
Binary file
assets/images/spacious/spacious-free.jpg ADDED
Binary file
assets/js/admin/demo-importer.js ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* global demo_importer_params */
2
+ jQuery( function ( $ ) {
3
+
4
+ var tg_demo_importer = {
5
+ init: function() {
6
+ this.uploader();
7
+ this.init_tiptip();
8
+
9
+ // Trigger importer events.
10
+ $( '.theme-actions' ).on( 'click', '.import', this.process_import );
11
+ $( '.notice.is-dismissible' ).on( 'click', '.notice-dismiss', this.dismiss_notice );
12
+ },
13
+ uploader: function() {
14
+ var uploadViewToggle = $( '.upload-view-toggle' ),
15
+ $body = $( document.body );
16
+
17
+ uploadViewToggle.on( 'click', function() {
18
+ // Toggle the upload view.
19
+ $body.toggleClass( 'show-upload-view' );
20
+ // Toggle the `aria-expanded` button attribute.
21
+ uploadViewToggle.attr( 'aria-expanded', $body.hasClass( 'show-upload-view' ) );
22
+ });
23
+ },
24
+ init_tiptip: function() {
25
+ $( '#tiptip_holder' ).removeAttr( 'style' );
26
+ $( '#tiptip_arrow' ).removeAttr( 'style' );
27
+ $( '.tips' ).tipTip({ 'attribute': 'data-tip', 'fadeIn': 50, 'fadeOut': 50, 'delay': 200 });
28
+ },
29
+ process_import: function( e ) {
30
+ e.preventDefault();
31
+
32
+ var $this_el = $( this );
33
+
34
+ if ( ! $this_el.hasClass( 'disabled' ) ) {
35
+ if ( window.confirm( demo_importer_params.i18n_import_dummy_data ) ) {
36
+
37
+ var data = {
38
+ action: 'tg_import_demo_data',
39
+ demo_id: $this_el.data( 'demo_id' ),
40
+ security: demo_importer_params.import_demo_data_nonce
41
+ };
42
+
43
+ $.ajax({
44
+ url: demo_importer_params.ajax_url,
45
+ data: data,
46
+ type: 'POST',
47
+ beforeSend: function() {
48
+ $this_el.parent().addClass( 'importing' );
49
+ $this_el.parent().find( '.spinner' ).addClass( 'is-active' );
50
+ },
51
+ success: function( response ) {
52
+ $this_el.closest( '.theme' ).find( '.notice' ).remove();
53
+ $this_el.parent().find( '.spinner' ).removeClass( 'is-active' );
54
+ $this_el.parent().removeClass( 'importing' ).addClass( 'imported' );
55
+
56
+ // Display import message.
57
+ if ( true === response.success ) {
58
+ $this_el.closest( '.theme' ).append( '<div class="notice notice-success notice-alt"><p>' + response.data.message + '</p></div>' );
59
+ } else {
60
+ $this_el.closest( '.theme' ).append( '<div class="update-message notice notice-error notice-alt"><p>' + demo_importer_params.i18n_import_data_error + '</p></div>' );
61
+ }
62
+ },
63
+ error: function( jqXHR, textStatus, errorThrown ) {
64
+ $this_el.closest( '.theme' ).find( '.notice' ).remove();
65
+ $this_el.parent().find( '.spinner' ).removeClass( 'is-active' );
66
+ $this_el.parent().removeClass( 'importing' ).addClass( 'imported' );
67
+
68
+ // Display error message.
69
+ $this_el.closest( '.theme' ).append( '<div class="update-message notice notice-error notice-alt"><p>' + errorThrown + '</p></div>' );
70
+ }
71
+ });
72
+ }
73
+
74
+ return false;
75
+ }
76
+ },
77
+ dismiss_notice: function( e ) {
78
+ e.preventDefault();
79
+
80
+ var $this_el = $( this );
81
+
82
+ if ( $this_el.parent().attr( 'id' ) === 'undefined' ) {
83
+ return;
84
+ }
85
+
86
+ $.post( demo_importer_params.ajax_url, {
87
+ action: 'tg_dismiss_notice',
88
+ notice_id: $this_el.parent().data( 'notice_id' )
89
+ });
90
+
91
+ return false;
92
+ }
93
+ };
94
+
95
+ tg_demo_importer.init();
96
+ });
assets/js/admin/demo-importer.min.js ADDED
@@ -0,0 +1 @@
 
1
+ jQuery(function(a){var b={init:function(){this.uploader(),this.init_tiptip(),a(".theme-actions").on("click",".import",this.process_import),a(".notice.is-dismissible").on("click",".notice-dismiss",this.dismiss_notice)},uploader:function(){var b=a(".upload-view-toggle"),c=a(document.body);b.on("click",function(){c.toggleClass("show-upload-view"),b.attr("aria-expanded",c.hasClass("show-upload-view"))})},init_tiptip:function(){a("#tiptip_holder").removeAttr("style"),a("#tiptip_arrow").removeAttr("style"),a(".tips").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200})},process_import:function(b){b.preventDefault();var c=a(this);if(!c.hasClass("disabled")){if(window.confirm(demo_importer_params.i18n_import_dummy_data)){var d={action:"tg_import_demo_data",demo_id:c.data("demo_id"),security:demo_importer_params.import_demo_data_nonce};a.ajax({url:demo_importer_params.ajax_url,data:d,type:"POST",beforeSend:function(){c.parent().addClass("importing"),c.parent().find(".spinner").addClass("is-active")},success:function(a){c.closest(".theme").find(".notice").remove(),c.parent().find(".spinner").removeClass("is-active"),c.parent().removeClass("importing").addClass("imported"),!0===a.success?c.closest(".theme").append('<div class="notice notice-success notice-alt"><p>'+a.data.message+"</p></div>"):c.closest(".theme").append('<div class="update-message notice notice-error notice-alt"><p>'+demo_importer_params.i18n_import_data_error+"</p></div>")},error:function(a,b,d){c.closest(".theme").find(".notice").remove(),c.parent().find(".spinner").removeClass("is-active"),c.parent().removeClass("importing").addClass("imported"),c.closest(".theme").append('<div class="update-message notice notice-error notice-alt"><p>'+d+"</p></div>")}})}return!1}},dismiss_notice:function(b){b.preventDefault();var c=a(this);if("undefined"!==c.parent().attr("id"))return a.post(demo_importer_params.ajax_url,{action:"tg_dismiss_notice",notice_id:c.parent().data("notice_id")}),!1}};b.init()});
assets/js/jquery-tiptip/jquery.tipTip.js ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * TipTip
3
+ * Copyright 2010 Drew Wilson
4
+ * www.drewwilson.com
5
+ * code.drewwilson.com/entry/tiptip-jquery-plugin
6
+ *
7
+ * Version 1.3 - Updated: Mar. 23, 2010
8
+ *
9
+ * This Plug-In will create a custom tooltip to replace the default
10
+ * browser tooltip. It is extremely lightweight and very smart in
11
+ * that it detects the edges of the browser window and will make sure
12
+ * the tooltip stays within the current window size. As a result the
13
+ * tooltip will adjust itself to be displayed above, below, to the left
14
+ * or to the right depending on what is necessary to stay within the
15
+ * browser window. It is completely customizable as well via CSS.
16
+ *
17
+ * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
18
+ * http://www.opensource.org/licenses/mit-license.php
19
+ * http://www.gnu.org/licenses/gpl.html
20
+ */
21
+
22
+ (function($){
23
+ $.fn.tipTip = function(options) {
24
+ var defaults = {
25
+ activation: "hover",
26
+ keepAlive: false,
27
+ maxWidth: "200px",
28
+ edgeOffset: 3,
29
+ defaultPosition: "bottom",
30
+ delay: 400,
31
+ fadeIn: 200,
32
+ fadeOut: 200,
33
+ attribute: "title",
34
+ content: false, // HTML or String to fill TipTIp with
35
+ enter: function(){},
36
+ exit: function(){}
37
+ };
38
+ var opts = $.extend(defaults, options);
39
+
40
+ // Setup tip tip elements and render them to the DOM
41
+ if($("#tiptip_holder").length <= 0){
42
+ var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
43
+ var tiptip_content = $('<div id="tiptip_content"></div>');
44
+ var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
45
+ $("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
46
+ } else {
47
+ var tiptip_holder = $("#tiptip_holder");
48
+ var tiptip_content = $("#tiptip_content");
49
+ var tiptip_arrow = $("#tiptip_arrow");
50
+ }
51
+
52
+ return this.each(function(){
53
+ var org_elem = $(this);
54
+ if(opts.content){
55
+ var org_title = opts.content;
56
+ } else {
57
+ var org_title = org_elem.attr(opts.attribute);
58
+ }
59
+ if(org_title != ""){
60
+ if(!opts.content){
61
+ org_elem.removeAttr(opts.attribute); //remove original Attribute
62
+ }
63
+ var timeout = false;
64
+
65
+ if(opts.activation == "hover"){
66
+ org_elem.hover(function(){
67
+ active_tiptip();
68
+ }, function(){
69
+ if(!opts.keepAlive){
70
+ deactive_tiptip();
71
+ }
72
+ });
73
+ if(opts.keepAlive){
74
+ tiptip_holder.hover(function(){}, function(){
75
+ deactive_tiptip();
76
+ });
77
+ }
78
+ } else if(opts.activation == "focus"){
79
+ org_elem.focus(function(){
80
+ active_tiptip();
81
+ }).blur(function(){
82
+ deactive_tiptip();
83
+ });
84
+ } else if(opts.activation == "click"){
85
+ org_elem.click(function(){
86
+ active_tiptip();
87
+ return false;
88
+ }).hover(function(){},function(){
89
+ if(!opts.keepAlive){
90
+ deactive_tiptip();
91
+ }
92
+ });
93
+ if(opts.keepAlive){
94
+ tiptip_holder.hover(function(){}, function(){
95
+ deactive_tiptip();
96
+ });
97
+ }
98
+ }
99
+
100
+ function active_tiptip(){
101
+ opts.enter.call(this);
102
+ tiptip_content.html(org_title);
103
+ tiptip_holder.hide().removeAttr("class").css("margin","0");
104
+ tiptip_arrow.removeAttr("style");
105
+
106
+ var top = parseInt(org_elem.offset()['top']);
107
+ var left = parseInt(org_elem.offset()['left']);
108
+ var org_width = parseInt(org_elem.outerWidth());
109
+ var org_height = parseInt(org_elem.outerHeight());
110
+ var tip_w = tiptip_holder.outerWidth();
111
+ var tip_h = tiptip_holder.outerHeight();
112
+ var w_compare = Math.round((org_width - tip_w) / 2);
113
+ var h_compare = Math.round((org_height - tip_h) / 2);
114
+ var marg_left = Math.round(left + w_compare);
115
+ var marg_top = Math.round(top + org_height + opts.edgeOffset);
116
+ var t_class = "";
117
+ var arrow_top = "";
118
+ var arrow_left = Math.round(tip_w - 12) / 2;
119
+
120
+ if(opts.defaultPosition == "bottom"){
121
+ t_class = "_bottom";
122
+ } else if(opts.defaultPosition == "top"){
123
+ t_class = "_top";
124
+ } else if(opts.defaultPosition == "left"){
125
+ t_class = "_left";
126
+ } else if(opts.defaultPosition == "right"){
127
+ t_class = "_right";
128
+ }
129
+
130
+ var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
131
+ var left_compare = (tip_w + left) > parseInt($(window).width());
132
+
133
+ if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){
134
+ t_class = "_right";
135
+ arrow_top = Math.round(tip_h - 13) / 2;
136
+ arrow_left = -12;
137
+ marg_left = Math.round(left + org_width + opts.edgeOffset);
138
+ marg_top = Math.round(top + h_compare);
139
+ } else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)){
140
+ t_class = "_left";
141
+ arrow_top = Math.round(tip_h - 13) / 2;
142
+ arrow_left = Math.round(tip_w);
143
+ marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
144
+ marg_top = Math.round(top + h_compare);
145
+ }
146
+
147
+ var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
148
+ var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;
149
+
150
+ if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){
151
+ if(t_class == "_top" || t_class == "_bottom"){
152
+ t_class = "_top";
153
+ } else {
154
+ t_class = t_class+"_top";
155
+ }
156
+ arrow_top = tip_h;
157
+ marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
158
+ } else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)){
159
+ if(t_class == "_top" || t_class == "_bottom"){
160
+ t_class = "_bottom";
161
+ } else {
162
+ t_class = t_class+"_bottom";
163
+ }
164
+ arrow_top = -12;
165
+ marg_top = Math.round(top + org_height + opts.edgeOffset);
166
+ }
167
+
168
+ if(t_class == "_right_top" || t_class == "_left_top"){
169
+ marg_top = marg_top + 5;
170
+ } else if(t_class == "_right_bottom" || t_class == "_left_bottom"){
171
+ marg_top = marg_top - 5;
172
+ }
173
+ if(t_class == "_left_top" || t_class == "_left_bottom"){
174
+ marg_left = marg_left + 5;
175
+ }
176
+ tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"});
177
+ tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class);
178
+
179
+ if (timeout){ clearTimeout(timeout); }
180
+ timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay);
181
+ }
182
+
183
+ function deactive_tiptip(){
184
+ opts.exit.call(this);
185
+ if (timeout){ clearTimeout(timeout); }
186
+ tiptip_holder.fadeOut(opts.fadeOut);
187
+ }
188
+ }
189
+ });
190
+ }
191
+ })(jQuery);
assets/js/jquery-tiptip/jquery.tipTip.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(a){a.fn.tipTip=function(b){var c={activation:"hover",keepAlive:!1,maxWidth:"200px",edgeOffset:3,defaultPosition:"bottom",delay:400,fadeIn:200,fadeOut:200,attribute:"title",content:!1,enter:function(){},exit:function(){}},d=a.extend(c,b);if(a("#tiptip_holder").length<=0){var e=a('<div id="tiptip_holder" style="max-width:'+d.maxWidth+';"></div>'),f=a('<div id="tiptip_content"></div>'),g=a('<div id="tiptip_arrow"></div>');a("body").append(e.html(f).prepend(g.html('<div id="tiptip_arrow_inner"></div>')))}else var e=a("#tiptip_holder"),f=a("#tiptip_content"),g=a("#tiptip_arrow");return this.each(function(){function b(){d.enter.call(this),f.html(i),e.hide().removeAttr("class").css("margin","0"),g.removeAttr("style");var b=parseInt(h.offset().top),c=parseInt(h.offset().left),k=parseInt(h.outerWidth()),l=parseInt(h.outerHeight()),m=e.outerWidth(),n=e.outerHeight(),o=Math.round((k-m)/2),p=Math.round((l-n)/2),q=Math.round(c+o),r=Math.round(b+l+d.edgeOffset),s="",t="",u=Math.round(m-12)/2;"bottom"==d.defaultPosition?s="_bottom":"top"==d.defaultPosition?s="_top":"left"==d.defaultPosition?s="_left":"right"==d.defaultPosition&&(s="_right");var v=o+c<parseInt(a(window).scrollLeft()),w=m+c>parseInt(a(window).width());v&&o<0||"_right"==s&&!w||"_left"==s&&c<m+d.edgeOffset+5?(s="_right",t=Math.round(n-13)/2,u=-12,q=Math.round(c+k+d.edgeOffset),r=Math.round(b+p)):(w&&o<0||"_left"==s&&!v)&&(s="_left",t=Math.round(n-13)/2,u=Math.round(m),q=Math.round(c-(m+d.edgeOffset+5)),r=Math.round(b+p));var x=b+l+d.edgeOffset+n+8>parseInt(a(window).height()+a(window).scrollTop()),y=b+l-(d.edgeOffset+n+8)<0;x||"_bottom"==s&&x||"_top"==s&&!y?("_top"==s||"_bottom"==s?s="_top":s+="_top",t=n,r=Math.round(b-(n+5+d.edgeOffset))):(y|("_top"==s&&y)||"_bottom"==s&&!x)&&("_top"==s||"_bottom"==s?s="_bottom":s+="_bottom",t=-12,r=Math.round(b+l+d.edgeOffset)),"_right_top"==s||"_left_top"==s?r+=5:"_right_bottom"!=s&&"_left_bottom"!=s||(r-=5),"_left_top"!=s&&"_left_bottom"!=s||(q+=5),g.css({"margin-left":u+"px","margin-top":t+"px"}),e.css({"margin-left":q+"px","margin-top":r+"px"}).attr("class","tip"+s),j&&clearTimeout(j),j=setTimeout(function(){e.stop(!0,!0).fadeIn(d.fadeIn)},d.delay)}function c(){d.exit.call(this),j&&clearTimeout(j),e.fadeOut(d.fadeOut)}var h=a(this);if(d.content)var i=d.content;else var i=h.attr(d.attribute);if(""!=i){d.content||h.removeAttr(d.attribute);var j=!1;"hover"==d.activation?(h.hover(function(){b()},function(){d.keepAlive||c()}),d.keepAlive&&e.hover(function(){},function(){c()})):"focus"==d.activation?h.focus(function(){b()}).blur(function(){c()}):"click"==d.activation&&(h.click(function(){return b(),!1}).hover(function(){},function(){d.keepAlive||c()}),d.keepAlive&&e.hover(function(){},function(){c()}))}})}}(jQuery);
includes/class-demo-importer.php ADDED
@@ -0,0 +1,690 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ThemeGrill Demo Importer.
4
+ *
5
+ * @class TG_Demo_Importer
6
+ * @version 1.0.0
7
+ * @package Importer/Classes
8
+ * @category Admin
9
+ * @author ThemeGrill
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) {
13
+ exit;
14
+ }
15
+
16
+ /**
17
+ * TG_Demo_Importer Class.
18
+ */
19
+ class TG_Demo_Importer {
20
+
21
+ /**
22
+ * Demo config.
23
+ * @var array
24
+ */
25
+ public $demo_config;
26
+
27
+ /**
28
+ * Demo packages.
29
+ * @var array
30
+ */
31
+ public $demo_packages;
32
+
33
+ /**
34
+ * Constructor.
35
+ */
36
+ public function __construct() {
37
+ add_action( 'init', array( $this, 'setup' ), 5 );
38
+ add_action( 'init', array( $this, 'includes' ) );
39
+
40
+ // Add Demo Importer menu.
41
+ if ( apply_filters( 'themegrill_show_demo_importer_page', true ) ) {
42
+ add_action( 'admin_menu', array( $this, 'demo_importer_menu' ) );
43
+ }
44
+
45
+ // Add Demo Importer filterable content.
46
+ add_action( 'themegrill_demo_importer_welcome', array( $this, 'welcome_panel' ) );
47
+ add_action( 'themegrill_demo_importer_uploaded', array( $this, 'output_uploaded' ) );
48
+ add_action( 'themegrill_demo_importer_previews', array( $this, 'output_previews' ) );
49
+
50
+ // AJAX Events to dismiss notice and import demo data.
51
+ add_action( 'wp_ajax_tg_dismiss_notice', array( $this, 'dismissible_notice' ) );
52
+ add_action( 'wp_ajax_tg_import_demo_data', array( $this, 'import_demo_data' ) );
53
+
54
+ // Update custom nav menu items and siteorigin panel data.
55
+ add_action( 'themegrill_ajax_demo_imported', array( $this, 'update_nav_menu_items' ) );
56
+ add_action( 'themegrill_ajax_demo_imported', array( $this, 'update_siteorigin_data' ), 10, 2 );
57
+
58
+ // Update widget and customizer demo import settings data.
59
+ add_filter( 'themegrill_widget_demo_import_settings', array( $this, 'update_widget_data' ), 10, 4 );
60
+ add_filter( 'themegrill_customizer_demo_import_settings', array( $this, 'update_customizer_data' ), 10, 2 );
61
+ }
62
+
63
+ /**
64
+ * Demo importer setup.
65
+ */
66
+ public function setup() {
67
+ $this->demo_config = apply_filters( 'themegrill_demo_importer_config', array() );
68
+ $this->demo_packages = apply_filters( 'themegrill_demo_importer_packages', array() );
69
+ }
70
+
71
+ /**
72
+ * Include required core files.
73
+ */
74
+ public function includes() {
75
+ include_once( dirname( __FILE__ ) . '/includes/functions-demo-importer.php' );
76
+ include_once( dirname( __FILE__ ) . '/includes/class-customizer-importer.php' );
77
+ include_once( dirname( __FILE__ ) . '/includes/class-widget-importer.php' );
78
+ }
79
+
80
+ /**
81
+ * Get the import file URL.
82
+ *
83
+ * @param string $demo_dir demo dir.
84
+ * @param string $filename import filename.
85
+ * @return string the demo import data file URL.
86
+ */
87
+ private function import_file_url( $demo_dir, $filename ) {
88
+ $working_dir = tg_get_demo_file_url( $demo_dir );
89
+
90
+ // If enabled demo pack, load from upload dir.
91
+ if ( $this->is_enabled_demo_pack( $demo_dir ) ) {
92
+ $upload_dir = wp_upload_dir();
93
+ $working_dir = $upload_dir['baseurl'] . '/tg-demo-pack/' . $demo_dir;
94
+ }
95
+
96
+ return trailingslashit( $working_dir ) . sanitize_file_name( $filename );
97
+ }
98
+
99
+ /**
100
+ * Get the import file path.
101
+ *
102
+ * @param string $demo_dir demo dir.
103
+ * @param string $filename import filename.
104
+ * @return string the import data file path.
105
+ */
106
+ private function import_file_path( $demo_dir, $filename ) {
107
+ $working_dir = tg_get_demo_file_path( $demo_dir );
108
+
109
+ // If enabled demo pack, load from upload dir.
110
+ if ( $this->is_enabled_demo_pack( $demo_dir ) ) {
111
+ $upload_dir = wp_upload_dir();
112
+ $working_dir = $upload_dir['basedir'] . '/tg-demo-pack/' . $demo_dir . '/dummy-data';
113
+ }
114
+
115
+ return trailingslashit( $working_dir ) . sanitize_file_name( $filename );
116
+ }
117
+
118
+ /**
119
+ * Check if demo pack is enabled.
120
+ * @param array $demo_id
121
+ * @return bool
122
+ */
123
+ public function is_enabled_demo_pack( $demo_id ) {
124
+ if ( isset( $this->demo_config[ $demo_id ]['demo_pack'] ) && true === $this->demo_config[ $demo_id ]['demo_pack'] ) {
125
+ return true;
126
+ }
127
+
128
+ return false;
129
+ }
130
+
131
+ /**
132
+ * Add menu item.
133
+ */
134
+ public function demo_importer_menu() {
135
+ $page = add_theme_page( __( 'Demo Importer', 'themegrill-demo-importer' ), __( 'Demo Importer', 'themegrill-demo-importer' ), 'switch_themes', 'demo-importer', array( $this, 'demo_importer' ) );
136
+ add_action( 'admin_print_styles-' . $page, array( $this, 'enqueue_styles' ) );
137
+ }
138
+
139
+ /**
140
+ * Enqueue styles.
141
+ */
142
+ public function enqueue_styles() {
143
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
144
+ $assets_path = tg_get_demo_importer_assets_path();
145
+
146
+ // Register Scripts
147
+ wp_register_script( 'jquery-tiptip', $assets_path . 'js/jquery-tiptip/jquery.tipTip' . $suffix . '.js', array( 'jquery' ), '1.3', true );
148
+
149
+ // Enqueue Scripts
150
+ wp_enqueue_style( 'tg-demo-importer', $assets_path . 'css/demo-importer.css', array() );
151
+ wp_enqueue_script( 'tg-demo-importer', $assets_path . 'js/admin/demo-importer' . $suffix . '.js', array( 'jquery', 'jquery-tiptip' ), '1.0.0' );
152
+
153
+ wp_localize_script( 'tg-demo-importer', 'demo_importer_params', array(
154
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
155
+ 'import_demo_data_nonce' => wp_create_nonce( 'import-demo-data' ),
156
+ 'i18n_import_data_error' => esc_js( __( 'Importing Failed. Try again!', 'themegrill-demo-importer' ) ),
157
+ 'i18n_import_dummy_data' => esc_js( __( 'Importing demo content will replicate the live demo and overwrites your current customizer, widgets and other settings. It might take few minutes to complete the demo import. Are you sure you want to import this demo?', 'themegrill-demo-importer' ) ),
158
+ ) );
159
+ }
160
+
161
+ /**
162
+ * Demo Importer page output.
163
+ */
164
+ public function demo_importer() {
165
+ global $current_tab;
166
+
167
+ $current_tab = empty( $_GET['tab'] ) ? 'welcome' : sanitize_title( $_GET['tab'] );
168
+
169
+ if ( isset( $_GET['action'] ) && 'upload-demo' === $_GET['action'] ) {
170
+ $this->upload_demo_pack();
171
+ } else {
172
+ include_once( dirname( __FILE__ ) . '/includes/admin/views/html-admin-page-importer.php' );
173
+ }
174
+ }
175
+
176
+ /**
177
+ * Output welcome panel page.
178
+ */
179
+ public function welcome_panel() {
180
+ include_once( dirname( __FILE__ ) . '/includes/admin/views/html-admin-page-importer-welcome.php' );
181
+ }
182
+
183
+ /**
184
+ * Output demo uploaded page.
185
+ */
186
+ public function output_uploaded() {
187
+ include_once( dirname( __FILE__ ) . '/includes/admin/views/html-admin-page-importer-uploaded.php' );
188
+ }
189
+
190
+ /**
191
+ * Output demo previews page.
192
+ */
193
+ public function output_previews() {
194
+ include_once( dirname( __FILE__ ) . '/includes/admin/views/html-admin-page-importer-previews.php' );
195
+ }
196
+
197
+ /**
198
+ * Upload demo pack.
199
+ */
200
+ private function upload_demo_pack() {
201
+ include_once( ABSPATH . 'wp-admin/includes/class-wp-upgrader.php' );
202
+
203
+ if ( ! current_user_can( 'upload_files' ) ) {
204
+ wp_die( __( 'Sorry, you are not allowed to install demo on this site.', 'themegrill-demo-importer' ) );
205
+ }
206
+
207
+ check_admin_referer( 'demo-upload' );
208
+
209
+ $file_upload = new File_Upload_Upgrader( 'demozip', 'package' );
210
+
211
+ $title = sprintf( __( 'Installing Demo from uploaded file: %s', 'themegrill-demo-importer' ), esc_html( basename( $file_upload->filename ) ) );
212
+ $nonce = 'demo-upload';
213
+ $url = add_query_arg( array( 'package' => $file_upload->id ), 'themes.php?page=demo-importer&action=upload-demo' );
214
+ $type = 'upload'; // Install demo type, From Web or an Upload.
215
+
216
+ // Demo Upgrader Class.
217
+ include_once( dirname( __FILE__ ) . '/includes/admin/class-demo-upgrader.php' );
218
+ include_once( dirname( __FILE__ ) . '/includes/admin/class-demo-installer-skin.php' );
219
+
220
+ $upgrader = new TG_Demo_Upgrader( new TG_Demo_Installer_Skin( compact( 'type', 'title', 'nonce', 'url' ) ) );
221
+ $result = $upgrader->install( $file_upload->package );
222
+
223
+ if ( $result || is_wp_error( $result ) ) {
224
+ $file_upload->cleanup();
225
+ }
226
+ }
227
+
228
+ /**
229
+ * AJAX Dismissible notice.
230
+ */
231
+ public function dismissible_notice() {
232
+ if ( ! current_user_can( 'manage_options' ) ) {
233
+ die( -1 );
234
+ }
235
+
236
+ $notice_id = sanitize_text_field( stripslashes( $_POST['notice_id'] ) );
237
+
238
+ if ( ! empty( $notice_id ) && 'demo-importer' == $notice_id ) {
239
+ update_option( 'themegrill_demo_imported_notice_dismiss', 1 );
240
+ }
241
+
242
+ die();
243
+ }
244
+
245
+ /**
246
+ * AJAX Import demo/dummy data.
247
+ */
248
+ public function import_demo_data() {
249
+ ob_start();
250
+
251
+ check_ajax_referer( 'import-demo-data', 'security' );
252
+
253
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
254
+ define( 'WP_LOAD_IMPORTERS', true );
255
+ }
256
+
257
+ if ( ! current_user_can( 'manage_options' ) ) {
258
+ die( -1 );
259
+ }
260
+
261
+ $demo_id = sanitize_text_field( stripslashes( $_POST['demo_id'] ) );
262
+ $demo_data = isset( $this->demo_config[ $demo_id ] ) ? $this->demo_config[ $demo_id ] : array();
263
+
264
+ do_action( 'themegrill_ajax_before_demo_import' );
265
+
266
+ if ( ! empty( $demo_data ) ) {
267
+ $this->import_dummy_xml( $demo_id, $demo_data );
268
+ $this->import_core_options( $demo_id, $demo_data );
269
+ $this->import_customizer_data( $demo_id, $demo_data );
270
+ $this->import_widget_settings( $demo_id, $demo_data );
271
+
272
+ update_option( 'themegrill_demo_imported_id', $demo_id );
273
+
274
+ do_action( 'themegrill_ajax_demo_imported', $demo_id, $demo_data );
275
+
276
+ wp_send_json_success( array(
277
+ 'demo_id' => $demo_id,
278
+ 'message' => __( 'Successfully Imported', 'themegrill-demo-importer' ),
279
+ ) );
280
+ }
281
+
282
+ die();
283
+ }
284
+
285
+ /**
286
+ * Import dummy content from a XML file.
287
+ * @param string $demo_id
288
+ * @param array $demo_data
289
+ * @return bool
290
+ */
291
+ public function import_dummy_xml( $demo_id, $demo_data ) {
292
+ $import_file = $this->import_file_path( $demo_id, 'dummy-data.xml' );
293
+
294
+ // Load Importer API
295
+ require_once ABSPATH . 'wp-admin/includes/import.php';
296
+
297
+ if ( ! class_exists( 'WP_Importer' ) ) {
298
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
299
+
300
+ if ( file_exists( $class_wp_importer ) ) {
301
+ require $class_wp_importer;
302
+ }
303
+ }
304
+
305
+ // Include WXR Importer.
306
+ require dirname( __FILE__ ) . '/includes/importers/class-wxr-importer.php';
307
+
308
+ do_action( 'themegrill_ajax_before_dummy_xml_import', $demo_data, $demo_id );
309
+
310
+ // Import XML file demo content.
311
+ if ( is_file( $import_file ) ) {
312
+ $wp_import = new TG_WXR_Importer();
313
+ $wp_import->fetch_attachments = true;
314
+
315
+ ob_start();
316
+ $wp_import->import( $import_file );
317
+ ob_end_clean();
318
+
319
+ do_action( 'themegrill_ajax_dummy_xml_imported', $demo_data, $demo_id );
320
+
321
+ flush_rewrite_rules();
322
+ } else {
323
+ wp_send_json_error( array( 'message' => __( 'The XML file containing the dummy content is not available.', 'themegrill-demo-importer' ) ) );
324
+ exit;
325
+ }
326
+
327
+ return true;
328
+ }
329
+
330
+ /**
331
+ * Import site core options from its ID.
332
+ * @param string $demo_id
333
+ * @param array $demo_data
334
+ * @return bool
335
+ */
336
+ public function import_core_options( $demo_id, $demo_data ) {
337
+ if ( ! empty( $demo_data['core_options'] ) ) {
338
+ foreach ( $demo_data['core_options'] as $option_key => $option_value ) {
339
+ if ( ! in_array( $option_key, array( 'blogname', 'blogdescription', 'show_on_front', 'page_on_front', 'page_for_posts' ) ) ) {
340
+ continue;
341
+ }
342
+
343
+ // Format the value based on option key.
344
+ switch ( $option_key ) {
345
+ case 'show_on_front':
346
+ if ( in_array( $option_value, array( 'posts', 'page' ) ) ) {
347
+ update_option( 'show_on_front', $option_value );
348
+ }
349
+ break;
350
+ case 'page_on_front':
351
+ case 'page_for_posts':
352
+ $page = get_page_by_title( $option_value );
353
+
354
+ if ( is_object( $page ) && $page->ID ) {
355
+ update_option( $option_key, $page->ID );
356
+ update_option( 'show_on_front', 'page' );
357
+ }
358
+ break;
359
+ default:
360
+ update_option( $option_key, sanitize_text_field( $option_value ) );
361
+ break;
362
+ }
363
+ }
364
+ }
365
+
366
+ return true;
367
+ }
368
+
369
+ /**
370
+ * Import customizer data from a DAT file.
371
+ * @param string $demo_id
372
+ * @param array $demo_data
373
+ * @return bool
374
+ */
375
+ public function import_customizer_data( $demo_id, $demo_data ) {
376
+ $import_file = $this->import_file_path( $demo_id, 'dummy-customizer.dat' );
377
+
378
+ if ( is_file( $import_file ) ) {
379
+ $results = TG_Customizer_Importer::import( $import_file, $demo_id, $demo_data );
380
+
381
+ if ( is_wp_error( $results ) ) {
382
+ return false;
383
+ }
384
+ }
385
+
386
+ return true;
387
+ }
388
+
389
+ /**
390
+ * Import widgets settings from WIE or JSON file.
391
+ * @param string $demo_id
392
+ * @param array $demo_data
393
+ * @return bool
394
+ */
395
+ public function import_widget_settings( $demo_id, $demo_data ) {
396
+ $import_file = $this->import_file_path( $demo_id, 'dummy-widgets.wie' );
397
+
398
+ if ( is_file( $import_file ) ) {
399
+ $results = TG_Widget_Importer::import( $import_file, $demo_id, $demo_data );
400
+
401
+ if ( is_wp_error( $results ) ) {
402
+ return false;
403
+ }
404
+ }
405
+
406
+ return true;
407
+ }
408
+
409
+ /**
410
+ * Update custom nav menu items URL.
411
+ */
412
+ public function update_nav_menu_items() {
413
+ $menu_locations = get_nav_menu_locations();
414
+
415
+ foreach ( $menu_locations as $location => $menu_id ) {
416
+
417
+ if ( is_nav_menu( $menu_id ) ) {
418
+ $menu_items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'any' ) );
419
+
420
+ if ( ! empty( $menu_items ) ) {
421
+ foreach ( $menu_items as $menu_item ) {
422
+ if ( isset( $menu_item->url ) && isset( $menu_item->db_id ) && 'custom' == $menu_item->type ) {
423
+ $site_parts = parse_url( home_url( '/' ) );
424
+ $menu_parts = parse_url( $menu_item->url );
425
+
426
+ // Update existing custom nav menu item URL.
427
+ if ( isset( $menu_parts['path'] ) && isset( $menu_parts['host'] ) && apply_filters( 'themegrill_demo_importer_nav_menu_item_url_hosts', in_array( $menu_parts['host'], array( 'demo.themegrill.com' ) ) ) ) {
428
+ $menu_item->url = str_replace( array( $menu_parts['scheme'], $menu_parts['host'], $menu_parts['path'] ), array( $site_parts['scheme'], $site_parts['host'], trailingslashit( $site_parts['path'] ) ), $menu_item->url );
429
+ update_post_meta( $menu_item->db_id, '_menu_item_url', esc_url_raw( $menu_item->url ) );
430
+ }
431
+ }
432
+ }
433
+ }
434
+ }
435
+ }
436
+ }
437
+
438
+ /**
439
+ * Updates widgets settings data.
440
+ * @param array $widget
441
+ * @param string $widget_type
442
+ * @param int $instance_id
443
+ * @param array $demo_data
444
+ * @return array
445
+ */
446
+ public function update_widget_data( $widget, $widget_type, $instance_id, $demo_data ) {
447
+ if ( 'nav_menu' == $widget_type ) {
448
+ $nav_menu = wp_get_nav_menu_object( $widget['title'] );
449
+
450
+ if ( is_object( $nav_menu ) && $nav_menu->term_id ) {
451
+ $widget['nav_menu'] = $nav_menu->term_id;
452
+ }
453
+ } elseif ( ! empty( $demo_data['widgets_data_update'] ) ) {
454
+ foreach ( $demo_data['widgets_data_update'] as $dropdown_type => $dropdown_data ) {
455
+ if ( ! in_array( $dropdown_type, array( 'dropdown_pages', 'dropdown_categories' ) ) ) {
456
+ continue;
457
+ }
458
+
459
+ // Format the value based on dropdown type.
460
+ switch ( $dropdown_type ) {
461
+ case 'dropdown_pages':
462
+ foreach ( $dropdown_data as $widget_id => $widget_data ) {
463
+ if ( ! empty( $widget_data[ $instance_id ] ) && $widget_id == $widget_type ) {
464
+ foreach ( $widget_data[ $instance_id ] as $widget_key => $widget_value ) {
465
+ $page = get_page_by_title( $widget_value );
466
+
467
+ if ( is_object( $page ) && $page->ID ) {
468
+ $widget[ $widget_key ] = $page->ID;
469
+ }
470
+ }
471
+ }
472
+ }
473
+ break;
474
+ case 'dropdown_categories':
475
+ foreach ( $dropdown_data as $taxonomy => $taxonomy_data ) {
476
+ if ( ! taxonomy_exists( $taxonomy ) ) {
477
+ continue;
478
+ }
479
+
480
+ foreach ( $taxonomy_data as $widget_id => $widget_data ) {
481
+ if ( ! empty( $widget_data[ $instance_id ] ) && $widget_id == $widget_type ) {
482
+ foreach ( $widget_data[ $instance_id ] as $widget_key => $widget_value ) {
483
+ $term = get_term_by( 'name', $widget_value, $taxonomy );
484
+
485
+ if ( is_object( $term ) && $term->term_id ) {
486
+ $widget[ $widget_key ] = $term->term_id;
487
+ }
488
+ }
489
+ }
490
+ }
491
+ }
492
+ break;
493
+ }
494
+ }
495
+ }
496
+
497
+ return $widget;
498
+ }
499
+
500
+ /**
501
+ * Update customizer settings data.
502
+ * @param array $data
503
+ * @param array $demo_data
504
+ * @return array
505
+ */
506
+ public function update_customizer_data( $data, $demo_data ) {
507
+ if ( ! empty( $demo_data['customizer_data_update'] ) ) {
508
+ foreach ( $demo_data['customizer_data_update'] as $data_type => $data_value ) {
509
+ if ( ! in_array( $data_type, array( 'pages', 'categories', 'nav_menu_locations' ) ) ) {
510
+ continue;
511
+ }
512
+
513
+ // Format the value based on data type.
514
+ switch ( $data_type ) {
515
+ case 'pages':
516
+ foreach ( $data_value as $option_key => $option_value ) {
517
+ if ( ! empty( $data['mods'][ $option_key ] ) ) {
518
+ $page = get_page_by_title( $option_value );
519
+
520
+ if ( is_object( $page ) && $page->ID ) {
521
+ $data['mods'][ $option_key ] = $page->ID;
522
+ }
523
+ }
524
+ }
525
+ break;
526
+ case 'categories':
527
+ foreach ( $data_value as $taxonomy => $taxonomy_data ) {
528
+ if ( ! taxonomy_exists( $taxonomy ) ) {
529
+ continue;
530
+ }
531
+
532
+ foreach ( $taxonomy_data as $option_key => $option_value ) {
533
+ if ( ! empty( $data['mods'][ $option_key ] ) ) {
534
+ $term = get_term_by( 'name', $option_value, $taxonomy );
535
+
536
+ if ( is_object( $term ) && $term->term_id ) {
537
+ $data['mods'][ $option_key ] = $term->term_id;
538
+ }
539
+ }
540
+ }
541
+ }
542
+ break;
543
+ case 'nav_menu_locations':
544
+ $nav_menus = wp_get_nav_menus();
545
+
546
+ if ( ! empty( $nav_menus ) ) {
547
+ foreach ( $nav_menus as $nav_menu ) {
548
+ if ( is_object( $nav_menu ) ) {
549
+ foreach ( $data_value as $location => $location_name ) {
550
+ if ( $nav_menu->name == $location_name ) {
551
+ $data['mods'][ $data_type ][ $location ] = $nav_menu->term_id;
552
+ }
553
+ }
554
+ }
555
+ }
556
+ }
557
+ break;
558
+ }
559
+ }
560
+ }
561
+
562
+ return $data;
563
+ }
564
+
565
+ /**
566
+ * Update siteorigin panel settings data.
567
+ * @param string $demo_id
568
+ * @param array $demo_data
569
+ */
570
+ public function update_siteorigin_data( $demo_id, $demo_data ) {
571
+ if ( ! empty( $demo_data['siteorigin_panels_data_update'] ) ) {
572
+ foreach ( $demo_data['siteorigin_panels_data_update'] as $data_type => $data_value ) {
573
+ if ( ! empty( $data_value['post_title'] ) ) {
574
+ $page = get_page_by_title( $data_value['post_title'] );
575
+
576
+ if ( is_object( $page ) && $page->ID ) {
577
+ $panels_data = get_post_meta( $page->ID, 'panels_data', true );
578
+
579
+ if ( ! empty( $panels_data ) ) {
580
+ foreach ( $panels_data as $panel_type => $panel_data ) {
581
+ if ( ! in_array( $panel_type, array( 'grids', 'widgets' ) ) ) {
582
+ continue;
583
+ }
584
+
585
+ // Format the value based on panel type.
586
+ switch ( $panel_type ) {
587
+ case 'grids':
588
+ foreach ( $panel_data as $instance_id => $grid_instance ) {
589
+ if ( ! empty( $data_value['data_update']['grids_data'] ) ) {
590
+ foreach ( $data_value['data_update']['grids_data'] as $grid_id => $grid_data ) {
591
+ if ( ! empty( $grid_data['style'] ) && $instance_id === $grid_id ) {
592
+ foreach ( $grid_data['style'] as $style_key => $style_value ) {
593
+ if ( empty( $style_value ) ) {
594
+ continue;
595
+ }
596
+
597
+ // Format the value based on style key.
598
+ switch ( $style_key ) {
599
+ case 'background_image_attachment':
600
+ $attachment_id = tg_get_attachment_id( $style_value );
601
+
602
+ if ( 0 !== $attachment_id ) {
603
+ $grid_instance['style'][ $style_key ] = $attachment_id;
604
+ }
605
+ break;
606
+ default:
607
+ $grid_instance['style'][ $style_key ] = $style_value;
608
+ break;
609
+ }
610
+ }
611
+ }
612
+ }
613
+ }
614
+
615
+ // Update panel grids data.
616
+ $panels_data['grids'][ $instance_id ] = $grid_instance;
617
+ }
618
+ break;
619
+ case 'widgets':
620
+ foreach ( $panel_data as $instance_id => $widget_instance ) {
621
+ if ( isset( $widget_instance['nav_menu'] ) && isset( $widget_instance['title'] ) ) {
622
+ $nav_menu = wp_get_nav_menu_object( $widget_instance['title'] );
623
+
624
+ if ( is_object( $nav_menu ) && $nav_menu->term_id ) {
625
+ $widget_instance['nav_menu'] = $nav_menu->term_id;
626
+ }
627
+ } elseif ( ! empty( $data_value['data_update']['widgets_data'] ) ) {
628
+ $instance_class = $widget_instance['panels_info']['class'];
629
+
630
+ foreach ( $data_value['data_update']['widgets_data'] as $dropdown_type => $dropdown_data ) {
631
+ if ( ! in_array( $dropdown_type, array( 'dropdown_pages', 'dropdown_categories' ) ) ) {
632
+ continue;
633
+ }
634
+
635
+ // Format the value based on dropdown type.
636
+ switch ( $dropdown_type ) {
637
+ case 'dropdown_pages':
638
+ foreach ( $dropdown_data as $widget_id => $widget_data ) {
639
+ if ( ! empty( $widget_data[ $instance_id ] ) && $widget_id == $instance_class ) {
640
+ foreach ( $widget_data[ $instance_id ] as $widget_key => $widget_value ) {
641
+ $page = get_page_by_title( $widget_value );
642
+
643
+ if ( is_object( $page ) && $page->ID ) {
644
+ $widget_instance[ $widget_key ] = $page->ID;
645
+ }
646
+ }
647
+ }
648
+ }
649
+ break;
650
+ case 'dropdown_categories':
651
+ foreach ( $dropdown_data as $taxonomy => $taxonomy_data ) {
652
+ if ( ! taxonomy_exists( $taxonomy ) ) {
653
+ continue;
654
+ }
655
+
656
+ foreach ( $taxonomy_data as $widget_id => $widget_data ) {
657
+ if ( ! empty( $widget_data[ $instance_id ] ) && $widget_id == $instance_class ) {
658
+ foreach ( $widget_data[ $instance_id ] as $widget_key => $widget_value ) {
659
+ $term = get_term_by( 'name', $widget_value, $taxonomy );
660
+
661
+ if ( is_object( $term ) && $term->term_id ) {
662
+ $widget_instance[ $widget_key ] = $term->term_id;
663
+ }
664
+ }
665
+ }
666
+ }
667
+ }
668
+ break;
669
+ }
670
+ }
671
+ }
672
+
673
+ // Update panel widgets data.
674
+ $panels_data['widgets'][ $instance_id ] = $widget_instance;
675
+ }
676
+ break;
677
+ }
678
+ }
679
+ }
680
+
681
+ // Update siteorigin panels data.
682
+ update_post_meta( $page->ID, 'panels_data', $panels_data );
683
+ }
684
+ }
685
+ }
686
+ }
687
+ }
688
+ }
689
+
690
+ new TG_Demo_Importer();
includes/includes/admin/class-demo-installer-skin.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Upgrader API: Plugin_Upgrader_Skin class
4
+ *
5
+ * Demo Installer Skin for the WordPress Demo Importer.
6
+ *
7
+ * @class TG_Demo_Installer_Skin
8
+ * @extends WP_Upgrader_Skin
9
+ * @version 1.0.0
10
+ * @package Importer/Classes
11
+ * @category Admin
12
+ * @author ThemeGrill
13
+ */
14
+
15
+ if ( ! defined( 'ABSPATH' ) ) {
16
+ exit;
17
+ }
18
+
19
+ /**
20
+ * TG_Demo_Installer_Skin Class.
21
+ */
22
+ class TG_Demo_Installer_Skin extends WP_Upgrader_Skin {
23
+ public $type;
24
+
25
+ /**
26
+ *
27
+ * @param array $args
28
+ */
29
+ public function __construct( $args = array() ) {
30
+ $defaults = array( 'type' => 'web', 'url' => '', 'demo' => '', 'nonce' => '', 'title' => '' );
31
+ $args = wp_parse_args( $args, $defaults );
32
+
33
+ $this->type = $args['type'];
34
+
35
+ parent::__construct( $args );
36
+ }
37
+
38
+ /**
39
+ * @access public
40
+ */
41
+ public function after() {
42
+ $install_actions = array();
43
+
44
+ $from = isset( $_GET['from'] ) ? wp_unslash( $_GET['from'] ) : 'demos';
45
+
46
+ if ( 'web' == $this->type ) {
47
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=demo-importer&tab=uploaded' ) . '" target="_parent">' . __( 'Return to Demo Importer', 'themegrill-demo-importer' ) . '</a>';
48
+ } elseif ( 'upload' == $this->type && 'demos' == $from ) {
49
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=demo-importer&tab=uploaded' ) . '">' . __( 'Return to Demo Importer', 'themegrill-demo-importer' ) . '</a>';
50
+ } else {
51
+ $install_actions['demos_page'] = '<a href="' . admin_url( 'themes.php?page=demo-importer&tab=uploaded' ) . '" target="_parent">' . __( 'Return to Demos page', 'themegrill-demo-importer' ) . '</a>';
52
+ }
53
+
54
+ /**
55
+ * Filters the list of action links available following a single demo installation.
56
+ * @param array $install_actions Array of demo action links.
57
+ */
58
+ $install_actions = apply_filters( 'themegrill_demo_install_complete_actions', $install_actions );
59
+
60
+ if ( ! empty( $install_actions ) ) {
61
+ $this->feedback( implode( ' | ', (array) $install_actions ) );
62
+ }
63
+ }
64
+ }
includes/includes/admin/class-demo-upgrader.php ADDED
@@ -0,0 +1,349 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Upgrade API: TG_Demo_Upgrader class
4
+ *
5
+ * Core class used for upgrading/installing demos.
6
+ *
7
+ * It is designed to upgrade/install demo from a local zip, remote zip URL,
8
+ * or uploaded zip file.
9
+ *
10
+ * @see WP_Upgrader
11
+ */
12
+ class TG_Demo_Upgrader extends WP_Upgrader {
13
+
14
+ /**
15
+ * Result of the demo upgrade offer.
16
+ *
17
+ * @since 2.8.0
18
+ * @access public
19
+ * @var array|WP_Error $result
20
+ * @see WP_Upgrader::$result
21
+ */
22
+ public $result;
23
+
24
+ /**
25
+ * Whether multiple demos are being upgraded/installed in bulk.
26
+ *
27
+ * @since 2.9.0
28
+ * @access public
29
+ * @var bool $bulk
30
+ */
31
+ public $bulk = false;
32
+
33
+ /**
34
+ * Initialize the install strings.
35
+ *
36
+ * @since 2.8.0
37
+ * @access public
38
+ */
39
+ public function install_strings() {
40
+ $this->strings['no_package'] = __( 'Install package not available.', 'themegrill-demo-importer' );
41
+ $this->strings['downloading_package'] = __( 'Downloading install package from <span class="code">%s</span>&#8230;', 'themegrill-demo-importer' );
42
+ $this->strings['unpack_package'] = __( 'Unpacking the package&#8230;', 'themegrill-demo-importer' );
43
+ $this->strings['installing_package'] = __( 'Installing the demo&#8230;', 'themegrill-demo-importer' );
44
+ $this->strings['no_files'] = __( 'The demo contains no files.', 'themegrill-demo-importer' );
45
+ $this->strings['process_failed'] = __( 'Demo install failed.', 'themegrill-demo-importer' );
46
+ $this->strings['process_success'] = __( 'Demo installed successfully.', 'themegrill-demo-importer' );
47
+ }
48
+
49
+ /**
50
+ * Install a demo package.
51
+ *
52
+ * @since 2.8.0
53
+ * @since 3.7.0 The `$args` parameter was added, making clearing the update cache optional.
54
+ * @access public
55
+ *
56
+ * @param string $package The full local path or URI of the package.
57
+ * @param array $args {
58
+ * Optional. Other arguments for installing a demo package. Default empty array.
59
+ *
60
+ * @type bool $clear_update_cache Whether to clear the updates cache if successful.
61
+ * Default true.
62
+ * }
63
+ *
64
+ * @return bool|WP_Error True if the install was successful, false or a WP_Error object otherwise.
65
+ */
66
+ public function install( $package, $args = array() ) {
67
+ $upload_dir = wp_upload_dir();
68
+
69
+ $defaults = array(
70
+ 'clear_update_cache' => true,
71
+ );
72
+ $parsed_args = wp_parse_args( $args, $defaults );
73
+
74
+ $this->init();
75
+ $this->install_strings();
76
+
77
+ add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
78
+
79
+ $this->run( array(
80
+ 'package' => $package,
81
+ 'destination' => $upload_dir['basedir'] . '/tg-demo-pack',
82
+ 'clear_destination' => false, // Do not overwrite files.
83
+ 'protect_destination' => true,
84
+ 'clear_working' => true,
85
+ 'hook_extra' => array(
86
+ 'type' => 'demo',
87
+ 'action' => 'install',
88
+ ),
89
+ ) );
90
+
91
+ remove_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
92
+
93
+ if ( ! $this->result || is_wp_error( $this->result ) ) {
94
+ return $this->result;
95
+ }
96
+
97
+ return true;
98
+ }
99
+
100
+ /**
101
+ * Check that the package source contains a valid demo.
102
+ *
103
+ * Hooked to the {@see 'upgrader_source_selection'} filter by TG_Demo_Upgrader::install().
104
+ * It will return an error if the demo doesn't have tg-demo-config.php
105
+ * files.
106
+ *
107
+ * @since 3.3.0
108
+ * @access public
109
+ *
110
+ * @global WP_Filesystem_Base $wp_filesystem Subclass
111
+ * @global array $wp_theme_directories
112
+ *
113
+ * @param string $source The full path to the package source.
114
+ * @return string|WP_Error The source or a WP_Error.
115
+ */
116
+ public function check_package( $source ) {
117
+ global $wp_filesystem, $wp_theme_directories;
118
+
119
+ if ( is_wp_error( $source ) )
120
+ return $source;
121
+
122
+ // Check the folder contains a valid demo.
123
+ $working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
124
+ if ( ! is_dir( $working_directory ) ) // Sanity check, if the above fails, let's not prevent installation.
125
+ return $source;
126
+
127
+ // A proper archive should have a tg-demo-config.php file in the single subdirectory
128
+ if ( ! file_exists( $working_directory . 'tg-demo-config.php' ) ) {
129
+ return new WP_Error( 'incompatible_archive_no_demos', $this->strings['incompatible_archive'], __( 'No valid demos were found.', 'themegrill-demo-importer' ) );
130
+ }
131
+
132
+ return $source;
133
+ }
134
+
135
+ /**
136
+ * Install a package.
137
+ *
138
+ * Copies the contents of a package form a source directory, and installs them in
139
+ * a destination directory. Optionally removes the source. It can also optionally
140
+ * clear out the destination folder if it already exists.
141
+ *
142
+ * Stuck with this until a fix for https://core.trac.wordpress.org/ticket/38946.
143
+ * We use a custom upgrader, just like WordPress does.
144
+ *
145
+ * @since 2.8.0
146
+ * @access public
147
+ *
148
+ * @global WP_Filesystem_Base $wp_filesystem Subclass
149
+ * @global array $wp_theme_directories
150
+ *
151
+ * @param array|string $args {
152
+ * Optional. Array or string of arguments for installing a package. Default empty array.
153
+ *
154
+ * @type string $source Required path to the package source. Default empty.
155
+ * @type string $destination Required path to a folder to install the package in.
156
+ * Default empty.
157
+ * @type bool $clear_destination Whether to delete any files already in the destination
158
+ * folder. Default false.
159
+ * @type bool $clear_working Whether to delete the files from the working directory
160
+ * after copying to the destination. Default false.
161
+ * @type bool $protect_destination Whether to protect against deleting any files already
162
+ * in the destination folder. Default false.
163
+ * @type bool $abort_if_destination_exists Whether to abort the installation if
164
+ * the destination folder already exists. Default true.
165
+ * @type array $hook_extra Extra arguments to pass to the filter hooks called by
166
+ * WP_Upgrader::install_package(). Default empty array.
167
+ * }
168
+ *
169
+ * @return array|WP_Error The result (also stored in `WP_Upgrader::$result`), or a WP_Error on failure.
170
+ */
171
+ public function install_package( $args = array() ) {
172
+ global $wp_filesystem, $wp_theme_directories;
173
+
174
+ $defaults = array(
175
+ 'source' => '', // Please always pass this
176
+ 'destination' => '', // and this
177
+ 'clear_destination' => false,
178
+ 'clear_working' => false,
179
+ 'protect_destination' => true, // If fixed in core then it will be false :)
180
+ 'abort_if_destination_exists' => true,
181
+ 'hook_extra' => array(),
182
+ );
183
+
184
+ $args = wp_parse_args( $args, $defaults );
185
+
186
+ // These were previously extract()'d.
187
+ $source = $args['source'];
188
+ $destination = $args['destination'];
189
+ $clear_destination = $args['clear_destination'];
190
+
191
+ @set_time_limit( 300 );
192
+
193
+ if ( empty( $source ) || empty( $destination ) ) {
194
+ return new WP_Error( 'bad_request', $this->strings['bad_request'] );
195
+ }
196
+ $this->skin->feedback( 'installing_package' );
197
+
198
+ /**
199
+ * Filters the install response before the installation has started.
200
+ *
201
+ * Returning a truthy value, or one that could be evaluated as a WP_Error
202
+ * will effectively short-circuit the installation, returning that value
203
+ * instead.
204
+ *
205
+ * @since 2.8.0
206
+ *
207
+ * @param bool|WP_Error $response Response.
208
+ * @param array $hook_extra Extra arguments passed to hooked filters.
209
+ */
210
+ $res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );
211
+
212
+ if ( is_wp_error( $res ) ) {
213
+ return $res;
214
+ }
215
+
216
+ // Retain the Original source and destinations
217
+ $remote_source = $args['source'];
218
+ $local_destination = $destination;
219
+
220
+ $source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
221
+ $remote_destination = $wp_filesystem->find_folder( $local_destination );
222
+
223
+ // Locate which directory to copy to the new folder, This is based on the actual folder holding the files.
224
+ if ( 1 == count( $source_files ) && $wp_filesystem->is_dir( trailingslashit( $args['source'] ) . $source_files[0] . '/' ) ) { // Only one folder? Then we want its contents.
225
+ $source = trailingslashit( $args['source'] ) . trailingslashit( $source_files[0] );
226
+ } elseif ( count( $source_files ) == 0 ) {
227
+ return new WP_Error( 'incompatible_archive_empty', $this->strings['incompatible_archive'], $this->strings['no_files'] ); // There are no files?
228
+ } else { // It's only a single file, the upgrader will use the folder name of this file as the destination folder. Folder name is based on zip filename.
229
+ $source = trailingslashit( $args['source'] );
230
+ }
231
+
232
+ /**
233
+ * Filters the source file location for the upgrade package.
234
+ *
235
+ * @since 2.8.0
236
+ * @since 4.4.0 The $hook_extra parameter became available.
237
+ *
238
+ * @param string $source File source location.
239
+ * @param string $remote_source Remote file source location.
240
+ * @param WP_Upgrader $this WP_Upgrader instance.
241
+ * @param array $hook_extra Extra arguments passed to hooked filters.
242
+ */
243
+ $source = apply_filters( 'upgrader_source_selection', $source, $remote_source, $this, $args['hook_extra'] );
244
+
245
+ if ( is_wp_error( $source ) ) {
246
+ return $source;
247
+ }
248
+
249
+ // Has the source location changed? If so, we need a new source_files list.
250
+ if ( $source !== $remote_source ) {
251
+ $source_files = array_keys( $wp_filesystem->dirlist( $source ) );
252
+ }
253
+
254
+ /*
255
+ * Protection against deleting files in any important base directories.
256
+ * Theme_Upgrader & Plugin_Upgrader also trigger this, as they pass the
257
+ * destination directory (WP_PLUGIN_DIR / wp-content/themes) intending
258
+ * to copy the directory into the directory, whilst they pass the source
259
+ * as the actual files to copy.
260
+ */
261
+ $protected_directories = array( ABSPATH, WP_CONTENT_DIR, WP_PLUGIN_DIR, WP_CONTENT_DIR . '/themes' );
262
+
263
+ if ( is_array( $wp_theme_directories ) ) {
264
+ $protected_directories = array_merge( $protected_directories, $wp_theme_directories );
265
+ }
266
+
267
+ if ( in_array( $destination, $protected_directories ) || $args['protect_destination'] ) {
268
+ $remote_destination = trailingslashit( $remote_destination ) . trailingslashit( basename( $source ) );
269
+ $destination = trailingslashit( $destination ) . trailingslashit( basename( $source ) );
270
+ }
271
+
272
+ if ( $clear_destination ) {
273
+ // We're going to clear the destination if there's something there.
274
+ $this->skin->feedback( 'remove_old' );
275
+
276
+ $removed = $this->clear_destination( $remote_destination );
277
+
278
+ /**
279
+ * Filters whether the upgrader cleared the destination.
280
+ *
281
+ * @since 2.8.0
282
+ *
283
+ * @param mixed $removed Whether the destination was cleared. true on success, WP_Error on failure
284
+ * @param string $local_destination The local package destination.
285
+ * @param string $remote_destination The remote package destination.
286
+ * @param array $hook_extra Extra arguments passed to hooked filters.
287
+ */
288
+ $removed = apply_filters( 'upgrader_clear_destination', $removed, $local_destination, $remote_destination, $args['hook_extra'] );
289
+
290
+ if ( is_wp_error( $removed ) ) {
291
+ return $removed;
292
+ }
293
+ } elseif ( $args['abort_if_destination_exists'] && $wp_filesystem->exists( $remote_destination ) ) {
294
+ // If we're not clearing the destination folder and something exists there already, Bail.
295
+ // But first check to see if there are actually any files in the folder.
296
+ $_files = $wp_filesystem->dirlist( $remote_destination );
297
+ if ( ! empty( $_files ) ) {
298
+ $wp_filesystem->delete( $remote_source, true ); // Clear out the source files.
299
+ return new WP_Error( 'folder_exists', $this->strings['folder_exists'], $remote_destination );
300
+ }
301
+ }
302
+
303
+ // Create destination if needed
304
+ if ( ! $wp_filesystem->exists( $remote_destination ) ) {
305
+ if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
306
+ return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed'], $remote_destination );
307
+ }
308
+ }
309
+ // Copy new version of item into place.
310
+ $result = copy_dir( $source, $remote_destination );
311
+ if ( is_wp_error( $result ) ) {
312
+ if ( $args['clear_working'] ) {
313
+ $wp_filesystem->delete( $remote_source, true );
314
+ }
315
+ return $result;
316
+ }
317
+
318
+ // Clear the Working folder?
319
+ if ( $args['clear_working'] ) {
320
+ $wp_filesystem->delete( $remote_source, true );
321
+ }
322
+
323
+ $destination_name = basename( str_replace( $local_destination, '', $destination ) );
324
+ if ( '.' == $destination_name ) {
325
+ $destination_name = '';
326
+ }
327
+
328
+ $this->result = compact( 'source', 'source_files', 'destination', 'destination_name', 'local_destination', 'remote_destination', 'clear_destination' );
329
+
330
+ /**
331
+ * Filters the install response after the installation has finished.
332
+ *
333
+ * @since 2.8.0
334
+ *
335
+ * @param bool $response Install response.
336
+ * @param array $hook_extra Extra arguments passed to hooked filters.
337
+ * @param array $result Installation result data.
338
+ */
339
+ $res = apply_filters( 'upgrader_post_install', true, $args['hook_extra'], $this->result );
340
+
341
+ if ( is_wp_error( $res ) ) {
342
+ $this->result = $res;
343
+ return $res;
344
+ }
345
+
346
+ // Bombard the calling function will all the info which we've just used.
347
+ return $this->result;
348
+ }
349
+ }
includes/includes/admin/views/html-admin-page-importer-previews.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Page - Demo Previews
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ global $current_tab;
11
+
12
+ $template = get_option( 'template' );
13
+ $assets_path = tg_get_demo_importer_assets_path();
14
+
15
+ ?>
16
+ <h2 class="screen-reader-text hide-if-no-js"><?php _e( 'Theme demos list', 'themegrill-demo-importer' ); ?></h2>
17
+
18
+ <div class="theme-browser content-filterable">
19
+ <div class="themes wp-clearfix">
20
+ <?php foreach ( $this->demo_packages as $pack_id => $pack_data ) : ?>
21
+ <div class="theme active" tabindex="0">
22
+ <?php if ( $screenshot = "{$assets_path}images/{$template}/{$pack_id}.jpg" ) : ?>
23
+ <div class="theme-screenshot">
24
+ <?php if ( file_is_displayable_image( $screenshot ) ) : ?>
25
+ <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
26
+ <?php endif; ?>
27
+ </div>
28
+ <?php else : ?>
29
+ <div class="theme-screenshot blank"></div>
30
+ <?php endif; ?>
31
+
32
+ <h2 class="theme-name" id="demo-name"><?php echo esc_html( $pack_data['name'] ); ?></h2>
33
+
34
+ <div class="theme-actions">
35
+ <a class="button button-primary live-preview" target="_blank" href="<?php echo esc_url( $pack_data['preview'] ); ?>"><?php _e( 'Live Preview', 'themegrill-demo-importer' ); ?></a>
36
+ </div>
37
+ </div>
38
+ <?php endforeach; ?>
39
+ </div>
40
+ </div>
includes/includes/admin/views/html-admin-page-importer-uploaded.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Page - Demo Uploaded
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ global $current_tab;
11
+
12
+ $template = get_option( 'template' );
13
+ $demo_imported_id = get_option( 'themegrill_demo_imported_id' );
14
+
15
+ ?>
16
+ <h2 class="screen-reader-text hide-if-no-js"><?php _e( 'Available demos list', 'themegrill-demo-importer' ); ?></h2>
17
+
18
+ <div class="theme-browser content-filterable">
19
+ <div class="themes wp-clearfix">
20
+ <?php foreach ( $this->demo_config as $demo_id => $demo_data ) : ?>
21
+ <div class="theme<?php if ( $demo_id == $demo_imported_id ) echo ' active'; ?>" tabindex="0">
22
+ <?php if ( $screenshot = $this->import_file_url( $demo_id, 'screenshot.jpg' ) ) : ?>
23
+ <div class="theme-screenshot">
24
+ <?php if ( file_is_displayable_image( $screenshot ) ) : ?>
25
+ <img src="<?php echo esc_url( $screenshot ); ?>" alt="" />
26
+ <?php endif; ?>
27
+ </div>
28
+ <?php else : ?>
29
+ <div class="theme-screenshot blank"></div>
30
+ <?php endif; ?>
31
+
32
+ <?php if ( ! empty( $demo_data['plugins_list'] ) ) : ?>
33
+ <div class="notice inline notice-<?php echo isset( $demo_data['notice_type'] ) ? esc_attr( $demo_data['notice_type'] ) : 'info'; ?> notice-alt">
34
+ <?php if ( ! empty( $demo_data['plugins_list']['required'] ) && $plugins_required = tg_get_plugins_links( $demo_data['plugins_list']['required'] ) ) : ?>
35
+ <p><?php printf( __( '<strong>Required Plugins:</strong> %s', 'themegrill-demo-importer' ), $plugins_required ); ?></p>
36
+ <?php endif; ?>
37
+ <?php if ( ! empty( $demo_data['plugins_list']['recommended'] ) && $plugins_recommended = tg_get_plugins_links( $demo_data['plugins_list']['recommended'] ) ) : ?>
38
+ <p><?php printf( __( '<strong>Recommended Plugins:</strong> %s', 'themegrill-demo-importer' ), $plugins_recommended ); ?></p>
39
+ <?php endif; ?>
40
+ </div>
41
+ <?php endif; ?>
42
+
43
+ <?php if ( $demo_id == $demo_imported_id ) { ?>
44
+ <h2 class="theme-name" id="demo-name"><?php
45
+ /* translators: %s: demo name */
46
+ printf( __( '<span>Imported:</span> %s', 'themegrill-demo-importer' ), esc_html( $demo_data['name'] ) );
47
+ ?></h2>
48
+ <?php } else { ?>
49
+ <h2 class="theme-name" id="demo-name"><?php echo esc_html( $demo_data['name'] ); ?></h2>
50
+ <?php } ?>
51
+ <div class="theme-actions">
52
+ <?php if ( $demo_id !== $demo_imported_id ) : ?>
53
+ <?php if ( isset( $demo_data['template'] ) && $template !== $demo_data['template'] ) : ?>
54
+ <a class="button button-secondary tips import disabled" href="#" data-demo_id="<?php echo $demo_id; ?>" data-tip="<?php printf( esc_attr( 'Required %s theme must be activated to import this demo.', 'themegrill-demo-importer' ), wp_get_theme()->get( 'Name' ) ); ?>"><?php _e( 'Import', 'themegrill-demo-importer' ); ?></a>
55
+ <?php elseif ( ! empty( $demo_data['plugins_list'] ) ) : ?>
56
+ <?php if ( ! empty( $demo_data['plugins_list']['required'] ) && tg_is_plugins_active( $demo_data['plugins_list']['required'] ) ) : ?>
57
+ <a class="button button-secondary tips import disabled" href="#" data-demo_id="<?php echo $demo_id; ?>" data-tip="<?php esc_attr_e( 'Required Plugin must be activated to import this demo.', 'themegrill-demo-importer' ); ?>"><?php _e( 'Import', 'themegrill-demo-importer' ); ?></a>
58
+ <?php else : ?>
59
+ <a class="button button-secondary import plugins-ready" href="#" data-demo_id="<?php echo $demo_id; ?>"><?php _e( 'Import', 'themegrill-demo-importer' ); ?></a>
60
+ <?php endif; ?>
61
+ <?php else : ?>
62
+ <a class="button button-secondary import no-plugins-needed" href="#" data-demo_id="<?php echo $demo_id; ?>"><?php _e( 'Import', 'themegrill-demo-importer' ); ?></a>
63
+ <?php endif; ?>
64
+ <a class="button button-primary live-preview" target="_blank" href="<?php echo esc_url( $demo_data['demo_url'] ); ?>"><?php _e( 'Live Preview', 'themegrill-demo-importer' ); ?></a>
65
+ <?php endif; ?>
66
+ <a class="button button-primary preview" target="_blank" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php _e( 'Preview', 'themegrill-demo-importer' ); ?></a>
67
+ <span class="spinner"><?php _e( 'Please Wait&hellip;', 'themegrill-demo-importer' ); ?></span>
68
+ </div>
69
+ </div>
70
+ <?php endforeach; ?>
71
+ </div>
72
+ </div>
includes/includes/admin/views/html-admin-page-importer-welcome.php ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Page - Welcome
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ ?>
11
+ <div class="themegrill-demo-BlankState">
12
+ <div id="welcome-panel" class="welcome-panel">
13
+ <div class="welcome-panel-content">
14
+ <h2><?php _e( 'Welcome to ThemeGrill Demo Importer!', 'themegrill-demo-importer' ); ?></h2>
15
+ <h3><?php _e( 'Get Started','themegrill-demo-importer' ); ?></h3>
16
+ <div class="welcome-panel-column-container">
17
+ <div class="welcome-panel-column">
18
+ <ul>
19
+ <li><?php printf( __( '1. Visit <a href="%s" target="_blank"><strong>this page</strong></a> and download demo zip file.','themegrill-demo-importer' ),esc_url( 'http://themegrill.com/theme-demo-file-downloads/' ) ); ?></li>
20
+ <li><?php _e( '2. Click <strong>Upload Demo</strong> button on the top of this Page.','themegrill-demo-importer' ); ?></li>
21
+ <li><?php _e( '3. Browse the demo zip file and click <strong>Install Now</strong>.','themegrill-demo-importer' ); ?></li>
22
+ <li><?php _e( '4. Go to <strong>Available Demos</strong> tab.','themegrill-demo-importer' ); ?></li>
23
+ <li><?php _e( '5. Click <strong>Import</strong> button and wait for few minutes. Done!','themegrill-demo-importer' ); ?></li>
24
+ </ul>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ </div>
includes/includes/admin/views/html-admin-page-importer.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Admin View: Page - Importer
4
+ */
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+
10
+ $demo_imported_id = get_option( 'themegrill_demo_imported_id' );
11
+ $demo_filter_links = apply_filters( 'themegrill_demo_importer_filter_links_array', array(
12
+ 'welcome' => __( 'Welcome', 'themegrill-demo-importer' ),
13
+ 'uploaded' => __( 'Available Demos', 'themegrill-demo-importer' ),
14
+ 'previews' => __( 'Theme Demos', 'themegrill-demo-importer' ),
15
+ ) );
16
+
17
+ ?>
18
+ <div class="wrap demo-importer">
19
+ <h1><?php
20
+ esc_html_e( 'Demo Importer', 'themegrill-demo-importer' );
21
+ if ( current_user_can( 'upload_files' ) ) {
22
+ echo ' <button type="button" class="upload-view-toggle page-title-action hide-if-no-js tg-demo-upload" aria-expanded="false">' . __( 'Upload Demo', 'themegrill-demo-importer' ) . '</button>';
23
+ }
24
+ ?></h1>
25
+ <?php if ( ! get_option( 'themegrill_demo_imported_notice_dismiss' ) && in_array( $demo_imported_id, array_keys( $this->demo_config ) ) ) : ?>
26
+ <div id="message" class="notice notice-info is-dismissible" data-notice_id="demo-importer">
27
+ <p><?php printf( __( '<strong>Notice</strong> &#8211; If you want to completely remove a demo installation after importing it, you can use a plugin like %1$sWordPress Reset%2$s.', 'themegrill-demo-importer' ), '<a target="_blank" href="' . esc_url( 'https://wordpress.org/plugins/wordpress-reset/' ) . '">', '</a>' ); ?></p>
28
+ </div>
29
+ <?php endif; ?>
30
+ <div class="error hide-if-js">
31
+ <p><?php _e( 'The Demo Importer screen requires JavaScript.', 'themegrill-demo-importer' ); ?></p>
32
+ </div>
33
+ <div class="upload-theme">
34
+ <p class="install-help"><?php _e( 'If you have a demo pack in a .zip format, you may install it by uploading it here.', 'themegrill-demo-importer' ); ?></p>
35
+ <form method="post" enctype="multipart/form-data" class="wp-upload-form" action="<?php echo self_admin_url( 'themes.php?page=demo-importer&action=upload-demo' ); ?>">
36
+ <?php wp_nonce_field( 'demo-upload' ); ?>
37
+ <label class="screen-reader-text" for="demozip"><?php _e( 'Demo zip file', 'themegrill-demo-importer' ); ?></label>
38
+ <input type="file" id="demozip" name="demozip" />
39
+ <?php submit_button( __( 'Install Now', 'themegrill-demo-importer' ), 'button', 'install-demo-submit', false ); ?>
40
+ </form>
41
+ </div>
42
+
43
+ <h2 class="screen-reader-text hide-if-no-js"><?php _e( 'Filter demos list', 'themegrill-demo-importer' ); ?></h2>
44
+
45
+ <div class="wp-filter hide-if-no-js">
46
+ <div class="filter-count">
47
+ <span class="count demo-count"><?php echo 'previews' == $current_tab ? count( $this->demo_packages ) : count( $this->demo_config ); ?></span>
48
+ </div>
49
+
50
+ <ul class="filter-links">
51
+ <?php
52
+ foreach ( $demo_filter_links as $name => $label ) {
53
+ if ( ( empty( $this->demo_config ) && 'uploaded' == $name ) || ( empty( $this->demo_packages ) && 'previews' == $name ) ) {
54
+ continue;
55
+ }
56
+ echo '<li><a href="' . admin_url( 'themes.php?page=demo-importer&tab=' . $name ) . '" class="demo-tab ' . ( $current_tab == $name ? 'current' : '' ) . '">' . $label . '</a></li>';
57
+ }
58
+ do_action( 'themegrill_demo_importer_filter_links' );
59
+ ?>
60
+ </ul>
61
+ </div>
62
+ <?php do_action( 'themegrill_demo_importer_' . $current_tab ); ?>
63
+ </div>
includes/includes/class-customizer-importer.php ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Customizer importer - import customizer settings.
4
+ *
5
+ * Code adapted from the "Customizer Export/Import" plugin.
6
+ *
7
+ * @class TG_Customizer_Importer
8
+ * @version 1.0.0
9
+ * @package Importer/Classes
10
+ * @category Admin
11
+ * @author ThemeGrill
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit;
16
+ }
17
+
18
+ /**
19
+ * TG_Customizer_Importer Class.
20
+ */
21
+ class TG_Customizer_Importer {
22
+
23
+ /**
24
+ * Imports uploaded mods and calls WordPress core customize_save actions so
25
+ * themes that hook into them can act before mods are saved to the database.
26
+ *
27
+ * Update: WP core customize_save actions were removed, because of some errors.
28
+ *
29
+ * @param string $import_file Path to the import file.
30
+ * @param string $demo_id The ID of demo being imported.
31
+ * @param array $demo_data The data of demo being imported.
32
+ * @return void|WP_Error
33
+ */
34
+ public static function import( $import_file, $demo_id, $demo_data ) {
35
+ global $wp_customize;
36
+
37
+ $temp = get_template();
38
+ $data = maybe_unserialize( file_get_contents( $import_file ) );
39
+
40
+ // Data checks.
41
+ if ( ! is_array( $data ) && ( ! isset( $data['template'] ) || ! isset( $data['mods'] ) ) ) {
42
+ return new WP_Error( 'themegrill_customizer_import_data_error', __( 'The customizer import file is not in a correct format. Please make sure to use the correct customizer import file.', 'themegrill-demo-importer' ) );
43
+ }
44
+
45
+ if ( $data['template'] !== $temp ) {
46
+ return new WP_Error( 'themegrill_customizer_import_wrong_theme', __( 'The customizer import file is not suitable for current theme. You can only import customizer settings for the same theme or a child theme.', 'themegrill-demo-importer' ) );
47
+ }
48
+
49
+ // Import Images.
50
+ if ( apply_filters( 'themegrill_customizer_import_images', true ) ) {
51
+ $data['mods'] = self::import_customizer_images( $data['mods'] );
52
+ }
53
+
54
+ // Modify settings array.
55
+ $data = apply_filters( 'themegrill_customizer_demo_import_settings', $data, $demo_data, $demo_id );
56
+
57
+ // Import custom options.
58
+ if ( isset( $data['options'] ) ) {
59
+
60
+ // Load WordPress Customize Setting Class.
61
+ if ( ! class_exists( 'WP_Customize_Setting' ) ) {
62
+ require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
63
+ }
64
+
65
+ // Include Customizer Demo Importer Setting class.
66
+ include_once( dirname( __FILE__ ) . '/customize/class-oc-customize-demo-importer-setting.php' );
67
+
68
+ foreach ( $data['options'] as $option_key => $option_value ) {
69
+ $option = new OC_Customize_Demo_Importer_Setting( $wp_customize, $option_key, array(
70
+ 'default' => '',
71
+ 'type' => 'option',
72
+ 'capability' => 'edit_theme_options',
73
+ ) );
74
+
75
+ $option->import( $option_value );
76
+ }
77
+ }
78
+
79
+ // Loop through theme mods and update them.
80
+ if ( ! empty( $data['mods'] ) ) {
81
+ foreach ( $data['mods'] as $key => $value ) {
82
+ set_theme_mod( $key, $value );
83
+ }
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Imports images for settings saved as mods.
89
+ *
90
+ * @param array $mods An array of customizer mods.
91
+ * @return array The mods array with any new import data.
92
+ */
93
+ private static function import_customizer_images( $mods ) {
94
+ foreach ( $mods as $key => $value ) {
95
+ if ( self::is_image_url( $value ) ) {
96
+ $data = self::media_handle_sideload( $value );
97
+ if ( ! is_wp_error( $data ) ) {
98
+ $mods[ $key ] = $data->url;
99
+
100
+ // Handle header image controls.
101
+ if ( isset( $mods[ $key . '_data' ] ) ) {
102
+ $mods[ $key . '_data' ] = $data;
103
+ update_post_meta( $data->attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
104
+ }
105
+ }
106
+ }
107
+ }
108
+
109
+ return $mods;
110
+ }
111
+
112
+ /**
113
+ * Checks to see whether a url is an image url or not.
114
+ *
115
+ * @param string $url The url to check.
116
+ * @return bool Whether the url is an image url or not.
117
+ */
118
+ private static function is_image_url( $url ) {
119
+ if ( is_string( $url ) && preg_match( '/\.(jpg|jpeg|png|gif)/i', $url ) ) {
120
+ return true;
121
+ }
122
+
123
+ return false;
124
+ }
125
+
126
+ /**
127
+ * Taken from the core media_sideload_image function and
128
+ * modified to return an array of data instead of html.
129
+ *
130
+ * @param string $file The image file path.
131
+ * @return array An array of image data.
132
+ */
133
+ private static function media_handle_sideload( $file ) {
134
+ $data = new stdClass();
135
+
136
+ if ( ! function_exists( 'media_handle_sideload' ) ) {
137
+ require_once( ABSPATH . 'wp-admin/includes/media.php' );
138
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
139
+ require_once( ABSPATH . 'wp-admin/includes/image.php' );
140
+ }
141
+
142
+ if ( ! empty( $file ) ) {
143
+ // Set variables for storage, fix file filename for query strings.
144
+ preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
145
+ $file_array = array();
146
+ $file_array['name'] = basename( $matches[0] );
147
+
148
+ // Download file to temp location.
149
+ $file_array['tmp_name'] = download_url( $file );
150
+
151
+ // If error storing temporarily, return the error.
152
+ if ( is_wp_error( $file_array['tmp_name'] ) ) {
153
+ return $file_array['tmp_name'];
154
+ }
155
+
156
+ // Do the validation and storage stuff.
157
+ $id = media_handle_sideload( $file_array, 0 );
158
+
159
+ // If error storing permanently, unlink.
160
+ if ( is_wp_error( $id ) ) {
161
+ @unlink( $file_array['tmp_name'] );
162
+ return $id;
163
+ }
164
+
165
+ // Build the object to return.
166
+ $meta = wp_get_attachment_metadata( $id );
167
+ $data->attachment_id = $id;
168
+ $data->url = wp_get_attachment_url( $id );
169
+ $data->thumbnail_url = wp_get_attachment_thumb_url( $id );
170
+ $data->height = $meta['height'];
171
+ $data->width = $meta['width'];
172
+ }
173
+
174
+ return $data;
175
+ }
176
+ }
includes/includes/class-widget-importer.php ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Widget importer - import widget settings.
4
+ *
5
+ * Code adapted from the "Widget Importer & Exporter" plugin.
6
+ *
7
+ * @class TG_Widget_Importer
8
+ * @version 1.0.0
9
+ * @package Importer/Classes
10
+ * @category Admin
11
+ * @author ThemeGrill
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit;
16
+ }
17
+
18
+ /**
19
+ * TG_Widget_Importer Class.
20
+ */
21
+ class TG_Widget_Importer {
22
+
23
+ /**
24
+ * Import widget JSON data.
25
+ *
26
+ * @global array $wp_registered_sidebars
27
+ * @param string $import_file Path to the import file.
28
+ * @param string $demo_id The ID of demo being imported.
29
+ * @param array $demo_data The data of demo being imported.
30
+ * @return WP_Error|array WP_Error on failure, $results on success.
31
+ */
32
+ public static function import( $import_file, $demo_id, $demo_data ) {
33
+ global $wp_registered_sidebars;
34
+
35
+ $data = json_decode( file_get_contents( $import_file ) );
36
+
37
+ // Have valid data? If no data or could not decode.
38
+ if ( empty( $data ) || ! is_object( $data ) ) {
39
+ return new WP_Error( 'themegrill_widget_import_data_error', __( 'Widget import data could not be read. Please try a different file.', 'themegrill-demo-importer' ) );
40
+ }
41
+
42
+ // Hook before import.
43
+ do_action( 'themegrill_widget_importer_before_widgets_import' );
44
+ $data = apply_filters( 'themegrill_before_widgets_import_data', $data );
45
+
46
+ // Get all available widgets site supports.
47
+ $available_widgets = self::available_widgets();
48
+
49
+ // Get all existing widget instances.
50
+ $widget_instances = array();
51
+ foreach ( $available_widgets as $widget_data ) {
52
+ $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
53
+ }
54
+
55
+ // Begin results.
56
+ $results = array();
57
+
58
+ // Loop import data's sidebars.
59
+ foreach ( $data as $sidebar_id => $widgets ) {
60
+
61
+ // Skip inactive widgets (should not be in export file).
62
+ if ( 'wp_inactive_widgets' == $sidebar_id ) {
63
+ continue;
64
+ }
65
+
66
+ // Check if sidebar is available on this site. Otherwise add widgets to inactive, and say so.
67
+ if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
68
+ $sidebar_available = true;
69
+ $use_sidebar_id = $sidebar_id;
70
+ $sidebar_message_type = 'success';
71
+ $sidebar_message = '';
72
+ } else {
73
+ $sidebar_available = false;
74
+ $use_sidebar_id = 'wp_inactive_widgets'; // Add to inactive if sidebar does not exist in theme.
75
+ $sidebar_message_type = 'error';
76
+ $sidebar_message = __( 'Sidebar does not exist in theme (moving widget to Inactive)', 'themegrill-demo-importer' );
77
+ }
78
+
79
+ // Result for sidebar.
80
+ $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.
81
+ $results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
82
+ $results[ $sidebar_id ]['message'] = $sidebar_message;
83
+ $results[ $sidebar_id ]['widgets'] = array();
84
+
85
+ // Loop widgets.
86
+ foreach ( $widgets as $widget_instance_id => $widget ) {
87
+
88
+ $fail = false;
89
+
90
+ // Get id_base (remove -# from end) and instance ID number.
91
+ $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
92
+ $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
93
+
94
+ // Does site support this widget?
95
+ if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
96
+ $fail = true;
97
+ $widget_message_type = 'error';
98
+ $widget_message = __( 'Site does not support widget', 'themegrill-demo-importer' ); // Explain why widget not imported.
99
+ }
100
+
101
+ /**
102
+ * Convert multidimensional objects to multidimensional arrays.
103
+ *
104
+ * Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays.
105
+ * Without this, they are imported as objects and cause fatal error on Widgets page.
106
+ * 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.
107
+ * It is probably much more likely that arrays are used than objects, however.
108
+ */
109
+ $widget = json_decode( json_encode( $widget ), true );
110
+
111
+ /**
112
+ * Filter to modify settings array.
113
+ *
114
+ * Do before identical check because changes may make it identical to end result (such as URL replacements).
115
+ */
116
+ $widget = apply_filters( 'themegrill_widget_demo_import_settings', $widget, $id_base, $instance_id_number, $demo_data, $demo_id );
117
+
118
+ // Does widget with identical settings already exist in same sidebar?
119
+ if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
120
+
121
+ // Get existing widgets in this sidebar.
122
+ $sidebars_widgets = get_option( 'sidebars_widgets' );
123
+ $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // Check Inactive if that's where will go.
124
+
125
+ // Loop widgets with ID base.
126
+ $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
127
+ foreach ( $single_widget_instances as $check_id => $check_widget ) {
128
+
129
+ // Is widget in same sidebar and has identical settings?
130
+ if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
131
+ $fail = true;
132
+ $widget_message_type = 'warning';
133
+ $widget_message = __( 'Widget already exists', 'themegrill-demo-importer' ); // Explain why widget not imported.
134
+
135
+ break;
136
+ }
137
+ }
138
+ }
139
+
140
+ // No failure.
141
+ if ( ! $fail ) {
142
+
143
+ // Add widget instance.
144
+ $single_widget_instances = get_option( 'widget_' . $id_base ); // All instances for that widget ID base, get fresh every time.
145
+ $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // Start fresh if have to.
146
+ $single_widget_instances[] = $widget; // Add it.
147
+
148
+ // Get the key it was given.
149
+ end( $single_widget_instances );
150
+ $new_instance_id_number = key( $single_widget_instances );
151
+
152
+ // If key is 0, make it 1.
153
+ // 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).
154
+ if ( '0' === strval( $new_instance_id_number ) ) {
155
+ $new_instance_id_number = 1;
156
+ $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
157
+ unset( $single_widget_instances[0] );
158
+ }
159
+
160
+ // Move _multiwidget to end of array for uniformity.
161
+ if ( isset( $single_widget_instances['_multiwidget'] ) ) {
162
+ $multiwidget = $single_widget_instances['_multiwidget'];
163
+ unset( $single_widget_instances['_multiwidget'] );
164
+ $single_widget_instances['_multiwidget'] = $multiwidget;
165
+ }
166
+
167
+ // Update option with new widget.
168
+ update_option( 'widget_' . $id_base, $single_widget_instances );
169
+
170
+ // Assign widget instance to sidebar.
171
+ $sidebars_widgets = get_option( 'sidebars_widgets' ); // Which sidebars have which widgets, get fresh every time.
172
+ $new_instance_id = $id_base . '-' . $new_instance_id_number; // Use ID number from new widget instance.
173
+ $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // Add new instance to sidebar.
174
+ update_option( 'sidebars_widgets', $sidebars_widgets ); // Save the amended data.
175
+
176
+ // After widget import action.
177
+ $after_widget_import = array(
178
+ 'sidebar' => $use_sidebar_id,
179
+ 'sidebar_old' => $sidebar_id,
180
+ 'widget' => $widget,
181
+ 'widget_type' => $id_base,
182
+ 'widget_id' => $new_instance_id,
183
+ 'widget_id_old' => $widget_instance_id,
184
+ 'widget_id_num' => $new_instance_id_number,
185
+ 'widget_id_num_old' => $instance_id_number,
186
+ );
187
+ do_action( 'themegrill_widget_importer_after_single_widget_import', $after_widget_import );
188
+
189
+ // Success message.
190
+ if ( $sidebar_available ) {
191
+ $widget_message_type = 'success';
192
+ $widget_message = __( 'Imported', 'themegrill-demo-importer' );
193
+ } else {
194
+ $widget_message_type = 'warning';
195
+ $widget_message = __( 'Imported to Inactive', 'themegrill-demo-importer' );
196
+ }
197
+ }
198
+
199
+ // Result for widget instance.
200
+ $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).
201
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : __( 'No Title', 'themegrill-demo-importer' ); // Show "No Title" if widget instance is untitled.
202
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
203
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
204
+ }
205
+ }
206
+
207
+ // Hook after import.
208
+ do_action( 'themegrill_widget_importer_after_widgets_import' );
209
+
210
+ // Return results.
211
+ return apply_filters( 'themegrill_widget_import_results', $results );
212
+ }
213
+
214
+ /**
215
+ * Available widgets.
216
+ *
217
+ * Gather site's widgets into array with ID base, name, etc.
218
+ *
219
+ * @global array $wp_registered_widget_controls
220
+ * @return array Widget information
221
+ */
222
+ private static function available_widgets() {
223
+ global $wp_registered_widget_controls;
224
+
225
+ $widget_controls = $wp_registered_widget_controls;
226
+ $available_widgets = array();
227
+
228
+ foreach ( $widget_controls as $widget ) {
229
+ if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) {
230
+ $available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
231
+ $available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
232
+ }
233
+ }
234
+
235
+ return apply_filters( 'themegrill_widget_importer_available_widgets', $available_widgets );
236
+ }
237
+ }
includes/includes/customize/class-oc-customize-demo-importer-setting.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Customize API: OC_Customize_Demo_Importer_Setting class
4
+ *
5
+ * @version 1.0.0
6
+ * @package Importer/Classes
7
+ * @category Customize
8
+ * @author ThemeGrill
9
+ */
10
+
11
+ /**
12
+ * Customizer Demo Importer Setting class.
13
+ * @see WP_Customize_Setting
14
+ */
15
+ final class OC_Customize_Demo_Importer_Setting extends WP_Customize_Setting {
16
+
17
+ /**
18
+ * Import an option value for this setting.
19
+ * @param mixed $value The value to update.
20
+ */
21
+ public function import( $value ) {
22
+ $this->update( $value );
23
+ }
24
+ }
includes/includes/functions-demo-importer.php ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Demo Importer Functions.
4
+ *
5
+ * @author ThemeGrill
6
+ * @category Admin
7
+ * @package Importer/Functions
8
+ * @version 1.0.0
9
+ */
10
+
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ exit;
13
+ }
14
+
15
+ if ( ! function_exists( 'tg_get_demo_file_url' ) ) {
16
+
17
+ /**
18
+ * Get a demo file URL.
19
+ *
20
+ * @param string $demo_dir demo dir.
21
+ * @return string the demo data file URL.
22
+ */
23
+ function tg_get_demo_file_url( $demo_dir ) {
24
+ return apply_filters( 'themegrill_demo_file_url', get_template_directory_uri() . '/inc/demo-data/' . $demo_dir, $demo_dir );
25
+ }
26
+ }
27
+
28
+ if ( ! function_exists( 'tg_get_demo_file_path' ) ) {
29
+
30
+ /**
31
+ * Get a demo file path.
32
+ *
33
+ * @param string $demo_dir demo dir.
34
+ * @return string the demo data file path.
35
+ */
36
+ function tg_get_demo_file_path( $demo_dir ) {
37
+ return apply_filters( 'themegrill_demo_file_path', get_template_directory() . '/inc/demo-data/' . $demo_dir . '/dummy-data', $demo_dir );
38
+ }
39
+ }
40
+
41
+ if ( ! function_exists( 'tg_get_demo_importer_assets_path' ) ) {
42
+
43
+ /**
44
+ * Get a demo importer assets path.
45
+ *
46
+ * @return string the demo data assets path.
47
+ */
48
+ function tg_get_demo_importer_assets_path() {
49
+ return apply_filters( 'themegrill_demo_importer_assets_path', get_template_directory_uri() . '/inc/demo-importer/assets/' );
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Get an attachment ID from the filename.
55
+ *
56
+ * @param string $filename
57
+ * @return int Attachment ID on success, 0 on failure
58
+ */
59
+ function tg_get_attachment_id( $filename ) {
60
+ $attachment_id = 0;
61
+
62
+ $file = basename( $filename );
63
+
64
+ $query_args = array(
65
+ 'post_type' => 'attachment',
66
+ 'post_status' => 'inherit',
67
+ 'fields' => 'ids',
68
+ 'meta_query' => array(
69
+ array(
70
+ 'value' => $file,
71
+ 'compare' => 'LIKE',
72
+ 'key' => '_wp_attachment_metadata',
73
+ ),
74
+ )
75
+ );
76
+
77
+ $query = new WP_Query( $query_args );
78
+
79
+ if ( $query->have_posts() ) {
80
+
81
+ foreach ( $query->posts as $post_id ) {
82
+
83
+ $meta = wp_get_attachment_metadata( $post_id );
84
+
85
+ $original_file = basename( $meta['file'] );
86
+ $cropped_image_files = wp_list_pluck( $meta['sizes'], 'file' );
87
+
88
+ if ( $original_file === $file || in_array( $file, $cropped_image_files ) ) {
89
+ $attachment_id = $post_id;
90
+ break;
91
+ }
92
+
93
+ }
94
+
95
+ }
96
+
97
+ return $attachment_id;
98
+ }
99
+
100
+ /**
101
+ * Retrieve the links for each plugins list.
102
+ *
103
+ * @param array $plugins_list
104
+ * @return mixed
105
+ */
106
+ function tg_get_plugins_links( $plugins_list ) {
107
+ $plugins_link = array();
108
+
109
+ foreach ( $plugins_list as $plugin_slug => $plugin_data ) {
110
+ if ( isset( $plugin_data['link'] ) ) {
111
+ $plugin_url = $plugin_data['link'];
112
+ } else {
113
+ $plugin_url = admin_url( 'plugin-install.php?tab=search&type=term&s=' . $plugin_slug );
114
+ }
115
+
116
+ $plugins_link[ $plugin_slug ] = '<a href="' . esc_url( $plugin_url ) . '" target="_blank">' . esc_html( $plugin_data['name'] ) . '</a>';
117
+ }
118
+
119
+ return implode( ', ', $plugins_link );
120
+ }
121
+
122
+ /**
123
+ * Checks whether the required plugins are active.
124
+ *
125
+ * @param array $raw_plugins_list Plugins list to check.
126
+ * @return bool
127
+ */
128
+ function tg_is_plugins_active( $raw_plugins_list ) {
129
+ $plugins_data = array();
130
+ $plugins_list = wp_list_pluck( $raw_plugins_list, 'slug' );
131
+
132
+ foreach ( $plugins_list as $plugin_name => $plugin_slug ) {
133
+ if ( is_plugin_active( $plugin_slug ) ) {
134
+ $plugins_data[ $plugin_name ] = $plugin_slug;
135
+ }
136
+ }
137
+
138
+ return array_diff( $plugins_list, $plugins_data ) ? true : false;
139
+ }
140
+
141
+ /**
142
+ * Clear data before demo import AJAX action.
143
+ *
144
+ * @see tg_reset_widgets()
145
+ * @see tg_delete_nav_menus()
146
+ * @see tg_remove_theme_mods()
147
+ */
148
+ if ( apply_filters( 'themegrill_clear_data_before_demo_import', true ) ) {
149
+ add_action( 'themegrill_ajax_before_demo_import', 'tg_reset_widgets', 10 );
150
+ add_action( 'themegrill_ajax_before_demo_import', 'tg_delete_nav_menus', 20 );
151
+ add_action( 'themegrill_ajax_before_demo_import', 'tg_remove_theme_mods', 30 );
152
+ }
153
+
154
+ /**
155
+ * Reset existing active widgets.
156
+ */
157
+ function tg_reset_widgets() {
158
+ $sidebars_widgets = wp_get_sidebars_widgets();
159
+
160
+ // Reset active widgets.
161
+ foreach ( $sidebars_widgets as $key => $widgets ) {
162
+ $sidebars_widgets[ $key ] = array();
163
+ }
164
+
165
+ wp_set_sidebars_widgets( $sidebars_widgets );
166
+ }
167
+
168
+ /**
169
+ * Delete existing navigation menus.
170
+ */
171
+ function tg_delete_nav_menus() {
172
+ $nav_menus = wp_get_nav_menus();
173
+
174
+ // Delete navigation menus.
175
+ if ( ! empty( $nav_menus ) ) {
176
+ foreach ( $nav_menus as $nav_menu ) {
177
+ wp_delete_nav_menu( $nav_menu->slug );
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Remove theme modifications option.
184
+ */
185
+ function tg_remove_theme_mods() {
186
+ remove_theme_mods();
187
+ }
188
+
189
+ /**
190
+ * After demo imported AJAX action.
191
+ *
192
+ * @see tg_set_wc_pages()
193
+ */
194
+ if ( class_exists( 'WooCommerce' ) ) {
195
+ add_action( 'themegrill_ajax_demo_imported', 'tg_set_wc_pages' );
196
+ }
197
+
198
+ /**
199
+ * Set WC pages properly and disable setup wizard redirect.
200
+ *
201
+ * After importing demo data filter out duplicate WC pages and set them properly.
202
+ * Happens when the user run default woocommerce setup wizard during installation.
203
+ *
204
+ * Note: WC pages ID are stored in an option and slug are modified to remove any numbers.
205
+ *
206
+ * @param string $demo_id
207
+ */
208
+ function tg_set_wc_pages( $demo_id ) {
209
+ global $wpdb;
210
+
211
+ $wc_pages = apply_filters( 'themegrill_wc_' . $demo_id . '_pages', array(
212
+ 'shop' => array(
213
+ 'name' => 'shop',
214
+ 'title' => 'Shop',
215
+ ),
216
+ 'cart' => array(
217
+ 'name' => 'cart',
218
+ 'title' => 'Cart',
219
+ ),
220
+ 'checkout' => array(
221
+ 'name' => 'checkout',
222
+ 'title' => 'Checkout',
223
+ ),
224
+ 'myaccount' => array(
225
+ 'name' => 'my-account',
226
+ 'title' => 'My Account',
227
+ ),
228
+ ) );
229
+
230
+ // Set WC pages properly.
231
+ foreach ( $wc_pages as $key => $wc_page ) {
232
+
233
+ // Get the ID of every page with matching name or title.
234
+ $page_ids = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE (post_name = %s OR post_title = %s) AND post_type = 'page' AND post_status = 'publish'", $wc_page['name'], $wc_page['title'] ) );
235
+
236
+ if ( ! is_null( $page_ids ) ) {
237
+ $page_id = 0;
238
+ $delete_ids = array();
239
+
240
+ // Retrieve page with greater id and delete others.
241
+ if ( sizeof( $page_ids ) > 1 ) {
242
+ foreach ( $page_ids as $page ) {
243
+ if ( $page->ID > $page_id ) {
244
+ if ( $page_id ) {
245
+ $delete_ids[] = $page_id;
246
+ }
247
+
248
+ $page_id = $page->ID;
249
+ } else {
250
+ $delete_ids[] = $page->ID;
251
+ }
252
+ }
253
+ } else {
254
+ $page_id = $page_ids[0]->ID;
255
+ }
256
+
257
+ // Delete posts.
258
+ foreach ( $delete_ids as $delete_id ) {
259
+ wp_delete_post( $delete_id, true );
260
+ }
261
+
262
+ // Update WC page.
263
+ if ( $page_id > 0 ) {
264
+ update_option( 'woocommerce_' . $key . '_page_id', $page_id );
265
+ wp_update_post( array( 'ID' => $page_id, 'post_name' => sanitize_title( $wc_page['name'] ) ) );
266
+ }
267
+ }
268
+ }
269
+
270
+ // We no longer need WC setup wizard redirect.
271
+ delete_transient( '_wc_activation_redirect' );
272
+ }
includes/includes/importers/class-wxr-importer.php ADDED
@@ -0,0 +1,1232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WordPress (WXR) Importer
4
+ *
5
+ * Code adapted from the "WordPress Importer" plugin.
6
+ *
7
+ * @class TG_WXR_Importer
8
+ * @extends WP_Importer
9
+ * @version 1.0.0
10
+ * @package Importer/Classes
11
+ * @category Admin
12
+ * @author ThemeGrill
13
+ */
14
+
15
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
16
+ return;
17
+ }
18
+
19
+ if ( ! class_exists( 'WP_Importer' ) ) {
20
+ return;
21
+ }
22
+
23
+ /** Display verbose errors */
24
+ define( 'IMPORT_DEBUG', false );
25
+
26
+ // Include WXR file parsers.
27
+ require dirname( __FILE__ ) . '/class-wxr-parsers.php';
28
+
29
+ /**
30
+ * TG_WXR_Importer Class.
31
+ */
32
+ class TG_WXR_Importer extends WP_Importer {
33
+ var $max_wxr_version = 1.2; // max. supported WXR version
34
+
35
+ var $id; // WXR attachment ID
36
+
37
+ // information to import from WXR file
38
+ var $version;
39
+ var $authors = array();
40
+ var $posts = array();
41
+ var $terms = array();
42
+ var $categories = array();
43
+ var $tags = array();
44
+ var $base_url = '';
45
+
46
+ // mappings from old information to new
47
+ var $processed_authors = array();
48
+ var $author_mapping = array();
49
+ var $processed_terms = array();
50
+ var $processed_posts = array();
51
+ var $post_orphans = array();
52
+ var $processed_menu_items = array();
53
+ var $menu_item_orphans = array();
54
+ var $missing_menu_items = array();
55
+
56
+ var $fetch_attachments = false;
57
+ var $url_remap = array();
58
+ var $featured_images = array();
59
+
60
+ /**
61
+ * Registered callback function for the WordPress Importer
62
+ *
63
+ * Manages the three separate stages of the WXR import process
64
+ */
65
+ function dispatch() {
66
+ $this->header();
67
+
68
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
69
+ switch ( $step ) {
70
+ case 0:
71
+ $this->greet();
72
+ break;
73
+ case 1:
74
+ check_admin_referer( 'import-upload' );
75
+ if ( $this->handle_upload() )
76
+ $this->import_options();
77
+ break;
78
+ case 2:
79
+ check_admin_referer( 'import-wordpress' );
80
+ $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() );
81
+ $this->id = (int) $_POST['import_id'];
82
+ $file = get_attached_file( $this->id );
83
+ set_time_limit(0);
84
+ $this->import( $file );
85
+ break;
86
+ }
87
+
88
+ $this->footer();
89
+ }
90
+
91
+ /**
92
+ * The main controller for the actual import stage.
93
+ *
94
+ * @param string $file Path to the WXR file for importing
95
+ */
96
+ function import( $file ) {
97
+ add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
98
+ add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
99
+
100
+ $this->import_start( $file );
101
+
102
+ $this->get_author_mapping();
103
+
104
+ wp_suspend_cache_invalidation( true );
105
+ $this->process_categories();
106
+ $this->process_tags();
107
+ $this->process_terms();
108
+ $this->process_posts();
109
+ wp_suspend_cache_invalidation( false );
110
+
111
+ // update incorrect/missing information in the DB
112
+ $this->backfill_parents();
113
+ $this->backfill_attachment_urls();
114
+ $this->remap_featured_images();
115
+
116
+ $this->import_end();
117
+ }
118
+
119
+ /**
120
+ * Parses the WXR file and prepares us for the task of processing parsed data
121
+ *
122
+ * @param string $file Path to the WXR file for importing
123
+ */
124
+ function import_start( $file ) {
125
+ if ( ! is_file($file) ) {
126
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'themegrill-demo-importer' ) . '</strong><br />';
127
+ echo __( 'The file does not exist, please try again.', 'themegrill-demo-importer' ) . '</p>';
128
+ $this->footer();
129
+ die();
130
+ }
131
+
132
+ $import_data = $this->parse( $file );
133
+
134
+ if ( is_wp_error( $import_data ) ) {
135
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'themegrill-demo-importer' ) . '</strong><br />';
136
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
137
+ $this->footer();
138
+ die();
139
+ }
140
+
141
+ $this->version = $import_data['version'];
142
+ $this->get_authors_from_import( $import_data );
143
+ $this->posts = $import_data['posts'];
144
+ $this->terms = $import_data['terms'];
145
+ $this->categories = $import_data['categories'];
146
+ $this->tags = $import_data['tags'];
147
+ $this->base_url = esc_url( $import_data['base_url'] );
148
+
149
+ wp_defer_term_counting( true );
150
+ wp_defer_comment_counting( true );
151
+
152
+ do_action( 'import_start' );
153
+ }
154
+
155
+ /**
156
+ * Performs post-import cleanup of files and the cache
157
+ */
158
+ function import_end() {
159
+ wp_import_cleanup( $this->id );
160
+
161
+ wp_cache_flush();
162
+ foreach ( get_taxonomies() as $tax ) {
163
+ delete_option( "{$tax}_children" );
164
+ _get_term_hierarchy( $tax );
165
+ }
166
+
167
+ wp_defer_term_counting( false );
168
+ wp_defer_comment_counting( false );
169
+
170
+ echo '<p>' . __( 'All done.', 'themegrill-demo-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'themegrill-demo-importer' ) . '</a>' . '</p>';
171
+ echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'themegrill-demo-importer' ) . '</p>';
172
+
173
+ do_action( 'import_end' );
174
+ }
175
+
176
+ /**
177
+ * Handles the WXR upload and initial parsing of the file to prepare for
178
+ * displaying author import options
179
+ *
180
+ * @return bool False if error uploading or invalid file, true otherwise
181
+ */
182
+ function handle_upload() {
183
+ $file = wp_import_handle_upload();
184
+
185
+ if ( isset( $file['error'] ) ) {
186
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'themegrill-demo-importer' ) . '</strong><br />';
187
+ echo esc_html( $file['error'] ) . '</p>';
188
+ return false;
189
+ } else if ( ! file_exists( $file['file'] ) ) {
190
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'themegrill-demo-importer' ) . '</strong><br />';
191
+ printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'themegrill-demo-importer' ), esc_html( $file['file'] ) );
192
+ echo '</p>';
193
+ return false;
194
+ }
195
+
196
+ $this->id = (int) $file['id'];
197
+ $import_data = $this->parse( $file['file'] );
198
+ if ( is_wp_error( $import_data ) ) {
199
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'themegrill-demo-importer' ) . '</strong><br />';
200
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
201
+ return false;
202
+ }
203
+
204
+ $this->version = $import_data['version'];
205
+ if ( $this->version > $this->max_wxr_version ) {
206
+ echo '<div class="error"><p><strong>';
207
+ printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'themegrill-demo-importer' ), esc_html($import_data['version']) );
208
+ echo '</strong></p></div>';
209
+ }
210
+
211
+ $this->get_authors_from_import( $import_data );
212
+
213
+ return true;
214
+ }
215
+
216
+ /**
217
+ * Retrieve authors from parsed WXR data
218
+ *
219
+ * Uses the provided author information from WXR 1.1 files
220
+ * or extracts info from each post for WXR 1.0 files
221
+ *
222
+ * @param array $import_data Data returned by a WXR parser
223
+ */
224
+ function get_authors_from_import( $import_data ) {
225
+ if ( ! empty( $import_data['authors'] ) ) {
226
+ $this->authors = $import_data['authors'];
227
+ // no author information, grab it from the posts
228
+ } else {
229
+ foreach ( $import_data['posts'] as $post ) {
230
+ $login = sanitize_user( $post['post_author'], true );
231
+ if ( empty( $login ) ) {
232
+ printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'themegrill-demo-importer' ), esc_html( $post['post_author'] ) );
233
+ echo '<br />';
234
+ continue;
235
+ }
236
+
237
+ if ( ! isset($this->authors[$login]) )
238
+ $this->authors[$login] = array(
239
+ 'author_login' => $login,
240
+ 'author_display_name' => $post['post_author']
241
+ );
242
+ }
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Display pre-import options, author importing/mapping and option to
248
+ * fetch attachments
249
+ */
250
+ function import_options() {
251
+ $j = 0;
252
+ ?>
253
+ <form action="<?php echo admin_url( 'admin.php?import=wordpress&amp;step=2' ); ?>" method="post">
254
+ <?php wp_nonce_field( 'import-wordpress' ); ?>
255
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
256
+
257
+ <?php if ( ! empty( $this->authors ) ) : ?>
258
+ <h3><?php _e( 'Assign Authors', 'themegrill-demo-importer' ); ?></h3>
259
+ <p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'themegrill-demo-importer' ); ?></p>
260
+ <?php if ( $this->allow_create_users() ) : ?>
261
+ <p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user&#8217;s role will be set as %s. Manually changing the new user&#8217;s details will be necessary.', 'themegrill-demo-importer' ), esc_html( get_option('default_role') ) ); ?></p>
262
+ <?php endif; ?>
263
+ <ol id="authors">
264
+ <?php foreach ( $this->authors as $author ) : ?>
265
+ <li><?php $this->author_select( $j++, $author ); ?></li>
266
+ <?php endforeach; ?>
267
+ </ol>
268
+ <?php endif; ?>
269
+
270
+ <?php if ( $this->allow_fetch_attachments() ) : ?>
271
+ <h3><?php _e( 'Import Attachments', 'themegrill-demo-importer' ); ?></h3>
272
+ <p>
273
+ <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments" />
274
+ <label for="import-attachments"><?php _e( 'Download and import file attachments', 'themegrill-demo-importer' ); ?></label>
275
+ </p>
276
+ <?php endif; ?>
277
+
278
+ <p class="submit"><input type="submit" class="button" value="<?php esc_attr_e( 'Submit', 'themegrill-demo-importer' ); ?>" /></p>
279
+ </form>
280
+ <?php
281
+ }
282
+
283
+ /**
284
+ * Display import options for an individual author. That is, either create
285
+ * a new user based on import info or map to an existing user
286
+ *
287
+ * @param int $n Index for each author in the form
288
+ * @param array $author Author information, e.g. login, display name, email
289
+ */
290
+ function author_select( $n, $author ) {
291
+ _e( 'Import author:', 'themegrill-demo-importer' );
292
+ echo ' <strong>' . esc_html( $author['author_display_name'] );
293
+ if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')';
294
+ echo '</strong><br />';
295
+
296
+ if ( $this->version != '1.0' )
297
+ echo '<div style="margin-left:18px">';
298
+
299
+ $create_users = $this->allow_create_users();
300
+ if ( $create_users ) {
301
+ if ( $this->version != '1.0' ) {
302
+ _e( 'or create new user with login name:', 'themegrill-demo-importer' );
303
+ $value = '';
304
+ } else {
305
+ _e( 'as a new user:', 'themegrill-demo-importer' );
306
+ $value = esc_attr( sanitize_user( $author['author_login'], true ) );
307
+ }
308
+
309
+ echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />';
310
+ }
311
+
312
+ if ( ! $create_users && $this->version == '1.0' )
313
+ _e( 'assign posts to an existing user:', 'themegrill-demo-importer' );
314
+ else
315
+ _e( 'or assign posts to an existing user:', 'themegrill-demo-importer' );
316
+ wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'themegrill-demo-importer' ) ) );
317
+ echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />';
318
+
319
+ if ( $this->version != '1.0' )
320
+ echo '</div>';
321
+ }
322
+
323
+ /**
324
+ * Map old author logins to local user IDs based on decisions made
325
+ * in import options form. Can map to an existing user, create a new user
326
+ * or falls back to the current user in case of error with either of the previous
327
+ */
328
+ function get_author_mapping() {
329
+ if ( ! isset( $_POST['imported_authors'] ) )
330
+ return;
331
+
332
+ $create_users = $this->allow_create_users();
333
+
334
+ foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
335
+ // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
336
+ $santized_old_login = sanitize_user( $old_login, true );
337
+ $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
338
+
339
+ if ( ! empty( $_POST['user_map'][$i] ) ) {
340
+ $user = get_userdata( intval($_POST['user_map'][$i]) );
341
+ if ( isset( $user->ID ) ) {
342
+ if ( $old_id )
343
+ $this->processed_authors[$old_id] = $user->ID;
344
+ $this->author_mapping[$santized_old_login] = $user->ID;
345
+ }
346
+ } else if ( $create_users ) {
347
+ if ( ! empty($_POST['user_new'][$i]) ) {
348
+ $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
349
+ } else if ( $this->version != '1.0' ) {
350
+ $user_data = array(
351
+ 'user_login' => $old_login,
352
+ 'user_pass' => wp_generate_password(),
353
+ 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
354
+ 'display_name' => $this->authors[$old_login]['author_display_name'],
355
+ 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
356
+ 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
357
+ );
358
+ $user_id = wp_insert_user( $user_data );
359
+ }
360
+
361
+ if ( ! is_wp_error( $user_id ) ) {
362
+ if ( $old_id )
363
+ $this->processed_authors[$old_id] = $user_id;
364
+ $this->author_mapping[$santized_old_login] = $user_id;
365
+ } else {
366
+ printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'themegrill-demo-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
367
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
368
+ echo ' ' . $user_id->get_error_message();
369
+ echo '<br />';
370
+ }
371
+ }
372
+
373
+ // failsafe: if the user_id was invalid, default to the current user
374
+ if ( ! isset( $this->author_mapping[$santized_old_login] ) ) {
375
+ if ( $old_id )
376
+ $this->processed_authors[$old_id] = (int) get_current_user_id();
377
+ $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
378
+ }
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Create new categories based on import information
384
+ *
385
+ * Doesn't create a new category if its slug already exists
386
+ */
387
+ function process_categories() {
388
+ $this->categories = apply_filters( 'wp_import_categories', $this->categories );
389
+
390
+ if ( empty( $this->categories ) )
391
+ return;
392
+
393
+ foreach ( $this->categories as $cat ) {
394
+ // if the category already exists leave it alone
395
+ $term_id = term_exists( $cat['category_nicename'], 'category' );
396
+ if ( $term_id ) {
397
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
398
+ if ( isset($cat['term_id']) )
399
+ $this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
400
+ continue;
401
+ }
402
+
403
+ $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
404
+ $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
405
+ $catarr = array(
406
+ 'category_nicename' => $cat['category_nicename'],
407
+ 'category_parent' => $category_parent,
408
+ 'cat_name' => $cat['cat_name'],
409
+ 'category_description' => $category_description
410
+ );
411
+ $catarr = wp_slash( $catarr );
412
+
413
+ $id = wp_insert_category( $catarr );
414
+ if ( ! is_wp_error( $id ) ) {
415
+ if ( isset($cat['term_id']) )
416
+ $this->processed_terms[intval($cat['term_id'])] = $id;
417
+ } else {
418
+ printf( __( 'Failed to import category %s', 'themegrill-demo-importer' ), esc_html($cat['category_nicename']) );
419
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
420
+ echo ': ' . $id->get_error_message();
421
+ echo '<br />';
422
+ continue;
423
+ }
424
+
425
+ $this->process_termmeta( $cat, $id['term_id'] );
426
+ }
427
+
428
+ unset( $this->categories );
429
+ }
430
+
431
+ /**
432
+ * Create new post tags based on import information
433
+ *
434
+ * Doesn't create a tag if its slug already exists
435
+ */
436
+ function process_tags() {
437
+ $this->tags = apply_filters( 'wp_import_tags', $this->tags );
438
+
439
+ if ( empty( $this->tags ) )
440
+ return;
441
+
442
+ foreach ( $this->tags as $tag ) {
443
+ // if the tag already exists leave it alone
444
+ $term_id = term_exists( $tag['tag_slug'], 'post_tag' );
445
+ if ( $term_id ) {
446
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
447
+ if ( isset($tag['term_id']) )
448
+ $this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
449
+ continue;
450
+ }
451
+
452
+ $tag = wp_slash( $tag );
453
+ $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
454
+ $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
455
+
456
+ $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
457
+ if ( ! is_wp_error( $id ) ) {
458
+ if ( isset($tag['term_id']) )
459
+ $this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
460
+ } else {
461
+ printf( __( 'Failed to import post tag %s', 'themegrill-demo-importer' ), esc_html($tag['tag_name']) );
462
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
463
+ echo ': ' . $id->get_error_message();
464
+ echo '<br />';
465
+ continue;
466
+ }
467
+
468
+ $this->process_termmeta( $tag, $id['term_id'] );
469
+ }
470
+
471
+ unset( $this->tags );
472
+ }
473
+
474
+ /**
475
+ * Create new terms based on import information
476
+ *
477
+ * Doesn't create a term its slug already exists
478
+ */
479
+ function process_terms() {
480
+ $this->terms = apply_filters( 'wp_import_terms', $this->terms );
481
+
482
+ if ( empty( $this->terms ) )
483
+ return;
484
+
485
+ foreach ( $this->terms as $term ) {
486
+ // if the term already exists in the correct taxonomy leave it alone
487
+ $term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
488
+ if ( $term_id ) {
489
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
490
+ if ( isset($term['term_id']) )
491
+ $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
492
+ continue;
493
+ }
494
+
495
+ if ( empty( $term['term_parent'] ) ) {
496
+ $parent = 0;
497
+ } else {
498
+ $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
499
+ if ( is_array( $parent ) ) $parent = $parent['term_id'];
500
+ }
501
+ $term = wp_slash( $term );
502
+ $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
503
+ $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
504
+
505
+ $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
506
+ if ( ! is_wp_error( $id ) ) {
507
+ if ( isset($term['term_id']) )
508
+ $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
509
+ } else {
510
+ printf( __( 'Failed to import %s %s', 'themegrill-demo-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) );
511
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
512
+ echo ': ' . $id->get_error_message();
513
+ echo '<br />';
514
+ continue;
515
+ }
516
+
517
+ $this->process_termmeta( $term, $id['term_id'] );
518
+ }
519
+
520
+ unset( $this->terms );
521
+ }
522
+
523
+ /**
524
+ * Add metadata to imported term.
525
+ *
526
+ * @since 0.6.2
527
+ *
528
+ * @param array $term Term data from WXR import.
529
+ * @param int $term_id ID of the newly created term.
530
+ */
531
+ protected function process_termmeta( $term, $term_id ) {
532
+ if ( ! isset( $term['termmeta'] ) ) {
533
+ $term['termmeta'] = array();
534
+ }
535
+
536
+ /**
537
+ * Filters the metadata attached to an imported term.
538
+ *
539
+ * @since 0.6.2
540
+ *
541
+ * @param array $termmeta Array of term meta.
542
+ * @param int $term_id ID of the newly created term.
543
+ * @param array $term Term data from the WXR import.
544
+ */
545
+ $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
546
+
547
+ if ( empty( $term['termmeta'] ) ) {
548
+ return;
549
+ }
550
+
551
+ foreach ( $term['termmeta'] as $meta ) {
552
+ /**
553
+ * Filters the meta key for an imported piece of term meta.
554
+ *
555
+ * @since 0.6.2
556
+ *
557
+ * @param string $meta_key Meta key.
558
+ * @param int $term_id ID of the newly created term.
559
+ * @param array $term Term data from the WXR import.
560
+ */
561
+ $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
562
+ if ( ! $key ) {
563
+ continue;
564
+ }
565
+
566
+ // Export gets meta straight from the DB so could have a serialized string
567
+ $value = maybe_unserialize( $meta['value'] );
568
+
569
+ add_term_meta( $term_id, $key, $value );
570
+
571
+ /**
572
+ * Fires after term meta is imported.
573
+ *
574
+ * @since 0.6.2
575
+ *
576
+ * @param int $term_id ID of the newly created term.
577
+ * @param string $key Meta key.
578
+ * @param mixed $value Meta value.
579
+ */
580
+ do_action( 'import_term_meta', $term_id, $key, $value );
581
+ }
582
+ }
583
+
584
+ /**
585
+ * Create new posts based on import information
586
+ *
587
+ * Posts marked as having a parent which doesn't exist will become top level items.
588
+ * Doesn't create a new post if: the post type doesn't exist, the given post ID
589
+ * is already noted as imported or a post with the same title and date already exists.
590
+ * Note that new/updated terms, comments and meta are imported for the last of the above.
591
+ */
592
+ function process_posts() {
593
+ $this->posts = apply_filters( 'wp_import_posts', $this->posts );
594
+
595
+ foreach ( $this->posts as $post ) {
596
+ $post = apply_filters( 'wp_import_post_data_raw', $post );
597
+
598
+ if ( ! post_type_exists( $post['post_type'] ) ) {
599
+ printf( __( 'Failed to import &#8220;%s&#8221;: Invalid post type %s', 'themegrill-demo-importer' ),
600
+ esc_html($post['post_title']), esc_html($post['post_type']) );
601
+ echo '<br />';
602
+ do_action( 'wp_import_post_exists', $post );
603
+ continue;
604
+ }
605
+
606
+ if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) )
607
+ continue;
608
+
609
+ if ( $post['status'] == 'auto-draft' )
610
+ continue;
611
+
612
+ if ( 'nav_menu_item' == $post['post_type'] ) {
613
+ $this->process_menu_item( $post );
614
+ continue;
615
+ }
616
+
617
+ $post_type_object = get_post_type_object( $post['post_type'] );
618
+
619
+ $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
620
+
621
+ /**
622
+ * Filter ID of the existing post corresponding to post currently importing.
623
+ *
624
+ * Return 0 to force the post to be imported. Filter the ID to be something else
625
+ * to override which existing post is mapped to the imported post.
626
+ *
627
+ * @see post_exists()
628
+ * @since 0.6.2
629
+ *
630
+ * @param int $post_exists Post ID, or 0 if post did not exist.
631
+ * @param array $post The post array to be inserted.
632
+ */
633
+ $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
634
+
635
+ if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
636
+ printf( __('%s &#8220;%s&#8221; already exists.', 'themegrill-demo-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) );
637
+ echo '<br />';
638
+ $comment_post_ID = $post_id = $post_exists;
639
+ $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
640
+ } else {
641
+ $post_parent = (int) $post['post_parent'];
642
+ if ( $post_parent ) {
643
+ // if we already know the parent, map it to the new local ID
644
+ if ( isset( $this->processed_posts[$post_parent] ) ) {
645
+ $post_parent = $this->processed_posts[$post_parent];
646
+ // otherwise record the parent for later
647
+ } else {
648
+ $this->post_orphans[intval($post['post_id'])] = $post_parent;
649
+ $post_parent = 0;
650
+ }
651
+ }
652
+
653
+ // map the post author
654
+ $author = sanitize_user( $post['post_author'], true );
655
+ if ( isset( $this->author_mapping[$author] ) )
656
+ $author = $this->author_mapping[$author];
657
+ else
658
+ $author = (int) get_current_user_id();
659
+
660
+ $postdata = array(
661
+ 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
662
+ 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
663
+ 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
664
+ 'post_status' => $post['status'], 'post_name' => $post['post_name'],
665
+ 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
666
+ 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
667
+ 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
668
+ );
669
+
670
+ $original_post_ID = $post['post_id'];
671
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
672
+
673
+ $postdata = wp_slash( $postdata );
674
+
675
+ if ( 'attachment' == $postdata['post_type'] ) {
676
+ $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
677
+
678
+ // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
679
+ // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
680
+ $postdata['upload_date'] = $post['post_date'];
681
+ if ( isset( $post['postmeta'] ) ) {
682
+ foreach( $post['postmeta'] as $meta ) {
683
+ if ( $meta['key'] == '_wp_attached_file' ) {
684
+ if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
685
+ $postdata['upload_date'] = $matches[0];
686
+ break;
687
+ }
688
+ }
689
+ }
690
+
691
+ $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
692
+ } else {
693
+ $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
694
+ do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
695
+ }
696
+
697
+ if ( is_wp_error( $post_id ) ) {
698
+ printf( __( 'Failed to import %s &#8220;%s&#8221;', 'themegrill-demo-importer' ),
699
+ $post_type_object->labels->singular_name, esc_html($post['post_title']) );
700
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
701
+ echo ': ' . $post_id->get_error_message();
702
+ echo '<br />';
703
+ continue;
704
+ }
705
+
706
+ if ( $post['is_sticky'] == 1 )
707
+ stick_post( $post_id );
708
+ }
709
+
710
+ // map pre-import ID to local ID
711
+ $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
712
+
713
+ if ( ! isset( $post['terms'] ) )
714
+ $post['terms'] = array();
715
+
716
+ $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
717
+
718
+ // add categories, tags and other terms
719
+ if ( ! empty( $post['terms'] ) ) {
720
+ $terms_to_set = array();
721
+ foreach ( $post['terms'] as $term ) {
722
+ // back compat with WXR 1.0 map 'tag' to 'post_tag'
723
+ $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain'];
724
+ $term_exists = term_exists( $term['slug'], $taxonomy );
725
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
726
+ if ( ! $term_id ) {
727
+ $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
728
+ if ( ! is_wp_error( $t ) ) {
729
+ $term_id = $t['term_id'];
730
+ do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
731
+ } else {
732
+ printf( __( 'Failed to import %s %s', 'themegrill-demo-importer' ), esc_html($taxonomy), esc_html($term['name']) );
733
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
734
+ echo ': ' . $t->get_error_message();
735
+ echo '<br />';
736
+ do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post );
737
+ continue;
738
+ }
739
+ }
740
+ $terms_to_set[$taxonomy][] = intval( $term_id );
741
+ }
742
+
743
+ foreach ( $terms_to_set as $tax => $ids ) {
744
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
745
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
746
+ }
747
+ unset( $post['terms'], $terms_to_set );
748
+ }
749
+
750
+ if ( ! isset( $post['comments'] ) )
751
+ $post['comments'] = array();
752
+
753
+ $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
754
+
755
+ // add/update comments
756
+ if ( ! empty( $post['comments'] ) ) {
757
+ $num_comments = 0;
758
+ $inserted_comments = array();
759
+ foreach ( $post['comments'] as $comment ) {
760
+ $comment_id = $comment['comment_id'];
761
+ $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
762
+ $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
763
+ $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
764
+ $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
765
+ $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
766
+ $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
767
+ $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
768
+ $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
769
+ $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
770
+ $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
771
+ $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
772
+ $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
773
+ if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
774
+ $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
775
+ }
776
+ ksort( $newcomments );
777
+
778
+ foreach ( $newcomments as $key => $comment ) {
779
+ // if this is a new post we can skip the comment_exists() check
780
+ if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
781
+ if ( isset( $inserted_comments[$comment['comment_parent']] ) )
782
+ $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
783
+ $comment = wp_filter_comment( $comment );
784
+ $inserted_comments[$key] = wp_insert_comment( $comment );
785
+ do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
786
+
787
+ foreach( $comment['commentmeta'] as $meta ) {
788
+ $value = maybe_unserialize( $meta['value'] );
789
+ add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
790
+ }
791
+
792
+ $num_comments++;
793
+ }
794
+ }
795
+ unset( $newcomments, $inserted_comments, $post['comments'] );
796
+ }
797
+
798
+ if ( ! isset( $post['postmeta'] ) )
799
+ $post['postmeta'] = array();
800
+
801
+ $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
802
+
803
+ // add/update post meta
804
+ if ( ! empty( $post['postmeta'] ) ) {
805
+ foreach ( $post['postmeta'] as $meta ) {
806
+ $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
807
+ $value = false;
808
+
809
+ if ( '_edit_last' == $key ) {
810
+ if ( isset( $this->processed_authors[intval($meta['value'])] ) )
811
+ $value = $this->processed_authors[intval($meta['value'])];
812
+ else
813
+ $key = false;
814
+ }
815
+
816
+ if ( $key ) {
817
+ // export gets meta straight from the DB so could have a serialized string
818
+ if ( ! $value )
819
+ $value = maybe_unserialize( $meta['value'] );
820
+
821
+ add_post_meta( $post_id, $key, $value );
822
+ do_action( 'import_post_meta', $post_id, $key, $value );
823
+
824
+ // if the post has a featured image, take note of this in case of remap
825
+ if ( '_thumbnail_id' == $key )
826
+ $this->featured_images[$post_id] = (int) $value;
827
+ }
828
+ }
829
+ }
830
+ }
831
+
832
+ unset( $this->posts );
833
+ }
834
+
835
+ /**
836
+ * Attempt to create a new menu item from import data
837
+ *
838
+ * Fails for draft, orphaned menu items and those without an associated nav_menu
839
+ * or an invalid nav_menu term. If the post type or term object which the menu item
840
+ * represents doesn't exist then the menu item will not be imported (waits until the
841
+ * end of the import to retry again before discarding).
842
+ *
843
+ * @param array $item Menu item details from WXR file
844
+ */
845
+ function process_menu_item( $item ) {
846
+ // skip draft, orphaned menu items
847
+ if ( 'draft' == $item['status'] )
848
+ return;
849
+
850
+ $menu_slug = false;
851
+ if ( isset($item['terms']) ) {
852
+ // loop through terms, assume first nav_menu term is correct menu
853
+ foreach ( $item['terms'] as $term ) {
854
+ if ( 'nav_menu' == $term['domain'] ) {
855
+ $menu_slug = $term['slug'];
856
+ break;
857
+ }
858
+ }
859
+ }
860
+
861
+ // no nav_menu term associated with this menu item
862
+ if ( ! $menu_slug ) {
863
+ _e( 'Menu item skipped due to missing menu slug', 'themegrill-demo-importer' );
864
+ echo '<br />';
865
+ return;
866
+ }
867
+
868
+ $menu_id = term_exists( $menu_slug, 'nav_menu' );
869
+ if ( ! $menu_id ) {
870
+ printf( __( 'Menu item skipped due to invalid menu slug: %s', 'themegrill-demo-importer' ), esc_html( $menu_slug ) );
871
+ echo '<br />';
872
+ return;
873
+ } else {
874
+ $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id;
875
+ }
876
+
877
+ foreach ( $item['postmeta'] as $meta ) {
878
+ if ( version_compare( PHP_VERSION, '7.0.0' ) >= 0 ) {
879
+ ${$meta['key']} = $meta['value'];
880
+ } else {
881
+ $$meta['key'] = $meta['value'];
882
+ }
883
+ }
884
+
885
+ if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) {
886
+ $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)];
887
+ } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval($_menu_item_object_id)] ) ) {
888
+ $_menu_item_object_id = $this->processed_posts[intval($_menu_item_object_id)];
889
+ } else if ( 'custom' != $_menu_item_type ) {
890
+ // associated object is missing or not imported yet, we'll retry later
891
+ $this->missing_menu_items[] = $item;
892
+ return;
893
+ }
894
+
895
+ if ( isset( $this->processed_menu_items[intval($_menu_item_menu_item_parent)] ) ) {
896
+ $_menu_item_menu_item_parent = $this->processed_menu_items[intval($_menu_item_menu_item_parent)];
897
+ } else if ( $_menu_item_menu_item_parent ) {
898
+ $this->menu_item_orphans[intval($item['post_id'])] = (int) $_menu_item_menu_item_parent;
899
+ $_menu_item_menu_item_parent = 0;
900
+ }
901
+
902
+ // wp_update_nav_menu_item expects CSS classes as a space separated string
903
+ $_menu_item_classes = maybe_unserialize( $_menu_item_classes );
904
+ if ( is_array( $_menu_item_classes ) )
905
+ $_menu_item_classes = implode( ' ', $_menu_item_classes );
906
+
907
+ $args = array(
908
+ 'menu-item-object-id' => $_menu_item_object_id,
909
+ 'menu-item-object' => $_menu_item_object,
910
+ 'menu-item-parent-id' => $_menu_item_menu_item_parent,
911
+ 'menu-item-position' => intval( $item['menu_order'] ),
912
+ 'menu-item-type' => $_menu_item_type,
913
+ 'menu-item-title' => $item['post_title'],
914
+ 'menu-item-url' => $_menu_item_url,
915
+ 'menu-item-description' => $item['post_content'],
916
+ 'menu-item-attr-title' => $item['post_excerpt'],
917
+ 'menu-item-target' => $_menu_item_target,
918
+ 'menu-item-classes' => $_menu_item_classes,
919
+ 'menu-item-xfn' => $_menu_item_xfn,
920
+ 'menu-item-status' => $item['status']
921
+ );
922
+
923
+ $id = wp_update_nav_menu_item( $menu_id, 0, $args );
924
+ if ( $id && ! is_wp_error( $id ) )
925
+ $this->processed_menu_items[intval($item['post_id'])] = (int) $id;
926
+ }
927
+
928
+ /**
929
+ * If fetching attachments is enabled then attempt to create a new attachment
930
+ *
931
+ * @param array $post Attachment post details from WXR
932
+ * @param string $remote_url URL to fetch attachment from
933
+ * @return int|WP_Error Post ID on success, WP_Error otherwise
934
+ */
935
+ function process_attachment( $post, $remote_url ) {
936
+ if ( ! $this->fetch_attachments )
937
+ return new WP_Error( 'attachment_processing_error',
938
+ __( 'Fetching attachments is not enabled', 'themegrill-demo-importer' ) );
939
+
940
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
941
+ if ( preg_match( '|^/[\w\W]+$|', $remote_url ) ) {
942
+ $remote_url = rtrim( $this->base_url, '/' ) . $remote_url;
943
+ }
944
+
945
+ $upload = $this->fetch_remote_file( $remote_url, $post );
946
+ if ( is_wp_error( $upload ) ) {
947
+ return $upload;
948
+ }
949
+
950
+ $info = wp_check_filetype( $upload['file'] );
951
+ if ( ! $info ) {
952
+ return new WP_Error( 'attachment_processing_error', __( 'Invalid file type', 'themegrill-demo-importer' ) );
953
+ }
954
+
955
+ $post['post_mime_type'] = $info['type'];
956
+
957
+ // WP really likes using the GUID for display. Allow updating it.
958
+ // See https://core.trac.wordpress.org/ticket/33386
959
+ $post['guid'] = $upload['url'];
960
+
961
+ // as per wp-admin/includes/upload.php
962
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
963
+ if ( is_wp_error( $post_id ) ) {
964
+ return $post_id;
965
+ }
966
+
967
+ $attachment_metadata = wp_generate_attachment_metadata( $post_id, $upload['file'] );
968
+ wp_update_attachment_metadata( $post_id, $attachment_metadata );
969
+
970
+ // Map this image URL later if we need to
971
+ $this->url_remap[ $remote_url ] = $upload['url'];
972
+
973
+ // If we have a HTTPS URL, ensure the HTTP URL gets replaced too
974
+ if ( substr( $remote_url, 0, 8 ) === 'https://' ) {
975
+ $insecure_url = 'http' . substr( $remote_url, 5 );
976
+ $this->url_remap[ $insecure_url ] = $upload['url'];
977
+ }
978
+
979
+ // remap resized image URLs, works by stripping the extension and remapping the URL stub.
980
+ /*if ( preg_match( '!^image/!', $info['type'] ) ) {
981
+ $parts = pathinfo( $remote_url );
982
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
983
+
984
+ $parts_new = pathinfo( $upload['url'] );
985
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
986
+
987
+ $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
988
+ }*/
989
+
990
+ return $post_id;
991
+ }
992
+
993
+ /**
994
+ * Attempt to download a remote file attachment
995
+ *
996
+ * @param string $url URL of item to fetch
997
+ * @param array $post Attachment details
998
+ * @return array|WP_Error Local file location details on success, WP_Error otherwise
999
+ */
1000
+ protected function fetch_remote_file( $url, $post ) {
1001
+ // extract the file name and extension from the url
1002
+ $file_name = basename( $url );
1003
+
1004
+ // get placeholder file in the upload dir with a unique, sanitized filename
1005
+ $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1006
+ if ( $upload['error'] ) {
1007
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1008
+ }
1009
+
1010
+ // fetch the remote url and write it to the placeholder file
1011
+ $response = wp_remote_get( $url, array(
1012
+ 'stream' => true,
1013
+ 'filename' => $upload['file'],
1014
+ ) );
1015
+
1016
+ // request failed
1017
+ if ( is_wp_error( $response ) ) {
1018
+ unlink( $upload['file'] );
1019
+ return $response;
1020
+ }
1021
+
1022
+ $code = (int) wp_remote_retrieve_response_code( $response );
1023
+
1024
+ // make sure the fetch was successful
1025
+ if ( $code !== 200 ) {
1026
+ unlink( $upload['file'] );
1027
+ return new WP_Error(
1028
+ 'import_file_error',
1029
+ sprintf(
1030
+ __( 'Remote server returned %1$d %2$s for %3$s', 'themegrill-demo-importer' ),
1031
+ $code,
1032
+ get_status_header_desc( $code ),
1033
+ $url
1034
+ )
1035
+ );
1036
+ }
1037
+
1038
+ $filesize = filesize( $upload['file'] );
1039
+ $headers = wp_remote_retrieve_headers( $response );
1040
+
1041
+ if ( isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) {
1042
+ unlink( $upload['file'] );
1043
+ return new WP_Error( 'import_file_error', __( 'Remote file is incorrect size', 'themegrill-demo-importer' ) );
1044
+ }
1045
+
1046
+ if ( 0 === $filesize ) {
1047
+ unlink( $upload['file'] );
1048
+ return new WP_Error( 'import_file_error', __( 'Zero size file downloaded', 'themegrill-demo-importer' ) );
1049
+ }
1050
+
1051
+ $max_size = (int) $this->max_attachment_size();
1052
+ if ( ! empty( $max_size ) && $filesize > $max_size ) {
1053
+ unlink( $upload['file'] );
1054
+ $message = sprintf( __( 'Remote file is too large, limit is %s', 'themegrill-demo-importer' ), size_format( $max_size ) );
1055
+ return new WP_Error( 'import_file_error', $message );
1056
+ }
1057
+
1058
+ return $upload;
1059
+ }
1060
+
1061
+ /**
1062
+ * Attempt to associate posts and menu items with previously missing parents
1063
+ *
1064
+ * An imported post's parent may not have been imported when it was first created
1065
+ * so try again. Similarly for child menu items and menu items which were missing
1066
+ * the object (e.g. post) they represent in the menu
1067
+ */
1068
+ function backfill_parents() {
1069
+ global $wpdb;
1070
+
1071
+ // find parents for post orphans
1072
+ foreach ( $this->post_orphans as $child_id => $parent_id ) {
1073
+ $local_child_id = $local_parent_id = false;
1074
+ if ( isset( $this->processed_posts[$child_id] ) )
1075
+ $local_child_id = $this->processed_posts[$child_id];
1076
+ if ( isset( $this->processed_posts[$parent_id] ) )
1077
+ $local_parent_id = $this->processed_posts[$parent_id];
1078
+
1079
+ if ( $local_child_id && $local_parent_id )
1080
+ $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1081
+ }
1082
+
1083
+ // all other posts/terms are imported, retry menu items with missing associated object
1084
+ $missing_menu_items = $this->missing_menu_items;
1085
+ foreach ( $missing_menu_items as $item )
1086
+ $this->process_menu_item( $item );
1087
+
1088
+ // find parents for menu item orphans
1089
+ foreach ( $this->menu_item_orphans as $child_id => $parent_id ) {
1090
+ $local_child_id = $local_parent_id = 0;
1091
+ if ( isset( $this->processed_menu_items[$child_id] ) )
1092
+ $local_child_id = $this->processed_menu_items[$child_id];
1093
+ if ( isset( $this->processed_menu_items[$parent_id] ) )
1094
+ $local_parent_id = $this->processed_menu_items[$parent_id];
1095
+
1096
+ if ( $local_child_id && $local_parent_id )
1097
+ update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id );
1098
+ }
1099
+ }
1100
+
1101
+ /**
1102
+ * Use stored mapping information to update old attachment URLs
1103
+ */
1104
+ function backfill_attachment_urls() {
1105
+ global $wpdb;
1106
+ // make sure we do the longest urls first, in case one is a substring of another
1107
+ uksort( $this->url_remap, array(&$this, 'cmpr_strlen') );
1108
+
1109
+ foreach ( $this->url_remap as $from_url => $to_url ) {
1110
+ // remap urls in post_content
1111
+ $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) );
1112
+ // remap enclosure urls
1113
+ $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) );
1114
+ }
1115
+ }
1116
+
1117
+ /**
1118
+ * Update _thumbnail_id meta to new, imported attachment IDs
1119
+ */
1120
+ function remap_featured_images() {
1121
+ // cycle through posts that have a featured image
1122
+ foreach ( $this->featured_images as $post_id => $value ) {
1123
+ if ( isset( $this->processed_posts[$value] ) ) {
1124
+ $new_id = $this->processed_posts[$value];
1125
+ // only update if there's a difference
1126
+ if ( $new_id != $value )
1127
+ update_post_meta( $post_id, '_thumbnail_id', $new_id );
1128
+ }
1129
+ }
1130
+ }
1131
+
1132
+ /**
1133
+ * Parse a WXR file
1134
+ *
1135
+ * @param string $file Path to WXR file for parsing
1136
+ * @return array Information gathered from the WXR file
1137
+ */
1138
+ function parse( $file ) {
1139
+ $parser = new TG_WXR_Parser();
1140
+ return $parser->parse( $file );
1141
+ }
1142
+
1143
+ // Display import page title
1144
+ function header() {
1145
+ echo '<div class="wrap">';
1146
+ screen_icon();
1147
+ echo '<h2>' . __( 'Import WordPress', 'themegrill-demo-importer' ) . '</h2>';
1148
+
1149
+ $updates = get_plugin_updates();
1150
+ $basename = plugin_basename(__FILE__);
1151
+ if ( isset( $updates[$basename] ) ) {
1152
+ $update = $updates[$basename];
1153
+ echo '<div class="error"><p><strong>';
1154
+ printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'themegrill-demo-importer' ), $update->update->new_version );
1155
+ echo '</strong></p></div>';
1156
+ }
1157
+ }
1158
+
1159
+ // Close div.wrap
1160
+ function footer() {
1161
+ echo '</div>';
1162
+ }
1163
+
1164
+ /**
1165
+ * Display introductory text and file upload form
1166
+ */
1167
+ function greet() {
1168
+ echo '<div class="narrow">';
1169
+ echo '<p>'.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'themegrill-demo-importer' ).'</p>';
1170
+ echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'themegrill-demo-importer' ).'</p>';
1171
+ wp_import_upload_form( 'admin.php?import=wordpress&amp;step=1' );
1172
+ echo '</div>';
1173
+ }
1174
+
1175
+ /**
1176
+ * Decide if the given meta key maps to information we will want to import
1177
+ *
1178
+ * @param string $key The meta key to check
1179
+ * @return string|bool The key if we do want to import, false if not
1180
+ */
1181
+ function is_valid_meta_key( $key ) {
1182
+ // skip attachment metadata since we'll regenerate it from scratch
1183
+ // skip _edit_lock as not relevant for import
1184
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
1185
+ return false;
1186
+ return $key;
1187
+ }
1188
+
1189
+ /**
1190
+ * Decide whether or not the importer is allowed to create users.
1191
+ * Default is true, can be filtered via import_allow_create_users
1192
+ *
1193
+ * @return bool True if creating users is allowed
1194
+ */
1195
+ function allow_create_users() {
1196
+ return apply_filters( 'import_allow_create_users', true );
1197
+ }
1198
+
1199
+ /**
1200
+ * Decide whether or not the importer should attempt to download attachment files.
1201
+ * Default is true, can be filtered via import_allow_fetch_attachments. The choice
1202
+ * made at the import options screen must also be true, false here hides that checkbox.
1203
+ *
1204
+ * @return bool True if downloading attachments is allowed
1205
+ */
1206
+ function allow_fetch_attachments() {
1207
+ return apply_filters( 'import_allow_fetch_attachments', true );
1208
+ }
1209
+
1210
+ /**
1211
+ * Decide what the maximum file size for downloaded attachments is.
1212
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1213
+ *
1214
+ * @return int Maximum attachment file size to import
1215
+ */
1216
+ function max_attachment_size() {
1217
+ return apply_filters( 'import_attachment_size_limit', 0 );
1218
+ }
1219
+
1220
+ /**
1221
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
1222
+ * @return int 60
1223
+ */
1224
+ function bump_request_timeout( $val ) {
1225
+ return 60;
1226
+ }
1227
+
1228
+ // return the difference in length between two strings
1229
+ function cmpr_strlen( $a, $b ) {
1230
+ return strlen($b) - strlen($a);
1231
+ }
1232
+ }
includes/includes/importers/class-wxr-parsers.php ADDED
@@ -0,0 +1,693 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WordPress eXtended RSS file parser implementations
4
+ *
5
+ * Code adapted from the "WordPress Importer" plugin.
6
+ *
7
+ * @package WordPress
8
+ * @subpackage Importer
9
+ */
10
+
11
+ /**
12
+ * WordPress Importer class for managing parsing of WXR files.
13
+ */
14
+ class TG_WXR_Parser {
15
+ function parse( $file ) {
16
+ // Attempt to use proper XML parsers first
17
+ if ( extension_loaded( 'simplexml' ) ) {
18
+ $parser = new TG_WXR_Parser_SimpleXML;
19
+ $result = $parser->parse( $file );
20
+
21
+ // If SimpleXML succeeds or this is an invalid WXR file then return the results
22
+ if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
23
+ return $result;
24
+ } else if ( extension_loaded( 'xml' ) ) {
25
+ $parser = new TG_WXR_Parser_XML;
26
+ $result = $parser->parse( $file );
27
+
28
+ // If XMLParser succeeds or this is an invalid WXR file then return the results
29
+ if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
30
+ return $result;
31
+ }
32
+
33
+ // We have a malformed XML file, so display the error and fallthrough to regex
34
+ if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
35
+ echo '<pre>';
36
+ if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
37
+ foreach ( $result->get_error_data() as $error )
38
+ echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
39
+ } else if ( 'XML_parse_error' == $result->get_error_code() ) {
40
+ $error = $result->get_error_data();
41
+ echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
42
+ }
43
+ echo '</pre>';
44
+ echo '<p><strong>' . __( 'There was an error when reading this WXR file', 'themegrill-demo-importer' ) . '</strong><br />';
45
+ echo __( 'Details are shown above. The importer will now try again with a different parser...', 'themegrill-demo-importer' ) . '</p>';
46
+ }
47
+
48
+ // use regular expressions if nothing else available or this is bad XML
49
+ $parser = new TG_WXR_Parser_Regex;
50
+ return $parser->parse( $file );
51
+ }
52
+ }
53
+
54
+ /**
55
+ * WXR Parser that makes use of the SimpleXML PHP extension.
56
+ */
57
+ class TG_WXR_Parser_SimpleXML {
58
+ function parse( $file ) {
59
+ $authors = $posts = $categories = $tags = $terms = array();
60
+
61
+ $internal_errors = libxml_use_internal_errors(true);
62
+
63
+ $dom = new DOMDocument;
64
+ $old_value = null;
65
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
66
+ $old_value = libxml_disable_entity_loader( true );
67
+ }
68
+ $success = $dom->loadXML( file_get_contents( $file ) );
69
+ if ( ! is_null( $old_value ) ) {
70
+ libxml_disable_entity_loader( $old_value );
71
+ }
72
+
73
+ if ( ! $success || isset( $dom->doctype ) ) {
74
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'themegrill-demo-importer' ), libxml_get_errors() );
75
+ }
76
+
77
+ $xml = simplexml_import_dom( $dom );
78
+ unset( $dom );
79
+
80
+ // halt if loading produces an error
81
+ if ( ! $xml )
82
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'themegrill-demo-importer' ), libxml_get_errors() );
83
+
84
+ $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
85
+ if ( ! $wxr_version )
86
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'themegrill-demo-importer' ) );
87
+
88
+ $wxr_version = (string) trim( $wxr_version[0] );
89
+ // confirm that we are dealing with the correct file format
90
+ if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
91
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'themegrill-demo-importer' ) );
92
+
93
+ $base_url = $xml->xpath('/rss/channel/wp:base_site_url');
94
+ $base_url = (string) trim( $base_url[0] );
95
+
96
+ $namespaces = $xml->getDocNamespaces();
97
+ if ( ! isset( $namespaces['wp'] ) )
98
+ $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
99
+ if ( ! isset( $namespaces['excerpt'] ) )
100
+ $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
101
+
102
+ // grab authors
103
+ foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
104
+ $a = $author_arr->children( $namespaces['wp'] );
105
+ $login = (string) $a->author_login;
106
+ $authors[$login] = array(
107
+ 'author_id' => (int) $a->author_id,
108
+ 'author_login' => $login,
109
+ 'author_email' => (string) $a->author_email,
110
+ 'author_display_name' => (string) $a->author_display_name,
111
+ 'author_first_name' => (string) $a->author_first_name,
112
+ 'author_last_name' => (string) $a->author_last_name
113
+ );
114
+ }
115
+
116
+ // grab cats, tags and terms
117
+ foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) {
118
+ $t = $term_arr->children( $namespaces['wp'] );
119
+ $category = array(
120
+ 'term_id' => (int) $t->term_id,
121
+ 'category_nicename' => (string) $t->category_nicename,
122
+ 'category_parent' => (string) $t->category_parent,
123
+ 'cat_name' => (string) $t->cat_name,
124
+ 'category_description' => (string) $t->category_description
125
+ );
126
+
127
+ foreach ( $t->termmeta as $meta ) {
128
+ $category['termmeta'][] = array(
129
+ 'key' => (string) $meta->meta_key,
130
+ 'value' => (string) $meta->meta_value
131
+ );
132
+ }
133
+
134
+ $categories[] = $category;
135
+ }
136
+
137
+ foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
138
+ $t = $term_arr->children( $namespaces['wp'] );
139
+ $tag = array(
140
+ 'term_id' => (int) $t->term_id,
141
+ 'tag_slug' => (string) $t->tag_slug,
142
+ 'tag_name' => (string) $t->tag_name,
143
+ 'tag_description' => (string) $t->tag_description
144
+ );
145
+
146
+ foreach ( $t->termmeta as $meta ) {
147
+ $tag['termmeta'][] = array(
148
+ 'key' => (string) $meta->meta_key,
149
+ 'value' => (string) $meta->meta_value
150
+ );
151
+ }
152
+
153
+ $tags[] = $tag;
154
+ }
155
+
156
+ foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
157
+ $t = $term_arr->children( $namespaces['wp'] );
158
+ $term = array(
159
+ 'term_id' => (int) $t->term_id,
160
+ 'term_taxonomy' => (string) $t->term_taxonomy,
161
+ 'slug' => (string) $t->term_slug,
162
+ 'term_parent' => (string) $t->term_parent,
163
+ 'term_name' => (string) $t->term_name,
164
+ 'term_description' => (string) $t->term_description
165
+ );
166
+
167
+ foreach ( $t->termmeta as $meta ) {
168
+ $term['termmeta'][] = array(
169
+ 'key' => (string) $meta->meta_key,
170
+ 'value' => (string) $meta->meta_value
171
+ );
172
+ }
173
+
174
+ $terms[] = $term;
175
+ }
176
+
177
+ // grab posts
178
+ foreach ( $xml->channel->item as $item ) {
179
+ $post = array(
180
+ 'post_title' => (string) $item->title,
181
+ 'guid' => (string) $item->guid,
182
+ );
183
+
184
+ $dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
185
+ $post['post_author'] = (string) $dc->creator;
186
+
187
+ $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
188
+ $excerpt = $item->children( $namespaces['excerpt'] );
189
+ $post['post_content'] = (string) $content->encoded;
190
+ $post['post_excerpt'] = (string) $excerpt->encoded;
191
+
192
+ $wp = $item->children( $namespaces['wp'] );
193
+ $post['post_id'] = (int) $wp->post_id;
194
+ $post['post_date'] = (string) $wp->post_date;
195
+ $post['post_date_gmt'] = (string) $wp->post_date_gmt;
196
+ $post['comment_status'] = (string) $wp->comment_status;
197
+ $post['ping_status'] = (string) $wp->ping_status;
198
+ $post['post_name'] = (string) $wp->post_name;
199
+ $post['status'] = (string) $wp->status;
200
+ $post['post_parent'] = (int) $wp->post_parent;
201
+ $post['menu_order'] = (int) $wp->menu_order;
202
+ $post['post_type'] = (string) $wp->post_type;
203
+ $post['post_password'] = (string) $wp->post_password;
204
+ $post['is_sticky'] = (int) $wp->is_sticky;
205
+
206
+ if ( isset($wp->attachment_url) )
207
+ $post['attachment_url'] = (string) $wp->attachment_url;
208
+
209
+ foreach ( $item->category as $c ) {
210
+ $att = $c->attributes();
211
+ if ( isset( $att['nicename'] ) )
212
+ $post['terms'][] = array(
213
+ 'name' => (string) $c,
214
+ 'slug' => (string) $att['nicename'],
215
+ 'domain' => (string) $att['domain']
216
+ );
217
+ }
218
+
219
+ foreach ( $wp->postmeta as $meta ) {
220
+ $post['postmeta'][] = array(
221
+ 'key' => (string) $meta->meta_key,
222
+ 'value' => (string) $meta->meta_value
223
+ );
224
+ }
225
+
226
+ foreach ( $wp->comment as $comment ) {
227
+ $meta = array();
228
+ if ( isset( $comment->commentmeta ) ) {
229
+ foreach ( $comment->commentmeta as $m ) {
230
+ $meta[] = array(
231
+ 'key' => (string) $m->meta_key,
232
+ 'value' => (string) $m->meta_value
233
+ );
234
+ }
235
+ }
236
+
237
+ $post['comments'][] = array(
238
+ 'comment_id' => (int) $comment->comment_id,
239
+ 'comment_author' => (string) $comment->comment_author,
240
+ 'comment_author_email' => (string) $comment->comment_author_email,
241
+ 'comment_author_IP' => (string) $comment->comment_author_IP,
242
+ 'comment_author_url' => (string) $comment->comment_author_url,
243
+ 'comment_date' => (string) $comment->comment_date,
244
+ 'comment_date_gmt' => (string) $comment->comment_date_gmt,
245
+ 'comment_content' => (string) $comment->comment_content,
246
+ 'comment_approved' => (string) $comment->comment_approved,
247
+ 'comment_type' => (string) $comment->comment_type,
248
+ 'comment_parent' => (string) $comment->comment_parent,
249
+ 'comment_user_id' => (int) $comment->comment_user_id,
250
+ 'commentmeta' => $meta,
251
+ );
252
+ }
253
+
254
+ $posts[] = $post;
255
+ }
256
+
257
+ return array(
258
+ 'authors' => $authors,
259
+ 'posts' => $posts,
260
+ 'categories' => $categories,
261
+ 'tags' => $tags,
262
+ 'terms' => $terms,
263
+ 'base_url' => $base_url,
264
+ 'version' => $wxr_version
265
+ );
266
+ }
267
+ }
268
+
269
+ /**
270
+ * WXR Parser that makes use of the XML Parser PHP extension.
271
+ */
272
+ class TG_WXR_Parser_XML {
273
+ var $wp_tags = array(
274
+ 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
275
+ 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
276
+ 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
277
+ 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
278
+ 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
279
+ 'wp:author_first_name', 'wp:author_last_name',
280
+ );
281
+ var $wp_sub_tags = array(
282
+ 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
283
+ 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
284
+ 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
285
+ );
286
+
287
+ function parse( $file ) {
288
+ $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
289
+ $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
290
+
291
+ $xml = xml_parser_create( 'UTF-8' );
292
+ xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
293
+ xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
294
+ xml_set_object( $xml, $this );
295
+ xml_set_character_data_handler( $xml, 'cdata' );
296
+ xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
297
+
298
+ if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) {
299
+ $current_line = xml_get_current_line_number( $xml );
300
+ $current_column = xml_get_current_column_number( $xml );
301
+ $error_code = xml_get_error_code( $xml );
302
+ $error_string = xml_error_string( $error_code );
303
+ return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
304
+ }
305
+ xml_parser_free( $xml );
306
+
307
+ if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
308
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'themegrill-demo-importer' ) );
309
+
310
+ return array(
311
+ 'authors' => $this->authors,
312
+ 'posts' => $this->posts,
313
+ 'categories' => $this->category,
314
+ 'tags' => $this->tag,
315
+ 'terms' => $this->term,
316
+ 'base_url' => $this->base_url,
317
+ 'version' => $this->wxr_version
318
+ );
319
+ }
320
+
321
+ function tag_open( $parse, $tag, $attr ) {
322
+ if ( in_array( $tag, $this->wp_tags ) ) {
323
+ $this->in_tag = substr( $tag, 3 );
324
+ return;
325
+ }
326
+
327
+ if ( in_array( $tag, $this->wp_sub_tags ) ) {
328
+ $this->in_sub_tag = substr( $tag, 3 );
329
+ return;
330
+ }
331
+
332
+ switch ( $tag ) {
333
+ case 'category':
334
+ if ( isset($attr['domain'], $attr['nicename']) ) {
335
+ $this->sub_data['domain'] = $attr['domain'];
336
+ $this->sub_data['slug'] = $attr['nicename'];
337
+ }
338
+ break;
339
+ case 'item': $this->in_post = true;
340
+ case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
341
+ case 'guid': $this->in_tag = 'guid'; break;
342
+ case 'dc:creator': $this->in_tag = 'post_author'; break;
343
+ case 'content:encoded': $this->in_tag = 'post_content'; break;
344
+ case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
345
+
346
+ case 'wp:term_slug': $this->in_tag = 'slug'; break;
347
+ case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
348
+ case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
349
+ }
350
+ }
351
+
352
+ function cdata( $parser, $cdata ) {
353
+ if ( ! trim( $cdata ) )
354
+ return;
355
+
356
+ if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
357
+ $this->cdata .= $cdata;
358
+ } else {
359
+ $this->cdata .= trim( $cdata );
360
+ }
361
+ }
362
+
363
+ function tag_close( $parser, $tag ) {
364
+ switch ( $tag ) {
365
+ case 'wp:comment':
366
+ unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
367
+ if ( ! empty( $this->sub_data ) )
368
+ $this->data['comments'][] = $this->sub_data;
369
+ $this->sub_data = false;
370
+ break;
371
+ case 'wp:commentmeta':
372
+ $this->sub_data['commentmeta'][] = array(
373
+ 'key' => $this->sub_data['key'],
374
+ 'value' => $this->sub_data['value']
375
+ );
376
+ break;
377
+ case 'category':
378
+ if ( ! empty( $this->sub_data ) ) {
379
+ $this->sub_data['name'] = $this->cdata;
380
+ $this->data['terms'][] = $this->sub_data;
381
+ }
382
+ $this->sub_data = false;
383
+ break;
384
+ case 'wp:postmeta':
385
+ if ( ! empty( $this->sub_data ) )
386
+ $this->data['postmeta'][] = $this->sub_data;
387
+ $this->sub_data = false;
388
+ break;
389
+ case 'item':
390
+ $this->posts[] = $this->data;
391
+ $this->data = false;
392
+ break;
393
+ case 'wp:category':
394
+ case 'wp:tag':
395
+ case 'wp:term':
396
+ $n = substr( $tag, 3 );
397
+ array_push( $this->$n, $this->data );
398
+ $this->data = false;
399
+ break;
400
+ case 'wp:author':
401
+ if ( ! empty($this->data['author_login']) )
402
+ $this->authors[$this->data['author_login']] = $this->data;
403
+ $this->data = false;
404
+ break;
405
+ case 'wp:base_site_url':
406
+ $this->base_url = $this->cdata;
407
+ break;
408
+ case 'wp:wxr_version':
409
+ $this->wxr_version = $this->cdata;
410
+ break;
411
+
412
+ default:
413
+ if ( $this->in_sub_tag ) {
414
+ $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
415
+ $this->in_sub_tag = false;
416
+ } else if ( $this->in_tag ) {
417
+ $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
418
+ $this->in_tag = false;
419
+ }
420
+ }
421
+
422
+ $this->cdata = false;
423
+ }
424
+ }
425
+
426
+ /**
427
+ * WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
428
+ */
429
+ class TG_WXR_Parser_Regex {
430
+ var $authors = array();
431
+ var $posts = array();
432
+ var $categories = array();
433
+ var $tags = array();
434
+ var $terms = array();
435
+ var $base_url = '';
436
+
437
+ function __construct() {
438
+ $this->has_gzip = is_callable( 'gzopen' );
439
+ }
440
+
441
+ function parse( $file ) {
442
+ $wxr_version = $in_post = false;
443
+
444
+ $fp = $this->fopen( $file, 'r' );
445
+ if ( $fp ) {
446
+ while ( ! $this->feof( $fp ) ) {
447
+ $importline = rtrim( $this->fgets( $fp ) );
448
+
449
+ if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
450
+ $wxr_version = $version[1];
451
+
452
+ if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
453
+ preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
454
+ $this->base_url = $url[1];
455
+ continue;
456
+ }
457
+ if ( false !== strpos( $importline, '<wp:category>' ) ) {
458
+ preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category );
459
+ $this->categories[] = $this->process_category( $category[1] );
460
+ continue;
461
+ }
462
+ if ( false !== strpos( $importline, '<wp:tag>' ) ) {
463
+ preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag );
464
+ $this->tags[] = $this->process_tag( $tag[1] );
465
+ continue;
466
+ }
467
+ if ( false !== strpos( $importline, '<wp:term>' ) ) {
468
+ preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term );
469
+ $this->terms[] = $this->process_term( $term[1] );
470
+ continue;
471
+ }
472
+ if ( false !== strpos( $importline, '<wp:author>' ) ) {
473
+ preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
474
+ $a = $this->process_author( $author[1] );
475
+ $this->authors[$a['author_login']] = $a;
476
+ continue;
477
+ }
478
+ if ( false !== strpos( $importline, '<item>' ) ) {
479
+ $post = '';
480
+ $in_post = true;
481
+ continue;
482
+ }
483
+ if ( false !== strpos( $importline, '</item>' ) ) {
484
+ $in_post = false;
485
+ $this->posts[] = $this->process_post( $post );
486
+ continue;
487
+ }
488
+ if ( $in_post ) {
489
+ $post .= $importline . "\n";
490
+ }
491
+ }
492
+
493
+ $this->fclose($fp);
494
+ }
495
+
496
+ if ( ! $wxr_version )
497
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'themegrill-demo-importer' ) );
498
+
499
+ return array(
500
+ 'authors' => $this->authors,
501
+ 'posts' => $this->posts,
502
+ 'categories' => $this->categories,
503
+ 'tags' => $this->tags,
504
+ 'terms' => $this->terms,
505
+ 'base_url' => $this->base_url,
506
+ 'version' => $wxr_version
507
+ );
508
+ }
509
+
510
+ function get_tag( $string, $tag ) {
511
+ preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
512
+ if ( isset( $return[1] ) ) {
513
+ if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
514
+ if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
515
+ preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
516
+ $return = '';
517
+ foreach( $matches[1] as $match )
518
+ $return .= $match;
519
+ } else {
520
+ $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
521
+ }
522
+ } else {
523
+ $return = $return[1];
524
+ }
525
+ } else {
526
+ $return = '';
527
+ }
528
+ return $return;
529
+ }
530
+
531
+ function process_category( $c ) {
532
+ return array(
533
+ 'term_id' => $this->get_tag( $c, 'wp:term_id' ),
534
+ 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
535
+ 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
536
+ 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
537
+ 'category_description' => $this->get_tag( $c, 'wp:category_description' ),
538
+ );
539
+ }
540
+
541
+ function process_tag( $t ) {
542
+ return array(
543
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
544
+ 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
545
+ 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
546
+ 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
547
+ );
548
+ }
549
+
550
+ function process_term( $t ) {
551
+ return array(
552
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
553
+ 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
554
+ 'slug' => $this->get_tag( $t, 'wp:term_slug' ),
555
+ 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
556
+ 'term_name' => $this->get_tag( $t, 'wp:term_name' ),
557
+ 'term_description' => $this->get_tag( $t, 'wp:term_description' ),
558
+ );
559
+ }
560
+
561
+ function process_author( $a ) {
562
+ return array(
563
+ 'author_id' => $this->get_tag( $a, 'wp:author_id' ),
564
+ 'author_login' => $this->get_tag( $a, 'wp:author_login' ),
565
+ 'author_email' => $this->get_tag( $a, 'wp:author_email' ),
566
+ 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
567
+ 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
568
+ 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
569
+ );
570
+ }
571
+
572
+ function process_post( $post ) {
573
+ $post_id = $this->get_tag( $post, 'wp:post_id' );
574
+ $post_title = $this->get_tag( $post, 'title' );
575
+ $post_date = $this->get_tag( $post, 'wp:post_date' );
576
+ $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
577
+ $comment_status = $this->get_tag( $post, 'wp:comment_status' );
578
+ $ping_status = $this->get_tag( $post, 'wp:ping_status' );
579
+ $status = $this->get_tag( $post, 'wp:status' );
580
+ $post_name = $this->get_tag( $post, 'wp:post_name' );
581
+ $post_parent = $this->get_tag( $post, 'wp:post_parent' );
582
+ $menu_order = $this->get_tag( $post, 'wp:menu_order' );
583
+ $post_type = $this->get_tag( $post, 'wp:post_type' );
584
+ $post_password = $this->get_tag( $post, 'wp:post_password' );
585
+ $is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
586
+ $guid = $this->get_tag( $post, 'guid' );
587
+ $post_author = $this->get_tag( $post, 'dc:creator' );
588
+
589
+ $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
590
+ $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
591
+ $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
592
+ $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
593
+
594
+ $post_content = $this->get_tag( $post, 'content:encoded' );
595
+ $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
596
+ $post_content = str_replace( '<br>', '<br />', $post_content );
597
+ $post_content = str_replace( '<hr>', '<hr />', $post_content );
598
+
599
+ $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt',
600
+ 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent',
601
+ 'menu_order', 'post_type', 'post_password', 'is_sticky'
602
+ );
603
+
604
+ $attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
605
+ if ( $attachment_url )
606
+ $postdata['attachment_url'] = $attachment_url;
607
+
608
+ preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
609
+ foreach ( $terms as $t ) {
610
+ $post_terms[] = array(
611
+ 'slug' => $t[2],
612
+ 'domain' => $t[1],
613
+ 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
614
+ );
615
+ }
616
+ if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
617
+
618
+ preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
619
+ $comments = $comments[1];
620
+ if ( $comments ) {
621
+ foreach ( $comments as $comment ) {
622
+ preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
623
+ $commentmeta = $commentmeta[1];
624
+ $c_meta = array();
625
+ foreach ( $commentmeta as $m ) {
626
+ $c_meta[] = array(
627
+ 'key' => $this->get_tag( $m, 'wp:meta_key' ),
628
+ 'value' => $this->get_tag( $m, 'wp:meta_value' ),
629
+ );
630
+ }
631
+
632
+ $post_comments[] = array(
633
+ 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
634
+ 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
635
+ 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
636
+ 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
637
+ 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
638
+ 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
639
+ 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
640
+ 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
641
+ 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
642
+ 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
643
+ 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
644
+ 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
645
+ 'commentmeta' => $c_meta,
646
+ );
647
+ }
648
+ }
649
+ if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
650
+
651
+ preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
652
+ $postmeta = $postmeta[1];
653
+ if ( $postmeta ) {
654
+ foreach ( $postmeta as $p ) {
655
+ $post_postmeta[] = array(
656
+ 'key' => $this->get_tag( $p, 'wp:meta_key' ),
657
+ 'value' => $this->get_tag( $p, 'wp:meta_value' ),
658
+ );
659
+ }
660
+ }
661
+ if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
662
+
663
+ return $postdata;
664
+ }
665
+
666
+ function _normalize_tag( $matches ) {
667
+ return '<' . strtolower( $matches[1] );
668
+ }
669
+
670
+ function fopen( $filename, $mode = 'r' ) {
671
+ if ( $this->has_gzip )
672
+ return gzopen( $filename, $mode );
673
+ return fopen( $filename, $mode );
674
+ }
675
+
676
+ function feof( $fp ) {
677
+ if ( $this->has_gzip )
678
+ return gzeof( $fp );
679
+ return feof( $fp );
680
+ }
681
+
682
+ function fgets( $fp, $len = 8192 ) {
683
+ if ( $this->has_gzip )
684
+ return gzgets( $fp, $len );
685
+ return fgets( $fp, $len );
686
+ }
687
+
688
+ function fclose( $fp ) {
689
+ if ( $this->has_gzip )
690
+ return gzclose( $fp );
691
+ return fclose( $fp );
692
+ }
693
+ }
languages/themegrill-demo-importer.pot ADDED
@@ -0,0 +1,485 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2016 ThemeGrill
2
+ # This file is distributed under the GPLv3 or later.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: ThemeGrill Demo Importer 1.0.0\n"
6
+ "Report-Msgid-Bugs-To: themegrill@gmail.com\n"
7
+ "POT-Creation-Date: 2016-12-13 06:51:06+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: 2016-MO-DA HO:MI+ZONE\n"
12
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
+ "Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.4\n"
15
+
16
+ #: includes/class-demo-importer.php:135
17
+ #: includes/includes/admin/views/html-admin-page-importer.php:20
18
+ msgid "Demo Importer"
19
+ msgstr ""
20
+
21
+ #: includes/class-demo-importer.php:156
22
+ msgid "Importing Failed. Try again!"
23
+ msgstr ""
24
+
25
+ #: includes/class-demo-importer.php:157
26
+ msgid ""
27
+ "Importing demo content will replicate the live demo and overwrites your "
28
+ "current customizer, widgets and other settings. It might take few minutes "
29
+ "to complete the demo import. Are you sure you want to import this demo?"
30
+ msgstr ""
31
+
32
+ #: includes/class-demo-importer.php:204
33
+ msgid "Sorry, you are not allowed to install demo on this site."
34
+ msgstr ""
35
+
36
+ #: includes/class-demo-importer.php:211
37
+ msgid "Installing Demo from uploaded file: %s"
38
+ msgstr ""
39
+
40
+ #: includes/class-demo-importer.php:278
41
+ msgid "Successfully Imported"
42
+ msgstr ""
43
+
44
+ #: includes/class-demo-importer.php:323
45
+ msgid "The XML file containing the dummy content is not available."
46
+ msgstr ""
47
+
48
+ #: includes/includes/admin/class-demo-installer-skin.php:47
49
+ #: includes/includes/admin/class-demo-installer-skin.php:49
50
+ msgid "Return to Demo Importer"
51
+ msgstr ""
52
+
53
+ #: includes/includes/admin/class-demo-installer-skin.php:51
54
+ msgid "Return to Demos page"
55
+ msgstr ""
56
+
57
+ #: includes/includes/admin/class-demo-upgrader.php:40
58
+ msgid "Install package not available."
59
+ msgstr ""
60
+
61
+ #: includes/includes/admin/class-demo-upgrader.php:41
62
+ msgid "Downloading install package from <span class=\"code\">%s</span>&#8230;"
63
+ msgstr ""
64
+
65
+ #: includes/includes/admin/class-demo-upgrader.php:42
66
+ msgid "Unpacking the package&#8230;"
67
+ msgstr ""
68
+
69
+ #: includes/includes/admin/class-demo-upgrader.php:43
70
+ msgid "Installing the demo&#8230;"
71
+ msgstr ""
72
+
73
+ #: includes/includes/admin/class-demo-upgrader.php:44
74
+ msgid "The demo contains no files."
75
+ msgstr ""
76
+
77
+ #: includes/includes/admin/class-demo-upgrader.php:45
78
+ msgid "Demo install failed."
79
+ msgstr ""
80
+
81
+ #: includes/includes/admin/class-demo-upgrader.php:46
82
+ msgid "Demo installed successfully."
83
+ msgstr ""
84
+
85
+ #: includes/includes/admin/class-demo-upgrader.php:129
86
+ msgid "No valid demos were found."
87
+ msgstr ""
88
+
89
+ #: includes/includes/admin/views/html-admin-page-importer-previews.php:16
90
+ msgid "Theme demos list"
91
+ msgstr ""
92
+
93
+ #: includes/includes/admin/views/html-admin-page-importer-previews.php:35
94
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:64
95
+ msgid "Live Preview"
96
+ msgstr ""
97
+
98
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:16
99
+ msgid "Available demos list"
100
+ msgstr ""
101
+
102
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:35
103
+ msgid "<strong>Required Plugins:</strong> %s"
104
+ msgstr ""
105
+
106
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:38
107
+ msgid "<strong>Recommended Plugins:</strong> %s"
108
+ msgstr ""
109
+
110
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:46
111
+ #. translators: %s: demo name
112
+ msgid "<span>Imported:</span> %s"
113
+ msgstr ""
114
+
115
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:54
116
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:57
117
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:59
118
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:62
119
+ msgid "Import"
120
+ msgstr ""
121
+
122
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:57
123
+ msgid "Required Plugin must be activated to import this demo."
124
+ msgstr ""
125
+
126
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:66
127
+ msgid "Preview"
128
+ msgstr ""
129
+
130
+ #: includes/includes/admin/views/html-admin-page-importer-uploaded.php:67
131
+ msgid "Please Wait&hellip;"
132
+ msgstr ""
133
+
134
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:14
135
+ msgid "Welcome to ThemeGrill Demo Importer!"
136
+ msgstr ""
137
+
138
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:15
139
+ msgid "Get Started"
140
+ msgstr ""
141
+
142
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:19
143
+ msgid ""
144
+ "1. Visit <a href=\"%s\" target=\"_blank\"><strong>this page</strong></a> "
145
+ "and download demo zip file."
146
+ msgstr ""
147
+
148
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:20
149
+ msgid "2. Click <strong>Upload Demo</strong> button on the top of this Page."
150
+ msgstr ""
151
+
152
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:21
153
+ msgid "3. Browse the demo zip file and click <strong>Install Now</strong>."
154
+ msgstr ""
155
+
156
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:22
157
+ msgid "4. Go to <strong>Available Demos</strong> tab."
158
+ msgstr ""
159
+
160
+ #: includes/includes/admin/views/html-admin-page-importer-welcome.php:23
161
+ msgid "5. Click <strong>Import</strong> button and wait for few minutes. Done!"
162
+ msgstr ""
163
+
164
+ #: includes/includes/admin/views/html-admin-page-importer.php:12
165
+ msgid "Welcome"
166
+ msgstr ""
167
+
168
+ #: includes/includes/admin/views/html-admin-page-importer.php:13
169
+ msgid "Available Demos"
170
+ msgstr ""
171
+
172
+ #: includes/includes/admin/views/html-admin-page-importer.php:14
173
+ msgid "Theme Demos"
174
+ msgstr ""
175
+
176
+ #: includes/includes/admin/views/html-admin-page-importer.php:22
177
+ msgid "Upload Demo"
178
+ msgstr ""
179
+
180
+ #: includes/includes/admin/views/html-admin-page-importer.php:27
181
+ msgid ""
182
+ "<strong>Notice</strong> &#8211; If you want to completely remove a demo "
183
+ "installation after importing it, you can use a plugin like %1$sWordPress "
184
+ "Reset%2$s."
185
+ msgstr ""
186
+
187
+ #: includes/includes/admin/views/html-admin-page-importer.php:31
188
+ msgid "The Demo Importer screen requires JavaScript."
189
+ msgstr ""
190
+
191
+ #: includes/includes/admin/views/html-admin-page-importer.php:34
192
+ msgid ""
193
+ "If you have a demo pack in a .zip format, you may install it by uploading "
194
+ "it here."
195
+ msgstr ""
196
+
197
+ #: includes/includes/admin/views/html-admin-page-importer.php:37
198
+ msgid "Demo zip file"
199
+ msgstr ""
200
+
201
+ #: includes/includes/admin/views/html-admin-page-importer.php:39
202
+ msgid "Install Now"
203
+ msgstr ""
204
+
205
+ #: includes/includes/admin/views/html-admin-page-importer.php:43
206
+ msgid "Filter demos list"
207
+ msgstr ""
208
+
209
+ #: includes/includes/class-customizer-importer.php:42
210
+ msgid ""
211
+ "The customizer import file is not in a correct format. Please make sure to "
212
+ "use the correct customizer import file."
213
+ msgstr ""
214
+
215
+ #: includes/includes/class-customizer-importer.php:46
216
+ msgid ""
217
+ "The customizer import file is not suitable for current theme. You can only "
218
+ "import customizer settings for the same theme or a child theme."
219
+ msgstr ""
220
+
221
+ #: includes/includes/class-widget-importer.php:39
222
+ msgid "Widget import data could not be read. Please try a different file."
223
+ msgstr ""
224
+
225
+ #: includes/includes/class-widget-importer.php:76
226
+ msgid "Sidebar does not exist in theme (moving widget to Inactive)"
227
+ msgstr ""
228
+
229
+ #: includes/includes/class-widget-importer.php:98
230
+ msgid "Site does not support widget"
231
+ msgstr ""
232
+
233
+ #: includes/includes/class-widget-importer.php:133
234
+ msgid "Widget already exists"
235
+ msgstr ""
236
+
237
+ #: includes/includes/class-widget-importer.php:192
238
+ msgid "Imported"
239
+ msgstr ""
240
+
241
+ #: includes/includes/class-widget-importer.php:195
242
+ msgid "Imported to Inactive"
243
+ msgstr ""
244
+
245
+ #: includes/includes/class-widget-importer.php:201
246
+ msgid "No Title"
247
+ msgstr ""
248
+
249
+ #: includes/includes/importers/class-wxr-importer.php:126
250
+ #: includes/includes/importers/class-wxr-importer.php:135
251
+ #: includes/includes/importers/class-wxr-importer.php:186
252
+ #: includes/includes/importers/class-wxr-importer.php:190
253
+ #: includes/includes/importers/class-wxr-importer.php:199
254
+ msgid "Sorry, there has been an error."
255
+ msgstr ""
256
+
257
+ #: includes/includes/importers/class-wxr-importer.php:127
258
+ msgid "The file does not exist, please try again."
259
+ msgstr ""
260
+
261
+ #: includes/includes/importers/class-wxr-importer.php:170
262
+ msgid "All done."
263
+ msgstr ""
264
+
265
+ #: includes/includes/importers/class-wxr-importer.php:170
266
+ msgid "Have fun!"
267
+ msgstr ""
268
+
269
+ #: includes/includes/importers/class-wxr-importer.php:171
270
+ msgid "Remember to update the passwords and roles of imported users."
271
+ msgstr ""
272
+
273
+ #: includes/includes/importers/class-wxr-importer.php:191
274
+ msgid ""
275
+ "The export file could not be found at <code>%s</code>. It is likely that "
276
+ "this was caused by a permissions problem."
277
+ msgstr ""
278
+
279
+ #: includes/includes/importers/class-wxr-importer.php:207
280
+ msgid ""
281
+ "This WXR file (version %s) may not be supported by this version of the "
282
+ "importer. Please consider updating."
283
+ msgstr ""
284
+
285
+ #: includes/includes/importers/class-wxr-importer.php:232
286
+ msgid ""
287
+ "Failed to import author %s. Their posts will be attributed to the current "
288
+ "user."
289
+ msgstr ""
290
+
291
+ #: includes/includes/importers/class-wxr-importer.php:258
292
+ msgid "Assign Authors"
293
+ msgstr ""
294
+
295
+ #: includes/includes/importers/class-wxr-importer.php:259
296
+ msgid ""
297
+ "To make it easier for you to edit and save the imported content, you may "
298
+ "want to reassign the author of the imported item to an existing user of "
299
+ "this site. For example, you may want to import all the entries as "
300
+ "<code>admin</code>s entries."
301
+ msgstr ""
302
+
303
+ #: includes/includes/importers/class-wxr-importer.php:261
304
+ msgid ""
305
+ "If a new user is created by WordPress, a new password will be randomly "
306
+ "generated and the new user&#8217;s role will be set as %s. Manually "
307
+ "changing the new user&#8217;s details will be necessary."
308
+ msgstr ""
309
+
310
+ #: includes/includes/importers/class-wxr-importer.php:271
311
+ msgid "Import Attachments"
312
+ msgstr ""
313
+
314
+ #: includes/includes/importers/class-wxr-importer.php:274
315
+ msgid "Download and import file attachments"
316
+ msgstr ""
317
+
318
+ #: includes/includes/importers/class-wxr-importer.php:278
319
+ msgid "Submit"
320
+ msgstr ""
321
+
322
+ #: includes/includes/importers/class-wxr-importer.php:291
323
+ msgid "Import author:"
324
+ msgstr ""
325
+
326
+ #: includes/includes/importers/class-wxr-importer.php:302
327
+ msgid "or create new user with login name:"
328
+ msgstr ""
329
+
330
+ #: includes/includes/importers/class-wxr-importer.php:305
331
+ msgid "as a new user:"
332
+ msgstr ""
333
+
334
+ #: includes/includes/importers/class-wxr-importer.php:313
335
+ msgid "assign posts to an existing user:"
336
+ msgstr ""
337
+
338
+ #: includes/includes/importers/class-wxr-importer.php:315
339
+ msgid "or assign posts to an existing user:"
340
+ msgstr ""
341
+
342
+ #: includes/includes/importers/class-wxr-importer.php:316
343
+ msgid "- Select -"
344
+ msgstr ""
345
+
346
+ #: includes/includes/importers/class-wxr-importer.php:366
347
+ msgid ""
348
+ "Failed to create new user for %s. Their posts will be attributed to the "
349
+ "current user."
350
+ msgstr ""
351
+
352
+ #: includes/includes/importers/class-wxr-importer.php:418
353
+ msgid "Failed to import category %s"
354
+ msgstr ""
355
+
356
+ #: includes/includes/importers/class-wxr-importer.php:461
357
+ msgid "Failed to import post tag %s"
358
+ msgstr ""
359
+
360
+ #: includes/includes/importers/class-wxr-importer.php:510
361
+ #: includes/includes/importers/class-wxr-importer.php:732
362
+ msgid "Failed to import %s %s"
363
+ msgstr ""
364
+
365
+ #: includes/includes/importers/class-wxr-importer.php:599
366
+ msgid "Failed to import &#8220;%s&#8221;: Invalid post type %s"
367
+ msgstr ""
368
+
369
+ #: includes/includes/importers/class-wxr-importer.php:636
370
+ msgid "%s &#8220;%s&#8221; already exists."
371
+ msgstr ""
372
+
373
+ #: includes/includes/importers/class-wxr-importer.php:698
374
+ msgid "Failed to import %s &#8220;%s&#8221;"
375
+ msgstr ""
376
+
377
+ #: includes/includes/importers/class-wxr-importer.php:863
378
+ msgid "Menu item skipped due to missing menu slug"
379
+ msgstr ""
380
+
381
+ #: includes/includes/importers/class-wxr-importer.php:870
382
+ msgid "Menu item skipped due to invalid menu slug: %s"
383
+ msgstr ""
384
+
385
+ #: includes/includes/importers/class-wxr-importer.php:938
386
+ msgid "Fetching attachments is not enabled"
387
+ msgstr ""
388
+
389
+ #: includes/includes/importers/class-wxr-importer.php:952
390
+ msgid "Invalid file type"
391
+ msgstr ""
392
+
393
+ #: includes/includes/importers/class-wxr-importer.php:1030
394
+ msgid "Remote server returned %1$d %2$s for %3$s"
395
+ msgstr ""
396
+
397
+ #: includes/includes/importers/class-wxr-importer.php:1043
398
+ msgid "Remote file is incorrect size"
399
+ msgstr ""
400
+
401
+ #: includes/includes/importers/class-wxr-importer.php:1048
402
+ msgid "Zero size file downloaded"
403
+ msgstr ""
404
+
405
+ #: includes/includes/importers/class-wxr-importer.php:1054
406
+ msgid "Remote file is too large, limit is %s"
407
+ msgstr ""
408
+
409
+ #: includes/includes/importers/class-wxr-importer.php:1147
410
+ msgid "Import WordPress"
411
+ msgstr ""
412
+
413
+ #: includes/includes/importers/class-wxr-importer.php:1154
414
+ msgid ""
415
+ "A new version of this importer is available. Please update to version %s to "
416
+ "ensure compatibility with newer export files."
417
+ msgstr ""
418
+
419
+ #: includes/includes/importers/class-wxr-importer.php:1169
420
+ msgid ""
421
+ "Howdy! Upload your WordPress eXtended RSS (WXR) file and we&#8217;ll import "
422
+ "the posts, pages, comments, custom fields, categories, and tags into this "
423
+ "site."
424
+ msgstr ""
425
+
426
+ #: includes/includes/importers/class-wxr-importer.php:1170
427
+ msgid "Choose a WXR (.xml) file to upload, then click Upload file and import."
428
+ msgstr ""
429
+
430
+ #: includes/includes/importers/class-wxr-parsers.php:44
431
+ #: includes/includes/importers/class-wxr-parsers.php:74
432
+ #: includes/includes/importers/class-wxr-parsers.php:82
433
+ msgid "There was an error when reading this WXR file"
434
+ msgstr ""
435
+
436
+ #: includes/includes/importers/class-wxr-parsers.php:45
437
+ msgid ""
438
+ "Details are shown above. The importer will now try again with a different "
439
+ "parser..."
440
+ msgstr ""
441
+
442
+ #: includes/includes/importers/class-wxr-parsers.php:86
443
+ #: includes/includes/importers/class-wxr-parsers.php:91
444
+ #: includes/includes/importers/class-wxr-parsers.php:308
445
+ #: includes/includes/importers/class-wxr-parsers.php:497
446
+ msgid "This does not appear to be a WXR file, missing/invalid WXR version number"
447
+ msgstr ""
448
+
449
+ #: themegrill-demo-importer.php:165
450
+ msgid "View Demos"
451
+ msgstr ""
452
+
453
+ #: themegrill-demo-importer.php:165
454
+ msgid "Demos"
455
+ msgstr ""
456
+
457
+ #. Plugin Name of the plugin/theme
458
+ msgid "ThemeGrill Demo Importer"
459
+ msgstr ""
460
+
461
+ #: themegrill-demo-importer.php:177
462
+ msgid "This plugin requires %s by ThemeGrill to work."
463
+ msgstr ""
464
+
465
+ #: themegrill-demo-importer.php:177
466
+ msgid "Official Theme"
467
+ msgstr ""
468
+
469
+ #. Plugin URI of the plugin/theme
470
+ msgid "http://themegrill.com/demo-importer/"
471
+ msgstr ""
472
+
473
+ #. Description of the plugin/theme
474
+ msgid ""
475
+ "Import your demo content, widgets and theme settings with one click for "
476
+ "ThemeGrill themes"
477
+ msgstr ""
478
+
479
+ #. Author of the plugin/theme
480
+ msgid "ThemeGrill"
481
+ msgstr ""
482
+
483
+ #. Author URI of the plugin/theme
484
+ msgid "http://themegrill.com"
485
+ msgstr ""
license.txt ADDED
@@ -0,0 +1,702 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ThemeGrill Demo Importer - Importer for WordPress
2
+
3
+ Copyright 2016 by the contributors
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ This program incorporates work covered by the following copyright and
19
+ permission notices:
20
+
21
+ ThemeGrill Demo Importer - Importer for WordPress
22
+
23
+ ThemeGrill Demo Importer is Copyright (c) 2016 ThemeGrill
24
+
25
+ ThemeGrill Demo Importer is released under the GPL
26
+
27
+ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
28
+
29
+ GNU GENERAL PUBLIC LICENSE
30
+ Version 3, 29 June 2007
31
+
32
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
33
+ Everyone is permitted to copy and distribute verbatim copies
34
+ of this license document, but changing it is not allowed.
35
+
36
+ Preamble
37
+
38
+ The GNU General Public License is a free, copyleft license for
39
+ software and other kinds of works.
40
+
41
+ The licenses for most software and other practical works are designed
42
+ to take away your freedom to share and change the works. By contrast,
43
+ the GNU General Public License is intended to guarantee your freedom to
44
+ share and change all versions of a program--to make sure it remains free
45
+ software for all its users. We, the Free Software Foundation, use the
46
+ GNU General Public License for most of our software; it applies also to
47
+ any other work released this way by its authors. You can apply it to
48
+ your programs, too.
49
+
50
+ When we speak of free software, we are referring to freedom, not
51
+ price. Our General Public Licenses are designed to make sure that you
52
+ have the freedom to distribute copies of free software (and charge for
53
+ them if you wish), that you receive source code or can get it if you
54
+ want it, that you can change the software or use pieces of it in new
55
+ free programs, and that you know you can do these things.
56
+
57
+ To protect your rights, we need to prevent others from denying you
58
+ these rights or asking you to surrender the rights. Therefore, you have
59
+ certain responsibilities if you distribute copies of the software, or if
60
+ you modify it: responsibilities to respect the freedom of others.
61
+
62
+ For example, if you distribute copies of such a program, whether
63
+ gratis or for a fee, you must pass on to the recipients the same
64
+ freedoms that you received. You must make sure that they, too, receive
65
+ or can get the source code. And you must show them these terms so they
66
+ know their rights.
67
+
68
+ Developers that use the GNU GPL protect your rights with two steps:
69
+ (1) assert copyright on the software, and (2) offer you this License
70
+ giving you legal permission to copy, distribute and/or modify it.
71
+
72
+ For the developers' and authors' protection, the GPL clearly explains
73
+ that there is no warranty for this free software. For both users' and
74
+ authors' sake, the GPL requires that modified versions be marked as
75
+ changed, so that their problems will not be attributed erroneously to
76
+ authors of previous versions.
77
+
78
+ Some devices are designed to deny users access to install or run
79
+ modified versions of the software inside them, although the manufacturer
80
+ can do so. This is fundamentally incompatible with the aim of
81
+ protecting users' freedom to change the software. The systematic
82
+ pattern of such abuse occurs in the area of products for individuals to
83
+ use, which is precisely where it is most unacceptable. Therefore, we
84
+ have designed this version of the GPL to prohibit the practice for those
85
+ products. If such problems arise substantially in other domains, we
86
+ stand ready to extend this provision to those domains in future versions
87
+ of the GPL, as needed to protect the freedom of users.
88
+
89
+ Finally, every program is threatened constantly by software patents.
90
+ States should not allow patents to restrict development and use of
91
+ software on general-purpose computers, but in those that do, we wish to
92
+ avoid the special danger that patents applied to a free program could
93
+ make it effectively proprietary. To prevent this, the GPL assures that
94
+ patents cannot be used to render the program non-free.
95
+
96
+ The precise terms and conditions for copying, distribution and
97
+ modification follow.
98
+
99
+ TERMS AND CONDITIONS
100
+
101
+ 0. Definitions.
102
+
103
+ "This License" refers to version 3 of the GNU General Public License.
104
+
105
+ "Copyright" also means copyright-like laws that apply to other kinds of
106
+ works, such as semiconductor masks.
107
+
108
+ "The Program" refers to any copyrightable work licensed under this
109
+ License. Each licensee is addressed as "you". "Licensees" and
110
+ "recipients" may be individuals or organizations.
111
+
112
+ To "modify" a work means to copy from or adapt all or part of the work
113
+ in a fashion requiring copyright permission, other than the making of an
114
+ exact copy. The resulting work is called a "modified version" of the
115
+ earlier work or a work "based on" the earlier work.
116
+
117
+ A "covered work" means either the unmodified Program or a work based
118
+ on the Program.
119
+
120
+ To "propagate" a work means to do anything with it that, without
121
+ permission, would make you directly or secondarily liable for
122
+ infringement under applicable copyright law, except executing it on a
123
+ computer or modifying a private copy. Propagation includes copying,
124
+ distribution (with or without modification), making available to the
125
+ public, and in some countries other activities as well.
126
+
127
+ To "convey" a work means any kind of propagation that enables other
128
+ parties to make or receive copies. Mere interaction with a user through
129
+ a computer network, with no transfer of a copy, is not conveying.
130
+
131
+ An interactive user interface displays "Appropriate Legal Notices"
132
+ to the extent that it includes a convenient and prominently visible
133
+ feature that (1) displays an appropriate copyright notice, and (2)
134
+ tells the user that there is no warranty for the work (except to the
135
+ extent that warranties are provided), that licensees may convey the
136
+ work under this License, and how to view a copy of this License. If
137
+ the interface presents a list of user commands or options, such as a
138
+ menu, a prominent item in the list meets this criterion.
139
+
140
+ 1. Source Code.
141
+
142
+ The "source code" for a work means the preferred form of the work
143
+ for making modifications to it. "Object code" means any non-source
144
+ form of a work.
145
+
146
+ A "Standard Interface" means an interface that either is an official
147
+ standard defined by a recognized standards body, or, in the case of
148
+ interfaces specified for a particular programming language, one that
149
+ is widely used among developers working in that language.
150
+
151
+ The "System Libraries" of an executable work include anything, other
152
+ than the work as a whole, that (a) is included in the normal form of
153
+ packaging a Major Component, but which is not part of that Major
154
+ Component, and (b) serves only to enable use of the work with that
155
+ Major Component, or to implement a Standard Interface for which an
156
+ implementation is available to the public in source code form. A
157
+ "Major Component", in this context, means a major essential component
158
+ (kernel, window system, and so on) of the specific operating system
159
+ (if any) on which the executable work runs, or a compiler used to
160
+ produce the work, or an object code interpreter used to run it.
161
+
162
+ The "Corresponding Source" for a work in object code form means all
163
+ the source code needed to generate, install, and (for an executable
164
+ work) run the object code and to modify the work, including scripts to
165
+ control those activities. However, it does not include the work's
166
+ System Libraries, or general-purpose tools or generally available free
167
+ programs which are used unmodified in performing those activities but
168
+ which are not part of the work. For example, Corresponding Source
169
+ includes interface definition files associated with source files for
170
+ the work, and the source code for shared libraries and dynamically
171
+ linked subprograms that the work is specifically designed to require,
172
+ such as by intimate data communication or control flow between those
173
+ subprograms and other parts of the work.
174
+
175
+ The Corresponding Source need not include anything that users
176
+ can regenerate automatically from other parts of the Corresponding
177
+ Source.
178
+
179
+ The Corresponding Source for a work in source code form is that
180
+ same work.
181
+
182
+ 2. Basic Permissions.
183
+
184
+ All rights granted under this License are granted for the term of
185
+ copyright on the Program, and are irrevocable provided the stated
186
+ conditions are met. This License explicitly affirms your unlimited
187
+ permission to run the unmodified Program. The output from running a
188
+ covered work is covered by this License only if the output, given its
189
+ content, constitutes a covered work. This License acknowledges your
190
+ rights of fair use or other equivalent, as provided by copyright law.
191
+
192
+ You may make, run and propagate covered works that you do not
193
+ convey, without conditions so long as your license otherwise remains
194
+ in force. You may convey covered works to others for the sole purpose
195
+ of having them make modifications exclusively for you, or provide you
196
+ with facilities for running those works, provided that you comply with
197
+ the terms of this License in conveying all material for which you do
198
+ not control copyright. Those thus making or running the covered works
199
+ for you must do so exclusively on your behalf, under your direction
200
+ and control, on terms that prohibit them from making any copies of
201
+ your copyrighted material outside their relationship with you.
202
+
203
+ Conveying under any other circumstances is permitted solely under
204
+ the conditions stated below. Sublicensing is not allowed; section 10
205
+ makes it unnecessary.
206
+
207
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
208
+
209
+ No covered work shall be deemed part of an effective technological
210
+ measure under any applicable law fulfilling obligations under article
211
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
212
+ similar laws prohibiting or restricting circumvention of such
213
+ measures.
214
+
215
+ When you convey a covered work, you waive any legal power to forbid
216
+ circumvention of technological measures to the extent such circumvention
217
+ is effected by exercising rights under this License with respect to
218
+ the covered work, and you disclaim any intention to limit operation or
219
+ modification of the work as a means of enforcing, against the work's
220
+ users, your or third parties' legal rights to forbid circumvention of
221
+ technological measures.
222
+
223
+ 4. Conveying Verbatim Copies.
224
+
225
+ You may convey verbatim copies of the Program's source code as you
226
+ receive it, in any medium, provided that you conspicuously and
227
+ appropriately publish on each copy an appropriate copyright notice;
228
+ keep intact all notices stating that this License and any
229
+ non-permissive terms added in accord with section 7 apply to the code;
230
+ keep intact all notices of the absence of any warranty; and give all
231
+ recipients a copy of this License along with the Program.
232
+
233
+ You may charge any price or no price for each copy that you convey,
234
+ and you may offer support or warranty protection for a fee.
235
+
236
+ 5. Conveying Modified Source Versions.
237
+
238
+ You may convey a work based on the Program, or the modifications to
239
+ produce it from the Program, in the form of source code under the
240
+ terms of section 4, provided that you also meet all of these conditions:
241
+
242
+ a) The work must carry prominent notices stating that you modified
243
+ it, and giving a relevant date.
244
+
245
+ b) The work must carry prominent notices stating that it is
246
+ released under this License and any conditions added under section
247
+ 7. This requirement modifies the requirement in section 4 to
248
+ "keep intact all notices".
249
+
250
+ c) You must license the entire work, as a whole, under this
251
+ License to anyone who comes into possession of a copy. This
252
+ License will therefore apply, along with any applicable section 7
253
+ additional terms, to the whole of the work, and all its parts,
254
+ regardless of how they are packaged. This License gives no
255
+ permission to license the work in any other way, but it does not
256
+ invalidate such permission if you have separately received it.
257
+
258
+ d) If the work has interactive user interfaces, each must display
259
+ Appropriate Legal Notices; however, if the Program has interactive
260
+ interfaces that do not display Appropriate Legal Notices, your
261
+ work need not make them do so.
262
+
263
+ A compilation of a covered work with other separate and independent
264
+ works, which are not by their nature extensions of the covered work,
265
+ and which are not combined with it such as to form a larger program,
266
+ in or on a volume of a storage or distribution medium, is called an
267
+ "aggregate" if the compilation and its resulting copyright are not
268
+ used to limit the access or legal rights of the compilation's users
269
+ beyond what the individual works permit. Inclusion of a covered work
270
+ in an aggregate does not cause this License to apply to the other
271
+ parts of the aggregate.
272
+
273
+ 6. Conveying Non-Source Forms.
274
+
275
+ You may convey a covered work in object code form under the terms
276
+ of sections 4 and 5, provided that you also convey the
277
+ machine-readable Corresponding Source under the terms of this License,
278
+ in one of these ways:
279
+
280
+ a) Convey the object code in, or embodied in, a physical product
281
+ (including a physical distribution medium), accompanied by the
282
+ Corresponding Source fixed on a durable physical medium
283
+ customarily used for software interchange.
284
+
285
+ b) Convey the object code in, or embodied in, a physical product
286
+ (including a physical distribution medium), accompanied by a
287
+ written offer, valid for at least three years and valid for as
288
+ long as you offer spare parts or customer support for that product
289
+ model, to give anyone who possesses the object code either (1) a
290
+ copy of the Corresponding Source for all the software in the
291
+ product that is covered by this License, on a durable physical
292
+ medium customarily used for software interchange, for a price no
293
+ more than your reasonable cost of physically performing this
294
+ conveying of source, or (2) access to copy the
295
+ Corresponding Source from a network server at no charge.
296
+
297
+ c) Convey individual copies of the object code with a copy of the
298
+ written offer to provide the Corresponding Source. This
299
+ alternative is allowed only occasionally and noncommercially, and
300
+ only if you received the object code with such an offer, in accord
301
+ with subsection 6b.
302
+
303
+ d) Convey the object code by offering access from a designated
304
+ place (gratis or for a charge), and offer equivalent access to the
305
+ Corresponding Source in the same way through the same place at no
306
+ further charge. You need not require recipients to copy the
307
+ Corresponding Source along with the object code. If the place to
308
+ copy the object code is a network server, the Corresponding Source
309
+ may be on a different server (operated by you or a third party)
310
+ that supports equivalent copying facilities, provided you maintain
311
+ clear directions next to the object code saying where to find the
312
+ Corresponding Source. Regardless of what server hosts the
313
+ Corresponding Source, you remain obligated to ensure that it is
314
+ available for as long as needed to satisfy these requirements.
315
+
316
+ e) Convey the object code using peer-to-peer transmission, provided
317
+ you inform other peers where the object code and Corresponding
318
+ Source of the work are being offered to the general public at no
319
+ charge under subsection 6d.
320
+
321
+ A separable portion of the object code, whose source code is excluded
322
+ from the Corresponding Source as a System Library, need not be
323
+ included in conveying the object code work.
324
+
325
+ A "User Product" is either (1) a "consumer product", which means any
326
+ tangible personal property which is normally used for personal, family,
327
+ or household purposes, or (2) anything designed or sold for incorporation
328
+ into a dwelling. In determining whether a product is a consumer product,
329
+ doubtful cases shall be resolved in favor of coverage. For a particular
330
+ product received by a particular user, "normally used" refers to a
331
+ typical or common use of that class of product, regardless of the status
332
+ of the particular user or of the way in which the particular user
333
+ actually uses, or expects or is expected to use, the product. A product
334
+ is a consumer product regardless of whether the product has substantial
335
+ commercial, industrial or non-consumer uses, unless such uses represent
336
+ the only significant mode of use of the product.
337
+
338
+ "Installation Information" for a User Product means any methods,
339
+ procedures, authorization keys, or other information required to install
340
+ and execute modified versions of a covered work in that User Product from
341
+ a modified version of its Corresponding Source. The information must
342
+ suffice to ensure that the continued functioning of the modified object
343
+ code is in no case prevented or interfered with solely because
344
+ modification has been made.
345
+
346
+ If you convey an object code work under this section in, or with, or
347
+ specifically for use in, a User Product, and the conveying occurs as
348
+ part of a transaction in which the right of possession and use of the
349
+ User Product is transferred to the recipient in perpetuity or for a
350
+ fixed term (regardless of how the transaction is characterized), the
351
+ Corresponding Source conveyed under this section must be accompanied
352
+ by the Installation Information. But this requirement does not apply
353
+ if neither you nor any third party retains the ability to install
354
+ modified object code on the User Product (for example, the work has
355
+ been installed in ROM).
356
+
357
+ The requirement to provide Installation Information does not include a
358
+ requirement to continue to provide support service, warranty, or updates
359
+ for a work that has been modified or installed by the recipient, or for
360
+ the User Product in which it has been modified or installed. Access to a
361
+ network may be denied when the modification itself materially and
362
+ adversely affects the operation of the network or violates the rules and
363
+ protocols for communication across the network.
364
+
365
+ Corresponding Source conveyed, and Installation Information provided,
366
+ in accord with this section must be in a format that is publicly
367
+ documented (and with an implementation available to the public in
368
+ source code form), and must require no special password or key for
369
+ unpacking, reading or copying.
370
+
371
+ 7. Additional Terms.
372
+
373
+ "Additional permissions" are terms that supplement the terms of this
374
+ License by making exceptions from one or more of its conditions.
375
+ Additional permissions that are applicable to the entire Program shall
376
+ be treated as though they were included in this License, to the extent
377
+ that they are valid under applicable law. If additional permissions
378
+ apply only to part of the Program, that part may be used separately
379
+ under those permissions, but the entire Program remains governed by
380
+ this License without regard to the additional permissions.
381
+
382
+ When you convey a copy of a covered work, you may at your option
383
+ remove any additional permissions from that copy, or from any part of
384
+ it. (Additional permissions may be written to require their own
385
+ removal in certain cases when you modify the work.) You may place
386
+ additional permissions on material, added by you to a covered work,
387
+ for which you have or can give appropriate copyright permission.
388
+
389
+ Notwithstanding any other provision of this License, for material you
390
+ add to a covered work, you may (if authorized by the copyright holders of
391
+ that material) supplement the terms of this License with terms:
392
+
393
+ a) Disclaiming warranty or limiting liability differently from the
394
+ terms of sections 15 and 16 of this License; or
395
+
396
+ b) Requiring preservation of specified reasonable legal notices or
397
+ author attributions in that material or in the Appropriate Legal
398
+ Notices displayed by works containing it; or
399
+
400
+ c) Prohibiting misrepresentation of the origin of that material, or
401
+ requiring that modified versions of such material be marked in
402
+ reasonable ways as different from the original version; or
403
+
404
+ d) Limiting the use for publicity purposes of names of licensors or
405
+ authors of the material; or
406
+
407
+ e) Declining to grant rights under trademark law for use of some
408
+ trade names, trademarks, or service marks; or
409
+
410
+ f) Requiring indemnification of licensors and authors of that
411
+ material by anyone who conveys the material (or modified versions of
412
+ it) with contractual assumptions of liability to the recipient, for
413
+ any liability that these contractual assumptions directly impose on
414
+ those licensors and authors.
415
+
416
+ All other non-permissive additional terms are considered "further
417
+ restrictions" within the meaning of section 10. If the Program as you
418
+ received it, or any part of it, contains a notice stating that it is
419
+ governed by this License along with a term that is a further
420
+ restriction, you may remove that term. If a license document contains
421
+ a further restriction but permits relicensing or conveying under this
422
+ License, you may add to a covered work material governed by the terms
423
+ of that license document, provided that the further restriction does
424
+ not survive such relicensing or conveying.
425
+
426
+ If you add terms to a covered work in accord with this section, you
427
+ must place, in the relevant source files, a statement of the
428
+ additional terms that apply to those files, or a notice indicating
429
+ where to find the applicable terms.
430
+
431
+ Additional terms, permissive or non-permissive, may be stated in the
432
+ form of a separately written license, or stated as exceptions;
433
+ the above requirements apply either way.
434
+
435
+ 8. Termination.
436
+
437
+ You may not propagate or modify a covered work except as expressly
438
+ provided under this License. Any attempt otherwise to propagate or
439
+ modify it is void, and will automatically terminate your rights under
440
+ this License (including any patent licenses granted under the third
441
+ paragraph of section 11).
442
+
443
+ However, if you cease all violation of this License, then your
444
+ license from a particular copyright holder is reinstated (a)
445
+ provisionally, unless and until the copyright holder explicitly and
446
+ finally terminates your license, and (b) permanently, if the copyright
447
+ holder fails to notify you of the violation by some reasonable means
448
+ prior to 60 days after the cessation.
449
+
450
+ Moreover, your license from a particular copyright holder is
451
+ reinstated permanently if the copyright holder notifies you of the
452
+ violation by some reasonable means, this is the first time you have
453
+ received notice of violation of this License (for any work) from that
454
+ copyright holder, and you cure the violation prior to 30 days after
455
+ your receipt of the notice.
456
+
457
+ Termination of your rights under this section does not terminate the
458
+ licenses of parties who have received copies or rights from you under
459
+ this License. If your rights have been terminated and not permanently
460
+ reinstated, you do not qualify to receive new licenses for the same
461
+ material under section 10.
462
+
463
+ 9. Acceptance Not Required for Having Copies.
464
+
465
+ You are not required to accept this License in order to receive or
466
+ run a copy of the Program. Ancillary propagation of a covered work
467
+ occurring solely as a consequence of using peer-to-peer transmission
468
+ to receive a copy likewise does not require acceptance. However,
469
+ nothing other than this License grants you permission to propagate or
470
+ modify any covered work. These actions infringe copyright if you do
471
+ not accept this License. Therefore, by modifying or propagating a
472
+ covered work, you indicate your acceptance of this License to do so.
473
+
474
+ 10. Automatic Licensing of Downstream Recipients.
475
+
476
+ Each time you convey a covered work, the recipient automatically
477
+ receives a license from the original licensors, to run, modify and
478
+ propagate that work, subject to this License. You are not responsible
479
+ for enforcing compliance by third parties with this License.
480
+
481
+ An "entity transaction" is a transaction transferring control of an
482
+ organization, or substantially all assets of one, or subdividing an
483
+ organization, or merging organizations. If propagation of a covered
484
+ work results from an entity transaction, each party to that
485
+ transaction who receives a copy of the work also receives whatever
486
+ licenses to the work the party's predecessor in interest had or could
487
+ give under the previous paragraph, plus a right to possession of the
488
+ Corresponding Source of the work from the predecessor in interest, if
489
+ the predecessor has it or can get it with reasonable efforts.
490
+
491
+ You may not impose any further restrictions on the exercise of the
492
+ rights granted or affirmed under this License. For example, you may
493
+ not impose a license fee, royalty, or other charge for exercise of
494
+ rights granted under this License, and you may not initiate litigation
495
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
496
+ any patent claim is infringed by making, using, selling, offering for
497
+ sale, or importing the Program or any portion of it.
498
+
499
+ 11. Patents.
500
+
501
+ A "contributor" is a copyright holder who authorizes use under this
502
+ License of the Program or a work on which the Program is based. The
503
+ work thus licensed is called the contributor's "contributor version".
504
+
505
+ A contributor's "essential patent claims" are all patent claims
506
+ owned or controlled by the contributor, whether already acquired or
507
+ hereafter acquired, that would be infringed by some manner, permitted
508
+ by this License, of making, using, or selling its contributor version,
509
+ but do not include claims that would be infringed only as a
510
+ consequence of further modification of the contributor version. For
511
+ purposes of this definition, "control" includes the right to grant
512
+ patent sublicenses in a manner consistent with the requirements of
513
+ this License.
514
+
515
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
516
+ patent license under the contributor's essential patent claims, to
517
+ make, use, sell, offer for sale, import and otherwise run, modify and
518
+ propagate the contents of its contributor version.
519
+
520
+ In the following three paragraphs, a "patent license" is any express
521
+ agreement or commitment, however denominated, not to enforce a patent
522
+ (such as an express permission to practice a patent or covenant not to
523
+ sue for patent infringement). To "grant" such a patent license to a
524
+ party means to make such an agreement or commitment not to enforce a
525
+ patent against the party.
526
+
527
+ If you convey a covered work, knowingly relying on a patent license,
528
+ and the Corresponding Source of the work is not available for anyone
529
+ to copy, free of charge and under the terms of this License, through a
530
+ publicly available network server or other readily accessible means,
531
+ then you must either (1) cause the Corresponding Source to be so
532
+ available, or (2) arrange to deprive yourself of the benefit of the
533
+ patent license for this particular work, or (3) arrange, in a manner
534
+ consistent with the requirements of this License, to extend the patent
535
+ license to downstream recipients. "Knowingly relying" means you have
536
+ actual knowledge that, but for the patent license, your conveying the
537
+ covered work in a country, or your recipient's use of the covered work
538
+ in a country, would infringe one or more identifiable patents in that
539
+ country that you have reason to believe are valid.
540
+
541
+ If, pursuant to or in connection with a single transaction or
542
+ arrangement, you convey, or propagate by procuring conveyance of, a
543
+ covered work, and grant a patent license to some of the parties
544
+ receiving the covered work authorizing them to use, propagate, modify
545
+ or convey a specific copy of the covered work, then the patent license
546
+ you grant is automatically extended to all recipients of the covered
547
+ work and works based on it.
548
+
549
+ A patent license is "discriminatory" if it does not include within
550
+ the scope of its coverage, prohibits the exercise of, or is
551
+ conditioned on the non-exercise of one or more of the rights that are
552
+ specifically granted under this License. You may not convey a covered
553
+ work if you are a party to an arrangement with a third party that is
554
+ in the business of distributing software, under which you make payment
555
+ to the third party based on the extent of your activity of conveying
556
+ the work, and under which the third party grants, to any of the
557
+ parties who would receive the covered work from you, a discriminatory
558
+ patent license (a) in connection with copies of the covered work
559
+ conveyed by you (or copies made from those copies), or (b) primarily
560
+ for and in connection with specific products or compilations that
561
+ contain the covered work, unless you entered into that arrangement,
562
+ or that patent license was granted, prior to 28 March 2007.
563
+
564
+ Nothing in this License shall be construed as excluding or limiting
565
+ any implied license or other defenses to infringement that may
566
+ otherwise be available to you under applicable patent law.
567
+
568
+ 12. No Surrender of Others' Freedom.
569
+
570
+ If conditions are imposed on you (whether by court order, agreement or
571
+ otherwise) that contradict the conditions of this License, they do not
572
+ excuse you from the conditions of this License. If you cannot convey a
573
+ covered work so as to satisfy simultaneously your obligations under this
574
+ License and any other pertinent obligations, then as a consequence you may
575
+ not convey it at all. For example, if you agree to terms that obligate you
576
+ to collect a royalty for further conveying from those to whom you convey
577
+ the Program, the only way you could satisfy both those terms and this
578
+ License would be to refrain entirely from conveying the Program.
579
+
580
+ 13. Use with the GNU Affero General Public License.
581
+
582
+ Notwithstanding any other provision of this License, you have
583
+ permission to link or combine any covered work with a work licensed
584
+ under version 3 of the GNU Affero General Public License into a single
585
+ combined work, and to convey the resulting work. The terms of this
586
+ License will continue to apply to the part which is the covered work,
587
+ but the special requirements of the GNU Affero General Public License,
588
+ section 13, concerning interaction through a network will apply to the
589
+ combination as such.
590
+
591
+ 14. Revised Versions of this License.
592
+
593
+ The Free Software Foundation may publish revised and/or new versions of
594
+ the GNU General Public License from time to time. Such new versions will
595
+ be similar in spirit to the present version, but may differ in detail to
596
+ address new problems or concerns.
597
+
598
+ Each version is given a distinguishing version number. If the
599
+ Program specifies that a certain numbered version of the GNU General
600
+ Public License "or any later version" applies to it, you have the
601
+ option of following the terms and conditions either of that numbered
602
+ version or of any later version published by the Free Software
603
+ Foundation. If the Program does not specify a version number of the
604
+ GNU General Public License, you may choose any version ever published
605
+ by the Free Software Foundation.
606
+
607
+ If the Program specifies that a proxy can decide which future
608
+ versions of the GNU General Public License can be used, that proxy's
609
+ public statement of acceptance of a version permanently authorizes you
610
+ to choose that version for the Program.
611
+
612
+ Later license versions may give you additional or different
613
+ permissions. However, no additional obligations are imposed on any
614
+ author or copyright holder as a result of your choosing to follow a
615
+ later version.
616
+
617
+ 15. Disclaimer of Warranty.
618
+
619
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
620
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
621
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
622
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
623
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
624
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
625
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
626
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
627
+
628
+ 16. Limitation of Liability.
629
+
630
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
631
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
632
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
633
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
634
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
635
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
636
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
637
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
638
+ SUCH DAMAGES.
639
+
640
+ 17. Interpretation of Sections 15 and 16.
641
+
642
+ If the disclaimer of warranty and limitation of liability provided
643
+ above cannot be given local legal effect according to their terms,
644
+ reviewing courts shall apply local law that most closely approximates
645
+ an absolute waiver of all civil liability in connection with the
646
+ Program, unless a warranty or assumption of liability accompanies a
647
+ copy of the Program in return for a fee.
648
+
649
+ END OF TERMS AND CONDITIONS
650
+
651
+ How to Apply These Terms to Your New Programs
652
+
653
+ If you develop a new program, and you want it to be of the greatest
654
+ possible use to the public, the best way to achieve this is to make it
655
+ free software which everyone can redistribute and change under these terms.
656
+
657
+ To do so, attach the following notices to the program. It is safest
658
+ to attach them to the start of each source file to most effectively
659
+ state the exclusion of warranty; and each file should have at least
660
+ the "copyright" line and a pointer to where the full notice is found.
661
+
662
+ {one line to give the program's name and a brief idea of what it does.}
663
+ Copyright (C) {year} {name of author}
664
+
665
+ This program is free software: you can redistribute it and/or modify
666
+ it under the terms of the GNU General Public License as published by
667
+ the Free Software Foundation, either version 3 of the License, or
668
+ (at your option) any later version.
669
+
670
+ This program is distributed in the hope that it will be useful,
671
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
672
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
673
+ GNU General Public License for more details.
674
+
675
+ You should have received a copy of the GNU General Public License
676
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
677
+
678
+ Also add information on how to contact you by electronic and paper mail.
679
+
680
+ If the program does terminal interaction, make it output a short
681
+ notice like this when it starts in an interactive mode:
682
+
683
+ {project} Copyright (C) {year} {fullname}
684
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
685
+ This is free software, and you are welcome to redistribute it
686
+ under certain conditions; type `show c' for details.
687
+
688
+ The hypothetical commands `show w' and `show c' should show the appropriate
689
+ parts of the General Public License. Of course, your program's commands
690
+ might be different; for a GUI interface, you would use an "about box".
691
+
692
+ You should also get your employer (if you work as a programmer) or school,
693
+ if any, to sign a "copyright disclaimer" for the program, if necessary.
694
+ For more information on this, and how to apply and follow the GNU GPL, see
695
+ <http://www.gnu.org/licenses/>.
696
+
697
+ The GNU General Public License does not permit incorporating your program
698
+ into proprietary programs. If your program is a subroutine library, you
699
+ may consider it more useful to permit linking proprietary applications with
700
+ the library. If this is what you want to do, use the GNU Lesser General
701
+ Public License instead of this License. But first, please read
702
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
readme.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === ThemeGrill Demo Importer ===
2
+ Contributors: ThemeGrill, shivapoudel
3
+ Tags: themegrill, themes, demo, importer, download
4
+ Requires at least: 4.0
5
+ Tested up to: 4.7
6
+ Stable tag: 1.0.0
7
+ License: GPLv3 or later
8
+ License URI: https://www.gnu.org/licenses/gpl-3.0.html
9
+
10
+ Import your demo content, widgets and theme settings with one click for themegrill themes
11
+
12
+ == Description ==
13
+
14
+ Import your demo content, widgets and theme settings with one click for <a href="https://themegrill.com/themes/" target="_blank" rel="nofollow">ThemeGrill</a> themes
15
+
16
+ Get free support at http://themegrill.com/support-forum/
17
+
18
+ == Installation ==
19
+
20
+ 1. Install the plugin either via the WordPress.org plugin directory, or by uploading the files to your server (in the /wp-content/plugins/ directory).
21
+ 2. Activate the ThemeGrill Demo Importer plugin through the 'Plugins' menu in WordPress.
22
+
23
+ == Frequently Asked Questions ==
24
+
25
+ = What is the plugin license? =
26
+
27
+ * This plugin is released under a GPL license.
28
+
29
+ = What themes this plugin supports? =
30
+
31
+ * The plugin currently only supports ThemeGrill themes.
32
+
33
+ = Where can I report bugs or contribute to the project? =
34
+
35
+ Bugs can be reported either in our support forum or preferably on the [GitHub repository](https://github.com/themegrill/themegrill-demo-importer/issues).
36
+
37
+ = ThemeGrill Demo Importer is awesome! Can I contribute? =
38
+
39
+ Yes you can! Join in on our [GitHub repository](https://github.com/themegrill/themegrill-demo-importer/) :)
40
+
41
+ == Changelog ==
42
+
43
+ = 1.0.0 =
44
+ * Initial Public Release
themegrill-demo-importer.php ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: ThemeGrill Demo Importer
4
+ * Plugin URI: http://themegrill.com/demo-importer/
5
+ * Description: Import your demo content, widgets and theme settings with one click for ThemeGrill themes
6
+ * Version: 1.0.0
7
+ * Author: ThemeGrill
8
+ * Author URI: http://themegrill.com
9
+ * License: GPLv3 or later
10
+ * Text Domain: themegrill-demo-importer
11
+ * Domain Path: /languages/
12
+ */
13
+
14
+ if ( ! defined( 'ABSPATH' ) ) {
15
+ exit; // Exit if accessed directly.
16
+ }
17
+
18
+ if ( ! class_exists( 'ThemeGrill_Demo_Importer' ) ) :
19
+
20
+ /**
21
+ * ThemeGrill_Demo_Importer main class.
22
+ */
23
+ final class ThemeGrill_Demo_Importer {
24
+
25
+ /**
26
+ * Plugin version.
27
+ * @var string
28
+ */
29
+ const VERSION = '1.0.0';
30
+
31
+ /**
32
+ * Instance of this class.
33
+ * @var object
34
+ */
35
+ protected static $instance = null;
36
+
37
+ /**
38
+ * Initialize the plugin.
39
+ */
40
+ private function __construct() {
41
+ // Load plugin text domain.
42
+ add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
43
+
44
+ // Check with ThemeGrill theme is installed.
45
+ if ( in_array( get_option( 'template' ), $this->get_core_supported_themes() ) ) {
46
+ $this->includes();
47
+ $this->demo_includes();
48
+
49
+ // Hooks.
50
+ add_filter( 'themegrill_demo_importer_assets_path', array( $this, 'plugin_assets_path' ) );
51
+ add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) );
52
+ } else {
53
+ add_action( 'admin_notices', array( $this, 'theme_support_missing_notice' ) );
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Return an instance of this class.
59
+ * @return object A single instance of this class.
60
+ */
61
+ public static function get_instance() {
62
+ // If the single instance hasn't been set, set it now.
63
+ if ( is_null( self::$instance ) ) {
64
+ self::$instance = new self();
65
+ }
66
+ return self::$instance;
67
+ }
68
+
69
+ /**
70
+ * Install TG Importer.
71
+ */
72
+ public static function install() {
73
+ $upload_dir = wp_upload_dir();
74
+
75
+ if ( ! is_blog_installed() ) {
76
+ return;
77
+ }
78
+
79
+ // Install files and folders for uploading files and prevent hotlinking.
80
+ $files = array(
81
+ array(
82
+ 'base' => $upload_dir['basedir'] . '/tg-demo-pack',
83
+ 'file' => 'index.html',
84
+ 'content' => '',
85
+ ),
86
+ );
87
+
88
+ foreach ( $files as $file ) {
89
+ if ( wp_mkdir_p( $file['base'] ) && ! file_exists( trailingslashit( $file['base'] ) . $file['file'] ) ) {
90
+ if ( $file_handle = @fopen( trailingslashit( $file['base'] ) . $file['file'], 'w' ) ) {
91
+ fwrite( $file_handle, $file['content'] );
92
+ fclose( $file_handle );
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Load Localisation files.
100
+ *
101
+ * Note: the first-loaded translation file overrides any following ones if the same translation is present.
102
+ *
103
+ * Locales found in:
104
+ * - WP_LANG_DIR/themegrill-demo-importer/themegrill-demo-importer-LOCALE.mo
105
+ * - WP_LANG_DIR/plugins/themegrill-demo-importer-LOCALE.mo
106
+ */
107
+ public function load_plugin_textdomain() {
108
+ $locale = apply_filters( 'plugin_locale', get_locale(), 'themegrill-demo-importer' );
109
+
110
+ load_textdomain( 'themegrill-demo-importer', WP_LANG_DIR . '/themegrill-demo-importer/themegrill-demo-importer-' . $locale . '.mo' );
111
+ load_plugin_textdomain( 'themegrill-demo-importer', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
112
+ }
113
+
114
+ /**
115
+ * Get core supported themes.
116
+ * @return array
117
+ */
118
+ private function get_core_supported_themes() {
119
+ return array( 'spacious', 'colormag', 'flash' );
120
+ }
121
+
122
+ /**
123
+ * Includes.
124
+ */
125
+ private function includes() {
126
+ include_once( dirname( __FILE__ ) . '/includes/class-demo-importer.php' );
127
+ }
128
+
129
+ /**
130
+ * Includes demo config.
131
+ */
132
+ private function demo_includes() {
133
+ $upload_dir = wp_upload_dir();
134
+
135
+ // Check the folder contains at least 1 valid demo config.
136
+ $files = glob( $upload_dir['basedir'] . '/tg-demo-pack/**/tg-demo-config.php' );
137
+ if ( $files ) {
138
+ foreach ( $files as $file ) {
139
+ if ( $file && is_readable( $file ) ) {
140
+ include_once( $file );
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Get the plugin url.
148
+ * @return string
149
+ */
150
+ public function plugin_url() {
151
+ return untrailingslashit( plugins_url( '/', __FILE__ ) );
152
+ }
153
+
154
+ /**
155
+ * Get the plugin assets path.
156
+ * @return string
157
+ */
158
+ public function plugin_assets_path() {
159
+ return trailingslashit( $this->plugin_url() . '/assets/' );
160
+ }
161
+
162
+ /**
163
+ * Display action links in the Plugins list table.
164
+ * @param array $actions
165
+ * @return array
166
+ */
167
+ public function plugin_action_links( $actions ) {
168
+ $new_actions = array(
169
+ 'previews' => '<a href="' . admin_url( 'themes.php?page=demo-importer&tab=previews' ) . '" aria-label="' . esc_attr( __( 'View Demos', 'themegrill-demo-importer' ) ) . '">' . __( 'Demos', 'themegrill-demo-importer' ) . '</a>',
170
+ );
171
+
172
+ return array_merge( $new_actions, $actions );
173
+ }
174
+
175
+ /**
176
+ * Theme support fallback notice.
177
+ * @return string
178
+ */
179
+ public function theme_support_missing_notice() {
180
+ if ( ! class_exists( 'TG_Demo_Importer' ) ) {
181
+ echo '<div class="error notice is-dismissible"><p><strong>' . __( 'ThemeGrill Demo Importer', 'themegrill-demo-importer' ) . '</strong> &#8211; ' . sprintf( __( 'This plugin requires %s by ThemeGrill to work.', 'themegrill-demo-importer' ), '<a href="http://www.themegrill.com/themes/" target="_blank">' . __( 'Official Theme', 'themegrill-demo-importer' ) . '</a>' ) . '</p></div>';
182
+ }
183
+ }
184
+ }
185
+
186
+ add_action( 'plugins_loaded', array( 'ThemeGrill_Demo_Importer', 'get_instance' ) );
187
+
188
+ register_activation_hook( __FILE__, array( 'ThemeGrill_Demo_Importer', 'install' ) );
189
+
190
+ endif;
uninstall.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ThemeGrill Demo Importer Uninstall
4
+ *
5
+ * Uninstalls the plugin and associated data.
6
+ *
7
+ * @author ThemeGrill
8
+ * @category Core
9
+ * @version 1.4.0
10
+ */
11
+
12
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
13
+ exit;
14
+ }
15
+
16
+ // Delete options.
17
+ delete_option( 'themegrill_demo_imported_id' );
18
+ delete_option( 'themegrill_demo_imported_notice_dismiss' );