Example #1
0
function ninja_forms_save_impexp_fields($data)
{
    global $wpdb, $ninja_forms_admin_update_message;
    $plugin_settings = nf_get_settings();
    $update_message = '';
    if ($_POST['submit'] == __('Export Fields', 'ninja-forms')) {
        if (isset($_POST['ninja_forms_fav']) and !empty($_POST['ninja_forms_fav'])) {
            $fav_ids = ninja_forms_esc_html_deep($_POST['ninja_forms_fav']);
            if (isset($plugin_settings['date_format'])) {
                $date_format = $plugin_settings['date_format'];
            } else {
                $date_format = 'm/d/Y';
            }
            //$today = date($date_format);
            $current_time = current_time('timestamp');
            $today = date($date_format, $current_time);
            $favorites = array();
            if (is_array($fav_ids) and !empty($fav_ids)) {
                $x = 0;
                foreach ($fav_ids as $fav_id) {
                    $fav_row = ninja_forms_get_fav_by_id($fav_id);
                    $fav_row['id'] = NULL;
                    $favorites[$x] = $fav_row;
                    $x++;
                }
            }
            $favorites = serialize($favorites);
            header("Content-type: application/csv");
            header("Content-Disposition: attachment; filename=favorites-" . $today . ".nff");
            header("Pragma: no-cache");
            header("Expires: 0");
            echo $favorites;
            die;
        } else {
            $update_message = __('Please select favorite fields to export.', 'ninja-forms');
        }
    } elseif ($_POST['submit'] == __('Import Favorites', 'ninja-forms')) {
        if ($_FILES['userfile']['error'] == UPLOAD_ERR_OK and is_uploaded_file($_FILES['userfile']['tmp_name'])) {
            $file = file_get_contents($_FILES['userfile']['tmp_name']);
            $favorites = unserialize($file);
            if (is_array($favorites)) {
                foreach ($favorites as $fav) {
                    $fav['data'] = serialize($fav['data']);
                    $wpdb->insert(NINJA_FORMS_FAV_FIELDS_TABLE_NAME, $fav);
                }
            }
            $update_message = __('Favorites imported successfully.', 'ninja-forms');
        } else {
            $update_message = __('Please select a valid favorite fields file.', 'ninja-forms');
        }
    }
    return $update_message;
}
Example #2
0
function nf_output_registered_field_settings($field_id, $data = array())
{
    global $ninja_forms_fields, $nf_rte_editors;
    $field_row = ninja_forms_get_field_by_id($field_id);
    $field_type = $field_row['type'];
    $field_data = empty($data) ? $field_row['data'] : $data;
    $current_tab = ninja_forms_get_current_tab();
    if (isset($_REQUEST['page'])) {
        $current_page = esc_html($_REQUEST['page']);
    } else {
        $current_page = '';
    }
    $reg_field = $ninja_forms_fields[$field_type];
    $type_name = $reg_field['name'];
    $edit_function = $reg_field['edit_function'];
    $edit_options = $reg_field['edit_options'];
    $edit_settings = $reg_field['edit_settings'];
    if ($reg_field['nesting']) {
        $nesting_class = 'ninja-forms-nest';
    } else {
        $nesting_class = 'ninja-forms-no-nest';
    }
    $conditional = $reg_field['conditional'];
    if (isset($field_row['fav_id']) && $field_row['fav_id'] != 0) {
        $fav_id = $field_row['fav_id'];
        $fav_row = ninja_forms_get_fav_by_id($fav_id);
        if (empty($fav_row['name'])) {
            $args = array('update_array' => array('fav_id' => ''), 'where' => array('id' => $field_id));
            ninja_forms_update_field($args);
            $fav_id = '';
        }
    } else {
        $fav_id = '';
    }
    if (isset($field_row['def_id']) && $field_row['def_id'] != 0) {
        $def_id = $field_row['def_id'];
    } else {
        $def_id = '';
    }
    if ($fav_id != 0 && $fav_id != '') {
        $fav_row = ninja_forms_get_fav_by_id($fav_id);
        if (!empty($fav_row['name'])) {
            $fav_class = 'ninja-forms-field-remove-fav';
            $type_name = $fav_row['name'];
            $icon_class = 'filled';
        }
    } else {
        $fav_class = 'ninja-forms-field-add-fav';
        $icon_class = 'empty';
    }
    if ($reg_field['show_field_id'] || $reg_field['show_fav']) {
        ?>
		<table id="field-info">
			<tr>
				<?php 
        if ($reg_field['show_field_id']) {
            ?>
					<td width="65%"><?php 
            _e('Field ID', 'ninja-forms');
            ?>
: <strong><?php 
            echo $field_id;
            ?>
</strong></td>
					<?php 
        }
        ?>
				<!-- <td width="15%"><a href="#" class="ninja-forms-field-add-def" id="ninja_forms_field_<?php 
        echo $field_id;
        ?>
_def" class="ninja-forms-field-add-def">Add Defined</a></td><td width="15%"><a href="#" class="ninja-forms-field-remove-def" id="ninja_forms_field_<?php 
        echo $field_id;
        ?>
_def">Remove Defined</a></td> -->
				<?php 
        if ($reg_field['show_fav']) {
            ?>
					<td width="5%"><a href="#" class="<?php 
            echo $fav_class;
            ?>
" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_fav"><span class="dashicons dashicons-star-<?php 
            echo $icon_class;
            ?>
"></span></a></td>
					<?php 
        }
        ?>
			</tr>
		</table>
		<?php 
    }
    do_action('ninja_forms_edit_field_before_registered', $field_id, $field_data);
    $arguments = array('field_id' => $field_id, 'data' => $field_data);
    if ($edit_function != '') {
        call_user_func_array($edit_function, $arguments);
    }
    /**
     * We need to get a list of all of our RTEs. 
     * If we're submitting via ajax, we'll need to use this list.
     */
    if (!isset($nf_rte_editors)) {
        $nf_rte_editors = array();
    }
    $editors = new NF_WP_Editor_Ajax();
    if (is_array($edit_options) and !empty($edit_options)) {
        foreach ($edit_options as $opt) {
            $type = $opt['type'];
            $label_class = '';
            if (isset($opt['label'])) {
                $label = $opt['label'];
            } else {
                $label = '';
            }
            if (isset($opt['name'])) {
                $name = $opt['name'];
            } else {
                $name = '';
            }
            if (isset($opt['width'])) {
                $width = $opt['width'];
            } else {
                $width = '';
            }
            if (isset($opt['options'])) {
                $options = $opt['options'];
            } else {
                $options = '';
            }
            if (isset($opt['class'])) {
                $class = $opt['class'];
            } else {
                $class = '';
            }
            if (isset($opt['default'])) {
                $default = $opt['default'];
            } else {
                $default = '';
            }
            if (isset($opt['desc'])) {
                $desc = $opt['desc'];
            } else {
                $desc = '';
            }
            if (isset($field_data[$name])) {
                $value = $field_data[$name];
            } else {
                $value = $default;
            }
            ninja_forms_edit_field_el_output($field_id, $type, $label, $name, $value, $width, $options, $class, $desc, $label_class);
        }
    }
    add_action('nf_edit_field_advanced', 'nf_test', 10, 2);
    $settings_sections = apply_filters('nf_edit_field_settings_sections', array('restrictions' => __('Restriction Settings', 'ninja-forms'), 'calculations' => __('Calculation Settings', 'ninja-forms'), 'advanced' => __('Advanced Settings', 'ninja-forms')));
    foreach ($settings_sections as $key => $name) {
        ?>
		<div class="nf-field-settings description-wide description">
			<div class="title">
				<?php 
        echo $name;
        ?>
<span class="dashicons dashicons-arrow-down nf-field-sub-section-toggle"></span>
			</div>
			<div class="inside" style="display:none;">
				<?php 
        if (!empty($edit_settings[$key])) {
            foreach ($edit_settings[$key] as $opt) {
                $type = $opt['type'];
                $label_class = '';
                if (isset($opt['label'])) {
                    $label = $opt['label'];
                } else {
                    $label = '';
                }
                if (isset($opt['name'])) {
                    $name = $opt['name'];
                } else {
                    $name = '';
                }
                if (isset($opt['width'])) {
                    $width = $opt['width'];
                } else {
                    $width = '';
                }
                if (isset($opt['options'])) {
                    $options = $opt['options'];
                } else {
                    $options = '';
                }
                if (isset($opt['class'])) {
                    $class = $opt['class'];
                } else {
                    $class = '';
                }
                if (isset($opt['default'])) {
                    $default = $opt['default'];
                } else {
                    $default = '';
                }
                if (isset($opt['desc'])) {
                    $desc = $opt['desc'];
                } else {
                    $desc = '';
                }
                if (isset($field_data[$name])) {
                    $value = $field_data[$name];
                } else {
                    $value = $default;
                }
                ninja_forms_edit_field_el_output($field_id, $type, $label, $name, $value, $width, $options, $class, $desc, $label_class);
            }
        }
        do_action('nf_edit_field_' . $key, $field_id, $field_data);
        ?>
			</div>
		</div>
		<?php 
    }
    ?>
	<div class="menu-item-actions description-wide submitbox">
		<a class="submitdelete deletion nf-remove-field" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_remove" data-field="<?php 
    echo $field_id;
    ?>
" href="#"><?php 
    _e('Remove', 'ninja-forms');
    ?>
</a>
	</div>
	<?php 
    if (!empty($nf_rte_editors) && isset($editors) && is_object($editors)) {
        $editors->output_js($field_id, $nf_rte_editors);
    }
}
Example #3
0
File: li.php Project: serker72/T3S
function ninja_forms_edit_field_output_li($field_id)
{
    global $wpdb, $ninja_forms_fields, $nf_rte_editors;
    $field_row = ninja_forms_get_field_by_id($field_id);
    $current_tab = ninja_forms_get_current_tab();
    if (isset($_REQUEST['page'])) {
        $current_page = esc_html($_REQUEST['page']);
    } else {
        $current_page = '';
    }
    $field_type = $field_row['type'];
    $field_data = $field_row['data'];
    $plugin_settings = nf_get_settings();
    if (isset($ninja_forms_fields[$field_type]['use_li']) and $ninja_forms_fields[$field_type]['use_li']) {
        if (isset($field_row['fav_id']) and $field_row['fav_id'] != 0) {
            $fav_id = $field_row['fav_id'];
            $fav_row = ninja_forms_get_fav_by_id($fav_id);
            if (empty($fav_row['name'])) {
                $args = array('update_array' => array('fav_id' => ''), 'where' => array('id' => $field_id));
                ninja_forms_update_field($args);
                $fav_id = '';
            }
        } else {
            $fav_id = '';
        }
        if (isset($field_row['def_id']) and $field_row['def_id'] != 0) {
            $def_id = $field_row['def_id'];
        } else {
            $def_id = '';
        }
        $form_id = $field_row['form_id'];
        $field_results = ninja_forms_get_fields_by_form_id($form_id);
        if (isset($ninja_forms_fields[$field_type])) {
            $reg_field = $ninja_forms_fields[$field_type];
            $type_name = $reg_field['name'];
            $edit_function = $reg_field['edit_function'];
            $edit_options = $reg_field['edit_options'];
            if ($reg_field['nesting']) {
                $nesting_class = 'ninja-forms-nest';
            } else {
                $nesting_class = 'ninja-forms-no-nest';
            }
            $conditional = $reg_field['conditional'];
            $type_class = $field_type . '-li';
            if ($def_id != 0 and $def_id != '') {
                $def_row = ninja_forms_get_def_by_id($def_id);
                if (!empty($def_row['name'])) {
                    $type_name = $def_row['name'];
                }
            }
            if ($fav_id != 0 and $fav_id != '') {
                $fav_row = ninja_forms_get_fav_by_id($fav_id);
                if (!empty($fav_row['name'])) {
                    $fav_class = 'ninja-forms-field-remove-fav';
                    $type_name = $fav_row['name'];
                }
            } else {
                $fav_class = 'ninja-forms-field-add-fav';
            }
            if (isset($field_data['label']) and $field_data['label'] != '') {
                $li_label = $field_data['label'];
            } else {
                $li_label = $type_name;
            }
            $li_label = apply_filters('ninja_forms_edit_field_li_label', $li_label, $field_id);
            $li_label = stripslashes($li_label);
            $li_label = ninja_forms_esc_html_deep($li_label);
            if (isset($reg_field) && isset($reg_field['conditional']) && isset($reg_field['conditional']['value']) && isset($reg_field['conditional']['value']['type'])) {
                $conditional_value_type = $reg_field['conditional']['value']['type'];
            } else {
                $conditional_value_type = '';
            }
            ?>
			<li id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
" class="<?php 
            echo $nesting_class;
            ?>
 <?php 
            echo $type_class;
            ?>
">
				<input type="hidden" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_conditional_value_type" value="<?php 
            echo $conditional_value_type;
            ?>
">
				<input type="hidden" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_fav_id" name="" class="ninja-forms-field-fav-id" value="<?php 
            echo $fav_id;
            ?>
">
				<dl class="menu-item-bar">
					<dt class="menu-item-handle" id="ninja_forms_metabox_field_<?php 
            echo $field_id;
            ?>
" >
						<span class="item-title ninja-forms-field-title" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_title"><?php 
            echo $li_label;
            ?>
</span>
						<span class="item-controls">
							<span class="item-type"><?php 
            echo $type_name;
            ?>
</span>
							<a class="item-edit metabox-item-edit" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_toggle" title="<?php 
            _e('Edit Menu Item', 'ninja-forms');
            ?>
" href="#"><?php 
            _e('Edit Menu Item', 'ninja-forms');
            ?>
</a>
						</span>
					</dt>
				</dl>
				<?php 
            $slug = 'field_' . $field_id;
            if (isset($plugin_settings['metabox_state'][$current_page][$current_tab][$slug])) {
                $state = $plugin_settings['metabox_state'][$current_page][$current_tab][$slug];
            } else {
                $state = 'display:none;';
            }
            ?>
				<div class="menu-item-settings type-class inside" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_inside" style="<?php 
            echo $state;
            ?>
">
					<table id="field-info"><tr><td width="65%"><?php 
            _e('Field ID', 'ninja-forms');
            ?>
: <strong><?php 
            echo $field_id;
            ?>
</strong></td><!-- <td width="15%"><a href="#" class="ninja-forms-field-add-def" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_def" class="ninja-forms-field-add-def">Add Defined</a></td><td width="15%"><a href="#" class="ninja-forms-field-remove-def" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_def">Remove Defined</a></td> --> <td width="5%"><a href="#" class="<?php 
            echo $fav_class;
            ?>
" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_fav">Star</a></td></tr></table>
			<?php 
            do_action('ninja_forms_edit_field_before_registered', $field_id);
            $arguments = func_get_args();
            array_shift($arguments);
            // We need to remove the first arg ($function_name)
            $arguments['field_id'] = $field_id;
            $arguments['data'] = $field_data;
            if ($edit_function != '') {
                call_user_func_array($edit_function, $arguments);
            }
            /**
             * We need to get a list of all of our RTEs. 
             * If we're submitting via ajax, we'll need to use this list.
             */
            if (!isset($nf_rte_editors)) {
                $nf_rte_editors = array();
            }
            $editors = new NF_WP_Editor_Ajax();
            if (is_array($edit_options) and !empty($edit_options)) {
                foreach ($edit_options as $opt) {
                    $type = $opt['type'];
                    $label_class = '';
                    if (isset($opt['label'])) {
                        $label = $opt['label'];
                    } else {
                        $label = '';
                    }
                    if (isset($opt['name'])) {
                        $name = $opt['name'];
                    } else {
                        $name = '';
                    }
                    if (isset($opt['width'])) {
                        $width = $opt['width'];
                    } else {
                        $width = '';
                    }
                    if (isset($opt['options'])) {
                        $options = $opt['options'];
                    } else {
                        $options = '';
                    }
                    if (isset($opt['class'])) {
                        $class = $opt['class'];
                    } else {
                        $class = '';
                    }
                    if (isset($opt['default'])) {
                        $default = $opt['default'];
                    } else {
                        $default = '';
                    }
                    if (isset($opt['desc'])) {
                        $desc = $opt['desc'];
                    } else {
                        $desc = '';
                    }
                    if (isset($field_data[$name])) {
                        $value = $field_data[$name];
                    } else {
                        $value = $default;
                    }
                    ninja_forms_edit_field_el_output($field_id, $type, $label, $name, $value, $width, $options, $class, $desc, $label_class);
                }
            }
            do_action('ninja_forms_edit_field_after_registered', $field_id);
        }
    } else {
        if (isset($ninja_forms_fields[$field_type])) {
            $reg_field = $ninja_forms_fields[$field_type];
            $edit_function = $reg_field['edit_function'];
            $arguments = func_get_args();
            array_shift($arguments);
            // We need to remove the first arg ($function_name)
            $arguments['field_id'] = $field_id;
            $arguments['data'] = $field_data;
            if ($edit_function != '') {
                call_user_func_array($edit_function, $arguments);
            }
        }
    }
    /**
     * We need to get a list of all of our RTEs. 
     * If we're submitting via ajax, we'll need to use this list.
     */
    if (isset($_POST['action']) && $_POST['action'] == 'ninja_forms_new_field') {
        if (!empty($nf_rte_editors) && isset($editors) && is_object($editors)) {
            $editors->output_js($field_id, $nf_rte_editors);
        }
    }
}
Example #4
0
function ninja_forms_insert_fav()
{
    global $wpdb, $ninja_forms_fields;
    // Bail if we aren't in the admin
    if (!is_admin()) {
        return false;
    }
    check_ajax_referer('nf_ajax', 'nf_ajax_nonce');
    $fav_id = absint($_REQUEST['fav_id']);
    $form_id = absint($_REQUEST['form_id']);
    $fav_row = ninja_forms_get_fav_by_id($fav_id);
    $data = serialize($fav_row['data']);
    $type = $fav_row['type'];
    $type_name = $ninja_forms_fields[$type]['name'];
    if ($form_id != 0 and $form_id != '') {
        $args = array('type' => $type, 'data' => $data, 'fav_id' => $fav_id);
        $new_id = ninja_forms_insert_field($form_id, $args);
        $new_html = ninja_forms_return_echo('ninja_forms_edit_field', $new_id);
        header("Content-type: application/json");
        $array = array('new_id' => $new_id, 'new_type' => $type_name, 'new_html' => $new_html);
        echo json_encode($array);
    }
    die;
}