PluginProbe
Tableberg – Simple Gutenberg Table Block / 0.4.1
Tableberg – Simple Gutenberg Table Block v0.4.1
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 0.5.8 All 41 releases
tableberg / includes / Utils / Utils.php

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

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