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 +163 -71 3.6.40 → 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,46 +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);
81 + $enabledFeeds = $this->getEnabledFeeds($feeds, $formData, $insertId);
49 82
50 - if ($isConditionMatched) {
51 - $enabledFeeds[] = [
52 - 'id' => $feed->id,
53 - 'meta_key' => $feed->meta_key,
54 - 'settings' => $parsedValue
55 - ];
56 - }
57 - }
58 - }
59 -
60 - if(!$enabledFeeds) {
61 - 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);
62 95 return;
63 96 }
64 97
65 98 $entry = false;
@@ -68,70 +101,98 @@
68 101 foreach ($enabledFeeds as $feed) {
69 102 // We will decide if this feed will run on async or sync
70 103 $integrationKey = ArrayHelper::get($feedKeys, $feed['meta_key']);
71 104
72 - $action = 'fluentform_integration_notify_' . $feed['meta_key'];
105 + $action = 'fluentform/integration_notify_' . $feed['meta_key'];
73 106
74 - if (!$entry) {
107 + if (! $entry) {
75 108 $entry = $this->getEntry($insertId, $form);
76 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 + }
77 116
78 117 // It's sync
79 118 $processedValues = $feed['settings'];
80 119 unset($processedValues['conditionals']);
81 - $processedValues = ShortCodeParser::parse($processedValues, $insertId, $formData);
120 + $processedValues = ShortCodeParser::parse($processedValues, $insertId, $formData, $form, false, $feed['meta_key']);
82 121 $feed['processedValues'] = $processedValues;
83 122
84 - 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) {
85 137 // It's async
86 138 $asyncFeeds[] = [
87 - 'action' => $action,
88 - 'form_id' => $form->id,
89 - 'origin_id' => $insertId,
90 - 'feed_id' => $feed['id'],
91 - 'type' => 'submission_action',
92 - 'status' => 'pending',
93 - '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),
94 146 'created_at' => current_time('mysql'),
95 - 'updated_at' => current_time('mysql')
147 + 'updated_at' => current_time('mysql'),
96 148 ];
97 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
98 163 do_action($action, $feed, $formData, $entry, $form);
99 164 }
100 165 }
101 166
102 - if (!$asyncFeeds) {
103 - 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);
104 179 return;
105 180 }
106 181
107 - /*
108 - * Maybe Migrate on run time
109 - * We will remove this code at the end of 2020
110 - * @todo: Remove when appropriate
111 - */
112 - if(get_option('fluentform_scheduled_actions_migrated') != 'yes') {
113 - ScheduledActions::migrate();
114 - $hookName = 'fluentform_do_scheduled_tasks';
115 - if (!wp_next_scheduled($hookName)) {
116 - wp_schedule_event(time(), 'ff_every_five_minutes', $hookName);
117 - }
118 - }
119 -
120 182 // Now we will push this async feeds
121 183 $handler = $this->app['fluentFormAsyncRequest'];
122 - $handler->queueFeeds( $asyncFeeds);
184 + $handler->queueFeeds($asyncFeeds);
123 185
124 186 $handler->dispatchAjax(['origin_id' => $insertId]);
125 187 }
126 188
127 - private function checkCondition($parsedValue, $formData, $insertId)
189 + public function checkCondition($parsedValue, $formData, $insertId)
128 190 {
129 191 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
130 192 if (
131 - !$conditionSettings ||
132 - !ArrayHelper::isTrue($conditionSettings, 'status') ||
133 - !count(ArrayHelper::get($conditionSettings, 'conditions'))
193 + ! $conditionSettings ||
194 + ! ArrayHelper::isTrue($conditionSettings, 'status')
134 195 ) {
135 196 return true;
136 197 }
137 198
@@ -137,11 +198,11 @@
137 198
138 199 return ConditionAssesor::evaluate($parsedValue, $formData);
139 200 }
140 201
141 - private function getEntry($id, $form)
202 + public function getEntry($id, $form)
142 203 {
143 - $submission = wpFluent()->table('fluentform_submissions')->find($id);
204 + $submission = Submission::find($id);
144 205 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
145 206 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
146 207 }
147 208
@@ -148,24 +209,25 @@
148 209 public function cleanUpPassword($entryId, $form)
149 210 {
150 211 // Let's get the password fields
151 212 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
152 - if(!$inputs) {
213 +
214 + if (! $inputs) {
153 215 return;
154 216 }
155 217 $passwordKeys = array_keys($inputs);
218 +
156 219 // Let's delete from entry details
157 - wpFluent()->table('fluentform_entry_details')
158 - ->where('form_id', $form->id)
220 + EntryDetails::where('form_id', $form->id)
159 221 ->whereIn('field_name', $passwordKeys)
160 222 ->where('submission_id', $entryId)
161 223 ->delete();
162 224
163 225 // Let's alter from main submission data
164 - $submission = wpFluent()->table('fluentform_submissions')
165 - ->where('id', $entryId)
226 + $submission = Submission::where('id', $entryId)
166 227 ->first();
167 - if(!$submission) {
228 +
229 + if (! $submission) {
168 230 return;
169 231 }
170 232
171 233 $responseInputs = \json_decode($submission->response, true);
@@ -171,20 +233,50 @@
171 233 $responseInputs = \json_decode($submission->response, true);
172 234
173 235 $replaced = false;
174 236 foreach ($passwordKeys as $passwordKey) {
175 - if(!empty($responseInputs[$passwordKey])) {
176 - $originalPassword = $responseInputs[$passwordKey];
177 - $responseInputs[$passwordKey] = str_repeat("*", strlen($originalPassword)).' '. __('(truncated)', 'fluentform');
237 + if (! empty($responseInputs[$passwordKey])) {
238 + $responseInputs[$passwordKey] = str_repeat('*', 6) . ' ' . __('(truncated)', 'fluentform');
178 239 $replaced = true;
179 240 }
180 241 }
181 242
182 - if($replaced) {
183 - wpFluent()->table('fluentform_submissions')
184 - ->where('id', $entryId)
243 + if ($replaced) {
244 + Submission::where('id', $entryId)
185 245 ->update([
186 - 'response' => \json_encode($responseInputs)
246 + 'response' => \json_encode($responseInputs),
187 247 ]);
188 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;
189 281 }
190 282 }