Completed
Push — master ( a84b5d...065334 )
by Jamie
03:44
created
classes/helpers/FrmXMLHelper.php 1 patch
Indentation   +596 added lines, -596 removed lines patch added patch discarded remove patch
@@ -23,30 +23,30 @@  discard block
 block discarded – undo
23 23
 	}
24 24
 
25 25
 	public static function import_xml( $file ) {
26
-        $defaults = array(
27
-            'forms' => 0, 'fields' => 0, 'terms' => 0,
28
-            'posts' => 0, 'views' => 0, 'actions' => 0,
29
-            'styles' => 0,
30
-        );
31
-
32
-        $imported = array(
33
-            'imported' => $defaults,
26
+		$defaults = array(
27
+			'forms' => 0, 'fields' => 0, 'terms' => 0,
28
+			'posts' => 0, 'views' => 0, 'actions' => 0,
29
+			'styles' => 0,
30
+		);
31
+
32
+		$imported = array(
33
+			'imported' => $defaults,
34 34
 			'updated'  => $defaults,
35 35
 			'forms'    => array(),
36 36
 			'terms'    => array(),
37
-        );
37
+		);
38 38
 
39
-        unset($defaults);
39
+		unset($defaults);
40 40
 
41 41
 		if ( ! defined( 'WP_IMPORTING' ) ) {
42
-            define('WP_IMPORTING', true);
43
-        }
42
+			define('WP_IMPORTING', true);
43
+		}
44 44
 
45 45
 		if ( ! class_exists( 'DOMDocument' ) ) {
46
-            return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
47
-        }
46
+			return new WP_Error( 'SimpleXML_parse_error', __( 'Your server does not have XML enabled', 'formidable' ), libxml_get_errors() );
47
+		}
48 48
 
49
-        $dom = new DOMDocument;
49
+		$dom = new DOMDocument;
50 50
 		$success = $dom->loadXML( file_get_contents( $file ) );
51 51
 		if ( ! $success ) {
52 52
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
@@ -64,46 +64,46 @@  discard block
 block discarded – undo
64 64
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
65 65
 		}
66 66
 
67
-        // add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
67
+		// add terms, forms (form and field ids), posts (post ids), and entries to db, in that order
68 68
 		foreach ( array( 'term', 'form', 'view' ) as $item_type ) {
69
-            // grab cats, tags, and terms, or forms or posts
70
-            if ( isset($xml->{$item_type} ) ) {
69
+			// grab cats, tags, and terms, or forms or posts
70
+			if ( isset($xml->{$item_type} ) ) {
71 71
 				$function_name = 'import_xml_' . $item_type . 's';
72 72
 				$imported = self::$function_name( $xml->{$item_type}, $imported );
73 73
 				unset( $function_name, $xml->{$item_type} );
74
-            }
75
-        }
74
+			}
75
+		}
76 76
 
77
-	    $return = apply_filters('frm_importing_xml', $imported, $xml );
77
+		$return = apply_filters('frm_importing_xml', $imported, $xml );
78 78
 
79
-	    return $return;
80
-    }
79
+		return $return;
80
+	}
81 81
 
82 82
 	public static function import_xml_terms( $terms, $imported ) {
83
-        foreach ( $terms as $t ) {
83
+		foreach ( $terms as $t ) {
84 84
 			if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
85
-			    continue;
85
+				continue;
86 86
 			}
87 87
 
88 88
 			$parent = self::get_term_parent_id( $t );
89 89
 
90 90
 			$term = wp_insert_term( (string) $t->term_name, (string) $t->term_taxonomy, array(
91
-                'slug'          => (string) $t->term_slug,
92
-                'description'   => (string) $t->term_description,
91
+				'slug'          => (string) $t->term_slug,
92
+				'description'   => (string) $t->term_description,
93 93
 				'parent'        => empty( $parent ) ? 0 : $parent,
94
-                'slug'          => (string) $t->term_slug,
95
-            ));
94
+				'slug'          => (string) $t->term_slug,
95
+			));
96 96
 
97 97
 			if ( $term && is_array( $term ) ) {
98
-                $imported['imported']['terms']++;
98
+				$imported['imported']['terms']++;
99 99
 				$imported['terms'][ (int) $t->term_id ] = $term['term_id'];
100
-            }
100
+			}
101 101
 
102 102
 			unset( $term, $t );
103 103
 		}
104 104
 
105 105
 		return $imported;
106
-    }
106
+	}
107 107
 
108 108
 	/**
109 109
 	 * @since 2.0.8
@@ -128,99 +128,99 @@  discard block
 block discarded – undo
128 128
 		self::put_child_forms_first( $forms );
129 129
 
130 130
 		foreach ( $forms as $item ) {
131
-            $form = array(
132
-                'id'            => (int) $item->id,
133
-                'form_key'      => (string) $item->form_key,
134
-                'name'          => (string) $item->name,
135
-                'description'   => (string) $item->description,
136
-                'options'       => (string) $item->options,
137
-                'logged_in'     => (int) $item->logged_in,
138
-                'is_template'   => (int) $item->is_template,
139
-                'default_template' => (int) $item->default_template,
140
-                'editable'      => (int) $item->editable,
141
-                'status'        => (string) $item->status,
142
-                'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
143
-                'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
144
-            );
145
-
146
-            $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
131
+			$form = array(
132
+				'id'            => (int) $item->id,
133
+				'form_key'      => (string) $item->form_key,
134
+				'name'          => (string) $item->name,
135
+				'description'   => (string) $item->description,
136
+				'options'       => (string) $item->options,
137
+				'logged_in'     => (int) $item->logged_in,
138
+				'is_template'   => (int) $item->is_template,
139
+				'default_template' => (int) $item->default_template,
140
+				'editable'      => (int) $item->editable,
141
+				'status'        => (string) $item->status,
142
+				'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
143
+				'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
144
+			);
145
+
146
+			$form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
147 147
 
148 148
 			self::update_custom_style_setting_on_import( $form );
149 149
 
150
-            // if template, allow to edit if form keys match, otherwise, creation date must also match
150
+			// if template, allow to edit if form keys match, otherwise, creation date must also match
151 151
 			$edit_query = array( 'form_key' => $form['form_key'], 'is_template' => $form['is_template'] );
152
-            if ( ! $form['is_template'] ) {
153
-                $edit_query['created_at'] = $form['created_at'];
154
-            }
152
+			if ( ! $form['is_template'] ) {
153
+				$edit_query['created_at'] = $form['created_at'];
154
+			}
155 155
 
156
-            $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
156
+			$edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
157 157
 
158
-            $this_form = FrmForm::getAll($edit_query, '', 1);
159
-            unset($edit_query);
158
+			$this_form = FrmForm::getAll($edit_query, '', 1);
159
+			unset($edit_query);
160 160
 
161
-            if ( ! empty( $this_form ) ) {
162
-                $old_id = $form_id = $this_form->id;
163
-                FrmForm::update($form_id, $form );
164
-                $imported['updated']['forms']++;
165
-                // Keep track of whether this specific form was updated or not
161
+			if ( ! empty( $this_form ) ) {
162
+				$old_id = $form_id = $this_form->id;
163
+				FrmForm::update($form_id, $form );
164
+				$imported['updated']['forms']++;
165
+				// Keep track of whether this specific form was updated or not
166 166
 				$imported['form_status'][ $form_id ] = 'updated';
167 167
 
168 168
 				$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
169
-                $old_fields = array();
170
-                foreach ( $form_fields as $f ) {
169
+				$old_fields = array();
170
+				foreach ( $form_fields as $f ) {
171 171
 					$old_fields[ $f->id ] = $f;
172 172
 					$old_fields[ $f->field_key ] = $f->id;
173
-                    unset($f);
174
-                }
175
-                $form_fields = $old_fields;
176
-                unset($old_fields);
177
-            } else {
178
-                $old_id = false;
179
-                //form does not exist, so create it
173
+					unset($f);
174
+				}
175
+				$form_fields = $old_fields;
176
+				unset($old_fields);
177
+			} else {
178
+				$old_id = false;
179
+				//form does not exist, so create it
180 180
 				$form_id = FrmForm::create( $form );
181
-                if ( $form_id ) {
182
-                    $imported['imported']['forms']++;
183
-                    // Keep track of whether this specific form was updated or not
181
+				if ( $form_id ) {
182
+					$imported['imported']['forms']++;
183
+					// Keep track of whether this specific form was updated or not
184 184
 					$imported['form_status'][ $form_id ] = 'imported';
185 185
 					self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
186
-                }
187
-            }
186
+				}
187
+			}
188 188
 
189
-    		self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
189
+			self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported );
190 190
 
191
-    		// Delete any fields attached to this form that were not included in the template
192
-    		if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
191
+			// Delete any fields attached to this form that were not included in the template
192
+			if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
193 193
 				foreach ( $form_fields as $field ) {
194
-                    if ( is_object($field) ) {
195
-                        FrmField::destroy($field->id);
196
-                    }
197
-                    unset($field);
198
-                }
199
-                unset($form_fields);
200
-            }
201
-
202
-		    // Update field ids/keys to new ones
194
+					if ( is_object($field) ) {
195
+						FrmField::destroy($field->id);
196
+					}
197
+					unset($field);
198
+				}
199
+				unset($form_fields);
200
+			}
201
+
202
+			// Update field ids/keys to new ones
203 203
 			do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
204 204
 
205 205
 			$imported['forms'][ (int) $item->id ] = $form_id;
206 206
 
207
-            // Send pre 2.0 form options through function that creates actions
208
-            self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
207
+			// Send pre 2.0 form options through function that creates actions
208
+			self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
209 209
 
210
-		    unset($form, $item);
210
+			unset($form, $item);
211 211
 		}
212 212
 
213 213
 		self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
214 214
 
215 215
 		return $imported;
216
-    }
216
+	}
217 217
 
218 218
 	/**
219
-	* Put child forms first so they will be imported before parents
220
-	*
221
-	* @since 2.0.16
222
-	* @param array $forms
223
-	*/
219
+	 * Put child forms first so they will be imported before parents
220
+	 *
221
+	 * @since 2.0.16
222
+	 * @param array $forms
223
+	 */
224 224
 	private static function put_child_forms_first( &$forms ) {
225 225
 		$child_forms = array();
226 226
 		$regular_forms = array();
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 	}
240 240
 
241 241
 	/**
242
-	* Keep track of all imported child forms
243
-	*
244
-	* @since 2.0.16
245
-	* @param int $form_id
246
-	* @param int $parent_form_id
247
-	* @param array $child_forms
248
-	*/
242
+	 * Keep track of all imported child forms
243
+	 *
244
+	 * @since 2.0.16
245
+	 * @param int $form_id
246
+	 * @param int $parent_form_id
247
+	 * @param array $child_forms
248
+	 */
249 249
 	private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
250 250
 		if ( $parent_form_id ) {
251 251
 			$child_forms[ $form_id ] = $parent_form_id;
@@ -253,13 +253,13 @@  discard block
 block discarded – undo
253 253
 	}
254 254
 
255 255
 	/**
256
-	* Update the parent_form_id on imported child forms
257
-	* Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
258
-	*
259
-	* @since 2.0.6
260
-	* @param array $imported_forms
261
-	* @param array $child_forms
262
-	*/
256
+	 * Update the parent_form_id on imported child forms
257
+	 * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported
258
+	 *
259
+	 * @since 2.0.6
260
+	 * @param array $imported_forms
261
+	 * @param array $child_forms
262
+	 */
263 263
 	private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
264 264
 		foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
265 265
 
@@ -273,61 +273,61 @@  discard block
 block discarded – undo
273 273
 	}
274 274
 
275 275
 	/**
276
-	* Import all fields for a form
277
-	* @since 2.0.13
278
-	*
279
-	* TODO: Cut down on params
280
-	*/
276
+	 * Import all fields for a form
277
+	 * @since 2.0.13
278
+	 *
279
+	 * TODO: Cut down on params
280
+	 */
281 281
 	private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) {
282 282
 		foreach ( $xml_fields as $field ) {
283
-		    $f = array(
284
-		        'id'            => (int) $field->id,
285
-		        'field_key'     => (string) $field->field_key,
286
-		        'name'          => (string) $field->name,
287
-		        'description'   => (string) $field->description,
288
-		        'type'          => (string) $field->type,
289
-		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
290
-		        'field_order'   => (int) $field->field_order,
291
-		        'form_id'       => (int) $form_id,
292
-		        'required'      => (int) $field->required,
293
-		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
283
+			$f = array(
284
+				'id'            => (int) $field->id,
285
+				'field_key'     => (string) $field->field_key,
286
+				'name'          => (string) $field->name,
287
+				'description'   => (string) $field->description,
288
+				'type'          => (string) $field->type,
289
+				'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
290
+				'field_order'   => (int) $field->field_order,
291
+				'form_id'       => (int) $form_id,
292
+				'required'      => (int) $field->required,
293
+				'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
294 294
 				'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
295
-		    );
296
-
297
-		    if ( is_array($f['default_value']) && in_array($f['type'], array(
298
-		        'text', 'email', 'url', 'textarea',
299
-		        'number','phone', 'date', 'time',
300
-		        'hidden', 'password', 'tag', 'image',
301
-		    )) ) {
302
-		        if ( count($f['default_value']) === 1 ) {
303
-		            $f['default_value'] = '['. reset($f['default_value']) .']';
304
-		        } else {
305
-		            $f['default_value'] = reset($f['default_value']);
306
-		        }
307
-		    }
308
-
309
-		    $f = apply_filters('frm_duplicated_field', $f);
295
+			);
296
+
297
+			if ( is_array($f['default_value']) && in_array($f['type'], array(
298
+				'text', 'email', 'url', 'textarea',
299
+				'number','phone', 'date', 'time',
300
+				'hidden', 'password', 'tag', 'image',
301
+			)) ) {
302
+				if ( count($f['default_value']) === 1 ) {
303
+					$f['default_value'] = '['. reset($f['default_value']) .']';
304
+				} else {
305
+					$f['default_value'] = reset($f['default_value']);
306
+				}
307
+			}
308
+
309
+			$f = apply_filters('frm_duplicated_field', $f);
310 310
 
311 311
 			self::maybe_update_form_select( $f, $imported );
312 312
 
313
-		    if ( ! empty($this_form) ) {
314
-		        // check for field to edit by field id
313
+			if ( ! empty($this_form) ) {
314
+				// check for field to edit by field id
315 315
 				if ( isset( $form_fields[ $f['id'] ] ) ) {
316
-		            FrmField::update( $f['id'], $f );
317
-		            $imported['updated']['fields']++;
316
+					FrmField::update( $f['id'], $f );
317
+					$imported['updated']['fields']++;
318 318
 
319 319
 					unset( $form_fields[ $f['id'] ] );
320 320
 
321
-		            //unset old field key
321
+					//unset old field key
322 322
 					if ( isset( $form_fields[ $f['field_key'] ] ) ) {
323 323
 						unset( $form_fields[ $f['field_key'] ] );
324 324
 					}
325 325
 				} else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
326
-		            // check for field to edit by field key
327
-		            unset($f['id']);
326
+					// check for field to edit by field key
327
+					unset($f['id']);
328 328
 
329 329
 					FrmField::update( $form_fields[ $f['field_key'] ], $f );
330
-		            $imported['updated']['fields']++;
330
+					$imported['updated']['fields']++;
331 331
 
332 332
 					unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
333 333
 					unset( $form_fields[ $f['field_key'] ] ); //unset old field key
@@ -337,29 +337,29 @@  discard block
 block discarded – undo
337 337
 						continue;
338 338
 					}
339 339
 
340
-		            // if no matching field id or key in this form, create the field
341
-		            $imported['imported']['fields']++;
342
-		        }
340
+					// if no matching field id or key in this form, create the field
341
+					$imported['imported']['fields']++;
342
+				}
343 343
 			} else {
344 344
 				$new_id = FrmField::create( $f );
345 345
 				if ( $new_id == false ) {
346 346
 					continue;
347 347
 				}
348 348
 
349
-	            $imported['imported']['fields']++;
350
-		    }
349
+				$imported['imported']['fields']++;
350
+			}
351 351
 
352 352
 			unset($field, $new_id);
353 353
 		}
354 354
 	}
355 355
 
356 356
 	/**
357
-	* Switch the form_select on a repeating field or embedded form if it needs to be switched
358
-	*
359
-	* @since 2.0.16
360
-	* @param array $f
361
-	* @param array $imported
362
-	*/
357
+	 * Switch the form_select on a repeating field or embedded form if it needs to be switched
358
+	 *
359
+	 * @since 2.0.16
360
+	 * @param array $f
361
+	 * @param array $imported
362
+	 */
363 363
 	private static function maybe_update_form_select( &$f, $imported ) {
364 364
 		if ( ! isset( $imported['forms'] ) ) {
365 365
 			return;
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
 	}
377 377
 
378 378
 	/**
379
-	* Updates the custom style setting on import
380
-	*
381
-	* @since 2.0.19
382
-	* @param array $form
383
-	*
384
-	*/
379
+	 * Updates the custom style setting on import
380
+	 *
381
+	 * @since 2.0.19
382
+	 * @param array $form
383
+	 *
384
+	 */
385 385
 	private static function update_custom_style_setting_on_import( &$form ) {
386 386
 		if ( is_numeric ( $form['options']['custom_style'] ) ) {
387 387
 			// Set to default
@@ -409,16 +409,16 @@  discard block
 block discarded – undo
409 409
 	}
410 410
 
411 411
 	public static function import_xml_views( $views, $imported ) {
412
-        $imported['posts'] = array();
413
-        $form_action_type = FrmFormActionsController::$action_post_type;
412
+		$imported['posts'] = array();
413
+		$form_action_type = FrmFormActionsController::$action_post_type;
414 414
 
415
-        $post_types = array(
416
-            'frm_display' => 'views',
417
-            $form_action_type => 'actions',
418
-            'frm_styles'    => 'styles',
419
-        );
415
+		$post_types = array(
416
+			'frm_display' => 'views',
417
+			$form_action_type => 'actions',
418
+			'frm_styles'    => 'styles',
419
+		);
420 420
 
421
-        foreach ( $views as $item ) {
421
+		foreach ( $views as $item ) {
422 422
 			$post = array(
423 423
 				'post_title'    => (string) $item->title,
424 424
 				'post_name'     => (string) $item->post_name,
@@ -437,52 +437,52 @@  discard block
 block discarded – undo
437 437
 				'post_date'     => (string) $item->post_date,
438 438
 				'post_date_gmt' => (string) $item->post_date_gmt,
439 439
 				'ping_status'   => (string) $item->ping_status,
440
-                'postmeta'      => array(),
441
-                'tax_input'     => array(),
440
+				'postmeta'      => array(),
441
+				'tax_input'     => array(),
442 442
 			);
443 443
 
444
-            $old_id = $post['post_id'];
445
-            self::populate_post($post, $item, $imported);
444
+			$old_id = $post['post_id'];
445
+			self::populate_post($post, $item, $imported);
446 446
 
447 447
 			unset($item);
448 448
 
449 449
 			$post_id = false;
450
-            if ( $post['post_type'] == $form_action_type ) {
451
-                $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
450
+			if ( $post['post_type'] == $form_action_type ) {
451
+				$action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] );
452 452
 				if ( $action_control ) {
453 453
 					$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
454 454
 				}
455
-                unset($action_control);
456
-            } else if ( $post['post_type'] == 'frm_styles' ) {
457
-                // Properly encode post content before inserting the post
458
-                $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
459
-                $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
460
-
461
-                // Create/update post now
462
-                $post_id = wp_insert_post( $post );
463
-            } else {
464
-                // Create/update post now
465
-                $post_id = wp_insert_post( $post );
466
-            }
467
-
468
-            if ( ! is_numeric($post_id) ) {
469
-                continue;
470
-            }
471
-
472
-            self::update_postmeta($post, $post_id);
473
-
474
-            $this_type = 'posts';
455
+				unset($action_control);
456
+			} else if ( $post['post_type'] == 'frm_styles' ) {
457
+				// Properly encode post content before inserting the post
458
+				$post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
459
+				$post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] );
460
+
461
+				// Create/update post now
462
+				$post_id = wp_insert_post( $post );
463
+			} else {
464
+				// Create/update post now
465
+				$post_id = wp_insert_post( $post );
466
+			}
467
+
468
+			if ( ! is_numeric($post_id) ) {
469
+				continue;
470
+			}
471
+
472
+			self::update_postmeta($post, $post_id);
473
+
474
+			$this_type = 'posts';
475 475
 			if ( isset( $post_types[ $post['post_type'] ] ) ) {
476 476
 				$this_type = $post_types[ $post['post_type'] ];
477
-            }
477
+			}
478 478
 
479
-            if ( isset($post['ID']) && $post_id == $post['ID'] ) {
480
-                $imported['updated'][ $this_type ]++;
481
-            } else {
482
-                $imported['imported'][ $this_type ]++;
483
-            }
479
+			if ( isset($post['ID']) && $post_id == $post['ID'] ) {
480
+				$imported['updated'][ $this_type ]++;
481
+			} else {
482
+				$imported['imported'][ $this_type ]++;
483
+			}
484 484
 
485
-            unset($post);
485
+			unset($post);
486 486
 
487 487
 			$imported['posts'][ (int) $old_id ] = $post_id;
488 488
 		}
@@ -490,157 +490,157 @@  discard block
 block discarded – undo
490 490
 		self::maybe_update_stylesheet( $imported );
491 491
 
492 492
 		return $imported;
493
-    }
493
+	}
494 494
 
495
-    private static function populate_post( &$post, $item, $imported ) {
495
+	private static function populate_post( &$post, $item, $imported ) {
496 496
 		if ( isset($item->attachment_url) ) {
497 497
 			$post['attachment_url'] = (string) $item->attachment_url;
498 498
 		}
499 499
 
500 500
 		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
501
-		    // update to new form id
502
-		    $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
501
+			// update to new form id
502
+			$post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
503 503
 		}
504 504
 
505 505
 		foreach ( $item->postmeta as $meta ) {
506
-		    self::populate_postmeta($post, $meta, $imported);
506
+			self::populate_postmeta($post, $meta, $imported);
507 507
 			unset($meta);
508 508
 		}
509 509
 
510
-        self::populate_taxonomies($post, $item);
510
+		self::populate_taxonomies($post, $item);
511 511
 
512
-        self::maybe_editing_post($post);
513
-    }
512
+		self::maybe_editing_post($post);
513
+	}
514 514
 
515
-    private static function populate_postmeta( &$post, $meta, $imported ) {
516
-        global $frm_duplicate_ids;
515
+	private static function populate_postmeta( &$post, $meta, $imported ) {
516
+		global $frm_duplicate_ids;
517 517
 
518
-	    $m = array(
518
+		$m = array(
519 519
 			'key'   => (string) $meta->meta_key,
520 520
 			'value' => (string) $meta->meta_value,
521 521
 		);
522 522
 
523 523
 		//switch old form and field ids to new ones
524 524
 		if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
525
-		    $m['value'] = $imported['forms'][ (int) $m['value'] ];
525
+			$m['value'] = $imported['forms'][ (int) $m['value'] ];
526 526
 		} else {
527
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
527
+			$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
528 528
 
529
-		    if ( ! empty($frm_duplicate_ids) ) {
529
+			if ( ! empty($frm_duplicate_ids) ) {
530 530
 
531
-		        if ( $m['key'] == 'frm_dyncontent' ) {
532
-		            $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
533
-    		    } else if ( $m['key'] == 'frm_options' ) {
531
+				if ( $m['key'] == 'frm_dyncontent' ) {
532
+					$m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
533
+				} else if ( $m['key'] == 'frm_options' ) {
534 534
 
535 535
 					foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
536 536
 						if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
537 537
 							$m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
538
-    		            }
539
-    		        }
540
-
541
-                    $check_dup_array = array();
542
-    		        if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
543
-    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
544
-    		                $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
545
-    		            } else if ( is_array( $m['value']['order_by'] ) ) {
546
-                            $check_dup_array[] = 'order_by';
547
-    		            }
548
-    		        }
549
-
550
-    		        if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
551
-    		            $check_dup_array[] = 'where';
552
-    		        }
553
-
554
-                    foreach ( $check_dup_array as $check_k ) {
538
+						}
539
+					}
540
+
541
+					$check_dup_array = array();
542
+					if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
543
+						if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
544
+							$m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
545
+						} else if ( is_array( $m['value']['order_by'] ) ) {
546
+							$check_dup_array[] = 'order_by';
547
+						}
548
+					}
549
+
550
+					if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) {
551
+						$check_dup_array[] = 'where';
552
+					}
553
+
554
+					foreach ( $check_dup_array as $check_k ) {
555 555
 						foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
556 556
 							if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
557 557
 								$m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
558
-		                    }
559
-		                    unset($mk, $mv);
560
-		                }
561
-                    }
562
-    		    }
563
-		    }
558
+							}
559
+							unset($mk, $mv);
560
+						}
561
+					}
562
+				}
563
+			}
564 564
 		}
565 565
 
566 566
 		if ( ! is_array($m['value']) ) {
567
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
567
+			$m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
568 568
 		}
569 569
 
570 570
 		$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
571
-    }
572
-
573
-    /**
574
-     * Add terms to post
575
-     * @param array $post by reference
576
-     * @param object $item The XML object data
577
-     */
578
-    private static function populate_taxonomies( &$post, $item ) {
571
+	}
572
+
573
+	/**
574
+	 * Add terms to post
575
+	 * @param array $post by reference
576
+	 * @param object $item The XML object data
577
+	 */
578
+	private static function populate_taxonomies( &$post, $item ) {
579 579
 		foreach ( $item->category as $c ) {
580 580
 			$att = $c->attributes();
581 581
 			if ( ! isset( $att['nicename'] ) ) {
582
-                continue;
583
-            }
584
-
585
-		    $taxonomy = (string) $att['domain'];
586
-		    if ( is_taxonomy_hierarchical($taxonomy) ) {
587
-		        $name = (string) $att['nicename'];
588
-		        $h_term = get_term_by('slug', $name, $taxonomy);
589
-		        if ( $h_term ) {
590
-		            $name = $h_term->term_id;
591
-		        }
592
-		        unset($h_term);
593
-		    } else {
594
-		        $name = (string) $c;
595
-		    }
582
+				continue;
583
+			}
584
+
585
+			$taxonomy = (string) $att['domain'];
586
+			if ( is_taxonomy_hierarchical($taxonomy) ) {
587
+				$name = (string) $att['nicename'];
588
+				$h_term = get_term_by('slug', $name, $taxonomy);
589
+				if ( $h_term ) {
590
+					$name = $h_term->term_id;
591
+				}
592
+				unset($h_term);
593
+			} else {
594
+				$name = (string) $c;
595
+			}
596 596
 
597 597
 			if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
598 598
 				$post['tax_input'][ $taxonomy ] = array();
599 599
 			}
600 600
 
601 601
 			$post['tax_input'][ $taxonomy ][] = $name;
602
-		    unset($name);
602
+			unset($name);
603 603
 		}
604
-    }
604
+	}
605 605
 
606
-    /**
607
-     * Edit post if the key and created time match
608
-     */
609
-    private static function maybe_editing_post( &$post ) {
606
+	/**
607
+	 * Edit post if the key and created time match
608
+	 */
609
+	private static function maybe_editing_post( &$post ) {
610 610
 		$match_by = array(
611
-		    'post_type'     => $post['post_type'],
612
-		    'name'          => $post['post_name'],
613
-		    'post_status'   => $post['post_status'],
614
-		    'posts_per_page' => 1,
611
+			'post_type'     => $post['post_type'],
612
+			'name'          => $post['post_name'],
613
+			'post_status'   => $post['post_status'],
614
+			'posts_per_page' => 1,
615 615
 		);
616 616
 
617 617
 		if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
618
-		    $match_by['include'] = $post['post_id'];
619
-		    unset($match_by['name']);
618
+			$match_by['include'] = $post['post_id'];
619
+			unset($match_by['name']);
620 620
 		}
621 621
 
622 622
 		$editing = get_posts($match_by);
623 623
 
624
-        if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
625
-            // set the id of the post to edit
626
-            $post['ID'] = current($editing)->ID;
627
-        }
628
-    }
624
+		if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
625
+			// set the id of the post to edit
626
+			$post['ID'] = current($editing)->ID;
627
+		}
628
+	}
629 629
 
630
-    private static function update_postmeta( &$post, $post_id ) {
631
-        foreach ( $post['postmeta'] as $k => $v ) {
632
-            if ( '_edit_last' == $k ) {
633
-                $v = FrmAppHelper::get_user_id_param($v);
634
-            } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
635
-                //change the attachment ID
636
-                $v = FrmProXMLHelper::get_file_id($v);
637
-            }
630
+	private static function update_postmeta( &$post, $post_id ) {
631
+		foreach ( $post['postmeta'] as $k => $v ) {
632
+			if ( '_edit_last' == $k ) {
633
+				$v = FrmAppHelper::get_user_id_param($v);
634
+			} else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
635
+				//change the attachment ID
636
+				$v = FrmProXMLHelper::get_file_id($v);
637
+			}
638 638
 
639
-            update_post_meta($post_id, $k, $v);
639
+			update_post_meta($post_id, $k, $v);
640 640
 
641
-            unset($k, $v);
642
-        }
643
-    }
641
+			unset($k, $v);
642
+		}
643
+	}
644 644
 
645 645
 	private static function maybe_update_stylesheet( $imported ) {
646 646
 		if ( ( isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ) ) || ( isset( $imported['updated']['styles'] ) && ! empty( $imported['updated']['styles'] ) ) ) {
@@ -651,72 +651,72 @@  discard block
 block discarded – undo
651 651
 		}
652 652
 	}
653 653
 
654
-    /**
655
-     * @param string $message
656
-     */
654
+	/**
655
+	 * @param string $message
656
+	 */
657 657
 	public static function parse_message( $result, &$message, &$errors ) {
658
-        if ( is_wp_error($result) ) {
659
-            $errors[] = $result->get_error_message();
660
-        } else if ( ! $result ) {
661
-            return;
662
-        }
663
-
664
-        if ( ! is_array($result) ) {
665
-            $message = is_string( $result ) ? $result : print_r( $result, 1 );
666
-            return;
667
-        }
668
-
669
-        $t_strings = array(
670
-            'imported'  => __( 'Imported', 'formidable' ),
671
-            'updated'   => __( 'Updated', 'formidable' ),
672
-        );
673
-
674
-        $message = '<ul>';
675
-        foreach ( $result as $type => $results ) {
658
+		if ( is_wp_error($result) ) {
659
+			$errors[] = $result->get_error_message();
660
+		} else if ( ! $result ) {
661
+			return;
662
+		}
663
+
664
+		if ( ! is_array($result) ) {
665
+			$message = is_string( $result ) ? $result : print_r( $result, 1 );
666
+			return;
667
+		}
668
+
669
+		$t_strings = array(
670
+			'imported'  => __( 'Imported', 'formidable' ),
671
+			'updated'   => __( 'Updated', 'formidable' ),
672
+		);
673
+
674
+		$message = '<ul>';
675
+		foreach ( $result as $type => $results ) {
676 676
 			if ( ! isset( $t_strings[ $type ] ) ) {
677
-                // only print imported and updated
678
-                continue;
679
-            }
677
+				// only print imported and updated
678
+				continue;
679
+			}
680 680
 
681
-            $s_message = array();
682
-            foreach ( $results as $k => $m ) {
683
-                self::item_count_message($m, $k, $s_message);
684
-                unset($k, $m);
685
-            }
681
+			$s_message = array();
682
+			foreach ( $results as $k => $m ) {
683
+				self::item_count_message($m, $k, $s_message);
684
+				unset($k, $m);
685
+			}
686 686
 
687
-            if ( ! empty($s_message) ) {
687
+			if ( ! empty($s_message) ) {
688 688
 				$message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
689
-                $message .= implode(', ', $s_message);
690
-                $message .= '</li>';
691
-            }
692
-        }
693
-
694
-        if ( $message == '<ul>' ) {
695
-            $message = '';
696
-            $errors[] = __( 'Nothing was imported or updated', 'formidable' );
697
-        } else {
698
-            $message .= '</ul>';
699
-        }
700
-    }
689
+				$message .= implode(', ', $s_message);
690
+				$message .= '</li>';
691
+			}
692
+		}
693
+
694
+		if ( $message == '<ul>' ) {
695
+			$message = '';
696
+			$errors[] = __( 'Nothing was imported or updated', 'formidable' );
697
+		} else {
698
+			$message .= '</ul>';
699
+		}
700
+	}
701 701
 
702 702
 	public static function item_count_message( $m, $type, &$s_message ) {
703
-        if ( ! $m ) {
704
-            return;
705
-        }
706
-
707
-        $strings = array(
708
-            'forms'     => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
709
-            'fields'    => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
710
-            'items'     => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
711
-            'views'     => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
712
-            'posts'     => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
713
-            'styles'     => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
714
-            'terms'     => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
715
-            'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
716
-        );
703
+		if ( ! $m ) {
704
+			return;
705
+		}
706
+
707
+		$strings = array(
708
+			'forms'     => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ),
709
+			'fields'    => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ),
710
+			'items'     => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ),
711
+			'views'     => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ),
712
+			'posts'     => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ),
713
+			'styles'     => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ),
714
+			'terms'     => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ),
715
+			'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
716
+		);
717 717
 
718 718
 		$s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
719
-    }
719
+	}
720 720
 
721 721
 	/**
722 722
 	 * Prepare the form options for export
@@ -750,16 +750,16 @@  discard block
 block discarded – undo
750 750
 	}
751 751
 
752 752
 	public static function cdata( $str ) {
753
-	    $str = maybe_unserialize($str);
754
-	    if ( is_array($str) ) {
755
-	        $str = json_encode($str);
753
+		$str = maybe_unserialize($str);
754
+		if ( is_array($str) ) {
755
+			$str = json_encode($str);
756 756
 		} else if ( seems_utf8( $str ) == false ) {
757 757
 			$str = utf8_encode( $str );
758 758
 		}
759 759
 
760
-        if ( is_numeric($str) ) {
761
-            return $str;
762
-        }
760
+		if ( is_numeric($str) ) {
761
+			return $str;
762
+		}
763 763
 
764 764
 		// $str = ent2ncr(esc_html($str));
765 765
 		$str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
@@ -767,58 +767,58 @@  discard block
 block discarded – undo
767 767
 		return $str;
768 768
 	}
769 769
 
770
-    public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
771
-        // Get post type
772
-        $post_type = FrmFormActionsController::$action_post_type;
773
-
774
-        // Set up imported index, if not set up yet
775
-        if ( ! isset( $imported['imported']['actions'] ) ) {
776
-            $imported['imported']['actions'] = 0;
777
-        }
778
-
779
-        // Migrate post settings to action
780
-        self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
781
-
782
-        // Migrate email settings to action
783
-        self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
784
-    }
785
-
786
-    /**
787
-    * Migrate post settings to form action
788
-    *
789
-    * @param string $post_type
790
-    */
791
-    private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
792
-        if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
793
-            return;
794
-        }
795
-
796
-        $new_action = array(
797
-            'post_type'     => $post_type,
798
-            'post_excerpt'  => 'wppost',
770
+	public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) {
771
+		// Get post type
772
+		$post_type = FrmFormActionsController::$action_post_type;
773
+
774
+		// Set up imported index, if not set up yet
775
+		if ( ! isset( $imported['imported']['actions'] ) ) {
776
+			$imported['imported']['actions'] = 0;
777
+		}
778
+
779
+		// Migrate post settings to action
780
+		self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
781
+
782
+		// Migrate email settings to action
783
+		self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch );
784
+	}
785
+
786
+	/**
787
+	 * Migrate post settings to form action
788
+	 *
789
+	 * @param string $post_type
790
+	 */
791
+	private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
792
+		if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
793
+			return;
794
+		}
795
+
796
+		$new_action = array(
797
+			'post_type'     => $post_type,
798
+			'post_excerpt'  => 'wppost',
799 799
 			'post_title'    => __( 'Create Posts', 'formidable' ),
800
-            'menu_order'    => $form_id,
801
-            'post_status'   => 'publish',
802
-            'post_content'  => array(),
803
-            'post_name'     => $form_id .'_wppost_1',
804
-        );
805
-
806
-        $post_settings = array(
807
-            'post_type', 'post_category', 'post_content',
808
-            'post_excerpt', 'post_title', 'post_name', 'post_date',
800
+			'menu_order'    => $form_id,
801
+			'post_status'   => 'publish',
802
+			'post_content'  => array(),
803
+			'post_name'     => $form_id .'_wppost_1',
804
+		);
805
+
806
+		$post_settings = array(
807
+			'post_type', 'post_category', 'post_content',
808
+			'post_excerpt', 'post_title', 'post_name', 'post_date',
809 809
 			'post_status', 'post_custom_fields', 'post_password',
810
-        );
810
+		);
811 811
 
812
-        foreach ( $post_settings as $post_setting ) {
812
+		foreach ( $post_settings as $post_setting ) {
813 813
 			if ( isset( $form_options[ $post_setting ] ) ) {
814 814
 				$new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
815
-            }
816
-            unset($post_setting);
817
-        }
815
+			}
816
+			unset($post_setting);
817
+		}
818 818
 
819 819
 		$new_action['event'] = array( 'create', 'update' );
820 820
 
821
-        if ( $switch ) {
821
+		if ( $switch ) {
822 822
 			// Fields with string or int saved
823 823
 			$basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' );
824 824
 
@@ -826,22 +826,22 @@  discard block
 block discarded – undo
826 826
 			$array_fields = array( 'post_category', 'post_custom_fields' );
827 827
 
828 828
 			$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
829
-        }
830
-        $new_action['post_content'] = json_encode($new_action['post_content']);
829
+		}
830
+		$new_action['post_content'] = json_encode($new_action['post_content']);
831 831
 
832
-        $exists = get_posts( array(
833
-            'name'          => $new_action['post_name'],
834
-            'post_type'     => $new_action['post_type'],
835
-            'post_status'   => $new_action['post_status'],
836
-            'numberposts'   => 1,
837
-        ) );
832
+		$exists = get_posts( array(
833
+			'name'          => $new_action['post_name'],
834
+			'post_type'     => $new_action['post_type'],
835
+			'post_status'   => $new_action['post_status'],
836
+			'numberposts'   => 1,
837
+		) );
838 838
 
839
-        if ( ! $exists ) {
839
+		if ( ! $exists ) {
840 840
 			// this isn't an email, but we need to use a class that will always be included
841 841
 			FrmAppHelper::save_json_post( $new_action );
842
-            $imported['imported']['actions']++;
843
-        }
844
-    }
842
+			$imported['imported']['actions']++;
843
+		}
844
+	}
845 845
 
846 846
 	/**
847 847
 	 * Switch old field IDs for new field IDs in emails and post
@@ -854,211 +854,211 @@  discard block
 block discarded – undo
854 854
 	 * @return string $post_content - new field IDs
855 855
 	 */
856 856
 	private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) {
857
-        global $frm_duplicate_ids;
857
+		global $frm_duplicate_ids;
858 858
 
859
-        // If there aren't IDs that were switched, end now
860
-        if ( ! $frm_duplicate_ids ) {
861
-            return;
862
-        }
859
+		// If there aren't IDs that were switched, end now
860
+		if ( ! $frm_duplicate_ids ) {
861
+			return;
862
+		}
863 863
 
864
-        // Get old IDs
865
-        $old = array_keys( $frm_duplicate_ids );
864
+		// Get old IDs
865
+		$old = array_keys( $frm_duplicate_ids );
866 866
 
867
-        // Get new IDs
868
-        $new = array_values( $frm_duplicate_ids );
867
+		// Get new IDs
868
+		$new = array_values( $frm_duplicate_ids );
869 869
 
870
-        // Do a str_replace with each item to set the new IDs
871
-        foreach ( $post_content as $key => $setting ) {
872
-            if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
873
-                // Replace old IDs with new IDs
870
+		// Do a str_replace with each item to set the new IDs
871
+		foreach ( $post_content as $key => $setting ) {
872
+			if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
873
+				// Replace old IDs with new IDs
874 874
 				$post_content[ $key ] = str_replace( $old, $new, $setting );
875
-            } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
876
-                foreach ( $setting as $k => $val ) {
877
-                    // Replace old IDs with new IDs
875
+			} else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
876
+				foreach ( $setting as $k => $val ) {
877
+					// Replace old IDs with new IDs
878 878
 					$post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
879
-                }
880
-            }
881
-            unset( $key, $setting );
882
-        }
883
-        return $post_content;
884
-    }
885
-
886
-    private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
887
-        // No old notifications or autoresponders to carry over
879
+				}
880
+			}
881
+			unset( $key, $setting );
882
+		}
883
+		return $post_content;
884
+	}
885
+
886
+	private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
887
+		// No old notifications or autoresponders to carry over
888 888
 		if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) {
889
-            return;
890
-        }
889
+			return;
890
+		}
891 891
 
892
-        // Initialize notifications array
893
-        $notifications = array();
892
+		// Initialize notifications array
893
+		$notifications = array();
894 894
 
895
-        // Migrate regular notifications
896
-        self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
895
+		// Migrate regular notifications
896
+		self::migrate_notifications_to_action( $form_options, $form_id, $notifications );
897 897
 
898
-        // Migrate autoresponders
899
-        self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
898
+		// Migrate autoresponders
899
+		self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
900 900
 
901
-        if (  empty( $notifications ) ) {
902
-            return;
903
-        }
901
+		if (  empty( $notifications ) ) {
902
+			return;
903
+		}
904 904
 
905
-        foreach ( $notifications as $new_notification ) {
906
-            $new_notification['post_type']      = $post_type;
907
-            $new_notification['post_excerpt']   = 'email';
905
+		foreach ( $notifications as $new_notification ) {
906
+			$new_notification['post_type']      = $post_type;
907
+			$new_notification['post_excerpt']   = 'email';
908 908
 			$new_notification['post_title']     = __( 'Email Notification', 'formidable' );
909
-            $new_notification['menu_order']     = $form_id;
910
-            $new_notification['post_status']    = 'publish';
909
+			$new_notification['menu_order']     = $form_id;
910
+			$new_notification['post_status']    = 'publish';
911 911
 
912
-            // Switch field IDs and keys, if needed
913
-            if ( $switch ) {
912
+			// Switch field IDs and keys, if needed
913
+			if ( $switch ) {
914 914
 
915 915
 				// Switch field IDs in email conditional logic
916 916
 				self::switch_email_contition_field_ids( $new_notification['post_content'] );
917 917
 
918 918
 				// Switch all other field IDs in email
919
-                $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
920
-            }
921
-            $new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
922
-
923
-            $exists = get_posts( array(
924
-                'name'          => $new_notification['post_name'],
925
-                'post_type'     => $new_notification['post_type'],
926
-                'post_status'   => $new_notification['post_status'],
927
-                'numberposts'   => 1,
928
-            ) );
929
-
930
-            if ( empty($exists) ) {
919
+				$new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
920
+			}
921
+			$new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
922
+
923
+			$exists = get_posts( array(
924
+				'name'          => $new_notification['post_name'],
925
+				'post_type'     => $new_notification['post_type'],
926
+				'post_status'   => $new_notification['post_status'],
927
+				'numberposts'   => 1,
928
+			) );
929
+
930
+			if ( empty($exists) ) {
931 931
 				FrmAppHelper::save_json_post( $new_notification );
932
-                $imported['imported']['actions']++;
933
-            }
934
-            unset($new_notification);
935
-        }
936
-    }
937
-
938
-    private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
939
-        if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
940
-            // add old settings into notification array
932
+				$imported['imported']['actions']++;
933
+			}
934
+			unset($new_notification);
935
+		}
936
+	}
937
+
938
+	private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) {
939
+		if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) {
940
+			// add old settings into notification array
941 941
 			$form_options['notification'] = array( 0 => $form_options );
942
-        } else if ( isset( $form_options['notification']['email_to'] ) ) {
943
-            // make sure it's in the correct format
942
+		} else if ( isset( $form_options['notification']['email_to'] ) ) {
943
+			// make sure it's in the correct format
944 944
 			$form_options['notification'] = array( 0 => $form_options['notification'] );
945
-        }
945
+		}
946 946
 
947
-        if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
948
-            foreach ( $form_options['notification'] as $email_key => $notification ) {
947
+		if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
948
+			foreach ( $form_options['notification'] as $email_key => $notification ) {
949 949
 
950
-                $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
950
+				$atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
951 951
 
952
-                // Format the email data
953
-                self::format_email_data( $atts, $notification );
952
+				// Format the email data
953
+				self::format_email_data( $atts, $notification );
954 954
 
955 955
 				if ( isset( $notification['twilio'] ) && $notification['twilio'] ) {
956 956
 					do_action( 'frm_create_twilio_action', $atts, $notification );
957 957
 				}
958 958
 
959
-                // Setup the new notification
960
-                $new_notification = array();
961
-                self::setup_new_notification( $new_notification, $notification, $atts );
959
+				// Setup the new notification
960
+				$new_notification = array();
961
+				self::setup_new_notification( $new_notification, $notification, $atts );
962 962
 
963
-                $notifications[] = $new_notification;
964
-            }
965
-        }
966
-    }
963
+				$notifications[] = $new_notification;
964
+			}
965
+		}
966
+	}
967 967
 
968
-    private static function format_email_data( &$atts, $notification ) {
969
-        // Format email_to
970
-        self::format_email_to_data( $atts, $notification );
968
+	private static function format_email_data( &$atts, $notification ) {
969
+		// Format email_to
970
+		self::format_email_to_data( $atts, $notification );
971 971
 
972
-        // Format the reply to email and name
973
-        $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
974
-        foreach ( $reply_fields as $f => $val ) {
972
+		// Format the reply to email and name
973
+		$reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
974
+		foreach ( $reply_fields as $f => $val ) {
975 975
 			if ( isset( $notification[ $f ] ) ) {
976 976
 				$atts[ $f ] = $notification[ $f ];
977 977
 				if ( 'custom' == $notification[ $f ] ) {
978 978
 					$atts[ $f ] = $notification[ 'cust_' . $f ];
979 979
 				} else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
980 980
 					$atts[ $f ] = '[' . $atts[ $f ] . ']';
981
-                }
982
-            }
983
-            unset( $f, $val );
984
-        }
981
+				}
982
+			}
983
+			unset( $f, $val );
984
+		}
985 985
 
986
-        // Format event
986
+		// Format event
987 987
 		$atts['event'] = array( 'create' );
988
-        if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
989
-            $atts['event'][] = 'update';
990
-        } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
988
+		if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
989
+			$atts['event'][] = 'update';
990
+		} else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
991 991
 			$atts['event'] = array( 'update' );
992
-        }
993
-    }
992
+		}
993
+	}
994 994
 
995
-    private static function format_email_to_data( &$atts, $notification ) {
996
-        if ( isset( $notification['email_to'] ) ) {
995
+	private static function format_email_to_data( &$atts, $notification ) {
996
+		if ( isset( $notification['email_to'] ) ) {
997 997
 			$atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] );
998
-        } else {
999
-            $atts['email_to'] = array();
1000
-        }
998
+		} else {
999
+			$atts['email_to'] = array();
1000
+		}
1001 1001
 
1002
-        if ( isset( $notification['also_email_to'] ) ) {
1003
-            $email_fields = (array) $notification['also_email_to'];
1004
-            $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1005
-            unset( $email_fields );
1006
-        }
1002
+		if ( isset( $notification['also_email_to'] ) ) {
1003
+			$email_fields = (array) $notification['also_email_to'];
1004
+			$atts['email_to'] = array_merge( $email_fields, $atts['email_to'] );
1005
+			unset( $email_fields );
1006
+		}
1007 1007
 
1008
-        foreach ( $atts['email_to'] as $key => $email_field ) {
1008
+		foreach ( $atts['email_to'] as $key => $email_field ) {
1009 1009
 
1010
-            if ( is_numeric( $email_field ) ) {
1010
+			if ( is_numeric( $email_field ) ) {
1011 1011
 				$atts['email_to'][ $key ] = '[' . $email_field . ']';
1012
-            }
1012
+			}
1013 1013
 
1014
-            if ( strpos( $email_field, '|') ) {
1015
-                $email_opt = explode( '|', $email_field );
1016
-                if ( isset( $email_opt[0] ) ) {
1014
+			if ( strpos( $email_field, '|') ) {
1015
+				$email_opt = explode( '|', $email_field );
1016
+				if ( isset( $email_opt[0] ) ) {
1017 1017
 					$atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1018
-                }
1019
-                unset( $email_opt );
1020
-            }
1021
-        }
1022
-        $atts['email_to'] = implode(', ', $atts['email_to']);
1023
-    }
1024
-
1025
-    private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1026
-        // Set up new notification
1027
-        $new_notification = array(
1028
-            'post_content'  => array(
1029
-                'email_to'      => $atts['email_to'],
1030
-                'event'         => $atts['event'],
1031
-            ),
1032
-            'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
1033
-        );
1034
-
1035
-        // Add more fields to the new notification
1036
-        $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1037
-        foreach ( $add_fields as $add_field ) {
1018
+				}
1019
+				unset( $email_opt );
1020
+			}
1021
+		}
1022
+		$atts['email_to'] = implode(', ', $atts['email_to']);
1023
+	}
1024
+
1025
+	private static function setup_new_notification( &$new_notification, $notification, $atts ) {
1026
+		// Set up new notification
1027
+		$new_notification = array(
1028
+			'post_content'  => array(
1029
+				'email_to'      => $atts['email_to'],
1030
+				'event'         => $atts['event'],
1031
+			),
1032
+			'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
1033
+		);
1034
+
1035
+		// Add more fields to the new notification
1036
+		$add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1037
+		foreach ( $add_fields as $add_field ) {
1038 1038
 			if ( isset( $notification[ $add_field ] ) ) {
1039 1039
 				$new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1040
-            } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1040
+			} else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1041 1041
 				$new_notification['post_content'][ $add_field ] = 0;
1042
-            } else {
1042
+			} else {
1043 1043
 				$new_notification['post_content'][ $add_field ] = '';
1044
-            }
1045
-            unset( $add_field );
1046
-        }
1044
+			}
1045
+			unset( $add_field );
1046
+		}
1047 1047
 
1048 1048
 		// Set reply to
1049 1049
 		$new_notification['post_content']['reply_to'] = $atts['reply_to'];
1050 1050
 
1051
-        // Set from
1051
+		// Set from
1052 1052
 		if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
1053
-            $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
1054
-        }
1055
-    }
1053
+			$new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
1054
+		}
1055
+	}
1056 1056
 
1057 1057
 	/**
1058
-	* Switch field IDs in pre-2.0 email conditional logic
1059
-	*
1060
-	* @param $post_content array, pass by reference
1061
-	*/
1058
+	 * Switch field IDs in pre-2.0 email conditional logic
1059
+	 *
1060
+	 * @param $post_content array, pass by reference
1061
+	 */
1062 1062
 	private static function switch_email_contition_field_ids( &$post_content ) {
1063 1063
 		// Switch field IDs in conditional logic
1064 1064
 		if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
@@ -1071,48 +1071,48 @@  discard block
 block discarded – undo
1071 1071
 		}
1072 1072
 	}
1073 1073
 
1074
-    private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1075
-        if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1076
-            // migrate autoresponder
1077
-
1078
-            $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1079
-            if ( strpos($email_field, '|') ) {
1080
-                // data from entries field
1081
-                $email_field = explode('|', $email_field);
1082
-                if ( isset($email_field[1]) ) {
1083
-                    $email_field = $email_field[1];
1084
-                }
1085
-            }
1086
-            if ( is_numeric($email_field) && ! empty($email_field) ) {
1087
-                $email_field = '['. $email_field .']';
1088
-            }
1089
-
1090
-            $notification = $form_options;
1091
-            $new_notification2 = array(
1092
-                'post_content'  => array(
1093
-                    'email_message' => $notification['ar_email_message'],
1094
-                    'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1095
-                    'email_to'      => $email_field,
1096
-                    'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1097
-                    'inc_user_info' => 0,
1098
-                ),
1099
-                'post_name'     => $form_id .'_email_'. count( $notifications ),
1100
-            );
1101
-
1102
-            $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1103
-            $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1074
+	private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1075
+		if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1076
+			// migrate autoresponder
1077
+
1078
+			$email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1079
+			if ( strpos($email_field, '|') ) {
1080
+				// data from entries field
1081
+				$email_field = explode('|', $email_field);
1082
+				if ( isset($email_field[1]) ) {
1083
+					$email_field = $email_field[1];
1084
+				}
1085
+			}
1086
+			if ( is_numeric($email_field) && ! empty($email_field) ) {
1087
+				$email_field = '['. $email_field .']';
1088
+			}
1089
+
1090
+			$notification = $form_options;
1091
+			$new_notification2 = array(
1092
+				'post_content'  => array(
1093
+					'email_message' => $notification['ar_email_message'],
1094
+					'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1095
+					'email_to'      => $email_field,
1096
+					'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1097
+					'inc_user_info' => 0,
1098
+				),
1099
+				'post_name'     => $form_id .'_email_'. count( $notifications ),
1100
+			);
1101
+
1102
+			$reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1103
+			$reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1104 1104
 
1105 1105
 			if ( ! empty( $reply_to ) ) {
1106 1106
 				$new_notification2['post_content']['reply_to'] = $reply_to;
1107 1107
 			}
1108 1108
 
1109 1109
 			if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
1110
-                $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1110
+				$new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1111 1111
 			}
1112 1112
 
1113
-            $notifications[] = $new_notification2;
1114
-            unset( $new_notification2 );
1115
-        }
1116
-    }
1113
+			$notifications[] = $new_notification2;
1114
+			unset( $new_notification2 );
1115
+		}
1116
+	}
1117 1117
 }
1118 1118
 
Please login to merge, or discard this patch.