PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 3.1.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v3.1.2
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 3.1.2, at includes/Core/Util/Utilities.php

140 lines 4.0 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 // IMPORTANT:
12 // For wp.org (free) distribution we treat "Pro" as "Pro addon is installed/active".
13 // License enforcement must live inside the Pro addon, not in the free plugin.
14 return class_exists('BitCode\\BitFormPro\\Plugin');
15 }
16
17 /**
18 * Kept for backward compatibility where the free plugin needs to know if a Pro
19 * license is marked active. Prefer checking license inside the Pro addon.
20 */
21 public static function isProLicensed(): bool
22 {
23 if (!self::isPro()) {
24 return false;
25 }
26 if (class_exists('BitCode\\BitFormPro\\Core\\Util\\LicenseHelper')) {
27 return \BitCode\BitFormPro\Core\Util\LicenseHelper::hasValidLicense();
28 }
29 $integrateData = get_option('bitformpro_integrate_key_data');
30
31 return !empty($integrateData)
32 && is_array($integrateData)
33 && !empty($integrateData['status'])
34 && 'success' === $integrateData['status'];
35 }
36
37 public static function getRealPath($dir, $name)
38 {
39 if (!isset($dir)) {
40 return false;
41 }
42 $directories = array_diff(scandir($dir), ['..', '.']);
43 $name = strtolower($name);
44
45 foreach ($directories as $directory) {
46 $dirLower = strtolower($directory);
47 if ($dirLower === $name) {
48 return $directory;
49 }
50 }
51
52 return false;
53 }
54
55 public static function getFileNameExceptExtension($filename)
56 {
57 $path_parts = pathinfo($filename);
58 return $path_parts['filename'];
59 }
60
61 public static function styleGenerator($styleObj, $important = false)
62 {
63 if (is_array($styleObj)) {
64 $styleObj = json_decode(wp_json_encode($styleObj));
65 }
66 $important = $important ? '!important' : '';
67 $classes = array_keys((array) $styleObj);
68 $css = '';
69 foreach ($classes as $class) {
70 $css .= $class;
71 $props = (array) $styleObj->{$class};
72 $propsKeys = array_keys($props);
73 $styleObject = '{';
74 foreach ($propsKeys as $property) {
75 $value = $props[$property];
76 if (empty($value)) {
77 continue;
78 }
79 if (is_object($value)) {
80 continue;
81 }
82 $styleObject .= "{$property}:{$value}{$important};";
83 }
84 $styleObject = rtrim($styleObject, ';');
85 $styleObject .= '}';
86 $css .= $styleObject;
87 }
88
89 return $css;
90 }
91
92 public static function convertToCSS(array $styles): string
93 {
94 $css = '';
95
96 foreach ($styles as $selector => $properties) {
97 $css .= "$selector{";
98
99 // Check if the properties are an array, meaning it's a nested rule (e.g., media queries, keyframes)
100 if (is_array($properties)) {
101 // If it's a nested array (media query or keyframe), recursively handle it
102 foreach ($properties as $property => $value) {
103 if (is_array($value)) {
104 // Recursively process nested arrays (media queries, keyframes, etc.)
105 $css .= self::convertToCSS([$property => $value]);
106 } else {
107 // Regular CSS property
108 $css .= "$property:$value;";
109 }
110 }
111 }
112
113 $css .= '}';
114 }
115
116 return $css;
117 }
118
119 public static function appendCSS($formId, $css, $mode = 'a')
120 {
121 $fileName = '';
122 $path = '';
123 $path = 'form-styles';
124 $fileName = "bitform-{$formId}.css";
125 Helpers::saveFile($path, $fileName, $css, $mode);
126 $fileName = "bitform-{$formId}-formid.css";
127 Helpers::saveFile($path, $fileName, $css, $mode);
128 }
129
130 public static function duplicateDbTable($oldTableName, $newTableName)
131 {
132 global $wpdb;
133 $oldTable = "{$wpdb->prefix}bitforms_{$oldTableName}";
134 $newTable = "{$wpdb->prefix}bitforms_{$newTableName}";
135 // Schema operation: table name interpolation only (no user input). $wpdb->prepare() cannot parameterize DDL statements.
136 $wpdb->query("CREATE TABLE IF NOT EXISTS `{$newTable}` LIKE `{$oldTable}`");
137 $wpdb->query("INSERT INTO `{$newTable}` SELECT * FROM `{$oldTable}`");
138 }
139 }
140