PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.10.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.10.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
ablocks / includes / blocks / advance-list-item / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.10.0, at includes/blocks/advance-list-item/block.php

276 lines 9.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\AdvanceListItem;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Controls\Alignment;
11 use ABlocks\Controls\Dimensions;
12 use ABlocks\Controls\Typography;
13 use ABlocks\Controls\TextShadow;
14 use ABlocks\Controls\TextStroke;
15 use ABlocks\Controls\Width;
16 use ABlocks\Controls\Border;
17 use ABlocks\Controls\Icon;
18 use ABlocks\Controls\Range;
19 use ABlocks\Controls\Color;
20
21 class Block extends BlockBaseAbstract {
22
23 protected $parent_block_name = 'advance-lists';
24 protected $block_name = 'advance-list-item';
25
26 public function build_css( $attributes ) {
27 // Generate CSS
28 $css_generator = new CssGenerator( $attributes );
29
30 $css_generator->add_class_styles(
31 '{{WRAPPER}}.ablocks-block--advance-list-item .ablocks-block-container .ablocks-advance-list-item-link',
32 $this->get_container_css( $attributes, '' ),
33 $this->get_container_css( $attributes, 'Tablet' ),
34 $this->get_container_css( $attributes, 'Mobile' ),
35 );
36 // Marker
37 $css_generator->add_class_styles(
38 '{{WRAPPER}}.ablocks-block--advance-list-item .advance-list-item-marker',
39 $this->get_marker_css( $attributes, '' ),
40 $this->get_marker_css( $attributes, 'Tablet' ),
41 $this->get_marker_css( $attributes, 'Mobile' ),
42 );
43 $css_generator->add_class_styles(
44 '{{WRAPPER}}.ablocks-block--advance-list-item .advance-list-item-marker,{{WRAPPER}}.ablocks-block--advance-list-item .ablocks-icon-wrap',
45 $this->get_icon_order_css( $attributes, '' ),
46 $this->get_icon_order_css( $attributes, 'Tablet' ),
47 $this->get_icon_order_css( $attributes, 'Mobile' ),
48 );
49 // Icon Style
50 $css_generator->add_class_styles(
51 '{{WRAPPER}} .ablocks-icon-wrap',
52 Icon::get_wrapper_css( $attributes ),
53 Icon::get_wrapper_css( $attributes, 'Tablet' ),
54 Icon::get_wrapper_css( $attributes, 'Mobile' )
55 );
56 $css_generator->add_class_styles(
57 '{{WRAPPER}} .ablocks-icon-wrap:hover',
58 Icon::get_wrapper_hover_css( $attributes ),
59 Icon::get_wrapper_hover_css( $attributes, 'Tablet' ),
60 Icon::get_wrapper_hover_css( $attributes, 'Mobile' )
61 );
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .ablocks-icon-wrap img.ablocks-image-icon',
64 Icon::get_element_image_css( $attributes ),
65 Icon::get_element_image_css( $attributes, 'Tablet' ),
66 Icon::get_element_image_css( $attributes, 'Mobile' ),
67 );
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .ablocks-icon-wrap svg.ablocks-svg-icon',
70 Icon::get_element_css( $attributes ),
71 Icon::get_element_css( $attributes, 'Tablet' ),
72 Icon::get_element_css( $attributes, 'Mobile' ),
73 );
74
75 // text
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .ablocks-block-container .ablocks-advance-list-item-text,
78 {{WRAPPER}} .ablocks-block-container .ablocks-advance-list-item-text a',
79 $this->get_paragraph_text_css( $attributes ),
80 $this->get_paragraph_text_css( $attributes, 'Tablet' ),
81 $this->get_paragraph_text_css( $attributes, 'Mobile' ),
82 );
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .ablocks-block-container .ablocks-advance-list-item-text-drop-caps::first-letter',
85 $this->get_paragraph_drop_text_css( $attributes ),
86 $this->get_paragraph_drop_text_css( $attributes, 'Tablet' ),
87 $this->get_paragraph_drop_text_css( $attributes, 'Mobile' ),
88 );
89
90 // Divider CSS
91 $css_generator->add_class_styles(
92 '{{WRAPPER}} .ablocks-advance-list-item-divider__pattern-' . ( $attributes['dividerType'] === 'mask-style' ? 'mask' : 'css' ),
93 $this->get_divider_css( $attributes, '' ),
94 $this->get_divider_css( $attributes, 'Tablet' ),
95 $this->get_divider_css( $attributes, 'Mobile' ),
96 );
97
98 return $css_generator->generate_css();
99 }
100
101
102 public function get_marker_css( $attributes, $device = '' ) {
103 $css = [];
104
105 if ( ! empty( $attributes['shapeColor'] ) && $attributes['markerType'] === 'Shapes' ) {
106 $css['border-color'] = Color::get_css( isset( $attributes['shapeColor'] ) ? $attributes['shapeColor'] : '' ) . '!important';
107 }
108 if ( ! empty( $attributes['shapeSize'][ 'value' . $device ] ) ) {
109 $shapeSize = $attributes['shapeSize'][ 'value' . $device ] . 'px';
110
111 if ( $attributes['markerType'] === 'Emoji' ) {
112 $css['font-size'] = $shapeSize;
113 } else {
114 if ( in_array( $attributes['shapeType'], [ 'inset', 'outset', 'ridge' ], true ) ) {
115 $css['border'] = $shapeSize . ' ' . $attributes['shapeType'];
116 } else {
117 $css['border-bottom'] = $shapeSize . ' ' . $attributes['shapeType'];
118 $css['width'] = $shapeSize;
119 }
120 }
121 }
122 return $css;
123 }
124
125 public function get_container_css( $attributes, $device = '' ) {
126 $css = [];
127 return array_merge(
128 $css,
129 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-items', $device ) : [],
130 Range::get_css([
131 'attributeValue' => $attributes['innerGap'],
132 'attribute_object_key' => 'value',
133 'isResponsive' => true,
134 'defaultValue' => null,
135 'hasUnit' => true,
136 'unitDefaultValue' => 'px',
137 'property' => 'gap',
138 'device' => $device,
139 ]),
140 );
141 }
142
143 public function get_icon_order_css( $attributes, $device = '' ) {
144 $css = [];
145
146 $css['margin'] = 'auto';
147
148 $iconAlignmentValue = $this->get_responsive_attribute_value( $attributes['iconAlignment'], $device );
149 if ( $iconAlignmentValue === 'row' ) {
150 $css['order'] = 1;
151 } elseif ( $iconAlignmentValue === 'row-reverse' ) {
152 $css['order'] = 2;
153 }
154
155 return array_merge(
156 $css,
157 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-items', $device ) : [],
158 Range::get_css([
159 'attributeValue' => $attributes['innerGap'],
160 'attribute_object_key' => 'value',
161 'isResponsive' => true,
162 'defaultValue' => null,
163 'hasUnit' => true,
164 'unitDefaultValue' => 'px',
165 'property' => 'gap',
166 'device' => $device,
167 ]),
168 );
169 }
170
171 public function get_paragraph_text_css( $attributes, $device = '' ) {
172 $css = [];
173 $iconAlignmentValue = $this->get_responsive_attribute_value( $attributes['iconAlignment'], $device );
174 $typographyValueGlobal = ! empty( $attributes['listTypographyGlobal'] ) ? $attributes['listTypographyGlobal'] : '';
175 $typography_value = isset( $attributes['listTypography'] ) ? $attributes['listTypography'] : [];
176
177 if ( $iconAlignmentValue === 'row' ) {
178 $css['order'] = 2;
179 } elseif ( $iconAlignmentValue === 'row-reverse' ) {
180 $css['order'] = 1;
181 }
182 return array_merge(
183 $css,
184 [ 'color' => Color::get_css( isset( $attributes['textColor'] ) ? $attributes['textColor'] : '' ) ],
185 Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ),
186 isset( $attributes['listTextStroke'] ) ? TextStroke::get_css( $attributes['listTextStroke'], '', $device ) : [],
187 isset( $attributes['listTextShadow'] ) ? TextShadow::get_css( $attributes['listTextShadow'] ) : [],
188 );
189 }
190 public function get_paragraph_drop_text_css( $attributes, $device = '' ) {
191 return [ 'color' => Color::get_css( isset( $attributes['dropCapsTextColor'] ) ? $attributes['dropCapsTextColor'] : '' ) ];
192 }
193
194 public function get_divider_css( $attributes, $device = '' ) {
195 $css = [];
196 $css['order'] = 3;
197 $divider_width = isset( $attributes['width'][ 'value' . $device ] ) ? $attributes['width'][ 'value' . $device ] : 60;
198 $default_Unit = '%';
199
200 if ( ! empty( $attributes['listsDirection'][ 'value' . $device ] ) && $attributes['listsDirection'][ 'value' . $device ] === 'row' ) {
201 $css['display'] = 'none';
202 } else {
203 $css['display'] = 'block';
204 }
205 if ( ! empty( $attributes['color'] ) ) {
206 $css['--ablocks-divider-pattern-color'] = Color::get_css( isset( $attributes['color'] ) ? $attributes['color'] : '#000000' );
207 }
208
209 $moreRangeCSS = [];
210 if ( isset( $attributes['dividerType'] ) && $attributes['dividerType'] === 'mask-style' && isset( $attributes['size'] ) && ! empty( $attributes['size'] ) ) {
211 $moreRangeCSS = Range::get_css([
212 'attributeValue' => $attributes['size'],
213 'attribute_object_key' => 'value',
214 'isResponsive' => false,
215 'defaultValue' => null,
216 'hasUnit' => false,
217 'unitDefaultValue' => 'px',
218 'property' => '--ablocks-divider-pattern-height',
219 ]);
220 } elseif ( isset( $attributes['weight'] ) && ! empty( $attributes['weight'] ) ) {
221 $moreRangeCSS = Range::get_css([
222 'attributeValue' => $attributes['weight'],
223 'attribute_object_key' => 'value',
224 'isResponsive' => false,
225 'defaultValue' => null,
226 'hasUnit' => false,
227 'unitDefaultValue' => 'px',
228 'property' => '--ablocks-divider-pattern-weight',
229 ]);
230 }//end if
231
232 if ( ! empty( $attributes['dividerPatternUrl'] ) ) {
233 if ( $attributes['dividerType'] === 'mask-style' ) {
234 $css['--ablocks-divider-pattern-url'] = 'url(' . $attributes['dividerPatternUrl'] . ')';
235 } else {
236 $css['--ablocks-divider-pattern-style'] = $attributes['dividerPatternUrl'];
237 }
238 }
239
240 return array_merge(
241 $css,
242 isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'justify-self', $device ) : [],
243 Range::get_css([
244 'attributeValue' => $attributes['width'],
245 'attribute_object_key' => 'value',
246 'isResponsive' => true,
247 'defaultValue' => null,
248 'hasUnit' => false,
249 'unitDefaultValue' => '%',
250 'property' => 'width',
251 'device' => $device,
252 ]),
253 $moreRangeCSS,
254 );
255 }
256
257 // don't delete this function, it's used in the render method to get responsive attribute values
258 public function get_responsive_attribute_value( $attribute, $device ) {
259
260 if ( $device === 'Mobile' ) {
261 return ! empty( $attribute['valueMobile'] ) ? $attribute['valueMobile']
262 : ( ! empty( $attribute['valueTablet'] ) ? $attribute['valueTablet']
263 : ( $attribute['value'] ?? '' ) );
264 }
265
266 if ( $device === 'Tablet' ) {
267 return ! empty( $attribute['valueTablet'] ) ? $attribute['valueTablet']
268 : ( $attribute['value'] ?? '' );
269 }
270
271 // Default (Desktop or others)
272 return $attribute['value'] ?? '';
273 }
274
275 }
276