PluginProbe
bBlocks – Essential Gutenberg Blocks & Patterns Collection / 1.5.2
bBlocks – Essential Gutenberg Blocks & Patterns Collection v1.5.2
2.1.8 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 All 108 releases
b-blocks / inc / cards.php

cards.php in bBlocks – Essential Gutenberg Blocks & Patterns Collection 1.5.2, at inc/cards.php

190 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksCards extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'cards', 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 'cards' => array( 'type' => 'array', 'default' => array(
20 array(
21 'background' => array( 'color' => '#0000' ),
22 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
23 'imgBorder' => array( 'radius' => '5px' ),
24 'cat' => 'Category 1',
25 'catColor' => '#0dcaf0',
26 'title' => 'Card Title 1',
27 'titleColor' => '#ff7500',
28 'desc' => 'This content area describes card 1 descriptions or details.',
29 'descColor' => '#333'
30 ),
31 array(
32 'background' => array( 'color' => '#0000' ),
33 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
34 'imgBorder' => array( 'radius' => '5px' ),
35 'cat' => 'Category 2',
36 'catColor' => '#0dcaf0',
37 'title' => 'Card Title 2',
38 'titleColor' => '#ff7500',
39 'desc' => 'This content area describes card 2 descriptions or details.',
40 'descColor' => '#333'
41 ),
42 array(
43 'background' => array( 'color' => '#0000' ),
44 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
45 'imgBorder' => array( 'radius' => '5px' ),
46 'cat' => 'Category 3',
47 'catColor' => '#0dcaf0',
48 'title' => 'Card Title 3',
49 'titleColor' => '#ff7500',
50 'desc' => 'This content area describes card 3 descriptions or details.',
51 'descColor' => '#333'
52 )
53 ) ),
54
55 'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ),
56
57 'columnGap' => array( 'type' => 'string', 'default' => '20px' ),
58 'rowGap' => array( 'type' => 'string', 'default' => '30px' ),
59
60 'layout' => array( 'type' => 'string', 'default' => 'vertical' ),
61
62 'textAlign' => array( 'type' => 'string', 'default' => 'left' ),
63 'padding' => array( 'type' => 'object', 'default' => array( 'vertical' => '20px', 'horizontal' => '10px' ) ),
64
65 'imgPos' => array( 'type' => 'string', 'default' => 'top' ),
66 'imgHeight' => array( 'type' => 'string', 'default' => '250px' ),
67
68 'isCat' => array( 'type' => 'boolean', 'default' => true ),
69 'catTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) ),
70 'catMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ),
71
72 'isTitle' => array( 'type' => 'boolean', 'default' => true ),
73 'titlePos' => array( 'type' => 'string', 'default' => 'image' ),
74 'titleTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 22 ) ),
75 'titleMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ),
76
77 'isDesc' => array( 'type' => 'boolean', 'default' => true ),
78 'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15 ) )
79 );
80 }
81
82 function render( $attributes ){
83 extract( $attributes );
84
85 // Generate Styles
86 $cardsStyle = new BBlocksStyleGenerator();
87 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards", array(
88 'grid-gap' => "$rowGap $columnGap"
89 ) );
90 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards .bBlocksCard .cardImage img", array(
91 'height' => $imgHeight
92 ) );
93 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards .bBlocksCard .cardDetails", array(
94 'text-align' => $textAlign,
95 'padding' => $padding['styles'] ?? '20px 10px'
96 ) );
97 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards .bBlocksCard .cardDetails .cardCategory", array(
98 $catTypo['styles'] ?? 'font-size: 15px;' => '',
99 'margin' => $catMargin['styles'] ?? '0 0 10px 0'
100 ) );
101 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards .bBlocksCard .cardTitle", array(
102 $titleTypo['styles'] ?? 'font-size: 22px;' => '',
103 'margin' => $titleMargin['styles'] ?? '0 0 10px 0'
104 ) );
105 $cardsStyle::addStyle( "#bBlocksCards-$cId .bBlocksCards .bBlocksCard .cardDescription", array(
106 $catTypo['styles'] ?? 'font-size: 15px;' => ''
107 ) );
108
109 ob_start(); ?>
110 <div class='wp-block-b-blocks-cards <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksCards-<?php echo esc_attr( $cId ); ?>'>
111 <style>
112 @import url(<?php echo esc_url( $catTypo['googleFontLink'] ?? '' ); ?>);
113 @import url(<?php echo esc_url( $titleTypo['googleFontLink'] ?? '' ); ?>);
114 @import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>);
115 <?php echo wp_kses( $cardsStyle::renderStyle(), array() ); ?>
116 </style>
117
118 <div class='bBlocksCards <?php echo esc_attr( $layout ?? 'vertical' ); ?> columns-<?php echo esc_attr( $columns['desktop'] ); ?> columns-tablet-<?php echo esc_attr( $columns['tablet'] ); ?> columns-mobile-<?php echo esc_attr( $columns['mobile'] ); ?>'>
119 <?php foreach ( $cards as $index => $card ) {
120 extract( $card );
121
122 $cardStyle = new BBlocksStyleGenerator();
123 $cardStyle::addStyle( "#bBlocksCards-$cId #bBlocksCard-$index .bBlocksCard", array(
124 $background['styles'] ?? 'background-color: #0000;' => ''
125 ) );
126 $cardStyle::addStyle( "#bBlocksCards-$cId #bBlocksCard-$index .cardImage", array(
127 $imgBorder['styles'] ?? 'border-radius: 5px;' => ''
128 ) );
129 $cardStyle::addStyle( "#bBlocksCards-$cId #bBlocksCard-$index .cardDetails .cardCategory", array(
130 'color' => $catColor
131 ) );
132 $cardStyle::addStyle( "#bBlocksCards-$cId #bBlocksCard-$index .cardTitle", array(
133 'color' => $titleColor
134 ) );
135 $cardStyle::addStyle( "#bBlocksCards-$cId #bBlocksCard-$index .cardDescription", array(
136 'color' => $descColor
137 ) );
138
139 // Classes
140 $imgClass = isset( $img['id'] ) ? 'wp-image-'.$img['id'] : '';
141
142 // Components
143 $cardTitle = $isTitle && $title ? "<h3 class='cardTitle'>$title</h3>" : '';
144 $cardTitleInImage = 'image' === $titlePos ? $cardTitle : '';
145 $cardTitleInContent = 'content' === $titlePos ? $cardTitle : '';
146
147 $cardImage = $img['url'] ? "<figure class='cardImage'>
148 <img class='$imgClass' src='". $img['url'] ."' alt='". $img['alt'] ."' /> $cardTitleInImage
149 </figure>" : '';
150
151 $cardImageInTop = 'top' === $imgPos ? $cardImage : '';
152 $cardImageInBottom = 'bottom' === $imgPos ? $cardImage : '';
153 ?>
154
155 <div id='bBlocksCard-<?php echo esc_attr( $index ); ?>'>
156 <style><?php echo wp_kses( $cardStyle::renderStyle(), array() ); ?></style>
157
158 <div class='bBlocksCard <?php echo 'bottom' === $imgPos ? 'bottomImg' : 'topImg'; ?>'>
159 <?php echo wp_kses( $cardImageInTop, array(
160 'figure' => array( 'class' => array() ),
161 'img' => array( 'class' => array(), 'src' => array(), 'alt' => array() ),
162 'h3' => array( 'class' => array() )
163 ) ); ?>
164
165 <div class='cardDetails'>
166 <?php echo $isCat && $cat ? "<h6 class='cardCategory'>". wp_kses_post( $cat ) ."</h6>" : ''; ?>
167
168 <?php echo wp_kses( $cardTitleInContent, array(
169 'h3' => array( 'class' => array() )
170 ) ); ?>
171
172 <?php echo $isDesc && $desc ? "<p class='cardDescription'>". wp_kses_post( $desc ) ."</p>" : ''; ?>
173 </div>
174
175 <?php echo wp_kses( $cardImageInBottom, array(
176 'figure' => array( 'class' => array() ),
177 'img' => array( 'class' => array(), 'src' => array(), 'alt' => array() ),
178 'h3' => array( 'class' => array() )
179 ) ); ?>
180 </div>
181 </div>
182 <?php $cardStyle::$styles = array(); } ?>
183 </div>
184 </div>
185
186 <?php $cardsStyle::$styles = array(); // Empty styles
187 return ob_get_clean();
188 }
189 }
190 new BBlocksCards();