PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 2.16.2
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v2.16.2
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
bit-form / includes / Core / Integration / MetaBox / MetaBoxHandler.php

MetaBoxHandler.php in Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder 2.16.2, at includes/Core/Integration/MetaBox/MetaBoxHandler.php

133 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 *POST CREATEION WITH Metabox
5 *
6 */
7
8 namespace BitCode\BitForm\Core\Integration\MetaBox;
9
10 use BitCode\BitForm\Core\Form\FormManager;
11 use BitCode\BitForm\Core\Integration\IntegrationHandler;
12 use BitCode\BitForm\Core\Util\PostHelpers;
13 use BitCode\BitForm\Core\Util\SmartTags;
14 use BitCode\BitForm\Core\Util\WpFileHandler;
15
16 class MetaBoxHandler
17 {
18 use PostHelpers;
19
20 private $_formID;
21
22 private $_wpdb;
23
24 private const UPLOAD_FIELD = ['file-up', 'advanced-file-up'];
25
26 public function __construct($integrationID, $fromID)
27 {
28 $this->_formID = $fromID;
29
30 global $wpdb;
31 $this->_wpdb = $wpdb;
32 }
33
34 private function smartTagMappingValue($fieldMap)
35 {
36 $specialTagFieldValue = [];
37 $data = SmartTags::getPostUserData(true);
38 $specialTagFields = SmartTags::smartTagFieldKeys();
39
40 foreach ($fieldMap as $value) {
41 if (isset($value->formField)) {
42 $triggerValue = $value->formField;
43 if (in_array($triggerValue, $specialTagFields)) {
44 $specialTagFieldValue[$value->formField] = SmartTags::getSmartTagValue($triggerValue, $data);
45 }
46 }
47 }
48 return $specialTagFieldValue;
49 }
50
51 public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID)
52 {
53 $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details;
54
55 $formManger = new FormManager($integrationData->form_id);
56
57 $formFields = $formManger->getFields();
58
59 $postData = $this->setPostData($integrationDetails);
60
61 $id = $postData['post_type'] . '_' . $entryID;
62
63 $existPostId = $this->_wpdb->get_results("SELECT * FROM `{$this->_wpdb->prefix}bitforms_form_entrymeta` WHERE `meta_key`='$id' ");
64
65 $metaBoxFields = rwmb_get_object_fields($postData['post_type']);
66
67 $taxonomies = (new WpFileHandler($integrationData->form_id))->getTaxonomies($formFields, $fieldValues);
68
69 if ([] === $existPostId) {
70 $postId = wp_insert_post(['post_title' => '(no title)', 'post_content' => '']);
71
72 $smartTagValue = $this->smartTagMappingValue($integrationDetails->post_map);
73
74 $updatedValues = $fieldValues + $smartTagValue;
75
76 $postMappedData = $this->postFieldMapping($integrationDetails->post_map, $updatedValues, $postId, $entryID);
77
78 $updatedData = $postData + $postMappedData;
79
80 $updatedData['ID'] = $postId;
81
82 unset($updatedData['_thumbnail_id']);
83
84 wp_update_post($updatedData, true);
85
86 if (!empty($taxonomies)) {
87 foreach ($taxonomies as $taxonomy) {
88 wp_set_post_terms($postId, $taxonomy['value'], $taxonomy['term'], false);
89 }
90 }
91
92 $this->_wpdb->insert(
93 "{$this->_wpdb->prefix}bitforms_form_entrymeta",
94 [
95 'meta_key' => $postData['post_type'] . '_' . $entryID,
96 'meta_value' => $postId,
97 'bitforms_form_entry_id' => $entryID,
98 ]
99 );
100
101 $smartTagValue = $this->smartTagMappingValue($integrationDetails->metabox_map);
102
103 $updatedMbValues = $fieldValues + $smartTagValue;
104
105 $metaBoxMappedData = MetaBoxHelper::metaBoxFieldMapping($integrationDetails->metabox_map, $updatedMbValues, $metaBoxFields, $postId, 'create');
106
107 MetaBoxHelper::fileUploadMapping($integrationDetails->metabox_file_map, $fieldValues, $metaBoxFields, $this->_formID, $entryID, $postId);
108
109 foreach ($metaBoxMappedData as $key => $value) {
110 add_post_meta($postId, $key, $value);
111 }
112 } else {
113 if (!empty($taxonomies)) {
114 foreach ($taxonomies as $taxonomy) {
115 wp_set_post_terms($existPostId[0]->meta_value, $taxonomy['value'], $taxonomy['term'], false);
116 }
117 }
118
119 $metaBoxMappedData = MetaBoxHelper::metaBoxFieldMapping($integrationDetails->metabox_map, $fieldValues, $metaBoxFields, $existPostId[0]->meta_value, 'update');
120
121 foreach ($metaBoxMappedData as $key => $value) {
122 update_post_meta($existPostId[0]->meta_value, $key, $value);
123 }
124
125 $updatedData = $this->postFieldMapping($postData, $integrationDetails->post_map, $fieldValues, $existPostId[0]->meta_value, $entryID);
126
127 $updatedData['ID'] = $existPostId[0]->meta_value;
128
129 wp_update_post($updatedData, true);
130 }
131 }
132 }
133