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