| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | namespace Elementor; |
| 3 | 3 | |
| 4 | -use Elementor\Core\Utils\Hints; | |
| 4 | +use Elementor\Core\Files\Uploads_Manager; | |
| 5 | 5 | use Elementor\Modules\DynamicTags\Module as TagsModule; |
| 6 | 6 | |
| 7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
| 8 | 8 | exit; // Exit if accessed directly. |
| @@ -46,20 +46,11 @@ | ||
| 46 | 46 | public function get_default_value() { |
| 47 | 47 | return [ |
| 48 | 48 | 'url' => '', |
| 49 | 49 | 'id' => '', |
| 50 | - 'size' => '', | |
| 51 | 50 | ]; |
| 52 | 51 | } |
| 53 | 52 | |
| 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 | 53 | /** |
| 63 | 54 | * Import media images. |
| 64 | 55 | * |
| 65 | 56 | * Used to import media control files from external sites while importing |
| @@ -67,9 +58,9 @@ | ||
| 67 | 58 | * |
| 68 | 59 | * @since 1.0.0 |
| 69 | 60 | * @access public |
| 70 | 61 | * |
| 71 | - * @param array $settings Control settings. | |
| 62 | + * @param array $settings Control settings | |
| 72 | 63 | * |
| 73 | 64 | * @return array Control settings. |
| 74 | 65 | */ |
| 75 | 66 | public function on_import( $settings ) { |
| @@ -76,19 +67,8 @@ | ||
| 76 | 67 | if ( empty( $settings['url'] ) ) { |
| 77 | 68 | return $settings; |
| 78 | 69 | } |
| 79 | 70 | |
| 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 | 71 | $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings ); |
| 92 | 72 | |
| 93 | 73 | if ( ! $settings ) { |
| 94 | 74 | $settings = [ |
| @@ -107,9 +87,9 @@ | ||
| 107 | 87 | * |
| 108 | 88 | * @since 3.4.6 |
| 109 | 89 | * @deprecated 3.5.0 |
| 110 | 90 | * |
| 111 | - * @param mixed $mimes | |
| 91 | + * @param $mimes | |
| 112 | 92 | * @return mixed |
| 113 | 93 | */ |
| 114 | 94 | public function support_svg_and_json_import( $mimes ) { |
| 115 | 95 | Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' ); |
| @@ -128,9 +108,9 @@ | ||
| 128 | 108 | */ |
| 129 | 109 | public function enqueue() { |
| 130 | 110 | global $wp_version; |
| 131 | 111 | |
| 132 | - $suffix = Utils::is_script_debug() ? '' : '.min'; | |
| 112 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; | |
| 133 | 113 | wp_enqueue_media(); |
| 134 | 114 | |
| 135 | 115 | wp_enqueue_style( |
| 136 | 116 | 'media', |
| @@ -221,9 +201,9 @@ | ||
| 221 | 201 | <div class="elementor-control-field elementor-control-media"> |
| 222 | 202 | <label class="elementor-control-title">{{{ data.label }}}</label> |
| 223 | 203 | <# |
| 224 | 204 | if ( isViewable() ) { |
| 225 | - let inputWrapperClasses = 'elementor-control-input-wrapper'; | |
| 205 | + let inputWrapperClasses = 'elementor-control-input-wrapper elementor-aspect-ratio-219'; | |
| 226 | 206 | |
| 227 | 207 | if ( ! data.label_block ) { |
| 228 | 208 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 209 | } |
| @@ -228,19 +208,18 @@ | ||
| 228 | 208 | inputWrapperClasses += ' elementor-control-unit-5'; |
| 229 | 209 | } |
| 230 | 210 | #> |
| 231 | 211 | <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> | |
| 212 | + <div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area elementor-fit-aspect-ratio"> | |
| 213 | + <div class="elementor-control-media-area elementor-fit-aspect-ratio"> | |
| 214 | + <div class="elementor-control-media__remove elementor-control-media__content__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 215 | + <i class="eicon-trash-o"></i> | |
| 237 | 216 | </div> |
| 238 | 217 | <# |
| 239 | 218 | switch( getPreviewType() ) { |
| 240 | 219 | case 'image': |
| 241 | 220 | #> |
| 242 | - <div class="elementor-control-media__preview"></div> | |
| 221 | + <div class="elementor-control-media__preview elementor-fit-aspect-ratio"></div> | |
| 243 | 222 | <# |
| 244 | 223 | break; |
| 245 | 224 | |
| 246 | 225 | case 'video': |
| @@ -245,9 +224,9 @@ | ||
| 245 | 224 | |
| 246 | 225 | case 'video': |
| 247 | 226 | #> |
| 248 | 227 | <video class="elementor-control-media-video" preload="metadata"></video> |
| 249 | - <i class="eicon-video-camera" aria-hidden="true"></i> | |
| 228 | + <i class="eicon-video-camera"></i> | |
| 250 | 229 | <# |
| 251 | 230 | break; |
| 252 | 231 | } |
| 253 | 232 | #> |
| @@ -253,9 +232,8 @@ | ||
| 253 | 232 | #> |
| 254 | 233 | </div> |
| 255 | 234 | <div class="elementor-control-media-upload-button elementor-control-media__content__upload-button"> |
| 256 | 235 | <i class="eicon-plus-circle" aria-hidden="true"></i> |
| 257 | - <span class="elementor-screen-only"><?php echo esc_html__( 'Add', 'elementor' ); ?></span> | |
| 258 | 236 | </div> |
| 259 | 237 | <div class="elementor-control-media__tools elementor-control-dynamic-switcher-wrapper"> |
| 260 | 238 | <# |
| 261 | 239 | data.media_types.forEach( ( type ) => { |
| @@ -265,24 +243,8 @@ | ||
| 265 | 243 | } ); |
| 266 | 244 | #> |
| 267 | 245 | </div> |
| 268 | 246 | </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 | 247 | </div> |
| 286 | 248 | <# } /* endif isViewable() */ else { #> |
| 287 | 249 | <div class="elementor-control-media__file elementor-control-preview-area"> |
| 288 | 250 | <div class="elementor-control-media__file__content"> |
| @@ -294,15 +256,13 @@ | ||
| 294 | 256 | <div class="elementor-control-media__file__content__info__name"></div> |
| 295 | 257 | </div> |
| 296 | 258 | </div> |
| 297 | 259 | <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> | |
| 260 | + <div class="elementor-control-media__remove elementor-control-media__file__controls__remove" title="<?php echo esc_html__( 'Remove', 'elementor' ); ?>"> | |
| 261 | + <i class="eicon-trash-o"></i> | |
| 301 | 262 | </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> | |
| 263 | + <div class="elementor-control-media__file__controls__upload-button elementor-control-media-upload-button" title="<?php echo esc_html__( 'Upload', 'elementor' ); ?>"> | |
| 264 | + <i class="eicon-upload"></i> | |
| 305 | 265 | </div> |
| 306 | 266 | </div> |
| 307 | 267 | </div> |
| 308 | 268 | <# } #> |
| @@ -308,111 +268,13 @@ | ||
| 308 | 268 | <# } #> |
| 309 | 269 | <# if ( data.description ) { #> |
| 310 | 270 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 311 | 271 | <# } #> |
| 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 | 272 | <input type="hidden" data-setting="{{ data.name }}"/> |
| 331 | 273 | </div> |
| 332 | 274 | <?php |
| 333 | 275 | } |
| 334 | 276 | |
| 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 | 277 | /** |
| 416 | 278 | * Get media control default settings. |
| 417 | 279 | * |
| 418 | 280 | * Retrieve the default settings of the media control. Used to return the default |
| @@ -425,14 +287,8 @@ | ||
| 425 | 287 | */ |
| 426 | 288 | protected function get_default_settings() { |
| 427 | 289 | return [ |
| 428 | 290 | 'label_block' => true, |
| 429 | - 'has_sizes' => false, | |
| 430 | - 'ai' => [ | |
| 431 | - 'active' => true, | |
| 432 | - 'type' => 'media', | |
| 433 | - 'category' => 'photographic', | |
| 434 | - ], | |
| 435 | 291 | 'media_types' => [ |
| 436 | 292 | 'image', |
| 437 | 293 | ], |
| 438 | 294 | 'dynamic' => [ |
| @@ -478,9 +334,9 @@ | ||
| 478 | 334 | */ |
| 479 | 335 | public static function get_image_alt( $instance ) { |
| 480 | 336 | if ( empty( $instance['id'] ) ) { |
| 481 | 337 | // For `Insert From URL` images. |
| 482 | - return isset( $instance['alt'] ) ? trim( self::sanitise_text( $instance['alt'] ) ) : ''; | |
| 338 | + return isset( $instance['alt'] ) ? trim( strip_tags( $instance['alt'] ) ) : ''; | |
| 483 | 339 | } |
| 484 | 340 | |
| 485 | 341 | $attachment_id = $instance['id']; |
| 486 | 342 | if ( ! $attachment_id ) { |
| @@ -493,32 +349,12 @@ | ||
| 493 | 349 | } |
| 494 | 350 | |
| 495 | 351 | $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ); |
| 496 | 352 | if ( ! $alt ) { |
| 497 | - if ( Utils::has_invalid_post_permissions( $attachment ) ) { | |
| 498 | - return ''; | |
| 499 | - } | |
| 500 | - | |
| 501 | 353 | $alt = $attachment->post_excerpt; |
| 502 | 354 | if ( ! $alt ) { |
| 503 | 355 | $alt = $attachment->post_title; |
| 504 | 356 | } |
| 505 | 357 | } |
| 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 ) ); | |
| 358 | + return trim( strip_tags( $alt ) ); | |
| 523 | 359 | } |
| 524 | 360 | } |