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