PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev6
Elementor Website Builder – more than just a page builder v3.23.0-dev6
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.23.0-dev6, at includes/widgets/image-box.php

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