PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.50
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.50
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 3.6.50, at app/Services/Integrations/GlobalNotificationManager.php

195 lines 6.6 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\App\Databases\Migrations\ScheduledActions;
6 use FluentForm\App\Modules\Form\FormDataParser;
7 use FluentForm\App\Modules\Form\FormFieldsParser;
8 use FluentForm\App\Services\ConditionAssesor;
9 use FluentForm\App\Services\FormBuilder\ShortCodeParser;
10 use FluentForm\Framework\Foundation\Application;
11 use FluentForm\Framework\Helpers\ArrayHelper;
12
13 class GlobalNotificationManager
14 {
15 private $app;
16
17 public function __construct(Application $app)
18 {
19 $this->app = $app;
20 }
21
22 public function globalNotify($insertId, $formData, $form)
23 {
24 // Let's find the feeds that are available for this form
25 $feedKeys = apply_filters('fluentform_global_notification_active_types', [], $form->id);
26
27 if (!$feedKeys) {
28 return;
29 }
30
31 $feedMetaKeys = array_keys($feedKeys);
32
33 $feeds = wpFluent()->table('fluentform_form_meta')
34 ->where('form_id', $form->id)
35 ->whereIn('meta_key', $feedMetaKeys)
36 ->orderBy('id', 'ASC')
37 ->get();
38 if (!$feeds) {
39 return;
40 }
41
42 // 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 }
63
64 if(!$enabledFeeds) {
65 do_action('fluentform_global_notify_completed', $insertId, $form);
66 return;
67 }
68
69 $entry = false;
70 $asyncFeeds = [];
71
72 foreach ($enabledFeeds as $feed) {
73 // We will decide if this feed will run on async or sync
74 $integrationKey = ArrayHelper::get($feedKeys, $feed['meta_key']);
75
76 $action = 'fluentform_integration_notify_' . $feed['meta_key'];
77
78 if (!$entry) {
79 $entry = $this->getEntry($insertId, $form);
80 }
81
82 // It's sync
83 $processedValues = $feed['settings'];
84 unset($processedValues['conditionals']);
85 $processedValues = ShortCodeParser::parse($processedValues, $insertId, $formData);
86 $feed['processedValues'] = $processedValues;
87
88 if (apply_filters('fluentform_notifying_async_' . $integrationKey, true, $form->id)) {
89 // It's async
90 $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),
98 'created_at' => current_time('mysql'),
99 'updated_at' => current_time('mysql')
100 ];
101 } else {
102 do_action($action, $feed, $formData, $entry, $form);
103 }
104 }
105
106 if (!$asyncFeeds) {
107 do_action('fluentform_global_notify_completed', $insertId, $form);
108 return;
109 }
110
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 // Now we will push this async feeds
125 $handler = $this->app['fluentFormAsyncRequest'];
126 $handler->queueFeeds( $asyncFeeds);
127
128 $handler->dispatchAjax(['origin_id' => $insertId]);
129 }
130
131 private function checkCondition($parsedValue, $formData, $insertId)
132 {
133 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
134 if (
135 !$conditionSettings ||
136 !ArrayHelper::isTrue($conditionSettings, 'status') ||
137 !count(ArrayHelper::get($conditionSettings, 'conditions'))
138 ) {
139 return true;
140 }
141
142 return ConditionAssesor::evaluate($parsedValue, $formData);
143 }
144
145 private function getEntry($id, $form)
146 {
147 $submission = wpFluent()->table('fluentform_submissions')->find($id);
148 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
149 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
150 }
151
152 public function cleanUpPassword($entryId, $form)
153 {
154 // Let's get the password fields
155 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
156 if(!$inputs) {
157 return;
158 }
159 $passwordKeys = array_keys($inputs);
160 // Let's delete from entry details
161 wpFluent()->table('fluentform_entry_details')
162 ->where('form_id', $form->id)
163 ->whereIn('field_name', $passwordKeys)
164 ->where('submission_id', $entryId)
165 ->delete();
166
167 // Let's alter from main submission data
168 $submission = wpFluent()->table('fluentform_submissions')
169 ->where('id', $entryId)
170 ->first();
171 if(!$submission) {
172 return;
173 }
174
175 $responseInputs = \json_decode($submission->response, true);
176
177 $replaced = false;
178 foreach ($passwordKeys as $passwordKey) {
179 if(!empty($responseInputs[$passwordKey])) {
180 $originalPassword = $responseInputs[$passwordKey];
181 $responseInputs[$passwordKey] = str_repeat("*", strlen($originalPassword)).' '. __('(truncated)', 'fluentform');
182 $replaced = true;
183 }
184 }
185
186 if($replaced) {
187 wpFluent()->table('fluentform_submissions')
188 ->where('id', $entryId)
189 ->update([
190 'response' => \json_encode($responseInputs)
191 ]);
192 }
193 }
194 }
195