PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
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 / GlobalNotificationManager.php

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

283 lines 10.0 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\Database\Migrations\ScheduledActions;
6 use FluentForm\App\Models\EntryDetails;
7 use FluentForm\App\Models\FormMeta;
8 use FluentForm\App\Models\Submission;
9 use FluentForm\App\Modules\Form\FormDataParser;
10 use FluentForm\App\Modules\Form\FormFieldsParser;
11 use FluentForm\App\Services\ConditionAssesor;
12 use FluentForm\App\Services\FormBuilder\ShortCodeParser;
13 use FluentForm\Framework\Foundation\Application;
14 use FluentForm\Framework\Helpers\ArrayHelper;
15
16 /**
17 * @deprecated deprecated use FluentForm\App\Hooks\Handlers\GlobalNotificationHandler;
18 */
19 class GlobalNotificationManager
20 {
21 private $app;
22
23 public function __construct(Application $app)
24 {
25 $this->app = $app;
26 }
27
28 public function globalNotify($insertId, $formData, $form)
29 {
30 $notifications = apply_filters_deprecated(
31 'fluentform_global_notification_active_types',
32 [
33 [],
34 $form->id
35 ],
36 FLUENTFORM_FRAMEWORK_UPGRADE,
37 'fluentform/global_notification_active_types',
38 'Use fluentform/global_notification_active_types instead of fluentform_global_notification_active_types.'
39 );
40 // Let's find the feeds that are available for this form
41 $feedKeys = apply_filters('fluentform/global_notification_active_types', $notifications, $form->id);
42
43 if (! $feedKeys) {
44 do_action_deprecated(
45 'fluentform_global_notify_completed',
46 [
47 $insertId,
48 $form
49 ],
50 FLUENTFORM_FRAMEWORK_UPGRADE,
51 'fluentform/global_notify_completed',
52 'Use fluentform/global_notify_completed instead of fluentform_global_notify_completed.'
53 );
54 do_action('fluentform/global_notify_completed', $insertId, $form);
55 return;
56 }
57
58 $feedMetaKeys = array_keys($feedKeys);
59
60 $feeds = FormMeta::where('form_id', $form->id)
61 ->whereIn('meta_key', $feedMetaKeys)
62 ->orderBy('id', 'ASC')
63 ->get();
64
65 if (count($feeds) === 0) {
66 do_action_deprecated(
67 'fluentform_global_notify_completed',
68 [
69 $insertId,
70 $form
71 ],
72 FLUENTFORM_FRAMEWORK_UPGRADE,
73 'fluentform/global_notify_completed',
74 'Use fluentform/global_notify_completed instead of fluentform_global_notify_completed.'
75 );
76 do_action('fluentform/global_notify_completed', $insertId, $form);
77 return;
78 }
79
80 // Now we have to filter the feeds which are enabled
81 $enabledFeeds = $this->getEnabledFeeds($feeds, $formData, $insertId);
82
83 if (! $enabledFeeds) {
84 do_action_deprecated(
85 'fluentform_global_notify_completed',
86 [
87 $insertId,
88 $form
89 ],
90 FLUENTFORM_FRAMEWORK_UPGRADE,
91 'fluentform/global_notify_completed',
92 'Use fluentform/global_notify_completed instead of fluentform_global_notify_completed.'
93 );
94 do_action('fluentform/global_notify_completed', $insertId, $form);
95 return;
96 }
97
98 $entry = false;
99 $asyncFeeds = [];
100
101 foreach ($enabledFeeds as $feed) {
102 // We will decide if this feed will run on async or sync
103 $integrationKey = ArrayHelper::get($feedKeys, $feed['meta_key']);
104
105 $action = 'fluentform/integration_notify_' . $feed['meta_key'];
106
107 if (! $entry) {
108 $entry = $this->getEntry($insertId, $form);
109 }
110 // skip emails which will be sent on payment form submit otherwise email is sent after payment success
111 if (! ! $form->has_payment && ('notifications' == $feed['meta_key'])) {
112 if (('payment_form_submit' == ArrayHelper::get($feed, 'settings.feed_trigger_event'))) {
113 continue;
114 }
115 }
116
117 // It's sync
118 $processedValues = $feed['settings'];
119 unset($processedValues['conditionals']);
120 $processedValues = ShortCodeParser::parse($processedValues, $insertId, $formData, $form, false, $feed['meta_key']);
121 $feed['processedValues'] = $processedValues;
122
123 $isNotifyAsync = apply_filters_deprecated(
124 'fluentform/notifying_async_' . $integrationKey,
125 [
126 true,
127 $form->id
128 ],
129 FLUENTFORM_FRAMEWORK_UPGRADE,
130 'fluentform/notifying_async_' . $integrationKey,
131 'Use fluentform/notifying_async_' . $integrationKey . ' instead of fluentform_notifying_async_' . $integrationKey
132 );
133
134 $isNotifyAsync = apply_filters('fluentform/notifying_async_' . $integrationKey, $isNotifyAsync, $form->id);
135
136 if ($isNotifyAsync) {
137 // It's async
138 $asyncFeeds[] = [
139 'action' => $action,
140 'form_id' => $form->id,
141 'origin_id' => $insertId,
142 'feed_id' => $feed['id'],
143 'type' => 'submission_action',
144 'status' => 'pending',
145 'data' => maybe_serialize($feed),
146 'created_at' => current_time('mysql'),
147 'updated_at' => current_time('mysql'),
148 ];
149 } else {
150 do_action_deprecated(
151 'fluentform_integration_notify_' . $feed['meta_key'],
152 [
153 $feed,
154 $formData,
155 $entry,
156 $form
157 ],
158 FLUENTFORM_FRAMEWORK_UPGRADE,
159 $action,
160 'Use ' . $action . ' instead of fluentform_integration_notify_' . $feed['meta_key']
161 );
162 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound -- Dynamic hook name constructed from deprecated hook
163 do_action($action, $feed, $formData, $entry, $form);
164 }
165 }
166
167 if (! $asyncFeeds) {
168 do_action_deprecated(
169 'fluentform_global_notify_completed',
170 [
171 $insertId,
172 $form
173 ],
174 FLUENTFORM_FRAMEWORK_UPGRADE,
175 'fluentform/global_notify_completed',
176 'Use fluentform/global_notify_completed instead of fluentform_global_notify_completed.'
177 );
178 do_action('fluentform/global_notify_completed', $insertId, $form);
179 return;
180 }
181
182 // Now we will push this async feeds
183 $handler = $this->app['fluentFormAsyncRequest'];
184 $handler->queueFeeds($asyncFeeds);
185
186 $handler->dispatchAjax(['origin_id' => $insertId]);
187 }
188
189 public function checkCondition($parsedValue, $formData, $insertId)
190 {
191 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
192 if (
193 ! $conditionSettings ||
194 ! ArrayHelper::isTrue($conditionSettings, 'status')
195 ) {
196 return true;
197 }
198
199 return ConditionAssesor::evaluate($parsedValue, $formData);
200 }
201
202 public function getEntry($id, $form)
203 {
204 $submission = Submission::find($id);
205 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
206 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
207 }
208
209 public function cleanUpPassword($entryId, $form)
210 {
211 // Let's get the password fields
212 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
213
214 if (! $inputs) {
215 return;
216 }
217 $passwordKeys = array_keys($inputs);
218
219 // Let's delete from entry details
220 EntryDetails::where('form_id', $form->id)
221 ->whereIn('field_name', $passwordKeys)
222 ->where('submission_id', $entryId)
223 ->delete();
224
225 // Let's alter from main submission data
226 $submission = Submission::where('id', $entryId)
227 ->first();
228
229 if (! $submission) {
230 return;
231 }
232
233 $responseInputs = \json_decode($submission->response, true);
234
235 $replaced = false;
236 foreach ($passwordKeys as $passwordKey) {
237 if (! empty($responseInputs[$passwordKey])) {
238 $responseInputs[$passwordKey] = str_repeat('*', 6) . ' ' . __('(truncated)', 'fluentform');
239 $replaced = true;
240 }
241 }
242
243 if ($replaced) {
244 Submission::where('id', $entryId)
245 ->update([
246 'response' => \json_encode($responseInputs),
247 ]);
248 }
249 }
250
251 /**
252 * @param $feeds
253 * @param $formData
254 * @param $insertId
255 *
256 * @return array
257 */
258 public function getEnabledFeeds($feeds, $formData, $insertId)
259 {
260 $enabledFeeds = [];
261 foreach ($feeds as $feed) {
262 $parsedValue = json_decode($feed->value, true);
263 if ($parsedValue && ArrayHelper::isTrue($parsedValue, 'enabled')) {
264 // Now check if conditions matched or not
265 $isConditionMatched = $this->checkCondition($parsedValue, $formData, $insertId);
266 if ($isConditionMatched) {
267 $item = [
268 'id' => $feed->id,
269 'meta_key' => $feed->meta_key,
270 'settings' => $parsedValue,
271 ];
272 if ('user_registration_feeds' == $feed->meta_key) {
273 array_unshift($enabledFeeds, $item);
274 } else {
275 $enabledFeeds[] = $item;
276 }
277 }
278 }
279 }
280 return $enabledFeeds;
281 }
282 }
283