PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.14.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.14.0
2.14.0 2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 All 81 releases
← All changes | includes/blocks/storeengine-product-description/block.php +150 -0 2.7.4 → 2.14.0 View file →
@@ -1,0 +1,150 @@
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 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_css( $attributes, $device ); } )
32 + );
33 +
34 + $css_generator->add_class_styles(
35 + '{{WRAPPER}} .storeengine-product-single__content-item h2:hover',
36 + $this->get_title_hover_css( $attributes ),
37 + $this->get_title_hover_css( $attributes, 'Tablet' ),
38 + $this->get_title_hover_css( $attributes, 'Mobile' ),
39 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_title_hover_css( $attributes, $device ); } )
40 + );
41 +
42 + $css_generator->add_class_styles(
43 + '{{WRAPPER}} .storeengine-product-single__content-item p',
44 + $this->get_description_css( $attributes ),
45 + $this->get_description_css( $attributes, 'Tablet' ),
46 + $this->get_description_css( $attributes, 'Mobile' ),
47 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_description_css( $attributes, $device ); } )
48 + );
49 +
50 + $css_generator->add_class_styles(
51 + '{{WRAPPER}} .storeengine-product-single__content-item p:hover',
52 + $this->get_description_hover_css( $attributes ),
53 + $this->get_description_hover_css( $attributes, 'Tablet' ),
54 + $this->get_description_hover_css( $attributes, 'Mobile' ),
55 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_description_hover_css( $attributes, $device ); } )
56 + );
57 +
58 + return $css_generator->generate_css();
59 + }
60 +
61 + public function get_title_css( $attributes, $device = '' ) {
62 + $typography_global = isset( $attributes['titleTypographyGlobal'] )
63 + ? $attributes['titleTypographyGlobal'] : '';
64 +
65 + $typography_value = isset( $attributes['titleTypography'] )
66 + ? Typography::get_css( $attributes['titleTypography'], '', $device, $typography_global )
67 + : array();
68 +
69 + return array_merge(
70 + Border::get_css( $attributes['border'], '', $device ),
71 + $typography_value,
72 + [
73 + 'color' => Color::get_css(
74 + isset( $attributes['titleColor'] ) ? $attributes['titleColor'] : ''
75 + ),
76 + ]
77 + );
78 + }
79 +
80 + public function get_title_hover_css( $attributes, $device = '' ) {
81 + return array_merge(
82 + [
83 + 'color' => Color::get_css(
84 + isset( $attributes['titleColor'] ) ? $attributes['titleColorH'] : ''
85 + )
86 + ],
87 + Border::get_hover_css( $attributes['border'], '', $device ),
88 + );
89 + }
90 +
91 + public function get_description_css( $attributes, $device = '' ) {
92 + $typography_global = isset( $attributes['descriptionTypographyGlobal'] )
93 + ? $attributes['descriptionTypographyGlobal'] : '';
94 +
95 + $typography_value = isset( $attributes['descriptionTypography'] )
96 + ? Typography::get_css( $attributes['descriptionTypography'], '', $device, $typography_global )
97 + : array();
98 +
99 + return array_merge(
100 + $typography_value,
101 + [
102 + 'color' => Color::get_css(
103 + isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColor'] : ''
104 + ),
105 + ]
106 + );
107 + }
108 +
109 + public function get_description_hover_css( $attributes, $device = '' ) {
110 + return [
111 + 'color' => Color::get_css(
112 + isset( $attributes['descriptionColor'] ) ? $attributes['descriptionColorH'] : ''
113 + )
114 + ];
115 + }
116 +
117 + public function render_block_content( $attributes, $content, $block_instance ) {
118 + $attr_array = [
119 + 'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ),
120 + ];
121 +
122 + // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
123 + $is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) );
124 +
125 + $is_custom = $attributes['isCustom'];
126 +
127 + if ( $is_custom ) {
128 + if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
129 + $attr_array['product_id'] = $block_instance->context['postId'];
130 + }
131 + } else {
132 + if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
133 + $attr_array['product_id'] = $block_instance->context['postId'];
134 + }
135 + }
136 +
137 + if ( $is_editor && empty( $attr_array['product_id'] ) ) {
138 + return '<p>Only in editor preview. Please Select a Product</p>';
139 + }
140 +
141 + if ( $is_editor ) {
142 + $attr_array['dummy'] = true;
143 + }
144 +
145 + $shortcode = '[storeengine_single_product_description ' . Helper::attr_shortcode( $attr_array ) . ']';
146 + echo do_shortcode( $shortcode );
147 +
148 + }
149 +
150 +}