/var/www/(Del)hsihk.com/wp-content/plugins/ninja-forms/includes/import-export.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

/*
 * Import a serialized ninja form
 *
 * @since unknown
 * @returns int
 */
function ninja_forms_import_form$file ){
    global 
$wpdb;
    
$form unserializetrim$file ) );
    
$form_fields = isset( $form['field'] ) ? $form['field'] : null;
    
$notifications = isset ( $form['notifications'] ) ? $form['notifications'] : null;

    unset ( 
$form['field'] );
    unset ( 
$form['notifications'] );

    
$form apply_filters'ninja_forms_before_import_form'$form );
    
$form['data'] = serialize$form['data'] ) ;

    
$wpdb->insertNINJA_FORMS_TABLE_NAME$form );
    
$form_id $wpdb->insert_id;
    
$form['id'] = $form_id;

    if(
is_array($form_fields)){
        for (
$x=0$x count$form_fields ); $x++) {
            
$form_fields[$x]['form_id'] = $form_id;
            
$form_fields[$x]['data'] = serialize$form_fields[$x]['data'] );
            
$old_field_id $form_fields[$x]['id'];
            
$form_fields[$x]['id'] = NULL;
            
$wpdb->insertNINJA_FORMS_FIELDS_TABLE_NAME$form_fields[$x] );
            
$form_fields[$x]['id'] = $wpdb->insert_id;
            
$form_fields[$x]['old_id'] = $old_field_id;
            
$form_fields[$x]['data'] = unserialize$form_fields[$x]['data'] );
        }
    }

    
$form['data'] = unserialize$form['data'] );
    
$form['field'] = $form_fields;
    
$form['notifications'] = $notifications;    

    
// Insert any notifications we might have.
    
if ( is_array$notifications ) ) {
        foreach ( 
$notifications as $n ) {
            
$n_id nf_insert_notification$form_id );
            
$n apply_filters'nf_import_notification_meta'$n$n_id$form );
            unset( 
$n['conditions'] );
            foreach ( 
$n as $meta_key => $meta_value ) {
                foreach ( 
$form_fields as $field ) {
                    
// We need to replace any references to old fields in our notification
                    
if ( 'email_message' == $meta_key ) {
                        
$meta_value str_replace'[ninja_forms_field id=' $field['old_id'].']''[ninja_forms_field id='.$field['id'].']'$meta_value );
                        
$meta_value str_replace'ninja_forms_field_' $field['old_id'], 'ninja_forms_field_' $field['id'], $meta_value );
                    } else {
                        
$meta_value preg_replace'/\bfield_' $field['old_id'] . '\b/u''field_' $field['id'], $meta_value );
                    }
                }
                
nf_update_object_meta$n_id$meta_key$meta_value );
            }
        }
    }

    
    
do_action'ninja_forms_after_import_form'$form );
    return 
$form['id'];
}