/**
 * Outputs the HTML for the ajax processing div. Only used when submitting via ajax.
 *
**/
function ninja_forms_display_process_message($form_id)
{
    global $ninja_forms_processing_error, $ninja_forms_processing_response;
    $plugin_settings = nf_get_settings();
    $form_row = ninja_forms_get_form_by_id($form_id);
    $process_label = __($plugin_settings['process_label'], 'ninja-forms');
    if (isset($form_row['data']['ajax'])) {
        $ajax = $form_row['data']['ajax'];
    } else {
        $ajax = 0;
    }
    if ($ajax == 1) {
        ?>
	<div id="ninja_forms_form_<?php 
        echo $form_id;
        ?>
_process_msg" style="display:none;" class="ninja-forms-processing">
		<?php 
        echo $process_label;
        ?>
 <img src="<?php 
        echo NINJA_FORMS_URL;
        ?>
/images/loading.gif" alt="loading">
	</div>
	<?php 
    }
}
function ninja_forms_admin_js()
{
    global $version_compare;
    if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
        $suffix = '';
        $src = 'dev';
    } else {
        $suffix = '.min';
        $src = 'min';
    }
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    $date_format = ninja_forms_date_to_datepicker($date_format);
    wp_enqueue_script('ninja-forms-admin', NINJA_FORMS_URL . '/js/' . $src . '/ninja-forms-admin' . $suffix . '.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    wp_localize_script('ninja-forms-admin', 'ninja_forms_settings', array('date_format' => $date_format));
    /*
    wp_enqueue_script('jquery.ui.nestedSortable',
    NINJA_FORMS_URL .'/js/dev/jquery.ui.nestedSortable.js',
    array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-dialog', 'jquery-ui-datepicker'));
    */
    //wp_localize_script( 'ninja_forms_admin_js', 'settings', array( 'plugin_url' => NINJA_FORMS_URL, 'help_size' => $plugin_settings['help_size'], 'help_color' => $plugin_settings['help_color'], 'admin_help' => $plugin_settings['admin_help']) );
}
function ninja_forms_preview_link($form_id = '', $echo = true)
{
    if ($form_id == '') {
        if (isset($_REQUEST['form_id'])) {
            $form_id = absint($_REQUEST['form_id']);
        } else {
            $form_id = '';
        }
    }
    $base = home_url();
    $form_data = ninja_forms_get_form_by_id($form_id);
    $append_page = Ninja_Forms()->form($form_id)->get_setting('append_page');
    if (empty($append_page)) {
        $opt = nf_get_settings();
        if (isset($opt['preview_id'])) {
            $page_id = $opt['preview_id'];
        } else {
            $page_id = '';
        }
    } else {
        $page_id = $append_page;
    }
    if ($echo) {
        $preview_link = '<a target="_blank" href="' . $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id . '">' . __('Preview Form', 'ninja-forms') . '</a>';
    } else {
        $preview_link = $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id;
    }
    return $preview_link;
}
Exemple #4
0
function ninja_forms_replyto_change()
{
    $plugin_settings = nf_get_settings();
    if (!isset($plugin_settings['fix_field_reply_to']) or $plugin_settings['fix_field_reply_to'] != 1) {
        $fields = ninja_forms_get_all_fields();
        foreach ($fields as $field) {
            if ($field['type'] = '_text') {
                $change_required = false;
                if (isset($field['data']['from_email']) and $field['data']['from_email'] == 1) {
                    $field['data']['replyto_email'] = 1;
                    unset($field['data']['from_email']);
                    $change_required = true;
                } elseif (isset($field['data']['from_email']) and $field['data']['from_email'] == 0) {
                    $field['data']['replyto_email'] = 0;
                    unset($field['data']['from_email']);
                    $change_required = true;
                }
                if ($change_required) {
                    $data = serialize($field['data']);
                    $args = array('update_array' => array('data' => $data), 'where' => array('id' => $field['id']));
                    ninja_forms_update_field($args);
                }
            }
        }
        $plugin_settings['fix_field_reply_to'] = 1;
        update_option('ninja_forms_settings', $plugin_settings);
    }
}
Exemple #5
0
/**
 * Outputs the HTML of the help icon if it is set to display.
 *
**/
function ninja_forms_display_field_help($field_id, $data)
{
    $plugin_settings = nf_get_settings();
    if (isset($data['show_help'])) {
        $show_help = $data['show_help'];
    } else {
        $show_help = 0;
    }
    if (isset($data['help_text'])) {
        $help_text = $data['help_text'];
    } else {
        $help_text = '';
    }
    $help_text = htmlspecialchars($help_text);
    if ($show_help) {
        ?>
		<img class='ninja-forms-help-text' src="<?php 
        echo NINJA_FORMS_URL;
        ?>
images/question-ico.gif" title="<?php 
        echo $help_text;
        ?>
" alt="<?php 
        _e('Help Text', 'ninja-forms');
        ?>
">
	<?php 
    }
}
function ninja_forms_display_req_items($form_id)
{
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['req_div_label'])) {
        $req_div_label = __($plugin_settings['req_div_label'], 'ninja-forms');
    } else {
        $req_div_label = __('Fields marked with a * are required.', 'ninja-forms');
    }
    $all_fields = ninja_forms_get_fields_by_form_id($form_id);
    $output = false;
    if (is_array($all_fields) and !empty($all_fields)) {
        foreach ($all_fields as $field) {
            if (isset($field['data']['req']) and $field['data']['req'] == 1) {
                $output = true;
            }
        }
    }
    if ($output && $req_div_label != '') {
        ?>
		<div class="ninja-forms-required-items"><?php 
        echo $req_div_label;
        ?>
</div>
		<?php 
    }
}
 /**
  * Process our date submitted trigger.
  * When this function is called, it will be passed the value of the parameter and will expect a bool return.
  * 
  * @since 1.2.8
  * @return bool
  */
 function compare($value, $compare)
 {
     $plugin_settings = nf_get_settings();
     $date_format = $plugin_settings['date_format'];
     $now = date($date_format, current_time('timestamp'));
     return ninja_forms_conditional_compare($now, $value, $compare);
 }
function ninja_forms_preview_link($form_id = '', $echo = true)
{
    if ($form_id == '') {
        if (isset($_REQUEST['form_id'])) {
            $form_id = absint($_REQUEST['form_id']);
        } else {
            $form_id = '';
        }
    }
    $base = home_url();
    $form_data = ninja_forms_get_form_by_id($form_id);
    //if( '' == $form_data['data']['append_page'] ) {
    if (!isset($form_data['data']['append_page']) or empty($form_data['data']['append_page'])) {
        // See the comment above about this check. !empty will ensure that it's not either empty quotes or null.
        $opt = nf_get_settings();
        if (isset($opt['preview_id'])) {
            $page_id = $opt['preview_id'];
        } else {
            $page_id = '';
        }
    } else {
        $page_id = $form_data['data']['append_page'];
    }
    if ($echo) {
        $preview_link = '<a target="_blank" href="' . $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id . '">' . __('Preview Form', 'ninja-forms') . '</a>';
    } else {
        $preview_link = $base . '/?page_id=' . $page_id . '&preview=true&form_id=' . $form_id;
    }
    return $preview_link;
}
function ninja_forms_inside_label_hidden($field_id, $data)
{
    if (isset($data['label_pos']) and $data['label_pos'] == 'inside') {
        $plugin_settings = nf_get_settings();
        if (isset($data['label'])) {
            $label = $data['label'];
        } else {
            $label = '';
        }
        if (isset($data['req'])) {
            $req = $data['req'];
        } else {
            $req = '';
        }
        if (isset($plugin_settings['req_field_symbol'])) {
            $req_symbol = $plugin_settings['req_field_symbol'];
        } else {
            $req_symbol = '';
        }
        if ($req == 1) {
            $req_span = "<span class='ninja-forms-req-symbol'>{$req_symbol}</span>";
        } else {
            $req_span = '';
        }
        ?>
		<input type="hidden" id="ninja_forms_field_<?php 
        echo $field_id;
        ?>
_label_hidden" value="<?php 
        echo $label;
        ?>
">
		<?php 
    }
}
function ninja_forms_display_response_message($form_id)
{
    global $ninja_forms_processing;
    //	if ( ! is_object( $ninja_forms_processing ) || $ninja_forms_processing->get_form_ID() != $form_id ) {
    //		return false;
    //	}
    $plugin_settings = nf_get_settings();
    $form_row = ninja_forms_get_form_by_id($form_id);
    if (isset($form_row['data']['ajax'])) {
        $ajax = $form_row['data']['ajax'];
    } else {
        $ajax = 0;
    }
    if ($ajax == 0 and (is_object($ninja_forms_processing) and !$ninja_forms_processing->get_all_errors() and !$ninja_forms_processing->get_all_success_msgs())) {
        $display = 'display:none;';
    } else {
        $display = '';
    }
    if (is_object($ninja_forms_processing)) {
        if ($ninja_forms_processing->get_errors_by_location('general')) {
            $class = 'ninja-forms-error-msg';
        } else {
            if ($ninja_forms_processing->get_all_success_msgs()) {
                $class = 'ninja-forms-success-msg';
            } else {
                $class = '';
            }
        }
    } else {
        $class = '';
    }
    $class = apply_filters('ninja_forms_display_response_message_class', $class, $form_id);
    //if ( $class != '' ) {
    echo '<div id="ninja_forms_form_' . $form_id . '_response_msg" style="' . $display . '" class="ninja-forms-response-msg ' . $class . '">';
    if (isset($ninja_forms_processing) && $ninja_forms_processing->get_form_ID() == $form_id) {
        if (is_object($ninja_forms_processing)) {
            if ($ninja_forms_processing->get_form_ID() == $form_id) {
                if ($ninja_forms_processing->get_errors_by_location('general')) {
                    foreach ($ninja_forms_processing->get_errors_by_location('general') as $error) {
                        echo '<div>';
                        echo $error['msg'];
                        echo '</div>';
                    }
                }
                if ($ninja_forms_processing->get_all_success_msgs()) {
                    foreach ($ninja_forms_processing->get_all_success_msgs() as $success) {
                        echo '<div>';
                        echo $success;
                        echo '</div>';
                    }
                }
            }
        }
    }
    echo '</div>';
    //}
}
Exemple #11
0
function ninja_forms_display_field_desc($field_id, $data)
{
    $plugin_settings = nf_get_settings();
    if (isset($data['show_desc']) and $data['show_desc'] == 1 and isset($data['desc_text'])) {
        echo '<div class="ninja-forms-field-description">';
        echo do_shortcode(wpautop($data['desc_text']));
        echo '</div>';
    }
}
Exemple #12
0
function ninja_forms_save_label_settings($data)
{
    $plugin_settings = nf_get_settings();
    foreach ($data as $key => $val) {
        $plugin_settings[$key] = $val;
    }
    update_option("ninja_forms_settings", $plugin_settings);
    $update_msg = __('Settings Saved', 'ninja-forms');
    return $update_msg;
}
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;
}
Exemple #14
0
function ninja_forms_field_honeypot_pre_process($field_id, $user_value)
{
    global $ninja_forms_processing;
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['honeypot_error'])) {
        $honeypot_error = __($plugin_settings['honeypot_error'], 'ninja-forms');
    }
    if ($ninja_forms_processing->get_action() != 'save' and $ninja_forms_processing->get_action() != 'mp_save' and !isset($_POST['_wp_login']) and $user_value != '') {
        if (is_object($ninja_forms_processing)) {
            $ninja_forms_processing->add_error('honeypot-' . $field_id, $honeypot_error, $field_id);
        }
    }
}
Exemple #15
0
function ninja_forms_admin_js()
{
    global $version_compare, $public_query_vars;
    $form_id = isset($_REQUEST['form_id']) ? absint($_REQUEST['form_id']) : '';
    if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
        $suffix = '';
        $src = 'dev';
    } else {
        $suffix = '.min';
        $src = 'min';
    }
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    $date_format = ninja_forms_date_to_datepicker($date_format);
    $datepicker_args = array();
    if (!empty($date_format)) {
        $datepicker_args['dateFormat'] = $date_format;
    }
    wp_enqueue_script('ninja-forms-admin', NINJA_FORMS_URL . 'js/' . $src . '/ninja-forms-admin' . $suffix . '.js?nf_ver=' . NF_PLUGIN_VERSION, array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable', 'nf-admin-modal'));
    wp_localize_script('ninja-forms-admin', 'ninja_forms_settings', array('nf_ajax_nonce' => wp_create_nonce('nf_ajax'), 'form_id' => $form_id, 'datepicker_args' => apply_filters('ninja_forms_admin_forms_datepicker_args', $datepicker_args), 'add_fav_prompt' => __('What would you like to name this favorite?', 'ninja-forms'), 'add_fav_error' => __('You must supply a name for this favorite.', 'ninja-forms'), 'deactivate_all_licenses_confirm' => __('Really deactivate all licenses?', 'ninja-forms')));
    wp_localize_script('ninja-forms-admin', 'nf_conversion_title', __('Reset the form conversion process for v2.9+', 'ninja-forms'));
    wp_localize_script('ninja-forms-admin', 'nf_nuke_title', __('Remove ALL Ninja Forms data upon uninstall?', 'ninja-forms'));
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'ninja-forms' && isset($_REQUEST['tab'])) {
        wp_enqueue_script('nf-builder', NINJA_FORMS_URL . 'assets/js/' . $src . '/builder' . $suffix . '.js?nf_ver=' . NF_PLUGIN_VERSION, array('backbone'));
        if ('' != $form_id) {
            $fields = Ninja_Forms()->form($form_id)->fields;
            $current_tab = ninja_forms_get_current_tab();
            $current_page = isset($_REQUEST['page']) ? esc_html($_REQUEST['page']) : '';
            foreach ($fields as $field_id => $field) {
                $fields[$field_id]['metabox_state'] = 0;
            }
            $form_status = Ninja_Forms()->form($form_id)->get_setting('status');
            $form_title = Ninja_Forms()->form($form_id)->get_setting('form_title');
            wp_localize_script('nf-builder', 'nf_admin', array('edit_form_text' => __('Edit Form', 'ninja-forms'), 'form_title' => $form_title, 'form_status' => $form_status, 'fields' => $fields, 'saved_text' => __('Saved', 'ninja-forms'), 'save_text' => __('Save', 'ninja-forms'), 'saving_text' => __('Saving...', 'ninja-forms'), 'remove_field' => __('Remove this field? It will be removed even if you do not save.', 'ninja-forms')));
            $reserved_terms = array('attachment', 'attachment_id', 'author', 'author_name', 'calendar', 'cat', 'category', 'category__and', 'category__in', 'category__not_in', 'category_name', 'comments_per_page', 'comments_popup', 'customize_messenger_channel', 'customized', 'cpage', 'day', 'debug', 'error', 'exact', 'feed', 'hour', 'link_category', 'm', 'minute', 'monthnum', 'more', 'name', 'nav_menu', 'nonce', 'nopaging', 'offset', 'order', 'orderby', 'p', 'page', 'page_id', 'paged', 'pagename', 'pb', 'perm', 'post', 'post__in', 'post__not_in', 'post_format', 'post_mime_type', 'post_status', 'post_tag', 'post_type', 'posts', 'posts_per_archive_page', 'posts_per_page', 'preview', 'robots', 's', 'search', 'second', 'sentence', 'showposts', 'static', 'subpost', 'subpost_id', 'tag', 'tag__and', 'tag__in', 'tag__not_in', 'tag_id', 'tag_slug__and', 'tag_slug__in', 'taxonomy', 'tb', 'term', 'theme', 'type', 'w', 'withcomments', 'withoutcomments', 'year');
            wp_localize_script('nf-builder', 'wp_reserved_terms', $reserved_terms);
        }
    }
}
function ninja_forms_inside_label_hidden($field_id, $data)
{
    if (isset($data['label_pos']) and $data['label_pos'] == 'inside') {
        $plugin_settings = nf_get_settings();
        if (isset($data['label'])) {
            $label = $data['label'];
        } else {
            $label = '';
        }
        ?>
		<input type="hidden" id="ninja_forms_field_<?php 
        echo $field_id;
        ?>
_label_hidden" value="<?php 
        echo $label;
        ?>
">
		<?php 
    }
}
Exemple #17
0
function ninja_forms_admin_js()
{
    global $version_compare;
    if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
        $suffix = '';
        $src = 'dev';
    } else {
        $suffix = '.min';
        $src = 'min';
    }
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    $date_format = ninja_forms_date_to_datepicker($date_format);
    wp_enqueue_script('ninja-forms-admin', NINJA_FORMS_URL . 'js/' . $src . '/ninja-forms-admin' . $suffix . '.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    wp_localize_script('ninja-forms-admin', 'ninja_forms_settings', array('date_format' => $date_format, 'nf_ajax_nonce' => wp_create_nonce('nf_ajax')));
}
Exemple #18
0
function ninja_forms_admin_js()
{
    global $version_compare;
    $form_id = isset($_REQUEST['form_id']) ? $_REQUEST['form_id'] : '';
    if (defined('NINJA_FORMS_JS_DEBUG') && NINJA_FORMS_JS_DEBUG) {
        $suffix = '';
        $src = 'dev';
    } else {
        $suffix = '.min';
        $src = 'min';
    }
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    $date_format = ninja_forms_date_to_datepicker($date_format);
    $datepicker_args = array();
    if (!empty($date_format)) {
        $datepicker_args['dateFormat'] = $date_format;
    }
    wp_enqueue_script('ninja-forms-admin', NINJA_FORMS_URL . 'js/' . $src . '/ninja-forms-admin' . $suffix . '.js', array('jquery', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-datepicker', 'jquery-ui-draggable', 'jquery-ui-droppable'));
    wp_localize_script('ninja-forms-admin', 'ninja_forms_settings', array('nf_ajax_nonce' => wp_create_nonce('nf_ajax'), 'form_id' => $form_id, 'datepicker_args' => apply_filters('ninja_forms_admin_forms_datepicker_args', $datepicker_args), 'add_fav_prompt' => __('What would you like to name this favorite?', 'ninja-forms'), 'add_fav_error' => __('You must supply a name for this favorite.', 'ninja-forms'), 'deactivate_all_licenses_confirm' => __('Really deactivate all licenses?', 'ninja-forms'), 'nuke_warning' => 'This setting will COMPLETELY remove anything Ninja Forms related. This includes SUBMISSIONS and FORMS. It cannot be undone.', 'ninja-forms'));
    if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'ninja-forms' && isset($_REQUEST['tab'])) {
        wp_enqueue_script('nf-builder', NINJA_FORMS_URL . 'assets/js/' . $src . '/builder' . $suffix . '.js', array('backbone'));
        if ('' != $form_id) {
            $fields = Ninja_Forms()->form($form_id)->fields;
            $current_tab = ninja_forms_get_current_tab();
            $current_page = isset($_REQUEST['page']) ? esc_html($_REQUEST['page']) : '';
            foreach ($fields as $field_id => $field) {
                $fields[$field_id]['metabox_state'] = 0;
            }
            $form_status = Ninja_Forms()->form($form_id)->get_setting('status');
            $form_title = Ninja_Forms()->form($form_id)->get_setting('form_title');
            wp_localize_script('nf-builder', 'nf_admin', array('edit_form_text' => __('Edit Form', 'ninja-forms'), 'form_title' => $form_title, 'form_status' => $form_status, 'fields' => $fields, 'saved_text' => __('Saved', 'ninja-forms'), 'save_text' => __('Save', 'ninja-forms'), 'saving_text' => __('Saving...', 'ninja-forms'), 'remove_field' => __('Remove this field? It will be removed even if you do not save.', 'ninja-forms')));
        }
    }
}
Exemple #19
0
function ninja_forms_field_timed_submit_pre_process($field_id, $user_value)
{
    global $ninja_forms_processing;
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['timed_submit_error'])) {
        $timed_submit_error = __($plugin_settings['timed_submit_error'], 'ninja-forms');
    } else {
        $timed_submit_error = __('If you are a human, please slow down.', 'ninja-forms');
    }
    if (isset($plugin_settings['javascript_error'])) {
        $javascript_error = __($plugin_settings['javascript_error'], 'ninja-forms');
    } else {
        $javascript_error = __('You need JavaScript to submit this form. Please enable it and try again.', 'ninja-forms');
    }
    if (isset($user_value['no-js'])) {
        $ninja_forms_processing->add_error('javascript-general', $javascript_error, 'general');
    } else {
        $timer = isset($user_value['timer']) ? $user_value['timer'] : 10;
        if (intval($timer) > 0) {
            $ninja_forms_processing->add_error('timer-' . $field_id, $timed_submit_error, $field_id);
        }
    }
}
function ninja_forms_check_email_from_name()
{
    $plugin_settings = nf_get_settings();
    // Check to see if we've already fixed the setting.
    if (!isset($plugin_settings['fix_form_email_from']) or $plugin_settings['fix_form_email_from'] != 1) {
        // Get our forms.
        $forms = ninja_forms_get_all_forms();
        if (is_array($forms)) {
            foreach ($forms as $form) {
                // Check to see if we've already added the "from_email_name."
                if (!isset($form['data']['email_from_name']) and isset($form['data']['email_from'])) {
                    // This field doesn't have an "email_from_name" saved, so we'll run it through the adjustment function.
                    $email_from = ninja_forms_split_email_from($form['data']['email_from']);
                    $form['data']['email_from'] = $email_from['email_from'];
                    $form['data']['email_from_name'] = $email_from['email_from_name'];
                    $args = array('update_array' => array('data' => serialize($form['data'])), 'where' => array('id' => $form['id']));
                    ninja_forms_update_form($args);
                }
            }
        }
        $plugin_settings['fix_form_email_from'] = 1;
        update_option('ninja_forms_settings', $plugin_settings);
    }
}
Exemple #21
0
 /**
  * Filter our submission list by form_id
  * 
  * @access public
  * @since 2.7
  * @return void
  */
 public function table_filter($query)
 {
     global $pagenow;
     if ($pagenow == 'edit.php' && is_admin() && (isset($query->query['post_type']) && $query->query['post_type'] == 'nf_sub') && is_main_query()) {
         $qv =& $query->query_vars;
         if (!empty($_GET['form_id'])) {
             $form_id = $_GET['form_id'];
         } else {
             $form_id = 0;
         }
         $plugin_settings = nf_get_settings();
         $date_format = $plugin_settings['date_format'];
         if (!empty($_GET['begin_date'])) {
             $begin_date = nf_get_begin_date($_GET['begin_date'])->format("Y-m-d G:i:s");
         } else {
             $begin_date = '';
         }
         if (!empty($_GET['end_date'])) {
             $end_date = nf_get_end_date($_GET['end_date'])->format("Y-m-d G:i:s");
         } else {
             $end_date = '';
         }
         if ($begin_date > $end_date) {
             $begin_date = new DateTime($begin_date);
             $end_date = new DateTime($end_date);
             $end_date_temp = $begin_date;
             $begin_date_temp = $end_date;
             $begin_date = $begin_date_temp;
             $end_date = $end_date_temp;
             $_GET['begin_date'] = $begin_date->format('m/d/Y');
             $_GET['end_date'] = $end_date->format('m/d/Y');
             $begin_date = $begin_date->format("Y-m-d G:i:s");
             $end_date = $end_date->format("Y-m-d G:i:s");
         }
         if (!isset($qv['date_query'])) {
             $qv['date_query'] = array('after' => $begin_date, 'before' => $end_date);
         }
         if (!isset($qv['meta_query'])) {
             $qv['meta_query'] = array(array('key' => '_form_id', 'value' => $form_id, 'compare' => '='));
         }
         $qv = apply_filters('nf_subs_table_qv', $qv, $form_id);
     }
 }
/**
 * ninja_forms_get_subs() has been deprecated in favour of Ninja_Forms()->subs()->get( $args ) or Ninja_Forms()->form( 23 )->get_subs( $args )
 * You can also use WordPress queries ,since this is a custom post type.
 * 
 * @since 2.7
 */
function ninja_forms_get_subs($args = array())
{
    $plugin_settings = nf_get_settings();
    if (isset($plugin_settings['date_format'])) {
        $date_format = $plugin_settings['date_format'];
    } else {
        $date_format = 'm/d/Y';
    }
    if (is_array($args) and !empty($args)) {
        $subs_results = array();
        $meta_query = array();
        $date_query = array();
        if (isset($args['form_id'])) {
            $meta_query[] = array('key' => '_form_id', 'value' => $args['form_id']);
        }
        if (isset($args['user_id'])) {
            $query_args['author'] = $args['user_id'];
        }
        if (isset($args['action'])) {
            $meta_query[] = array('key' => '_action', 'value' => $args['action']);
        }
        if (isset($args['begin_date']) and $args['begin_date'] != '') {
            $query_args['date_query']['after'] = nf_get_begin_date($args['begin_date'])->format("Y-m-d G:i:s");
        }
        if (isset($args['end_date']) and $args['end_date'] != '') {
            $query_args['date_query']['before'] = nf_get_end_date($args['end_date'])->format("Y-m-d G:i:s");
        }
        $query_args = array('post_type' => 'nf_sub', 'date_query' => $date_query, 'meta_query' => $meta_query, 'posts_per_page' => -1);
        $subs = get_posts($query_args);
        if (is_array($subs) && !empty($subs)) {
            $x = 0;
            foreach ($subs as $sub) {
                $data = array();
                $subs_results[$x]['id'] = $sub->ID;
                $subs_results[$x]['user_id'] = $sub->post_author;
                $subs_results[$x]['form_id'] = get_post_meta($sub->ID, '_form_id');
                $subs_results[$x]['action'] = get_post_meta($sub->ID, '_action');
                $meta = get_post_custom($sub->ID);
                foreach ($meta as $key => $array) {
                    if (strpos($key, '_field_') !== false) {
                        $field_id = str_replace('_field_', '', $key);
                        $user_value = $array[0];
                        $data[] = array('field_id' => $field_id, 'user_value' => $user_value);
                    }
                }
                $subs_results[$x]['data'] = $data;
                $subs_results[$x]['date_updated'] = $sub->post_modified;
                $x++;
            }
        }
        return $subs_results;
    }
}
 /**
  * Update our version number if necessary
  * 
  * @access public
  * @since 2.7
  * @return void
  */
 public function update_version_number()
 {
     $plugin_settings = nf_get_settings();
     if (!isset($plugin_settings['version']) or NF_PLUGIN_VERSION != $plugin_settings['version']) {
         $plugin_settings['version'] = NF_PLUGIN_VERSION;
         update_option('ninja_forms_settings', $plugin_settings);
     }
 }
Exemple #24
0
function ninja_forms_field_number_edit($field_id, $data)
{
    $plugin_settings = nf_get_settings();
    $custom = '';
    // Default Value
    if (isset($data['default_value'])) {
        $default_value = $data['default_value'];
    } else {
        $default_value = '';
    }
    if ($default_value == 'none') {
        $default_value = '';
    }
    ?>
	<div class="description description-thin">
		<span class="field-option">
		<label for="">
			<?php 
    _e('Default Value', 'ninja-forms');
    ?>
		</label><br />
			<select id="default_value_<?php 
    echo $field_id;
    ?>
" name="" class="widefat ninja-forms-_text-default-value">
				<option value="" <?php 
    if ($default_value == '') {
        echo 'selected';
        $custom = 'no';
    }
    ?>
><?php 
    _e('None', 'ninja-forms');
    ?>
</option>
				<option value="_user_id" <?php 
    if ($default_value == '_user_id') {
        echo 'selected';
        $custom = 'no';
    }
    ?>
><?php 
    _e('User ID (If logged in)', 'ninja-forms');
    ?>
</option>
				<option value="post_id" <?php 
    if ($default_value == 'post_id') {
        echo 'selected';
        $custom = 'no';
    }
    ?>
><?php 
    _e('Post / Page ID (If available)', 'ninja-forms');
    ?>
</option>
				<option value="_custom" <?php 
    if ($custom != 'no') {
        echo 'selected';
    }
    ?>
><?php 
    _e('Custom', 'ninja-forms');
    ?>
 -></option>
			</select>
		</span>
	</div>
	<div class="description description-thin">

		<label for="" id="default_value_label_<?php 
    echo $field_id;
    ?>
" style="<?php 
    if ($custom == 'no') {
        echo 'display:none;';
    }
    ?>
">
			<span class="field-option">
			<?php 
    _e('Default Value', 'ninja-forms');
    ?>
<br />
			<input type="number" class="widefat code" name="ninja_forms_field_<?php 
    echo $field_id;
    ?>
[default_value]" id="ninja_forms_field_<?php 
    echo $field_id;
    ?>
_default_value" value="<?php 
    echo $default_value;
    ?>
" />
			</span>
		</label>

	</div>
	<?php 
}
function ninja_forms_output_tab_metabox($form_id = '', $slug, $metabox)
{
    $plugin_settings = nf_get_settings();
    if ($form_id != '') {
        $form_row = ninja_forms_get_form_by_id($form_id);
        $current_settings = $form_row['data'];
    } else {
        $form_id = '';
        $current_settings = nf_get_settings();
    }
    $page = $metabox['page'];
    $tab = $metabox['tab'];
    $title = $metabox['title'];
    if (isset($metabox['settings'])) {
        $settings = $metabox['settings'];
    } else {
        $settings = '';
    }
    if (isset($metabox['display_function'])) {
        $display_function = $metabox['display_function'];
    } else {
        $display_function = '';
    }
    if ($metabox['state'] == 'closed') {
        $state = 'display:none;';
    } else {
        $state = '';
    }
    if (isset($plugin_settings['metabox_state'][$page][$tab][$slug])) {
        $state = $plugin_settings['metabox_state'][$page][$tab][$slug];
    }
    if (isset($metabox['display_container'])) {
        $display_container = $metabox['display_container'];
    } else {
        $display_container = true;
    }
    if ($display_container) {
        ?>
		<div id="ninja_forms_metabox_<?php 
        echo $slug;
        ?>
" class="postbox ">
			<span class="item-controls">
				<a class="item-edit metabox-item-edit" id="edit_id" title="<?php 
        _e('Edit Menu Item', 'ninja-forms');
        ?>
" href="#"><?php 
        _e('Edit Menu Item', 'ninja-forms');
        ?>
</a>
			</span>
			<h3 class="hndle"><span><?php 
        _e($title, 'ninja-forms');
        ?>
</span></h3>
			<div class="inside" style="<?php 
        echo $state;
        ?>
">
			<table class="form-table">
				<tbody>
		<?php 
    }
    if (is_array($settings) and !empty($settings)) {
        foreach ($settings as $s) {
            $value = '';
            if (isset($s['name'])) {
                $name = $s['name'];
            } else {
                $name = '';
            }
            $name_array = '';
            if (strpos($name, '[') !== false) {
                $name_array = str_replace(']', '', $name);
                $name_array = explode('[', $name_array);
            }
            if (isset($s['type'])) {
                $type = $s['type'];
            } else {
                $type = '';
            }
            if (isset($s['desc'])) {
                $desc = $s['desc'];
            } else {
                $desc = '';
            }
            if (isset($s['help_text'])) {
                $help_text = $s['help_text'];
            } else {
                $help_text = '';
            }
            if (isset($s['label'])) {
                $label = $s['label'];
            } else {
                $label = '';
            }
            if (isset($s['class'])) {
                $class = $s['class'];
            } else {
                $class = '';
            }
            if (isset($s['tr_class'])) {
                $tr_class = $s['tr_class'];
            } else {
                $tr_class = '';
            }
            if (isset($s['max_file_size'])) {
                $max_file_size = $s['max_file_size'];
            } else {
                $max_file_size = '';
            }
            if (isset($s['select_all'])) {
                $select_all = $s['select_all'];
            } else {
                $select_all = false;
            }
            if (isset($s['default_value'])) {
                $default_value = $s['default_value'];
            } else {
                $default_value = '';
            }
            if (isset($s['style'])) {
                $style = $s['style'];
            } else {
                $style = '';
            }
            if (isset($s['size'])) {
                $size = $s['size'];
            } else {
                $size = '';
            }
            if (isset($s['min'])) {
                $min = $s['min'];
            } else {
                $min = 0;
            }
            if (isset($s['max'])) {
                $max = $s['max'];
            } else {
                $max = '';
            }
            if (is_array($name_array)) {
                $tmp = '';
                foreach ($name_array as $n) {
                    if ($tmp == '') {
                        if (isset($current_settings[$n])) {
                            $tmp = $current_settings[$n];
                        }
                    } else {
                        if (isset($tmp[$n])) {
                            $tmp = $tmp[$n];
                        }
                    }
                }
                $value = !is_array($tmp) && !is_object($tmp) ? $tmp : '';
            } else {
                if (isset($current_settings[$name])) {
                    if (is_array($current_settings[$name])) {
                        $value = ninja_forms_stripslashes_deep($current_settings[$name]);
                    } else {
                        $value = stripslashes($current_settings[$name]);
                    }
                } else {
                    $value = '';
                }
            }
            if ($value == '') {
                $value = $default_value;
            }
            ?>

			<tr id="row_<?php 
            echo $name;
            ?>
" <?php 
            if ($tr_class != '') {
                ?>
class="<?php 
                echo $tr_class;
                ?>
"<?php 
            }
            ?>
 <?php 
            if ($style != '') {
                ?>
 style="<?php 
                echo $style;
                ?>
"<?php 
            }
            ?>
>
				<?php 
            if ($s['type'] == 'desc' and !$label) {
                ?>
					 <td colspan="2">
				<?php 
            } else {
                ?>
					<th scope="row">
						<label for="<?php 
                echo $name;
                ?>
"><?php 
                echo $label;
                ?>
</label>
					</th>
					<td>
				<?php 
            }
            ?>
			<?php 
            switch ($s['type']) {
                case 'text':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>

					<input type="text" class="code widefat <?php 
                    echo $class;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
" />
					<?php 
                    if ($help_text != '') {
                        ?>
					<a href="#" class="tooltip">
					    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
					    <span>
					        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
					        <?php 
                        echo $help_text;
                        ?>
					    </span>
					</a>
					<?php 
                    }
                    break;
                case 'number':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>

					<input type="number" class="code <?php 
                    echo $class;
                    ?>
" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
" min="<?php 
                    echo $min;
                    ?>
" max="<?php 
                    echo $max;
                    ?>
" />
					<?php 
                    if ($help_text != '') {
                        ?>
					<a href="#" class="tooltip">
					    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
					    <span>
					        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
					        <?php 
                        echo $help_text;
                        ?>
					    </span>
					</a>
					<?php 
                    }
                    break;
                case 'select':
                    ?>
					<select name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
						<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        foreach ($s['options'] as $option) {
                            ?>
								<option value="<?php 
                            echo $option['value'];
                            ?>
" <?php 
                            selected($value, $option['value']);
                            ?>
><?php 
                            echo $option['name'];
                            ?>
</option>
								<?php 
                        }
                    }
                    ?>
					</select>
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'multi_select':
                    if ($value == '') {
                        $value = array();
                    }
                    ?>

					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="">
					<select name="<?php 
                    echo $name;
                    ?>
[]" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" multiple="multiple" size="<?php 
                    echo $size;
                    ?>
">
						<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        foreach ($s['options'] as $option) {
                            ?>
								<option value="<?php 
                            echo $option['value'];
                            ?>
" <?php 
                            selected(in_array($option['value'], $value));
                            ?>
><?php 
                            echo $option['name'];
                            ?>
</option>
								<?php 
                        }
                    }
                    ?>
					</select>
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
/images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'checkbox':
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="0">
					<input type="checkbox" name="<?php 
                    echo $name;
                    ?>
" value="1" <?php 
                    checked($value, 1);
                    ?>
 id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
					<?php 
                    if ($help_text != '') {
                        ?>
						<a href="#" class="tooltip">
						    <img id="" class='ninja-forms-help-text' src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/question-ico.gif" title="">
						    <span>
						        <img class="callout" src="<?php 
                        echo NINJA_FORMS_URL;
                        ?>
images/callout.gif" />
						        <?php 
                        echo $help_text;
                        ?>
						    </span>
						</a>
					<?php 
                    }
                    break;
                case 'checkbox_list':
                    if ($value == '') {
                        $value = array();
                    }
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" value="">

						<?php 
                    if ($select_all) {
                        ?>

								<label>
									<input type="checkbox" name="" value="" id="<?php 
                        echo $name;
                        ?>
_select_all" class="ninja-forms-select-all" title="ninja-forms-<?php 
                        echo $name;
                        ?>
">
								- <?php 
                        _e('Select All', 'ninja-forms');
                        ?>
								</label>

						<?php 
                    } else {
                        if (is_array($s['options']) and isset($s['options'][0])) {
                            $option_name = $s['options'][0]['name'];
                            $option_value = $s['options'][0]['value'];
                            ?>

									<label>
										<input type="checkbox" class="ninja-forms-<?php 
                            echo $name;
                            ?>
 <?php 
                            echo $class;
                            ?>
" name="<?php 
                            echo $name;
                            ?>
[]" value="<?php 
                            echo $option_value;
                            ?>
" <?php 
                            checked(in_array($option_value, $value));
                            ?>
 id="<?php 
                            echo $option_name;
                            ?>
">
										<?php 
                            echo $option_name;
                            ?>
									</label>

								<?php 
                        }
                    }
                    ?>

					<?php 
                    if (is_array($s['options']) and !empty($s['options'])) {
                        $x = 0;
                        foreach ($s['options'] as $option) {
                            if (!$select_all and $x > 0 or $select_all) {
                                $option_name = $option['name'];
                                $option_value = $option['value'];
                                ?>
										<label>
											<input type="checkbox" class="ninja-forms-<?php 
                                echo $name;
                                ?>
 <?php 
                                echo $class;
                                ?>
" name="<?php 
                                echo $name;
                                ?>
[]" value="<?php 
                                echo $option_value;
                                ?>
" <?php 
                                checked(in_array($option_value, $value));
                                ?>
 id="<?php 
                                echo $option_name;
                                ?>
">
											<?php 
                                echo $option_name;
                                ?>
										</label>
								<?php 
                            }
                            $x++;
                        }
                    }
                    break;
                case 'radio':
                    if (is_array($s['options']) and !empty($s['options'])) {
                        $x = 0;
                        ?>
						<?php 
                        foreach ($s['options'] as $option) {
                            ?>
							<input type="radio" name="<?php 
                            echo $name;
                            ?>
" value="<?php 
                            echo $option['value'];
                            ?>
" id="<?php 
                            echo $name . "_" . $x;
                            ?>
" <?php 
                            checked($value, $option['value']);
                            ?>
 class="<?php 
                            echo $class;
                            ?>
"> <label for="<?php 
                            echo $name . "_" . $x;
                            ?>
"><?php 
                            echo $option['name'];
                            ?>
</label>
								<?php 
                            if ($help_text != '') {
                                ?>
									<a href="#" class="tooltip">
									    <img id="" class='ninja-forms-help-text' src="<?php 
                                echo NINJA_FORMS_URL;
                                ?>
images/question-ico.gif" title="">
									    <span>
									        <img class="callout" src="<?php 
                                echo NINJA_FORMS_URL;
                                ?>
images/callout.gif" />
									        <?php 
                                echo $help_text;
                                ?>
									    </span>
									</a>
								<?php 
                            }
                            ?>
							<br />

						<?php 
                            $x++;
                        }
                    }
                    break;
                case 'textarea':
                    $value = ninja_forms_esc_html_deep($value);
                    ?>
					<textarea name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
"><?php 
                    echo $value;
                    ?>
</textarea>
					<?php 
                    break;
                case 'rte':
                    $args = apply_filters('ninja_forms_admin_metabox_rte', array());
                    wp_editor($value, $name, $args);
                    break;
                case 'file':
                    ?>
					<input type="hidden" name="MAX_FILE_SIZE" value="<?php 
                    echo $max_file_size;
                    ?>
" />
					<input type="file" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
">
					<?php 
                    break;
                case 'desc':
                    echo $desc;
                    break;
                case 'hidden':
                    ?>
					<input type="hidden" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" value="<?php 
                    echo $value;
                    ?>
">
					<?php 
                    break;
                case 'submit':
                    ?>
					<input type="submit" name="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" value="<?php 
                    echo $label;
                    ?>
">
					<?php 
                    break;
                case 'button':
                    // set a default value for $class to maintain the standard WordPress UI
                    if (isset($class) && empty($class)) {
                        $class = "button-secondary";
                    }
                    ?>
					<input type="button" name="<?php 
                    echo $name;
                    ?>
" id="<?php 
                    echo $name;
                    ?>
" class="<?php 
                    echo $class;
                    ?>
" value="<?php 
                    echo $label;
                    ?>
">
					<?php 
                    break;
                default:
                    if (isset($s['display_function'])) {
                        $s_display_function = $s['display_function'];
                        if ($s_display_function != '') {
                            $arguments['form_id'] = $form_id;
                            $arguments['data'] = $current_settings;
                            $arguments['field'] = $s;
                            call_user_func_array($s_display_function, $arguments);
                        }
                    }
                    break;
            }
            if ($desc != '' and $s['type'] != 'desc') {
                ?>
					<p class="description">
						<?php 
                echo $desc;
                ?>
					</p>
				<?php 
            }
            echo '</td></tr>';
        }
    }
    if ($display_function != '') {
        if ($form_id != '') {
            $arguments['form_id'] = $form_id;
        }
        $arguments['metabox'] = $metabox;
        call_user_func_array($display_function, $arguments);
    }
    if ($display_container) {
        ?>
					</tbody>
				</table>
			</div>
		</div>
		<?php 
    }
}
Exemple #26
0
function ninja_forms_edit_field_output_li($field_id, $new = false)
{
    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']) && $ninja_forms_fields[$field_type]['use_li']) {
        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 = '';
        }
        $form_id = $field_row['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'];
            $li_class = $reg_field['li_class'];
            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 && $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 && $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']) && $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 $li_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"><span class="spinner" style="margin-top:-2px;float:left;"></span><span class="item-type-name"><?php 
            echo $type_name;
            ?>
</span></span>
							<a class="item-edit nf-edit-field" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_toggle" title="<?php 
            _e('Edit Menu Item', 'ninja-forms');
            ?>
" href="#" data-field="<?php 
            echo $field_id;
            ?>
"><?php 
            _e('Edit Menu Item', 'ninja-forms');
            ?>
</a>
						</span>
					</dt>
				</dl>
				<?php 
            if ($new) {
                $padding = '';
            } else {
                $padding = 'no-padding';
            }
            ?>
				<div class="menu-item-settings type-class inside <?php 
            echo $padding;
            ?>
" id="ninja_forms_field_<?php 
            echo $field_id;
            ?>
_inside" >
					<?php 
            if ($new) {
                nf_output_registered_field_settings($field_id);
            }
        }
    } else {
        if (isset($ninja_forms_fields[$field_type])) {
            $reg_field = $ninja_forms_fields[$field_type];
            $edit_function = $reg_field['edit_function'];
            $arguments = array();
            $arguments['field_id'] = $field_id;
            $arguments['data'] = $field_data;
            if ($edit_function != '') {
                call_user_func_array($edit_function, $arguments);
            }
        }
    }
}
Exemple #27
0
 /**
  * Export submissions.
  * 
  * @access public
  * @param array $sub_ids
  * @param bool @return
  * @since 2.7
  * @return void
  */
 public function export($sub_ids = '', $return = false)
 {
     global $ninja_forms_fields;
     // Bail if we haven't been sent any IDs.
     if (empty($sub_ids)) {
         return false;
     }
     if (!is_array($sub_ids)) {
         $sub_ids = array($sub_ids);
     }
     $plugin_settings = nf_get_settings();
     $date_format = $plugin_settings['date_format'];
     $label_array = array();
     // Get our Form ID.
     $form_id = Ninja_Forms()->sub($sub_ids[0])->form_id;
     // Get our list of fields.
     $fields = Ninja_Forms()->form($form_id)->fields;
     // Add our sequential number.
     $label_array[0]['_seq_num'] = __('#', 'ninja-forms');
     // Add our "Date" label.
     $label_array[0]['_date_submitted'] = __('Date Submitted', 'ninja-forms');
     $label_array = apply_filters('nf_subs_csv_label_array_before_fields', $label_array, $sub_ids);
     foreach ($fields as $field_id => $field) {
         // Get our field type
         $field_type = $field['type'];
         // Check to see if our field type has been set as a "process_field".
         if (isset($ninja_forms_fields[$field_type])) {
             $reg_field = $ninja_forms_fields[$field_type];
             $process_field = $reg_field['process_field'];
         } else {
             $process_field = false;
         }
         // If this field's "process_field" is set to true, then add its label to the array.
         if ($process_field) {
             if (isset($field['data']['admin_label']) && $field['data']['admin_label'] != '') {
                 $label = $field['data']['admin_label'];
             } else {
                 if (isset($field['data']['label'])) {
                     $label = $field['data']['label'];
                 } else {
                     $label = '';
                 }
             }
             $label_array[0][$field_id] = apply_filters('nf_subs_csv_field_label', $label, $field_id);
         }
     }
     $label_array = ninja_forms_stripslashes_deep($label_array);
     $label_array = apply_filters('nf_subs_csv_label_array', $label_array, $sub_ids);
     $value_array = array();
     $x = 0;
     // Loop through our submissions and create a new row for each one.
     foreach ($sub_ids as $sub_id) {
         foreach ($label_array[0] as $field_id => $label) {
             // Make sure we aren't working with our date field, which will always have a field id of 0.
             if ($field_id !== 0) {
                 // Check to see if our field_id is numeric. If it isn't, then we're working with meta, not a field.
                 if (is_numeric($field_id)) {
                     // We're working with a field, grab the value.
                     $user_value = Ninja_Forms()->sub($sub_id)->get_field($field_id);
                 } else {
                     if ('_date_submitted' == $field_id) {
                         // Get the date of our submission.
                         $date = strtotime(Ninja_Forms()->sub($sub_id)->date_submitted);
                         // The first item is our date field.
                         $user_value = date($date_format, $date);
                     } else {
                         if ('_seq_num' == $field_id) {
                             $user_value = Ninja_Forms()->sub($sub_id)->get_seq_num();
                         } else {
                             // We're working with a piece of meta, grabe the value.
                             $user_value = Ninja_Forms()->sub($sub_id)->get_meta($field_id);
                         }
                     }
                 }
                 // Run our value through the appropriate filters before we flatten any arrays.
                 $user_value = apply_filters('nf_subs_export_pre_value', $user_value, $field_id);
                 // Implode any arrays we might have.
                 if (is_array($user_value)) {
                     $user_value = implode(',', $user_value);
                 }
                 // Add an ' to the beginning = sign to prevent any CSV/Excel security issues.
                 if (strpos($user_value, '=') === 0) {
                     $user_value = "'" . $user_value;
                 }
                 // Run our final value through the appropriate filters and assign it to the array.
                 $value_array[$x][$field_id] = htmlspecialchars_decode(apply_filters('nf_subs_csv_field_value', $user_value, $field_id), ENT_QUOTES);
             }
         }
         $x++;
     }
     $value_array = ninja_forms_stripslashes_deep($value_array);
     $value_array = apply_filters('nf_subs_csv_value_array', $value_array, $sub_ids);
     $array = array($label_array, $value_array);
     $today = date($date_format, current_time('timestamp'));
     $filename = apply_filters('nf_subs_csv_filename', 'nf_subs_' . $today);
     $filename = $filename . ".csv";
     if ($return) {
         return str_putcsv($array, apply_filters('nf_sub_csv_delimiter', ','), apply_filters('nf_sub_csv_enclosure', '"'), apply_filters('nf_sub_csv_terminator', "\n"));
     } else {
         header('Content-type: application/csv');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Pragma: no-cache');
         header('Expires: 0');
         echo apply_filters('nf_sub_csv_bom', "");
         // Byte Order Mark
         echo str_putcsv($array, apply_filters('nf_sub_csv_delimiter', ','), apply_filters('nf_sub_csv_enclosure', '"'), apply_filters('nf_sub_csv_terminator', "\n"));
         die;
     }
 }
 /**
  * Get any error messages for this license field.
  *
  * @access public
  * @since 2.9
  * @return string $error
  */
 public function get_error()
 {
     $plugin_settings = nf_get_settings();
     $error = !empty($plugin_settings[$this->product_name . '_license_error']) ? $plugin_settings[$this->product_name . '_license_error'] : false;
     return $error;
 }
function ninja_forms_save_screen_option_tabs()
{
    $current_tab = ninja_forms_get_current_tab();
    $current_page = $_REQUEST['page'];
    $opt = nf_get_settings();
    if (is_array($_POST['ninja-forms-tab'])) {
        foreach ($_POST['ninja-forms-tab'] as $slug => $val) {
            $opt['screen_options']['tab'][$slug]['visible'] = $val;
        }
    }
    if (is_array($_POST['ninja-forms-sidebar'])) {
        foreach ($_POST['ninja-forms-sidebar'] as $slug => $val) {
            $opt['screen_options']['tab'][$current_tab]['sidebars'][$slug]['visible'] = $val;
        }
    }
    update_option('ninja_forms_settings', $opt);
}
function ninja_forms_req_fields_process()
{
    global $ninja_forms_processing, $ninja_forms_fields;
    $all_fields = $ninja_forms_processing->get_all_fields();
    if (is_array($all_fields) and !empty($all_fields)) {
        foreach ($all_fields as $field_id => $user_value) {
            $field_row = $ninja_forms_processing->get_field_settings($field_id);
            if (!$field_row) {
                $field_row = ninja_forms_get_field_by_id($field_id);
            }
            $field_type = $field_row['type'];
            if (isset($ninja_forms_fields[$field_type])) {
                if (isset($field_row['data'])) {
                    $field_data = $field_row['data'];
                } else {
                    $field_data = '';
                }
                if (isset($field_data['req'])) {
                    $req = $field_data['req'];
                } else {
                    $req = '';
                }
                if (isset($field_data['label_pos'])) {
                    $label_pos = $field_data['label_pos'];
                } else {
                    $label_pos = '';
                }
                // Get the required field symbol.
                $settings = nf_get_settings();
                if (isset($settings['req_field_symbol'])) {
                    $req_symbol = $settings['req_field_symbol'];
                } else {
                    $req_symbol = '*';
                }
                if (isset($field_data['req']) and $field_data['req'] == 1 and $label_pos == 'inside') {
                    $field_data['label'] .= ' ' . $req_symbol;
                }
                if (isset($field_data['label'])) {
                    $label = $field_data['label'];
                } else {
                    $label = '';
                }
                $label = strip_tags($label);
                $reg_type = $ninja_forms_fields[$field_type];
                $req_validation = $reg_type['req_validation'];
                $plugin_settings = nf_get_settings();
                if (isset($plugin_settings['req_field_error'])) {
                    $req_field_error = __($plugin_settings['req_field_error'], 'ninja-forms');
                } else {
                    $req_field_error = __('This is a required field.', 'ninja-forms');
                }
                if (isset($plugin_settings['req_error_label'])) {
                    $req_error_label = __($plugin_settings['req_error_label'], 'ninja-forms');
                } else {
                    $req_error_label = __('Please check required fields.', 'ninja-forms');
                }
                if ($req == 1 and $user_value !== false) {
                    if ($req_validation != '') {
                        $arguments['field_id'] = $field_id;
                        $arguments['user_value'] = $user_value;
                        $req = call_user_func_array($req_validation, $arguments);
                        if (!$req) {
                            $ninja_forms_processing->add_error('required-' . $field_id, $req_field_error, $field_id);
                            $ninja_forms_processing->add_error('required-general', $req_error_label, 'general');
                        }
                    } else {
                        if ($label_pos == 'inside') {
                            if ($user_value == $label or empty($user_value)) {
                                $ninja_forms_processing->add_error('required-' . $field_id, $req_field_error, $field_id);
                                $ninja_forms_processing->add_error('required-general', $req_error_label, 'general');
                            }
                        } else {
                            if ($user_value === '') {
                                $ninja_forms_processing->add_error('required-' . $field_id, $req_field_error, $field_id);
                                $ninja_forms_processing->add_error('required-general', $req_error_label, 'general');
                            }
                        }
                    }
                }
            }
        }
    }
}