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

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

234 lines 10.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\AcademyAdditionInfo;
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-addition-info';
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--benefits .benefits-title',
29 $this->get_heading_css( $attributes, '' ),
30 $this->get_heading_css( $attributes, 'Tablet' ),
31 $this->get_heading_css( $attributes, 'Mobile' ),
32 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_css( $attributes, $device ); } )
33 );
34
35 $css_generator->add_class_styles(
36 '{{WRAPPER}} .academy-single-course__content-item--benefits .benefits-title:hover',
37 $this->get_heading_hover_css( $attributes, '' ),
38 $this->get_heading_hover_css( $attributes, 'Tablet' ),
39 $this->get_heading_hover_css( $attributes, 'Mobile' ),
40 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_heading_hover_css( $attributes, $device ); } )
41 );
42
43 $css_generator->add_class_styles(
44 '{{WRAPPER}} .academy-single-course__content-item--benefits .benefits-content ul li span,
45 {{WRAPPER}} .academy-tabs-content .academy-lists li span',
46 $this->get_list_css( $attributes, '' ),
47 $this->get_list_css( $attributes, 'Tablet' ),
48 $this->get_list_css( $attributes, 'Mobile' ),
49 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_css( $attributes, $device ); } )
50 );
51
52 $css_generator->add_class_styles(
53 '{{WRAPPER}} .academy-single-course__content-item--benefits .benefits-content ul li span:hover,
54 {{WRAPPER}} .academy-tabs-content .academy-lists li span:hover',
55 $this->get_list_hover_css( $attributes, '' ),
56 $this->get_list_hover_css( $attributes, 'Tablet' ),
57 $this->get_list_hover_css( $attributes, 'Mobile' ),
58 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_list_hover_css( $attributes, $device ); } )
59 );
60 $css_generator->add_class_styles(
61 '{{WRAPPER}} .academy-single-course__content-item--additional-info .academy-tabs-nav li a',
62 $this->get_tab_css( $attributes, '' ),
63 $this->get_tab_css( $attributes, 'Tablet' ),
64 $this->get_tab_css( $attributes, 'Mobile' ),
65 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_tab_css( $attributes, $device ); } )
66 );
67
68 $css_generator->add_class_styles(
69 '{{WRAPPER}} .academy-single-course__content-item--additional-info .academy-tabs-nav li a:hover',
70 $this->get_tab_hover_css( $attributes, '' ),
71 $this->get_tab_hover_css( $attributes, 'Tablet' ),
72 $this->get_tab_hover_css( $attributes, 'Mobile' ),
73 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_tab_hover_css( $attributes, $device ); } )
74 );
75
76 $css_generator->add_class_styles(
77 '{{WRAPPER}} .academy-tabs-nav li.active',
78 $this->get_active_list_css( $attributes, '' ),
79 $this->get_active_list_css( $attributes, 'Tablet' ),
80 $this->get_active_list_css( $attributes, 'Mobile' ),
81 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_active_list_css( $attributes, $device ); } )
82 );
83
84 $css_generator->add_class_styles(
85 '{{WRAPPER}} .academy-tabs-nav li.active',
86 $this->get_active_list_hover_css( $attributes, '' ),
87 $this->get_active_list_hover_css( $attributes, 'Tablet' ),
88 $this->get_active_list_hover_css( $attributes, 'Mobile' ),
89 $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_active_list_hover_css( $attributes, $device ); } )
90 );
91
92 return $css_generator->generate_css();
93 }
94
95 public function get_heading_css( $attributes, $device = '' ) {
96 $typographyValueGlobal = ! empty( $attributes['headingTypographyGlobal'] ) ? $attributes['headingTypographyGlobal'] : '';
97 $typography_value = ! empty( $attributes['headingTypography'] ) ?
98 Typography::get_css( $attributes['headingTypography'], '', $device, $typographyValueGlobal )
99 : array();
100
101 return array_merge(
102 [ 'color' => Color::get_css( isset( $attributes['headingColor'] ) ? $attributes['headingColor'] : '#111' ) ],
103 $typography_value,
104 );
105 }
106
107 public function get_heading_hover_css( $attributes, $device = '' ) {
108 return array_merge(
109 [ 'color' => Color::get_css( isset( $attributes['headingColorH'] ) ? $attributes['headingColorH'] : '#111' ) ],
110 Range::get_css([
111 'attributeValue' => $attributes['headingTransition'],
112 'attribute_object_key' => 'value',
113 'isResponsive' => false,
114 'defaultValue' => 0,
115 'hasUnit' => false,
116 'unitDefaultValue' => 's',
117 'property' => 'transition-duration',
118 'device' => $device,
119 ]),
120 );
121
122 }
123 public function get_list_css( $attributes, $device = '' ) {
124 $typographyValueGlobal = ! empty( $attributes['listTypographyGlobal'] ) ? $attributes['listTypographyGlobal'] : '';
125 $typography_value = ! empty( $attributes['listTypography'] ) ?
126 Typography::get_css( $attributes['listTypography'], '', $device, $typographyValueGlobal )
127 : array();
128
129 return array_merge(
130 [ 'color' => Color::get_css( isset( $attributes['listColor'] ) ? $attributes['listColor'] : '#111' ) ],
131 $typography_value,
132 );
133 }
134
135 public function get_list_hover_css( $attributes, $device = '' ) {
136 return array_merge(
137 [ 'color' => Color::get_css( isset( $attributes['listColorH'] ) ? $attributes['listColorH'] : '#111' ) ],
138 Range::get_css([
139 'attributeValue' => $attributes['listTransition'],
140 'attribute_object_key' => 'value',
141 'isResponsive' => false,
142 'defaultValue' => 0,
143 'hasUnit' => false,
144 'unitDefaultValue' => 's',
145 'property' => 'transition-duration',
146 'device' => $device,
147 ]),
148 );
149
150 }
151 public function get_tab_css( $attributes, $device = '' ) {
152 $typographyValueGlobal = ! empty( $attributes['tabTypographyGlobal'] ) ? $attributes['tabTypographyGlobal'] : '';
153 $typography_value = ! empty( $attributes['tabTypography'] ) ?
154 Typography::get_css( $attributes['tabTypography'], '', $device, $typographyValueGlobal )
155 : array();
156
157 return array_merge(
158 [ 'color' => Color::get_css( isset( $attributes['tabColor'] ) ? $attributes['tabColor'] : '#111' ) ],
159 $typography_value,
160 );
161 }
162
163 public function get_tab_hover_css( $attributes, $device = '' ) {
164 return array_merge(
165 [ 'color' => Color::get_css( isset( $attributes['tabColorH'] ) ? $attributes['tabColorH'] : '#111' ) ],
166 Range::get_css([
167 'attributeValue' => $attributes['tabTransition'],
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_active_list_css( $attributes, $device = '' ) {
180 $border_value = Border::get_css( $attributes['listBorder'], '', $device ) ?? [];
181 $margin_value = Dimensions::get_css( $attributes['listMargin'], 'margin', $device ) ?? [];
182
183 return array_merge(
184 Border::get_css( $attributes['listBorder'], '', $device ),
185 Dimensions::get_css( $attributes['listMargin'], 'margin', $device ),
186 );
187 }
188
189 public function get_active_list_hover_css( $attributes, $device = '' ) {
190 $border_value = Border::get_hover_css( $attributes['listBorder'], '', $device ) ?? [];
191
192 return $border_value;
193 }
194
195 public function render_block_content( $attributes, $content, $block_instance ) {
196 $course_addition_info_id = method_exists( Helper::class, 'get_attribute_value' ) ? (int) Helper::get_attribute_value( $attributes, 'course_id' ) : (int) ( $attributes['course_id'] ?? 0 );
197 $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 ) . '"';
198 $course_addition_info_shortcode = '[academy_single_course_addition_info ' . trim( $course_addition_info_attr ) . ']';
199 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
200 $course_addition_info_is_edit = defined( 'REST_REQUEST' ) && REST_REQUEST && ( $_REQUEST['context'] ?? '' ) === 'edit';
201 if ( $course_addition_info_is_edit && $course_addition_info_id && ( $course_addition_info_post = get_post( $course_addition_info_id ) ) ) {
202 global $post, $wp_query;
203 $course_addition_info_prev_post = $post;
204 $course_addition_info_prev_query = $wp_query;
205 $post = $course_addition_info_post;
206 setup_postdata( $post );
207 $wp_query = new \WP_Query( [
208 'p' => $course_addition_info_id,
209 'post_type' => $course_addition_info_post->post_type,
210 'no_found_rows' => 1,
211 'posts_per_page' => 1
212 ] );
213 $wp_query->is_singular = 1;
214 $wp_query->is_single = ( $course_addition_info_post->post_type !== 'page' );
215 $wp_query->is_page = ( $course_addition_info_post->post_type === 'page' );
216 $wp_query->is_home = $wp_query->is_front_page = 0;
217 if ( method_exists( $wp_query, 'set' ) ) {
218 $wp_query->set( 'is_main_query', 1 );
219 }
220 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
221 wp_reset_postdata();
222 $wp_query = $course_addition_info_prev_query;
223 $post = $course_addition_info_prev_post;
224 } else {
225 $course_addition_info_html = do_shortcode( $course_addition_info_shortcode );
226 }//end if
227 if ( $course_addition_info_is_edit && trim( wp_strip_all_tags( $course_addition_info_html ) ) === '' ) {
228 $course_addition_info_html = '<div class="no-data-message"><strong>Editor Only:</strong> No output. Check course ID or data.</div>';
229 }
230 return $course_addition_info_html;
231 }
232
233 }
234