Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/fluentform/app/Hooks/Ajax.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 +
3 + /**
4 + * Add all ajax hooks
5 + */
6 +
7 + use FluentForm\App\Modules\Acl\Acl;
8 +
9 + /**
10 + * App instance
11 + *
12 + * @var $app \FluentForm\Framework\Foundation\Application
13 + */
14 +
15 + $app->addAction('wp_ajax_nopriv_fluentform_submit', function () use ($app) {
16 + (new \FluentForm\App\Modules\SubmissionHandler\SubmissionHandler($app))->submit();
17 + });
18 +
19 + $app->addAction('wp_ajax_fluentform_submit', function () use ($app) {
20 + // (new \FluentForm\App\Modules\Form\FormHandler($app))->onSubmit();
21 + (new \FluentForm\App\Modules\SubmissionHandler\SubmissionHandler($app))->submit();
22 + });
23 +
24 + /*
25 + * We are using this ajax call for updating form fields
26 + * REST API seems not working for some servers with Mod Security Enabled
27 + */
28 + $app->addAction('wp_ajax_fluentform-form-update', function () use ($app) {
29 + Acl::verify('fluentform_forms_manager', $app->request->get('form_id'));
30 + try {
31 + $data = $app->request->all();
32 + $isValidJson = (!empty($data['formFields'])) && json_decode($data['formFields'], true);
33 +
34 + if(!$isValidJson) {
35 + wp_send_json([
36 + 'message' => 'Looks like the provided JSON is invalid. Please try again or contact support',
37 + 'reason' => 'formFields JSON validation failed'
38 + ], 422);
39 + }
40 +
41 + $formService = new \FluentForm\App\Services\Form\FormService();
42 + $form = $formService->update($data);
43 + wp_send_json([
44 + 'message' => __('The form is successfully updated.', 'fluentform')
45 + ], 200);
46 + } catch (\Exception $exception) {
47 + wp_send_json([
48 + 'message' => $exception->getMessage(),
49 + ], 422);
50 + }
51 + });
52 +
53 + /*
54 + * This ajax endpoint is used to update form general settings
55 + * Mod-Security also block this request
56 + */
57 + $app->addAction('wp_ajax_fluentform-save-settings-general-formSettings', function () use ($app) {
58 + Acl::verify('fluentform_forms_manager');
59 + try {
60 + $settingsService = new \FluentForm\App\Services\Settings\SettingsService();
61 + $settingsService->saveGeneral($app->request->all());
62 + wp_send_json([
63 + 'message' => __('Settings has been saved.', 'fluentform'),
64 + ]);
65 + } catch (\FluentForm\Framework\Validator\ValidationException $exception) {
66 + wp_send_json($exception->errors(), 422);
67 + }
68 + });
69 +
70 + /*
71 + * This ajax endpoint is used to update form email notifications settings
72 + * Mod-Security also block this request
73 + */
74 + $app->addAction('wp_ajax_fluentform-save-form-email-notification', function () use ($app) {
75 + Acl::verify('fluentform_forms_manager');
76 + try {
77 + $settingsService = new \FluentForm\App\Services\Settings\SettingsService();
78 + [$settingsId, $settings] = $settingsService->store($app->request->all());
79 +
80 + wp_send_json([
81 + 'message' => __('Settings has been saved.', 'fluentform'),
82 + 'id' => $settingsId,
83 + 'settings' => $settings,
84 + ]);
85 + } catch (\FluentForm\Framework\Validator\ValidationException $exception) {
86 + wp_send_json($exception->errors(), 422);
87 + }
88 + });
89 +
90 +
91 + $app->addAction('wp_ajax_fluentform-forms', function () use ($app) {
92 + dd('wp_ajax_fluentform-forms');
93 + Acl::verify('fluentform_dashboard_access');
94 + (new \FluentForm\App\Modules\Form\Form($app))->index();
95 + });
96 +
97 + $app->addAction('wp_ajax_fluentform-form-store', function () use ($app) {
98 + dd('wp_ajax_fluentform-form-store');
99 + Acl::verify('fluentform_forms_manager');
100 + (new \FluentForm\App\Modules\Form\Form($app))->store();
101 + });
102 +
103 + $app->addAction('wp_ajax_fluentform-form-find', function () use ($app) {
104 + //No usage found
105 + Acl::verify('fluentform_dashboard_access');
106 + (new \FluentForm\App\Modules\Form\Form($app))->find();
107 + });
108 +
109 + $app->addAction('wp_ajax_fluentform-form-delete', function () use ($app) {
110 + dd('wp_ajax_fluentform-form-delete');
111 + Acl::verify('fluentform_forms_manager');
112 + (new \FluentForm\App\Modules\Form\Form($app))->delete();
113 + });
114 +
115 + $app->addAction('wp_ajax_fluentform-form-duplicate', function () use ($app) {
116 + dd('wp_ajax_fluentform-form-duplicate');
117 + Acl::verify('fluentform_forms_manager');
118 + (new \FluentForm\App\Modules\Form\Form($app))->duplicate();
119 + });
120 + $app->addAdminAjaxAction('fluentform-form-find-shortcode-locations', function () use ($app) {
121 + Acl::verify('fluentform_forms_manager');
122 + (new \FluentForm\App\Modules\Form\Form($app))->findFormLocations();
123 + });
124 +
125 + $app->addAction('wp_ajax_fluentform-convert-to-conversational', function () use ($app) {
126 + dd('wp_ajax_fluentform-convert-to-conversational');
127 + Acl::verify('fluentform_forms_manager');
128 + (new \FluentForm\App\Modules\Form\Form($app))->convertToConversational();
129 + });
130 +
131 + $app->addAction('wp_ajax_fluentform_get_all_entries', function () {
132 + dd('wp_ajax_fluentform_get_all_entries');
133 + Acl::verify('fluentform_entries_viewer');
134 + (new \FluentForm\App\Modules\Entries\Entries())->getAllFormEntries();
135 + });
136 +
137 + $app->addAction('wp_ajax_fluentform_get_all_entries_report', function () {
138 + dd('wp_ajax_fluentform_get_all_entries_report');
139 + Acl::verify('fluentform_entries_viewer');
140 + (new \FluentForm\App\Modules\Entries\Entries())->getEntriesReport();
141 + });
142 +
143 + $app->addAction('wp_ajax_fluentform-form-inputs', function () use ($app) {
144 + dd('wp_ajax_fluentform-form-inputs');
145 + Acl::verify('fluentform_forms_manager');
146 + (new \FluentForm\App\Modules\Form\Inputs($app))->index();
147 + });
148 +
149 + $app->addAction('wp_ajax_fluentform-load-editor-shortcodes', function () use ($app) {
150 + dd('wp_ajax_fluentform-load-editor-shortcodes');
151 + Acl::verify('fluentform_forms_manager');
152 + (new \FluentForm\App\Modules\Component\Component($app))->getEditorShortcodes();
153 + });
154 +
155 + $app->addAction('wp_ajax_fluentform-load-all-editor-shortcodes', function () use ($app) {
156 + dd('wp_ajax_fluentform-load-all-editor-shortcodes');
157 + Acl::verify('fluentform_forms_manager');
158 + (new \FluentForm\App\Modules\Component\Component($app))->getAllEditorShortcodes();
159 + });
160 +
161 + $app->addAction('wp_ajax_fluentform-settings-formSettings', function () use ($app) {
162 + dd('wp_ajax_fluentform-settings-formSettings');
163 + Acl::verify('fluentform_forms_manager');
164 + (new \FluentForm\App\Modules\Form\Settings\FormSettings($app))->index();
165 + });
166 +
167 + $app->addAction('wp_ajax_fluentform-settings-general-formSettings', function () use ($app) {
168 + dd('wp_ajax_fluentform-settings-general-formSettings');
169 + Acl::verify('fluentform_forms_manager');
170 + (new \FluentForm\App\Modules\Form\Settings\FormSettings($app))->getGeneralSettingsAjax();
171 + });
172 +
173 + $app->addAction('wp_ajax_fluentform-settings-formSettings-store', function () use ($app) {
174 + dd('wp_ajax_fluentform-settings-formSettings-store');
175 + Acl::verify('fluentform_forms_manager');
176 + (new \FluentForm\App\Modules\Form\Settings\FormSettings($app))->store();
177 + });
178 +
179 + $app->addAction('wp_ajax_fluentform-settings-formSettings-remove', function () use ($app) {
180 + dd('wp_ajax_fluentform-settings-formSettings-remove');
181 + Acl::verify('fluentform_forms_manager');
182 + (new \FluentForm\App\Modules\Form\Settings\FormSettings($app))->remove();
183 + });
184 +
185 + $app->addAction('wp_ajax_fluentform-get-form-custom_css_js', function () {
186 + dd('wp_ajax_fluentform-get-form-custom_css_js');
187 + Acl::verify('fluentform_forms_manager');
188 + (new \FluentForm\App\Modules\Form\Settings\FormCssJs())->getSettingsAjax();
189 + });
190 +
191 + $app->addAction('wp_ajax_fluentform-save-form-custom_css_js', function () {
192 + dd('wp_ajax_fluentform-save-form-custom_css_js');
193 + Acl::verify('fluentform_forms_manager');
194 + (new \FluentForm\App\Modules\Form\Settings\FormCssJs())->saveSettingsAjax();
195 + });
196 +
197 + $app->addAction('wp_ajax_fluentform-save-form-entry_column_view_settings', function () {
198 + dd('wp_ajax_fluentform-save-form-entry_column_view_settings');
199 + Acl::verify('fluentform_forms_manager');
200 + (new \FluentForm\App\Modules\Form\Settings\EntryColumnViewSettings())->saveVisibleColumnsAjax();
201 + });
202 +
203 + $app->addAction('wp_ajax_fluentform-save-form-entry_column_order_settings', function () {
204 + dd('wp_ajax_fluentform-save-form-entry_column_order_settings');
205 + Acl::verify('fluentform_forms_manager');
206 + (new \FluentForm\App\Modules\Form\Settings\EntryColumnViewSettings())->saveEntryColumnsOrderAjax();
207 + });
208 +
209 + $app->addAction('wp_ajax_fluentform-reset-form-entry_column_order_settings', function () {
210 + dd('wp_ajax_fluentform-reset-form-entry_column_order_settings');
211 + Acl::verify('fluentform_forms_manager');
212 + (new \FluentForm\App\Modules\Form\Settings\EntryColumnViewSettings())->resetEntryDisplaySettings();
213 + });
214 +
215 + $app->addAction('wp_ajax_fluentform-load-editor-components', function () use ($app) {
216 + dd('wp_ajax_fluentform-load-editor-components');
217 + Acl::verify('fluentform_forms_manager');
218 + (new \FluentForm\App\Modules\Component\Component($app))->index();
219 + });
220 +
221 + $app->addAction('wp_ajax_fluentform-form-entry-counts', function () {
222 + dd('wp_ajax_fluentform-form-entry-counts');
223 + Acl::verify('fluentform_entries_viewer');
224 + (new \FluentForm\App\Modules\Entries\Entries())->getEntriesGroup();
225 + });
226 +
227 + $app->addAction('wp_ajax_fluentform-form-entries', function () {
228 + dd('wp_ajax_fluentform-form-entries');
229 + Acl::verify('fluentform_entries_viewer');
230 + (new \FluentForm\App\Modules\Entries\Entries())->getEntries();
231 + });
232 +
233 + $app->addAction('wp_ajax_fluentform-form-report', function () use ($app) {
234 + dd('wp_ajax_fluentform-form-report');
235 + $formId = intval($app->request->get('form_id'));
236 + Acl::verify('fluentform_entries_viewer', $formId);
237 + (new \FluentForm\App\Modules\Entries\Report($app))->getReport($formId);
238 + });
239 +
240 + $app->addAction('wp_ajax_fluentform-form-entries-export', function () use ($app) {
241 + Acl::verify('fluentform_entries_viewer');
242 + (new \FluentForm\App\Modules\Transfer\Transfer())->exportEntries();
243 + });
244 +
245 + $app->addAction('wp_ajax_fluentform-get-entry', function () {
246 + //No usage found
247 + Acl::verify('fluentform_entries_viewer');
248 + (new \FluentForm\App\Modules\Entries\Entries())->getEntry();
249 + });
250 +
251 + $app->addAction('wp_ajax_fluentform-update-entry-user', function () {
252 + Acl::verify('fluentform_entries_viewer');
253 + (new \FluentForm\App\Modules\Entries\Entries())->changeEntryUser();
254 + });
255 +
256 + $app->addAction('wp_ajax_fluentform-get-users', function () {
257 + Acl::verify('fluentform_entries_viewer');
258 + (new \FluentForm\App\Modules\Entries\Entries())->getUsers();
259 + });
260 +
261 + $app->addAction('wp_ajax_fluentform-get-entry-notes', function () {
262 + dd('wp_ajax_fluentform-get-entry-notes');
263 + Acl::verify('fluentform_entries_viewer');
264 + (new \FluentForm\App\Modules\Entries\Entries())->getNotes();
265 + });
266 +
267 + $app->addAction('wp_ajax_fluentform-add-entry-note', function () {
268 + dd('wp_ajax_fluentform-add-entry-note');
269 + Acl::verify('fluentform_entries_viewer');
270 + (new \FluentForm\App\Modules\Entries\Entries())->addNote();
271 + });
272 +
273 + $app->addAction('wp_ajax_fluentform-get-entry-logs', function () use ($app) {
274 + dd('wp_ajax_fluentform-get-entry-logs');
275 + Acl::verify('fluentform_entries_viewer');
276 + $entry_id = intval($app->request->get('entry_id'));
277 + $logType = sanitize_text_field($app->request->get('log_type'));
278 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->getLogsByEntry($entry_id, $logType);
279 + });
280 +
281 + $app->addAction('wp_ajax_fluentform_get_activity_log_filters', function () use ($app) {
282 + dd('wp_ajax_fluentform_get_activity_log_filters');
283 + Acl::verify('fluentform_entries_viewer');
284 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->getLogFilters();
285 + });
286 +
287 + $app->addAction('wp_ajax_fluentform_get_activity_api_log_filters', function () use ($app) {
288 + dd('wp_ajax_fluentform_get_activity_api_log_filters');
289 + Acl::verify('fluentform_entries_viewer');
290 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->getApiLogFilters();
291 + });
292 +
293 + $app->addAction('wp_ajax_fluentform_get_all_logs', function () use ($app) {
294 + dd('wp_ajax_fluentform_get_all_logs');
295 + Acl::verify('fluentform_entries_viewer');
296 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->getAllLogs();
297 + });
298 +
299 + $app->addAction('wp_ajax_fluentform_get_api_logs', function () use ($app) {
300 + dd('wp_ajax_fluentform_get_api_logs');
301 + Acl::verify('fluentform_entries_viewer');
302 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->getApiLogs();
303 + });
304 +
305 + $app->addAction('wp_ajax_fluentform_retry_api_action', function () use ($app) {
306 + // No usage found
307 + Acl::verify('fluentform_entries_viewer');
308 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->retryApiAction();
309 + });
310 +
311 + $app->addAction('wp_ajax_fluentform_delete_logs_by_ids', function () use ($app) {
312 + dd('wp_ajax_fluentform_delete_logs_by_ids');
313 + Acl::verify('fluentform_manage_entries');
314 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->deleteLogsByIds();
315 + });
316 +
317 + $app->addAction('wp_ajax_fluentform_delete_api_logs_by_ids', function () use ($app) {
318 + dd('wp_ajax_fluentform_delete_api_logs_by_ids');
319 + Acl::verify('fluentform_manage_entries');
320 + (new \FluentForm\App\Modules\Logger\DataLogger($app))->deleteApiLogsByIds();
321 + });
322 +
323 + $app->addAction('wp_ajax_fluentform-change-entry-status', function () {
324 + Acl::verify('fluentform_manage_entries');
325 + (new \FluentForm\App\Modules\Entries\Entries())->changeEntryStatus();
326 + });
327 +
328 +
329 + $app->addAction('wp_ajax_fluentform_notice_action_track_yes', function () {
330 + Acl::hasAnyFormPermission();
331 + (new FluentForm\App\Modules\Track\TrackModule())->sendInitialInfo();
332 + });
333 +
334 + $app->addAction('wp_ajax_fluentform_install_fluentsmtp', function () {
335 + Acl::verify('fluentform_settings_manager');
336 + (new FluentForm\App\Modules\Track\SetupModule())->installPlugin('fluent-smtp');
337 + });
338 +
339 + // Export forms
340 + $app->addAction('wp_ajax_fluentform-export-forms', function () use ($app) {
341 + Acl::verify('fluentform_settings_manager', $app->request->get('forms'));
342 + (new \FluentForm\App\Modules\Transfer\Transfer())->exportForms();
343 + });
344 +
345 + // Import forms
346 + $app->addAction('wp_ajax_fluentform-import-forms', function () use ($app) {
347 + Acl::verify('fluentform_settings_manager');
348 + (new \FluentForm\App\Modules\Transfer\Transfer())->importForms();
349 + });
350 +
351 + /*
352 + * Background Process Receiver
353 + */
354 +
355 + $app->addAction('wp_ajax_fluentform_background_process', function () {
356 + $this->app['fluentFormAsyncRequest']->handleBackgroundCall();
357 + });
358 +
359 + $app->addAction('wp_ajax_nopriv_fluentform_background_process', function () {
360 + $this->app['fluentFormAsyncRequest']->handleBackgroundCall();
361 + });
362 +
363 + /*
364 + * For REST API Nonce Renewal
365 + */
366 + $app->addAction('wp_ajax_fluentform_renew_rest_nonce', function () {
367 + if (!Acl::getCurrentUserPermissions()) {
368 + wp_send_json([
369 + 'error' => 'You do not have permission to do this',
370 + ], 403);
371 + }
372 +
373 + wp_send_json([
374 + 'nonce' => wp_create_nonce('wp_rest'),
375 + ], 200);
376 + });
377 + /*
378 + * For selectGroup Component Grouped Options
379 + * Use this filter to pass data to component
380 + */
381 +
382 + add_action('wp_ajax_fluentform_select_group_ajax_data', function () {
383 + $requestData = wpFluentForm('request')->all();
384 + $ajaxList = apply_filters('fluentform/select_group_component_ajax_options', [], $requestData);
385 + wp_send_json_success($ajaxList);
386 + });
387 +