import.php 0000644 00000007223 14720715312 0006575 0 ustar 00 demos_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.php 0000644 00000027664 14720715312 0006221 0 ustar 00 get_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' => '
', 'before_title' => '