PluginProbe
Bricksable for Bricks Builder / 1.3.6
Bricksable for Bricks Builder v1.3.6
1.2.9 1.3.0 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.31 1.4.32 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 All 132 releases
bricksable / includes / elements / element-tilt-image.php

element-tilt-image.php in Bricksable for Bricks Builder 1.3.6, at includes/elements/element-tilt-image.php

745 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly.
5 }
6
7 class Bricksable_Tilt_Image extends \Bricks\Element {
8 public $category = 'bricksable';
9 public $name = 'ba-tilt-image';
10 public $icon = 'ti-image';
11 public $css_selector = '.ba-tilt-image-wrapper img';
12 public $scripts = array( 'bricksableTiltImage' );
13
14 public function get_label() {
15 return esc_html__( 'Tilt Image', 'bricksable' );
16 }
17 public function set_control_groups() {
18 $this->control_groups['image'] = array(
19 'title' => esc_html__( 'Image', 'bricksable' ),
20 'tab' => 'content',
21 );
22 $this->control_groups['tilt_settings'] = array(
23 'title' => esc_html__( 'Tilt Settings', 'bricksable' ),
24 'tab' => 'content',
25 );
26 $this->control_groups['tilt_alignment'] = array(
27 'title' => esc_html__( 'Alignment', 'bricksable' ),
28 'tab' => 'style',
29 );
30 $this->control_groups['overlay'] = array(
31 'title' => esc_html__( 'Overlay Content', 'bricksable' ),
32 'tab' => 'content',
33 );
34 $this->control_groups['overlay_style'] = array(
35 'title' => esc_html__( 'Overlay', 'bricksable' ),
36 'tab' => 'style',
37 );
38 unset( $this->control_groups['_typography'] );
39 }
40
41 public function set_controls() {
42 $this->controls['_gradient']['css'][0]['selector'] = '.ba-tilt-image-wrapper';
43 $this->controls['_border']['css'][] =
44 array(
45 'property' => 'border',
46 'selector' => '.ba-tilt-image-wrapper:before',
47 );
48 array(
49 'property' => 'border',
50 'selector' => '.ba-tilt-image-wrapper img',
51 );
52
53 $this->controls['image'] = array(
54 'tab' => 'content',
55 'group' => 'image',
56 'type' => 'image',
57 );
58 // Link To.
59 $this->controls['linkToSeparator'] = array(
60 'tab' => 'content',
61 'group' => 'image',
62 'type' => 'separator',
63 'label' => esc_html__( 'Link To', 'bricksable' ),
64 );
65
66 $this->controls['link'] = array(
67 'tab' => 'content',
68 'group' => 'image',
69 'type' => 'select',
70 'options' => array(
71 'lightbox' => esc_html__( 'Lightbox', 'bricksable' ),
72 'attachment' => esc_html__( 'Attachment Page', 'bricksable' ),
73 'media' => esc_html__( 'Media File', 'bricksable' ),
74 'url' => esc_html__( 'Other (URL)', 'bricksable' ),
75 ),
76 'placeholder' => esc_html__( 'None', 'bricksable' ),
77 );
78
79 $this->controls['url'] = array(
80 'tab' => 'content',
81 'group' => 'image',
82 'label' => esc_html__( 'Link type', 'bricksable' ),
83 'type' => 'link',
84 'required' => array( 'link', '=', 'url' ),
85 );
86
87 // Alignment.
88 $this->controls['tilt_textAlign'] = array(
89 'tab' => 'style',
90 'group' => 'tilt_alignment',
91 'label' => esc_html__( 'Text align', 'bricksable' ),
92 'type' => 'text-align',
93 'css' => array(
94 array(
95 'property' => 'text-align',
96 'selector' => '.ba-tilt-image-wrapper .image-overlay-content',
97 ),
98 array(
99 'property' => 'text-align',
100 'selector' => '.ba-tilt-image-wrapper .ba-tilt-image-overlay-caption',
101 ),
102 ),
103 'default' => 'center',
104 'placeholder' => esc_html__( 'Center', 'bricksable' ),
105 'inline' => true,
106 );
107
108 $this->controls['tilt_verticalAlign'] = array(
109 'tab' => 'style',
110 'group' => 'tilt_alignment',
111 'label' => esc_html__( 'Vertical align', 'bricksable' ),
112 'type' => 'select',
113 'options' => $this->control_options['alignItems'],
114 'css' => array(
115 array(
116 'property' => 'align-items',
117 'selector' => '.ba-tilt-image-wrapper .image-overlay-wrapper',
118 ),
119 ),
120 'inline' => true,
121 'default' => 'center',
122 'placeholder' => esc_html__( 'Center', 'bricksable' ),
123 );
124
125 // Overlay.
126 $this->controls['imageOverlayShowHover'] = array(
127 'tab' => 'content',
128 'group' => 'overlay',
129 'label' => esc_html__( 'Only show overlay on hover', 'bricksable' ),
130 'type' => 'checkbox',
131 'inline' => true,
132 'description' => esc_html__( 'Set your overlay in the style tab (Gradient/Overlay).', 'bricksable' ),
133 );
134
135 // Title & Caption.
136
137 $this->controls['title_caption_separator'] = array(
138 'tab' => 'content',
139 'group' => 'overlay',
140 'type' => 'separator',
141 'label' => esc_html__( 'Title & Caption', 'bricksable' ),
142 );
143
144 $this->controls['overlay_title'] = array(
145 'tab' => 'content',
146 'group' => 'overlay',
147 'label' => esc_html__( 'Title Type', 'bricksable' ),
148 'type' => 'select',
149 'options' => array(
150 'none' => esc_html__( 'No title', 'bricksable' ),
151 'attachment' => esc_html__( 'Attachment', 'bricksable' ),
152 'custom' => esc_html__( 'Custom', 'bricksable' ),
153 ),
154 'inline' => true,
155 'placeholder' => esc_html__( 'No title', 'bricksable' ),
156 );
157
158 $this->controls['overlay_title_custom'] = array(
159 'tab' => 'content',
160 'group' => 'overlay',
161 'label' => esc_html__( 'Overlay Title', 'bricksable' ),
162 'type' => 'text',
163 'spellcheck' => true,
164 'inlineEditing' => true,
165 'hasDynamicData' => 'text',
166 'required' => array( 'overlay_title', '=', 'custom' ),
167 );
168
169 $this->controls['overlay_title_tag'] = array(
170 'tab' => 'content',
171 'group' => 'overlay',
172 'label' => esc_html__( 'Title Tag', 'bricksable' ),
173 'type' => 'select',
174 'options' => array(
175 'h1' => esc_html__( 'Heading 1 (h1)', 'bricksable' ),
176 'h2' => esc_html__( 'Heading 2 (h2)', 'bricksable' ),
177 'h3' => esc_html__( 'Heading 3 (h3)', 'bricksable' ),
178 'h4' => esc_html__( 'Heading 4 (h4)', 'bricksable' ),
179 'h5' => esc_html__( 'Heading 5 (h5)', 'bricksable' ),
180 'h6' => esc_html__( 'Heading 6 (h6)', 'bricksable' ),
181 ),
182 'clearable' => false,
183 'pasteStyles' => false,
184 'default' => 'h3',
185 'inline' => true,
186 'required' => array( 'overlay_title', '!=', 'none' ),
187 );
188
189 $this->controls['overlay_caption'] = array(
190 'tab' => 'content',
191 'group' => 'overlay',
192 'label' => esc_html__( 'Caption Type', 'bricksable' ),
193 'type' => 'select',
194 'options' => array(
195 'none' => esc_html__( 'No caption', 'bricksable' ),
196 'attachment' => esc_html__( 'Attachment', 'bricksable' ),
197 'custom' => esc_html__( 'Custom', 'bricksable' ),
198 ),
199 'inline' => true,
200 'placeholder' => esc_html__( 'No caption', 'bricksable' ),
201 );
202
203 $this->controls['overlay_caption_custom'] = array(
204 'tab' => 'content',
205 'group' => 'overlay',
206 'label' => esc_html__( 'Custom caption', 'bricksable' ),
207 'type' => 'text',
208 'placeholder' => esc_html__( 'Here goes your caption ...', 'bricksable' ),
209 'required' => array( 'overlay_caption', '=', 'custom' ),
210 );
211
212 $this->controls['overlayShowHover'] = array(
213 'tab' => 'content',
214 'group' => 'overlay',
215 'label' => esc_html__( 'Only show on hover', 'bricksable' ),
216 'type' => 'checkbox',
217 'inline' => true,
218 );
219
220 $this->controls['overlay_icon_separator'] = array(
221 'tab' => 'content',
222 'group' => 'overlay',
223 'label' => esc_html__( 'Icon', 'bricksable' ),
224 'type' => 'separator',
225 'inline' => true,
226 'small' => true,
227 );
228
229 $this->controls['overlay_icon'] = array(
230 'tab' => 'content',
231 'group' => 'overlay',
232 'label' => esc_html__( 'Icon', 'bricksable' ),
233 'type' => 'icon',
234 'inline' => true,
235 'small' => true,
236 );
237
238 $this->controls['overlay_translatez'] = array(
239 'tab' => 'style',
240 'group' => 'overlay_style',
241 'label' => esc_html__( 'Overlay Content Distance', 'bricksable' ),
242 'type' => 'slider',
243 'css' => array(
244 array(
245 'property' => 'transform:translateZ',
246 'selector' => '.image-overlay-wrapper',
247 ),
248 ),
249 'units' => array(
250 'px' => array(
251 'min' => 1,
252 'max' => 200,
253 'step' => 1,
254 ),
255 ),
256 'default' => '50px',
257 'description' => esc_html__( 'Adjust the distance between the image and the overlay content.', 'bricksable' ),
258 );
259
260 $this->controls['overlay_title_typography'] = array(
261 'tab' => 'style',
262 'group' => 'overlay_style',
263 'label' => esc_html__( 'Title Typography', 'bricksable' ),
264 'type' => 'typography',
265 'css' => array(
266 array(
267 'property' => 'font',
268 'selector' => '.ba-tilt-image-overlay-title',
269 ),
270 ),
271 'inline' => true,
272 'small' => true,
273 'required' => array( 'overlay_title', '!=', '' ),
274 );
275
276 $this->controls['overlay_caption_typography'] = array(
277 'tab' => 'style',
278 'group' => 'overlay_style',
279 'label' => esc_html__( 'Caption Typography', 'bricksable' ),
280 'type' => 'typography',
281 'css' => array(
282 array(
283 'property' => 'font',
284 'selector' => '.ba-tilt-image-caption',
285 ),
286 ),
287 'inline' => true,
288 'small' => true,
289 'required' => array( 'overlay_title', '!=', '' ),
290 );
291
292 $this->controls['overlay_style_icon_separator'] = array(
293 'tab' => 'style',
294 'group' => 'overlay_style',
295 'label' => esc_html__( 'Icon', 'bricksable' ),
296 'type' => 'separator',
297 'inline' => true,
298 'small' => true,
299 );
300
301 $this->controls['overlay_icon_border'] = array(
302 'tab' => 'style',
303 'group' => 'overlay_style',
304 'label' => esc_html__( 'Icon border', 'bricksable' ),
305 'type' => 'border',
306 'css' => array(
307 array(
308 'property' => 'border',
309 'selector' => '.image-overlay-wrapper .overlay-icon',
310 ),
311 ),
312 'inline' => true,
313 'small' => true,
314 'required' => array( 'overlay_icon', '!=', '' ),
315 );
316
317 $this->controls['overlay_icon_boxshadow'] = array(
318 'tab' => 'style',
319 'group' => 'overlay_style',
320 'label' => esc_html__( 'Icon box shadow', 'bricksable' ),
321 'type' => 'box-shadow',
322 'css' => array(
323 array(
324 'property' => 'box-shadow',
325 'selector' => '.image-overlay-wrapper .overlay-icon',
326 ),
327 ),
328 'inline' => true,
329 'small' => true,
330 'required' => array( 'overlay_icon', '!=', '' ),
331 );
332
333 $this->controls['overlay_icon_height'] = array(
334 'tab' => 'style',
335 'group' => 'overlay_style',
336 'label' => esc_html__( 'Icon height', 'bricksable' ),
337 'type' => 'number',
338 'unit' => 'px',
339 'css' => array(
340 array(
341 'property' => 'line-height',
342 'selector' => '.image-overlay-wrapper .overlay-icon',
343 ),
344 ),
345 'inline' => true,
346 'small' => true,
347 'required' => array( 'overlay_icon', '!=', '' ),
348 );
349
350 $this->controls['overlay_icon_width'] = array(
351 'tab' => 'style',
352 'group' => 'overlay_style',
353 'label' => esc_html__( 'Icon width', 'bricksable' ),
354 'type' => 'number',
355 'unit' => 'px',
356 'css' => array(
357 array(
358 'property' => 'width',
359 'selector' => '.image-overlay-wrapper .overlay-icon',
360 ),
361 ),
362 'inline' => true,
363 'small' => true,
364 'required' => array( 'overlay_icon', '!=', '' ),
365 );
366
367 $this->controls['overlay_icon_typography'] = array(
368 'tab' => 'style',
369 'group' => 'overlay_style',
370 'label' => esc_html__( 'Icon typography', 'bricksable' ),
371 'type' => 'typography',
372 'exclude' => array(
373 'font-family',
374 'font-weight',
375 'text-align',
376 'text-transform',
377 'line-height',
378 'letter-spacing',
379 ),
380 'css' => array(
381 array(
382 'property' => 'font',
383 'selector' => '.image-overlay-wrapper .overlay-icon',
384 ),
385 ),
386 'inline' => true,
387 'small' => true,
388 'required' => array( 'overlay_icon', '!=', '' ),
389 );
390
391 // Tilt Settings.
392 $this->controls['tilt_reverse'] = array(
393 'tab' => 'content',
394 'group' => 'tilt_settings',
395 'label' => esc_html__( 'Reverse', 'bricksable' ),
396 'type' => 'checkbox',
397 'inline' => true,
398 'description' => esc_html__( 'Reverse the tilt direction.', 'bricksable' ),
399 );
400 $this->controls['tilt_max'] = array(
401 'tab' => 'content',
402 'group' => 'tilt_settings',
403 'label' => esc_html__( 'Tilt rotation', 'bricksable' ),
404 'type' => 'slider',
405 'unitless' => true,
406 'min' => 10,
407 'max' => 100,
408 'step' => '1',
409 'default' => 40,
410 );
411
412 $this->controls['tilt_speed'] = array(
413 'tab' => 'content',
414 'group' => 'tilt_settings',
415 'label' => esc_html__( 'Tilt Speed', 'bricksable' ),
416 'type' => 'slider',
417 'unitless' => true,
418 'min' => 200,
419 'max' => 2000,
420 'step' => '100',
421 'default' => 1000,
422 );
423
424 $this->controls['tilt_perspective'] = array(
425 'tab' => 'content',
426 'group' => 'tilt_settings',
427 'label' => esc_html__( 'Tilt Perspective', 'bricksable' ),
428 'type' => 'slider',
429 'unitless' => true,
430 'min' => 200,
431 'max' => 1200,
432 'step' => '100',
433 'default' => 1000,
434 );
435
436 $this->controls['tilt_scale'] = array(
437 'tab' => 'content',
438 'group' => 'tilt_settings',
439 'label' => esc_html__( 'Tilt Scale', 'bricksable' ),
440 'type' => 'slider',
441 'unitless' => true,
442 'min' => 1,
443 'max' => 2,
444 'step' => '0.01',
445 'default' => 1,
446 );
447
448 $this->controls['tilt_glare'] = array(
449 'tab' => 'content',
450 'group' => 'tilt_settings',
451 'label' => esc_html__( 'Use glare', 'bricksable' ),
452 'type' => 'checkbox',
453 'inline' => true,
454 'description' => esc_html__( 'Setting this option will enable a glare effect.', 'bricksable' ),
455 );
456
457 $this->controls['tilt_max_glare'] = array(
458 'tab' => 'content',
459 'group' => 'tilt_settings',
460 'label' => esc_html__( 'Max Glare', 'bricksable' ),
461 'type' => 'slider',
462 'unitless' => true,
463 'min' => 0.1,
464 'max' => 1,
465 'step' => '0.01',
466 'default' => 0.8,
467 'required' => array( 'tilt_glare', '=', true ),
468 );
469 }
470
471 public function enqueue_scripts() {
472 wp_enqueue_script( 'ba-tilt-image' );
473 wp_localize_script(
474 'ba-tilt-image',
475 'bricksableTiltImageData',
476 array(
477 'tiltImageInstances' => array(),
478 )
479 );
480 }
481
482 public function get_normalized_image_settings( $settings ) {
483 if ( ! isset( $settings['image'] ) ) {
484 $settings['image'] = array(
485 'id' => 0,
486 'url' => '',
487 );
488 return $settings;
489 }
490
491 $image = $settings['image'];
492
493 if ( isset( $image['useDynamicData']['name'] ) ) {
494 $images = $this->render_dynamic_data_tag( $image['useDynamicData']['name'] );
495 $image['id'] = empty( $images ) ? 0 : $images[0];
496 } else {
497 $image['id'] = isset( $image['id'] ) ? $image['id'] : 0;
498 }
499
500 // Image Size.
501 $image['size'] = isset( $image['size'] ) ? $settings['image']['size'] : BRICKS_DEFAULT_IMAGE_SIZE;
502
503 // Image URL.
504 if ( ! isset( $image['url'] ) ) {
505 $image['url'] = wp_get_attachment_image_url( $image['id'], $image['size'] );
506 }
507
508 $settings['image'] = $image;
509
510 return $settings;
511 }
512
513 public function render() {
514 $settings = $this->settings;
515 $settings = $this->get_normalized_image_settings( $settings );
516
517 $tilt_max = isset( $settings['tilt_max'] ) ? intval( $settings['tilt_max'] ) : 40;
518 $tilt_speed = isset( $settings['tilt_speed'] ) ? intval( $settings['tilt_speed'] ) : 1000;
519 $tilt_perspective = isset( $settings['tilt_perspective'] ) ? intval( $settings['tilt_perspective'] ) : 1000;
520 $tilt_scale = isset( $settings['tilt_scale'] ) ? round( $settings['tilt_scale'], 1 ) : 1;
521 $tilt_glare = isset( $settings['tilt_glare'] ) ? true : false;
522 $tilt_maxglare = isset( $settings['tilt_max_glare'] ) ? round( $settings['tilt_max_glare'], 1 ) : 1;
523 $tilt_reverse = isset( $settings['tilt_reverse'] ) ? true : false;
524
525 $tilt_options = array(
526 'max' => $tilt_max,
527 'speed' => $tilt_speed,
528 'perspective' => $tilt_perspective,
529 'scale' => $tilt_scale,
530 'glare' => $tilt_glare,
531 'max-glare' => $tilt_maxglare,
532 'reverse' => $tilt_reverse,
533 );
534
535 // Dynamic Data is empty.
536 if ( isset( $settings['image']['useDynamicData']['name'] ) ) {
537
538 if ( empty( $settings['image']['id'] ) ) {
539
540 if ( 'ACF' === $settings['image']['useDynamicData']['group'] && ! class_exists( 'ACF' ) ) {
541 $message = esc_html__( 'Can\'t render element, as the selected ACF field is not available. Please activate ACF or edit the element to select different data.', 'bricksable' );
542 } elseif ( '{featured_image}' === $settings['image']['useDynamicData']['name'] ) {
543 $message = esc_html__( 'No featured image set.', 'bricksable' );
544 } else {
545 /* translators: 1: Data 2: Dynamic Value */
546 $message = esc_html__( 'Dynamic Data %1$s (%2$s) is empty.', 'bricksable' );
547 }
548
549 $this->set_attribute( 'ba-no-image-wrapper', 'class', 'ba-tilt-image-wrapper' );
550 $this->set_attribute( 'ba-no-image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
551 $this->set_attribute( 'ba-no-image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
552
553 echo '<div ' . $this->render_attributes( 'ba-no-image-wrapper' ) . '>'; //phpcs:ignore
554
555 return $this->render_element_placeholder(
556 array(
557 'icon-class' => 'ti-image',
558 'text' => sprintf(
559 $message,
560 $settings['image']['useDynamicData']['label'],
561 $settings['image']['useDynamicData']['group']
562 ),
563 )
564 );
565 //phpcs:ignore
566 echo '</div>';
567
568 }
569 } else {
570 // Image id is empty or doesn't exist.
571 // No image.
572 if ( empty( $settings['image']['id'] ) ) {
573 $this->set_attribute( 'ba-no-image-wrapper', 'class', 'ba-tilt-image-wrapper' );
574 $this->set_attribute( 'ba-no-image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
575 $this->set_attribute( 'ba-no-image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
576
577 echo '<div ' . $this->render_attributes( 'ba-no-image-wrapper' ) . '>'; //phpcs:ignore
578
579 return $this->render_element_placeholder(
580 array(
581 'icon-class' => 'ti-image',
582 'text' => esc_html__( 'No image selected.', 'bricksable' ),
583 )
584 );
585 //phpcs:ignore
586 echo '</div>';
587 }
588
589 // Return if image ID does not exist.
590 if ( ! wp_get_attachment_image_src( $settings['image']['id'] ) ) {
591 return $this->render_element_placeholder(
592 array(
593 'icon-class' => 'ti-image',
594 /* translators: 1: Image ID */
595 'text' => sprintf( esc_html__( 'Image ID (%s) no longer exist. Please select another image.', 'bricksable' ), $settings['image']['id'] ),
596 )
597 );
598 }
599 }
600
601 // Render.
602 $image_atts = array();
603 $image_atts['id'] = 'image-' . $settings['image']['id'];
604
605 $image_wrapper_classes = array( 'ba-tilt-image-wrapper' );
606 $img_classes = array( 'post-thumbnail', 'css-filter' );
607
608 if ( isset( $settings['overlayShowHover'] ) ) {
609 $image_wrapper_classes[] = 'ba-tilt-image-show-hover';
610 }
611
612 if ( isset( $settings['imageOverlayShowHover'] ) ) {
613 $image_wrapper_classes[] = 'ba-tilt-image-overlay-hover';
614 }
615
616 if ( isset( $settings['link'] ) && 'lightbox' === $settings['link'] ) {
617 $image_wrapper_classes[] = 'bricks-lightbox';
618
619 $image_src = $settings['image']['id'] ? wp_get_attachment_image_src( $settings['image']['id'], 'full' ) : array(
620 \Bricks\Builder::get_template_placeholder_image(),
621 800,
622 600,
623 );
624 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-source="' . $image_src[0] . '"' );
625 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-width="' . $image_src[1] . '"' );
626 $this->set_attribute( 'image-wrapper', 'data-bricks-lightbox-height="' . $image_src[2] . '"' );
627 }
628
629 $img_classes[] = 'size-' . $settings['image']['size'];
630 $image_atts['class'] = join( ' ', $img_classes );
631
632 // Title.
633 $show_title = isset( $settings['overlay_title'] ) ? $settings['overlay_title'] : 'none';
634
635 if ( 'none' === $show_title ) {
636 $image_title = false;
637 } elseif ( 'custom' === $show_title && isset( $settings['overlay_title_custom'] ) ) {
638 $image_title = trim( $settings['overlay_title_custom'] );
639 } else {
640 $image_data = get_post( $settings['image']['id'] );
641 $image_title = $image_data ? $image_data->post_title : '';
642 }
643
644 // Caption.
645 $show_caption = isset( $settings['overlay_caption'] ) ? $settings['overlay_caption'] : 'none';
646
647 if ( 'none' === $show_caption ) {
648 $image_caption = false;
649 } elseif ( 'custom' === $show_caption && isset( $settings['overlay_caption_custom'] ) ) {
650 $image_caption = trim( $settings['overlay_caption_custom'] );
651 } else {
652 $image_data = get_post( $settings['image']['id'] );
653 $image_caption = $image_data ? $image_data->post_excerpt : '';
654 }
655
656 $this->set_attribute( 'image-wrapper', 'data-ba-bricks-tilt-image-options', wp_json_encode( $tilt_options ) );
657
658 $this->set_attribute( 'image-wrapper', 'class', $image_wrapper_classes );
659 $this->set_attribute( 'image-wrapper', 'id', esc_attr( 'ba-tilt-image-' . $this->id ) );
660 $this->set_attribute( 'image-wrapper', 'data-tilt' );
661 $this->set_attribute( 'image-wrapper', 'data-tilt-max="' . $tilt_max . '"' );
662 $this->set_attribute( 'image-wrapper', 'data-tilt-speed="' . $tilt_speed . '"' );
663 $this->set_attribute( 'image-wrapper', 'data-tilt-perspective="' . $tilt_perspective . '"' );
664 $this->set_attribute( 'image-wrapper', 'data-tilt-scale="' . $tilt_scale . '"' );
665 $this->set_attribute( 'image-wrapper', $settings['tilt_glare'] ? ' data-tilt-glare' : '' );
666 $this->set_attribute( 'image-wrapper', 'data-tilt-max-glare="' . $tilt_maxglare . '"' );
667 $this->set_attribute( 'image-wrapper', 'data-tilt-reverse="' . $tilt_reverse . '"' );
668
669 echo '<figure ' . $this->render_attributes( 'image-wrapper' ) . '>'; //phpcs:ignore
670
671 $close_a_tag = false;
672
673 if ( isset( $settings['link'] ) && 'media' === $settings['link'] ) {
674 $close_a_tag = true;
675
676 echo '<a href="' . esc_url( wp_get_attachment_url( $settings['image']['id'] ) ) . '" target="_blank">';
677 }
678
679 if ( isset( $settings['link'] ) && 'attachment' === $settings['link'] ) {
680 echo '<a href="' . esc_url( get_permalink( $settings['image']['id'] ) ) . '" target="_blank">';
681 }
682
683 if ( isset( $settings['link'] ) && 'url' === $settings['link'] && isset( $settings['url'] ) ) {
684 $close_a_tag = true;
685
686 // Link.
687 $this->set_link_attributes( 'a', $settings['url'] );
688
689 echo '<a ' . $this->render_attributes( 'a' ) . '>'; //phpcs:ignore
690 }
691
692 // Lazy load atts set via 'wp_get_attachment_image_attributes' filter.
693 if ( isset( $settings['image']['id'] ) ) {
694 echo wp_get_attachment_image( $settings['image']['id'], $settings['image']['size'], false, $image_atts );
695 } elseif ( ! empty( $settings['image']['url'] ) ) {
696 echo '<img src="' . esc_url( $settings['image']['url'] ) . '">';
697 }
698
699 if ( 'none' !== $show_title || 'none' !== $show_caption || isset( $settings['overlay_icon']['icon'] ) ) {
700 $overlay_title_tag = isset( $settings['overlay_title_tag'] ) ? esc_html( $settings['overlay_title_tag'] ) : 'h3';
701 $overlay_title_classes = array(
702 'ba-tilt-image-overlay-title',
703 'bricks-heading',
704 'bricks-heading-' . $overlay_title_tag,
705 );
706 $this->set_attribute( 'overlay_title', $overlay_title_tag );
707 $this->set_attribute( 'overlay_title', 'class', $overlay_title_classes );
708 if ( isset( $settings['overlay_icon']['icon'] ) ) {
709 $icon_classes = array( 'overlay-icon', $settings['overlay_icon']['icon'], 'icon' );
710 $this->set_attribute( 'overlay-icon-wrapper', 'class', 'overlay-icon-wrapper' );
711 $this->set_attribute( 'overlay-icon', 'class', $icon_classes );
712 }
713
714 $overlay_title_output = '<' . $this->render_attributes( 'overlay_title' ) . '>' . esc_html( $image_title ) . '</' . $overlay_title_tag . '>';
715
716 $this->set_attribute( 'image-overlay-wrapper', 'class', 'image-overlay-wrapper' );
717 $this->set_attribute( 'image-overlay-content', 'class', 'image-overlay-content' );
718
719 echo '<div ' . $this->render_attributes( 'image-overlay-wrapper' ) . '>'; //phpcs:ignore
720 echo '<div ' . $this->render_attributes( 'image-overlay-content' ) . '>'; //phpcs:ignore
721 if ( isset( $settings['overlay_icon']['icon'] ) ) {
722 echo '<div ' . $this->render_attributes( 'overlay-icon-wrapper' ) . '>'; //phpcs:ignore
723 echo '<i ' . $this->render_attributes( 'overlay-icon' ) . '></i>'; //phpcs:ignore
724 echo '</div>';
725 }
726 if ( $image_title ) {
727 //phpcs:ignore
728 echo $overlay_title_output;
729 }
730 if ( $image_caption ) {
731 echo '<figcaption class="ba-tilt-image-overlay-caption">' . esc_html( $image_caption ) . '</figcaption>';
732 }
733 echo '</div>';
734 echo '</div>';
735 }
736
737 if ( $close_a_tag ) {
738 echo '</a>';
739 }
740
741 echo '</figure>';
742
743 }
744 }
745