| 1 |
<?php |
| 2 |
namespace ABlocks\Classes; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocks\Controls\Dimensions; |
| 9 |
use ABlocks\Controls\Width; |
| 10 |
use ABlocks\Controls\Border; |
| 11 |
use ABlocks\Controls\Position; |
| 12 |
use ABlocks\Controls\Background; |
| 13 |
use ABlocks\Controls\Zindex; |
| 14 |
use ABlocks\Controls\Transform; |
| 15 |
use ABlocks\Controls\Mask; |
| 16 |
use ABlocks\Controls\Animation; |
| 17 |
use ABlocks\Controls\BoxShadow; |
| 18 |
use ABlocks\Helper; |
| 19 |
|
| 20 |
class BlockGlobal { |
| 21 |
public static function get_attributes() { |
| 22 |
$attributes = [ |
| 23 |
'_hide_on_desktop' => [ |
| 24 |
'type' => 'boolean', |
| 25 |
'default' => false, |
| 26 |
], |
| 27 |
'_hide_on_tablet' => [ |
| 28 |
'type' => 'boolean', |
| 29 |
'default' => false, |
| 30 |
], |
| 31 |
'_hide_on_mobile' => [ |
| 32 |
'type' => 'boolean', |
| 33 |
'default' => false, |
| 34 |
], |
| 35 |
'_custom_css' => [ |
| 36 |
'type' => 'string', |
| 37 |
'default' => '', |
| 38 |
] |
| 39 |
]; |
| 40 |
$attributes = array_merge( |
| 41 |
Dimensions::get_attribute( '_margin', true ), |
| 42 |
Dimensions::get_attribute( '_padding', true ), |
| 43 |
Width::get_attribute( '_width', true ), |
| 44 |
Border::get_attribute( '_border', true ), |
| 45 |
Position::get_attribute( '_position', true ), |
| 46 |
Background::get_attribute( '_background', true ), |
| 47 |
Zindex::get_attribute( '_zIndex', true ), |
| 48 |
Transform::get_attribute( '_transform', true ), |
| 49 |
Mask::get_attribute( '_mask', true ), |
| 50 |
Animation::get_attribute( '_animation', true ), |
| 51 |
BoxShadow::get_attribute( '_boxShadow', true ), |
| 52 |
Transform::get_attribute( '_transform', true ), |
| 53 |
$attributes, |
| 54 |
); |
| 55 |
return apply_filters( 'ablocks/get_block_common_attributes', $attributes ); |
| 56 |
} |
| 57 |
public static function get_wrapper_css( $attribute, $device = '' ) { |
| 58 |
$transitions = []; |
| 59 |
$transition_types = [ |
| 60 |
'_border' => 'border', |
| 61 |
'_background' => 'background', |
| 62 |
'_boxShadow' => 'box-shadow', |
| 63 |
]; |
| 64 |
foreach ( $transition_types as $key => $property ) { |
| 65 |
if ( isset( $attribute[ $key ] ) ) { |
| 66 |
$duration = ! empty( $attribute[ $key ]['transitionDuration'] ) ? $attribute[ $key ]['transitionDuration'] : '0'; |
| 67 |
$transitions[] = "{$property} {$duration}s ease"; |
| 68 |
} |
| 69 |
} |
| 70 |
$transition_string = implode( ',', $transitions ); |
| 71 |
|
| 72 |
$css = array_merge( |
| 73 |
Dimensions::get_css( $attribute['_margin'], 'margin', $device ), |
| 74 |
Dimensions::get_css( $attribute['_padding'], 'padding', $device ), |
| 75 |
Mask::get_css( $attribute['_mask'], $device ), |
| 76 |
Background::get_css( $attribute['_background'], 'background', $device ), |
| 77 |
Border::get_css( $attribute['_border'], '', $device ), |
| 78 |
Width::get_css( $attribute['_width'], 'width', $device ), |
| 79 |
BoxShadow::get_css( $attribute['_boxShadow'], $device ), |
| 80 |
Position::get_css( $attribute['_position'], 'position', $device ), |
| 81 |
Zindex::get_css( $attribute['_zIndex'], 'z-index', $device ), |
| 82 |
[ 'transition' => $transition_string ] |
| 83 |
); |
| 84 |
return apply_filters( 'ablocks/get_block_common_wrapper_css', $css, $attribute, $device ); |
| 85 |
} |
| 86 |
public static function get_wrapper_hover_css( $attribute, $device = '' ) { |
| 87 |
$css = array_merge( |
| 88 |
Background::get_hover_css( $attribute['_background'], 'background', $device ), |
| 89 |
Border::get_hover_css( $attribute['_border'], '', $device ), |
| 90 |
BoxShadow::get_hover_css( $attribute['_boxShadow'], '', $device ), |
| 91 |
); |
| 92 |
return apply_filters( 'ablocks/get_block_common_wrapper_hover_css', $css, $attribute, $device ); |
| 93 |
} |
| 94 |
public static function get_container_css( $attribute, $device = '' ) { |
| 95 |
$css = array_merge( |
| 96 |
Transform::get_css( $attribute['_transform'], 'transform', $device ), |
| 97 |
); |
| 98 |
return apply_filters( 'ablocks/get_block_common_container_css', $css, $attribute, $device ); |
| 99 |
} |
| 100 |
public static function get_container_hover_css( $attribute, $device = '' ) { |
| 101 |
$css = array_merge( |
| 102 |
Transform::get_hover_css( $attribute['_transform'], 'transform', $device ), |
| 103 |
); |
| 104 |
return apply_filters( 'ablocks/get_block_common_container_hover_css', $css, $attribute, $device ); |
| 105 |
} |
| 106 |
public static function get_wrapper_device_responsive_css( $attribute, $device = '' ) { |
| 107 |
if ( ! isset( $attribute['_hide_on_desktop'] ) && ! isset( $attribute['_hide_on_tablet'] ) && ! isset( $attribute['_hide_on_mobile'] ) ) { |
| 108 |
return []; |
| 109 |
} |
| 110 |
|
| 111 |
if ( ! $device && Helper::has_value( $attribute['_hide_on_desktop'] ) ) { |
| 112 |
return [ |
| 113 |
'display' => 'none' |
| 114 |
]; |
| 115 |
} |
| 116 |
|
| 117 |
if ( 'Tablet' === $device && Helper::has_value( $attribute['_hide_on_tablet'] ) ) { |
| 118 |
return [ |
| 119 |
'display' => 'none' |
| 120 |
]; |
| 121 |
} |
| 122 |
if ( 'Mobile' === $device && Helper::has_value( $attribute['_hide_on_mobile'] ) ) { |
| 123 |
return [ |
| 124 |
'display' => 'none' |
| 125 |
]; |
| 126 |
} |
| 127 |
|
| 128 |
return [ |
| 129 |
'display' => 'inherit' |
| 130 |
]; |
| 131 |
} |
| 132 |
} |
| 133 |
|