public static function create($values = array())
 {
     FrmAppHelper::permission_check('frm_edit_forms');
     global $frm_vars;
     if (empty($values)) {
         $values = $_POST;
     }
     //Set radio button and checkbox meta equal to "other" value
     if (FrmAppHelper::pro_is_installed()) {
         $values = FrmProEntry::mod_other_vals($values, 'back');
     }
     $id = isset($values['id']) ? absint($values['id']) : FrmAppHelper::get_param('id', '', 'get', 'absint');
     if (!current_user_can('frm_edit_forms') || $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce'))) {
         $frm_settings = FrmAppHelper::get_settings();
         $errors = array('form' => $frm_settings->admin_permission);
     } else {
         $errors = FrmForm::validate($values);
     }
     if (count($errors) > 0) {
         $hide_preview = true;
         $frm_field_selection = FrmField::field_selection();
         $form = FrmForm::getOne($id);
         $fields = FrmField::get_all_for_form($id);
         $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
         $all_templates = FrmForm::getAll(array('is_template' => 1), 'name');
         require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php';
     } else {
         FrmForm::update($id, $values, true);
         die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id=' . $id)));
     }
 }
 public static function display_list($message = '', $errors = array())
 {
     global $wpdb, $frm_vars;
     $form = FrmForm::get_current_form();
     $params = FrmForm::get_admin_params($form);
     if ($form) {
         $params['form'] = $form->id;
         $frm_vars['current_form'] = $form;
         if ('trash' == $form->status) {
             $delete_timestamp = time() - DAY_IN_SECONDS * EMPTY_TRASH_DAYS;
             $time_to_delete = FrmAppHelper::human_time_diff($delete_timestamp, isset($form->options['trash_time']) ? $form->options['trash_time'] : time());
             $errors['trash'] = sprintf(__('This form is in the trash and is scheduled to be deleted permanently in %s along with any entries.', 'formidable'), $time_to_delete);
             unset($time_to_delete, $delete_timestamp);
         }
     }
     $table_class = apply_filters('frm_entries_list_class', 'FrmEntriesListHelper');
     $wp_list_table = new $table_class(array('params' => $params));
     $pagenum = $wp_list_table->get_pagenum();
     $wp_list_table->prepare_items();
     $total_pages = $wp_list_table->get_pagination_arg('total_pages');
     if ($pagenum > $total_pages && $total_pages > 0) {
         $url = add_query_arg('paged', $total_pages);
         if (headers_sent()) {
             echo FrmAppHelper::js_redirect($url);
         } else {
             wp_redirect(esc_url_raw($url));
         }
         die;
     }
     if (empty($message) && isset($_GET['import-message'])) {
         $message = __('Your import is complete', 'formidable');
     }
     require FrmAppHelper::plugin_path() . '/classes/views/frm-entries/list.php';
 }
 public static function create($values = false)
 {
     global $frm_entry, $frm_field, $frm_vars;
     if (!$values) {
         $values = $_POST;
     }
     if (!current_user_can('frm_edit_forms') || $_POST && (!isset($values['frm_save_form']) || !wp_verify_nonce($values['frm_save_form'], 'frm_save_form_nonce'))) {
         global $frm_settings;
         $errors['form'] = $frm_settings->admin_permission;
     }
     $id = isset($values['id']) ? (int) $values['id'] : (int) FrmAppHelper::get_param('id');
     $frm_form = new FrmForm();
     $errors = $frm_form->validate($values);
     if (count($errors) > 0) {
         $hide_preview = true;
         $frm_field_selection = FrmFieldsHelper::field_selection();
         $form = $frm_form->getOne($id);
         $fields = $frm_field->getAll(array('fi.form_id' => $id), 'field_order');
         $values = FrmAppHelper::setup_edit_vars($form, 'forms', $fields, true);
         require FrmAppHelper::plugin_path() . '/classes/views/frm-forms/new.php';
     } else {
         $form = $frm_form->update($id, $values, true);
         die(FrmAppHelper::js_redirect(admin_url('admin.php?page=formidable&frm_action=settings&id=' . $id)));
         //$message = __('Form was Successfully Created', 'formidable');
         //return self::settings($record, $message);
     }
 }
 public static function display_list($params = array(), $message = '', $errors = array())
 {
     global $wpdb, $frmdb, $frm_entry, $frm_entry_meta, $frm_field, $frm_vars;
     if (empty($params)) {
         $params = self::get_params();
     }
     $errors = array();
     $frm_form = new FrmForm();
     $form_select = $frm_form->getAll("is_template=0 AND (status is NULL OR status = '' OR status = 'published')", ' ORDER BY name');
     if ($params['form']) {
         $form = $frm_form->getOne($params['form']);
     } else {
         $form = isset($form_select[0]) ? $form_select[0] : 0;
     }
     if ($form) {
         $params['form'] = $form->id;
         $frm_vars['current_form'] = $form;
         $where_clause = " it.form_id={$form->id}";
     } else {
         $where_clause = '';
     }
     require FrmAppHelper::plugin_path() . '/pro/classes/helpers/FrmProListHelper.php';
     $wp_list_table = new FrmProListHelper(array('singular' => 'entry', 'plural' => 'entries', 'table_name' => $frmdb->entries, 'page_name' => 'entries', 'params' => $params));
     $pagenum = $wp_list_table->get_pagenum();
     $wp_list_table->prepare_items();
     $total_pages = $wp_list_table->get_pagination_arg('total_pages');
     if ($pagenum > $total_pages && $total_pages > 0) {
         $url = add_query_arg('paged', $total_pages);
         if (headers_sent()) {
             echo FrmAppHelper::js_redirect($url);
         } else {
             wp_redirect($url);
         }
         die;
     }
     if (empty($message) && isset($_GET['import-message'])) {
         $message = __('Your import is complete', 'formidable');
     }
     require FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-entries/list.php';
 }
 public static function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array())
 {
     global $frmpro_display, $frm_entry, $frmpro_settings, $frm_entry_meta, $frm_vars, $post;
     $frm_vars['forms_loaded'][] = true;
     if (!isset($display->frm_form_id)) {
         $display = FrmProDisplaysHelper::setup_edit_vars($display, false);
     }
     if (!isset($display->frm_form_id) or empty($display->frm_form_id)) {
         return $content;
     }
     // check if entry needs to be deleted before loading entries
     if (FrmAppHelper::get_param('frm_action') == 'destroy' && isset($_GET['entry'])) {
         $deleted = FrmProEntriesController::ajax_destroy($display->frm_form_id, false, false);
         if (!empty($deleted)) {
             $message = '<div class="with_frm_style"><div class="frm_message">' . $deleted . '</div></div>';
         }
         unset($_GET['entry']);
     }
     //for backwards compatability
     $display->id = $display->frm_old_id;
     $display->display_key = $display->post_name;
     $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '', 'drafts' => false, 'auto_id' => '');
     extract(wp_parse_args($extra_atts, $defaults));
     //if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
     //    self::parse_pretty_entry_url();
     if ($display->frm_show_count == 'one' and is_numeric($display->frm_entry_id) and $display->frm_entry_id > 0 and !$entry_id) {
         $entry_id = $display->frm_entry_id;
     }
     $entry = false;
     $show = 'all';
     global $wpdb, $frmpro_entry;
     $where = $wpdb->prepare('it.form_id=%d', $display->frm_form_id);
     if (in_array($display->frm_show_count, array('dynamic', 'calendar', 'one'))) {
         $one_param = isset($_GET['entry']) ? $_GET['entry'] : $auto_id;
         $get_param = isset($_GET[$display->frm_param]) ? $_GET[$display->frm_param] : ($display->frm_show_count == 'one' ? $one_param : $auto_id);
         unset($one_param);
         if ($get_param) {
             if (($display->frm_type == 'id' or $display->frm_show_count == 'one') and is_numeric($get_param)) {
                 $where .= $wpdb->prepare(' AND it.id=%d', $get_param);
             } else {
                 $where .= $wpdb->prepare(' AND it.item_key=%s', $get_param);
             }
             $entry = $frm_entry->getAll($where, '', 1, 0);
             if ($entry) {
                 $entry = reset($entry);
             }
             if ($entry and $entry->post_id) {
                 //redirect to single post page if this entry is a post
                 if (in_the_loop() and $display->frm_show_count != 'one' and !is_single($entry->post_id) and $post->ID != $entry->post_id) {
                     $this_post = get_post($entry->post_id);
                     if (in_array($this_post->post_status, array('publish', 'private'))) {
                         die(FrmAppHelper::js_redirect(get_permalink($entry->post_id)));
                     }
                 }
             }
         }
         unset($get_param);
     }
     if ($entry and in_array($display->frm_show_count, array('dynamic', 'calendar'))) {
         $new_content = $display->frm_dyncontent;
         $show = 'one';
     } else {
         $new_content = $display->post_content;
     }
     $show = $display->frm_show_count == 'one' ? 'one' : $show;
     $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->frm_form_id);
     //don't let page size and limit override single entry displays
     if ($display->frm_show_count == 'one') {
         $display->frm_page_size = $display->frm_limit = '';
     }
     //don't keep current content if post type is frm_display
     if ($post and $post->post_type == 'frm_display') {
         $display->frm_insert_loc = '';
     }
     $pagination = '';
     $is_draft = !empty($drafts) ? 1 : 0;
     $form_query = $wpdb->prepare("SELECT id, post_id FROM {$wpdb->prefix}frm_items WHERE form_id=%d and post_id>%d", $display->frm_form_id, 1);
     if ($drafts != 'both') {
         $form_query .= $wpdb->prepare(' AND is_draft=%d', $is_draft);
     }
     if ($entry and $entry->form_id == $display->frm_form_id) {
         $form_query .= $wpdb->prepare(' AND id=%d', $entry->id);
         $form_posts = $wpdb->get_results($form_query);
         $entry_ids = array($entry->id);
     } else {
         $form_posts = $wpdb->get_results($form_query);
         //Only get $entry_ids if filters are set or if frm_search parameter is set
         if (isset($display->frm_where) && !empty($display->frm_where) && (!$entry || !$post || empty($auto_id)) || isset($_GET['frm_search'])) {
             $entry_query = $wpdb->prepare("SELECT id FROM {$wpdb->prefix}frm_items WHERE form_id=%d", $display->frm_form_id);
             if ($drafts != 'both') {
                 $entry_query .= $wpdb->prepare(" AND is_draft=%d", $is_draft);
             }
             $entry_ids = $wpdb->get_col($entry_query);
             unset($entry_query);
         }
     }
     unset($form_query);
     $empty_msg = (isset($display->frm_empty_msg) and !empty($display->frm_empty_msg)) ? '<div class="frm_no_entries">' . FrmProFieldsHelper::get_default_value($display->frm_empty_msg, false, true, true) . '</div>' : '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $empty_msg = $message . $empty_msg;
     }
     $after_where = false;
     if ($user_id and !empty($user_id)) {
         $user_id = FrmProAppHelper::get_user_id_param($user_id);
         $uid_used = false;
     }
     if (isset($display->frm_where) && !empty($display->frm_where) && (!$entry || !$post || empty($auto_id))) {
         $display->frm_where = apply_filters('frm_custom_where_opt', $display->frm_where, array('display' => $display, 'entry' => $entry));
         $continue = false;
         foreach ($display->frm_where as $where_key => $where_opt) {
             $where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : '';
             if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                 //if this param doesn't exist, then don't include it
                 if ($where_val == '') {
                     if (!$after_where) {
                         $continue = true;
                     }
                     continue;
                 }
             } else {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
             }
             $continue = false;
             if ($where_val == 'current_user') {
                 if ($user_id and is_numeric($user_id)) {
                     $where_val = $user_id;
                     $uid_used = true;
                 } else {
                     $where_val = get_current_user_id();
                 }
             }
             $where_val = do_shortcode($where_val);
             if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) {
                 $where_val = explode(',', $where_val);
             }
             if (is_array($where_val) and !empty($where_val)) {
                 $new_where = '(';
                 if (strpos($display->frm_where_is[$where_key], 'LIKE') !== false) {
                     foreach ($where_val as $w) {
                         if ($new_where != '(') {
                             $new_where .= ',';
                         }
                         $new_where .= $wpdb->prepare('%s', '%' . FrmAppHelper::esc_like($w) . '%');
                         unset($w);
                     }
                 } else {
                     foreach ($where_val as $w) {
                         if ($new_where != '(') {
                             $new_where .= ',';
                         }
                         $new_where .= $wpdb->prepare('%s', $w);
                         unset($w);
                     }
                 }
                 $new_where .= ')';
                 $where_val = $new_where;
                 unset($new_where);
                 if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) {
                     $display->frm_where_is[$where_key] = ' in ';
                 } else {
                     $display->frm_where_is[$where_key] = ' not in ';
                 }
             }
             if (is_numeric($where_opt)) {
                 $filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft));
                 $entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts);
                 unset($filter_opts);
                 $after_where = true;
                 $continue = false;
                 if (empty($entry_ids)) {
                     break;
                 }
             } else {
                 if ($where_opt == 'created_at' or $where_opt == 'updated_at') {
                     if ($where_val == 'NOW') {
                         $where_val = current_time('mysql', 1);
                     }
                     if (strpos($display->frm_where_is[$where_key], 'LIKE') === false) {
                         $where_val = date('Y-m-d H:i:s', strtotime($where_val));
                     }
                     $where .= $wpdb->prepare(" and it.{$where_opt} " . $display->frm_where_is[$where_key] . "%s", '');
                     if (strpos($display->frm_where_is[$where_key], 'in')) {
                         $where .= " {$where_val}";
                     } else {
                         if (strpos($display->frm_where_is[$where_key], 'LIKE') !== false) {
                             $where .= $wpdb->prepare(" %s", '%' . FrmAppHelper::esc_like($where_val) . '%');
                         } else {
                             $where .= $wpdb->prepare(" %s", $where_val);
                         }
                     }
                     $continue = true;
                 } else {
                     if (in_array($where_opt, array('id', 'item_key', 'post_id'))) {
                         $where .= " and it.{$where_opt} " . $display->frm_where_is[$where_key];
                         if (strpos($display->frm_where_is[$where_key], 'in')) {
                             $where .= " {$where_val}";
                         } else {
                             $where .= $wpdb->prepare(" %s", $where_val);
                         }
                         $continue = true;
                     }
                 }
             }
         }
         if (!$continue and empty($entry_ids)) {
             if ($display->frm_insert_loc == 'after') {
                 $content .= $empty_msg;
             } else {
                 if ($display->frm_insert_loc == 'before') {
                     $content = $empty_msg . $content;
                 } else {
                     if ($filter) {
                         $empty_msg = apply_filters('the_content', $empty_msg);
                     }
                     if ($post->post_type == 'frm_display' and in_the_loop()) {
                         $content = '';
                     }
                     $content .= $empty_msg;
                 }
             }
             return $content;
         }
     }
     if ($user_id && is_numeric($user_id) && !$uid_used) {
         $where .= $wpdb->prepare(" AND it.user_id=%d", $user_id);
     }
     $s = FrmAppHelper::get_param('frm_search', false);
     if ($s) {
         $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->frm_form_id);
         if ($after_where and isset($entry_ids) and !empty($entry_ids)) {
             $entry_ids = array_intersect($new_ids, $entry_ids);
         } else {
             $entry_ids = $new_ids;
         }
         if (empty($entry_ids)) {
             if ($post->post_type == 'frm_display' and in_the_loop()) {
                 $content = '';
             }
             return $content . ' ' . $empty_msg;
         }
     }
     if (isset($entry_ids) && !empty($entry_ids)) {
         $where .= ' and it.id in (' . implode(',', array_filter($entry_ids, 'is_numeric')) . ')';
     }
     if ($entry_id) {
         $entry_id_array = explode(',', $entry_id);
         //Get IDs (if there are any)
         $numeric_entry_ids = array_filter($entry_id_array, 'is_numeric');
         //If there are entry keys, use esc_sql
         if (empty($numeric_entry_ids)) {
             $entry_id_array = array_filter($entry_id_array, 'esc_sql');
         }
         $where .= !empty($numeric_entry_ids) ? " and it.id in ('" . implode("','", $numeric_entry_ids) . "')" : " and it.item_key in ('" . implode("','", $entry_id_array) . "')";
     }
     if ($drafts != 'both') {
         $where .= $wpdb->prepare(' AND is_draft=%d', $is_draft);
     }
     unset($is_draft);
     if ($show == 'one') {
         $limit = ' LIMIT 1';
     } else {
         if (isset($_GET['frm_cat']) and isset($_GET['frm_cat_id'])) {
             //Get fields with specified field value 'frm_cat' = field key/id, 'frm_cat_id' = order position of selected option
             global $frm_field;
             if ($cat_field = $frm_field->getOne($_GET['frm_cat'])) {
                 $categories = maybe_unserialize($cat_field->options);
                 if (isset($categories[$_GET['frm_cat_id']])) {
                     $cat_entry_ids = $frm_entry_meta->getEntryIds(array('meta_value' => $categories[$_GET['frm_cat_id']], 'fi.field_key' => $_GET['frm_cat']));
                     if ($cat_entry_ids) {
                         $where .= " and it.id in (" . implode(',', $cat_entry_ids) . ")";
                     } else {
                         $where .= " and it.id=0";
                     }
                 }
             }
         }
     }
     if (!empty($limit) and is_numeric($limit)) {
         $display->frm_limit = (int) $limit;
     }
     if (is_numeric($display->frm_limit)) {
         $num_limit = (int) $display->frm_limit;
         $limit = ' LIMIT ' . $display->frm_limit;
     }
     if (!empty($order_by)) {
         $display->frm_order_by = explode(',', $order_by);
         $order_by = '';
     }
     if (!empty($order)) {
         $display->frm_order = explode(',', $order);
     }
     unset($order);
     if (!empty($page_size) && is_numeric($page_size)) {
         $display->frm_page_size = (int) $page_size;
     }
     // if limit is lower than page size, ignore the page size
     if (isset($num_limit) && $display->frm_page_size > $num_limit) {
         $display->frm_page_size = '';
     }
     if (isset($display->frm_page_size) and is_numeric($display->frm_page_size)) {
         $page_param = ($_GET and isset($_GET['frm-page-' . $display->ID])) ? 'frm-page-' . $display->ID : 'frm-page';
         $current_page = (int) FrmAppHelper::get_param($page_param, 1);
         $record_where = $where == $wpdb->prepare('it.form_id=%d', $display->frm_form_id) ? $display->frm_form_id : $where;
         $record_count = $frm_entry->getRecordCount($record_where);
         if (isset($num_limit) and $record_count > (int) $num_limit) {
             $record_count = (int) $num_limit;
         }
         $page_count = $frm_entry->getPageCount($display->frm_page_size, $record_count);
         //Get a page of entries
         $entries = $frmpro_entry->get_view_page($current_page, $display->frm_page_size, $where, array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'posts' => $form_posts));
         $page_last_record = FrmAppHelper::getLastRecordNum($record_count, $current_page, $display->frm_page_size);
         $page_first_record = FrmAppHelper::getFirstRecordNum($record_count, $current_page, $display->frm_page_size);
         if ($page_count > 1) {
             $page_param = 'frm-page-' . $display->ID;
             $pagination = FrmProDisplaysController::get_pagination_file(FrmAppHelper::plugin_path() . '/pro/classes/views/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record', 'page_param'));
         }
     } else {
         //Get all entries
         $entries = $frmpro_entry->get_view_results($where, array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'limit' => $limit, 'posts' => $form_posts));
     }
     $total_count = count($entries);
     $sc_atts = array();
     if (isset($record_count)) {
         $sc_atts['record_count'] = $record_count;
     } else {
         $sc_atts['record_count'] = $total_count;
     }
     $display_content = '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $display_content .= $message;
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_before_content) ? $display->frm_before_content : '';
     }
     if (!isset($entry_ids) || empty($entry_ids)) {
         $entry_ids = array_keys($entries);
     }
     $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entries, $shortcodes, $display, $show, $sc_atts);
     if ($filtered_content != $new_content) {
         $display_content .= $filtered_content;
     } else {
         $odd = 'odd';
         $count = 0;
         if (!empty($entries)) {
             foreach ($entries as $entry) {
                 $count++;
                 //TODO: use the count with conditionals
                 $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd, array('count' => $count, 'total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'pagination' => $pagination, 'entry_ids' => $entry_ids));
                 $odd = $odd == 'odd' ? 'even' : 'odd';
                 unset($entry);
             }
             unset($count);
         } else {
             if ($post->post_type == 'frm_display' and in_the_loop()) {
                 $display_content = '';
             }
             if (!isset($message) || FrmAppHelper::get_param('frm_action') != 'destroy') {
                 $display_content .= $empty_msg;
             }
         }
     }
     if (isset($message)) {
         unset($message);
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_after_content) ? apply_filters('frm_after_content', $display->frm_after_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids)) : '';
     }
     if (!isset($sc_atts)) {
         $sc_atts = array('record_count' => 0);
     }
     if (!isset($total_count)) {
         $total_count = 0;
     }
     $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     unset($sc_atts);
     $display_content = FrmProFieldsHelper::get_default_value($display_content, false, true, true);
     if ($display->frm_insert_loc == 'after') {
         $content .= $display_content;
     } else {
         if ($display->frm_insert_loc == 'before') {
             $content = $display_content . $content;
         } else {
             if ($filter) {
                 $display_content = apply_filters('the_content', $display_content);
             }
             $content = $display_content;
         }
     }
     return $content;
 }
 public static function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array())
 {
     if (post_password_required($display)) {
         return get_the_password_form($display);
     }
     add_action('frm_load_view_hooks', 'FrmProDisplaysController::trigger_load_view_hooks');
     FrmAppHelper::trigger_hook_load('view', $display);
     global $frm_vars, $post;
     $frm_vars['forms_loaded'][] = true;
     if (!isset($display->frm_empty_msg)) {
         $display = FrmProDisplaysHelper::setup_edit_vars($display, false);
     }
     if (!isset($display->frm_form_id) || empty($display->frm_form_id)) {
         return $content;
     }
     //for backwards compatability
     $display->id = $display->frm_old_id;
     $display->display_key = $display->post_name;
     $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => '', 'drafts' => false, 'auto_id' => '');
     $extra_atts = wp_parse_args($extra_atts, $defaults);
     extract($extra_atts);
     //if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks )
     //    self::parse_pretty_entry_url();
     if ($display->frm_show_count == 'one' && is_numeric($display->frm_entry_id) && $display->frm_entry_id > 0 && !$entry_id) {
         $entry_id = $display->frm_entry_id;
     }
     $entry = false;
     $show = 'all';
     // Don't filter with $entry_ids by default because the query gets too long.
     // Only filter with $entry_ids when showing one entry
     $use_ids = false;
     global $wpdb;
     $where = array('it.form_id' => $display->frm_form_id);
     if (in_array($display->frm_show_count, array('dynamic', 'calendar', 'one'))) {
         $one_param = FrmAppHelper::simple_get('entry', 'sanitize_title', $extra_atts['auto_id']);
         $get_param = FrmAppHelper::simple_get($display->frm_param, 'sanitize_title', $display->frm_show_count == 'one' ? $one_param : $extra_atts['auto_id']);
         unset($one_param);
         if ($get_param) {
             if (($display->frm_type == 'id' || $display->frm_show_count == 'one') && is_numeric($get_param)) {
                 $where['it.id'] = $get_param;
             } else {
                 $where['it.item_key'] = $get_param;
             }
             $entry = FrmEntry::getAll($where, '', 1, 0);
             if ($entry) {
                 $entry = reset($entry);
             }
             if ($entry && $entry->post_id) {
                 //redirect to single post page if this entry is a post
                 if (in_the_loop() && $display->frm_show_count != 'one' && !is_single($entry->post_id) && $post->ID != $entry->post_id) {
                     $this_post = get_post($entry->post_id);
                     if (in_array($this_post->post_status, array('publish', 'private'))) {
                         die(FrmAppHelper::js_redirect(get_permalink($entry->post_id)));
                     }
                 }
             }
         }
         unset($get_param);
     }
     if ($entry && in_array($display->frm_show_count, array('dynamic', 'calendar'))) {
         $new_content = $display->frm_dyncontent;
         $show = 'one';
     } else {
         $new_content = $display->post_content;
     }
     $show = $display->frm_show_count == 'one' ? 'one' : $show;
     $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->frm_form_id);
     //don't let page size and limit override single entry displays
     if ($display->frm_show_count == 'one') {
         $display->frm_page_size = $display->frm_limit = '';
     }
     //don't keep current content if post type is frm_display
     if ($post && $post->post_type == self::$post_type) {
         $display->frm_insert_loc = '';
     }
     $pagination = '';
     $form_query = array('form_id' => $display->frm_form_id, 'post_id >' => 1);
     if ($extra_atts['drafts'] != 'both') {
         $is_draft = empty($extra_atts['drafts']) ? 0 : 1;
         $form_query['is_draft'] = $is_draft;
     } else {
         $is_draft = 'both';
     }
     if ($entry && $entry->form_id == $display->frm_form_id) {
         $form_query['id'] = $entry->id;
     }
     $form_posts = FrmDb::get_results('frm_items', $form_query, 'id, post_id');
     unset($form_query);
     $getting_entries = !$entry || !$post || empty($extra_atts['auto_id']);
     $check_filter_opts = !empty($display->frm_where) && $getting_entries;
     if ($entry && $entry->form_id == $display->frm_form_id) {
         $entry_ids = array($entry->id);
         // Filter by this entry ID to make query faster
         $use_ids = true;
     } else {
         if ($check_filter_opts || isset($_GET['frm_search'])) {
             //Only get $entry_ids if filters are set or if frm_search parameter is set
             $entry_query = array('form_id' => $display->frm_form_id);
             if ($extra_atts['drafts'] != 'both') {
                 $entry_query['is_draft'] = $is_draft;
             }
             $entry_ids = FrmDb::get_col('frm_items', $entry_query);
             unset($entry_query);
         }
     }
     $empty_msg = isset($display->frm_empty_msg) && !empty($display->frm_empty_msg) ? '<div class="frm_no_entries">' . FrmProFieldsHelper::get_default_value($display->frm_empty_msg, false) . '</div>' : '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $empty_msg = $message . $empty_msg;
     }
     $after_where = false;
     $user_id = $extra_atts['user_id'];
     if (!empty($user_id)) {
         $user_id = FrmAppHelper::get_user_id_param($user_id);
         $uid_used = false;
     }
     self::add_group_by_filter($display, $getting_entries);
     unset($getting_entries);
     if ($check_filter_opts) {
         $display->frm_where = apply_filters('frm_custom_where_opt', $display->frm_where, array('display' => $display, 'entry' => $entry));
         $continue = false;
         foreach ($display->frm_where as $where_key => $where_opt) {
             $where_val = isset($display->frm_where_val[$where_key]) ? $display->frm_where_val[$where_key] : '';
             if (preg_match("/\\[(get|get-(.?))\\b(.*?)(?:(\\/))?\\]/s", $where_val)) {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
                 //if this param doesn't exist, then don't include it
                 if ($where_val == '') {
                     if (!$after_where) {
                         $continue = true;
                     }
                     continue;
                 }
             } else {
                 $where_val = FrmProFieldsHelper::get_default_value($where_val, false, true, true);
             }
             $continue = false;
             if ($where_val == 'current_user') {
                 if ($user_id && is_numeric($user_id)) {
                     $where_val = $user_id;
                     $uid_used = true;
                 } else {
                     $where_val = get_current_user_id();
                 }
             } else {
                 if (!is_array($where_val)) {
                     $where_val = do_shortcode($where_val);
                 }
             }
             if (in_array($where_opt, array('id', 'item_key', 'post_id')) && !is_array($where_val) && strpos($where_val, ',')) {
                 $where_val = explode(',', $where_val);
                 $where_val = array_filter($where_val);
             }
             if (is_array($where_val) && !empty($where_val)) {
                 if (strpos($display->frm_where_is[$where_key], '!') === false && strpos($display->frm_where_is[$where_key], 'not') === false) {
                     $display->frm_where_is[$where_key] = ' in ';
                 } else {
                     $display->frm_where_is[$where_key] = 'not in';
                 }
             }
             if (is_numeric($where_opt)) {
                 $filter_opts = apply_filters('frm_display_filter_opt', array('where_opt' => $where_opt, 'where_is' => $display->frm_where_is[$where_key], 'where_val' => $where_val, 'form_id' => $display->frm_form_id, 'form_posts' => $form_posts, 'after_where' => $after_where, 'display' => $display, 'drafts' => $is_draft, 'use_ids' => $use_ids));
                 $entry_ids = FrmProAppHelper::filter_where($entry_ids, $filter_opts);
                 unset($filter_opts);
                 $after_where = true;
                 $continue = false;
                 if (empty($entry_ids)) {
                     break;
                 }
             } else {
                 if (in_array($where_opt, array('created_at', 'updated_at'))) {
                     if ($where_val == 'NOW') {
                         $where_val = current_time('mysql', 1);
                     }
                     if (strpos($display->frm_where_is[$where_key], 'LIKE') === false) {
                         $where_val = date('Y-m-d H:i:s', strtotime($where_val));
                         // If using less than or equal to, set the time to the end of the day
                         if ($display->frm_where_is[$where_key] == '<=') {
                             $where_val = str_replace('00:00:00', '23:59:59', $where_val);
                         }
                         // Convert date to GMT since that is the format in the DB
                         $where_val = get_gmt_from_date($where_val);
                     }
                     $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val;
                     $continue = true;
                 } else {
                     if (in_array($where_opt, array('id', 'item_key', 'post_id', 'ip'))) {
                         $where['it.' . sanitize_title($where_opt) . FrmDb::append_where_is($display->frm_where_is[$where_key])] = $where_val;
                         // Update entry IDs if the entry ID filter is set to "equal to"
                         if ($where_opt == 'id' && in_array($display->frm_where_is[$where_key], array('=', ' in '))) {
                             $entry_ids = $where_val;
                         }
                         $continue = true;
                     }
                 }
             }
         }
         if (!$continue && empty($entry_ids)) {
             if ($display->frm_insert_loc == 'after') {
                 $content .= $empty_msg;
             } else {
                 if ($display->frm_insert_loc == 'before') {
                     $content = $empty_msg . $content;
                 } else {
                     if ($filter) {
                         $empty_msg = apply_filters('the_content', $empty_msg);
                     }
                     if ($post && $post->post_type == self::$post_type && in_the_loop()) {
                         $content = '';
                     }
                     $content .= $empty_msg;
                 }
             }
             return $content;
         }
     }
     if ($user_id && is_numeric($user_id) && !$uid_used) {
         $where['it.user_id'] = $user_id;
     }
     $s = FrmAppHelper::get_param('frm_search', false, 'get', 'sanitize_text_field');
     if ($s) {
         $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->frm_form_id, array('is_draft' => $extra_atts['drafts']));
         if ($after_where && isset($entry_ids) && !empty($entry_ids)) {
             $entry_ids = array_intersect($new_ids, $entry_ids);
         } else {
             $entry_ids = $new_ids;
         }
         if (empty($entry_ids)) {
             if ($post->post_type == self::$post_type && in_the_loop()) {
                 $content = '';
             }
             return $content . ' ' . $empty_msg;
         }
     }
     if (isset($entry_ids) && !empty($entry_ids)) {
         $where['it.id'] = $entry_ids;
     }
     self::maybe_add_entry_query($entry_id, $where);
     if ($extra_atts['drafts'] != 'both') {
         $where['is_draft'] = $is_draft;
     }
     unset($is_draft);
     if ($show == 'one') {
         $limit = ' LIMIT 1';
     } else {
         self::maybe_add_cat_query($where);
     }
     if (!empty($limit) && is_numeric($limit)) {
         $display->frm_limit = (int) $limit;
     }
     if (is_numeric($display->frm_limit)) {
         $num_limit = (int) $display->frm_limit;
         $limit = ' LIMIT ' . $display->frm_limit;
     }
     if (!empty($order_by)) {
         $display->frm_order_by = explode(',', $order_by);
     }
     if (!empty($order)) {
         $display->frm_order = explode(',', $order);
         if (!isset($display->frm_order_by[0])) {
             $display->frm_order_by = FrmProAppHelper::reset_keys($display->frm_order_by);
         }
     }
     unset($order);
     if (!empty($page_size) && is_numeric($page_size)) {
         $display->frm_page_size = (int) $page_size;
     }
     // if limit is lower than page size, ignore the page size
     if (isset($num_limit) && $display->frm_page_size > $num_limit) {
         $display->frm_page_size = '';
     }
     $display_page_query = array('order_by_array' => $display->frm_order_by, 'order_array' => $display->frm_order, 'posts' => $form_posts, 'display' => $display);
     if (isset($display->frm_page_size) && is_numeric($display->frm_page_size)) {
         $page_param = $_GET && isset($_GET['frm-page-' . $display->ID]) ? 'frm-page-' . $display->ID : 'frm-page';
         $current_page = FrmAppHelper::simple_get($page_param, 'absint', 1);
         $record_count = FrmEntry::getRecordCount($where);
         if (isset($num_limit) && $record_count > (int) $num_limit) {
             $record_count = (int) $num_limit;
         }
         $page_count = FrmEntry::getPageCount($display->frm_page_size, $record_count);
         $entry_ids = FrmProEntry::get_view_page($current_page, $display->frm_page_size, $where, $display_page_query);
         $page_last_record = FrmAppHelper::get_last_record_num($record_count, $current_page, $display->frm_page_size);
         $page_first_record = FrmAppHelper::get_first_record_num($record_count, $current_page, $display->frm_page_size);
         if ($page_count > 1) {
             $page_param = 'frm-page-' . $display->ID;
             $pagination = FrmAppHelper::get_file_contents(FrmAppHelper::plugin_path() . '/pro/classes/views/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record', 'page_param'));
         }
     } else {
         $display_page_query['limit'] = $limit;
         //Get all entries
         $entry_ids = FrmProEntry::get_view_results($where, $display_page_query);
     }
     $total_count = count($entry_ids);
     $sc_atts = array();
     if (isset($record_count)) {
         $sc_atts['record_count'] = $record_count;
     } else {
         $sc_atts['record_count'] = $total_count;
     }
     $display_content = '';
     if (isset($message)) {
         // if an entry was deleted above, show a message
         $display_content .= $message;
     }
     if ($show == 'all') {
         $display_content .= isset($display->frm_before_content) ? $display->frm_before_content : '';
     }
     add_filter('frm_before_display_content', 'FrmProDisplaysController::calendar_header', 10, 3);
     add_filter('frm_before_display_content', 'FrmProDisplaysController::filter_after_content', 10, 4);
     $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     add_filter('frm_display_entries_content', 'FrmProDisplaysController::build_calendar', 10, 5);
     $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entry_ids, $shortcodes, $display, $show, $sc_atts);
     if ($filtered_content != $new_content) {
         $display_content .= $filtered_content;
     } else {
         $odd = 'odd';
         $count = 0;
         if (!empty($entry_ids)) {
             $loop_entry_ids = $entry_ids;
             while ($next_set = array_splice($loop_entry_ids, 0, 30)) {
                 $entries = FrmEntry::getAll(array('id' => $next_set), ' ORDER BY FIELD(it.id,' . implode(',', $next_set) . ')', '', true, false);
                 foreach ($entries as $entry) {
                     $count++;
                     //TODO: use the count with conditionals
                     $display_content .= apply_filters('frm_display_entry_content', $new_content, $entry, $shortcodes, $display, $show, $odd, array('count' => $count, 'total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'pagination' => $pagination, 'entry_ids' => $entry_ids));
                     $odd = $odd == 'odd' ? 'even' : 'odd';
                     unset($entry);
                 }
                 unset($entries);
             }
             unset($loop_entry_ids, $count);
         } else {
             if ($post && $post->post_type == self::$post_type && in_the_loop()) {
                 $display_content = '';
             }
             if (!isset($message) || FrmAppHelper::get_param('frm_action', '', 'get', 'sanitize_title') != 'destroy') {
                 $display_content .= $empty_msg;
             }
         }
     }
     if (isset($message)) {
         unset($message);
     }
     if ($show == 'all' && isset($display->frm_after_content)) {
         add_filter('frm_after_content', 'FrmProDisplaysController::filter_after_content', 10, 4);
         $display_content .= apply_filters('frm_after_content', $display->frm_after_content, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     }
     if (!isset($sc_atts)) {
         $sc_atts = array('record_count' => 0);
     }
     if (!isset($total_count)) {
         $total_count = 0;
     }
     $pagination = self::calendar_footer($pagination, $display, $show);
     $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show, array('total_count' => $total_count, 'record_count' => $sc_atts['record_count'], 'entry_ids' => $entry_ids));
     unset($sc_atts);
     $display_content = FrmProFieldsHelper::get_default_value($display_content, false, true, false);
     if ($display->frm_insert_loc == 'after') {
         $content .= $display_content;
     } else {
         if ($display->frm_insert_loc == 'before') {
             $content = $display_content . $content;
         } else {
             if ($filter) {
                 $display_content = apply_filters('the_content', $display_content);
             }
             $content = $display_content;
         }
     }
     // load the styling for css classes and pagination
     FrmStylesController::enqueue_style();
     return $content;
 }