PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.8.1
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.8.1
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
ablocks / includes / blocks / academy-review-form / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.8.1, at includes/blocks/academy-review-form/block.php

290 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\AcademyReviewForm;
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 use ABlocks\Classes\BlockBaseAbstract;
9 use ABlocks\Classes\CssGenerator;
10 use ABlocks\Classes\CssGeneratorV2;
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
21 class Block extends BlockBaseAbstract {
22 protected $block_name = 'academy-review-form';
23
24
25 public function build_css( $attributes ) {
26 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
27
28 $css_generator->add_class_styles(
29 '{{WRAPPER}} .academy-review-form,
30 {{WRAPPER}} .academy-review-form--open-form .comment-respond',
31 $this->get_review_form_css( $attributes, '' ),
32 $this->get_review_form_css( $attributes, 'Tablet' ),
33 $this->get_review_form_css( $attributes, 'Mobile' )
34 );
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} .academy-review-form:hover,
37 {{WRAPPER}} .academy-review-form--open-form .comment-respond:hover',
38 $this->get_review_form_hover_css( $attributes, '' ),
39 $this->get_review_form_hover_css( $attributes, 'Tablet' ),
40 $this->get_review_form_hover_css( $attributes, 'Mobile' )
41 );
42 $css_generator->add_class_styles(
43 '{{WRAPPER}} .academy-review-form__add-review .academy-btn-add-review',
44 $this->get_review_button_css( $attributes, '' ),
45 $this->get_review_button_css( $attributes, 'Tablet' ),
46 $this->get_review_button_css( $attributes, 'Mobile' )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .academy-review-form__add-review .academy-btn-add-review:hover',
50 $this->get_review_button_hover_css( $attributes, '' ),
51 $this->get_review_button_hover_css( $attributes, 'Tablet' ),
52 $this->get_review_button_hover_css( $attributes, 'Mobile' )
53 );
54 $css_generator->add_class_styles(
55 '{{WRAPPER}} .academy-review-form .academy-review-form-rating p.stars a,
56 {{WRAPPER}} .academy-review-form .academy-review-form-rating p.stars a::before',
57 $this->get_start_review_css( $attributes, '' ),
58 $this->get_start_review_css( $attributes, 'Tablet' ),
59 $this->get_start_review_css( $attributes, 'Mobile' )
60 );
61 $css_generator->add_class_styles(
62 '{{WRAPPER}} .academy-review-form .academy-review-form-rating p.stars a:hover,
63 {{WRAPPER}} .academy-review-form .academy-review-form-rating p.stars a:hover::before',
64 $this->get_start_review_hover_css( $attributes, '' ),
65 $this->get_start_review_hover_css( $attributes, 'Tablet' ),
66 $this->get_start_review_hover_css( $attributes, 'Mobile' )
67 );
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .academy-review-form .comment-respond form.comment-form .academy-review-form-review textarea',
70 $this->get_form_css( $attributes, '' ),
71 $this->get_form_css( $attributes, 'Tablet' ),
72 $this->get_form_css( $attributes, 'Mobile' )
73 );
74 $css_generator->add_class_styles(
75 '{{WRAPPER}} .academy-review-form .comment-respond form.comment-form .academy-review-form-review textarea:hover',
76 $this->get_form_hover_css( $attributes, '' ),
77 $this->get_form_hover_css( $attributes, 'Tablet' ),
78 $this->get_form_hover_css( $attributes, 'Mobile' )
79 );
80 $css_generator->add_class_styles(
81 '{{WRAPPER}} .academy-review-form input[type=submit]',
82 $this->get_submit_css( $attributes, '' ),
83 $this->get_submit_css( $attributes, 'Tablet' ),
84 $this->get_submit_css( $attributes, 'Mobile' )
85 );
86 $css_generator->add_class_styles(
87 '{{WRAPPER}} .academy-review-form input[type=submit]:hover',
88 $this->get_submit_hover_css( $attributes, '' ),
89 $this->get_submit_hover_css( $attributes, 'Tablet' ),
90 $this->get_submit_hover_css( $attributes, 'Mobile' )
91 );
92 return $css_generator->generate_css();
93 }
94
95 public function get_review_form_css( $attributes, $device = '' ) {
96 return array_merge(
97 [ 'background' => Color::get_css( isset( $attributes['review_bg'] ) ? $attributes['review_bg'] : '' ) ],
98 Border::get_css( $attributes['border'], '', $device ),
99 Dimensions::get_css( $attributes['padding'], 'padding', $device ),
100 BoxShadow::get_css( $attributes['boxShadow'], '', $device ),
101 Range::get_css([
102 'attributeValue' => $attributes['box_width'],
103 'attribute_object_key' => 'value',
104 'isResponsive' => true,
105 'defaultValue' => 100,
106 'hasUnit' => true,
107 'unitDefaultValue' => '%',
108 'property' => 'width',
109 'device' => $device,
110 ]),
111 );
112
113 }
114
115 public function get_review_form_hover_css( $attributes, $device = '' ) {
116 return array_merge(
117 [ 'background' => Color::get_css( isset( $attributes['review_bg_hover'] ) ? $attributes['review_bg_hover'] : '' ) ],
118 Border::get_hover_css( $attributes['border'], '', $device ),
119 BoxShadow::get_hover_css( $attributes['boxShadow'], '', $device ),
120 );
121 }
122
123 public function get_review_button_css( $attributes, $device = '' ) {
124 $typographyValueGlobal = ! empty( $attributes['review_btn_typographyGlobal'] ) ? $attributes['review_btn_typographyGlobal'] : '';
125 $typography_value = ! empty( $attributes['review_btn_typography'] ) ?
126 Typography::get_css( $attributes['review_btn_typography'], '', $device, $typographyValueGlobal )
127 : array();
128
129 return array_merge(
130 [ 'color' => Color::get_css( isset( $attributes['review_btn'] ) ? $attributes['review_btn'] : '#fff' ) ],
131 [ 'background' => Color::get_css( isset( $attributes['review_btn_bg'] ) ? $attributes['review_btn_bg'] : '#7b68ee' ) ],
132 Dimensions::get_css( $attributes['button_padding'], 'padding', $device ),
133 $typography_value,
134 );
135 }
136
137 public function get_review_button_hover_css( $attributes, $device = '' ) {
138 return array_merge(
139 [ 'color' => Color::get_css( isset( $attributes['review_btn_bg_hover'] ) ? $attributes['review_btn_bg_hover'] : '' ) ],
140 [ 'background' => Color::get_css( isset( $attributes['review_btn_hover'] ) ? $attributes['review_btn_hover'] : '' ) ],
141 Range::get_css([
142 'attributeValue' => $attributes['btn_transition'],
143 'attribute_object_key' => 'value',
144 'isResponsive' => false,
145 'defaultValue' => 0,
146 'hasUnit' => false,
147 'unitDefaultValue' => 's',
148 'property' => 'transition-duration',
149 'device' => $device,
150 ]),
151 );
152
153 }
154 public function get_start_review_css( $attributes, $device = '' ) {
155 return array_merge(
156 [ 'color' => Color::get_css( isset( $attributes['starColor'] ) ? $attributes['starColor'] : '#f4c150' ) ],
157 Range::get_css([
158 'attributeValue' => $attributes['startSize'],
159 'attribute_object_key' => 'value',
160 'isResponsive' => true,
161 'defaultValue' => 16,
162 'hasUnit' => true,
163 'unitDefaultValue' => 'px',
164 'property' => 'font-size',
165 'device' => $device,
166 ]),
167 );
168 }
169
170 public function get_start_review_hover_css( $attributes, $device = '' ) {
171 return array_merge(
172 [ 'color' => Color::get_css( isset( $attributes['starColorH'] ) ? $attributes['starColorH'] : '#f4c150' ) ],
173 Range::get_css([
174 'attributeValue' => $attributes['startT'],
175 'attribute_object_key' => 'value',
176 'isResponsive' => false,
177 'defaultValue' => 0,
178 'hasUnit' => false,
179 'unitDefaultValue' => 's',
180 'property' => 'transition-duration',
181 'device' => $device,
182 ]),
183 );
184
185 }
186
187 public function get_form_css( $attributes, $device = '' ) {
188 $typographyValueGlobal = ! empty( $attributes['formTypographyGlobal'] ) ? $attributes['formTypographyGlobal'] : '';
189 $typography_value = ! empty( $attributes['formTypography'] ) ?
190 Typography::get_css( $attributes['formTypography'], '', $device, $typographyValueGlobal )
191 : array();
192
193 return array_merge(
194 [ 'color' => Color::get_css( isset( $attributes['formColor'] ) ? $attributes['formColor'] : '#444' ) ],
195 [ 'background' => Color::get_css( isset( $attributes['formBg'] ) ? $attributes['formBg'] : '#E5E4E6' ) ],
196 $typography_value,
197 Border::get_css( $attributes['formBorder'], '', $device ),
198 );
199 }
200
201 public function get_form_hover_css( $attributes, $device = '' ) {
202 return array_merge(
203 [ 'color' => Color::get_css( isset( $attributes['formColorH'] ) ? $attributes['formColorH'] : '#444' ) ],
204 [ 'background' => Color::get_css( isset( $attributes['formBgH'] ) ? $attributes['formBgH'] : '#E5E4E6' ) ],
205 Range::get_css([
206 'attributeValue' => $attributes['formTransition'],
207 'attribute_object_key' => 'value',
208 'isResponsive' => false,
209 'defaultValue' => 0,
210 'hasUnit' => false,
211 'unitDefaultValue' => 's',
212 'property' => 'transition-duration',
213 'device' => $device,
214 ]),
215 Border::get_hover_css( $attributes['formBorder'], '', $device ),
216 );
217 }
218
219 public function get_submit_css( $attributes, $device = '' ) {
220 $typographyValueGlobal = ! empty( $attributes['formBtnTypographyGlobal'] ) ? $attributes['formBtnTypographyGlobal'] : '';
221 $typography_value = ! empty( $attributes['formBtnTypography'] ) ?
222 Typography::get_css( $attributes['formBtnTypography'], '', $device, $typographyValueGlobal )
223 : array();
224
225 return array_merge(
226 [ 'color' => Color::get_css( isset( $attributes['formBtnColor'] ) ? $attributes['formBtnColor'] : '#fff' ) ],
227 [ 'background' => Color::get_css( isset( $attributes['formBtnBg'] ) ? $attributes['formBtnBg'] : '#7b68ee' ) ],
228 Dimensions::get_css( $attributes['formBtnPadding'], 'padding', $device ),
229 $typography_value,
230 );
231 }
232
233 public function get_submit_hover_css( $attributes, $device = '' ) {
234 return array_merge(
235 [ 'color' => Color::get_css( isset( $attributes['formBtnColorH'] ) ? $attributes['formBtnColorH'] : '' ) ],
236 [ 'background' => Color::get_css( isset( $attributes['formBtnBgH'] ) ? $attributes['formBtnBgH'] : '' ) ],
237 Range::get_css([
238 'attributeValue' => $attributes['formBtnT'],
239 'attribute_object_key' => 'value',
240 'isResponsive' => false,
241 'defaultValue' => 0,
242 'hasUnit' => false,
243 'unitDefaultValue' => 's',
244 'property' => 'transition-duration',
245 'device' => $device,
246 ]),
247 );
248
249 }
250
251 public function render_block_content( $attributes, $content, $block_instance ) {
252 $course_addition_info_id = method_exists( Helper::class, 'get_attribute_value' ) ? (int) Helper::get_attribute_value( $attributes, 'course_id' ) : (int) ( $attributes['course_id'] ?? 0 );
253 $course_addition_info_attr = method_exists( Helper::class, 'attr_shortcode' ) ? Helper::attr_shortcode( [ 'course_id' => $course_addition_info_id ] ) : 'course_id="' . esc_attr( $course_addition_info_id ) . '"';
254 $course_addition_info_shortcode = '[academy_single_course_review_form ' . trim( $course_addition_info_attr ) . ']';
255 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
256 $course_addition_info_is_edit = defined( 'REST_REQUEST' ) && REST_REQUEST && ( $_REQUEST['context'] ?? '' ) === 'edit';
257 if ( $course_addition_info_is_edit && $course_addition_info_id && ( $course_addition_info_post = get_post( $course_addition_info_id ) ) ) {
258 global $post, $wp_query;
259 $course_addition_info_prev_post = $post;
260 $course_addition_info_prev_query = $wp_query;
261 $post = $course_addition_info_post;
262 setup_postdata( $post );
263 $wp_query = new \WP_Query( [
264 'p' => $course_addition_info_id,
265 'post_type' => $course_addition_info_post->post_type,
266 'no_found_rows' => 1,
267 'posts_per_page' => 1
268 ] );
269 $wp_query->is_singular = 1;
270 $wp_query->is_single = ( $course_addition_info_post->post_type !== 'page' );
271 $wp_query->is_page = ( $course_addition_info_post->post_type === 'page' );
272 $wp_query->is_home = $wp_query->is_front_page = 0;
273 if ( method_exists( $wp_query, 'set' ) ) {
274 $wp_query->set( 'is_main_query', 1 );
275 }
276 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
277 wp_reset_postdata();
278 $wp_query = $course_addition_info_prev_query;
279 $post = $course_addition_info_prev_post;
280 } else {
281 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
282 }//end if
283 if ( $course_addition_info_is_edit && trim( wp_strip_all_tags( $course_addition_info_html ) ) === '' ) {
284 $course_addition_info_html = '<div class="no-data-message"><strong>Editor Only:</strong> No output. Check course ID or data.</div>';
285 }
286 return $course_addition_info_html;
287 }
288
289 }
290