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

182 lines 6.2 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, $form, false, $feed['meta_key']);
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 // Now we will push this async feeds
112 $handler = $this->app['fluentFormAsyncRequest'];
113 $handler->queueFeeds( $asyncFeeds);
114
115 $handler->dispatchAjax(['origin_id' => $insertId]);
116 }
117
118 public function checkCondition($parsedValue, $formData, $insertId)
119 {
120 $conditionSettings = ArrayHelper::get($parsedValue, 'conditionals');
121 if (
122 !$conditionSettings ||
123 !ArrayHelper::isTrue($conditionSettings, 'status') ||
124 !count(ArrayHelper::get($conditionSettings, 'conditions'))
125 ) {
126 return true;
127 }
128
129 return ConditionAssesor::evaluate($parsedValue, $formData);
130 }
131
132 private function getEntry($id, $form)
133 {
134 $submission = wpFluent()->table('fluentform_submissions')->find($id);
135 $formInputs = FormFieldsParser::getEntryInputs($form, ['admin_label', 'raw']);
136 return FormDataParser::parseFormEntry($submission, $form, $formInputs);
137 }
138
139 public function cleanUpPassword($entryId, $form)
140 {
141 // Let's get the password fields
142 $inputs = FormFieldsParser::getInputsByElementTypes($form, ['input_password']);
143 if(!$inputs) {
144 return;
145 }
146 $passwordKeys = array_keys($inputs);
147 // Let's delete from entry details
148 wpFluent()->table('fluentform_entry_details')
149 ->where('form_id', $form->id)
150 ->whereIn('field_name', $passwordKeys)
151 ->where('submission_id', $entryId)
152 ->delete();
153
154 // Let's alter from main submission data
155 $submission = wpFluent()->table('fluentform_submissions')
156 ->where('id', $entryId)
157 ->first();
158 if(!$submission) {
159 return;
160 }
161
162 $responseInputs = \json_decode($submission->response, true);
163
164 $replaced = false;
165 foreach ($passwordKeys as $passwordKey) {
166 if(!empty($responseInputs[$passwordKey])) {
167 $originalPassword = $responseInputs[$passwordKey];
168 $responseInputs[$passwordKey] = str_repeat("*", strlen($originalPassword)).' '. __('(truncated)', 'fluentform');
169 $replaced = true;
170 }
171 }
172
173 if($replaced) {
174 wpFluent()->table('fluentform_submissions')
175 ->where('id', $entryId)
176 ->update([
177 'response' => \json_encode($responseInputs)
178 ]);
179 }
180 }
181 }
182