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