| 1 |
<?php |
| 2 |
namespace VBB; |
| 3 |
|
| 4 |
class GetCSS{ |
| 5 |
static function isValidCSS($property, $value) { |
| 6 |
if ( empty( $value ) && $value !== '0' && $value !== 0 ) { |
| 7 |
return ''; |
| 8 |
} |
| 9 |
return "$property: $value;"; |
| 10 |
} |
| 11 |
|
| 12 |
static function getBackgroundCSS( $bg, $isSolid = true, $isGradient = true, $isImage = true ) { |
| 13 |
extract( $bg ); |
| 14 |
$type = $type ?? 'solid'; |
| 15 |
$color = $color ?? '#000000b3'; |
| 16 |
$gradient = $gradient ?? 'linear-gradient(135deg, #0040E3, #18D4FD)'; |
| 17 |
$image = $image ?? []; |
| 18 |
$position = $position ?? 'center center'; |
| 19 |
$attachment = $attachment ?? ''; |
| 20 |
$repeat = $repeat ?? ''; |
| 21 |
$size = $size ?? ''; |
| 22 |
$overlayColor = $overlayColor ?? ''; |
| 23 |
|
| 24 |
if ( 'gradient' === $type && $isGradient ) { |
| 25 |
$styles = self::isValidCSS('background', $gradient); |
| 26 |
} elseif ( 'image' === $type && $isImage ) { |
| 27 |
$imgUrl = $image['url'] ?? ''; |
| 28 |
$styles = "background: url($imgUrl);" |
| 29 |
. self::isValidCSS('background-color', $overlayColor) |
| 30 |
. self::isValidCSS('background-position', $position) |
| 31 |
. self::isValidCSS('background-size', $size) |
| 32 |
. self::isValidCSS('background-repeat', $repeat) |
| 33 |
. self::isValidCSS('background-attachment', $attachment) |
| 34 |
. "background-blend-mode: overlay;"; |
| 35 |
} else { |
| 36 |
$styles = $isSolid ? self::isValidCSS('background', $color) : ''; |
| 37 |
} |
| 38 |
|
| 39 |
return $styles; |
| 40 |
} |
| 41 |
|
| 42 |
static function getSpaceCSS( $space ) { |
| 43 |
extract( $space ); |
| 44 |
$side = $side ?? 2; |
| 45 |
$vertical = $vertical ?? '0px'; |
| 46 |
$horizontal = $horizontal ?? '0px'; |
| 47 |
$top = $top ?? '0px'; |
| 48 |
$right = $right ?? '0px'; |
| 49 |
$bottom = $bottom ?? '0px'; |
| 50 |
$left = $left ?? '0px'; |
| 51 |
|
| 52 |
$styles = ( 2 === $side ) ? "$vertical $horizontal" : "$top $right $bottom $left"; |
| 53 |
|
| 54 |
return $styles; |
| 55 |
} |
| 56 |
} |