| @@ -2,23 +2,35 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\Frontend\Form; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Admin\Form\FrontEndScriptGenerator; |
| 6 | +use BitCode\BitForm\Admin\Form\Helpers; | |
| 7 | +use BitCode\BitForm\Core\Database\FormEntryMetaModel; | |
| 6 | 8 | use BitCode\BitForm\Core\Database\FormModel; |
| 7 | 9 | use BitCode\BitForm\Core\Form\FormManager; |
| 8 | 10 | use BitCode\BitForm\Core\Integration\IntegrationHandler; |
| 9 | 11 | use BitCode\BitForm\Core\Util\FieldValueHandler; |
| 12 | +use BitCode\BitForm\Core\Util\FileDownloadProvider; | |
| 10 | 13 | use BitCode\BitForm\Core\Util\FrontendHelpers; |
| 14 | +use BitCode\BitForm\Core\Util\SmartTags; | |
| 15 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 11 | 16 | use BitCode\BitForm\Core\WorkFlow\WorkFlow; |
| 17 | +use BitCode\BitFormPro\Admin\FormSettings\FormAbandonment; | |
| 12 | 18 | |
| 13 | -final class FrontendFormHandler { | |
| 14 | - public function __construct() { | |
| 19 | +final class FrontendFormHandler | |
| 20 | +{ | |
| 21 | + public function __construct() | |
| 22 | + { | |
| 23 | + // before markup load - formids [], posts [1,2] | |
| 15 | 24 | add_action('wp_enqueue_scripts', [$this, 'loadAssets']); |
| 25 | + // markup loads - formids [] | |
| 26 | + add_shortcode('bitform', [$this, 'handleFrontendRenderRequest']); | |
| 27 | + // after markup load - formids [1,35,3] | |
| 16 | 28 | add_action('wp_footer', [$this, 'generateJS']); |
| 17 | - add_shortcode('bitform', [$this, 'handleFrontendRenderRequest']); | |
| 18 | 29 | } |
| 19 | 30 | |
| 20 | - private function validPassowordResetToken($token, $userID, $formId) { | |
| 31 | + private function validPassowordResetToken($token, $userID, $formId) | |
| 32 | + { | |
| 21 | 33 | $existResetInteg = (new IntegrationHandler($formId))->getAllIntegration('wp_user_auth', 'wp_auth', 1); |
| 22 | 34 | if (!is_wp_error($existResetInteg) && count($existResetInteg) > 0) { |
| 23 | 35 | if ('reset' === $existResetInteg[0]->integration_name) { |
| 24 | 36 | $user = get_userdata($userID); |
| @@ -35,9 +47,10 @@ | ||
| 35 | 47 | } |
| 36 | 48 | } |
| 37 | 49 | } |
| 38 | 50 | |
| 39 | - private function getJSFileSrc($postId) { | |
| 51 | + private function getJSFileSrc($postId) | |
| 52 | + { | |
| 40 | 53 | $formUpdateVersion = get_option('bit-form_form_update_version'); |
| 41 | 54 | $formScriptSrc = BITFORMS_UPLOAD_BASE_URL . "/form-scripts/$postId/bitform-js-$postId.js?bfv=$formUpdateVersion"; |
| 42 | 55 | |
| 43 | 56 | return $formScriptSrc; |
| @@ -42,17 +55,20 @@ | ||
| 42 | 55 | |
| 43 | 56 | return $formScriptSrc; |
| 44 | 57 | } |
| 45 | 58 | |
| 46 | - public function generateJs($formID = null) { | |
| 59 | + public function generateJs($formID = null, $entryID = null, $formType = null) | |
| 60 | + { | |
| 61 | + // return true; | |
| 47 | 62 | $isFormPreview = get_transient('bitform_form_preview'); |
| 48 | 63 | if ($isFormPreview && !$formID) { |
| 49 | 64 | delete_transient('bitform_form_preview'); |
| 50 | 65 | return; |
| 51 | 66 | } |
| 52 | - FrontendHelpers::isPageBuilder(); | |
| 53 | - global $isPageBuilder; | |
| 54 | - if ($isPageBuilder) { | |
| 67 | + $frontendScriptGenObj = new FrontEndScriptGenerator(); | |
| 68 | + $isPageBuilder = FrontendHelpers::checkIsPageBuilder($_SERVER); | |
| 69 | + $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; | |
| 70 | + if ($isPageBuilder || empty($bfFrontendFormIds)) { | |
| 55 | 71 | return; |
| 56 | 72 | } |
| 57 | 73 | // for unique fields ids in the same form (e.g. multiple forms in the same page) |
| 58 | 74 | $allFields = []; |
| @@ -58,23 +74,36 @@ | ||
| 58 | 74 | $allFields = []; |
| 59 | 75 | $formContents = []; |
| 60 | 76 | $contentIds = []; |
| 61 | 77 | $formIDs = []; |
| 62 | - $preview = false; | |
| 78 | + $previewMode = 'classic'; | |
| 63 | 79 | $postId = ''; |
| 64 | 80 | |
| 81 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 65 | 82 | if ($formID) { |
| 66 | 83 | $formIDs[] = $formID; |
| 67 | 84 | $FrontendFormManager = new FrontendFormManager($formID, 1); |
| 85 | + $formInfo = $FrontendFormManager->getFormInfo(); | |
| 68 | 86 | $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier()); |
| 69 | 87 | $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams()); |
| 88 | + $formContent->formId = $formID; | |
| 70 | 89 | $formContents[] = $formContent; |
| 71 | - $fields = $this->triggerWorkflowOnLoad($formID, 1, $formContent->fields); | |
| 90 | + $workFlowRunType = $entryID ? 'edit' : 'create'; | |
| 91 | + $fields = $formContent->fields; | |
| 92 | + if ($entryID) { | |
| 93 | + $fields = $this->setFieldsValue($fields, $formID, $entryID); | |
| 94 | + } | |
| 95 | + $fields = $this->triggerWorkflowOnLoad($formID, 1, $fields, $workFlowRunType); | |
| 72 | 96 | array_push($contentIds, $FormIdentifier); |
| 97 | + | |
| 73 | 98 | foreach ($fields as $fk => $field) { |
| 74 | 99 | $allFields[$field->typ][] = ['fk' => $fk, 'field' => $field, 'formID' => $formID, 'contentId' => $FormIdentifier]; |
| 75 | 100 | } |
| 76 | - $preview = true; | |
| 101 | + //Generate JS file for conversational form | |
| 102 | + if (!empty($formInfo->conversationalSettings->enable) && $formInfo->conversationalSettings->enable) { | |
| 103 | + $frontendScriptGenObj->generateJsFile([$formContent], $allFields, [$FormIdentifier], $formID, [$formID], 'conversational'); | |
| 104 | + } | |
| 105 | + $previewMode = 'preview'; | |
| 77 | 106 | $postId = $formID; |
| 78 | 107 | } else { |
| 79 | 108 | global $post; |
| 80 | 109 | if (!is_object($post) && !isset($post->ID)) { |
| @@ -79,43 +108,54 @@ | ||
| 79 | 108 | global $post; |
| 80 | 109 | if (!is_object($post) && !isset($post->ID)) { |
| 81 | 110 | return; |
| 82 | 111 | } |
| 83 | - FrontendHelpers::handleBfFormIdsSession(); | |
| 84 | - global $bfFrontendFormIds; | |
| 85 | - $bfUniqFormIds = array_unique($bfFrontendFormIds); | |
| 112 | + $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; | |
| 113 | + $bfUniqFormIds = FrontendHelpers::getAllUniqFormIdsInPage(); | |
| 114 | + $formIDs = $bfUniqFormIds; | |
| 115 | + $regenerateScriptFlag = $this->regenerateScriptChecker($bfUniqFormIds); | |
| 86 | 116 | |
| 87 | - $regenerateScriptFlag = $this->regenerateScriptChecker($bfUniqFormIds); | |
| 88 | 117 | $postId = $post->ID; |
| 89 | 118 | if (!$regenerateScriptFlag) { |
| 90 | 119 | $regenerateScriptFlag = $this->deleteUnusedFormPageIds($postId, $bfUniqFormIds); |
| 91 | 120 | } |
| 92 | 121 | $isJsGenerating = get_option('bitforms_frontend_js_generating'); |
| 93 | - if (!$regenerateScriptFlag && !$isJsGenerating) { | |
| 94 | - wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], '', true); | |
| 122 | + if (!$regenerateScriptFlag && !$isJsGenerating && !empty($formIDs)) { | |
| 123 | + wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], $formUpdateVersion, true); | |
| 95 | 124 | return; |
| 96 | 125 | } |
| 97 | - | |
| 98 | - $formIDs = $bfUniqFormIds; | |
| 99 | - | |
| 100 | 126 | foreach ($bfFrontendFormIds as $index => $formId) { |
| 101 | 127 | $shortCodeCounter = $index + 1; |
| 102 | 128 | $FrontendFormManager = new FrontendFormManager($formId, $shortCodeCounter); |
| 129 | + $formInfo = $FrontendFormManager->getFormInfo(); | |
| 103 | 130 | $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier()); |
| 104 | 131 | $formContent = $FrontendFormManager->getFormContentWithValue($this->getValuesFromQueryParams()); |
| 132 | + $formContent->formId = $formId; | |
| 105 | 133 | $formContents[] = $formContent; |
| 106 | 134 | $fields = $this->triggerWorkflowOnLoad($formId, $shortCodeCounter, $formContent->fields); |
| 107 | - array_push($contentIds, $FormIdentifier); | |
| 135 | + $contentIds[] = $FormIdentifier; | |
| 136 | + $formFields = []; // indivisual form fields array for conversational view | |
| 108 | 137 | foreach ($fields as $fk => $field) { |
| 109 | - $allFields[$field->typ][] = ['fk' => $fk, 'field' => $field, 'formID' => $formId, 'contentId' => $FormIdentifier]; | |
| 138 | + $fieldArr = ['fk' => $fk, 'field' => $field, 'formID' => $formId, 'contentId' => $FormIdentifier]; | |
| 139 | + $allFields[$field->typ][] = $fieldArr; | |
| 140 | + $formFields[$field->typ][] = $fieldArr; | |
| 110 | 141 | } |
| 142 | + //Generate JS file for conversational form | |
| 143 | + if (!empty($formInfo->conversationalSettings->enable) && $formInfo->conversationalSettings->enable) { | |
| 144 | + $frontendScriptGenObj->generateJsFile([$formContent], $formFields, [$FormIdentifier], $formId, [$formId], 'conversational'); | |
| 145 | + } | |
| 111 | 146 | } |
| 112 | 147 | } |
| 113 | - (new FrontEndScriptGenerator())->generateJsFile($formContents, $allFields, $contentIds, $postId, $formIDs, $preview); | |
| 114 | - wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], '', true); | |
| 148 | + if (empty($formIDs)) { | |
| 149 | + return; | |
| 150 | + } | |
| 151 | + | |
| 152 | + $frontendScriptGenObj->generateJsFile($formContents, $allFields, $contentIds, $postId, $formIDs, $previewMode); | |
| 153 | + wp_enqueue_script('bit-form-all-script-test', $this->getJSFileSrc($postId), [], $formUpdateVersion, true); | |
| 115 | 154 | } |
| 116 | 155 | |
| 117 | - private function deleteUnusedFormPageIds($postId, $formIDs) { | |
| 156 | + private function deleteUnusedFormPageIds($postId, $formIDs) | |
| 157 | + { | |
| 118 | 158 | global $post; |
| 119 | 159 | if (!is_object($post) && !isset($post->ID)) { |
| 120 | 160 | return; |
| 121 | 161 | } |
| @@ -130,18 +170,31 @@ | ||
| 130 | 170 | $generatedScriptPageIdsDecoded = json_decode($form->generated_script_page_ids, true); |
| 131 | 171 | $generatedScriptPageIds = is_array($generatedScriptPageIdsDecoded) ? array_keys($generatedScriptPageIdsDecoded) : []; |
| 132 | 172 | if (!empty($generatedScriptPageIds) && !in_array($formId, $formIDs) && in_array($postId, $generatedScriptPageIds)) { |
| 133 | 173 | unset($generatedScriptPageIdsDecoded[$postId]); |
| 174 | + if (empty($generatedScriptPageIdsDecoded)) { | |
| 175 | + $generatedScriptPageIdsDecoded = new \stdClass(); | |
| 176 | + } | |
| 134 | 177 | $regenerateScriptFlag = true; |
| 135 | 178 | $formModel->update(['generated_script_page_ids' => wp_json_encode($generatedScriptPageIdsDecoded)], ['id' => $formId]); |
| 136 | 179 | } |
| 137 | 180 | } |
| 181 | + if ($regenerateScriptFlag) { | |
| 182 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 183 | + if (!$formUpdateVersion) { | |
| 184 | + $formUpdateVersion = 1; | |
| 185 | + } else { | |
| 186 | + $formUpdateVersion = (int) $formUpdateVersion + 1; | |
| 187 | + } | |
| 188 | + update_option('bit-form_form_update_version', $formUpdateVersion); | |
| 189 | + } | |
| 138 | 190 | return $regenerateScriptFlag; |
| 139 | 191 | } |
| 140 | 192 | |
| 141 | - private function regenerateScriptChecker($formsIds) { | |
| 193 | + private function regenerateScriptChecker($formsIds) | |
| 194 | + { | |
| 142 | 195 | global $post; |
| 143 | - if (!is_object($post) && !isset($post->ID)) { | |
| 196 | + if (!is_a($post, 'WP_Post') && !isset($post->ID)) { | |
| 144 | 197 | return; |
| 145 | 198 | } |
| 146 | 199 | $postId = $post->ID; |
| 147 | 200 | $regenerateScriptFlag = false; |
| @@ -147,10 +200,12 @@ | ||
| 147 | 200 | $regenerateScriptFlag = false; |
| 148 | 201 | $formModel = new FormModel(); |
| 149 | 202 | foreach ($formsIds as $formId) { |
| 150 | 203 | $formInstance = new FormManager($formId); |
| 204 | + if (!$formInstance->isExist()) { | |
| 205 | + continue; | |
| 206 | + } | |
| 151 | 207 | $generatedPages = $formInstance->getFormData('generated_script_page_ids'); |
| 152 | - | |
| 153 | 208 | if (empty($generatedPages)) { |
| 154 | 209 | $regenerateScriptFlag = true; |
| 155 | 210 | } elseif (is_object($generatedPages) && (!isset($generatedPages->{$postId}) || (isset($generatedPages->{$postId}) && false === $generatedPages->{$postId}))) { |
| 156 | 211 | $regenerateScriptFlag = true; |
| @@ -157,9 +212,11 @@ | ||
| 157 | 212 | } |
| 158 | 213 | if (!$regenerateScriptFlag) { |
| 159 | 214 | continue; |
| 160 | 215 | } |
| 161 | - | |
| 216 | + if (!is_object($generatedPages)) { | |
| 217 | + $generatedPages = (object) []; | |
| 218 | + } | |
| 162 | 219 | $generatedPages->{$postId} = true; |
| 163 | 220 | $formModel->update( |
| 164 | 221 | [ |
| 165 | 222 | 'generated_script_page_ids' => \wp_json_encode($generatedPages) |
| @@ -171,9 +228,10 @@ | ||
| 171 | 228 | } |
| 172 | 229 | return $regenerateScriptFlag; |
| 173 | 230 | } |
| 174 | 231 | |
| 175 | - private function addInlineScript($code, $handle = '', $position = 'after') { | |
| 232 | + private function addInlineScript($code, $handle = '', $position = 'after') | |
| 233 | + { | |
| 176 | 234 | $scriptHandle = !empty($handle) ? $handle : 'bf-inline-script'; |
| 177 | 235 | if (!wp_script_is($scriptHandle)) { |
| 178 | 236 | wp_register_script($scriptHandle, '', [], '', true); |
| 179 | 237 | wp_enqueue_script($scriptHandle); |
| @@ -180,9 +238,10 @@ | ||
| 180 | 238 | } |
| 181 | 239 | wp_add_inline_script($scriptHandle, $code, $position); |
| 182 | 240 | } |
| 183 | 241 | |
| 184 | - private function addInlineStyle($code, $handle = '') { | |
| 242 | + private function addInlineStyle($code, $handle = '') | |
| 243 | + { | |
| 185 | 244 | $styleHandle = !empty($handle) ? $handle : 'bf-inline-style'; |
| 186 | 245 | if (!wp_style_is($styleHandle)) { |
| 187 | 246 | wp_register_style($styleHandle, '', [], '', true); |
| 188 | 247 | wp_enqueue_style($styleHandle); |
| @@ -189,9 +248,10 @@ | ||
| 189 | 248 | } |
| 190 | 249 | wp_add_inline_style($styleHandle, $code); |
| 191 | 250 | } |
| 192 | 251 | |
| 193 | - private function triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields) { | |
| 252 | + private function triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields, $workFlowRunType = 'create') | |
| 253 | + { | |
| 194 | 254 | $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter); |
| 195 | 255 | $previousValue = $this->getValuesFromQueryParams(); |
| 196 | 256 | $formContent = $FrontendFormManager->getFormContentWithValue($previousValue); |
| 197 | 257 | if (!empty($formContent->workFlowExist)) { |
| @@ -197,9 +257,9 @@ | ||
| 197 | 257 | if (!empty($formContent->workFlowExist)) { |
| 198 | 258 | $workFlowRunHelper = new WorkFlow($formID); |
| 199 | 259 | if (!empty($formContent->workFlowExist->onload)) { |
| 200 | 260 | $workFlowreturnedOnLoad = $workFlowRunHelper->executeOnLoad( |
| 201 | - 'create', | |
| 261 | + $workFlowRunType, | |
| 202 | 262 | $fields |
| 203 | 263 | ); |
| 204 | 264 | |
| 205 | 265 | if (!empty($workFlowreturnedOnLoad['fields'])) { |
| @@ -210,9 +270,10 @@ | ||
| 210 | 270 | |
| 211 | 271 | return $fields; |
| 212 | 272 | } |
| 213 | 273 | |
| 214 | - private function executeOnUserInput($formID, $shortCodeCounter, $fields) { | |
| 274 | + private function executeOnUserInput($formID, $shortCodeCounter, $fields) | |
| 275 | + { | |
| 215 | 276 | $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter); |
| 216 | 277 | $previousValue = $this->getValuesFromQueryParams(); |
| 217 | 278 | $formContent = $FrontendFormManager->getFormContentWithValue($previousValue); |
| 218 | 279 | $customCodesExist = strpos(FrontEndScriptGenerator::getCustomCodes($formID)['JavaScript'], 'bfVars'); |
| @@ -221,12 +282,13 @@ | ||
| 221 | 282 | return $workFlowRunHelper->executeOnUserInput('create', $fields); |
| 222 | 283 | } |
| 223 | 284 | } |
| 224 | 285 | |
| 225 | - private function getValuesFromQueryParams() { | |
| 226 | - $reqField = $_SERVER['QUERY_STRING']; | |
| 286 | + private function getValuesFromQueryParams() | |
| 287 | + { | |
| 227 | 288 | $queryParamsValue = []; |
| 228 | - if (!empty($reqField)) { | |
| 289 | + if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { | |
| 290 | + $reqField = $_SERVER['QUERY_STRING']; | |
| 229 | 291 | foreach (explode('&', $reqField) as $keyValue) { |
| 230 | 292 | // $pattern = '/([a-zA-Z0-9])([a-zA-Z])\=+/'; |
| 231 | 293 | $pattern = '/([^.]+)=(.*?)([^.]+)/'; |
| 232 | 294 | $matches = preg_match($pattern, $keyValue, $matchFormat); |
| @@ -244,16 +306,23 @@ | ||
| 244 | 306 | |
| 245 | 307 | return $queryParamsValue; |
| 246 | 308 | } |
| 247 | 309 | |
| 248 | - public function handleFrontendRenderRequest($atts, $formPreview = false) { | |
| 249 | - static $shortCodeCounter = 0; | |
| 250 | - $shortCodeCounter += 1; | |
| 251 | - | |
| 252 | - if ($formPreview) { | |
| 253 | - // when $formPreview is true, it means that the atts is the form id | |
| 254 | - $formID = $atts; | |
| 310 | + public function handleFrontendRenderRequest($atts) | |
| 311 | + { | |
| 312 | + $formType = isset($atts['type']) ? $atts['type'] : 'classic'; | |
| 313 | + $formPreview = isset($atts['form_preview']) ? $atts['form_preview'] : false; | |
| 314 | + if (isset($atts['form_id'])) { | |
| 315 | + $formID = intval($atts['form_id']); | |
| 316 | + } | |
| 317 | + if (isset($atts['entry_id'])) { | |
| 318 | + $entryId = intval($atts['entry_id']); | |
| 319 | + } elseif (isset($_GET['bf_entry_id'])) { | |
| 320 | + $entryId = $_GET['bf_entry_id']; | |
| 255 | 321 | } else { |
| 322 | + $entryId = false; | |
| 323 | + } | |
| 324 | + if (isset($atts['id'])) { | |
| 256 | 325 | $atts = shortcode_atts(['id' => 0], $atts); |
| 257 | 326 | $formID = intval($atts['id']); |
| 258 | 327 | } |
| 259 | 328 | |
| @@ -263,15 +332,31 @@ | ||
| 263 | 332 | |
| 264 | 333 | if (!$this->isExist($formID)) { |
| 265 | 334 | return sprintf(__('#%s no. Form doesn\'t exists', 'bit-form'), $formID); |
| 266 | 335 | } |
| 267 | - FrontendHelpers::handleBfFormIdsSession($formID); | |
| 336 | + | |
| 337 | + // check for abandoned form entry id | |
| 338 | + $isAbandoned = false; | |
| 339 | + if (empty($entryId) && Utilities::isPro() && class_exists('\BitCode\BitFormPro\Admin\FormSettings\FormAbandonment')) { | |
| 340 | + $FormAbandonment = new FormAbandonment($formID); | |
| 341 | + $isAbandoned = $FormAbandonment->checkAbandonedFormEntryId(); | |
| 342 | + } | |
| 343 | + | |
| 344 | + FrontendHelpers::setBfFrontendFormIds($formID); | |
| 345 | + $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; | |
| 346 | + $shortCodeCounter = count($bfFrontendFormIds); | |
| 268 | 347 | $FrontendFormManager = new FrontendFormManager($formID, $shortCodeCounter); |
| 269 | 348 | |
| 349 | + if (!$FrontendFormManager->checkStatus()) { | |
| 350 | + return sprintf(__('#%s no. Form is not active', 'bit-form'), $formID); | |
| 351 | + } | |
| 352 | + ob_start(); | |
| 353 | + $this->loadAssets($formID, $formType); | |
| 354 | + | |
| 270 | 355 | $font = $FrontendFormManager->getFont(); |
| 271 | 356 | |
| 272 | 357 | if ($font && !$formPreview) { |
| 273 | - wp_enqueue_style('google-font', $font, '1.0.0', true); | |
| 358 | + wp_enqueue_style('bf-google-font', $font, '1.0.0', true); | |
| 274 | 359 | } |
| 275 | 360 | |
| 276 | 361 | if (!empty($_GET['token']) && !empty($_GET['id'])) { |
| 277 | 362 | $this->validPassowordResetToken($_GET['token'], $_GET['id'], $formID); |
| @@ -282,137 +367,238 @@ | ||
| 282 | 367 | $FormIdentifier = esc_js($FrontendFormManager->getFormIdentifier()); |
| 283 | 368 | $nonce = $FrontendFormManager->getFormToken(); |
| 284 | 369 | $file = count($FrontendFormManager->getUploadFields()) > 0 ? $FrontendFormManager->getUploadFields() : false; |
| 285 | 370 | |
| 286 | - if ($FrontendFormManager->checkStatus()) { | |
| 287 | - $FrontendFormManager->setViewCount(); | |
| 371 | + $FrontendFormManager->setViewCount(); | |
| 288 | 372 | |
| 289 | - $formContent = $FrontendFormManager->getFormContentWithValue($previousValue); | |
| 290 | - $fields = $formContent->fields; | |
| 291 | - $layout = $formContent->layout; | |
| 292 | - $buttons = !empty($formContent->buttons) ? $formContent->buttons : ''; | |
| 293 | - $additional = $formContent->additional; | |
| 373 | + $formContent = $FrontendFormManager->getFormContentWithValue($previousValue); | |
| 374 | + $fields = $formContent->fields; | |
| 375 | + $layout = $formContent->layout; | |
| 376 | + $nestedLayout = isset($formContent->nestedLayout) ? $formContent->nestedLayout : (object) []; | |
| 377 | + $buttons = !empty($formContent->buttons) ? $formContent->buttons : ''; | |
| 378 | + $additional = $formContent->additional; | |
| 294 | 379 | |
| 295 | - $fields = $this->triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields); | |
| 296 | - $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $fields); | |
| 380 | + // $workFlowRunType = $entryId ? 'edit' : 'create'; | |
| 381 | + if ($entryId && (get_current_user_id() || is_admin())) { | |
| 382 | + // return sprintf(__('Sorry!, You cannot edit #%s no form.', 'bit-form'), $formID); | |
| 383 | + $workFlowRunType = 'edit'; | |
| 384 | + $fields = $this->setFieldsValue($fields, $formID, $entryId); | |
| 385 | + } else { | |
| 386 | + $workFlowRunType = 'create'; | |
| 387 | + } | |
| 297 | 388 | |
| 298 | - // only for form not preview | |
| 299 | - if (!wp_style_is('bitform-style' . $formID)) { | |
| 300 | - $this->loadAssets(true, $formID, $file); | |
| 389 | + // if ($entryId) { | |
| 390 | + // $fields = $this->setFieldsValue($fields, $formID, $entryId); | |
| 391 | + // } | |
| 392 | + | |
| 393 | + $fields = apply_filters('bitform_filter_before_workflow_onload_fields', $fields, $formID); | |
| 394 | + $fields = $this->triggerWorkflowOnLoad($formID, $shortCodeCounter, $fields, $workFlowRunType); | |
| 395 | + $fields = apply_filters('bitform_filter_after_workflow_onload_fields', $fields, $formID); | |
| 396 | + do_action('bitform_onload_fields', $fields, $formID); | |
| 397 | + $workFlowreturnedOnUserInput = $this->executeOnUserInput($formID, $shortCodeCounter, $fields); | |
| 398 | + | |
| 399 | + // test for form before remove | |
| 400 | + $noLabel = ['decision-box', 'html', 'shortcode', 'button', 'paypal', 'razorpay', 'recaptcha']; | |
| 401 | + foreach ($fields as $fldKey => $field) { | |
| 402 | + if (!in_array($field->typ, $noLabel) && isset($field->lbl)) { | |
| 403 | + $lblReplaceToBackslash = str_replace('$_bf_$', '\\', $field->lbl); | |
| 404 | + $fields->{$fldKey}->lbl = FieldValueHandler::replaceSmartTagWithValue($lblReplaceToBackslash); | |
| 301 | 405 | } |
| 406 | + } | |
| 407 | + $fieldsKey = $FrontendFormManager->getFieldsKey(); | |
| 302 | 408 | |
| 303 | - // test for form before remove | |
| 304 | - $noLabel = ['decision-box', 'html', 'button', 'paypal', 'razorpay', 'recaptcha']; | |
| 305 | - $newFields = json_decode(json_encode($fields), true); | |
| 306 | - foreach ($newFields as $fldKey => $field) { | |
| 307 | - if (!in_array($field['typ'], $noLabel) && isset($field['lbl'])) { | |
| 308 | - $lblReplaceToBackslash = str_replace('$_bf_$', '\\', $field['lbl']); | |
| 309 | - $newFields[$fldKey]['lbl'] = FieldValueHandler::replaceSmartTagWithValue($lblReplaceToBackslash); | |
| 310 | - } | |
| 311 | - } | |
| 312 | - $fieldsKey = $FrontendFormManager->getFieldsKey(); | |
| 409 | + $captchaV3Settings = $FrontendFormManager->getCaptchaV3Settings(); | |
| 410 | + if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings || $FrontendFormManager->getTurnstileSettings()) { | |
| 411 | + $integrationHandler = new IntegrationHandler(0); | |
| 412 | + $allFormIntegrations = $integrationHandler->getAllIntegration('app'); | |
| 413 | + if (!is_wp_error($allFormIntegrations)) { | |
| 414 | + foreach ($allFormIntegrations as $integration) { | |
| 415 | + if ( | |
| 416 | + $FrontendFormManager->getCaptchaSettings() | |
| 417 | + && !is_null($integration->integration_type) | |
| 418 | + && 'gReCaptcha' === $integration->integration_type | |
| 419 | + ) { | |
| 420 | + $integrationDetails = json_decode($integration->integration_details); | |
| 421 | + $integrationDetails->id = $integration->id; | |
| 422 | + $reCAPTCHA = $integrationDetails; | |
| 423 | + $reCAPTCHAVersion = 'v2'; | |
| 424 | + } | |
| 313 | 425 | |
| 314 | - $captchaV3Settings = $FrontendFormManager->getCaptchaV3Settings(); | |
| 315 | - if ($FrontendFormManager->getCaptchaSettings() || $captchaV3Settings) { | |
| 316 | - $integrationHandler = new IntegrationHandler(0); | |
| 317 | - $allFormIntegrations = $integrationHandler->getAllIntegration('app'); | |
| 318 | - if (!is_wp_error($allFormIntegrations)) { | |
| 319 | - foreach ($allFormIntegrations as $integration) { | |
| 320 | - if ( | |
| 321 | - $FrontendFormManager->getCaptchaSettings() | |
| 322 | - && !is_null($integration->integration_type) | |
| 323 | - && 'gReCaptcha' === $integration->integration_type | |
| 324 | - ) { | |
| 426 | + if ( | |
| 427 | + $FrontendFormManager->getTurnstileSettings() | |
| 428 | + && !is_null($integration->integration_type) | |
| 429 | + && 'turnstileCaptcha' === $integration->integration_type | |
| 430 | + ) { | |
| 431 | + $integrationDetails = json_decode($integration->integration_details); | |
| 432 | + $turnstileSiteKey = $integrationDetails->siteKey; | |
| 433 | + } | |
| 434 | + | |
| 435 | + if ($captchaV3Settings) { | |
| 436 | + if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) { | |
| 325 | 437 | $integrationDetails = json_decode($integration->integration_details); |
| 326 | 438 | $integrationDetails->id = $integration->id; |
| 327 | 439 | $reCAPTCHA = $integrationDetails; |
| 328 | - $reCAPTCHAVersion = 'v2'; | |
| 440 | + $reCAPTCHAVersion = 'v3'; | |
| 329 | 441 | } |
| 442 | + } | |
| 443 | + } | |
| 444 | + } | |
| 445 | + } | |
| 330 | 446 | |
| 331 | - if ($captchaV3Settings) { | |
| 332 | - if (!is_null($integration->integration_type) && 'gReCaptchaV3' === $integration->integration_type) { | |
| 333 | - $integrationDetails = json_decode($integration->integration_details); | |
| 334 | - $integrationDetails->id = $integration->id; | |
| 335 | - $reCAPTCHA = $integrationDetails; | |
| 336 | - $reCAPTCHAVersion = 'v3'; | |
| 337 | - } | |
| 338 | - } | |
| 339 | - } | |
| 447 | + if ($captchaV3Settings && !empty($reCAPTCHA->siteKey)) { | |
| 448 | + // DANGER: no matter what, DONT CHANGE THE SCRIPT ID OF THIS SCRIPT | |
| 449 | + $scriptId = BITFORMS_PREFIX . 'recaptcha'; | |
| 450 | + wp_enqueue_script($scriptId, "https://www.google.com/recaptcha/api.js?render={$reCAPTCHA->siteKey}"); | |
| 451 | + } | |
| 452 | + | |
| 453 | + $configs = [ | |
| 454 | + 'bf_separator' => BITFORMS_BF_SEPARATOR, | |
| 455 | + ]; | |
| 456 | + | |
| 457 | + // check if fields has paypal or razorpay | |
| 458 | + $paymentFields = ['paypal', 'razorpay', 'stripe']; | |
| 459 | + $paymentFieldData = []; | |
| 460 | + foreach ($fields as $key => $field) { | |
| 461 | + if (in_array($field->typ, $paymentFields)) { | |
| 462 | + $paymentFieldData[$key] = $field; | |
| 463 | + } | |
| 464 | + } | |
| 465 | + | |
| 466 | + if (!empty($paymentFieldData)) { | |
| 467 | + $integrationHandler = new IntegrationHandler(0); | |
| 468 | + foreach ($paymentFieldData as $fldKey => $fldData) { | |
| 469 | + $paymentIntegration = $integrationHandler->getAIntegration($fldData->payIntegID); | |
| 470 | + if (is_wp_error($paymentIntegration)) { | |
| 471 | + continue; | |
| 340 | 472 | } |
| 473 | + if ('paypal' === $fldData->typ) { | |
| 474 | + $integrationDetails = json_decode($paymentIntegration[0]->integration_details); | |
| 475 | + $clientID = $integrationDetails->clientID; | |
| 476 | + $fields->{$fldKey}->clientId = $clientID; | |
| 477 | + } elseif ('razorpay' === $fldData->typ) { | |
| 478 | + $integrationDetails = json_decode($paymentIntegration[0]->integration_details); | |
| 479 | + $clientID = $integrationDetails->apiKey; | |
| 480 | + $fields->{$fldKey}->clientId = $clientID; | |
| 481 | + } elseif ('stripe' === $fldData->typ) { | |
| 482 | + $integrationDetails = json_decode($paymentIntegration[0]->integration_details); | |
| 483 | + $publishableKey = $integrationDetails->publishableKey; | |
| 484 | + $fields->{$fldKey}->publishableKey = $publishableKey; | |
| 485 | + } | |
| 341 | 486 | } |
| 487 | + } | |
| 342 | 488 | |
| 343 | - $configs = [ | |
| 344 | - 'bf_separator' => BITFORMS_BF_SEPARATOR, | |
| 489 | + $bitFormFrontArr = [ | |
| 490 | + 'ajaxURL' => admin_url('admin-ajax.php'), | |
| 491 | + 'nonce' => $nonce, | |
| 492 | + 'version' => BITFORMS_VERSION, | |
| 493 | + 'layout' => $layout, | |
| 494 | + 'nestedLayout' => $nestedLayout, | |
| 495 | + 'fields' => $fields, | |
| 496 | + 'buttons' => $buttons, | |
| 497 | + 'fieldsKey' => $fieldsKey, | |
| 498 | + 'file' => $file, | |
| 499 | + 'configs' => $configs, | |
| 500 | + 'formId' => $formID, | |
| 501 | + 'appID' => "bitforms_{$formID}", | |
| 502 | + 'GCLID' => $FrontendFormManager->isGCLIDEnabled(), | |
| 503 | + 'assetUrl' => BITFORMS_ASSET_URI, | |
| 504 | + 'onfieldCondition' => !empty($workFlowreturnedOnUserInput['onfield_input_conditions']) ? $workFlowreturnedOnUserInput['onfield_input_conditions'] : false, | |
| 505 | + 'smartTags' => SmartTags::smartTags(SmartTags::getPostUserData()), | |
| 506 | + 'paymentCallbackUrl' => get_rest_url() . 'bitform/v1/payments/razorpay', | |
| 507 | + 'gRecaptchaSiteKey' => !empty($reCAPTCHA->siteKey) ? $reCAPTCHA->siteKey : null, | |
| 508 | + 'gRecaptchaVersion' => !empty($reCAPTCHAVersion) ? $reCAPTCHAVersion : null, | |
| 509 | + 'turnstileSiteKey' => !empty($turnstileSiteKey) ? $turnstileSiteKey : null | |
| 510 | + ]; | |
| 511 | + | |
| 512 | + if ($entryId) { | |
| 513 | + $bitFormFrontArr['entryId'] = $entryId; | |
| 514 | + } | |
| 515 | + | |
| 516 | + if (isset($additional->enabled->validateFocusLost)) { | |
| 517 | + $bitFormFrontArr['validateFocusLost'] = true; | |
| 518 | + } | |
| 519 | + | |
| 520 | + if (!empty($isAbandoned)) { | |
| 521 | + $bitFormFrontArr['oldValues'] = $this->getFieldsValue($formID, $isAbandoned); | |
| 522 | + if (empty($entryId)) { | |
| 523 | + $bitFormFrontArr['entryId'] = $isAbandoned; | |
| 524 | + } | |
| 525 | + } | |
| 526 | + | |
| 527 | + $formInfo = $FrontendFormManager->getFormInfo(); | |
| 528 | + if (is_array($layout) && count($layout) > 1) { | |
| 529 | + $multiStepSettings = isset($formInfo->multiStepSettings) ? $formInfo->multiStepSettings : null; | |
| 530 | + $newTempSettings = (object) [ | |
| 531 | + 'validateOnStepChange' => isset($multiStepSettings->validateOnStepChange) ? $multiStepSettings->validateOnStepChange : false, | |
| 532 | + 'maintainStepHistory' => isset($multiStepSettings->maintainStepHistory) ? $multiStepSettings->maintainStepHistory : false, | |
| 533 | + 'saveProgress' => isset($multiStepSettings->saveProgress) ? $multiStepSettings->saveProgress : false, | |
| 534 | + 'showPercentage' => isset($multiStepSettings->progressSettings->showPercentage) ? $multiStepSettings->progressSettings->showPercentage : false, | |
| 345 | 535 | ]; |
| 346 | - | |
| 347 | - $bitFormFrontArr = [ | |
| 348 | - 'ajaxURL' => admin_url('admin-ajax.php'), | |
| 349 | - 'nonce' => $nonce, | |
| 350 | - 'version' => BITFORMS_VERSION, | |
| 351 | - 'layout' => $layout, | |
| 352 | - 'fields' => $newFields, | |
| 353 | - 'buttons' => $buttons, | |
| 354 | - 'fieldsKey' => $fieldsKey, | |
| 355 | - 'file' => $file, | |
| 356 | - 'configs' => $configs, | |
| 357 | - 'formId' => $formID, | |
| 358 | - 'GCLID' => $FrontendFormManager->isGCLIDEnabled(), | |
| 359 | - 'assetUrl' => BITFORMS_ASSET_URI, | |
| 360 | - 'onfieldCondition' => !empty($workFlowreturnedOnUserInput['onfield_input_conditions']) ? $workFlowreturnedOnUserInput['onfield_input_conditions'] : false, | |
| 361 | - 'smartTags' => !empty($workFlowreturnedOnUserInput['smart_tags']) ? $workFlowreturnedOnUserInput['smart_tags'] : [], | |
| 362 | - 'paymentCallbackUrl' => get_rest_url() . 'bitform/v1/payments/razorpay', | |
| 363 | - 'gRecaptchaSiteKey' => !empty($reCAPTCHA->siteKey) ? $reCAPTCHA->siteKey : null, | |
| 364 | - 'gRecaptchaVersion' => !empty($reCAPTCHAVersion) ? $reCAPTCHAVersion : null, | |
| 536 | + $bitFormFrontArr['formInfo'] = (object) [ | |
| 537 | + 'multiStepSettings' => $newTempSettings | |
| 365 | 538 | ]; |
| 539 | + } | |
| 366 | 540 | |
| 367 | - if (isset($additional->enabled->validateFocusLost)) { | |
| 368 | - $bitFormFrontArr['validateFocusLost'] = true; | |
| 541 | + if (Helpers::property_exists_nested($formInfo, 'conversationalSettings->enable', true)) { | |
| 542 | + if (!isset($bitFormFrontArr['formInfo'])) { | |
| 543 | + $bitFormFrontArr['formInfo'] = new \stdClass(); | |
| 369 | 544 | } |
| 545 | + $bitFormFrontArr['formInfo']->conversationalSettings = $formInfo->conversationalSettings; | |
| 546 | + } | |
| 370 | 547 | |
| 371 | - $bitFormsFront = apply_filters( | |
| 372 | - 'bitforms_localized_script', | |
| 373 | - $bitFormFrontArr | |
| 374 | - ); | |
| 548 | + $formAbandonmentSettings = $FrontendFormManager->getFormAbandonmentSettings(); | |
| 549 | + if (Helpers::property_exists_nested($formAbandonmentSettings, 'active', true)) { | |
| 550 | + $bitFormFrontArr['formSettings'] = (object)[ | |
| 551 | + 'formAbandonment' => $formAbandonmentSettings | |
| 552 | + ]; | |
| 553 | + } | |
| 375 | 554 | |
| 376 | - $fields = \json_encode($fields); | |
| 377 | - $layout = \json_encode($layout); | |
| 378 | - $buttons = \json_encode($buttons); | |
| 379 | - $frontArr = json_encode($bitFormFrontArr); | |
| 555 | + $bitFormsFront = apply_filters( | |
| 556 | + 'bitforms_localized_script', | |
| 557 | + $bitFormFrontArr | |
| 558 | + ); | |
| 380 | 559 | |
| 381 | - $bfGlobals = "if(!window.bf_globals) { | |
| 560 | + $layout = wp_json_encode($layout); | |
| 561 | + $buttons = wp_json_encode($buttons); | |
| 562 | + $frontArr = wp_json_encode($bitFormFrontArr); | |
| 563 | + | |
| 564 | + $bfGlobals = <<<BFGLOBALS | |
| 565 | + if(!window.bf_globals) { | |
| 382 | 566 | window.bf_globals = {} |
| 383 | 567 | } if(!window.bf_globals.{$FormIdentifier}) { |
| 384 | 568 | window.bf_globals.{$FormIdentifier} = {} |
| 385 | 569 | } |
| 386 | - window.bf_globals.{$FormIdentifier} = {...window.bf_globals.{$FormIdentifier}, ...{$frontArr}};"; | |
| 387 | - $this->addInlineScript($bfGlobals, 'bit-form-all-script', 'before'); | |
| 570 | + if(document.getElementById('{$FormIdentifier}')) { | |
| 571 | + window.bf_globals.{$FormIdentifier} = {...window.bf_globals.{$FormIdentifier}, ...{$frontArr}}; | |
| 572 | + } | |
| 573 | +BFGLOBALS; | |
| 388 | 574 | |
| 389 | - $html = ''; | |
| 575 | + if ('conversational' === $formType | |
| 576 | + && isset($formContent->formInfo->conversationalSettings->enable) | |
| 577 | + && $formContent->formInfo->conversationalSettings->enable) { | |
| 578 | + $html = $FrontendFormManager->conversationalFormView($fields, $file, $errorMessages); | |
| 579 | + } else { | |
| 580 | + $html = $FrontendFormManager->formView($fields, $file, $errorMessages); | |
| 581 | + } | |
| 390 | 582 | |
| 391 | - FrontendHelpers::isPageBuilder(); | |
| 392 | - global $isPageBuilder; | |
| 393 | - if ($isPageBuilder) { | |
| 394 | - $newFormId = $formID . '-formid'; | |
| 395 | - $formStyles = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css'); | |
| 396 | - $html .= '<style>' . $formStyles . '</style>'; | |
| 397 | - } | |
| 398 | - $html .= $FrontendFormManager->formView($fields, $file, $errorMessages); | |
| 399 | - // if form preview then return html otherwise echo with output buffer | |
| 400 | - if ($formPreview) { | |
| 401 | - $formViewObject = new \stdClass(); | |
| 402 | - $formViewObject->html = $html; | |
| 403 | - $formViewObject->font = $font; | |
| 404 | - $formViewObject->bfGlobals = $bfGlobals; | |
| 405 | - return $formViewObject; | |
| 406 | - } | |
| 407 | - | |
| 408 | - ob_start(); | |
| 409 | - echo trim($html); | |
| 410 | - return ob_get_clean(); | |
| 583 | + // if form preview then return html otherwise echo with output buffer | |
| 584 | + if ($formPreview) { | |
| 585 | + ob_clean(); | |
| 586 | + $formViewObject = new \stdClass(); | |
| 587 | + $formViewObject->html = $html; | |
| 588 | + $formViewObject->font = $font; | |
| 589 | + $formViewObject->bfGlobals = $bfGlobals; | |
| 590 | + return $formViewObject; | |
| 411 | 591 | } |
| 592 | + $html .= <<<BFGLOBALSSCRIPT | |
| 593 | + <script id="bit-form-bf-globals-{$FormIdentifier}">{$bfGlobals}</script> | |
| 594 | +BFGLOBALSSCRIPT; | |
| 595 | + echo trim($html); | |
| 596 | + return ob_get_clean(); | |
| 412 | 597 | } |
| 413 | 598 | |
| 414 | - private function isExist($formID) { | |
| 599 | + private function isExist($formID) | |
| 600 | + { | |
| 415 | 601 | $formModel = new FormModel(); |
| 416 | 602 | $form = $formModel->get( |
| 417 | 603 | [ |
| 418 | 604 | 'id' |
| @@ -426,50 +612,144 @@ | ||
| 426 | 612 | } |
| 427 | 613 | return false; |
| 428 | 614 | } |
| 429 | 615 | |
| 430 | - public function loadAssets($recheck = false, $formID = 0, $isFileExists = false) { | |
| 431 | - FrontendHelpers::getFormIdsFromPost(); | |
| 432 | - FrontendHelpers::isPageBuilder(); | |
| 433 | - global $bfUniqFormIds; | |
| 434 | - global $bfMultipleFormsExists; | |
| 616 | + private function getFieldsValue($formID, $entryID) | |
| 617 | + { | |
| 618 | + $formEntryModel = new FormEntryMetaModel(); | |
| 619 | + $metaValues = $formEntryModel->get( | |
| 620 | + [ | |
| 621 | + 'meta_key', | |
| 622 | + 'meta_value' | |
| 623 | + ], | |
| 624 | + [ | |
| 625 | + 'bitforms_form_entry_id' => $entryID, | |
| 626 | + ] | |
| 627 | + ); | |
| 628 | + $fldsData = (object) []; | |
| 629 | + if (!is_wp_error($metaValues)) { | |
| 630 | + foreach ($metaValues as $metaValue) { | |
| 631 | + $metaKey = $metaValue->meta_key; | |
| 632 | + $metaVal = $metaValue->meta_value; | |
| 633 | + // if meta value is array then convert to string | |
| 634 | + if (preg_match('/^\[.*\]$/', $metaVal)) { | |
| 635 | + $metaVal = json_decode($metaVal); | |
| 636 | + //check is it array of objects | |
| 637 | + if (is_array($metaVal) && is_object($metaVal[0])) { | |
| 638 | + $metaVal = $metaValue->meta_value; | |
| 639 | + } else { | |
| 640 | + $metaVal = implode(BITFORMS_BF_SEPARATOR, $metaVal); | |
| 641 | + } | |
| 642 | + } | |
| 643 | + if (!isset($fldsData->{$metaKey})) { | |
| 644 | + $fldsData->{$metaKey} = ''; | |
| 645 | + } | |
| 646 | + $fldsData->{$metaKey} = $metaVal; | |
| 647 | + } | |
| 648 | + } | |
| 435 | 649 | |
| 436 | - if ($formID) { | |
| 650 | + return $fldsData; | |
| 651 | + } | |
| 652 | + | |
| 653 | + public function setFieldsValue($fields, $formID, $entryID) | |
| 654 | + { | |
| 655 | + $formEntryModel = new FormEntryMetaModel(); | |
| 656 | + $metaValues = $formEntryModel->get( | |
| 657 | + [ | |
| 658 | + 'meta_key', | |
| 659 | + 'meta_value' | |
| 660 | + ], | |
| 661 | + [ | |
| 662 | + 'bitforms_form_entry_id' => $entryID, | |
| 663 | + ] | |
| 664 | + ); | |
| 665 | + if (!is_wp_error($metaValues)) { | |
| 666 | + foreach ($metaValues as $metaValue) { | |
| 667 | + $metaKey = $metaValue->meta_key; | |
| 668 | + $metaVal = $metaValue->meta_value; | |
| 669 | + // if meta value is array then convert to string | |
| 670 | + if (preg_match('/^\[.*\]$/', $metaVal)) { | |
| 671 | + $metaVal = json_decode($metaVal); | |
| 672 | + //check is it array of objects | |
| 673 | + if (is_array($metaVal) && is_object($metaVal[0])) { | |
| 674 | + $metaVal = $metaValue->meta_value; | |
| 675 | + } else { | |
| 676 | + $metaVal = implode(BITFORMS_BF_SEPARATOR, $metaVal); | |
| 677 | + } | |
| 678 | + } | |
| 679 | + if (property_exists($fields, $metaKey)) { | |
| 680 | + $fields->{$metaKey}->val = $metaVal; | |
| 681 | + if ('file-up' === $fields->{$metaKey}->typ || 'advanced-file-up' === $fields->{$metaKey}->typ) { | |
| 682 | + $fields->{$metaKey}->val = $metaValue->meta_value; | |
| 683 | + $fields->{$metaKey}->config->oldFiles = $metaValue->meta_value; | |
| 684 | + $urlQuery = wp_parse_url(FileDownloadProvider::getBaseDownloadURL(), PHP_URL_QUERY); | |
| 685 | + $baseDLURL = FileDownloadProvider::getBaseDownloadURL(); | |
| 686 | + $baseDLURL = empty($urlQuery) ? $baseDLURL . '?' : $baseDLURL . '&'; | |
| 687 | + $fields->{$metaKey}->config->baseDLURL = $baseDLURL . "formID={$formID}&entryID={$entryID}"; | |
| 688 | + } | |
| 689 | + } | |
| 690 | + } | |
| 691 | + } | |
| 692 | + return $fields; | |
| 693 | + } | |
| 694 | + | |
| 695 | + public function loadAssets($formID = 0, $fromType = 'classic') | |
| 696 | + { | |
| 697 | + $bfUniqFormIds = FrontendHelpers::getAllFormIdsInPage(); | |
| 698 | + $isPageBuilder = FrontendHelpers::$isPageBuilder; | |
| 699 | + $bfMultipleFormsExists = $isPageBuilder ? true : count($bfUniqFormIds) > 1; | |
| 700 | + | |
| 701 | + if (!empty($formID)) { | |
| 437 | 702 | $formIds = [$formID]; |
| 438 | - if (count($bfUniqFormIds) > 1) { | |
| 439 | - $bfMultipleFormsExists = true; | |
| 440 | - } | |
| 441 | 703 | } else { |
| 442 | 704 | $formIds = $bfUniqFormIds; |
| 443 | 705 | } |
| 444 | - | |
| 445 | 706 | foreach ($formIds as $formID) { |
| 707 | + global $bitform_dequeued_styles; | |
| 708 | + if (is_array($bitform_dequeued_styles) && in_array($formID, $bitform_dequeued_styles)) { | |
| 709 | + continue; | |
| 710 | + } | |
| 446 | 711 | if ($bfMultipleFormsExists) { |
| 447 | 712 | $newFormId = $formID . '-formid'; |
| 448 | 713 | } else { |
| 449 | 714 | $newFormId = $formID; |
| 450 | 715 | } |
| 451 | - if (is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css')) { | |
| 452 | - $styleModifyTime = filemtime(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css'); | |
| 453 | - wp_register_style( | |
| 454 | - 'bitform-style' . $formID, | |
| 455 | - BITFORMS_UPLOAD_BASE_URL . '/form-styles/bitform-' . $newFormId . '.css', | |
| 716 | + $formUpdateVersion = get_option('bit-form_form_update_version'); | |
| 717 | + if (!wp_style_is('bitform-style-' . $newFormId) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css')) { | |
| 718 | + wp_enqueue_style( | |
| 719 | + 'bitform-style-' . $newFormId, | |
| 720 | + BITFORMS_UPLOAD_BASE_URL . "/form-styles/bitform-{$newFormId}.css", | |
| 456 | 721 | [], |
| 457 | - $styleModifyTime, | |
| 458 | - 'all' | |
| 722 | + $formUpdateVersion | |
| 459 | 723 | ); |
| 460 | - wp_enqueue_style('bitform-style' . $formID); | |
| 724 | + if ($isPageBuilder) { | |
| 725 | + $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-' . $newFormId . '.css'); | |
| 726 | + echo sprintf("<style id='bitform-style-{$newFormId}'>%s</style>", $formStyle); | |
| 727 | + } | |
| 461 | 728 | } |
| 462 | - if (is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $newFormId . '.css')) { | |
| 463 | - $styleModifyTime = filemtime(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $newFormId . '.css'); | |
| 464 | - wp_register_style( | |
| 729 | + if (!wp_style_is('bitform-style-custom-' . $formID) && is_readable(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css')) { | |
| 730 | + wp_enqueue_style( | |
| 465 | 731 | 'bitform-style-custom-' . $formID, |
| 466 | - BITFORMS_UPLOAD_BASE_URL . '/form-styles/bitform-custom-' . $newFormId . '.css', | |
| 732 | + BITFORMS_UPLOAD_BASE_URL . "/form-styles/bitform-custom-{$formID}.css", | |
| 467 | 733 | [], |
| 468 | - $styleModifyTime, | |
| 469 | - 'all' | |
| 734 | + $formUpdateVersion | |
| 470 | 735 | ); |
| 471 | - wp_enqueue_style('bitform-style-custom-' . $formID); | |
| 736 | + if ($isPageBuilder) { | |
| 737 | + $formStyle = file_get_contents(BITFORMS_CONTENT_DIR . '/form-styles/bitform-custom-' . $formID . '.css'); | |
| 738 | + echo sprintf("<style id='bitform-style-custom-{$formID}'>%s</style>", $formStyle); | |
| 739 | + } | |
| 740 | + } | |
| 741 | + // load conversational form css | |
| 742 | + if ('conversational' === $fromType) { | |
| 743 | + if (!wp_style_is('bitform-conversational-style-' . $formID) && | |
| 744 | + is_readable(BITFORMS_CONTENT_DIR . "/form-styles/bitform-conversational-{$formID}.css")) { | |
| 745 | + wp_enqueue_style( | |
| 746 | + 'bitform-conversational-style', | |
| 747 | + BITFORMS_UPLOAD_BASE_URL . "/form-styles/bitform-conversational-{$formID}.css", | |
| 748 | + [], | |
| 749 | + $formUpdateVersion | |
| 750 | + ); | |
| 751 | + } | |
| 472 | 752 | } |
| 473 | 753 | } |
| 474 | 754 | } |
| 475 | 755 | } |