function user_can_edit_check($entry, $form)
 {
     global $user_ID;
     if (!$user_ID) {
         return false;
     }
     if (is_numeric($form)) {
         $form = FrmForm::getOne($form);
     }
     $form->options = maybe_unserialize($form->options);
     //if editable and user can edit someone elses entry
     if ($form->editable and isset($form->options['open_editable']) and $form->options['open_editable'] and isset($form->options['open_editable_role']) and FrmAppHelper::user_has_permission($form->options['open_editable_role'])) {
         return true;
     }
     if (is_object($entry)) {
         if ($entry->user_id == $user_ID) {
             return true;
         } else {
             return false;
         }
     }
     $where = "user_id='{$user_ID}' and fr.id='{$form->id}'";
     if ($entry and !empty($entry)) {
         if (is_numeric($entry)) {
             $where .= ' and it.id=' . $entry;
         } else {
             $where .= " and item_key='" . $entry . "'";
         }
     }
     return FrmEntry::getAll($where, '', ' LIMIT 1', true);
 }
 public function prepare_items()
 {
     global $wpdb, $per_page;
     $per_page = $this->get_items_per_page('formidable_page_formidable_entries_per_page');
     $form_id = $this->params['form'];
     if (!$form_id) {
         $this->items = array();
         $this->set_pagination_args(array('total_items' => 0, 'per_page' => $per_page));
         return;
     }
     $default_orderby = 'id';
     $default_order = 'DESC';
     $s_query = array('it.form_id' => $form_id);
     $s = isset($_REQUEST['s']) ? stripslashes($_REQUEST['s']) : '';
     if ($s != '' && FrmAppHelper::pro_is_installed()) {
         $fid = isset($_REQUEST['fid']) ? sanitize_title($_REQUEST['fid']) : '';
         $s_query = FrmProEntriesHelper::get_search_str($s_query, $s, $form_id, $fid);
     }
     $orderby = isset($_REQUEST['orderby']) ? sanitize_title($_REQUEST['orderby']) : $default_orderby;
     if (strpos($orderby, 'meta') !== false) {
         $order_field_type = FrmField::get_type(str_replace('meta_', '', $orderby));
         $orderby .= in_array($order_field_type, array('number', 'scale')) ? ' +0 ' : '';
     }
     $order = isset($_REQUEST['order']) ? sanitize_title($_REQUEST['order']) : $default_order;
     $order = ' ORDER BY ' . $orderby . ' ' . $order;
     $page = $this->get_pagenum();
     $start = (int) isset($_REQUEST['start']) ? absint($_REQUEST['start']) : ($page - 1) * $per_page;
     $this->items = FrmEntry::getAll($s_query, $order, ' LIMIT ' . $start . ',' . $per_page, true, false);
     $total_items = FrmEntry::getRecordCount($s_query);
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page));
 }
 /**
  * @covers FrmEntry::getAll
  */
 function test_getAll()
 {
     $form = $this->factory->form->get_object_by_id($this->contact_form_key);
     $entry_data = $this->factory->field->generate_entry_array($form);
     $entry_id = $this->factory->entry->create_many(10, $entry_data);
     $items = FrmEntry::getAll(array('it.form_id' => $form->id));
     $this->assertTrue(count($items) >= 10, 'There are no entries in form ' . $form->id);
 }
 /**
  * Make sure all entries are still retrieved with All Entries View even if entry parameter is in the URL
  */
 function _test_all_entries_view_with_entry_param($detail_type)
 {
     // Get all the entries in the form
     $where['form_key'] = 'all_field_types';
     $total_entries = count(FrmEntry::getAll($where));
     // Get the All Entries View Content
     $all_entries_view = do_shortcode('[display-frm-data id="all-entries"]');
     $entry_num = substr_count($all_entries_view, 'All Entries');
     $this->assertTrue($total_entries == $entry_num, 'All Entries View is affected by entry ' . $detail_type . ' parameter');
 }
 function _get_dynamic_entry_ids($form_key, $where_field_key, $args)
 {
     // Get where_field
     $where_field = FrmField::getOne($where_field_key);
     // Get all entry IDs for form
     $form_id = $this->factory->form->get_id_by_key($form_key);
     $entry_ids = FrmEntry::getAll(array('it.form_id' => $form_id), '', '', false, false);
     // Prepare the args
     self::_do_prepare_where_args($args, $where_field, $entry_ids);
     // Set new where_val
     self::_do_prepare_dfe_text($args, $where_field);
     return $args['where_val'];
 }
 /**
  * Search for a value in an entry
  */
 function test_search_by_field()
 {
     $form = $this->factory->form->create_and_get();
     $this->assertNotEmpty($form);
     $field_id = $this->factory->field->create(array('type' => 'email', 'form_id' => $form->id));
     $this->assertNotEmpty($field_id);
     $this->assertTrue(is_numeric($field_id));
     $entry_data = $this->factory->field->generate_entry_array($form);
     $this->factory->entry->create_many(10, $entry_data);
     $s_query = array('it.form_id' => $form->id);
     if (is_callable('FrmProEntriesHelper::get_search_str')) {
         $s = '*****@*****.**';
         //$s_query = FrmProEntriesHelper::get_search_str( $s_query, $s, $form->id, $field_id );
     }
     $items = FrmEntry::getAll($s_query, '', '', true, false);
     $this->assertNotEmpty($items);
 }
 public static function prepare_display_value($entry, $field, $atts)
 {
     $field_value = isset($entry->metas[$field->id]) ? $entry->metas[$field->id] : false;
     if (FrmAppHelper::pro_is_installed()) {
         FrmProEntriesHelper::get_dynamic_list_values($field, $entry, $field_value);
     }
     if ($field->form_id == $entry->form_id || empty($atts['embedded_field_id'])) {
         return self::display_value($field_value, $field, $atts);
     }
     // this is an embeded form
     $val = '';
     if (strpos($atts['embedded_field_id'], 'form') === 0) {
         //this is a repeating section
         $child_entries = FrmEntry::getAll(array('it.parent_item_id' => $entry->id));
     } else {
         // get all values for this field
         $child_values = isset($entry->metas[$atts['embedded_field_id']]) ? $entry->metas[$atts['embedded_field_id']] : false;
         if ($child_values) {
             $child_entries = FrmEntry::getAll(array('it.id' => (array) $child_values));
         }
     }
     $field_value = array();
     if (!isset($child_entries) || !$child_entries || !FrmAppHelper::pro_is_installed()) {
         return $val;
     }
     foreach ($child_entries as $child_entry) {
         $atts['item_id'] = $child_entry->id;
         $atts['post_id'] = $child_entry->post_id;
         // get the value for this field -- check for post values as well
         $entry_val = FrmProEntryMetaHelper::get_post_or_meta_value($child_entry, $field);
         if ($entry_val) {
             // foreach entry get display_value
             $field_value[] = self::display_value($entry_val, $field, $atts);
         }
         unset($child_entry);
     }
     $val = implode(', ', (array) $field_value);
     $val = wp_kses_post($val);
     return $val;
 }
 public static function user_can_edit_check($entry, $form)
 {
     $user_ID = get_current_user_id();
     if (!$user_ID || empty($form) || is_object($entry) && $entry->form_id != $form->id) {
         return false;
     }
     if (is_object($entry)) {
         if ($entry->is_draft && $entry->user_id == $user_ID || self::user_can_edit_others($form)) {
             //if editable and user can edit this entry
             return true;
         }
     }
     $where = array('fr.id' => $form->id);
     if (self::user_can_only_edit_draft($form)) {
         //only allow editing of drafts
         $where['user_id'] = $user_ID;
         $where['is_draft'] = 1;
     }
     if (!self::user_can_edit_others($form)) {
         $where['user_id'] = $user_ID;
         if (is_object($entry) && $entry->user_id != $user_ID) {
             return false;
         }
         // Check if open_editable_role and editable_role is set for reverse compatibility
         if ($form->editable && isset($form->options['open_editable_role']) && !FrmAppHelper::user_has_permission($form->options['open_editable_role']) && isset($form->options['editable_role']) && !FrmAppHelper::user_has_permission($form->options['editable_role'])) {
             // make sure user cannot edit their own entry, even if a higher user role can unless it's a draft
             if (is_object($entry) && !$entry->is_draft) {
                 return false;
             } else {
                 if (!is_object($entry)) {
                     $where['is_draft'] = 1;
                 }
             }
         }
     } else {
         if ($form->editable && $user_ID && empty($entry)) {
             // make sure user is editing their own draft by default, even if they have permission to edit others' entries
             $where['user_id'] = $user_ID;
         }
     }
     if (!$form->editable) {
         $where['is_draft'] = 1;
         if (is_object($entry) && !$entry->is_draft) {
             return false;
         }
     }
     // If entry object, and we made it this far, then don't do another db call
     if (is_object($entry)) {
         return true;
     }
     if (!empty($entry)) {
         $where_key = is_numeric($entry) ? 'it.id' : 'item_key';
         $where[$where_key] = $entry;
     }
     return FrmEntry::getAll($where, ' ORDER BY created_at DESC', 1, true);
 }
 /**
  * @covers FrmProFieldsHelper::move_entries_to_child_form
  */
 function _check_if_child_entries_created($args, $child_form_id)
 {
     global $wpdb;
     // Check for value in repeating section
     $rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
     $this->assertNotEmpty($rep_meta_values, 'When switching from non-repeating to repeating, the repeating section frm_item_metas is not saving the IDs of the child entries.');
     // Check if entries were created in child form
     $child_items = FrmEntry::getAll(array('it.form_id' => $child_form_id));
     $parent_items = FrmEntry::getAll(array('it.form_id' => $args['parent_form_id']));
     $this->assertEquals(count($parent_items), count($child_items), 'When switching from non-repeating to repeating section, child entries are not created. ');
     // Check if entries in child form match IDs saved in repeating section frm_item_metas
     $child_ids = array_keys($child_items);
     $this->assertEquals($child_ids, $rep_meta_values, 'When switching from non-repeating to repeating, created entry IDs do not match IDs saved in repeating section field frm_item_metas.');
     // Check if the item_id for child field frm_item_metas was updated to match new child entry IDs
     $new_child_metas = FrmDb::get_col($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items it ON it.id=m.item_id', array('field_id' => $args['children']), 'm.item_id', array('order_by' => 'it.created_at ASC'));
     $new_child_metas = array_unique($new_child_metas);
     $this->assertEquals($child_ids, $new_child_metas, 'When switching from non-repeating to repeating, the item_id is not updated on frm_item_metas for child fields');
 }
 function _check_xml_updated_number_of_entries($args)
 {
     $parent_entries = FrmEntry::getAll(array('form_id' => $args['parent_form_id']));
     $this->assertEquals(count($args['parent_entries']), count($parent_entries), 'The number of entries in form ' . $args['parent_form_id'] . ' should be the same after an XML update.');
     $rep_sec_form_id = FrmForm::getIdByKey($this->repeat_sec_form_key);
     $child_entries = FrmEntry::getAll(array('form_id' => $rep_sec_form_id));
     $this->assertEquals(count($args['child_entries']), count($child_entries), 'The number of entries in form ' . $rep_sec_form_id . ' should be the same after an XML update.');
     $embed_form_id = FrmForm::getIdByKey($this->contact_form_key);
     $embedded_entries = FrmEntry::getAll(array('form_id' => $embed_form_id, 'parent_item_id !' => 0));
     $this->assertEquals(count($args['embedded_entries']), count($embedded_entries), 'The number of entries in the embedded form should be the same after an XML update.');
 }
 private static function get_entry_link_entries($atts)
 {
     $s = FrmAppHelper::get_param('frm_search', false, 'get', 'sanitize_text_field');
     // Convert logged_in parameter to user_id for other functions
     $atts['user_id'] = false;
     if ($atts['logged_in']) {
         global $wpdb;
         $atts['user_id'] = get_current_user_id();
     }
     if ($s) {
         $entry_ids = FrmProEntriesHelper::get_search_ids($s, $atts['id'], array('is_draft' => $atts['drafts'], 'user_id' => $atts['user_id']));
     } else {
         $entry_ids = FrmEntryMeta::getEntryIds(array('fi.form_id' => (int) $atts['id']), '', '', true, array('is_draft' => $atts['drafts'], 'user_id' => $atts['user_id']));
     }
     if (empty($entry_ids)) {
         return;
     }
     $order = $atts['type'] == 'collapse' || $atts['order'] == 'DESC' ? ' ORDER BY it.created_at DESC' : '';
     $entries = FrmEntry::getAll(array('it.id' => $entry_ids), $order, '', true);
     return $entries;
 }
Example #12
0
 /**
  * @since 2.0.8
  * @return boolean
  */
 public static function user_can_submit_form($form)
 {
     $admin_entry = FrmAppHelper::is_admin();
     $can_submit = true;
     if ($form->options['single_entry_type'] == 'cookie' && isset($_COOKIE['frm_form' . $form->id . '_' . COOKIEHASH])) {
         $can_submit = $admin_entry ? true : false;
     } else {
         if ($form->options['single_entry_type'] == 'ip') {
             if (!$admin_entry) {
                 $prev_entry = FrmEntry::getAll(array('it.form_id' => $form->id, 'it.ip' => FrmAppHelper::get_ip_address()), '', 1);
                 if ($prev_entry) {
                     $can_submit = false;
                 }
             }
         } else {
             if (($form->options['single_entry_type'] == 'user' || isset($form->options['save_draft']) && $form->options['save_draft'] == 1) && !$form->editable) {
                 $user_ID = get_current_user_id();
                 if ($user_ID) {
                     $meta = FrmProEntriesHelper::check_for_user_entry($user_ID, $form, $form->options['single_entry_type'] != 'user');
                     if ($meta) {
                         $can_submit = false;
                     }
                 }
             }
         }
     }
     return $can_submit;
 }
 private static function prepare_next_csv_rows($next_set)
 {
     // order by parent_item_id so children will be first
     $entries = FrmEntry::getAll(array('or' => 1, 'id' => $next_set, 'parent_item_id' => $next_set), ' ORDER BY parent_item_id DESC', '', true, false);
     foreach ($entries as $k => $entry) {
         self::$entry = $entry;
         unset($entry);
         if (self::$entry->form_id != self::$form_id) {
             self::add_repeat_field_values_to_csv($entries);
         } else {
             self::prepare_csv_row();
         }
     }
 }
Example #14
0
 function widget($args, $instance)
 {
     global $wpdb;
     $display = FrmProDisplay::getOne($instance['display_id'], false, true);
     $title = apply_filters('widget_title', empty($instance['title']) && $display ? $display->post_title : $instance['title']);
     $limit = empty($instance['limit']) ? ' LIMIT 100' : " LIMIT {$instance['limit']}";
     $post_id = !$display || empty($display->frm_post_id) ? $instance['post_id'] : $display->frm_post_id;
     $page_url = get_permalink($post_id);
     $order_by = '';
     $cat_field = false;
     if ($display && is_numeric($display->frm_form_id) && !empty($display->frm_form_id)) {
         //Set up order for Entries List Widget
         if (isset($display->frm_order_by) && !empty($display->frm_order_by)) {
             //Get only the first order field and order
             $order_field = reset($display->frm_order_by);
             $order = reset($display->frm_order);
             FrmAppHelper::esc_order_by($order);
             if ($order_field == 'rand') {
                 //If random is set, set the order to random
                 $order_by = ' RAND()';
             } else {
                 if (is_numeric($order_field)) {
                     //If ordering by a field
                     //Get all post IDs for this form
                     $posts = FrmDb::get_results($wpdb->prefix . 'frm_items', array('form_id' => $display->frm_form_id, 'post_id >' => 1, 'is_draft' => 0), 'id, post_id');
                     $linked_posts = array();
                     foreach ($posts as $post_meta) {
                         $linked_posts[$post_meta->post_id] = $post_meta->id;
                     }
                     //Get all field information
                     $o_field = FrmField::getOne($order_field);
                     $query = 'SELECT m.id FROM ' . $wpdb->prefix . 'frm_items m INNER JOIN ';
                     $where = array();
                     //create query with ordered values
                     //if field is some type of post field
                     if (isset($o_field->field_options['post_field']) && $o_field->field_options['post_field']) {
                         if ($o_field->field_options['post_field'] == 'post_custom' && !empty($linked_posts)) {
                             //if field is custom field
                             $where['pm.post_id'] = array_keys($linked_posts);
                             FrmDb::get_where_clause_and_values($where);
                             array_unshift($where['values'], $o_field->field_options['custom_field']);
                             $query .= $wpdb->postmeta . ' pm ON pm.post_id=m.post_id AND pm.meta_key=%s ' . $where['where'] . ' ORDER BY CASE when pm.meta_value IS NULL THEN 1 ELSE 0 END, pm.meta_value ' . $order;
                         } else {
                             if ($o_field->field_options['post_field'] != 'post_category' && !empty($linked_posts)) {
                                 //if field is a non-category post field
                                 $where['p.ID'] = array_keys($linked_posts);
                                 FrmDb::get_where_clause_and_values($where);
                                 $query .= $wpdb->posts . ' p ON p.ID=m.post_id ' . $where['where'] . ' ORDER BY CASE p.' . sanitize_title($o_field->field_options['post_field']) . ' WHEN "" THEN 1 ELSE 0 END, p.' . sanitize_title($o_field->field_options['post_field']) . ' ' . $order;
                             }
                         }
                     } else {
                         //if field is a normal, non-post field
                         $where['em.field_id'] = $o_field->id;
                         FrmDb::get_where_clause_and_values($where);
                         $query .= $wpdb->prefix . 'frm_item_metas em ON em.item_id=m.id ' . $where['where'] . ' ORDER BY CASE when em.meta_value IS NULL THEN 1 ELSE 0 END, em.meta_value' . ($o_field->type == 'number' ? ' +0 ' : '') . ' ' . $order;
                     }
                     //Get ordered values
                     if (!empty($where)) {
                         $metas = $wpdb->get_results($wpdb->prepare($query, $where['values']));
                     } else {
                         $metas = false;
                     }
                     unset($query, $where);
                     if (!empty($metas)) {
                         $order_by_array = array();
                         foreach ($metas as $meta) {
                             $order_by_array[] = $wpdb->prepare('it.id=%d DESC', $meta->id);
                         }
                         $order_by = implode(', ', $order_by_array);
                         unset($order_by_array);
                     } else {
                         $order_by .= 'it.created_at ' . $order;
                     }
                     unset($metas);
                 } else {
                     if (!empty($order_field)) {
                         //If ordering by created_at or updated_at
                         $order_by = 'it.' . sanitize_title($order_field) . ' ' . $order;
                     }
                 }
             }
             if (!empty($order_by)) {
                 $order_by = ' ORDER BY ' . $order_by;
             }
         }
         if (isset($instance['cat_list']) && (int) $instance['cat_list'] == 1 && is_numeric($instance['cat_id'])) {
             if ($cat_field = FrmField::getOne($instance['cat_id'])) {
                 $categories = maybe_unserialize($cat_field->options);
             }
         }
     }
     echo $args['before_widget'];
     if ($title) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo '<ul id="frm_entry_list' . ($display ? $display->frm_form_id : '') . '">' . "\n";
     //if Listing entries by category
     if (isset($instance['cat_list']) && (int) $instance['cat_list'] == 1 && isset($categories) && is_array($categories)) {
         foreach ($categories as $cat_order => $cat) {
             if ($cat == '') {
                 continue;
             }
             echo '<li>';
             if (isset($instance['cat_name']) && (int) $instance['cat_name'] == 1 && $cat_field) {
                 echo '<a href="' . esc_url(add_query_arg(array('frm_cat' => $cat_field->field_key, 'frm_cat_id' => $cat_order), $page_url)) . '">';
             }
             echo $cat;
             if (isset($instance['cat_count']) && (int) $instance['cat_count'] == 1) {
                 echo ' (' . FrmProFieldsHelper::get_field_stats($instance['cat_id'], 'count', false, $cat) . ')';
             }
             if (isset($instance['cat_name']) && (int) $instance['cat_name'] == 1) {
                 echo '</a>';
             } else {
                 $entry_ids = FrmEntryMeta::getEntryIds(array('meta_value like' => $cat, 'fi.id' => $instance['cat_id']));
                 $items = false;
                 if ($entry_ids) {
                     $items = FrmEntry::getAll(array('it.id' => $entry_ids, 'it.form_id' => (int) $display->frm_form_id), $order_by, $limit);
                 }
                 if ($items) {
                     echo '<ul>';
                     foreach ($items as $item) {
                         $url_id = $display->frm_type == 'id' ? $item->id : $item->item_key;
                         $current = FrmAppHelper::simple_get($display->frm_param) == $url_id ? ' class="current_page"' : '';
                         if ($item->post_id) {
                             $entry_link = get_permalink($item->post_id);
                         } else {
                             $entry_link = add_query_arg(array($display->frm_param => $url_id), $page_url);
                         }
                         echo '<li' . $current . '><a href="' . esc_url($entry_link) . '">' . FrmAppHelper::kses($item->name) . '</a></li>' . "\n";
                     }
                     echo '</ul>';
                 }
             }
             echo '</li>';
         }
     } else {
         // if not listing entries by category
         if ($display) {
             $items = FrmEntry::getAll(array('it.form_id' => $display->frm_form_id, 'is_draft' => '0'), $order_by, $limit);
         } else {
             $items = array();
         }
         foreach ($items as $item) {
             $url_id = $display->frm_type == 'id' ? $item->id : $item->item_key;
             $current = FrmAppHelper::simple_get($display->frm_param) == $url_id ? ' class="current_page"' : '';
             echo '<li' . $current . '><a href="' . esc_url(add_query_arg(array($display->frm_param => $url_id), $page_url)) . '">' . FrmAppHelper::kses($item->name) . '</a></li>' . "\n";
         }
     }
     echo "</ul>\n";
     echo $args['after_widget'];
 }
 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;
 }
Example #16
0
 public static function get_sub_entries($entry_id, $meta = false)
 {
     $entries = FrmEntry::getAll(array('parent_item_id' => $entry_id), '', '', $meta, false);
     return $entries;
 }