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
← All changes | includes/Core/WorkFlow/Helper.php +56 -15 2.02.21.4 View file →
@@ -6,16 +6,19 @@
6 6 use BitCode\BitForm\Core\Messages\SuccessMessageHandler;
7 7 use BitCode\BitForm\Core\Util\FieldValueHandler;
8 8 use BitCode\BitForm\Core\Util\SmartTags;
9 9
10 -final class Helper {
11 - public static function getFieldData($fields) {
10 +final class Helper
11 +{
12 + public static function getFieldData($fields)
13 + {
12 14 $fieldData = [];
13 15
14 16 foreach ($fields as $fieldKey => $fieldDetail) {
17 + $value = isset($fieldDetail->val) ? $fieldDetail->val : (isset($fieldDetail->defaultValue) ? $fieldDetail->defaultValue : '');
15 18 $fieldData[$fieldKey] = [
16 19 'key' => $fieldKey,
17 - 'value' => empty($fieldDetail->val) ? '' : $fieldDetail->val,
20 + 'value' => $value,
18 21 'type' => $fieldDetail->typ,
19 22 ];
20 23 if (isset($fieldDetail->mul)) {
21 24 $fieldData[$fieldKey] =
@@ -21,9 +24,9 @@
21 24 $fieldData[$fieldKey] =
22 25 array_merge(
23 26 $fieldData[$fieldKey],
24 27 [
25 - 'mul' => true,
28 + 'mul' => $fieldDetail->mul,
26 29 ]
27 30 );
28 31 }
29 32 }
@@ -29,9 +32,10 @@
29 32 }
30 33 return $fieldData;
31 34 }
32 35
33 - public static function smartFldMargeFormFld($logics, $fieldData) {
36 + public static function smartFldMargeFormFld($logics, $fieldData)
37 + {
34 38 $fieldKeys = SmartTags::smartTagFieldKeys();
35 39
36 40 foreach ($logics as $logic) {
37 41 $removeSpecialStr = ['${', '}', '()'];
@@ -51,10 +55,11 @@
51 55 }
52 56 return $fieldData;
53 57 }
54 58
55 - public static function replaceFieldWithValue($stringToReplaceField, $fieldValues, $evalMathExpr = true) {
56 - $stringToReplaceField = FieldValueHandler::replaceFieldWithValue($stringToReplaceField, $fieldValues);
59 + public static function replaceFieldWithValue($stringToReplaceField, $fieldValues, $evalMathExpr = true, $formID = null)
60 + {
61 + $stringToReplaceField = FieldValueHandler::replaceFieldWithValue($stringToReplaceField, $fieldValues, $formID);
57 62 if ($evalMathExpr) {
58 63 return self::evalMathExpression($stringToReplaceField);
59 64 }
60 65 return $stringToReplaceField;
@@ -59,9 +64,10 @@
59 64 }
60 65 return $stringToReplaceField;
61 66 }
62 67
63 - public static function setDefaultSubmitConfirmation($confirmationType, $fieldValue, $formId, $logID = 0) {
68 + public static function setDefaultSubmitConfirmation($confirmationType, $fieldValue, $formId, $logID = 0)
69 + {
64 70 $messageId = 0;
65 71 $returnableData = null;
66 72 return [
67 73 'msg_id' => $messageId,
@@ -103,9 +109,10 @@
103 109 'confirmation' => $returnableData,
104 110 ];
105 111 }
106 112
107 - public static function calculte($firstOperand, $secondOperand, $operator) {
113 + public static function calculte($firstOperand, $secondOperand, $operator)
114 + {
108 115 switch ($operator) {
109 116 case '+':
110 117 return $firstOperand + $secondOperand;
111 118 case '-':
@@ -118,13 +125,15 @@
118 125 return $firstOperand ** $secondOperand;
119 126 }
120 127 }
121 128
122 - public static function filterMailContentType() {
129 + public static function filterMailContentType()
130 + {
123 131 return 'text/html';
124 132 }
125 133
126 - public static function evalMathExpression($stringWithFieldValue) {
134 + public static function evalMathExpression($stringWithFieldValue)
135 + {
127 136 $mathExpr = $stringWithFieldValue;
128 137 if (empty($mathExpr)) {
129 138 return $stringWithFieldValue;
130 139 }
@@ -146,9 +155,9 @@
146 155 if (!in_array(trim($value), $validOperator)) {
147 156 return $stringWithFieldValue;
148 157 }
149 158 }
150 - $mathExpr = str_replace(' ', null, $mathExpr);
159 + $mathExpr = str_replace(' ', '', $mathExpr);
151 160 $mathExpr = preg_replace('/\{|\[|\(/', '(', $mathExpr);
152 161 $mathExpr = preg_replace('/\}|\]/', ')', $mathExpr);
153 162 $calculated = self::infixToPostfixEvalute($mathExpr);
154 163 if (!is_null($calculated)) {
@@ -157,9 +166,10 @@
157 166
158 167 return (string) $stringWithFieldValue;
159 168 }
160 169
161 - public static function infixToPostfixEvalute($expression) {
170 + public static function infixToPostfixEvalute($expression)
171 + {
162 172 $operatorStack = [];
163 173 $outputQueue = [];
164 174 $numTemp = null;
165 175 for ($strIndex = 0; $strIndex < strlen($expression); $strIndex++) {
@@ -214,9 +224,10 @@
214 224 }
215 225 return $resultStack;
216 226 }
217 227
218 - public static function operatorPrecedence($operator) {
228 + public static function operatorPrecedence($operator)
229 + {
219 230 $precedence = [
220 231 '+' => 2,
221 232 '-' => 2,
222 233 '*' => 3,
@@ -226,9 +237,10 @@
226 237
227 238 return isset($precedence[$operator]) ? $precedence[$operator] : 0;
228 239 }
229 240
230 - public static function calculate($firstOperand, $secondOperand, $operator) {
241 + public static function calculate($firstOperand, $secondOperand, $operator)
242 + {
231 243 $calculated = [
232 244 '+' => $firstOperand + $secondOperand,
233 245 '-' => $firstOperand - $secondOperand,
234 246 '*' => $firstOperand * $secondOperand,
@@ -236,6 +248,35 @@
236 248 '^' => $firstOperand ** $secondOperand,
237 249 ];
238 250
239 251 return isset($calculated[$operator]) ? $calculated[$operator] : '';
252 + }
253 +
254 + /**
255 + * Recursively sets a nested property in a given object.
256 + *
257 + * This function takes an object, a string path representing nested properties
258 + * (e.g., "fk->valid->hide"), and a value to assign. It ensures that all
259 + * intermediate properties exist as objects before setting the final value.
260 + *
261 + * @param object $object The main object where properties should be set.
262 + * @param string $path The nested property path, with keys separated by "->".
263 + * @param mixed $value The value to assign to the final property.
264 + *
265 + * @return void
266 + */
267 + public static function setNestedProperty(&$object, $path, $value)
268 + {
269 + $keys = explode('->', $path);
270 + $key = array_shift($keys);
271 +
272 + if (!isset($object->$key) || !is_object($object->$key)) {
273 + $object->$key = new \stdClass();
274 + }
275 +
276 + if (!empty($keys)) {
277 + self::setNestedProperty($object->$key, implode('->', $keys), $value);
278 + } else {
279 + $object->$key = $value;
280 + }
240 281 }
241 282 }