| @@ -1,8 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Utils\Hints; | |
| 5 | 4 | use Elementor\Modules\DynamicTags\Module as TagsModule; |
| 6 | 5 | |
| 7 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 7 | exit; // Exit if accessed directly. |
| @@ -46,20 +45,11 @@ | ||
| 46 | 45 | public function get_default_value() { |
| 47 | 46 | return [ |
| 48 | 47 | 'url' => '', |
| 49 | 48 | 'id' => '', |
| 50 | - 'size' => '', | |
| 51 | 49 | ]; |
| 52 | 50 | } |
| 53 | 51 | |
| 54 | - public function on_export( $settings ) { | |
| 55 | - if ( ! empty( $settings['url'] ) ) { | |
| 56 | - do_action( 'elementor/templates/collect_media_url', $settings['url'], $settings ); | |
| 57 | - } | |
| 58 | - | |
| 59 | - return $settings; | |
| 60 | - } | |
| 61 | - | |
| 62 | 52 | /** |
| 63 | 53 | * Import media images. |
| 64 | 54 | * |
| 65 | 55 | * Used to import media control files from external sites while importing |
| @@ -67,9 +57,9 @@ | ||
| 67 | 57 | * |
| 68 | 58 | * @since 1.0.0 |
| 69 | 59 | * @access public |
| 70 | 60 | * |
| 71 | - * @param array $settings Control settings. | |
| 61 | + * @param array $settings Control settings | |
| 72 | 62 | * |
| 73 | 63 | * @return array Control settings. |
| 74 | 64 | */ |
| 75 | 65 | public function on_import( $settings ) { |
| @@ -76,21 +66,14 @@ | ||
| 76 | 66 | if ( empty( $settings['url'] ) ) { |
| 77 | 67 | return $settings; |
| 78 | 68 | } |
| 79 | 69 | |
| 80 | - $local_file_path = \Elementor\TemplateLibrary\Classes\Media_Mapper::get_local_file_path( $settings['url'] ); | |
| 81 | - $imported_attachment = false; | |
| 70 | + add_filter( 'upload_mimes', [ $this, 'support_svg_and_json_import' ], 100 ); | |
| 82 | 71 | |
| 83 | - if ( $local_file_path !== $settings['url'] && file_exists( $local_file_path ) ) { | |
| 84 | - $imported_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import_local_file( $local_file_path ); | |
| 85 | - } | |
| 72 | + $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings ); | |
| 86 | 73 | |
| 87 | - if ( $imported_attachment ) { | |
| 88 | - return $imported_attachment; | |
| 89 | - } | |
| 74 | + remove_filter( 'upload_mimes', [ $this, 'support_svg_and_json_import' ], 100 ); | |
| 90 | 75 | |
| 91 | - $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings ); | |
| 92 | - | |
| 93 | 76 | if ( ! $settings ) { |
| 94 | 77 | $settings = [ |
| 95 | 78 | 'id' => '', |
| 96 | 79 | 'url' => Utils::get_placeholder_image_src(), |
| @@ -104,16 +87,16 @@ | ||
| 104 | 87 | * Support SVG and JSON Import |
| 105 | 88 | * |
| 106 | 89 | * Called by the 'upload_mimes' filter. Adds SVG and JSON mime types to the list of WordPress' allowed mime types. |
| 107 | 90 | * |
| 108 | - * @since 3.4.6 | |
| 109 | - * @deprecated 3.5.0 | |
| 91 | + * @since 3.4.0 | |
| 110 | 92 | * |
| 111 | - * @param mixed $mimes | |
| 93 | + * @param $mimes | |
| 112 | 94 | * @return mixed |
| 113 | 95 | */ |
| 114 | 96 | public function support_svg_and_json_import( $mimes ) { |
| 115 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); | |
| 97 | + $mimes['svg'] = 'image/svg+xml'; | |
| 98 | + $mimes['json'] = 'application/json'; | |
| 116 | 99 | |
| 117 | 100 | return $mimes; |
| 118 | 101 | } |
| 119 | 102 | |
| @@ -128,9 +111,9 @@ | ||
| 128 | 111 | */ |
| 129 | 112 | public function enqueue() { |
| 130 | 113 | global $wp_version; |
| 131 | 114 | |
| 132 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 115 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 133 | 116 | wp_enqueue_media(); |
| 134 | 117 | |
| 135 | 118 | wp_enqueue_style( |
| 136 | 119 | 'media', |
| @@ -221,9 +204,9 @@ | ||
| 221 | 204 | <div class="elementor-control-field elementor-control-media"> |
| 222 | 205 | <label class="elementor-control-title">{{{ data.label }}}</label> |
| 223 | 206 | <# |
| 224 | 207 | if ( isViewable() ) { |
| 225 | - let inputWrapperClasses = 'elementor-control-input-wrapper'; | |
| 208 | + let inputWrapperClasses = 'elementor-control-input-wrapper elementor-aspect-ratio-219'; | |
| 226 | 209 | |
| 227 | 210 | if ( ! data.label_block ) { |
| 228 | 211 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 212 | } |
| @@ -228,19 +211,18 @@ | ||
| 228 | 211 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 212 | } |
| 230 | 213 | #> |
| 231 | 214 | <div class="{{{ inputWrapperClasses }}}"> |
| 232 | - <div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area"> | |
| 233 | - <div class="elementor-control-media-area"> | |
| 234 | - <div class="elementor-control-media__remove elementor-control-media__content__remove" data-tooltip="<?php echo esc_attr__( 'Remove', 'elementor' ); ?>"> | |
| 235 | - <i class="eicon-trash-o" aria-hidden="true"></i> | |
| 236 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Remove', 'elementor' ); ?></span> | |
| 215 | + <div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area elementor-fit-aspect-ratio"> | |
| 216 | + <div class="elementor-control-media-area elementor-fit-aspect-ratio"> | |
| 217 | + <div class="elementor-control-media__remove elementor-control-media__content__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 218 | + <i class="eicon-trash-o"></i> | |
| 237 | 219 | </div> |
| 238 | 220 | <# |
| 239 | 221 | switch( getPreviewType() ) { |
| 240 | 222 | case 'image': |
| 241 | 223 | #> |
| 242 | - <div class="elementor-control-media__preview"></div> | |
| 224 | + <div class="elementor-control-media__preview elementor-fit-aspect-ratio"></div> | |
| 243 | 225 | <# |
| 244 | 226 | break; |
| 245 | 227 | |
| 246 | 228 | case 'video': |
| @@ -245,9 +227,9 @@ | ||
| 245 | 227 | |
| 246 | 228 | case 'video': |
| 247 | 229 | #> |
| 248 | 230 | <video class="elementor-control-media-video" preload="metadata"></video> |
| 249 | - <i class="eicon-video-camera" aria-hidden="true"></i> | |
| 231 | + <i class="eicon-video-camera"></i> | |
| 250 | 232 | <# |
| 251 | 233 | break; |
| 252 | 234 | } |
| 253 | 235 | #> |
| @@ -253,9 +235,8 @@ | ||
| 253 | 235 | #> |
| 254 | 236 | </div> |
| 255 | 237 | <div class="elementor-control-media-upload-button elementor-control-media__content__upload-button"> |
| 256 | 238 | <i class="eicon-plus-circle" aria-hidden="true"></i> |
| 257 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Add', 'elementor' ); ?></span> | |
| 258 | 239 | </div> |
| 259 | 240 | <div class="elementor-control-media__tools elementor-control-dynamic-switcher-wrapper"> |
| 260 | 241 | <# |
| 261 | 242 | data.media_types.forEach( ( type ) => { |
| @@ -265,24 +246,8 @@ | ||
| 265 | 246 | } ); |
| 266 | 247 | #> |
| 267 | 248 | </div> |
| 268 | 249 | </div> |
| 269 | - | |
| 270 | - <?php | |
| 271 | - /* | |
| 272 | - ?> | |
| 273 | - <div class="elementor-control-media__warnings" role="alert" style="display: none;"> | |
| 274 | - <?php | |
| 275 | - Hints::get_notice_template( [ | |
| 276 | - 'type' => 'warning', | |
| 277 | - 'content' => esc_html__( 'This image doesn’t contain ALT text - which is necessary for accessibility and SEO.', 'elementor' ), | |
| 278 | - 'icon' => true, | |
| 279 | - ] ); | |
| 280 | - ?> | |
| 281 | - </div> | |
| 282 | - <?php | |
| 283 | - */ ?> | |
| 284 | - <?php $this->maybe_display_io_hints(); ?> | |
| 285 | 250 | </div> |
| 286 | 251 | <# } /* endif isViewable() */ else { #> |
| 287 | 252 | <div class="elementor-control-media__file elementor-control-preview-area"> |
| 288 | 253 | <div class="elementor-control-media__file__content"> |
| @@ -294,15 +259,13 @@ | ||
| 294 | 259 | <div class="elementor-control-media__file__content__info__name"></div> |
| 295 | 260 | </div> |
| 296 | 261 | </div> |
| 297 | 262 | <div class="elementor-control-media__file__controls"> |
| 298 | - <div class="elementor-control-media__remove elementor-control-media__file__controls__remove" data-tooltip="<?php echo esc_attr__( 'Remove', 'elementor' ); ?>"> | |
| 299 | - <i class="eicon-trash-o" aria-hidden="true"></i> | |
| 300 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Remove', 'elementor' ); ?></span> | |
| 263 | + <div class="elementor-control-media__remove elementor-control-media__file__controls__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 264 | + <i class="eicon-trash-o"></i> | |
| 301 | 265 | </div> |
| 302 | - <div class="elementor-control-media__file__controls__upload-button elementor-control-media-upload-button" data-tooltip="<?php echo esc_attr__( 'Upload', 'elementor' ); ?>"> | |
| 303 | - <i class="eicon-upload" aria-hidden="true"></i> | |
| 304 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Upload', 'elementor' ); ?></span> | |
| 266 | + <div class="elementor-control-media__file__controls__upload-button elementor-control-media-upload-button" title="<?php echo esc_html__( 'Upload', 'elementor' ); ?>"> | |
| 267 | + <i class="eicon-upload"></i> | |
| 305 | 268 | </div> |
| 306 | 269 | </div> |
| 307 | 270 | </div> |
| 308 | 271 | <# } #> |
| @@ -308,111 +271,13 @@ | ||
| 308 | 271 | <# } #> |
| 309 | 272 | <# if ( data.description ) { #> |
| 310 | 273 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 311 | 274 | <# } #> |
| 312 | - | |
| 313 | - <# if ( data.has_sizes ) { #> | |
| 314 | - <div class="elementor-control-type-select e-control-image-size"> | |
| 315 | - <div class="elementor-control-field"> | |
| 316 | - <label class="elementor-control-title" data-e-responsive-switcher-sibling="false" for="<?php $this->print_control_uid( 'size' ); ?>"><?php echo esc_html__( 'Image Resolution', 'elementor' ); ?></label> | |
| 317 | - <div class="elementor-control-input-wrapper elementor-control-unit-5"> | |
| 318 | - <select class="e-image-size-select" id="<?php $this->print_control_uid( 'size' ); ?>" data-setting="size"> | |
| 319 | - <?php foreach ( $this->get_image_sizes() as $size_key => $size_title ) : ?> | |
| 320 | - <option value="<?php echo esc_attr( $size_key ); ?>"><?php echo esc_html( $size_title ); ?></option> | |
| 321 | - <?php endforeach; ?> | |
| 322 | - </select> | |
| 323 | - </div> | |
| 324 | - </div> | |
| 325 | - | |
| 326 | - <div class="elementor-control-field-description"><?php echo esc_html__( 'Image size settings don’t apply to Dynamic Images.', 'elementor' ); ?></div> | |
| 327 | - </div> | |
| 328 | - <# } #> | |
| 329 | - | |
| 330 | 275 | <input type="hidden" data-setting="{{ data.name }}"/> |
| 331 | 276 | </div> |
| 332 | 277 | <?php |
| 333 | 278 | } |
| 334 | 279 | |
| 335 | - private function maybe_display_io_hints() { | |
| 336 | - $plugin_slug = 'image-optimization'; | |
| 337 | - | |
| 338 | - if ( ! Hints::should_display_hint( $plugin_slug ) ) { | |
| 339 | - return; | |
| 340 | - } | |
| 341 | - | |
| 342 | - $one_subscription = Hints::is_plugin_connected_to_one_subscription(); | |
| 343 | - $is_installed = Hints::is_plugin_installed( $plugin_slug ); | |
| 344 | - $is_active = Hints::is_plugin_active( $plugin_slug ); | |
| 345 | - | |
| 346 | - if ( $is_active ) { | |
| 347 | - return; | |
| 348 | - } | |
| 349 | - | |
| 350 | - if ( $one_subscription ) { | |
| 351 | - if ( ! $is_installed ) { | |
| 352 | - $content = esc_html__( 'Optimize your images to improve site speed and performance. Image Optimizer is included in your ONE subscription.', 'elementor' ); | |
| 353 | - $button_text = esc_html__( 'Install now', 'elementor' ); | |
| 354 | - $button_url = Hints::get_plugin_install_url( $plugin_slug ); | |
| 355 | - $source = 'io-editor-image-one-install'; | |
| 356 | - } elseif ( ! $is_active ) { | |
| 357 | - $content = esc_html__( 'Your ONE subscription includes Image Optimizer. Activate it to optimize images and improve site performance.', 'elementor' ); | |
| 358 | - $button_text = esc_html__( 'Activate now', 'elementor' ); | |
| 359 | - $button_url = Hints::get_plugin_activate_url( $plugin_slug ); | |
| 360 | - $source = 'io-editor-image-one-activate'; | |
| 361 | - } | |
| 362 | - } else { | |
| 363 | - $content = esc_html__( 'Optimize your images to enhance site performance by using Image Optimizer.', 'elementor' ); | |
| 364 | - if ( ! $is_installed ) { | |
| 365 | - $button_text = esc_html__( 'Install now', 'elementor' ); | |
| 366 | - $button_url = Hints::get_plugin_install_url( $plugin_slug ); | |
| 367 | - $source = 'io-editor-image-install'; | |
| 368 | - } elseif ( ! $is_active ) { | |
| 369 | - $button_text = esc_html__( 'Activate now', 'elementor' ); | |
| 370 | - $button_url = Hints::get_plugin_activate_url( $plugin_slug ); | |
| 371 | - $source = 'io-editor-image-activate'; | |
| 372 | - } | |
| 373 | - } | |
| 374 | - ?> | |
| 375 | - <div class="elementor-control-media__promotions" role="alert"> | |
| 376 | - <?php | |
| 377 | - Hints::get_notice_template( [ | |
| 378 | - 'display' => ! Hints::is_dismissed( $plugin_slug ), | |
| 379 | - 'type' => 'info', | |
| 380 | - 'icon' => true, | |
| 381 | - 'heading' => '', | |
| 382 | - 'content' => $content, | |
| 383 | - 'dismissible' => 'image_optimizer_hint', | |
| 384 | - 'button_text' => $button_text, | |
| 385 | - 'button_event' => 'image_optimizer_hint', | |
| 386 | - 'button_data' => [ | |
| 387 | - 'action_url' => $button_url, | |
| 388 | - 'source' => $source, | |
| 389 | - ], | |
| 390 | - ] ); | |
| 391 | - ?> | |
| 392 | - </div> | |
| 393 | - <?php | |
| 394 | - } | |
| 395 | - | |
| 396 | - private function get_image_sizes(): array { | |
| 397 | - $wp_image_sizes = Group_Control_Image_Size::get_all_image_sizes(); | |
| 398 | - | |
| 399 | - $image_sizes = []; | |
| 400 | - | |
| 401 | - foreach ( $wp_image_sizes as $size_key => $size_attributes ) { | |
| 402 | - $control_title = ucwords( str_replace( '_', ' ', $size_key ) ); | |
| 403 | - if ( is_array( $size_attributes ) ) { | |
| 404 | - $control_title .= sprintf( ' - %d x %d', $size_attributes['width'], $size_attributes['height'] ); | |
| 405 | - } | |
| 406 | - | |
| 407 | - $image_sizes[ $size_key ] = $control_title; | |
| 408 | - } | |
| 409 | - | |
| 410 | - $image_sizes[''] = esc_html_x( 'Full', 'Image Size Control', 'elementor' ); | |
| 411 | - | |
| 412 | - return $image_sizes; | |
| 413 | - } | |
| 414 | - | |
| 415 | 280 | /** |
| 416 | 281 | * Get media control default settings. |
| 417 | 282 | * |
| 418 | 283 | * Retrieve the default settings of the media control. Used to return the default |
| @@ -425,14 +290,8 @@ | ||
| 425 | 290 | */ |
| 426 | 291 | protected function get_default_settings() { |
| 427 | 292 | return [ |
| 428 | 293 | 'label_block' => true, |
| 429 | - 'has_sizes' => false, | |
| 430 | - 'ai' => [ | |
| 431 | - 'active' => true, | |
| 432 | - 'type' => 'media', | |
| 433 | - 'category' => 'photographic', | |
| 434 | - ], | |
| 435 | 294 | 'media_types' => [ |
| 436 | 295 | 'image', |
| 437 | 296 | ], |
| 438 | 297 | 'dynamic' => [ |
| @@ -478,9 +337,9 @@ | ||
| 478 | 337 | */ |
| 479 | 338 | public static function get_image_alt( $instance ) { |
| 480 | 339 | if ( empty( $instance['id'] ) ) { |
| 481 | 340 | // For `Insert From URL` images. |
| 482 | - return isset( $instance['alt'] ) ? trim( self::sanitise_text( $instance['alt'] ) ) : ''; | |
| 341 | + return isset( $instance['alt'] ) ? trim( strip_tags( $instance['alt'] ) ) : ''; | |
| 483 | 342 | } |
| 484 | 343 | |
| 485 | 344 | $attachment_id = $instance['id']; |
| 486 | 345 | if ( ! $attachment_id ) { |
| @@ -493,32 +352,12 @@ | ||
| 493 | 352 | } |
| 494 | 353 | |
| 495 | 354 | $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); |
| 496 | 355 | if ( ! $alt ) { |
| 497 | - if ( Utils::has_invalid_post_permissions( $attachment ) ) { | |
| 498 | - return ''; | |
| 499 | - } | |
| 500 | - | |
| 501 | 356 | $alt = $attachment->post_excerpt; |
| 502 | 357 | if ( ! $alt ) { |
| 503 | 358 | $alt = $attachment->post_title; |
| 504 | 359 | } |
| 505 | 360 | } |
| 506 | - return trim( self::sanitise_text( $alt ) ); | |
| 507 | - } | |
| 508 | - | |
| 509 | - public function get_style_value( $css_property, $control_value, array $control_data ) { | |
| 510 | - if ( 'URL' !== $css_property || empty( $control_value['id'] ) ) { | |
| 511 | - return parent::get_style_value( $css_property, $control_value, $control_data ); | |
| 512 | - } | |
| 513 | - | |
| 514 | - if ( empty( $control_value['size'] ) ) { | |
| 515 | - $control_value['size'] = 'full'; | |
| 516 | - } | |
| 517 | - | |
| 518 | - return wp_get_attachment_image_url( $control_value['id'], $control_value['size'] ); | |
| 519 | - } | |
| 520 | - | |
| 521 | - public static function sanitise_text( $text ) { | |
| 522 | - return esc_attr( strip_tags( $text ) ); | |
| 361 | + return trim( strip_tags( $alt ) ); | |
| 523 | 362 | } |
| 524 | 363 | } |