Completed
Push — master ( bf7f9b...642895 )
by Jamie
03:40
created
classes/helpers/FrmXMLHelper.php 1 patch
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined('ABSPATH') ) {
2
+if ( ! defined( 'ABSPATH' ) ) {
3 3
 	die( 'You are not allowed to call this page directly.' );
4 4
 }
5 5
 
@@ -36,10 +36,10 @@  discard block
 block discarded – undo
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);
42
+            define( 'WP_IMPORTING', true );
43 43
         }
44 44
 
45 45
 		if ( ! class_exists( 'DOMDocument' ) ) {
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 			return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this XML file', 'formidable' ), libxml_get_errors() );
53 53
 		}
54 54
 
55
-		if ( ! function_exists('simplexml_import_dom') ) {
55
+		if ( ! function_exists( 'simplexml_import_dom' ) ) {
56 56
 			return new WP_Error( 'SimpleXML_parse_error', __( 'Your server is missing the simplexml_import_dom function', 'formidable' ), libxml_get_errors() );
57 57
 		}
58 58
 
@@ -67,21 +67,21 @@  discard block
 block discarded – undo
67 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 69
             // grab cats, tags, and terms, or forms or posts
70
-            if ( isset($xml->{$item_type} ) ) {
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 74
             }
75 75
         }
76 76
 
77
-	    $return = apply_filters('frm_importing_xml', $imported, $xml );
77
+	    $return = apply_filters( 'frm_importing_xml', $imported, $xml );
78 78
 
79 79
 	    return $return;
80 80
     }
81 81
 
82 82
 	public static function import_xml_terms( $terms, $imported ) {
83 83
         foreach ( $terms as $t ) {
84
-			if ( term_exists((string) $t->term_slug, (string) $t->term_taxonomy) ) {
84
+			if ( term_exists( (string) $t->term_slug, (string) $t->term_taxonomy ) ) {
85 85
 			    continue;
86 86
 			}
87 87
 
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
                 'slug'          => (string) $t->term_slug,
92 92
                 'description'   => (string) $t->term_description,
93 93
 				'parent'        => empty( $parent ) ? 0 : $parent,
94
-            ));
94
+            ) );
95 95
 
96 96
 			if ( $term && is_array( $term ) ) {
97
-                $imported['imported']['terms']++;
98
-				$imported['terms'][ (int) $t->term_id ] = $term['term_id'];
97
+                $imported['imported']['terms'] ++;
98
+				$imported['terms'][(int) $t->term_id] = $term['term_id'];
99 99
             }
100 100
 
101 101
 			unset( $term, $t );
@@ -138,11 +138,11 @@  discard block
 block discarded – undo
138 138
                 'default_template' => (int) $item->default_template,
139 139
                 'editable'      => (int) $item->editable,
140 140
                 'status'        => (string) $item->status,
141
-                'parent_form_id' => isset($item->parent_form_id) ? (int) $item->parent_form_id : 0,
142
-                'created_at'    => date('Y-m-d H:i:s', strtotime((string) $item->created_at)),
141
+                'parent_form_id' => isset( $item->parent_form_id ) ? (int) $item->parent_form_id : 0,
142
+                'created_at'    => date( 'Y-m-d H:i:s', strtotime( (string) $item->created_at ) ),
143 143
             );
144 144
 
145
-            $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
145
+            $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
146 146
 
147 147
 			self::update_custom_style_setting_on_import( $form );
148 148
 
@@ -152,35 +152,35 @@  discard block
 block discarded – undo
152 152
                 $edit_query['created_at'] = $form['created_at'];
153 153
             }
154 154
 
155
-            $edit_query = apply_filters('frm_match_xml_form', $edit_query, $form);
155
+            $edit_query = apply_filters( 'frm_match_xml_form', $edit_query, $form );
156 156
 
157
-            $this_form = FrmForm::getAll($edit_query, '', 1);
158
-            unset($edit_query);
157
+            $this_form = FrmForm::getAll( $edit_query, '', 1 );
158
+            unset( $edit_query );
159 159
 
160 160
             if ( ! empty( $this_form ) ) {
161 161
                 $old_id = $form_id = $this_form->id;
162
-                FrmForm::update($form_id, $form );
163
-                $imported['updated']['forms']++;
162
+                FrmForm::update( $form_id, $form );
163
+                $imported['updated']['forms'] ++;
164 164
                 // Keep track of whether this specific form was updated or not
165
-				$imported['form_status'][ $form_id ] = 'updated';
165
+				$imported['form_status'][$form_id] = 'updated';
166 166
 
167 167
 				$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
168 168
                 $old_fields = array();
169 169
                 foreach ( $form_fields as $f ) {
170
-					$old_fields[ $f->id ] = $f;
171
-					$old_fields[ $f->field_key ] = $f->id;
172
-                    unset($f);
170
+					$old_fields[$f->id] = $f;
171
+					$old_fields[$f->field_key] = $f->id;
172
+                    unset( $f );
173 173
                 }
174 174
                 $form_fields = $old_fields;
175
-                unset($old_fields);
175
+                unset( $old_fields );
176 176
             } else {
177 177
                 $old_id = false;
178 178
                 //form does not exist, so create it
179 179
 				$form_id = FrmForm::create( $form );
180 180
                 if ( $form_id ) {
181
-                    $imported['imported']['forms']++;
181
+                    $imported['imported']['forms'] ++;
182 182
                     // Keep track of whether this specific form was updated or not
183
-					$imported['form_status'][ $form_id ] = 'imported';
183
+					$imported['form_status'][$form_id] = 'imported';
184 184
 					self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
185 185
                 }
186 186
             }
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
     		// Delete any fields attached to this form that were not included in the template
191 191
     		if ( isset( $form_fields ) && ! empty( $form_fields ) ) {
192 192
 				foreach ( $form_fields as $field ) {
193
-                    if ( is_object($field) ) {
194
-                        FrmField::destroy($field->id);
193
+                    if ( is_object( $field ) ) {
194
+                        FrmField::destroy( $field->id );
195 195
                     }
196
-                    unset($field);
196
+                    unset( $field );
197 197
                 }
198
-                unset($form_fields);
198
+                unset( $form_fields );
199 199
             }
200 200
 
201 201
 		    // Update field ids/keys to new ones
202 202
 			do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) );
203 203
 
204
-			$imported['forms'][ (int) $item->id ] = $form_id;
204
+			$imported['forms'][(int) $item->id] = $form_id;
205 205
 
206 206
             // Send pre 2.0 form options through function that creates actions
207 207
             self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true );
208 208
 
209
-		    unset($form, $item);
209
+		    unset( $form, $item );
210 210
 		}
211 211
 
212 212
 		self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms );
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 		$regular_forms = array();
226 226
 
227 227
 		foreach ( $forms as $form ) {
228
-			$parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0;
228
+			$parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0;
229 229
 
230 230
 			if ( $parent_form_id ) {
231 231
 				$child_forms[] = $form;
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 	*/
248 248
 	private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
249 249
 		if ( $parent_form_id ) {
250
-			$child_forms[ $form_id ] = $parent_form_id;
250
+			$child_forms[$form_id] = $parent_form_id;
251 251
 		}
252 252
 	}
253 253
 
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 	private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) {
263 263
 		foreach ( $child_forms as $child_form_id => $old_parent_form_id ) {
264 264
 
265
-			if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) {
265
+			if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) {
266 266
 				// Update all children with this old parent_form_id
267
-				$new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ];
267
+				$new_parent_form_id = (int) $imported_forms[$old_parent_form_id];
268 268
 
269 269
 				FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) );
270 270
 			}
@@ -287,23 +287,23 @@  discard block
 block discarded – undo
287 287
 		        'name'          => (string) $field->name,
288 288
 		        'description'   => (string) $field->description,
289 289
 		        'type'          => (string) $field->type,
290
-		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
290
+		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ),
291 291
 		        'field_order'   => (int) $field->field_order,
292 292
 		        'form_id'       => (int) $form_id,
293 293
 		        'required'      => (int) $field->required,
294
-		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
294
+		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options ),
295 295
 				'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
296 296
 		    );
297 297
 
298
-		    if ( is_array($f['default_value']) && in_array($f['type'], array(
298
+		    if ( is_array( $f['default_value'] ) && in_array( $f['type'], array(
299 299
 		        'text', 'email', 'url', 'textarea',
300
-		        'number','phone', 'date', 'time',
300
+		        'number', 'phone', 'date', 'time',
301 301
 		        'hidden', 'password', 'tag', 'image',
302
-		    )) ) {
303
-		        if ( count($f['default_value']) === 1 ) {
302
+		    ) ) ) {
303
+		        if ( count( $f['default_value'] ) === 1 ) {
304 304
 					$f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
305 305
 		        } else {
306
-		            $f['default_value'] = reset($f['default_value']);
306
+		            $f['default_value'] = reset( $f['default_value'] );
307 307
 		        }
308 308
 		    }
309 309
 
@@ -311,27 +311,27 @@  discard block
 block discarded – undo
311 311
 			self::maybe_update_form_select( $f, $imported );
312 312
 			self::maybe_update_get_values_form_setting( $imported, $f );
313 313
 
314
-			if ( ! empty($this_form) ) {
314
+			if ( ! empty( $this_form ) ) {
315 315
 				// check for field to edit by field id
316
-				if ( isset( $form_fields[ $f['id'] ] ) ) {
316
+				if ( isset( $form_fields[$f['id']] ) ) {
317 317
 					FrmField::update( $f['id'], $f );
318
-					$imported['updated']['fields']++;
318
+					$imported['updated']['fields'] ++;
319 319
 
320
-					unset( $form_fields[ $f['id'] ] );
320
+					unset( $form_fields[$f['id']] );
321 321
 
322 322
 					//unset old field key
323
-					if ( isset( $form_fields[ $f['field_key'] ] ) ) {
324
-						unset( $form_fields[ $f['field_key'] ] );
323
+					if ( isset( $form_fields[$f['field_key']] ) ) {
324
+						unset( $form_fields[$f['field_key']] );
325 325
 					}
326
-				} else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
326
+				} else if ( isset( $form_fields[$f['field_key']] ) ) {
327 327
 					// check for field to edit by field key
328
-					unset($f['id']);
328
+					unset( $f['id'] );
329 329
 
330
-					FrmField::update( $form_fields[ $f['field_key'] ], $f );
331
-					$imported['updated']['fields']++;
330
+					FrmField::update( $form_fields[$f['field_key']], $f );
331
+					$imported['updated']['fields'] ++;
332 332
 
333
-					unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
334
-					unset( $form_fields[ $f['field_key'] ] ); //unset old field key
333
+					unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id
334
+					unset( $form_fields[$f['field_key']] ); //unset old field key
335 335
 				} else {
336 336
 					// if no matching field id or key in this form, create the field
337 337
 					self::create_imported_field( $f, $imported );
@@ -382,8 +382,8 @@  discard block
 block discarded – undo
382 382
 		if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
383 383
 			if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
384 384
 				$form_select = $f['field_options']['form_select'];
385
-				if ( isset( $imported['forms'][ $form_select ] ) ) {
386
-					$f['field_options']['form_select'] = $imported['forms'][ $form_select ];
385
+				if ( isset( $imported['forms'][$form_select] ) ) {
386
+					$f['field_options']['form_select'] = $imported['forms'][$form_select];
387 387
 				}
388 388
 			}
389 389
 		}
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
 
404 404
 		if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) {
405 405
 			$old_form = $f['field_options']['get_values_form'];
406
-			if ( isset( $imported['forms'][ $old_form ] ) ) {
407
-				$f['field_options']['get_values_form'] = $imported['forms'][ $old_form ];
406
+			if ( isset( $imported['forms'][$old_form] ) ) {
407
+				$f['field_options']['get_values_form'] = $imported['forms'][$old_form];
408 408
 			}
409 409
 		}
410 410
 	}
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
 	private static function create_imported_field( $f, &$imported ) {
420 420
 		$new_id = FrmField::create( $f );
421 421
 		if ( $new_id != false ) {
422
-			$imported['imported']['fields']++;
422
+			$imported['imported']['fields'] ++;
423 423
 			do_action( 'frm_after_field_is_imported', $f, $new_id );
424 424
 		}
425 425
 	}
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
 				'post_id'       => (int) $item->post_id,
482 482
 				'post_parent'   => (int) $item->post_parent,
483 483
 				'menu_order'    => (int) $item->menu_order,
484
-				'post_content'  => FrmFieldsHelper::switch_field_ids((string) $item->content),
485
-				'post_excerpt'  => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
484
+				'post_content'  => FrmFieldsHelper::switch_field_ids( (string) $item->content ),
485
+				'post_excerpt'  => FrmFieldsHelper::switch_field_ids( (string) $item->excerpt ),
486 486
 				'is_sticky'     => (string) $item->is_sticky,
487 487
 				'comment_status' => (string) $item->comment_status,
488 488
 				'post_date'     => (string) $item->post_date,
@@ -493,9 +493,9 @@  discard block
 block discarded – undo
493 493
 			);
494 494
 
495 495
             $old_id = $post['post_id'];
496
-            self::populate_post($post, $item, $imported);
496
+            self::populate_post( $post, $item, $imported );
497 497
 
498
-			unset($item);
498
+			unset( $item );
499 499
 
500 500
 			$post_id = false;
501 501
             if ( $post['post_type'] == $form_action_type ) {
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 				if ( $action_control && is_object( $action_control ) ) {
504 504
 					$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
505 505
 				}
506
-                unset($action_control);
506
+                unset( $action_control );
507 507
             } else if ( $post['post_type'] == 'frm_styles' ) {
508 508
                 // Properly encode post content before inserting the post
509 509
                 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
@@ -516,26 +516,26 @@  discard block
 block discarded – undo
516 516
                 $post_id = wp_insert_post( $post );
517 517
             }
518 518
 
519
-            if ( ! is_numeric($post_id) ) {
519
+            if ( ! is_numeric( $post_id ) ) {
520 520
                 continue;
521 521
             }
522 522
 
523
-            self::update_postmeta($post, $post_id);
523
+            self::update_postmeta( $post, $post_id );
524 524
 
525 525
             $this_type = 'posts';
526
-			if ( isset( $post_types[ $post['post_type'] ] ) ) {
527
-				$this_type = $post_types[ $post['post_type'] ];
526
+			if ( isset( $post_types[$post['post_type']] ) ) {
527
+				$this_type = $post_types[$post['post_type']];
528 528
             }
529 529
 
530
-            if ( isset($post['ID']) && $post_id == $post['ID'] ) {
531
-                $imported['updated'][ $this_type ]++;
530
+            if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
531
+                $imported['updated'][$this_type] ++;
532 532
             } else {
533
-                $imported['imported'][ $this_type ]++;
533
+                $imported['imported'][$this_type] ++;
534 534
             }
535 535
 
536
-            unset($post);
536
+            unset( $post );
537 537
 
538
-			$imported['posts'][ (int) $old_id ] = $post_id;
538
+			$imported['posts'][(int) $old_id] = $post_id;
539 539
 		}
540 540
 
541 541
 		self::maybe_update_stylesheet( $imported );
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
     }
545 545
 
546 546
     private static function populate_post( &$post, $item, $imported ) {
547
-		if ( isset($item->attachment_url) ) {
547
+		if ( isset( $item->attachment_url ) ) {
548 548
 			$post['attachment_url'] = (string) $item->attachment_url;
549 549
 		}
550 550
 
551
-		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
551
+		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) {
552 552
 		    // update to new form id
553
-		    $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
553
+		    $post['menu_order'] = $imported['forms'][(int) $post['menu_order']];
554 554
 		}
555 555
 
556 556
 		foreach ( $item->postmeta as $meta ) {
557
-		    self::populate_postmeta($post, $meta, $imported);
558
-			unset($meta);
557
+		    self::populate_postmeta( $post, $meta, $imported );
558
+			unset( $meta );
559 559
 		}
560 560
 
561
-        self::populate_taxonomies($post, $item);
561
+        self::populate_taxonomies( $post, $item );
562 562
 
563
-        self::maybe_editing_post($post);
563
+        self::maybe_editing_post( $post );
564 564
     }
565 565
 
566 566
     private static function populate_postmeta( &$post, $meta, $imported ) {
@@ -572,27 +572,27 @@  discard block
 block discarded – undo
572 572
 		);
573 573
 
574 574
 		//switch old form and field ids to new ones
575
-		if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
576
-		    $m['value'] = $imported['forms'][ (int) $m['value'] ];
575
+		if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) {
576
+		    $m['value'] = $imported['forms'][(int) $m['value']];
577 577
 		} else {
578
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
578
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
579 579
 
580
-		    if ( ! empty($frm_duplicate_ids) ) {
580
+		    if ( ! empty( $frm_duplicate_ids ) ) {
581 581
 
582 582
 		        if ( $m['key'] == 'frm_dyncontent' ) {
583
-		            $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
583
+		            $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
584 584
     		    } else if ( $m['key'] == 'frm_options' ) {
585 585
 
586 586
 					foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
587
-						if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
588
-							$m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
587
+						if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) {
588
+							$m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
589 589
     		            }
590 590
     		        }
591 591
 
592 592
                     $check_dup_array = array();
593 593
     		        if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
594
-    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
595
-    		                $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
594
+    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) {
595
+    		                $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']];
596 596
     		            } else if ( is_array( $m['value']['order_by'] ) ) {
597 597
                             $check_dup_array[] = 'order_by';
598 598
     		            }
@@ -603,22 +603,22 @@  discard block
 block discarded – undo
603 603
     		        }
604 604
 
605 605
                     foreach ( $check_dup_array as $check_k ) {
606
-						foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
607
-							if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
608
-								$m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
606
+						foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
607
+							if ( isset( $frm_duplicate_ids[$mv] ) ) {
608
+								$m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
609 609
 		                    }
610
-		                    unset($mk, $mv);
610
+		                    unset( $mk, $mv );
611 611
 		                }
612 612
                     }
613 613
     		    }
614 614
 		    }
615 615
 		}
616 616
 
617
-		if ( ! is_array($m['value']) ) {
618
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
617
+		if ( ! is_array( $m['value'] ) ) {
618
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
619 619
 		}
620 620
 
621
-		$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
621
+		$post['postmeta'][(string) $meta->meta_key] = $m['value'];
622 622
     }
623 623
 
624 624
     /**
@@ -634,23 +634,23 @@  discard block
 block discarded – undo
634 634
             }
635 635
 
636 636
 		    $taxonomy = (string) $att['domain'];
637
-		    if ( is_taxonomy_hierarchical($taxonomy) ) {
637
+		    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
638 638
 		        $name = (string) $att['nicename'];
639
-		        $h_term = get_term_by('slug', $name, $taxonomy);
639
+		        $h_term = get_term_by( 'slug', $name, $taxonomy );
640 640
 		        if ( $h_term ) {
641 641
 		            $name = $h_term->term_id;
642 642
 		        }
643
-		        unset($h_term);
643
+		        unset( $h_term );
644 644
 		    } else {
645 645
 		        $name = (string) $c;
646 646
 		    }
647 647
 
648
-			if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
649
-				$post['tax_input'][ $taxonomy ] = array();
648
+			if ( ! isset( $post['tax_input'][$taxonomy] ) ) {
649
+				$post['tax_input'][$taxonomy] = array();
650 650
 			}
651 651
 
652
-			$post['tax_input'][ $taxonomy ][] = $name;
653
-		    unset($name);
652
+			$post['tax_input'][$taxonomy][] = $name;
653
+		    unset( $name );
654 654
 		}
655 655
     }
656 656
 
@@ -667,29 +667,29 @@  discard block
 block discarded – undo
667 667
 
668 668
 		if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
669 669
 		    $match_by['include'] = $post['post_id'];
670
-		    unset($match_by['name']);
670
+		    unset( $match_by['name'] );
671 671
 		}
672 672
 
673
-		$editing = get_posts($match_by);
673
+		$editing = get_posts( $match_by );
674 674
 
675
-        if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
675
+        if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) {
676 676
             // set the id of the post to edit
677
-            $post['ID'] = current($editing)->ID;
677
+            $post['ID'] = current( $editing )->ID;
678 678
         }
679 679
     }
680 680
 
681 681
     private static function update_postmeta( &$post, $post_id ) {
682 682
         foreach ( $post['postmeta'] as $k => $v ) {
683 683
             if ( '_edit_last' == $k ) {
684
-                $v = FrmAppHelper::get_user_id_param($v);
684
+                $v = FrmAppHelper::get_user_id_param( $v );
685 685
             } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
686 686
                 //change the attachment ID
687
-                $v = FrmProXMLHelper::get_file_id($v);
687
+                $v = FrmProXMLHelper::get_file_id( $v );
688 688
             }
689 689
 
690
-            update_post_meta($post_id, $k, $v);
690
+            update_post_meta( $post_id, $k, $v );
691 691
 
692
-            unset($k, $v);
692
+            unset( $k, $v );
693 693
         }
694 694
     }
695 695
 
@@ -706,13 +706,13 @@  discard block
 block discarded – undo
706 706
      * @param string $message
707 707
      */
708 708
 	public static function parse_message( $result, &$message, &$errors ) {
709
-        if ( is_wp_error($result) ) {
709
+        if ( is_wp_error( $result ) ) {
710 710
             $errors[] = $result->get_error_message();
711 711
         } else if ( ! $result ) {
712 712
             return;
713 713
         }
714 714
 
715
-        if ( ! is_array($result) ) {
715
+        if ( ! is_array( $result ) ) {
716 716
             $message = is_string( $result ) ? $result : print_r( $result, 1 );
717 717
             return;
718 718
         }
@@ -724,20 +724,20 @@  discard block
 block discarded – undo
724 724
 
725 725
         $message = '<ul>';
726 726
         foreach ( $result as $type => $results ) {
727
-			if ( ! isset( $t_strings[ $type ] ) ) {
727
+			if ( ! isset( $t_strings[$type] ) ) {
728 728
                 // only print imported and updated
729 729
                 continue;
730 730
             }
731 731
 
732 732
             $s_message = array();
733 733
             foreach ( $results as $k => $m ) {
734
-                self::item_count_message($m, $k, $s_message);
735
-                unset($k, $m);
734
+                self::item_count_message( $m, $k, $s_message );
735
+                unset( $k, $m );
736 736
             }
737 737
 
738
-            if ( ! empty($s_message) ) {
739
-				$message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
740
-                $message .= implode(', ', $s_message);
738
+            if ( ! empty( $s_message ) ) {
739
+				$message .= '<li><strong>' . $t_strings[$type] . ':</strong> ';
740
+                $message .= implode( ', ', $s_message );
741 741
                 $message .= '</li>';
742 742
             }
743 743
         }
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
             'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
767 767
         );
768 768
 
769
-		$s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
769
+		$s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type );
770 770
     }
771 771
 
772 772
 	/**
@@ -798,14 +798,14 @@  discard block
 block discarded – undo
798 798
 	}
799 799
 
800 800
 	public static function cdata( $str ) {
801
-	    $str = maybe_unserialize($str);
802
-	    if ( is_array($str) ) {
803
-	        $str = json_encode($str);
801
+	    $str = maybe_unserialize( $str );
802
+	    if ( is_array( $str ) ) {
803
+	        $str = json_encode( $str );
804 804
 		} else if ( seems_utf8( $str ) == false ) {
805 805
 			$str = utf8_encode( $str );
806 806
 		}
807 807
 
808
-        if ( is_numeric($str) ) {
808
+        if ( is_numeric( $str ) ) {
809 809
             return $str;
810 810
         }
811 811
 
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
     * @param string $post_type
851 851
     */
852 852
     private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
853
-        if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
853
+        if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
854 854
             return;
855 855
         }
856 856
 
@@ -871,10 +871,10 @@  discard block
 block discarded – undo
871 871
         );
872 872
 
873 873
         foreach ( $post_settings as $post_setting ) {
874
-			if ( isset( $form_options[ $post_setting ] ) ) {
875
-				$new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
874
+			if ( isset( $form_options[$post_setting] ) ) {
875
+				$new_action['post_content'][$post_setting] = $form_options[$post_setting];
876 876
             }
877
-            unset($post_setting);
877
+            unset( $post_setting );
878 878
         }
879 879
 
880 880
 		$new_action['event'] = array( 'create', 'update' );
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
 
889 889
 			$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
890 890
         }
891
-        $new_action['post_content'] = json_encode($new_action['post_content']);
891
+        $new_action['post_content'] = json_encode( $new_action['post_content'] );
892 892
 
893 893
         $exists = get_posts( array(
894 894
             'name'          => $new_action['post_name'],
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
         if ( ! $exists ) {
901 901
 			// this isn't an email, but we need to use a class that will always be included
902 902
 			FrmAppHelper::save_json_post( $new_action );
903
-            $imported['imported']['actions']++;
903
+            $imported['imported']['actions'] ++;
904 904
         }
905 905
     }
906 906
 
@@ -932,11 +932,11 @@  discard block
 block discarded – undo
932 932
         foreach ( $post_content as $key => $setting ) {
933 933
             if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
934 934
                 // Replace old IDs with new IDs
935
-				$post_content[ $key ] = str_replace( $old, $new, $setting );
935
+				$post_content[$key] = str_replace( $old, $new, $setting );
936 936
             } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
937 937
                 foreach ( $setting as $k => $val ) {
938 938
                     // Replace old IDs with new IDs
939
-					$post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
939
+					$post_content[$key][$k] = str_replace( $old, $new, $val );
940 940
                 }
941 941
             }
942 942
             unset( $key, $setting );
@@ -959,14 +959,14 @@  discard block
 block discarded – undo
959 959
         // Migrate autoresponders
960 960
         self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
961 961
 
962
-        if (  empty( $notifications ) ) {
962
+        if ( empty( $notifications ) ) {
963 963
             return;
964 964
         }
965 965
 
966 966
         foreach ( $notifications as $new_notification ) {
967 967
             $new_notification['post_type']      = $post_type;
968 968
             $new_notification['post_excerpt']   = 'email';
969
-			$new_notification['post_title']     = __( 'Email Notification', 'formidable' );
969
+			$new_notification['post_title'] = __( 'Email Notification', 'formidable' );
970 970
             $new_notification['menu_order']     = $form_id;
971 971
             $new_notification['post_status']    = 'publish';
972 972
 
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
 				// Switch all other field IDs in email
980 980
                 $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
981 981
             }
982
-            $new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
982
+            $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
983 983
 
984 984
             $exists = get_posts( array(
985 985
                 'name'          => $new_notification['post_name'],
@@ -988,11 +988,11 @@  discard block
 block discarded – undo
988 988
                 'numberposts'   => 1,
989 989
             ) );
990 990
 
991
-            if ( empty($exists) ) {
991
+            if ( empty( $exists ) ) {
992 992
 				FrmAppHelper::save_json_post( $new_notification );
993
-                $imported['imported']['actions']++;
993
+                $imported['imported']['actions'] ++;
994 994
             }
995
-            unset($new_notification);
995
+            unset( $new_notification );
996 996
         }
997 997
     }
998 998
 
@@ -1005,7 +1005,7 @@  discard block
 block discarded – undo
1005 1005
 			$form_options['notification'] = array( 0 => $form_options['notification'] );
1006 1006
         }
1007 1007
 
1008
-        if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
1008
+        if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
1009 1009
             foreach ( $form_options['notification'] as $email_key => $notification ) {
1010 1010
 
1011 1011
                 $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
@@ -1033,12 +1033,12 @@  discard block
 block discarded – undo
1033 1033
         // Format the reply to email and name
1034 1034
         $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
1035 1035
         foreach ( $reply_fields as $f => $val ) {
1036
-			if ( isset( $notification[ $f ] ) ) {
1037
-				$atts[ $f ] = $notification[ $f ];
1038
-				if ( 'custom' == $notification[ $f ] ) {
1039
-					$atts[ $f ] = $notification[ 'cust_' . $f ];
1040
-				} else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
1041
-					$atts[ $f ] = '[' . $atts[ $f ] . ']';
1036
+			if ( isset( $notification[$f] ) ) {
1037
+				$atts[$f] = $notification[$f];
1038
+				if ( 'custom' == $notification[$f] ) {
1039
+					$atts[$f] = $notification['cust_' . $f];
1040
+				} else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) {
1041
+					$atts[$f] = '[' . $atts[$f] . ']';
1042 1042
                 }
1043 1043
             }
1044 1044
             unset( $f, $val );
@@ -1048,7 +1048,7 @@  discard block
 block discarded – undo
1048 1048
 		$atts['event'] = array( 'create' );
1049 1049
         if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
1050 1050
             $atts['event'][] = 'update';
1051
-        } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
1051
+        } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
1052 1052
 			$atts['event'] = array( 'update' );
1053 1053
         }
1054 1054
     }
@@ -1069,18 +1069,18 @@  discard block
 block discarded – undo
1069 1069
         foreach ( $atts['email_to'] as $key => $email_field ) {
1070 1070
 
1071 1071
             if ( is_numeric( $email_field ) ) {
1072
-				$atts['email_to'][ $key ] = '[' . $email_field . ']';
1072
+				$atts['email_to'][$key] = '[' . $email_field . ']';
1073 1073
             }
1074 1074
 
1075
-            if ( strpos( $email_field, '|') ) {
1075
+            if ( strpos( $email_field, '|' ) ) {
1076 1076
                 $email_opt = explode( '|', $email_field );
1077 1077
                 if ( isset( $email_opt[0] ) ) {
1078
-					$atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1078
+					$atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1079 1079
                 }
1080 1080
                 unset( $email_opt );
1081 1081
             }
1082 1082
         }
1083
-        $atts['email_to'] = implode(', ', $atts['email_to']);
1083
+        $atts['email_to'] = implode( ', ', $atts['email_to'] );
1084 1084
     }
1085 1085
 
1086 1086
     private static function setup_new_notification( &$new_notification, $notification, $atts ) {
@@ -1096,12 +1096,12 @@  discard block
 block discarded – undo
1096 1096
         // Add more fields to the new notification
1097 1097
         $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1098 1098
         foreach ( $add_fields as $add_field ) {
1099
-			if ( isset( $notification[ $add_field ] ) ) {
1100
-				$new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1099
+			if ( isset( $notification[$add_field] ) ) {
1100
+				$new_notification['post_content'][$add_field] = $notification[$add_field];
1101 1101
             } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1102
-				$new_notification['post_content'][ $add_field ] = 0;
1102
+				$new_notification['post_content'][$add_field] = 0;
1103 1103
             } else {
1104
-				$new_notification['post_content'][ $add_field ] = '';
1104
+				$new_notification['post_content'][$add_field] = '';
1105 1105
             }
1106 1106
             unset( $add_field );
1107 1107
         }
@@ -1125,26 +1125,26 @@  discard block
 block discarded – undo
1125 1125
 		if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
1126 1126
 			foreach ( $post_content['conditions'] as $email_key => $val ) {
1127 1127
 				if ( is_numeric( $email_key ) ) {
1128
-					$post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1128
+					$post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1129 1129
 				}
1130
-				unset( $email_key, $val);
1130
+				unset( $email_key, $val );
1131 1131
 			}
1132 1132
 		}
1133 1133
 	}
1134 1134
 
1135 1135
     private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1136
-        if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1136
+        if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1137 1137
             // migrate autoresponder
1138 1138
 
1139
-            $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1140
-            if ( strpos($email_field, '|') ) {
1139
+            $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
1140
+            if ( strpos( $email_field, '|' ) ) {
1141 1141
                 // data from entries field
1142
-                $email_field = explode('|', $email_field);
1143
-                if ( isset($email_field[1]) ) {
1142
+                $email_field = explode( '|', $email_field );
1143
+                if ( isset( $email_field[1] ) ) {
1144 1144
                     $email_field = $email_field[1];
1145 1145
                 }
1146 1146
             }
1147
-            if ( is_numeric($email_field) && ! empty($email_field) ) {
1147
+            if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
1148 1148
 				$email_field = '[' . $email_field . ']';
1149 1149
             }
1150 1150
 
@@ -1152,16 +1152,16 @@  discard block
 block discarded – undo
1152 1152
             $new_notification2 = array(
1153 1153
                 'post_content'  => array(
1154 1154
                     'email_message' => $notification['ar_email_message'],
1155
-                    'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1155
+                    'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1156 1156
                     'email_to'      => $email_field,
1157
-                    'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1157
+                    'plain_text'    => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1158 1158
                     'inc_user_info' => 0,
1159 1159
                 ),
1160 1160
 				'post_name'     => $form_id . '_email_' . count( $notifications ),
1161 1161
             );
1162 1162
 
1163
-            $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1164
-            $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1163
+            $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1164
+            $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
1165 1165
 
1166 1166
 			if ( ! empty( $reply_to ) ) {
1167 1167
 				$new_notification2['post_content']['reply_to'] = $reply_to;
Please login to merge, or discard this patch.