PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.21
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.21
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 / Modules / Registerer / Menu.php

Menu.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 4.3.21, at app/Modules/Registerer/Menu.php

977 lines 41.7 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\Modules\Registerer;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\App\Modules\Acl\Acl;
7 use FluentForm\App\Modules\Activator;
8 use FluentForm\App\Modules\AddOnModule;
9 use FluentForm\App\Modules\DocumentationModule;
10 use FluentForm\Framework\Foundation\Application;
11 use FluentForm\Framework\Helpers\ArrayHelper;
12 use FluentForm\View;
13
14 class Menu
15 {
16 /**
17 * App instance
18 *
19 * @var \FluentForm\Framework\Foundation\Application
20 */
21 protected $app;
22
23 /**
24 * Menu constructor.
25 *
26 * @param \FluentForm\Framework\Foundation\Application $application
27 */
28 public function __construct(Application $application)
29 {
30 $this->app = $application;
31
32 $this->app->addFilter('fluentform_form_settings_menu', [
33 $this, 'filterFormSettingsMenu',
34 ], 10, 2);
35 }
36
37 public function reisterScripts()
38 {
39 if (!$this->isFluentPages()) {
40 return;
41 }
42
43 $app = $this->app;
44
45 wp_register_script(
46 'fluent_forms_global',
47 $app->publicUrl('js/fluent_forms_global.js'),
48 ['jquery'],
49 FLUENTFORM_VERSION,
50 true
51 );
52
53 $settingsGlobalStyle = $app->publicUrl('css/settings_global.css');
54 $allFormsStyle = $app->publicUrl('css/fluent-all-forms.css');
55 $fluentFormAdminEditorStyles = $app->publicUrl('css/fluent-forms-admin-sass.css');
56 $fluentFormAdminCSS = $app->publicUrl('css/fluent-forms-admin.css');
57 $addOnsCss = $app->publicUrl('css/add-ons.css');
58 $adminDocCss = $app->publicUrl('css/admin_docs.css');
59 if (is_rtl()) {
60 $settingsGlobalStyle = $app->publicUrl('css/settings_global_rtl.css');
61 $allFormsStyle = $app->publicUrl('css/fluent-all-forms-rtl.css');
62 $fluentFormAdminEditorStyles = $app->publicUrl('css/fluent-forms-admin-sass-rtl.css');
63 $fluentFormAdminCSS = $app->publicUrl('css/fluent-forms-admin-rtl.css');
64 $addOnsCss = $app->publicUrl('css/add-ons-rtl.css');
65 $adminDocCss = $app->publicUrl('css/admin_docs_rtl.css');
66 }
67
68 wp_register_style(
69 'fluentform_settings_global',
70 $settingsGlobalStyle,
71 [],
72 FLUENTFORM_VERSION,
73 'all'
74 );
75
76 wp_register_script(
77 'clipboard',
78 $app->publicUrl('libs/clipboard.min.js'),
79 [],
80 false,
81 true
82 );
83
84 wp_register_script(
85 'copier',
86 $app->publicUrl('js/copier.js'),
87 [],
88 false,
89 true
90 );
91
92 wp_register_script(
93 'fluentform_form_settings',
94 $app->publicUrl('js/form_settings_app.js'),
95 ['jquery'],
96 FLUENTFORM_VERSION,
97 true
98 );
99
100 wp_register_script(
101 'fluent_all_forms',
102 $app->publicUrl('js/fluent-all-forms-admin.js'),
103 ['jquery'],
104 FLUENTFORM_VERSION,
105 true
106 );
107
108 wp_register_style(
109 'fluent_all_forms',
110 $allFormsStyle,
111 [],
112 FLUENTFORM_VERSION,
113 'all'
114 );
115
116 wp_register_script(
117 'fluentform_editor_script',
118 $app->publicUrl('js/fluent-forms-editor.js'),
119 ['jquery'],
120 FLUENTFORM_VERSION,
121 true
122 );
123
124 wp_register_style(
125 'fluentform_editor_style',
126 $fluentFormAdminEditorStyles,
127 [],
128 FLUENTFORM_VERSION,
129 'all'
130 );
131
132 wp_register_style(
133 'fluentform_editor_sass',
134 $fluentFormAdminCSS,
135 [],
136 FLUENTFORM_VERSION,
137 'all'
138 );
139
140 wp_register_script(
141 'fluentform-transfer-js',
142 $app->publicUrl('js/fluentform-transfer.js'),
143 ['jquery'],
144 FLUENTFORM_VERSION,
145 true
146 );
147
148 wp_register_script(
149 'fluentform-global-settings-js',
150 $app->publicUrl('js/fluentform-global-settings.js'),
151 ['jquery'],
152 FLUENTFORM_VERSION,
153 true
154 );
155
156 wp_register_script(
157 'fluentform-modules',
158 $app->publicUrl('js/modules.js'),
159 ['jquery'],
160 FLUENTFORM_VERSION,
161 true
162 );
163
164 wp_register_script(
165 'fluentform_form_entries',
166 $app->publicUrl('js/form_entries.js'),
167 ['jquery', 'fluentform_chart_js', 'fluentform_vue_chart_js'],
168 FLUENTFORM_VERSION,
169 true
170 );
171
172 wp_register_script(
173 'fluentform_all_entries',
174 $app->publicUrl('js/all_entries.js'),
175 ['jquery', 'fluentform_chart_js', 'fluentform_vue_chart_js'],
176 FLUENTFORM_VERSION,
177 true
178 );
179
180 wp_register_script(
181 'fluentform_chart_js',
182 $app->publicUrl('libs/chartjs/chart.min.js'),
183 [],
184 FLUENTFORM_VERSION,
185 true
186 );
187
188 wp_register_script(
189 'fluentform_vue_chart_js',
190 $app->publicUrl('libs/chartjs/vue-chartjs.min.js'),
191 [],
192 FLUENTFORM_VERSION,
193 true
194 );
195
196 wp_register_style(
197 'fluentform-add-ons',
198 $addOnsCss,
199 [],
200 FLUENTFORM_VERSION,
201 'all'
202 );
203
204 wp_register_style(
205 'fluentform_doc_style',
206 $adminDocCss,
207 [],
208 FLUENTFORM_VERSION,
209 'all'
210 );
211
212 add_filter('admin_footer_text', function ($text) {
213 return '<span id="footer-thankyou">Thanks for using <a target="_blank" rel="nofollow" href="https://wordpress.org/plugins/fluentform">Fluent Forms</a></span>';
214 });
215
216 add_filter('update_footer', function ($text) {
217 $footerContent = 'Version ' . FLUENTFORM_VERSION;
218 if (defined('FLUENTFORMPRO')) {
219 $footerContent .= ' & Pro ' . FLUENTFORMPRO_VERSION;
220 }
221 return $footerContent;
222 });
223
224 $elementUIStyle = $app->publicUrl('css/element-ui-css.css');
225 if (is_rtl()) {
226 $elementUIStyle = $app->publicUrl('css/element-ui-css-rtl.css');
227 }
228 wp_enqueue_style(
229 'fluentform_global_elements',
230 $elementUIStyle,
231 [],
232 FLUENTFORM_VERSION,
233 'all'
234 );
235 }
236
237 public function isFluentPages()
238 {
239 return Helper::isFluentAdminPage();
240 }
241
242 public function enqueuePageScripts()
243 {
244 // dd('asas'. $this->isFluentPages());
245 if (!$this->isFluentPages()) {
246 return;
247 }
248
249 wp_enqueue_script('fluent_forms_global');
250 wp_localize_script('fluent_forms_global', 'fluent_forms_global_var', [
251 'fluent_forms_admin_nonce' => wp_create_nonce('fluent_forms_admin_nonce'),
252 'ajaxurl' => admin_url('admin-ajax.php'),
253 'admin_i18n' => TranslationString::getAdminI18n(),
254 'payments_str' => TranslationString::getPaymentsI18n(),
255 'permissions' => Acl::getCurrentUserPermissions(),
256 ]);
257
258 $page = sanitize_text_field($this->app->request->get('page'));
259 $route = sanitize_text_field($this->app->request->get('route'));
260 $formId = intval($this->app->request->get('form_id'));
261
262 if ('fluent_forms' == $page && $route && $formId) {
263 if (true) {
264 wp_enqueue_style('fluentform_settings_global');
265 wp_enqueue_script('clipboard');
266 wp_enqueue_script('copier');
267
268 if (Acl::hasPermission('fluentform_forms_manager')) {
269 if ('settings' == $route) {
270 if (function_exists('wp_enqueue_editor')) {
271 add_filter('user_can_richedit', function ($status) {
272 return true;
273 });
274
275 wp_enqueue_editor();
276 wp_enqueue_media();
277 }
278
279 wp_enqueue_script('fluentform_form_settings');
280 } elseif ('editor' == $route) {
281 $this->enqueueEditorAssets();
282 }
283 }
284 }
285 } elseif ('fluent_forms' == $page) {
286 wp_enqueue_script('fluent_all_forms');
287 wp_enqueue_style('fluent_all_forms');
288 } elseif ('fluent_forms_transfer' == $page) {
289 wp_enqueue_style('fluentform_settings_global');
290 wp_enqueue_script('fluentform-transfer-js');
291 } elseif (
292 'fluent_forms_settings' == $page ||
293 'fluent_forms_payment_entries' == $page ||
294 'fluent_forms_all_entries' == $page
295 ) {
296 wp_enqueue_style('fluentform_settings_global');
297 } elseif ('fluent_forms_add_ons' == $page) {
298 wp_enqueue_style('fluentform-add-ons');
299 } elseif ('fluent_forms_docs' == $page || 'fluent_forms_smtp' == $page) {
300 wp_enqueue_style('fluentform_doc_style');
301 }
302 }
303
304 /**
305 * Register menu and sub-menus.
306 */
307 public function register()
308 {
309 $dashBoardCapability = apply_filters(
310 'fluentform_dashboard_capability',
311 'fluentform_dashboard_access'
312 );
313
314 $settingsCapability = apply_filters(
315 'fluentform_settings_capability',
316 'fluentform_settings_manager'
317 );
318
319 $fromRole = false;
320 if (!current_user_can($dashBoardCapability) && !current_user_can($settingsCapability)) {
321 $currentUserCapability = Acl::getCurrentUserCapability();
322
323 if (!$currentUserCapability) {
324 return;
325 } else {
326 $fromRole = true;
327 $dashBoardCapability = $settingsCapability = $currentUserCapability;
328 }
329 }
330
331 if (Acl::isSuperMan()) {
332 $fromRole = true;
333 }
334
335 if (defined('FLUENTFORMPRO')) {
336 $title = __('Fluent Forms Pro', 'fluentform');
337 } else {
338 $title = __('Fluent Forms', 'fluentform');
339 }
340
341 $menuPriority = 25;
342
343 if (defined('FLUENTCRM')) {
344 $menuPriority = 3;
345 }
346
347 add_menu_page(
348 $title,
349 $title,
350 $dashBoardCapability,
351 'fluent_forms',
352 [$this, 'renderFormAdminRoute'],
353 $this->getMenuIcon(),
354 $menuPriority
355 );
356
357 add_submenu_page(
358 'fluent_forms',
359 __('All Forms', 'fluentform'),
360 __('All Forms', 'fluentform'),
361 $dashBoardCapability,
362 'fluent_forms',
363 [$this, 'renderFormAdminRoute']
364 );
365
366 if ($settingsCapability) {
367 add_submenu_page(
368 'fluent_forms',
369 __('New Form', 'fluentform'),
370 __('New Form', 'fluentform'),
371 $fromRole ? $settingsCapability : 'fluentform_forms_manager',
372 'fluent_forms#add=1',
373 [$this, 'renderFormAdminRoute']
374 );
375
376 $entriesTitle = __('Entries', 'fluentform');
377
378 if (Helper::isFluentAdminPage()) {
379 $entriesCount = wpFluent()->table('fluentform_submissions')
380 ->where('status', 'unread')
381 ->count();
382
383 if ($entriesCount) {
384 $entriesTitle .= ' <span class="ff_unread_count" style="background: #ca4a20;color: white;border-radius: 8px;padding: 1px 8px;">' . $entriesCount . '</span>';
385 }
386 }
387
388 // Register entries intermediary page
389 add_submenu_page(
390 'fluent_forms',
391 $entriesTitle,
392 $entriesTitle,
393 $fromRole ? $settingsCapability : 'fluentform_entries_viewer',
394 'fluent_forms_all_entries',
395 [$this, 'renderAllEntriesAdminRoute']
396 );
397
398 if (apply_filters('fluentform_show_payment_entries', false)) {
399 add_submenu_page(
400 'fluent_forms',
401 __('Payments', 'fluentform'),
402 __('Payments', 'fluentform'),
403 $fromRole ? $settingsCapability : 'fluentform_view_payments',
404 'fluent_forms_payment_entries',
405 [$this, 'renderPaymentEntries']
406 );
407 }
408
409 // Register global settings sub menu page.
410 add_submenu_page(
411 'fluent_forms',
412 __('Global Settings', 'fluentform'),
413 __('Global Settings', 'fluentform'),
414 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
415 'fluent_forms_settings',
416 [$this, 'renderGlobalSettings']
417 );
418
419 // Register import/export sub menu page.
420 add_submenu_page(
421 'fluent_forms',
422 __('Tools', 'fluentform'),
423 __('Tools', 'fluentform'),
424 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
425 'fluent_forms_transfer',
426 [$this, 'renderTransfer']
427 );
428
429 // Register FluentSMTP Sub Menu.
430 add_submenu_page(
431 'fluent_forms',
432 __('SMTP', 'fluentform'),
433 __('SMTP', 'fluentform'),
434 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
435 'fluent_forms_smtp',
436 [$this, 'renderSmtpPromo']
437 );
438
439 // Register Add-Ons
440 add_submenu_page(
441 'fluent_forms',
442 __('Integrations', 'fluentform'),
443 __('Integrations', 'fluentform'),
444 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
445 'fluent_forms_add_ons',
446 [$this, 'renderAddOns']
447 );
448 }
449
450 // Register Documentation
451 add_submenu_page(
452 'fluent_forms',
453 __('Get Help', 'fluentform'),
454 __('Get Help', 'fluentform'),
455 $dashBoardCapability,
456 'fluent_forms_docs',
457 [$this, 'renderDocs']
458 );
459
460 $this->commonAction();
461 }
462
463 private function getMenuIcon()
464 {
465 return 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><defs><style>.cls-1{fill:#fff;}</style></defs><title>dashboard_icon</title><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M15.57,0H4.43A4.43,4.43,0,0,0,0,4.43V15.57A4.43,4.43,0,0,0,4.43,20H15.57A4.43,4.43,0,0,0,20,15.57V4.43A4.43,4.43,0,0,0,15.57,0ZM12.82,14a2.36,2.36,0,0,1-1.66.68H6.5A2.31,2.31,0,0,1,7.18,13a2.36,2.36,0,0,1,1.66-.68l4.66,0A2.34,2.34,0,0,1,12.82,14Zm3.3-3.46a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,10.53Zm0-3.73a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,6.81Z"/></g></g></svg>');
466 }
467
468 public function renderFormAdminRoute()
469 {
470 $formId = intval($this->app->request->get('form_id'));
471 $route = sanitize_key($this->app->request->get('route'));
472
473 if ($route && $formId) {
474 $formRoutePermissionSet = apply_filters('fluentform/form_inner_route_permission_set', [
475 'editor' => 'fluentform_forms_manager',
476 'settings' => 'fluentform_forms_manager',
477 'entries' => 'fluentform_entries_viewer',
478 ]);
479
480 $toVerifyPermission = ArrayHelper::get(
481 $formRoutePermissionSet,
482 $route,
483 'fluentform_forms_manager'
484 );
485
486 $hasPermission = apply_filters(
487 'fluentform_inner_route_has_permission',
488 Acl::hasPermission($toVerifyPermission),
489 $route,
490 $formId
491 );
492
493 if ($hasPermission) {
494 return $this->renderFormInnerPages();
495 } else {
496 return View::render('admin.no_permission');
497 }
498 }
499
500 $this->renderForms();
501 }
502
503 public function renderAllEntriesAdminRoute()
504 {
505 wp_enqueue_script('fluentform_all_entries');
506 View::render('admin.all_entries', []);
507 }
508
509 public function renderFormInnerPages()
510 {
511 $form_id = intval($this->app->request->get('form_id'));
512
513 $form = wpFluent()->table('fluentform_forms')->find($form_id);
514
515 if (!$form) {
516 echo __('<h2>No form found</h2>', 'fluentform');
517 return;
518 }
519
520 $formAdminMenus = [];
521
522 if (Acl::hasPermission('fluentform_forms_manager')) {
523 $formAdminMenus = [
524 'editor' => [
525 'slug' => 'editor',
526 'title' => __('Editor', 'fluentform'),
527 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=editor'),
528 ],
529 'settings' => [
530 'slug' => 'settings',
531 'hash' => 'basic_settings',
532 'title' => __('Settings & Integrations', 'fluentform'),
533 'sub_route' => 'form_settings',
534 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=settings&sub_route=form_settings'),
535 ],
536 ];
537 }
538
539 if (Acl::hasPermission('fluentform_entries_viewer')) {
540 $formAdminMenus['entries'] = [
541 'slug' => 'entries',
542 'hash' => '/',
543 'title' => __('Entries', 'fluentform'),
544 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=entries'),
545 ];
546 }
547
548 $formAdminMenus = apply_filters('fluentform_form_admin_menu', $formAdminMenus, $form_id, $form);
549
550 $route = sanitize_key($this->app->request->get('route'));
551
552 View::render('admin.form.form_wrapper', [
553 'route' => $route,
554 'form_id' => $form_id,
555 'form' => $form,
556 'menu_items' => $formAdminMenus,
557 ]);
558 }
559
560 public function renderSettings($form_id)
561 {
562 $settingsMenus = [
563 'form_settings' => [
564 'title' => __('Form Settings', 'fluentform'),
565 'slug' => 'form_settings',
566 'hash' => 'basic_settings',
567 'route' => '/',
568 ],
569 'email_notifications' => [
570 'title' => __('Email Notifications', 'fluentform'),
571 'slug' => 'form_settings',
572 'hash' => 'email_notifications',
573 'route' => '/email-settings',
574 ],
575 'other_confirmations' => [
576 'title' => __('Other Confirmations', 'fluentform'),
577 'slug' => 'form_settings',
578 'hash' => 'other_confirmations',
579 'route' => '/other-confirmations',
580 ],
581 'all_integrations' => [
582 'title' => __('Marketing & CRM Integrations', 'fluentform'),
583 'slug' => 'form_settings',
584 'route' => '/all-integrations',
585 ],
586 ];
587
588 if (Helper::isSlackEnabled()) {
589 $settingsMenus['slack'] = [
590 'title' => __('Slack', 'fluentform'),
591 'slug' => 'form_settings',
592 'hash' => 'slack',
593 'route' => '/slack',
594 ];
595 }
596
597 $settingsMenus = apply_filters('fluentform_form_settings_menu', $settingsMenus, $form_id);
598
599 $externalMenuItems = [];
600 foreach ($settingsMenus as $key => $menu) {
601 if (empty($menu['hash'])) {
602 unset($settingsMenus[$key]);
603 $externalMenuItems[$key] = $menu;
604 }
605 }
606
607 $settingsMenus['custom_css_js'] = [
608 'title' => __('Custom CSS/JS', 'fluentform'),
609 'slug' => 'form_settings',
610 'hash' => 'custom_css_js',
611 'route' => '/custom-css-js',
612 ];
613
614 $settingsMenus = array_filter(array_merge($settingsMenus, $externalMenuItems));
615
616 $currentRoute = sanitize_key($this->app->request->get('sub_route', ''));
617
618 View::render('admin.form.settings_wrapper', [
619 'form_id' => $form_id,
620 'settings_menus' => $settingsMenus,
621 'current_sub_route' => $currentRoute,
622 ]);
623 }
624
625 /**
626 * Remove the inactive addOn menu items
627 *
628 * @param string $addOn
629 *
630 * @return boolean
631 */
632 public function filterFormSettingsMenu($settingsMenus, $form_id)
633 {
634 if (array_key_exists('mailchimp_integration', $settingsMenus)) {
635 $option = (array) get_option('_fluentform_mailchimp_details');
636 if (!isset($option['status']) || !$option['status']) {
637 unset($settingsMenus['mailchimp_integration']);
638 }
639 }
640
641 return $settingsMenus;
642 }
643
644 public function renderFormSettings($form_id)
645 {
646 wp_localize_script('fluentform_form_settings', 'FluentFormApp', [
647 'form_id' => $form_id,
648 'plugin' => $this->app->getSlug(),
649 'hasPro' => defined('FLUENTFORMPRO'),
650 'hasPDF' => defined('FLUENTFORM_PDF_VERSION'),
651 'hasFluentCRM' => defined('FLUENTCRM'),
652 'upgrade_url' => fluentform_upgrade_url(),
653 'ace_path_url' => $this->app->publicUrl('libs/ace'),
654 'is_conversion_form' => Helper::isConversionForm($form_id),
655 'has_fluent_smtp' => defined('FLUENTMAIL'),
656 'fluent_smtp_url' => admin_url('admin.php?page=fluent_forms_smtp'),
657 'form_settings_str' => TranslationString::getSettingsI18n(),
658 'integrationsResource' => [
659 'asset_url' => $this->app->publicUrl('img/integrations.png'),
660 'list_url' => fluentform_integrations_url(),
661 'instruction' => __("Fluent Forms Pro has tons of integrations to take your forms to the next level. From payment gateways to quiz building, SMS notifications to email marketing - you'll get integrations for various purposes. Even if you don't find your favorite tools, you can integrate them easily with Zapier.", 'fluentform'),
662 ],
663 ]);
664
665 View::render('admin.form.settings', [
666 'form_id' => $form_id,
667 ]);
668 }
669
670 public function renderForms()
671 {
672 if (!get_option('_fluentform_installed_version')) {
673 (new Activator())->migrate();
674 }
675
676 $formsCount = wpFluent()->table('fluentform_forms')->count();
677
678 wp_localize_script('fluent_all_forms', 'FluentFormApp', apply_filters('fluent_all_forms_vars', [
679 'plugin' => $this->app->getSlug(),
680 'formsCount' => $formsCount,
681 'hasPro' => defined('FLUENTFORMPRO'),
682 'upgrade_url' => fluentform_upgrade_url(),
683 'adminUrl' => admin_url('admin.php?page=fluent_forms'),
684 'isDisableAnalytics' => apply_filters('fluentform-disabled_analytics', false),
685 ]));
686
687 View::render('admin.all_forms', []);
688 }
689
690 public function renderEditor($form_id)
691 {
692 View::render('admin.form.editor', [
693 'plugin' => $this->app->getSlug(),
694 'form_id' => $form_id,
695 ]);
696 }
697
698 public function renderDocs()
699 {
700 (new DocumentationModule())->render(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped --
701 }
702
703 public function renderAddOns()
704 {
705 (new AddOnModule())->render();
706 }
707
708 private function enqueueEditorAssets()
709 {
710 $formId = intval($this->app->request->get('form_id'));
711
712 $form = wpFluent()->table('fluentform_forms')->find($formId);
713
714 do_action('fluentform_loading_editor_assets', $form);
715
716 wp_enqueue_style('fluentform_editor_sass');
717 wp_enqueue_style('fluentform_editor_style');
718
719 $pluginSlug = $this->app->getSlug();
720
721 if (function_exists('wp_enqueue_editor')) {
722 add_filter('user_can_richedit', '__return_true');
723 wp_enqueue_editor();
724 wp_enqueue_media();
725 }
726
727 wp_enqueue_script('fluentform_editor_script');
728
729 $jsonData = $form->form_fields;
730
731 if (!defined('FLUENTFORM_DISABLE_EDITOR_FILED_HOOOK')) {
732 $formFields = $form->form_fields;
733
734 if ($formFields) {
735 $formFields = json_decode($formFields, true);
736
737 foreach ($formFields['fields'] as $index => $formField) {
738 $formField = $formFields['fields'][$index] = apply_filters(
739 'fluentform_editor_init_element_' . $formField['element'],
740 $formField,
741 $form
742 );
743
744 if (!$formFields['fields'][$index]) {
745 unset($formFields['fields'][$index]);
746 continue;
747 }
748
749 if ('container' == $formField['element']) {
750 $columns = $formField['columns'];
751 foreach ($columns as $columnIndex => $column) {
752 foreach ($column['fields'] as $fieldIndex => $columnField) {
753 $columns[$columnIndex]['fields'][$fieldIndex] = apply_filters(
754 'fluentform_editor_init_element_' . $columnField['element'],
755 $columnField,
756 $form
757 );
758
759 if (!$columns[$columnIndex]['fields'][$fieldIndex]) {
760 unset($columns[$columnIndex]['fields'][$fieldIndex]);
761 }
762 }
763 }
764
765 $formFields['fields'][$index]['columns'] = array_values($columns);
766 }
767 }
768
769 $formFields['fields'] = array_values($formFields['fields']);
770 $formFields = json_encode($formFields, true);
771 }
772
773 $form->form_fields = $formFields;
774 }
775
776 $searchTags = $this->app->load(
777 $this->app->appPath('Services/FormBuilder/ElementSearchTags.php')
778 );
779
780 $searchTags = apply_filters('fluent_editor_element_search_tags', $searchTags, $form);
781
782 $elementPlacements = apply_filters(
783 'fluent_editor_element_settings_placement',
784 $this->app->load($this->app->appPath('Services/FormBuilder/ElementSettingsPlacement.php')),
785 $form
786 );
787
788 wp_localize_script('fluentform_editor_script', 'FluentFormApp', apply_filters('fluentform_editor_vars', [
789 'plugin' => $pluginSlug,
790 'form_id' => $formId,
791 'plugin_public_url' => $this->app->publicUrl(),
792 'preview_url' => Helper::getPreviewUrl($formId),
793 'form' => $form,
794 'hasPro' => defined('FLUENTFORMPRO'),
795 'countries' => $this->app->load(
796 $this->app->appPath('Services/FormBuilder/CountryNames.php')
797 ),
798 'element_customization_settings' => $this->app->load(
799 $this->app->appPath('Services/FormBuilder/ElementCustomization.php')
800 ),
801
802 'validation_rule_settings' => $this->app->load(
803 $this->app->appPath('Services/FormBuilder/ValidationRuleSettings.php')
804 ),
805
806 'form_editor_str' => TranslationString::getEditorI18n(),
807 'element_search_tags' => $searchTags,
808 'element_settings_placement' => $elementPlacements,
809 'all_forms_url' => admin_url('admin.php?page=fluent_forms'),
810 'has_payment_features' => !defined('FLUENTFORMPRO'),
811 'upgrade_url' => fluentform_upgrade_url(),
812 'is_conversion_form' => Helper::isConversionForm($formId),
813 'used_name_attributes' => $this->usedNameAttributes($formId),
814 'bulk_options_json' => '{"Countries":["Afghanistan","Albania","Algeria","American Samoa","Andorra","Angola","Anguilla","Antarctica","Antigua and Barbuda","Argentina","Armenia","Aruba","Australia","Austria","Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bermuda","Bhutan","Bolivia","Bonaire, Sint Eustatius and Saba","Bosnia and Herzegovina","Botswana","Bouvet Island","Brazil","British Indian Ocean Territory","Brunei Darussalam","Bulgaria","Burkina Faso","Burundi","Cambodia","Cameroon","Canada","Cape Verde","Cayman Islands","Central African Republic","Chad","Chile","China","Christmas Island","Cocos Islands","Colombia","Comoros","Congo, Democratic Republic of the","Congo, Republic of the","Cook Islands","Costa Rica","Croatia","Cuba","Cura\u00e7ao","Cyprus","Czech Republic","C\u00f4te d\'Ivoire","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador","Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Eswatini (Swaziland)","Ethiopia","Falkland Islands","Faroe Islands","Fiji","Finland","France","French Guiana","French Polynesia","French Southern Territories","Gabon","Gambia","Georgia","Germany","Ghana","Gibraltar","Greece","Greenland","Grenada","Guadeloupe","Guam","Guatemala","Guernsey","Guinea","Guinea-Bissau","Guyana","Haiti","Heard and McDonald Islands","Holy See","Honduras","Hong Kong","Hungary","Iceland","India","Indonesia","Iran","Iraq","Ireland","Isle of Man","Israel","Italy","Jamaica","Japan","Jersey","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait","Kyrgyzstan","Lao People\'s Democratic Republic","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg","Macau","Macedonia","Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Martinique","Mauritania","Mauritius","Mayotte","Mexico","Micronesia","Moldova","Monaco","Mongolia","Montenegro","Montserrat","Morocco","Mozambique","Myanmar","Namibia","Nauru","Nepal","Netherlands","New Caledonia","New Zealand","Nicaragua","Niger","Nigeria","Niue","Norfolk Island","North Korea","Northern Mariana Islands","Norway","Oman","Pakistan","Palau","Palestine, State of","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Pitcairn","Poland","Portugal","Puerto Rico","Qatar","Romania","Russia","Rwanda","R\u00e9union","Saint Barth\u00e9lemy","Saint Helena","Saint Kitts and Nevis","Saint Lucia","Saint Martin","Saint Pierre and Miquelon","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe","Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Sint Maarten","Slovakia","Slovenia","Solomon Islands","Somalia","South Africa","South Georgia","South Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Svalbard and Jan Mayen Islands","Sweden","Switzerland","Syria","Taiwan","Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tokelau","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan","Turks and Caicos Islands","Tuvalu","US Minor Outlying Islands","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam","Virgin Islands, British","Virgin Islands, U.S.","Wallis and Futuna","Western Sahara","Yemen","Zambia","Zimbabwe","\u00c5land Islands"],"U.S. States":["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","District of Columbia","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Carolina","North Dakota","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming","Armed Forces Americas","Armed Forces Europe","Armed Forces Pacific"],"Canadian Province\/Territory":["Alberta","British Columbia","Manitoba","New Brunswick","Newfoundland and Labrador","Northwest Territories","Nova Scotia","Nunavut","Ontario","Prince Edward Island","Quebec","Saskatchewan","Yukon"],"Continents":["Africa","Antarctica","Asia","Australia","Europe","North America","South America"],"Gender":["Male","Female","Prefer Not to Answer"],"Age":["Under 18","18-24","25-34","35-44","45-54","55-64","65 or Above","Prefer Not to Answer"],"Marital Status":["Single","Married","Divorced","Widowed"],"Employment":["Employed Full-Time","Employed Part-Time","Self-employed","Not employed but looking for work","Not employed and not looking for work","Homemaker","Retired","Student","Prefer Not to Answer"],"Job Type":["Full-Time","Part-Time","Per Diem","Employee","Temporary","Contract","Intern","Seasonal"],"Industry":["Accounting\/Finance","Advertising\/Public Relations","Aerospace\/Aviation","Arts\/Entertainment\/Publishing","Automotive","Banking\/Mortgage","Business Development","Business Opportunity","Clerical\/Administrative","Construction\/Facilities","Consumer Goods","Customer Service","Education\/Training","Energy\/Utilities","Engineering","Government\/Military","Green","Healthcare","Hospitality\/Travel","Human Resources","Installation\/Maintenance","Insurance","Internet","Job Search Aids","Law Enforcement\/Security","Legal","Management\/Executive","Manufacturing\/Operations","Marketing","Non-Profit\/Volunteer","Pharmaceutical\/Biotech","Professional Services","QA\/Quality Control","Real Estate","Restaurant\/Food Service","Retail","Sales","Science\/Research","Skilled Labor","Technology","Telecommunications","Transportation\/Logistics","Other"],"Education":["High School","Associate Degree","Bachelor\'s Degree","Graduate or Professional Degree","Some College","Other","Prefer Not to Answer"],"Days of the Week":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"Months of the Year":["January","February","March","April","May","June","July","August","September","October","November","December"],"How Often":["Every day","Once a week","2 to 3 times a week","Once a month","2 to 3 times a month","Less than once a month"],"How Long":["Less than a month","1-6 months","1-3 years","Over 3 years","Never used"],"Satisfaction":["Very Satisfied","Satisfied","Neutral","Unsatisfied","Very Unsatisfied"],"Importance":["Very Important","Important","Somewhat Important","Not Important"],"Agreement":["Strongly Agree","Agree","Disagree","Strongly Disagree"],"Comparison":["Much Better","Somewhat Better","About the Same","Somewhat Worse","Much Worse"],"Would You":["Definitely","Probably","Not Sure","Probably Not","Definitely Not"],"Size":["Extra Small","Small","Medium","Large","Extra Large"],"Timezone":["(GMT -12-00) Eniwetok, Kwajalein:-12","(GMT -11-00) Midway Island, Samoa:-11","(GMT -10-00) Hawaii:-10","(GMT -9-00) Alaska:-9","(GMT -8-00) Pacific Time (US & Canada):-8","(GMT -7-00) Mountain Time (US & Canada):-7","(GMT -6-00) Central Time (US & Canada), Mexico City:-6","(GMT -5-00) Eastern Time (US & Canada), Bogota, Lima:-5","(GMT -4-00) Atlantic Time (Canada), Caracas, La Paz:-4","(GMT -3-30) Newfoundland:-3.5","(GMT -3-00) Brazil, Buenos Aires, Georgetown:-3","(GMT -2-00) Mid-Atlantic:-2","(GMT -1-00) Azores, Cape Verde Islands:-1","(GMT) Western Europe Time, London, Lisbon, Casablanca:0","(GMT +1-00) Brussels, Copenhagen, Madrid, Paris:1","(GMT +2-00) Kaliningrad, South Africa:2","(GMT +3-00) Baghdad, Riyadh, Moscow, St. Petersburg:3","(GMT +3-30) Tehran:3.5","(GMT +4-00) Abu Dhabi, Muscat, Baku, Tbilisi:4","(GMT +4-30) Kabul:4.5","(GMT +5-00) Ekaterinburg, Islamabad, Karachi, Tashkent:5","(GMT +5-30) Bombay, Calcutta, Madras, New Delhi:5.5","(GMT +5-45) Kathmandu:5.75","(GMT +6-00) Almaty, Dhaka, Colombo:6","(GMT +7-00) Bangkok, Hanoi, Jakarta:7","(GMT +8-00) Beijing, Perth, Singapore, Hong Kong:8","(GMT +9-00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk:9","(GMT +9-30) Adelaide, Darwin:9.5","(GMT +10-00) Eastern Australia, Guam, Vladivostok:10","(GMT +11-00) Magadan, Solomon Islands, New Caledonia:11","(GMT +12-00) Auckland, Wellington, Fiji, Kamchatka:12"]}',
815 ]));
816 }
817
818 /**
819 * Render global settings page.
820 *
821 * @throws \Exception
822 */
823 public function renderGlobalSettings()
824 {
825 if (function_exists('wp_enqueue_editor')) {
826 add_filter('user_can_richedit', '__return_true');
827 wp_enqueue_editor();
828 wp_enqueue_media();
829 }
830
831 // Fire an event letting others know the current component
832 // that fluentform is rendering for the global settings
833 // page. So that they can hook and load their custom
834 // components on this page dynamically & easily.
835 // N.B. native 'components' will always use
836 // 'settings' as their current component.
837 $currentComponent = apply_filters(
838 'fluentform_global_settings_current_component',
839 $this->app->request->get('component', 'settings')
840 );
841
842 $currentComponent = sanitize_key($currentComponent);
843
844 $components = apply_filters('fluentform_global_settings_components', []);
845
846 $components['reCAPTCHA'] = [
847 'hash' => 're_captcha',
848 'title' => 'reCAPTCHA',
849 ];
850
851 $components['hCAPTCHA'] = [
852 'hash' => 'h_captcha',
853 'title' => 'hCaptcha',
854 ];
855
856 $components['Turnstile'] = [
857 'hash' => 'turnstile',
858 'title' => 'Turnstile (Beta)',
859 ];
860
861 View::render('admin.settings.index', [
862 'components' => $components,
863 'currentComponent' => $currentComponent,
864 ]);
865 }
866
867 public function renderTransfer()
868 {
869 $forms = wpFluent()->table('fluentform_forms')
870 ->orderBy('id', 'desc')
871 ->select(['id', 'title'])
872 ->get();
873
874 wp_localize_script('fluentform-transfer-js', 'FluentFormApp', [
875 'plugin' => $this->app->getSlug(),
876 'forms' => $forms,
877 'upgrade_url' => fluentform_upgrade_url(),
878 'hasPro' => defined('FLUENTFORMPRO'),
879 'transfer_str' => TranslationString::getTransferModuleI18n(),
880 ]);
881
882 View::render('admin.transfer.index');
883 }
884
885 public function addPreviewButton($formId)
886 {
887 $previewText = __('Preview & Design', 'fluentform');
888 $previewUrl = Helper::getPreviewUrl($formId);
889 if ($isConversational = Helper::isConversionForm($formId)) {
890 $previewText = __('Preview', 'fluentform');
891 }
892
893 echo '<a target="_blank" class="el-button el-button--small" href="' . esc_url($previewUrl) . '">' . '<i class="el-icon-view"></i> ' . esc_attr($previewText) . '</a>';
894 }
895
896 public function addCopyShortcodeButton($formId)
897 {
898 $formId = (int) $formId;
899 $shortcode = '[fluentform id="' . $formId . '"]';
900 if (Helper::isConversionForm($formId)) {
901 $shortcode = '[fluentform type="conversational" id="' . $formId . '"]';
902 }
903 echo '<button style="background:#dedede;color:#545454;padding:5px;max-width: 200px;overflow: hidden;" title="Click to Copy" class="btn copy" data-clipboard-text=\'' . $shortcode . '\'><i class="dashicons dashicons-admin-page" style="color:#eee;text-shadow:#000 -1px 1px 1px;"></i> ' . $shortcode . '</button>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $shortcode is escaped before being passed in.
904 return;
905 }
906
907 public function commonAction()
908 {
909 $fluentFormPages = [
910 'fluent_forms',
911 'fluent_forms_transfer',
912 'fluent_forms_settings',
913 'fluent_forms_add_ons',
914 'fluent_forms_docs',
915 'fluent_forms_smtp',
916 ];
917
918 $page = sanitize_text_field($this->app->request->get('page'));
919
920 if ($page && in_array($page, $fluentFormPages)) {
921 // Let's deregister existing vuejs by other devs
922 // Other devs should not regis
923 add_action('admin_print_scripts', function () {
924 wp_dequeue_script('vuejs');
925 wp_dequeue_script('vue');
926 wp_deregister_script('elementor-admin-app');
927 });
928 }
929 }
930
931 public function renderGlobalMenu()
932 {
933 $showPayment = false;
934 if (defined('FLUENTFORMPRO')) {
935 $showPayment = !get_option('__fluentform_payment_module_settings');
936 if ($showPayment) {
937 $formCount = wpFluent()->table('fluentform_forms')
938 ->count();
939 $showPayment = $formCount > 2;
940 }
941 }
942 View::render('admin.global_menu', [
943 'show_payment' => $showPayment,
944 'show_payment_entries' => apply_filters('fluentform_show_payment_entries', false),
945 ]);
946 }
947
948 public function renderPaymentEntries()
949 {
950 do_action('flunetform_render_payment_entries');
951 }
952
953 public function renderSmtpPromo()
954 {
955 wp_enqueue_script('fluentform_admin_notice', fluentformMix('js/admin_notices.js'), [
956 'jquery',
957 ], FLUENTFORM_VERSION);
958
959 View::render('admin.smtp.index', [
960 'logo' => $this->app->publicUrl('img/fluentsmtp.svg'),
961 'banner_image' => $this->app->publicUrl('img/fluentsmtp-banner.png'),
962 'is_installed' => defined('FLUENTMAIL'),
963 'setup_url' => admin_url('options-general.php?page=fluent-mail#/connections'),
964 ]);
965 }
966
967 private function usedNameAttributes($formId)
968 {
969 return wpFluent()->table('fluentform_entry_details')
970 ->select(['field_name'])
971 ->where('form_id', $formId)
972 ->orderBy('submission_id', 'desc')
973 ->groupBy('field_name')
974 ->get();
975 }
976 }
977