PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.50
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.50
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.50, at app/Services/Integrations/GlobalIntegrationManager.php

287 lines 9.6 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 if($notificationKeys) {
71 $feeds = wpFluent()->table('fluentform_form_meta')
72 ->where('form_id', $formId)
73 ->whereIn('meta_key', $notificationKeys)
74 ->orderBy('id', 'DESC')
75 ->get();
76 } else {
77 $feeds = [];
78 }
79
80 $formattedFeeds = [];
81
82 foreach ($feeds as $feed) {
83 $data = json_decode($feed->value, true);
84 $enabled = $data['enabled'];
85 if($enabled && $enabled == 'true') {
86 $enabled = true;
87 } else if($enabled == 'false') {
88 $enabled = false;
89 }
90 $feedData = [
91 'id' => $feed->id,
92 'name' => ArrayHelper::get($data, 'name'),
93 'enabled' => $enabled,
94 'provider' => $feed->meta_key,
95 'feed' => $data
96 ];
97 $feedData = apply_filters('fluentform_global_notification_feed_' . $feed->meta_key, $feedData, $formId);
98 $formattedFeeds[] = $feedData;
99 }
100
101 $availableIntegrations = apply_filters('fluentform_get_available_form_integrations', [], $formId);
102
103 wp_send_json_success([
104 'feeds' => $formattedFeeds,
105 'available_integrations' => $availableIntegrations,
106 'all_module_config_url' => admin_url('admin.php?page=fluent_form_add_ons')
107 ], 200);
108
109 }
110
111 public function updateNotificationStatus()
112 {
113 $formId = $this->app->request->get('form_id');
114 $notificationId = $this->app->request->get('notification_id');
115 $status = $_REQUEST['status'];
116
117 $feed = wpFluent()->table('fluentform_form_meta')
118 ->where('form_id', intval($formId))
119 ->where('id', intval($notificationId))
120 ->first();
121
122 $notification = json_decode($feed->value, true);
123
124
125 if ($status == 'false' || !$status) {
126 $notification['enabled'] = false;
127 } else {
128 $notification['enabled'] = true;
129 }
130
131 wpFluent()->table('fluentform_form_meta')
132 ->where('form_id', intval($formId))
133 ->where('id', intval($notificationId))
134 ->update([
135 'value' => json_encode($notification, JSON_NUMERIC_CHECK)
136 ]);
137
138 $feed = wpFluent()->table('fluentform_form_meta')
139 ->where('form_id', intval($formId))
140 ->where('id', intval($notificationId))
141 ->first();
142
143
144 wp_send_json_success([
145 'message' => __('Integration successfully updated', 'fluentform')
146 ], 200);
147
148 }
149
150 public function getIntegrationSettings()
151 {
152 $integrationName = $this->app->request->get('integration_name');
153 $integrationId = intval($this->app->request->get('integration_id'));
154 $formId = intval($this->app->request->get('form_id'));
155
156 $settings = [
157 'conditionals' => [
158 'conditions' => [],
159 'status' => false,
160 'type' => 'all'
161 ],
162 'enabled' => true,
163 'list_id' => '',
164 'list_name' => '',
165 'name' => '',
166 'merge_fields' => []
167 ];
168
169 $mergeFields = false;
170 if ($integrationId) {
171 $feed = wpFluent()->table('fluentform_form_meta')
172 ->where('form_id', $formId)
173 ->where('id', $integrationId)
174 ->first();
175
176 if ($feed->value) {
177 $settings = json_decode($feed->value, true);
178
179 $settings = apply_filters('fluentform_get_integration_values_' . $integrationName, $settings, $feed, $formId);
180 if (!empty($settings['list_id'])) {
181 $mergeFields = apply_filters('fluentform_get_integration_merge_fields_' . $integrationName, false, $settings['list_id'], $formId);
182 }
183 }
184 } else {
185 $settings = apply_filters('fluentform_get_integration_defaults_' . $integrationName, $settings, $formId);
186 }
187
188 if($settings['enabled'] == 'true') {
189 $settings['enabled'] = true;
190 } else if($settings['enabled'] == 'false' || $settings['enabled']) {
191 $settings['enabled'] = false;
192 }
193
194 $settingsFields = apply_filters('fluentform_get_integration_settings_fields_' . $integrationName, [], $formId, $settings);
195
196
197 wp_send_json_success([
198 'settings' => $settings,
199 'settings_fields' => $settingsFields,
200 'merge_fields' => $mergeFields
201 ], 200);
202
203 }
204
205 public function saveIntegrationSettings()
206 {
207 $integrationName = $this->app->request->get('integration_name');
208 $integrationId = intval($this->app->request->get('integration_id'));
209 $formId = intval($this->app->request->get('form_id'));
210
211 if($this->app->request->get('data_type') == 'stringify') {
212 $integration = \json_decode($this->app->request->get('integration'), true);
213 } else {
214 $integration = wp_unslash($_REQUEST['integration']);
215 }
216
217 if($integration['enabled'] && $integration['enabled'] == 'true') {
218 $integration['status'] = true;
219 }
220
221 if(!$integration['name']) {
222 wp_send_json_error([
223 'message' => 'Validation Failed',
224 'errors' => [
225 'name' => ['Feed name is required']
226 ]
227 ], 423);
228 }
229
230 $integration = apply_filters('fluentform_save_integration_value_'.$integrationName, $integration, $integrationId, $formId);
231
232 $data = [
233 'form_id' => $formId,
234 'meta_key' => $integrationName.'_feeds',
235 'value' => \json_encode($integration)
236 ];
237
238 $data = apply_filters('fluentform_save_integration_settings_'.$integrationName, $data, $integrationId);
239
240 $created = false;
241 if($integrationId) {
242 wpFluent()->table('fluentform_form_meta')
243 ->where('form_id', $formId)
244 ->where('id', $integrationId)
245 ->update($data);
246 } else {
247 $created = true;
248 $integrationId = wpFluent()->table('fluentform_form_meta')
249 ->insert($data);
250 }
251
252 wp_send_json_success([
253 'message' => __('Integration successfully saved', 'fluentform'),
254 'integration_id' => $integrationId,
255 'integration_name' => $integrationName,
256 'created' => $created
257 ], 200);
258 }
259
260 public function deleteIntegrationFeed()
261 {
262 $formId = intval($this->app->request->get('form_id'));
263 $integrationId = intval($this->app->request->get('integration_id'));
264
265 wpFluent()->table('fluentform_form_meta')
266 ->where('form_id', $formId)
267 ->where('id', $integrationId)
268 ->delete();
269
270 wp_send_json_success([
271 'message' => __('Selected integration feed successfully deleted', 'fluentform')
272 ]);
273 }
274
275 public function getIntegrationList()
276 {
277 $integrationName = $this->app->request->get('integration_name');
278 $formId = intval($this->app->request->get('form_id'));
279 $listId = $this->app->request->get('list_id');
280 $merge_fields = apply_filters('fluentform_get_integration_merge_fields_' . $integrationName, false, $listId, $formId);
281
282 wp_send_json_success([
283 'merge_fields' => $merge_fields
284 ], 200);
285
286 }
287 }