PluginProbe
Core Framework / 1.4.0
Core Framework v1.4.0
2.0.2 2.0.1 2.0.0 1.10.4 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.3.10 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.1.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.8.0 All 32 releases
core-framework / wp / Helper.php

Helper.php in Core Framework 1.4.0, at wp/Helper.php

1,239 lines 49.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace CoreFramework;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9
10 /**
11 * Core Framework Helper class
12 * Can be used to retrieve an array of class names and variables.
13 * Class names and variables can be grouped into categories.
14 *
15 * @since 1.2.7
16 */
17 class Helper {
18 private $preset = null;
19 private $stylesheet_data_keys = array(
20 'colorStyles',
21 'typographyStyles',
22 'spacingStyles',
23 'layoutsStyles',
24 'designStyles',
25 'componentsStyles',
26 'otherStyles',
27 );
28
29 public function __construct() {
30 }
31
32 /**
33 * Load selected preset from database
34 *
35 * @return array|null
36 */
37 private function loadPreset(): ?array {
38 if ( $this->preset ) {
39 return $this->preset;
40 }
41
42 $options = get_option( 'core_framework_main', array() );
43
44 if ( ! is_array( $options ) || ! isset( $options['selected_id'] ) || empty( $options ) ) {
45 return null;
46 }
47
48 global $wpdb;
49
50 $id = $options['selected_id'];
51 $table_name = $wpdb->prefix . 'core_framework_presets';
52 $row = $wpdb->get_row(
53 $wpdb->prepare( "SELECT * FROM $table_name WHERE id = %s", $id )
54 );
55
56 if ( ! $row ) {
57 return null;
58 }
59
60 $preset = json_decode( $row->data, true );
61 $this->preset = $preset;
62 return $preset;
63 }
64
65 public function getPreset() {
66 return $this->preset;
67 }
68
69 /**
70 * Get stylesheet plain stylesheet url
71 *
72 * @return string
73 * @since 1.3.3
74 */
75 public function getStylesheetUrl(): string {
76 if ( is_multisite() ) {
77 $blog_id = get_current_blog_id();
78 return \plugins_url( '/assets/public/css/core_framework_' . $blog_id . '.css', CORE_FRAMEWORK_ABSOLUTE );
79 }
80
81 return \plugins_url( '/assets/public/css/core_framework.css', CORE_FRAMEWORK_ABSOLUTE );
82 }
83
84 /**
85 * Get Stylesheet plain path
86 *
87 * @return string
88 * @since 1.3.3
89 */
90 public function getStylesheetPath(): string {
91 if ( is_multisite() ) {
92 $blog_id = get_current_blog_id();
93 return plugin_dir_path( CORE_FRAMEWORK_ABSOLUTE ) . '/assets/public/css/core_framework_' . $blog_id . '.css';
94 }
95
96 return plugin_dir_path( CORE_FRAMEWORK_ABSOLUTE ) . '/assets/public/css/core_framework.css';
97 }
98
99 /**
100 * Get stylesheet version
101 *
102 * @return string
103 * @since 1.3.3
104 */
105 public function getStylesheetVersion(): string {
106 if ( is_multisite() ) {
107 $blog_id = get_current_blog_id();
108 $version = \filemtime( plugin_dir_path( CORE_FRAMEWORK_ABSOLUTE ) . '/assets/public/css/core_framework_' . $blog_id . '.css' );
109 return $version ?? strval( time() );
110 }
111
112 if ( \file_exists( plugin_dir_path( CORE_FRAMEWORK_ABSOLUTE ) . '/assets/public/css/core_framework.css' ) ) {
113 $version = \filemtime( plugin_dir_path( CORE_FRAMEWORK_ABSOLUTE ) . '/assets/public/css/core_framework.css' );
114 }
115
116 return $version ?? strval( time() );
117 }
118
119 /**
120 * Extract all classNames from selector. Prefix first className with class_prefix.
121 *
122 * @param string $selector
123 * @param string $class_prefix
124 * @return array
125 * @since 1.2.7
126 */
127 private function extractClassNames( string $selector, string $class_prefix ): array {
128 if ( ! $selector || $selector === '.' ) {
129 return array();
130 }
131
132 $get_first_selector = function ( $selector ) {
133 $arr = explode( ',', $selector );
134 $arr = array_map(
135 function ( $s ) {
136 return trim( $s );
137 },
138 $arr
139 );
140 $arr = array_filter(
141 $arr,
142 function ( $s ) {
143 return ! empty( $s );
144 }
145 );
146 $arr = array_filter(
147 $arr,
148 function ( $s ) {
149 return $s !== '.';
150 }
151 );
152
153 return $arr[0];
154 };
155
156 $class_accumulator = array();
157
158 $selector = strpos( $selector, ',' ) !== false
159 ? $get_first_selector( $selector )
160 : trim( $selector );
161
162 if ( strpos( $selector, '.' ) === 0 && strpos( $selector, ':' ) === false ) {
163 $dots = substr_count( $selector, '.' );
164
165 if ( $dots && $dots > 1 ) {
166 $split = explode( '.', $selector );
167 $last = end( $split );
168
169 if ( $last ) {
170 $class_accumulator[] = $last;
171 }
172
173 return $class_accumulator;
174 }
175
176 $class_accumulator[] = str_replace( '.', '', $class_prefix . $selector );
177 }
178
179 return $class_accumulator;
180 }
181
182 /**
183 * Get all class names from project
184 *
185 * @param array $options
186 * - group_by_category: bool (default: true) - if true, returns array of grouped class names, otherwise returns flat array
187 * - excluded_keys: array of ['colorStyles', 'typographyStyles', 'spacingStyles', 'layoutsStyles', 'designStyles', 'componentsStyles', 'otherStyles']
188 * @return array
189 * @since 1.2.7
190 */
191 public function getClassNames(array $options = array(
192 'group_by_category' => true,
193 'excluded_keys' => array(),
194 )): array {
195 $options = \wp_parse_args(
196 $options,
197 array(
198 'group_by_category' => true,
199 'excluded_keys' => array(),
200 )
201 );
202
203 $preset = $this->loadPreset();
204
205 if ( ! $preset ) {
206 return array();
207 }
208
209 $class_prefix = isset( $preset['classPrefix'] ) ? $preset['classPrefix'] : '';
210
211 $grouped_class_names = array(
212 'colorStyles' => array(),
213 'typographyStyles' => array(),
214 'spacingStyles' => array(),
215 'layoutsStyles' => array(),
216 'designStyles' => array(),
217 'componentsStyles' => array(),
218 'otherStyles' => array(),
219 );
220
221 if ( isset( $preset['styleSheetData'] ) && is_array( $preset['styleSheetData'] ) ) {
222 foreach ( $this->stylesheet_data_keys as $key ) {
223 if ( isset( $preset['styleSheetData'][ $key ] ) && is_array( $preset['styleSheetData'][ $key ] ) ) {
224 foreach ( $preset['styleSheetData'][ $key ] as $group ) {
225 $is_variable_group = isset( $group['type'] ) && $group['type'] === 'variable';
226 $is_group_disabled = isset( $group['isDisabled'] ) && $group['isDisabled'] === true;
227
228 if ( $is_variable_group || $is_group_disabled ) {
229 continue;
230 }
231
232 if ( isset( $group['cssObjects'] ) && is_array( $group['cssObjects'] ) ) {
233 foreach ( $group['cssObjects'] as $cssObject ) {
234 $is_disabled = isset( $cssObject['isDisabled'] ) && $cssObject['isDisabled'] === true;
235
236 if ( $is_disabled ) {
237 continue;
238 }
239
240 $selector = isset( $cssObject['selector'] ) ? $cssObject['selector'] : '';
241 $grouped_class_names[ $key ] = array_merge(
242 $grouped_class_names[ $key ],
243 $this->extractClassNames( $selector, $class_prefix )
244 );
245 }
246 }
247 }
248 }
249 }
250 }
251
252 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COMPONENTS'] ) && isset( $preset['modulesData']['COMPONENTS']['components'] ) ) {
253 $is_disabled = isset( $preset['modulesData']['COMPONENTS']['isDisabled'] ) && $preset['modulesData']['COMPONENTS']['isDisabled'] === true;
254
255 if ( ! $is_disabled ) {
256 foreach ( $preset['modulesData']['COMPONENTS']['components'] as $component ) {
257 if ( strpos( $component['selector'], '.' ) === 0 ) {
258 $grouped_class_names['componentsStyles'] = array_merge(
259 $grouped_class_names['componentsStyles'],
260 $this->extractClassNames( $component['selector'], $class_prefix )
261 );
262
263 if ( isset( $component['variants'] ) ) {
264 foreach ( $component['variants'] as $variant ) {
265 if ( isset( $variant['variantSelector'] ) && strpos( $variant['variantSelector'], '.' ) === 0 ) {
266 $grouped_class_names['componentsStyles'] = array_merge(
267 $grouped_class_names['componentsStyles'],
268 $this->extractClassNames( $variant['variantSelector'], '' )
269 );
270 }
271 }
272 }
273 }
274 }
275 }
276 }
277
278 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_SPACING'] ) ) {
279 $spacing_data = $preset['modulesData']['FLUID_SPACING'];
280 $is_disabled = isset( $spacing_data['isDisabled'] ) && $spacing_data['isDisabled'] === true;
281 $is_manual_fluid_spacing = isset( $spacing_data['mode'] ) && $spacing_data['mode'] === 'fluid_manual';
282 $is_gen_padding = isset( $spacing_data['genPadding'] ) && $spacing_data['genPadding'] === true;
283 $is_gen_margin = isset( $spacing_data['genMargin'] ) && $spacing_data['genMargin'] === true;
284 $is_gen_gap = isset( $spacing_data['genGap'] ) && $spacing_data['genGap'] === true;
285 $generate_any_classes = $is_gen_padding || $is_gen_margin || $is_gen_gap;
286
287 $key = 'spacingStyles';
288
289 if ( $generate_any_classes ) {
290 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $spacing_data['manualSizes'] ) ) {
291 foreach ( $spacing_data['manualSizes'] as $manual_size ) {
292 $name = $manual_size['name'];
293 $get_suffix = function ( $name ) {
294 $parts = explode( '-', $name );
295 return end( $parts );
296 };
297 $suffix = $get_suffix( $name );
298
299 if ( $is_gen_gap ) {
300 $grouped_class_names[ $key ][] = $class_prefix . 'gap-' . $suffix;
301 $grouped_class_names[ $key ][] = $class_prefix . 'gap-horizontal-' . $suffix;
302 $grouped_class_names[ $key ][] = $class_prefix . 'gap-vertical-' . $suffix;
303 }
304
305 if ( $is_gen_padding ) {
306 $grouped_class_names[ $key ][] = $class_prefix . 'padding-' . $suffix;
307 $grouped_class_names[ $key ][] = $class_prefix . 'padding-horizontal-' . $suffix;
308 $grouped_class_names[ $key ][] = $class_prefix . 'padding-vertical-' . $suffix;
309 $grouped_class_names[ $key ][] = $class_prefix . 'padding-top-' . $suffix;
310 $grouped_class_names[ $key ][] = $class_prefix . 'padding-right-' . $suffix;
311 $grouped_class_names[ $key ][] = $class_prefix . 'padding-bottom-' . $suffix;
312 $grouped_class_names[ $key ][] = $class_prefix . 'padding-left-' . $suffix;
313 }
314
315 if ( $is_gen_margin ) {
316 $grouped_class_names[ $key ][] = $class_prefix . 'margin-' . $suffix;
317 $grouped_class_names[ $key ][] = $class_prefix . 'margin-horizontal-' . $suffix;
318 $grouped_class_names[ $key ][] = $class_prefix . 'margin-vertical-' . $suffix;
319 $grouped_class_names[ $key ][] = $class_prefix . 'margin-top-' . $suffix;
320 $grouped_class_names[ $key ][] = $class_prefix . 'margin-right-' . $suffix;
321 $grouped_class_names[ $key ][] = $class_prefix . 'margin-bottom-' . $suffix;
322 $grouped_class_names[ $key ][] = $class_prefix . 'margin-left-' . $suffix;
323 }
324 }
325 }
326
327 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $spacing_data['steps'] ) && isset( $spacing_data['namingConvention'] ) ) {
328 $steps = $spacing_data['steps'];
329 $steps = explode( ',', $steps );
330
331 foreach ( $steps as $step ) {
332 if ( $is_gen_gap ) {
333 $grouped_class_names[ $key ][] = $class_prefix . 'gap-' . $step;
334 $grouped_class_names[ $key ][] = $class_prefix . 'gap-horizontal-' . $step;
335 $grouped_class_names[ $key ][] = $class_prefix . 'gap-vertical-' . $step;
336 }
337
338 if ( $is_gen_padding ) {
339 $grouped_class_names[ $key ][] = $class_prefix . 'padding-' . $step;
340 $grouped_class_names[ $key ][] = $class_prefix . 'padding-horizontal-' . $step;
341 $grouped_class_names[ $key ][] = $class_prefix . 'padding-vertical-' . $step;
342 $grouped_class_names[ $key ][] = $class_prefix . 'padding-top-' . $step;
343 $grouped_class_names[ $key ][] = $class_prefix . 'padding-right-' . $step;
344 $grouped_class_names[ $key ][] = $class_prefix . 'padding-bottom-' . $step;
345 $grouped_class_names[ $key ][] = $class_prefix . 'padding-left-' . $step;
346 }
347
348 if ( $is_gen_margin ) {
349 $grouped_class_names[ $key ][] = $class_prefix . 'margin-' . $step;
350 $grouped_class_names[ $key ][] = $class_prefix . 'margin-horizontal-' . $step;
351 $grouped_class_names[ $key ][] = $class_prefix . 'margin-vertical-' . $step;
352 $grouped_class_names[ $key ][] = $class_prefix . 'margin-top-' . $step;
353 $grouped_class_names[ $key ][] = $class_prefix . 'margin-right-' . $step;
354 $grouped_class_names[ $key ][] = $class_prefix . 'margin-bottom-' . $step;
355 $grouped_class_names[ $key ][] = $class_prefix . 'margin-left-' . $step;
356 }
357 }
358 }
359 }
360 }
361
362 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_TYPOGRAPHY'] ) ) {
363 $typography_data = $preset['modulesData']['FLUID_TYPOGRAPHY'];
364 $is_disabled = isset( $typography_data['isDisabled'] ) && $typography_data['isDisabled'] === true;
365 $is_manual_fluid_spacing = isset( $typography_data['mode'] ) && $typography_data['mode'] === 'fluid_manual';
366 $is_gen_text_class = isset( $typography_data['genFontSizeClass'] ) && $typography_data['genFontSizeClass'] === true;
367 $key = 'typographyStyles';
368
369 if ( $is_gen_text_class ) {
370 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $typography_data['manualSizes'] ) ) {
371 foreach ( $typography_data['manualSizes'] as $manual_size ) {
372 $name = $manual_size['name'];
373 $get_suffix = function ( $name ) {
374 $parts = explode( '-', $name );
375 return end( $parts );
376 };
377 $suffix = $get_suffix( $name );
378 $naming_convention = $typography_data['namingConvention'];
379
380 $grouped_class_names[ $key ][] = $class_prefix . $naming_convention . '-' . str_replace( 'text-', '', $name );
381 }
382 }
383
384 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $typography_data['steps'] ) && isset( $typography_data['namingConvention'] ) ) {
385 $steps = $typography_data['steps'];
386 $steps = explode( ',', $steps );
387 $naming_convention = $typography_data['namingConvention'];
388
389 foreach ( $steps as $step ) {
390 $grouped_class_names[ $key ][] = $class_prefix . $naming_convention . '-' . str_replace( 'text-', '', $step );
391 }
392 }
393 }
394 }
395
396 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COLOR_SYSTEM'] ) && isset( $preset['modulesData']['COLOR_SYSTEM']['groups'] ) ) {
397 foreach ( $preset['modulesData']['COLOR_SYSTEM']['groups'] as $group ) {
398 if ( isset( $group['colors'] ) && is_array( $group['colors'] ) ) {
399 foreach ( $group['colors'] as $color ) {
400 $key = 'colorStyles';
401
402 $local_color_names = array();
403 $main_name = $color['name'];
404 $local_color_names[] = $main_name;
405
406 $shades = isset( $color['shades'] ) ? $color['shades'] : array();
407 foreach ( $shades as $shade ) {
408 $local_color_names[] = $shade['name'];
409 }
410
411 $tints = isset( $color['tints'] ) ? $color['tints'] : array();
412 foreach ( $tints as $tint ) {
413 $local_color_names[] = $tint['name'];
414 }
415
416 $process_name = function ( $name, $prefix ) {
417 if ( strpos( $name, $prefix ) === 0 ) {
418 $name = str_replace( $prefix, '', $name );
419 }
420
421 return $name;
422 };
423
424 $class_generation_array = isset( $color['gen'] ) ? $color['gen'] : array();
425 $is_gen_bg = in_array( 'bg', $class_generation_array );
426 $is_gen_text = in_array( 'text', $class_generation_array );
427 $is_gen_border = in_array( 'border', $class_generation_array );
428
429 $is_transparent = isset( $color['transparent'] ) && $color['transparent'] === true;
430 $transparent_variables = isset( $color['transparentVariables'] ) ? $color['transparentVariables'] : array();
431
432 foreach ( $local_color_names as $name ) {
433 if ( $is_gen_bg ) {
434 $prefix = 'bg-';
435 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
436
437 if ( $is_transparent ) {
438 foreach ( $transparent_variables as $transparent_value ) {
439 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
440 }
441 }
442 }
443
444 if ( $is_gen_text ) {
445 $prefix = 'text-';
446 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
447
448 if ( $is_transparent ) {
449 foreach ( $transparent_variables as $transparent_value ) {
450 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
451 }
452 }
453 }
454
455 if ( $is_gen_border ) {
456 $prefix = 'border-';
457 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
458
459 if ( $is_transparent ) {
460 foreach ( $transparent_variables as $transparent_value ) {
461 $grouped_class_names[ $key ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
462 }
463 }
464 }
465 }
466 }
467 }
468 }
469 }
470
471 $core_framework_main = \get_option( 'core_framework_main', array() );
472 $has_theme = isset( $core_framework_main['has_theme'] ) && $core_framework_main['has_theme'];
473 if ( $has_theme ) {
474 $grouped_class_names['otherStyles'][] = $class_prefix . 'theme-inverted';
475 }
476
477 if ( isset( $options['excluded_keys'] ) && is_array( $options['excluded_keys'] ) && ! empty( $options['excluded_keys'] ) ) {
478 foreach ( $options['excluded_keys'] as $excluded_key ) {
479 if ( isset( $grouped_class_names[ $excluded_key ] ) ) {
480 unset( $grouped_class_names[ $excluded_key ] );
481 }
482 }
483 }
484
485 foreach ( array_keys( $grouped_class_names ) as $key ) {
486 $grouped_class_names[ $key ] = array_values( array_unique( $grouped_class_names[ $key ] ) );
487 }
488
489 if ( $options['group_by_category'] === false ) {
490 $grouped_class_names = array_merge( ...array_values( $grouped_class_names ?? array() ) );
491 }
492
493 return $grouped_class_names;
494 }
495
496 /**
497 * @return array
498 * @since 1.2.7
499 */
500 public function getClassNamesGroupedByCategoriesAndGroups(): array {
501 $preset = $this->loadPreset();
502
503 if ( ! $preset ) {
504 return array();
505 }
506
507 $class_prefix = isset( $preset['classPrefix'] ) ? $preset['classPrefix'] : '';
508
509 $grouped_class_names = array(
510 'colorStyles' => array(),
511 'typographyStyles' => array(),
512 'spacingStyles' => array(),
513 'layoutsStyles' => array(),
514 'designStyles' => array(),
515 'componentsStyles' => array(),
516 'otherStyles' => array(),
517 );
518
519 if ( isset( $preset['styleSheetData'] ) && is_array( $preset['styleSheetData'] ) ) {
520 foreach ( $this->stylesheet_data_keys as $key ) {
521 if ( isset( $preset['styleSheetData'][ $key ] ) && is_array( $preset['styleSheetData'][ $key ] ) ) {
522 foreach ( $preset['styleSheetData'][ $key ] as $group ) {
523 $is_variable_group = isset( $group['type'] ) && $group['type'] === 'variable';
524 $is_group_disabled = isset( $group['isDisabled'] ) && $group['isDisabled'] === true;
525 $group_name = isset( $group['name'] ) ? $group['name'] : 'No name';
526
527 if ( $is_variable_group || $is_group_disabled ) {
528 continue;
529 }
530
531 if ( isset( $group['cssObjects'] ) && is_array( $group['cssObjects'] ) ) {
532 foreach ( $group['cssObjects'] as $cssObject ) {
533 $selector = isset( $cssObject['selector'] ) ? $cssObject['selector'] : '';
534 $grouped_class_names[ $key ][ $group_name ] = array_merge(
535 $grouped_class_names[ $key ][ $group_name ] ?? array(),
536 $this->extractClassNames( $selector, $class_prefix )
537 );
538 }
539 }
540 }
541 }
542 }
543 }
544
545 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COMPONENTS'] ) && isset( $preset['modulesData']['COMPONENTS']['components'] ) ) {
546 $is_disabled = isset( $preset['modulesData']['COMPONENTS']['isDisabled'] ) && $preset['modulesData']['COMPONENTS']['isDisabled'] === true;
547 $group_name = 'Components';
548
549 if ( ! $is_disabled ) {
550 foreach ( $preset['modulesData']['COMPONENTS']['components'] as $component ) {
551 if ( strpos( $component['selector'], '.' ) === 0 ) {
552 $grouped_class_names['componentsStyles'][ $group_name ] = array_merge(
553 $grouped_class_names['componentsStyles'][ $group_name ] ?? array(),
554 $this->extractClassNames( $component['selector'], $class_prefix )
555 );
556
557 if ( isset( $component['variants'] ) ) {
558 foreach ( $component['variants'] as $variant ) {
559 if ( isset( $variant['variantSelector'] ) && strpos( $variant['variantSelector'], '.' ) === 0 ) {
560 $grouped_class_names['componentsStyles'][ $group_name ] = array_merge(
561 $grouped_class_names['componentsStyles'][ $group_name ] ?? array(),
562 $this->extractClassNames( $variant['variantSelector'], $class_prefix )
563 );
564 }
565 }
566 }
567 }
568 }
569 }
570 }
571
572 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_SPACING'] ) ) {
573 $spacing_data = $preset['modulesData']['FLUID_SPACING'];
574 $is_disabled = isset( $spacing_data['isDisabled'] ) && $spacing_data['isDisabled'] === true;
575 $is_manual_fluid_spacing = isset( $spacing_data['mode'] ) && $spacing_data['mode'] === 'fluid_manual';
576 $is_gen_padding = isset( $spacing_data['genPadding'] ) && $spacing_data['genPadding'] === true;
577 $is_gen_margin = isset( $spacing_data['genMargin'] ) && $spacing_data['genMargin'] === true;
578 $is_gen_gap = isset( $spacing_data['genGap'] ) && $spacing_data['genGap'] === true;
579 $generate_any_classes = $is_gen_padding || $is_gen_margin || $is_gen_gap;
580
581 $key = 'spacingStyles';
582
583 if ( $generate_any_classes ) {
584 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $spacing_data['manualSizes'] ) ) {
585 foreach ( $spacing_data['manualSizes'] as $manual_size ) {
586 $name = $manual_size['name'];
587 $get_suffix = function ( $name ) {
588 $parts = explode( '-', $name );
589 return end( $parts );
590 };
591 $suffix = $get_suffix( $name );
592
593 if ( $is_gen_gap ) {
594 $group_name = 'Gaps';
595 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-' . $suffix;
596 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-horizontal-' . $suffix;
597 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-vertical-' . $suffix;
598 }
599
600 if ( $is_gen_padding ) {
601 $group_name = 'Paddings';
602 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-' . $suffix;
603 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-horizontal-' . $suffix;
604 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-vertical-' . $suffix;
605 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-top-' . $suffix;
606 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-right-' . $suffix;
607 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-bottom-' . $suffix;
608 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-left-' . $suffix;
609 }
610
611 if ( $is_gen_margin ) {
612 $group_name = 'Margins';
613 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-' . $suffix;
614 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-horizontal-' . $suffix;
615 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-vertical-' . $suffix;
616 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-top-' . $suffix;
617 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-right-' . $suffix;
618 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-bottom-' . $suffix;
619 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-left-' . $suffix;
620 }
621 }
622 }
623
624 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $spacing_data['steps'] ) && isset( $spacing_data['namingConvention'] ) ) {
625 $steps = $spacing_data['steps'];
626 $steps = explode( ',', $steps );
627
628 foreach ( $steps as $step ) {
629 if ( $is_gen_gap ) {
630 $group_name = 'Gaps';
631 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-' . $step;
632 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-horizontal-' . $step;
633 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'gap-vertical-' . $step;
634 }
635
636 if ( $is_gen_padding ) {
637 $group_name = 'Paddings';
638 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-' . $step;
639 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-horizontal-' . $step;
640 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-vertical-' . $step;
641 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-top-' . $step;
642 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-right-' . $step;
643 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-bottom-' . $step;
644 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'padding-left-' . $step;
645 }
646
647 if ( $is_gen_margin ) {
648 $group_name = 'Margins';
649 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-' . $step;
650 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-horizontal-' . $step;
651 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-vertical-' . $step;
652 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-top-' . $step;
653 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-right-' . $step;
654 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-bottom-' . $step;
655 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . 'margin-left-' . $step;
656 }
657 }
658 }
659 }
660 }
661
662 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_TYPOGRAPHY'] ) ) {
663 $typography_data = $preset['modulesData']['FLUID_TYPOGRAPHY'];
664 $is_disabled = isset( $typography_data['isDisabled'] ) && $typography_data['isDisabled'] === true;
665 $is_manual_fluid_spacing = isset( $typography_data['mode'] ) && $typography_data['mode'] === 'fluid_manual';
666 $is_gen_text_class = isset( $typography_data['genFontSizeClass'] ) && $typography_data['genFontSizeClass'] === true;
667 $key = 'typographyStyles';
668 $group_name = 'Fluid Typography';
669
670 if ( $is_gen_text_class ) {
671 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $typography_data['manualSizes'] ) ) {
672 foreach ( $typography_data['manualSizes'] as $manual_size ) {
673 $name = $manual_size['name'];
674 $get_suffix = function ( $name ) {
675 $parts = explode( '-', $name );
676 return end( $parts );
677 };
678 $suffix = $get_suffix( $name );
679 $naming_convention = $typography_data['namingConvention'];
680
681 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $naming_convention . '-' . str_replace( 'text-', '', $name );
682 }
683 }
684
685 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $typography_data['steps'] ) && isset( $typography_data['namingConvention'] ) ) {
686 $steps = $typography_data['steps'];
687 $steps = explode( ',', $steps );
688 $naming_convention = $typography_data['namingConvention'];
689
690 foreach ( $steps as $step ) {
691 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $naming_convention . '-' . str_replace( 'text-', '', $step );
692 }
693 }
694 }
695 }
696
697 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COLOR_SYSTEM'] ) && isset( $preset['modulesData']['COLOR_SYSTEM']['groups'] ) ) {
698 foreach ( $preset['modulesData']['COLOR_SYSTEM']['groups'] as $group ) {
699 if ( isset( $group['colors'] ) && is_array( $group['colors'] ) ) {
700 foreach ( $group['colors'] as $color ) {
701 $key = 'colorStyles';
702
703 $local_color_names = array();
704 $main_name = $color['name'];
705 $local_color_names[] = $main_name;
706
707 $shades = isset( $color['shades'] ) ? $color['shades'] : array();
708 foreach ( $shades as $shade ) {
709 $local_color_names[] = $shade['name'];
710 }
711
712 $tints = isset( $color['tints'] ) ? $color['tints'] : array();
713 foreach ( $tints as $tint ) {
714 $local_color_names[] = $tint['name'];
715 }
716
717 $process_name = function ( $name, $prefix ) {
718 if ( strpos( $name, $prefix ) === 0 ) {
719 $name = str_replace( $prefix, '', $name );
720 }
721
722 return $name;
723 };
724
725 $class_generation_array = isset( $color['gen'] ) ? $color['gen'] : array();
726 $is_gen_bg = in_array( 'bg', $class_generation_array );
727 $is_gen_text = in_array( 'text', $class_generation_array );
728 $is_gen_border = in_array( 'border', $class_generation_array );
729
730 $is_transparent = isset( $color['transparent'] ) && $color['transparent'] === true;
731 $transparent_variables = isset( $color['transparentVariables'] ) ? $color['transparentVariables'] : array();
732
733 foreach ( $local_color_names as $name ) {
734 if ( $is_gen_bg ) {
735 $prefix = 'bg-';
736 $group_name = 'Backgrounds';
737 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
738
739 if ( $is_transparent ) {
740 foreach ( $transparent_variables as $transparent_value ) {
741 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
742 }
743 }
744 }
745
746 if ( $is_gen_text ) {
747 $prefix = 'text-';
748 $group_name = 'Text Colors';
749 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
750
751 if ( $is_transparent ) {
752 foreach ( $transparent_variables as $transparent_value ) {
753 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
754 }
755 }
756 }
757
758 if ( $is_gen_border ) {
759 $prefix = 'border-';
760 $group_name = 'Border Colors';
761 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $process_name( $name, $prefix );
762
763 if ( $is_transparent ) {
764 foreach ( $transparent_variables as $transparent_value ) {
765 $grouped_class_names[ $key ][ $group_name ][] = $class_prefix . $prefix . $main_name . '-' . $transparent_value;
766 }
767 }
768 }
769 }
770 }
771 }
772 }
773 }
774
775 $core_framework_main = \get_option( 'core_framework_main', array() );
776 $has_theme = isset( $core_framework_main['has_theme'] ) && $core_framework_main['has_theme'];
777 if ( $has_theme ) {
778 $group_name = 'Theme';
779 $grouped_class_names['otherStyles'][ $group_name ][] = $class_prefix . 'theme-inverted';
780 }
781
782 foreach ( array_keys( $grouped_class_names ) as $key ) {
783 foreach ( array_keys( $grouped_class_names[ $key ] ) as $key2 ) {
784 $grouped_class_names[ $key ][ $key2 ] = array_values( array_unique( $grouped_class_names[ $key ][ $key2 ] ) );
785 if ( empty( $grouped_class_names[ $key ][ $key2 ] ) ) {
786 unset( $grouped_class_names[ $key ][ $key2 ] );
787 }
788 }
789 }
790
791 return $grouped_class_names;
792 }
793
794 /**
795 * @param array $options
796 * - group_by_category: bool (default: true) - if true, returns array of grouped variables, otherwise returns flat array
797 * - excluded_keys: array of ['colorStyles', 'typographyStyles', 'spacingStyles', 'layoutsStyles', 'designStyles', 'componentsStyles', 'otherStyles']
798 * @return array
799 * @since 1.2.7
800 */
801 public function getVariables(array $options = array(
802 'group_by_category' => true,
803 'excluded_keys' => array(),
804 )): array {
805 $options = \wp_parse_args(
806 $options,
807 array(
808 'group_by_category' => true,
809 'excluded_keys' => array(),
810 )
811 );
812
813 $preset = $this->loadPreset();
814
815 if ( ! $preset ) {
816 return array();
817 }
818
819 $variable_prefix = isset( $preset['variablePrefix'] ) ? $preset['variablePrefix'] : '';
820
821 $grouped_variables = array(
822 'colorStyles' => array(),
823 'typographyStyles' => array(),
824 'spacingStyles' => array(),
825 'layoutsStyles' => array(),
826 'designStyles' => array(),
827 'componentsStyles' => array(),
828 'otherStyles' => array(),
829 );
830
831 if ( isset( $preset['styleSheetData'] ) && is_array( $preset['styleSheetData'] ) ) {
832 foreach ( $this->stylesheet_data_keys as $key ) {
833 if ( isset( $preset['styleSheetData'][ $key ] ) && is_array( $preset['styleSheetData'][ $key ] ) ) {
834 $stylesheet_category = $preset['styleSheetData'][ $key ];
835
836 foreach ( $stylesheet_category as $group ) {
837 $is_variable_group = isset( $group['type'] ) && $group['type'] === 'variable';
838 $is_group_disabled = isset( $group['isDisabled'] ) && $group['isDisabled'] === true;
839
840 if ( ! $is_variable_group || $is_group_disabled ) {
841 continue;
842 }
843
844 if ( isset( $group['cssObjects'] ) && is_array( $group['cssObjects'] ) ) {
845 foreach ( $group['cssObjects'] as $cssObject ) {
846 $is_disabled = isset( $cssObject['isDisabled'] ) && $cssObject['isDisabled'] === true;
847
848 if ( $is_disabled ) {
849 continue;
850 }
851
852 $declarations = isset( $cssObject['declarations'] ) ? $cssObject['declarations'] : array();
853
854 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
855 continue;
856 }
857
858 foreach ( $declarations as $declaration ) {
859 $property = $declaration['property'];
860 $grouped_variables[ $key ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
861 }
862 }
863 }
864 }
865 }
866 }
867 }
868
869 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_SPACING'] ) ) {
870 $key = 'spacingStyles';
871
872 $spacing_data = $preset['modulesData']['FLUID_SPACING'];
873 $is_disabled = isset( $spacing_data['isDisabled'] ) && $spacing_data['isDisabled'] === true;
874 $is_manual_fluid_spacing = isset( $spacing_data['mode'] ) && $spacing_data['mode'] === 'fluid_manual';
875 $is_gen_semantic_variables = isset( $spacing_data['genSemanticVariables'] ) && $spacing_data['genSemanticVariables'] === true;
876
877 if ( $is_gen_semantic_variables ) {
878 $sematic_variables_css_object_array = isset( $spacing_data['semanticVariables'] ) ? $spacing_data['semanticVariables'] : array();
879
880 foreach ( $sematic_variables_css_object_array as $css_object ) {
881 $declarations = isset( $css_object['declarations'] ) ? $css_object['declarations'] : array();
882
883 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
884 continue;
885 }
886
887 foreach ( $declarations as $declaration ) {
888 $property = $declaration['property'];
889 $grouped_variables[ $key ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
890 }
891 }
892 }
893
894 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $spacing_data['manualSizes'] ) ) {
895 $manual_sizes = $spacing_data['manualSizes'];
896
897 foreach ( $manual_sizes as $manual_size ) {
898 $grouped_variables[ $key ][] = $variable_prefix . $manual_size['name'];
899 }
900 }
901
902 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $spacing_data['steps'] ) && isset( $spacing_data['namingConvention'] ) ) {
903 $steps = $spacing_data['steps'];
904 $steps = explode( ',', $steps );
905 $naming_convention = $spacing_data['namingConvention'];
906
907 foreach ( $steps as $step ) {
908 $grouped_variables[ $key ][] = $variable_prefix . $naming_convention . '-' . $step;
909 }
910 }
911 }
912
913 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_TYPOGRAPHY'] ) ) {
914 $key = 'typographyStyles';
915
916 $typography_data = $preset['modulesData']['FLUID_TYPOGRAPHY'];
917 $is_disabled = isset( $typography_data['isDisabled'] ) && $typography_data['isDisabled'] === true;
918 $is_manual_fluid_spacing = isset( $typography_data['mode'] ) && $typography_data['mode'] === 'fluid_manual';
919 $is_gen_semantic_variables = isset( $typography_data['genSemanticVariables'] ) && $typography_data['genSemanticVariables'] === true;
920
921 if ( $is_gen_semantic_variables ) {
922 $sematic_variables_css_object_array = isset( $typography_data['semanticVariables'] ) ? $typography_data['semanticVariables'] : array();
923
924 foreach ( $sematic_variables_css_object_array as $css_object ) {
925 $declarations = isset( $css_object['declarations'] ) ? $css_object['declarations'] : array();
926
927 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
928 continue;
929 }
930
931 foreach ( $declarations as $declaration ) {
932 $property = $declaration['property'];
933 $grouped_variables[ $key ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
934 }
935 }
936 }
937
938 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $typography_data['manualSizes'] ) ) {
939 $manual_sizes = $typography_data['manualSizes'];
940
941 foreach ( $manual_sizes as $manual_size ) {
942 $grouped_variables[ $key ][] = $variable_prefix . $manual_size['name'];
943 }
944 }
945
946 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $typography_data['steps'] ) && isset( $typography_data['namingConvention'] ) ) {
947 $steps = $typography_data['steps'];
948 $steps = explode( ',', $steps );
949 $naming_convention = $typography_data['namingConvention'];
950
951 foreach ( $steps as $step ) {
952 $grouped_variables[ $key ][] = $variable_prefix . $naming_convention . '-' . $step;
953 }
954 }
955 }
956
957 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COLOR_SYSTEM'] ) && isset( $preset['modulesData']['COLOR_SYSTEM']['groups'] ) ) {
958 foreach ( $preset['modulesData']['COLOR_SYSTEM']['groups'] as $group ) {
959 if ( isset( $group['colors'] ) && is_array( $group['colors'] ) ) {
960 foreach ( $group['colors'] as $color ) {
961 $name = $color['name'];
962 $grouped_variables['colorStyles'][] = $variable_prefix . $name;
963
964 $shades = isset( $color['shades'] ) ? $color['shades'] : array();
965 foreach ( $shades as $shade ) {
966 $grouped_variables['colorStyles'][] = $variable_prefix . $shade['name'];
967 }
968
969 $tints = isset( $color['tints'] ) ? $color['tints'] : array();
970 foreach ( $tints as $tint ) {
971 $grouped_variables['colorStyles'][] = $variable_prefix . $tint['name'];
972 }
973
974 $is_transparent = isset( $color['transparent'] ) && $color['transparent'] === true;
975 $transparent_variables = isset( $color['transparentVariables'] ) ? $color['transparentVariables'] : array();
976
977 if ( $is_transparent ) {
978 foreach ( $transparent_variables as $transparent_variable ) {
979 $grouped_variables['colorStyles'][] = $variable_prefix . $name . '-' . $transparent_variable;
980 }
981 }
982 }
983 }
984 }
985 }
986
987 foreach ( array_keys( $grouped_variables ) as $key ) {
988 $grouped_variables[ $key ] = array_unique( $grouped_variables[ $key ] );
989 }
990
991 if ( isset( $options['excluded_keys'] ) && is_array( $options['excluded_keys'] ) && ! empty( $options['excluded_keys'] ) ) {
992 foreach ( $options['excluded_keys'] as $excluded_key ) {
993 if ( isset( $grouped_variables[ $excluded_key ] ) ) {
994 unset( $grouped_variables[ $excluded_key ] );
995 }
996 }
997 }
998
999 if ( $options['group_by_category'] === false ) {
1000 $grouped_variables = array_merge( ...array_values( $grouped_variables ?? array() ) );
1001 }
1002
1003 return $grouped_variables ?? array();
1004 }
1005
1006 public function getVariablesGroupedByCategoriesAndGroups(array $options = array(
1007 'group_by_category' => true,
1008 'excluded_keys' => array(),
1009 'exclude_color_system_variables' => false,
1010 )): array {
1011 $options = \wp_parse_args(
1012 $options,
1013 array(
1014 'group_by_category' => true,
1015 'excluded_keys' => array(),
1016 'exclude_color_system_variables' => false,
1017 )
1018 );
1019
1020 $preset = $this->loadPreset();
1021
1022 if ( ! $preset ) {
1023 return array();
1024 }
1025
1026 $variable_prefix = isset( $preset['variablePrefix'] ) ? $preset['variablePrefix'] : '';
1027
1028 $grouped_variables = array(
1029 'colorStyles' => array(),
1030 'typographyStyles' => array(),
1031 'spacingStyles' => array(),
1032 'layoutsStyles' => array(),
1033 'designStyles' => array(),
1034 'componentsStyles' => array(),
1035 'otherStyles' => array(),
1036 );
1037
1038 $protected_group_names = array( 'Fluid Layouts', 'Fluid Typography', 'Fluid Spacing', 'Color System', 'Components' );
1039
1040 if ( isset( $preset['styleSheetData'] ) && is_array( $preset['styleSheetData'] ) ) {
1041 foreach ( $this->stylesheet_data_keys as $key ) {
1042 if ( isset( $preset['styleSheetData'][ $key ] ) && is_array( $preset['styleSheetData'][ $key ] ) ) {
1043 $stylesheet_category = $preset['styleSheetData'][ $key ];
1044
1045 $i = 1;
1046
1047 foreach ( $stylesheet_category as $group ) {
1048 ++$i;
1049 $is_variable_group = isset( $group['type'] ) && $group['type'] === 'variable';
1050 $is_group_disabled = isset( $group['isDisabled'] ) && $group['isDisabled'] === true;
1051
1052 $group_name = isset( $group['name'] ) ? $group['name'] : 'No name';
1053
1054 if ( array_search( $group_name, $protected_group_names ) !== false ) {
1055 $group_name = $group_name . ' (' . $i . ')';
1056 }
1057
1058 if ( ! $is_variable_group || $is_group_disabled ) {
1059 continue;
1060 }
1061
1062 if ( isset( $group['cssObjects'] ) && is_array( $group['cssObjects'] ) ) {
1063 foreach ( $group['cssObjects'] as $cssObject ) {
1064 $is_disabled = isset( $cssObject['isDisabled'] ) && $cssObject['isDisabled'] === true;
1065
1066 if ( $is_disabled ) {
1067 continue;
1068 }
1069
1070 $declarations = isset( $cssObject['declarations'] ) ? $cssObject['declarations'] : array();
1071
1072 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
1073 continue;
1074 }
1075
1076 foreach ( $declarations as $declaration ) {
1077 $property = $declaration['property'];
1078 $grouped_variables[ $key ][ $group_name ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
1079 }
1080 }
1081 }
1082 }
1083 }
1084 }
1085 }
1086
1087 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_SPACING'] ) ) {
1088 $key = 'spacingStyles';
1089 $group_name = 'Fluid Spacing';
1090
1091 $spacing_data = $preset['modulesData']['FLUID_SPACING'];
1092 $is_disabled = isset( $spacing_data['isDisabled'] ) && $spacing_data['isDisabled'] === true;
1093 $is_manual_fluid_spacing = isset( $spacing_data['mode'] ) && $spacing_data['mode'] === 'fluid_manual';
1094 $is_gen_semantic_variables = isset( $spacing_data['genSemanticVariables'] ) && $spacing_data['genSemanticVariables'] === true;
1095
1096 if ( $is_gen_semantic_variables ) {
1097 $sematic_variables_group_name = 'Contextual Spacing Variables';
1098 $sematic_variables_css_object_array = isset( $spacing_data['semanticVariables'] ) ? $spacing_data['semanticVariables'] : array();
1099
1100 foreach ( $sematic_variables_css_object_array as $css_object ) {
1101 $declarations = isset( $css_object['declarations'] ) ? $css_object['declarations'] : array();
1102
1103 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
1104 continue;
1105 }
1106
1107 foreach ( $declarations as $declaration ) {
1108 $property = $declaration['property'];
1109 $grouped_variables[ $key ][ $sematic_variables_group_name ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
1110 }
1111 }
1112 }
1113
1114 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $spacing_data['manualSizes'] ) ) {
1115 $manual_sizes = $spacing_data['manualSizes'];
1116 foreach ( $manual_sizes as $manual_size ) {
1117 $grouped_variables[ $key ][ $group_name ][] = $variable_prefix . $manual_size['name'];
1118 }
1119 }
1120
1121 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $spacing_data['steps'] ) && isset( $spacing_data['namingConvention'] ) ) {
1122 $steps = $spacing_data['steps'];
1123 $steps = explode( ',', $steps );
1124 $naming_convention = $spacing_data['namingConvention'];
1125
1126 foreach ( $steps as $step ) {
1127 $grouped_variables[ $key ][ $group_name ][] = $variable_prefix . $naming_convention . '-' . $step;
1128 }
1129 }
1130 }
1131
1132 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['FLUID_TYPOGRAPHY'] ) ) {
1133 $key = 'typographyStyles';
1134 $group_name = 'Fluid Typography';
1135
1136 $typography_data = $preset['modulesData']['FLUID_TYPOGRAPHY'];
1137 $is_disabled = isset( $typography_data['isDisabled'] ) && $typography_data['isDisabled'] === true;
1138 $is_manual_fluid_spacing = isset( $typography_data['mode'] ) && $typography_data['mode'] === 'fluid_manual';
1139 $is_gen_semantic_variables = isset( $typography_data['genSemanticVariables'] ) && $typography_data['genSemanticVariables'] === true;
1140
1141 if ( $is_gen_semantic_variables ) {
1142 $sematic_variables_group_name = 'Contextual Typography Variables';
1143 $sematic_variables_css_object_array = isset( $typography_data['semanticVariables'] ) ? $typography_data['semanticVariables'] : array();
1144
1145 foreach ( $sematic_variables_css_object_array as $css_object ) {
1146 $declarations = isset( $css_object['declarations'] ) ? $css_object['declarations'] : array();
1147
1148 if ( ! is_array( $declarations ) || empty( $declarations ) ) {
1149 continue;
1150 }
1151
1152 foreach ( $declarations as $declaration ) {
1153 $property = $declaration['property'];
1154 $grouped_variables[ $key ][ $sematic_variables_group_name ][] = $variable_prefix . CoreFramework()->str_replace_first( '--', '', $property );
1155 }
1156 }
1157 }
1158
1159 if ( ! $is_disabled && $is_manual_fluid_spacing && isset( $typography_data['manualSizes'] ) ) {
1160 $manual_sizes = $typography_data['manualSizes'];
1161
1162 foreach ( $manual_sizes as $manual_size ) {
1163 $grouped_variables[ $key ][ $group_name ][] = $variable_prefix . $manual_size['name'];
1164 }
1165 }
1166
1167 if ( ! $is_disabled && ! $is_manual_fluid_spacing && isset( $typography_data['steps'] ) && isset( $typography_data['namingConvention'] ) ) {
1168 $steps = $typography_data['steps'];
1169 $steps = explode( ',', $steps );
1170 $naming_convention = $typography_data['namingConvention'];
1171
1172 foreach ( $steps as $step ) {
1173 $grouped_variables[ $key ][ $group_name ][] = $variable_prefix . $naming_convention . '-' . $step;
1174 }
1175 }
1176 }
1177
1178 if ( $options['exclude_color_system_variables'] === false ) {
1179 if ( isset( $preset['modulesData'] ) && isset( $preset['modulesData']['COLOR_SYSTEM'] ) && isset( $preset['modulesData']['COLOR_SYSTEM']['groups'] ) ) {
1180 foreach ( $preset['modulesData']['COLOR_SYSTEM']['groups'] as $group ) {
1181 if ( isset( $group['colors'] ) && is_array( $group['colors'] ) ) {
1182 $group_name = isset( $group['name'] ) ? $group['name'] : 'No name';
1183 foreach ( $group['colors'] as $color ) {
1184 $name = $color['name'];
1185 $grouped_variables['colorStyles'][ $group_name ][] = $variable_prefix . $name;
1186
1187 $shades = isset( $color['shades'] ) ? $color['shades'] : array();
1188 foreach ( $shades as $shade ) {
1189 $grouped_variables['colorStyles'][ $group_name ][] = $variable_prefix . $shade['name'];
1190 }
1191
1192 $tints = isset( $color['tints'] ) ? $color['tints'] : array();
1193 foreach ( $tints as $tint ) {
1194 $grouped_variables['colorStyles'][ $group_name ][] = $variable_prefix . $tint['name'];
1195 }
1196
1197 $is_transparent = isset( $color['transparent'] ) && $color['transparent'] === true;
1198 $transparent_variables = isset( $color['transparentVariables'] ) ? $color['transparentVariables'] : array();
1199
1200 if ( $is_transparent ) {
1201 foreach ( $transparent_variables as $transparent_variable ) {
1202 $grouped_variables['colorStyles'][ $group_name ][] = $variable_prefix . $name . '-' . $transparent_variable;
1203 }
1204 }
1205 }
1206 }
1207 }
1208 }
1209 }
1210
1211 if ( isset( $options['excluded_keys'] ) && is_array( $options['excluded_keys'] ) && ! empty( $options['excluded_keys'] ) ) {
1212 foreach ( $options['excluded_keys'] as $excluded_key ) {
1213 if ( isset( $grouped_variables[ $excluded_key ] ) ) {
1214 unset( $grouped_variables[ $excluded_key ] );
1215 }
1216 }
1217 }
1218
1219 if ( $options['group_by_category'] === false ) {
1220 $grouped_variables = array_merge( ...array_values( $grouped_variables ?? array() ) );
1221 }
1222
1223 return $grouped_variables ?? array();
1224 }
1225
1226 public function getVariableString(): string {
1227 $cssString = get_option( 'core_framework_selected_preset_backup', '' );
1228
1229 if ( ! $cssString ) {
1230 return '';
1231 }
1232
1233 $pattern = '/(:root[^{]*\{[^}]*--[^}]*\})/s';
1234 preg_match_all( $pattern, $cssString, $matches );
1235
1236 return implode( "\n\n", $matches[0] );
1237 }
1238 }
1239