/**
 * Update form settings to the new storage system when the form is viewed for the first time.
 *
 * @since 2.9
 * @return void
 */
function nf_29_update_form_settings($form_id)
{
    global $wpdb;
    // Check to see if an object exists with our form id.
    $type = nf_get_object_type($form_id);
    if ('form' != $type) {
        // We have an object with our form id.
        // Insert a new object.
        $next_id = nf_insert_object($type);
        // Replace all instances of the object ID with our new one.
        $wpdb->update(NF_OBJECT_META_TABLE_NAME, array('object_id' => $next_id), array('object_id' => $form_id));
        $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('parent_id' => $next_id), array('parent_type' => $type, 'parent_id' => $form_id));
        $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('child_id' => $next_id), array('child_type' => $type, 'child_id' => $form_id));
        // Delete the original object
        $wpdb->query('DELETE FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = ' . $form_id);
    }
    $form = $wpdb->get_row('SELECT * FROM ' . NINJA_FORMS_TABLE_NAME . ' WHERE id = ' . $form_id, ARRAY_A);
    $settings = maybe_unserialize($form['data']);
    $settings['date_updated'] = $form['date_updated'];
    $f_id = nf_insert_object('form', $form['id']);
    foreach ($settings as $meta_key => $value) {
        nf_update_object_meta($f_id, $meta_key, $value);
    }
    nf_update_object_meta($f_id, 'status', '');
}
Esempio n. 2
0
/**
 * Update form settings to the new storage system when the form is viewed for the first time.
 *
 * @since 2.9
 * @return void
 */
function nf_29_update_form_settings($form_id)
{
    global $wpdb;
    // Check to see if the conversion has been reset.
    $is_reset = get_option('nf_converted_form_reset', 0);
    // Check to see if an object exists with our form id.
    $type = nf_get_object_type($form_id);
    if ($type) {
        // We have an object with our form id.
        if ($is_reset and 'form' == $type) {
            // Give precedence to the most recent form.
            // Set a new ID for the form being converted.
            $f_id = nf_insert_object('form');
            $fields = $wpdb->get_results("SELECT * FROM " . NINJA_FORMS_FIELDS_TABLE_NAME . " WHERE form_id = " . $form_id, ARRAY_A);
            foreach ($fields as $field) {
                unset($field['id']);
                $field['form_id'] = $f_id;
                // Copy the Fields to the new ID.
                $wpdb->insert(NINJA_FORMS_FIELDS_TABLE_NAME, $field);
            }
            $relationships = $wpdb->get_results("SELECT * FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE parent_id = " . $form_id, ARRAY_A);
            foreach ($relationships as $relationship) {
                unset($relationship['id']);
                // Copy the object related to the form.
                $object = $wpdb->get_results("SELECT * FROM " . NF_OBJECTS_TABLE_NAME . " WHERE id = " . $relationship['child_id'], ARRAY_A);
                unset($object['id']);
                $wpdb->insert(NF_OBJECTS_TABLE_NAME, $object);
                $relationship['child_id'] = $wpdb->insert_id;
                $relationship['parent_id'] = $f_id;
                // Copy the Relationships to the new ID.
                $wpdb->insert(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, $relationship);
            }
        } else {
            // Give precedence to the converting form.
            // Insert a new object.
            $next_id = nf_insert_object($type);
            // Replace all instances of the conflicting object ID with our new one.
            $wpdb->update(NF_OBJECT_META_TABLE_NAME, array('object_id' => $next_id), array('object_id' => $form_id));
            $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('parent_id' => $next_id), array('parent_type' => $type, 'parent_id' => $form_id));
            $wpdb->update(NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array('child_id' => $next_id), array('child_type' => $type, 'child_id' => $form_id));
            // Delete the original (conflicting) object
            $wpdb->query('DELETE FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = ' . $form_id);
        }
    }
    // Get the form from the old table.
    $form = $wpdb->get_row('SELECT * FROM ' . NINJA_FORMS_TABLE_NAME . ' WHERE id = ' . $form_id, ARRAY_A);
    // Set the insert form ID, if not already set.
    $f_id = isset($f_id) ? $f_id : nf_insert_object('form', $form['id']);
    // Unpack the converted form's settings
    $settings = maybe_unserialize($form['data']);
    $settings['date_updated'] = $form['date_updated'];
    foreach ($settings as $meta_key => $value) {
        nf_update_object_meta($f_id, $meta_key, $value);
    }
    nf_update_object_meta($f_id, 'status', '');
}
Esempio n. 3
0
function ninja_forms_import_form($file)
{
    global $wpdb;
    $form = unserialize(trim($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);
    // Remove our last_sub setting. This is our starting seq_num.
    if (isset($form['data']['last_sub'])) {
        unset($form['data']['last_sub']);
    }
    $form['data'] = serialize($form['data']);
    $wpdb->insert(NINJA_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'] = apply_filters('nf_before_import_field', $form_fields[$x]['data'], $form_fields[$x]['id']);
            $form_fields[$x]['data'] = serialize($form_fields[$x]['data']);
            $old_field_id = $form_fields[$x]['id'];
            $form_fields[$x]['id'] = NULL;
            $wpdb->insert(NINJA_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'];
}
Esempio n. 4
0
 /**
  * Update a notification setting
  * 
  * @access public
  * @since 2.8
  * @return bool
  */
 public function update_setting($meta_key, $meta_value)
 {
     nf_update_object_meta($this->id, $meta_key, $meta_value);
     return true;
 }
 public function step($step)
 {
     global $ninja_forms_fields;
     // Get our form ID
     $form_id = $this->args['forms'][$step];
     // Bail if we've already converted the notifications for this form.
     if (in_array($form_id, $this->completed_forms)) {
         return false;
     }
     // Grab our form from the database
     $form_settings = Ninja_Forms()->form($form_id)->settings;
     $fields = Ninja_Forms()->form($form_id)->fields;
     $process_fields = array();
     foreach ($fields as $field_id => $field) {
         $label = strip_tags(nf_get_field_admin_label($field_id));
         if (strlen($label) > 30) {
             $tmp_label = substr($label, 0, 30);
         } else {
             $tmp_label = $label;
         }
         $tmp_array = array('value' => $field_id, 'label' => $tmp_label . ' - ID: ' . $field_id);
         $admin_label = $label;
         $label = isset($field['data']['label']) ? $field['data']['label'] : '';
         // Check to see if this field is supposed to be "processed"
         $type = $field['type'];
         if (isset($ninja_forms_fields[$type]['process_field']) && $ninja_forms_fields[$type]['process_field']) {
             $process_fields[$field_id] = array('field_id' => $field_id, 'label' => $label, 'admin_label' => $admin_label);
         }
     }
     // Create a notification for our admin email
     if (isset($form_settings['admin_email_msg']) && !empty($form_settings['admin_email_msg']) || isset($form_settings['admin_email_fields']) && 1 == $form_settings['admin_email_fields']) {
         // Create a notification
         $n_id = nf_insert_notification($form_id);
         // Update our notification type
         nf_update_object_meta($n_id, 'type', 'email');
         // Activate our notification
         Ninja_Forms()->notification($n_id)->activate();
         // Update our notification name
         Ninja_Forms()->notification($n_id)->update_setting('name', __('Admin Email', 'ninja-forms'));
         $admin_mailto = isset($form_settings['admin_mailto']) ? $form_settings['admin_mailto'] : array();
         // Implode our admin email addresses
         $to = implode('`', $admin_mailto);
         // Update our to setting
         Ninja_Forms()->notification($n_id)->update_setting('to', $to);
         // Update our Format Setting
         Ninja_Forms()->notification($n_id)->update_setting('email_format', $form_settings['email_type']);
         // Update our attach csv option
         Ninja_Forms()->notification($n_id)->update_setting('attach_csv', $form_settings['admin_attach_csv']);
         // Update our subject
         $subject = $this->replace_shortcodes($form_settings['admin_subject']);
         Ninja_Forms()->notification($n_id)->update_setting('email_subject', $subject);
         // Update our From Name
         if (isset($form_settings['email_from_name'])) {
             Ninja_Forms()->notification($n_id)->update_setting('from_name', $form_settings['email_from_name']);
         }
         foreach ($fields as $field) {
             if (isset($field['data']['from_name']) && $field['data']['from_name'] == 1) {
                 // Update our From Name
                 Ninja_Forms()->notification($n_id)->update_setting('from_name', 'field_' . $field['id']);
                 break;
             }
         }
         // Update our From Address
         Ninja_Forms()->notification($n_id)->update_setting('from_address', $form_settings['email_from']);
         // Get our reply-to address
         foreach ($fields as $field) {
             if (isset($field['data']['replyto_email']) && $field['data']['replyto_email'] == 1) {
                 Ninja_Forms()->notification($n_id)->update_setting('reply_to', 'field_' . $field['id']);
                 break;
             }
         }
         $email_message = $form_settings['admin_email_msg'];
         // Check to see if the "include list of fields" checkbox was checked.
         if (isset($form_settings['admin_email_fields']) && $form_settings['admin_email_fields'] == 1) {
             $email_message .= '<br />[ninja_forms_all_fields]';
         }
         // Update our email message
         Ninja_Forms()->notification($n_id)->update_setting('email_message', $email_message);
         Ninja_Forms()->notification($n_id)->update_setting('admin_email', true);
     }
     // Create a notification for our user email
     if (!empty($fields)) {
         $addresses = array();
         foreach ($fields as $field_id => $field) {
             if (isset($field['data']['send_email']) && $field['data']['send_email'] == 1) {
                 // Add this field to our $addresses variable.
                 $addresses[] = 'field_' . $field_id;
                 unset($field['data']['send_email']);
                 unset($field['data']['replyto_email']);
                 unset($field['data']['from_name']);
                 $args = array('update_array' => array('data' => serialize($field['data'])), 'where' => array('id' => $field_id));
                 ninja_forms_update_field($args);
             }
         }
         if (!empty($addresses)) {
             // We have a user email, so create a notification
             $n_id = nf_insert_notification($form_id);
             // Update our notification type
             nf_update_object_meta($n_id, 'type', 'email');
             // Activate our notification
             Ninja_Forms()->notification($n_id)->activate();
             // Update our notification name
             Ninja_Forms()->notification($n_id)->update_setting('name', __('User Email', 'ninja-forms'));
             // Implode our admin email addresses
             $n_var = count($addresses) > 1 ? 'bcc' : 'to';
             $addresses = implode('`', $addresses);
             Ninja_Forms()->notification($n_id)->update_setting($n_var, $addresses);
             // Update our Format Setting
             Ninja_Forms()->notification($n_id)->update_setting('email_format', $form_settings['email_type']);
             // Update our subject
             $subject = $this->replace_shortcodes($form_settings['user_subject']);
             Ninja_Forms()->notification($n_id)->update_setting('email_subject', $subject);
             // Update our From Name
             if (isset($form_settings['email_from_name'])) {
                 Ninja_Forms()->notification($n_id)->update_setting('from_name', $form_settings['email_from_name']);
             }
             // Update our From Address
             Ninja_Forms()->notification($n_id)->update_setting('from_address', $form_settings['email_from']);
             $email_message = $form_settings['user_email_msg'];
             // Check to see if the "include list of fields" checkbox was checked. If so, add our table to the end of the email message.
             if (isset($form_settings['user_email_fields']) && $form_settings['user_email_fields'] == 1) {
                 $email_message .= '<br />[ninja_forms_all_fields]';
             }
             // Update our email message
             Ninja_Forms()->notification($n_id)->update_setting('email_message', $email_message);
             Ninja_Forms()->notification($n_id)->update_setting('user_email', true);
         }
     }
     if (isset($form_settings['success_msg']) && !empty($form_settings['success_msg'])) {
         // Create a notification for our success message
         $n_id = nf_insert_notification($form_id);
         nf_update_object_meta($n_id, 'name', __('Success Message', 'ninja-forms'));
         nf_update_object_meta($n_id, 'type', 'success_message');
         nf_update_object_meta($n_id, 'active', 1);
         nf_update_object_meta($n_id, 'success_msg', $form_settings['success_msg']);
     }
     if (isset($form_settings['landing_page']) && !empty($form_settings['landing_page'])) {
         // Create a notification for our redirect
         $n_id = nf_insert_notification($form_id);
         nf_update_object_meta($n_id, 'name', __('Redirect', 'ninja-forms'));
         nf_update_object_meta($n_id, 'type', 'redirect');
         nf_update_object_meta($n_id, 'active', 1);
         nf_update_object_meta($n_id, 'redirect_url', $form_settings['landing_page']);
     }
     $completed_forms = get_option('nf_convert_notifications_forms');
     if (!is_array($completed_forms) || empty($completed_forms)) {
         $completed_forms = array($form_id);
     } else {
         $completed_forms[] = $form_id;
     }
     update_option('nf_convert_notifications_forms', $completed_forms);
     // Unset our admin email settings and save the form.
     if (isset($form_settings['admin_mailto'])) {
         unset($form_settings['admin_mailto']);
         unset($form_settings['admin_attach_csv']);
         unset($form_settings['admin_subject']);
         unset($form_settings['admin_email_msg']);
         unset($form_settings['admin_email_fields']);
         unset($form_settings['success_msg']);
         unset($form_settings['user_email_msg']);
         unset($form_settings['user_subject']);
         unset($form_settings['landing_page']);
         $args = array('update_array' => array('data' => serialize($form_settings)), 'where' => array('id' => $form_id));
         ninja_forms_update_form($args);
     }
 }
Esempio n. 6
0
 /**
  * Update a form setting (this doesn't update anything in the database)
  * Changes are only applied to this object.
  * 
  * @access public
  * @since 2.8
  * @param string $setting
  * @param mixed $value
  * @return bool
  */
 public function update_setting($setting, $value)
 {
     $this->settings[$setting] = $value;
     nf_update_object_meta($this->form_id, $setting, $value);
     return true;
 }
Esempio n. 7
0
/**
 * Insert a notification into the database.
 *
 * Calls nf_insert_object()
 * Calls nf_add_relationship()
 * Calls nf_update_object_meta()
 *
 * @since 2.8
 * @param int $form_id
 * @return int $n_id
 */
function nf_insert_notification($form_id = '')
{
    if (empty($form_id)) {
        return false;
    }
    $n_id = nf_insert_object('notification');
    nf_add_relationship($n_id, 'notification', $form_id, 'form');
    $date_updated = date('Y-m-d', current_time('timestamp'));
    nf_update_object_meta($n_id, 'date_updated', $date_updated);
    return $n_id;
}
 /**
  * Save our notifications admin.
  * 
  * @access public
  *
  * @since 2.8
  * @return void
  */
 public function save_admin($form_id, $data)
 {
     if (!isset($data['notification_id']) || empty($data['notification_id'])) {
         return false;
     }
     $n_id = $data['notification_id'];
     $settings = $data['settings'];
     if ('new' == $n_id) {
         $type = $settings['type'];
         $n_id = $this->create($form_id);
         $new = true;
     } else {
         $type = Ninja_Forms()->notification($n_id)->type;
         $new = false;
     }
     $data = Ninja_Forms()->notification_types[$type]->save_admin($n_id, $data);
     foreach ($settings as $meta_key => $meta_value) {
         nf_update_object_meta($n_id, $meta_key, $meta_value);
     }
     do_action('nf_save_notification', $n_id, $data, $new);
     if ($new) {
         $redirect = esc_url_raw(remove_query_arg(array('notification-action')));
         $redirect = esc_url_raw(add_query_arg(array('id' => $n_id, 'notification-action' => 'edit', 'update_message' => urlencode(__('Action Updated', 'ninja-forms'))), $redirect));
         wp_redirect($redirect);
         die;
     }
     return __('Action Updated', 'ninja-forms');
 }
Esempio n. 9
0
 private function ninja_forms()
 {
     if (!is_plugin_active('ninja-forms/ninja-forms.php')) {
         return;
     }
     // Update localized strings in sample contact form
     $contact_form_meta = array('form_title' => __('Contact Form', 'wp-easy-mode'), 'success_msg' => __('Your form has been successfully submitted.', 'wp-easy-mode'), 'user_email_msg' => __('Thank you so much for contacting us. We will get back to you shortly.', 'wp-easy-mode'));
     foreach ($contact_form_meta as $key => $value) {
         nf_update_object_meta(1, $key, $value);
     }
     // Add contact form to WPEM contact page
     $this->add_ninja_form_to_page('contact-%', 1);
     // Create sample quote form
     if ('standard' === $this->site_type) {
         $contact_form_data = ninja_forms_serialize_form(1);
         // Duplicate the sample contact form
         $quote_form_id = ninja_forms_import_form($contact_form_data);
         // Update localized strings in sample quote form
         $quote_form_meta = array('form_title' => __('Request A Quote Form', 'wp-easy-mode'), 'success_msg' => __('Your form has been successfully submitted.', 'wp-easy-mode'), 'user_email_msg' => __('Thank you so much for contacting us. We will get back to you shortly.', 'wp-easy-mode'));
         foreach ($quote_form_meta as $key => $value) {
             nf_update_object_meta($quote_form_id, $key, $value);
         }
         // Add quote form to WPEM estimates page
         $this->add_ninja_form_to_page('estimates', $quote_form_id);
     }
 }
Esempio n. 10
0
/**
 * Change the field IDs in our notification conditions after we import a form.
 */
function nf_cl_form_import($n, $n_id, $form)
{
    // Bail if we don't have any fields set.
    if (!isset($form['field']) || empty($form['field'])) {
        return $n;
    }
    $fields = array();
    foreach ($form['field'] as $field) {
        $old_id = $field['old_id'];
        $fields[$old_id] = $field['id'];
    }
    // Make sure we have some conditions.
    if (isset($n['conditions'])) {
        // Loop through our conditions, change the field ids, and insert them into the database.
        foreach ($n['conditions'] as $condition) {
            // Make sure that we have criteria set.
            if (!isset($condition['criteria']) || empty($condition['criteria'])) {
                continue;
            }
            // There isn't any criteria set. Skip to the next condition.
            // Insert our condition
            $c_id = nf_cl_insert_condition($n_id);
            // Update our condition meta
            nf_update_object_meta($c_id, 'action', $condition['action']);
            nf_update_object_meta($c_id, 'connector', $condition['connector']);
            // Change our field ids.
            // Loop through our criteria and search for field ids
            foreach ($condition['criteria'] as $cr) {
                // First, we check the param to see if it is a field id.
                if (isset($fields[$cr['param']])) {
                    $cr['param'] = $fields[$cr['param']];
                }
                // Next, check to see if the value is a field id
                if (isset($fields[$cr['value']])) {
                    $cr['value'] = $fields[$cr['param']];
                }
                // Insert our criteria
                $cr_id = nf_cl_insert_criteria($c_id);
                // Update our criteria object meta.
                nf_update_object_meta($cr_id, 'param', $cr['param']);
                nf_update_object_meta($cr_id, 'compare', $cr['compare']);
                nf_update_object_meta($cr_id, 'value', $cr['value']);
            }
        }
        unset($n['conditions']);
    }
    return $n;
}
 /**
  * Save admin edit screen
  *
  * @access public
  * @since 1.0
  * @return void
  */
 public function save_admin($id = '', $data)
 {
     if (isset($data['wh_args']) && is_array($data['wh_args'])) {
         $args = nf_get_object_children($id, 'wh_args');
         foreach ($args as $object_id => $vars) {
             if (!isset($data['wh_args'][$object_id])) {
                 nf_delete_object($object_id);
             }
         }
         if (isset($data['wh_args']['new'])) {
             foreach ($data['wh_args']['new'] as $vars) {
                 $object_id = nf_insert_object('wh_args');
                 nf_update_object_meta($object_id, 'key', $vars['key']);
                 nf_update_object_meta($object_id, 'field', $vars['field']);
                 nf_add_relationship($object_id, 'wh_args', $id, 'notification');
             }
             unset($data['wh_args']['new']);
         }
         foreach ($data['wh_args'] as $object_id => $vars) {
             if (!empty($object_id)) {
                 nf_update_object_meta($object_id, 'key', $vars['key']);
                 nf_update_object_meta($object_id, 'field', $vars['field']);
             }
         }
         unset($data['wh_args']);
     }
     return $data;
 }