PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 1.5
bBlocks – Essential Gutenberg Blocks & Patterns Collection v1.5
2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 2.1.2 2.1.1 2.1.0 2.0.43 2.0.42 2.0.41 2.0.40 2.0.39 2.0.38 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.5.1 1.5.2 1.5.3 1.5.4 All 107 releases
b-blocks / inc / feature-boxes.php

feature-boxes.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 1.5, at inc/feature-boxes.php

168 lines 9.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksFeatureBoxes extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'feature-boxes', array(
9 'attributes' => $this->attributes(),
10 'render_callback' => [$this, 'render']
11 ) );
12 }
13
14 function attributes(){
15 return array(
16 'align' => array( 'type' => 'string', 'default' => '' ),
17 'cId' => array( 'type' => 'string', 'default' => '' ),
18
19 'features' => array( 'type' => 'array', 'default' => array(
20 array(
21 'background' => array( 'color' => '#0000' ),
22 'isUpIcon' => false,
23 'icon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 120 ),
24 'upIcon' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
25 'iconWidth' => '120px',
26 'title' => 'Feature 1',
27 'titleColor' => '#333',
28 'separator' => array( 'width' => '20%', 'height' => '2px', 'style' => 'solid', 'color' => '#bbb' ),
29 'desc' => 'This content area describes feature 1 descriptions or details.',
30 'descColor' => '#333'
31 ),
32 array(
33 'background' => array( 'color' => '#0000' ),
34 'isUpIcon' => false,
35 'icon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 120 ),
36 'upIcon' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
37 'iconWidth' => '120px',
38 'title' => 'Feature 2',
39 'titleColor' => '#333',
40 'separator' => array( 'width' => '20%', 'height' => '2px', 'style' => 'solid', 'color' => '#bbb' ),
41 'desc' => 'This content area describes feature 2 descriptions or details.',
42 'descColor' => '#333'
43 ),
44 array(
45 'background' => array( 'color' => '#0000' ),
46 'isUpIcon' => false,
47 'icon' => array( 'class' => 'fa fa-wordpress', 'fontSize' => 120 ),
48 'upIcon' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
49 'iconWidth' => '120px',
50 'title' => 'Feature 3',
51 'titleColor' => '#333',
52 'separator' => array( 'width' => '20%', 'height' => '2px', 'style' => 'solid', 'color' => '#bbb' ),
53 'desc' => 'This content area describes feature 3 descriptions or details.',
54 'descColor' => '#333'
55 )
56 ) ),
57
58 'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ),
59
60 'columnGap' => array( 'type' => 'string', 'default' => '30px' ),
61 'rowGap' => array( 'type' => 'string', 'default' => '30px' ),
62
63 'textAlign' => array( 'type' => 'string', 'default' => 'center' ),
64 'padding' => array( 'type' => 'object', 'default' => array( 'vertical' => '50px', 'horizontal' => '20px' ) ),
65
66 'isIcon' => array( 'type' => 'boolean', 'default' => true ),
67 'iconMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '20px' ) ),
68
69 'isTitle' => array( 'type' => 'boolean', 'default' => true ),
70 'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 20, 'fontWeight' => 600 ) ),
71 'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ),
72
73 'isSep' => array( 'type' => 'boolean', 'default' => true ),
74 'sepMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ),
75
76 'isDesc' => array( 'type' => 'boolean', 'default' => true ),
77 'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) )
78 );
79 }
80
81 function render( $attributes ){
82 extract( $attributes );
83
84 // Generate Styles
85 $featureBoxesStyle = new BBlocksStyleGenerator();
86 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes", array(
87 'grid-gap' => "$rowGap $columnGap"
88 ) );
89 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes .bBlocksFeature", array(
90 'text-align' => $textAlign,
91 'padding' => $padding['styles'] ?? '50px 20px'
92 ) );
93 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes .bBlocksFeature .featureIcon", array(
94 'margin' => $iconMargin['styles'] ?? '0 0 10px 0'
95 ) );
96 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes .bBlocksFeature .featureTitle", array(
97 $titleTypo['styles'] ?? 'font-size: 20px; font-weight: 600;' => '',
98 'margin' => $titleMargin['styles'] ?? '0 0 10px 0'
99 ) );
100 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes .bBlocksFeature .featureSeparator", array(
101 'margin' => $sepMargin['styles'] ?? '0 0 10px 0'
102 ) );
103 $featureBoxesStyle::addStyle( "#bBlocksFeatureBoxes-$cId .bBlocksFeatureBoxes .bBlocksFeature .featureDescription", array(
104 $descTypo['styles'] ?? 'font-size: 15px;' => ''
105 ) );
106
107 ob_start(); ?>
108 <div class='wp-block-b-blocks-feature-boxes <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksFeatureBoxes-<?php echo esc_attr( $cId ); ?>'>
109 <style>
110 @import url(<?php echo esc_url( $titleTypo['googleFontLink'] ?? '' ); ?>);
111 @import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>);
112 <?php echo wp_kses( $featureBoxesStyle::renderStyle(), array() ); ?>
113 </style>
114
115 <div class='bBlocksFeatureBoxes columns-<?php echo esc_attr( $columns['desktop'] ); ?> columns-tablet-<?php echo esc_attr( $columns['tablet'] ); ?> columns-mobile-<?php echo esc_attr( $columns['mobile'] ); ?>'>
116 <?php foreach ( $features as $index => $feature ) {
117 extract( $feature );
118
119 $featureStyle = new BBlocksStyleGenerator();
120 $featureStyle::addStyle( "#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index", array(
121 $background['styles'] ?? 'background-color: #0000;' => ''
122 ) );
123 $featureStyle::addStyle("#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index .featureIcon i", array(
124 $icon['styles'] ?? 'font-size: 120px;' => ''
125 ) );
126 $featureStyle::addStyle("#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index .featureIcon img", array(
127 'width' => $iconWidth
128 ) );
129 $featureStyle::addStyle( "#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index .featureTitle", array(
130 'color' => $titleColor
131 ) );
132 $featureStyle::addStyle( "#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index .featureSeparator", array(
133 $separator['styles'] ?? 'width: 20%; border-top: 1px solid #bbb;' => ''
134 ) );
135 $featureStyle::addStyle( "#bBlocksFeatureBoxes-$cId #bBlocksFeature-$index .featureDescription", array(
136 'color' => $descColor
137 ) );
138
139 // Classes
140 $iconClass = isset( $upIcon['id'] ) ? 'wp-image-'.$upIcon['id'] : '';
141 ?>
142
143 <div class='bBlocksFeature' id='bBlocksFeature-<?php echo esc_attr( $index ); ?>'>
144 <style><?php echo wp_kses( $featureStyle::renderStyle(), array() ); ?></style>
145
146 <div class='featureIcon'>
147 <?php echo $isUpIcon ?
148 ( $upIcon['url'] ? "<img class='". esc_attr( $iconClass ) ."' src='". esc_url( $upIcon['url'] ) ."' alt='". esc_attr( $upIcon['alt'] ) ."' />" : '' ) :
149 ( $icon['class'] ? "<i class='". esc_attr( $icon['class'] ) ."'></i>" : '' ); ?>
150 </div>
151
152 <div class='featureDetails'>
153 <?php echo $isTitle && $title ? "<h4 class='featureTitle'>". esc_html( $title ) ."</h4>" : ''; ?>
154
155 <?php echo $isSep ? "<span class='featureSeparator'></span>" : ''; ?>
156
157 <?php echo $isDesc && $desc ? "<p class='featureDescription'>". esc_html( $desc ) ."</p>" : ''; ?>
158 </div>
159 </div>
160 <?php $featureStyle::$styles = array(); } ?>
161 </div>
162 </div>
163
164 <?php $featureBoxesStyle::$styles = array(); // Empty styles
165 return ob_get_clean();
166 }
167 }
168 new BBlocksFeatureBoxes();