Ocean Demo Import - Version 1.0.0

Version Description

  • Initial release.
Download this release

Release Info

Developer oceanwp
Plugin Icon 128x128 Ocean Demo Import
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

assets/css/admin.css ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #odi-demo-wrap { display: block; }
2
+ #odi-demo-wrap .odi-important-notice { padding: 10px 15px; background: #fff; margin: 15px 0 0; }
3
+ #odi-demo-wrap .odi-important-notice p { font-size: 14px; margin: 0 0 5px; }
4
+ #odi-demo-wrap .odi-important-notice p:last-child { margin: 0; }
5
+ #odi-demo-wrap .odi-about-description { margin-top: 30px; }
6
+ #odi-demo-wrap .odi-about-description p { font-size: 15px; font-weight: 400; line-height: 1.8; margin: 0; }
7
+ #odi-demo-wrap hr { margin: 32px 0 40px; }
8
+ #odi-demo-wrap .themes { margin: 0 -15px; }
9
+ #odi-demo-wrap .theme-wrap { float: left; width: 33.33%; padding: 0 15px 30px 15px; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; }
10
+ #odi-demo-wrap .theme { float: none; width: 100%; margin: 0; }
11
+ .demo-import-loader { display: none; position: absolute; top: 0; width: 100%; height: 100%; text-align: center; }
12
+ .demo-import-loader.preview-all { background: rgba( 255, 255, 255, 0.7 ); }
13
+ .demo-import-loader i { display: inline-block; margin: -16px auto 0 auto; height: 32px; width: 32px; top: 50%; position: relative; font-size: 32px; line-height: 32px; text-align: center; -moz-animation: spin 2s infinite linear; -o-animation: spin 2s infinite linear; -webkit-animation: spin 2s infinite linear; animation: spin 2s infinite linear; }
14
+ .preview-icon i { color: #333; }
15
+ .success-icon i { color: #329e6d; margin: -20px auto 0 auto; height: 40px; width: 40px; font-size: 40px; }
16
+ .warning-icon i { color: #ff6c6c; }
17
+ .success-icon i, .warning-icon i { -moz-animation: none; -o-animation: none; -webkit-animation: none; animation: none; }
18
+ @-webkit-keyframes spin { 0% { -webkit-transform: rotate(0deg); } 100% { -webkit-transform: rotate(359deg); } }
19
+ @-moz-keyframes spin { 0% { -moz-transform: rotate(0deg); } 100% { -moz-transform: rotate(359deg); } }
20
+ @-o-keyframes spin { 0% { -o-transform: rotate(0deg); } 100% { -o-transform: rotate(359deg); } }
21
+ @-ms-keyframes spin { 0% { -ms-transform: rotate(0deg); } 100% { -ms-transform: rotate(359deg); } }
22
+ @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(359deg); } }
23
+ #odi-demo-wrap .theme-browser .theme:focus,
24
+ #odi-demo-wrap .theme-browser .theme:hover { cursor: default; }
25
+ #odi-demo-wrap .theme-browser .theme .theme-screenshot { cursor: pointer; }
26
+ #odi-demo-wrap .theme-browser .theme .theme-name span { cursor: text; }
27
+
28
+ /* RTL */
29
+ .rtl #odi-demo-wrap .theme-wrap { float: right; }
30
+
31
+ /* Responsive */
32
+ @media only screen and (max-width: 1080px) {
33
+ #odi-demo-wrap .theme-wrap { width: 50%; }
34
+ }
35
+
36
+ @media only screen and (max-width: 780px) {
37
+ #odi-demo-wrap .theme { text-align: center; }
38
+ #odi-demo-wrap .theme-actions { display: block; position: relative; opacity: 1; }
39
+ #odi-demo-wrap .theme-browser .theme .theme-actions .button-primary { margin-right: 0 !important; margin-left: 0 !important; }
40
+ }
41
+
42
+ @media only screen and (max-width: 580px) {
43
+ #odi-demo-wrap .theme-wrap { float: none; width: 100%; }
44
+ }
assets/js/admin.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var $j = jQuery.noConflict();
2
+
3
+ $j(document).ready(function(e) {
4
+
5
+ // if clicked on import data button
6
+ $j( '.odi-install' ).live( 'click', function(e) {
7
+
8
+ var $selected_demo = $j( this ).data( 'demo-id' ),
9
+ $loading_icon = $j( '.preview-' + $selected_demo ),
10
+ $success_icon = $j( '.success-' + $selected_demo ),
11
+ $warning_icon = $j( '.warning-' + $selected_demo ),
12
+ $disable_preview = $j( '.preview-all-' + $selected_demo );
13
+
14
+ $loading_icon.show();
15
+ $disable_preview.show();
16
+
17
+ var data = {
18
+ action: 'ocean_import_demo_data',
19
+ demo_type: $selected_demo
20
+ };
21
+
22
+ $j( '.importer-notice' ).hide();
23
+
24
+ $j.post( ajaxurl, data, function( $response ) {
25
+ if( $response && $response.indexOf( 'imported' ) == -1 ) {
26
+ $j( '.importer-notice-1' ).attr( 'style', 'display:block !important' );
27
+ $warning_icon.show();
28
+ setTimeout( function() {
29
+ $warning_icon.hide();
30
+ $disable_preview.hide();
31
+ }, 4000 );
32
+ } else {
33
+ $j( '.importer-notice-2' ).attr( 'style', 'display:block !important' );
34
+ $success_icon.show();
35
+ setTimeout( function() {
36
+ $success_icon.hide();
37
+ $disable_preview.hide();
38
+ }, 4000 );
39
+ }
40
+ $loading_icon.hide();
41
+ } ).fail( function() {
42
+ $j( '.importer-notice-3' ).attr( 'style', 'display:block !important' );
43
+ $warning_icon.show();
44
+ setTimeout( function() {
45
+ $warning_icon.hide();
46
+ $disable_preview.hide();
47
+ }, 4000 );
48
+ $loading_icon.hide();
49
+
50
+ } );
51
+
52
+ e.preventDefault();
53
+
54
+ } );
55
+
56
+ } );
includes/class/class-helpers.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helpers class
5
+ */
6
+ class ODI_Helpers {
7
+
8
+ /**
9
+ * Gets and returns url body using wp_remote_get
10
+ *
11
+ * @since 1.0.0
12
+ */
13
+ public static function get_remote( $url ) {
14
+
15
+ // Get data
16
+ $response = wp_remote_get( $url );
17
+
18
+ // Check for errors
19
+ if ( is_wp_error( $response ) or ( wp_remote_retrieve_response_code( $response ) != 200 ) ) {
20
+ return false;
21
+ }
22
+
23
+ // Get remote body val
24
+ $body = wp_remote_retrieve_body( $response );
25
+
26
+ // Return data
27
+ if ( ! empty( $body ) ) {
28
+ return $body;
29
+ } else {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Perform a HTTP HEAD or GET request.
36
+ *
37
+ * If $file_path is a writable filename, this will do a GET request and write
38
+ * the file to that path.
39
+ *
40
+ * This is a re-implementation of the deprecated wp_get_http() function from WP Core,
41
+ * but this time using the recommended WP_Http() class and the WordPress filesystem.
42
+ *
43
+ * @param string $url URL to fetch.
44
+ * @param string|bool $file_path Optional. File path to write request to. Default false.
45
+ * @param array $args Optional. Arguments to be passed-on to the request.
46
+ * @return bool|string False on failure and string of headers if HEAD request.
47
+ */
48
+ public static function odi_wp_get_http( $url, $file_path = false, $red = 1 ) {
49
+
50
+ // No need to proceed if we don't have a $url or a $file_path.
51
+ if ( ! $url || ! $file_path ) {
52
+ return false;
53
+ }
54
+
55
+ $try_file_get_contents = false;
56
+
57
+ // Make sure we normalize $file_path.
58
+ $file_path = wp_normalize_path( $file_path );
59
+
60
+ // Include the WP_Http class if it doesn't already exist.
61
+ if ( ! class_exists( 'WP_Http' ) ) {
62
+ include_once( wp_normalize_path( ABSPATH . WPINC . '/class-http.php' ) );
63
+ }
64
+ // Inlude the wp_remote_get function if it doesn't already exist.
65
+ if ( ! function_exists( 'wp_remote_get' ) ) {
66
+ include_once( wp_normalize_path( ABSPATH . WPINC . '/http.php' ) );
67
+ }
68
+
69
+ $args = wp_parse_args( $args, array(
70
+ 'timeout' => 30,
71
+ 'user-agent' => 'avada-user-agent',
72
+ ) );
73
+ $response = wp_remote_get( esc_url_raw( $url ), $args );
74
+ $body = wp_remote_retrieve_body( $response );
75
+
76
+ // Try file_get_contents if body is empty.
77
+ if ( empty( $body ) ) {
78
+ if ( function_exists( 'ini_get' ) && ini_get( 'allow_url_fopen' ) ) {
79
+ $body = @file_get_contents( $url );
80
+ }
81
+ }
82
+
83
+ // Initialize the Wordpress filesystem.
84
+ global $wp_filesystem;
85
+ if ( empty( $wp_filesystem ) ) {
86
+ require_once( ABSPATH . '/wp-admin/includes/file.php' );
87
+ WP_Filesystem();
88
+ }
89
+
90
+ // Attempt to write the file.
91
+ if ( ! $wp_filesystem->put_contents( $file_path, $body, FS_CHMOD_FILE ) ) {
92
+ // If the attempt to write to the file failed, then fallback to fwrite.
93
+ @unlink( $file_path );
94
+ $fp = fopen( $file_path, 'w' );
95
+ $written = fwrite( $fp, $body );
96
+ fclose( $fp );
97
+ if ( false === $written ) {
98
+ return false;
99
+ }
100
+ }
101
+
102
+ // If all went well, then return the headers of the request.
103
+ if ( isset( $response['headers'] ) ) {
104
+ $response['headers']['response'] = $response['response']['code'];
105
+ return $response['headers'];
106
+ }
107
+
108
+ // If all else fails, then return false.
109
+ return false;
110
+
111
+ }
112
+
113
+ }
includes/class/class-parsers.php ADDED
@@ -0,0 +1,691 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WordPress eXtended RSS file parser implementations
4
+ *
5
+ * @package WordPress
6
+ * @subpackage Importer
7
+ */
8
+
9
+ /**
10
+ * WordPress Importer class for managing parsing of WXR files.
11
+ */
12
+ class WXR_Parser {
13
+ function parse( $file ) {
14
+ // Attempt to use proper XML parsers first
15
+ if ( extension_loaded( 'simplexml' ) ) {
16
+ $parser = new WXR_Parser_SimpleXML;
17
+ $result = $parser->parse( $file );
18
+
19
+ // If SimpleXML succeeds or this is an invalid WXR file then return the results
20
+ if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
21
+ return $result;
22
+ } else if ( extension_loaded( 'xml' ) ) {
23
+ $parser = new WXR_Parser_XML;
24
+ $result = $parser->parse( $file );
25
+
26
+ // If XMLParser succeeds or this is an invalid WXR file then return the results
27
+ if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
28
+ return $result;
29
+ }
30
+
31
+ // We have a malformed XML file, so display the error and fallthrough to regex
32
+ if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
33
+ echo '<pre>';
34
+ if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
35
+ foreach ( $result->get_error_data() as $error )
36
+ echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
37
+ } else if ( 'XML_parse_error' == $result->get_error_code() ) {
38
+ $error = $result->get_error_data();
39
+ echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
40
+ }
41
+ echo '</pre>';
42
+ echo '<p><strong>' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '</strong><br />';
43
+ echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '</p>';
44
+ }
45
+
46
+ // use regular expressions if nothing else available or this is bad XML
47
+ $parser = new WXR_Parser_Regex;
48
+ return $parser->parse( $file );
49
+ }
50
+ }
51
+
52
+ /**
53
+ * WXR Parser that makes use of the SimpleXML PHP extension.
54
+ */
55
+ class WXR_Parser_SimpleXML {
56
+ function parse( $file ) {
57
+ $authors = $posts = $categories = $tags = $terms = array();
58
+
59
+ $internal_errors = libxml_use_internal_errors(true);
60
+
61
+ $dom = new DOMDocument;
62
+ $old_value = null;
63
+ if ( function_exists( 'libxml_disable_entity_loader' ) ) {
64
+ $old_value = libxml_disable_entity_loader( true );
65
+ }
66
+ $success = $dom->loadXML( file_get_contents( $file ) );
67
+ if ( ! is_null( $old_value ) ) {
68
+ libxml_disable_entity_loader( $old_value );
69
+ }
70
+
71
+ if ( ! $success || isset( $dom->doctype ) ) {
72
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
73
+ }
74
+
75
+ $xml = simplexml_import_dom( $dom );
76
+ unset( $dom );
77
+
78
+ // halt if loading produces an error
79
+ if ( ! $xml )
80
+ return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() );
81
+
82
+ $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
83
+ if ( ! $wxr_version )
84
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
85
+
86
+ $wxr_version = (string) trim( $wxr_version[0] );
87
+ // confirm that we are dealing with the correct file format
88
+ if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
89
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
90
+
91
+ $base_url = $xml->xpath('/rss/channel/wp:base_site_url');
92
+ $base_url = (string) trim( $base_url[0] );
93
+
94
+ $namespaces = $xml->getDocNamespaces();
95
+ if ( ! isset( $namespaces['wp'] ) )
96
+ $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
97
+ if ( ! isset( $namespaces['excerpt'] ) )
98
+ $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
99
+
100
+ // grab authors
101
+ foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
102
+ $a = $author_arr->children( $namespaces['wp'] );
103
+ $login = (string) $a->author_login;
104
+ $authors[$login] = array(
105
+ 'author_id' => (int) $a->author_id,
106
+ 'author_login' => $login,
107
+ 'author_email' => (string) $a->author_email,
108
+ 'author_display_name' => (string) $a->author_display_name,
109
+ 'author_first_name' => (string) $a->author_first_name,
110
+ 'author_last_name' => (string) $a->author_last_name
111
+ );
112
+ }
113
+
114
+ // grab cats, tags and terms
115
+ foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) {
116
+ $t = $term_arr->children( $namespaces['wp'] );
117
+ $category = array(
118
+ 'term_id' => (int) $t->term_id,
119
+ 'category_nicename' => (string) $t->category_nicename,
120
+ 'category_parent' => (string) $t->category_parent,
121
+ 'cat_name' => (string) $t->cat_name,
122
+ 'category_description' => (string) $t->category_description
123
+ );
124
+
125
+ foreach ( $t->termmeta as $meta ) {
126
+ $category['termmeta'][] = array(
127
+ 'key' => (string) $meta->meta_key,
128
+ 'value' => (string) $meta->meta_value
129
+ );
130
+ }
131
+
132
+ $categories[] = $category;
133
+ }
134
+
135
+ foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) {
136
+ $t = $term_arr->children( $namespaces['wp'] );
137
+ $tag = array(
138
+ 'term_id' => (int) $t->term_id,
139
+ 'tag_slug' => (string) $t->tag_slug,
140
+ 'tag_name' => (string) $t->tag_name,
141
+ 'tag_description' => (string) $t->tag_description
142
+ );
143
+
144
+ foreach ( $t->termmeta as $meta ) {
145
+ $tag['termmeta'][] = array(
146
+ 'key' => (string) $meta->meta_key,
147
+ 'value' => (string) $meta->meta_value
148
+ );
149
+ }
150
+
151
+ $tags[] = $tag;
152
+ }
153
+
154
+ foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) {
155
+ $t = $term_arr->children( $namespaces['wp'] );
156
+ $term = array(
157
+ 'term_id' => (int) $t->term_id,
158
+ 'term_taxonomy' => (string) $t->term_taxonomy,
159
+ 'slug' => (string) $t->term_slug,
160
+ 'term_parent' => (string) $t->term_parent,
161
+ 'term_name' => (string) $t->term_name,
162
+ 'term_description' => (string) $t->term_description
163
+ );
164
+
165
+ foreach ( $t->termmeta as $meta ) {
166
+ $term['termmeta'][] = array(
167
+ 'key' => (string) $meta->meta_key,
168
+ 'value' => (string) $meta->meta_value
169
+ );
170
+ }
171
+
172
+ $terms[] = $term;
173
+ }
174
+
175
+ // grab posts
176
+ foreach ( $xml->channel->item as $item ) {
177
+ $post = array(
178
+ 'post_title' => (string) $item->title,
179
+ 'guid' => (string) $item->guid,
180
+ );
181
+
182
+ $dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
183
+ $post['post_author'] = (string) $dc->creator;
184
+
185
+ $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
186
+ $excerpt = $item->children( $namespaces['excerpt'] );
187
+ $post['post_content'] = (string) $content->encoded;
188
+ $post['post_excerpt'] = (string) $excerpt->encoded;
189
+
190
+ $wp = $item->children( $namespaces['wp'] );
191
+ $post['post_id'] = (int) $wp->post_id;
192
+ $post['post_date'] = (string) $wp->post_date;
193
+ $post['post_date_gmt'] = (string) $wp->post_date_gmt;
194
+ $post['comment_status'] = (string) $wp->comment_status;
195
+ $post['ping_status'] = (string) $wp->ping_status;
196
+ $post['post_name'] = (string) $wp->post_name;
197
+ $post['status'] = (string) $wp->status;
198
+ $post['post_parent'] = (int) $wp->post_parent;
199
+ $post['menu_order'] = (int) $wp->menu_order;
200
+ $post['post_type'] = (string) $wp->post_type;
201
+ $post['post_password'] = (string) $wp->post_password;
202
+ $post['is_sticky'] = (int) $wp->is_sticky;
203
+
204
+ if ( isset($wp->attachment_url) )
205
+ $post['attachment_url'] = (string) $wp->attachment_url;
206
+
207
+ foreach ( $item->category as $c ) {
208
+ $att = $c->attributes();
209
+ if ( isset( $att['nicename'] ) )
210
+ $post['terms'][] = array(
211
+ 'name' => (string) $c,
212
+ 'slug' => (string) $att['nicename'],
213
+ 'domain' => (string) $att['domain']
214
+ );
215
+ }
216
+
217
+ foreach ( $wp->postmeta as $meta ) {
218
+ $post['postmeta'][] = array(
219
+ 'key' => (string) $meta->meta_key,
220
+ 'value' => (string) $meta->meta_value
221
+ );
222
+ }
223
+
224
+ foreach ( $wp->comment as $comment ) {
225
+ $meta = array();
226
+ if ( isset( $comment->commentmeta ) ) {
227
+ foreach ( $comment->commentmeta as $m ) {
228
+ $meta[] = array(
229
+ 'key' => (string) $m->meta_key,
230
+ 'value' => (string) $m->meta_value
231
+ );
232
+ }
233
+ }
234
+
235
+ $post['comments'][] = array(
236
+ 'comment_id' => (int) $comment->comment_id,
237
+ 'comment_author' => (string) $comment->comment_author,
238
+ 'comment_author_email' => (string) $comment->comment_author_email,
239
+ 'comment_author_IP' => (string) $comment->comment_author_IP,
240
+ 'comment_author_url' => (string) $comment->comment_author_url,
241
+ 'comment_date' => (string) $comment->comment_date,
242
+ 'comment_date_gmt' => (string) $comment->comment_date_gmt,
243
+ 'comment_content' => (string) $comment->comment_content,
244
+ 'comment_approved' => (string) $comment->comment_approved,
245
+ 'comment_type' => (string) $comment->comment_type,
246
+ 'comment_parent' => (string) $comment->comment_parent,
247
+ 'comment_user_id' => (int) $comment->comment_user_id,
248
+ 'commentmeta' => $meta,
249
+ );
250
+ }
251
+
252
+ $posts[] = $post;
253
+ }
254
+
255
+ return array(
256
+ 'authors' => $authors,
257
+ 'posts' => $posts,
258
+ 'categories' => $categories,
259
+ 'tags' => $tags,
260
+ 'terms' => $terms,
261
+ 'base_url' => $base_url,
262
+ 'version' => $wxr_version
263
+ );
264
+ }
265
+ }
266
+
267
+ /**
268
+ * WXR Parser that makes use of the XML Parser PHP extension.
269
+ */
270
+ class WXR_Parser_XML {
271
+ var $wp_tags = array(
272
+ 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
273
+ 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
274
+ 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
275
+ 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
276
+ 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
277
+ 'wp:author_first_name', 'wp:author_last_name',
278
+ );
279
+ var $wp_sub_tags = array(
280
+ 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
281
+ 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
282
+ 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
283
+ );
284
+
285
+ function parse( $file ) {
286
+ $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
287
+ $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
288
+
289
+ $xml = xml_parser_create( 'UTF-8' );
290
+ xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
291
+ xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
292
+ xml_set_object( $xml, $this );
293
+ xml_set_character_data_handler( $xml, 'cdata' );
294
+ xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
295
+
296
+ if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) {
297
+ $current_line = xml_get_current_line_number( $xml );
298
+ $current_column = xml_get_current_column_number( $xml );
299
+ $error_code = xml_get_error_code( $xml );
300
+ $error_string = xml_error_string( $error_code );
301
+ return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
302
+ }
303
+ xml_parser_free( $xml );
304
+
305
+ if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
306
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
307
+
308
+ return array(
309
+ 'authors' => $this->authors,
310
+ 'posts' => $this->posts,
311
+ 'categories' => $this->category,
312
+ 'tags' => $this->tag,
313
+ 'terms' => $this->term,
314
+ 'base_url' => $this->base_url,
315
+ 'version' => $this->wxr_version
316
+ );
317
+ }
318
+
319
+ function tag_open( $parse, $tag, $attr ) {
320
+ if ( in_array( $tag, $this->wp_tags ) ) {
321
+ $this->in_tag = substr( $tag, 3 );
322
+ return;
323
+ }
324
+
325
+ if ( in_array( $tag, $this->wp_sub_tags ) ) {
326
+ $this->in_sub_tag = substr( $tag, 3 );
327
+ return;
328
+ }
329
+
330
+ switch ( $tag ) {
331
+ case 'category':
332
+ if ( isset($attr['domain'], $attr['nicename']) ) {
333
+ $this->sub_data['domain'] = $attr['domain'];
334
+ $this->sub_data['slug'] = $attr['nicename'];
335
+ }
336
+ break;
337
+ case 'item': $this->in_post = true;
338
+ case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
339
+ case 'guid': $this->in_tag = 'guid'; break;
340
+ case 'dc:creator': $this->in_tag = 'post_author'; break;
341
+ case 'content:encoded': $this->in_tag = 'post_content'; break;
342
+ case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
343
+
344
+ case 'wp:term_slug': $this->in_tag = 'slug'; break;
345
+ case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
346
+ case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
347
+ }
348
+ }
349
+
350
+ function cdata( $parser, $cdata ) {
351
+ if ( ! trim( $cdata ) )
352
+ return;
353
+
354
+ if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
355
+ $this->cdata .= $cdata;
356
+ } else {
357
+ $this->cdata .= trim( $cdata );
358
+ }
359
+ }
360
+
361
+ function tag_close( $parser, $tag ) {
362
+ switch ( $tag ) {
363
+ case 'wp:comment':
364
+ unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
365
+ if ( ! empty( $this->sub_data ) )
366
+ $this->data['comments'][] = $this->sub_data;
367
+ $this->sub_data = false;
368
+ break;
369
+ case 'wp:commentmeta':
370
+ $this->sub_data['commentmeta'][] = array(
371
+ 'key' => $this->sub_data['key'],
372
+ 'value' => $this->sub_data['value']
373
+ );
374
+ break;
375
+ case 'category':
376
+ if ( ! empty( $this->sub_data ) ) {
377
+ $this->sub_data['name'] = $this->cdata;
378
+ $this->data['terms'][] = $this->sub_data;
379
+ }
380
+ $this->sub_data = false;
381
+ break;
382
+ case 'wp:postmeta':
383
+ if ( ! empty( $this->sub_data ) )
384
+ $this->data['postmeta'][] = $this->sub_data;
385
+ $this->sub_data = false;
386
+ break;
387
+ case 'item':
388
+ $this->posts[] = $this->data;
389
+ $this->data = false;
390
+ break;
391
+ case 'wp:category':
392
+ case 'wp:tag':
393
+ case 'wp:term':
394
+ $n = substr( $tag, 3 );
395
+ array_push( $this->$n, $this->data );
396
+ $this->data = false;
397
+ break;
398
+ case 'wp:author':
399
+ if ( ! empty($this->data['author_login']) )
400
+ $this->authors[$this->data['author_login']] = $this->data;
401
+ $this->data = false;
402
+ break;
403
+ case 'wp:base_site_url':
404
+ $this->base_url = $this->cdata;
405
+ break;
406
+ case 'wp:wxr_version':
407
+ $this->wxr_version = $this->cdata;
408
+ break;
409
+
410
+ default:
411
+ if ( $this->in_sub_tag ) {
412
+ $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
413
+ $this->in_sub_tag = false;
414
+ } else if ( $this->in_tag ) {
415
+ $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
416
+ $this->in_tag = false;
417
+ }
418
+ }
419
+
420
+ $this->cdata = false;
421
+ }
422
+ }
423
+
424
+ /**
425
+ * WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
426
+ */
427
+ class WXR_Parser_Regex {
428
+ var $authors = array();
429
+ var $posts = array();
430
+ var $categories = array();
431
+ var $tags = array();
432
+ var $terms = array();
433
+ var $base_url = '';
434
+
435
+ function __construct() {
436
+ $this->has_gzip = is_callable( 'gzopen' );
437
+ }
438
+
439
+ function parse( $file ) {
440
+ $wxr_version = $in_post = false;
441
+
442
+ $fp = $this->fopen( $file, 'r' );
443
+ if ( $fp ) {
444
+ while ( ! $this->feof( $fp ) ) {
445
+ $importline = rtrim( $this->fgets( $fp ) );
446
+
447
+ if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
448
+ $wxr_version = $version[1];
449
+
450
+ if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
451
+ preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
452
+ $this->base_url = $url[1];
453
+ continue;
454
+ }
455
+ if ( false !== strpos( $importline, '<wp:category>' ) ) {
456
+ preg_match( '|<wp:category>(.*?)</wp:category>|is', $importline, $category );
457
+ $this->categories[] = $this->process_category( $category[1] );
458
+ continue;
459
+ }
460
+ if ( false !== strpos( $importline, '<wp:tag>' ) ) {
461
+ preg_match( '|<wp:tag>(.*?)</wp:tag>|is', $importline, $tag );
462
+ $this->tags[] = $this->process_tag( $tag[1] );
463
+ continue;
464
+ }
465
+ if ( false !== strpos( $importline, '<wp:term>' ) ) {
466
+ preg_match( '|<wp:term>(.*?)</wp:term>|is', $importline, $term );
467
+ $this->terms[] = $this->process_term( $term[1] );
468
+ continue;
469
+ }
470
+ if ( false !== strpos( $importline, '<wp:author>' ) ) {
471
+ preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
472
+ $a = $this->process_author( $author[1] );
473
+ $this->authors[$a['author_login']] = $a;
474
+ continue;
475
+ }
476
+ if ( false !== strpos( $importline, '<item>' ) ) {
477
+ $post = '';
478
+ $in_post = true;
479
+ continue;
480
+ }
481
+ if ( false !== strpos( $importline, '</item>' ) ) {
482
+ $in_post = false;
483
+ $this->posts[] = $this->process_post( $post );
484
+ continue;
485
+ }
486
+ if ( $in_post ) {
487
+ $post .= $importline . "\n";
488
+ }
489
+ }
490
+
491
+ $this->fclose($fp);
492
+ }
493
+
494
+ if ( ! $wxr_version )
495
+ return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) );
496
+
497
+ return array(
498
+ 'authors' => $this->authors,
499
+ 'posts' => $this->posts,
500
+ 'categories' => $this->categories,
501
+ 'tags' => $this->tags,
502
+ 'terms' => $this->terms,
503
+ 'base_url' => $this->base_url,
504
+ 'version' => $wxr_version
505
+ );
506
+ }
507
+
508
+ function get_tag( $string, $tag ) {
509
+ preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
510
+ if ( isset( $return[1] ) ) {
511
+ if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
512
+ if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
513
+ preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
514
+ $return = '';
515
+ foreach( $matches[1] as $match )
516
+ $return .= $match;
517
+ } else {
518
+ $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
519
+ }
520
+ } else {
521
+ $return = $return[1];
522
+ }
523
+ } else {
524
+ $return = '';
525
+ }
526
+ return $return;
527
+ }
528
+
529
+ function process_category( $c ) {
530
+ return array(
531
+ 'term_id' => $this->get_tag( $c, 'wp:term_id' ),
532
+ 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
533
+ 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
534
+ 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
535
+ 'category_description' => $this->get_tag( $c, 'wp:category_description' ),
536
+ );
537
+ }
538
+
539
+ function process_tag( $t ) {
540
+ return array(
541
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
542
+ 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
543
+ 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
544
+ 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
545
+ );
546
+ }
547
+
548
+ function process_term( $t ) {
549
+ return array(
550
+ 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
551
+ 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
552
+ 'slug' => $this->get_tag( $t, 'wp:term_slug' ),
553
+ 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
554
+ 'term_name' => $this->get_tag( $t, 'wp:term_name' ),
555
+ 'term_description' => $this->get_tag( $t, 'wp:term_description' ),
556
+ );
557
+ }
558
+
559
+ function process_author( $a ) {
560
+ return array(
561
+ 'author_id' => $this->get_tag( $a, 'wp:author_id' ),
562
+ 'author_login' => $this->get_tag( $a, 'wp:author_login' ),
563
+ 'author_email' => $this->get_tag( $a, 'wp:author_email' ),
564
+ 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
565
+ 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
566
+ 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
567
+ );
568
+ }
569
+
570
+ function process_post( $post ) {
571
+ $post_id = $this->get_tag( $post, 'wp:post_id' );
572
+ $post_title = $this->get_tag( $post, 'title' );
573
+ $post_date = $this->get_tag( $post, 'wp:post_date' );
574
+ $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
575
+ $comment_status = $this->get_tag( $post, 'wp:comment_status' );
576
+ $ping_status = $this->get_tag( $post, 'wp:ping_status' );
577
+ $status = $this->get_tag( $post, 'wp:status' );
578
+ $post_name = $this->get_tag( $post, 'wp:post_name' );
579
+ $post_parent = $this->get_tag( $post, 'wp:post_parent' );
580
+ $menu_order = $this->get_tag( $post, 'wp:menu_order' );
581
+ $post_type = $this->get_tag( $post, 'wp:post_type' );
582
+ $post_password = $this->get_tag( $post, 'wp:post_password' );
583
+ $is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
584
+ $guid = $this->get_tag( $post, 'guid' );
585
+ $post_author = $this->get_tag( $post, 'dc:creator' );
586
+
587
+ $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
588
+ $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
589
+ $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
590
+ $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
591
+
592
+ $post_content = $this->get_tag( $post, 'content:encoded' );
593
+ $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
594
+ $post_content = str_replace( '<br>', '<br />', $post_content );
595
+ $post_content = str_replace( '<hr>', '<hr />', $post_content );
596
+
597
+ $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt',
598
+ 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent',
599
+ 'menu_order', 'post_type', 'post_password', 'is_sticky'
600
+ );
601
+
602
+ $attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
603
+ if ( $attachment_url )
604
+ $postdata['attachment_url'] = $attachment_url;
605
+
606
+ preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
607
+ foreach ( $terms as $t ) {
608
+ $post_terms[] = array(
609
+ 'slug' => $t[2],
610
+ 'domain' => $t[1],
611
+ 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
612
+ );
613
+ }
614
+ if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
615
+
616
+ preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
617
+ $comments = $comments[1];
618
+ if ( $comments ) {
619
+ foreach ( $comments as $comment ) {
620
+ preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
621
+ $commentmeta = $commentmeta[1];
622
+ $c_meta = array();
623
+ foreach ( $commentmeta as $m ) {
624
+ $c_meta[] = array(
625
+ 'key' => $this->get_tag( $m, 'wp:meta_key' ),
626
+ 'value' => $this->get_tag( $m, 'wp:meta_value' ),
627
+ );
628
+ }
629
+
630
+ $post_comments[] = array(
631
+ 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
632
+ 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
633
+ 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
634
+ 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
635
+ 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
636
+ 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
637
+ 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
638
+ 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
639
+ 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
640
+ 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
641
+ 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
642
+ 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
643
+ 'commentmeta' => $c_meta,
644
+ );
645
+ }
646
+ }
647
+ if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
648
+
649
+ preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
650
+ $postmeta = $postmeta[1];
651
+ if ( $postmeta ) {
652
+ foreach ( $postmeta as $p ) {
653
+ $post_postmeta[] = array(
654
+ 'key' => $this->get_tag( $p, 'wp:meta_key' ),
655
+ 'value' => $this->get_tag( $p, 'wp:meta_value' ),
656
+ );
657
+ }
658
+ }
659
+ if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
660
+
661
+ return $postdata;
662
+ }
663
+
664
+ function _normalize_tag( $matches ) {
665
+ return '<' . strtolower( $matches[1] );
666
+ }
667
+
668
+ function fopen( $filename, $mode = 'r' ) {
669
+ if ( $this->has_gzip )
670
+ return gzopen( $filename, $mode );
671
+ return fopen( $filename, $mode );
672
+ }
673
+
674
+ function feof( $fp ) {
675
+ if ( $this->has_gzip )
676
+ return gzeof( $fp );
677
+ return feof( $fp );
678
+ }
679
+
680
+ function fgets( $fp, $len = 8192 ) {
681
+ if ( $this->has_gzip )
682
+ return gzgets( $fp, $len );
683
+ return fgets( $fp, $len );
684
+ }
685
+
686
+ function fclose( $fp ) {
687
+ if ( $this->has_gzip )
688
+ return gzclose( $fp );
689
+ return fclose( $fp );
690
+ }
691
+ }
includes/class/class-settings-importer.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class for the settings importer.
4
+ */
5
+
6
+ class ODI_Settings_Importer {
7
+
8
+ /**
9
+ * Process import file - this parses the settings data and returns it.
10
+ *
11
+ * @param string $file path to json file.
12
+ */
13
+ public function process_import_file( $file ) {
14
+
15
+ // Get file contents.
16
+ $data = ODI_Helpers::get_remote( $file );
17
+
18
+ // Return from this function if there was an error.
19
+ if ( is_wp_error( $data ) ) {
20
+ return $data;
21
+ }
22
+
23
+ // Decode file contents.
24
+ $data = json_decode( $data, true );
25
+
26
+ // Import the data
27
+ return $this->import_data( $data );
28
+
29
+ }
30
+
31
+ /**
32
+ * Import JSON data
33
+ *
34
+ * @return array $results
35
+ */
36
+ private function import_data( $file ) {
37
+
38
+ // Import the file
39
+ if ( ! empty( $file ) ) {
40
+
41
+ if ( '0' == json_last_error() ) {
42
+
43
+ // Loop through mods and add them
44
+ foreach ( $file as $mod => $value ) {
45
+ set_theme_mod( $mod, $value );
46
+ }
47
+
48
+ }
49
+
50
+ }
51
+
52
+ // Return file
53
+ return $file;
54
+
55
+ }
56
+ }
includes/class/class-widget-importer.php ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class for the widget importer.
4
+ *
5
+ * Code is mostly from the Widget Importer & Exporter plugin.
6
+ *
7
+ * @see https://wordpress.org/plugins/widget-importer-exporter/
8
+ */
9
+
10
+ class ODI_Widget_Importer {
11
+
12
+ /**
13
+ * Process import file - this parses the widget data and returns it.
14
+ *
15
+ * @param string $file path to json file.
16
+ * @global string $widget_import_results
17
+ */
18
+ public function process_import_file( $file ) {
19
+
20
+ // Get file contents.
21
+ $data = ODI_Helpers::get_remote( $file );
22
+
23
+ // Return from this function if there was an error.
24
+ if ( is_wp_error( $data ) ) {
25
+ return $data;
26
+ }
27
+
28
+ // Decode file contents.
29
+ $data = json_decode( $data );
30
+
31
+ // Import the widget data
32
+ return $this->import_data( $data );
33
+
34
+ }
35
+
36
+ /**
37
+ * Import widget JSON data
38
+ *
39
+ * @global array $wp_registered_sidebars
40
+ * @param object $data JSON widget data.
41
+ * @return array $results
42
+ */
43
+ private function import_data( $data ) {
44
+
45
+ global $wp_registered_sidebars;
46
+
47
+ // Have valid data? If no data or could not decode.
48
+ if ( empty( $data ) || ! is_object( $data ) ) {
49
+ return;
50
+ }
51
+
52
+ // Get all available widgets site supports.
53
+ $available_widgets = $this->available_widgets();
54
+
55
+ // Get all existing widget instances.
56
+ $widget_instances = array();
57
+
58
+ foreach ( $available_widgets as $widget_data ) {
59
+ $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
60
+ }
61
+
62
+ // Begin results.
63
+ $results = array();
64
+
65
+ // Loop import data's sidebars.
66
+ foreach ( $data as $sidebar_id => $widgets ) {
67
+
68
+ // Skip inactive widgets (should not be in export file).
69
+ if ( 'wp_inactive_widgets' == $sidebar_id ) {
70
+ continue;
71
+ }
72
+
73
+ // Check if sidebar is available on this site. Otherwise add widgets to inactive, and say so.
74
+ if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
75
+ $sidebar_available = true;
76
+ $use_sidebar_id = $sidebar_id;
77
+ $sidebar_message_type = 'success';
78
+ $sidebar_message = '';
79
+ }
80
+ else {
81
+ $sidebar_available = false;
82
+ $use_sidebar_id = 'wp_inactive_widgets'; // Add to inactive if sidebar does not exist in theme.
83
+ $sidebar_message_type = 'error';
84
+ $sidebar_message = esc_html__( 'Sidebar does not exist in theme (moving widget to Inactive)', 'ocean-demo-import' );
85
+ }
86
+
87
+ // Result for sidebar.
88
+ $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.
89
+ $results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
90
+ $results[ $sidebar_id ]['message'] = $sidebar_message;
91
+ $results[ $sidebar_id ]['widgets'] = array();
92
+
93
+ // Loop widgets.
94
+ foreach ( $widgets as $widget_instance_id => $widget ) {
95
+
96
+ $fail = false;
97
+
98
+ // Get id_base (remove -# from end) and instance ID number.
99
+ $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
100
+ $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
101
+
102
+ // Does site support this widget?
103
+ if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
104
+ $fail = true;
105
+ $widget_message_type = 'error';
106
+ $widget_message = esc_html__( 'Site does not support widget', 'ocean-demo-import' ); // Explain why widget not imported.
107
+ }
108
+
109
+ // Convert multidimensional objects to multidimensional arrays.
110
+ $widget = json_decode( json_encode( $widget ), true );
111
+
112
+ // Does widget with identical settings already exist in same sidebar?
113
+ if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
114
+
115
+ // Get existing widgets in this sidebar.
116
+ $sidebars_widgets = get_option( 'sidebars_widgets' );
117
+ $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // Check Inactive if that's where will go.
118
+
119
+ // Loop widgets with ID base.
120
+ $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
121
+ foreach ( $single_widget_instances as $check_id => $check_widget ) {
122
+
123
+ // Is widget in same sidebar and has identical settings?
124
+ if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) {
125
+ $fail = true;
126
+ $widget_message_type = 'warning';
127
+ $widget_message = esc_html__( 'Widget already exists', 'ocean-demo-import' ); // Explain why widget not imported.
128
+
129
+ break;
130
+ }
131
+ }
132
+ }
133
+
134
+ // No failure.
135
+ if ( ! $fail ) {
136
+
137
+ // Add widget instance.
138
+ $single_widget_instances = get_option( 'widget_' . $id_base ); // All instances for that widget ID base, get fresh every time.
139
+ $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // Start fresh if have to.
140
+ $single_widget_instances[] = $widget; // Add it.
141
+
142
+ // Get the key it was given.
143
+ end( $single_widget_instances );
144
+ $new_instance_id_number = key( $single_widget_instances );
145
+
146
+ // If key is 0, make it 1.
147
+ // 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).
148
+ if ( '0' === strval( $new_instance_id_number ) ) {
149
+ $new_instance_id_number = 1;
150
+ $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
151
+ unset( $single_widget_instances[0] );
152
+ }
153
+
154
+ // Move _multiwidget to end of array for uniformity.
155
+ if ( isset( $single_widget_instances['_multiwidget'] ) ) {
156
+ $multiwidget = $single_widget_instances['_multiwidget'];
157
+ unset( $single_widget_instances['_multiwidget'] );
158
+ $single_widget_instances['_multiwidget'] = $multiwidget;
159
+ }
160
+
161
+ // Update option with new widget.
162
+ update_option( 'widget_' . $id_base, $single_widget_instances );
163
+
164
+ // Assign widget instance to sidebar.
165
+ $sidebars_widgets = get_option( 'sidebars_widgets' ); // Which sidebars have which widgets, get fresh every time.
166
+ $new_instance_id = $id_base . '-' . $new_instance_id_number; // Use ID number from new widget instance.
167
+ $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // Add new instance to sidebar.
168
+ update_option( 'sidebars_widgets', $sidebars_widgets ); // Save the amended data.
169
+
170
+ // After widget import action.
171
+ $after_widget_import = array(
172
+ 'sidebar' => $use_sidebar_id,
173
+ 'sidebar_old' => $sidebar_id,
174
+ 'widget' => $widget,
175
+ 'widget_type' => $id_base,
176
+ 'widget_id' => $new_instance_id,
177
+ 'widget_id_old' => $widget_instance_id,
178
+ 'widget_id_num' => $new_instance_id_number,
179
+ 'widget_id_num_old' => $instance_id_number,
180
+ );
181
+
182
+ // Success message.
183
+ if ( $sidebar_available ) {
184
+ $widget_message_type = 'success';
185
+ $widget_message = esc_html__( 'Imported', 'ocean-demo-import' );
186
+ }
187
+ else {
188
+ $widget_message_type = 'warning';
189
+ $widget_message = esc_html__( 'Imported to Inactive', 'ocean-demo-import' );
190
+ }
191
+ }
192
+
193
+ // Result for widget instance.
194
+ $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).
195
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'ocean-demo-import' ); // Show "No Title" if widget instance is untitled.
196
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
197
+ $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
198
+
199
+ }
200
+ }
201
+
202
+ // Return results.
203
+ return $results;
204
+ }
205
+
206
+ /**
207
+ * Available widgets.
208
+ *
209
+ * Gather site's widgets into array with ID base, name, etc.
210
+ *
211
+ * @global array $wp_registered_widget_controls
212
+ * @return array $available_widgets, Widget information
213
+ */
214
+ private function available_widgets() {
215
+
216
+ global $wp_registered_widget_controls;
217
+
218
+ $widget_controls = $wp_registered_widget_controls;
219
+
220
+ $available_widgets = array();
221
+
222
+ foreach ( $widget_controls as $widget ) {
223
+
224
+ if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[$widget['id_base']] ) ) { // no dupes
225
+
226
+ $available_widgets[$widget['id_base']]['id_base'] = $widget['id_base'];
227
+ $available_widgets[$widget['id_base']]['name'] = $widget['name'];
228
+
229
+ }
230
+
231
+ }
232
+
233
+ return $available_widgets;
234
+ }
235
+ }
includes/class/class-wordpress-importer.php ADDED
@@ -0,0 +1,1221 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: WordPress Importer
4
+ Plugin URI: http://wordpress.org/extend/plugins/wordpress-importer/
5
+ Description: Import posts, pages, comments, custom fields, categories, tags and more from a WordPress export file.
6
+ Author: wordpressdotorg
7
+ Author URI: http://wordpress.org/
8
+ Version: 0.6.3
9
+ Text Domain: wordpress-importer
10
+ License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11
+ */
12
+
13
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
14
+ return;
15
+
16
+ /** Display verbose errors */
17
+ define( 'IMPORT_DEBUG', false );
18
+
19
+ // Load Importer API
20
+ require_once ABSPATH . 'wp-admin/includes/import.php';
21
+
22
+ if ( ! class_exists( 'WP_Importer' ) ) {
23
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
24
+ if ( file_exists( $class_wp_importer ) )
25
+ require $class_wp_importer;
26
+ }
27
+
28
+ // include WXR file parsers
29
+ require ODI_PATH . '/includes/class/class-parsers.php';
30
+
31
+ /**
32
+ * WordPress Importer class for managing the import process of a WXR file
33
+ *
34
+ * @package WordPress
35
+ * @subpackage Importer
36
+ */
37
+ if ( class_exists( 'WP_Importer' ) ) {
38
+ class WP_Import extends WP_Importer {
39
+ var $max_wxr_version = 1.2; // max. supported WXR version
40
+
41
+ var $id; // WXR attachment ID
42
+
43
+ // information to import from WXR file
44
+ var $version;
45
+ var $authors = array();
46
+ var $posts = array();
47
+ var $terms = array();
48
+ var $categories = array();
49
+ var $tags = array();
50
+ var $base_url = '';
51
+
52
+ // mappings from old information to new
53
+ var $processed_authors = array();
54
+ var $author_mapping = array();
55
+ var $processed_terms = array();
56
+ var $processed_posts = array();
57
+ var $post_orphans = array();
58
+ var $processed_menu_items = array();
59
+ var $menu_item_orphans = array();
60
+ var $missing_menu_items = array();
61
+
62
+ var $fetch_attachments = false;
63
+ var $url_remap = array();
64
+ var $featured_images = array();
65
+
66
+ /**
67
+ * Registered callback function for the WordPress Importer
68
+ *
69
+ * Manages the three separate stages of the WXR import process
70
+ */
71
+ function dispatch() {
72
+ $this->header();
73
+
74
+ $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step'];
75
+ switch ( $step ) {
76
+ case 0:
77
+ $this->greet();
78
+ break;
79
+ case 1:
80
+ check_admin_referer( 'import-upload' );
81
+ if ( $this->handle_upload() )
82
+ $this->import_options();
83
+ break;
84
+ case 2:
85
+ check_admin_referer( 'import-wordpress' );
86
+ $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() );
87
+ $this->id = (int) $_POST['import_id'];
88
+ $file = get_attached_file( $this->id );
89
+ set_time_limit(0);
90
+ $this->import( $file );
91
+ break;
92
+ }
93
+
94
+ $this->footer();
95
+ }
96
+
97
+ /**
98
+ * The main controller for the actual import stage.
99
+ *
100
+ * @param string $file Path to the WXR file for importing
101
+ */
102
+ function import( $file ) {
103
+ add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) );
104
+ add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) );
105
+
106
+ $this->import_start( $file );
107
+
108
+ $this->get_author_mapping();
109
+
110
+ wp_suspend_cache_invalidation( true );
111
+ $this->process_categories();
112
+ $this->process_tags();
113
+ $this->process_terms();
114
+ $this->process_posts();
115
+ wp_suspend_cache_invalidation( false );
116
+
117
+ // update incorrect/missing information in the DB
118
+ $this->backfill_parents();
119
+ $this->backfill_attachment_urls();
120
+ $this->remap_featured_images();
121
+
122
+ $this->import_end();
123
+ }
124
+
125
+ /**
126
+ * Parses the WXR file and prepares us for the task of processing parsed data
127
+ *
128
+ * @param string $file Path to the WXR file for importing
129
+ */
130
+ function import_start( $file ) {
131
+ if ( ! is_file($file) ) {
132
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
133
+ echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '</p>';
134
+ $this->footer();
135
+ die();
136
+ }
137
+
138
+ $import_data = $this->parse( $file );
139
+
140
+ if ( is_wp_error( $import_data ) ) {
141
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
142
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
143
+ $this->footer();
144
+ die();
145
+ }
146
+
147
+ $this->version = $import_data['version'];
148
+ $this->get_authors_from_import( $import_data );
149
+ $this->posts = $import_data['posts'];
150
+ $this->terms = $import_data['terms'];
151
+ $this->categories = $import_data['categories'];
152
+ $this->tags = $import_data['tags'];
153
+ $this->base_url = esc_url( $import_data['base_url'] );
154
+
155
+ wp_defer_term_counting( true );
156
+ wp_defer_comment_counting( true );
157
+
158
+ do_action( 'import_start' );
159
+ }
160
+
161
+ /**
162
+ * Performs post-import cleanup of files and the cache
163
+ */
164
+ function import_end() {
165
+ wp_import_cleanup( $this->id );
166
+
167
+ wp_cache_flush();
168
+ foreach ( get_taxonomies() as $tax ) {
169
+ delete_option( "{$tax}_children" );
170
+ _get_term_hierarchy( $tax );
171
+ }
172
+
173
+ wp_defer_term_counting( false );
174
+ wp_defer_comment_counting( false );
175
+
176
+ echo '<p>' . __( 'All done.', 'wordpress-importer' ) . ' <a href="' . admin_url() . '">' . __( 'Have fun!', 'wordpress-importer' ) . '</a>' . '</p>';
177
+ echo '<p>' . __( 'Remember to update the passwords and roles of imported users.', 'wordpress-importer' ) . '</p>';
178
+
179
+ do_action( 'import_end' );
180
+ }
181
+
182
+ /**
183
+ * Handles the WXR upload and initial parsing of the file to prepare for
184
+ * displaying author import options
185
+ *
186
+ * @return bool False if error uploading or invalid file, true otherwise
187
+ */
188
+ function handle_upload() {
189
+ $file = wp_import_handle_upload();
190
+
191
+ if ( isset( $file['error'] ) ) {
192
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
193
+ echo esc_html( $file['error'] ) . '</p>';
194
+ return false;
195
+ } else if ( ! file_exists( $file['file'] ) ) {
196
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
197
+ printf( __( 'The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) );
198
+ echo '</p>';
199
+ return false;
200
+ }
201
+
202
+ $this->id = (int) $file['id'];
203
+ $import_data = $this->parse( $file['file'] );
204
+ if ( is_wp_error( $import_data ) ) {
205
+ echo '<p><strong>' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
206
+ echo esc_html( $import_data->get_error_message() ) . '</p>';
207
+ return false;
208
+ }
209
+
210
+ $this->version = $import_data['version'];
211
+ if ( $this->version > $this->max_wxr_version ) {
212
+ echo '<div class="error"><p><strong>';
213
+ printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html($import_data['version']) );
214
+ echo '</strong></p></div>';
215
+ }
216
+
217
+ $this->get_authors_from_import( $import_data );
218
+
219
+ return true;
220
+ }
221
+
222
+ /**
223
+ * Retrieve authors from parsed WXR data
224
+ *
225
+ * Uses the provided author information from WXR 1.1 files
226
+ * or extracts info from each post for WXR 1.0 files
227
+ *
228
+ * @param array $import_data Data returned by a WXR parser
229
+ */
230
+ function get_authors_from_import( $import_data ) {
231
+ if ( ! empty( $import_data['authors'] ) ) {
232
+ $this->authors = $import_data['authors'];
233
+ // no author information, grab it from the posts
234
+ } else {
235
+ foreach ( $import_data['posts'] as $post ) {
236
+ $login = sanitize_user( $post['post_author'], true );
237
+ if ( empty( $login ) ) {
238
+ printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) );
239
+ echo '<br />';
240
+ continue;
241
+ }
242
+
243
+ if ( ! isset($this->authors[$login]) )
244
+ $this->authors[$login] = array(
245
+ 'author_login' => $login,
246
+ 'author_display_name' => $post['post_author']
247
+ );
248
+ }
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Display pre-import options, author importing/mapping and option to
254
+ * fetch attachments
255
+ */
256
+ function import_options() {
257
+ $j = 0;
258
+ ?>
259
+ <form action="<?php echo admin_url( 'admin.php?import=wordpress&amp;step=2' ); ?>" method="post">
260
+ <?php wp_nonce_field( 'import-wordpress' ); ?>
261
+ <input type="hidden" name="import_id" value="<?php echo $this->id; ?>" />
262
+
263
+ <?php if ( ! empty( $this->authors ) ) : ?>
264
+ <h3><?php _e( 'Assign Authors', 'wordpress-importer' ); ?></h3>
265
+ <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.', 'wordpress-importer' ); ?></p>
266
+ <?php if ( $this->allow_create_users() ) : ?>
267
+ <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.', 'wordpress-importer' ), esc_html( get_option('default_role') ) ); ?></p>
268
+ <?php endif; ?>
269
+ <ol id="authors">
270
+ <?php foreach ( $this->authors as $author ) : ?>
271
+ <li><?php $this->author_select( $j++, $author ); ?></li>
272
+ <?php endforeach; ?>
273
+ </ol>
274
+ <?php endif; ?>
275
+
276
+ <?php if ( $this->allow_fetch_attachments() ) : ?>
277
+ <h3><?php _e( 'Import Attachments', 'wordpress-importer' ); ?></h3>
278
+ <p>
279
+ <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments" />
280
+ <label for="import-attachments"><?php _e( 'Download and import file attachments', 'wordpress-importer' ); ?></label>
281
+ </p>
282
+ <?php endif; ?>
283
+
284
+ <p class="submit"><input type="submit" class="button" value="<?php esc_attr_e( 'Submit', 'wordpress-importer' ); ?>" /></p>
285
+ </form>
286
+ <?php
287
+ }
288
+
289
+ /**
290
+ * Display import options for an individual author. That is, either create
291
+ * a new user based on import info or map to an existing user
292
+ *
293
+ * @param int $n Index for each author in the form
294
+ * @param array $author Author information, e.g. login, display name, email
295
+ */
296
+ function author_select( $n, $author ) {
297
+ _e( 'Import author:', 'wordpress-importer' );
298
+ echo ' <strong>' . esc_html( $author['author_display_name'] );
299
+ if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')';
300
+ echo '</strong><br />';
301
+
302
+ if ( $this->version != '1.0' )
303
+ echo '<div style="margin-left:18px">';
304
+
305
+ $create_users = $this->allow_create_users();
306
+ if ( $create_users ) {
307
+ if ( $this->version != '1.0' ) {
308
+ _e( 'or create new user with login name:', 'wordpress-importer' );
309
+ $value = '';
310
+ } else {
311
+ _e( 'as a new user:', 'wordpress-importer' );
312
+ $value = esc_attr( sanitize_user( $author['author_login'], true ) );
313
+ }
314
+
315
+ echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />';
316
+ }
317
+
318
+ if ( ! $create_users && $this->version == '1.0' )
319
+ _e( 'assign posts to an existing user:', 'wordpress-importer' );
320
+ else
321
+ _e( 'or assign posts to an existing user:', 'wordpress-importer' );
322
+ wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) );
323
+ echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />';
324
+
325
+ if ( $this->version != '1.0' )
326
+ echo '</div>';
327
+ }
328
+
329
+ /**
330
+ * Map old author logins to local user IDs based on decisions made
331
+ * in import options form. Can map to an existing user, create a new user
332
+ * or falls back to the current user in case of error with either of the previous
333
+ */
334
+ function get_author_mapping() {
335
+ if ( ! isset( $_POST['imported_authors'] ) )
336
+ return;
337
+
338
+ $create_users = $this->allow_create_users();
339
+
340
+ foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) {
341
+ // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
342
+ $santized_old_login = sanitize_user( $old_login, true );
343
+ $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
344
+
345
+ if ( ! empty( $_POST['user_map'][$i] ) ) {
346
+ $user = get_userdata( intval($_POST['user_map'][$i]) );
347
+ if ( isset( $user->ID ) ) {
348
+ if ( $old_id )
349
+ $this->processed_authors[$old_id] = $user->ID;
350
+ $this->author_mapping[$santized_old_login] = $user->ID;
351
+ }
352
+ } else if ( $create_users ) {
353
+ if ( ! empty($_POST['user_new'][$i]) ) {
354
+ $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
355
+ } else if ( $this->version != '1.0' ) {
356
+ $user_data = array(
357
+ 'user_login' => $old_login,
358
+ 'user_pass' => wp_generate_password(),
359
+ 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
360
+ 'display_name' => $this->authors[$old_login]['author_display_name'],
361
+ 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
362
+ 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
363
+ );
364
+ $user_id = wp_insert_user( $user_data );
365
+ }
366
+
367
+ if ( ! is_wp_error( $user_id ) ) {
368
+ if ( $old_id )
369
+ $this->processed_authors[$old_id] = $user_id;
370
+ $this->author_mapping[$santized_old_login] = $user_id;
371
+ } else {
372
+ printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
373
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
374
+ echo ' ' . $user_id->get_error_message();
375
+ echo '<br />';
376
+ }
377
+ }
378
+
379
+ // failsafe: if the user_id was invalid, default to the current user
380
+ if ( ! isset( $this->author_mapping[$santized_old_login] ) ) {
381
+ if ( $old_id )
382
+ $this->processed_authors[$old_id] = (int) get_current_user_id();
383
+ $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
384
+ }
385
+ }
386
+ }
387
+
388
+ /**
389
+ * Create new categories based on import information
390
+ *
391
+ * Doesn't create a new category if its slug already exists
392
+ */
393
+ function process_categories() {
394
+ $this->categories = apply_filters( 'wp_import_categories', $this->categories );
395
+
396
+ if ( empty( $this->categories ) )
397
+ return;
398
+
399
+ foreach ( $this->categories as $cat ) {
400
+ // if the category already exists leave it alone
401
+ $term_id = term_exists( $cat['category_nicename'], 'category' );
402
+ if ( $term_id ) {
403
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
404
+ if ( isset($cat['term_id']) )
405
+ $this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
406
+ continue;
407
+ }
408
+
409
+ $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
410
+ $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
411
+ $catarr = array(
412
+ 'category_nicename' => $cat['category_nicename'],
413
+ 'category_parent' => $category_parent,
414
+ 'cat_name' => $cat['cat_name'],
415
+ 'category_description' => $category_description
416
+ );
417
+ $catarr = wp_slash( $catarr );
418
+
419
+ $id = wp_insert_category( $catarr );
420
+ if ( ! is_wp_error( $id ) ) {
421
+ if ( isset($cat['term_id']) )
422
+ $this->processed_terms[intval($cat['term_id'])] = $id;
423
+ } else {
424
+ printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) );
425
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
426
+ echo ': ' . $id->get_error_message();
427
+ echo '<br />';
428
+ continue;
429
+ }
430
+
431
+ $this->process_termmeta( $cat, $id['term_id'] );
432
+ }
433
+
434
+ unset( $this->categories );
435
+ }
436
+
437
+ /**
438
+ * Create new post tags based on import information
439
+ *
440
+ * Doesn't create a tag if its slug already exists
441
+ */
442
+ function process_tags() {
443
+ $this->tags = apply_filters( 'wp_import_tags', $this->tags );
444
+
445
+ if ( empty( $this->tags ) )
446
+ return;
447
+
448
+ foreach ( $this->tags as $tag ) {
449
+ // if the tag already exists leave it alone
450
+ $term_id = term_exists( $tag['tag_slug'], 'post_tag' );
451
+ if ( $term_id ) {
452
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
453
+ if ( isset($tag['term_id']) )
454
+ $this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
455
+ continue;
456
+ }
457
+
458
+ $tag = wp_slash( $tag );
459
+ $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
460
+ $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
461
+
462
+ $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
463
+ if ( ! is_wp_error( $id ) ) {
464
+ if ( isset($tag['term_id']) )
465
+ $this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
466
+ } else {
467
+ printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) );
468
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
469
+ echo ': ' . $id->get_error_message();
470
+ echo '<br />';
471
+ continue;
472
+ }
473
+
474
+ $this->process_termmeta( $tag, $id['term_id'] );
475
+ }
476
+
477
+ unset( $this->tags );
478
+ }
479
+
480
+ /**
481
+ * Create new terms based on import information
482
+ *
483
+ * Doesn't create a term its slug already exists
484
+ */
485
+ function process_terms() {
486
+ $this->terms = apply_filters( 'wp_import_terms', $this->terms );
487
+
488
+ if ( empty( $this->terms ) )
489
+ return;
490
+
491
+ foreach ( $this->terms as $term ) {
492
+ // if the term already exists in the correct taxonomy leave it alone
493
+ $term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
494
+ if ( $term_id ) {
495
+ if ( is_array($term_id) ) $term_id = $term_id['term_id'];
496
+ if ( isset($term['term_id']) )
497
+ $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
498
+ continue;
499
+ }
500
+
501
+ if ( empty( $term['term_parent'] ) ) {
502
+ $parent = 0;
503
+ } else {
504
+ $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
505
+ if ( is_array( $parent ) ) $parent = $parent['term_id'];
506
+ }
507
+ $term = wp_slash( $term );
508
+ $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
509
+ $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
510
+
511
+ $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
512
+ if ( ! is_wp_error( $id ) ) {
513
+ if ( isset($term['term_id']) )
514
+ $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
515
+ } else {
516
+ printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) );
517
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
518
+ echo ': ' . $id->get_error_message();
519
+ echo '<br />';
520
+ continue;
521
+ }
522
+
523
+ $this->process_termmeta( $term, $id['term_id'] );
524
+ }
525
+
526
+ unset( $this->terms );
527
+ }
528
+
529
+ /**
530
+ * Add metadata to imported term.
531
+ *
532
+ * @since 0.6.2
533
+ *
534
+ * @param array $term Term data from WXR import.
535
+ * @param int $term_id ID of the newly created term.
536
+ */
537
+ protected function process_termmeta( $term, $term_id ) {
538
+ if ( ! isset( $term['termmeta'] ) ) {
539
+ $term['termmeta'] = array();
540
+ }
541
+
542
+ /**
543
+ * Filters the metadata attached to an imported term.
544
+ *
545
+ * @since 0.6.2
546
+ *
547
+ * @param array $termmeta Array of term meta.
548
+ * @param int $term_id ID of the newly created term.
549
+ * @param array $term Term data from the WXR import.
550
+ */
551
+ $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
552
+
553
+ if ( empty( $term['termmeta'] ) ) {
554
+ return;
555
+ }
556
+
557
+ foreach ( $term['termmeta'] as $meta ) {
558
+ /**
559
+ * Filters the meta key for an imported piece of term meta.
560
+ *
561
+ * @since 0.6.2
562
+ *
563
+ * @param string $meta_key Meta key.
564
+ * @param int $term_id ID of the newly created term.
565
+ * @param array $term Term data from the WXR import.
566
+ */
567
+ $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
568
+ if ( ! $key ) {
569
+ continue;
570
+ }
571
+
572
+ // Export gets meta straight from the DB so could have a serialized string
573
+ $value = maybe_unserialize( $meta['value'] );
574
+
575
+ add_term_meta( $term_id, $key, $value );
576
+
577
+ /**
578
+ * Fires after term meta is imported.
579
+ *
580
+ * @since 0.6.2
581
+ *
582
+ * @param int $term_id ID of the newly created term.
583
+ * @param string $key Meta key.
584
+ * @param mixed $value Meta value.
585
+ */
586
+ do_action( 'import_term_meta', $term_id, $key, $value );
587
+ }
588
+ }
589
+
590
+ /**
591
+ * Create new posts based on import information
592
+ *
593
+ * Posts marked as having a parent which doesn't exist will become top level items.
594
+ * Doesn't create a new post if: the post type doesn't exist, the given post ID
595
+ * is already noted as imported or a post with the same title and date already exists.
596
+ * Note that new/updated terms, comments and meta are imported for the last of the above.
597
+ */
598
+ function process_posts() {
599
+ $this->posts = apply_filters( 'wp_import_posts', $this->posts );
600
+
601
+ foreach ( $this->posts as $post ) {
602
+ $post = apply_filters( 'wp_import_post_data_raw', $post );
603
+
604
+ if ( ! post_type_exists( $post['post_type'] ) ) {
605
+ printf( __( 'Failed to import &#8220;%s&#8221;: Invalid post type %s', 'wordpress-importer' ),
606
+ esc_html($post['post_title']), esc_html($post['post_type']) );
607
+ echo '<br />';
608
+ do_action( 'wp_import_post_exists', $post );
609
+ continue;
610
+ }
611
+
612
+ if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) )
613
+ continue;
614
+
615
+ if ( $post['status'] == 'auto-draft' )
616
+ continue;
617
+
618
+ if ( 'nav_menu_item' == $post['post_type'] ) {
619
+ $this->process_menu_item( $post );
620
+ continue;
621
+ }
622
+
623
+ $post_type_object = get_post_type_object( $post['post_type'] );
624
+
625
+ $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
626
+
627
+ /**
628
+ * Filter ID of the existing post corresponding to post currently importing.
629
+ *
630
+ * Return 0 to force the post to be imported. Filter the ID to be something else
631
+ * to override which existing post is mapped to the imported post.
632
+ *
633
+ * @see post_exists()
634
+ * @since 0.6.2
635
+ *
636
+ * @param int $post_exists Post ID, or 0 if post did not exist.
637
+ * @param array $post The post array to be inserted.
638
+ */
639
+ $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
640
+
641
+ if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) {
642
+ printf( __('%s &#8220;%s&#8221; already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) );
643
+ echo '<br />';
644
+ $comment_post_ID = $post_id = $post_exists;
645
+ $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
646
+ } else {
647
+ $post_parent = (int) $post['post_parent'];
648
+ if ( $post_parent ) {
649
+ // if we already know the parent, map it to the new local ID
650
+ if ( isset( $this->processed_posts[$post_parent] ) ) {
651
+ $post_parent = $this->processed_posts[$post_parent];
652
+ // otherwise record the parent for later
653
+ } else {
654
+ $this->post_orphans[intval($post['post_id'])] = $post_parent;
655
+ $post_parent = 0;
656
+ }
657
+ }
658
+
659
+ // map the post author
660
+ $author = sanitize_user( $post['post_author'], true );
661
+ if ( isset( $this->author_mapping[$author] ) )
662
+ $author = $this->author_mapping[$author];
663
+ else
664
+ $author = (int) get_current_user_id();
665
+
666
+ $postdata = array(
667
+ 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
668
+ 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
669
+ 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
670
+ 'post_status' => $post['status'], 'post_name' => $post['post_name'],
671
+ 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
672
+ 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
673
+ 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
674
+ );
675
+
676
+ $original_post_ID = $post['post_id'];
677
+ $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
678
+
679
+ $postdata = wp_slash( $postdata );
680
+
681
+ if ( 'attachment' == $postdata['post_type'] ) {
682
+ $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
683
+
684
+ // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
685
+ // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
686
+ $postdata['upload_date'] = $post['post_date'];
687
+ if ( isset( $post['postmeta'] ) ) {
688
+ foreach( $post['postmeta'] as $meta ) {
689
+ if ( $meta['key'] == '_wp_attached_file' ) {
690
+ if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
691
+ $postdata['upload_date'] = $matches[0];
692
+ break;
693
+ }
694
+ }
695
+ }
696
+
697
+ $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url );
698
+ } else {
699
+ $comment_post_ID = $post_id = wp_insert_post( $postdata, true );
700
+ do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
701
+ }
702
+
703
+ if ( is_wp_error( $post_id ) ) {
704
+ printf( __( 'Failed to import %s &#8220;%s&#8221;', 'wordpress-importer' ),
705
+ $post_type_object->labels->singular_name, esc_html($post['post_title']) );
706
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
707
+ echo ': ' . $post_id->get_error_message();
708
+ echo '<br />';
709
+ continue;
710
+ }
711
+
712
+ if ( $post['is_sticky'] == 1 )
713
+ stick_post( $post_id );
714
+ }
715
+
716
+ // map pre-import ID to local ID
717
+ $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
718
+
719
+ if ( ! isset( $post['terms'] ) )
720
+ $post['terms'] = array();
721
+
722
+ $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
723
+
724
+ // add categories, tags and other terms
725
+ if ( ! empty( $post['terms'] ) ) {
726
+ $terms_to_set = array();
727
+ foreach ( $post['terms'] as $term ) {
728
+ // back compat with WXR 1.0 map 'tag' to 'post_tag'
729
+ $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain'];
730
+ $term_exists = term_exists( $term['slug'], $taxonomy );
731
+ $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
732
+ if ( ! $term_id ) {
733
+ $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
734
+ if ( ! is_wp_error( $t ) ) {
735
+ $term_id = $t['term_id'];
736
+ do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
737
+ } else {
738
+ printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) );
739
+ if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
740
+ echo ': ' . $t->get_error_message();
741
+ echo '<br />';
742
+ do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post );
743
+ continue;
744
+ }
745
+ }
746
+ $terms_to_set[$taxonomy][] = intval( $term_id );
747
+ }
748
+
749
+ foreach ( $terms_to_set as $tax => $ids ) {
750
+ $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
751
+ do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
752
+ }
753
+ unset( $post['terms'], $terms_to_set );
754
+ }
755
+
756
+ if ( ! isset( $post['comments'] ) )
757
+ $post['comments'] = array();
758
+
759
+ $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
760
+
761
+ // add/update comments
762
+ if ( ! empty( $post['comments'] ) ) {
763
+ $num_comments = 0;
764
+ $inserted_comments = array();
765
+ foreach ( $post['comments'] as $comment ) {
766
+ $comment_id = $comment['comment_id'];
767
+ $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
768
+ $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
769
+ $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
770
+ $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
771
+ $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
772
+ $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
773
+ $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
774
+ $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
775
+ $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
776
+ $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
777
+ $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
778
+ $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
779
+ if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
780
+ $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
781
+ }
782
+ ksort( $newcomments );
783
+
784
+ foreach ( $newcomments as $key => $comment ) {
785
+ // if this is a new post we can skip the comment_exists() check
786
+ if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) {
787
+ if ( isset( $inserted_comments[$comment['comment_parent']] ) )
788
+ $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
789
+ $comment = wp_filter_comment( $comment );
790
+ $inserted_comments[$key] = wp_insert_comment( $comment );
791
+ do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
792
+
793
+ foreach( $comment['commentmeta'] as $meta ) {
794
+ $value = maybe_unserialize( $meta['value'] );
795
+ add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
796
+ }
797
+
798
+ $num_comments++;
799
+ }
800
+ }
801
+ unset( $newcomments, $inserted_comments, $post['comments'] );
802
+ }
803
+
804
+ if ( ! isset( $post['postmeta'] ) )
805
+ $post['postmeta'] = array();
806
+
807
+ $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
808
+
809
+ // add/update post meta
810
+ if ( ! empty( $post['postmeta'] ) ) {
811
+ foreach ( $post['postmeta'] as $meta ) {
812
+ $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
813
+ $value = false;
814
+
815
+ if ( '_edit_last' == $key ) {
816
+ if ( isset( $this->processed_authors[intval($meta['value'])] ) )
817
+ $value = $this->processed_authors[intval($meta['value'])];
818
+ else
819
+ $key = false;
820
+ }
821
+
822
+ if ( $key ) {
823
+ // export gets meta straight from the DB so could have a serialized string
824
+ if ( ! $value )
825
+ $value = maybe_unserialize( $meta['value'] );
826
+
827
+ add_post_meta( $post_id, $key, $value );
828
+ do_action( 'import_post_meta', $post_id, $key, $value );
829
+
830
+ // if the post has a featured image, take note of this in case of remap
831
+ if ( '_thumbnail_id' == $key )
832
+ $this->featured_images[$post_id] = (int) $value;
833
+ }
834
+ }
835
+ }
836
+ }
837
+
838
+ unset( $this->posts );
839
+ }
840
+
841
+ /**
842
+ * Attempt to create a new menu item from import data
843
+ *
844
+ * Fails for draft, orphaned menu items and those without an associated nav_menu
845
+ * or an invalid nav_menu term. If the post type or term object which the menu item
846
+ * represents doesn't exist then the menu item will not be imported (waits until the
847
+ * end of the import to retry again before discarding).
848
+ *
849
+ * @param array $item Menu item details from WXR file
850
+ */
851
+ function process_menu_item( $item ) {
852
+ // skip draft, orphaned menu items
853
+ if ( 'draft' == $item['status'] )
854
+ return;
855
+
856
+ $menu_slug = false;
857
+ if ( isset($item['terms']) ) {
858
+ // loop through terms, assume first nav_menu term is correct menu
859
+ foreach ( $item['terms'] as $term ) {
860
+ if ( 'nav_menu' == $term['domain'] ) {
861
+ $menu_slug = $term['slug'];
862
+ break;
863
+ }
864
+ }
865
+ }
866
+
867
+ // no nav_menu term associated with this menu item
868
+ if ( ! $menu_slug ) {
869
+ _e( 'Menu item skipped due to missing menu slug', 'wordpress-importer' );
870
+ echo '<br />';
871
+ return;
872
+ }
873
+
874
+ $menu_id = term_exists( $menu_slug, 'nav_menu' );
875
+ if ( ! $menu_id ) {
876
+ printf( __( 'Menu item skipped due to invalid menu slug: %s', 'wordpress-importer' ), esc_html( $menu_slug ) );
877
+ echo '<br />';
878
+ return;
879
+ } else {
880
+ $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id;
881
+ }
882
+
883
+ foreach ( $item['postmeta'] as $meta )
884
+ $$meta['key'] = $meta['value'];
885
+
886
+ if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) {
887
+ $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)];
888
+ } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval($_menu_item_object_id)] ) ) {
889
+ $_menu_item_object_id = $this->processed_posts[intval($_menu_item_object_id)];
890
+ } else if ( 'custom' != $_menu_item_type ) {
891
+ // associated object is missing or not imported yet, we'll retry later
892
+ $this->missing_menu_items[] = $item;
893
+ return;
894
+ }
895
+
896
+ if ( isset( $this->processed_menu_items[intval($_menu_item_menu_item_parent)] ) ) {
897
+ $_menu_item_menu_item_parent = $this->processed_menu_items[intval($_menu_item_menu_item_parent)];
898
+ } else if ( $_menu_item_menu_item_parent ) {
899
+ $this->menu_item_orphans[intval($item['post_id'])] = (int) $_menu_item_menu_item_parent;
900
+ $_menu_item_menu_item_parent = 0;
901
+ }
902
+
903
+ // wp_update_nav_menu_item expects CSS classes as a space separated string
904
+ $_menu_item_classes = maybe_unserialize( $_menu_item_classes );
905
+ if ( is_array( $_menu_item_classes ) )
906
+ $_menu_item_classes = implode( ' ', $_menu_item_classes );
907
+
908
+ $args = array(
909
+ 'menu-item-object-id' => $_menu_item_object_id,
910
+ 'menu-item-object' => $_menu_item_object,
911
+ 'menu-item-parent-id' => $_menu_item_menu_item_parent,
912
+ 'menu-item-position' => intval( $item['menu_order'] ),
913
+ 'menu-item-type' => $_menu_item_type,
914
+ 'menu-item-title' => $item['post_title'],
915
+ 'menu-item-url' => $_menu_item_url,
916
+ 'menu-item-description' => $item['post_content'],
917
+ 'menu-item-attr-title' => $item['post_excerpt'],
918
+ 'menu-item-target' => $_menu_item_target,
919
+ 'menu-item-classes' => $_menu_item_classes,
920
+ 'menu-item-xfn' => $_menu_item_xfn,
921
+ 'menu-item-status' => $item['status']
922
+ );
923
+
924
+ $id = wp_update_nav_menu_item( $menu_id, 0, $args );
925
+
926
+ // Make sure all custom menu fields are imported correctly
927
+ if ( ! $args['menu-item-parent-id'] ) {
928
+ $field_name_suffix = array( 'nolink', 'category_post', 'megamenu', 'megamenu_auto_width', 'megamenu_col', 'megamenu_heading', 'icon' );
929
+ } else {
930
+ $field_name_suffix = array( 'nolink', 'category_post', 'icon', 'megamenu_widgetarea' );
931
+ }
932
+
933
+ foreach ( $field_name_suffix as $suffix ) {
934
+ $key = '_menu_item_' . $suffix;
935
+ if ( isset( $$key ) ) {
936
+ update_post_meta( $id, '_menu_item_' . $suffix , $$key );
937
+ }
938
+ }
939
+
940
+ if ( $id && ! is_wp_error( $id ) )
941
+ $this->processed_menu_items[intval($item['post_id'])] = (int) $id;
942
+ }
943
+
944
+ /**
945
+ * If fetching attachments is enabled then attempt to create a new attachment
946
+ *
947
+ * @param array $post Attachment post details from WXR
948
+ * @param string $url URL to fetch attachment from
949
+ * @return int|WP_Error Post ID on success, WP_Error otherwise
950
+ */
951
+ function process_attachment( $post, $url ) {
952
+ if ( ! $this->fetch_attachments )
953
+ return new WP_Error( 'attachment_processing_error',
954
+ __( 'Fetching attachments is not enabled', 'wordpress-importer' ) );
955
+
956
+ // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
957
+ if ( preg_match( '|^/[\w\W]+$|', $url ) )
958
+ $url = rtrim( $this->base_url, '/' ) . $url;
959
+
960
+ $upload = $this->fetch_remote_file( $url, $post );
961
+ if ( is_wp_error( $upload ) )
962
+ return $upload;
963
+
964
+ if ( $info = wp_check_filetype( $upload['file'] ) )
965
+ $post['post_mime_type'] = $info['type'];
966
+ else
967
+ return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') );
968
+
969
+ $post['guid'] = $upload['url'];
970
+
971
+ // as per wp-admin/includes/upload.php
972
+ $post_id = wp_insert_attachment( $post, $upload['file'] );
973
+ wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
974
+
975
+ // remap resized image URLs, works by stripping the extension and remapping the URL stub.
976
+ if ( preg_match( '!^image/!', $info['type'] ) ) {
977
+ $parts = pathinfo( $url );
978
+ $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
979
+
980
+ $parts_new = pathinfo( $upload['url'] );
981
+ $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
982
+
983
+ $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
984
+ }
985
+
986
+ return $post_id;
987
+ }
988
+
989
+ /**
990
+ * Attempt to download a remote file attachment
991
+ *
992
+ * @param string $url URL of item to fetch
993
+ * @param array $post Attachment details
994
+ * @return array|WP_Error Local file location details on success, WP_Error otherwise
995
+ */
996
+ function fetch_remote_file( $url, $post ) {
997
+ // extract the file name and extension from the url
998
+ $file_name = basename( $url );
999
+
1000
+ // get placeholder file in the upload dir with a unique, sanitized filename
1001
+ $upload = wp_upload_bits( $file_name, 0, '', $post['upload_date'] );
1002
+ if ( $upload['error'] )
1003
+ return new WP_Error( 'upload_dir_error', $upload['error'] );
1004
+
1005
+ // fetch the remote url and write it to the placeholder file
1006
+ $headers = ODI_Helpers::odi_wp_get_http( $url, $upload['file'] );
1007
+
1008
+ // request failed
1009
+ if ( ! $headers ) {
1010
+ @unlink( $upload['file'] );
1011
+ return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') );
1012
+ }
1013
+
1014
+ // make sure the fetch was successful
1015
+ if ( $headers['response'] != '200' ) {
1016
+ @unlink( $upload['file'] );
1017
+ return new WP_Error( 'import_file_error', sprintf( __('Remote server returned error response %1$d %2$s', 'wordpress-importer'), esc_html($headers['response']), get_status_header_desc($headers['response']) ) );
1018
+ }
1019
+
1020
+ $filesize = filesize( $upload['file'] );
1021
+
1022
+ if ( isset( $headers['content-length'] ) && $filesize != $headers['content-length'] ) {
1023
+ @unlink( $upload['file'] );
1024
+ return new WP_Error( 'import_file_error', __('Remote file is incorrect size', 'wordpress-importer') );
1025
+ }
1026
+
1027
+ if ( 0 == $filesize ) {
1028
+ @unlink( $upload['file'] );
1029
+ return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') );
1030
+ }
1031
+
1032
+ $max_size = (int) $this->max_attachment_size();
1033
+ if ( ! empty( $max_size ) && $filesize > $max_size ) {
1034
+ @unlink( $upload['file'] );
1035
+ return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer'), size_format($max_size) ) );
1036
+ }
1037
+
1038
+ // keep track of the old and new urls so we can substitute them later
1039
+ $this->url_remap[$url] = $upload['url'];
1040
+ $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed?
1041
+ // keep track of the destination if the remote url is redirected somewhere else
1042
+ if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url )
1043
+ $this->url_remap[$headers['x-final-location']] = $upload['url'];
1044
+
1045
+ return $upload;
1046
+ }
1047
+
1048
+ /**
1049
+ * Attempt to associate posts and menu items with previously missing parents
1050
+ *
1051
+ * An imported post's parent may not have been imported when it was first created
1052
+ * so try again. Similarly for child menu items and menu items which were missing
1053
+ * the object (e.g. post) they represent in the menu
1054
+ */
1055
+ function backfill_parents() {
1056
+ global $wpdb;
1057
+
1058
+ // find parents for post orphans
1059
+ foreach ( $this->post_orphans as $child_id => $parent_id ) {
1060
+ $local_child_id = $local_parent_id = false;
1061
+ if ( isset( $this->processed_posts[$child_id] ) )
1062
+ $local_child_id = $this->processed_posts[$child_id];
1063
+ if ( isset( $this->processed_posts[$parent_id] ) )
1064
+ $local_parent_id = $this->processed_posts[$parent_id];
1065
+
1066
+ if ( $local_child_id && $local_parent_id )
1067
+ $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' );
1068
+ }
1069
+
1070
+ // all other posts/terms are imported, retry menu items with missing associated object
1071
+ $missing_menu_items = $this->missing_menu_items;
1072
+ foreach ( $missing_menu_items as $item )
1073
+ $this->process_menu_item( $item );
1074
+
1075
+ // find parents for menu item orphans
1076
+ foreach ( $this->menu_item_orphans as $child_id => $parent_id ) {
1077
+ $local_child_id = $local_parent_id = 0;
1078
+ if ( isset( $this->processed_menu_items[$child_id] ) )
1079
+ $local_child_id = $this->processed_menu_items[$child_id];
1080
+ if ( isset( $this->processed_menu_items[$parent_id] ) )
1081
+ $local_parent_id = $this->processed_menu_items[$parent_id];
1082
+
1083
+ if ( $local_child_id && $local_parent_id )
1084
+ update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id );
1085
+ }
1086
+ }
1087
+
1088
+ /**
1089
+ * Use stored mapping information to update old attachment URLs
1090
+ */
1091
+ function backfill_attachment_urls() {
1092
+ global $wpdb;
1093
+ // make sure we do the longest urls first, in case one is a substring of another
1094
+ uksort( $this->url_remap, array(&$this, 'cmpr_strlen') );
1095
+
1096
+ foreach ( $this->url_remap as $from_url => $to_url ) {
1097
+ // remap urls in post_content
1098
+ $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) );
1099
+ // remap enclosure urls
1100
+ $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) );
1101
+ }
1102
+ }
1103
+
1104
+ /**
1105
+ * Update _thumbnail_id meta to new, imported attachment IDs
1106
+ */
1107
+ function remap_featured_images() {
1108
+ // cycle through posts that have a featured image
1109
+ foreach ( $this->featured_images as $post_id => $value ) {
1110
+ if ( isset( $this->processed_posts[$value] ) ) {
1111
+ $new_id = $this->processed_posts[$value];
1112
+ // only update if there's a difference
1113
+ if ( $new_id != $value )
1114
+ update_post_meta( $post_id, '_thumbnail_id', $new_id );
1115
+ }
1116
+ }
1117
+ }
1118
+
1119
+ /**
1120
+ * Parse a WXR file
1121
+ *
1122
+ * @param string $file Path to WXR file for parsing
1123
+ * @return array Information gathered from the WXR file
1124
+ */
1125
+ function parse( $file ) {
1126
+ $parser = new WXR_Parser();
1127
+ return $parser->parse( $file );
1128
+ }
1129
+
1130
+ // Display import page title
1131
+ function header() {
1132
+ echo '<div class="wrap">';
1133
+ screen_icon();
1134
+ echo '<h2>' . __( 'Import WordPress', 'wordpress-importer' ) . '</h2>';
1135
+
1136
+ $updates = get_plugin_updates();
1137
+ $basename = plugin_basename(__FILE__);
1138
+ if ( isset( $updates[$basename] ) ) {
1139
+ $update = $updates[$basename];
1140
+ echo '<div class="error"><p><strong>';
1141
+ printf( __( 'A new version of this importer is available. Please update to version %s to ensure compatibility with newer export files.', 'wordpress-importer' ), $update->update->new_version );
1142
+ echo '</strong></p></div>';
1143
+ }
1144
+ }
1145
+
1146
+ // Close div.wrap
1147
+ function footer() {
1148
+ echo '</div>';
1149
+ }
1150
+
1151
+ /**
1152
+ * Display introductory text and file upload form
1153
+ */
1154
+ function greet() {
1155
+ echo '<div class="narrow">';
1156
+ 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.', 'wordpress-importer' ).'</p>';
1157
+ echo '<p>'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'</p>';
1158
+ wp_import_upload_form( 'admin.php?import=wordpress&amp;step=1' );
1159
+ echo '</div>';
1160
+ }
1161
+
1162
+ /**
1163
+ * Decide if the given meta key maps to information we will want to import
1164
+ *
1165
+ * @param string $key The meta key to check
1166
+ * @return string|bool The key if we do want to import, false if not
1167
+ */
1168
+ function is_valid_meta_key( $key ) {
1169
+ // skip attachment metadata since we'll regenerate it from scratch
1170
+ // skip _edit_lock as not relevant for import
1171
+ if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) )
1172
+ return false;
1173
+ return $key;
1174
+ }
1175
+
1176
+ /**
1177
+ * Decide whether or not the importer is allowed to create users.
1178
+ * Default is true, can be filtered via import_allow_create_users
1179
+ *
1180
+ * @return bool True if creating users is allowed
1181
+ */
1182
+ function allow_create_users() {
1183
+ return apply_filters( 'import_allow_create_users', true );
1184
+ }
1185
+
1186
+ /**
1187
+ * Decide whether or not the importer should attempt to download attachment files.
1188
+ * Default is true, can be filtered via import_allow_fetch_attachments. The choice
1189
+ * made at the import options screen must also be true, false here hides that checkbox.
1190
+ *
1191
+ * @return bool True if downloading attachments is allowed
1192
+ */
1193
+ function allow_fetch_attachments() {
1194
+ return apply_filters( 'import_allow_fetch_attachments', true );
1195
+ }
1196
+
1197
+ /**
1198
+ * Decide what the maximum file size for downloaded attachments is.
1199
+ * Default is 0 (unlimited), can be filtered via import_attachment_size_limit
1200
+ *
1201
+ * @return int Maximum attachment file size to import
1202
+ */
1203
+ function max_attachment_size() {
1204
+ return apply_filters( 'import_attachment_size_limit', 0 );
1205
+ }
1206
+
1207
+ /**
1208
+ * Added to http_request_timeout filter to force timeout at 60 seconds during import
1209
+ * @return int 60
1210
+ */
1211
+ function bump_request_timeout( $val ) {
1212
+ return 60;
1213
+ }
1214
+
1215
+ // return the difference in length between two strings
1216
+ function cmpr_strlen( $a, $b ) {
1217
+ return strlen($b) - strlen($a);
1218
+ }
1219
+ }
1220
+
1221
+ } // class_exists( 'WP_Importer' )
includes/importer.php ADDED
@@ -0,0 +1,513 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Importer function
4
+ */
5
+
6
+ // Exit if accessed directly
7
+ if ( ! defined( 'ABSPATH' ) ) {
8
+ exit;
9
+ }
10
+
11
+ /**
12
+ * The importer class.
13
+ */
14
+ class ODI_Importer {
15
+
16
+ /**
17
+ * Class Constructor
18
+ *
19
+ * @since 1.0.0
20
+ */
21
+ public function __construct() {
22
+ add_action( 'admin_init', array( $this, 'init' ) );
23
+ add_filter( 'upload_mimes', array( $this, 'allow_xml_uploads' ) );
24
+ }
25
+
26
+ /**
27
+ * Register the AJAX method
28
+ *
29
+ * @since 1.0.0
30
+ */
31
+ public function init() {
32
+ add_action( 'wp_ajax_ocean_import_demo_data', array( $this, 'ocean_importer' ) );
33
+ }
34
+
35
+ /**
36
+ * Return data
37
+ *
38
+ * @since 1.0.0
39
+ */
40
+ public static function get_data() {
41
+
42
+ // Demos url
43
+ $url = 'https://raw.githubusercontent.com/oceanwp/ocean-sample-data/master/';
44
+
45
+ $data = array(
46
+
47
+ 'architect' => array(
48
+ 'xml_file' => $url . 'architect/sample-data.xml',
49
+ 'theme_settings' => $url . 'architect/ocean-export.json',
50
+ 'widgets_file' => $url . 'architect/widgets.wie',
51
+ 'home_title' => 'Home',
52
+ 'blog_title' => 'Blog',
53
+ 'posts_to_show' => '3',
54
+ 'elementor_width' => '1220',
55
+ 'is_shop' => false,
56
+ ),
57
+
58
+ 'blogger' => array(
59
+ 'xml_file' => $url . 'blogger/sample-data.xml',
60
+ 'theme_settings' => $url . 'blogger/ocean-export.json',
61
+ 'widgets_file' => $url . 'blogger/widgets.wie',
62
+ 'home_title' => '',
63
+ 'blog_title' => 'Home',
64
+ 'posts_to_show' => '12',
65
+ 'is_shop' => false,
66
+ ),
67
+
68
+ 'coach' => array(
69
+ 'xml_file' => $url . 'coach/sample-data.xml',
70
+ 'theme_settings' => $url . 'coach/ocean-export.json',
71
+ 'widgets_file' => $url . 'coach/widgets.wie',
72
+ 'home_title' => 'Home',
73
+ 'blog_title' => 'Blog',
74
+ 'posts_to_show' => '3',
75
+ 'is_shop' => false,
76
+ ),
77
+
78
+ 'gym' => array(
79
+ 'xml_file' => $url . 'gym/sample-data.xml',
80
+ 'theme_settings' => $url . 'gym/ocean-export.json',
81
+ 'widgets_file' => $url . 'gym/widgets.wie',
82
+ 'home_title' => 'Home',
83
+ 'blog_title' => 'News',
84
+ 'posts_to_show' => '3',
85
+ 'elementor_width' => '1100',
86
+ 'is_shop' => false,
87
+ ),
88
+
89
+ 'lawyer' => array(
90
+ 'xml_file' => $url . 'lawyer/sample-data.xml',
91
+ 'theme_settings' => $url . 'lawyer/ocean-export.json',
92
+ 'widgets_file' => $url . 'lawyer/widgets.wie',
93
+ 'home_title' => 'Home',
94
+ 'blog_title' => 'Blog',
95
+ 'posts_to_show' => '3',
96
+ 'elementor_width' => '1220',
97
+ 'is_shop' => false,
98
+ ),
99
+
100
+ 'megagym' => array(
101
+ 'xml_file' => $url . 'megagym/sample-data.xml',
102
+ 'theme_settings' => $url . 'megagym/ocean-export.json',
103
+ 'widgets_file' => $url . 'megagym/widgets.wie',
104
+ 'home_title' => 'Home',
105
+ 'blog_title' => 'Blog',
106
+ 'posts_to_show' => '3',
107
+ 'is_shop' => false,
108
+ ),
109
+
110
+ 'personal' => array(
111
+ 'xml_file' => $url . 'personal/sample-data.xml',
112
+ 'theme_settings' => $url . 'personal/ocean-export.json',
113
+ 'widgets_file' => $url . 'personal/widgets.wie',
114
+ 'home_title' => '',
115
+ 'blog_title' => 'Home',
116
+ 'posts_to_show' => '3',
117
+ 'is_shop' => false,
118
+ ),
119
+
120
+ 'store' => array(
121
+ 'xml_file' => $url . 'store/sample-data.xml',
122
+ 'theme_settings' => $url . 'store/ocean-export.json',
123
+ 'widgets_file' => $url . 'store/widgets.wie',
124
+ 'home_title' => 'Home',
125
+ 'blog_title' => 'Blog',
126
+ 'posts_to_show' => '3',
127
+ 'elementor_width' => '1220',
128
+ 'is_shop' => true,
129
+ 'catalog_img' => array(
130
+ 'width' => '265',
131
+ 'height' => '354',
132
+ ),
133
+ 'single_img' => array(
134
+ 'width' => '504',
135
+ 'height' => '674',
136
+ ),
137
+ 'thumbnails_img' => array(
138
+ 'width' => '93',
139
+ 'height' => '120',
140
+ ),
141
+ ),
142
+
143
+ 'stylish' => array(
144
+ 'xml_file' => $url . 'stylish/sample-data.xml',
145
+ 'theme_settings' => $url . 'stylish/ocean-export.json',
146
+ 'widgets_file' => $url . 'stylish/widgets.wie',
147
+ 'home_title' => 'Home',
148
+ 'blog_title' => 'Blog',
149
+ 'posts_to_show' => '12',
150
+ 'elementor_width' => '1420',
151
+ 'is_shop' => false,
152
+ ),
153
+
154
+ 'travel' => array(
155
+ 'xml_file' => $url . 'travel/sample-data.xml',
156
+ 'theme_settings' => $url . 'travel/ocean-export.json',
157
+ 'widgets_file' => $url . 'travel/widgets.wie',
158
+ 'home_title' => 'Home',
159
+ 'blog_title' => 'Blog',
160
+ 'posts_to_show' => '4',
161
+ 'elementor_width' => '1220',
162
+ 'is_shop' => false,
163
+ ),
164
+
165
+ 'underwear' => array(
166
+ 'xml_file' => $url . 'underwear/sample-data.xml',
167
+ 'theme_settings' => $url . 'underwear/ocean-export.json',
168
+ 'widgets_file' => $url . 'underwear/widgets.wie',
169
+ 'home_title' => 'Home',
170
+ 'blog_title' => 'Blog',
171
+ 'posts_to_show' => '3',
172
+ 'elementor_width' => '1220',
173
+ 'is_shop' => true,
174
+ 'catalog_img' => array(
175
+ 'width' => '265',
176
+ 'height' => '352',
177
+ ),
178
+ 'single_img' => array(
179
+ 'width' => '433',
180
+ 'height' => '578',
181
+ ),
182
+ 'thumbnails_img' => array(
183
+ 'width' => '90',
184
+ 'height' => '120',
185
+ ),
186
+ ),
187
+
188
+ 'yoga' => array(
189
+ 'xml_file' => $url . 'yoga/sample-data.xml',
190
+ 'theme_settings' => $url . 'yoga/ocean-export.json',
191
+ 'widgets_file' => $url . 'yoga/widgets.wie',
192
+ 'home_title' => 'Home',
193
+ 'blog_title' => 'Blog',
194
+ 'posts_to_show' => '3',
195
+ 'is_shop' => false,
196
+ ),
197
+
198
+ );
199
+
200
+ // Return
201
+ return $data;
202
+
203
+ }
204
+
205
+ /**
206
+ * Allows xml uploads so we can import from github
207
+ *
208
+ * @since 1.0.0
209
+ */
210
+ public function allow_xml_uploads( $mimes ) {
211
+ $mimes = array_merge( $mimes, array(
212
+ 'xml' => 'application/xml'
213
+ ) );
214
+ return $mimes;
215
+ }
216
+
217
+ /**
218
+ * Importer
219
+ *
220
+ * @since 1.0.0
221
+ */
222
+ public function ocean_importer() {
223
+
224
+ // Include settings importer
225
+ include ODI_PATH . 'includes/class/class-settings-importer.php';
226
+
227
+ // Include widgets importer
228
+ include ODI_PATH . 'includes/class/class-widget-importer.php';
229
+
230
+ if ( current_user_can( 'manage_options' ) ) {
231
+
232
+ if ( ! isset( $_POST['demo_type'] ) || '' == trim( $_POST['demo_type'] ) ) {
233
+ $demo_type = 'architect';
234
+ } else {
235
+ $demo_type = $_POST['demo_type'];
236
+ }
237
+
238
+ // Get demo data
239
+ $demo = self::get_data()[ $demo_type ];
240
+
241
+ // Content file
242
+ $xml_file = isset ( $demo['xml_file'] ) ? $demo['xml_file'] : '';
243
+
244
+ // Settings file
245
+ $theme_settings = isset ( $demo['theme_settings'] ) ? $demo['theme_settings'] : '';
246
+
247
+ // Widgets file
248
+ $widgets_file = isset ( $demo['widgets_file'] ) ? $demo['widgets_file'] : '';
249
+
250
+ // Elementor width setting
251
+ if ( $demo['elementor_width'] ) {
252
+ $elementor_width = isset ( $demo['elementor_width'] ) ? $demo['elementor_width'] : '';
253
+ }
254
+
255
+ // Reading settings
256
+ $homepage_title = isset ( $demo['home_title'] ) ? $demo['home_title'] : 'Home';
257
+ $blog_title = isset ( $demo['blog_title'] ) ? $demo['blog_title'] : 'Blog';
258
+
259
+ // Posts to show on the blog page
260
+ $posts_to_show = isset ( $demo['posts_to_show'] ) ? $demo['posts_to_show'] : '';
261
+
262
+ // If shop demo
263
+ $shop_demo = isset ( $demo['is_shop'] ) ? $demo['is_shop'] : false;
264
+
265
+ // Woo catalog images sizes
266
+ $catalog_img = isset ( $demo['catalog_img'] ) ? $demo['catalog_img'] : '';
267
+ $c_width = isset ( $catalog_img['width'] ) ? $catalog_img['width'] : '';
268
+ $c_height = isset ( $catalog_img['height'] ) ? $catalog_img['height'] : '';
269
+
270
+ // Woo single product image sizes
271
+ $single_img = isset ( $demo['single_img'] ) ? $demo['single_img'] : '';
272
+ $s_width = isset ( $single_img['width'] ) ? $single_img['width'] : '';
273
+ $s_height = isset ( $single_img['height'] ) ? $single_img['height'] : '';
274
+
275
+ // Woo product thumbnails images sizes
276
+ $thumbnails_img = isset ( $demo['thumbnails_img'] ) ? $demo['thumbnails_img'] : '';
277
+ $t_width = isset ( $thumbnails_img['width'] ) ? $thumbnails_img['width'] : '';
278
+ $t_height = isset ( $thumbnails_img['height'] ) ? $thumbnails_img['height'] : '';
279
+
280
+ // Import Posts, Pages, Images, Menus.
281
+ $this->process_xml( $xml_file );
282
+
283
+ // Assign WooCommerce pages if WooCommerce Exists
284
+ if ( class_exists( 'WooCommerce' ) && $shop_demo ) {
285
+
286
+ $woopages = array(
287
+ 'woocommerce_shop_page_id' => 'Shop',
288
+ 'woocommerce_cart_page_id' => 'Cart',
289
+ 'woocommerce_checkout_page_id' => 'Checkout',
290
+ 'woocommerce_pay_page_id' => 'Checkout &#8594; Pay',
291
+ 'woocommerce_thanks_page_id' => 'Order Received',
292
+ 'woocommerce_myaccount_page_id' => 'My Account',
293
+ 'woocommerce_edit_address_page_id' => 'Edit My Address',
294
+ 'woocommerce_view_order_page_id' => 'View Order',
295
+ 'woocommerce_change_password_page_id' => 'Change Password',
296
+ 'woocommerce_logout_page_id' => 'Logout',
297
+ 'woocommerce_lost_password_page_id' => 'Lost Password'
298
+ );
299
+
300
+ foreach ( $woopages as $woo_page_name => $woo_page_title ) {
301
+
302
+ $woopage = get_page_by_title( $woo_page_title );
303
+ if ( isset( $woopage ) && $woopage->ID ) {
304
+ update_option( $woo_page_name, $woopage->ID );
305
+ }
306
+
307
+ }
308
+
309
+ // Catalog images sizes
310
+ if ( $catalog_img ) {
311
+ $catalog = array(
312
+ 'width' => $c_width,
313
+ 'height' => $c_height,
314
+ 'crop' => 1
315
+ );
316
+ update_option( 'shop_catalog_image_size', $catalog );
317
+ }
318
+
319
+ // Single product image sizes
320
+ if ( $single_img ) {
321
+ $single = array(
322
+ 'width' => $s_width,
323
+ 'height' => $s_height,
324
+ 'crop' => 1
325
+ );
326
+ update_option( 'shop_single_image_size', $single );
327
+ }
328
+
329
+ // Product thumbnails image sizes
330
+ if ( $thumbnails_img ) {
331
+ $thumbnail = array(
332
+ 'width' => $t_width,
333
+ 'height' => $t_height,
334
+ 'crop' => 1
335
+ );
336
+ update_option( 'shop_thumbnail_image_size', $thumbnail );
337
+ }
338
+
339
+ // We no longer need to install pages
340
+ delete_option( '_wc_needs_pages' );
341
+ delete_transient( '_wc_activation_redirect' );
342
+
343
+ }
344
+
345
+ // Import settings
346
+ if ( $theme_settings ) {
347
+ $settings_importer = new ODI_Settings_Importer();
348
+ $settings_importer->process_import_file( $theme_settings );
349
+ }
350
+
351
+ // Import widgets
352
+ if ( $widgets_file ) {
353
+ $widgets_importer = new ODI_Widget_Importer();
354
+ $widgets_importer->process_import_file( $widgets_file );
355
+ }
356
+
357
+ // Set imported menus to registered theme locations
358
+ $locations = get_theme_mod( 'nav_menu_locations' );
359
+ $menus = wp_get_nav_menus();
360
+
361
+ if ( $menus ) {
362
+
363
+ foreach ( $menus as $menu ) {
364
+
365
+ if ( $menu->name == 'Main Menu' ) {
366
+ $locations['main_menu'] = $menu->term_id;
367
+ } else if ( $menu->name == 'Top Menu' ) {
368
+ $locations['topbar_menu'] = $menu->term_id;
369
+ } else if ( $menu->name == 'Footer Menu' ) {
370
+ $locations['footer_menu'] = $menu->term_id;
371
+ }
372
+
373
+ }
374
+
375
+ }
376
+
377
+ // Set menus to locations
378
+ set_theme_mod( 'nav_menu_locations', $locations );
379
+
380
+ // Disable Elementor default settings
381
+ update_option( 'elementor_disable_color_schemes', 'yes' );
382
+ update_option( 'elementor_disable_typography_schemes', 'yes' );
383
+ if ( $elementor_width ) {
384
+ update_option( 'elementor_container_width', $elementor_width );
385
+ }
386
+
387
+ // Assign front page and posts page (blog page).
388
+ $home_page = get_page_by_title( $homepage_title );
389
+ $blog_page = get_page_by_title( $blog_title );
390
+
391
+ update_option( 'show_on_front', 'page' );
392
+
393
+ if ( isset( $home_page ) && $home_page->ID ) {
394
+ update_option( 'page_on_front', $home_page->ID );
395
+ }
396
+
397
+ if ( isset( $blog_page ) && $blog_page->ID ) {
398
+ update_option( 'page_for_posts', $blog_page->ID );
399
+ }
400
+
401
+ // Posts to show on the blog page
402
+ if ( $posts_to_show ) {
403
+ update_option( 'posts_per_page', $posts_to_show );
404
+ }
405
+
406
+ echo 'imported';
407
+
408
+ exit;
409
+
410
+ }
411
+
412
+ }
413
+
414
+ /**
415
+ * Import XML data
416
+ *
417
+ * @since 1.0.0
418
+ */
419
+ public function process_xml( $file ) {
420
+
421
+ $response = ODI_Helpers::get_remote( $file );
422
+
423
+ // No sample data found
424
+ if ( $response === false ) {
425
+ return new WP_Error( 'xml_import_error', __( 'Can not retrieve sample data xml file. Github may be down at the momment please try again later. If you still have issues contact the theme developer for assistance.', 'ocean-demo-import' ) );
426
+ }
427
+
428
+ // Write sample data content to temp xml file
429
+ $temp_xml = ODI_PATH .'includes/temp.xml';
430
+ file_put_contents( $temp_xml, $response );
431
+
432
+ // Set temp xml to attachment url for use
433
+ $attachment_url = $temp_xml;
434
+
435
+ // If file exists lets import it
436
+ if ( file_exists( $attachment_url ) ) {
437
+ $this->import_xml( $attachment_url );
438
+ } else {
439
+ // Import file can't be imported - we should die here since this is core for most people.
440
+ return new WP_Error( 'xml_import_error', __( 'The xml import file could not be accessed. Please try again or contact the theme developer.', 'ocean-demo-import' ) );
441
+ }
442
+
443
+ }
444
+
445
+ /**
446
+ * Import XML file
447
+ *
448
+ * @since 1.0.0
449
+ */
450
+ private function import_xml( $file ) {
451
+
452
+ // Make sure importers constant is defined
453
+ if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
454
+ define( 'WP_LOAD_IMPORTERS', true );
455
+ }
456
+
457
+ // Import file location
458
+ $import_file = ABSPATH . 'wp-admin/includes/import.php';
459
+
460
+ // Include import file
461
+ if ( ! file_exists( $import_file ) ) {
462
+ return;
463
+ }
464
+
465
+ // Include import file
466
+ require_once( $import_file );
467
+
468
+ // Define error var
469
+ $importer_error = false;
470
+
471
+ if ( ! class_exists( 'WP_Importer' ) ) {
472
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
473
+
474
+ if ( file_exists( $class_wp_importer ) ) {
475
+ require_once $class_wp_importer;
476
+ } else {
477
+ $importer_error = __( 'Can not retrieve class-wp-importer.php', 'ocean-demo-import' );
478
+ }
479
+ }
480
+
481
+ if ( ! class_exists( 'WP_Import' ) ) {
482
+ $class_wp_import = ODI_PATH . 'includes/class/class-wordpress-importer.php';
483
+
484
+ if ( file_exists( $class_wp_import ) ) {
485
+ require_once $class_wp_import;
486
+ } else {
487
+ $importer_error = __( 'Can not retrieve wordpress-importer.php', 'ocean-demo-import' );
488
+ }
489
+ }
490
+
491
+ // Display error
492
+ if ( $importer_error ) {
493
+ return new WP_Error( 'xml_import_error', $importer_error );
494
+ } else {
495
+
496
+ // No error, lets import things...
497
+ if ( ! is_file( $file ) ) {
498
+ $importer_error = __( 'Sample data file appears corrupt or can not be accessed.', 'ocean-demo-import' );
499
+ return new WP_Error( 'xml_import_error', $importer_error );
500
+ } else {
501
+ $importer = new WP_Import();
502
+ $importer->fetch_attachments = true;
503
+ $importer->import( $file );
504
+
505
+ // Clear sample data content from temp xml file
506
+ $temp_xml = ODI_PATH .'includes/temp.xml';
507
+ file_put_contents( $temp_xml, '' );
508
+ }
509
+ }
510
+ }
511
+
512
+ }
513
+ new ODI_Importer();
includes/install-demos.php ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Install demos page
4
+ */
5
+
6
+ // Exit if accessed directly
7
+ if ( ! defined( 'ABSPATH' ) ) {
8
+ exit;
9
+ }
10
+
11
+ // Start Class
12
+ class ODI_Install_Demos {
13
+
14
+ /**
15
+ * Start things up
16
+ */
17
+ public function __construct() {
18
+ add_action( 'admin_menu', array( $this, 'add_page' ), 50 );
19
+ }
20
+
21
+ /**
22
+ * Add sub menu page for the custom CSS input
23
+ *
24
+ * @since 1.0.0
25
+ */
26
+ public function add_page() {
27
+ add_submenu_page(
28
+ 'ocean-panel',
29
+ esc_html__( 'Install Demos', 'ocean-demo-import' ),
30
+ esc_html__( 'Install Demos', 'ocean-demo-import' ),
31
+ 'manage_options',
32
+ 'ocean-panel-install-demos',
33
+ array( $this, 'create_admin_page' )
34
+ );
35
+ }
36
+
37
+ /**
38
+ * Settings page output
39
+ *
40
+ * @since 1.0.0
41
+ */
42
+ public function create_admin_page() {
43
+
44
+ // Vars
45
+ $ocean_url = 'https://oceanwp.org/';
46
+ $demos = ODI_Importer::get_data(); ?>
47
+
48
+ <div id="odi-demo-wrap" class="wrap">
49
+
50
+ <h2>Ocean - <?php esc_attr_e( 'Install Demos', 'ocean-demo-import' ); ?></h2>
51
+
52
+ <div class="updated error importer-notice importer-notice-1" style="display: none;">
53
+
54
+ <p><?php esc_attr_e( 'We&rsquo;re sorry but the demo data could not be imported. It is most likely due to low PHP configurations on your server. You need to import the demo manually, look the second method from this article of the documentation:', 'ocean-demo-import' ); ?> <a href="http://docs.oceanwp.org/article/52-importing-the-sample-data/#manual-installation" target="_blank"><?php esc_attr_e( 'Importing the sample data', 'ocean-demo-import' ); ?></a></p>
55
+
56
+ </div>
57
+
58
+ <div class="updated importer-notice importer-notice-2" style="display: none;">
59
+
60
+ <p><?php esc_html_e( 'Demo data successfully imported.', 'ocean-demo-import' ); ?></p>
61
+
62
+ </div>
63
+
64
+ <div class="updated error importer-notice importer-notice-3" style="display: none;">
65
+
66
+ <p><?php esc_attr_e( 'We&rsquo;re sorry but the demo data could not be imported. It is most likely due to low PHP configurations on your server. You need to import the demo manually, look the second method from this article of the documentation:', 'ocean-demo-import' ); ?> <a href="http://docs.oceanwp.org/article/52-importing-the-sample-data/#manual-installation" target="_blank"><?php esc_attr_e( 'Importing the sample data', 'ocean-demo-import' ); ?></a></p>
67
+
68
+ </div>
69
+
70
+ <div class="odi-important-notice notice notice-warning">
71
+
72
+ <p><?php esc_html_e( 'Before you begin, make sure all the required plugins are activated.', 'ocean-demo-import' ); ?></p>
73
+
74
+ </div>
75
+
76
+ <div class="odi-about-description">
77
+
78
+ <?php
79
+ if ( is_plugin_active( 'wordpress-database-reset/wp-reset.php' ) ) {
80
+ $plugin_link = admin_url( 'tools.php?page=database-reset' );
81
+ } else {
82
+ $plugin_link = admin_url( 'plugin-install.php?s=Wordpress+Database+Reset&tab=search' );
83
+ } ?>
84
+
85
+ <p><?php echo sprintf( __( 'Importing demo data ( post, pages, images, customizer settings, ... ) is the easiest way to setup your theme. It will allow you to quickly edit everything instead of creating content from scratch. We recommend uploading sample data on a clean installation to prevent conflicts with your current content. You can use this plugin to reset your site if needed: <a href="%s" target="_blank">Wordpress Database Reset</a>.', 'ocean-demo-import' ), $plugin_link ); ?>
86
+ </p>
87
+
88
+ </div>
89
+
90
+ <hr>
91
+
92
+ <div class="theme-browser rendered">
93
+
94
+ <div class="themes wp-clearfix">
95
+
96
+ <?php
97
+ // Loop through all demos
98
+ foreach ( $demos as $demo => $key ) {
99
+
100
+ // Preview url
101
+ $preview = $ocean_url . $demo; ?>
102
+
103
+ <div class="theme-wrap">
104
+
105
+ <div class="theme">
106
+
107
+ <div class="theme-screenshot odi-install" data-demo-id="<?php echo esc_attr( $demo ); ?>">
108
+ <img src="https://raw.githubusercontent.com/oceanwp/ocean-sample-data/master/<?php echo esc_attr( $demo ); ?>/preview.jpg" />
109
+
110
+ <div class="demo-import-loader preview-all preview-all-<?php echo esc_attr( $demo ); ?>"></div>
111
+
112
+ <div class="demo-import-loader preview-icon preview-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-update"></i></div>
113
+
114
+ <div class="demo-import-loader success-icon success-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-yes"></i></div>
115
+
116
+ <div class="demo-import-loader warning-icon warning-<?php echo esc_attr( $demo ); ?>"><i class="dashicons dashicons-warning"></i></div>
117
+ </div>
118
+
119
+ <h3 class="theme-name" id="<?php echo esc_attr( $demo ); ?>"><span><?php echo ucwords( $demo ); ?></span></h3>
120
+
121
+ <div class="theme-actions">
122
+ <a class="button button-secondary odi-install" data-demo-id="<?php echo esc_attr( $demo ); ?>" href="#"><?php _e( 'Install', 'ocean-demo-import' ); ?></a>
123
+ <a class="button button-primary" href="<?php echo esc_url( $preview ); ?>" target="_blank"><?php _e( 'Preview', 'ocean-demo-import' ); ?></a>
124
+ </div>
125
+
126
+ </div>
127
+
128
+ </div>
129
+
130
+ <?php } ?>
131
+
132
+ </div>
133
+
134
+ </div>
135
+
136
+ </div>
137
+
138
+ <?php }
139
+ }
140
+ new ODI_Install_Demos();
includes/temp.xml ADDED
File without changes
languages/ocean-demo-import.pot ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2016
2
+ # This file is distributed under the same license as the package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: \n"
6
+ "Report-Msgid-Bugs-To: https://oceanwp.org/support/\n"
7
+ "POT-Creation-Date: 2016-11-16 23:30:37+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: OceanWP\n"
13
+ "Language-Team: OceanWP\n"
14
+ "X-Generator: grunt-wp-i18n 0.5.3\n"
15
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
16
+ "X-Poedit-Basepath: ..\n"
17
+ "X-Poedit-Language: English\n"
18
+ "X-Poedit-Country: UNITED STATES\n"
19
+ "X-Poedit-SourceCharset: utf-8\n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Poedit-KeywordsList: "
22
+ "_esc_attr__;esc_attr_x;esc_attr_e;esc_html__;esc_html_e;esc_html_x;__;_e;__"
23
+ "ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c;_nc:4c,1,2;_x:1,2c;_"
24
+ "ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
25
+ "X-Textdomain-Support: yes\n"
26
+
27
+ #: inc/class-odi-customizer-importer.php:35
28
+ msgid "The customizer import file is missing! File path: %s"
29
+ msgstr ""
30
+
31
+ #: inc/class-odi-customizer-importer.php:55
32
+ msgid ""
33
+ "The customizer import file is not in a correct format. Please make sure to "
34
+ "use the correct customizer import file."
35
+ msgstr ""
36
+
37
+ #: inc/class-odi-customizer-importer.php:61
38
+ msgid ""
39
+ "The customizer import file is not suitable for current theme. You can only "
40
+ "import customizer settings for the same theme or a child theme."
41
+ msgstr ""
42
+
43
+ #: inc/class-odi-helpers.php:66
44
+ msgid "\"import_file_url\" or \"local_import_file\" for %s%s%s are not defined!"
45
+ msgstr ""
46
+
47
+ #: inc/class-odi-helpers.php:171
48
+ msgid "URL for %s%s%s file is not defined!"
49
+ msgstr ""
50
+
51
+ #: inc/class-odi-helpers.php:193
52
+ msgid ""
53
+ "An error occurred while fetching %s%s%s file from the server!%sReason: %s - "
54
+ "%s."
55
+ msgstr ""
56
+
57
+ #: inc/class-odi-helpers.php:232 inc/class-odi-helpers.php:275
58
+ msgid ""
59
+ "An error occurred while writing file to your server! Tried to write a file "
60
+ "to: %s%s."
61
+ msgstr ""
62
+
63
+ #: inc/class-odi-helpers.php:309
64
+ msgid ""
65
+ "An error occurred while reading a file from your server! Tried reading file "
66
+ "from path: %s%s."
67
+ msgstr ""
68
+
69
+ #: inc/class-odi-helpers.php:332
70
+ msgid ""
71
+ "This WordPress page does not have %sdirect%s write file access. This plugin "
72
+ "needs it in order to save the demo import xml file to the upload directory "
73
+ "of your site. You can change this setting with these instructions: %s."
74
+ msgstr ""
75
+
76
+ #: inc/class-odi-helpers.php:343 inc/class-odi-main.php:76
77
+ #: inc/class-odi-main.php:93
78
+ msgid "Ocean Demo Import"
79
+ msgstr ""
80
+
81
+ #: inc/class-odi-helpers.php:344 inc/class-odi-main.php:77
82
+ #: inc/class-odi-main.php:227
83
+ msgid "Import Demo Data"
84
+ msgstr ""
85
+
86
+ #: inc/class-odi-helpers.php:355
87
+ msgid ""
88
+ "An error occurred while retrieving reading/writing permissions to your "
89
+ "server (could not retrieve WP filesystem credentials)!"
90
+ msgstr ""
91
+
92
+ #: inc/class-odi-helpers.php:363
93
+ msgid "Your WordPress login credentials don't allow to use WP_Filesystem!"
94
+ msgstr ""
95
+
96
+ #: inc/class-odi-helpers.php:425
97
+ msgid "Ocean Demo Import - "
98
+ msgstr ""
99
+
100
+ #: inc/class-odi-helpers.php:459
101
+ msgid ""
102
+ "%sYour user role isn't high enough. You don't have permission to import "
103
+ "demo data.%s"
104
+ msgstr ""
105
+
106
+ #: inc/class-odi-helpers.php:494
107
+ msgid ""
108
+ "Please upload XML file for content import. If you want to import widgets or "
109
+ "customizer settings only, please use Widget Importer & Exporter or the "
110
+ "Customizer Export/Import plugin."
111
+ msgstr ""
112
+
113
+ #: inc/class-odi-helpers.php:496 inc/class-odi-helpers.php:518
114
+ #: inc/class-odi-helpers.php:537 inc/class-odi-helpers.php:545
115
+ msgid "Upload files"
116
+ msgstr ""
117
+
118
+ #: inc/class-odi-helpers.php:514
119
+ msgid "Widget file was not uploaded. Error: %s"
120
+ msgstr ""
121
+
122
+ #: inc/class-odi-helpers.php:533
123
+ msgid "Customizer file was not uploaded. Error: %s"
124
+ msgstr ""
125
+
126
+ #: inc/class-odi-helpers.php:543
127
+ msgid "The import files were successfully uploaded!"
128
+ msgstr ""
129
+
130
+ #: inc/class-odi-helpers.php:560
131
+ msgid "Initial max execution time = %s"
132
+ msgstr ""
133
+
134
+ #: inc/class-odi-helpers.php:564
135
+ msgid ""
136
+ "Files info:%1$sSite URL = %2$s%1$sData file = %3$s%1$sWidget file = "
137
+ "%4$s%1$sCustomizer file = %5$s"
138
+ msgstr ""
139
+
140
+ #: inc/class-odi-helpers.php:568 inc/class-odi-helpers.php:569
141
+ msgid "not defined!"
142
+ msgstr ""
143
+
144
+ #: inc/class-odi-main.php:100
145
+ msgid ""
146
+ "%sWarning: your server is using %sPHP safe mode%s. This means that you "
147
+ "might experience server timeout errors.%s"
148
+ msgstr ""
149
+
150
+ #: inc/class-odi-main.php:113
151
+ msgid "Before you begin, make sure all the required plugins are activated."
152
+ msgstr ""
153
+
154
+ #: inc/class-odi-main.php:119
155
+ msgid ""
156
+ "Importing demo data (post, pages, images, theme settings, ...) is the "
157
+ "easiest way to setup your theme."
158
+ msgstr ""
159
+
160
+ #: inc/class-odi-main.php:120
161
+ msgid ""
162
+ "It will allow you to quickly edit everything instead of creating content "
163
+ "from scratch."
164
+ msgstr ""
165
+
166
+ #: inc/class-odi-main.php:125
167
+ msgid "When you import the data, the following things might happen:"
168
+ msgstr ""
169
+
170
+ #: inc/class-odi-main.php:128
171
+ msgid ""
172
+ "No existing posts, pages, categories, images, custom post types or any "
173
+ "other data will be deleted or modified."
174
+ msgstr ""
175
+
176
+ #: inc/class-odi-main.php:129
177
+ msgid "Posts, pages, images, widgets and menus will get imported."
178
+ msgstr ""
179
+
180
+ #: inc/class-odi-main.php:130
181
+ msgid ""
182
+ "Please click \"Import Demo Data\" button only once and wait, it can take a "
183
+ "couple of minutes."
184
+ msgstr ""
185
+
186
+ #: inc/class-odi-main.php:148
187
+ msgid ""
188
+ "There are no predefined import files available in this theme. Please upload "
189
+ "the import files manually!"
190
+ msgstr ""
191
+
192
+ #: inc/class-odi-main.php:153
193
+ msgid "Manual demo files upload"
194
+ msgstr ""
195
+
196
+ #: inc/class-odi-main.php:156
197
+ msgid "Choose a XML file for content import:"
198
+ msgstr ""
199
+
200
+ #: inc/class-odi-main.php:161
201
+ msgid "Choose a WIE or JSON file for widget import:"
202
+ msgstr ""
203
+
204
+ #: inc/class-odi-main.php:161 inc/class-odi-main.php:166
205
+ msgid "(*optional)"
206
+ msgstr ""
207
+
208
+ #: inc/class-odi-main.php:166
209
+ msgid "Choose a DAT file for customizer import:"
210
+ msgstr ""
211
+
212
+ #: inc/class-odi-main.php:176
213
+ msgid "Choose which demo you want to import:"
214
+ msgstr ""
215
+
216
+ #: inc/class-odi-main.php:201
217
+ msgid "Import preview:"
218
+ msgstr ""
219
+
220
+ #: inc/class-odi-main.php:205 inc/class-odi-main.php:258
221
+ msgid "No preview image defined for this import."
222
+ msgstr ""
223
+
224
+ #: inc/class-odi-main.php:231
225
+ msgid "Importing, please wait!"
226
+ msgstr ""
227
+
228
+ #: inc/class-odi-main.php:314
229
+ msgid "Manually uploaded files"
230
+ msgstr ""
231
+
232
+ #: inc/class-odi-main.php:331 inc/class-odi-main.php:342
233
+ msgid "Downloaded files"
234
+ msgstr ""
235
+
236
+ #: inc/class-odi-main.php:338
237
+ msgid "The import files for: %s were successfully downloaded!"
238
+ msgstr ""
239
+
240
+ #: inc/class-odi-main.php:348
241
+ msgid "No import files specified!"
242
+ msgstr ""
243
+
244
+ #: inc/class-odi-main.php:395
245
+ msgid ""
246
+ "%1$s%3$sThat's it, all done!%4$s%2$sThe demo import has finished. Please "
247
+ "check your page and make sure that everything has imported correctly. If it "
248
+ "did, you can deactivate the %3$sOcean Demo Import%4$s plugin, because it "
249
+ "has done its job.%5$s"
250
+ msgstr ""
251
+
252
+ #: inc/class-odi-main.php:406
253
+ msgid ""
254
+ "%1$sThe demo import has finished, but there were some import "
255
+ "errors.%2$sMore details about the errors can be found in this %3$s%5$slog "
256
+ "file%6$s%4$s%7$s"
257
+ msgstr ""
258
+
259
+ #: inc/class-odi-main.php:459
260
+ msgid "Max execution time after content import = "
261
+ msgstr ""
262
+
263
+ #: inc/class-odi-main.php:461
264
+ msgid "Importing content"
265
+ msgstr ""
266
+
267
+ #: inc/class-odi-main.php:499 inc/class-odi-main.php:511
268
+ msgid "Importing widgets"
269
+ msgstr ""
270
+
271
+ #: inc/class-odi-main.php:532 inc/class-odi-main.php:540
272
+ msgid "Importing customizer settings"
273
+ msgstr ""
274
+
275
+ #: inc/class-odi-main.php:538
276
+ msgid "Customizer settings import finished!"
277
+ msgstr ""
278
+
279
+ #: inc/class-odi-main.php:588
280
+ msgid "Completed AJAX call number: "
281
+ msgstr ""
282
+
283
+ #: inc/class-odi-widget-importer.php:43
284
+ msgid "Widget import file could not be found."
285
+ msgstr ""
286
+
287
+ #: inc/class-odi-widget-importer.php:73
288
+ msgid "Widget import data could not be read. Please try a different file."
289
+ msgstr ""
290
+
291
+ #: inc/class-odi-widget-importer.php:113
292
+ msgid "Sidebar does not exist in theme (moving widget to Inactive)"
293
+ msgstr ""
294
+
295
+ #: inc/class-odi-widget-importer.php:135
296
+ msgid "Site does not support widget"
297
+ msgstr ""
298
+
299
+ #: inc/class-odi-widget-importer.php:170
300
+ msgid "Widget already exists"
301
+ msgstr ""
302
+
303
+ #: inc/class-odi-widget-importer.php:229
304
+ msgid "Imported"
305
+ msgstr ""
306
+
307
+ #: inc/class-odi-widget-importer.php:233
308
+ msgid "Imported to Inactive"
309
+ msgstr ""
310
+
311
+ #: inc/class-odi-widget-importer.php:239
312
+ msgid "No Title"
313
+ msgstr ""
314
+
315
+ #: inc/class-odi-widget-importer.php:288
316
+ msgid "No results for widget import!"
317
+ msgstr ""
318
+
319
+ #: ocean-demo-import.php:136 ocean-demo-import.php:145
320
+ msgid "Cheatin&#8217; huh?"
321
+ msgstr ""
322
+
323
+ #: ocean-demo-import.php:198
324
+ msgid ""
325
+ "The %2$sOcean Demo Import%3$s plugin requires %2$sPHP 5.3.2+%3$s to run "
326
+ "properly. Please contact your hosting company and ask them to update the "
327
+ "PHP version of your site to at least PHP 5.3.2.%4$s Your current version of "
328
+ "PHP: %2$s%1$s%3$s"
329
+ msgstr ""
330
+
331
+ #: ocean-demo-import.php:211
332
+ msgid "Ocean Extra requires that you use ocean as your parent theme."
333
+ msgstr ""
334
+
335
+ #: ocean-demo-import.php:211
336
+ msgid "Install Ocean Now"
337
+ msgstr ""
338
+
339
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:131
340
+ msgid "Could not open the file for parsing"
341
+ msgstr ""
342
+
343
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:167
344
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:283
345
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:356
346
+ msgid ""
347
+ "This WXR file (version %s) is newer than the importer (version %s) and may "
348
+ "not be supported. Please consider updating."
349
+ msgstr ""
350
+
351
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:505
352
+ msgid "The file does not exist, please try again."
353
+ msgstr ""
354
+
355
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:565
356
+ msgid "Invalid author mapping"
357
+ msgstr ""
358
+
359
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:666
360
+ msgid "Cannot import auto-draft posts"
361
+ msgstr ""
362
+
363
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:754
364
+ msgid "Failed to import \"%s\": Invalid post type %s"
365
+ msgstr ""
366
+
367
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:764
368
+ msgid "%s \"%s\" already exists."
369
+ msgstr ""
370
+
371
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:842
372
+ msgid "Skipping attachment \"%s\", fetching attachments disabled"
373
+ msgstr ""
374
+
375
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:856
376
+ msgid "Failed to import \"%s\" (%s)"
377
+ msgstr ""
378
+
379
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:888
380
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1711
381
+ msgid "Imported \"%s\" (%s)"
382
+ msgstr ""
383
+
384
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:893
385
+ msgid "Post %d remapped to %d"
386
+ msgstr ""
387
+
388
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1037
389
+ msgid "Invalid file type"
390
+ msgstr ""
391
+
392
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1520
393
+ msgid "Failed to import user \"%s\""
394
+ msgstr ""
395
+
396
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1541
397
+ msgid "Imported user \"%s\""
398
+ msgstr ""
399
+
400
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1545
401
+ msgid "User %d remapped to %d"
402
+ msgstr ""
403
+
404
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1687
405
+ msgid "Failed to import %s %s"
406
+ msgstr ""
407
+
408
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1716
409
+ msgid "Term %d remapped to %d"
410
+ msgstr ""
411
+
412
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1813
413
+ msgid "Remote server returned %1$d %2$s for %3$s"
414
+ msgstr ""
415
+
416
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1826
417
+ msgid "Remote file is incorrect size"
418
+ msgstr ""
419
+
420
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1831
421
+ msgid "Zero size file downloaded"
422
+ msgstr ""
423
+
424
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1837
425
+ msgid "Remote file is too large, limit is %s"
426
+ msgstr ""
427
+
428
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1859
429
+ msgid "Running post-processing for post %d"
430
+ msgstr ""
431
+
432
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1872
433
+ msgid "Could not find the post parent for \"%s\" (post #%d)"
434
+ msgstr ""
435
+
436
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1877
437
+ msgid "Post %d was imported with parent %d, but could not be found"
438
+ msgstr ""
439
+
440
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1891
441
+ msgid "Could not find the author for \"%s\" (post #%d)"
442
+ msgstr ""
443
+
444
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1896
445
+ msgid "Post %d was imported with author \"%s\", but could not be found"
446
+ msgstr ""
447
+
448
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1922
449
+ msgid "Post %d was marked for post-processing, but none was required."
450
+ msgstr ""
451
+
452
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1933
453
+ msgid "Could not update \"%s\" (post #%d) with mapped data"
454
+ msgstr ""
455
+
456
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1978
457
+ msgid "Could not find the menu object for \"%s\" (post #%d)"
458
+ msgstr ""
459
+
460
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:1983
461
+ msgid ""
462
+ "Post %d was imported with object \"%d\" of type \"%s\", but could not be "
463
+ "found"
464
+ msgstr ""
465
+
466
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:2005
467
+ msgid "Could not find the comment parent for comment #%d"
468
+ msgstr ""
469
+
470
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:2009
471
+ msgid "Comment %d was imported with parent %d, but could not be found"
472
+ msgstr ""
473
+
474
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:2023
475
+ msgid "Could not find the author for comment #%d"
476
+ msgstr ""
477
+
478
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:2027
479
+ msgid "Comment %d was imported with author %d, but could not be found"
480
+ msgstr ""
481
+
482
+ #: vendor/oceanwp/wp-content-importer-v2/WXRImporter.php:2044
483
+ msgid "Could not update comment #%d with mapped data"
484
+ msgstr ""
ocean-demo-import.php ADDED
@@ -0,0 +1,220 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Ocean Demo Import
4
+ * Plugin URI: https://oceanwp.org/extension/ocean-demo-import/
5
+ * Description: Import the Ocean demo content, widgets and customizer settings with one click.
6
+ * Version: 1.0.0
7
+ * Author: OceanWP
8
+ * Author URI: https://oceanwp.org/
9
+ * Requires at least: 4.0.0
10
+ * Tested up to: 4.7
11
+ *
12
+ * Text Domain: ocean-demo-import
13
+ * Domain Path: /languages/
14
+ *
15
+ * @package Ocean_Demo_Import
16
+ * @category Core
17
+ * @author OceanWP
18
+ * @see This plugin is based on: https://github.com/proteusthemes/one-click-demo-import/
19
+ */
20
+
21
+ // Exit if accessed directly
22
+ if ( ! defined( 'ABSPATH' ) ) {
23
+ exit;
24
+ }
25
+
26
+ /**
27
+ * Returns the main instance of Ocean_Demo_Import to prevent the need to use globals.
28
+ *
29
+ * @since 1.0.0
30
+ * @return object Ocean_Demo_Import
31
+ */
32
+ function Ocean_Demo_Import() {
33
+ return Ocean_Demo_Import::instance();
34
+ } // End Ocean_Demo_Import()
35
+
36
+ Ocean_Demo_Import();
37
+
38
+ /**
39
+ * Main Ocean_Demo_Import Class
40
+ *
41
+ * @class Ocean_Demo_Import
42
+ * @version 1.0.0
43
+ * @since 1.0.0
44
+ * @package Ocean_Demo_Import
45
+ */
46
+ final class Ocean_Demo_Import {
47
+ /**
48
+ * Ocean_Demo_Import The single instance of Ocean_Demo_Import.
49
+ * @var object
50
+ * @access private
51
+ * @since 1.0.0
52
+ */
53
+ private static $_instance = null;
54
+
55
+ /**
56
+ * The token.
57
+ * @var string
58
+ * @access public
59
+ * @since 1.0.0
60
+ */
61
+ public $token;
62
+
63
+ /**
64
+ * The version number.
65
+ * @var string
66
+ * @access public
67
+ * @since 1.0.0
68
+ */
69
+ public $version;
70
+
71
+ // Admin - Start
72
+ /**
73
+ * The admin object.
74
+ * @var object
75
+ * @access public
76
+ * @since 1.0.0
77
+ */
78
+ public $admin;
79
+
80
+ /**
81
+ * Constructor function.
82
+ * @access public
83
+ * @since 1.0.0
84
+ * @return void
85
+ */
86
+ public function __construct( $widget_areas = array() ) {
87
+ $this->token = 'ocean-demo-import';
88
+ $this->plugin_url = plugin_dir_url( __FILE__ );
89
+ $this->plugin_path = plugin_dir_path( __FILE__ );
90
+ $this->version = '1.0.0';
91
+
92
+ define( 'ODI_ROOT', dirname( __FILE__ ) );
93
+ define( 'ODI_PATH', $this->plugin_path );
94
+ define( 'ODI_URL', $this->plugin_url );
95
+
96
+ register_activation_hook( __FILE__, array( $this, 'install' ) );
97
+
98
+ add_action( 'init', array( $this, 'odi_load_plugin_textdomain' ) );
99
+
100
+ add_action( 'init', array( $this, 'odi_setup' ) );
101
+ }
102
+
103
+ /**
104
+ * Main Ocean_Demo_Import Instance
105
+ *
106
+ * Ensures only one instance of Ocean_Demo_Import is loaded or can be loaded.
107
+ *
108
+ * @since 1.0.0
109
+ * @static
110
+ * @see Ocean_Demo_Import()
111
+ * @return Main Ocean_Demo_Import instance
112
+ */
113
+ public static function instance() {
114
+ if ( is_null( self::$_instance ) )
115
+ self::$_instance = new self();
116
+ return self::$_instance;
117
+ } // End instance()
118
+
119
+ /**
120
+ * Load the localisation file.
121
+ * @access public
122
+ * @since 1.0.0
123
+ * @return void
124
+ */
125
+ public function odi_load_plugin_textdomain() {
126
+ load_plugin_textdomain( 'ocean-demo-import', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
127
+ }
128
+
129
+ /**
130
+ * Cloning is forbidden.
131
+ *
132
+ * @since 1.0.0
133
+ */
134
+ public function __clone() {
135
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), '1.0.0' );
136
+ }
137
+
138
+ /**
139
+ * Unserializing instances of this class is forbidden.
140
+ *
141
+ * @since 1.0.0
142
+ */
143
+ public function __wakeup() {
144
+ _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?' ), '1.0.0' );
145
+ }
146
+
147
+ /**
148
+ * Installation.
149
+ * Runs on activation. Logs the version number and assigns a notice message to a WordPress option.
150
+ * @access public
151
+ * @since 1.0.0
152
+ * @return void
153
+ */
154
+ public function install() {
155
+ $this->_log_version_number();
156
+ }
157
+
158
+ /**
159
+ * Log the plugin version number.
160
+ * @access private
161
+ * @since 1.0.0
162
+ * @return void
163
+ */
164
+ private function _log_version_number() {
165
+ // Log the version number.
166
+ update_option( $this->token . '-version', $this->version );
167
+ }
168
+
169
+ /**
170
+ * Setup all the things.
171
+ * Only executes if Ocean or a child theme using Ocean as a parent is active and the extension specific filter returns true.
172
+ * @return void
173
+ */
174
+ public function odi_setup() {
175
+ $theme = wp_get_theme();
176
+
177
+ if ( 'Ocean' == $theme->name || 'ocean' == $theme->template ) {
178
+ if ( is_admin() ) {
179
+ require_once( ODI_ROOT .'/includes/class/class-helpers.php' );
180
+ require_once( ODI_ROOT .'/includes/importer.php' );
181
+ require_once( ODI_ROOT .'/includes/install-demos.php' );
182
+ }
183
+ add_action( 'admin_enqueue_scripts', array( $this, 'odi_scripts' ) );
184
+ } else {
185
+ add_action( 'admin_notices', array( $this, 'odi_install_ocean_notice' ) );
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Ocean install
191
+ * If the user activates the plugin while having a different parent theme active, prompt them to install Ocean.
192
+ * @since 1.0.0
193
+ * @return void
194
+ */
195
+ public function odi_install_ocean_notice() {
196
+ echo '<div class="notice is-dismissible updated">
197
+ <p>' . esc_html__( 'Ocean Extra requires that you use ocean as your parent theme.', 'ocean-demo-import' ) . ' <a href="https://oceanwp.com/">' . esc_html__( 'Install Ocean Now', 'ocean-demo-import' ) . '</a></p>
198
+ </div>';
199
+ }
200
+
201
+ /**
202
+ * Load scripts
203
+ *
204
+ * @since 1.0.0
205
+ */
206
+ public static function odi_scripts( $hook_suffix ) {
207
+
208
+ if ( 'theme-panel_page_ocean-panel-install-demos' == $hook_suffix ) {
209
+
210
+ // CSS
211
+ wp_enqueue_style( 'odi-style', plugins_url( '/assets/css/admin.css', __FILE__ ) );
212
+
213
+ // JS
214
+ wp_enqueue_script( 'odi-js', plugins_url( '/assets/js/admin.js', __FILE__ ) );
215
+
216
+ }
217
+
218
+ }
219
+
220
+ } // End Class
readme.txt ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Ocean Demo Import ===
2
+ Contributors: oceanwp
3
+ Tags: import, content, demo, data, widgets, settings, ocean
4
+ Requires at least: 4.0
5
+ Tested up to: 4.7
6
+ Stable tag: 1.0.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Import the Ocean demo content, widgets and customizer settings with one click.
11
+
12
+ == Description ==
13
+
14
+ This plugin requires the [Ocean](https://oceanwp.org/) theme to be installed.
15
+
16
+ == Installation ==
17
+
18
+ 1. Upload `ocean-demo-import` to the `/wp-content/plugins/` directory
19
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
20
+ 3. Done!
21
+
22
+ == Frequently Asked Questions ==
23
+
24
+ = I installed the plugin but the panel do not appear =
25
+
26
+ This plugin will only work with the [Ocean](https://oceanwp.org/) theme.
27
+
28
+ == Screenshots ==
29
+
30
+ 1. The demos.
31
+
32
+ == Changelog ==
33
+
34
+ = 1.0.0 =
35
+ - Initial release.