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
ablocks / includes / blocks / academy-course-curriculums / block.php

block.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.14.0, at includes/blocks/academy-course-curriculums/block.php

253 lines 12.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ABlocks\Blocks\AcademyCourseCurriculums;
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\Color;
18
19
20 class Block extends BlockBaseAbstract {
21 protected $block_name = 'academy-course-curriculums';
22
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-single-course__content-item--curriculum .academy-curriculum-title',
29 $this->get_curriculum_heading_css( $attributes ),
30 $this->get_curriculum_heading_css( $attributes, 'Tablet' ),
31 $this->get_curriculum_heading_css( $attributes, 'Mobile' ),
32 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_curriculum_heading_css( $attributes, $device ); } )
33 );
34 $css_generator->add_class_styles(
35 '{{WRAPPER}} .academy-single-course__content-item--curriculum .academy-curriculum-title:hover',
36 $this->get_curriculum_heading_hover_css( $attributes ),
37 $this->get_curriculum_heading_hover_css( $attributes, 'Tablet' ),
38 $this->get_curriculum_heading_hover_css( $attributes, 'Mobile' ),
39 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_curriculum_heading_hover_css( $attributes, $device ); } )
40 );
41 $css_generator->add_class_styles(
42 '{{WRAPPER}} .academy-accordion a.academy-accordion__title',
43 $this->get_sub_heading_css( $attributes ),
44 $this->get_sub_heading_css( $attributes, 'Tablet' ),
45 $this->get_sub_heading_css( $attributes, 'Mobile' ),
46 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_sub_heading_css( $attributes, $device ); } )
47 );
48 $css_generator->add_class_styles(
49 '{{WRAPPER}} .academy-accordion a.academy-accordion__title:hover',
50 $this->get_sub_heading_hover_css( $attributes ),
51 $this->get_sub_heading_hover_css( $attributes, 'Tablet' ),
52 $this->get_sub_heading_hover_css( $attributes, 'Mobile' ),
53 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_sub_heading_hover_css( $attributes, $device ); } )
54 );
55 $css_generator->add_class_styles(
56 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-content .academy-entry-title',
57 $this->get_lesson_title_css( $attributes ),
58 $this->get_lesson_title_css( $attributes, 'Tablet' ),
59 $this->get_lesson_title_css( $attributes, 'Mobile' ),
60 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_lesson_title_css( $attributes, $device ); } )
61 );
62 $css_generator->add_class_styles(
63 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-content .academy-entry-title:hover',
64 $this->get_lesson_title_hover_css( $attributes ),
65 $this->get_lesson_title_hover_css( $attributes, 'Tablet' ),
66 $this->get_lesson_title_hover_css( $attributes, 'Mobile' ),
67 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_lesson_title_hover_css( $attributes, $device ); } )
68 );
69 $css_generator->add_class_styles(
70 '{{WRAPPER}} .academy-lesson-list__item',
71 $this->get_lesson_list_css( $attributes ),
72 $this->get_lesson_list_css( $attributes, 'Tablet' ),
73 $this->get_lesson_list_css( $attributes, 'Mobile' ),
74 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_lesson_list_css( $attributes, $device ); } )
75 );
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .academy-lesson-list__item:hover',
78 $this->get_lesson_list_hover_css( $attributes ),
79 $this->get_lesson_list_hover_css( $attributes, 'Tablet' ),
80 $this->get_lesson_list_hover_css( $attributes, 'Mobile' ),
81 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_lesson_list_hover_css( $attributes, $device ); } )
82 );
83 $css_generator->add_class_styles(
84 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-control .academy-btn-play i',
85 $this->get_icon_css( $attributes, '' ),
86 $this->get_icon_css( $attributes, 'Tablet' ),
87 $this->get_icon_css( $attributes, 'Mobile' ),
88 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_css( $attributes, $device ); } )
89 );
90 $css_generator->add_class_styles(
91 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-control .academy-btn-play i:hover',
92 $this->get_icon_hover_css( $attributes, '' ),
93 $this->get_icon_hover_css( $attributes, 'Tablet' ),
94 $this->get_icon_hover_css( $attributes, 'Mobile' ),
95 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_icon_hover_css( $attributes, $device ); } )
96 );
97 $css_generator->add_class_styles(
98 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-content .academy-icon::before',
99 $this->get_read_icon_css( $attributes, '' ),
100 $this->get_read_icon_css( $attributes, 'Tablet' ),
101 $this->get_read_icon_css( $attributes, 'Mobile' ),
102 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_read_icon_css( $attributes, $device ); } )
103 );
104 $css_generator->add_class_styles(
105 '{{WRAPPER}} .academy-lesson-list__item .academy-entry-content .academy-icon:hover::before',
106 $this->get_read_icon_hover_css( $attributes, '' ),
107 $this->get_read_icon_hover_css( $attributes, 'Tablet' ),
108 $this->get_read_icon_hover_css( $attributes, 'Mobile' ),
109 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_read_icon_hover_css( $attributes, $device ); } )
110 );
111
112 return $css_generator->generate_css();
113 }
114
115 public function get_curriculum_heading_css( $attributes, $device = '' ) {
116 $typographyValueGlobal = ! empty( $attributes['heading_typographyGlobal'] ) ? $attributes['heading_typographyGlobal'] : '';
117 $typography_value = ! empty( $attributes['heading_typography'] ) ?
118 Typography::get_css( $attributes['heading_typography'], '', $device, $typographyValueGlobal )
119 : array();
120
121 return array_merge(
122 [ 'color' => Color::get_css( isset( $attributes['heading_color'] ) ? $attributes['heading_color'] : '' ) ],
123 $typography_value,
124 );
125 }
126
127 public function get_curriculum_heading_hover_css( $attributes, $device = '' ) {
128 return [ 'color' => Color::get_css( isset( $attributes['heading_color_hover'] ) ? $attributes['heading_color_hover'] : '' ) ];
129
130 }
131 public function get_sub_heading_css( $attributes, $device = '' ) {
132 $typographyValueGlobal = ! empty( $attributes['title_typographyGlobal'] ) ? $attributes['title_typographyGlobal'] : '';
133 $typography_value = ! empty( $attributes['title_typography'] ) ?
134 Typography::get_css( $attributes['title_typography'], '', $device, $typographyValueGlobal )
135 : array();
136
137 return array_merge(
138 [ 'color' => Color::get_css( isset( $attributes['title_color'] ) ? $attributes['title_color'] : '' ) ],
139 [ 'background' => Color::get_css( isset( $attributes['title_bg'] ) ? $attributes['title_bg'] : '' ) ],
140 $typography_value,
141 );
142 }
143
144 public function get_sub_heading_hover_css( $attributes, $device = '' ) {
145 return array_merge(
146 [ 'color' => Color::get_css( isset( $attributes['title_color_hover'] ) ? $attributes['title_color_hover'] : '' ) ],
147 [ 'background' => Color::get_css( isset( $attributes['title_bg_hover'] ) ? $attributes['title_bg_hover'] : '#fff' ) ],
148 );
149 }
150
151 public function get_lesson_title_css( $attributes, $device = '' ) {
152 $typographyValueGlobal = ! empty( $attributes['contentTypographyGlobal'] ) ? $attributes['contentTypographyGlobal'] : '';
153 $typography_value = ! empty( $attributes['contentTypography'] ) ?
154 Typography::get_css( $attributes['contentTypography'], '', $device, $typographyValueGlobal )
155 : array();
156
157 return array_merge(
158 [ 'color' => Color::get_css( isset( $attributes['contentColor'] ) ? $attributes['contentColor'] : '' ) ],
159 $typography_value,
160 );
161 }
162
163 public function get_lesson_title_hover_css( $attributes, $device = '' ) {
164 return [ 'color' => Color::get_css( isset( $attributes['contentColorH'] ) ? $attributes['contentColorH'] : '' ) ];
165 }
166 public function get_lesson_list_css( $attributes, $device = '' ) {
167 return [ 'background' => Color::get_css( isset( $attributes['lesson_list_bg'] ) ? $attributes['lesson_list_bg'] : '' ) ];
168 }
169
170 public function get_lesson_list_hover_css( $attributes, $device = '' ) {
171 return [ 'background' => Color::get_css( isset( $attributes['lesson_list_hover'] ) ? $attributes['lesson_list_hover'] : '' ) ];
172 }
173
174 public function get_icon_hover_css( $attributes, $device = '' ) {
175 return [ 'color' => Color::get_css( isset( $attributes['lock_icon_hover'] ) ? $attributes['lock_icon_hover'] : '' ) ];
176 }
177
178 public function get_icon_css( $attributes, $device = '' ) {
179 return array_merge(
180 [ 'color' => Color::get_css( isset( $attributes['lock_icon_color'] ) ? $attributes['lock_icon_color'] : '' ) ],
181 Range::get_css([
182 'attributeValue' => $attributes['lock_icon_size'],
183 'attribute_object_key' => 'value',
184 'isResponsive' => true,
185 'defaultValue' => 16,
186 'hasUnit' => true,
187 'unitDefaultValue' => 'px',
188 'property' => 'font-size',
189 'device' => $device,
190 ]),
191 );
192 }
193
194 public function get_read_icon_css( $attributes, $device = '' ) {
195 return array_merge(
196 [ 'color' => Color::get_css( isset( $attributes['read_icon_color'] ) ? $attributes['read_icon_color'] : '' ) ],
197 Range::get_css([
198 'attributeValue' => $attributes['readIconSize'],
199 'attribute_object_key' => 'value',
200 'isResponsive' => true,
201 'defaultValue' => 16,
202 'hasUnit' => true,
203 'unitDefaultValue' => 'px',
204 'property' => 'font-size',
205 'device' => $device,
206 ]),
207 );
208
209 }
210 public function get_read_icon_hover_css( $attributes, $device = '' ) {
211 return [ 'color' => Color::get_css( isset( $attributes['read_icon_hover'] ) ? $attributes['read_icon_hover'] : '' ) ];
212 }
213
214 public function render_block_content( $attributes, $content, $block_instance ) {
215 $course_addition_info_id = method_exists( Helper::class, 'get_attribute_value' ) ? (int) Helper::get_attribute_value( $attributes, 'course_id' ) : (int) ( $attributes['course_id'] ?? 0 );
216 $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 ) . '"';
217 $course_addition_info_shortcode = '[academy_single_course_curriculums ' . trim( $course_addition_info_attr ) . ']';
218 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
219 $course_addition_info_is_edit = defined( 'REST_REQUEST' ) && REST_REQUEST && ( $_REQUEST['context'] ?? '' ) === 'edit';
220 if ( $course_addition_info_is_edit && $course_addition_info_id && ( $course_addition_info_post = get_post( $course_addition_info_id ) ) ) {
221 global $post, $wp_query;
222 $course_addition_info_prev_post = $post;
223 $course_addition_info_prev_query = $wp_query;
224 $post = $course_addition_info_post;
225 setup_postdata( $post );
226 $wp_query = new \WP_Query( [
227 'p' => $course_addition_info_id,
228 'post_type' => $course_addition_info_post->post_type,
229 'no_found_rows' => 1,
230 'posts_per_page' => 1
231 ] );
232 $wp_query->is_singular = 1;
233 $wp_query->is_single = ( $course_addition_info_post->post_type !== 'page' );
234 $wp_query->is_page = ( $course_addition_info_post->post_type === 'page' );
235 $wp_query->is_home = $wp_query->is_front_page = 0;
236 if ( method_exists( $wp_query, 'set' ) ) {
237 $wp_query->set( 'is_main_query', 1 );
238 }
239 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
240 wp_reset_postdata();
241 $wp_query = $course_addition_info_prev_query;
242 $post = $course_addition_info_prev_post;
243 } else {
244 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
245 }//end if
246 if ( $course_addition_info_is_edit && trim( wp_strip_all_tags( $course_addition_info_html ) ) === '' ) {
247 $course_addition_info_html = '<div class="no-data-message"><strong>Editor Only:</strong> No output. Check course ID or data.</div>';
248 }
249 return $course_addition_info_html;
250 }
251
252 }
253