| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\Blocks\StoreengineProductDescription; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
use ABlocks\Classes\BlockBaseAbstract; |
| 10 |
use ABlocks\Classes\CssGenerator; |
| 11 |
use ABlocks\Helper; |
| 12 |
use ABlocks\Controls\Typography; |
| 13 |
use ABlocks\Controls\Background; |
| 14 |
use ABlocks\Controls\Border; |
| 15 |
use ABlocks\Controls\Dimensions; |
| 16 |
use ABlocks\Controls\Range; |
| 17 |
use ABlocks\Controls\BoxShadow; |
| 18 |
use ABlocks\Controls\Color; |
| 19 |
|
| 20 |
class Block extends BlockBaseAbstract { |
| 21 |
protected $block_name = 'storeengine-product-description'; |
| 22 |
|
| 23 |
public function build_css( $attributes ) { |
| 24 |
$css_generator = new CssGenerator( $attributes, $this->block_name ); |
| 25 |
|
| 26 |
$css_generator->add_class_styles( |
| 27 |
'{{WRAPPER}} .storeengine-product-single__content-item h2', |
| 28 |
$this->get_title_css( $attributes ), |
| 29 |
$this->get_title_css( $attributes, 'Tablet' ), |
| 30 |
$this->get_title_css( $attributes, 'Mobile' ) |
| 31 |
); |
| 32 |
|
| 33 |
$css_generator->add_class_styles( |
| 34 |
'{{WRAPPER}} .storeengine-product-single__content-item h2:hover', |
| 35 |
$this->get_title_hover_css( $attributes ), |
| 36 |
$this->get_title_hover_css( $attributes, 'Tablet' ), |
| 37 |
$this->get_title_hover_css( $attributes, 'Mobile' ) |
| 38 |
); |
| 39 |
|
| 40 |
$css_generator->add_class_styles( |
| 41 |
'{{WRAPPER}} .storeengine-product-single__content-item p', |
| 42 |
$this->get_description_css( $attributes ), |
| 43 |
$this->get_description_css( $attributes, 'Tablet' ), |
| 44 |
$this->get_description_css( $attributes, 'Mobile' ) |
| 45 |
); |
| 46 |
|
| 47 |
$css_generator->add_class_styles( |
| 48 |
'{{WRAPPER}} .storeengine-product-single__content-item p:hover', |
| 49 |
$this->get_description_hover_css( $attributes ), |
| 50 |
$this->get_description_hover_css( $attributes, 'Tablet' ), |
| 51 |
$this->get_description_hover_css( $attributes, 'Mobile' ) |
| 52 |
); |
| 53 |
|
| 54 |
return $css_generator->generate_css(); |
| 55 |
} |
| 56 |
|
| 57 |
public function get_title_css( $attributes, $device = '' ) { |
| 58 |
$typography_global = isset( $attributes['titleTypographyGlobal'] ) |
| 59 |
? $attributes['titleTypographyGlobal'] : ''; |
| 60 |
|
| 61 |
$typography_value = isset( $attributes['titleTypography'] ) |
| 62 |
? Typography::get_css( $attributes['titleTypography'], '', $device, $typography_global ) |
| 63 |
: array(); |
| 64 |
|
| 65 |
return array_merge( |
| 66 |
Border::get_css( $attributes['border'], '', $device ), |
| 67 |
$typography_value, |
| 68 |
[ |
| 69 |
'color' => Color::get_css( |
| 70 |
isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : '' |
| 71 |
), |
| 72 |
] |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
public function get_title_hover_css( $attributes, $device = '' ) { |
| 77 |
return array_merge( |
| 78 |
[ |
| 79 |
'color' => Color::get_css( |
| 80 |
isset( $attributes['titleColor'] ) ? $attributes['titleColorH'] : '' |
| 81 |
) |
| 82 |
], |
| 83 |
Border::get_hover_css( $attributes['border'], '', $device ), |
| 84 |
); |
| 85 |
} |
| 86 |
|
| 87 |
public function get_description_css( $attributes, $device = '' ) { |
| 88 |
$typography_global = isset( $attributes['descriptionTypographyGlobal'] ) |
| 89 |
? $attributes['descriptionTypographyGlobal'] : ''; |
| 90 |
|
| 91 |
$typography_value = isset( $attributes['descriptionTypography'] ) |
| 92 |
? Typography::get_css( $attributes['descriptionTypography'], '', $device, $typography_global ) |
| 93 |
: array(); |
| 94 |
|
| 95 |
return array_merge( |
| 96 |
$typography_value, |
| 97 |
[ |
| 98 |
'color' => Color::get_css( |
| 99 |
isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : '' |
| 100 |
), |
| 101 |
] |
| 102 |
); |
| 103 |
} |
| 104 |
|
| 105 |
public function get_description_hover_css( $attributes, $device = '' ) { |
| 106 |
return [ |
| 107 |
'color' => Color::get_css( |
| 108 |
isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColorH'] : '' |
| 109 |
) |
| 110 |
]; |
| 111 |
} |
| 112 |
|
| 113 |
public function render_block_content( $attributes, $content, $block_instance ) { |
| 114 |
$attr_array = [ |
| 115 |
'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ), |
| 116 |
]; |
| 117 |
|
| 118 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 119 |
$is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) ); |
| 120 |
|
| 121 |
$is_custom = $attributes['isCustom']; |
| 122 |
|
| 123 |
if ( $is_custom ) { |
| 124 |
if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) { |
| 125 |
$attr_array['product_id'] = $block_instance->context['postId']; |
| 126 |
} |
| 127 |
} else { |
| 128 |
if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) { |
| 129 |
$attr_array['product_id'] = $block_instance->context['postId']; |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
if ( $is_editor && empty( $attr_array['product_id'] ) ) { |
| 134 |
return '<p>Only in editor preview. Please Select a Product</p>'; |
| 135 |
} |
| 136 |
|
| 137 |
if ( $is_editor ) { |
| 138 |
$attr_array['dummy'] = true; |
| 139 |
} |
| 140 |
|
| 141 |
$shortcode = '[storeengine_single_product_description ' . Helper::attr_shortcode( $attr_array ) . ']'; |
| 142 |
echo do_shortcode( $shortcode ); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
} |
| 147 |
|