← All changes
|
app/modules/import-export-customization/processes/export.php
+9
-66
4.2.0-beta2
→
3.31.2
View file →
| @@ -37,15 +37,8 @@ | ||
| 37 | 37 | */ |
| 38 | 38 | private $settings_kit_info; |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * Customization settings for selective export. | |
| 42 | - * | |
| 43 | - * @var array | |
| 44 | - */ | |
| 45 | - private $settings_customization; | |
| 46 | - | |
| 47 | - /** | |
| 48 | 41 | * Selected plugins to export. |
| 49 | 42 | * Contains the plugins essential data for export. (e.g: name, path, version, etc.) |
| 50 | 43 | * |
| 51 | 44 | * @var array |
| @@ -76,11 +69,10 @@ | ||
| 76 | 69 | |
| 77 | 70 | public function __construct( $settings = [] ) { |
| 78 | 71 | $this->settings_include = ! empty( $settings['include'] ) ? $settings['include'] : null; |
| 79 | 72 | $this->settings_kit_info = ! empty( $settings['kitInfo'] ) ? $settings['kitInfo'] : null; |
| 80 | - $this->settings_customization = isset( $settings['customization'] ) ? $settings['customization'] : null; | |
| 81 | 73 | $this->settings_selected_plugins = isset( $settings['plugins'] ) ? $settings['plugins'] : null; |
| 82 | - $this->settings_selected_custom_post_types = isset( $settings['customization']['content']['customPostTypes'] ) ? $settings['customization']['content']['customPostTypes'] : null; | |
| 74 | + $this->settings_selected_custom_post_types = isset( $settings['selectedCustomPostTypes'] ) ? $settings['selectedCustomPostTypes'] : null; | |
| 83 | 75 | } |
| 84 | 76 | |
| 85 | 77 | /** |
| 86 | 78 | * Register a runner. |
| @@ -118,19 +110,12 @@ | ||
| 118 | 110 | $this->init_manifest_data(); |
| 119 | 111 | |
| 120 | 112 | $data = [ |
| 121 | 113 | 'include' => $this->settings_include, |
| 122 | - 'customization' => $this->settings_customization, | |
| 123 | 114 | 'selected_plugins' => $this->settings_selected_plugins, |
| 124 | 115 | 'selected_custom_post_types' => $this->settings_selected_custom_post_types, |
| 125 | 116 | ]; |
| 126 | 117 | |
| 127 | - $media_collector = null; | |
| 128 | - if ( $this->should_collect_media( $data ) ) { | |
| 129 | - $media_collector = new \Elementor\TemplateLibrary\Classes\Media_Collector(); | |
| 130 | - $media_collector->start_collection(); | |
| 131 | - } | |
| 132 | - | |
| 133 | 118 | foreach ( $this->runners as $runner ) { |
| 134 | 119 | if ( $runner->should_export( $data ) ) { |
| 135 | 120 | $export_result = $runner->export( $data ); |
| 136 | 121 | $this->handle_export_result( $export_result ); |
| @@ -136,13 +121,8 @@ | ||
| 136 | 121 | $this->handle_export_result( $export_result ); |
| 137 | 122 | } |
| 138 | 123 | } |
| 139 | 124 | |
| 140 | - $media_urls = null; | |
| 141 | - if ( $media_collector ) { | |
| 142 | - $media_urls = $media_collector->get_collected_urls(); | |
| 143 | - } | |
| 144 | - | |
| 145 | 125 | $this->add_json_file( 'manifest', $this->manifest_data ); |
| 146 | 126 | |
| 147 | 127 | $zip_file_name = $this->zip->filename; |
| 148 | 128 | $this->zip->close(); |
| @@ -149,9 +129,8 @@ | ||
| 149 | 129 | |
| 150 | 130 | return [ |
| 151 | 131 | 'manifest' => $this->manifest_data, |
| 152 | 132 | 'file_name' => $zip_file_name, |
| 153 | - 'media_urls' => $media_urls, | |
| 154 | 133 | ]; |
| 155 | 134 | } |
| 156 | 135 | |
| 157 | 136 | /** |
| @@ -172,16 +151,12 @@ | ||
| 172 | 151 | |
| 173 | 152 | if ( ! is_array( $this->get_settings_selected_plugins() ) && in_array( 'plugins', $this->settings_include, true ) ) { |
| 174 | 153 | $this->settings_selected_plugins( $this->get_default_settings_selected_plugins() ); |
| 175 | 154 | } |
| 176 | - | |
| 177 | - if ( ! is_array( $this->get_settings_customization() ) ) { | |
| 178 | - $this->settings_customization( $this->get_default_settings_customization() ); | |
| 179 | - } | |
| 180 | 155 | } |
| 181 | 156 | |
| 182 | - public function settings_include( $settings_include ) { | |
| 183 | - $this->settings_include = $settings_include; | |
| 157 | + public function settings_include( $include ) { | |
| 158 | + $this->settings_include = $include; | |
| 184 | 159 | } |
| 185 | 160 | |
| 186 | 161 | public function get_settings_include() { |
| 187 | 162 | return $this->settings_include; |
| @@ -194,16 +169,8 @@ | ||
| 194 | 169 | private function get_settings_kit_info() { |
| 195 | 170 | return $this->settings_kit_info; |
| 196 | 171 | } |
| 197 | 172 | |
| 198 | - public function settings_customization( $customization ) { | |
| 199 | - $this->settings_customization = $customization; | |
| 200 | - } | |
| 201 | - | |
| 202 | - public function get_settings_customization() { | |
| 203 | - return $this->settings_customization; | |
| 204 | - } | |
| 205 | - | |
| 206 | 173 | public function settings_selected_custom_post_types( $selected_custom_post_types ) { |
| 207 | 174 | $this->settings_selected_custom_post_types = $selected_custom_post_types; |
| 208 | 175 | } |
| 209 | 176 | |
| @@ -247,33 +214,18 @@ | ||
| 247 | 214 | */ |
| 248 | 215 | private function get_default_settings_selected_plugins() { |
| 249 | 216 | $installed_plugins = Plugin::$instance->wp->get_plugins(); |
| 250 | 217 | |
| 251 | - $result = []; | |
| 252 | - foreach ( $installed_plugins->all() as $key => $item ) { | |
| 253 | - $plugin_key = str_replace( '.php', '', $key ); // Inconsistency between get_plugins() and WP Rest API's key format. | |
| 254 | - | |
| 255 | - $result[ $plugin_key ] = [ | |
| 218 | + return $installed_plugins->map( function ( $item, $key ) { | |
| 219 | + return [ | |
| 256 | 220 | 'name' => $item['Name'], |
| 257 | - 'plugin' => $plugin_key, | |
| 221 | + 'plugin' => $key, | |
| 258 | 222 | 'pluginUri' => $item['PluginURI'], |
| 259 | 223 | 'version' => $item['Version'], |
| 260 | 224 | ]; |
| 261 | - } | |
| 262 | - return $result; | |
| 225 | + } )->all(); | |
| 263 | 226 | } |
| 264 | 227 | |
| 265 | - private function get_default_settings_customization() { | |
| 266 | - return [ | |
| 267 | - 'settings' => null, | |
| 268 | - 'templates' => null, | |
| 269 | - 'content' => [ | |
| 270 | - 'mediaFormat' => 'link', | |
| 271 | - ], | |
| 272 | - 'plugins' => null, | |
| 273 | - ]; | |
| 274 | - } | |
| 275 | - | |
| 276 | 228 | /** |
| 277 | 229 | * Get the default settings of all the custom post types that should be exported. |
| 278 | 230 | * Should be all the custom post types that are not built in to WordPress and not part of Elementor. |
| 279 | 231 | * |
| @@ -284,10 +236,8 @@ | ||
| 284 | 236 | } |
| 285 | 237 | |
| 286 | 238 | /** |
| 287 | 239 | * Init the zip archive. |
| 288 | - * | |
| 289 | - * @throws \Error If export process fails, file creation errors occur, or data serialization fails. | |
| 290 | 240 | */ |
| 291 | 241 | private function init_zip_archive() { |
| 292 | 242 | if ( ! class_exists( '\ZipArchive' ) ) { |
| 293 | 243 | throw new \Error( static::ZIP_ARCHIVE_MODULE_MISSING ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| @@ -360,10 +310,10 @@ | ||
| 360 | 310 | /** |
| 361 | 311 | * Add json file to the zip archive. |
| 362 | 312 | * |
| 363 | 313 | * @param string $path The relative path to the file. |
| 364 | - * @param array $content The content of the file. | |
| 365 | - * @param int $json_flags | |
| 314 | + * @param array $content The content of the file. | |
| 315 | + * @param int $json_flags | |
| 366 | 316 | */ |
| 367 | 317 | private function add_json_file( $path, array $content, $json_flags = 0 ) { |
| 368 | 318 | if ( ! Str::ends_with( $path, '.json' ) ) { |
| 369 | 319 | $path .= '.json'; |
| @@ -379,13 +329,6 @@ | ||
| 379 | 329 | * @param string $content The content of the file. |
| 380 | 330 | */ |
| 381 | 331 | private function add_file( $file, $content ) { |
| 382 | 332 | $this->zip->addFromString( $file, $content ); |
| 383 | - } | |
| 384 | - | |
| 385 | - private function should_collect_media( $data ) { | |
| 386 | - return ( | |
| 387 | - isset( $data['customization']['content']['mediaFormat'] ) && | |
| 388 | - 'cloud' === $data['customization']['content']['mediaFormat'] | |
| 389 | - ); | |
| 390 | 333 | } |
| 391 | 334 | } |