← All changes
|
includes/import/xml-parsers/wxr-parser-simple-xml.php
+133
-15
2.9.1
→
2.14.0
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ABlocks\import\XmlParsers; |
| 4 | 4 | |
| 5 | +use SimpleXMLElement; | |
| 5 | 6 | use WP_Error; |
| 6 | 7 | |
| 7 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 9 | exit; |
| @@ -174,14 +175,22 @@ | ||
| 174 | 175 | |
| 175 | 176 | $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); |
| 176 | 177 | $post['post_author'] = (string) $dc->creator; |
| 177 | 178 | |
| 178 | - $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); | |
| 179 | - $excerpt = $item->children( $namespaces['excerpt'] ); | |
| 180 | - $post['post_content'] = (string) $content->encoded; | |
| 179 | + $wp = $item->children( $namespaces['wp'] ); | |
| 180 | + $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); | |
| 181 | + $excerpt = $item->children( $namespaces['excerpt'] ); | |
| 182 | + $content = (string) $content->encoded; | |
| 183 | + if ( in_array( (string) $wp->post_type, array( 'wp_template', 'wp_template_part' ), true ) ) { | |
| 184 | + $content = preg_replace( | |
| 185 | + '/\s*,?\s*"theme"\s*:\s*"[^"]+"/', | |
| 186 | + '', | |
| 187 | + $content | |
| 188 | + ); | |
| 189 | + } | |
| 190 | + $post['post_content'] = $content; | |
| 181 | 191 | $post['post_excerpt'] = (string) $excerpt->encoded; |
| 182 | 192 | |
| 183 | - $wp = $item->children( $namespaces['wp'] ); | |
| 184 | 193 | $post['post_id'] = (int) $wp->post_id; |
| 185 | 194 | $post['post_date'] = (string) $wp->post_date; |
| 186 | 195 | $post['post_date_gmt'] = (string) $wp->post_date_gmt; |
| 187 | 196 | $post['comment_status'] = (string) $wp->comment_status; |
| @@ -247,18 +256,127 @@ | ||
| 247 | 256 | $posts[] = $post; |
| 248 | 257 | }//end foreach |
| 249 | 258 | |
| 250 | 259 | return array( |
| 251 | - 'authors' => $authors, | |
| 252 | - 'posts' => $posts, | |
| 253 | - 'categories' => $categories, | |
| 254 | - 'tags' => $tags, | |
| 255 | - 'terms' => $terms, | |
| 256 | - 'base_url' => $base_url, | |
| 257 | - 'base_blog_url' => $base_blog_url, | |
| 258 | - 'version' => $wxr_version, | |
| 259 | - 'show_on_front' => $show_on_front, | |
| 260 | - 'page_on_front' => $page_on_front, | |
| 261 | - 'page_for_posts' => $page_for_posts, | |
| 260 | + 'authors' => $authors, | |
| 261 | + 'posts' => $posts, | |
| 262 | + 'categories' => $categories, | |
| 263 | + 'tags' => $tags, | |
| 264 | + 'terms' => $terms, | |
| 265 | + 'base_url' => $base_url, | |
| 266 | + 'base_blog_url' => $base_blog_url, | |
| 267 | + 'version' => $wxr_version, | |
| 268 | + 'show_on_front' => $show_on_front, | |
| 269 | + 'page_on_front' => $page_on_front, | |
| 270 | + 'page_for_posts' => $page_for_posts, | |
| 271 | + 'storeengine_pages' => $this->get_storeengine_pages( $xml ), | |
| 272 | + 'academy_pages' => $this->get_academy_pages( $xml ), | |
| 273 | + 'ablocks_pages' => $this->get_ablocks_pages( $xml ), | |
| 274 | + 'ablocks_options' => $this->get_ablocks_options( $xml ), | |
| 262 | 275 | ); |
| 276 | + } | |
| 277 | + | |
| 278 | + private function get_storeengine_pages( SimpleXMLElement $xml ): array { | |
| 279 | + $storeengine_pages = [ | |
| 280 | + 'shop_page' => 0, | |
| 281 | + 'cart_page' => 0, | |
| 282 | + 'checkout_page' => 0, | |
| 283 | + 'thankyou_page' => 0, | |
| 284 | + 'dashboard_page' => 0, | |
| 285 | + 'membership_pricing_page' => 0, | |
| 286 | + 'affiliate_registration_page' => 0, | |
| 287 | + ]; | |
| 288 | + | |
| 289 | + foreach ( array_keys( $storeengine_pages ) as $page_key ) { | |
| 290 | + $value = $xml->xpath( '/rss/channel/ablocks_options/storeengine_' . $page_key ); | |
| 291 | + if ( $value ) { | |
| 292 | + $storeengine_pages[ $page_key ] = (int) $value[0]; | |
| 293 | + } | |
| 294 | + } | |
| 295 | + | |
| 296 | + return $storeengine_pages; | |
| 297 | + } | |
| 298 | + | |
| 299 | + private function get_academy_pages( SimpleXMLElement $xml ): array { | |
| 300 | + $academy_pages = [ | |
| 301 | + 'frontend_dashboard_page' => 0, | |
| 302 | + 'frontend_student_reg_page' => 0, | |
| 303 | + 'password_reset_page' => 0, | |
| 304 | + 'lessons_page' => 0, | |
| 305 | + 'course_page' => 0, | |
| 306 | + 'frontend_instructor_reg_page' => 0, | |
| 307 | + 'tutor_booking_page' => 0, | |
| 308 | + ]; | |
| 309 | + | |
| 310 | + foreach ( array_keys( $academy_pages ) as $page_key ) { | |
| 311 | + $value = $xml->xpath( '/rss/channel/ablocks_options/academy_' . $page_key ); | |
| 312 | + if ( $value ) { | |
| 313 | + $academy_pages[ $page_key ] = (int) $value[0]; | |
| 314 | + } | |
| 315 | + } | |
| 316 | + | |
| 317 | + return $academy_pages; | |
| 318 | + } | |
| 319 | + | |
| 320 | + private function get_ablocks_pages( SimpleXMLElement $xml ): array { | |
| 321 | + $ablocks_pages = [ | |
| 322 | + 'login_page' => 0, | |
| 323 | + 'registration_page' => 0, | |
| 324 | + 'forget_password_page' => 0, | |
| 325 | + ]; | |
| 326 | + | |
| 327 | + foreach ( array_keys( $ablocks_pages ) as $page_key ) { | |
| 328 | + $value = $xml->xpath( '/rss/channel/ablocks_options/ablocks_' . $page_key ); | |
| 329 | + if ( $value ) { | |
| 330 | + $ablocks_pages[ $page_key ] = (int) $value[0]; | |
| 331 | + } | |
| 332 | + } | |
| 333 | + | |
| 334 | + return $ablocks_pages; | |
| 335 | + } | |
| 336 | + | |
| 337 | + private function get_ablocks_options( SimpleXMLElement $xml ): array { | |
| 338 | + $ablocks_options = [ | |
| 339 | + 'default_container_width' => null, | |
| 340 | + 'container_padding' => null, | |
| 341 | + 'container_element_gap' => null, | |
| 342 | + 'global_color' => 'json', | |
| 343 | + 'global_typography' => 'json', | |
| 344 | + 'global_font_family_fallback' => null, | |
| 345 | + 'global_body_text_color' => null, | |
| 346 | + 'global_body_typography' => 'json', | |
| 347 | + 'global_body_paragraph_space' => 'json', | |
| 348 | + 'global_link_color' => null, | |
| 349 | + 'global_link_hover_color' => null, | |
| 350 | + 'global_link_typography' => 'json', | |
| 351 | + 'global_link_hover_typography' => 'json', | |
| 352 | + 'global_h1_color' => null, | |
| 353 | + 'global_h1_typography' => 'json', | |
| 354 | + 'global_h2_color' => null, | |
| 355 | + 'global_h2_typography' => 'json', | |
| 356 | + 'global_h3_color' => null, | |
| 357 | + 'global_h3_typography' => 'json', | |
| 358 | + 'global_h4_color' => null, | |
| 359 | + 'global_h4_typography' => 'json', | |
| 360 | + 'global_h5_color' => null, | |
| 361 | + 'global_h5_typography' => 'json', | |
| 362 | + 'global_h6_color' => null, | |
| 363 | + 'global_h6_typography' => 'json', | |
| 364 | + 'frontend_dashboard_page' => null, | |
| 365 | + 'frontend_dashboard_sub_pages' => 'json', | |
| 366 | + 'global_classes' => 'json', | |
| 367 | + ]; | |
| 368 | + | |
| 369 | + foreach ( array_keys( $ablocks_options ) as $page_key ) { | |
| 370 | + $value = $xml->xpath( '/rss/channel/ablocks_options/ablocks_' . $page_key ); | |
| 371 | + if ( $value ) { | |
| 372 | + $ablocks_options[ $page_key ] = 'json' === $ablocks_options[ $page_key ] ? json_decode( | |
| 373 | + base64_decode( (string) $value[0] ), true | |
| 374 | + ) : (string) $value[0]; | |
| 375 | + } else { | |
| 376 | + unset( $ablocks_options[ $page_key ] ); | |
| 377 | + } | |
| 378 | + } | |
| 379 | + | |
| 380 | + return $ablocks_options; | |
| 263 | 381 | } |
| 264 | 382 | } |