PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.14
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.14
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 / Migrator / Bootstrap.php

Bootstrap.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.14, at app/Services/Migrator/Bootstrap.php

151 lines 4.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\Services\Migrator;
4
5 defined('ABSPATH') or die;
6
7 use FluentForm\App\Services\Migrator\Classes\NinjaFormsMigrator;
8 use FluentForm\App\Services\Migrator\Classes\CalderaMigrator;
9 use FluentForm\App\Services\Migrator\Classes\GravityFormsMigrator;
10 use FluentForm\App\Services\Migrator\Classes\WpFormsMigrator;
11 use FluentForm\App\Services\Migrator\Classes\ContactForm7Migrator;
12 class Bootstrap
13 {
14 protected $importer;
15
16 public function boot()
17 {
18 add_action('wp_ajax_fluentform-migrator-get-migrator-data', [$this, 'getMigratorData']);
19 add_action('wp_ajax_fluentform-migrator-get-forms-by-key', [$this, 'getFormsByKey']);
20 add_action('wp_ajax_fluentform-migrator-import-forms', [$this, 'importForms']);
21 add_action('wp_ajax_fluentform-migrator-import-entries', [$this, 'importEntries']);
22 }
23
24 public function availableMigrations()
25 {
26 $migratorLinks = [];
27
28 if ((new CalderaMigrator())->exist()) {
29 $migratorLinks[] = [
30 'name' => 'Caldera Forms',
31 'key' => 'caldera',
32 ];
33 }
34 if ((new NinjaFormsMigrator())->exist()) {
35 $migratorLinks[] = [
36 'name' => 'Ninja Forms',
37 'key' => 'ninja_forms',
38 ];
39 }
40 if ((new GravityFormsMigrator())->exist()) {
41 $migratorLinks[] = [
42 'name' => 'Gravity Forms',
43 'key' => 'gravityform',
44 ];
45 }
46 if ((new WpFormsMigrator())->exist()) {
47 $migratorLinks[] = [
48 'name' => 'WPForms',
49 'key' => 'wpforms',
50 ];
51 }
52 if ((new ContactForm7Migrator())->exist()) {
53 $migratorLinks[] = [
54 'name' => 'Contact Form 7',
55 'key' => 'contactform7',
56 ];
57 }
58 return $migratorLinks;
59 }
60
61 public function setImporterType()
62 {
63 $formType = sanitize_text_field(wpFluentForm('request')->get('form_type'));
64
65 switch ($formType) {
66 case 'caldera':
67 $this->importer = new CalderaMigrator();
68 break;
69 case 'ninja_forms':
70 $this->importer = new NinjaFormsMigrator();
71 break;
72 case 'gravityform':
73 $this->importer = new GravityFormsMigrator();
74 break;
75 case 'wpforms':
76 $this->importer = new WpFormsMigrator();
77 break;
78 case 'contactform7':
79 $this->importer = new ContactForm7Migrator();
80 break;
81 default:
82 wp_send_json([
83 'message' => __('Unsupported Form Type!', 'fluentform'),
84 'success' => false,
85 ]);
86 }
87 }
88
89 public function getMigratorData()
90 {
91 \FluentForm\App\Modules\Acl\Acl::verify(['fluentform_settings_manager', 'fluentform_forms_manager']);
92
93 wp_send_json([
94 'status' => true,
95 'migrator_data' => $this->availableMigrations(),
96 ], 200);
97 }
98
99 public function importForms()
100 {
101 \FluentForm\App\Modules\Acl\Acl::verify(['fluentform_settings_manager', 'fluentform_forms_manager']);
102
103 $formIds = wpFluentForm('request')->get('form_ids');
104 if (!is_array($formIds)) {
105 $formIds = [];
106 }
107 $formIds = array_map('sanitize_text_field', $formIds);
108
109 $this->setImporterType();
110 $this->importer->import_forms($formIds);
111 }
112
113 public function importEntries()
114 {
115 $fluentFormId = \FluentForm\App\Modules\Acl\Acl::verifyFormId(
116 wpFluentForm('request')->get('imported_fluent_form_id')
117 );
118 \FluentForm\App\Modules\Acl\Acl::verify(
119 ['fluentform_settings_manager', 'fluentform_forms_manager'],
120 $fluentFormId
121 );
122 $importFormId = sanitize_text_field(wpFluentForm('request')->get('source_form_id'));
123 $this->setImporterType();
124 $this->importer->insertEntries($fluentFormId, $importFormId);
125 }
126
127 public function hasOtherForms()
128 {
129 \FluentForm\App\Modules\Acl\Acl::verify(['fluentform_settings_manager', 'fluentform_forms_manager']);
130
131 $migrationData = $this->availableMigrations();
132 if (is_array($migrationData) && !empty($migrationData)) {
133 return true;
134 }
135 return false;
136 }
137
138 public function getFormsByKey()
139 {
140 \FluentForm\App\Modules\Acl\Acl::verify(['fluentform_settings_manager', 'fluentform_forms_manager']);
141
142 $this->setImporterType();
143 $forms = $this->importer->getFormsFormatted();
144
145 wp_send_json([
146 'forms' => $forms,
147 'success' => true,
148 ]);
149 }
150 }
151