| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExport\Compatibility; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils; |
| 6 |
use Elementor\Plugin; |
| 7 |
|
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit; // Exit if accessed directly. |
| 10 |
} |
| 11 |
|
| 12 |
class Envato extends Base_Adapter { |
| 13 |
public static function is_compatibility_needed( array $manifest_data, array $meta ) { |
| 14 |
return ! empty( $manifest_data['manifest_version'] ); |
| 15 |
} |
| 16 |
|
| 17 |
public function adapt_manifest( array $manifest_data ) { |
| 18 |
$templates = $manifest_data['templates']; |
| 19 |
|
| 20 |
$manifest_data['templates'] = []; |
| 21 |
|
| 22 |
foreach ( $templates as $template ) { |
| 23 |
// Envato store their global kit styles as a 'global.json' template file. |
| 24 |
// We need to be able to know the path to this specific 'global.json' since it functions as the site-settings.json |
| 25 |
$is_global = ! empty( $template['metadata']['template_type'] ) && 'global-styles' === $template['metadata']['template_type']; |
| 26 |
if ( $is_global ) { |
| 27 |
// Adding the path of the 'global.json' template to the manifest which will be used in the future. |
| 28 |
$manifest_data['path-to-envto-site-settings'] = $template['source']; |
| 29 |
|
| 30 |
// Getting the site-settings because Envato stores them in one of the posts. |
| 31 |
$kit = Plugin::$instance->kits_manager->get_active_kit(); |
| 32 |
$kit_tabs = $kit->get_tabs(); |
| 33 |
unset( $kit_tabs['settings-site-identity'] ); |
| 34 |
$manifest_data['site-settings'] = array_keys( $kit_tabs ); |
| 35 |
|
| 36 |
continue; |
| 37 |
} |
| 38 |
|
| 39 |
// Evanto uses "type" instead of "doc_type" |
| 40 |
$template['doc_type'] = $template['type']; |
| 41 |
|
| 42 |
// Evanto uses for "name" instead of "title" |
| 43 |
$template['title'] = $template['name']; |
| 44 |
|
| 45 |
// Envato specifying an exact path to the template rather than using its "ID" as an index. |
| 46 |
// This extracts the "file name" part out of our exact source list and we treat that as an ID. |
| 47 |
$file_name_without_extension = str_replace( '.json', '', basename( $template['source'] ) ); |
| 48 |
|
| 49 |
// Append the template to the global list: |
| 50 |
$manifest_data['templates'][ $file_name_without_extension ] = $template; |
| 51 |
} |
| 52 |
|
| 53 |
$manifest_data['name'] = $manifest_data['title']; |
| 54 |
|
| 55 |
return $manifest_data; |
| 56 |
} |
| 57 |
|
| 58 |
public function adapt_site_settings( array $site_settings, array $manifest_data, $path ) { |
| 59 |
if ( empty( $manifest_data['path-to-envto-site-settings'] ) ) { |
| 60 |
return $site_settings; |
| 61 |
} |
| 62 |
|
| 63 |
$global_file_path = $path . $manifest_data['path-to-envto-site-settings']; |
| 64 |
$global_file_data = ImportExportUtils::read_json_file( $global_file_path ); |
| 65 |
|
| 66 |
return [ |
| 67 |
'settings' => $global_file_data['page_settings'], |
| 68 |
]; |
| 69 |
} |
| 70 |
|
| 71 |
public function adapt_template( array $template_data, array $template_settings ) { |
| 72 |
if ( ! empty( $template_data['metadata']['elementor_pro_conditions'] ) ) { |
| 73 |
foreach ( $template_data['metadata']['elementor_pro_conditions'] as $condition ) { |
| 74 |
list ( $type, $name, $sub_name, $sub_id ) = array_pad( explode( '/', $condition ), 4, '' ); |
| 75 |
|
| 76 |
$template_data['import_settings']['conditions'][] = compact( 'type', 'name', 'sub_name', 'sub_id' ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
return $template_data; |
| 81 |
} |
| 82 |
} |
| 83 |
|