Completed
Push — master ( 065334...ead3be )
by Jamie
03:33
created
classes/helpers/FrmXMLHelper.php 1 patch
Spacing   +177 added lines, -177 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
 
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 				echo "\n" . $padding;
12 12
 				$tag = ( is_numeric( $ok ) ? 'key:' : '' ) . $ok;
13 13
 				echo '<' . $tag . '>';
14
-				self::get_xml_values( $ov, $padding .'    ' );
14
+				self::get_xml_values( $ov, $padding . '    ' );
15 15
 				if ( is_array( $ov ) ) {
16 16
 					echo "\n" . $padding;
17 17
 				}
@@ -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
 
@@ -92,11 +92,11 @@  discard block
 block discarded – undo
92 92
                 'description'   => (string) $t->term_description,
93 93
 				'parent'        => empty( $parent ) ? 0 : $parent,
94 94
                 'slug'          => (string) $t->term_slug,
95
-            ));
95
+            ) );
96 96
 
97 97
 			if ( $term && is_array( $term ) ) {
98
-                $imported['imported']['terms']++;
99
-				$imported['terms'][ (int) $t->term_id ] = $term['term_id'];
98
+                $imported['imported']['terms'] ++;
99
+				$imported['terms'][(int) $t->term_id] = $term['term_id'];
100 100
             }
101 101
 
102 102
 			unset( $term, $t );
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
                 'default_template' => (int) $item->default_template,
140 140
                 'editable'      => (int) $item->editable,
141 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)),
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 144
             );
145 145
 
146
-            $form['options'] = FrmAppHelper::maybe_json_decode($form['options']);
146
+            $form['options'] = FrmAppHelper::maybe_json_decode( $form['options'] );
147 147
 
148 148
 			self::update_custom_style_setting_on_import( $form );
149 149
 
@@ -153,35 +153,35 @@  discard block
 block discarded – undo
153 153
                 $edit_query['created_at'] = $form['created_at'];
154 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 161
             if ( ! empty( $this_form ) ) {
162 162
                 $old_id = $form_id = $this_form->id;
163
-                FrmForm::update($form_id, $form );
164
-                $imported['updated']['forms']++;
163
+                FrmForm::update( $form_id, $form );
164
+                $imported['updated']['forms'] ++;
165 165
                 // Keep track of whether this specific form was updated or not
166
-				$imported['form_status'][ $form_id ] = 'updated';
166
+				$imported['form_status'][$form_id] = 'updated';
167 167
 
168 168
 				$form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' );
169 169
                 $old_fields = array();
170 170
                 foreach ( $form_fields as $f ) {
171
-					$old_fields[ $f->id ] = $f;
172
-					$old_fields[ $f->field_key ] = $f->id;
173
-                    unset($f);
171
+					$old_fields[$f->id] = $f;
172
+					$old_fields[$f->field_key] = $f->id;
173
+                    unset( $f );
174 174
                 }
175 175
                 $form_fields = $old_fields;
176
-                unset($old_fields);
176
+                unset( $old_fields );
177 177
             } else {
178 178
                 $old_id = false;
179 179
                 //form does not exist, so create it
180 180
 				$form_id = FrmForm::create( $form );
181 181
                 if ( $form_id ) {
182
-                    $imported['imported']['forms']++;
182
+                    $imported['imported']['forms'] ++;
183 183
                     // Keep track of whether this specific form was updated or not
184
-					$imported['form_status'][ $form_id ] = 'imported';
184
+					$imported['form_status'][$form_id] = 'imported';
185 185
 					self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms );
186 186
                 }
187 187
             }
@@ -191,23 +191,23 @@  discard block
 block discarded – undo
191 191
     		// Delete any fields attached to this form that were not included in the template
192 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);
194
+                    if ( is_object( $field ) ) {
195
+                        FrmField::destroy( $field->id );
196 196
                     }
197
-                    unset($field);
197
+                    unset( $field );
198 198
                 }
199
-                unset($form_fields);
199
+                unset( $form_fields );
200 200
             }
201 201
 
202 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
-			$imported['forms'][ (int) $item->id ] = $form_id;
205
+			$imported['forms'][(int) $item->id] = $form_id;
206 206
 
207 207
             // Send pre 2.0 form options through function that creates actions
208 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 );
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		$regular_forms = array();
227 227
 
228 228
 		foreach ( $forms as $form ) {
229
-			$parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0;
229
+			$parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0;
230 230
 
231 231
 			if ( $parent_form_id ) {
232 232
 				$child_forms[] = $form;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 	*/
249 249
 	private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) {
250 250
 		if ( $parent_form_id ) {
251
-			$child_forms[ $form_id ] = $parent_form_id;
251
+			$child_forms[$form_id] = $parent_form_id;
252 252
 		}
253 253
 	}
254 254
 
@@ -263,9 +263,9 @@  discard block
 block discarded – undo
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
 
266
-			if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) {
266
+			if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) {
267 267
 				// Update all children with this old parent_form_id
268
-				$new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ];
268
+				$new_parent_form_id = (int) $imported_forms[$old_parent_form_id];
269 269
 
270 270
 				FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) );
271 271
 			}
@@ -286,51 +286,51 @@  discard block
 block discarded – undo
286 286
 		        'name'          => (string) $field->name,
287 287
 		        'description'   => (string) $field->description,
288 288
 		        'type'          => (string) $field->type,
289
-		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value),
289
+		        'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ),
290 290
 		        'field_order'   => (int) $field->field_order,
291 291
 		        'form_id'       => (int) $form_id,
292 292
 		        'required'      => (int) $field->required,
293
-		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options),
293
+		        'options'       => FrmAppHelper::maybe_json_decode( (string) $field->options ),
294 294
 				'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ),
295 295
 		    );
296 296
 
297
-		    if ( is_array($f['default_value']) && in_array($f['type'], array(
297
+		    if ( is_array( $f['default_value'] ) && in_array( $f['type'], array(
298 298
 		        'text', 'email', 'url', 'textarea',
299
-		        'number','phone', 'date', 'time',
299
+		        'number', 'phone', 'date', 'time',
300 300
 		        'hidden', 'password', 'tag', 'image',
301
-		    )) ) {
302
-		        if ( count($f['default_value']) === 1 ) {
303
-		            $f['default_value'] = '['. reset($f['default_value']) .']';
301
+		    ) ) ) {
302
+		        if ( count( $f['default_value'] ) === 1 ) {
303
+		            $f['default_value'] = '[' . reset( $f['default_value'] ) . ']';
304 304
 		        } else {
305
-		            $f['default_value'] = reset($f['default_value']);
305
+		            $f['default_value'] = reset( $f['default_value'] );
306 306
 		        }
307 307
 		    }
308 308
 
309
-		    $f = apply_filters('frm_duplicated_field', $f);
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) ) {
313
+		    if ( ! empty( $this_form ) ) {
314 314
 		        // check for field to edit by field id
315
-				if ( isset( $form_fields[ $f['id'] ] ) ) {
315
+				if ( isset( $form_fields[$f['id']] ) ) {
316 316
 		            FrmField::update( $f['id'], $f );
317
-		            $imported['updated']['fields']++;
317
+		            $imported['updated']['fields'] ++;
318 318
 
319
-					unset( $form_fields[ $f['id'] ] );
319
+					unset( $form_fields[$f['id']] );
320 320
 
321 321
 		            //unset old field key
322
-					if ( isset( $form_fields[ $f['field_key'] ] ) ) {
323
-						unset( $form_fields[ $f['field_key'] ] );
322
+					if ( isset( $form_fields[$f['field_key']] ) ) {
323
+						unset( $form_fields[$f['field_key']] );
324 324
 					}
325
-				} else if ( isset( $form_fields[ $f['field_key'] ] ) ) {
325
+				} else if ( isset( $form_fields[$f['field_key']] ) ) {
326 326
 		            // check for field to edit by field key
327
-		            unset($f['id']);
327
+		            unset( $f['id'] );
328 328
 
329
-					FrmField::update( $form_fields[ $f['field_key'] ], $f );
330
-		            $imported['updated']['fields']++;
329
+					FrmField::update( $form_fields[$f['field_key']], $f );
330
+		            $imported['updated']['fields'] ++;
331 331
 
332
-					unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id
333
-					unset( $form_fields[ $f['field_key'] ] ); //unset old field key
332
+					unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id
333
+					unset( $form_fields[$f['field_key']] ); //unset old field key
334 334
 				} else {
335 335
 					$new_id = FrmField::create( $f );
336 336
 					if ( $new_id == false ) {
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 					}
339 339
 
340 340
 		            // if no matching field id or key in this form, create the field
341
-		            $imported['imported']['fields']++;
341
+		            $imported['imported']['fields'] ++;
342 342
 		        }
343 343
 			} else {
344 344
 				$new_id = FrmField::create( $f );
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
 					continue;
347 347
 				}
348 348
 
349
-	            $imported['imported']['fields']++;
349
+	            $imported['imported']['fields'] ++;
350 350
 		    }
351 351
 
352
-			unset($field, $new_id);
352
+			unset( $field, $new_id );
353 353
 		}
354 354
 	}
355 355
 
@@ -368,8 +368,8 @@  discard block
 block discarded – undo
368 368
 		if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) {
369 369
 			if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) {
370 370
 				$form_select = $f['field_options']['form_select'];
371
-				if ( isset( $imported['forms'][ $form_select ] ) ) {
372
-					$f['field_options']['form_select'] = $imported['forms'][ $form_select ];
371
+				if ( isset( $imported['forms'][$form_select] ) ) {
372
+					$f['field_options']['form_select'] = $imported['forms'][$form_select];
373 373
 				}
374 374
 			}
375 375
 		}
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 	*
384 384
 	*/
385 385
 	private static function update_custom_style_setting_on_import( &$form ) {
386
-		if ( is_numeric ( $form['options']['custom_style'] ) ) {
386
+		if ( is_numeric( $form['options']['custom_style'] ) ) {
387 387
 			// Set to default
388 388
 			$form['options']['custom_style'] = 1;
389 389
 		} else {
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 				'post_id'       => (int) $item->post_id,
433 433
 				'post_parent'   => (int) $item->post_parent,
434 434
 				'menu_order'    => (int) $item->menu_order,
435
-				'post_content'  => FrmFieldsHelper::switch_field_ids((string) $item->content),
436
-				'post_excerpt'  => FrmFieldsHelper::switch_field_ids((string) $item->excerpt),
435
+				'post_content'  => FrmFieldsHelper::switch_field_ids( (string) $item->content ),
436
+				'post_excerpt'  => FrmFieldsHelper::switch_field_ids( (string) $item->excerpt ),
437 437
 				'is_sticky'     => (string) $item->is_sticky,
438 438
 				'comment_status' => (string) $item->comment_status,
439 439
 				'post_date'     => (string) $item->post_date,
@@ -444,9 +444,9 @@  discard block
 block discarded – undo
444 444
 			);
445 445
 
446 446
             $old_id = $post['post_id'];
447
-            self::populate_post($post, $item, $imported);
447
+            self::populate_post( $post, $item, $imported );
448 448
 
449
-			unset($item);
449
+			unset( $item );
450 450
 
451 451
 			$post_id = false;
452 452
             if ( $post['post_type'] == $form_action_type ) {
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 				if ( $action_control ) {
455 455
 					$post_id = $action_control->maybe_create_action( $post, $imported['form_status'] );
456 456
 				}
457
-                unset($action_control);
457
+                unset( $action_control );
458 458
             } else if ( $post['post_type'] == 'frm_styles' ) {
459 459
                 // Properly encode post content before inserting the post
460 460
                 $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] );
@@ -467,26 +467,26 @@  discard block
 block discarded – undo
467 467
                 $post_id = wp_insert_post( $post );
468 468
             }
469 469
 
470
-            if ( ! is_numeric($post_id) ) {
470
+            if ( ! is_numeric( $post_id ) ) {
471 471
                 continue;
472 472
             }
473 473
 
474
-            self::update_postmeta($post, $post_id);
474
+            self::update_postmeta( $post, $post_id );
475 475
 
476 476
             $this_type = 'posts';
477
-			if ( isset( $post_types[ $post['post_type'] ] ) ) {
478
-				$this_type = $post_types[ $post['post_type'] ];
477
+			if ( isset( $post_types[$post['post_type']] ) ) {
478
+				$this_type = $post_types[$post['post_type']];
479 479
             }
480 480
 
481
-            if ( isset($post['ID']) && $post_id == $post['ID'] ) {
482
-                $imported['updated'][ $this_type ]++;
481
+            if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) {
482
+                $imported['updated'][$this_type] ++;
483 483
             } else {
484
-                $imported['imported'][ $this_type ]++;
484
+                $imported['imported'][$this_type] ++;
485 485
             }
486 486
 
487
-            unset($post);
487
+            unset( $post );
488 488
 
489
-			$imported['posts'][ (int) $old_id ] = $post_id;
489
+			$imported['posts'][(int) $old_id] = $post_id;
490 490
 		}
491 491
 
492 492
 		self::maybe_update_stylesheet( $imported );
@@ -495,23 +495,23 @@  discard block
 block discarded – undo
495 495
     }
496 496
 
497 497
     private static function populate_post( &$post, $item, $imported ) {
498
-		if ( isset($item->attachment_url) ) {
498
+		if ( isset( $item->attachment_url ) ) {
499 499
 			$post['attachment_url'] = (string) $item->attachment_url;
500 500
 		}
501 501
 
502
-		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) {
502
+		if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) {
503 503
 		    // update to new form id
504
-		    $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ];
504
+		    $post['menu_order'] = $imported['forms'][(int) $post['menu_order']];
505 505
 		}
506 506
 
507 507
 		foreach ( $item->postmeta as $meta ) {
508
-		    self::populate_postmeta($post, $meta, $imported);
509
-			unset($meta);
508
+		    self::populate_postmeta( $post, $meta, $imported );
509
+			unset( $meta );
510 510
 		}
511 511
 
512
-        self::populate_taxonomies($post, $item);
512
+        self::populate_taxonomies( $post, $item );
513 513
 
514
-        self::maybe_editing_post($post);
514
+        self::maybe_editing_post( $post );
515 515
     }
516 516
 
517 517
     private static function populate_postmeta( &$post, $meta, $imported ) {
@@ -523,27 +523,27 @@  discard block
 block discarded – undo
523 523
 		);
524 524
 
525 525
 		//switch old form and field ids to new ones
526
-		if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) {
527
-		    $m['value'] = $imported['forms'][ (int) $m['value'] ];
526
+		if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) {
527
+		    $m['value'] = $imported['forms'][(int) $m['value']];
528 528
 		} else {
529
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
529
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
530 530
 
531
-		    if ( ! empty($frm_duplicate_ids) ) {
531
+		    if ( ! empty( $frm_duplicate_ids ) ) {
532 532
 
533 533
 		        if ( $m['key'] == 'frm_dyncontent' ) {
534
-		            $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']);
534
+		            $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] );
535 535
     		    } else if ( $m['key'] == 'frm_options' ) {
536 536
 
537 537
 					foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) {
538
-						if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) {
539
-							$m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ];
538
+						if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) {
539
+							$m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]];
540 540
     		            }
541 541
     		        }
542 542
 
543 543
                     $check_dup_array = array();
544 544
     		        if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) {
545
-    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) {
546
-    		                $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ];
545
+    		            if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) {
546
+    		                $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']];
547 547
     		            } else if ( is_array( $m['value']['order_by'] ) ) {
548 548
                             $check_dup_array[] = 'order_by';
549 549
     		            }
@@ -554,22 +554,22 @@  discard block
 block discarded – undo
554 554
     		        }
555 555
 
556 556
                     foreach ( $check_dup_array as $check_k ) {
557
-						foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) {
558
-							if ( isset( $frm_duplicate_ids[ $mv ] ) ) {
559
-								$m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ];
557
+						foreach ( (array) $m['value'][$check_k] as $mk => $mv ) {
558
+							if ( isset( $frm_duplicate_ids[$mv] ) ) {
559
+								$m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv];
560 560
 		                    }
561
-		                    unset($mk, $mv);
561
+		                    unset( $mk, $mv );
562 562
 		                }
563 563
                     }
564 564
     		    }
565 565
 		    }
566 566
 		}
567 567
 
568
-		if ( ! is_array($m['value']) ) {
569
-		    $m['value'] = FrmAppHelper::maybe_json_decode($m['value']);
568
+		if ( ! is_array( $m['value'] ) ) {
569
+		    $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] );
570 570
 		}
571 571
 
572
-		$post['postmeta'][ (string) $meta->meta_key ] = $m['value'];
572
+		$post['postmeta'][(string) $meta->meta_key] = $m['value'];
573 573
     }
574 574
 
575 575
     /**
@@ -585,23 +585,23 @@  discard block
 block discarded – undo
585 585
             }
586 586
 
587 587
 		    $taxonomy = (string) $att['domain'];
588
-		    if ( is_taxonomy_hierarchical($taxonomy) ) {
588
+		    if ( is_taxonomy_hierarchical( $taxonomy ) ) {
589 589
 		        $name = (string) $att['nicename'];
590
-		        $h_term = get_term_by('slug', $name, $taxonomy);
590
+		        $h_term = get_term_by( 'slug', $name, $taxonomy );
591 591
 		        if ( $h_term ) {
592 592
 		            $name = $h_term->term_id;
593 593
 		        }
594
-		        unset($h_term);
594
+		        unset( $h_term );
595 595
 		    } else {
596 596
 		        $name = (string) $c;
597 597
 		    }
598 598
 
599
-			if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) {
600
-				$post['tax_input'][ $taxonomy ] = array();
599
+			if ( ! isset( $post['tax_input'][$taxonomy] ) ) {
600
+				$post['tax_input'][$taxonomy] = array();
601 601
 			}
602 602
 
603
-			$post['tax_input'][ $taxonomy ][] = $name;
604
-		    unset($name);
603
+			$post['tax_input'][$taxonomy][] = $name;
604
+		    unset( $name );
605 605
 		}
606 606
     }
607 607
 
@@ -618,29 +618,29 @@  discard block
 block discarded – undo
618 618
 
619 619
 		if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) {
620 620
 		    $match_by['include'] = $post['post_id'];
621
-		    unset($match_by['name']);
621
+		    unset( $match_by['name'] );
622 622
 		}
623 623
 
624
-		$editing = get_posts($match_by);
624
+		$editing = get_posts( $match_by );
625 625
 
626
-        if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) {
626
+        if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) {
627 627
             // set the id of the post to edit
628
-            $post['ID'] = current($editing)->ID;
628
+            $post['ID'] = current( $editing )->ID;
629 629
         }
630 630
     }
631 631
 
632 632
     private static function update_postmeta( &$post, $post_id ) {
633 633
         foreach ( $post['postmeta'] as $k => $v ) {
634 634
             if ( '_edit_last' == $k ) {
635
-                $v = FrmAppHelper::get_user_id_param($v);
635
+                $v = FrmAppHelper::get_user_id_param( $v );
636 636
             } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) {
637 637
                 //change the attachment ID
638
-                $v = FrmProXMLHelper::get_file_id($v);
638
+                $v = FrmProXMLHelper::get_file_id( $v );
639 639
             }
640 640
 
641
-            update_post_meta($post_id, $k, $v);
641
+            update_post_meta( $post_id, $k, $v );
642 642
 
643
-            unset($k, $v);
643
+            unset( $k, $v );
644 644
         }
645 645
     }
646 646
 
@@ -657,13 +657,13 @@  discard block
 block discarded – undo
657 657
      * @param string $message
658 658
      */
659 659
 	public static function parse_message( $result, &$message, &$errors ) {
660
-        if ( is_wp_error($result) ) {
660
+        if ( is_wp_error( $result ) ) {
661 661
             $errors[] = $result->get_error_message();
662 662
         } else if ( ! $result ) {
663 663
             return;
664 664
         }
665 665
 
666
-        if ( ! is_array($result) ) {
666
+        if ( ! is_array( $result ) ) {
667 667
             $message = is_string( $result ) ? $result : print_r( $result, 1 );
668 668
             return;
669 669
         }
@@ -675,20 +675,20 @@  discard block
 block discarded – undo
675 675
 
676 676
         $message = '<ul>';
677 677
         foreach ( $result as $type => $results ) {
678
-			if ( ! isset( $t_strings[ $type ] ) ) {
678
+			if ( ! isset( $t_strings[$type] ) ) {
679 679
                 // only print imported and updated
680 680
                 continue;
681 681
             }
682 682
 
683 683
             $s_message = array();
684 684
             foreach ( $results as $k => $m ) {
685
-                self::item_count_message($m, $k, $s_message);
686
-                unset($k, $m);
685
+                self::item_count_message( $m, $k, $s_message );
686
+                unset( $k, $m );
687 687
             }
688 688
 
689
-            if ( ! empty($s_message) ) {
690
-				$message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> ';
691
-                $message .= implode(', ', $s_message);
689
+            if ( ! empty( $s_message ) ) {
690
+				$message .= '<li><strong>' . $t_strings[$type] . ':</strong> ';
691
+                $message .= implode( ', ', $s_message );
692 692
                 $message .= '</li>';
693 693
             }
694 694
         }
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
             'actions'   => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ),
718 718
         );
719 719
 
720
-		$s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type );
720
+		$s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type );
721 721
     }
722 722
 
723 723
 	/**
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 	 * @return string
729 729
 	 */
730 730
 	public static function prepare_form_options_for_export( $options ) {
731
-		$options = maybe_unserialize ( $options );
731
+		$options = maybe_unserialize( $options );
732 732
 		// Change custom_style to the post_name instead of ID
733 733
 		if ( isset( $options['custom_style'] ) && $options['custom_style'] !== 1 ) {
734 734
 			global $wpdb;
@@ -752,14 +752,14 @@  discard block
 block discarded – undo
752 752
 	}
753 753
 
754 754
 	public static function cdata( $str ) {
755
-	    $str = maybe_unserialize($str);
756
-	    if ( is_array($str) ) {
757
-	        $str = json_encode($str);
755
+	    $str = maybe_unserialize( $str );
756
+	    if ( is_array( $str ) ) {
757
+	        $str = json_encode( $str );
758 758
 		} else if ( seems_utf8( $str ) == false ) {
759 759
 			$str = utf8_encode( $str );
760 760
 		}
761 761
 
762
-        if ( is_numeric($str) ) {
762
+        if ( is_numeric( $str ) ) {
763 763
             return $str;
764 764
         }
765 765
 
@@ -791,7 +791,7 @@  discard block
 block discarded – undo
791 791
     * @param string $post_type
792 792
     */
793 793
     private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) {
794
-        if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) {
794
+        if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) {
795 795
             return;
796 796
         }
797 797
 
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
             'menu_order'    => $form_id,
803 803
             'post_status'   => 'publish',
804 804
             'post_content'  => array(),
805
-            'post_name'     => $form_id .'_wppost_1',
805
+            'post_name'     => $form_id . '_wppost_1',
806 806
         );
807 807
 
808 808
         $post_settings = array(
@@ -812,10 +812,10 @@  discard block
 block discarded – undo
812 812
         );
813 813
 
814 814
         foreach ( $post_settings as $post_setting ) {
815
-			if ( isset( $form_options[ $post_setting ] ) ) {
816
-				$new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ];
815
+			if ( isset( $form_options[$post_setting] ) ) {
816
+				$new_action['post_content'][$post_setting] = $form_options[$post_setting];
817 817
             }
818
-            unset($post_setting);
818
+            unset( $post_setting );
819 819
         }
820 820
 
821 821
 		$new_action['event'] = array( 'create', 'update' );
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 
830 830
 			$new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields );
831 831
         }
832
-        $new_action['post_content'] = json_encode($new_action['post_content']);
832
+        $new_action['post_content'] = json_encode( $new_action['post_content'] );
833 833
 
834 834
         $exists = get_posts( array(
835 835
             'name'          => $new_action['post_name'],
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
         if ( ! $exists ) {
842 842
 			// this isn't an email, but we need to use a class that will always be included
843 843
 			FrmAppHelper::save_json_post( $new_action );
844
-            $imported['imported']['actions']++;
844
+            $imported['imported']['actions'] ++;
845 845
         }
846 846
     }
847 847
 
@@ -873,11 +873,11 @@  discard block
 block discarded – undo
873 873
         foreach ( $post_content as $key => $setting ) {
874 874
             if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) {
875 875
                 // Replace old IDs with new IDs
876
-				$post_content[ $key ] = str_replace( $old, $new, $setting );
876
+				$post_content[$key] = str_replace( $old, $new, $setting );
877 877
             } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) {
878 878
                 foreach ( $setting as $k => $val ) {
879 879
                     // Replace old IDs with new IDs
880
-					$post_content[ $key ][ $k ] = str_replace( $old, $new, $val );
880
+					$post_content[$key][$k] = str_replace( $old, $new, $val );
881 881
                 }
882 882
             }
883 883
             unset( $key, $setting );
@@ -900,14 +900,14 @@  discard block
 block discarded – undo
900 900
         // Migrate autoresponders
901 901
         self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications );
902 902
 
903
-        if (  empty( $notifications ) ) {
903
+        if ( empty( $notifications ) ) {
904 904
             return;
905 905
         }
906 906
 
907 907
         foreach ( $notifications as $new_notification ) {
908 908
             $new_notification['post_type']      = $post_type;
909 909
             $new_notification['post_excerpt']   = 'email';
910
-			$new_notification['post_title']     = __( 'Email Notification', 'formidable' );
910
+			$new_notification['post_title'] = __( 'Email Notification', 'formidable' );
911 911
             $new_notification['menu_order']     = $form_id;
912 912
             $new_notification['post_status']    = 'publish';
913 913
 
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 				// Switch all other field IDs in email
921 921
                 $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] );
922 922
             }
923
-            $new_notification['post_content']   = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
923
+            $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] );
924 924
 
925 925
             $exists = get_posts( array(
926 926
                 'name'          => $new_notification['post_name'],
@@ -929,11 +929,11 @@  discard block
 block discarded – undo
929 929
                 'numberposts'   => 1,
930 930
             ) );
931 931
 
932
-            if ( empty($exists) ) {
932
+            if ( empty( $exists ) ) {
933 933
 				FrmAppHelper::save_json_post( $new_notification );
934
-                $imported['imported']['actions']++;
934
+                $imported['imported']['actions'] ++;
935 935
             }
936
-            unset($new_notification);
936
+            unset( $new_notification );
937 937
         }
938 938
     }
939 939
 
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 			$form_options['notification'] = array( 0 => $form_options['notification'] );
947 947
         }
948 948
 
949
-        if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) {
949
+        if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) {
950 950
             foreach ( $form_options['notification'] as $email_key => $notification ) {
951 951
 
952 952
                 $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key );
@@ -974,12 +974,12 @@  discard block
 block discarded – undo
974 974
         // Format the reply to email and name
975 975
         $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' );
976 976
         foreach ( $reply_fields as $f => $val ) {
977
-			if ( isset( $notification[ $f ] ) ) {
978
-				$atts[ $f ] = $notification[ $f ];
979
-				if ( 'custom' == $notification[ $f ] ) {
980
-					$atts[ $f ] = $notification[ 'cust_' . $f ];
981
-				} else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) {
982
-					$atts[ $f ] = '[' . $atts[ $f ] . ']';
977
+			if ( isset( $notification[$f] ) ) {
978
+				$atts[$f] = $notification[$f];
979
+				if ( 'custom' == $notification[$f] ) {
980
+					$atts[$f] = $notification['cust_' . $f];
981
+				} else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) {
982
+					$atts[$f] = '[' . $atts[$f] . ']';
983 983
                 }
984 984
             }
985 985
             unset( $f, $val );
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
 		$atts['event'] = array( 'create' );
990 990
         if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) {
991 991
             $atts['event'][] = 'update';
992
-        } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) {
992
+        } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) {
993 993
 			$atts['event'] = array( 'update' );
994 994
         }
995 995
     }
@@ -1010,18 +1010,18 @@  discard block
 block discarded – undo
1010 1010
         foreach ( $atts['email_to'] as $key => $email_field ) {
1011 1011
 
1012 1012
             if ( is_numeric( $email_field ) ) {
1013
-				$atts['email_to'][ $key ] = '[' . $email_field . ']';
1013
+				$atts['email_to'][$key] = '[' . $email_field . ']';
1014 1014
             }
1015 1015
 
1016
-            if ( strpos( $email_field, '|') ) {
1016
+            if ( strpos( $email_field, '|' ) ) {
1017 1017
                 $email_opt = explode( '|', $email_field );
1018 1018
                 if ( isset( $email_opt[0] ) ) {
1019
-					$atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1019
+					$atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']';
1020 1020
                 }
1021 1021
                 unset( $email_opt );
1022 1022
             }
1023 1023
         }
1024
-        $atts['email_to'] = implode(', ', $atts['email_to']);
1024
+        $atts['email_to'] = implode( ', ', $atts['email_to'] );
1025 1025
     }
1026 1026
 
1027 1027
     private static function setup_new_notification( &$new_notification, $notification, $atts ) {
@@ -1031,18 +1031,18 @@  discard block
 block discarded – undo
1031 1031
                 'email_to'      => $atts['email_to'],
1032 1032
                 'event'         => $atts['event'],
1033 1033
             ),
1034
-            'post_name'         => $atts['form_id'] .'_email_'. $atts['email_key'],
1034
+            'post_name'         => $atts['form_id'] . '_email_' . $atts['email_key'],
1035 1035
         );
1036 1036
 
1037 1037
         // Add more fields to the new notification
1038 1038
         $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' );
1039 1039
         foreach ( $add_fields as $add_field ) {
1040
-			if ( isset( $notification[ $add_field ] ) ) {
1041
-				$new_notification['post_content'][ $add_field ] = $notification[ $add_field ];
1040
+			if ( isset( $notification[$add_field] ) ) {
1041
+				$new_notification['post_content'][$add_field] = $notification[$add_field];
1042 1042
             } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) {
1043
-				$new_notification['post_content'][ $add_field ] = 0;
1043
+				$new_notification['post_content'][$add_field] = 0;
1044 1044
             } else {
1045
-				$new_notification['post_content'][ $add_field ] = '';
1045
+				$new_notification['post_content'][$add_field] = '';
1046 1046
             }
1047 1047
             unset( $add_field );
1048 1048
         }
@@ -1052,7 +1052,7 @@  discard block
 block discarded – undo
1052 1052
 
1053 1053
         // Set from
1054 1054
 		if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) {
1055
-            $new_notification['post_content']['from'] = ( empty($atts['reply_to_name']) ? '[sitename]' : $atts['reply_to_name'] ) .' <'. ( empty($atts['reply_to']) ? '[admin_email]' : $atts['reply_to'] ) .'>';
1055
+            $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>';
1056 1056
         }
1057 1057
     }
1058 1058
 
@@ -1066,50 +1066,50 @@  discard block
 block discarded – undo
1066 1066
 		if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) {
1067 1067
 			foreach ( $post_content['conditions'] as $email_key => $val ) {
1068 1068
 				if ( is_numeric( $email_key ) ) {
1069
-					$post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1069
+					$post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) );
1070 1070
 				}
1071
-				unset( $email_key, $val);
1071
+				unset( $email_key, $val );
1072 1072
 			}
1073 1073
 		}
1074 1074
 	}
1075 1075
 
1076 1076
     private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) {
1077
-        if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) {
1077
+        if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) {
1078 1078
             // migrate autoresponder
1079 1079
 
1080
-            $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0;
1081
-            if ( strpos($email_field, '|') ) {
1080
+            $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0;
1081
+            if ( strpos( $email_field, '|' ) ) {
1082 1082
                 // data from entries field
1083
-                $email_field = explode('|', $email_field);
1084
-                if ( isset($email_field[1]) ) {
1083
+                $email_field = explode( '|', $email_field );
1084
+                if ( isset( $email_field[1] ) ) {
1085 1085
                     $email_field = $email_field[1];
1086 1086
                 }
1087 1087
             }
1088
-            if ( is_numeric($email_field) && ! empty($email_field) ) {
1089
-                $email_field = '['. $email_field .']';
1088
+            if ( is_numeric( $email_field ) && ! empty( $email_field ) ) {
1089
+                $email_field = '[' . $email_field . ']';
1090 1090
             }
1091 1091
 
1092 1092
             $notification = $form_options;
1093 1093
             $new_notification2 = array(
1094 1094
                 'post_content'  => array(
1095 1095
                     'email_message' => $notification['ar_email_message'],
1096
-                    'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '',
1096
+                    'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '',
1097 1097
                     'email_to'      => $email_field,
1098
-                    'plain_text'    => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0,
1098
+                    'plain_text'    => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0,
1099 1099
                     'inc_user_info' => 0,
1100 1100
                 ),
1101
-                'post_name'     => $form_id .'_email_'. count( $notifications ),
1101
+                'post_name'     => $form_id . '_email_' . count( $notifications ),
1102 1102
             );
1103 1103
 
1104
-            $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : '';
1105
-            $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : '';
1104
+            $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : '';
1105
+            $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : '';
1106 1106
 
1107 1107
 			if ( ! empty( $reply_to ) ) {
1108 1108
 				$new_notification2['post_content']['reply_to'] = $reply_to;
1109 1109
 			}
1110 1110
 
1111 1111
 			if ( ! empty( $reply_to ) || ! empty( $reply_to_name ) ) {
1112
-                $new_notification2['post_content']['from'] = ( empty($reply_to_name) ? '[sitename]' : $reply_to_name ) .' <'. ( empty($reply_to) ? '[admin_email]' : $reply_to ) .'>';
1112
+                $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>';
1113 1113
 			}
1114 1114
 
1115 1115
             $notifications[] = $new_notification2;
Please login to merge, or discard this patch.