PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 4.3.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v4.3.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 3.6.66 All 195 releases
fluentform / app / Modules / Registerer / Menu.php

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

936 lines 40.0 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 * @var \FluentForm\Framework\Foundation\Application
18 */
19 protected $app;
20
21 /**
22 * Menu constructor.
23 *
24 * @param \FluentForm\Framework\Foundation\Application $application
25 */
26 public function __construct(Application $application)
27 {
28 $this->app = $application;
29
30 $this->app->addFilter('fluentform_form_settings_menu', array(
31 $this, 'filterFormSettingsMenu'
32 ), 10, 2);
33 }
34
35 public function reisterScripts()
36 {
37 if (!$this->isFluentPages()) {
38 return;
39 }
40
41 $app = $this->app;
42
43 wp_register_script(
44 'fluent_forms_global',
45 $app->publicUrl('js/fluent_forms_global.js'),
46 array('jquery'),
47 FLUENTFORM_VERSION,
48 true
49 );
50
51 $settingsGlobalStyle = $app->publicUrl('css/settings_global.css');
52 $allFormsStyle = $app->publicUrl("css/fluent-all-forms.css");
53 $fluentFormAdminEditorStyles = $app->publicUrl("css/fluent-forms-admin-sass.css");
54 $fluentFormAdminCSS = $app->publicUrl("css/fluent-forms-admin.css");
55 $addOnsCss = $app->publicUrl("css/add-ons.css");
56 $adminDocCss = $app->publicUrl("css/admin_docs.css");
57 if (is_rtl()) {
58 $settingsGlobalStyle = $app->publicUrl('css/settings_global_rtl.css');
59 $allFormsStyle = $app->publicUrl("css/fluent-all-forms-rtl.css");
60 $fluentFormAdminEditorStyles = $app->publicUrl("css/fluent-forms-admin-sass-rtl.css");
61 $fluentFormAdminCSS = $app->publicUrl("css/fluent-forms-admin-rtl.css");
62 $addOnsCss = $app->publicUrl("css/add-ons-rtl.css");
63 $adminDocCss = $app->publicUrl("css/admin_docs_rtl.css");
64 }
65
66 wp_register_style(
67 'fluentform_settings_global',
68 $settingsGlobalStyle,
69 array(),
70 FLUENTFORM_VERSION,
71 'all'
72 );
73
74 wp_register_script(
75 'clipboard',
76 $app->publicUrl('libs/clipboard.min.js'),
77 array(),
78 false,
79 true
80 );
81
82 wp_register_script(
83 'copier',
84 $app->publicUrl('js/copier.js'),
85 array(),
86 false,
87 true
88 );
89
90 wp_register_script(
91 'fluentform_form_settings',
92 $app->publicUrl("js/form_settings_app.js"),
93 array('jquery'),
94 FLUENTFORM_VERSION,
95 true
96 );
97
98 wp_register_script(
99 'fluent_all_forms',
100 $app->publicUrl("js/fluent-all-forms-admin.js"),
101 array('jquery'),
102 FLUENTFORM_VERSION,
103 true
104 );
105
106 wp_register_style(
107 'fluent_all_forms',
108 $allFormsStyle,
109 array(),
110 FLUENTFORM_VERSION,
111 'all'
112 );
113
114 wp_register_script(
115 'fluentform_editor_script',
116 $app->publicUrl("js/fluent-forms-editor.js"),
117 array('jquery'),
118 FLUENTFORM_VERSION,
119 true
120 );
121
122 wp_register_style(
123 'fluentform_editor_style',
124 $fluentFormAdminEditorStyles,
125 [],
126 FLUENTFORM_VERSION,
127 'all'
128 );
129
130 wp_register_style(
131 'fluentform_editor_sass',
132 $fluentFormAdminCSS,
133 [],
134 FLUENTFORM_VERSION,
135 'all'
136 );
137
138 wp_register_script(
139 'fluentform-transfer-js',
140 $app->publicUrl("js/fluentform-transfer.js"),
141 ['jquery'],
142 FLUENTFORM_VERSION,
143 true
144 );
145
146 wp_register_script(
147 'fluentform-global-settings-js',
148 $app->publicUrl("js/fluentform-global-settings.js"),
149 ['jquery'],
150 FLUENTFORM_VERSION,
151 true
152 );
153
154 wp_register_script(
155 'fluentform-modules',
156 $app->publicUrl('js/modules.js'),
157 ['jquery'],
158 FLUENTFORM_VERSION,
159 true
160 );
161
162 wp_register_script(
163 'fluentform_form_entries',
164 $app->publicUrl('js/form_entries.js'),
165 array('jquery'),
166 FLUENTFORM_VERSION,
167 true
168 );
169
170 wp_register_script(
171 'fluentform_all_entries',
172 $app->publicUrl('js/all_entries.js'),
173 array('jquery'),
174 FLUENTFORM_VERSION,
175 true
176 );
177
178 wp_register_style(
179 'fluentform-add-ons',
180 $addOnsCss,
181 [],
182 FLUENTFORM_VERSION,
183 'all'
184 );
185
186 wp_register_style(
187 'fluentform_doc_style',
188 $adminDocCss,
189 [],
190 FLUENTFORM_VERSION,
191 'all'
192 );
193
194 add_filter('admin_footer_text', function ($text) {
195 return '<span id="footer-thankyou">Thanks for using <a target="_blank" rel="nofollow" href="https://wordpress.org/plugins/fluentform">Fluent Forms</a>.</span>';
196 });
197
198 $elementUIStyle = $app->publicUrl('css/element-ui-css.css');
199 if (is_rtl()) {
200 $elementUIStyle = $app->publicUrl('css/element-ui-css-rtl.css');
201 }
202 wp_enqueue_style(
203 'fluentform_global_elements',
204 $elementUIStyle,
205 [],
206 FLUENTFORM_VERSION,
207 'all'
208 );
209 }
210
211 public function isFluentPages()
212 {
213 return Helper::isFluentAdminPage();
214 }
215
216 public function enqueuePageScripts()
217 {
218 if (!$this->isFluentPages()) {
219 return;
220 }
221
222 wp_enqueue_script('fluent_forms_global');
223 wp_localize_script('fluent_forms_global', 'fluent_forms_global_var', [
224 'fluent_forms_admin_nonce' => wp_create_nonce('fluent_forms_admin_nonce'),
225 'ajaxurl' => admin_url('admin-ajax.php'),
226 'admin_i18n' => TranslationString::getAdminI18n(),
227 'payments_str' => TranslationString::getPaymentsI18n(),
228 'permissions' => Acl::getCurrentUserPermissions()
229 ]);
230
231 $page = sanitize_text_field($_GET['page']);
232
233 if ($page == 'fluent_forms' && isset($_GET['route']) && isset($_GET['form_id'])) {
234 if (true) {
235 wp_enqueue_style('fluentform_settings_global');
236 wp_enqueue_script('clipboard');
237 wp_enqueue_script('copier');
238
239 if (Acl::hasPermission('fluentform_forms_manager')) {
240 if ($_GET['route'] == 'settings') {
241 if (function_exists('wp_enqueue_editor')) {
242 add_filter('user_can_richedit', function ($status) {
243 return true;
244 });
245
246 wp_enqueue_editor();
247 wp_enqueue_media();
248 }
249
250 wp_enqueue_script('fluentform_form_settings');
251 } elseif ($_GET['route'] == 'editor') {
252 $this->enqueueEditorAssets();
253 }
254 }
255 }
256 } else if ($page == 'fluent_forms') {
257 wp_enqueue_script('fluent_all_forms');
258 wp_enqueue_style('fluent_all_forms');
259 } else if ($page == 'fluent_forms_transfer') {
260 wp_enqueue_style('fluentform_settings_global');
261 wp_enqueue_script('fluentform-transfer-js');
262 } else if (
263 $page == 'fluent_forms_settings' ||
264 $page == 'fluent_forms_payment_entries' ||
265 $page == 'fluent_forms_all_entries'
266 ) {
267 wp_enqueue_style('fluentform_settings_global');
268 } else if ($page == 'fluent_forms_add_ons') {
269 wp_enqueue_style('fluentform-add-ons');
270 } else if ($page == 'fluent_forms_docs' || $page == 'fluent_forms_smtp') {
271 wp_enqueue_style('fluentform_doc_style');
272 }
273 }
274
275 /**
276 * Register menu and sub-menus.
277 */
278 public function register()
279 {
280 $dashBoardCapability = apply_filters(
281 'fluentform_dashboard_capability', 'fluentform_dashboard_access'
282 );
283
284 $settingsCapability = apply_filters(
285 'fluentform_settings_capability', 'fluentform_settings_manager'
286 );
287
288 $fromRole = false;
289 if (!current_user_can($dashBoardCapability) && !current_user_can($settingsCapability)) {
290 $currentUserCapability = Acl::getCurrentUserCapability();
291
292 if (!$currentUserCapability) {
293 return;
294 } else {
295 $fromRole = true;
296 $dashBoardCapability = $settingsCapability = $currentUserCapability;
297 }
298 }
299
300 if (Acl::isSuperMan()) {
301 $fromRole = true;
302 }
303
304 if (defined('FLUENTFORMPRO')) {
305 $title = __('Fluent Forms Pro', 'fluentform');
306 } else {
307 $title = __('Fluent Forms', 'fluentform');
308 }
309
310 $menuPriority = 25;
311
312 if (defined('FLUENTCRM')) {
313 $menuPriority = 3;
314 }
315
316 add_menu_page(
317 $title,
318 $title,
319 $dashBoardCapability,
320 'fluent_forms',
321 array($this, 'renderFormAdminRoute'),
322 $this->getMenuIcon(),
323 $menuPriority
324 );
325
326
327 add_submenu_page(
328 'fluent_forms',
329 __('All Forms', 'fluentform'),
330 __('All Forms', 'fluentform'),
331 $dashBoardCapability,
332 'fluent_forms',
333 array($this, 'renderFormAdminRoute')
334 );
335
336 if ($settingsCapability) {
337 add_submenu_page(
338 'fluent_forms',
339 __('New Form', 'fluentform'),
340 __('New Form', 'fluentform'),
341 $fromRole ? $settingsCapability : 'fluentform_forms_manager',
342 'fluent_forms#add=1',
343 array($this, 'renderFormAdminRoute')
344 );
345
346 $entriesTitle = __('Entries', 'fluentform');
347
348 if (Helper::isFluentAdminPage()) {
349 $entriesCount = wpFluent()->table('fluentform_submissions')
350 ->where('status', 'unread')
351 ->count();
352
353 if ($entriesCount) {
354 $entriesTitle .= ' <span class="ff_unread_count" style="background: #ca4a20;color: white;border-radius: 8px;padding: 1px 8px;">'.$entriesCount.'</span>';
355 }
356 }
357
358 // Register entries intermediary page
359 add_submenu_page(
360 'fluent_forms',
361 $entriesTitle,
362 $entriesTitle,
363 $fromRole ? $settingsCapability : 'fluentform_entries_viewer',
364 'fluent_forms_all_entries',
365 array($this, 'renderAllEntriesAdminRoute')
366 );
367
368 if (apply_filters('fluentform_show_payment_entries', false)) {
369 add_submenu_page(
370 'fluent_forms',
371 __('Payments', 'fluentform'),
372 __('Payments', 'fluentform'),
373 $fromRole ? $settingsCapability : 'fluentform_view_payments',
374 'fluent_forms_payment_entries',
375 array($this, 'renderPaymentEntries')
376 );
377 }
378
379 // Register global settings sub menu page.
380 add_submenu_page(
381 'fluent_forms',
382 __('Global Settings', 'fluentform'),
383 __('Global Settings', 'fluentform'),
384 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
385 'fluent_forms_settings',
386 array($this, 'renderGlobalSettings')
387 );
388
389 // Register import/export sub menu page.
390 add_submenu_page(
391 'fluent_forms',
392 __('Tools', 'fluentform'),
393 __('Tools', 'fluentform'),
394 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
395 'fluent_forms_transfer',
396 array($this, 'renderTransfer')
397 );
398
399 // Register FluentSMTP Sub Menu.
400 add_submenu_page(
401 'fluent_forms',
402 __('SMTP', 'fluentform'),
403 __('SMTP', 'fluentform'),
404 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
405 'fluent_forms_smtp',
406 array($this, 'renderSmtpPromo')
407 );
408
409 // Register Add-Ons
410 add_submenu_page(
411 'fluent_forms',
412 __('Integration Modules', 'fluentform'),
413 __('Integration Modules', 'fluentform'),
414 $fromRole ? $settingsCapability : 'fluentform_settings_manager',
415 'fluent_forms_add_ons',
416 array($this, 'renderAddOns')
417 );
418 }
419
420 // Register Documentation
421 add_submenu_page(
422 'fluent_forms',
423 __('Get Help', 'fluentform'),
424 __('Get Help', 'fluentform'),
425 $dashBoardCapability,
426 'fluent_forms_docs',
427 array($this, 'renderDocs')
428 );
429
430 $this->commonAction();
431 }
432
433 private function getMenuIcon()
434 {
435 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>');
436 }
437
438 public function renderFormAdminRoute()
439 {
440 if (isset($_GET['route']) && isset($_GET['form_id'])) {
441 $route = sanitize_key($_GET['route']);
442
443 $formRoutePermissionSet = apply_filters('fluentform/form_inner_route_permission_set', [
444 'editor' => 'fluentform_forms_manager',
445 'settings' => 'fluentform_forms_manager',
446 'entries' => 'fluentform_entries_viewer',
447 ]);
448
449 $toVerifyPermission = ArrayHelper::get(
450 $formRoutePermissionSet,
451 $route,
452 'fluentform_forms_manager'
453 );
454
455 $hasPermission = apply_filters(
456 'fluentform_inner_route_has_permission',
457 Acl::hasPermission($toVerifyPermission),
458 $route,
459 intval($_GET['form_id'])
460 );
461
462 if ($hasPermission) {
463 return $this->renderFormInnerPages();
464 } else {
465 return View::render('admin.no_permission');
466 }
467 }
468
469 $this->renderForms();
470 }
471
472 public function renderAllEntriesAdminRoute()
473 {
474 wp_enqueue_script('fluentform_all_entries');
475 View::render('admin.all_entries', array());
476 }
477
478 public function renderFormInnerPages()
479 {
480 $form_id = intval($_GET['form_id']);
481 $form = wpFluent()->table('fluentform_forms')->find($form_id);
482
483 if (!$form) {
484 echo __("<h2>No form found</h2>", 'fluentform');
485 return;
486 }
487
488 $formAdminMenus = [];
489
490 if (Acl::hasPermission('fluentform_forms_manager')) {
491 $formAdminMenus = [
492 'editor' => array(
493 'slug' => 'editor',
494 'title' => __('Editor', 'fluentform'),
495 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=editor')
496 ),
497 'settings' => array(
498 'slug' => 'settings',
499 'hash' => 'basic_settings',
500 'title' => __('Settings & Integrations', 'fluentform'),
501 'sub_route' => 'form_settings',
502 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=settings&sub_route=form_settings')
503 )
504 ];
505 }
506
507 if (Acl::hasPermission('fluentform_entries_viewer')) {
508 $formAdminMenus['entries'] = [
509 'slug' => 'entries',
510 'hash' => '/',
511 'title' => __('Entries', 'fluentform'),
512 'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=entries')
513 ];
514 }
515
516 $formAdminMenus = apply_filters('fluentform_form_admin_menu', $formAdminMenus, $form_id, $form);
517
518 $route = sanitize_key($_GET['route']);
519
520 View::render('admin.form.form_wrapper', array(
521 'route' => $route,
522 'form_id' => $form_id,
523 'form' => $form,
524 'menu_items' => $formAdminMenus
525 ));
526 }
527
528 public function renderSettings($form_id)
529 {
530 $settingsMenus = array(
531 'form_settings' => array(
532 'title' => __('Form Settings', 'fluentform'),
533 'slug' => 'form_settings',
534 'hash' => 'basic_settings',
535 'route' => '/'
536 ),
537 'email_notifications' => array(
538 'title' => __('Email Notifications', 'fluentform'),
539 'slug' => 'form_settings',
540 'hash' => 'email_notifications',
541 'route' => '/email-settings'
542 ),
543 'other_confirmations' => array(
544 'title' => __('Other Confirmations', 'fluentform'),
545 'slug' => 'form_settings',
546 'hash' => 'other_confirmations',
547 'route' => '/other-confirmations'
548 ),
549 'all_integrations' => array(
550 'title' => __('Marketing & CRM Integrations', 'fluentform'),
551 'slug' => 'form_settings',
552 'route' => '/all-integrations'
553 )
554 );
555
556 if (Helper::isSlackEnabled()) {
557 $settingsMenus['slack'] = array(
558 'title' => __('Slack', 'fluentform'),
559 'slug' => 'form_settings',
560 'hash' => 'slack',
561 'route' => '/slack'
562 );
563 }
564
565 $settingsMenus = apply_filters('fluentform_form_settings_menu', $settingsMenus, $form_id);
566
567 $externalMenuItems = [];
568 foreach ($settingsMenus as $key => $menu) {
569 if (empty($menu['hash'])) {
570 unset($settingsMenus[$key]);
571 $externalMenuItems[$key] = $menu;
572 }
573 }
574
575 $settingsMenus['custom_css_js'] = array(
576 'title' => __('Custom CSS/JS', 'fluentform'),
577 'slug' => 'form_settings',
578 'hash' => 'custom_css_js',
579 'route' => '/custom-css-js'
580 );
581
582 $settingsMenus = array_filter(array_merge($settingsMenus, $externalMenuItems));
583
584 $currentRoute = sanitize_key($this->app->request->get('sub_route', ''));
585
586 View::render('admin.form.settings_wrapper', array(
587 'form_id' => $form_id,
588 'settings_menus' => $settingsMenus,
589 'current_sub_route' => $currentRoute
590 ));
591 }
592
593 /**
594 * Remove the inactive addOn menu items
595 * @param string $addOn
596 * @return boolean
597 */
598 public function filterFormSettingsMenu($settingsMenus, $form_id)
599 {
600 if (array_key_exists('mailchimp_integration', $settingsMenus)) {
601 $option = (array)get_option('_fluentform_mailchimp_details');
602 if (!isset($option['status']) || !$option['status']) {
603 unset($settingsMenus['mailchimp_integration']);
604 }
605 }
606
607 return $settingsMenus;
608 }
609
610 public function renderFormSettings($form_id)
611 {
612 wp_localize_script('fluentform_form_settings', 'FluentFormApp', array(
613 'form_id' => $form_id,
614 'plugin' => $this->app->getSlug(),
615 'hasPro' => defined('FLUENTFORMPRO'),
616 'hasPDF' => defined('FLUENTFORM_PDF_VERSION'),
617 'hasFluentCRM' => defined('FLUENTCRM'),
618 'upgrade_url' => fluentform_upgrade_url(),
619 'ace_path_url' => $this->app->publicUrl('libs/ace'),
620 'is_conversion_form' => Helper::isConversionForm($form_id),
621 'has_fluent_smtp' => defined('FLUENTMAIL'),
622 'fluent_smtp_url' => admin_url('admin.php?page=fluent_forms_smtp'),
623 'form_settings_str' => TranslationString::getSettingsI18n(),
624 'integrationsResource' => [
625 'asset_url' => $this->app->publicUrl('img/integrations.png'),
626 'list_url' => fluentform_integrations_url(),
627 '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')
628 ]
629 ));
630
631 View::render('admin.form.settings', array(
632 'form_id' => $form_id
633 ));
634 }
635
636 public function renderForms()
637 {
638 if (!get_option('_fluentform_installed_version')) {
639 (new Activator())->migrate();
640 }
641
642 $formsCount = wpFluent()->table('fluentform_forms')->count();
643
644 wp_localize_script('fluent_all_forms', 'FluentFormApp', apply_filters('fluent_all_forms_vars', array(
645 'plugin' => $this->app->getSlug(),
646 'formsCount' => $formsCount,
647 'hasPro' => defined('FLUENTFORMPRO'),
648 'upgrade_url' => fluentform_upgrade_url(),
649 'adminUrl' => admin_url('admin.php?page=fluent_forms'),
650 'isDisableAnalytics' => apply_filters('fluentform-disabled_analytics', false)
651 )));
652
653 View::render('admin.all_forms', array());
654 }
655
656 public function renderEditor($form_id)
657 {
658 View::render('admin.form.editor', array(
659 'plugin' => $this->app->getSlug(),
660 'form_id' => $form_id
661 ));
662 }
663
664 public function renderDocs()
665 {
666 echo (new DocumentationModule())->render();
667 }
668
669 public function renderAddOns()
670 {
671 echo (new AddOnModule())->render();
672 }
673
674 private function enqueueEditorAssets()
675 {
676 $formId = intval($_GET['form_id']);
677
678 $form = wpFluent()->table('fluentform_forms')->find($formId);
679
680 do_action('fluentform_loading_editor_assets', $form);
681
682 wp_enqueue_style('fluentform_editor_sass');
683 wp_enqueue_style('fluentform_editor_style');
684
685 $pluginSlug = $this->app->getSlug();
686
687 if (function_exists('wp_enqueue_editor')) {
688 add_filter('user_can_richedit', '__return_true');
689 wp_enqueue_editor();
690 wp_enqueue_media();
691 }
692
693 wp_enqueue_script('fluentform_editor_script');
694
695 $jsonData = $form->form_fields;
696
697 if (!defined('FLUENTFORM_DISABLE_EDITOR_FILED_HOOOK')) {
698 $formFields = $form->form_fields;
699
700 if ($formFields) {
701 $formFields = json_decode($formFields, true);
702
703 foreach ($formFields['fields'] as $index => $formField) {
704 $formField = $formFields['fields'][$index] = apply_filters(
705 'fluentform_editor_init_element_' . $formField['element'], $formField, $form
706 );
707
708 if (!$formFields['fields'][$index]) {
709 unset($formFields['fields'][$index]);
710 continue;
711 }
712
713 if ($formField['element'] == 'container') {
714 $columns = $formField['columns'];
715 foreach ($columns as $columnIndex => $column) {
716 foreach ($column['fields'] as $fieldIndex => $columnField) {
717 $columns[$columnIndex]['fields'][$fieldIndex] = apply_filters(
718 'fluentform_editor_init_element_' . $columnField['element'],
719 $columnField, $form
720 );
721
722 if (!$columns[$columnIndex]['fields'][$fieldIndex]) {
723 unset($columns[$columnIndex]['fields'][$fieldIndex]);
724 }
725 }
726 }
727
728 $formFields['fields'][$index]['columns'] = array_values($columns);
729 }
730 }
731
732 $formFields['fields'] = array_values($formFields['fields']);
733 $formFields = json_encode($formFields, true);
734 }
735
736
737 $form->form_fields = $formFields;
738 }
739
740 $searchTags = $this->app->load(
741 $this->app->appPath('Services/FormBuilder/ElementSearchTags.php')
742 );
743
744 $searchTags = apply_filters( 'fluent_editor_element_search_tags', $searchTags, $form );
745
746 $elementPlacements = apply_filters('fluent_editor_element_settings_placement',
747 $this->app->load( $this->app->appPath('Services/FormBuilder/ElementSettingsPlacement.php') ), $form
748 );
749
750 wp_localize_script('fluentform_editor_script', 'FluentFormApp', apply_filters('fluentform_editor_vars', array(
751 'plugin' => $pluginSlug,
752 'form_id' => $formId,
753 'plugin_public_url' => $this->app->publicUrl(),
754 'preview_url' => Helper::getPreviewUrl($formId),
755 'form' => $form,
756 'hasPro' => defined('FLUENTFORMPRO'),
757 'countries' => $this->app->load(
758 $this->app->appPath('Services/FormBuilder/CountryNames.php')
759 ),
760 'element_customization_settings' => $this->app->load(
761 $this->app->appPath('Services/FormBuilder/ElementCustomization.php')
762 ),
763
764 'validation_rule_settings' => $this->app->load(
765 $this->app->appPath('Services/FormBuilder/ValidationRuleSettings.php')
766 ),
767
768 'form_editor_str' => TranslationString::getEditorI18n(),
769 'element_search_tags' => $searchTags,
770 'element_settings_placement' => $elementPlacements,
771 'all_forms_url' => admin_url('admin.php?page=fluent_forms'),
772 'has_payment_features' => !defined('FLUENTFORMPRO'),
773 'upgrade_url' => fluentform_upgrade_url(),
774 'is_conversion_form' => Helper::isConversionForm($formId),
775 'used_name_attributes' => $this->usedNameAttributes($formId),
776 '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"]}'
777 )));
778 }
779
780 /**
781 * Render global settings page.
782 *
783 * @throws \Exception
784 */
785 public function renderGlobalSettings()
786 {
787 if (function_exists('wp_enqueue_editor')) {
788 add_filter('user_can_richedit', '__return_true');
789 wp_enqueue_editor();
790 wp_enqueue_media();
791 }
792
793 // Fire an event letting others know the current component
794 // that fluentform is rendering for the global settings
795 // page. So that they can hook and load their custom
796 // components on this page dynamically & easily.
797 // N.B. native 'components' will always use
798 // 'settings' as their current component.
799 $currentComponent = apply_filters('fluentform_global_settings_current_component',
800 $this->app->request->get('component', 'settings')
801 );
802
803
804 $currentComponent = sanitize_key($currentComponent);
805
806 $components = apply_filters('fluentform_global_settings_components', []);
807
808 $components['reCAPTCHA'] = [
809 'hash' => 're_captcha',
810 'title' => 'reCAPTCHA',
811 ];
812
813 $components['hCAPTCHA'] = [
814 'hash' => 'h_captcha',
815 'title' => 'hCaptcha',
816 ];
817
818 $components['Turnstile'] = [
819 'hash' => 'turnstile',
820 'title' => 'Turnstile (Beta)',
821 ];
822
823 View::render('admin.settings.index', [
824 'components' => $components,
825 'currentComponent' => $currentComponent
826 ]);
827 }
828
829 public function renderTransfer()
830 {
831 $forms = wpFluent()->table('fluentform_forms')
832 ->orderBy('id', 'desc')
833 ->select(['id', 'title'])
834 ->get();
835
836 wp_localize_script('fluentform-transfer-js', 'FluentFormApp', [
837 'plugin' => $this->app->getSlug(),
838 'forms' => $forms,
839 'upgrade_url' => fluentform_upgrade_url(),
840 'hasPro' => defined('FLUENTFORMPRO'),
841 'transfer_str' => TranslationString::getTransferModuleI18n()
842 ]);
843
844 View::render('admin.transfer.index');
845 }
846
847 public function addPreviewButton($formId)
848 {
849 $previewText = __('Preview & Design', 'fluentform');
850 $previewUrl = Helper::getPreviewUrl($formId);
851 if($isConversational = Helper::isConversionForm($formId)) {
852 $previewText = __('Preview', 'fluentform');
853 }
854
855 echo '<a target="_blank" class="el-button el-button--small" href="' . esc_url($previewUrl) . '">'.esc_attr($previewText).'</a>';
856 }
857
858 public function addCopyShortcodeButton($formId)
859 {
860 $shortcode = '[fluentform id="' . $formId . '"]';
861 if(Helper::isConversionForm($formId)) {
862 $shortcode = '[fluentform type="conversational" id="' . $formId . '"]';
863 }
864 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>';
865 return;
866 }
867
868 public function commonAction()
869 {
870 $fluentFormPages = array(
871 'fluent_forms',
872 'fluent_forms_transfer',
873 'fluent_forms_settings',
874 'fluent_forms_add_ons',
875 'fluent_forms_docs',
876 'fluent_forms_smtp'
877 );
878
879 if (isset($_GET['page']) && in_array($_GET['page'], $fluentFormPages)) {
880 // Let's deregister existing vuejs by other devs
881 // Other devs should not regis
882 add_action('admin_print_scripts', function () {
883 wp_dequeue_script('vuejs');
884 wp_dequeue_script('vue');
885 wp_deregister_script('elementor-admin-app');
886 });
887 }
888 }
889
890 public function renderGlobalMenu()
891 {
892 $showPayment = false;
893 if(defined('FLUENTFORMPRO')) {
894 $showPayment = !get_option('__fluentform_payment_module_settings');
895 if($showPayment) {
896 $formCount = wpFluent()->table('fluentform_forms')
897 ->count();
898 $showPayment = $formCount > 2;
899 }
900 }
901 View::render('admin.global_menu', array(
902 'show_payment' => $showPayment,
903 'show_payment_entries' => apply_filters('fluentform_show_payment_entries', false)
904 ));
905 }
906
907 public function renderPaymentEntries()
908 {
909 do_action('flunetform_render_payment_entries');
910 }
911
912 public function renderSmtpPromo()
913 {
914 wp_enqueue_script('fluentform_admin_notice', fluentformMix('js/admin_notices.js'), array(
915 'jquery'
916 ), FLUENTFORM_VERSION);
917
918 View::render('admin.smtp.index', [
919 'logo' => $this->app->publicUrl('img/fluentsmtp.svg'),
920 'banner_image' => $this->app->publicUrl('img/fluentsmtp-banner.png'),
921 'is_installed' => defined('FLUENTMAIL'),
922 'setup_url' => admin_url('options-general.php?page=fluent-mail#/connections')
923 ]);
924 }
925
926 private function usedNameAttributes($formId)
927 {
928 return wpFluent()->table('fluentform_entry_details')
929 ->select(['field_name'])
930 ->where('form_id', $formId)
931 ->orderBy('submission_id', 'desc')
932 ->groupBy('field_name')
933 ->get();
934 }
935 }
936