PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.2.1
Tableberg – Simple Gutenberg Table Block v0.2.1
1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.5 1.0.4 1.0.3 1.0.2 1.0.1 trunk 0.0.2 0.2.1 0.3.2 0.3.3 0.4.1 0.5.0 0.5.1 0.5.2 0.5.3 0.5.4 0.5.5 0.5.6 0.5.7 All 42 releases
tableberg / includes / Utils.php

Utils.php in Tableberg – Simple Gutenberg Table Block 0.2.1, at includes/Utils.php

300 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Table Block
5 *
6 * @package Tableberg
7 */
8
9 namespace Tableberg;
10
11 /**
12 * Styling Help full functions utility class
13 */
14 class Utils {
15
16 /**
17 * Get global font style variables for CSS.
18 * @return array CSS styles for the global font.
19 */
20 public static function get_global_style_variables_css( array $attributes) {
21 return [
22 '--tableberg-global-text-color' => $attributes['fontColor']??'',
23 '--tableberg-global-link-color' => $attributes['linkColor']??'',
24 '--tableberg-global-font-size' => $attributes['fontSize']??'',
25 ];
26 }
27
28 /**
29 * Get welcome page data.
30 *
31 * @return array
32 */
33 public static function welcome_page() {
34 return array(
35 'welcome' => array(
36 'title' => 'Welcome to Tableberg!',
37 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
38 ),
39 'documentation' => array(
40 'title' => 'Documentation',
41 'content' => 'Elevate your space with Tableberg: a sleek, modern table block for style and functionality. Crafted for timeless elegance and versatility.',
42 ),
43 'support' => array(
44 'title' => 'Support',
45 'content' => "Visit our Tableberg Support Page for quick solutions and assistance. We're here to ensure your Tableberg experience is seamless and satisfying.",
46 ),
47 'community' => array(
48 'title' => 'Join Community',
49 'content' => 'Join the vibrant Tableberg community. Connect, share, and discover endless possibilities together. Elevate your experience with like-minded enthusiasts now!',
50 ),
51 'upgrade' => array(
52 'title' => 'Upgrade to Tableberg PRO!',
53 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
54 ),
55 );
56 }
57 /**
58 * Get Individual Control.
59 *
60 * @return array
61 */
62 public static function individual_control() {
63 return array(
64 array(
65 'title' => 'Individual Control',
66 'name' => 'individual_control',
67 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
68 'active' => false,
69 ),
70 );
71 }
72 /**
73 * Get global control.
74 *
75 * @return array
76 */
77 public static function global_control() {
78 return array(
79 array(
80 'title' => 'Global Control',
81 'name' => 'global_control',
82 'content' => 'Elevate Your Content with Seamless Tables - The Ultimate WordPress Block Editor Plugin for Effortless Table Creation!',
83 'active' => true,
84 ),
85 );
86 }
87 /**
88 * Get default block properties.
89 *
90 * @return array
91 */
92 public static function default_block_properties() {
93 return array(
94 array(
95 'title' => 'Default Row Number',
96 'name' => 'row_number',
97 'content' => 'Set your default row number of the table when you add Tableberg to your site. Further you can increase or decrease it there simply.',
98 'value' => 3,
99 ),
100 array(
101 'title' => 'Default Column Number',
102 'name' => 'column_number',
103 'content' => 'Set your default column number of the table when you add Tableberg to your site. Further you can increase or decrease it there simply.',
104 'value' => 3,
105 ),
106 array(
107 'title' => 'Default Property Font Size',
108 'name' => 'font_size',
109 'content' => 'Set your default FONT SIZE of the PROPERTY of the table when you add Tableberg to your site. Further you can increase or decrease it there simply.',
110 'value' => 18,
111 ),
112 );
113 }
114 /**
115 * Check if border has split borders.
116 *
117 * @param array $border - block border.
118 * @return bool Whether the border has split sides.
119 */
120 public static function has_split_borders($border = array()) {
121 $sides = array('top', 'right', 'bottom', 'left');
122 foreach ($border as $side => $value) {
123 if (in_array($side, $sides, true)) {
124 return true;
125 }
126 }
127
128 return false;
129 }
130
131 /**
132 * Get the border CSS from attributes.
133 *
134 * @param array $object - block border.
135 * @return array CSS styles for the border.
136 */
137 public static function get_border_css($object) {
138 $css = array();
139
140 if (!self::has_split_borders($object)) {
141 $css['top'] = $object;
142 $css['right'] = $object;
143 $css['bottom'] = $object;
144 $css['left'] = $object;
145 return $css;
146 }
147
148 return $object;
149 }
150
151 /**
152 * Get the CSS value for a single side of the border.
153 *
154 * @param array $border - border.
155 * @param string $side - border side.
156 * @return string CSS value for the specified side.
157 */
158 public static function get_single_side_border_value($border, $side) {
159 $width = $border[$side]['width'] ?? '';
160 $style = $border[$side]['style'] ?? '';
161 $color = $border[$side]['color'] ?? '';
162
163 return "{$width} " . ($width && empty($border[$side]['style']) ? 'solid' : $style) . " {$color}";
164 }
165 /**
166 * Check if a value is considered empty based on certain conditions.
167 *
168 * @param mixed $value - The value to check.
169 * @return bool Whether the value is considered empty.
170 */
171 public static function is_value_empty($value) {
172 return (
173 self::is_undefined($value) ||
174 false === $value ||
175 trim($value) === '' ||
176 trim($value) === 'undefined undefined undefined' ||
177 empty($value)
178 );
179 }
180 /**
181 * Get border variables for CSS.
182 *
183 * @param array $border - border.
184 * @param string $slug - slug to use in variable.
185 * @return array CSS styles for the border variables.
186 */
187 public static function get_border_variables_css($border, $slug) {
188 $border_in_dimensions = self::get_border_css($border);
189 $border_sides = array('top', 'right', 'bottom', 'left');
190 $borders = array();
191
192 foreach ($border_sides as $side) {
193 $side_property = "--tableberg-{$slug}-border-{$side}";
194 $side_value = self::get_single_side_border_value($border_in_dimensions, $side);
195 $borders[$side_property] = $side_value;
196 }
197
198 return $borders;
199 }
200
201 /**
202 * Check if spacing value is preset or custom.
203 *
204 * @param string $value - spacing value.
205 * @return bool Whether the value is a preset or custom spacing.
206 */
207 public static function is_value_spacing_preset($value) {
208 if (!$value || !is_string($value)) {
209 return false;
210 }
211 return '0' === $value || strpos($value, 'var:preset|spacing|') === 0;
212 }
213
214 /**
215 * Return the spacing variable for CSS.
216 *
217 * @param string $value - spacing value.
218 * @return string CSS variable or the original value.
219 */
220 public static function get_spacing_preset_css_var($value) {
221 if (!$value) {
222 return null;
223 }
224
225 $matches = array();
226 preg_match('/var:preset\|spacing\|(.+)/', $value, $matches);
227
228 if (empty($matches)) {
229 return $value;
230 }
231 return "var(--wp--preset--spacing--{$matches[1]})";
232 }
233
234 /**
235 * Get the CSS for spacing.
236 *
237 * @param array $object - spacing object.
238 * @return array CSS styles for spacing.
239 */
240 public static function get_spacing_css($object) {
241 $css = array();
242
243 foreach ($object as $key => $value) {
244 if (self::is_value_spacing_preset($value)) {
245 $css[$key] = self::get_spacing_preset_css_var($value);
246 } else {
247 $css[$key] = $value;
248 }
249 }
250
251 return $css;
252 }
253
254 /**
255 * Check if a value is undefined.
256 *
257 * @param mixed $value - value.
258 * @return bool Whether the value is undefined.
259 */
260 public static function is_undefined($value) {
261 return null === $value || !isset($value) || empty($value);
262 }
263
264 /**
265 * Generate CSS string if value is not empty.
266 *
267 * @param array $styles - CSS styles.
268 * @return string Generated CSS string.
269 */
270 public static function generate_css_string($styles) {
271 $css_string = '';
272
273 foreach ($styles as $key => $value) {
274 if (!self::is_undefined($value) && false !== $value && trim($value) !== '' && trim($value) !== 'undefined undefined undefined' && !empty($value)) {
275 $css_string .= $key . ': ' . $value . '; ';
276 }
277 }
278
279 return $css_string;
280 }
281
282 /**
283 * Get background color or gradient.
284 *
285 * @param array $attributes - block attributes.
286 * @param string $color_attr_key - block background color attribute key.
287 * @param string $gradient_attr_key - block background gradient attribute key.
288 * @return string Background color or gradient.
289 */
290 public static function get_background_color($attributes, $color_attr_key, $gradient_attr_key) {
291 $bg_color = '';
292 if (!empty($attributes[$color_attr_key])) {
293 $bg_color = $attributes[$color_attr_key];
294 } elseif (!empty($attributes[$gradient_attr_key])) {
295 $bg_color = $attributes[$gradient_attr_key];
296 }
297 return $bg_color;
298 }
299 }
300