@@ -23,30 +23,30 @@ discard block |
||
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,45 +64,45 @@ discard block |
||
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 | - )); |
|
94 | + )); |
|
95 | 95 | |
96 | 96 | if ( $term && is_array( $term ) ) { |
97 | - $imported['imported']['terms']++; |
|
97 | + $imported['imported']['terms']++; |
|
98 | 98 | $imported['terms'][ (int) $t->term_id ] = $term['term_id']; |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | unset( $term, $t ); |
102 | 102 | } |
103 | 103 | |
104 | 104 | return $imported; |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | /** |
108 | 108 | * @since 2.0.8 |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | self::put_child_forms_first( $forms ); |
128 | 128 | |
129 | 129 | foreach ( $forms as $item ) { |
130 | - $form = self::fill_form( $item ); |
|
130 | + $form = self::fill_form( $item ); |
|
131 | 131 | |
132 | 132 | self::update_custom_style_setting_on_import( $form ); |
133 | 133 | |
134 | - $this_form = self::maybe_get_form( $form ); |
|
134 | + $this_form = self::maybe_get_form( $form ); |
|
135 | 135 | |
136 | 136 | $old_id = $form_fields = false; |
137 | 137 | if ( ! empty( $this_form ) ) { |
@@ -141,35 +141,35 @@ discard block |
||
141 | 141 | $form_fields = self::get_form_fields( $form_id ); |
142 | 142 | } else { |
143 | 143 | $form_id = FrmForm::create( $form ); |
144 | - if ( $form_id ) { |
|
145 | - $imported['imported']['forms']++; |
|
146 | - // Keep track of whether this specific form was updated or not |
|
144 | + if ( $form_id ) { |
|
145 | + $imported['imported']['forms']++; |
|
146 | + // Keep track of whether this specific form was updated or not |
|
147 | 147 | $imported['form_status'][ $form_id ] = 'imported'; |
148 | 148 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
149 | - } |
|
149 | + } |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | self::import_xml_fields( $item->field, $form_id, $this_form, $form_fields, $imported ); |
153 | 153 | |
154 | 154 | self::delete_removed_fields( $form_fields ); |
155 | 155 | |
156 | - // Update field ids/keys to new ones |
|
156 | + // Update field ids/keys to new ones |
|
157 | 157 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
158 | 158 | |
159 | 159 | $imported['forms'][ (int) $item->id ] = $form_id; |
160 | 160 | |
161 | - // Send pre 2.0 form options through function that creates actions |
|
162 | - self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
161 | + // Send pre 2.0 form options through function that creates actions |
|
162 | + self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
|
163 | 163 | |
164 | 164 | do_action( 'frm_after_import_form', $form_id, $form ); |
165 | 165 | |
166 | - unset($form, $item); |
|
166 | + unset($form, $item); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
170 | 170 | |
171 | 171 | return $imported; |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | 174 | private static function fill_form( $item ) { |
175 | 175 | $form = array( |
@@ -237,11 +237,11 @@ discard block |
||
237 | 237 | } |
238 | 238 | |
239 | 239 | /** |
240 | - * Put child forms first so they will be imported before parents |
|
241 | - * |
|
242 | - * @since 2.0.16 |
|
243 | - * @param array $forms |
|
244 | - */ |
|
240 | + * Put child forms first so they will be imported before parents |
|
241 | + * |
|
242 | + * @since 2.0.16 |
|
243 | + * @param array $forms |
|
244 | + */ |
|
245 | 245 | private static function put_child_forms_first( &$forms ) { |
246 | 246 | $child_forms = array(); |
247 | 247 | $regular_forms = array(); |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
263 | - * Keep track of all imported child forms |
|
264 | - * |
|
265 | - * @since 2.0.16 |
|
266 | - * @param int $form_id |
|
267 | - * @param int $parent_form_id |
|
268 | - * @param array $child_forms |
|
269 | - */ |
|
263 | + * Keep track of all imported child forms |
|
264 | + * |
|
265 | + * @since 2.0.16 |
|
266 | + * @param int $form_id |
|
267 | + * @param int $parent_form_id |
|
268 | + * @param array $child_forms |
|
269 | + */ |
|
270 | 270 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
271 | 271 | if ( $parent_form_id ) { |
272 | 272 | $child_forms[ $form_id ] = $parent_form_id; |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
277 | - * Update the parent_form_id on imported child forms |
|
278 | - * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
279 | - * |
|
280 | - * @since 2.0.6 |
|
281 | - * @param array $imported_forms |
|
282 | - * @param array $child_forms |
|
283 | - */ |
|
277 | + * Update the parent_form_id on imported child forms |
|
278 | + * Child forms are imported first so their parent_form_id will need to be updated after the parent is imported |
|
279 | + * |
|
280 | + * @since 2.0.6 |
|
281 | + * @param array $imported_forms |
|
282 | + * @param array $child_forms |
|
283 | + */ |
|
284 | 284 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
285 | 285 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
286 | 286 | |
@@ -294,28 +294,28 @@ discard block |
||
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Import all fields for a form |
|
298 | - * @since 2.0.13 |
|
299 | - * |
|
300 | - * TODO: Cut down on params |
|
301 | - */ |
|
297 | + * Import all fields for a form |
|
298 | + * @since 2.0.13 |
|
299 | + * |
|
300 | + * TODO: Cut down on params |
|
301 | + */ |
|
302 | 302 | private static function import_xml_fields( $xml_fields, $form_id, $this_form, &$form_fields, &$imported ) { |
303 | 303 | $in_section = 0; |
304 | 304 | |
305 | 305 | foreach ( $xml_fields as $field ) { |
306 | 306 | $f = self::fill_field( $field, $form_id ); |
307 | 307 | |
308 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
309 | - 'text', 'email', 'url', 'textarea', |
|
310 | - 'number','phone', 'date', 'time', |
|
311 | - 'hidden', 'password', 'tag', 'image', |
|
312 | - )) ) { |
|
313 | - if ( count($f['default_value']) === 1 ) { |
|
308 | + if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
309 | + 'text', 'email', 'url', 'textarea', |
|
310 | + 'number','phone', 'date', 'time', |
|
311 | + 'hidden', 'password', 'tag', 'image', |
|
312 | + )) ) { |
|
313 | + if ( count($f['default_value']) === 1 ) { |
|
314 | 314 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
315 | - } else { |
|
316 | - $f['default_value'] = reset($f['default_value']); |
|
317 | - } |
|
318 | - } |
|
315 | + } else { |
|
316 | + $f['default_value'] = reset($f['default_value']); |
|
317 | + } |
|
318 | + } |
|
319 | 319 | |
320 | 320 | self::maybe_update_in_section_variable( $in_section, $f ); |
321 | 321 | self::maybe_update_form_select( $f, $imported ); |
@@ -394,12 +394,12 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
397 | - * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
398 | - * |
|
399 | - * @since 2.0.16 |
|
400 | - * @param array $f |
|
401 | - * @param array $imported |
|
402 | - */ |
|
397 | + * Switch the form_select on a repeating field or embedded form if it needs to be switched |
|
398 | + * |
|
399 | + * @since 2.0.16 |
|
400 | + * @param array $f |
|
401 | + * @param array $imported |
|
402 | + */ |
|
403 | 403 | private static function maybe_update_form_select( &$f, $imported ) { |
404 | 404 | if ( ! isset( $imported['forms'] ) ) { |
405 | 405 | return; |
@@ -451,13 +451,13 @@ discard block |
||
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
454 | - * Updates the custom style setting on import |
|
455 | - * Convert the post slug to an ID |
|
456 | - * |
|
457 | - * @since 2.0.19 |
|
458 | - * @param array $form |
|
459 | - * |
|
460 | - */ |
|
454 | + * Updates the custom style setting on import |
|
455 | + * Convert the post slug to an ID |
|
456 | + * |
|
457 | + * @since 2.0.19 |
|
458 | + * @param array $form |
|
459 | + * |
|
460 | + */ |
|
461 | 461 | private static function update_custom_style_setting_on_import( &$form ) { |
462 | 462 | if ( ! isset( $form['options']['custom_style'] ) ) { |
463 | 463 | return; |
@@ -511,16 +511,16 @@ discard block |
||
511 | 511 | } |
512 | 512 | |
513 | 513 | public static function import_xml_views( $views, $imported ) { |
514 | - $imported['posts'] = array(); |
|
515 | - $form_action_type = FrmFormActionsController::$action_post_type; |
|
514 | + $imported['posts'] = array(); |
|
515 | + $form_action_type = FrmFormActionsController::$action_post_type; |
|
516 | 516 | |
517 | - $post_types = array( |
|
518 | - 'frm_display' => 'views', |
|
519 | - $form_action_type => 'actions', |
|
520 | - 'frm_styles' => 'styles', |
|
521 | - ); |
|
517 | + $post_types = array( |
|
518 | + 'frm_display' => 'views', |
|
519 | + $form_action_type => 'actions', |
|
520 | + 'frm_styles' => 'styles', |
|
521 | + ); |
|
522 | 522 | |
523 | - foreach ( $views as $item ) { |
|
523 | + foreach ( $views as $item ) { |
|
524 | 524 | $post = array( |
525 | 525 | 'post_title' => (string) $item->title, |
526 | 526 | 'post_name' => (string) $item->post_name, |
@@ -539,52 +539,52 @@ discard block |
||
539 | 539 | 'post_date' => (string) $item->post_date, |
540 | 540 | 'post_date_gmt' => (string) $item->post_date_gmt, |
541 | 541 | 'ping_status' => (string) $item->ping_status, |
542 | - 'postmeta' => array(), |
|
543 | - 'tax_input' => array(), |
|
542 | + 'postmeta' => array(), |
|
543 | + 'tax_input' => array(), |
|
544 | 544 | ); |
545 | 545 | |
546 | - $old_id = $post['post_id']; |
|
547 | - self::populate_post($post, $item, $imported); |
|
546 | + $old_id = $post['post_id']; |
|
547 | + self::populate_post($post, $item, $imported); |
|
548 | 548 | |
549 | 549 | unset($item); |
550 | 550 | |
551 | 551 | $post_id = false; |
552 | - if ( $post['post_type'] == $form_action_type ) { |
|
553 | - $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
552 | + if ( $post['post_type'] == $form_action_type ) { |
|
553 | + $action_control = FrmFormActionsController::get_form_actions( $post['post_excerpt'] ); |
|
554 | 554 | if ( $action_control && is_object( $action_control ) ) { |
555 | 555 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
556 | 556 | } |
557 | - unset($action_control); |
|
558 | - } else if ( $post['post_type'] == 'frm_styles' ) { |
|
559 | - // Properly encode post content before inserting the post |
|
560 | - $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
561 | - $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
562 | - |
|
563 | - // Create/update post now |
|
564 | - $post_id = wp_insert_post( $post ); |
|
565 | - } else { |
|
566 | - // Create/update post now |
|
567 | - $post_id = wp_insert_post( $post ); |
|
568 | - } |
|
569 | - |
|
570 | - if ( ! is_numeric($post_id) ) { |
|
571 | - continue; |
|
572 | - } |
|
573 | - |
|
574 | - self::update_postmeta($post, $post_id); |
|
575 | - |
|
576 | - $this_type = 'posts'; |
|
557 | + unset($action_control); |
|
558 | + } else if ( $post['post_type'] == 'frm_styles' ) { |
|
559 | + // Properly encode post content before inserting the post |
|
560 | + $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
|
561 | + $post['post_content'] = FrmAppHelper::prepare_and_encode( $post['post_content'] ); |
|
562 | + |
|
563 | + // Create/update post now |
|
564 | + $post_id = wp_insert_post( $post ); |
|
565 | + } else { |
|
566 | + // Create/update post now |
|
567 | + $post_id = wp_insert_post( $post ); |
|
568 | + } |
|
569 | + |
|
570 | + if ( ! is_numeric($post_id) ) { |
|
571 | + continue; |
|
572 | + } |
|
573 | + |
|
574 | + self::update_postmeta($post, $post_id); |
|
575 | + |
|
576 | + $this_type = 'posts'; |
|
577 | 577 | if ( isset( $post_types[ $post['post_type'] ] ) ) { |
578 | 578 | $this_type = $post_types[ $post['post_type'] ]; |
579 | - } |
|
579 | + } |
|
580 | 580 | |
581 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | - $imported['updated'][ $this_type ]++; |
|
583 | - } else { |
|
584 | - $imported['imported'][ $this_type ]++; |
|
585 | - } |
|
581 | + if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | + $imported['updated'][ $this_type ]++; |
|
583 | + } else { |
|
584 | + $imported['imported'][ $this_type ]++; |
|
585 | + } |
|
586 | 586 | |
587 | - unset($post); |
|
587 | + unset($post); |
|
588 | 588 | |
589 | 589 | $imported['posts'][ (int) $old_id ] = $post_id; |
590 | 590 | } |
@@ -592,16 +592,16 @@ discard block |
||
592 | 592 | self::maybe_update_stylesheet( $imported ); |
593 | 593 | |
594 | 594 | return $imported; |
595 | - } |
|
595 | + } |
|
596 | 596 | |
597 | - private static function populate_post( &$post, $item, $imported ) { |
|
597 | + private static function populate_post( &$post, $item, $imported ) { |
|
598 | 598 | if ( isset($item->attachment_url) ) { |
599 | 599 | $post['attachment_url'] = (string) $item->attachment_url; |
600 | 600 | } |
601 | 601 | |
602 | 602 | if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
603 | - // update to new form id |
|
604 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
603 | + // update to new form id |
|
604 | + $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Don't allow default styles to take over a site's default style |
@@ -610,144 +610,144 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | foreach ( $item->postmeta as $meta ) { |
613 | - self::populate_postmeta($post, $meta, $imported); |
|
613 | + self::populate_postmeta($post, $meta, $imported); |
|
614 | 614 | unset($meta); |
615 | 615 | } |
616 | 616 | |
617 | - self::populate_taxonomies($post, $item); |
|
617 | + self::populate_taxonomies($post, $item); |
|
618 | 618 | |
619 | - self::maybe_editing_post($post); |
|
620 | - } |
|
619 | + self::maybe_editing_post($post); |
|
620 | + } |
|
621 | 621 | |
622 | - private static function populate_postmeta( &$post, $meta, $imported ) { |
|
623 | - global $frm_duplicate_ids; |
|
622 | + private static function populate_postmeta( &$post, $meta, $imported ) { |
|
623 | + global $frm_duplicate_ids; |
|
624 | 624 | |
625 | - $m = array( |
|
625 | + $m = array( |
|
626 | 626 | 'key' => (string) $meta->meta_key, |
627 | 627 | 'value' => (string) $meta->meta_value, |
628 | 628 | ); |
629 | 629 | |
630 | 630 | //switch old form and field ids to new ones |
631 | 631 | if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
632 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
632 | + $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
633 | 633 | } else { |
634 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
634 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
635 | 635 | |
636 | - if ( ! empty($frm_duplicate_ids) ) { |
|
636 | + if ( ! empty($frm_duplicate_ids) ) { |
|
637 | 637 | |
638 | - if ( $m['key'] == 'frm_dyncontent' ) { |
|
639 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
640 | - } else if ( $m['key'] == 'frm_options' ) { |
|
638 | + if ( $m['key'] == 'frm_dyncontent' ) { |
|
639 | + $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
640 | + } else if ( $m['key'] == 'frm_options' ) { |
|
641 | 641 | |
642 | 642 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
643 | 643 | if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
644 | 644 | $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
645 | - } |
|
646 | - } |
|
647 | - |
|
648 | - $check_dup_array = array(); |
|
649 | - if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
650 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
652 | - } else if ( is_array( $m['value']['order_by'] ) ) { |
|
653 | - $check_dup_array[] = 'order_by'; |
|
654 | - } |
|
655 | - } |
|
656 | - |
|
657 | - if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
658 | - $check_dup_array[] = 'where'; |
|
659 | - } |
|
660 | - |
|
661 | - foreach ( $check_dup_array as $check_k ) { |
|
645 | + } |
|
646 | + } |
|
647 | + |
|
648 | + $check_dup_array = array(); |
|
649 | + if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
|
650 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | + $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
652 | + } else if ( is_array( $m['value']['order_by'] ) ) { |
|
653 | + $check_dup_array[] = 'order_by'; |
|
654 | + } |
|
655 | + } |
|
656 | + |
|
657 | + if ( isset( $m['value']['where'] ) && ! empty( $m['value']['where'] ) ) { |
|
658 | + $check_dup_array[] = 'where'; |
|
659 | + } |
|
660 | + |
|
661 | + foreach ( $check_dup_array as $check_k ) { |
|
662 | 662 | foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
663 | 663 | if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
664 | 664 | $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
665 | - } |
|
666 | - unset($mk, $mv); |
|
667 | - } |
|
668 | - } |
|
669 | - } |
|
670 | - } |
|
665 | + } |
|
666 | + unset($mk, $mv); |
|
667 | + } |
|
668 | + } |
|
669 | + } |
|
670 | + } |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | if ( ! is_array($m['value']) ) { |
674 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
674 | + $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
675 | 675 | } |
676 | 676 | |
677 | 677 | $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
678 | - } |
|
679 | - |
|
680 | - /** |
|
681 | - * Add terms to post |
|
682 | - * @param array $post by reference |
|
683 | - * @param object $item The XML object data |
|
684 | - */ |
|
685 | - private static function populate_taxonomies( &$post, $item ) { |
|
678 | + } |
|
679 | + |
|
680 | + /** |
|
681 | + * Add terms to post |
|
682 | + * @param array $post by reference |
|
683 | + * @param object $item The XML object data |
|
684 | + */ |
|
685 | + private static function populate_taxonomies( &$post, $item ) { |
|
686 | 686 | foreach ( $item->category as $c ) { |
687 | 687 | $att = $c->attributes(); |
688 | 688 | if ( ! isset( $att['nicename'] ) ) { |
689 | - continue; |
|
690 | - } |
|
691 | - |
|
692 | - $taxonomy = (string) $att['domain']; |
|
693 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
694 | - $name = (string) $att['nicename']; |
|
695 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
696 | - if ( $h_term ) { |
|
697 | - $name = $h_term->term_id; |
|
698 | - } |
|
699 | - unset($h_term); |
|
700 | - } else { |
|
701 | - $name = (string) $c; |
|
702 | - } |
|
689 | + continue; |
|
690 | + } |
|
691 | + |
|
692 | + $taxonomy = (string) $att['domain']; |
|
693 | + if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
694 | + $name = (string) $att['nicename']; |
|
695 | + $h_term = get_term_by('slug', $name, $taxonomy); |
|
696 | + if ( $h_term ) { |
|
697 | + $name = $h_term->term_id; |
|
698 | + } |
|
699 | + unset($h_term); |
|
700 | + } else { |
|
701 | + $name = (string) $c; |
|
702 | + } |
|
703 | 703 | |
704 | 704 | if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
705 | 705 | $post['tax_input'][ $taxonomy ] = array(); |
706 | 706 | } |
707 | 707 | |
708 | 708 | $post['tax_input'][ $taxonomy ][] = $name; |
709 | - unset($name); |
|
709 | + unset($name); |
|
710 | 710 | } |
711 | - } |
|
711 | + } |
|
712 | 712 | |
713 | - /** |
|
714 | - * Edit post if the key and created time match |
|
715 | - */ |
|
716 | - private static function maybe_editing_post( &$post ) { |
|
713 | + /** |
|
714 | + * Edit post if the key and created time match |
|
715 | + */ |
|
716 | + private static function maybe_editing_post( &$post ) { |
|
717 | 717 | $match_by = array( |
718 | - 'post_type' => $post['post_type'], |
|
719 | - 'name' => $post['post_name'], |
|
720 | - 'post_status' => $post['post_status'], |
|
721 | - 'posts_per_page' => 1, |
|
718 | + 'post_type' => $post['post_type'], |
|
719 | + 'name' => $post['post_name'], |
|
720 | + 'post_status' => $post['post_status'], |
|
721 | + 'posts_per_page' => 1, |
|
722 | 722 | ); |
723 | 723 | |
724 | 724 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
725 | - $match_by['include'] = $post['post_id']; |
|
726 | - unset($match_by['name']); |
|
725 | + $match_by['include'] = $post['post_id']; |
|
726 | + unset($match_by['name']); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | $editing = get_posts($match_by); |
730 | 730 | |
731 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
732 | - // set the id of the post to edit |
|
733 | - $post['ID'] = current($editing)->ID; |
|
734 | - } |
|
735 | - } |
|
731 | + if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
732 | + // set the id of the post to edit |
|
733 | + $post['ID'] = current($editing)->ID; |
|
734 | + } |
|
735 | + } |
|
736 | 736 | |
737 | - private static function update_postmeta( &$post, $post_id ) { |
|
738 | - foreach ( $post['postmeta'] as $k => $v ) { |
|
739 | - if ( '_edit_last' == $k ) { |
|
740 | - $v = FrmAppHelper::get_user_id_param($v); |
|
741 | - } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
742 | - //change the attachment ID |
|
743 | - $v = FrmProXMLHelper::get_file_id($v); |
|
744 | - } |
|
737 | + private static function update_postmeta( &$post, $post_id ) { |
|
738 | + foreach ( $post['postmeta'] as $k => $v ) { |
|
739 | + if ( '_edit_last' == $k ) { |
|
740 | + $v = FrmAppHelper::get_user_id_param($v); |
|
741 | + } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
|
742 | + //change the attachment ID |
|
743 | + $v = FrmProXMLHelper::get_file_id($v); |
|
744 | + } |
|
745 | 745 | |
746 | - update_post_meta($post_id, $k, $v); |
|
746 | + update_post_meta($post_id, $k, $v); |
|
747 | 747 | |
748 | - unset($k, $v); |
|
749 | - } |
|
750 | - } |
|
748 | + unset($k, $v); |
|
749 | + } |
|
750 | + } |
|
751 | 751 | |
752 | 752 | private static function maybe_update_stylesheet( $imported ) { |
753 | 753 | $new_styles = isset( $imported['imported']['styles'] ) && ! empty( $imported['imported']['styles'] ); |
@@ -763,72 +763,72 @@ discard block |
||
763 | 763 | } |
764 | 764 | } |
765 | 765 | |
766 | - /** |
|
767 | - * @param string $message |
|
768 | - */ |
|
766 | + /** |
|
767 | + * @param string $message |
|
768 | + */ |
|
769 | 769 | public static function parse_message( $result, &$message, &$errors ) { |
770 | - if ( is_wp_error($result) ) { |
|
771 | - $errors[] = $result->get_error_message(); |
|
772 | - } else if ( ! $result ) { |
|
773 | - return; |
|
774 | - } |
|
775 | - |
|
776 | - if ( ! is_array($result) ) { |
|
777 | - $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
778 | - return; |
|
779 | - } |
|
780 | - |
|
781 | - $t_strings = array( |
|
782 | - 'imported' => __( 'Imported', 'formidable' ), |
|
783 | - 'updated' => __( 'Updated', 'formidable' ), |
|
784 | - ); |
|
785 | - |
|
786 | - $message = '<ul>'; |
|
787 | - foreach ( $result as $type => $results ) { |
|
770 | + if ( is_wp_error($result) ) { |
|
771 | + $errors[] = $result->get_error_message(); |
|
772 | + } else if ( ! $result ) { |
|
773 | + return; |
|
774 | + } |
|
775 | + |
|
776 | + if ( ! is_array($result) ) { |
|
777 | + $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
|
778 | + return; |
|
779 | + } |
|
780 | + |
|
781 | + $t_strings = array( |
|
782 | + 'imported' => __( 'Imported', 'formidable' ), |
|
783 | + 'updated' => __( 'Updated', 'formidable' ), |
|
784 | + ); |
|
785 | + |
|
786 | + $message = '<ul>'; |
|
787 | + foreach ( $result as $type => $results ) { |
|
788 | 788 | if ( ! isset( $t_strings[ $type ] ) ) { |
789 | - // only print imported and updated |
|
790 | - continue; |
|
791 | - } |
|
789 | + // only print imported and updated |
|
790 | + continue; |
|
791 | + } |
|
792 | 792 | |
793 | - $s_message = array(); |
|
794 | - foreach ( $results as $k => $m ) { |
|
795 | - self::item_count_message($m, $k, $s_message); |
|
796 | - unset($k, $m); |
|
797 | - } |
|
793 | + $s_message = array(); |
|
794 | + foreach ( $results as $k => $m ) { |
|
795 | + self::item_count_message($m, $k, $s_message); |
|
796 | + unset($k, $m); |
|
797 | + } |
|
798 | 798 | |
799 | - if ( ! empty($s_message) ) { |
|
799 | + if ( ! empty($s_message) ) { |
|
800 | 800 | $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
801 | - $message .= implode(', ', $s_message); |
|
802 | - $message .= '</li>'; |
|
803 | - } |
|
804 | - } |
|
805 | - |
|
806 | - if ( $message == '<ul>' ) { |
|
807 | - $message = ''; |
|
808 | - $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
809 | - } else { |
|
810 | - $message .= '</ul>'; |
|
811 | - } |
|
812 | - } |
|
801 | + $message .= implode(', ', $s_message); |
|
802 | + $message .= '</li>'; |
|
803 | + } |
|
804 | + } |
|
805 | + |
|
806 | + if ( $message == '<ul>' ) { |
|
807 | + $message = ''; |
|
808 | + $errors[] = __( 'Nothing was imported or updated', 'formidable' ); |
|
809 | + } else { |
|
810 | + $message .= '</ul>'; |
|
811 | + } |
|
812 | + } |
|
813 | 813 | |
814 | 814 | public static function item_count_message( $m, $type, &$s_message ) { |
815 | - if ( ! $m ) { |
|
816 | - return; |
|
817 | - } |
|
818 | - |
|
819 | - $strings = array( |
|
820 | - 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
821 | - 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
822 | - 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
823 | - 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
824 | - 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
825 | - 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
826 | - 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
827 | - 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
828 | - ); |
|
815 | + if ( ! $m ) { |
|
816 | + return; |
|
817 | + } |
|
818 | + |
|
819 | + $strings = array( |
|
820 | + 'forms' => sprintf( _n( '%1$s Form', '%1$s Forms', $m, 'formidable' ), $m ), |
|
821 | + 'fields' => sprintf( _n( '%1$s Field', '%1$s Fields', $m, 'formidable' ), $m ), |
|
822 | + 'items' => sprintf( _n( '%1$s Entry', '%1$s Entries', $m, 'formidable' ), $m ), |
|
823 | + 'views' => sprintf( _n( '%1$s View', '%1$s Views', $m, 'formidable' ), $m ), |
|
824 | + 'posts' => sprintf( _n( '%1$s Post', '%1$s Posts', $m, 'formidable' ), $m ), |
|
825 | + 'styles' => sprintf( _n( '%1$s Style', '%1$s Styles', $m, 'formidable' ), $m ), |
|
826 | + 'terms' => sprintf( _n( '%1$s Term', '%1$s Terms', $m, 'formidable' ), $m ), |
|
827 | + 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
|
828 | + ); |
|
829 | 829 | |
830 | 830 | $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
831 | - } |
|
831 | + } |
|
832 | 832 | |
833 | 833 | /** |
834 | 834 | * Prepare the form options for export |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | } |
860 | 860 | |
861 | 861 | public static function cdata( $str ) { |
862 | - $str = maybe_unserialize($str); |
|
863 | - if ( is_array($str) ) { |
|
864 | - $str = json_encode($str); |
|
862 | + $str = maybe_unserialize($str); |
|
863 | + if ( is_array($str) ) { |
|
864 | + $str = json_encode($str); |
|
865 | 865 | } else if ( seems_utf8( $str ) == false ) { |
866 | 866 | $str = utf8_encode( $str ); |
867 | 867 | } |
868 | 868 | |
869 | - if ( is_numeric($str) ) { |
|
870 | - return $str; |
|
871 | - } |
|
869 | + if ( is_numeric($str) ) { |
|
870 | + return $str; |
|
871 | + } |
|
872 | 872 | |
873 | 873 | self::remove_invalid_characters_from_xml( $str ); |
874 | 874 | |
@@ -889,58 +889,58 @@ discard block |
||
889 | 889 | $str = str_replace( '\x1F', '', $str ); |
890 | 890 | } |
891 | 891 | |
892 | - public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
893 | - // Get post type |
|
894 | - $post_type = FrmFormActionsController::$action_post_type; |
|
895 | - |
|
896 | - // Set up imported index, if not set up yet |
|
897 | - if ( ! isset( $imported['imported']['actions'] ) ) { |
|
898 | - $imported['imported']['actions'] = 0; |
|
899 | - } |
|
900 | - |
|
901 | - // Migrate post settings to action |
|
902 | - self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
903 | - |
|
904 | - // Migrate email settings to action |
|
905 | - self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Migrate post settings to form action |
|
910 | - * |
|
911 | - * @param string $post_type |
|
912 | - */ |
|
913 | - private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
914 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
915 | - return; |
|
916 | - } |
|
917 | - |
|
918 | - $new_action = array( |
|
919 | - 'post_type' => $post_type, |
|
920 | - 'post_excerpt' => 'wppost', |
|
892 | + public static function migrate_form_settings_to_actions( $form_options, $form_id, &$imported = array(), $switch = false ) { |
|
893 | + // Get post type |
|
894 | + $post_type = FrmFormActionsController::$action_post_type; |
|
895 | + |
|
896 | + // Set up imported index, if not set up yet |
|
897 | + if ( ! isset( $imported['imported']['actions'] ) ) { |
|
898 | + $imported['imported']['actions'] = 0; |
|
899 | + } |
|
900 | + |
|
901 | + // Migrate post settings to action |
|
902 | + self::migrate_post_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
903 | + |
|
904 | + // Migrate email settings to action |
|
905 | + self::migrate_email_settings_to_action( $form_options, $form_id, $post_type, $imported, $switch ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Migrate post settings to form action |
|
910 | + * |
|
911 | + * @param string $post_type |
|
912 | + */ |
|
913 | + private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
914 | + if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
915 | + return; |
|
916 | + } |
|
917 | + |
|
918 | + $new_action = array( |
|
919 | + 'post_type' => $post_type, |
|
920 | + 'post_excerpt' => 'wppost', |
|
921 | 921 | 'post_title' => __( 'Create Posts', 'formidable' ), |
922 | - 'menu_order' => $form_id, |
|
923 | - 'post_status' => 'publish', |
|
924 | - 'post_content' => array(), |
|
922 | + 'menu_order' => $form_id, |
|
923 | + 'post_status' => 'publish', |
|
924 | + 'post_content' => array(), |
|
925 | 925 | 'post_name' => $form_id . '_wppost_1', |
926 | - ); |
|
926 | + ); |
|
927 | 927 | |
928 | - $post_settings = array( |
|
929 | - 'post_type', 'post_category', 'post_content', |
|
930 | - 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
928 | + $post_settings = array( |
|
929 | + 'post_type', 'post_category', 'post_content', |
|
930 | + 'post_excerpt', 'post_title', 'post_name', 'post_date', |
|
931 | 931 | 'post_status', 'post_custom_fields', 'post_password', |
932 | - ); |
|
932 | + ); |
|
933 | 933 | |
934 | - foreach ( $post_settings as $post_setting ) { |
|
934 | + foreach ( $post_settings as $post_setting ) { |
|
935 | 935 | if ( isset( $form_options[ $post_setting ] ) ) { |
936 | 936 | $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
937 | - } |
|
938 | - unset($post_setting); |
|
939 | - } |
|
937 | + } |
|
938 | + unset($post_setting); |
|
939 | + } |
|
940 | 940 | |
941 | 941 | $new_action['event'] = array( 'create', 'update' ); |
942 | 942 | |
943 | - if ( $switch ) { |
|
943 | + if ( $switch ) { |
|
944 | 944 | // Fields with string or int saved |
945 | 945 | $basic_fields = array( 'post_title', 'post_content', 'post_excerpt', 'post_password', 'post_date', 'post_status' ); |
946 | 946 | |
@@ -948,22 +948,22 @@ discard block |
||
948 | 948 | $array_fields = array( 'post_category', 'post_custom_fields' ); |
949 | 949 | |
950 | 950 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
951 | - } |
|
952 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
951 | + } |
|
952 | + $new_action['post_content'] = json_encode($new_action['post_content']); |
|
953 | 953 | |
954 | - $exists = get_posts( array( |
|
955 | - 'name' => $new_action['post_name'], |
|
956 | - 'post_type' => $new_action['post_type'], |
|
957 | - 'post_status' => $new_action['post_status'], |
|
958 | - 'numberposts' => 1, |
|
959 | - ) ); |
|
954 | + $exists = get_posts( array( |
|
955 | + 'name' => $new_action['post_name'], |
|
956 | + 'post_type' => $new_action['post_type'], |
|
957 | + 'post_status' => $new_action['post_status'], |
|
958 | + 'numberposts' => 1, |
|
959 | + ) ); |
|
960 | 960 | |
961 | - if ( ! $exists ) { |
|
961 | + if ( ! $exists ) { |
|
962 | 962 | // this isn't an email, but we need to use a class that will always be included |
963 | 963 | FrmAppHelper::save_json_post( $new_action ); |
964 | - $imported['imported']['actions']++; |
|
965 | - } |
|
966 | - } |
|
964 | + $imported['imported']['actions']++; |
|
965 | + } |
|
966 | + } |
|
967 | 967 | |
968 | 968 | /** |
969 | 969 | * Switch old field IDs for new field IDs in emails and post |
@@ -976,211 +976,211 @@ discard block |
||
976 | 976 | * @return string $post_content - new field IDs |
977 | 977 | */ |
978 | 978 | private static function switch_action_field_ids( $post_content, $basic_fields, $array_fields = array() ) { |
979 | - global $frm_duplicate_ids; |
|
979 | + global $frm_duplicate_ids; |
|
980 | 980 | |
981 | - // If there aren't IDs that were switched, end now |
|
982 | - if ( ! $frm_duplicate_ids ) { |
|
983 | - return; |
|
984 | - } |
|
981 | + // If there aren't IDs that were switched, end now |
|
982 | + if ( ! $frm_duplicate_ids ) { |
|
983 | + return; |
|
984 | + } |
|
985 | 985 | |
986 | - // Get old IDs |
|
987 | - $old = array_keys( $frm_duplicate_ids ); |
|
986 | + // Get old IDs |
|
987 | + $old = array_keys( $frm_duplicate_ids ); |
|
988 | 988 | |
989 | - // Get new IDs |
|
990 | - $new = array_values( $frm_duplicate_ids ); |
|
989 | + // Get new IDs |
|
990 | + $new = array_values( $frm_duplicate_ids ); |
|
991 | 991 | |
992 | - // Do a str_replace with each item to set the new IDs |
|
993 | - foreach ( $post_content as $key => $setting ) { |
|
994 | - if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
995 | - // Replace old IDs with new IDs |
|
992 | + // Do a str_replace with each item to set the new IDs |
|
993 | + foreach ( $post_content as $key => $setting ) { |
|
994 | + if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
|
995 | + // Replace old IDs with new IDs |
|
996 | 996 | $post_content[ $key ] = str_replace( $old, $new, $setting ); |
997 | - } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
998 | - foreach ( $setting as $k => $val ) { |
|
999 | - // Replace old IDs with new IDs |
|
997 | + } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
|
998 | + foreach ( $setting as $k => $val ) { |
|
999 | + // Replace old IDs with new IDs |
|
1000 | 1000 | $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
1001 | - } |
|
1002 | - } |
|
1003 | - unset( $key, $setting ); |
|
1004 | - } |
|
1005 | - return $post_content; |
|
1006 | - } |
|
1007 | - |
|
1008 | - private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
1009 | - // No old notifications or autoresponders to carry over |
|
1001 | + } |
|
1002 | + } |
|
1003 | + unset( $key, $setting ); |
|
1004 | + } |
|
1005 | + return $post_content; |
|
1006 | + } |
|
1007 | + |
|
1008 | + private static function migrate_email_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
|
1009 | + // No old notifications or autoresponders to carry over |
|
1010 | 1010 | if ( ! isset( $form_options['auto_responder'] ) && ! isset( $form_options['notification'] ) && ! isset( $form_options['email_to'] ) ) { |
1011 | - return; |
|
1012 | - } |
|
1011 | + return; |
|
1012 | + } |
|
1013 | 1013 | |
1014 | - // Initialize notifications array |
|
1015 | - $notifications = array(); |
|
1014 | + // Initialize notifications array |
|
1015 | + $notifications = array(); |
|
1016 | 1016 | |
1017 | - // Migrate regular notifications |
|
1018 | - self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
1017 | + // Migrate regular notifications |
|
1018 | + self::migrate_notifications_to_action( $form_options, $form_id, $notifications ); |
|
1019 | 1019 | |
1020 | - // Migrate autoresponders |
|
1021 | - self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
1020 | + // Migrate autoresponders |
|
1021 | + self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
|
1022 | 1022 | |
1023 | - if ( empty( $notifications ) ) { |
|
1024 | - return; |
|
1025 | - } |
|
1023 | + if ( empty( $notifications ) ) { |
|
1024 | + return; |
|
1025 | + } |
|
1026 | 1026 | |
1027 | - foreach ( $notifications as $new_notification ) { |
|
1028 | - $new_notification['post_type'] = $post_type; |
|
1029 | - $new_notification['post_excerpt'] = 'email'; |
|
1027 | + foreach ( $notifications as $new_notification ) { |
|
1028 | + $new_notification['post_type'] = $post_type; |
|
1029 | + $new_notification['post_excerpt'] = 'email'; |
|
1030 | 1030 | $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
1031 | - $new_notification['menu_order'] = $form_id; |
|
1032 | - $new_notification['post_status'] = 'publish'; |
|
1031 | + $new_notification['menu_order'] = $form_id; |
|
1032 | + $new_notification['post_status'] = 'publish'; |
|
1033 | 1033 | |
1034 | - // Switch field IDs and keys, if needed |
|
1035 | - if ( $switch ) { |
|
1034 | + // Switch field IDs and keys, if needed |
|
1035 | + if ( $switch ) { |
|
1036 | 1036 | |
1037 | 1037 | // Switch field IDs in email conditional logic |
1038 | 1038 | self::switch_email_contition_field_ids( $new_notification['post_content'] ); |
1039 | 1039 | |
1040 | 1040 | // Switch all other field IDs in email |
1041 | - $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
1042 | - } |
|
1043 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | - |
|
1045 | - $exists = get_posts( array( |
|
1046 | - 'name' => $new_notification['post_name'], |
|
1047 | - 'post_type' => $new_notification['post_type'], |
|
1048 | - 'post_status' => $new_notification['post_status'], |
|
1049 | - 'numberposts' => 1, |
|
1050 | - ) ); |
|
1051 | - |
|
1052 | - if ( empty($exists) ) { |
|
1041 | + $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
|
1042 | + } |
|
1043 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | + |
|
1045 | + $exists = get_posts( array( |
|
1046 | + 'name' => $new_notification['post_name'], |
|
1047 | + 'post_type' => $new_notification['post_type'], |
|
1048 | + 'post_status' => $new_notification['post_status'], |
|
1049 | + 'numberposts' => 1, |
|
1050 | + ) ); |
|
1051 | + |
|
1052 | + if ( empty($exists) ) { |
|
1053 | 1053 | FrmAppHelper::save_json_post( $new_notification ); |
1054 | - $imported['imported']['actions']++; |
|
1055 | - } |
|
1056 | - unset($new_notification); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - |
|
1060 | - private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
1061 | - if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
1062 | - // add old settings into notification array |
|
1054 | + $imported['imported']['actions']++; |
|
1055 | + } |
|
1056 | + unset($new_notification); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + |
|
1060 | + private static function migrate_notifications_to_action( $form_options, $form_id, &$notifications ) { |
|
1061 | + if ( ! isset( $form_options['notification'] ) && isset( $form_options['email_to'] ) && ! empty( $form_options['email_to'] ) ) { |
|
1062 | + // add old settings into notification array |
|
1063 | 1063 | $form_options['notification'] = array( 0 => $form_options ); |
1064 | - } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
1065 | - // make sure it's in the correct format |
|
1064 | + } else if ( isset( $form_options['notification']['email_to'] ) ) { |
|
1065 | + // make sure it's in the correct format |
|
1066 | 1066 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
1067 | - } |
|
1067 | + } |
|
1068 | 1068 | |
1069 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1070 | - foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
1069 | + if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1070 | + foreach ( $form_options['notification'] as $email_key => $notification ) { |
|
1071 | 1071 | |
1072 | - $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
1072 | + $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
|
1073 | 1073 | |
1074 | - // Format the email data |
|
1075 | - self::format_email_data( $atts, $notification ); |
|
1074 | + // Format the email data |
|
1075 | + self::format_email_data( $atts, $notification ); |
|
1076 | 1076 | |
1077 | 1077 | if ( isset( $notification['twilio'] ) && $notification['twilio'] ) { |
1078 | 1078 | do_action( 'frm_create_twilio_action', $atts, $notification ); |
1079 | 1079 | } |
1080 | 1080 | |
1081 | - // Setup the new notification |
|
1082 | - $new_notification = array(); |
|
1083 | - self::setup_new_notification( $new_notification, $notification, $atts ); |
|
1081 | + // Setup the new notification |
|
1082 | + $new_notification = array(); |
|
1083 | + self::setup_new_notification( $new_notification, $notification, $atts ); |
|
1084 | 1084 | |
1085 | - $notifications[] = $new_notification; |
|
1086 | - } |
|
1087 | - } |
|
1088 | - } |
|
1085 | + $notifications[] = $new_notification; |
|
1086 | + } |
|
1087 | + } |
|
1088 | + } |
|
1089 | 1089 | |
1090 | - private static function format_email_data( &$atts, $notification ) { |
|
1091 | - // Format email_to |
|
1092 | - self::format_email_to_data( $atts, $notification ); |
|
1090 | + private static function format_email_data( &$atts, $notification ) { |
|
1091 | + // Format email_to |
|
1092 | + self::format_email_to_data( $atts, $notification ); |
|
1093 | 1093 | |
1094 | - // Format the reply to email and name |
|
1095 | - $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
1096 | - foreach ( $reply_fields as $f => $val ) { |
|
1094 | + // Format the reply to email and name |
|
1095 | + $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
|
1096 | + foreach ( $reply_fields as $f => $val ) { |
|
1097 | 1097 | if ( isset( $notification[ $f ] ) ) { |
1098 | 1098 | $atts[ $f ] = $notification[ $f ]; |
1099 | 1099 | if ( 'custom' == $notification[ $f ] ) { |
1100 | 1100 | $atts[ $f ] = $notification[ 'cust_' . $f ]; |
1101 | 1101 | } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
1102 | 1102 | $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
1103 | - } |
|
1104 | - } |
|
1105 | - unset( $f, $val ); |
|
1106 | - } |
|
1103 | + } |
|
1104 | + } |
|
1105 | + unset( $f, $val ); |
|
1106 | + } |
|
1107 | 1107 | |
1108 | - // Format event |
|
1108 | + // Format event |
|
1109 | 1109 | $atts['event'] = array( 'create' ); |
1110 | - if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
1111 | - $atts['event'][] = 'update'; |
|
1112 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1110 | + if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
|
1111 | + $atts['event'][] = 'update'; |
|
1112 | + } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1113 | 1113 | $atts['event'] = array( 'update' ); |
1114 | - } |
|
1115 | - } |
|
1114 | + } |
|
1115 | + } |
|
1116 | 1116 | |
1117 | - private static function format_email_to_data( &$atts, $notification ) { |
|
1118 | - if ( isset( $notification['email_to'] ) ) { |
|
1117 | + private static function format_email_to_data( &$atts, $notification ) { |
|
1118 | + if ( isset( $notification['email_to'] ) ) { |
|
1119 | 1119 | $atts['email_to'] = preg_split( '/ (,|;) /', $notification['email_to'] ); |
1120 | - } else { |
|
1121 | - $atts['email_to'] = array(); |
|
1122 | - } |
|
1120 | + } else { |
|
1121 | + $atts['email_to'] = array(); |
|
1122 | + } |
|
1123 | 1123 | |
1124 | - if ( isset( $notification['also_email_to'] ) ) { |
|
1125 | - $email_fields = (array) $notification['also_email_to']; |
|
1126 | - $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
1127 | - unset( $email_fields ); |
|
1128 | - } |
|
1124 | + if ( isset( $notification['also_email_to'] ) ) { |
|
1125 | + $email_fields = (array) $notification['also_email_to']; |
|
1126 | + $atts['email_to'] = array_merge( $email_fields, $atts['email_to'] ); |
|
1127 | + unset( $email_fields ); |
|
1128 | + } |
|
1129 | 1129 | |
1130 | - foreach ( $atts['email_to'] as $key => $email_field ) { |
|
1130 | + foreach ( $atts['email_to'] as $key => $email_field ) { |
|
1131 | 1131 | |
1132 | - if ( is_numeric( $email_field ) ) { |
|
1132 | + if ( is_numeric( $email_field ) ) { |
|
1133 | 1133 | $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
1134 | - } |
|
1134 | + } |
|
1135 | 1135 | |
1136 | - if ( strpos( $email_field, '|') ) { |
|
1137 | - $email_opt = explode( '|', $email_field ); |
|
1138 | - if ( isset( $email_opt[0] ) ) { |
|
1136 | + if ( strpos( $email_field, '|') ) { |
|
1137 | + $email_opt = explode( '|', $email_field ); |
|
1138 | + if ( isset( $email_opt[0] ) ) { |
|
1139 | 1139 | $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
1140 | - } |
|
1141 | - unset( $email_opt ); |
|
1142 | - } |
|
1143 | - } |
|
1144 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1145 | - } |
|
1146 | - |
|
1147 | - private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
1148 | - // Set up new notification |
|
1149 | - $new_notification = array( |
|
1150 | - 'post_content' => array( |
|
1151 | - 'email_to' => $atts['email_to'], |
|
1152 | - 'event' => $atts['event'], |
|
1153 | - ), |
|
1140 | + } |
|
1141 | + unset( $email_opt ); |
|
1142 | + } |
|
1143 | + } |
|
1144 | + $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1145 | + } |
|
1146 | + |
|
1147 | + private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
|
1148 | + // Set up new notification |
|
1149 | + $new_notification = array( |
|
1150 | + 'post_content' => array( |
|
1151 | + 'email_to' => $atts['email_to'], |
|
1152 | + 'event' => $atts['event'], |
|
1153 | + ), |
|
1154 | 1154 | 'post_name' => $atts['form_id'] . '_email_' . $atts['email_key'], |
1155 | - ); |
|
1155 | + ); |
|
1156 | 1156 | |
1157 | - // Add more fields to the new notification |
|
1158 | - $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
1159 | - foreach ( $add_fields as $add_field ) { |
|
1157 | + // Add more fields to the new notification |
|
1158 | + $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
|
1159 | + foreach ( $add_fields as $add_field ) { |
|
1160 | 1160 | if ( isset( $notification[ $add_field ] ) ) { |
1161 | 1161 | $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
1162 | - } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
1162 | + } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
|
1163 | 1163 | $new_notification['post_content'][ $add_field ] = 0; |
1164 | - } else { |
|
1164 | + } else { |
|
1165 | 1165 | $new_notification['post_content'][ $add_field ] = ''; |
1166 | - } |
|
1167 | - unset( $add_field ); |
|
1168 | - } |
|
1166 | + } |
|
1167 | + unset( $add_field ); |
|
1168 | + } |
|
1169 | 1169 | |
1170 | 1170 | // Set reply to |
1171 | 1171 | $new_notification['post_content']['reply_to'] = $atts['reply_to']; |
1172 | 1172 | |
1173 | - // Set from |
|
1173 | + // Set from |
|
1174 | 1174 | if ( ! empty( $atts['reply_to'] ) || ! empty( $atts['reply_to_name'] ) ) { |
1175 | 1175 | $new_notification['post_content']['from'] = ( empty( $atts['reply_to_name'] ) ? '[sitename]' : $atts['reply_to_name'] ) . ' <' . ( empty( $atts['reply_to'] ) ? '[admin_email]' : $atts['reply_to'] ) . '>'; |
1176 | - } |
|
1177 | - } |
|
1176 | + } |
|
1177 | + } |
|
1178 | 1178 | |
1179 | 1179 | /** |
1180 | - * Switch field IDs in pre-2.0 email conditional logic |
|
1181 | - * |
|
1182 | - * @param $post_content array, pass by reference |
|
1183 | - */ |
|
1180 | + * Switch field IDs in pre-2.0 email conditional logic |
|
1181 | + * |
|
1182 | + * @param $post_content array, pass by reference |
|
1183 | + */ |
|
1184 | 1184 | private static function switch_email_contition_field_ids( &$post_content ) { |
1185 | 1185 | // Switch field IDs in conditional logic |
1186 | 1186 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
@@ -1193,36 +1193,36 @@ discard block |
||
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
1197 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1198 | - // migrate autoresponder |
|
1199 | - |
|
1200 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | - if ( strpos($email_field, '|') ) { |
|
1202 | - // data from entries field |
|
1203 | - $email_field = explode('|', $email_field); |
|
1204 | - if ( isset($email_field[1]) ) { |
|
1205 | - $email_field = $email_field[1]; |
|
1206 | - } |
|
1207 | - } |
|
1208 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1196 | + private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
|
1197 | + if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1198 | + // migrate autoresponder |
|
1199 | + |
|
1200 | + $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | + if ( strpos($email_field, '|') ) { |
|
1202 | + // data from entries field |
|
1203 | + $email_field = explode('|', $email_field); |
|
1204 | + if ( isset($email_field[1]) ) { |
|
1205 | + $email_field = $email_field[1]; |
|
1206 | + } |
|
1207 | + } |
|
1208 | + if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1209 | 1209 | $email_field = '[' . $email_field . ']'; |
1210 | - } |
|
1211 | - |
|
1212 | - $notification = $form_options; |
|
1213 | - $new_notification2 = array( |
|
1214 | - 'post_content' => array( |
|
1215 | - 'email_message' => $notification['ar_email_message'], |
|
1216 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1217 | - 'email_to' => $email_field, |
|
1218 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1219 | - 'inc_user_info' => 0, |
|
1220 | - ), |
|
1210 | + } |
|
1211 | + |
|
1212 | + $notification = $form_options; |
|
1213 | + $new_notification2 = array( |
|
1214 | + 'post_content' => array( |
|
1215 | + 'email_message' => $notification['ar_email_message'], |
|
1216 | + 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1217 | + 'email_to' => $email_field, |
|
1218 | + 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1219 | + 'inc_user_info' => 0, |
|
1220 | + ), |
|
1221 | 1221 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
1222 | - ); |
|
1222 | + ); |
|
1223 | 1223 | |
1224 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1224 | + $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | + $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1226 | 1226 | |
1227 | 1227 | if ( ! empty( $reply_to ) ) { |
1228 | 1228 | $new_notification2['post_content']['reply_to'] = $reply_to; |
@@ -1232,9 +1232,9 @@ discard block |
||
1232 | 1232 | $new_notification2['post_content']['from'] = ( empty( $reply_to_name ) ? '[sitename]' : $reply_to_name ) . ' <' . ( empty( $reply_to ) ? '[admin_email]' : $reply_to ) . '>'; |
1233 | 1233 | } |
1234 | 1234 | |
1235 | - $notifications[] = $new_notification2; |
|
1236 | - unset( $new_notification2 ); |
|
1237 | - } |
|
1238 | - } |
|
1235 | + $notifications[] = $new_notification2; |
|
1236 | + unset( $new_notification2 ); |
|
1237 | + } |
|
1238 | + } |
|
1239 | 1239 | } |
1240 | 1240 |
@@ -1,5 +1,5 @@ discard block |
||
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 |
||
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 |
||
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,14 +67,14 @@ discard block |
||
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 | } |
@@ -91,11 +91,11 @@ discard block |
||
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 ); |
@@ -142,9 +142,9 @@ discard block |
||
142 | 142 | } else { |
143 | 143 | $form_id = FrmForm::create( $form ); |
144 | 144 | if ( $form_id ) { |
145 | - $imported['imported']['forms']++; |
|
145 | + $imported['imported']['forms'] ++; |
|
146 | 146 | // Keep track of whether this specific form was updated or not |
147 | - $imported['form_status'][ $form_id ] = 'imported'; |
|
147 | + $imported['form_status'][$form_id] = 'imported'; |
|
148 | 148 | self::track_imported_child_forms( (int) $form_id, $form['parent_form_id'], $child_forms ); |
149 | 149 | } |
150 | 150 | } |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | // Update field ids/keys to new ones |
157 | 157 | do_action( 'frm_after_duplicate_form', $form_id, $form, array( 'old_id' => $old_id ) ); |
158 | 158 | |
159 | - $imported['forms'][ (int) $item->id ] = $form_id; |
|
159 | + $imported['forms'][(int) $item->id] = $form_id; |
|
160 | 160 | |
161 | 161 | // Send pre 2.0 form options through function that creates actions |
162 | 162 | self::migrate_form_settings_to_actions( $form['options'], $form_id, $imported, $switch = true ); |
163 | 163 | |
164 | 164 | do_action( 'frm_after_import_form', $form_id, $form ); |
165 | 165 | |
166 | - unset($form, $item); |
|
166 | + unset( $form, $item ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | self::maybe_update_child_form_parent_id( $imported['forms'], $child_forms ); |
@@ -205,18 +205,18 @@ discard block |
||
205 | 205 | private static function update_form( $this_form, $form, &$imported ) { |
206 | 206 | $form_id = $this_form->id; |
207 | 207 | FrmForm::update( $form_id, $form ); |
208 | - $imported['updated']['forms']++; |
|
208 | + $imported['updated']['forms'] ++; |
|
209 | 209 | // Keep track of whether this specific form was updated or not |
210 | - $imported['form_status'][ $form_id ] = 'updated'; |
|
210 | + $imported['form_status'][$form_id] = 'updated'; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | private static function get_form_fields( $form_id ) { |
214 | 214 | $form_fields = FrmField::get_all_for_form( $form_id, '', 'exclude', 'exclude' ); |
215 | 215 | $old_fields = array(); |
216 | 216 | foreach ( $form_fields as $f ) { |
217 | - $old_fields[ $f->id ] = $f; |
|
218 | - $old_fields[ $f->field_key ] = $f->id; |
|
219 | - unset($f); |
|
217 | + $old_fields[$f->id] = $f; |
|
218 | + $old_fields[$f->field_key] = $f->id; |
|
219 | + unset( $f ); |
|
220 | 220 | } |
221 | 221 | $form_fields = $old_fields; |
222 | 222 | return $form_fields; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | $regular_forms = array(); |
248 | 248 | |
249 | 249 | foreach ( $forms as $form ) { |
250 | - $parent_form_id = isset( $form->parent_form_id) ? (int) $form->parent_form_id : 0; |
|
250 | + $parent_form_id = isset( $form->parent_form_id ) ? (int) $form->parent_form_id : 0; |
|
251 | 251 | |
252 | 252 | if ( $parent_form_id ) { |
253 | 253 | $child_forms[] = $form; |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | private static function track_imported_child_forms( $form_id, $parent_form_id, &$child_forms ) { |
271 | 271 | if ( $parent_form_id ) { |
272 | - $child_forms[ $form_id ] = $parent_form_id; |
|
272 | + $child_forms[$form_id] = $parent_form_id; |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | private static function maybe_update_child_form_parent_id( $imported_forms, $child_forms ) { |
285 | 285 | foreach ( $child_forms as $child_form_id => $old_parent_form_id ) { |
286 | 286 | |
287 | - if ( isset( $imported_forms[ $old_parent_form_id ] ) && $imported_forms[ $old_parent_form_id ] != $old_parent_form_id ) { |
|
287 | + if ( isset( $imported_forms[$old_parent_form_id] ) && $imported_forms[$old_parent_form_id] != $old_parent_form_id ) { |
|
288 | 288 | // Update all children with this old parent_form_id |
289 | - $new_parent_form_id = (int) $imported_forms[ $old_parent_form_id ]; |
|
289 | + $new_parent_form_id = (int) $imported_forms[$old_parent_form_id]; |
|
290 | 290 | |
291 | 291 | FrmForm::update( $child_form_id, array( 'parent_form_id' => $new_parent_form_id ) ); |
292 | 292 | } |
@@ -305,15 +305,15 @@ discard block |
||
305 | 305 | foreach ( $xml_fields as $field ) { |
306 | 306 | $f = self::fill_field( $field, $form_id ); |
307 | 307 | |
308 | - if ( is_array($f['default_value']) && in_array($f['type'], array( |
|
308 | + if ( is_array( $f['default_value'] ) && in_array( $f['type'], array( |
|
309 | 309 | 'text', 'email', 'url', 'textarea', |
310 | - 'number','phone', 'date', 'time', |
|
310 | + 'number', 'phone', 'date', 'time', |
|
311 | 311 | 'hidden', 'password', 'tag', 'image', |
312 | - )) ) { |
|
313 | - if ( count($f['default_value']) === 1 ) { |
|
312 | + ) ) ) { |
|
313 | + if ( count( $f['default_value'] ) === 1 ) { |
|
314 | 314 | $f['default_value'] = '[' . reset( $f['default_value'] ) . ']'; |
315 | 315 | } else { |
316 | - $f['default_value'] = reset($f['default_value']); |
|
316 | + $f['default_value'] = reset( $f['default_value'] ); |
|
317 | 317 | } |
318 | 318 | } |
319 | 319 | |
@@ -321,27 +321,27 @@ discard block |
||
321 | 321 | self::maybe_update_form_select( $f, $imported ); |
322 | 322 | self::maybe_update_get_values_form_setting( $imported, $f ); |
323 | 323 | |
324 | - if ( ! empty($this_form) ) { |
|
324 | + if ( ! empty( $this_form ) ) { |
|
325 | 325 | // check for field to edit by field id |
326 | - if ( isset( $form_fields[ $f['id'] ] ) ) { |
|
326 | + if ( isset( $form_fields[$f['id']] ) ) { |
|
327 | 327 | FrmField::update( $f['id'], $f ); |
328 | - $imported['updated']['fields']++; |
|
328 | + $imported['updated']['fields'] ++; |
|
329 | 329 | |
330 | - unset( $form_fields[ $f['id'] ] ); |
|
330 | + unset( $form_fields[$f['id']] ); |
|
331 | 331 | |
332 | 332 | //unset old field key |
333 | - if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
334 | - unset( $form_fields[ $f['field_key'] ] ); |
|
333 | + if ( isset( $form_fields[$f['field_key']] ) ) { |
|
334 | + unset( $form_fields[$f['field_key']] ); |
|
335 | 335 | } |
336 | - } else if ( isset( $form_fields[ $f['field_key'] ] ) ) { |
|
336 | + } else if ( isset( $form_fields[$f['field_key']] ) ) { |
|
337 | 337 | // check for field to edit by field key |
338 | - unset($f['id']); |
|
338 | + unset( $f['id'] ); |
|
339 | 339 | |
340 | - FrmField::update( $form_fields[ $f['field_key'] ], $f ); |
|
341 | - $imported['updated']['fields']++; |
|
340 | + FrmField::update( $form_fields[$f['field_key']], $f ); |
|
341 | + $imported['updated']['fields'] ++; |
|
342 | 342 | |
343 | - unset( $form_fields[ $form_fields[ $f['field_key'] ] ] ); //unset old field id |
|
344 | - unset( $form_fields[ $f['field_key'] ] ); //unset old field key |
|
343 | + unset( $form_fields[$form_fields[$f['field_key']]] ); //unset old field id |
|
344 | + unset( $form_fields[$f['field_key']] ); //unset old field key |
|
345 | 345 | } else { |
346 | 346 | // if no matching field id or key in this form, create the field |
347 | 347 | self::create_imported_field( $f, $imported ); |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | 'name' => (string) $field->name, |
361 | 361 | 'description' => (string) $field->description, |
362 | 362 | 'type' => (string) $field->type, |
363 | - 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value), |
|
363 | + 'default_value' => FrmAppHelper::maybe_json_decode( (string) $field->default_value ), |
|
364 | 364 | 'field_order' => (int) $field->field_order, |
365 | 365 | 'form_id' => (int) $form_id, |
366 | 366 | 'required' => (int) $field->required, |
367 | - 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options), |
|
367 | + 'options' => FrmAppHelper::maybe_json_decode( (string) $field->options ), |
|
368 | 368 | 'field_options' => FrmAppHelper::maybe_json_decode( (string) $field->field_options ), |
369 | 369 | ); |
370 | 370 | } |
@@ -408,8 +408,8 @@ discard block |
||
408 | 408 | if ( $f['type'] == 'form' || ( $f['type'] == 'divider' && FrmField::is_option_true( $f['field_options'], 'repeat' ) ) ) { |
409 | 409 | if ( FrmField::is_option_true( $f['field_options'], 'form_select' ) ) { |
410 | 410 | $form_select = $f['field_options']['form_select']; |
411 | - if ( isset( $imported['forms'][ $form_select ] ) ) { |
|
412 | - $f['field_options']['form_select'] = $imported['forms'][ $form_select ]; |
|
411 | + if ( isset( $imported['forms'][$form_select] ) ) { |
|
412 | + $f['field_options']['form_select'] = $imported['forms'][$form_select]; |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | } |
@@ -429,8 +429,8 @@ discard block |
||
429 | 429 | |
430 | 430 | if ( FrmField::is_option_true_in_array( $f['field_options'], 'get_values_form' ) ) { |
431 | 431 | $old_form = $f['field_options']['get_values_form']; |
432 | - if ( isset( $imported['forms'][ $old_form ] ) ) { |
|
433 | - $f['field_options']['get_values_form'] = $imported['forms'][ $old_form ]; |
|
432 | + if ( isset( $imported['forms'][$old_form] ) ) { |
|
433 | + $f['field_options']['get_values_form'] = $imported['forms'][$old_form]; |
|
434 | 434 | } |
435 | 435 | } |
436 | 436 | } |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | private static function create_imported_field( $f, &$imported ) { |
446 | 446 | $new_id = FrmField::create( $f ); |
447 | 447 | if ( $new_id != false ) { |
448 | - $imported['imported']['fields']++; |
|
448 | + $imported['imported']['fields'] ++; |
|
449 | 449 | do_action( 'frm_after_field_is_imported', $f, $new_id ); |
450 | 450 | } |
451 | 451 | } |
@@ -544,9 +544,9 @@ discard block |
||
544 | 544 | ); |
545 | 545 | |
546 | 546 | $old_id = $post['post_id']; |
547 | - self::populate_post($post, $item, $imported); |
|
547 | + self::populate_post( $post, $item, $imported ); |
|
548 | 548 | |
549 | - unset($item); |
|
549 | + unset( $item ); |
|
550 | 550 | |
551 | 551 | $post_id = false; |
552 | 552 | if ( $post['post_type'] == $form_action_type ) { |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | if ( $action_control && is_object( $action_control ) ) { |
555 | 555 | $post_id = $action_control->maybe_create_action( $post, $imported['form_status'] ); |
556 | 556 | } |
557 | - unset($action_control); |
|
557 | + unset( $action_control ); |
|
558 | 558 | } else if ( $post['post_type'] == 'frm_styles' ) { |
559 | 559 | // Properly encode post content before inserting the post |
560 | 560 | $post['post_content'] = FrmAppHelper::maybe_json_decode( $post['post_content'] ); |
@@ -567,26 +567,26 @@ discard block |
||
567 | 567 | $post_id = wp_insert_post( $post ); |
568 | 568 | } |
569 | 569 | |
570 | - if ( ! is_numeric($post_id) ) { |
|
570 | + if ( ! is_numeric( $post_id ) ) { |
|
571 | 571 | continue; |
572 | 572 | } |
573 | 573 | |
574 | - self::update_postmeta($post, $post_id); |
|
574 | + self::update_postmeta( $post, $post_id ); |
|
575 | 575 | |
576 | 576 | $this_type = 'posts'; |
577 | - if ( isset( $post_types[ $post['post_type'] ] ) ) { |
|
578 | - $this_type = $post_types[ $post['post_type'] ]; |
|
577 | + if ( isset( $post_types[$post['post_type']] ) ) { |
|
578 | + $this_type = $post_types[$post['post_type']]; |
|
579 | 579 | } |
580 | 580 | |
581 | - if ( isset($post['ID']) && $post_id == $post['ID'] ) { |
|
582 | - $imported['updated'][ $this_type ]++; |
|
581 | + if ( isset( $post['ID'] ) && $post_id == $post['ID'] ) { |
|
582 | + $imported['updated'][$this_type] ++; |
|
583 | 583 | } else { |
584 | - $imported['imported'][ $this_type ]++; |
|
584 | + $imported['imported'][$this_type] ++; |
|
585 | 585 | } |
586 | 586 | |
587 | - unset($post); |
|
587 | + unset( $post ); |
|
588 | 588 | |
589 | - $imported['posts'][ (int) $old_id ] = $post_id; |
|
589 | + $imported['posts'][(int) $old_id] = $post_id; |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | self::maybe_update_stylesheet( $imported ); |
@@ -595,13 +595,13 @@ discard block |
||
595 | 595 | } |
596 | 596 | |
597 | 597 | private static function populate_post( &$post, $item, $imported ) { |
598 | - if ( isset($item->attachment_url) ) { |
|
598 | + if ( isset( $item->attachment_url ) ) { |
|
599 | 599 | $post['attachment_url'] = (string) $item->attachment_url; |
600 | 600 | } |
601 | 601 | |
602 | - if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][ (int) $post['menu_order'] ] ) ) { |
|
602 | + if ( $post['post_type'] == FrmFormActionsController::$action_post_type && isset( $imported['forms'][(int) $post['menu_order']] ) ) { |
|
603 | 603 | // update to new form id |
604 | - $post['menu_order'] = $imported['forms'][ (int) $post['menu_order'] ]; |
|
604 | + $post['menu_order'] = $imported['forms'][(int) $post['menu_order']]; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // Don't allow default styles to take over a site's default style |
@@ -610,13 +610,13 @@ discard block |
||
610 | 610 | } |
611 | 611 | |
612 | 612 | foreach ( $item->postmeta as $meta ) { |
613 | - self::populate_postmeta($post, $meta, $imported); |
|
614 | - unset($meta); |
|
613 | + self::populate_postmeta( $post, $meta, $imported ); |
|
614 | + unset( $meta ); |
|
615 | 615 | } |
616 | 616 | |
617 | - self::populate_taxonomies($post, $item); |
|
617 | + self::populate_taxonomies( $post, $item ); |
|
618 | 618 | |
619 | - self::maybe_editing_post($post); |
|
619 | + self::maybe_editing_post( $post ); |
|
620 | 620 | } |
621 | 621 | |
622 | 622 | private static function populate_postmeta( &$post, $meta, $imported ) { |
@@ -628,27 +628,27 @@ discard block |
||
628 | 628 | ); |
629 | 629 | |
630 | 630 | //switch old form and field ids to new ones |
631 | - if ( $m['key'] == 'frm_form_id' && isset($imported['forms'][ (int) $m['value'] ]) ) { |
|
632 | - $m['value'] = $imported['forms'][ (int) $m['value'] ]; |
|
631 | + if ( $m['key'] == 'frm_form_id' && isset( $imported['forms'][(int) $m['value']] ) ) { |
|
632 | + $m['value'] = $imported['forms'][(int) $m['value']]; |
|
633 | 633 | } else { |
634 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
634 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
635 | 635 | |
636 | - if ( ! empty($frm_duplicate_ids) ) { |
|
636 | + if ( ! empty( $frm_duplicate_ids ) ) { |
|
637 | 637 | |
638 | 638 | if ( $m['key'] == 'frm_dyncontent' ) { |
639 | - $m['value'] = FrmFieldsHelper::switch_field_ids($m['value']); |
|
639 | + $m['value'] = FrmFieldsHelper::switch_field_ids( $m['value'] ); |
|
640 | 640 | } else if ( $m['key'] == 'frm_options' ) { |
641 | 641 | |
642 | 642 | foreach ( array( 'date_field_id', 'edate_field_id' ) as $setting_name ) { |
643 | - if ( isset( $m['value'][ $setting_name ] ) && is_numeric( $m['value'][ $setting_name ] ) && isset( $frm_duplicate_ids[ $m['value'][ $setting_name ] ] ) ) { |
|
644 | - $m['value'][ $setting_name ] = $frm_duplicate_ids[ $m['value'][ $setting_name ] ]; |
|
643 | + if ( isset( $m['value'][$setting_name] ) && is_numeric( $m['value'][$setting_name] ) && isset( $frm_duplicate_ids[$m['value'][$setting_name]] ) ) { |
|
644 | + $m['value'][$setting_name] = $frm_duplicate_ids[$m['value'][$setting_name]]; |
|
645 | 645 | } |
646 | 646 | } |
647 | 647 | |
648 | 648 | $check_dup_array = array(); |
649 | 649 | if ( isset( $m['value']['order_by'] ) && ! empty( $m['value']['order_by'] ) ) { |
650 | - if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[ $m['value']['order_by'] ] ) ) { |
|
651 | - $m['value']['order_by'] = $frm_duplicate_ids[ $m['value']['order_by'] ]; |
|
650 | + if ( is_numeric( $m['value']['order_by'] ) && isset( $frm_duplicate_ids[$m['value']['order_by']] ) ) { |
|
651 | + $m['value']['order_by'] = $frm_duplicate_ids[$m['value']['order_by']]; |
|
652 | 652 | } else if ( is_array( $m['value']['order_by'] ) ) { |
653 | 653 | $check_dup_array[] = 'order_by'; |
654 | 654 | } |
@@ -659,22 +659,22 @@ discard block |
||
659 | 659 | } |
660 | 660 | |
661 | 661 | foreach ( $check_dup_array as $check_k ) { |
662 | - foreach ( (array) $m['value'][ $check_k ] as $mk => $mv ) { |
|
663 | - if ( isset( $frm_duplicate_ids[ $mv ] ) ) { |
|
664 | - $m['value'][ $check_k ][ $mk ] = $frm_duplicate_ids[ $mv ]; |
|
662 | + foreach ( (array) $m['value'][$check_k] as $mk => $mv ) { |
|
663 | + if ( isset( $frm_duplicate_ids[$mv] ) ) { |
|
664 | + $m['value'][$check_k][$mk] = $frm_duplicate_ids[$mv]; |
|
665 | 665 | } |
666 | - unset($mk, $mv); |
|
666 | + unset( $mk, $mv ); |
|
667 | 667 | } |
668 | 668 | } |
669 | 669 | } |
670 | 670 | } |
671 | 671 | } |
672 | 672 | |
673 | - if ( ! is_array($m['value']) ) { |
|
674 | - $m['value'] = FrmAppHelper::maybe_json_decode($m['value']); |
|
673 | + if ( ! is_array( $m['value'] ) ) { |
|
674 | + $m['value'] = FrmAppHelper::maybe_json_decode( $m['value'] ); |
|
675 | 675 | } |
676 | 676 | |
677 | - $post['postmeta'][ (string) $meta->meta_key ] = $m['value']; |
|
677 | + $post['postmeta'][(string) $meta->meta_key] = $m['value']; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | /** |
@@ -690,23 +690,23 @@ discard block |
||
690 | 690 | } |
691 | 691 | |
692 | 692 | $taxonomy = (string) $att['domain']; |
693 | - if ( is_taxonomy_hierarchical($taxonomy) ) { |
|
693 | + if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
|
694 | 694 | $name = (string) $att['nicename']; |
695 | - $h_term = get_term_by('slug', $name, $taxonomy); |
|
695 | + $h_term = get_term_by( 'slug', $name, $taxonomy ); |
|
696 | 696 | if ( $h_term ) { |
697 | 697 | $name = $h_term->term_id; |
698 | 698 | } |
699 | - unset($h_term); |
|
699 | + unset( $h_term ); |
|
700 | 700 | } else { |
701 | 701 | $name = (string) $c; |
702 | 702 | } |
703 | 703 | |
704 | - if ( ! isset( $post['tax_input'][ $taxonomy ] ) ) { |
|
705 | - $post['tax_input'][ $taxonomy ] = array(); |
|
704 | + if ( ! isset( $post['tax_input'][$taxonomy] ) ) { |
|
705 | + $post['tax_input'][$taxonomy] = array(); |
|
706 | 706 | } |
707 | 707 | |
708 | - $post['tax_input'][ $taxonomy ][] = $name; |
|
709 | - unset($name); |
|
708 | + $post['tax_input'][$taxonomy][] = $name; |
|
709 | + unset( $name ); |
|
710 | 710 | } |
711 | 711 | } |
712 | 712 | |
@@ -723,29 +723,29 @@ discard block |
||
723 | 723 | |
724 | 724 | if ( in_array( $post['post_status'], array( 'trash', 'draft' ) ) ) { |
725 | 725 | $match_by['include'] = $post['post_id']; |
726 | - unset($match_by['name']); |
|
726 | + unset( $match_by['name'] ); |
|
727 | 727 | } |
728 | 728 | |
729 | - $editing = get_posts($match_by); |
|
729 | + $editing = get_posts( $match_by ); |
|
730 | 730 | |
731 | - if ( ! empty($editing) && current($editing)->post_date == $post['post_date'] ) { |
|
731 | + if ( ! empty( $editing ) && current( $editing )->post_date == $post['post_date'] ) { |
|
732 | 732 | // set the id of the post to edit |
733 | - $post['ID'] = current($editing)->ID; |
|
733 | + $post['ID'] = current( $editing )->ID; |
|
734 | 734 | } |
735 | 735 | } |
736 | 736 | |
737 | 737 | private static function update_postmeta( &$post, $post_id ) { |
738 | 738 | foreach ( $post['postmeta'] as $k => $v ) { |
739 | 739 | if ( '_edit_last' == $k ) { |
740 | - $v = FrmAppHelper::get_user_id_param($v); |
|
740 | + $v = FrmAppHelper::get_user_id_param( $v ); |
|
741 | 741 | } else if ( '_thumbnail_id' == $k && FrmAppHelper::pro_is_installed() ) { |
742 | 742 | //change the attachment ID |
743 | - $v = FrmProXMLHelper::get_file_id($v); |
|
743 | + $v = FrmProXMLHelper::get_file_id( $v ); |
|
744 | 744 | } |
745 | 745 | |
746 | - update_post_meta($post_id, $k, $v); |
|
746 | + update_post_meta( $post_id, $k, $v ); |
|
747 | 747 | |
748 | - unset($k, $v); |
|
748 | + unset( $k, $v ); |
|
749 | 749 | } |
750 | 750 | } |
751 | 751 | |
@@ -767,13 +767,13 @@ discard block |
||
767 | 767 | * @param string $message |
768 | 768 | */ |
769 | 769 | public static function parse_message( $result, &$message, &$errors ) { |
770 | - if ( is_wp_error($result) ) { |
|
770 | + if ( is_wp_error( $result ) ) { |
|
771 | 771 | $errors[] = $result->get_error_message(); |
772 | 772 | } else if ( ! $result ) { |
773 | 773 | return; |
774 | 774 | } |
775 | 775 | |
776 | - if ( ! is_array($result) ) { |
|
776 | + if ( ! is_array( $result ) ) { |
|
777 | 777 | $message = is_string( $result ) ? $result : print_r( $result, 1 ); |
778 | 778 | return; |
779 | 779 | } |
@@ -785,20 +785,20 @@ discard block |
||
785 | 785 | |
786 | 786 | $message = '<ul>'; |
787 | 787 | foreach ( $result as $type => $results ) { |
788 | - if ( ! isset( $t_strings[ $type ] ) ) { |
|
788 | + if ( ! isset( $t_strings[$type] ) ) { |
|
789 | 789 | // only print imported and updated |
790 | 790 | continue; |
791 | 791 | } |
792 | 792 | |
793 | 793 | $s_message = array(); |
794 | 794 | foreach ( $results as $k => $m ) { |
795 | - self::item_count_message($m, $k, $s_message); |
|
796 | - unset($k, $m); |
|
795 | + self::item_count_message( $m, $k, $s_message ); |
|
796 | + unset( $k, $m ); |
|
797 | 797 | } |
798 | 798 | |
799 | - if ( ! empty($s_message) ) { |
|
800 | - $message .= '<li><strong>' . $t_strings[ $type ] . ':</strong> '; |
|
801 | - $message .= implode(', ', $s_message); |
|
799 | + if ( ! empty( $s_message ) ) { |
|
800 | + $message .= '<li><strong>' . $t_strings[$type] . ':</strong> '; |
|
801 | + $message .= implode( ', ', $s_message ); |
|
802 | 802 | $message .= '</li>'; |
803 | 803 | } |
804 | 804 | } |
@@ -827,7 +827,7 @@ discard block |
||
827 | 827 | 'actions' => sprintf( _n( '%1$s Form Action', '%1$s Form Actions', $m, 'formidable' ), $m ), |
828 | 828 | ); |
829 | 829 | |
830 | - $s_message[] = isset( $strings[ $type ] ) ? $strings[ $type ] : ' ' . $m . ' ' . ucfirst( $type ); |
|
830 | + $s_message[] = isset( $strings[$type] ) ? $strings[$type] : ' ' . $m . ' ' . ucfirst( $type ); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | /** |
@@ -859,14 +859,14 @@ discard block |
||
859 | 859 | } |
860 | 860 | |
861 | 861 | public static function cdata( $str ) { |
862 | - $str = maybe_unserialize($str); |
|
863 | - if ( is_array($str) ) { |
|
864 | - $str = json_encode($str); |
|
862 | + $str = maybe_unserialize( $str ); |
|
863 | + if ( is_array( $str ) ) { |
|
864 | + $str = json_encode( $str ); |
|
865 | 865 | } else if ( seems_utf8( $str ) == false ) { |
866 | 866 | $str = utf8_encode( $str ); |
867 | 867 | } |
868 | 868 | |
869 | - if ( is_numeric($str) ) { |
|
869 | + if ( is_numeric( $str ) ) { |
|
870 | 870 | return $str; |
871 | 871 | } |
872 | 872 | |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | * @param string $post_type |
912 | 912 | */ |
913 | 913 | private static function migrate_post_settings_to_action( $form_options, $form_id, $post_type, &$imported, $switch ) { |
914 | - if ( ! isset($form_options['create_post']) || ! $form_options['create_post'] ) { |
|
914 | + if ( ! isset( $form_options['create_post'] ) || ! $form_options['create_post'] ) { |
|
915 | 915 | return; |
916 | 916 | } |
917 | 917 | |
@@ -932,10 +932,10 @@ discard block |
||
932 | 932 | ); |
933 | 933 | |
934 | 934 | foreach ( $post_settings as $post_setting ) { |
935 | - if ( isset( $form_options[ $post_setting ] ) ) { |
|
936 | - $new_action['post_content'][ $post_setting ] = $form_options[ $post_setting ]; |
|
935 | + if ( isset( $form_options[$post_setting] ) ) { |
|
936 | + $new_action['post_content'][$post_setting] = $form_options[$post_setting]; |
|
937 | 937 | } |
938 | - unset($post_setting); |
|
938 | + unset( $post_setting ); |
|
939 | 939 | } |
940 | 940 | |
941 | 941 | $new_action['event'] = array( 'create', 'update' ); |
@@ -949,7 +949,7 @@ discard block |
||
949 | 949 | |
950 | 950 | $new_action['post_content'] = self::switch_action_field_ids( $new_action['post_content'], $basic_fields, $array_fields ); |
951 | 951 | } |
952 | - $new_action['post_content'] = json_encode($new_action['post_content']); |
|
952 | + $new_action['post_content'] = json_encode( $new_action['post_content'] ); |
|
953 | 953 | |
954 | 954 | $exists = get_posts( array( |
955 | 955 | 'name' => $new_action['post_name'], |
@@ -961,7 +961,7 @@ discard block |
||
961 | 961 | if ( ! $exists ) { |
962 | 962 | // this isn't an email, but we need to use a class that will always be included |
963 | 963 | FrmAppHelper::save_json_post( $new_action ); |
964 | - $imported['imported']['actions']++; |
|
964 | + $imported['imported']['actions'] ++; |
|
965 | 965 | } |
966 | 966 | } |
967 | 967 | |
@@ -993,11 +993,11 @@ discard block |
||
993 | 993 | foreach ( $post_content as $key => $setting ) { |
994 | 994 | if ( ! is_array( $setting ) && in_array( $key, $basic_fields ) ) { |
995 | 995 | // Replace old IDs with new IDs |
996 | - $post_content[ $key ] = str_replace( $old, $new, $setting ); |
|
996 | + $post_content[$key] = str_replace( $old, $new, $setting ); |
|
997 | 997 | } else if ( is_array( $setting ) && in_array( $key, $array_fields ) ) { |
998 | 998 | foreach ( $setting as $k => $val ) { |
999 | 999 | // Replace old IDs with new IDs |
1000 | - $post_content[ $key ][ $k ] = str_replace( $old, $new, $val ); |
|
1000 | + $post_content[$key][$k] = str_replace( $old, $new, $val ); |
|
1001 | 1001 | } |
1002 | 1002 | } |
1003 | 1003 | unset( $key, $setting ); |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | // Migrate autoresponders |
1021 | 1021 | self::migrate_autoresponder_to_action( $form_options, $form_id, $notifications ); |
1022 | 1022 | |
1023 | - if ( empty( $notifications ) ) { |
|
1023 | + if ( empty( $notifications ) ) { |
|
1024 | 1024 | return; |
1025 | 1025 | } |
1026 | 1026 | |
1027 | 1027 | foreach ( $notifications as $new_notification ) { |
1028 | 1028 | $new_notification['post_type'] = $post_type; |
1029 | 1029 | $new_notification['post_excerpt'] = 'email'; |
1030 | - $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
1030 | + $new_notification['post_title'] = __( 'Email Notification', 'formidable' ); |
|
1031 | 1031 | $new_notification['menu_order'] = $form_id; |
1032 | 1032 | $new_notification['post_status'] = 'publish'; |
1033 | 1033 | |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | // Switch all other field IDs in email |
1041 | 1041 | $new_notification['post_content'] = FrmFieldsHelper::switch_field_ids( $new_notification['post_content'] ); |
1042 | 1042 | } |
1043 | - $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1043 | + $new_notification['post_content'] = FrmAppHelper::prepare_and_encode( $new_notification['post_content'] ); |
|
1044 | 1044 | |
1045 | 1045 | $exists = get_posts( array( |
1046 | 1046 | 'name' => $new_notification['post_name'], |
@@ -1049,11 +1049,11 @@ discard block |
||
1049 | 1049 | 'numberposts' => 1, |
1050 | 1050 | ) ); |
1051 | 1051 | |
1052 | - if ( empty($exists) ) { |
|
1052 | + if ( empty( $exists ) ) { |
|
1053 | 1053 | FrmAppHelper::save_json_post( $new_notification ); |
1054 | - $imported['imported']['actions']++; |
|
1054 | + $imported['imported']['actions'] ++; |
|
1055 | 1055 | } |
1056 | - unset($new_notification); |
|
1056 | + unset( $new_notification ); |
|
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | $form_options['notification'] = array( 0 => $form_options['notification'] ); |
1067 | 1067 | } |
1068 | 1068 | |
1069 | - if ( isset( $form_options['notification'] ) && is_array($form_options['notification']) ) { |
|
1069 | + if ( isset( $form_options['notification'] ) && is_array( $form_options['notification'] ) ) { |
|
1070 | 1070 | foreach ( $form_options['notification'] as $email_key => $notification ) { |
1071 | 1071 | |
1072 | 1072 | $atts = array( 'email_to' => '', 'reply_to' => '', 'reply_to_name' => '', 'event' => '', 'form_id' => $form_id, 'email_key' => $email_key ); |
@@ -1094,12 +1094,12 @@ discard block |
||
1094 | 1094 | // Format the reply to email and name |
1095 | 1095 | $reply_fields = array( 'reply_to' => '', 'reply_to_name' => '' ); |
1096 | 1096 | foreach ( $reply_fields as $f => $val ) { |
1097 | - if ( isset( $notification[ $f ] ) ) { |
|
1098 | - $atts[ $f ] = $notification[ $f ]; |
|
1099 | - if ( 'custom' == $notification[ $f ] ) { |
|
1100 | - $atts[ $f ] = $notification[ 'cust_' . $f ]; |
|
1101 | - } else if ( is_numeric( $atts[ $f ] ) && ! empty( $atts[ $f ] ) ) { |
|
1102 | - $atts[ $f ] = '[' . $atts[ $f ] . ']'; |
|
1097 | + if ( isset( $notification[$f] ) ) { |
|
1098 | + $atts[$f] = $notification[$f]; |
|
1099 | + if ( 'custom' == $notification[$f] ) { |
|
1100 | + $atts[$f] = $notification['cust_' . $f]; |
|
1101 | + } else if ( is_numeric( $atts[$f] ) && ! empty( $atts[$f] ) ) { |
|
1102 | + $atts[$f] = '[' . $atts[$f] . ']'; |
|
1103 | 1103 | } |
1104 | 1104 | } |
1105 | 1105 | unset( $f, $val ); |
@@ -1109,7 +1109,7 @@ discard block |
||
1109 | 1109 | $atts['event'] = array( 'create' ); |
1110 | 1110 | if ( isset( $notification['update_email'] ) && 1 == $notification['update_email'] ) { |
1111 | 1111 | $atts['event'][] = 'update'; |
1112 | - } else if ( isset($notification['update_email']) && 2 == $notification['update_email'] ) { |
|
1112 | + } else if ( isset( $notification['update_email'] ) && 2 == $notification['update_email'] ) { |
|
1113 | 1113 | $atts['event'] = array( 'update' ); |
1114 | 1114 | } |
1115 | 1115 | } |
@@ -1130,18 +1130,18 @@ discard block |
||
1130 | 1130 | foreach ( $atts['email_to'] as $key => $email_field ) { |
1131 | 1131 | |
1132 | 1132 | if ( is_numeric( $email_field ) ) { |
1133 | - $atts['email_to'][ $key ] = '[' . $email_field . ']'; |
|
1133 | + $atts['email_to'][$key] = '[' . $email_field . ']'; |
|
1134 | 1134 | } |
1135 | 1135 | |
1136 | - if ( strpos( $email_field, '|') ) { |
|
1136 | + if ( strpos( $email_field, '|' ) ) { |
|
1137 | 1137 | $email_opt = explode( '|', $email_field ); |
1138 | 1138 | if ( isset( $email_opt[0] ) ) { |
1139 | - $atts['email_to'][ $key ] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
1139 | + $atts['email_to'][$key] = '[' . $email_opt[0] . ' show=' . $email_opt[1] . ']'; |
|
1140 | 1140 | } |
1141 | 1141 | unset( $email_opt ); |
1142 | 1142 | } |
1143 | 1143 | } |
1144 | - $atts['email_to'] = implode(', ', $atts['email_to']); |
|
1144 | + $atts['email_to'] = implode( ', ', $atts['email_to'] ); |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | private static function setup_new_notification( &$new_notification, $notification, $atts ) { |
@@ -1157,12 +1157,12 @@ discard block |
||
1157 | 1157 | // Add more fields to the new notification |
1158 | 1158 | $add_fields = array( 'email_message', 'email_subject', 'plain_text', 'inc_user_info', 'conditions' ); |
1159 | 1159 | foreach ( $add_fields as $add_field ) { |
1160 | - if ( isset( $notification[ $add_field ] ) ) { |
|
1161 | - $new_notification['post_content'][ $add_field ] = $notification[ $add_field ]; |
|
1160 | + if ( isset( $notification[$add_field] ) ) { |
|
1161 | + $new_notification['post_content'][$add_field] = $notification[$add_field]; |
|
1162 | 1162 | } else if ( in_array( $add_field, array( 'plain_text', 'inc_user_info' ) ) ) { |
1163 | - $new_notification['post_content'][ $add_field ] = 0; |
|
1163 | + $new_notification['post_content'][$add_field] = 0; |
|
1164 | 1164 | } else { |
1165 | - $new_notification['post_content'][ $add_field ] = ''; |
|
1165 | + $new_notification['post_content'][$add_field] = ''; |
|
1166 | 1166 | } |
1167 | 1167 | unset( $add_field ); |
1168 | 1168 | } |
@@ -1186,26 +1186,26 @@ discard block |
||
1186 | 1186 | if ( isset( $post_content['conditions'] ) && is_array( $post_content['conditions'] ) ) { |
1187 | 1187 | foreach ( $post_content['conditions'] as $email_key => $val ) { |
1188 | 1188 | if ( is_numeric( $email_key ) ) { |
1189 | - $post_content['conditions'][ $email_key ] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
1189 | + $post_content['conditions'][$email_key] = self::switch_action_field_ids( $val, array( 'hide_field' ) ); |
|
1190 | 1190 | } |
1191 | - unset( $email_key, $val); |
|
1191 | + unset( $email_key, $val ); |
|
1192 | 1192 | } |
1193 | 1193 | } |
1194 | 1194 | } |
1195 | 1195 | |
1196 | 1196 | private static function migrate_autoresponder_to_action( $form_options, $form_id, &$notifications ) { |
1197 | - if ( isset($form_options['auto_responder']) && $form_options['auto_responder'] && isset($form_options['ar_email_message']) && $form_options['ar_email_message'] ) { |
|
1197 | + if ( isset( $form_options['auto_responder'] ) && $form_options['auto_responder'] && isset( $form_options['ar_email_message'] ) && $form_options['ar_email_message'] ) { |
|
1198 | 1198 | // migrate autoresponder |
1199 | 1199 | |
1200 | - $email_field = isset($form_options['ar_email_to']) ? $form_options['ar_email_to'] : 0; |
|
1201 | - if ( strpos($email_field, '|') ) { |
|
1200 | + $email_field = isset( $form_options['ar_email_to'] ) ? $form_options['ar_email_to'] : 0; |
|
1201 | + if ( strpos( $email_field, '|' ) ) { |
|
1202 | 1202 | // data from entries field |
1203 | - $email_field = explode('|', $email_field); |
|
1204 | - if ( isset($email_field[1]) ) { |
|
1203 | + $email_field = explode( '|', $email_field ); |
|
1204 | + if ( isset( $email_field[1] ) ) { |
|
1205 | 1205 | $email_field = $email_field[1]; |
1206 | 1206 | } |
1207 | 1207 | } |
1208 | - if ( is_numeric($email_field) && ! empty($email_field) ) { |
|
1208 | + if ( is_numeric( $email_field ) && ! empty( $email_field ) ) { |
|
1209 | 1209 | $email_field = '[' . $email_field . ']'; |
1210 | 1210 | } |
1211 | 1211 | |
@@ -1213,16 +1213,16 @@ discard block |
||
1213 | 1213 | $new_notification2 = array( |
1214 | 1214 | 'post_content' => array( |
1215 | 1215 | 'email_message' => $notification['ar_email_message'], |
1216 | - 'email_subject' => isset($notification['ar_email_subject']) ? $notification['ar_email_subject'] : '', |
|
1216 | + 'email_subject' => isset( $notification['ar_email_subject'] ) ? $notification['ar_email_subject'] : '', |
|
1217 | 1217 | 'email_to' => $email_field, |
1218 | - 'plain_text' => isset($notification['ar_plain_text']) ? $notification['ar_plain_text'] : 0, |
|
1218 | + 'plain_text' => isset( $notification['ar_plain_text'] ) ? $notification['ar_plain_text'] : 0, |
|
1219 | 1219 | 'inc_user_info' => 0, |
1220 | 1220 | ), |
1221 | 1221 | 'post_name' => $form_id . '_email_' . count( $notifications ), |
1222 | 1222 | ); |
1223 | 1223 | |
1224 | - $reply_to = isset($notification['ar_reply_to']) ? $notification['ar_reply_to'] : ''; |
|
1225 | - $reply_to_name = isset($notification['ar_reply_to_name']) ? $notification['ar_reply_to_name'] : ''; |
|
1224 | + $reply_to = isset( $notification['ar_reply_to'] ) ? $notification['ar_reply_to'] : ''; |
|
1225 | + $reply_to_name = isset( $notification['ar_reply_to_name'] ) ? $notification['ar_reply_to_name'] : ''; |
|
1226 | 1226 | |
1227 | 1227 | if ( ! empty( $reply_to ) ) { |
1228 | 1228 | $new_notification2['post_content']['reply_to'] = $reply_to; |