| @@ -11,12 +11,11 @@ | ||
| 11 | 11 | use Elementor\Plugin; |
| 12 | 12 | use Elementor\Tools; |
| 13 | 13 | use Elementor\Utils as ElementorUtils; |
| 14 | 14 | use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils; |
| 15 | -use Elementor\Modules\CloudKitLibrary\Module as CloudKitLibrary; | |
| 16 | 15 | |
| 17 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | - exit; // Exit if accessed directly. | |
| 17 | + exit; // Exit if accessed directly | |
| 19 | 18 | } |
| 20 | 19 | |
| 21 | 20 | /** |
| 22 | 21 | * Import Export Module |
| @@ -37,10 +36,8 @@ | ||
| 37 | 36 | const REFERRER_KIT_LIBRARY = 'kit-library'; |
| 38 | 37 | |
| 39 | 38 | const REFERRER_LOCAL = 'local'; |
| 40 | 39 | |
| 41 | - const REFERRER_CLOUD = 'cloud'; | |
| 42 | - | |
| 43 | 40 | const PLUGIN_PERMISSIONS_ERROR_KEY = 'plugin-installation-permissions-error'; |
| 44 | 41 | |
| 45 | 42 | const KIT_LIBRARY_ERROR_KEY = 'invalid-kit-library-zip-error'; |
| 46 | 43 | |
| @@ -57,10 +54,8 @@ | ||
| 57 | 54 | const META_KEY_ELEMENTOR_IMPORT_SESSION_ID = '_elementor_import_session_id'; |
| 58 | 55 | |
| 59 | 56 | const META_KEY_ELEMENTOR_EDIT_MODE = '_elementor_edit_mode'; |
| 60 | 57 | const IMPORT_PLUGINS_ACTION = 'import-plugins'; |
| 61 | - const EXPORT_SOURCE_CLOUD = 'cloud'; | |
| 62 | - const EXPORT_SOURCE_FILE = 'file'; | |
| 63 | 58 | |
| 64 | 59 | /** |
| 65 | 60 | * Assigning the export process to a property, so we can use the process from outside the class. |
| 66 | 61 | * |
| @@ -117,12 +112,12 @@ | ||
| 117 | 112 | * Register the import/export tab in elementor tools. |
| 118 | 113 | */ |
| 119 | 114 | public function register_settings_tab( Tools $tools ) { |
| 120 | 115 | $tools->add_tab( 'import-export-kit', [ |
| 121 | - 'label' => esc_html__( 'Website Templates', 'elementor' ), | |
| 116 | + 'label' => esc_html__( 'Import / Export Kit', 'elementor' ), | |
| 122 | 117 | 'sections' => [ |
| 123 | 118 | 'intro' => [ |
| 124 | - 'label' => esc_html__( 'Website Templates', 'elementor' ), | |
| 119 | + 'label' => esc_html__( 'Template Kits', 'elementor' ), | |
| 125 | 120 | 'callback' => function() { |
| 126 | 121 | $this->render_import_export_tab_content(); |
| 127 | 122 | }, |
| 128 | 123 | 'fields' => [], |
| @@ -134,39 +129,44 @@ | ||
| 134 | 129 | /** |
| 135 | 130 | * Render the import/export tab content. |
| 136 | 131 | */ |
| 137 | 132 | private function render_import_export_tab_content() { |
| 138 | - $is_cloud_kits_available = CloudKitLibrary::get_app()->check_eligibility()['is_eligible']; | |
| 133 | + $intro_text_link = sprintf( '<a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%s</a>', esc_html__( 'Learn more', 'elementor' ) ); | |
| 139 | 134 | |
| 135 | + $intro_text = sprintf( | |
| 136 | + /* translators: 1: New line break, 2: Learn more link. */ | |
| 137 | + __( 'Design sites faster with a template kit that contains some or all components of a complete site, like templates, content & site settings.%1$sYou can import a kit and apply it to your site, or export the elements from this site to be used anywhere else. %2$s', 'elementor' ), | |
| 138 | + '<br>', | |
| 139 | + $intro_text_link | |
| 140 | + ); | |
| 141 | + | |
| 140 | 142 | $content_data = [ |
| 141 | 143 | 'export' => [ |
| 142 | - 'title' => esc_html__( 'Export this website', 'elementor' ), | |
| 144 | + 'title' => esc_html__( 'Export a Template Kit', 'elementor' ), | |
| 143 | 145 | 'button' => [ |
| 144 | 146 | 'url' => Plugin::$instance->app->get_base_url() . '#/export', |
| 145 | - 'text' => esc_html__( 'Export', 'elementor' ), | |
| 146 | - 'id' => 'elementor-import-export__export', | |
| 147 | + 'text' => esc_html__( 'Start Export', 'elementor' ), | |
| 147 | 148 | ], |
| 148 | - 'description' => esc_html__( 'You can download this website as a .zip file, or upload it to the library.', 'elementor' ), | |
| 149 | + 'description' => esc_html__( 'Bundle your whole site - or just some of its elements - to be used for another website.', 'elementor' ), | |
| 150 | + 'link' => [ | |
| 151 | + 'url' => 'https://go.elementor.com/wp-dash-import-export-export-flow/', | |
| 152 | + 'text' => esc_html__( 'Learn More', 'elementor' ), | |
| 153 | + ], | |
| 149 | 154 | ], |
| 150 | 155 | 'import' => [ |
| 151 | - 'title' => esc_html__( 'Import website templates', 'elementor' ), | |
| 156 | + 'title' => esc_html__( 'Import a Template Kit', 'elementor' ), | |
| 152 | 157 | 'button' => [ |
| 153 | 158 | 'url' => Plugin::$instance->app->get_base_url() . '#/import', |
| 154 | - 'text' => esc_html__( 'Import', 'elementor' ), | |
| 155 | - 'id' => 'elementor-import-export__import', | |
| 159 | + 'text' => esc_html__( 'Start Import', 'elementor' ), | |
| 156 | 160 | ], |
| 157 | - 'description' => esc_html__( 'You can import design and settings from a .zip file or choose from the library.', 'elementor' ), | |
| 161 | + 'description' => esc_html__( 'Apply the design and settings of another site to this one.', 'elementor' ), | |
| 162 | + 'link' => [ | |
| 163 | + 'url' => 'https://go.elementor.com/wp-dash-import-export-import-flow/', | |
| 164 | + 'text' => esc_html__( 'Learn More', 'elementor' ), | |
| 165 | + ], | |
| 158 | 166 | ], |
| 159 | 167 | ]; |
| 160 | 168 | |
| 161 | - if ( $is_cloud_kits_available ) { | |
| 162 | - $content_data['import']['button_secondary'] = [ | |
| 163 | - 'url' => Plugin::$instance->app->get_base_url() . '#/kit-library/cloud', | |
| 164 | - 'text' => esc_html__( 'Import from library', 'elementor' ), | |
| 165 | - 'id' => 'elementor-import-export__import_from_library', | |
| 166 | - ]; | |
| 167 | - } | |
| 168 | - | |
| 169 | 169 | $last_imported_kit = $this->revert->get_last_import_session(); |
| 170 | 170 | $penultimate_imported_kit = $this->revert->get_penultimate_import_session(); |
| 171 | 171 | |
| 172 | 172 | $user_date_format = get_option( 'date_format' ); |
| @@ -177,9 +177,8 @@ | ||
| 177 | 177 | |
| 178 | 178 | if ( $should_show_revert_section ) { |
| 179 | 179 | if ( ! empty( $penultimate_imported_kit ) ) { |
| 180 | 180 | $revert_text = sprintf( |
| 181 | - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>, 4: Penultimate imported kit title, 5: Penultimate imported kit date. */ | |
| 182 | 181 | esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s %3$s and revert to the site setting that came with "%4$s" on %5$s.', 'elementor' ), |
| 183 | 182 | ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ), |
| 184 | 183 | gmdate( $date_format, $last_imported_kit['start_timestamp'] ), |
| 185 | 184 | '<br>', |
| @@ -187,9 +186,8 @@ | ||
| 187 | 186 | gmdate( $date_format, $penultimate_imported_kit['start_timestamp'] ) |
| 188 | 187 | ); |
| 189 | 188 | } else { |
| 190 | 189 | $revert_text = sprintf( |
| 191 | - /* translators: 1: Last imported kit title, 2: Last imported kit date, 3: Line break <br>. */ | |
| 192 | 190 | esc_html__( 'Remove all the content and site settings that came with "%1$s" on %2$s.%3$s Your original site settings will be restored.', 'elementor' ), |
| 193 | 191 | ! empty( $last_imported_kit['kit_title'] ) ? $last_imported_kit['kit_title'] : esc_html__( 'imported kit', 'elementor' ), |
| 194 | 192 | gmdate( $date_format, $last_imported_kit['start_timestamp'] ), |
| 195 | 193 | '<br>' |
| @@ -198,22 +196,23 @@ | ||
| 198 | 196 | } |
| 199 | 197 | ?> |
| 200 | 198 | |
| 201 | 199 | <div class="tab-import-export-kit__content"> |
| 202 | - <p class="tab-import-export-kit__info"> | |
| 203 | - <?php | |
| 204 | - printf( | |
| 205 | - '%1$s <a href="https://go.elementor.com/wp-dash-import-export-general/" target="_blank">%2$s</a>', | |
| 206 | - esc_html__( 'Here’s where you can export this website as a .zip file, upload it to the cloud, or start the process of applying an existing template to your site.', 'elementor' ), | |
| 207 | - esc_html__( 'Learn more', 'elementor' ), | |
| 208 | - ); | |
| 209 | - ?> | |
| 210 | - </p> | |
| 200 | + <p class="tab-import-export-kit__info"><?php ElementorUtils::print_unescaped_internal_string( $intro_text ); ?></p> | |
| 211 | 201 | |
| 212 | 202 | <div class="tab-import-export-kit__wrapper"> |
| 213 | - <?php foreach ( $content_data as $data ) { | |
| 214 | - $this->print_item_content( $data ); | |
| 215 | - } ?> | |
| 203 | + <?php foreach ( $content_data as $data ) { ?> | |
| 204 | + <div class="tab-import-export-kit__container"> | |
| 205 | + <div class="tab-import-export-kit__box"> | |
| 206 | + <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2> | |
| 207 | + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary"> | |
| 208 | + <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?> | |
| 209 | + </a> | |
| 210 | + </div> | |
| 211 | + <p><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p> | |
| 212 | + <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a> | |
| 213 | + </div> | |
| 214 | + <?php } ?> | |
| 216 | 215 | </div> |
| 217 | 216 | |
| 218 | 217 | <?php |
| 219 | 218 | if ( $should_show_revert_section ) { |
| @@ -225,9 +224,9 @@ | ||
| 225 | 224 | ]; |
| 226 | 225 | ?> |
| 227 | 226 | <div class="tab-import-export-kit__revert"> |
| 228 | 227 | <h2> |
| 229 | - <?php echo esc_html__( 'Remove the most recent Website Template', 'elementor' ); ?> | |
| 228 | + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove the most recent Kit', 'elementor' ) ); ?> | |
| 230 | 229 | </h2> |
| 231 | 230 | <p class="tab-import-export-kit__info"> |
| 232 | 231 | <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?> |
| 233 | 232 | </p> |
| @@ -232,9 +231,9 @@ | ||
| 232 | 231 | <?php ElementorUtils::print_unescaped_internal_string( $revert_text ); ?> |
| 233 | 232 | </p> |
| 234 | 233 | <?php $this->render_last_kit_thumbnail( $last_imported_kit ); ?> |
| 235 | 234 | <a <?php ElementorUtils::print_html_attributes( $link_attributes ); ?> > |
| 236 | - <?php echo esc_html__( 'Remove Website Template', 'elementor' ); ?> | |
| 235 | + <?php ElementorUtils::print_unescaped_internal_string( esc_html__( 'Remove Kit', 'elementor' ) ); ?> | |
| 237 | 236 | </a> |
| 238 | 237 | </div> |
| 239 | 238 | <?php } ?> |
| 240 | 239 | </div> |
| @@ -240,33 +239,8 @@ | ||
| 240 | 239 | </div> |
| 241 | 240 | <?php |
| 242 | 241 | } |
| 243 | 242 | |
| 244 | - private function print_item_content( $data ) { | |
| 245 | - ?> | |
| 246 | - <div class="tab-import-export-kit__container"> | |
| 247 | - <div class="tab-import-export-kit__box"> | |
| 248 | - <h2><?php ElementorUtils::print_unescaped_internal_string( $data['title'] ); ?></h2> | |
| 249 | - </div> | |
| 250 | - <p class="description"><?php ElementorUtils::print_unescaped_internal_string( $data['description'] ); ?></p> | |
| 251 | - | |
| 252 | - <?php if ( ! empty( $data['link'] ) ) : ?> | |
| 253 | - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['link']['url'] ); ?>" target="_blank"><?php ElementorUtils::print_unescaped_internal_string( $data['link']['text'] ); ?></a> | |
| 254 | - <?php endif; ?> | |
| 255 | - <div class="tab-import-export-kit__box action-buttons"> | |
| 256 | - <?php if ( ! empty( $data['button_secondary'] ) ) : ?> | |
| 257 | - <a href="<?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['url'] ); ?>" class="elementor-button e-btn-txt e-btn-txt-border"> | |
| 258 | - <?php ElementorUtils::print_unescaped_internal_string( $data['button_secondary']['text'] ); ?> | |
| 259 | - </a> | |
| 260 | - <?php endif; ?> | |
| 261 | - <a <?php ElementorUtils::print_html_attributes( [ 'id' => $data['button']['id'] ] ); ?> href="<?php ElementorUtils::print_unescaped_internal_string( $data['button']['url'] ); ?>" class="elementor-button e-primary"> | |
| 262 | - <?php ElementorUtils::print_unescaped_internal_string( $data['button']['text'] ); ?> | |
| 263 | - </a> | |
| 264 | - </div> | |
| 265 | - </div> | |
| 266 | - <?php | |
| 267 | - } | |
| 268 | - | |
| 269 | 243 | private function get_revert_href(): string { |
| 270 | 244 | $admin_post_url = admin_url( 'admin-post.php?action=elementor_revert_kit' ); |
| 271 | 245 | $nonced_admin_post_url = wp_nonce_url( $admin_post_url, 'elementor_revert_kit' ); |
| 272 | 246 | return $this->maybe_add_referrer_param( $nonced_admin_post_url ); |
| @@ -326,19 +300,15 @@ | ||
| 326 | 300 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| 327 | 301 | * |
| 328 | 302 | * @param string $file Path to the file. |
| 329 | 303 | * @param string $referrer Referrer of the file 'local' or 'kit-library'. |
| 330 | - * @param string $kit_id | |
| 331 | 304 | * @return array |
| 332 | - * @throws \Exception If export validation fails or processing errors occur. | |
| 305 | + * @throws \Exception | |
| 333 | 306 | */ |
| 334 | - public function upload_kit( $file, $referrer, $kit_id = null ) { | |
| 307 | + public function upload_kit( $file, $referrer ) { | |
| 335 | 308 | $this->ensure_writing_permissions(); |
| 336 | 309 | |
| 337 | - $this->import = new Import( $file, [ | |
| 338 | - 'referrer' => $referrer, | |
| 339 | - 'id' => $kit_id, | |
| 340 | - ] ); | |
| 310 | + $this->import = new Import( $file, [ 'referrer' => $referrer ] ); | |
| 341 | 311 | |
| 342 | 312 | return [ |
| 343 | 313 | 'session' => $this->import->get_session_id(), |
| 344 | 314 | 'manifest' => $this->import->get_manifest(), |
| @@ -356,13 +326,13 @@ | ||
| 356 | 326 | * Assigning the Import process to the 'import' property, |
| 357 | 327 | * so it will be available to use in different places such as: WP_Cli, Pro, etc. |
| 358 | 328 | * |
| 359 | 329 | * @param string $path Path to the file or session_id. |
| 360 | - * @param array $settings Settings the import use to determine which content to import. | |
| 361 | - * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 362 | - * @param bool $split_to_chunks Determine if the import process should be split into chunks. | |
| 330 | + * @param array $settings Settings the import use to determine which content to import. | |
| 331 | + * (e.g: include, selected_plugins, selected_cpt, selected_override_conditions, etc.) | |
| 332 | + * @param bool $split_to_chunks Determine if the import process should be split into chunks. | |
| 363 | 333 | * @return array |
| 364 | - * @throws \Exception If export configuration is invalid or processing fails. | |
| 334 | + * @throws \Exception | |
| 365 | 335 | */ |
| 366 | 336 | public function import_kit( string $path, array $settings, bool $split_to_chunks = false ): array { |
| 367 | 337 | $this->ensure_writing_permissions(); |
| 368 | 338 | $this->ensure_DOMDocument_exists(); |
| @@ -393,9 +363,9 @@ | ||
| 393 | 363 | * |
| 394 | 364 | * @return array Two types of response. |
| 395 | 365 | * 1. The status and the runner name. |
| 396 | 366 | * 2. The imported data. (Only if the runner is the last one in the import process) |
| 397 | - * @throws \Exception If import configuration is invalid or processing fails. | |
| 367 | + * @throws \Exception | |
| 398 | 368 | */ |
| 399 | 369 | public function import_kit_by_runner( string $session_id, string $runner_name ): array { |
| 400 | 370 | // Check session_id |
| 401 | 371 | $this->import = Import::from_session( $session_id ); |
| @@ -418,9 +388,9 @@ | ||
| 418 | 388 | * |
| 419 | 389 | * @param array $settings Settings the export use to determine which content to export. |
| 420 | 390 | * (e.g: include, kit_info, selected_plugins, selected_cpt, etc.) |
| 421 | 391 | * @return array |
| 422 | - * @throws \Exception If import/export process fails or validation errors occur. | |
| 392 | + * @throws \Exception | |
| 423 | 393 | */ |
| 424 | 394 | public function export_kit( array $settings ) { |
| 425 | 395 | $this->ensure_writing_permissions(); |
| 426 | 396 | |
| @@ -474,13 +444,11 @@ | ||
| 474 | 444 | add_action( 'admin_post_elementor_revert_kit', [ $this, 'handle_revert_last_imported_kit' ] ); |
| 475 | 445 | |
| 476 | 446 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); |
| 477 | 447 | |
| 478 | - if ( ! Plugin::$instance->experiments->is_feature_active( 'import-export-customization' ) ) { | |
| 479 | - $page_id = Tools::PAGE_ID; | |
| 448 | + $page_id = Tools::PAGE_ID; | |
| 480 | 449 | |
| 481 | - add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] ); | |
| 482 | - } | |
| 450 | + add_action( "elementor/admin/after_create_settings/{$page_id}", [ $this, 'register_settings_tab' ] ); | |
| 483 | 451 | |
| 484 | 452 | // TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done. |
| 485 | 453 | if ( self::IMPORT_PLUGINS_ACTION === ElementorUtils::get_super_global_value( $_SERVER, 'HTTP_X_ELEMENTOR_ACTION' ) ) { |
| 486 | 454 | add_filter( 'woocommerce_create_pages', [ $this, 'empty_pages' ], 10, 0 ); |
| @@ -485,20 +453,8 @@ | ||
| 485 | 453 | if ( self::IMPORT_PLUGINS_ACTION === ElementorUtils::get_super_global_value( $_SERVER, 'HTTP_X_ELEMENTOR_ACTION' ) ) { |
| 486 | 454 | add_filter( 'woocommerce_create_pages', [ $this, 'empty_pages' ], 10, 0 ); |
| 487 | 455 | } |
| 488 | 456 | // TODO ^^^ |
| 489 | - | |
| 490 | - add_filter( 'elementor/import/kit/result', function( $result ) { | |
| 491 | - if ( ! empty( $result['file_url'] ) ) { | |
| 492 | - return [ | |
| 493 | - 'file_name' => $this->get_remote_kit_zip( $result['file_url'] ), | |
| 494 | - 'referrer' => static::REFERRER_KIT_LIBRARY, | |
| 495 | - 'file_url' => $result['file_url'], | |
| 496 | - ]; | |
| 497 | - } | |
| 498 | - | |
| 499 | - return $result; | |
| 500 | - } ); | |
| 501 | 457 | } |
| 502 | 458 | |
| 503 | 459 | /** |
| 504 | 460 | * Prevent the creation of the default WooCommerce pages (Cart, Checkout, etc.) |
| @@ -503,9 +459,8 @@ | ||
| 503 | 459 | /** |
| 504 | 460 | * Prevent the creation of the default WooCommerce pages (Cart, Checkout, etc.) |
| 505 | 461 | * |
| 506 | 462 | * TODO 18/04/2023 : This needs to be moved to the runner itself after https://elementor.atlassian.net/browse/HTS-434 is done. |
| 507 | - * | |
| 508 | 463 | * @return array |
| 509 | 464 | */ |
| 510 | 465 | public function empty_pages(): array { |
| 511 | 466 | return []; |
| @@ -523,14 +478,14 @@ | ||
| 523 | 478 | $permissions = $server->get_paths_permissions( $paths_to_check ); |
| 524 | 479 | |
| 525 | 480 | // WP Content dir has to be exists and writable. |
| 526 | 481 | if ( ! $permissions[ Server::KEY_PATH_WP_CONTENT_DIR ]['write'] ) { |
| 527 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 482 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 528 | 483 | } |
| 529 | 484 | |
| 530 | 485 | // WP Uploads dir has to be exists and writable. |
| 531 | 486 | if ( ! $permissions[ Server::KEY_PATH_UPLOADS_DIR ]['write'] ) { |
| 532 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 487 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 533 | 488 | } |
| 534 | 489 | |
| 535 | 490 | // Elementor uploads dir permissions is divided to 2 cases: |
| 536 | 491 | // 1. If the dir exists, it has to be writable. |
| @@ -535,15 +490,15 @@ | ||
| 535 | 490 | // Elementor uploads dir permissions is divided to 2 cases: |
| 536 | 491 | // 1. If the dir exists, it has to be writable. |
| 537 | 492 | // 2. If the dir doesn't exist, the parent dir has to be writable (wp uploads dir), so we can create it. |
| 538 | 493 | if ( $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['exists'] && ! $permissions[ Server::KEY_PATH_ELEMENTOR_UPLOADS_DIR ]['write'] ) { |
| 539 | - throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 494 | + throw new \Error( self::NO_WRITE_PERMISSIONS_KEY ); | |
| 540 | 495 | } |
| 541 | 496 | } |
| 542 | 497 | |
| 543 | 498 | private function ensure_DOMDocument_exists() { |
| 544 | 499 | if ( ! class_exists( 'DOMDocument' ) ) { |
| 545 | - throw new \Error( self::DOMDOCUMENT_MISSING ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 500 | + throw new \Error( self::DOMDOCUMENT_MISSING ); | |
| 546 | 501 | } |
| 547 | 502 | } |
| 548 | 503 | |
| 549 | 504 | /** |
| @@ -616,10 +571,8 @@ | ||
| 616 | 571 | } |
| 617 | 572 | |
| 618 | 573 | /** |
| 619 | 574 | * Handle upload kit ajax request. |
| 620 | - * | |
| 621 | - * @throws \Error If operation validation fails or processing errors occur. | |
| 622 | 575 | */ |
| 623 | 576 | private function handle_upload_kit() { |
| 624 | 577 | // PHPCS - A URL that should contain special chars (auth headers information). |
| 625 | 578 | $file_url = isset( $_POST['e_import_file'] ) |
| @@ -626,15 +579,10 @@ | ||
| 626 | 579 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 627 | 580 | ? wp_unslash( $_POST['e_import_file'] ) |
| 628 | 581 | : ''; |
| 629 | 582 | |
| 630 | - // PHPCS - Already validated in caller function | |
| 631 | - $kit_id = ElementorUtils::get_super_global_value( $_POST, 'kit_id' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 632 | - $source = ElementorUtils::get_super_global_value( $_POST, 'source' ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 633 | - | |
| 634 | - $is_import_from_library = ! empty( $file_url ); | |
| 635 | - | |
| 636 | - if ( $is_import_from_library ) { | |
| 583 | + // Import from kit library | |
| 584 | + if ( ! empty( $file_url ) ) { | |
| 637 | 585 | if ( |
| 638 | 586 | ! wp_verify_nonce( ElementorUtils::get_super_global_value( $_POST, 'e_kit_library_nonce' ), 'kit-library-import' ) |
| 639 | 587 | ) { |
| 640 | 588 | throw new \Error( 'Invalid kit library nonce.' ); |
| @@ -640,59 +588,57 @@ | ||
| 640 | 588 | throw new \Error( 'Invalid kit library nonce.' ); |
| 641 | 589 | } |
| 642 | 590 | |
| 643 | 591 | if ( ! filter_var( $file_url, FILTER_VALIDATE_URL ) || 0 !== strpos( $file_url, 'http' ) ) { |
| 644 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 592 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 645 | 593 | } |
| 646 | 594 | |
| 647 | - $import_result = apply_filters( 'elementor/import/kit/result', [ 'file_url' => $file_url ] ); | |
| 648 | - } elseif ( ! empty( $source ) ) { | |
| 649 | - $import_result = apply_filters( 'elementor/import/kit/result/' . $source, [ | |
| 650 | - 'kit_id' => $kit_id, | |
| 651 | - 'source' => $source, | |
| 652 | - ] ); | |
| 595 | + $remote_zip_request = wp_safe_remote_get( $file_url ); | |
| 596 | + | |
| 597 | + if ( is_wp_error( $remote_zip_request ) ) { | |
| 598 | + Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() ); | |
| 599 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 600 | + } | |
| 601 | + | |
| 602 | + if ( 200 !== $remote_zip_request['response']['code'] ) { | |
| 603 | + Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] ); | |
| 604 | + throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); | |
| 605 | + } | |
| 606 | + | |
| 607 | + $file_name = Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); | |
| 608 | + $referrer = static::REFERRER_KIT_LIBRARY; | |
| 653 | 609 | } else { |
| 654 | - $import_result = [ | |
| 655 | - 'file_name' => ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name'], | |
| 656 | - 'referrer' => static::REFERRER_LOCAL, | |
| 657 | - ]; | |
| 610 | + // PHPCS - Already validated in caller function. | |
| 611 | + $file_name = ElementorUtils::get_super_global_value( $_FILES, 'e_import_file' )['tmp_name']; | |
| 612 | + $referrer = static::REFERRER_LOCAL; | |
| 658 | 613 | } |
| 659 | 614 | |
| 660 | 615 | Plugin::$instance->logger->get_logger()->info( 'Uploading Kit: ', [ |
| 661 | 616 | 'meta' => [ |
| 662 | - 'kit_id' => $kit_id, | |
| 663 | - 'referrer' => $import_result['referrer'], | |
| 617 | + 'kit_id' => ElementorUtils::get_super_global_value( $_POST, 'kit_id' ), | |
| 618 | + 'referrer' => $referrer, | |
| 664 | 619 | ], |
| 665 | 620 | ] ); |
| 666 | 621 | |
| 667 | - if ( is_wp_error( $import_result ) ) { | |
| 668 | - wp_send_json_error( $import_result->get_error_message() ); | |
| 669 | - } | |
| 622 | + $uploaded_kit = $this->upload_kit( $file_name, $referrer ); | |
| 670 | 623 | |
| 671 | - $uploaded_kit = $this->upload_kit( $import_result['file_name'], $import_result['referrer'], $kit_id ); | |
| 672 | - | |
| 673 | 624 | $session_dir = $uploaded_kit['session']; |
| 674 | 625 | $manifest = $uploaded_kit['manifest']; |
| 675 | 626 | $conflicts = $uploaded_kit['conflicts']; |
| 676 | 627 | |
| 677 | - if ( $is_import_from_library || ! empty( $source ) ) { | |
| 678 | - Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $import_result['file_name'] ) ); | |
| 628 | + if ( ! empty( $file_url ) ) { | |
| 629 | + Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); | |
| 679 | 630 | } |
| 680 | 631 | |
| 681 | 632 | if ( isset( $manifest['plugins'] ) && ! current_user_can( 'install_plugins' ) ) { |
| 682 | - throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 633 | + throw new \Error( static::PLUGIN_PERMISSIONS_ERROR_KEY ); | |
| 683 | 634 | } |
| 684 | 635 | |
| 685 | 636 | $result = [ |
| 686 | 637 | 'session' => $session_dir, |
| 687 | 638 | 'manifest' => $manifest, |
| 688 | - 'file_url' => $import_result['file_url'], | |
| 689 | 639 | ]; |
| 690 | 640 | |
| 691 | - if ( ! empty( $import_result['kit'] ) ) { | |
| 692 | - $result['uploaded_kit'] = $import_result['kit']; | |
| 693 | - } | |
| 694 | - | |
| 695 | 641 | if ( ! empty( $conflicts ) ) { |
| 696 | 642 | $result['conflicts'] = $conflicts; |
| 697 | 643 | } else { |
| 698 | 644 | // Moved into the IE process \Elementor\App\Modules\ImportExport\Processes\Import::get_default_settings_conflicts |
| @@ -702,24 +648,8 @@ | ||
| 702 | 648 | |
| 703 | 649 | wp_send_json_success( $result ); |
| 704 | 650 | } |
| 705 | 651 | |
| 706 | - protected function get_remote_kit_zip( $url ) { | |
| 707 | - $remote_zip_request = wp_safe_remote_get( $url ); | |
| 708 | - | |
| 709 | - if ( is_wp_error( $remote_zip_request ) ) { | |
| 710 | - Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() ); | |
| 711 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 712 | - } | |
| 713 | - | |
| 714 | - if ( 200 !== $remote_zip_request['response']['code'] ) { | |
| 715 | - Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] ); | |
| 716 | - throw new \Error( static::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped | |
| 717 | - } | |
| 718 | - | |
| 719 | - return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' ); | |
| 720 | - } | |
| 721 | - | |
| 722 | 652 | /** |
| 723 | 653 | * Handle import kit ajax request. |
| 724 | 654 | */ |
| 725 | 655 | private function handle_import_kit() { |
| @@ -763,27 +693,20 @@ | ||
| 763 | 693 | ) |
| 764 | 694 | ); |
| 765 | 695 | } |
| 766 | 696 | |
| 767 | - do_action( 'elementor/import-export/import-kit/runner/after-run', $import ); | |
| 768 | - | |
| 769 | 697 | wp_send_json_success( $import ); |
| 770 | 698 | } |
| 771 | 699 | |
| 772 | 700 | /** |
| 773 | 701 | * Handle export kit ajax request. |
| 774 | - * | |
| 775 | - * @throws \Error If cleanup process fails or file system errors occur. | |
| 776 | 702 | */ |
| 777 | 703 | private function handle_export_kit() { |
| 778 | 704 | // PHPCS - Already validated in caller function |
| 779 | 705 | $settings = json_decode( ElementorUtils::get_super_global_value( $_POST, 'data' ), true ); // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 780 | - $source = $settings['kitInfo']['source']; | |
| 781 | - | |
| 782 | 706 | $export = $this->export_kit( $settings ); |
| 783 | 707 | |
| 784 | 708 | $file_name = $export['file_name']; |
| 785 | - $file_size = filesize( $file_name ); | |
| 786 | 709 | $file = ElementorUtils::file_get_contents( $file_name ); |
| 787 | 710 | |
| 788 | 711 | if ( ! $file ) { |
| 789 | 712 | throw new \Error( 'Could not read the exported file.' ); |
| @@ -790,25 +713,13 @@ | ||
| 790 | 713 | } |
| 791 | 714 | |
| 792 | 715 | Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); |
| 793 | 716 | |
| 794 | - $result = apply_filters( | |
| 795 | - 'elementor/export/kit/export-result', | |
| 796 | - [ | |
| 797 | - 'manifest' => $export['manifest'], | |
| 798 | - 'file' => base64_encode( $file ), | |
| 799 | - ], | |
| 800 | - $source, | |
| 801 | - $export, | |
| 802 | - $settings, | |
| 803 | - $file, | |
| 804 | - $file_size, | |
| 805 | - ); | |
| 717 | + $result = [ | |
| 718 | + 'manifest' => $export['manifest'], | |
| 719 | + 'file' => base64_encode( $file ), | |
| 720 | + ]; | |
| 806 | 721 | |
| 807 | - if ( is_wp_error( $result ) ) { | |
| 808 | - wp_send_json_error( $result ); | |
| 809 | - } | |
| 810 | - | |
| 811 | 722 | wp_send_json_success( $result ); |
| 812 | 723 | } |
| 813 | 724 | |
| 814 | 725 | /** |
| @@ -828,9 +739,8 @@ | ||
| 828 | 739 | 'recentlyEditedElementorPageUrl' => $this->get_recently_edited_elementor_page_url(), |
| 829 | 740 | 'tools_url' => Tools::get_url(), |
| 830 | 741 | 'importSessions' => Revert::get_import_sessions(), |
| 831 | 742 | 'lastImportedSession' => $this->revert->get_last_import_session(), |
| 832 | - 'kitPreviewNonce' => wp_create_nonce( 'kit_thumbnail' ), | |
| 833 | 743 | ]; |
| 834 | 744 | } |
| 835 | 745 | |
| 836 | 746 | /** |
| @@ -895,11 +805,11 @@ | ||
| 895 | 805 | return false; |
| 896 | 806 | } |
| 897 | 807 | |
| 898 | 808 | // TODO: BC - remove in the future |
| 899 | - // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC) | |
| 900 | - // The runner that is in the core version is missing the revert functionality, | |
| 901 | - // therefore we shouldn't display the revert section if the import process done with the core version. | |
| 809 | + // The 'templates' runner was in core and moved to the Pro plugin. (Part of it still exits in the Core for BC) | |
| 810 | + // The runner that is in the core version is missing the revert functionality, | |
| 811 | + // therefore we shouldn't display the revert section if the import process done with the core version. | |
| 902 | 812 | $is_import_templates_ran = isset( $last_imported_kit['runners']['templates'] ); |
| 903 | 813 | if ( $this->has_pro() && $is_import_templates_ran ) { |
| 904 | 814 | $has_imported_templates = ! empty( $last_imported_kit['runners']['templates'] ); |
| 905 | 815 | |
| @@ -975,13 +885,13 @@ | ||
| 975 | 885 | return $document ? $document->get_edit_url() : ''; |
| 976 | 886 | } |
| 977 | 887 | |
| 978 | 888 | /** |
| 979 | - * @param string $class_name | |
| 889 | + * @param string $class | |
| 980 | 890 | * |
| 981 | 891 | * @return bool |
| 982 | 892 | */ |
| 983 | - public function is_third_party_class( $class_name ) { | |
| 893 | + public function is_third_party_class( $class ) { | |
| 984 | 894 | $allowed_classes = [ |
| 985 | 895 | 'Elementor\\', |
| 986 | 896 | 'ElementorPro\\', |
| 987 | 897 | 'WP_', |
| @@ -988,9 +898,9 @@ | ||
| 988 | 898 | 'wp_', |
| 989 | 899 | ]; |
| 990 | 900 | |
| 991 | 901 | foreach ( $allowed_classes as $allowed_class ) { |
| 992 | - if ( str_starts_with( $class_name, $allowed_class ) ) { | |
| 902 | + if ( str_starts_with( $class, $allowed_class ) ) { | |
| 993 | 903 | return false; |
| 994 | 904 | } |
| 995 | 905 | } |
| 996 | 906 | |