PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.6.28
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.6.28
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / importer / class-importer-caldera-forms.php

class-importer-caldera-forms.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.6.28, at includes/importer/class-importer-caldera-forms.php

275 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Import caldera forms
5 *
6 * Class WeForms_Importer_Caldera_Forms
7 */
8 class WeForms_Importer_Caldera_Forms extends WeForms_Importer_Abstract {
9
10 /**
11 * Will store submit button label
12 *
13 * @var string
14 */
15 private $submit_text;
16
17 public function __construct() {
18 $this->id = 'caldera-forms';
19 $this->title = 'Caldera Forms';
20 $this->shortcode = 'caldera_form';
21
22 parent::__construct();
23 }
24
25 /**
26 * See if the plugin exists
27 *
28 * @return bool
29 */
30 public function plugin_exists() {
31 return class_exists( 'Caldera_Forms' );
32 }
33
34 /**
35 * Get all the forms
36 *
37 * @return array
38 */
39 public function get_forms() {
40 $forms = [];
41
42 $items = Caldera_Forms_Forms::get_forms();
43
44 foreach ( $items as $item ) {
45 $forms[] = Caldera_Forms_Forms::get_form( $item );
46 }
47
48 return $forms;
49 }
50
51 /**
52 * Get form name
53 *
54 * @param object $form
55 *
56 * @return string
57 */
58 public function get_form_name( $form ) {
59 return $form['name'];
60 }
61
62 /**
63 * Get the form id
64 *
65 * @param mixed $form
66 *
67 * @return int
68 */
69 protected function get_form_id( $form ) {
70 return $form['ID'];
71 }
72
73 /**
74 * Get the form fields
75 *
76 * @param object $form
77 *
78 * @return array
79 */
80 public function get_form_fields( $form ) {
81 $form_fields = [];
82 $fields = Caldera_Forms_Forms::get_fields( $form );
83
84 foreach ( $fields as $name => $field ) {
85 if ( isset( $field['config']['type_override'] ) && $field['config']['type_override'] ) {
86 $field['type'] = $field['config']['type_override'];
87 }
88
89 switch ( $field['type'] ) {
90 case 'text':
91 case 'email':
92 case 'textarea':
93 case 'date':
94 case 'url':
95 case 'phone_better':
96 case 'paragraph':
97
98 if ( $field['type'] == 'phone_better' ) {
99 $field['type'] = 'text';
100 }
101
102 if ( $field['type'] == 'paragraph' ) {
103 $field['type'] = 'textarea';
104 }
105
106 $form_fields[] = $this->get_form_field( $field['type'], [
107 'required' => isset( $field['required'] ) ? 'yes' : 'no',
108 'label' => $field['label'],
109 'name' => $field['slug'],
110 'css' => $field['config']['custom_class'],
111 ] );
112 break;
113
114 case 'select':
115 case 'radio':
116 case 'checkbox':
117 case 'dropdown':
118
119 if ( $field['type'] == 'dropdown' ) {
120 $field['type'] = 'select';
121 }
122
123 $form_fields[] = $this->get_form_field( $field['type'], [
124 'required' => isset( $field['required'] ) ? 'yes' : 'no',
125 'label' => $field['label'],
126 'name' => $field['slug'],
127 'css' => $field['config']['custom_class'],
128 'options' => $this->get_option( $field['config']['option'] ),
129 ] );
130 break;
131
132 case 'range':
133 case 'number':
134 $form_fields[] = $this->get_form_field( $field['type'], [
135 'required' => isset( $field['required'] ) ? 'yes' : 'no',
136 'label' => $field['label'],
137 'name' => $field['slug'],
138 'css' => $field['config']['custom_class'],
139 'step_text_field' => $field['config']['step'],
140 'min_value_field' => $field['config']['min'],
141 'max_value_field' => $field['config']['max'],
142 ] );
143
144 break;
145
146 case 'star_rating':
147
148 if ( empty( $field['config']['number'] ) ) {
149 $field['config']['number'] = 5;
150 }
151
152 $form_fields[] = $this->get_form_field( 'ratings', [
153 'required' => isset( $field['required'] ) ? 'yes' : 'no',
154 'label' => $field['label'],
155 'name' => $field['slug'],
156 'css' => $field['config']['custom_class'],
157 'options' => array_combine( range( 1, $field['config']['number'] ), range( 1, $field['config']['number'] ) ),
158 ] );
159
160 break;
161
162 case 'advanced_file':
163
164 $form_fields[] = $this->get_form_field( 'file', [
165 'required' => isset( $field['required'] ) ? 'yes' : 'no',
166 'label' => $field['label'],
167 'name' => $field['slug'],
168 'css' => $field['config']['custom_class'],
169 'help' => $field['caption'],
170 ] );
171
172 break;
173
174 case 'button':
175
176 $this->submit_text = $field['label'];
177
178 break;
179
180 }
181 }
182
183 return $form_fields;
184 }
185
186 /**
187 * Get form settings
188 *
189 * @param object $form
190 *
191 * @return array
192 */
193 public function get_form_settings( $form ) {
194 $default = $this->get_default_form_settings();
195 $settings = wp_parse_args( [
196 'message' => $form['success'],
197 ], $default );
198
199 if ( $this->submit_text ) {
200 $settings['submit_text'] = $this->submit_text;
201 }
202
203 return $settings;
204 }
205
206 /**
207 * Format options
208 *
209 * @param object $options
210 *
211 * @return array
212 */
213 public function get_option( $options ) {
214 $_options = [];
215
216 foreach ( $options as $key => $option ) {
217 $label = !empty( $option['label'] ) ? $option['label'] : 'Option - ' . $key;
218 $value = !empty( $option['value'] ) ? $option['value'] : $label;
219
220 $_options[$value] = $label;
221 }
222
223 return $_options;
224 }
225
226 /**
227 * Get form notifications
228 *
229 * @param object $form
230 *
231 * @return array
232 */
233 public function get_form_notifications( $form ) {
234 $notifications = [
235 [
236 'active' => $form['mailer']['on_insert'] ? 'true' : 'false',
237 'name' => 'Admin Notification',
238 'subject' => isset( $form['mailer']['email_subject'] ) ? $form['mailer']['email_subject'] : 'Admin Notification',
239 'to' => isset( $form['mailer']['recipients'] ) ? $form['mailer']['recipients'] : '{admin_email}',
240 'replyTo' => '{field:your-email}',
241 'message' => '{all_fields}',
242 'fromName' => '{site_name}',
243 'fromAddress' => '{admin_email}',
244 'cc' => '',
245 'bcc' => '',
246 ],
247 ];
248
249 // $processors = array();
250 // if(isset($form['processors'])){
251 // $processors = $form['processors'];
252 // }
253 //
254 // foreach ($processors as $key => $processor){
255 // if($processor['type'] == 'auto_responder'){
256 // $config = $processor['config'];
257 // $notifications[] = array(
258 // 'active' => true,
259 // 'name' => 'Admin Notification',
260 // 'subject' => $config['subject'],
261 // 'to' => $config['recipient_email'],
262 // 'replyTo' => '{field:your-email}',
263 // 'message' => '{all_fields}',
264 // 'fromName' => '{site_name}',
265 // 'fromAddress' => '{admin_email}',
266 // 'cc' => '',
267 // 'bcc' => '',
268 // );
269 // }
270 // }
271
272 return $notifications;
273 }
274 }
275