PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 3.26.0-beta1
Elementor Website Builder – more than just a page builder v3.26.0-beta1
4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / includes / controls / media.php
elementor / includes / controls Last commit date
groups 1 year ago alert.php 2 years ago animation.php 1 year ago base-data.php 3 years ago base-icon-font.php 3 years ago base-multiple.php 3 years ago base-ui.php 3 years ago base-units.php 2 years ago base.php 3 years ago box-shadow.php 3 years ago button.php 3 years ago choose.php 3 years ago code.php 3 years ago color.php 3 years ago date-time.php 3 years ago deprecated-notice.php 3 years ago dimensions.php 3 years ago divider.php 2 years ago exit-animation.php 1 year ago font.php 3 years ago gallery.php 1 year ago gaps.php 2 years ago heading.php 3 years ago hidden.php 3 years ago hover-animation.php 1 year ago icon.php 2 years ago icons.php 2 years ago image-dimensions.php 3 years ago media.php 1 year ago notice.php 1 year ago number.php 3 years ago popover-toggle.php 3 years ago raw-html.php 3 years ago repeater.php 1 year ago section.php 2 years ago select.php 3 years ago select2.php 2 years ago slider.php 3 years ago structure.php 2 years ago switcher.php 3 years ago tab.php 2 years ago tabs.php 2 years ago text-shadow.php 3 years ago text.php 3 years ago textarea.php 3 years ago url.php 1 year ago wp-widget.php 3 years ago wysiwyg.php 3 years ago
media.php
458 lines
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Utils\Hints;
5 use Elementor\Modules\DynamicTags\Module as TagsModule;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor media control.
13 *
14 * A base control for creating a media chooser control. Based on the WordPress
15 * media library. Used to select an image from the WordPress media library.
16 *
17 * @since 1.0.0
18 */
19 class Control_Media extends Control_Base_Multiple {
20
21 /**
22 * Get media control type.
23 *
24 * Retrieve the control type, in this case `media`.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @return string Control type.
30 */
31 public function get_type() {
32 return 'media';
33 }
34
35 /**
36 * Get media control default values.
37 *
38 * Retrieve the default value of the media control. Used to return the default
39 * values while initializing the media control.
40 *
41 * @since 1.0.0
42 * @access public
43 *
44 * @return array Control default value.
45 */
46 public function get_default_value() {
47 return [
48 'url' => '',
49 'id' => '',
50 'size' => '',
51 ];
52 }
53
54 /**
55 * Import media images.
56 *
57 * Used to import media control files from external sites while importing
58 * Elementor template JSON file, and replacing the old data.
59 *
60 * @since 1.0.0
61 * @access public
62 *
63 * @param array $settings Control settings
64 *
65 * @return array Control settings.
66 */
67 public function on_import( $settings ) {
68 if ( empty( $settings['url'] ) ) {
69 return $settings;
70 }
71
72 $settings = Plugin::$instance->templates_manager->get_import_images_instance()->import( $settings );
73
74 if ( ! $settings ) {
75 $settings = [
76 'id' => '',
77 'url' => Utils::get_placeholder_image_src(),
78 ];
79 }
80
81 return $settings;
82 }
83
84 /**
85 * Support SVG and JSON Import
86 *
87 * Called by the 'upload_mimes' filter. Adds SVG and JSON mime types to the list of WordPress' allowed mime types.
88 *
89 * @since 3.4.6
90 * @deprecated 3.5.0
91 *
92 * @param $mimes
93 * @return mixed
94 */
95 public function support_svg_and_json_import( $mimes ) {
96 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' );
97
98 return $mimes;
99 }
100
101 /**
102 * Enqueue media control scripts and styles.
103 *
104 * Used to register and enqueue custom scripts and styles used by the media
105 * control.
106 *
107 * @since 1.0.0
108 * @access public
109 */
110 public function enqueue() {
111 global $wp_version;
112
113 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
114 wp_enqueue_media();
115
116 wp_enqueue_style(
117 'media',
118 admin_url( '/css/media' . $suffix . '.css' ),
119 [],
120 $wp_version
121 );
122
123 wp_register_script(
124 'image-edit',
125 '/wp-admin/js/image-edit' . $suffix . '.js',
126 [
127 'jquery',
128 'json2',
129 'imgareaselect',
130 ],
131 $wp_version,
132 true
133 );
134
135 wp_enqueue_script( 'image-edit' );
136 }
137
138 /**
139 * Render media control output in the editor.
140 *
141 * Used to generate the control HTML in the editor using Underscore JS
142 * template. The variables for the class are available using `data` JS
143 * object.
144 *
145 * @since 1.0.0
146 * @access public
147 */
148 public function content_template() {
149 ?>
150 <#
151 // For BC.
152 if ( data.media_type ) {
153 data.media_types = [ data.media_type ];
154 }
155
156 if ( data.should_include_svg_inline_option ) {
157 data.media_types.push( 'svg' );
158 }
159
160 // Determine if the current media type is viewable.
161 const isViewable = () => {
162 const viewable = [
163 'image',
164 'video',
165 'svg',
166 ];
167
168 // Make sure that all media types are viewable.
169 return data.media_types.every( ( type ) => viewable.includes( type ) );
170 };
171
172 // Get the preview type for the current media type.
173 const getPreviewType = () => {
174 if ( data.media_types.includes( 'video' ) ) {
175 return 'video';
176 }
177
178 if ( data.media_types.includes( 'image' ) || data.media_types.includes( 'svg' ) ) {
179 return 'image';
180 }
181
182 return 'none';
183 }
184
185 // Retrieve a button label by media type.
186 const getButtonLabel = ( mediaType ) => {
187 switch( mediaType ) {
188 case 'image':
189 return '<?php esc_html_e( 'Choose Image', 'elementor' ); ?>';
190
191 case 'video':
192 return '<?php esc_html_e( 'Choose Video', 'elementor' ); ?>';
193
194 case 'svg':
195 return '<?php esc_html_e( 'Choose SVG', 'elementor' ); ?>';
196
197 default:
198 return '<?php esc_html_e( 'Choose File', 'elementor' ); ?>';
199 }
200 }
201 #>
202 <div class="elementor-control-field elementor-control-media">
203 <label class="elementor-control-title">{{{ data.label }}}</label>
204 <#
205 if ( isViewable() ) {
206 let inputWrapperClasses = 'elementor-control-input-wrapper';
207
208 if ( ! data.label_block ) {
209 inputWrapperClasses += ' elementor-control-unit-5';
210 }
211 #>
212 <div class="{{{ inputWrapperClasses }}}">
213 <div class="elementor-control-media__content elementor-control-tag-area elementor-control-preview-area">
214 <div class="elementor-control-media-area">
215 <div class="elementor-control-media__remove elementor-control-media__content__remove" title="<?php echo esc_attr__( 'Remove', 'elementor' ); ?>">
216 <i class="eicon-trash-o" aria-hidden="true"></i>
217 <span class="elementor-screen-only"><?php echo esc_html__( 'Remove', 'elementor' ); ?></span>
218 </div>
219 <#
220 switch( getPreviewType() ) {
221 case 'image':
222 #>
223 <div class="elementor-control-media__preview"></div>
224 <#
225 break;
226
227 case 'video':
228 #>
229 <video class="elementor-control-media-video" preload="metadata"></video>
230 <i class="eicon-video-camera" aria-hidden="true"></i>
231 <#
232 break;
233 }
234 #>
235 </div>
236 <div class="elementor-control-media-upload-button elementor-control-media__content__upload-button">
237 <i class="eicon-plus-circle" aria-hidden="true"></i>
238 <span class="elementor-screen-only"><?php echo esc_html__( 'Add', 'elementor' ); ?></span>
239 </div>
240 <div class="elementor-control-media__tools elementor-control-dynamic-switcher-wrapper">
241 <#
242 data.media_types.forEach( ( type ) => {
243 #>
244 <div class="elementor-control-media__tool elementor-control-media__replace" data-media-type="{{{ type }}}">{{{ getButtonLabel( type ) }}}</div>
245 <#
246 } );
247 #>
248 </div>
249 </div>
250
251 <?php /* ?>
252 <div class="elementor-control-media__warnings" role="alert" style="display: none;">
253 <?php
254 Hints::get_notice_template( [
255 'type' => 'warning',
256 'content' => esc_html__( 'This image doesn’t contain ALT text - which is necessary for accessibility and SEO.', 'elementor' ),
257 'icon' => true,
258 ] );
259 ?>
260 </div>
261 <?php */ ?>
262
263 <?php if ( Hints::should_display_hint( 'image-optimization' ) ) : ?>
264 <div class="elementor-control-media__promotions" role="alert" style="display: none;">
265 <?php
266 Hints::get_notice_template( [
267 'display' => ! Hints::is_dismissed( 'image-optimization' ),
268 'type' => 'info',
269 'content' => __( 'Optimize your images to enhance site performance by using Image Optimizer.', 'elementor' ),
270 'icon' => true,
271 'dismissible' => 'image_optimizer_hint',
272 'button_text' => Hints::is_plugin_installed( 'image-optimization' ) ? __( 'Activate Plugin', 'elementor' ) : __( 'Install Plugin', 'elementor' ),
273 'button_event' => 'image_optimizer_hint',
274 'button_data' => [
275 'action_url' => Hints::get_plugin_action_url( 'image-optimization' ),
276 ],
277 ] ); ?>
278 </div>
279 <?php endif; ?>
280
281 </div>
282 <# } /* endif isViewable() */ else { #>
283 <div class="elementor-control-media__file elementor-control-preview-area">
284 <div class="elementor-control-media__file__content">
285 <div class="elementor-control-media__file__content__label"><?php echo esc_html__( 'Click the media icon to upload file', 'elementor' ); ?></div>
286 <div class="elementor-control-media__file__content__info">
287 <div class="elementor-control-media__file__content__info__icon">
288 <i class="eicon-document-file"></i>
289 </div>
290 <div class="elementor-control-media__file__content__info__name"></div>
291 </div>
292 </div>
293 <div class="elementor-control-media__file__controls">
294 <div class="elementor-control-media__remove elementor-control-media__file__controls__remove" title="<?php echo esc_attr__( 'Remove', 'elementor' ); ?>">
295 <i class="eicon-trash-o" aria-hidden="true"></i>
296 <span class="elementor-screen-only"><?php echo esc_html__( 'Remove', 'elementor' ); ?></span>
297 </div>
298 <div class="elementor-control-media__file__controls__upload-button elementor-control-media-upload-button" title="<?php echo esc_attr__( 'Upload', 'elementor' ); ?>">
299 <i class="eicon-upload" aria-hidden="true"></i>
300 <span class="elementor-screen-only"><?php echo esc_html__( 'Upload', 'elementor' ); ?></span>
301 </div>
302 </div>
303 </div>
304 <# } #>
305 <# if ( data.description ) { #>
306 <div class="elementor-control-field-description">{{{ data.description }}}</div>
307 <# } #>
308
309 <# if ( data.has_sizes ) { #>
310 <div class="elementor-control-type-select e-control-image-size">
311 <div class="elementor-control-field">
312 <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>
313 <div class="elementor-control-input-wrapper elementor-control-unit-5">
314 <select class="e-image-size-select" id="<?php $this->print_control_uid( 'size' ); ?>" data-setting="size">
315 <?php foreach ( $this->get_image_sizes() as $size_key => $size_title ) : ?>
316 <option value="<?php echo esc_attr( $size_key ); ?>"><?php echo esc_html( $size_title ); ?></option>
317 <?php endforeach; ?>
318 </select>
319 </div>
320 </div>
321 </div>
322 <# } #>
323
324 <input type="hidden" data-setting="{{ data.name }}"/>
325 </div>
326 <?php
327 }
328
329 private function get_image_sizes() : array {
330 $wp_image_sizes = Group_Control_Image_Size::get_all_image_sizes();
331
332 $image_sizes = [];
333
334 foreach ( $wp_image_sizes as $size_key => $size_attributes ) {
335 $control_title = ucwords( str_replace( '_', ' ', $size_key ) );
336 if ( is_array( $size_attributes ) ) {
337 $control_title .= sprintf( ' - %d x %d', $size_attributes['width'], $size_attributes['height'] );
338 }
339
340 $image_sizes[ $size_key ] = $control_title;
341 }
342
343 $image_sizes[''] = esc_html_x( 'Full', 'Image Size Control', 'elementor' );
344
345 return $image_sizes;
346 }
347
348 /**
349 * Get media control default settings.
350 *
351 * Retrieve the default settings of the media control. Used to return the default
352 * settings while initializing the media control.
353 *
354 * @since 1.0.0
355 * @access protected
356 *
357 * @return array Control default settings.
358 */
359 protected function get_default_settings() {
360 return [
361 'label_block' => true,
362 'has_sizes' => false,
363 'ai' => [
364 'active' => true,
365 'type' => 'media',
366 'category' => 'photographic',
367 ],
368 'media_types' => [
369 'image',
370 ],
371 'dynamic' => [
372 'categories' => [ TagsModule::IMAGE_CATEGORY ],
373 'returnType' => 'object',
374 ],
375 ];
376 }
377
378 /**
379 * Get media control image title.
380 *
381 * Retrieve the `title` of the image selected by the media control.
382 *
383 * @since 1.0.0
384 * @access public
385 * @static
386 *
387 * @param array $attachment Media attachment.
388 *
389 * @return string Image title.
390 */
391 public static function get_image_title( $attachment ) {
392 if ( empty( $attachment['id'] ) ) {
393 return '';
394 }
395
396 return get_the_title( $attachment['id'] );
397 }
398
399 /**
400 * Get media control image alt.
401 *
402 * Retrieve the `alt` value of the image selected by the media control.
403 *
404 * @since 1.0.0
405 * @access public
406 * @static
407 *
408 * @param array $instance Media attachment.
409 *
410 * @return string Image alt.
411 */
412 public static function get_image_alt( $instance ) {
413 if ( empty( $instance['id'] ) ) {
414 // For `Insert From URL` images.
415 return isset( $instance['alt'] ) ? trim( self::sanitise_text( $instance['alt'] ) ) : '';
416 }
417
418 $attachment_id = $instance['id'];
419 if ( ! $attachment_id ) {
420 return '';
421 }
422
423 $attachment = get_post( $attachment_id );
424 if ( ! $attachment ) {
425 return '';
426 }
427
428 $alt = get_post_meta( $attachment_id, '_wp_attachment_image_alt', true );
429 if ( ! $alt ) {
430 if ( Utils::has_invalid_post_permissions( $attachment ) ) {
431 return '';
432 }
433
434 $alt = $attachment->post_excerpt;
435 if ( ! $alt ) {
436 $alt = $attachment->post_title;
437 }
438 }
439 return trim( self::sanitise_text( $alt ) );
440 }
441
442 public function get_style_value( $css_property, $control_value, array $control_data ) {
443 if ( 'URL' !== $css_property || empty( $control_value['id'] ) ) {
444 return parent::get_style_value( $css_property, $control_value, $control_data );
445 }
446
447 if ( empty( $control_value['size'] ) ) {
448 $control_value['size'] = 'full';
449 }
450
451 return wp_get_attachment_image_url( $control_value['id'], $control_value['size'] );
452 }
453
454 public static function sanitise_text( $string ) {
455 return esc_attr( strip_tags( $string ) );
456 }
457 }
458