| @@ -5,9 +5,10 @@ | ||
| 5 | 5 | /** |
| 6 | 6 | * Helps to relpicate form information for form duplication or export |
| 7 | 7 | * |
| 8 | 8 | */ |
| 9 | -final class FormDuplicateHelper { | |
| 9 | +final class FormDuplicateHelper | |
| 10 | +{ | |
| 10 | 11 | /** |
| 11 | 12 | * Create replica |
| 12 | 13 | * |
| 13 | 14 | * @param Array $data Data to replicate |
| @@ -15,9 +16,10 @@ | ||
| 15 | 16 | * @param Integer|String $newFormId Id of the new form |
| 16 | 17 | * |
| 17 | 18 | * @return $formData Replicated data |
| 18 | 19 | */ |
| 19 | - public static function createReplica($data, $oldFormId, $newFormId) { | |
| 20 | + public static function createReplica($data, $oldFormId, $newFormId) | |
| 21 | + { | |
| 20 | 22 | // $new_lay_fields = static::genarateNewLayoutNField($data['form_content']['layout'], $data['form_content']['fields'], $oldFormId, $newFormId); |
| 21 | 23 | $formName = $data['form_name']; |
| 22 | 24 | $formData = (object)[]; |
| 23 | 25 | $formData->form_id = $newFormId; |
| @@ -22,29 +24,42 @@ | ||
| 22 | 24 | $formData = (object)[]; |
| 23 | 25 | $formData->form_id = $newFormId; |
| 24 | 26 | $formData->fields = (object) $data['form_content']['fields']; |
| 25 | 27 | $formData->layout = $data['form_content']['layout']; |
| 28 | + $formData->nestedLayouts = $data['form_content']['nestedLayout']; | |
| 26 | 29 | $formData->form_name = $formName; |
| 30 | + $formData->formInfo = isset($data['form_content']['formInfo']) ? $data['form_content']['formInfo'] : (object)[]; | |
| 27 | 31 | |
| 28 | 32 | if (isset($data['formSettings'])) { |
| 29 | 33 | $formSettings = (array) (!is_string($data['formSettings']) ? $data['formSettings'] : json_decode($data['formSettings'])); |
| 30 | 34 | |
| 31 | 35 | if (isset($formSettings['confirmation'])) { |
| 32 | - $confirmation = !is_string($formSettings['confirmation']) ? json_encode($formSettings['confirmation']) : $formSettings['confirmation']; | |
| 36 | + $confirmation = !is_string($formSettings['confirmation']) ? wp_json_encode($formSettings['confirmation']) : $formSettings['confirmation']; | |
| 33 | 37 | $formSettings['confirmation'] = json_decode(\preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $confirmation)); |
| 34 | 38 | } |
| 35 | 39 | |
| 36 | 40 | if (isset($formSettings['integrations'])) { |
| 37 | - $integrations = !is_string($formSettings['integrations']) ? json_encode($formSettings['integrations']) : $formSettings['integrations']; | |
| 41 | + $integrations = !is_string($formSettings['integrations']) ? wp_json_encode($formSettings['integrations']) : $formSettings['integrations']; | |
| 38 | 42 | $integrations = \preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $integrations); |
| 39 | 43 | $formSettings['integrations'] = json_decode(\preg_replace('/(\"formField\"\s*\:\s*\"bf?)(\d+)([- \d]+)/', '${1}' . $newFormId . '$3', $integrations)); |
| 40 | 44 | } |
| 41 | 45 | |
| 46 | + if (isset($formSettings['formAbandonment'])) { | |
| 47 | + $formAbandonment = !is_string($formSettings['formAbandonment']) ? wp_json_encode($formSettings['formAbandonment']) : $formSettings['formAbandonment']; | |
| 48 | + $formSettings['formAbandonment'] = json_decode(\preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $formAbandonment)); | |
| 49 | + } | |
| 50 | + | |
| 42 | 51 | if (isset($formSettings['mailTem'])) { |
| 43 | - $mailTem = !is_string($formSettings['mailTem']) ? json_encode($formSettings['mailTem']) : $formSettings['mailTem']; | |
| 52 | + $mailTem = !is_string($formSettings['mailTem']) ? wp_json_encode($formSettings['mailTem']) : $formSettings['mailTem']; | |
| 44 | 53 | $formSettings['mailTem'] = json_decode(\preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $mailTem)); |
| 45 | 54 | $formData->formSettings = (object)$formSettings; |
| 46 | 55 | } |
| 56 | + | |
| 57 | + if (isset($formSettings['pdfTem'])) { | |
| 58 | + $pdfTem = !is_string($formSettings['pdfTem']) ? wp_json_encode($formSettings['pdfTem']) : $formSettings['pdfTem']; | |
| 59 | + $formSettings['pdfTem'] = json_decode(\preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $pdfTem)); | |
| 60 | + $formData->formSettings = (object)$formSettings; | |
| 61 | + } | |
| 47 | 62 | } |
| 48 | 63 | |
| 49 | 64 | if (isset($data['breakpointSize'])) { |
| 50 | 65 | $formData->breakpointSize = $data['breakpointSize']; |
| @@ -49,9 +64,9 @@ | ||
| 49 | 64 | if (isset($data['breakpointSize'])) { |
| 50 | 65 | $formData->breakpointSize = $data['breakpointSize']; |
| 51 | 66 | } |
| 52 | 67 | if (isset($data['style'])) { |
| 53 | - // $styleTemp = !is_string($data['style']) ? json_encode($data['style']) : $data['style']; | |
| 68 | + // $styleTemp = !is_string($data['style']) ? wp_json_encode($data['style']) : $data['style']; | |
| 54 | 69 | // $formData->style = json_decode(\preg_replace('/(\.?b)(\d+)(-\d+)/', '${1}' . $newFormId . '$3', $styleTemp)); |
| 55 | 70 | $formData->style = $data['style']; |
| 56 | 71 | } |
| 57 | 72 | if (isset($data['themeVars'])) { |
| @@ -67,9 +82,9 @@ | ||
| 67 | 82 | $formData->builderSettings = $data['builderSettings']; |
| 68 | 83 | } |
| 69 | 84 | |
| 70 | 85 | if (isset($data['workFlows'])) { |
| 71 | - $workFlows = !is_string($data['workFlows']) ? \json_encode($data['workFlows']) : $data['workFlows']; | |
| 86 | + $workFlows = !is_string($data['workFlows']) ? wp_json_encode($data['workFlows']) : $data['workFlows']; | |
| 72 | 87 | $workFlows = \preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $workFlows); |
| 73 | 88 | $workFlows = json_decode(\preg_replace('/(\"bf?)(\d+)([- \d]+\")/', '${1}' . $newFormId . '$3', $workFlows)); |
| 74 | 89 | $formData->workFlows = $workFlows; |
| 75 | 90 | } |
| @@ -74,9 +89,9 @@ | ||
| 74 | 89 | $formData->workFlows = $workFlows; |
| 75 | 90 | } |
| 76 | 91 | |
| 77 | 92 | if (isset($data['reports'])) { |
| 78 | - $reports = !is_string($data['reports']) ? \json_encode($data['reports']) : $data['reports']; | |
| 93 | + $reports = !is_string($data['reports']) ? wp_json_encode($data['reports']) : $data['reports']; | |
| 79 | 94 | $reports = json_decode(\preg_replace("/(\"bf?)(\d+)([- \d]+\")/", '${1}' . $newFormId . '$3', $reports)); |
| 80 | 95 | $formData->reports = $reports; |
| 81 | 96 | } |
| 82 | 97 | |
| @@ -83,12 +98,25 @@ | ||
| 83 | 98 | if (isset($data['additional'])) { |
| 84 | 99 | $formData->additional = $data['additional']; |
| 85 | 100 | } |
| 86 | 101 | |
| 102 | + $formData->customCode = (object) []; | |
| 103 | + if (isset($data['customCode']->customCss)) { | |
| 104 | + $customCss = !is_string($data['customCode']->customCss) ? wp_json_encode($data['customCode']->customCss) : $data['customCode']->customCss; | |
| 105 | + $customCss = \preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $customCss); | |
| 106 | + $formData->customCode->customCss = \preg_replace('/(\"bf?)(\d+)([- \d]+\")/', '${1}' . $newFormId . '$3', $customCss); | |
| 107 | + } | |
| 108 | + | |
| 109 | + if (isset($data['customCode']->customJs)) { | |
| 110 | + $customJs = !is_string($data['customCode']->customJs) ? wp_json_encode($data['customCode']->customJs) : $data['customCode']->customJs; | |
| 111 | + $customJs = \preg_replace('/(\${bf?)(\d+)([- \d]+\})/', '${1}' . $newFormId . '$3', $customJs); | |
| 112 | + $formData->customCode->customJs = \preg_replace('/(\"bf?)(\d+)([- \d]+\")/', '${1}' . $newFormId . '$3', $customJs); | |
| 113 | + } | |
| 87 | 114 | return $formData; |
| 88 | 115 | } |
| 89 | 116 | |
| 90 | - public static function genarateNewLayoutNField($layout, $fields, $oldId, $newId) { | |
| 117 | + public static function genarateNewLayoutNField($layout, $fields, $oldId, $newId) | |
| 118 | + { | |
| 91 | 119 | $newField = (object) []; |
| 92 | 120 | foreach ((array)$layout->lg as $ind => $itm) { |
| 93 | 121 | $fld_tmp = $fields->{$layout->lg[$ind]->i}; |
| 94 | 122 | $layout->lg[$ind]->i = \preg_replace('/bf?(\d+)(-\d+)/', "b$newId$2", $layout->lg[$ind]->i); |
| @@ -98,9 +126,10 @@ | ||
| 98 | 126 | } |
| 99 | 127 | return ['layout' => $layout, 'fields' => $newField]; |
| 100 | 128 | } |
| 101 | 129 | |
| 102 | - public static function calcRowHeight($formStyle, $formID) { | |
| 130 | + public static function calcRowHeight($formStyle, $formID) | |
| 131 | + { | |
| 103 | 132 | $rowHeight = 0; |
| 104 | 133 | preg_match('/fld-lbl-' . $formID . '\s*{[\w\-\(\)\!\;\,\s\:\.\#]*font-size\s*:\s*(\d+)[px|em|rem|!important]*;/', $formStyle, $fontSize); |
| 105 | 134 | if ($fontSize) { |
| 106 | 135 | $lineHeight = 1; |
| @@ -129,9 +158,10 @@ | ||
| 129 | 158 | |
| 130 | 159 | return $rowHeight / 2; |
| 131 | 160 | } |
| 132 | 161 | |
| 133 | - public static function cssPropSumByAxis($value, $axis) { | |
| 162 | + public static function cssPropSumByAxis($value, $axis) | |
| 163 | + { | |
| 134 | 164 | if (1 === count($value)) { |
| 135 | 165 | $value = array_fill(0, 4, $value[0]); |
| 136 | 166 | } |
| 137 | 167 | |