PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.15
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.15
6.2.15 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 All 197 releases
← All changes | app/Services/Integrations/GlobalNotificationManager.php +161 -60 3.6.62 → 6.2.15 View file →
@@ -1,9 +1,12 @@
1 1 <?php
2 2
3 3 namespace FluentForm\App\Services\Integrations;
4 4
5 -use FluentForm\App\Databases\Migrations\ScheduledActions;
5 +use FluentForm\Database\Migrations\ScheduledActions;
6 +use FluentForm\App\Models\EntryDetails;
7 +use FluentForm\App\Models\FormMeta;
8 +use FluentForm\App\Models\Submission;
6 9 use FluentForm\App\Modules\Form\FormDataParser;
7 10 use FluentForm\App\Modules\Form\FormFieldsParser;
8 11 use FluentForm\App\Services\ConditionAssesor;
9 12 use FluentForm\App\Services\FormBuilder\ShortCodeParser;
@@ -9,8 +12,11 @@
9 12 use FluentForm\App\Services\FormBuilder\ShortCodeParser;
10 13 use FluentForm\Framework\Foundation\Application;
11 14 use FluentForm\Framework\Helpers\ArrayHelper;
12 15
16 +/**
17 + * @deprecated deprecated use FluentForm\App\Hooks\Handlers\GlobalNotificationHandler;
18 + */
13 19 class GlobalNotificationManager
14 20 {
15 21 private $app;
16 22
@@ -20,50 +26,73 @@
20 26 }
21 27
22 28 public function globalNotify($insertId, $formData, $form)
23 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 + );
24 40 // Let's find the feeds that are available for this form
25 - $feedKeys = apply_filters('fluentform_global_notification_active_types', [], $form->id);
41 + $feedKeys = apply_filters('fluentform/global_notification_active_types', $notifications, $form->id);
26 42
27 - if (!$feedKeys) {
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);
28 55 return;
29 56 }
30 57
31 58 $feedMetaKeys = array_keys($feedKeys);
32 59
33 - $feeds = wpFluent()->table('fluentform_form_meta')
34 - ->where('form_id', $form->id)
60 + $feeds = FormMeta::where('form_id', $form->id)
35 61 ->whereIn('meta_key', $feedMetaKeys)
36 62 ->orderBy('id', 'ASC')
37 63 ->get();
38 - if (!$feeds) {
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);
39 77 return;
40 78 }
41 79
42 80 // Now we have to filter the feeds which are enabled
43 - $enabledFeeds = [];
44 - foreach ($feeds as $feed) {
45 - $parsedValue = json_decode($feed->value, true);
46 - if ($parsedValue && ArrayHelper::isTrue($parsedValue, 'enabled')) {
47 - // Now check if conditions matched or not
48 - $isConditionMatched = $this->checkCondition($parsedValue, $formData, $insertId);
49 - if ($isConditionMatched) {
50 - $item = [
51 - 'id' => $feed->id,
52 - 'meta_key' => $feed->meta_key,
53 - 'settings' => $parsedValue
54 - ];
55 - if($feed->meta_key == 'user_registration_feeds') {
56 - array_unshift($enabledFeeds , $item);
57 - } else {
58 - $enabledFeeds[] = $item;
59 - }
60 - }
61 - }
62 - }
81 + $enabledFeeds = $this->getEnabledFeeds($feeds, $formData, $insertId);
63 82
64 - if(!$enabledFeeds) {
65 - do_action('fluentform_global_notify_completed', $insertId, $form);
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);
66 95 return;
67 96 }
68 97
69 98 $entry = false;
@@ -72,13 +101,19 @@
72 101 foreach ($enabledFeeds as $feed) {
73 102 // We will decide if this feed will run on async or sync
74 103 $integrationKey = ArrayHelper::get($feedKeys, $feed['meta_key']);
75 104
76 - $action = 'fluentform_integration_notify_' . $feed['meta_key'];
105 + $action = 'fluentform/integration_notify_' . $feed['meta_key'];
77 106
78 - if (!$entry) {
107 + if (! $entry) {
79 108 $entry = $this->getEntry($insertId, $form);
80 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 + }
81 116
82 117 // It's sync
83 118 $processedValues = $feed['settings'];
84 119 unset($processedValues['conditionals']);
@@ -84,34 +119,70 @@
84 119 unset($processedValues['conditionals']);
85 120 $processedValues = ShortCodeParser::parse($processedValues, $insertId, $formData, $form, false, $feed['meta_key']);
86 121 $feed['processedValues'] = $processedValues;
87 122
88 - if (apply_filters('fluentform_notifying_async_' . $integrationKey, true, $form->id)) {
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) {
89 137 // It's async
90 138 $asyncFeeds[] = [
91 - 'action' => $action,
92 - 'form_id' => $form->id,
93 - 'origin_id' => $insertId,
94 - 'feed_id' => $feed['id'],
95 - 'type' => 'submission_action',
96 - 'status' => 'pending',
97 - 'data' => maybe_serialize($feed),
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),
98 146 'created_at' => current_time('mysql'),
99 - 'updated_at' => current_time('mysql')
147 + 'updated_at' => current_time('mysql'),
100 148 ];
101 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
102 163 do_action($action, $feed, $formData, $entry, $form);
103 164 }
104 165 }
105 166
106 - if (!$asyncFeeds) {
107 - do_action('fluentform_global_notify_completed', $insertId, $form);
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);
108 179 return;
109 180 }
110 181
111 182 // Now we will push this async feeds
112 183 $handler = $this->app['fluentFormAsyncRequest'];
113 - $handler->queueFeeds( $asyncFeeds);
184 + $handler->queueFeeds($asyncFeeds);
114 185
115 186 $handler->dispatchAjax(['origin_id' => $insertId]);
116 187 }
117 188
@@ -118,11 +189,10 @@
118 189 public function checkCondition($parsedValue, $formData, $insertId)
119 190 {
120 191 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
121 192 if (
122 - !$conditionSettings ||
123 - !ArrayHelper::isTrue($conditionSettings, 'status') ||
124 - !count(ArrayHelper::get($conditionSettings, 'conditions'))
193 + ! $conditionSettings ||
194 + ! ArrayHelper::isTrue($conditionSettings, 'status')
125 195 ) {
126 196 return true;
127 197 }
128 198
@@ -128,11 +198,11 @@
128 198
129 199 return ConditionAssesor::evaluate($parsedValue, $formData);
130 200 }
131 201
132 - private function getEntry($id, $form)
202 + public function getEntry($id, $form)
133 203 {
134 - $submission = wpFluent()->table('fluentform_submissions')->find($id);
204 + $submission = Submission::find($id);
135 205 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
136 206 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
137 207 }
138 208
@@ -139,24 +209,25 @@
139 209 public function cleanUpPassword($entryId, $form)
140 210 {
141 211 // Let's get the password fields
142 212 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
143 - if(!$inputs) {
213 +
214 + if (! $inputs) {
144 215 return;
145 216 }
146 217 $passwordKeys = array_keys($inputs);
218 +
147 219 // Let's delete from entry details
148 - wpFluent()->table('fluentform_entry_details')
149 - ->where('form_id', $form->id)
220 + EntryDetails::where('form_id', $form->id)
150 221 ->whereIn('field_name', $passwordKeys)
151 222 ->where('submission_id', $entryId)
152 223 ->delete();
153 224
154 225 // Let's alter from main submission data
155 - $submission = wpFluent()->table('fluentform_submissions')
156 - ->where('id', $entryId)
226 + $submission = Submission::where('id', $entryId)
157 227 ->first();
158 - if(!$submission) {
228 +
229 + if (! $submission) {
159 230 return;
160 231 }
161 232
162 233 $responseInputs = \json_decode($submission->response, true);
@@ -162,20 +233,50 @@
162 233 $responseInputs = \json_decode($submission->response, true);
163 234
164 235 $replaced = false;
165 236 foreach ($passwordKeys as $passwordKey) {
166 - if(!empty($responseInputs[$passwordKey])) {
167 - $originalPassword = $responseInputs[$passwordKey];
168 - $responseInputs[$passwordKey] = str_repeat("*", strlen($originalPassword)).' '. __('(truncated)', 'fluentform');
237 + if (! empty($responseInputs[$passwordKey])) {
238 + $responseInputs[$passwordKey] = str_repeat('*', 6) . ' ' . __('(truncated)', 'fluentform');
169 239 $replaced = true;
170 240 }
171 241 }
172 242
173 - if($replaced) {
174 - wpFluent()->table('fluentform_submissions')
175 - ->where('id', $entryId)
243 + if ($replaced) {
244 + Submission::where('id', $entryId)
176 245 ->update([
177 - 'response' => \json_encode($responseInputs)
246 + 'response' => \json_encode($responseInputs),
178 247 ]);
179 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;
180 281 }
181 282 }