PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.15.3
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.15.3
3.3.1 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 All 138 releases
← All changes | includes/Core/Integration/IntegrationHandler.php +13 -180 -3.0.12.15.3 View file →
@@ -6,9 +6,8 @@
6 6 use BitCode\BitForm\Admin\Form\Helpers;
7 7 use BitCode\BitForm\Core\Database\FormEntryLogModel;
8 8 use BitCode\BitForm\Core\Database\FormEntryModel;
9 9 use BitCode\BitForm\Core\Database\IntegrationModel;
10 -use BitCode\BitForm\Core\Form\FormManager;
11 10 use BitCode\BitForm\Core\Util\FieldValueHandler;
12 11 use BitCode\BitForm\Core\Util\MailNotifier;
13 12 use BitCode\BitForm\Frontend\Form\FrontendFormManager;
14 13
@@ -217,13 +216,13 @@
217 216 }
218 217 $fieldPattern = '/\${\w[^ ${}]*}/';
219 218 preg_match_all($fieldPattern, $stringToReplaceField, $matchedField);
220 219 $uniqueFieldsInStr = array_unique($matchedField[0]);
221 -
222 - foreach ($uniqueFieldsInStr as $value) {
220 + foreach ($uniqueFieldsInStr as $key => $value) {
223 221 $fieldName = substr($value, 2, strlen($value) - 3);
224 222
225 223 $repeaterArr = explode('.', $fieldName);
224 +
226 225 if (isset($fieldValues[$fieldName])) {
227 226 $stringToReplaceField = is_string($fieldValues[$fieldName])
228 227 ? str_replace($value, $fieldValues[$fieldName], $stringToReplaceField)
229 228 : wp_json_encode($fieldValues[$fieldName]);
@@ -229,8 +228,9 @@
229 228 : wp_json_encode($fieldValues[$fieldName]);
230 229 } elseif (2 === count($repeaterArr) && isset($fieldValues[$repeaterArr[0]])) {
231 230 $repeaterValues = [];
232 231 $repeaterFieldValues = $fieldValues[$repeaterArr[0]];
232 +
233 233 foreach ($repeaterFieldValues as $value) {
234 234 if (isset($value[$repeaterArr[1]])) {
235 235 $repeaterValues[] = $value[$repeaterArr[1]];
236 236 }
@@ -236,10 +236,8 @@
236 236 }
237 237 }
238 238
239 239 $stringToReplaceField = $repeaterValues;
240 - } else {
241 - $stringToReplaceField = FieldValueHandler::replaceSmartTagWithValue($value);
242 240 }
243 241 }
244 242 return $stringToReplaceField;
245 243 }
@@ -246,9 +244,9 @@
246 244
247 245 public static function updatedHiddenFieldValue($formID)
248 246 {
249 247 $hiddenFields = [];
250 - $frontendFormManger = FrontendFormManager::getInstance($formID);
248 + $frontendFormManger = new FrontendFormManager($formID);
251 249
252 250 if ($frontendFormManger->isHoneypotActive()) {
253 251 $str = '_bitform' . '_' . $formID . '_' . time() . '_';
254 252 $honpotToken = Helpers::honeypotEncryptedToken($str);
@@ -288,11 +286,8 @@
288 286 }
289 287 if ('update' === $opType && isset($workFlowReturnedData['updatedData'])) {
290 288 $responseData['updatedData'] = $workFlowReturnedData['updatedData'];
291 289 }
292 - if (isset($workFlowReturnedData['new_nonce'])) {
293 - $responseData['new_nonce'] = $workFlowReturnedData['new_nonce'];
294 - }
295 290 if (!isset($workFlowReturnedData['triggerData'])) {
296 291 return $responseData;
297 292 }
298 293
@@ -299,12 +294,10 @@
299 294 $triggerData = $workFlowReturnedData['triggerData'];
300 295
301 296 $trnasientData = get_transient("bitform_trigger_transient_{$entryId}");
302 297 $trnasientData = is_string($trnasientData) ? json_decode($trnasientData) : $trnasientData;
303 -
304 298 if (!empty($trnasientData['fields'])) {
305 - $fieldData = isset($workFlowReturnedData['fields']) ? $workFlowReturnedData['fields'] : $workFlowReturnedData['updatedData'];
306 - $workFlowReturnedData['fields'] = array_merge($fieldData, $trnasientData['fields']);
299 + $workFlowReturnedData['fields'] = array_merge($workFlowReturnedData['fields'], $trnasientData['fields']);
307 300 }
308 301
309 302 if (function_exists('fastcgi_finish_request') || !wp_doing_ajax()) {
310 303 if (!headers_sent()) {
@@ -326,9 +319,9 @@
326 319 ];
327 320 }
328 321 }
329 322 ob_start();
330 - echo wp_doing_ajax() || defined('REST_REQUEST') ? wp_json_encode($response) : esc_html($workFlowReturnedData['message']);
323 + echo wp_doing_ajax() || defined('REST_REQUEST') ? wp_json_encode($response) : $workFlowReturnedData['message'];
331 324 ob_end_flush();
332 325 flush();
333 326 session_write_close();
334 327
@@ -343,13 +336,12 @@
343 336 'id' => $triggerData['entryID'],
344 337 ]
345 338 );
346 339
347 - $triggerData['fields'] = $workFlowReturnedData['fields'];
348 340 if (!is_wp_error($updatedStatus)) {
349 341 if ($workFlowReturnedData['dflt_template']) {
350 - // $triggerData['fields'] = $workFlowReturnedData['fields'];
351 - do_action('bitform_double_optin_confirmation', $workFlowReturnedData['integrationDetails'], $triggerData);
342 + $triggerData['fields'] = $workFlowReturnedData['fields'];
343 + do_action('bf_double_optin_confirmation', $workFlowReturnedData['integrationDetails'], $triggerData);
352 344 } elseif (isset($triggerData['dblOptin'])) {
353 345 foreach ($triggerData['dblOptin'] as $value) {
354 346 MailNotifier::notify($value, $triggerData['formID'], $triggerData['fields'], $triggerData['entryID'], true, $triggerData['logID']);
355 347 }
@@ -364,15 +356,15 @@
364 356 }
365 357 return $workFlowReturnedData;
366 358 }
367 359
368 - if (isset($triggerData['mail']) && !empty($triggerData['mail'])) {
360 + if (isset($triggerData['mail'])) {
369 361 $formManager = new AdminFormManager($triggerData['formID']);
370 362 $formContent = $formManager->getFormContent();
371 363 $submitted_fields = $formContent->fields;
372 364 $fieldValueForMail = FieldValueHandler::formatFieldValueForMail($submitted_fields, $workFlowReturnedData['fields']);
373 365 foreach ($triggerData['mail'] as $value) {
374 - MailNotifier::notify($value, $triggerData['formID'], $fieldValueForMail, $triggerData['entryID'], false, $triggerData['logID']);
366 + MailNotifier::notify($value, $triggerData['formID'], $fieldValueForMail, $triggerData['entryID']);
375 367 }
376 368 }
377 369 do_action('bitforms_exec_integrations', $triggerData['integrations'], $workFlowReturnedData['fields'], $triggerData['formID'], $triggerData['entryID'], $triggerData['logID']);
378 370
@@ -397,13 +389,8 @@
397 389 $triggerData['dbl_opt_donf'] = $workFlowReturnedData['integrationDetails'];
398 390 $triggerData['dbl_opt_dflt_template'] = $workFlowReturnedData['dflt_template'];
399 391 $triggerData['integrationRun'] = $workFlowReturnedData['integrationRun'];
400 392 }
401 -
402 - // Generate one-time trigger token for security
403 - $triggerToken = wp_hash($triggerData['entryID'] . $triggerData['logID'] . time() . wp_rand(), 'nonce');
404 - $triggerData['trigger_token'] = $triggerToken;
405 -
406 393 set_transient("bitform_trigger_transient_{$entryID}", $triggerData, HOUR_IN_SECONDS);
407 394 $entryLog = new FormEntryLogModel();
408 395 $queueuEntry = $entryLog->log_history_insert(
409 396 [
@@ -418,9 +405,8 @@
418 405 $responseData['cronNotOk'] = [
419 406 $triggerData['entryID'],
420 407 $triggerData['logID'],
421 408 $queueuEntry,
422 - $triggerToken, // Add one-time token as 4th element
423 409 ];
424 410 }
425 411 return $responseData;
426 412 }
@@ -464,15 +450,14 @@
464 450 }
465 451 $repeaterField[] = $key;
466 452 }
467 453
468 - // put the value of the child key to the parent repeater field\
454 + // put the value of the child key to the parent repeater field
469 455 foreach ($repeaterField as $key) {
470 456 list($parentKey, $childKey) = explode('.', $key);
471 - $repeatValues = isset($fieldValues[$parentKey]) ? $fieldValues[$parentKey] : $key;
457 + $repeatValues = $fieldValues[$parentKey];
472 458
473 459 if (!is_array($repeatValues)) {
474 - $fieldValues[$key] = $fieldValues[$childKey];
475 460 continue;
476 461 }
477 462
478 463 foreach ($repeatValues as $value) {
@@ -488,163 +473,11 @@
488 473 }
489 474
490 475 // convert the array to string repeater field value
491 476 if ('string' === $returnRepeaterValue) {
492 - $form = new FormManager(static::$_formID);
493 477 foreach ($repeaterField as $key) {
494 - if (isset($fieldValues[$key]) && is_array($fieldValues[$key])) {
495 - $fieldValues[$key] = implode(', ', self::flattenArray($fieldValues[$key]));
496 - }
478 + $fieldValues[$key] = implode(', ', $fieldValues[$key]);
497 479 }
498 -
499 - foreach ($fieldValues as $key=>$value) {
500 - if (!$form->isRepeaterField($key)) {
501 - continue;
502 - }
503 - $repeaterValues = $fieldValues[$key];
504 -
505 - $newFieldValues = self::constructRepeaterValue($repeaterValues, static::$_formID);
506 -
507 - $fieldValues[$key] = is_array($newFieldValues) ? json_encode(array_values($newFieldValues), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : $fieldValues[$key];
508 - }
509 480 }
510 -
511 481 return $fieldValues;
512 482 }
513 -
514 - private static function flattenArray($array)
515 - {
516 - return array_map(function ($val) {
517 - if (is_array($val)) {
518 - return count($val) > 1 ? ('[' . implode(', ') . ']') : implode(', ', $val);
519 - } else {
520 - return $val;
521 - }
522 - }, $array);
523 - }
524 -
525 - /**
526 - * Replace file field value with web url
527 - * @param mixed $fieldValues
528 - * @param number $formId
529 - * @param number $entryId
530 - * @return mixed $fieldValues
531 - */
532 - public static function handleFileUrl($fieldValues, $formId, $entryId)
533 - {
534 - if (!$formId || !$entryId) {
535 - return $fieldValues;
536 - }
537 - $form = FormManager::getInstance($formId);
538 - $formFields = $form->getFields();
539 -
540 - $fldsIncludeFile = ['file-up', 'advanced-file-up', 'repeater', 'signature'];
541 - foreach ($fieldValues as $key =>$value) {
542 - $fldTyp = $formFields[$key]['type'] ?? null;
543 - if (!in_array($fldTyp, $fldsIncludeFile)) {
544 - continue;
545 - }
546 -
547 - if ('repeater' === $fldTyp && is_array($value)) {
548 - foreach ($value as $rIndex => $rValue) {
549 - foreach ($rValue as $subKey=>$subValue) {
550 - if (!in_array($formFields[$subKey]['type'], $fldsIncludeFile)) {
551 - continue;
552 - }
553 - // for file fields inside repeater
554 - if (is_array($subValue)) {
555 - foreach ($subValue as $fileIndex=>$fileValue) {
556 - $fieldValues[$key][$rIndex][$subKey][$fileIndex] = self::constructFileUrl($formId, $entryId, $fileValue);
557 - }
558 - } else {
559 - // for signature field inside repeater;
560 - $fieldValues[$key][$rIndex][$subKey] = self::constructFileUrl($formId, $entryId, $subValue);
561 - }
562 - }
563 - }
564 - }
565 -
566 - if (in_array($fldTyp, ['file-up', 'advanced-file-up', 'signature'], true)) {
567 - if (is_array($value)) {
568 - foreach ($value as $fldIndex=>$fldValue) {
569 - $fieldValues[$key][$fldIndex] = self::constructFileUrl($formId, $entryId, $fldValue);
570 - }
571 - } else {
572 - $fieldValues[$key] = self::constructFileUrl($formId, $entryId, $value);
573 - }
574 - }
575 - }
576 -
577 - return $fieldValues;
578 - }
579 -
580 - public static function assignRepeaterFieldValue($fieldValues, $formId)
581 - {
582 - if (!$formId) {
583 - return $fieldValues;
584 - }
585 - $form = new FormManager($formId);
586 - $formFields = $form->getFields();
587 -
588 - foreach ($fieldValues as $key=>$value) {
589 - if (!$form->isRepeaterField($key)) {
590 - continue;
591 - }
592 -
593 - if ('repeater' === $formFields[$key]['type']) {
594 - if (is_array($value)) {
595 - foreach ($value as $rIndex=>$rValue) {
596 - foreach ($rValue as $subKey =>$subValue) {
597 - $fieldValues[$subKey] = $subValue;
598 - }
599 - }
600 - }
601 - }
602 - }
603 -
604 - return $fieldValues;
605 - }
606 -
607 - public static function constructRepeaterValue($repeaterValues, $formId)
608 - {
609 - if (!$formId || !is_array($repeaterValues)) {
610 - return $repeaterValues;
611 - }
612 - $form = FormManager::getInstance($formId);
613 - $formFields = $form->getFields();
614 - $newRptrValue = [];
615 - foreach ($repeaterValues as $key=>$value) {
616 - $newRepeatedValue = [];
617 - foreach ($value as $rKey =>$rValue) {
618 - $fldLbl = isset($formFields[$rKey]) ? $formFields[$rKey]['label'] : $rKey;
619 - $newRepeatedValue[$fldLbl] = $rValue;
620 - }
621 - $newRptrValue[$key] = $newRepeatedValue;
622 - }
623 -
624 - return $newRptrValue;
625 - }
626 -
627 - private static function constructFileUrl($formId, $entryId, $fileName)
628 - {
629 - $webPath = Helpers::getWebPathWithEncryptedEntryId($formId, $entryId);
630 -
631 - return rtrim($webPath, '/') . '/' . ltrim($fileName, '/');
632 - }
633 -
634 - // private static function constructFileUrl($formId, $entryId, $fileName)
635 - // {
636 - // $restBaseUrl = get_rest_url();
637 - // if (!$restBaseUrl) {
638 - // return $fileName;
639 - // }
640 - // //http://bitlocal.local/wp-json/bitform/v1/bitform-file-download/?formID=1&entryID=16&fileID=bit-form-1005.pdf
641 - // $queryParam = build_query([
642 - // 'formID' => $formId,
643 - // 'entryID' => $entryId,
644 - // 'fileID' => $fileName
645 - // ]);
646 -
647 - // $path = $restBaseUrl . 'bitform' . '/' . 'v1' . '/' . 'bitform-file-download' . '/' . '?' . $queryParam;
648 - // return rtrim($path, '/');
649 - // }
650 483 }