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