class-auxels-admin-assets.php
2 years ago
class-auxels-archive-menu-links.php
2 years ago
class-auxels-envato-elements.php
2 years ago
class-auxels-import-parser.php
3 years ago
class-auxels-import.php
3 years ago
class-auxels-search-post-type.php
2 years ago
class-auxels-wc-attribute-nav-menu.php
2 years ago
class-auxin-admin-dashboard.php
2 years ago
class-auxin-demo-importer.php
2 years ago
class-auxin-dependency-sorting.php
3 years ago
class-auxin-import.php
2 years ago
class-auxin-install.php
2 years ago
class-auxin-master-nav-menu-admin.php
2 years ago
class-auxin-page-template.php
2 years ago
class-auxin-permalink.php
2 years ago
class-auxin-plugin-requirements.php
3 years ago
class-auxin-post-type-base.php
2 years ago
class-auxin-svg-support-allowedattributes.php
7 years ago
class-auxin-svg-support-allowedtags.php
7 years ago
class-auxin-svg-support.php
3 years ago
class-auxin-walker-nav-menu-back.php
2 years ago
class-auxin-welcome-sections.php
3 years ago
class-auxin-welcome.php
3 years ago
class-auxin-whitelabel.php
3 years ago
class-auxin-widget-indie.php
2 years ago
class-auxin-widget-shortcode-map.php
2 years ago
class-auxin-widget.php
2 years ago
class-auxin-import.php
217 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class for simplifying the demo import process |
| 4 | * |
| 5 | * |
| 6 | * @package Auxin |
| 7 | * @license LICENSE.txt |
| 8 | * @author averta |
| 9 | * @link http://phlox.pro/ |
| 10 | * @copyright (c) 2010-2024 averta |
| 11 | */ |
| 12 | |
| 13 | // no direct access allowed |
| 14 | if ( ! defined('ABSPATH') ) { |
| 15 | die(); |
| 16 | } |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * Master Slider Import/Export Class. |
| 21 | * |
| 22 | * @since 1.2.0 |
| 23 | */ |
| 24 | class Auxin_Import { |
| 25 | |
| 26 | |
| 27 | var $upload_baseurl = ''; |
| 28 | |
| 29 | var $upload_basedir = ''; |
| 30 | |
| 31 | /** |
| 32 | * The ID of this importer |
| 33 | * @var string |
| 34 | */ |
| 35 | var $importer_id = ''; |
| 36 | |
| 37 | /** |
| 38 | * The link to welcome page in admin |
| 39 | * @var string |
| 40 | */ |
| 41 | var $welcome_page_url = ''; |
| 42 | |
| 43 | /** |
| 44 | * The link to demos page in admin |
| 45 | * @var string |
| 46 | */ |
| 47 | var $demo_page_url = ''; |
| 48 | |
| 49 | /** |
| 50 | * Instance of this class. |
| 51 | * |
| 52 | * @var object |
| 53 | */ |
| 54 | protected static $instance = null; |
| 55 | |
| 56 | |
| 57 | |
| 58 | public function __construct() { |
| 59 | |
| 60 | $this->importer_id = 'auxin-importer'; |
| 61 | |
| 62 | $welcome_root_page = ( defined( 'THEME_PRO' ) && THEME_PRO ) ? 'admin.php' : 'themes.php'; |
| 63 | |
| 64 | $this->welcome_page_url = admin_url( $welcome_root_page . '?page=auxin-welcome' ); |
| 65 | $this->demo_page_url = $this->welcome_page_url . '&tab=demos'; |
| 66 | |
| 67 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 68 | |
| 69 | // process and redirect the import page prior to rendering the header |
| 70 | add_action( 'load-importer-'. $this->importer_id, array( $this, 'process_before_header_output' ) ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Return an instance of this class. |
| 75 | * |
| 76 | * @return object A single instance of this class. |
| 77 | */ |
| 78 | public static function get_instance() { |
| 79 | |
| 80 | // If the single instance hasn't been set, set it now. |
| 81 | if ( null == self::$instance ) { |
| 82 | self::$instance = new self; |
| 83 | } |
| 84 | |
| 85 | return self::$instance; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | /** |
| 90 | * Print and process the output of auxin importer page |
| 91 | * @return string Importer page output |
| 92 | */ |
| 93 | public function admin_init() { |
| 94 | |
| 95 | $upload = wp_upload_dir(); |
| 96 | $this->upload_baseurl = $upload['baseurl']; |
| 97 | $this->upload_basedir = $upload['basedir']; |
| 98 | |
| 99 | |
| 100 | register_importer( 'auxin-importer', |
| 101 | __( 'Auxin Importer', 'auxin-elements' ), |
| 102 | sprintf( __( 'Import demo data for %s theme.', 'auxin-elements' ), '<strong>' . THEME_NAME_I18N . '</strong>' ), |
| 103 | array( $this, 'render_importer_page' ) |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Check if the request for importer page is valid and authorized, otherwise redirect client to demos page |
| 109 | * |
| 110 | * @return void |
| 111 | */ |
| 112 | public function process_before_header_output(){ |
| 113 | |
| 114 | // authorize the request and make sure it is from admin page, otherwise take the client back to demos page |
| 115 | if ( ! $this->is_valid_request() ) { |
| 116 | wp_redirect( $this->demo_page_url, 301 ); |
| 117 | exit(); |
| 118 | } |
| 119 | |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Outputs the custom import page for auxin |
| 124 | * |
| 125 | */ |
| 126 | public function render_importer_page() { |
| 127 | |
| 128 | $this->header(); |
| 129 | |
| 130 | $this->process_import_request(); |
| 131 | |
| 132 | $this->footer(); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | /** |
| 137 | * Display import page title |
| 138 | */ |
| 139 | public function header() { |
| 140 | echo '<div class="wrap">'; |
| 141 | echo '<h2>' . esc_html__( 'Importing Demo Data', 'auxin-elements' ) . '</h2><br />'; |
| 142 | echo '<div class="aux-import-wrapper">'; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Close div.wrap |
| 147 | */ |
| 148 | public function footer() { |
| 149 | echo '</div></div>'; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /** |
| 154 | * Process incoming requests for importing demo data |
| 155 | * @return void |
| 156 | */ |
| 157 | public function process_import_request(){ |
| 158 | |
| 159 | // make sure the demo-id is specified |
| 160 | if( ! empty( $_GET['demo-id'] ) ) { |
| 161 | $demo_id = sanitize_key( $_GET['demo-id'] ); |
| 162 | $demo_list = auxin_get_demo_info_list(); |
| 163 | |
| 164 | // if demo-id is valid, start importing the data |
| 165 | if( ! empty( $demo_list[ $demo_id ]['file'] ) ){ |
| 166 | $file = $demo_list[ $demo_id ]['file']; |
| 167 | |
| 168 | // if wordpress importer is not available, try to install it |
| 169 | if ( ! class_exists( 'WP_Importer' ) ) { |
| 170 | |
| 171 | printf( esc_html__( 'In order to import the demo data, you need to have "WordPress Importer" plugin installed. Please %s install and activate "WordPress Importer"%s and then try importing the demo data again.', 'auxin-elements' ), |
| 172 | '<a href="'. esc_url( admin_url( 'plugin-install.php?s=WordPress+Importer+zourbuth&tab=search' ) ) .'&tab=plugins">', |
| 173 | '</a>' |
| 174 | ); |
| 175 | |
| 176 | |
| 177 | // start parsing and importing the data |
| 178 | } else { |
| 179 | global $wp_import; |
| 180 | set_time_limit(0); |
| 181 | $wp_import->fetch_attachments = true; |
| 182 | $wp_import->import_file = $file; |
| 183 | $wp_import->import( $file ); |
| 184 | } |
| 185 | |
| 186 | |
| 187 | } else { |
| 188 | |
| 189 | printf( esc_html__( 'The demo that you have requested is not valid. Please try to %s select a demo %s to import.', 'auxin-elements' ), |
| 190 | '<a href="'. esc_url( $this->demo_page_url ) .'">', |
| 191 | '</a>' |
| 192 | ); |
| 193 | |
| 194 | } |
| 195 | |
| 196 | } else { |
| 197 | printf( esc_html__( 'Please %s select a demo %s to import.', 'auxin-elements' ), '<a href="'. esc_url( $this->demo_page_url ) .'">', '</a>' ); |
| 198 | } |
| 199 | |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Makes sure that a user was referred from another admin page. |
| 204 | * |
| 205 | * @return boolean True if user was referred from an admin page, false otherwise |
| 206 | */ |
| 207 | private function is_valid_request(){ |
| 208 | $adminurl = strtolower( admin_url() ); |
| 209 | $referer = strtolower( wp_get_referer() ); |
| 210 | $result = isset( $_REQUEST['_wpnonce'] ) ? wp_verify_nonce( $_REQUEST['_wpnonce'], 'auxin-import' ) : false; |
| 211 | |
| 212 | return $result && ( strpos( $referer, $adminurl ) === 0 ); |
| 213 | } |
| 214 | |
| 215 | } |
| 216 | |
| 217 |