PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.12.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.12.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.12.0, at includes/blocks/academy-course-curriculums/block.php

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