| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\Divider; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use ABlocks\Classes\BlockBaseAbstract; |
| 10 |
use ABlocks\Classes\CssGenerator; |
| 11 |
use ABlocks\Controls\Alignment; |
| 12 |
use ABlocks\Controls\TextStroke; |
| 13 |
use ABlocks\Controls\Typography; |
| 14 |
use ABlocks\Controls\Icon; |
| 15 |
use ABlocks\Controls\Range; |
| 16 |
use ABlocks\Classes\CssGeneratorV2; |
| 17 |
use ABlocks\Controls\Color; |
| 18 |
class Block extends BlockBaseAbstract { |
| 19 |
|
| 20 |
protected $block_name = 'divider'; |
| 21 |
|
| 22 |
public function build_css_v1( $attributes ) { |
| 23 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 24 |
$css_generator->add_class_styles( |
| 25 |
'{{WRAPPER}}', |
| 26 |
$this->get_wrapper_css( $attributes ), |
| 27 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 28 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 29 |
); |
| 30 |
|
| 31 |
$css_generator->add_class_styles( |
| 32 |
'{{WRAPPER}} .ablocks-block-container', |
| 33 |
$this->get_divider_container_css( $attributes ), |
| 34 |
$this->get_divider_container_css( $attributes, 'Tablet' ), |
| 35 |
$this->get_divider_container_css( $attributes, 'Mobile' ), |
| 36 |
); |
| 37 |
|
| 38 |
$css_generator->add_class_styles( |
| 39 |
'{{WRAPPER}} .ablocks-divider', |
| 40 |
$this->get_divider_css( $attributes ), |
| 41 |
$this->get_divider_css( $attributes, 'Tablet' ), |
| 42 |
$this->get_divider_css( $attributes, 'Mobile' ), |
| 43 |
); |
| 44 |
// element text |
| 45 |
|
| 46 |
$css_generator->add_class_styles( |
| 47 |
'{{WRAPPER}} .ablocks-divider__element-text', |
| 48 |
$this->get_divider_element_text_css( $attributes ), |
| 49 |
$this->get_divider_element_text_css( $attributes, 'Tablet' ), |
| 50 |
$this->get_divider_element_text_css( $attributes, 'Mobile' ), |
| 51 |
); |
| 52 |
// Icon Style |
| 53 |
$css_generator->add_class_styles( |
| 54 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 55 |
Icon::get_wrapper_css( $attributes ), |
| 56 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 57 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 58 |
); |
| 59 |
$css_generator->add_class_styles( |
| 60 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap:hover', |
| 61 |
Icon::get_wrapper_hover_css( $attributes ), |
| 62 |
Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), |
| 63 |
Icon::get_wrapper_hover_css( $attributes, 'Mobile' ) |
| 64 |
); |
| 65 |
|
| 66 |
$css_generator->add_class_styles( |
| 67 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 68 |
array_merge( Icon::get_wrapper_css( $attributes ), $this->get_icon_spacing_margins( $attributes, '' ) ), |
| 69 |
array_merge( Icon::get_wrapper_css( $attributes, 'Tablet' ), $this->get_icon_spacing_margins( $attributes, 'Tablet' ) ), |
| 70 |
array_merge( Icon::get_wrapper_css( $attributes, 'Mobile' ), $this->get_icon_spacing_margins( $attributes, 'Mobile' ) ) |
| 71 |
); |
| 72 |
$css_generator->add_class_styles( |
| 73 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon', |
| 74 |
Icon::get_element_image_css( $attributes ), |
| 75 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 76 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 77 |
); |
| 78 |
$css_generator->add_class_styles( |
| 79 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 80 |
Icon::get_element_image_hover_css( $attributes ), |
| 81 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 82 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 83 |
); |
| 84 |
$css_generator->add_class_styles( |
| 85 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 86 |
Icon::get_element_css( $attributes ), |
| 87 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 88 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 89 |
); |
| 90 |
$css_generator->add_class_styles( |
| 91 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 92 |
Icon::get_element_image_hover_css( $attributes ), |
| 93 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 94 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 95 |
); |
| 96 |
return $css_generator->generate_css(); |
| 97 |
} |
| 98 |
public function build_css_v2( $attributes ) { |
| 99 |
$css_generator = new CssGeneratorV2( $attributes, $this->block_name ); |
| 100 |
$css_generator->add_class_styles( |
| 101 |
'{{WRAPPER}}.ablocks-block--divider:not(.ablocks-has-block-container), |
| 102 |
.ablocks-block--divider .ablocks-block-container', |
| 103 |
$this->get_wrapper_css( $attributes ), |
| 104 |
$this->get_wrapper_css( $attributes, 'Tablet' ), |
| 105 |
$this->get_wrapper_css( $attributes, 'Mobile' ), |
| 106 |
); |
| 107 |
|
| 108 |
$css_generator->add_class_styles( |
| 109 |
'{{WRAPPER}}.ablocks-block--divider:not(.ablocks-has-block-container), |
| 110 |
.ablocks-block--divider .ablocks-block-container', |
| 111 |
$this->get_divider_container_css( $attributes ), |
| 112 |
$this->get_divider_container_css( $attributes, 'Tablet' ), |
| 113 |
$this->get_divider_container_css( $attributes, 'Mobile' ) |
| 114 |
); |
| 115 |
|
| 116 |
$css_generator->add_class_styles( |
| 117 |
'{{WRAPPER}} .ablocks-divider', |
| 118 |
$this->get_divider_css( $attributes ), |
| 119 |
$this->get_divider_css( $attributes, 'Tablet' ), |
| 120 |
$this->get_divider_css( $attributes, 'Mobile' ), |
| 121 |
); |
| 122 |
// element text |
| 123 |
|
| 124 |
$css_generator->add_class_styles( |
| 125 |
'{{WRAPPER}} .ablocks-divider__element-text', |
| 126 |
$this->get_divider_element_text_css( $attributes ), |
| 127 |
$this->get_divider_element_text_css( $attributes, 'Tablet' ), |
| 128 |
$this->get_divider_element_text_css( $attributes, 'Mobile' ), |
| 129 |
); |
| 130 |
// Icon Style |
| 131 |
$css_generator->add_class_styles( |
| 132 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 133 |
Icon::get_wrapper_css( $attributes ), |
| 134 |
Icon::get_wrapper_css( $attributes, 'Tablet' ), |
| 135 |
Icon::get_wrapper_css( $attributes, 'Mobile' ) |
| 136 |
); |
| 137 |
$css_generator->add_class_styles( |
| 138 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap:hover', |
| 139 |
Icon::get_wrapper_hover_css( $attributes ), |
| 140 |
Icon::get_wrapper_hover_css( $attributes, 'Tablet' ), |
| 141 |
Icon::get_wrapper_hover_css( $attributes, 'Mobile' ) |
| 142 |
); |
| 143 |
$css_generator->add_class_styles( |
| 144 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap', |
| 145 |
array_merge( Icon::get_wrapper_css( $attributes ), $this->get_icon_spacing_margins( $attributes, '' ) ), |
| 146 |
array_merge( Icon::get_wrapper_css( $attributes, 'Tablet' ), $this->get_icon_spacing_margins( $attributes, 'Tablet' ) ), |
| 147 |
array_merge( Icon::get_wrapper_css( $attributes, 'Mobile' ), $this->get_icon_spacing_margins( $attributes, 'Mobile' ) ) |
| 148 |
); |
| 149 |
$css_generator->add_class_styles( |
| 150 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon', |
| 151 |
Icon::get_element_image_css( $attributes ), |
| 152 |
Icon::get_element_image_css( $attributes, 'Tablet' ), |
| 153 |
Icon::get_element_image_css( $attributes, 'Mobile' ), |
| 154 |
); |
| 155 |
$css_generator->add_class_styles( |
| 156 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap img.ablocks-image-icon:hover', |
| 157 |
Icon::get_element_image_hover_css( $attributes ), |
| 158 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 159 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 160 |
); |
| 161 |
$css_generator->add_class_styles( |
| 162 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon', |
| 163 |
Icon::get_element_css( $attributes ), |
| 164 |
Icon::get_element_css( $attributes, 'Tablet' ), |
| 165 |
Icon::get_element_css( $attributes, 'Mobile' ), |
| 166 |
); |
| 167 |
$css_generator->add_class_styles( |
| 168 |
'{{WRAPPER}} .ablocks-divider__element-icon .ablocks-icon-wrap svg.ablocks-svg-icon:hover', |
| 169 |
Icon::get_element_image_hover_css( $attributes ), |
| 170 |
Icon::get_element_image_hover_css( $attributes, 'Tablet' ), |
| 171 |
Icon::get_element_image_hover_css( $attributes, 'Mobile' ), |
| 172 |
); |
| 173 |
return $css_generator->generate_css(); |
| 174 |
} |
| 175 |
public function build_css( $attributes ) { |
| 176 |
if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) { |
| 177 |
return $this->build_css_v2( $attributes ); |
| 178 |
} |
| 179 |
return $this->build_css_v1( $attributes ); |
| 180 |
} |
| 181 |
public function get_wrapper_css( $attributes, $device = '' ) { |
| 182 |
if ( isset( $attributes['alignment'] ) ) { |
| 183 |
return Alignment::get_css( $attributes['alignment'], 'text-align', $device ); |
| 184 |
} |
| 185 |
return []; |
| 186 |
} |
| 187 |
|
| 188 |
public function get_divider_element_text_css( $attributes, $device = '' ) { |
| 189 |
$typographyValueGlobal = ! empty( $attributes['elementTextTypographyGlobal'] ) ? $attributes['elementTextTypographyGlobal'] : ''; |
| 190 |
$typography_value = isset( $attributes['elementTextTypographyGlobal'] ) ? $attributes['elementTextTypographyGlobal'] : []; |
| 191 |
return array_merge( |
| 192 |
[ 'color' => Color::get_css( isset( $attributes['elementTextColor'] ) ? $attributes['elementTextColor'] : '' ) ], |
| 193 |
Range::get_css([ |
| 194 |
'attributeValue' => $attributes['elementTextSpacing'], |
| 195 |
'attributeObjectKey' => 'value', |
| 196 |
'isResponsive' => true, |
| 197 |
'defaultValue' => 0, |
| 198 |
'hasUnit' => true, |
| 199 |
'unitDefaultValue' => 'px', |
| 200 |
'property' => 'padding-right', |
| 201 |
'device' => $device, |
| 202 |
]), |
| 203 |
Range::get_css([ |
| 204 |
'attributeValue' => $attributes['elementTextSpacing'], |
| 205 |
'attributeObjectKey' => 'value', |
| 206 |
'isResponsive' => true, |
| 207 |
'defaultValue' => 0, |
| 208 |
'hasUnit' => true, |
| 209 |
'unitDefaultValue' => 'px', |
| 210 |
'property' => 'padding-left', |
| 211 |
'device' => $device, |
| 212 |
]), |
| 213 |
Typography::get_css( $typography_value, '', $device, $typographyValueGlobal ), |
| 214 |
TextStroke::get_css( $attributes['elementTextStroke'], '', $device ), |
| 215 |
); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
public function get_divider_container_css( $attributes, $device = '' ) { |
| 220 |
$divider_container_css = []; |
| 221 |
if ( ! empty( $attributes['alignment'][ 'value' . $device ] ) ) { |
| 222 |
$divider_container_css['justify-content'] = $attributes['alignment'][ 'value' . $device ]; |
| 223 |
} |
| 224 |
return array_merge( |
| 225 |
Range::get_css([ |
| 226 |
'attributeValue' => $attributes['gap'], |
| 227 |
'attributeObjectKey' => 'value', |
| 228 |
'isResponsive' => true, |
| 229 |
'defaultValue' => 10, |
| 230 |
'unitDefaultValue' => 'px', |
| 231 |
'property' => 'padding-block-start', |
| 232 |
'device' => $device, |
| 233 |
]), |
| 234 |
Range::get_css([ |
| 235 |
'attributeValue' => $attributes['gap'], |
| 236 |
'attributeObjectKey' => 'value', |
| 237 |
'isResponsive' => true, |
| 238 |
'defaultValue' => 10, |
| 239 |
'unitDefaultValue' => 'px', |
| 240 |
'property' => 'padding-block-end', |
| 241 |
'device' => $device, |
| 242 |
]), |
| 243 |
$divider_container_css |
| 244 |
); |
| 245 |
} |
| 246 |
|
| 247 |
public function get_divider_css( $attributes, $device = '' ) { |
| 248 |
$css = []; |
| 249 |
|
| 250 |
$prepared_container = Range::get_css([ |
| 251 |
'attributeValue' => $attributes['width'], |
| 252 |
'attributeObjectKey' => 'value', |
| 253 |
'isResponsive' => true, |
| 254 |
'defaultValue' => 100, |
| 255 |
'hasUnit' => true, |
| 256 |
'unitDefaultValue' => '%', |
| 257 |
'property' => 'value', |
| 258 |
'device' => $device, |
| 259 |
]); |
| 260 |
if ( ! empty( $prepared_container['value'] ) && ( '100%' !== $prepared_container['value'] . $prepared_container['valueUnit'] || $device !== '' ) ) { |
| 261 |
$css['max-width'] = "min(100%, {$prepared_container['value']}{$prepared_container['valueUnit']})"; |
| 262 |
} |
| 263 |
return array_merge( |
| 264 |
$css |
| 265 |
); |
| 266 |
} |
| 267 |
|
| 268 |
public function get_icon_spacing_margins( $attributes, $device = '' ) { |
| 269 |
$marginLeft = Range::get_css([ |
| 270 |
'attributeValue' => $attributes['elementIconSpacing'], |
| 271 |
'attributeObjectKey' => 'value', |
| 272 |
'isResponsive' => true, |
| 273 |
'defaultValue' => 0, |
| 274 |
'hasUnit' => true, |
| 275 |
'unitDefaultValue' => 'px', |
| 276 |
'property' => 'margin-left', |
| 277 |
'device' => $device, |
| 278 |
]); |
| 279 |
$marginRight = Range::get_css([ |
| 280 |
'attributeValue' => $attributes['elementIconSpacing'], |
| 281 |
'attributeObjectKey' => 'value', |
| 282 |
'isResponsive' => true, |
| 283 |
'defaultValue' => 0, |
| 284 |
'hasUnit' => true, |
| 285 |
'unitDefaultValue' => 'px', |
| 286 |
'property' => 'margin-right', |
| 287 |
'device' => $device, |
| 288 |
]); |
| 289 |
return array_merge( $marginLeft, $marginRight ); |
| 290 |
} |
| 291 |
} |
| 292 |
|