PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.42
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.42
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Integrations / GlobalIntegrationManager.php

GlobalIntegrationManager.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 3.6.42, at app/Services/Integrations/GlobalIntegrationManager.php

283 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\Integrations;
4
5 use FluentForm\Framework\Foundation\Application;
6 use FluentForm\Framework\Helpers\ArrayHelper;
7
8 class GlobalIntegrationManager
9 {
10
11 private $app;
12
13 public function __construct(Application $app)
14 {
15 $this->app = $app;
16 }
17
18 public function getGlobalSettingsAjax()
19 {
20 $settingsKey = sanitize_text_field($_REQUEST['settings_key']);
21 $settings = apply_filters('fluentform_global_integration_settings_' . $settingsKey, []);
22 $fieldSettings = apply_filters('fluentform_global_integration_fields_' . $settingsKey, []);
23
24 if (!$fieldSettings) {
25 wp_send_json_error([
26 'settings' => $settings,
27 'settings_key' => $settingsKey,
28 'message' => __('Sorry! No integration failed found with: ', 'fluentform') . $settingsKey
29 ], 423);
30 }
31
32 if (empty($fieldSettings['save_button_text'])) {
33 $fieldSettings['save_button_text'] = __('Save Settings', 'fluentform');
34 }
35
36 if (empty($fieldSettings['valid_message'])) {
37 $fieldSettings['valid_message'] = __('Your API Key is valid', 'fluentform');
38 }
39
40 if (empty($fieldSettings['invalid_message'])) {
41 $fieldSettings['invalid_message'] = __('Your API Key is not valid', 'fluentform');
42 }
43
44 wp_send_json_success([
45 'integration' => $settings,
46 'settings' => $fieldSettings
47 ], 200);
48
49 }
50
51 public function saveGlobalSettingsAjax()
52 {
53 $settingsKey = sanitize_text_field($_REQUEST['settings_key']);
54 $integration = wp_unslash($_REQUEST['integration']);
55 do_action('fluentform_save_global_integration_settings_' . $settingsKey, $integration);
56
57 // Someone should catch that above action and send response
58 wp_send_json_error([
59 'message' => __('Sorry, no Integration found. Please make sure that latest version of WP Fluent Form pro installed', 'wpfluentform')
60 ], 423);
61
62 }
63
64 public function getAllFormIntegrations()
65 {
66 $formId = $this->app->request->get('form_id');
67
68 $notificationKeys = apply_filters('fluentform_global_notification_types', [], $formId);
69
70 $feeds = wpFluent()->table('fluentform_form_meta')
71 ->where('form_id', $formId)
72 ->whereIn('meta_key', $notificationKeys)
73 ->orderBy('id', 'DESC')
74 ->get();
75
76 $formattedFeeds = [];
77
78 foreach ($feeds as $feed) {
79 $data = json_decode($feed->value, true);
80 $enabled = $data['enabled'];
81 if($enabled && $enabled == 'true') {
82 $enabled = true;
83 } else if($enabled == 'false') {
84 $enabled = false;
85 }
86 $feedData = [
87 'id' => $feed->id,
88 'name' => ArrayHelper::get($data, 'name'),
89 'enabled' => $enabled,
90 'provider' => $feed->meta_key,
91 'feed' => $data
92 ];
93 $feedData = apply_filters('fluentform_global_notification_feed_' . $feed->meta_key, $feedData, $formId);
94 $formattedFeeds[] = $feedData;
95 }
96
97 $availableIntegrations = apply_filters('fluentform_get_available_form_integrations', [], $formId);
98
99 wp_send_json_success([
100 'feeds' => $formattedFeeds,
101 'available_integrations' => $availableIntegrations,
102 'all_module_config_url' => admin_url('admin.php?page=fluent_form_add_ons')
103 ], 200);
104
105 }
106
107 public function updateNotificationStatus()
108 {
109 $formId = $this->app->request->get('form_id');
110 $notificationId = $this->app->request->get('notification_id');
111 $status = $_REQUEST['status'];
112
113 $feed = wpFluent()->table('fluentform_form_meta')
114 ->where('form_id', intval($formId))
115 ->where('id', intval($notificationId))
116 ->first();
117
118 $notification = json_decode($feed->value, true);
119
120
121 if ($status == 'false' || !$status) {
122 $notification['enabled'] = false;
123 } else {
124 $notification['enabled'] = true;
125 }
126
127 wpFluent()->table('fluentform_form_meta')
128 ->where('form_id', intval($formId))
129 ->where('id', intval($notificationId))
130 ->update([
131 'value' => json_encode($notification, JSON_NUMERIC_CHECK)
132 ]);
133
134 $feed = wpFluent()->table('fluentform_form_meta')
135 ->where('form_id', intval($formId))
136 ->where('id', intval($notificationId))
137 ->first();
138
139
140 wp_send_json_success([
141 'message' => __('Integration successfully updated', 'fluentform')
142 ], 200);
143
144 }
145
146 public function getIntegrationSettings()
147 {
148 $integrationName = $this->app->request->get('integration_name');
149 $integrationId = intval($this->app->request->get('integration_id'));
150 $formId = intval($this->app->request->get('form_id'));
151
152 $settings = [
153 'conditionals' => [
154 'conditions' => [],
155 'status' => false,
156 'type' => 'all'
157 ],
158 'enabled' => true,
159 'list_id' => '',
160 'list_name' => '',
161 'name' => '',
162 'merge_fields' => []
163 ];
164
165 $mergeFields = false;
166 if ($integrationId) {
167 $feed = wpFluent()->table('fluentform_form_meta')
168 ->where('form_id', $formId)
169 ->where('id', $integrationId)
170 ->first();
171
172 if ($feed->value) {
173 $settings = json_decode($feed->value, true);
174
175 $settings = apply_filters('fluentform_get_integration_values_' . $integrationName, $settings, $feed, $formId);
176 if (!empty($settings['list_id'])) {
177 $mergeFields = apply_filters('fluentform_get_integration_merge_fields_' . $integrationName, false, $settings['list_id'], $formId);
178 }
179 }
180 } else {
181 $settings = apply_filters('fluentform_get_integration_defaults_' . $integrationName, $settings, $formId);
182 }
183
184 if($settings['enabled'] == 'true') {
185 $settings['enabled'] = true;
186 } else if($settings['enabled'] == 'false' || $settings['enabled']) {
187 $settings['enabled'] = false;
188 }
189
190 $settingsFields = apply_filters('fluentform_get_integration_settings_fields_' . $integrationName, [], $formId, $settings);
191
192
193 wp_send_json_success([
194 'settings' => $settings,
195 'settings_fields' => $settingsFields,
196 'merge_fields' => $mergeFields
197 ], 200);
198
199 }
200
201 public function saveIntegrationSettings()
202 {
203 $integrationName = $this->app->request->get('integration_name');
204 $integrationId = intval($this->app->request->get('integration_id'));
205 $formId = intval($this->app->request->get('form_id'));
206
207 if($this->app->request->get('data_type') == 'stringify') {
208 $integration = \json_decode($this->app->request->get('integration'), true);
209 } else {
210 $integration = wp_unslash($_REQUEST['integration']);
211 }
212
213 if($integration['enabled'] && $integration['enabled'] == 'true') {
214 $integration['status'] = true;
215 }
216
217 if(!$integration['name']) {
218 wp_send_json_error([
219 'message' => 'Validation Failed',
220 'errors' => [
221 'name' => ['Feed name is required']
222 ]
223 ], 423);
224 }
225
226 $integration = apply_filters('fluentform_save_integration_value_'.$integrationName, $integration, $integrationId, $formId);
227
228 $data = [
229 'form_id' => $formId,
230 'meta_key' => $integrationName.'_feeds',
231 'value' => \json_encode($integration)
232 ];
233
234 $data = apply_filters('fluentform_save_integration_settings_'.$integrationName, $data, $integrationId);
235
236 $created = false;
237 if($integrationId) {
238 wpFluent()->table('fluentform_form_meta')
239 ->where('form_id', $formId)
240 ->where('id', $integrationId)
241 ->update($data);
242 } else {
243 $created = true;
244 $integrationId = wpFluent()->table('fluentform_form_meta')
245 ->insert($data);
246 }
247
248 wp_send_json_success([
249 'message' => __('Integration successfully saved', 'fluentform'),
250 'integration_id' => $integrationId,
251 'integration_name' => $integrationName,
252 'created' => $created
253 ], 200);
254 }
255
256 public function deleteIntegrationFeed()
257 {
258 $formId = intval($this->app->request->get('form_id'));
259 $integrationId = intval($this->app->request->get('integration_id'));
260
261 wpFluent()->table('fluentform_form_meta')
262 ->where('form_id', $formId)
263 ->where('id', $integrationId)
264 ->delete();
265
266 wp_send_json_success([
267 'message' => __('Selected integration feed successfully deleted', 'fluentform')
268 ]);
269 }
270
271 public function getIntegrationList()
272 {
273 $integrationName = $this->app->request->get('integration_name');
274 $formId = intval($this->app->request->get('form_id'));
275 $listId = $this->app->request->get('list_id');
276 $merge_fields = apply_filters('fluentform_get_integration_merge_fields_' . $integrationName, false, $listId, $formId);
277
278 wp_send_json_success([
279 'merge_fields' => $merge_fields
280 ], 200);
281
282 }
283 }