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
← All changes | includes/blocks/table/block.php +239 -0 2.7.7 → 2.14.0 View file →
@@ -1,0 +1,239 @@
1 +<?php
2 +namespace ABlocks\Blocks\Table;
3 +
4 +if ( ! defined( 'ABSPATH' ) ) {
5 + exit;
6 +}
7 +
8 +use ABlocks\Classes\BlockBaseAbstract;
9 +use ABlocks\Classes\CssGenerator;
10 +use ABlocks\Controls\Border;
11 +use ABlocks\Classes\CssGeneratorV2;
12 +use ABlocks\Controls\Color;
13 +
14 +class Block extends BlockBaseAbstract {
15 + protected $block_name = 'table';
16 +
17 + public function build_css_v1( $attributes ) {
18 + $css_generator = new CssGenerator( $attributes, $this->block_name );
19 + $css_generator->add_class_styles(
20 + '{{WRAPPER}}.ablocks-block--table table',
21 + $this->get_table_css( $attributes )
22 + );
23 + $css_generator->add_class_styles(
24 + '{{WRAPPER}}.ablocks-block--table table, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell , {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell',
25 + $this->get_table_border_css( $attributes ),
26 + $this->get_table_border_css( $attributes, 'Tablet' ),
27 + $this->get_table_border_css( $attributes, 'Mobile' ),
28 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_css( $attributes, $device ); } )
29 + );
30 + $css_generator->add_class_styles(
31 + '{{WRAPPER}}.ablocks-block--table table:hover, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell:hover, {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell:hover',
32 + $this->get_table_border_hover_css( $attributes ),
33 + $this->get_table_border_hover_css( $attributes, 'Tablet' ),
34 + $this->get_table_border_hover_css( $attributes, 'Mobile' ),
35 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_hover_css( $attributes, $device ); } )
36 + );
37 + $css_generator->add_class_styles(
38 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd',
39 + $this->get_row_odd_css( $attributes )
40 + );
41 + $css_generator->add_class_styles(
42 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd:hover',
43 + $this->get_row_odd_hover_css( $attributes )
44 + );
45 + $css_generator->add_class_styles(
46 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even',
47 + $this->get_row_even_css( $attributes )
48 + );
49 + $css_generator->add_class_styles(
50 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even:hover',
51 + $this->get_row_even_hover_css( $attributes )
52 + );
53 + // ---header----
54 + $css_generator->add_class_styles(
55 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header',
56 + $this->get_header_css( $attributes )
57 + );
58 + $css_generator->add_class_styles(
59 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header:hover',
60 + $this->get_header_hover_css( $attributes )
61 + );
62 + // --table body----
63 + $css_generator->add_class_styles(
64 + '{{WRAPPER}} .ablocks-block--table-body',
65 + $this->get_body_css( $attributes )
66 + );
67 + $css_generator->add_class_styles(
68 + '{{WRAPPER}} .ablocks-block--table-body:hover',
69 + $this->get_body_hover_css( $attributes )
70 + );
71 +
72 + // --table footer--
73 + $css_generator->add_class_styles(
74 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer',
75 + $this->get_footer_css( $attributes )
76 + );
77 + $css_generator->add_class_styles(
78 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer:hover',
79 + $this->get_footer_hover_css( $attributes )
80 + );
81 + return $css_generator->generate_css();
82 + }
83 + public function build_css_v2( $attributes ) {
84 + $css_generator = new CssGeneratorV2( $attributes, $this->block_name );
85 + $css_generator->add_class_styles(
86 + '{{WRAPPER}}.ablocks-block--table table',
87 + $this->get_table_css( $attributes )
88 + );
89 + $css_generator->add_class_styles(
90 + '{{WRAPPER}}.ablocks-block--table table, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell , {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell',
91 + $this->get_table_border_css( $attributes ),
92 + $this->get_table_border_css( $attributes, 'Tablet' ),
93 + $this->get_table_border_css( $attributes, 'Mobile' ),
94 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_css( $attributes, $device ); } )
95 + );
96 + $css_generator->add_class_styles(
97 + '{{WRAPPER}}.ablocks-block--table table:hover, {{WRAPPER}}.ablocks-block--table-header .ablocks-block--table-cell:hover, {{WRAPPER}}.ablocks-block--table .ablocks-block--table-cell:hover',
98 + $this->get_table_border_hover_css( $attributes ),
99 + $this->get_table_border_hover_css( $attributes, 'Tablet' ),
100 + $this->get_table_border_hover_css( $attributes, 'Mobile' ),
101 + $css_generator->custom_device_map( function ( $device ) use ( $attributes ) { return $this->get_table_border_hover_css( $attributes, $device ); } )
102 + );
103 + $css_generator->add_class_styles(
104 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd',
105 + $this->get_row_odd_css( $attributes )
106 + );
107 + $css_generator->add_class_styles(
108 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--odd:hover',
109 + $this->get_row_odd_hover_css( $attributes )
110 + );
111 + $css_generator->add_class_styles(
112 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even',
113 + $this->get_row_even_css( $attributes )
114 + );
115 + $css_generator->add_class_styles(
116 + '{{WRAPPER}} .ablocks-block--table-body .ablocks-table-row--even:hover',
117 + $this->get_row_even_hover_css( $attributes )
118 + );
119 + // ---header----
120 + $css_generator->add_class_styles(
121 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header',
122 + $this->get_header_css( $attributes )
123 + );
124 + $css_generator->add_class_styles(
125 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-header:hover',
126 + $this->get_header_hover_css( $attributes )
127 + );
128 + // --table body----
129 + $css_generator->add_class_styles(
130 + '{{WRAPPER}} .ablocks-block--table-body',
131 + $this->get_body_css( $attributes )
132 + );
133 + $css_generator->add_class_styles(
134 + '{{WRAPPER}} .ablocks-block--table-body:hover',
135 + $this->get_body_hover_css( $attributes )
136 + );
137 +
138 + // --table footer--
139 + $css_generator->add_class_styles(
140 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer',
141 + $this->get_footer_css( $attributes )
142 + );
143 + $css_generator->add_class_styles(
144 + '{{WRAPPER}}.ablocks-block--table .ablocks-block--table-footer:hover',
145 + $this->get_footer_hover_css( $attributes )
146 + );
147 + return $css_generator->generate_css();
148 + }
149 + public function build_css( $attributes ) {
150 + if ( isset( $attributes['blockVersion'] ) && (int) $attributes['blockVersion'] === 2 ) {
151 + return $this->build_css_v2( $attributes );
152 + }
153 + return $this->build_css_v1( $attributes );
154 + }
155 + public function get_table_css( $attributes, $device = '' ) {
156 + $css = [];
157 +
158 + if ( ! empty( $attributes['borderCollapse'] ) && $attributes['borderCollapse'] === 'collapse' ) {
159 + $css['border-collapse'] = 'collapse';
160 + } elseif ( ! empty( $attributes['borderCollapse'] ) && $attributes['borderCollapse'] === 'separate' ) {
161 + $css['border-collapse'] = 'separate';
162 + }
163 +
164 + return $css;
165 + }
166 +
167 + public function get_table_border_css( $attributes, $device = '' ) {
168 +
169 + return Border::get_css( $attributes['border'], '', $device );
170 +
171 + }
172 + public function get_table_border_hover_css( $attributes, $device = '' ) {
173 +
174 + return Border::get_hover_css( $attributes['border'], '', $device );
175 + }
176 +
177 + public function get_row_odd_css( $attributes, $device = '' ) {
178 + return [ 'background' => Color::get_css( isset( $attributes['rowOddColor'] ) ? $attributes['rowOddColor'] : '' ) ];
179 + }
180 +
181 + public function get_row_odd_hover_css( $attributes, $device = '' ) {
182 + return [ 'background' => Color::get_css( isset( $attributes['rowOddColorH'] ) ? $attributes['rowOddColorH'] : '' ) ];
183 + }
184 +
185 + public function get_row_even_css( $attributes, $device = '' ) {
186 + return [ 'background' => Color::get_css( isset( $attributes['rowEvenColor'] ) ? $attributes['rowEvenColor'] : '' ) ];
187 + }
188 +
189 + public function get_row_even_hover_css( $attributes, $device = '' ) {
190 + return [ 'background' => Color::get_css( isset( $attributes['rowEvenColorH'] ) ? $attributes['rowEvenColorH'] : '' ) ];
191 + }
192 +
193 + public function get_header_css( $attributes, $device = '' ) {
194 + $css = [];
195 + $css['background'] = Color::get_css(
196 + isset( $attributes['headerColor'] ) ? $attributes['headerColor'] : '') . ' !important';
197 + return $css;
198 + }
199 +
200 + public function get_header_hover_css( $attributes, $device = '' ) {
201 + $css = [];
202 + $css['background'] = Color::get_css(
203 + isset( $attributes['headerColorH'] ) ? $attributes['headerColorH'] : '') . ' !important';
204 +
205 + return $css;
206 + }
207 +
208 + public function get_body_css( $attributes, $device = '' ) {
209 + $css = [];
210 + $css['background'] = Color::get_css(
211 + isset( $attributes['bodyBg'] ) ? $attributes['bodyBg'] : '') . ' !important';
212 + return $css;
213 + }
214 +
215 + public function get_body_hover_css( $attributes, $device = '' ) {
216 + $css = [];
217 + $css['background'] = Color::get_css(
218 + isset( $attributes['bodyBgH'] ) ? $attributes['bodyBgH'] : '') . ' !important';
219 +
220 + return $css;
221 + }
222 +
223 + public function get_footer_css( $attributes, $device = '' ) {
224 + $css = [];
225 + $css['background'] = Color::get_css(
226 + isset( $attributes['footerColor'] ) ? $attributes['footerColor'] : '') . ' !important';
227 +
228 + return $css;
229 + }
230 +
231 + public function get_footer_hover_css( $attributes, $device = '' ) {
232 + $css = [];
233 +
234 + $css['background'] = Color::get_css(
235 + isset( $attributes['footerColorH'] ) ? $attributes['footerColorH'] : '') . ' !important';
236 +
237 + return $css;
238 + }
239 +}