| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Modules\GlobalClasses\ImportExportCustomization\Runners; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Design_System_Import_Context; |
| 6 |
use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Import_Runner_Base; |
| 7 |
use Elementor\Modules\GlobalClasses\ImportExportCustomization\Import_Export_Customization; |
| 8 |
use Elementor\Modules\GlobalClasses\ImportExportUtils\Import_Utils; |
| 9 |
use Elementor\Plugin; |
| 10 |
use Elementor\Core\Kits\Documents\Kit; |
| 11 |
use Elementor\Modules\GlobalClasses\ImportExportUtils\Legacy_Import_Utils; |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
class Import extends Import_Runner_Base { |
| 18 |
public static function get_name(): string { |
| 19 |
return 'global-classes'; |
| 20 |
} |
| 21 |
|
| 22 |
public function should_import( array $data ): bool { |
| 23 |
$import_context = Design_System_Import_Context::from_data( $data ); |
| 24 |
|
| 25 |
return ( |
| 26 |
$import_context->is_included() && |
| 27 |
! empty( $data['extracted_directory_path'] ) && |
| 28 |
$this->is_classes_enabled( $data ) |
| 29 |
); |
| 30 |
} |
| 31 |
|
| 32 |
private function is_classes_enabled( array $data ): bool { |
| 33 |
if ( isset( $data['customization']['settings']['classes'] ) ) { |
| 34 |
return (bool) $data['customization']['settings']['classes']; |
| 35 |
} |
| 36 |
|
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
public function import( array $data, array $imported_data ): array { |
| 41 |
$import_context = Design_System_Import_Context::from_data( $data ); |
| 42 |
$conflict_resolution = $import_context->resolve_conflict_resolution( $data, 'classesOverrideAll' ); |
| 43 |
|
| 44 |
if ( $this->is_legacy_import_format( $data ) ) { |
| 45 |
$global_classes_file = $data['extracted_directory_path'] . '/' . Import_Export_Customization::FILE_NAME . '.json'; |
| 46 |
return Legacy_Import_Utils::import_classes( $global_classes_file, $conflict_resolution ); |
| 47 |
} |
| 48 |
|
| 49 |
$global_classes_dir = $data['extracted_directory_path'] . '/' . Import_Export_Customization::DIRECTORY_NAME; |
| 50 |
return Import_Utils::import_classes( $global_classes_dir, [ 'conflict_resolution' => $conflict_resolution ] ); |
| 51 |
} |
| 52 |
|
| 53 |
protected function is_legacy_import_format( array $data ): bool { |
| 54 |
$manifest = $data['manifest']; |
| 55 |
$elementor_version = $manifest['elementor_version']; |
| 56 |
|
| 57 |
return version_compare( $elementor_version, '4.1.0-beta1', '<' ); |
| 58 |
} |
| 59 |
} |
| 60 |
|