PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.21.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.21.4
V-3.3.0 3.2.2 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 V3.0.3 V3.0.2 -3.0.1 V_3.0.0 1.1.1 1.1.8 1.2 1.3 1.4 1.4.18 1.5.2 1.9 2.0 2.10.0 2.10.1 2.10.2 All 137 releases
bit-form / includes / Core / Util / Utilities.php

Utilities.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.21.4, at includes/Core/Util/Utilities.php

126 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace BitCode\BitForm\Core\Util;
4
5 use BitCode\BitForm\Admin\Form\Helpers;
6
7 final class Utilities
8 {
9 public static function isPro()
10 {
11 $integrateData = get_option('bitformpro_integrate_key_data');
12 $isProLicenseActivated = !empty($integrateData) && is_array($integrateData) && 'success' === $integrateData['status'];
13 return class_exists('BitCode\\BitFormPro\\Plugin') && $isProLicenseActivated;
14 }
15
16 public static function getRealPath($dir, $name)
17 {
18 if (!isset($dir)) {
19 return false;
20 }
21 $directories = array_diff(scandir($dir), ['..', '.']);
22 $name = strtolower($name);
23
24 foreach ($directories as $directory) {
25 $dirLower = strtolower($directory);
26 if ($dirLower === $name) {
27 return $directory;
28 }
29 }
30
31 return false;
32 }
33
34 public static function getFileNameExceptExtension($filename)
35 {
36 $path_parts = pathinfo($filename);
37 return $path_parts['filename'];
38 }
39
40 public static function styleGenerator($styleObj, $important = false)
41 {
42 if (is_array($styleObj)) {
43 $styleObj = json_decode(wp_json_encode($styleObj));
44 }
45 $important = $important ? '!important' : '';
46 $classes = array_keys((array) $styleObj);
47 $css = '';
48 foreach ($classes as $class) {
49 $css .= $class;
50 $props = (array) $styleObj->{$class};
51 $propsKeys = array_keys($props);
52 $styleObject = '{';
53 foreach ($propsKeys as $property) {
54 $value = $props[$property];
55 if (empty($value)) {
56 continue;
57 }
58 if (is_object($value)) {
59 continue;
60 }
61 $styleObject .= "{$property}:{$value}{$important};";
62 }
63 $styleObject = rtrim($styleObject, ';');
64 $styleObject .= '}';
65 $css .= $styleObject;
66 }
67
68 return $css;
69 }
70
71 public static function convertToCSS(array $styles): string
72 {
73 $css = '';
74
75 foreach ($styles as $selector => $properties) {
76 $css .= "$selector{";
77
78 // Check if the properties are an array, meaning it's a nested rule (e.g., media queries, keyframes)
79 if (is_array($properties)) {
80 // If it's a nested array (media query or keyframe), recursively handle it
81 foreach ($properties as $property => $value) {
82 if (is_array($value)) {
83 // Recursively process nested arrays (media queries, keyframes, etc.)
84 $css .= self::convertToCSS([$property => $value]);
85 } else {
86 // Regular CSS property
87 $css .= "$property:$value;";
88 }
89 }
90 }
91
92 $css .= '}';
93 }
94
95 return $css;
96 }
97
98 public static function appendCSS($formId, $css, $mode = 'a')
99 {
100 $fileName = '';
101 $path = '';
102 $path = 'form-styles';
103 $fileName = "bitform-{$formId}.css";
104 Helpers::saveFile($path, $fileName, $css, $mode);
105 $fileName = "bitform-{$formId}-formid.css";
106 Helpers::saveFile($path, $fileName, $css, $mode);
107 }
108
109 public static function duplicateDbTable($oldTableName, $newTableName)
110 {
111 global $wpdb;
112 $oldTable = "{$wpdb->prefix}bitforms_{$oldTableName}";
113 $newTable = "{$wpdb->prefix}bitforms_{$newTableName}";
114 $wpdb->query(
115 $wpdb->prepare(
116 "CREATE TABLE IF NOT EXISTS $newTable LIKE $oldTable"
117 )
118 );
119 $wpdb->query(
120 $wpdb->prepare(
121 "INSERT $newTable SELECT * FROM $oldTable"
122 )
123 );
124 }
125 }
126