| @@ -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,19 +66,8 @@ | ||
| 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; | |
| 82 | - | |
| 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 | - } | |
| 86 | - | |
| 87 | - if ( $imported_attachment ) { | |
| 88 | - return $imported_attachment; | |
| 89 | - } | |
| 90 | - | |
| 91 | 70 | $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings ); |
| 92 | 71 | |
| 93 | 72 | if ( ! $settings ) { |
| 94 | 73 | $settings = [ |
| @@ -100,25 +79,8 @@ | ||
| 100 | 79 | return $settings; |
| 101 | 80 | } |
| 102 | 81 | |
| 103 | 82 | /** |
| 104 | - * Support SVG and JSON Import | |
| 105 | - * | |
| 106 | - * Called by the 'upload_mimes' filter. Adds SVG and JSON mime types to the list of WordPress' allowed mime types. | |
| 107 | - * | |
| 108 | - * @since 3.4.6 | |
| 109 | - * @deprecated 3.5.0 | |
| 110 | - * | |
| 111 | - * @param mixed $mimes | |
| 112 | - * @return mixed | |
| 113 | - */ | |
| 114 | - public function support_svg_and_json_import( $mimes ) { | |
| 115 | - Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); | |
| 116 | - | |
| 117 | - return $mimes; | |
| 118 | - } | |
| 119 | - | |
| 120 | - /** | |
| 121 | 83 | * Enqueue media control scripts and styles. |
| 122 | 84 | * |
| 123 | 85 | * Used to register and enqueue custom scripts and styles used by the media |
| 124 | 86 | * control. |
| @@ -128,9 +90,9 @@ | ||
| 128 | 90 | */ |
| 129 | 91 | public function enqueue() { |
| 130 | 92 | global $wp_version; |
| 131 | 93 | |
| 132 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 94 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 133 | 95 | wp_enqueue_media(); |
| 134 | 96 | |
| 135 | 97 | wp_enqueue_style( |
| 136 | 98 | 'media', |
| @@ -221,9 +183,9 @@ | ||
| 221 | 183 | <div class="elementor-control-field elementor-control-media"> |
| 222 | 184 | <label class="elementor-control-title">{{{ data.label }}}</label> |
| 223 | 185 | <# |
| 224 | 186 | if ( isViewable() ) { |
| 225 | - let inputWrapperClasses = 'elementor-control-input-wrapper'; | |
| 187 | + let inputWrapperClasses = 'elementor-control-input-wrapper elementor-aspect-ratio-219'; | |
| 226 | 188 | |
| 227 | 189 | if ( ! data.label_block ) { |
| 228 | 190 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 191 | } |
| @@ -228,19 +190,18 @@ | ||
| 228 | 190 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 191 | } |
| 230 | 192 | #> |
| 231 | 193 | <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> | |
| 194 | + <div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area elementor-fit-aspect-ratio"> | |
| 195 | + <div class="elementor-control-media-area elementor-fit-aspect-ratio"> | |
| 196 | + <div class="elementor-control-media__remove elementor-control-media__content__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 197 | + <i class="eicon-trash-o"></i> | |
| 237 | 198 | </div> |
| 238 | 199 | <# |
| 239 | 200 | switch( getPreviewType() ) { |
| 240 | 201 | case 'image': |
| 241 | 202 | #> |
| 242 | - <div class="elementor-control-media__preview"></div> | |
| 203 | + <div class="elementor-control-media__preview elementor-fit-aspect-ratio"></div> | |
| 243 | 204 | <# |
| 244 | 205 | break; |
| 245 | 206 | |
| 246 | 207 | case 'video': |
| @@ -245,9 +206,9 @@ | ||
| 245 | 206 | |
| 246 | 207 | case 'video': |
| 247 | 208 | #> |
| 248 | 209 | <video class="elementor-control-media-video" preload="metadata"></video> |
| 249 | - <i class="eicon-video-camera" aria-hidden="true"></i> | |
| 210 | + <i class="eicon-video-camera"></i> | |
| 250 | 211 | <# |
| 251 | 212 | break; |
| 252 | 213 | } |
| 253 | 214 | #> |
| @@ -253,9 +214,8 @@ | ||
| 253 | 214 | #> |
| 254 | 215 | </div> |
| 255 | 216 | <div class="elementor-control-media-upload-button elementor-control-media__content__upload-button"> |
| 256 | 217 | <i class="eicon-plus-circle" aria-hidden="true"></i> |
| 257 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Add', 'elementor' ); ?></span> | |
| 258 | 218 | </div> |
| 259 | 219 | <div class="elementor-control-media__tools elementor-control-dynamic-switcher-wrapper"> |
| 260 | 220 | <# |
| 261 | 221 | data.media_types.forEach( ( type ) => { |
| @@ -265,24 +225,8 @@ | ||
| 265 | 225 | } ); |
| 266 | 226 | #> |
| 267 | 227 | </div> |
| 268 | 228 | </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 | 229 | </div> |
| 286 | 230 | <# } /* endif isViewable() */ else { #> |
| 287 | 231 | <div class="elementor-control-media__file elementor-control-preview-area"> |
| 288 | 232 | <div class="elementor-control-media__file__content"> |
| @@ -294,15 +238,13 @@ | ||
| 294 | 238 | <div class="elementor-control-media__file__content__info__name"></div> |
| 295 | 239 | </div> |
| 296 | 240 | </div> |
| 297 | 241 | <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> | |
| 242 | + <div class="elementor-control-media__remove elementor-control-media__file__controls__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 243 | + <i class="eicon-trash-o"></i> | |
| 301 | 244 | </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> | |
| 245 | + <div class="elementor-control-media__file__controls__upload-button elementor-control-media-upload-button" title="<?php echo esc_html__( 'Upload', 'elementor' ); ?>"> | |
| 246 | + <i class="eicon-upload"></i> | |
| 305 | 247 | </div> |
| 306 | 248 | </div> |
| 307 | 249 | </div> |
| 308 | 250 | <# } #> |
| @@ -308,111 +250,13 @@ | ||
| 308 | 250 | <# } #> |
| 309 | 251 | <# if ( data.description ) { #> |
| 310 | 252 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 311 | 253 | <# } #> |
| 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 | 254 | <input type="hidden" data-setting="{{ data.name }}"/> |
| 331 | 255 | </div> |
| 332 | 256 | <?php |
| 333 | 257 | } |
| 334 | 258 | |
| 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 Optimization 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 Optimization. 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 Optimization.', '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 | 259 | /** |
| 416 | 260 | * Get media control default settings. |
| 417 | 261 | * |
| 418 | 262 | * Retrieve the default settings of the media control. Used to return the default |
| @@ -425,14 +269,8 @@ | ||
| 425 | 269 | */ |
| 426 | 270 | protected function get_default_settings() { |
| 427 | 271 | return [ |
| 428 | 272 | 'label_block' => true, |
| 429 | - 'has_sizes' => false, | |
| 430 | - 'ai' => [ | |
| 431 | - 'active' => true, | |
| 432 | - 'type' => 'media', | |
| 433 | - 'category' => 'photographic', | |
| 434 | - ], | |
| 435 | 273 | 'media_types' => [ |
| 436 | 274 | 'image', |
| 437 | 275 | ], |
| 438 | 276 | 'dynamic' => [ |
| @@ -478,9 +316,9 @@ | ||
| 478 | 316 | */ |
| 479 | 317 | public static function get_image_alt( $instance ) { |
| 480 | 318 | if ( empty( $instance['id'] ) ) { |
| 481 | 319 | // For `Insert From URL` images. |
| 482 | - return isset( $instance['alt'] ) ? trim( self::sanitise_text( $instance['alt'] ) ) : ''; | |
| 320 | + return isset( $instance['alt'] ) ? trim( strip_tags( $instance['alt'] ) ) : ''; | |
| 483 | 321 | } |
| 484 | 322 | |
| 485 | 323 | $attachment_id = $instance['id']; |
| 486 | 324 | if ( ! $attachment_id ) { |
| @@ -493,32 +331,12 @@ | ||
| 493 | 331 | } |
| 494 | 332 | |
| 495 | 333 | $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); |
| 496 | 334 | if ( ! $alt ) { |
| 497 | - if ( Utils::has_invalid_post_permissions( $attachment ) ) { | |
| 498 | - return ''; | |
| 499 | - } | |
| 500 | - | |
| 501 | 335 | $alt = $attachment->post_excerpt; |
| 502 | 336 | if ( ! $alt ) { |
| 503 | 337 | $alt = $attachment->post_title; |
| 504 | 338 | } |
| 505 | 339 | } |
| 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 ) ); | |
| 340 | + return trim( strip_tags( $alt ) ); | |
| 523 | 341 | } |
| 524 | 342 | } |