PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.10.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.10.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.10.0, at includes/blocks/academy-addition-info/block.php

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