PluginProbe
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder / 1.4
Bit Form – Contact Form, Payment Forms, Multi Step Forms, Calculator & Custom Form Builder v1.4
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.4, at includes/Core/Integration/Integrations.php

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