| 1 |
<?php |
| 2 |
namespace Elementor\App\Modules\ImportExportCustomization\Data\Routes; |
| 3 |
|
| 4 |
use Elementor\Plugin; |
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Data\Response; |
| 6 |
use Elementor\Utils as ElementorUtils; |
| 7 |
|
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; // Exit if accessed directly. |
| 11 |
} |
| 12 |
|
| 13 |
class Export extends Base_Route { |
| 14 |
|
| 15 |
protected function get_route(): string { |
| 16 |
return 'export'; |
| 17 |
} |
| 18 |
|
| 19 |
protected function get_method(): string { |
| 20 |
return \WP_REST_Server::CREATABLE; |
| 21 |
} |
| 22 |
|
| 23 |
protected function callback( $request ): \WP_REST_Response { |
| 24 |
try { |
| 25 |
$settings = [ |
| 26 |
'include' => $request->get_param( 'include' ), |
| 27 |
'kitInfo' => $request->get_param( 'kitInfo' ), |
| 28 |
'screenShotBlob' => $request->get_param( 'screenShotBlob' ), |
| 29 |
'customization' => $request->get_param( 'customization' ), |
| 30 |
'plugins' => $request->get_param( 'plugins' ), |
| 31 |
'selectedCustomPostTypes' => $request->get_param( 'selectedCustomPostTypes' ), |
| 32 |
]; |
| 33 |
|
| 34 |
$settings = array_filter( $settings ); |
| 35 |
|
| 36 |
$source = $settings['kitInfo']['source']; |
| 37 |
|
| 38 |
$module = Plugin::$instance->app->get_component( 'import-export-customization' ); |
| 39 |
|
| 40 |
$export = $module->export_kit( $settings ); |
| 41 |
|
| 42 |
$file_name = $export['file_name']; |
| 43 |
$file = ElementorUtils::file_get_contents( $file_name ); |
| 44 |
|
| 45 |
if ( ! $file ) { |
| 46 |
throw new \Error( 'Could not read the exported file.' ); |
| 47 |
} |
| 48 |
|
| 49 |
Plugin::$instance->uploads_manager->remove_file_or_dir( dirname( $file_name ) ); |
| 50 |
|
| 51 |
$result = apply_filters( |
| 52 |
'elementor/export/kit/export-result', |
| 53 |
[ |
| 54 |
'manifest' => $export['manifest'], |
| 55 |
'file' => base64_encode( $file ), |
| 56 |
], |
| 57 |
$source, |
| 58 |
$export, |
| 59 |
$settings, |
| 60 |
$file, |
| 61 |
); |
| 62 |
|
| 63 |
if ( is_wp_error( $result ) ) { |
| 64 |
throw new \Error( $result->get_error_message() ); |
| 65 |
} |
| 66 |
|
| 67 |
return Response::success( $result ); |
| 68 |
|
| 69 |
} catch ( \Error |\Exception $e ) { |
| 70 |
Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [ |
| 71 |
'meta' => [ |
| 72 |
'trace' => $e->getTraceAsString(), |
| 73 |
], |
| 74 |
] ); |
| 75 |
|
| 76 |
return Response::error( 'export_error', $e->getMessage() ); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
protected function get_args(): array { |
| 81 |
return [ |
| 82 |
'include' => [ |
| 83 |
'type' => 'array', |
| 84 |
'description' => 'Content types to include in export', |
| 85 |
'required' => false, |
| 86 |
'default' => [ 'templates', 'content', 'settings', 'plugins' ], |
| 87 |
], |
| 88 |
'kitInfo' => [ |
| 89 |
'type' => 'object', |
| 90 |
'description' => 'Kit information', |
| 91 |
'required' => false, |
| 92 |
'default' => [ |
| 93 |
'title' => 'Elementor Website Template', |
| 94 |
'description' => '', |
| 95 |
'source' => 'local', |
| 96 |
], |
| 97 |
], |
| 98 |
'screenShotBlob' => [ |
| 99 |
'type' => [ 'string', 'null' ], |
| 100 |
'description' => 'Base64 encoded screenshot for cloud exports', |
| 101 |
'required' => false, |
| 102 |
'default' => null, |
| 103 |
], |
| 104 |
'customization' => [ |
| 105 |
'type' => 'object', |
| 106 |
'description' => 'Customization settings for selective export', |
| 107 |
'required' => false, |
| 108 |
'default' => null, |
| 109 |
'properties' => [ |
| 110 |
'settings' => [ |
| 111 |
'type' => [ 'object', 'null' ], |
| 112 |
'description' => 'Site settings customization', |
| 113 |
], |
| 114 |
'templates' => [ |
| 115 |
'type' => [ 'object', 'null' ], |
| 116 |
'description' => 'Templates customization', |
| 117 |
], |
| 118 |
'content' => [ |
| 119 |
'type' => [ 'object', 'null' ], |
| 120 |
'description' => 'Content customization', |
| 121 |
], |
| 122 |
'plugins' => [ |
| 123 |
'type' => [ 'object', 'null' ], |
| 124 |
'description' => 'Plugins customization', |
| 125 |
], |
| 126 |
], |
| 127 |
], |
| 128 |
'plugins' => [ |
| 129 |
'type' => 'array', |
| 130 |
'description' => 'Selected plugins to export', |
| 131 |
'required' => false, |
| 132 |
'default' => [], |
| 133 |
], |
| 134 |
'selectedCustomPostTypes' => [ |
| 135 |
'type' => 'array', |
| 136 |
'description' => 'Selected custom post types', |
| 137 |
'required' => false, |
| 138 |
'default' => [], |
| 139 |
], |
| 140 |
]; |
| 141 |
} |
| 142 |
} |
| 143 |
|