PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.11
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.11
2.12.8 2.12.7 2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 All 98 releases
sureforms / modules / gutenberg / dist / blocks / advanced-heading / class-advanced-heading.php

class-advanced-heading.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 0.0.11, at modules/gutenberg/dist/blocks/advanced-heading/class-advanced-heading.php

748 lines 18.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Sureforms - Advanced Heading
4 *
5 * @package Sureforms
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 if ( ! class_exists( 'Advanced_Heading' ) ) {
13
14 /**
15 * Class Advanced_Heading.
16 */
17 class Advanced_Heading {
18
19 /**
20 * Member Variable
21 *
22 * @var Advanced_Heading|null
23 */
24 private static $instance;
25
26 /**
27 * Initiator
28 *
29 * @return Advanced_Heading The instance of the Advanced_Heading class.
30 */
31 public static function get_instance() {
32 if ( ! isset( self::$instance ) ) {
33 self::$instance = new self();
34 }
35 return self::$instance;
36 }
37
38 /**
39 * Constructor
40 */
41 public function __construct() {
42
43 // Activation hook.
44 add_action( 'init', [ $this, 'register_blocks' ] );
45 }
46
47 /**
48 * Registers the `sureforms/advanced-heading` block on server.
49 *
50 * @since 0.0.1
51 *
52 * @return void
53 */
54 public function register_blocks() {
55
56 // Check if the register function exists.
57 if ( ! function_exists( 'register_block_type' ) ) {
58 return;
59 }
60
61 $attr = [
62 'block_id' => [
63 'type' => 'string',
64 ],
65 'classMigrate' => [
66 'type' => 'boolean',
67 'default' => false,
68 ],
69 'blockBackgroundType' => [
70 'type' => 'string',
71 'default' => 'classic',
72 ],
73 'blockGradientBackground' => [
74 'type' => 'string',
75 'default' => 'linear-gradient(90deg, rgb(6, 147, 227) 0%, rgb(155, 81, 224) 100%)',
76 ],
77 'blockBackground' => [
78 'type' => 'string',
79 ],
80 'headingTitleToggle' => [
81 'type' => 'boolean',
82 'default' => true,
83 ],
84 'headingTitle' => [
85 'type' => 'string',
86 'default' => __( 'Your Attractive Heading', 'sureforms' ),
87 ],
88 'headingId' => [
89 'type' => 'string',
90 ],
91 'headingDescToggle' => [
92 'type' => 'boolean',
93 'default' => false,
94 ],
95 'headingDescPosition' => [
96 'type' => 'string',
97 'default' => 'below-heading',
98 ],
99 'headingDesc' => [
100 'type' => 'string',
101 ],
102 'headingAlign' => [
103 'type' => 'string',
104 'default' => 'left',
105 ],
106 'headingAlignTablet' => [
107 'type' => 'string',
108 'default' => '',
109 ],
110 'headingAlignMobile' => [
111 'type' => 'string',
112 'default' => '',
113 ],
114 'headingColorType' => [
115 'type' => 'string',
116 'default' => 'classic',
117 ],
118 'headingColor' => [
119 'type' => 'string',
120 'default' => '#000',
121 ],
122 'headingGradientColor' => [
123 'type' => 'string',
124 'default' => 'linear-gradient(90deg, rgb(155, 81, 224) 0%, rgb(6, 147, 227) 100%)',
125 ],
126 'subHeadingColor' => [
127 'type' => 'string',
128 'default' => '#000',
129 ],
130 'separatorColor' => [
131 'type' => 'string',
132 'default' => '#0170b9',
133 ],
134 'headingTag' => [
135 'type' => 'string',
136 'default' => 'h2',
137 ],
138 'level' => [
139 'type' => 'number',
140 'default' => 2,
141 ],
142 'separatorStyle' => [
143 'type' => 'string',
144 'default' => 'none',
145 ],
146 'separatorPosition' => [
147 'type' => 'string',
148 'default' => 'below-heading',
149 ],
150 'separatorHeight' => [
151 'type' => 'number',
152 'default' => 2,
153 ],
154 'separatorHeightType' => [
155 'type' => 'string',
156 'default' => 'px',
157 ],
158 'separatorWidth' => [
159 'type' => 'number',
160 'default' => 12,
161 ],
162 'separatorWidthTablet' => [
163 'type' => 'number',
164 ],
165 'separatorWidthMobile' => [
166 'type' => 'number',
167 ],
168 'separatorWidthType' => [
169 'type' => 'string',
170 'default' => '%',
171 ],
172 'headSpace' => [
173 'type' => 'number',
174 'default' => 15,
175 ],
176 'headSpaceMobile' => [
177 'type' => 'number',
178 'default' => '',
179 ],
180 'headSpaceTablet' => [
181 'type' => 'number',
182 'default' => '',
183 ],
184 'headSpaceType' => [
185 'type' => 'string',
186 'default' => 'px',
187 ],
188 'subHeadSpace' => [
189 'type' => 'number',
190 'default' => 15,
191 ],
192 'subHeadSpaceMobile' => [
193 'type' => 'number',
194 'default' => '',
195 ],
196 'subHeadSpaceTablet' => [
197 'type' => 'number',
198 'default' => '',
199 ],
200 'subHeadSpaceType' => [
201 'type' => 'string',
202 'default' => 'px',
203 ],
204 'headFontFamily' => [
205 'type' => 'string',
206 'default' => 'Default',
207 ],
208 'headFontWeight' => [
209 'type' => 'string',
210 ],
211 'headFontStyle' => [
212 'type' => 'string',
213 'default' => 'normal',
214 ],
215 'headTransform' => [
216 'type' => 'string',
217 ],
218 'headDecoration' => [
219 'type' => 'string',
220 ],
221 'headFontSizeType' => [
222 'type' => 'string',
223 'default' => 'px',
224 ],
225 'headFontSizeTypeMobile' => [
226 'type' => 'string',
227 'default' => 'px',
228 ],
229 'headFontSizeTypeTablet' => [
230 'type' => 'string',
231 'default' => 'px',
232 ],
233 'headLineHeightType' => [
234 'type' => 'string',
235 'default' => 'em',
236 ],
237 'headFontSize' => [
238 'type' => 'number',
239 ],
240 'headFontSizeTablet' => [
241 'type' => 'number',
242 ],
243 'headFontSizeMobile' => [
244 'type' => 'number',
245 ],
246 'headLineHeight' => [
247 'type' => 'number',
248 ],
249 'headLineHeightTablet' => [
250 'type' => 'number',
251 ],
252 'headLineHeightMobile' => [
253 'type' => 'number',
254 ],
255 'headLetterSpacing' => [
256 'type' => 'number',
257 ],
258 'headLetterSpacingTablet' => [
259 'type' => 'number',
260 ],
261 'headLetterSpacingMobile' => [
262 'type' => 'number',
263 ],
264 'headLetterSpacingType' => [
265 'type' => 'string',
266 'default' => 'px',
267 ],
268 'headShadowColor' => [
269 'type' => 'string',
270 'default' => '',
271 ],
272 'headShadowHOffset' => [
273 'type' => 'number',
274 'default' => 0,
275 ],
276 'headShadowVOffset' => [
277 'type' => 'number',
278 'default' => 0,
279 ],
280 'headShadowBlur' => [
281 'type' => 'number',
282 'default' => 10,
283 ],
284 // sub headline.
285 'subHeadFontFamily' => [
286 'type' => 'string',
287 'default' => 'Default',
288 ],
289 'subHeadFontWeight' => [
290 'type' => 'string',
291 ],
292 'subHeadFontStyle' => [
293 'type' => 'string',
294 'default' => 'normal',
295 ],
296 'subHeadTransform' => [
297 'type' => 'string',
298 ],
299 'subHeadDecoration' => [
300 'type' => 'string',
301 ],
302 'subHeadFontSize' => [
303 'type' => 'number',
304 ],
305 'subHeadFontSizeType' => [
306 'type' => 'string',
307 'default' => 'px',
308 ],
309 'subHeadFontSizeTypeMobile' => [
310 'type' => 'string',
311 'default' => 'px',
312 ],
313 'subHeadFontSizeTypeTablet' => [
314 'type' => 'string',
315 'default' => 'px',
316 ],
317 'subHeadFontSizeTablet' => [
318 'type' => 'number',
319 ],
320 'subHeadFontSizeMobile' => [
321 'type' => 'number',
322 ],
323 'subHeadLineHeight' => [
324 'type' => 'number',
325 ],
326 'subHeadLineHeightType' => [
327 'type' => 'string',
328 'default' => 'em',
329 ],
330 'subHeadLineHeightTablet' => [
331 'type' => 'number',
332 ],
333 'subHeadLineHeightMobile' => [
334 'type' => 'number',
335 ],
336 'subHeadLetterSpacing' => [
337 'type' => 'number',
338 ],
339 'subHeadLetterSpacingTablet' => [
340 'type' => 'number',
341 ],
342 'subHeadLetterSpacingMobile' => [
343 'type' => 'number',
344 ],
345 'subHeadLetterSpacingType' => [
346 'type' => 'string',
347 'default' => 'px',
348 ],
349 // separator.
350 'separatorSpace' => [
351 'type' => 'number',
352 'default' => 15,
353 ],
354 'separatorSpaceTablet' => [
355 'type' => 'number',
356 'default' => '',
357 ],
358 'separatorSpaceMobile' => [
359 'type' => 'number',
360 'default' => '',
361 ],
362 'separatorSpaceType' => [
363 'type' => 'string',
364 'default' => 'px',
365 ],
366 'headLoadGoogleFonts' => [
367 'type' => 'boolean',
368 'default' => false,
369 ],
370 'subHeadLoadGoogleFonts' => [
371 'type' => 'boolean',
372 'default' => false,
373 ],
374 'separatorHoverColor' => [
375 'type' => 'string',
376 ],
377 'isPreview' => [
378 'type' => 'boolean',
379 'default' => false,
380 ],
381 // padding.
382 'blockTopPadding' => [
383 'type' => 'number',
384 ],
385 'blockRightPadding' => [
386 'type' => 'number',
387 ],
388 'blockLeftPadding' => [
389 'type' => 'number',
390 ],
391 'blockBottomPadding' => [
392 'type' => 'number',
393 ],
394 'blockTopPaddingTablet' => [
395 'type' => 'number',
396 ],
397 'blockRightPaddingTablet' => [
398 'type' => 'number',
399 ],
400 'blockLeftPaddingTablet' => [
401 'type' => 'number',
402 ],
403 'blockBottomPaddingTablet' => [
404 'type' => 'number',
405 ],
406 'blockTopPaddingMobile' => [
407 'type' => 'number',
408 ],
409 'blockRightPaddingMobile' => [
410 'type' => 'number',
411 ],
412 'blockLeftPaddingMobile' => [
413 'type' => 'number',
414 ],
415 'blockBottomPaddingMobile' => [
416 'type' => 'number',
417 ],
418 'blockPaddingUnit' => [
419 'type' => 'string',
420 'default' => 'px',
421 ],
422 'blockPaddingUnitTablet' => [
423 'type' => 'string',
424 'default' => 'px',
425 ],
426 'blockPaddingUnitMobile' => [
427 'type' => 'string',
428 'default' => 'px',
429 ],
430 'blockPaddingLink' => [
431 'type' => 'boolean',
432 'default' => false,
433 ],
434 // margin.
435 'blockTopMargin' => [
436 'type' => 'number',
437 ],
438 'blockRightMargin' => [
439 'type' => 'number',
440 ],
441 'blockLeftMargin' => [
442 'type' => 'number',
443 ],
444 'blockBottomMargin' => [
445 'type' => 'number',
446 ],
447 'blockTopMarginTablet' => [
448 'type' => 'number',
449 ],
450 'blockRightMarginTablet' => [
451 'type' => 'number',
452 ],
453 'blockLeftMarginTablet' => [
454 'type' => 'number',
455 ],
456 'blockBottomMarginTablet' => [
457 'type' => 'number',
458 ],
459 'blockTopMarginMobile' => [
460 'type' => 'number',
461 ],
462 'blockRightMarginMobile' => [
463 'type' => 'number',
464 ],
465 'blockLeftMarginMobile' => [
466 'type' => 'number',
467 ],
468 'blockBottomMarginMobile' => [
469 'type' => 'number',
470 ],
471 'blockMarginUnit' => [
472 'type' => 'string',
473 'default' => 'px',
474 ],
475 'blockMarginUnitTablet' => [
476 'type' => 'string',
477 'default' => 'px',
478 ],
479 'blockMarginUnitMobile' => [
480 'type' => 'string',
481 'default' => 'px',
482 ],
483 'blockMarginLink' => [
484 'type' => 'boolean',
485 'default' => false,
486 ],
487 // link.
488 'linkColor' => [
489 'type' => 'string',
490 ],
491 'linkHColor' => [
492 'type' => 'string',
493 ],
494 // Highlight.
495 'highLightColor' => [
496 'type' => 'string',
497 'default' => '#fff',
498 ],
499 'highLightBackground' => [
500 'type' => 'string',
501 'default' => '#007cba',
502 ],
503 'highLightLoadGoogleFonts' => [
504 'type' => 'boolean',
505 'default' => false,
506 ],
507 'highLightFontFamily' => [
508 'type' => 'string',
509 'default' => 'default',
510 ],
511 'highLightFontWeight' => [
512 'type' => 'string',
513 'default' => 'Default',
514 ],
515 'highLightFontStyle' => [
516 'type' => 'string',
517 'default' => 'normal',
518 ],
519 'highLightTransform' => [
520 'type' => 'string',
521 ],
522 'highLightDecoration' => [
523 'type' => 'string',
524 ],
525 'highLightFontSizeType' => [
526 'type' => 'string',
527 'default' => 'px',
528 ],
529 'highLightFontSizeTypeMobile' => [
530 'type' => 'string',
531 'default' => 'px',
532 ],
533 'highLightFontSizeTypeTablet' => [
534 'type' => 'string',
535 'default' => 'px',
536 ],
537 'highLightLineHeightType' => [
538 'type' => 'string',
539 'default' => 'em',
540 ],
541 'highLightFontSize' => [
542 'type' => 'number',
543 ],
544 'highLightFontSizeTablet' => [
545 'type' => 'number',
546 ],
547 'highLightFontSizeMobile' => [
548 'type' => 'number',
549 ],
550 'highLightLineHeight' => [
551 'type' => 'number',
552 ],
553 'highLightLineHeightTablet' => [
554 'type' => 'number',
555 ],
556 'highLightLineHeightMobile' => [
557 'type' => 'number',
558 ],
559 'highLightLetterSpacing' => [
560 'type' => 'number',
561 ],
562 'highLightLetterSpacingTablet' => [
563 'type' => 'number',
564 ],
565 'highLightLetterSpacingMobile' => [
566 'type' => 'number',
567 ],
568 'highLightLetterSpacingType' => [
569 'type' => 'string',
570 'default' => 'px',
571 ],
572 'highLightTopPadding' => [
573 'type' => 'number',
574 ],
575 'highLightRightPadding' => [
576 'type' => 'number',
577 ],
578 'highLightLeftPadding' => [
579 'type' => 'number',
580 ],
581 'highLightBottomPadding' => [
582 'type' => 'number',
583 ],
584 'highLightTopPaddingTablet' => [
585 'type' => 'number',
586 ],
587 'highLightRightPaddingTablet' => [
588 'type' => 'number',
589 ],
590 'highLightLeftPaddingTablet' => [
591 'type' => 'number',
592 ],
593 'highLightBottomPaddingTablet' => [
594 'type' => 'number',
595 ],
596 'highLightTopPaddingMobile' => [
597 'type' => 'number',
598 ],
599 'highLightRightPaddingMobile' => [
600 'type' => 'number',
601 ],
602 'highLightLeftPaddingMobile' => [
603 'type' => 'number',
604 ],
605 'highLightBottomPaddingMobile' => [
606 'type' => 'number',
607 ],
608 'highLightPaddingUnit' => [
609 'type' => 'string',
610 'default' => 'px',
611 ],
612 'highLightPaddingUnitTablet' => [
613 'type' => 'string',
614 'default' => 'px',
615 ],
616 'highLightPaddingUnitMobile' => [
617 'type' => 'string',
618 'default' => 'px',
619 ],
620 'highLightPaddingLink' => [
621 'type' => 'boolean',
622 'default' => false,
623 ],
624 ];
625
626 $advaned_heading_border_attr = Spec_Gb_Helper::get_instance()->generate_php_border_attribute( 'highLight' );
627
628 $attr = array_merge( $advaned_heading_border_attr, $attr );
629
630 $attributes = apply_filters( 'srfm_gutenberg_advaned_heading_attributes_filters', $attr );
631
632 register_block_type(
633 'srfm/advanced-heading',
634 [
635 'attributes' => $attributes,
636 'render_callback' => [ $this, 'render_html' ],
637 ]
638 );
639 }
640
641 /**
642 * Render CF HTML.
643 *
644 * @param array<mixed> $attributes Array of block attributes.
645 *
646 * @since 0.0.1
647 *
648 * @return string|false
649 */
650 public function render_html( $attributes ) {
651
652 $block_id = '';
653 $form_id = '';
654 $heading_wrapper = '';
655 if ( isset( $attributes['block_id'] ) ) {
656 $block_id = $attributes['block_id'];
657 }
658 if ( isset( $attributes['formId'] ) ) {
659 $form_id = $attributes['formId'];
660 }
661 if ( isset( $attributes['headingWrapper'] ) ) {
662 $heading_wrapper = $attributes['headingWrapper'];
663 }
664
665 $element = ! empty( $heading_wrapper ) ? $heading_wrapper : 'div';
666
667 $seperator = '';
668
669 if ( isset( $attributes['separatorStyle'] )
670 && 'none' !== $attributes['separatorStyle']
671 ) {
672 $seperator = '<div class="uagb-separator"></div>';
673 }
674
675 $heading_text = '';
676
677 if ( isset( $attributes['headingTitle'] ) ) {
678 $heading_text = 'above-heading' === $attributes['separatorPosition'] ? $seperator : '';
679 $attributes['headingId'] = isset( $attributes['headingId'] ) ? "id='{$attributes['headingId']}'" : '';
680 $heading_text .= sprintf(
681 '<%1$s class="uagb-heading-text" %3$s>%2$s</%1$s>',
682 esc_attr( $attributes['headingTag'] ),
683 $attributes['headingTitle'],
684 esc_attr( $attributes['headingId'] )
685 );
686 $heading_text .= 'below-heading' === $attributes['separatorPosition'] ? $seperator : '';
687 }
688
689 $desc_text = '';
690
691 if ( isset( $attributes['headingDesc'] ) ) {
692 $desc_text = 'above-sub-heading' === $attributes['separatorPosition'] ? $seperator : '';
693 $desc_text .= sprintf(
694 '<p class="uagb-desc-text">%1$s</p>',
695 $attributes['headingDesc']
696 );
697 $desc_text .= 'below-sub-heading' === $attributes['separatorPosition'] ? $seperator : '';
698 }
699
700 $conditional_class = apply_filters( 'srfm_conditional_logic_classes', $form_id, $block_id );
701
702 $main_classes = [
703 'wp-block-uagb-advanced-heading',
704 'uagb-block',
705 'uagb-block-' . $block_id,
706 $conditional_class,
707 ];
708
709 if ( isset( $attributes['className'] ) ) {
710 $main_classes[] = $attributes['className'];
711 }
712
713 ob_start();
714 ?>
715 <<?php echo esc_attr( $element ); ?> data-block-id="<?php echo esc_attr( $block_id ); ?>" class="<?php echo esc_attr( implode( ' ', $main_classes ) ); ?>">
716 <?php
717 if ( $attributes['headingDescToggle']
718 && 'above-heading' === $attributes['headingDescPosition']
719 ) {
720 echo wp_kses( $desc_text, 'post' );
721 }
722 if ( isset( $attributes['headingTitleToggle'] ) && true === $attributes['headingTitleToggle'] ) {
723 echo wp_kses( $heading_text, 'post' );
724 }
725 if ( $attributes['headingDescToggle']
726 && 'below-heading' === $attributes['headingDescPosition']
727 ) {
728 echo wp_kses( $desc_text, 'post' );
729 }
730 if ( ! $attributes['headingDescToggle']
731 && ! $attributes['headingTitleToggle']
732 ) {
733 echo wp_kses( $seperator, 'post' );
734 }
735 ?>
736 </<?php echo esc_attr( $element ); ?>>
737 <?php
738 return ob_get_clean();
739 }
740 }
741
742 /**
743 * Prepare if class 'Advanced_Heading' exist.
744 * Kicking this off by calling 'get_instance()' method
745 */
746 Advanced_Heading::get_instance();
747 }
748