PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.11.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.11.1
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 1.1.2 All 80 releases
ablocks / includes / blocks / storeengine-cart-notice / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.11.1, at includes/blocks/storeengine-cart-notice/block.php

197 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks\Blocks\StoreengineCartNotice;
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-cart-notice';
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-notice--info',
28 $this->get_notice_css( $attributes ),
29 $this->get_notice_css( $attributes, 'Tablet' ),
30 $this->get_notice_css( $attributes, 'Mobile' )
31 );
32 $css_generator->add_class_styles(
33 '{{WRAPPER}} .storeengine-notice--info:hover',
34 $this->get_notice_Hover_css( $attributes ),
35 $this->get_notice_Hover_css( $attributes, 'Tablet' ),
36 $this->get_notice_Hover_css( $attributes, 'Mobile' )
37 );
38 $css_generator->add_class_styles(
39 '{{WRAPPER}} .storeengine-notice .storeengine-notice--message p,
40 {{WRAPPER}} .storeengine-notice .storeengine-notice--message i',
41 $this->get_notice_massage_css( $attributes ),
42 $this->get_notice_massage_css( $attributes, 'Tablet' ),
43 $this->get_notice_massage_css( $attributes, 'Mobile' )
44 );
45
46 $css_generator->add_class_styles(
47 '{{WRAPPER}} .storeengine-notice a,
48 {{WRAPPER}} .storeengine-notice button',
49 $this->get_notice_link_css( $attributes ),
50 $this->get_notice_link_css( $attributes, 'Tablet' ),
51 $this->get_notice_link_css( $attributes, 'Mobile' )
52 );
53
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .storeengine-notice a:hover,
56 {{WRAPPER}} .storeengine-notice button:hover',
57 $this->get_notice_link_hover_css( $attributes ),
58 $this->get_notice_link_hover_css( $attributes, 'Tablet' ),
59 $this->get_notice_link_hover_css( $attributes, 'Mobile' )
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}}.ablocks-block--storeengine-cart-notice:not(.ablocks-block-container),
63 {{WRAPPER}}.ablocks-block--storeengine-cart-notice .ablocks-block-container',
64 $this->get_notice_wrapper_css( $attributes ),
65 $this->get_notice_wrapper_css( $attributes, 'Tablet' ),
66 $this->get_notice_wrapper_css( $attributes, 'Mobile' )
67 );
68 return $css_generator->generate_css();
69 }
70
71 public function get_notice_css( $attributes, $device = '' ) {
72 if ( ! empty( $attributes['infoBoxPadding'] ) ) {
73 $cssPadding = Dimensions::get_css( $attributes['infoBoxPadding'], 'padding', $device );
74 }
75
76 return array_merge(
77 [
78 'color' => Color::get_css(
79 isset( $attributes['boxColor'] ) ? $attributes['boxColor'] : ''
80 ),
81 ],
82 [
83 'background' => Color::get_css(
84 isset( $attributes['boxBackground'] ) ? $attributes['boxBackground'] : ''
85 ),
86 ],
87 $cssPadding,
88 Border::get_css( $attributes['infoBoxBorder'], '', $device ),
89 BoxShadow::get_css( $attributes['infoBoxoxShadow'], '', $device ),
90 Range::get_css( [
91 'attributeValue' => $attributes['infoBoxWidth'],
92 'attribute_object_key' => 'value',
93 'isResponsive' => true,
94 'defaultValue' => 100,
95 'hasUnit' => true,
96 'unitDefaultValue' => '%',
97 'property' => 'width',
98 'device' => $device,
99 ] )
100 );
101 }
102
103 public function get_notice_Hover_css( $attributes, $device = '' ) {
104 return array_merge(
105 Border::get_hover_css( $attributes['infoBoxBorder'], '', $device ),
106 BoxShadow::get_hover_css( $attributes['infoBoxoxShadow'], '', $device ),
107 [
108 'color' => Color::get_css(
109 isset( $attributes['boxColorH'] ) ? $attributes['boxColorH'] : ''
110 ),
111 ],
112 [
113 'background' => Color::get_css(
114 isset( $attributes['boxBackgroundH'] ) ? $attributes['boxBackgroundH'] : ''
115 ),
116 ],
117 );
118 }
119
120 public function get_notice_massage_css( $attributes, $device = '' ) {
121 $typographyValueGlobal = ( isset( $attributes['infoTypographyGlobal'] ) ? $attributes['infoTypographyGlobal'] : '' );
122
123 $typography_value = isset( $attributes['infoTypography'] ) ?
124 Typography::get_css( $attributes['infoTypography'], '', $device, $typographyValueGlobal )
125 : array();
126 return $typography_value;
127 }
128
129 public function get_notice_link_css( $attributes, $device = '' ) {
130 $typographyValueGlobal = ( isset( $attributes['linkTypographyGlobal'] ) ? $attributes['linkTypographyGlobal'] : '' );
131
132 $typography_value = isset( $attributes['linkTypography'] ) ?
133 Typography::get_css( $attributes['linkTypography'], '', $device, $typographyValueGlobal )
134 : array();
135 return array_merge(
136 [
137 'color' => Color::get_css(
138 isset( $attributes['linkColor'] ) ? $attributes['linkColor'] : ''
139 ),
140 ],
141 $typography_value,
142 );
143 }
144
145 public function get_notice_link_hover_css( $attributes, $device = '' ) {
146 return [
147 'color' => Color::get_css(
148 isset( $attributes['linkColorH'] ) ? $attributes['linkColorH'] : ''
149 ),
150 ];
151 }
152
153 public function get_notice_wrapper_css( $attributes, $device = '' ) {
154 $alignment_value = $attributes['infoboxAlignment'][ 'value' . $device ] ?? '';
155 $css = [];
156 if ( ! empty( $alignment_value ) ) {
157 $css['display'] = 'flex';
158 $css['width'] = '100%';
159 $css['justify-content'] = $alignment_value;
160 }
161 return $css;
162 }
163
164 public function render_block_content( $attributes, $content, $block_instance ) {
165 $attr_array = [
166 'product_id' => Helper::get_attribute_value( $attributes, 'product_id' ),
167 ];
168
169 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
170 $is_editor = ( isset( $_GET['context'] ) && 'edit' === sanitize_text_field( $_GET['context'] ) );
171
172 $is_custom = $attributes['isCustom'];
173
174 if ( $is_custom ) {
175 if ( empty( $attr_array['product_id'] ) && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
176 $attr_array['product_id'] = $block_instance->context['postId'];
177 }
178 } else {
179 if ( ! $is_editor && isset( $block_instance->context['postId'] ) && ! empty( $block_instance->context['postId'] ) ) {
180 $attr_array['product_id'] = $block_instance->context['postId'];
181 }
182 }
183
184 if ( $is_editor && empty( $attr_array['product_id'] ) ) {
185 return '<p>Only in editor preview. Please Select a Product</p>';
186 }
187
188 if ( $is_editor ) {
189 $attr_array['dummy'] = true;
190 }
191
192 $shortcode = '[storeengine_single_product_cart_notice ' . Helper::attr_shortcode( $attr_array ) . ']';
193 echo do_shortcode( $shortcode );
194 }
195
196 }
197