PluginProbe
SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) / 1.3.0
SlingBlocks – Gutenberg Blocks by FunnelKit (Formerly WooFunnels) v1.3.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.3.0, at includes/class-render-blocks.php

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