| 1 |
<?php |
| 2 |
namespace ABlocks\Blocks\SocialShares; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
use ABlocks\Classes\BlockBaseAbstract; |
| 8 |
use ABlocks\Classes\CssGenerator; |
| 9 |
use ABlocks\Controls\Alignment; |
| 10 |
use ABlocks\Controls\Border; |
| 11 |
use ABlocks\Controls\Typography; |
| 12 |
use ABlocks\Controls\TextShadow; |
| 13 |
use ABlocks\Controls\TextStroke; |
| 14 |
use ABlocks\Controls\Range; |
| 15 |
class Block extends BlockBaseAbstract { |
| 16 |
protected $block_name = 'social-shares'; |
| 17 |
|
| 18 |
public function build_css( $attributes ) { |
| 19 |
// Initialize CSS Generator |
| 20 |
$css_generator = new CssGenerator( $attributes ); |
| 21 |
$css_generator->add_class_styles( |
| 22 |
'{{WRAPPER}}.ablocks-block--social-shares .ablocks-block-container', |
| 23 |
$this->get_share_css( $attributes, '' ), |
| 24 |
$this->get_share_css( $attributes, 'Tablet' ), |
| 25 |
$this->get_share_css( $attributes, 'Mobile' ) |
| 26 |
); |
| 27 |
// Social Button Styles |
| 28 |
$css_generator->add_class_styles( |
| 29 |
'{{WRAPPER}} .ablocks-block-container .ablocks-social-share', |
| 30 |
$this->get_social_share_bar_css( $attributes ), |
| 31 |
$this->get_social_share_bar_css( $attributes, 'Table' ), |
| 32 |
$this->get_social_share_bar_css( $attributes, 'Mobile' ) |
| 33 |
); |
| 34 |
// share Hover Styles |
| 35 |
$css_generator->add_class_styles( |
| 36 |
'{{WRAPPER}} .ablocks-block-container .ablocks-social-share:hover', |
| 37 |
$this->get_share_border_hover_css( $attributes, '' ), |
| 38 |
$this->get_share_border_hover_css( $attributes, 'Tablet' ), |
| 39 |
$this->get_share_border_hover_css( $attributes, 'Mobile' ) |
| 40 |
); |
| 41 |
// share Icon Size |
| 42 |
$css_generator->add_class_styles( |
| 43 |
'{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon', |
| 44 |
$this->get_share_icon_css( $attributes ), |
| 45 |
$this->get_share_icon_css( $attributes, 'Table' ), |
| 46 |
$this->get_share_icon_css( $attributes, 'Mobile' ), |
| 47 |
); |
| 48 |
$css_generator->add_class_styles( |
| 49 |
'{{WRAPPER}} .ablocks-social-share > .ablocks-svg-icon:hover', |
| 50 |
$this->get_share_icon_hover_css( |
| 51 |
$attributes |
| 52 |
), |
| 53 |
); |
| 54 |
// item style |
| 55 |
$css_generator->add_class_styles( |
| 56 |
'{{WRAPPER}} .ablocks-social-share-item', |
| 57 |
$this->get_item_border_css( $attributes ), |
| 58 |
$this->get_item_border_css( $attributes, 'Tablet' ), |
| 59 |
$this->get_item_border_css( $attributes, 'Mobile' ) |
| 60 |
); |
| 61 |
$css_generator->add_class_styles( |
| 62 |
'{{WRAPPER}} .ablocks-block-container .ablocks-social-share-item:hover', |
| 63 |
$this->get_Item_border_hover_css( $attributes ), |
| 64 |
$this->get_Item_border_hover_css( $attributes, 'Tablet' ), |
| 65 |
$this->get_Item_border_hover_css( $attributes, 'Mobile' ) |
| 66 |
); |
| 67 |
$css_generator->add_class_styles( |
| 68 |
'{{WRAPPER}} .ablocks-social-share-item--icon', |
| 69 |
$this->get_share_item_css( $attributes ), |
| 70 |
$this->get_share_item_css( $attributes, 'Tablet' ), |
| 71 |
$this->get_share_item_css( $attributes, 'Mobile' ), |
| 72 |
); |
| 73 |
$css_generator->add_class_styles( |
| 74 |
'{{WRAPPER}} .ablocks-social-share-item--icon>.ablocks-svg-icon', |
| 75 |
$this->shareItemIconSVG( $attributes ), |
| 76 |
$this->shareItemIconSVG( $attributes, 'Tablet' ), |
| 77 |
$this->shareItemIconSVG( $attributes, 'Mobile' ), |
| 78 |
); |
| 79 |
$css_generator->add_class_styles( |
| 80 |
'{{WRAPPER}} .ablocks-social-share-item--text', |
| 81 |
$this->get_share_item_text_css( $attributes, '' ), |
| 82 |
$this->get_share_item_text_css( $attributes, 'Tablet' ), |
| 83 |
$this->get_share_item_text_css( $attributes, 'Mobile' ) |
| 84 |
); |
| 85 |
return $css_generator->generate_css(); |
| 86 |
} |
| 87 |
|
| 88 |
public function get_share_css( $attributes, $device = '' ) { |
| 89 |
$css = []; |
| 90 |
$stack = $attributes[ 'stack' . $device ] ?? $attributes['stack'] ?? ''; |
| 91 |
if ( $stack === 'vertical' ) { |
| 92 |
$css['flex-direction'] = 'column'; |
| 93 |
if ( ! empty( $attributes[ 'verticalAlignment' . $device ] ) ) { |
| 94 |
$css['align-items'] = $attributes[ 'verticalAlignment' . $device ]; |
| 95 |
} |
| 96 |
} elseif ( $stack === 'horizontal' ) { |
| 97 |
$css['flex-direction'] = 'row'; |
| 98 |
$horizontal_alignment = $attributes[ 'horizontalAlignment' . $device ] ?? $attributes['horizontalAlignment'] ?? ''; |
| 99 |
if ( ! empty( $horizontal_alignment ) ) { |
| 100 |
$css['justify-content'] = $horizontal_alignment; |
| 101 |
} |
| 102 |
} |
| 103 |
$alignment_css = isset( $attributes['horizontalAlignment'] ) |
| 104 |
? Alignment::get_css( $attributes['horizontalAlignment'], 'justify-content', $device ) |
| 105 |
: []; |
| 106 |
$css = array_merge( $css, $alignment_css ); |
| 107 |
|
| 108 |
foreach ( $css as $property => $value ) { |
| 109 |
if ( ! is_string( $value ) || empty( $value ) ) { |
| 110 |
unset( $css[ $property ] ); |
| 111 |
} |
| 112 |
} |
| 113 |
return array_merge( |
| 114 |
$css, |
| 115 |
Range::get_css([ |
| 116 |
'attributeValue' => $attributes['spaceBetween'], |
| 117 |
'attribute_object_key' => 'value', |
| 118 |
'isResponsive' => true, |
| 119 |
'defaultValue' => 20, |
| 120 |
'hasUnit' => true, |
| 121 |
'unitDefaultValue' => 'px', |
| 122 |
'property' => 'gap', |
| 123 |
'device' => $device, |
| 124 |
]) |
| 125 |
); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
public function get_social_share_bar_css( $attributes, $device = '' ) { |
| 130 |
$css = [ |
| 131 |
'background' => $attributes['buttonBackground'], |
| 132 |
]; |
| 133 |
|
| 134 |
return array_merge( |
| 135 |
$css, |
| 136 |
Border::get_css( $attributes['border'], $device ), |
| 137 |
Range::get_css([ |
| 138 |
'attributeValue' => $attributes['shareSize'], |
| 139 |
'attribute_object_key' => 'value', |
| 140 |
'isResponsive' => false, |
| 141 |
'defaultValue' => 48, |
| 142 |
'hasUnit' => true, |
| 143 |
'unitDefaultValue' => 'px', |
| 144 |
'property' => 'height', |
| 145 |
'device' => $device, |
| 146 |
]), |
| 147 |
Range::get_css([ |
| 148 |
'attributeValue' => $attributes['shareSize'], |
| 149 |
'attribute_object_key' => 'value', |
| 150 |
'isResponsive' => false, |
| 151 |
'defaultValue' => 48, |
| 152 |
'hasUnit' => true, |
| 153 |
'unitDefaultValue' => 'px', |
| 154 |
'property' => 'width', |
| 155 |
'device' => $device, |
| 156 |
]), |
| 157 |
); |
| 158 |
} |
| 159 |
|
| 160 |
public function get_share_border_hover_css( $attributes, $device = '' ) { |
| 161 |
$css = []; |
| 162 |
if ( ! empty( $attributes['buttonHover'] ) ) { |
| 163 |
$css['background'] = $attributes['buttonHover']; |
| 164 |
} |
| 165 |
return array_merge( |
| 166 |
$css, |
| 167 |
( isset( $attributes['border'] ) ? Border::get_hover_css( $attributes['border'], '', $device ) : [] ) |
| 168 |
); |
| 169 |
} |
| 170 |
public function get_share_icon_css( $attributes, $device = '' ) { |
| 171 |
$css = []; |
| 172 |
if ( ! empty( $attributes['shareButtonIconColor'] ) ) { |
| 173 |
$css['fill'] = $attributes['shareButtonIconColor'] . ' !important'; |
| 174 |
} |
| 175 |
return array_merge( $css, |
| 176 |
Range::get_css( [ |
| 177 |
'attributeValue' => $attributes['shareIconSize'], |
| 178 |
'attribute_object_key' => 'value', |
| 179 |
'isResponsive' => false, |
| 180 |
'defaultValue' => 16, |
| 181 |
'hasUnit' => true, |
| 182 |
'unitDefaultValue' => 'px', |
| 183 |
'property' => 'width', |
| 184 |
'device' => $device, |
| 185 |
] ), |
| 186 |
Range::get_css( [ |
| 187 |
'attributeValue' => $attributes['shareIconSize'], |
| 188 |
'attribute_object_key' => 'value', |
| 189 |
'isResponsive' => false, |
| 190 |
'defaultValue' => 16, |
| 191 |
'hasUnit' => true, |
| 192 |
'unitDefaultValue' => 'px', |
| 193 |
'property' => 'height', |
| 194 |
'device' => $device, |
| 195 |
] ) |
| 196 |
); |
| 197 |
} |
| 198 |
public function get_share_icon_hover_css( $attributes, $device = '' ) { |
| 199 |
$css = []; |
| 200 |
|
| 201 |
if ( ! empty( $attributes['shareButtonIconColorH'] ) ) { |
| 202 |
$css['fill'] = $attributes['shareButtonIconColorH'] . ' !important'; |
| 203 |
} |
| 204 |
return $css; |
| 205 |
} |
| 206 |
public function shareItemIconSVG( $attributes, $device = '' ) { |
| 207 |
return Range::get_css( [ |
| 208 |
'attributeValue' => $attributes['shareItemIconSize'], |
| 209 |
'attribute_object_key' => 'value', |
| 210 |
'isResponsive' => false, |
| 211 |
'defaultValue' => 42, |
| 212 |
'hasUnit' => true, |
| 213 |
'unitDefaultValue' => 'px', |
| 214 |
'property' => 'height', |
| 215 |
'device' => $device, |
| 216 |
] ); |
| 217 |
} |
| 218 |
|
| 219 |
public function get_share_item_css( $attributes, $device = '' ) { |
| 220 |
$css = []; |
| 221 |
$range_width = Range::get_css([ |
| 222 |
'attributeValue' => $attributes['itemIconWidth'], |
| 223 |
'attribute_object_key' => 'value', |
| 224 |
'isResponsive' => false, |
| 225 |
'defaultValue' => 43, |
| 226 |
'hasUnit' => true, |
| 227 |
'unitDefaultValue' => 'px', |
| 228 |
'property' => 'width', |
| 229 |
'device' => $device, |
| 230 |
]); |
| 231 |
$range_height = Range::get_css([ |
| 232 |
'attributeValue' => $attributes['itemIconHeight'], |
| 233 |
'attribute_object_key' => 'value', |
| 234 |
'isResponsive' => false, |
| 235 |
'defaultValue' => 42, |
| 236 |
'hasUnit' => true, |
| 237 |
'unitDefaultValue' => 'px', |
| 238 |
'property' => 'height', |
| 239 |
'device' => $device, |
| 240 |
] ); |
| 241 |
return array_merge( $css, $range_width, $range_height ); |
| 242 |
} |
| 243 |
public function get_item_border_css( $attributes, $device = '' ) { |
| 244 |
$css = ( isset( $attributes['itemBorder'] ) |
| 245 |
? Border::get_css( $attributes['itemBorder'], '', $device ) |
| 246 |
: [] ); |
| 247 |
return $css; |
| 248 |
} |
| 249 |
public function get_Item_border_hover_css( $attributes, $device = '' ) { |
| 250 |
return array_merge( |
| 251 |
( isset( $attributes['itemBorder'] ) ? Border::get_hover_css( $attributes['itemBorder'], '', $device ) : [] ) |
| 252 |
); |
| 253 |
} |
| 254 |
public function get_share_item_text_css( $attributes, $device = '' ) { |
| 255 |
$css = []; |
| 256 |
$range_width = Range::get_css([ |
| 257 |
'attributeValue' => $attributes['itemTextWidth'], |
| 258 |
'attribute_object_key' => 'value', |
| 259 |
'isResponsive' => false, |
| 260 |
'defaultValue' => 80, |
| 261 |
'hasUnit' => true, |
| 262 |
'unitDefaultValue' => 'px', |
| 263 |
'property' => 'width', |
| 264 |
'device' => $device, |
| 265 |
]); |
| 266 |
$range_height = Range::get_css( [ |
| 267 |
'attributeValue' => $attributes['itemTextHeight'], |
| 268 |
'attribute_object_key' => 'value', |
| 269 |
'isResponsive' => false, |
| 270 |
'defaultValue' => 42, |
| 271 |
'hasUnit' => true, |
| 272 |
'unitDefaultValue' => 'px', |
| 273 |
'property' => 'height', |
| 274 |
'device' => $device, |
| 275 |
] ); |
| 276 |
return array_merge( |
| 277 |
$css, |
| 278 |
$range_width, |
| 279 |
$range_height, |
| 280 |
isset( $attributes['alignment'] ) ? Alignment::get_css( $attributes['alignment'], 'text-align', $device ) : [], |
| 281 |
isset( $attributes['typography'] ) ? Typography::get_css( $attributes['typography'], '', $device ) : [], |
| 282 |
isset( $attributes['textShadow'] ) ? TextShadow::get_css( $attributes['textShadow'], '', $device ) : [], |
| 283 |
isset( $attributes['textStroke'] ) ? TextStroke::get_css( $attributes['textStroke'], '', $device ) : [] |
| 284 |
); |
| 285 |
} |
| 286 |
|
| 287 |
} |
| 288 |
|