PluginProbe
SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) / 1.2.0
SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) v1.2.0
1.8.1 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.6.0 1.7.0 1.8.0
slingblocks / includes / class-render-blocks.php

class-render-blocks.php in SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) 1.2.0, at includes/class-render-blocks.php

1,169 lines 37.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * This file handles the dynamic parts of our blocks.
4 *
5 * @package BWFBlocks
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Render the dynamic aspects of our blocks.
14 *
15 * @since 1.2.0
16 */
17 class SLINGBLOCKS_Render_Block {
18 /**
19 * Instance.
20 *
21 * @access private
22 * @var object Instance
23 * @since 1.2.0
24 */
25 private static $instance;
26
27 /**
28 * Initiator.
29 *
30 * @return object initialized object of class.
31 * @since 1.2.0
32 */
33 public static function get_instance() {
34 if ( ! isset( self::$instance ) ) {
35 self::$instance = new self();
36 }
37
38 return self::$instance;
39 }
40
41 /**
42 * Constructor.
43 */
44 public function __construct() {
45 add_action( 'init', array( $this, 'register_blocks' ) );
46 if ( ! is_admin() ) {
47 add_action( 'render_block', array( $this, 'conditionally_render_block' ), 6, 2 );
48 }
49 }
50
51 /**
52 * Register our dynamic blocks.
53 *
54 * @since 1.2.0
55 */
56 public function register_blocks() {
57 // Only load if Gutenberg is available.
58 if ( ! function_exists( 'register_block_type' ) ) {
59 return;
60 }
61
62 $bwfblocks = [
63 [
64 'name' => 'sling-block/accordion',
65 'callback' => 'do_accordion_block',
66 ],
67 [
68 'name' => 'sling-block/pane',
69 'callback' => 'do_pane_block',
70 ],
71 [
72 'name' => 'sling-block/columns',
73 'callback' => 'do_columns_block',
74 ],
75 [
76 'name' => 'sling-block/col',
77 'callback' => 'do_inner_column_block',
78 ],
79 [
80 'name' => 'sling-block/advance-button',
81 'callback' => 'do_adv_button_block',
82 ],
83 [
84 'name' => 'sling-block/button',
85 'callback' => 'do_button_block',
86 ],
87 [
88 'name' => 'sling-block/advance-heading',
89 'callback' => 'do_heading_block',
90 ],
91 [
92 'name' => 'sling-block/icon-list',
93 'callback' => 'do_icon_list_block',
94 ],
95 [
96 'name' => 'sling-block/space-divider',
97 'callback' => 'do_divider_block',
98 ],
99 [
100 'name' => 'sling-block/icon',
101 'callback' => 'do_icon_block',
102 ],
103 [
104 'name' => 'sling-block/progress-bar',
105 'callback' => 'do_progress_block',
106 ],
107 [
108 'name' => 'sling-block/countdown',
109 'callback' => 'do_count_down_block',
110 ],
111 ];
112
113 foreach ( $bwfblocks as $block ) {
114 register_block_type( $block['name'], array( 'render_callback' => array( $this, $block['callback'] ) ) );
115 }
116 }
117
118 /**
119 * Check for logged in, logged out visibility settings.
120 *
121 * @param mixed $block_content The block content.
122 * @param array $block The block data.
123 *
124 * @return mixed Returns the block content.
125 */
126 public function conditionally_render_block( $block_content, $block ) {
127 if ( ! is_admin() ) {
128 if ( 0 === strpos( $block['blockName'], 'sling-block/' ) && isset( $block['attrs'] ) ) {
129 if ( isset( $block['attrs']['loggedIn'] ) && $block['attrs']['loggedIn'] && is_user_logged_in() ) {
130 return '';
131 }
132 if ( isset( $block['attrs']['loggedOut'] ) && $block['attrs']['loggedOut'] && ! is_user_logged_in() ) {
133 return '';
134 }
135 }
136
137 }
138
139 return $block_content;
140 }
141
142 public function has_block_visibiliy_classes( $settings, $classes ) {
143 if ( ! empty( $settings['vsdesk'] ) ) {
144 $classes[] = 'bwf-hide-lg';
145 }
146 if ( ! empty( $settings['vstablet'] ) ) {
147 $classes[] = 'bwf-hide-md';
148 }
149 if ( ! empty( $settings['vsmobile'] ) ) {
150 $classes[] = 'bwf-hide-sm';
151 }
152
153 return $classes;
154 }
155
156 /**
157 * Output the dynamic aspects of our Accordion block.
158 *
159 * @param array $attributes The block attributes.
160 * @param string $content The inner blocks.
161 *
162 * @since 1.2.0
163 */
164 public function do_accordion_block( $attributes, $content ) {
165
166 if ( isset( $attributes['uniqueID'] ) ) {
167 $unique_id = $attributes['uniqueID'];
168 $style_id = 'sling-block-' . esc_attr( $unique_id );
169 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
170 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_accordion_css_head( $attributes, $unique_id );
171 if ( ! empty( $css ) ) {
172 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
173 }
174 }
175 }
176
177 $output = '';
178 $defaults = array(
179 'paneClose' => false,
180 'paneOpenOne' => true,
181 'openPane' => 1,
182 'anchor' => ''
183 );
184
185 $settings = wp_parse_args( $attributes, $defaults );
186
187
188 if ( ! isset( $settings['accordionLayout'] ) ) {
189 return $output;
190 }
191
192 $alignment = $settings['align'] ?? 'default';
193
194 $classNames = array(
195 'bwf-accordion',
196 'bwf-' . $settings['accordionLayout'],
197 'bwf-accordion-' . $settings['uniqueID'],
198 'bwf-width-' . $alignment,
199 );
200
201 if ( ! empty( $settings['className'] ) ) {
202 $classNames[] = $settings['className'];
203 }
204
205 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
206
207 $start_open = isset( $settings['openPane'] ) ? $settings['openPane'] : 1;
208 if ( isset( $settings['paneClose'] ) && true === $settings['paneClose'] ) {
209 $start_open = 'none';
210 }
211
212 $output = sprintf( '<div %s>', slingblocks_attr( 'accordion', array(
213 'id' => $settings['anchor'],
214 'class' => implode( ' ', $classNames ),
215 'data-allow-multiple-open' => isset( $settings['paneOpenOne'] ) && true === $settings['paneOpenOne'] ? 'false' : 'true',
216 'data-open' => $start_open,
217 ), $settings ) );
218
219 $output .= $content;
220
221 $output .= '</div>';
222
223
224 return $output;
225 }
226
227 /**
228 * Output the dynamic aspects of our Pane block.
229 *
230 * @param array $attributes The block attributes.
231 * @param string $content The inner blocks.
232 *
233 * @since 1.2.0
234 */
235 public function do_pane_block( $attributes, $content ) {
236
237 $output = '';
238
239 $defaults = array(
240 'paneClose' => true,
241 'paneOpenOne' => false,
242 'openPane' => 1,
243 'anchor' => ''
244 );
245
246 $settings = wp_parse_args( $attributes, $defaults );
247
248
249 $classNames = array(
250 'bwf-accordion-wrapper',
251 'bwf-pane-' . $settings['uniqueID'],
252 );
253
254 if ( ! empty( $settings['className'] ) ) {
255 $classNames[] = $settings['className'];
256 }
257
258 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
259
260 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'pane', array(
261 'id' => $settings['anchor'],
262 'class' => implode( ' ', $classNames ),
263 ), $settings ) );
264 $output .= '<div class="bwf-accordion-head">';
265
266 $output .= '<h2 class="bwf-accordion-head-tag">';
267 $output .= isset( $settings['content'] ) ? $settings['content'] : ''; //pane heading title
268 $output .= '</h2>';
269 $output .= $this->get_pane_toggle_icon( $settings );
270 $output .= '</div>';
271
272 $output .= '<div class="bwf-accordion-body">';
273 $output .= $content; //InnerBlocks.Content
274 $output .= '</div>';
275
276 $output .= '</div>';
277
278 return $output;
279 }
280
281 public function get_pane_toggle_icon( $attributes ) {
282 $icons = '';
283 if ( isset( $attributes['triggerIcon'] ) && ! empty( $attributes['triggerIcon'] ) ) {
284 switch ( $attributes['triggerIcon'] ) {
285 case 'plus-minus':
286 $icons = '<div class="bwf-icon-open">' . slingblocks_svg_icons( 'minus' ) . '</div><div class="bwf-icon-close">' . slingblocks_svg_icons( 'plus' ) . '</div>';
287 break;
288 case 'up-down':
289 $icons = '<div class="bwf-icon-open">' . slingblocks_svg_icons( 'collapse-arrow' ) . '</div><div class="bwf-icon-close">' . slingblocks_svg_icons( 'expand-arrow' ) . '</div>';
290 break;
291 case 'up-down-arrow':
292 $icons = '<div class="bwf-icon-open">' . slingblocks_svg_icons( 'up-arrow' ) . '</div><div class="bwf-icon-close">' . slingblocks_svg_icons( 'down-arrow' ) . '</div>';
293 break;
294 case 'plus-minus-circle':
295 $icons = '<div class="bwf-icon-open">' . slingblocks_svg_icons( 'close-circle' ) . '</div><div class="bwf-icon-close">' . slingblocks_svg_icons( 'plus-circle' ) . '</div>';
296 break;
297 }
298 } else {
299 $default_open = ! isset( $attributes['accordionLayout'] ) || 'accordion-3' !== $attributes['accordionLayout'] ? 'minus' : 'collapse-arrow';
300 $default_close = ! isset( $attributes['accordionLayout'] ) || 'accordion-3' !== $attributes['accordionLayout'] ? 'plus' : 'expand-arrow';
301 $icons = '<div class="bwf-icon-open">' . slingblocks_svg_icons( $default_open ) . '</div><div class="bwf-icon-close">' . slingblocks_svg_icons( $default_close ) . '</div>';
302 }
303
304 return $icons;
305 }
306
307 /**
308 * Output the dynamic aspects of our Columns block.
309 *
310 * @param array $attributes The block attributes.
311 * @param string $content The inner blocks.
312 *
313 * @since 1.2.0
314 */
315 public function do_columns_block( $attributes, $content, $col ) {
316
317 if ( isset( $attributes['uniqueID'] ) ) {
318 $unique_id = $attributes['uniqueID'];
319 $style_id = 'sling-block-' . esc_attr( $unique_id );
320 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
321 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_columns_css_head( $attributes, $unique_id );
322 if ( ! empty( $css ) ) {
323 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
324 }
325 }
326 }
327
328
329 $output = '';
330
331 $defaults = array(
332 'columns' => 1,
333 'anchor' => ''
334 );
335
336 $settings = wp_parse_args( $attributes, $defaults );
337
338 $classNames = array(
339 'bwf-section-wrap',
340 'bwf-section-' . $settings['uniqueID'],
341 );
342
343 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
344
345 if ( isset( $settings['align'] ) && ! empty( $settings['align'] ) ) {
346 $output .= '<div class="bwf-align-wrap-' . $settings['align'] . '">';
347 }
348
349
350 if ( ! empty( $settings['className'] ) ) {
351 $classNames[] = $settings['className'];
352 }
353
354 if ( ! empty( $settings['contentWidth'] ) && 'full' === $settings['contentWidth'] ) {
355 $classNames[] = 'bwf-width-full';
356 }
357
358 if ( $this->hasColumnBG( $settings ) ) {
359 $classNames[] = 'bwf-has-bg';
360 }
361
362
363 $tagName = ! empty( $settings['htmlTag'] ) ? $settings['htmlTag'] : 'div';
364 if ( ! empty( $settings['link'] ) ) {
365 $classNames[] = 'bwf-cursor';
366 }
367 $output .= sprintf( '<%1$s %2$s>', $tagName, slingblocks_attr( 'columns', array(
368 'id' => $settings['anchor'],
369 'class' => implode( ' ', $classNames ),
370 'bwf-href' => isset( $settings['link'] ) ? $settings['link'] : '',
371 'bwf-newtab' => isset( $settings['linkNewTab'] ) && $settings['linkNewTab'] ? "_blank" : '',
372 ), $settings ) );
373
374 // Column background video
375 if ( isset( $settings['backgroundVideo'] ) && ! empty( $settings['backgroundVideo'] ) && isset( $settings['backgroundVideo']['desktop'] ) ) {
376 $column_bgvideo = $settings['backgroundVideo']['desktop'];
377
378 if ( isset( $column_bgvideo['local'] ) && ! empty( $column_bgvideo['local'] ) ) {
379 $output .= sprintf( '<video autoplay %2$s><source src="%1$s" type="video/mp4"/></video>', $column_bgvideo['local'], slingblocks_attr( 'columns-video', array(
380 'muted' => isset( $column_bgvideo['mute'] ) ? $column_bgvideo['mute'] : null,
381 'loop' => isset( $column_bgvideo['loop'] ) ? $column_bgvideo['loop'] : null,
382 'control' => isset( $column_bgvideo['control'] ) ? $column_bgvideo['control'] : null,
383 ), $settings ) );
384 }
385 }
386 $column = $settings['columns'] ?? 1;
387
388 $output .= '<div class="bwf-col">';
389 $output .= $content; //InnerBlocks.Content
390 $output .= '</div>';
391
392
393 $output .= sprintf( '</%s>', $tagName );
394 if ( isset( $settings['align'] ) && ! empty( $settings['align'] ) ) {
395 $output .= '</div>';
396 }
397
398 return $output;
399 }
400
401 public function hasColumnBG( $attrs ) {
402 if ( ! empty( $attrs['background'] ) && ! empty( $attrs['background']['desktop'] ) && ( ! empty( $attrs['background']['desktop']['image'] ) || ! empty( $attrs['background']['desktop']['color'] ) || ! empty( $attrs['background']['desktop']['gradient'] ) ) ) {
403 return true;
404 }
405 if ( ! empty( $attrs['overlayBackground'] ) && ! empty( $attrs['overlayBackground']['desktop'] ) && ( ! empty( $attrs['overlayBackground']['desktop']['image'] ) || ! empty( $attrs['overlayBackground']['desktop']['color'] ) || ! empty( $attrs['overlayBackground']['desktop']['gradient'] ) ) ) {
406 return true;
407 }
408 if ( ! empty( $attrs['backgroundVideo'] ) && ! empty( $attrs['backgroundVideo']['desktop'] ) && ! empty( $attrs['backgroundVideo']['desktop']['local'] ) ) {
409 return true;
410 }
411
412 return false;
413 }
414
415 public function map_column_old_val( $layout ) {
416 if ( 'equal' == $layout ) {
417 return '';
418 }
419 $value = $layout;
420 switch ( $layout ) {
421 case 'left-golden':
422 $value = '2-1';
423 break;
424 case 'right-golden':
425 $value = '1-2';
426 break;
427 case 'right-forty':
428 $value = '1-1-1-2';
429 break;
430 case 'left-forty':
431 $value = '2-1-1-1';
432 break;
433 case 'center-exwide':
434 $value = '1-4-1';
435 break;
436 case 'center-wide':
437 $value = '1-3-1';
438 break;
439 case 'center-half':
440 $value = '1-2-1';
441 break;
442 case 'right-half':
443 $value = '1-1-2';
444 break;
445 case 'left-half':
446 $value = '2-1-1';
447 break;
448 }
449
450 return $value;
451 }
452
453
454 /**
455 * Output the dynamic aspects of our Inner Columns block(Column block child).
456 *
457 * @param array $attributes The block attributes.
458 * @param string $content The inner blocks.
459 *
460 * @since 1.2.0
461 */
462 public function do_inner_column_block( $attributes, $content, $col ) {
463
464 if ( isset( $attributes['uniqueID'] ) ) {
465 $unique_id = $attributes['uniqueID'];
466 $style_id = 'sling-block-' . esc_attr( $unique_id );
467 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
468 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_col_css_head( $attributes, $unique_id );
469 if ( ! empty( $css ) ) {
470 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
471 }
472 }
473 }
474
475 $output = '';
476
477 if ( empty( $attributes['uniqueID'] ) ) {
478 return $output;
479 }
480
481 $defaults = array( 'anchor' => '' );
482 $settings = wp_parse_args( $attributes, $defaults );
483
484 $classNames = array(
485 'bwf-inner-col',
486 'bwf-inner-col-' . $settings['uniqueID'],
487 );
488
489 if ( ! empty( $settings['className'] ) ) {
490 $classNames[] = $settings['className'];
491 }
492
493 if ( ! empty( $settings['link'] ) ) {
494 $classNames[] = 'bwf-cursor';
495 }
496
497 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'inner-column', array(
498 'id' => $settings['anchor'],
499 'class' => implode( ' ', $classNames ),
500 'bwf-href' => isset( $settings['link'] ) ? $settings['link'] : '',
501 'bwf-newtab' => isset( $settings['linkNewTab'] ) && $settings['linkNewTab'] ? "_blank" : '',
502 ), $settings ) );
503
504
505 $output .= $content; //InnerBlocks.Content
506 $output .= '</div>';
507
508 return $output;
509 }
510
511 /**
512 * Output the dynamic aspects of our Space Divider block.
513 *
514 * @param array $attributes The block attributes.
515 * @param string $content The inner blocks.
516 *
517 * @since 1.2.0
518 */
519 public function do_divider_block( $attributes, $content ) {
520
521 if ( isset( $attributes['uniqueID'] ) ) {
522 $unique_id = $attributes['uniqueID'];
523 $style_id = 'sling-block-' . esc_attr( $unique_id );
524 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
525 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_divider_css_head( $attributes, $unique_id );
526 if ( ! empty( $css ) ) {
527 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
528 }
529 }
530 }
531
532 $output = '';
533
534 $defaults = array(
535 'alignment' => [ 'desktop' => 'center' ],
536 'width' => [ 'desktop' => 100 ],
537 'anchor' => ''
538 );
539 $settings = wp_parse_args( $attributes, $defaults );
540
541 $classNames = array(
542 'bwf-space-divider-wrapper',
543 'bwf-' . $settings['uniqueID'],
544 );
545
546 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
547
548 if ( ! empty( $settings['className'] ) ) {
549 $classNames[] = $settings['className'];
550 }
551
552 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'space-divider', array(
553 'id' => $settings['anchor'],
554 'class' => implode( ' ', $classNames ),
555 ), $settings ) );
556
557
558 $output .= '<div class="bwf-space-divider"></div>';
559 $output .= '</div>';
560
561 return $output;
562 }
563
564 /**
565 * Output the dynamic aspects of our Advance Button blocks.
566 *
567 * @param array $attributes The block attributes.
568 * @param string $content The inner blocks.
569 *
570 * @since 1.2.0
571 */
572 public function do_adv_button_block( $attributes, $content ) {
573
574 if ( isset( $attributes['uniqueID'] ) ) {
575 $unique_id = $attributes['uniqueID'];
576 $style_id = 'sling-block-' . esc_attr( $unique_id );
577 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
578 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_adv_button_css_head( $attributes, $unique_id );
579 if ( ! empty( $css ) ) {
580 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
581 }
582 }
583 }
584
585 $output = '';
586 $defaults = array();
587 $settings = wp_parse_args( $attributes, $defaults );
588
589 $classNames = array(
590 'bwf-advance-btn',
591 'bwf-' . $settings['uniqueID'],
592 );
593
594 if ( ! empty( $settings['className'] ) ) {
595 $classNames[] = $settings['className'];
596 }
597
598 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
599
600 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'adv-button', array(
601 'id' => ! empty( $settings['anchor'] ) ? $settings['anchor'] : '',
602 'class' => implode( ' ', $classNames ),
603 ), $settings ) );
604
605 $output .= $content; //inner block
606 $output .= '</div>';
607
608 return $output;
609 }
610
611 /**
612 * Output the dynamic aspects of our Advance Button blocks.
613 *
614 * @param array $attributes The block attributes.
615 * @param string $content The inner blocks.
616 *
617 * @since 1.2.0
618 */
619 public function do_button_block( $attributes, $content ) {
620
621 if ( isset( $attributes['uniqueID'] ) ) {
622 $unique_id = $attributes['uniqueID'];
623 $style_id = 'sling-block-' . esc_attr( $unique_id );
624 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
625 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_button_css_head( $attributes, $unique_id );
626 if ( ! empty( $css ) ) {
627 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
628 }
629 }
630 }
631
632 $output = '';
633
634 $defaults = array(
635 'type' => 'solid',
636 'content' => __( 'Button' ),
637 'anchor' => ''
638 );
639
640 $settings = wp_parse_args( $attributes, $defaults );
641
642 $type = $settings['type'] ?? 'solid';
643 $classNames = array( 'bwf-btn', 'btn-' . $type, 'bwf-' . $settings['uniqueID'] );
644
645 if ( ! empty( $settings['secondaryContentEnable'] ) ) {
646 $classNames[] = 'has-secondary-text';
647 }
648 if ( ! empty( $settings['className'] ) ) {
649 $classNames[] = $settings['className'];
650 }
651 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
652
653
654 $button_rel = '';
655 $button_target = '';
656 $button = isset( $settings['button'] ) ? $settings['button'] : [];
657 if ( isset( $button['newTab'] ) && ! empty( $button['newTab'] ) ) {
658 $button_target = '_blank';
659 $button_rel = 'noopener noreferrer';
660 }
661
662 if ( isset( $button['noFollow'] ) && ! empty( $button['noFollow'] ) ) {
663 $button_rel .= ' nofollow';
664 }
665 $output .= sprintf( '<a %1$s>', slingblocks_attr( 'button-anchor', array(
666 'id' => $settings['anchor'],
667 'class' => implode( ' ', $classNames ),
668 'href' => isset( $settings['link'] ) ? esc_url( $settings['link'] ) : '',
669 'target' => $button_target,
670 'rel' => $button_rel,
671 ), $settings ) );
672
673 //Button Icon Left Side
674 if ( isset( $button['icon'] ) && ! empty( $button['icon'] ) && 'left' === $button['iconPos'] ) {
675 $output .= '<span class="bwf-icon-inner-svg bwf-left-icon">' . $button['icon'] . '</span>';
676 }
677
678 //Button content
679 $output .= isset( $settings['content'] ) ? '<span class="bwf-btn-inner-text">' . $settings['content'] . '</span>' : '';
680
681 //Button Icon Right Side
682 if ( isset( $button['icon'] ) && ! empty( $button['icon'] ) && 'right' === $button['iconPos'] ) {
683 $output .= '<span class="bwf-icon-inner-svg bwf-right-icon">' . $button['icon'] . '</span>';
684 }
685
686 // Button Secondary Text (Sub heading)
687 if ( isset( $settings['secondaryContentEnable'] ) && ! empty( $settings['secondaryContentEnable'] ) ) {
688 $buttonSubText = isset( $settings['secondaryContent'] ) ? $settings['secondaryContent'] : '';
689 $output .= '<span class="bwf-btn-sub-text">' . $buttonSubText . '</span>';
690 }
691
692 $output .= '</a>';
693
694 return $output;
695 }
696
697 /**
698 * Output the dynamic aspects of our Advance Heading block.
699 *
700 * @param array $attributes The block attributes.
701 * @param string $content The inner blocks.
702 *
703 * @since 1.2.0
704 */
705 public function do_heading_block( $attributes, $content ) {
706
707 if ( isset( $attributes['uniqueID'] ) ) {
708 $unique_id = $attributes['uniqueID'];
709 $style_id = 'sling-block-' . esc_attr( $unique_id );
710 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
711 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_heading_css_head( $attributes, $unique_id );
712 if ( ! empty( $css ) ) {
713 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
714 }
715 }
716 }
717
718 $output = '';
719 $defaults = array( 'anchor' => '' );
720 $settings = wp_parse_args( $attributes, $defaults );
721 $alignment = $settings['align'] ?? 'default';
722
723 $classNames = array(
724 'bwf-adv-heading',
725 'bwf-adv-head-' . $settings['uniqueID'],
726 'bwf-width-' . $alignment,
727 );
728
729 if ( ! empty( $settings['className'] ) ) {
730 $classNames[] = $settings['className'];
731 }
732
733 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
734
735 $tagName = ! empty( $settings['htmlTag'] ) ? $settings['htmlTag'] : 'div';
736
737 $output .= sprintf( '<%1$s %2$s>', $tagName, slingblocks_attr( 'heading', array(
738 'id' => $settings['anchor'],
739 'class' => implode( ' ', $classNames ),
740 ), $settings ) );
741 $output .= $settings['content'] ?? ''; //Heading Content
742
743 $output .= sprintf( '</%s>', $tagName );
744
745 return $output;
746 }
747
748 /**
749 * Output the dynamic aspects of our Icon List block.
750 *
751 * @param array $attributes The block attributes.
752 * @param string $content The inner blocks.
753 *
754 * @since 1.2.0
755 */
756 public function do_icon_list_block( $attributes, $content ) {
757
758 if ( isset( $attributes['uniqueID'] ) ) {
759 $unique_id = $attributes['uniqueID'];
760 $style_id = 'sling-block-' . esc_attr( $unique_id );
761 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
762 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_list_css_head( $attributes, $unique_id );
763 if ( ! empty( $css ) ) {
764 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
765 }
766 }
767 }
768
769 $output = '';
770 $defaults = array(
771 'listCount' => 1,
772 'anchor' => ''
773 );
774 $settings = wp_parse_args( $attributes, $defaults );
775 $classNames = array(
776 'bwf-icon-list-wrap',
777 'bwf-list-' . $settings['uniqueID'],
778 );
779
780 if ( ! empty( $settings['className'] ) ) {
781 $classNames[] = $settings['className'];
782 }
783
784 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
785
786 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'icon-list', array(
787 'class' => implode( ' ', $classNames ),
788 ), $settings ) );
789 $blockID = $settings['anchor'] ? 'id="' . $settings['anchor'] . '"' : '';
790 $output .= '<ul class="bwf-icon-list" ' . $blockID . '>';
791
792 $listCount = isset( $settings['listCount'] ) ? $settings['listCount'] : 1;
793
794 for ( $i = 0; $i < $listCount; $i ++ ) {
795
796 $output .= '<li class="bwf-icon-list-item-wrap bwf-icon-list-item-' . $i . '">';
797
798 if ( isset( $settings['items'] ) && isset( $settings['items'][ $i ] ) ) {
799 $defaultIcon = '<svg data-prefix="fas" data-icon="check" class="svg-inline--fa fa-check fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M173.898 439.404l-166.4-166.4c-9.997-9.997-9.997-26.206 0-36.204l36.203-36.204c9.997-9.998 26.207-9.998 36.204 0L192 312.69 432.095 72.596c9.997-9.997 26.207-9.997 36.204 0l36.203 36.204c9.997 9.997 9.997 26.206 0 36.204l-294.4 294.401c-9.998 9.997-26.207 9.997-36.204-.001z"></path></svg>';
800
801 $icon = $settings['items'][ $i ]['icon'] ? $settings['items'][ $i ]['icon'] : ( ! empty( $settings['defaultIcon'] ) ? $settings['defaultIcon'] : $defaultIcon );
802 $text = isset( $settings['items'][ $i ]['text'] ) ? $settings['items'][ $i ]['text'] : '';
803
804 $output .= '<span class="bwf-icon-inner-svg">' . $icon;
805 $output .= '</span>';
806 $output .= '<span class="bwf-icon-list-text">' . $text;
807 $output .= '</span>';
808 }
809
810 $output .= '</li>';
811 }
812
813 $output .= '</ul>';
814 $output .= '</div>';
815
816 return $output;
817 }
818
819 public function do_icon_block( $attributes, $content ) {
820
821 if ( isset( $attributes['uniqueID'] ) ) {
822 $unique_id = $attributes['uniqueID'];
823 $style_id = 'sling-block-' . esc_attr( $unique_id );
824 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
825 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_icon_css_head( $attributes, $unique_id );
826 if ( ! empty( $css ) ) {
827 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
828 }
829 }
830 }
831
832 $output = '';
833
834 $settings = wp_parse_args( $attributes, [] );
835
836 $classNames = array(
837 'bwf-icon-wrap',
838 'bwf-icon-' . $settings['uniqueID'],
839 );
840
841 if ( ! empty( $settings['className'] ) ) {
842 $classNames[] = $settings['className'];
843 }
844
845 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
846
847 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'icon', array(
848 'class' => implode( ' ', $classNames ),
849 'id' => isset( $settings['anchor'] ) ? $settings['anchor'] : '',
850 ), $settings ) );
851
852 $listCount = isset( $settings['count'] ) ? $settings['count'] : 1;
853
854
855 $defaultIcon = isset( $settings['defaultIcon'] ) && $settings['defaultIcon'] ? $settings['defaultIcon'] : '';
856
857 for ( $i = 0; $i < $listCount; $i ++ ) {
858
859 $icon_type = isset( $settings['type'] ) && 'shaped' === $settings['type'] ? ' bwf-svg-shaped' : '';
860 $output .= '<div class="bwf--icon bwf--icon-' . $i . $icon_type . '">';
861
862 if ( isset( $settings['icons'] ) && isset( $settings['icons'][ $i ] ) ) {
863 if ( ! empty( $settings['icons'][ $i ]['link'] ) ) {
864 $target = ! empty( $settings['icons'][ $i ]['newTab'] ) ? 'target="__blank"' : '';
865 $relation = '';
866 $relation .= ! empty( $settings['icons'][ $i ]['newTab'] ) ? 'noopener noreferrer' : '';
867 $relation .= ! empty( $settings['icons'][ $i ]['noFollow'] ) ? ' nofollow' : '';
868
869 $output .= sprintf( '<a %1$s>', slingblocks_attr( 'icon-link', array(
870 'href' => $settings['icons'][ $i ]['link'],
871 'target' => $target,
872 'rel' => trim( $relation ),
873 'class' => 'bwf-icon-link'
874 ), $settings ) );
875 }
876
877 }
878 $icon = isset( $settings['icons'][ $i ]['icon'] ) ? $settings['icons'][ $i ]['icon'] : $defaultIcon;
879 $output .= $icon;
880
881 if ( isset( $settings['icons'] ) && isset( $settings['icons'][ $i ] ) ) {
882 $output .= '</a>';
883 }
884 $output .= '</div>';
885
886 }
887 $output .= '</div>';
888
889 return $output;
890 }
891
892 /**
893 * Output the dynamic aspects of our Progress Bar block.
894 *
895 * @param array $attributes The block attributes.
896 * @param string $content The inner blocks.
897 *
898 * @since 1.2.0
899 */
900 public function do_progress_block( $attributes, $content ) {
901
902 if ( isset( $attributes['uniqueID'] ) ) {
903 $unique_id = $attributes['uniqueID'];
904 $style_id = 'sling-block-' . esc_attr( $unique_id );
905 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
906 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_progress_css_head( $attributes, $unique_id );
907 if ( ! empty( $css ) ) {
908 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
909 }
910 }
911 }
912
913 $output = '';
914
915 $settings = wp_parse_args( $attributes, [] );
916
917 $classNames = array(
918 'bwf-progress-bar-wrapper',
919 'bwf-' . $settings['uniqueID'],
920 );
921
922 if ( ! empty( $settings['className'] ) ) {
923 $classNames[] = $settings['className'];
924 }
925
926 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
927
928 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'bwf-progress-wrap', array(
929 'class' => implode( ' ', $classNames ),
930 'id' => isset( $settings['anchor'] ) ? $settings['anchor'] : '',
931 ), $settings ) );
932
933 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'bwf-progress-inner-wrap', array(
934 'class' => 'bwf-progress-inner-wrap',
935 ), $settings ) );
936
937 if ( isset( $settings['enableTitle'] ) && $settings['enableTitle'] && isset( $settings['titleContent'] ) ) {
938 $output .= '<div class="bwf-progress-title">' . $settings['titleContent'] . '</div>';
939 }
940 $content = 'Progress...';
941 if ( isset( $settings['content'] ) ) {
942 $content = $settings['content'];
943 }
944 $animate = '';
945 if ( isset( $settings['enableAnimationStrip'] ) && $settings['enableAnimationStrip'] ) {
946 $animate = 'bwf-animate';
947 }
948 $output .= '<div class="bwf-progress-bar"><div class="bwf-progress ' . $animate . '"><span class="bwf-progress-inner-text">' . $content . '</span></div></div>';
949
950 $output .= '</div></div>';
951
952 return $output;
953 }
954
955 /**
956 * Output the dynamic aspects of Countdown block.
957 *
958 * @param array $attributes The block attributes.
959 * @param string $content The inner blocks.
960 *
961 * @since 1.1.0
962 */
963 public function do_count_down_block( $attributes, $content ) {
964
965 if ( isset( $attributes['uniqueID'] ) ) {
966 $unique_id = $attributes['uniqueID'];
967 $style_id = 'sling-block-' . esc_attr( $unique_id );
968 if ( ! wp_style_is( $style_id, 'enqueued' ) ) {
969 $css = SLINGBLOCKS_Frontend_CSS::get_instance()->render_count_down_css_head( $attributes, $unique_id );
970 if ( ! empty( $css ) ) {
971 SLINGBLOCKS_Frontend_CSS::get_instance()->render_inline_css( $css, $style_id );
972 }
973 }
974 }
975
976 try {
977 //code...
978
979 $output = '';
980
981 $settings = wp_parse_args( $attributes, [
982 'separatorStyle' => 'dotted'
983 ] );
984
985 $classNames = array(
986 'bwf-countdown-outer',
987 'bwf-' . $settings['uniqueID'],
988 );
989
990 if ( ! empty( $settings['className'] ) ) {
991 $classNames[] = $settings['className'];
992 }
993 $countdownStyle = 'block';
994 if ( ! empty( $settings['countdownStyle'] ) ) {
995 $classNames[] = 'bwf-' . $settings['countdownStyle'];
996 $countdownStyle = $settings['countdownStyle'];
997 }
998
999 $classNames = $this->has_block_visibiliy_classes( $settings, $classNames );
1000
1001 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'bwf-countdown-outer', array(
1002 'class' => implode( ' ', $classNames ),
1003 'id' => isset( $settings['anchor'] ) ? $settings['anchor'] : '',
1004 ), $settings ) );
1005 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'bwf-countdown-wrapper', array(
1006 'class' => 'bwf-countdown-wrapper',
1007 ), $settings ) );
1008 $date_style = '';
1009 if ( ! isset( $settings['campaignType'] ) ) {
1010 $campaignType = 'evergreen';
1011 } else {
1012 $campaignType = $settings['campaignType'];
1013 }
1014
1015 $checkDate = $campaignType !== 'evergreen' && ! empty( $settings['reverseCountdown'] ) && ! empty( $settings['startdate'] ) && new DateTime( $settings['startdate'] ) > new DateTime();
1016 $end_date = null;
1017 $cookie_data = null;
1018 $cookie_name = null;
1019 if ( $campaignType === 'evergreen' ) {
1020 $cookie_name = "sling_user_end_date" . $settings['uniqueID'];
1021
1022 $evergreenDay = isset( $settings['evergreenDay'] ) ? $settings['evergreenDay'] : 0;
1023 $evergreenHour = isset( $settings['evergreenHour'] ) ? $settings['evergreenHour'] : 11;
1024 $evergreenMinute = isset( $settings['evergreenMinute'] ) ? $settings['evergreenMinute'] : 0;
1025 $evergreenSecond = isset( $settings['evergreenSecond'] ) ? $settings['evergreenSecond'] : 0;
1026 $date = new DateTime( "+{$evergreenDay} day +{$evergreenHour} hour +{$evergreenMinute} minute +{$evergreenSecond} second" );
1027 $date_style = "{$evergreenDay},{$evergreenHour},{$evergreenMinute},{$evergreenSecond}";
1028 if ( ! isset( $_COOKIE[ $cookie_name ] ) ) {
1029 $cookie_data = $date->getTimestamp() . '000';
1030 } else {
1031 $new_date = new DateTime();
1032 $date_style = $new_date->getTimestamp();
1033 $end_date = $_COOKIE[ $cookie_name ];
1034 }
1035
1036 } else {
1037
1038
1039 $date = isset( $settings['timestamp'] ) ? $settings['timestamp'] : null;
1040
1041 $date_style = $date ? $date : '';
1042 if ( $checkDate ) {
1043 $date = isset( $settings['starttimestamp'] ) ? $settings['starttimestamp'] : null;
1044 $end_date = $date_style;
1045 $date_style = $date ? $date : '';
1046 } else {
1047 if ( empty( $settings['startdate'] ) || new DateTime( $settings['startdate'] ) < new DateTime() ) {
1048 $date = isset( $settings['timestamp'] ) ? $settings['timestamp'] : null;
1049 } else {
1050 return;
1051 }
1052 }
1053 }
1054 ob_start();
1055
1056 if ( $checkDate && ! empty( $settings['reverseText'] ) ) {
1057 ?>
1058 <div class="bwf-pre-text bwf-reverse-text"><?php echo $settings['reverseText']; ?></div>
1059 <?php
1060 } elseif ( ! empty( $settings['preText'] ) ) {
1061 ?>
1062 <div class="bwf-pre-text bwf-before-text"><?php echo $settings['preText']; ?></div>
1063 <?php
1064 }
1065 global $post;
1066 $funnel_redirect_link = null;
1067 if ( $post instanceof WP_Post ) {
1068 $post_type = $post->post_type;
1069 if ( $post_type === 'wfocu_offer' ) {
1070 $funnel_redirect_link = 'wfocu-reject-link=yes';
1071 } elseif ( $post_type === 'wffn_landing' ) {
1072 $funnel_redirect_link = 'wffn-next-link=yes';
1073 }
1074 }
1075 $seperator_classes = [
1076 'bwf-countdown-inner-wrap',
1077 'bwf-hidden'
1078 ];
1079 if ( ! isset( $settings['enableSeparator'] ) || $settings['enableSeparator'] && 'inline' !== $countdownStyle ) {
1080 array_push( $seperator_classes, 'bwf-separator' );
1081 array_push( $seperator_classes, 'bwf-separator-' . $settings['separatorStyle'] );
1082 }
1083 $output .= ob_get_clean();
1084 $output .= sprintf( '<div %1$s>', slingblocks_attr( 'bwf-countdown-inner-wrap', array(
1085 'class' => implode( ' ', $seperator_classes ),
1086 'cookie_data' => $cookie_data ? $cookie_data : null,
1087 'cookie_name' => $cookie_data ? $cookie_name : null,
1088 'bwf-date' => $date_style,
1089 'end_date' => $end_date,
1090 'msgAfter' => isset( $settings['expiryType'] ) && 'message' === $settings['expiryType'] ? ( isset( $settings['expiryTitle'] ) ? $settings['expiryTitle'] : 'Countdown is finished!' ) : null,
1091 'expiryRedirectUrl' => isset( $settings['expiryType'] ) && 'redirect' === $settings['expiryType'] ? ( isset( $settings['expiryRedirectUrl'] ) ? $settings['expiryRedirectUrl'] : null ) : null,
1092 'funnel-next-step' => isset( $settings['expiryType'] ) && 'funnel-next-step' === $settings['expiryType'] ? $funnel_redirect_link : null,
1093 ), $settings ) );
1094 $settings['dayLabel'] = isset( $settings['dayLabel'] ) ? $settings['dayLabel'] : 'Days';
1095 $settings['hourLabel'] = isset( $settings['hourLabel'] ) ? $settings['hourLabel'] : 'Hours';
1096 $settings['minuteLabel'] = isset( $settings['minuteLabel'] ) ? $settings['minuteLabel'] : 'Minutes';
1097 $settings['secondLabel'] = isset( $settings['secondLabel'] ) ? $settings['secondLabel'] : 'Seconds';
1098 ob_start();
1099 ?>
1100 <!-- Days -->
1101 <?php if ( ! isset( $settings['fixDayEnable'] ) || $settings['fixDayEnable'] ) { ?>
1102 <div class="bwf-digit-card" bwftype="<?php echo 'inline' !== $countdownStyle ? ( isset( $settings['separatorStyle'] ) && 'dotted' !== $settings['separatorStyle'] ? "|" : ":" ) : ''; ?>">
1103 <div class="bwf-card-data">
1104 <div class="bwf-timer-digit">{days}</div>
1105 <?php if ( $settings['dayLabel'] ) { ?>
1106 <div class="bwf-timer-label"><?php echo esc_html( $settings['dayLabel'] ); ?></div>
1107 <?php } else { ?>
1108 <div class="bwf-timer-label bwf-hidden">Days</div>
1109 <?php } ?>
1110 </div>
1111 </div>
1112 <?php } ?>
1113 <!-- Hours -->
1114 <?php if ( ! isset( $settings['fixHourEnable'] ) || $settings['fixHourEnable'] ) { ?>
1115 <div class="bwf-digit-card" bwftype="<?php echo 'inline' !== $countdownStyle ? ( isset( $settings['separatorStyle'] ) && 'dotted' !== $settings['separatorStyle'] ? "|" : ":" ) : ''; ?>">
1116 <div class="bwf-card-data">
1117 <div class="bwf-timer-digit">{hours}</div>
1118 <?php if ( $settings['hourLabel'] ) { ?>
1119 <div class="bwf-timer-label"><?php echo esc_html( $settings['hourLabel'] ); ?></div>
1120 <?php } else { ?>
1121 <div class="bwf-timer-label bwf-hidden">Hours</div>
1122 <?php } ?>
1123 </div>
1124 </div>
1125 <?php } ?>
1126 <!-- Minutes -->
1127 <?php if ( ! isset( $settings['fixMinuteEnable'] ) || $settings['fixMinuteEnable'] ) { ?>
1128 <div class="bwf-digit-card" bwftype="<?php echo 'inline' !== $countdownStyle ? ( isset( $settings['separatorStyle'] ) && 'dotted' !== $settings['separatorStyle'] ? "|" : ":" ) : ''; ?>">
1129 <div class="bwf-card-data">
1130 <div class="bwf-timer-digit">{minutes}</div>
1131 <?php if ( $settings['minuteLabel'] ) { ?>
1132 <div class="bwf-timer-label"><?php echo esc_html( $settings['minuteLabel'] ); ?></div>
1133 <?php } else { ?>
1134 <div class="bwf-timer-label bwf-hidden">Minutes</div>
1135 <?php } ?>
1136 </div>
1137 </div>
1138 <?php } ?>
1139 <!-- Seconds -->
1140 <?php if ( ! isset( $settings['fixSecEnable'] ) || $settings['fixSecEnable'] ) { ?>
1141 <div class="bwf-digit-card" bwftype="<?php echo 'inline' !== $countdownStyle ? ( isset( $settings['separatorStyle'] ) && 'dotted' !== $settings['separatorStyle'] ? "|" : ":" ) : ''; ?>">
1142 <div class="bwf-card-data">
1143 <div class="bwf-timer-digit">{seconds}</div>
1144 <?php if ( $settings['secondLabel'] ) { ?>
1145 <div class="bwf-timer-label"><?php echo esc_html( $settings['secondLabel'] ); ?></div>
1146 <?php } else { ?>
1147 <div class="bwf-timer-label bwf-hidden">Seconds</div>
1148 <?php } ?>
1149 </div>
1150 </div>
1151 <?php } ?>
1152 <div style="display:none" class="bwf-timer-hidden">{days}{hours}{seconds}{minutes}</div></div>
1153 <?php
1154 if ( ! $checkDate && ! empty( $settings['preText'] ) ) {
1155 ?>
1156 <div class="bwf-pre-text bwf-after-text"><?php echo $settings['postText']; ?></div>
1157 <?php
1158 }
1159 $output .= ob_get_clean() . '</div></div>';
1160
1161 return $output;
1162 } catch ( \Throwable $th ) {
1163 //throw $th;
1164 }
1165 }
1166 }
1167
1168 SLINGBLOCKS_Render_Block::get_instance();
1169