PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.9
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.9
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 / Integrations.php

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

191 lines 6.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 *
5 * @package BitForms
6 */
7
8 namespace BitCode\BitForm\Core\Integration;
9 use BitCode\BitForm\Core\Database\FormEntryModel;
10 use BitCode\BitForm\Core\Database\FormModel;
11 use BitCode\BitForm\Core\Util\SmartTags;
12 /**
13 * Provides details of available integration and helps to
14 * execute available integrations
15 */
16
17 use WP_Error;
18 use FilesystemIterator;
19
20 final class Integrations
21 {
22 public $integrations = array();
23
24 /**
25 * Undocumented function
26 *
27 * @return all
28 */
29 public function getAllIntegrations()
30 {
31 return $this->allIntegrations();
32 }
33 /**
34 * Undocumented function
35 *
36 * @return void
37 */
38 protected function allIntegrations()
39 {
40 $dirs = new FilesystemIterator(__DIR__);
41 foreach ($dirs as $dirInfo) {
42 if ($dirInfo->isDir()) {
43 $integartionBaseName = basename($dirInfo);
44 if (
45 file_exists(__DIR__ . '/' . $integartionBaseName)
46 && file_exists(__DIR__ . '/' . $integartionBaseName . '/' . $integartionBaseName . 'Handler.php')
47 ) {
48 $integrations[] = $integartionBaseName;
49 }
50 }
51 }
52 return $integrations;
53 }
54 /**
55 * Checks a Integration Exists or not
56 *
57 * @param String $name Name of Integration
58 * @return boolean
59 */
60 protected static function isExists($name)
61 {
62 if (file_exists(__DIR__ . '/' . $name) && file_exists(__DIR__ . '/' . $name . '/' . $name . 'Handler.php')) {
63 return __NAMESPACE__ . "\\{$name}\\{$name}Handler";
64 } else if (class_exists("BitCode\\BitFormPro\\Integration\\{$name}\\{$name}Handler")) {
65 return "BitCode\\BitFormPro\\Integration\\{$name}\\{$name}Handler";
66 } else {
67 return false;
68 }
69 }
70 /**
71 * This function helps to get single intgration information
72 *
73 * @return bool setIntegration()
74 */
75 public function getIntegration($integartionBaseName)
76 {
77 return $this->setIntegration($integartionBaseName);
78 }
79
80 public function registerAjax()
81 {
82 $dirs = new FilesystemIterator(__DIR__);
83 foreach ($dirs as $dirInfo) {
84 if ($dirInfo->isDir()) {
85 $integartionBaseName = basename($dirInfo);
86 if (
87 file_exists(__DIR__ . '/' . $integartionBaseName)
88 && file_exists(__DIR__ . '/' . $integartionBaseName . '/' . $integartionBaseName . 'Handler.php')
89 ) {
90 $integration = __NAMESPACE__ . "\\{$integartionBaseName}\\{$integartionBaseName}Handler";
91 if (method_exists($integration, 'registerAjax')) {
92 $integration::registerAjax();
93 // (new $integration(0, 0))->registerAjax();
94 }
95 /* $handler = new $integration($integrationID, $formID);
96 $handler->execute($integrationHandler, $integrationDetails, $fieldValues); */
97 }
98 }
99 }
100 }
101
102 protected static function entryDeleted($formId,$entryId){
103 $formModel = new FormModel();
104 $formContent = $formModel->get(
105 [
106 "id",
107 "form_content",
108 ],
109 array(
110 'id' => $formId,
111 )
112 );
113 if(!is_wp_error($formContent)){
114 $content = \json_decode($formContent[0]->form_content);
115 if(isset($content->additional->enabled->submission)){
116 global $wpdb;
117 $prefix = $wpdb->prefix;
118 $formEntryModel = new FormEntryModel();
119 $formEntryModel->bulkDelete(
120 array(
121 "`{$prefix}bitforms_form_entries`.`id`" => $entryId,
122 "`{$prefix}bitforms_form_entries`.`form_id`" => $formId,
123 )
124 );
125 }
126 }
127 }
128
129 public static function specialTagFields($fieldMap)
130 {
131 $specialTagFieldValue = [];
132 $data = SmartTags::getPostUserData(true);
133 $specialTagFields = SmartTags::smartTagFieldKeys();
134
135 foreach ($fieldMap as $value) {
136 $triggerValue = $value->formField;
137 if (in_array($triggerValue, $specialTagFields)) {
138 $specialTagFieldValue[$value->formField] = SmartTags::getSmartTagValue($triggerValue, $data);
139 }
140 }
141 return $specialTagFieldValue;
142 }
143
144 /**
145 * This function helps to execute Integration
146 *
147 * @param Array $integrations List of integrstion to execute.
148 * Element will be json string like {"id":1}
149 * @param Array $fieldValues Values of submitted fields
150 * @param Integer $formID ID of current form
151 *
152 * @return void Nothing to return
153 */
154 public static function executeIntegrations($integrations, $fieldValues, $formID, $logID=null, $entryID = 0)
155 {
156 $integrationHandler = new IntegrationHandler($formID);
157 if (is_array($integrations)) {
158 foreach ($integrations as $integrationIDStr) {
159 $integrationID = intval(json_decode($integrationIDStr)->id, 10);
160 if (!empty($integrationID) && is_int($integrationID)) {
161 $integrationResult
162 = $integrationHandler->getAIntegration($integrationID);
163 $integrationDetails = is_wp_error($integrationResult) ? null : $integrationResult[0];
164 $integrationName = is_null($integrationDetails) ? null : ucfirst(str_replace(' ', '', $integrationDetails->integration_type));
165 if (!is_null($integrationName) && static::isExists($integrationName)) {
166 $integration = static::isExists($integrationName);
167 $handler = new $integration($integrationID, $formID);
168 $integDetails = is_string($integrationDetails->integration_details) ? json_decode($integrationDetails->integration_details) : $integrationDetails->integration_details;
169 if (isset($integDetails->field_map)) {
170 $sptagData = self::specialTagFields($integDetails->field_map);
171 $fieldValues = $fieldValues + $sptagData;
172 }
173 $handler->execute($integrationHandler, $integrationDetails, $fieldValues, $entryID, $logID);
174 }
175 }
176 }
177 }
178 }
179
180 public static function integrationExecutionHelper($integrations, $fieldValue, $formID, $entryID, $logID)
181 {
182 if (empty($integrations) || empty($formID)) {
183 return;
184 }
185 foreach ($integrations as $key => $value) {
186 self::executeIntegrations($value, $fieldValue, $formID, $logID, $entryID);
187 }
188 self::entryDeleted($formID,$entryID);
189 }
190 }
191