PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.7
Elementor Website Builder – more than just a page builder v3.25.7
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 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 All 451 releases
elementor / includes / widgets / image-box.php

image-box.php in Elementor Website Builder – more than just a page builder 3.25.7, at includes/widgets/image-box.php

759 lines 17.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
9 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
10
11 /**
12 * Elementor image box widget.
13 *
14 * Elementor widget that displays an image, a headline and a text.
15 *
16 * @since 1.0.0
17 */
18 class Widget_Image_Box extends Widget_Base {
19
20 /**
21 * Get widget name.
22 *
23 * Retrieve image box widget name.
24 *
25 * @since 1.0.0
26 * @access public
27 *
28 * @return string Widget name.
29 */
30 public function get_name() {
31 return 'image-box';
32 }
33
34 /**
35 * Get widget title.
36 *
37 * Retrieve image box widget title.
38 *
39 * @since 1.0.0
40 * @access public
41 *
42 * @return string Widget title.
43 */
44 public function get_title() {
45 return esc_html__( 'Image Box', 'elementor' );
46 }
47
48 /**
49 * Get widget icon.
50 *
51 * Retrieve image box widget icon.
52 *
53 * @since 1.0.0
54 * @access public
55 *
56 * @return string Widget icon.
57 */
58 public function get_icon() {
59 return 'eicon-image-box';
60 }
61
62 /**
63 * Get widget keywords.
64 *
65 * Retrieve the list of keywords the widget belongs to.
66 *
67 * @since 2.1.0
68 * @access public
69 *
70 * @return array Widget keywords.
71 */
72 public function get_keywords() {
73 return [ 'image', 'photo', 'visual', 'box' ];
74 }
75
76 protected function is_dynamic_content(): bool {
77 return false;
78 }
79
80 /**
81 * Get style dependencies.
82 *
83 * Retrieve the list of style dependencies the widget requires.
84 *
85 * @since 3.24.0
86 * @access public
87 *
88 * @return array Widget style dependencies.
89 */
90 public function get_style_depends(): array {
91 return [ 'widget-image-box' ];
92 }
93
94 /**
95 * Register image box widget controls.
96 *
97 * Adds different input fields to allow the user to change and customize the widget settings.
98 *
99 * @since 3.1.0
100 * @access protected
101 */
102 protected function register_controls() {
103 $this->start_controls_section(
104 'section_image',
105 [
106 'label' => esc_html__( 'Image Box', 'elementor' ),
107 ]
108 );
109
110 $this->add_control(
111 'image',
112 [
113 'label' => esc_html__( 'Choose Image', 'elementor' ),
114 'type' => Controls_Manager::MEDIA,
115 'dynamic' => [
116 'active' => true,
117 ],
118 'default' => [
119 'url' => Utils::get_placeholder_image_src(),
120 ],
121 ]
122 );
123
124 $this->add_group_control(
125 Group_Control_Image_Size::get_type(),
126 [
127 'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
128 'default' => 'full',
129 'condition' => [
130 'image[url]!' => '',
131 ],
132 ]
133 );
134
135 $this->add_control(
136 'title_text',
137 [
138 'label' => esc_html__( 'Title', 'elementor' ),
139 'type' => Controls_Manager::TEXT,
140 'dynamic' => [
141 'active' => true,
142 ],
143 'default' => esc_html__( 'This is the heading', 'elementor' ),
144 'placeholder' => esc_html__( 'Enter your title', 'elementor' ),
145 'label_block' => true,
146 ]
147 );
148
149 $this->add_control(
150 'description_text',
151 [
152 'label' => esc_html__( 'Description', 'elementor' ),
153 'type' => Controls_Manager::TEXTAREA,
154 'dynamic' => [
155 'active' => true,
156 ],
157 'default' => esc_html__( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'elementor' ),
158 'placeholder' => esc_html__( 'Enter your description', 'elementor' ),
159 'rows' => 10,
160 ]
161 );
162
163 $this->add_control(
164 'link',
165 [
166 'label' => esc_html__( 'Link', 'elementor' ),
167 'type' => Controls_Manager::URL,
168 'dynamic' => [
169 'active' => true,
170 ],
171 'separator' => 'before',
172 ]
173 );
174
175 $this->add_control(
176 'title_size',
177 [
178 'label' => esc_html__( 'Title HTML Tag', 'elementor' ),
179 'type' => Controls_Manager::SELECT,
180 'options' => [
181 'h1' => 'H1',
182 'h2' => 'H2',
183 'h3' => 'H3',
184 'h4' => 'H4',
185 'h5' => 'H5',
186 'h6' => 'H6',
187 'div' => 'div',
188 'span' => 'span',
189 'p' => 'p',
190 ],
191 'default' => 'h3',
192 ]
193 );
194
195 $this->end_controls_section();
196
197 $this->start_controls_section(
198 'section_style_box',
199 [
200 'label' => esc_html__( 'Box', 'elementor' ),
201 'tab' => Controls_Manager::TAB_STYLE,
202 ]
203 );
204
205 $this->add_responsive_control(
206 'position',
207 [
208 'label' => esc_html__( 'Image Position', 'elementor' ),
209 'type' => Controls_Manager::CHOOSE,
210 'default' => 'top',
211 'options' => [
212 'left' => [
213 'title' => esc_html__( 'Left', 'elementor' ),
214 'icon' => 'eicon-h-align-left',
215 ],
216 'top' => [
217 'title' => esc_html__( 'Top', 'elementor' ),
218 'icon' => 'eicon-v-align-top',
219 ],
220 'right' => [
221 'title' => esc_html__( 'Right', 'elementor' ),
222 'icon' => 'eicon-h-align-right',
223 ],
224 ],
225 'prefix_class' => 'elementor-position-',
226 'toggle' => false,
227 'condition' => [
228 'image[url]!' => '',
229 ],
230 ]
231 );
232
233 $this->add_responsive_control(
234 'content_vertical_alignment',
235 [
236 'label' => esc_html__( 'Vertical Alignment', 'elementor' ),
237 'type' => Controls_Manager::CHOOSE,
238 'options' => [
239 'top' => [
240 'title' => esc_html__( 'Top', 'elementor' ),
241 'icon' => 'eicon-v-align-top',
242 ],
243 'middle' => [
244 'title' => esc_html__( 'Middle', 'elementor' ),
245 'icon' => 'eicon-v-align-middle',
246 ],
247 'bottom' => [
248 'title' => esc_html__( 'Bottom', 'elementor' ),
249 'icon' => 'eicon-v-align-bottom',
250 ],
251 ],
252 'default' => 'top',
253 'toggle' => false,
254 'prefix_class' => 'elementor-vertical-align-',
255 'condition' => [
256 'position!' => 'top',
257 ],
258 ]
259 );
260
261 $this->add_responsive_control(
262 'text_align',
263 [
264 'label' => esc_html__( 'Alignment', 'elementor' ),
265 'type' => Controls_Manager::CHOOSE,
266 'options' => [
267 'left' => [
268 'title' => esc_html__( 'Left', 'elementor' ),
269 'icon' => 'eicon-text-align-left',
270 ],
271 'center' => [
272 'title' => esc_html__( 'Center', 'elementor' ),
273 'icon' => 'eicon-text-align-center',
274 ],
275 'right' => [
276 'title' => esc_html__( 'Right', 'elementor' ),
277 'icon' => 'eicon-text-align-right',
278 ],
279 'justify' => [
280 'title' => esc_html__( 'Justified', 'elementor' ),
281 'icon' => 'eicon-text-align-justify',
282 ],
283 ],
284 'selectors' => [
285 '{{WRAPPER}} .elementor-image-box-wrapper' => 'text-align: {{VALUE}};',
286 ],
287 'separator' => 'after',
288 ]
289 );
290
291 $this->add_responsive_control(
292 'image_space',
293 [
294 'label' => esc_html__( 'Image Spacing', 'elementor' ),
295 'type' => Controls_Manager::SLIDER,
296 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
297 'default' => [
298 'size' => 15,
299 ],
300 'range' => [
301 'px' => [
302 'max' => 100,
303 ],
304 ],
305 'selectors' => [
306 '{{WRAPPER}}.elementor-position-right .elementor-image-box-img' => 'margin-left: {{SIZE}}{{UNIT}};',
307 '{{WRAPPER}}.elementor-position-left .elementor-image-box-img' => 'margin-right: {{SIZE}}{{UNIT}};',
308 '{{WRAPPER}}.elementor-position-top .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
309 '(mobile){{WRAPPER}} .elementor-image-box-img' => 'margin-bottom: {{SIZE}}{{UNIT}};',
310 ],
311 'condition' => [
312 'image[url]!' => '',
313 ],
314 ]
315 );
316
317 $this->add_responsive_control(
318 'title_bottom_space',
319 [
320 'label' => esc_html__( 'Content Spacing', 'elementor' ),
321 'type' => Controls_Manager::SLIDER,
322 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
323 'range' => [
324 'px' => [
325 'max' => 100,
326 ],
327 'em' => [
328 'min' => 0,
329 'max' => 10,
330 ],
331 'rem' => [
332 'min' => 0,
333 'max' => 10,
334 ],
335 ],
336 'selectors' => [
337 '{{WRAPPER}} .elementor-image-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
338 ],
339 ]
340 );
341
342 $this->end_controls_section();
343
344 $this->start_controls_section(
345 'section_style_image',
346 [
347 'label' => esc_html__( 'Image', 'elementor' ),
348 'tab' => Controls_Manager::TAB_STYLE,
349 'condition' => [
350 'image[url]!' => '',
351 ],
352 ]
353 );
354
355 $this->add_responsive_control(
356 'image_size',
357 [
358 'label' => esc_html__( 'Width', 'elementor' ),
359 'type' => Controls_Manager::SLIDER,
360 'default' => [
361 'size' => 30,
362 'unit' => '%',
363 ],
364 'tablet_default' => [
365 'unit' => '%',
366 ],
367 'mobile_default' => [
368 'unit' => '%',
369 ],
370 'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ],
371 'range' => [
372 '%' => [
373 'min' => 5,
374 'max' => 100,
375 ],
376 ],
377 'selectors' => [
378 '{{WRAPPER}} .elementor-image-box-wrapper .elementor-image-box-img' => 'width: {{SIZE}}{{UNIT}};',
379 ],
380 ]
381 );
382
383 $this->add_group_control(
384 Group_Control_Border::get_type(),
385 [
386 'name' => 'image_border',
387 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
388 'separator' => 'before',
389 ]
390 );
391
392 $this->add_responsive_control(
393 'image_border_radius',
394 [
395 'label' => esc_html__( 'Border Radius', 'elementor' ),
396 'type' => Controls_Manager::SLIDER,
397 'size_units' => [ 'px', '%', 'em', 'rem', 'custom' ],
398 'separator' => 'after',
399 'selectors' => [
400 '{{WRAPPER}} .elementor-image-box-img img' => 'border-radius: {{SIZE}}{{UNIT}};',
401 ],
402 ]
403 );
404
405 $this->start_controls_tabs( 'image_effects' );
406
407 $this->start_controls_tab(
408 'normal',
409 [
410 'label' => esc_html__( 'Normal', 'elementor' ),
411 ]
412 );
413
414 $this->add_group_control(
415 Group_Control_Css_Filter::get_type(),
416 [
417 'name' => 'css_filters',
418 'selector' => '{{WRAPPER}} .elementor-image-box-img img',
419 ]
420 );
421
422 $this->add_control(
423 'image_opacity',
424 [
425 'label' => esc_html__( 'Opacity', 'elementor' ),
426 'type' => Controls_Manager::SLIDER,
427 'range' => [
428 'px' => [
429 'max' => 1,
430 'min' => 0.10,
431 'step' => 0.01,
432 ],
433 ],
434 'selectors' => [
435 '{{WRAPPER}} .elementor-image-box-img img' => 'opacity: {{SIZE}};',
436 ],
437 ]
438 );
439
440 $this->end_controls_tab();
441
442 $this->start_controls_tab(
443 'hover',
444 [
445 'label' => esc_html__( 'Hover', 'elementor' ),
446 ]
447 );
448
449 $this->add_group_control(
450 Group_Control_Css_Filter::get_type(),
451 [
452 'name' => 'css_filters_hover',
453 'selector' => '{{WRAPPER}}:hover .elementor-image-box-img img',
454 ]
455 );
456
457 $this->add_control(
458 'image_opacity_hover',
459 [
460 'label' => esc_html__( 'Opacity', 'elementor' ),
461 'type' => Controls_Manager::SLIDER,
462 'range' => [
463 'px' => [
464 'max' => 1,
465 'min' => 0.10,
466 'step' => 0.01,
467 ],
468 ],
469 'selectors' => [
470 '{{WRAPPER}}:hover .elementor-image-box-img img' => 'opacity: {{SIZE}};',
471 ],
472 ]
473 );
474
475 $this->add_control(
476 'background_hover_transition',
477 [
478 'label' => esc_html__( 'Transition Duration', 'elementor' ) . ' (s)',
479 'type' => Controls_Manager::SLIDER,
480 'default' => [
481 'size' => 0.3,
482 ],
483 'range' => [
484 'px' => [
485 'min' => 0,
486 'max' => 3,
487 'step' => 0.1,
488 ],
489 ],
490 'selectors' => [
491 '{{WRAPPER}} .elementor-image-box-img img' => 'transition-duration: {{SIZE}}s',
492 ],
493 ]
494 );
495
496 $this->add_control(
497 'hover_animation',
498 [
499 'label' => esc_html__( 'Hover Animation', 'elementor' ),
500 'type' => Controls_Manager::HOVER_ANIMATION,
501 ]
502 );
503
504 $this->end_controls_tab();
505
506 $this->end_controls_tabs();
507
508 $this->end_controls_section();
509
510 $this->start_controls_section(
511 'section_style_content',
512 [
513 'label' => esc_html__( 'Content', 'elementor' ),
514 'tab' => Controls_Manager::TAB_STYLE,
515 ]
516 );
517
518 $this->add_control(
519 'heading_title',
520 [
521 'label' => esc_html__( 'Title', 'elementor' ),
522 'type' => Controls_Manager::HEADING,
523 'separator' => 'before',
524 ]
525 );
526
527 $this->add_control(
528 'title_color',
529 [
530 'label' => esc_html__( 'Color', 'elementor' ),
531 'type' => Controls_Manager::COLOR,
532 'default' => '',
533 'selectors' => [
534 '{{WRAPPER}} .elementor-image-box-title' => 'color: {{VALUE}};',
535 ],
536 'global' => [
537 'default' => Global_Colors::COLOR_PRIMARY,
538 ],
539 ]
540 );
541
542 $this->add_group_control(
543 Group_Control_Typography::get_type(),
544 [
545 'name' => 'title_typography',
546 'selector' => '{{WRAPPER}} .elementor-image-box-title',
547 'global' => [
548 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
549 ],
550 ]
551 );
552
553 $this->add_group_control(
554 Group_Control_Text_Stroke::get_type(),
555 [
556 'name' => 'title_stroke',
557 'selector' => '{{WRAPPER}} .elementor-image-box-title',
558 ]
559 );
560
561 $this->add_group_control(
562 Group_Control_Text_Shadow::get_type(),
563 [
564 'name' => 'title_shadow',
565 'selector' => '{{WRAPPER}} .elementor-image-box-title',
566 ]
567 );
568
569 $this->add_control(
570 'heading_description',
571 [
572 'label' => esc_html__( 'Description', 'elementor' ),
573 'type' => Controls_Manager::HEADING,
574 'separator' => 'before',
575 ]
576 );
577
578 $this->add_control(
579 'description_color',
580 [
581 'label' => esc_html__( 'Color', 'elementor' ),
582 'type' => Controls_Manager::COLOR,
583 'default' => '',
584 'selectors' => [
585 '{{WRAPPER}} .elementor-image-box-description' => 'color: {{VALUE}};',
586 ],
587 'global' => [
588 'default' => Global_Colors::COLOR_TEXT,
589 ],
590 ]
591 );
592
593 $this->add_group_control(
594 Group_Control_Typography::get_type(),
595 [
596 'name' => 'description_typography',
597 'selector' => '{{WRAPPER}} .elementor-image-box-description',
598 'global' => [
599 'default' => Global_Typography::TYPOGRAPHY_TEXT,
600 ],
601 ]
602 );
603
604 $this->add_group_control(
605 Group_Control_Text_Shadow::get_type(),
606 [
607 'name' => 'description_shadow',
608 'selector' => '{{WRAPPER}} .elementor-image-box-description',
609 ]
610 );
611
612 $this->end_controls_section();
613 }
614
615 /**
616 * Render image box widget output on the frontend.
617 *
618 * Written in PHP and used to generate the final HTML.
619 *
620 * @since 1.0.0
621 * @access protected
622 */
623 protected function render() {
624 $settings = $this->get_settings_for_display();
625
626 $has_image = ! empty( $settings['image']['url'] );
627 $has_content = ! Utils::is_empty( $settings['title_text'] ) || ! Utils::is_empty( $settings['description_text'] );
628
629 if ( ! $has_image && ! $has_content ) {
630 return;
631 }
632
633 $html = '<div class="elementor-image-box-wrapper">';
634
635 if ( ! empty( $settings['link']['url'] ) ) {
636 $this->add_link_attributes( 'link', $settings['link'] );
637 }
638
639 if ( $has_image ) {
640
641 $image_html = wp_kses_post( Group_Control_Image_Size::get_attachment_image_html( $settings, 'thumbnail', 'image' ) );
642
643 if ( ! empty( $settings['link']['url'] ) ) {
644 $image_html = '<a ' . $this->get_render_attribute_string( 'link' ) . ' tabindex="-1">' . $image_html . '</a>';
645 }
646
647 $html .= '<figure class="elementor-image-box-img">' . $image_html . '</figure>';
648 }
649
650 if ( $has_content ) {
651 $html .= '<div class="elementor-image-box-content">';
652
653 if ( ! Utils::is_empty( $settings['title_text'] ) ) {
654 $this->add_render_attribute( 'title_text', 'class', 'elementor-image-box-title' );
655
656 $this->add_inline_editing_attributes( 'title_text', 'none' );
657
658 $title_html = $settings['title_text'];
659
660 if ( ! empty( $settings['link']['url'] ) ) {
661 $title_html = '<a ' . $this->get_render_attribute_string( 'link' ) . '>' . $title_html . '</a>';
662 }
663
664 $html .= sprintf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $settings['title_size'] ), $this->get_render_attribute_string( 'title_text' ), $title_html );
665 }
666
667 if ( ! Utils::is_empty( $settings['description_text'] ) ) {
668 $this->add_render_attribute( 'description_text', 'class', 'elementor-image-box-description' );
669
670 $this->add_inline_editing_attributes( 'description_text' );
671
672 $html .= sprintf( '<p %1$s>%2$s</p>', $this->get_render_attribute_string( 'description_text' ), $settings['description_text'] );
673 }
674
675 $html .= '</div>';
676 }
677
678 $html .= '</div>';
679
680 Utils::print_unescaped_internal_string( $html );
681 }
682
683 /**
684 * Render image box widget output in the editor.
685 *
686 * Written as a Backbone JavaScript template and used to generate the live preview.
687 *
688 * @since 2.9.0
689 * @access protected
690 */
691 protected function content_template() {
692 ?>
693 <#
694 var hasImage = !! settings.image.url;
695 var hasContent = !! ( settings.title_text || settings.description_text );
696
697 if ( ! hasImage && ! hasContent ) {
698 return;
699 }
700
701 var html = '<div class="elementor-image-box-wrapper">';
702
703 if ( hasImage ) {
704 var image = {
705 id: settings.image.id,
706 url: settings.image.url,
707 size: settings.thumbnail_size,
708 dimension: settings.thumbnail_custom_dimension,
709 model: view.getEditModel()
710 };
711
712 var image_url = elementor.imagesManager.getImageUrl( image );
713
714 var imageHtml = '<img src="' + _.escape( image_url ) + '" class="elementor-animation-' + _.escape( settings.hover_animation ) + '" />';
715
716 if ( settings.link.url ) {
717 imageHtml = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '" tabindex="-1">' + imageHtml + '</a>';
718 }
719
720 html += '<figure class="elementor-image-box-img">' + imageHtml + '</figure>';
721 }
722
723 if ( hasContent ) {
724 html += '<div class="elementor-image-box-content">';
725
726 if ( settings.title_text ) {
727 var title_html = elementor.helpers.sanitize( settings.title_text ),
728 titleSizeTag = elementor.helpers.validateHTMLTag( settings.title_size );
729
730 if ( settings.link.url ) {
731 title_html = '<a href="' + elementor.helpers.sanitizeUrl( settings.link.url ) + '">' + title_html + '</a>';
732 }
733
734 view.addRenderAttribute( 'title_text', 'class', 'elementor-image-box-title' );
735
736 view.addInlineEditingAttributes( 'title_text', 'none' );
737
738 html += '<' + titleSizeTag + ' ' + view.getRenderAttributeString( 'title_text' ) + '>' + title_html + '</' + titleSizeTag + '>';
739 }
740
741 if ( settings.description_text ) {
742 view.addRenderAttribute( 'description_text', 'class', 'elementor-image-box-description' );
743
744 view.addInlineEditingAttributes( 'description_text' );
745
746 html += '<p ' + view.getRenderAttributeString( 'description_text' ) + '>' + settings.description_text + '</p>';
747 }
748
749 html += '</div>';
750 }
751
752 html += '</div>';
753
754 print( html );
755 #>
756 <?php
757 }
758 }
759