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 / price-lists.php

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

170 lines 8.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 class BBlocksPriceLists extends BBlocks{
3 public function __construct(){
4 add_action( 'init', [$this, 'register'] );
5 }
6
7 function register(){
8 $this::registerScripts( 'price-lists', 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 'products' => array( 'type' => 'array', 'default' => array(
20 array(
21 'background' => array( 'color' => '#0000' ),
22 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
23 'imgBorder' => array(),
24 'name' => 'Product 1 Name',
25 'nameColor' => '#333',
26 'desc' => 'This content area describes product 1 descriptions or details.',
27 'descColor' => '#333',
28 'price' => '$99.99',
29 'priceColor' => '#4527a4',
30 'separator' => array( 'width' => '40%', 'height' => '1px', 'color' => '#bbb' )
31 ),
32 array(
33 'background' => array( 'color' => '#0000' ),
34 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
35 'imgBorder' => array(),
36 'name' => 'Product 2 Name',
37 'nameColor' => '#333',
38 'desc' => 'This content area describes product 2 descriptions or details.',
39 'descColor' => '#333',
40 'price' => '$99.99',
41 'priceColor' => '#4527a4',
42 'separator' => array( 'width' => '40%', 'height' => '1px', 'color' => '#bbb' )
43 ),
44 array(
45 'background' => array( 'color' => '#0000' ),
46 'img' => array( 'id' => NULL, 'url' => '', 'alt' => '', 'title' => '' ),
47 'imgBorder' => array(),
48 'name' => 'Product 3 Name',
49 'nameColor' => '#333',
50 'desc' => 'This content area describes product 3 descriptions or details.',
51 'descColor' => '#333',
52 'price' => '$99.99',
53 'priceColor' => '#4527a4',
54 'separator' => array( 'width' => '40%', 'height' => '1px', 'color' => '#bbb' )
55 )
56 ) ),
57
58 'columns' => array( 'type' => 'object', 'default' => array( 'desktop' => 3, 'tablet' => 2, 'mobile' => 1 ) ),
59
60 'columnGap' => array( 'type' => 'string', 'default' => '40px' ),
61 'rowGap' => array( 'type' => 'string', 'default' => '30px' ),
62
63 'layout' => array( 'type' => 'string', 'default' => 'vertical' ),
64
65 'textAlign' => array( 'type' => 'string', 'default' => 'center' ),
66 'padding' => array( 'type' => 'object', 'default' => array( 'vertical' => '50px', 'horizontal' => '20px' ) ),
67
68 'imgMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '20px' ) ),
69
70 'nameTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 18, 'fontWeight' => 600 ) ),
71 'nameMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '10px' ) ),
72
73 'isDesc' => array( 'type' => 'boolean', 'default' => true ),
74 'descTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 15, 'fontStyle' => 'italic' ) ),
75 'descMargin' => array( 'type' => 'object', 'default' => array( 'bottom' => '15px' ) ),
76
77 'priceTypo' => array( 'type' => 'object', 'default' => array( 'fontSize' => 24, 'fontStyle' => 'italic' ) ),
78
79 'isSep' => array( 'type' => 'boolean', 'default' => true )
80 );
81 }
82
83 function render( $attributes ){
84 extract( $attributes );
85
86 // Generate Styles
87 $priceListsStyle = new BBlocksStyleGenerator();
88 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists", array(
89 'grid-gap' => "$rowGap $columnGap"
90 ) );
91 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists .bBlocksPrice", array(
92 'text-align' => $textAlign,
93 'padding' => $padding['styles'] ?? '50px 20px'
94 ) );
95 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists .bBlocksPrice .productImage", array(
96 'margin' => $imgMargin['styles'] ?? '0 0 20px 0'
97 ) );
98 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists .bBlocksPrice .productName", array(
99 $nameTypo['styles'] ?? 'font-size: 18px; font-weight: 600;' => '',
100 'margin' => $nameMargin['styles'] ?? '0 0 10px 0'
101 ) );
102 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists .bBlocksPrice .productDescription", array(
103 $descTypo['styles'] ?? 'font-size: 15px; font-style: italic;' => '',
104 'margin' => $descMargin['styles'] ?? '0 0 15px 0'
105 ) );
106 $priceListsStyle::addStyle( "#bBlocksPriceLists-$cId .bBlocksPriceLists .bBlocksPrice .productPrice", array(
107 $priceTypo['styles'] ?? 'font-size: 24px; font-style: italic;' => ''
108 ) );
109
110 ob_start(); ?>
111 <div class='wp-block-b-blocks-price-lists <?php echo 'align' . esc_attr( $align ); ?>' id='bBlocksPriceLists-<?php echo esc_attr( $cId ); ?>'>
112 <style>
113 @import url(<?php echo esc_url( $nameTypo['googleFontLink'] ?? '' ); ?>);
114 @import url(<?php echo esc_url( $descTypo['googleFontLink'] ?? '' ); ?>);
115 @import url(<?php echo esc_url( $priceTypo['googleFontLink'] ?? '' ); ?>);
116 <?php echo wp_kses( $priceListsStyle::renderStyle(), array() ); ?>
117 </style>
118
119 <div class='bBlocksPriceLists <?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'] ); ?>'>
120 <?php foreach ( $products as $index => $product ) {
121 extract( $product );
122
123 $productStyle = new BBlocksStyleGenerator();
124 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index", array(
125 $background['styles'] ?? 'background-color: #0000;' => ''
126 ) );
127 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index .productImage", array(
128 $imgBorder['styles'] ?? '' => ''
129 ) );
130 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index .productName", array(
131 'color' => $nameColor
132 ) );
133 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index .productDescription", array(
134 'color' => $descColor
135 ) );
136 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index .productPrice", array(
137 'color' => $priceColor
138 ) );
139 $productStyle::addStyle( "#bBlocksPriceLists-$cId #bBlocksPrice-$index .productSeparator", array(
140 $separator['styles'] ?? 'width: 40%; border-top: 1px solid #bbb;' => ''
141 ) );
142
143 // Classes
144 $imgClass = isset( $img['id'] ) ? 'wp-image-'.$img['id'] : '';
145 ?>
146
147 <div class='bBlocksPrice' id='bBlocksPrice-<?php echo esc_attr( $index ); ?>'>
148 <style><?php echo wp_kses( $productStyle::renderStyle(), array() ); ?></style>
149
150 <?php echo $img['url'] ? "<img class='productImage ". esc_attr($imgClass) ."' src='". esc_url($img['url']) ."' alt='". esc_attr($img['alt']) ."' />" : ''; ?>
151
152 <div class='productDetails'>
153 <h4 class='productName'><?php echo wp_kses_post( $name ); ?></h4>
154
155 <?php echo $isDesc ? "<p class='productDescription'>". wp_kses_post( $desc ) ."</p>" : ''; ?>
156
157 <span class='productPrice'><?php echo wp_kses_post( $price ); ?></span>
158 </div>
159
160 <?php echo $isSep ? "<span class='productSeparator'></span>" : ''; ?>
161 </div>
162 <?php $productStyle::$styles = array(); } ?>
163 </div>
164 </div>
165
166 <?php $priceListsStyle::$styles = array(); // Empty styles
167 return ob_get_clean();
168 }
169 }
170 new BBlocksPriceLists();