PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.9.1
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.9.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 2.10.2 All 137 releases
← All changes | includes/Core/Integration/IntegrationHandler.php +18 -278 3.1.22.9.1 View file →
@@ -6,10 +6,10 @@
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;
11 +use BitCode\BitForm\Core\Util\Log;
12 12 use BitCode\BitForm\Core\Util\MailNotifier;
13 13 use BitCode\BitForm\Frontend\Form\FrontendFormManager;
14 14
15 15 final class IntegrationHandler
@@ -217,29 +217,13 @@
217 217 }
218 218 $fieldPattern = '/\${\w[^ ${}]*}/';
219 219 preg_match_all($fieldPattern, $stringToReplaceField, $matchedField);
220 220 $uniqueFieldsInStr = array_unique($matchedField[0]);
221 -
222 - foreach ($uniqueFieldsInStr as $value) {
221 + foreach ($uniqueFieldsInStr as $key => $value) {
223 222 $fieldName = substr($value, 2, strlen($value) - 3);
224 -
225 - $repeaterArr = explode('.', $fieldName);
226 223 if (isset($fieldValues[$fieldName])) {
227 - $stringToReplaceField = is_string($fieldValues[$fieldName])
228 - ? str_replace($value, $fieldValues[$fieldName], $stringToReplaceField)
229 - : wp_json_encode($fieldValues[$fieldName]);
230 - } elseif (2 === count($repeaterArr) && isset($fieldValues[$repeaterArr[0]])) {
231 - $repeaterValues = [];
232 - $repeaterFieldValues = $fieldValues[$repeaterArr[0]];
233 - foreach ($repeaterFieldValues as $value) {
234 - if (isset($value[$repeaterArr[1]])) {
235 - $repeaterValues[] = $value[$repeaterArr[1]];
236 - }
237 - }
238 -
239 - $stringToReplaceField = $repeaterValues;
240 - } else {
241 - $stringToReplaceField = FieldValueHandler::replaceSmartTagWithValue($value);
224 + $stringToReplaceField = is_string($fieldValues[$fieldName]) ? str_replace($value, $fieldValues[$fieldName], $stringToReplaceField) :
225 + wp_json_encode($fieldValues[$fieldName]);
242 226 }
243 227 }
244 228 return $stringToReplaceField;
245 229 }
@@ -246,9 +230,9 @@
246 230
247 231 public static function updatedHiddenFieldValue($formID)
248 232 {
249 233 $hiddenFields = [];
250 - $frontendFormManger = FrontendFormManager::getInstance($formID);
234 + $frontendFormManger = new FrontendFormManager($formID);
251 235
252 236 if ($frontendFormManger->isHoneypotActive()) {
253 237 $str = '_bitform' . '_' . $formID . '_' . time() . '_';
254 238 $honpotToken = Helpers::honeypotEncryptedToken($str);
@@ -268,9 +252,9 @@
268 252 ];
269 253 return $hiddenFields;
270 254 }
271 255
272 - public static function maybeSetCronForIntegration($workFlowReturnedData, $opType, $isFormRequest = true)
256 + public static function maybeSetCronForIntegration($workFlowReturnedData, $opType)
273 257 {
274 258 $responseData = [];
275 259 $entryId = $workFlowReturnedData['triggerData']['entryID'];
276 260 $responseData['entry_id'] = $entryId;
@@ -288,11 +272,8 @@
288 272 }
289 273 if ('update' === $opType && isset($workFlowReturnedData['updatedData'])) {
290 274 $responseData['updatedData'] = $workFlowReturnedData['updatedData'];
291 275 }
292 - if (isset($workFlowReturnedData['new_nonce'])) {
293 - $responseData['new_nonce'] = $workFlowReturnedData['new_nonce'];
294 - }
295 276 if (!isset($workFlowReturnedData['triggerData'])) {
296 277 return $responseData;
297 278 }
298 279
@@ -299,12 +280,10 @@
299 280 $triggerData = $workFlowReturnedData['triggerData'];
300 281
301 282 $trnasientData = get_transient("bitform_trigger_transient_{$entryId}");
302 283 $trnasientData = is_string($trnasientData) ? json_decode($trnasientData) : $trnasientData;
303 -
304 - if (!empty($trnasientData['fields'])) {
305 - $fieldData = isset($workFlowReturnedData['fields']) ? $workFlowReturnedData['fields'] : $workFlowReturnedData['updatedData'];
306 - $workFlowReturnedData['fields'] = array_merge($fieldData, $trnasientData['fields']);
284 + if(!empty($trnasientData['fields'])){
285 + $workFlowReturnedData['fields'] = array_merge($workFlowReturnedData['fields'], $trnasientData['fields']);
307 286 }
308 287
309 288 if (function_exists('fastcgi_finish_request') || !wp_doing_ajax()) {
310 289 if (!headers_sent()) {
@@ -311,24 +290,15 @@
311 290 header('Connection: close');
312 291 $contentType = wp_doing_ajax() || defined('REST_REQUEST') ? 'application/json' : 'text/html';
313 292 header('Content-Type: ' . $contentType . '; charset=' . get_option('blog_charset'));
314 293 status_header(200);
315 - if (!$isFormRequest) {
316 - $response = [
317 - 'status' => 200,
318 - 'code' => 4000,
319 - 'message' => 'Data Added Successfully!!',
320 - 'success' => true
321 - ];
322 - } else {
323 - $response = [
324 - 'success' => true,
325 - 'data' => $responseData,
326 - ];
327 - }
294 + $response = [
295 + 'success' => true,
296 + 'data' => $responseData,
297 + ];
328 298 }
329 299 ob_start();
330 - echo wp_doing_ajax() || defined('REST_REQUEST') ? wp_json_encode($response) : esc_html($workFlowReturnedData['message']);
300 + echo wp_doing_ajax() || defined('REST_REQUEST') ? wp_json_encode($response) : $workFlowReturnedData['message'];
331 301 ob_end_flush();
332 302 flush();
333 303 session_write_close();
334 304
@@ -343,13 +313,12 @@
343 313 'id' => $triggerData['entryID'],
344 314 ]
345 315 );
346 316
347 - $triggerData['fields'] = $workFlowReturnedData['fields'];
348 317 if (!is_wp_error($updatedStatus)) {
349 318 if ($workFlowReturnedData['dflt_template']) {
350 - // $triggerData['fields'] = $workFlowReturnedData['fields'];
351 - do_action('bitform_double_optin_confirmation', $workFlowReturnedData['integrationDetails'], $triggerData);
319 + $triggerData['fields'] = $workFlowReturnedData['fields'];
320 + do_action('bf_double_optin_confirmation', $workFlowReturnedData['integrationDetails'], $triggerData);
352 321 } elseif (isset($triggerData['dblOptin'])) {
353 322 foreach ($triggerData['dblOptin'] as $value) {
354 323 MailNotifier::notify($value, $triggerData['formID'], $triggerData['fields'], $triggerData['entryID'], true, $triggerData['logID']);
355 324 }
@@ -364,15 +333,15 @@
364 333 }
365 334 return $workFlowReturnedData;
366 335 }
367 336
368 - if (isset($triggerData['mail']) && !empty($triggerData['mail'])) {
337 + if (isset($triggerData['mail'])) {
369 338 $formManager = new AdminFormManager($triggerData['formID']);
370 339 $formContent = $formManager->getFormContent();
371 340 $submitted_fields = $formContent->fields;
372 341 $fieldValueForMail = FieldValueHandler::formatFieldValueForMail($submitted_fields, $workFlowReturnedData['fields']);
373 342 foreach ($triggerData['mail'] as $value) {
374 - MailNotifier::notify($value, $triggerData['formID'], $fieldValueForMail, $triggerData['entryID'], false, $triggerData['logID']);
343 + MailNotifier::notify($value, $triggerData['formID'], $fieldValueForMail, $triggerData['entryID']);
375 344 }
376 345 }
377 346 do_action('bitforms_exec_integrations', $triggerData['integrations'], $workFlowReturnedData['fields'], $triggerData['formID'], $triggerData['entryID'], $triggerData['logID']);
378 347
@@ -397,13 +366,8 @@
397 366 $triggerData['dbl_opt_donf'] = $workFlowReturnedData['integrationDetails'];
398 367 $triggerData['dbl_opt_dflt_template'] = $workFlowReturnedData['dflt_template'];
399 368 $triggerData['integrationRun'] = $workFlowReturnedData['integrationRun'];
400 369 }
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 370 set_transient("bitform_trigger_transient_{$entryID}", $triggerData, HOUR_IN_SECONDS);
407 371 $entryLog = new FormEntryLogModel();
408 372 $queueuEntry = $entryLog->log_history_insert(
409 373 [
@@ -410,9 +374,9 @@
410 374 'log_id' => $triggerData['logID'],
411 375 'integration_id' => 0,
412 376 'api_type' => wp_json_encode(['type' => 'trigger', 'type_name' => 'Workflow', 'on' => $opType]),
413 377 'response_type' => 'queued',
414 - 'response_obj' => wp_json_encode(['status' => 'queued']),
378 + 'response_obj' => json_encode(['status' => 'queued']),
415 379 'created_at' => current_time('mysql'),
416 380 ]
417 381 );
418 382 $responseData['cronNotOk'] = [
@@ -418,233 +382,9 @@
418 382 $responseData['cronNotOk'] = [
419 383 $triggerData['entryID'],
420 384 $triggerData['logID'],
421 385 $queueuEntry,
422 - $triggerToken, // Add one-time token as 4th element
423 386 ];
424 387 }
425 388 return $responseData;
426 389 }
427 -
428 - public static function repeaterFieldValueFormatter($fieldValues)
429 - {
430 - $formattedArray = [];
431 -
432 - foreach ($fieldValues as $key => $value) {
433 - if (is_array($value)) {
434 - foreach ($value as $index => $v) {
435 - if (is_array($v)) {
436 - foreach ($v as $k1 => $v1) {
437 - $formattedArray[$k1][] = $v1;
438 - }
439 - } else {
440 - $formattedArray[$key][] = $v;
441 - }
442 - }
443 - } else {
444 - $formattedArray[$key] = $value;
445 - }
446 - }
447 -
448 - return $formattedArray;
449 - }
450 -
451 - /**
452 - *
453 - * @param mixed $fieldValues
454 - * @param mixed $returnRepeaterValue default is array
455 - * @return array and repeater field value as array or string
456 - */
457 - public static function formattedRepeaterValue($fieldValues, $returnRepeaterValue = '')
458 - {
459 - // get the repeater field and store it in an array
460 - $repeaterField = [];
461 - foreach ($fieldValues as $key => $value) {
462 - if (!preg_match('/\./', $key)) {
463 - continue;
464 - }
465 - $repeaterField[] = $key;
466 - }
467 -
468 - // put the value of the child key to the parent repeater field\
469 - foreach ($repeaterField as $key) {
470 - list($parentKey, $childKey) = explode('.', $key);
471 - $repeatValues = isset($fieldValues[$parentKey]) ? $fieldValues[$parentKey] : $key;
472 -
473 - if (!is_array($repeatValues)) {
474 - $fieldValues[$key] = $fieldValues[$childKey];
475 - continue;
476 - }
477 -
478 - foreach ($repeatValues as $value) {
479 - if (isset($value[$childKey])) {
480 - if (!isset($fieldValues[$key]) || !is_array($fieldValues[$key])) {
481 - $fieldValues[$key] = [];
482 - }
483 - if (!empty($value[$childKey])) {
484 - $fieldValues[$key][] = $value[$childKey];
485 - }
486 - }
487 - }
488 - }
489 -
490 - // convert the array to string repeater field value
491 - if ('string' === $returnRepeaterValue) {
492 - $form = new FormManager(static::$_formID);
493 - foreach ($repeaterField as $key) {
494 - if (isset($fieldValues[$key]) && is_array($fieldValues[$key])) {
495 - $fieldValues[$key] = implode(', ', self::flattenArray($fieldValues[$key]));
496 - }
497 - }
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 - }
510 -
511 - return $fieldValues;
512 - }
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 390 }