PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.1
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 1.1.2 All 80 releases
ablocks / includes / blocks / content-timeline / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.1, at includes/blocks/content-timeline/block.php

368 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\ContentTimeline;
4
5 use ABlocks\Controls\Range;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10 use ABlocks\Classes\BlockBaseAbstract;
11 use ABlocks\Classes\CssGenerator;
12 use ABlocks\Controls\Dimensions;
13 use ABlocks\Controls\Typography;
14 use ABlocks\Controls\Border;
15
16 class Block extends BlockBaseAbstract {
17
18 protected $block_name = 'content-timeline';
19
20 public function build_css( $attributes ) {
21 $css_generator = new CssGenerator( $attributes );
22
23 // Generate and add CSS styles for different parts of the block
24 $css_generator->add_class_styles(
25 '{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-icon-maker svg',
26 $this->get_content_timeline_icon_css( $attributes ),
27 $this->get_content_timeline_icon_css( $attributes, 'Tablet' ),
28 $this->get_content_timeline_icon_css( $attributes, 'Mobile' )
29 );
30 $css_generator->add_class_styles(
31 '{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks__in-view-icon .ablocks-icon-wrap',
32 $this->get_content_timeline_icon_background_css( $attributes ),
33 $this->get_content_timeline_icon_background_css( $attributes, 'Tablet' ),
34 $this->get_content_timeline_icon_background_css( $attributes, 'Mobile' )
35 );
36 $css_generator->add_class_styles(
37 '{{WRAPPER}} .ablocks-block-content-timeline .ablocks-block-content-timeline__line',
38 $this->get_content_timeline_connector_css( $attributes ),
39 $this->get_content_timeline_connector_css( $attributes, 'Tablet' ),
40 $this->get_content_timeline_connector_css( $attributes, 'Mobile' )
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field',
44 $this->get_content_timeline_item_gap_css( $attributes ),
45 $this->get_content_timeline_item_gap_css( $attributes, 'Tablet' ),
46 $this->get_content_timeline_item_gap_css( $attributes, 'Mobile' )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .ablocks-block-content-timeline--outer-wrap .ablocks-block-content-timeline-child--field .ablocks-block-content-timeline-child__content-part',
50 $this->get_content_timeline_content_css( $attributes ),
51 $this->get_content_timeline_content_css( $attributes, 'Tablet' ),
52 $this->get_content_timeline_content_css( $attributes, 'Mobile' )
53 );
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .ablocks-block-content-timeline-child__content-part .ablocks-block-content-timeline-child__arrow::after',
56 $this->get_content_timeline_content_background_css( $attributes ),
57 $this->get_content_timeline_content_background_css( $attributes, 'Tablet' ),
58 $this->get_content_timeline_content_background_css( $attributes, 'Mobile' )
59 );
60 // Conditional CSS generation based on arrowAlignment
61 $arrowAlignment = $attributes['arrowAlignment'] ?? 'top';
62
63 if ( $arrowAlignment === 'top' ) {
64 $css_generator->add_class_styles(
65 '{{WRAPPER}} .ablocks-block-content-timeline-child--line-top .ablocks-block-content-timeline-child__arrow',
66 $this->get_content_timeline_arrow_css( $attributes ),
67 $this->get_content_timeline_arrow_css( $attributes, 'Tablet' ),
68 $this->get_content_timeline_arrow_css( $attributes, 'Mobile' )
69 );
70 $css_generator->add_class_styles(
71 '{{WRAPPER}} .ablocks-block-content-timeline-child--line-top .ablocks-block-content-timeline-child__date',
72 $this->get_content_timeline_date_alignment_css( $attributes ),
73 $this->get_content_timeline_date_alignment_css( $attributes, 'Tablet' ),
74 $this->get_content_timeline_date_alignment_css( $attributes, 'Mobile' )
75 );
76 } elseif ( $arrowAlignment === 'bottom' ) {
77 $css_generator->add_class_styles(
78 '{{WRAPPER}} .ablocks-block-content-timeline-child--line-bottom .ablocks-block-content-timeline-child__arrow',
79 $this->get_content_timeline_arrow_css( $attributes ),
80 $this->get_content_timeline_arrow_css( $attributes, 'Tablet' ),
81 $this->get_content_timeline_arrow_css( $attributes, 'Mobile' )
82 );
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .ablocks-block-content-timeline-child--line-bottom .ablocks-block-content-timeline-child__date',
85 $this->get_content_timeline_date_alignment_css( $attributes ),
86 $this->get_content_timeline_date_alignment_css( $attributes, 'Tablet' ),
87 $this->get_content_timeline_date_alignment_css( $attributes, 'Mobile' )
88 );
89 }//end if
90 $css_generator->add_class_styles(
91 '{{WRAPPER}} .ablocks-block-content-timeline-child__date,.ablocks-block-content-timeline-child__inner-content-date',
92 $this->get_content_timeline_date_css( $attributes ),
93 $this->get_content_timeline_date_css( $attributes, 'Tablet' ),
94 $this->get_content_timeline_date_css( $attributes, 'Mobile' )
95 );
96 $css_generator->add_class_styles(
97 '{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date',
98 $this->get_content_timeline_date_mobile_css( $attributes, 'Mobile' )
99 );
100 $css_generator->add_class_styles(
101 '{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date:hover',
102 $this->get_content_timeline_date_hover_mobile_css( $attributes, 'Mobile' )
103 );
104 $css_generator->add_class_styles(
105 '{{WRAPPER}} .ablocks-block-content-timeline-child__date-inner',
106 $this->get_content_timeline_show_date_center_css( $attributes, '' ),
107 $this->get_content_timeline_show_date_center_css( $attributes, 'Tablet' ),
108 $this->get_content_timeline_show_date_center_css( $attributes, 'Mobile' )
109 );
110 $css_generator->add_class_styles(
111 '{{WRAPPER}} .ablocks-block-content-timeline-child__date',
112 $this->get_content_timeline_show_date_left_right_css( $attributes, '' ),
113 $this->get_content_timeline_show_date_left_right_css( $attributes, 'Tablet' ),
114 $this->get_content_timeline_show_date_left_right_css( $attributes, 'Mobile' )
115 );
116 $css_generator->add_class_styles(
117 '{{WRAPPER}} .ablocks-block-content-timeline--left .ablocks-block-content-timeline__line,.ablocks-block-content-timeline--right .ablocks-block-content-timeline__line',
118 $this->get_content_timeline_show_date_left_right_line_css( $attributes, '' ),
119 $this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Tablet' ),
120 $this->get_content_timeline_show_date_left_right_line_css( $attributes, 'Mobile' )
121 );
122 $css_generator->add_class_styles(
123 '{{WRAPPER}} .ablocks-block-content-timeline-child__inner-content-date',
124 $this->get_content_timeline_show_date_mobile_css( $attributes, '' ),
125 $this->get_content_timeline_show_date_mobile_css( $attributes, 'Tablet' ),
126 $this->get_content_timeline_show_date_mobile_css( $attributes, 'Mobile' )
127 );
128
129 return $css_generator->generate_css();
130 }
131 public function get_content_timeline_show_date_mobile_css( $attributes, $device = '' ) {
132 $css = [];
133 if ( $device === '' || $device === 'Tablet' ) {
134 $css['display'] = 'none';
135 }
136 if ( $device === 'Mobile' ) {
137 if ( isset( $attributes[ "showDate{$device}" ] ) && $attributes[ "showDate{$device}" ] === false ) {
138 $css['display'] = 'none';
139 } elseif ( isset( $attributes[ "showDate{$device}" ] ) && $attributes[ "showDate{$device}" ] === true ) {
140 $css['display'] = 'block';
141 }
142 }
143
144 return $css;
145 }
146 public function get_content_timeline_show_date_center_css( $attribute, $device ) {
147 $css = [];
148 $showDateKey = $device ? "showDate{$device}" : 'showDate';
149 $showDate = $attribute[ $showDateKey ] ?? null;
150 $isCentered = $attribute['contentPosition'] === 'center';
151
152 if ( $isCentered ) {
153 $css['display'] = $showDate ? 'block' : 'none';
154 }
155
156 return $css;
157 }
158
159 public function get_content_timeline_show_date_left_right_css( $attribute, $device ) {
160 $css = [];
161 $showDateKey = $device ? "showDate{$device}" : 'showDate';
162 $showDate = $attribute[ $showDateKey ] ?? null;
163 $isLeftOrRight = in_array( $attribute['contentPosition'], [ 'left', 'right' ], true );
164
165 if ( $isLeftOrRight ) {
166 if ( $device !== 'Mobile' ) {
167 $css['display'] = $showDate ? 'block !important' : 'none !important';
168 } elseif ( $device === 'Mobile' ) {
169 $css['display'] = 'none !important';
170
171 }
172 }
173 if ( $attribute['contentPosition'] === 'center' ) {
174 $css['display'] = 'block';
175 }
176
177 return $css;
178 }
179 public function get_content_timeline_show_date_left_right_line_css( $attribute, $device ) {
180 $css = [];
181 $showDate = $attribute[ "showDate{$device}" ] ?? null;
182 if ( $device === 'Mobile' ) {
183 // Specific case for mobile content position left/right without date
184 if ( $attribute['contentPosition'] === 'left' ) {
185 $css['left'] = 'calc(61px / 2) !important'; // fallback for left without date
186 } elseif ( $attribute['contentPosition'] === 'right' ) {
187 $css['right'] = 'calc(61px / 2) !important'; // fallback for right without date
188 }
189 } elseif ( $device ) {
190 // Non-mobile styles (if needed)
191 if ( $attribute['contentPosition'] === 'left' ) {
192 $css['left'] = $showDate ? 'calc(33% / 2) !important' : 'calc(61px / 2) !important';
193 $css['right'] = 'auto !important';
194 } elseif ( $attribute['contentPosition'] === 'right' ) {
195 $css['right'] = $showDate ? 'calc(33% / 2) !important' : 'calc(61px / 2) !important';
196 $css['left'] = 'auto !important';
197 }
198 } else {
199 if ( $attribute['contentPosition'] === 'left' ) {
200 $css['left'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important';
201 $css['right'] = 'auto !important';
202 } elseif ( $attribute['contentPosition'] === 'right' ) {
203 $css['right'] = $showDate ? 'calc(30% / 2) !important' : 'calc(61px / 2) !important';
204 $css['left'] = 'auto !important';
205 }
206 }//end if
207
208 return $css;
209 }
210 public function get_content_timeline_icon_css( $attributes, $device = '' ) {
211 $css = [];
212 if ( ! empty( $attributes['iconColor'] ) ) {
213 $css['fill'] = $attributes['iconColor'];
214 }
215 return array_merge(
216 Range::get_css([
217 'attributeValue' => $attributes['iconSize'],
218 'attribute_object_key' => 'value',
219 'unitDefaultValue' => 'px',
220 'defaultValue' => 18,
221 'property' => 'width',
222 ]),
223 Range::get_css([
224 'attributeValue' => $attributes['iconSize'],
225 'attribute_object_key' => 'value',
226 'unitDefaultValue' => 'px',
227 'defaultValue' => 18,
228 'property' => 'height',
229 ]),
230 $css,
231 );
232 }
233
234 public function get_content_timeline_icon_background_css( $attributes, $device = '' ) {
235 $css = [];
236 if ( ! empty( $attributes['iconBackgroundColor'] ) ) {
237 $css['background-color'] = $attributes['iconBackgroundColor'];
238 }
239 return array_merge(
240 Range::get_css([
241 'attributeValue' => $attributes['iconBackgroundSize'],
242 'attribute_object_key' => 'value',
243 'defaultValue' => 48,
244 'property' => 'width',
245 ]),
246 Range::get_css([
247 'attributeValue' => $attributes['iconBackgroundSize'],
248 'attribute_object_key' => 'value',
249 'defaultValue' => 48,
250 'property' => 'height',
251 ]),
252 $css,
253 );
254 }
255
256 public function get_content_timeline_connector_css( $attributes, $device = '' ) {
257 $css = [];
258 if ( ! empty( $attributes['thicknessColor'] ) ) {
259 $css['background-color'] = $attributes['thicknessColor'];
260 }
261 return array_merge(
262 Range::get_css([
263 'attributeValue' => $attributes['thickness'],
264 'attribute_object_key' => 'value',
265 'defaultValue' => 3,
266 'property' => 'width',
267 ]),
268 $css,
269 );
270 }
271
272 public function get_content_timeline_item_gap_css( $attributes, $device = '' ) {
273 $css = [];
274 return array_merge(
275 Range::get_css([
276 'attributeValue' => $attributes['itemGap'],
277 'attribute_object_key' => 'value',
278 'defaultValue' => 10,
279 'isResponsive' => true,
280 'hasUnit' => true,
281 'unitDefaultValue' => 'px',
282 'property' => 'margin-top',
283 ]),
284 $css,
285 );
286 }
287
288 public function get_content_timeline_content_css( $attributes, $device = '' ) {
289 $css = [];
290 $css['padding'] = '15px';
291 if ( ! empty( $attributes['contentBackgroundColor'] ) ) {
292 $css['background-color'] = $attributes['contentBackgroundColor'];
293 }
294 return array_merge(
295 $css,
296 Dimensions::get_css( $attributes['contentPadding'] ?? [], 'padding', $device )
297 );
298 }
299
300 public function get_content_timeline_content_background_css( $attributes, $device = '' ) {
301 $css = [];
302 if ( ! empty( $attributes['contentBackgroundColor'] ) ) {
303 $css['border-left-color'] = $attributes['contentBackgroundColor'];
304 $css['border-right-color'] = $attributes['contentBackgroundColor'];
305 }
306 return $css;
307 }
308 public function get_content_timeline_arrow_css( $attributes, $device = '' ) {
309 $css = [];
310 $arrowAlignment = $attributes['arrowAlignment'] ?? '';
311 $iconBackgroundSize = $attributes['iconBackgroundSize'] ?? '';
312
313 if ( $arrowAlignment === 'top' ) {
314 $css['height'] = '0px';
315 $css['top'] = $iconBackgroundSize ? ( $iconBackgroundSize / 2 ) . 'px' : '0';
316 } elseif ( $arrowAlignment === 'bottom' ) {
317 $css['height'] = $iconBackgroundSize ? ( $iconBackgroundSize / 2 ) . 'px' : '0';
318 $css['bottom'] = '0';
319 }
320
321 return $css;
322 }
323 public function get_content_timeline_date_alignment_css( $attributes, $device = '' ) {
324 $css = [];
325
326 $arrowAlignment = $attributes['arrowAlignment'] ?? '';
327 $iconBackgroundSize = $attributes['iconBackgroundSize'] ?? '';
328
329 if ( $arrowAlignment === 'top' ) {
330 $css['margin-top'] = $iconBackgroundSize ? ( $iconBackgroundSize / 4 ) . 'px' : '0';
331 } elseif ( $arrowAlignment === 'bottom' ) {
332 $css['margin-bottom'] = $iconBackgroundSize ? ( $iconBackgroundSize / 4 ) . 'px' : '0';
333 }
334
335 return $css;
336 }
337
338 public function get_content_timeline_date_css( $attributes, $device = '' ) {
339 $css = [];
340 if ( ! empty( $attributes['dateColor'] ) ) {
341 $css['color'] = $attributes['dateColor'];
342 }
343 return array_merge(
344 $css,
345 Typography::get_css( $attributes['dateTypography'] ?? [], '', $device )
346 );
347 }
348 public function get_content_timeline_date_mobile_css( $attributes, $device = '' ) {
349 $css = [];
350 if ( ! empty( $attributes['dateAlign'] ) ) {
351 $css['text-align'] = $attributes['dateAlign'];
352 }
353 if ( ! empty( $attributes['dateBackground'] ) ) {
354 $css['background'] = $attributes['dateBackground'];
355 }
356 return array_merge(
357 $css,
358 Dimensions::get_css( $attributes['datePadding'] ?? [], 'padding', $device ),
359 Border::get_css( $attributes['dateBorder'] ?? [], '', $device )
360 );
361 }
362 public function get_content_timeline_date_hover_mobile_css( $attributes, $device = '' ) {
363 return array_merge(
364 Border::get_hover_css( $attributes['dateBorder'] ?? [], '', $device )
365 );
366 }
367 }
368