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-list / 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-list/block.php

296 lines 11.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\AcademyReviewList;
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-list';
23
24 public function build_css( $attributes ) {
25 $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
26
27 $css_generator->add_class_styles(
28 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-thumnail img',
29 $this->get_avatar_css( $attributes, '' ),
30 $this->get_avatar_css( $attributes, 'Tablet' ),
31 $this->get_avatar_css( $attributes, 'Mobile' )
32 );
33 $css_generator->add_class_styles(
34 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-meta__author',
35 $this->get_author_css( $attributes, '' ),
36 $this->get_author_css( $attributes, 'Tablet' ),
37 $this->get_author_css( $attributes, 'Mobile' )
38 );
39 $css_generator->add_class_styles(
40 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-meta__author:hover',
41 $this->get_author_hover_css( $attributes, '' ),
42 $this->get_author_hover_css( $attributes, 'Tablet' ),
43 $this->get_author_hover_css( $attributes, 'Mobile' )
44 );
45 $css_generator->add_class_styles(
46 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-meta__published-date',
47 $this->get_date_time_css( $attributes, '' ),
48 $this->get_date_time_css( $attributes, 'Tablet' ),
49 $this->get_date_time_css( $attributes, 'Mobile' )
50 );
51 $css_generator->add_class_styles(
52 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-meta__published-date:hover',
53 $this->get_date_time_hover_css( $attributes, '' ),
54 $this->get_date_time_hover_css( $attributes, 'Tablet' ),
55 $this->get_date_time_hover_css( $attributes, 'Mobile' )
56 );
57 $css_generator->add_class_styles(
58 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-description p',
59 $this->get_description_css( $attributes, '' ),
60 $this->get_description_css( $attributes, 'Tablet' ),
61 $this->get_description_css( $attributes, 'Mobile' )
62 );
63 $css_generator->add_class_styles(
64 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-content .academy-review-description p:hover',
65 $this->get_description_hover_css( $attributes, '' ),
66 $this->get_description_hover_css( $attributes, 'Tablet' ),
67 $this->get_description_hover_css( $attributes, 'Mobile' )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-thumnail .academy-review__rating',
71 $this->get_summary_css( $attributes, '' ),
72 $this->get_summary_css( $attributes, 'Tablet' ),
73 $this->get_summary_css( $attributes, 'Mobile' )
74 );
75 $css_generator->add_class_styles(
76 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-thumnail .academy-review__rating:hover',
77 $this->get_summary_hover_css( $attributes, '' ),
78 $this->get_summary_hover_css( $attributes, 'Tablet' ),
79 $this->get_summary_hover_css( $attributes, 'Mobile' )
80 );
81 $css_generator->add_class_styles(
82 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-thumnail .academy-group-star i',
83 $this->get_summary_icon_css( $attributes, '' ),
84 $this->get_summary_icon_css( $attributes, 'Tablet' ),
85 $this->get_summary_icon_css( $attributes, 'Mobile' )
86 );
87 $css_generator->add_class_styles(
88 '{{WRAPPER}} .academy-review-list li .academy-review_container .academy-review-thumnail .academy-group-star i:hover',
89 $this->get_summary_icon_hover_css( $attributes, '' ),
90 $this->get_summary_icon_hover_css( $attributes, 'Tablet' ),
91 $this->get_summary_icon_hover_css( $attributes, 'Mobile' )
92 );
93
94 return $css_generator->generate_css();
95 }
96
97 public function get_avatar_css( $attributes, $device = '' ) {
98 return array_merge(
99 Range::get_css([
100 'attributeValue' => $attributes['avatarWidth'],
101 'attribute_object_key' => 'value',
102 'isResponsive' => true,
103 'defaultValue' => 50,
104 'hasUnit' => true,
105 'unitDefaultValue' => 'px',
106 'property' => 'width',
107 'device' => $device,
108 ]),
109 Range::get_css([
110 'attributeValue' => $attributes['avatarHeight'],
111 'attribute_object_key' => 'value',
112 'isResponsive' => true,
113 'defaultValue' => 50,
114 'hasUnit' => true,
115 'unitDefaultValue' => 'px',
116 'property' => 'height',
117 'device' => $device,
118 ]),
119 );
120 }
121
122 public function get_author_css( $attributes, $device = '' ) {
123 $typographyValueGlobal = ! empty( $attributes['authorTypographyGlobal'] ) ? $attributes['authorTypographyGlobal'] : '';
124 $typography_value = ! empty( $attributes['authorTypography'] ) ?
125 Typography::get_css( $attributes['authorTypography'], '', $device, $typographyValueGlobal )
126 : array();
127
128 return array_merge(
129 [ 'color' => Color::get_css( isset( $attributes['authorColor'] ) ? $attributes['authorColor'] : '#111' ) ],
130 $typography_value,
131 );
132 }
133
134 public function get_author_hover_css( $attributes, $device = '' ) {
135 return array_merge(
136 [ 'color' => Color::get_css( isset( $attributes['authorHoverColor'] ) ? $attributes['authorHoverColor'] : '#111' ) ],
137 Range::get_css([
138 'attributeValue' => $attributes['authorTransition'],
139 'attribute_object_key' => 'value',
140 'isResponsive' => false,
141 'defaultValue' => 0,
142 'hasUnit' => false,
143 'unitDefaultValue' => 's',
144 'property' => 'transition-duration',
145 'device' => $device,
146 ]),
147 );
148
149 }
150
151 public function get_date_time_css( $attributes, $device = '' ) {
152 $typographyValueGlobal = ! empty( $attributes['dateTypographyGlobal'] ) ? $attributes['dateTypographyGlobal'] : '';
153 $typography_value = ! empty( $attributes['dateTypography'] ) ?
154 Typography::get_css( $attributes['dateTypography'], '', $device, $typographyValueGlobal )
155 : array();
156
157 return array_merge(
158 [ 'color' => Color::get_css( isset( $attributes['dateColor'] ) ? $attributes['dateColor'] : '#111' ) ],
159 $typography_value,
160 );
161 }
162
163 public function get_date_time_hover_css( $attributes, $device = '' ) {
164 return array_merge(
165 [ 'color' => Color::get_css( isset( $attributes['dateHoverColor'] ) ? $attributes['dateHoverColor'] : '#111' ) ],
166 Range::get_css([
167 'attributeValue' => $attributes['dateTransition'],
168 'attribute_object_key' => 'value',
169 'isResponsive' => false,
170 'defaultValue' => 0,
171 'hasUnit' => false,
172 'unitDefaultValue' => 's',
173 'property' => 'transition-duration',
174 'device' => $device,
175 ]),
176 );
177
178 }
179 public function get_description_css( $attributes, $device = '' ) {
180 $typographyValueGlobal = ! empty( $attributes['desTypographyGlobal'] ) ? $attributes['desTypographyGlobal'] : '';
181 $typography_value = ! empty( $attributes['desTypography'] ) ?
182 Typography::get_css( $attributes['desTypography'], '', $device, $typographyValueGlobal )
183 : array();
184
185 return array_merge(
186 [ 'color' => Color::get_css( isset( $attributes['desColor'] ) ? $attributes['desColor'] : '#111' ) ],
187 $typography_value,
188 );
189 }
190
191 public function get_description_hover_css( $attributes, $device = '' ) {
192 return array_merge(
193 [ 'color' => Color::get_css( isset( $attributes['desHoverColor'] ) ? $attributes['desHoverColor'] : '#111' ) ],
194 Range::get_css([
195 'attributeValue' => $attributes['desTransition'],
196 'attribute_object_key' => 'value',
197 'isResponsive' => false,
198 'defaultValue' => 0,
199 'hasUnit' => false,
200 'unitDefaultValue' => 's',
201 'property' => 'transition-duration',
202 'device' => $device,
203 ]),
204 );
205
206 }
207
208 public function get_summary_css( $attributes, $device = '' ) {
209 $typographyValueGlobal = ! empty( $attributes['sumTypographyGlobal'] ) ? $attributes['sumTypographyGlobal'] : '';
210 $typography_value = ! empty( $attributes['sumTypography'] ) ?
211 Typography::get_css( $attributes['sumTypography'], '', $device, $typographyValueGlobal )
212 : array();
213
214 return array_merge(
215 [ 'color' => Color::get_css( isset( $attributes['sumColor'] ) ? $attributes['sumColor'] : '#111' ) ],
216 $typography_value,
217 );
218 }
219
220 public function get_summary_hover_css( $attributes, $device = '' ) {
221 return array_merge(
222 [ 'color' => Color::get_css( isset( $attributes['sumColorH'] ) ? $attributes['sumColorH'] : '#111' ) ],
223 Range::get_css([
224 'attributeValue' => $attributes['sumTransition'],
225 'attribute_object_key' => 'value',
226 'isResponsive' => false,
227 'defaultValue' => 0,
228 'hasUnit' => false,
229 'unitDefaultValue' => 's',
230 'property' => 'transition-duration',
231 'device' => $device,
232 ]),
233 );
234 }
235
236 public function get_summary_icon_css( $attributes, $device = '' ) {
237 return array_merge(
238 [ 'color' => Color::get_css( isset( $attributes['iconColor'] ) ? $attributes['iconColor'] : '#f4c150' ) ],
239 Range::get_css([
240 'attributeValue' => $attributes['iconSize'],
241 'attribute_object_key' => 'value',
242 'isResponsive' => true,
243 'defaultValue' => 50,
244 'hasUnit' => true,
245 'unitDefaultValue' => 'px',
246 'property' => 'font-size',
247 'device' => $device,
248 ]),
249 );
250
251 }
252
253 public function get_summary_icon_hover_css( $attributes, $device = '' ) {
254 return [ 'color' => Color::get_css( isset( $attributes['iconColorH'] ) ? $attributes['iconColorH'] : '#f4c150' ) ];
255 }
256
257 public function render_block_content( $attributes, $content, $block_instance ) {
258 $course_addition_info_id = method_exists( Helper::class, 'get_attribute_value' ) ? (int) Helper::get_attribute_value( $attributes, 'course_id' ) : (int) ( $attributes['course_id'] ?? 0 );
259 $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 ) . '"';
260 $course_addition_info_shortcode = '[academy_course_reviews ' . trim( $course_addition_info_attr ) . ']';
261 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
262 $course_addition_info_is_edit = defined( 'REST_REQUEST' ) && REST_REQUEST && ( $_REQUEST['context'] ?? '' ) === 'edit';
263 if ( $course_addition_info_is_edit && $course_addition_info_id && ( $course_addition_info_post = get_post( $course_addition_info_id ) ) ) {
264 global $post, $wp_query;
265 $course_addition_info_prev_post = $post;
266 $course_addition_info_prev_query = $wp_query;
267 $post = $course_addition_info_post;
268 setup_postdata( $post );
269 $wp_query = new \WP_Query( [
270 'p' => $course_addition_info_id,
271 'post_type' => $course_addition_info_post->post_type,
272 'no_found_rows' => 1,
273 'posts_per_page' => 1
274 ] );
275 $wp_query->is_singular = 1;
276 $wp_query->is_single = ( $course_addition_info_post->post_type !== 'page' );
277 $wp_query->is_page = ( $course_addition_info_post->post_type === 'page' );
278 $wp_query->is_home = $wp_query->is_front_page = 0;
279 if ( method_exists( $wp_query, 'set' ) ) {
280 $wp_query->set( 'is_main_query', 1 );
281 }
282 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
283 wp_reset_postdata();
284 $wp_query = $course_addition_info_prev_query;
285 $post = $course_addition_info_prev_post;
286 } else {
287 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
288 }//end if
289 if ( $course_addition_info_is_edit && trim( wp_strip_all_tags( $course_addition_info_html ) ) === '' ) {
290 $course_addition_info_html = '<div class="no-data-message"><strong>Editor Only:</strong> No output. Check course ID or data.</div>';
291 }
292 return $course_addition_info_html;
293 }
294
295 }
296