function get_display_data($display, $content = '', $entry_id = false, $extra_atts = array()) { global $frmpro_display, $frm_entry, $frmpro_settings, $frm_entry_meta, $frm_forms_loaded; $frm_forms_loaded[] = true; $defaults = array('filter' => false, 'user_id' => '', 'limit' => '', 'page_size' => '', 'order_by' => '', 'order' => ''); extract(wp_parse_args($extra_atts, $defaults)); if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks) { $this->parse_pretty_entry_url(); } if (is_numeric($display->entry_id) && $display->entry_id > 0 and !$entry_id) { $entry_id = $display->entry_id; } $entry = false; $show = 'all'; if (in_array($display->show_count, array('dynamic', 'calendar', 'one'))) { $one_param = isset($_GET['entry']) ? $_GET['entry'] : $entry_id; $get_param = isset($_GET[$display->param]) ? $_GET[$display->param] : ($display->show_count == 'one' ? $one_param : $entry_id); unset($one_param); if ($get_param) { $where_entry = array('it.form_id' => $display->form_id); if (($display->type == 'id' or $display->show_count == 'one') and is_numeric($get_param)) { $where_entry['it.id'] = $get_param; } else { $where_entry['it.item_key'] = $get_param; } $entry = $frm_entry->getAll($where_entry, '', 1, 0); if ($entry) { $entry = reset($entry); } if ($entry and $entry->post_id) { //redirect to single post page if this entry is a post global $post; if (in_the_loop() and $display->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('<script type="text/javascript">window.location="' . get_permalink($entry->post_id) . '"</script>'); } } } } unset($get_param); } if ($entry and in_array($display->show_count, array('dynamic', 'calendar'))) { $new_content = stripslashes($display->dyncontent); $show = 'one'; } else { $new_content = stripslashes($display->content); } $show = ($display->show_count == 'one' or $entry_id and is_numeric($entry_id)) ? 'one' : $show; $shortcodes = FrmProDisplaysHelper::get_shortcodes($new_content, $display->form_id); $pagination = ''; if ($entry and $entry->form_id == $display->form_id) { $display_content = FrmProFieldsHelper::replace_shortcodes($new_content, $entry, $shortcodes, $display, $show); } else { global $frmdb, $wpdb; $options = maybe_unserialize($display->options); $empty_msg = '<div class="frm_no_entries">' . (isset($options['empty_msg']) ? stripslashes($options['empty_msg']) : '') . '</div>'; $display_content = ''; if ($show == 'all') { $display_content .= isset($options['before_content']) ? stripslashes($options['before_content']) : ''; } $display_content = apply_filters('frm_before_display_content', $display_content, $display, $show); $where = 'it.form_id=' . $display->form_id; $form_posts = $frmdb->get_records($frmdb->entries, array('form_id' => $display->form_id, 'post_id >' => 1), '', '', 'id,post_id'); $entry_ids = $frmdb->get_col($frmdb->entries, array('form_id' => $display->form_id), 'id'); $after_where = false; if ($user_id and !empty($user_id)) { $user_id = FrmProAppHelper::get_user_id_param($user_id); $uid_used = false; } if (isset($options['where']) and !empty($options['where'])) { $options['where'] = apply_filters('frm_custom_where_opt', $options['where'], array('display' => $display, 'entry' => $entry)); $continue = false; foreach ($options['where'] as $where_key => $where_opt) { $where_val = isset($options['where_val'][$where_key]) ? $options['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 { global $user_ID; $where_val = $user_ID; } } $where_val = do_shortcode($where_val); if (is_array($where_val) and !empty($where_val)) { $new_where = '('; if (strpos($options['where_is'][$where_key], 'LIKE') !== false) { foreach ($where_val as $w) { if ($new_where != '(') { $new_where .= ','; } $new_where .= "'%" . esc_sql(like_escape($w)) . "%'"; unset($w); } } else { foreach ($where_val as $w) { if ($new_where != '(') { $new_where .= ','; } $new_where .= "'" . esc_sql($w) . "'"; unset($w); } } $new_where .= ')'; $where_val = $new_where; unset($new_where); if (strpos($options['where_is'][$where_key], '!') === false and strpos($options['where_is'][$where_key], 'not') === false) { $options['where_is'][$where_key] = ' in '; } else { $options['where_is'][$where_key] = ' not in '; } } if (is_numeric($where_opt)) { $entry_ids = FrmProAppHelper::filter_where($entry_ids, array('where_opt' => $where_opt, 'where_is' => $options['where_is'][$where_key], 'where_val' => $where_val, 'form_id' => $display->form_id, 'form_posts' => $form_posts, 'after_where' => $after_where)); $after_where = true; $continue = false; if (empty($entry_ids)) { break; } } else { if ($where_opt == 'created_at') { if ($where_val == 'NOW') { $where_val = current_time('mysql', 1); } $where_val = date('Y-m-d H:i:s', strtotime($where_val)); $where .= " and it.created_at " . $options['where_is'][$where_key]; if (strpos($options['where_is'][$where_key], 'in')) { $where .= " {$where_val}"; } else { $where .= " '" . esc_sql($where_val) . "'"; } $continue = true; } else { if ($where_opt == 'id' or $where_opt == 'item_key') { $where .= " and it.{$where_opt} " . $options['where_is'][$where_key]; if (strpos($options['where_is'][$where_key], 'in')) { $where .= " {$where_val}"; } else { $where .= " '" . esc_sql($where_val) . "'"; } $continue = true; } } } } if (!$continue and empty($entry_ids)) { return $content . ' ' . $empty_msg; } } if ($user_id and is_numeric($user_id) and !$uid_used) { $where .= " AND it.user_id=" . (int) $user_id; } $s = FrmAppHelper::get_param('frm_search', false); if ($s) { $new_ids = FrmProEntriesHelper::get_search_ids($s, $display->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)) { return $content . ' ' . $empty_msg; } } if (isset($entry_ids) and !empty($entry_ids)) { $where .= ' and it.id in (' . implode(',', $entry_ids) . ')'; } if ($entry_id) { $where .= " and it.id in ({$entry_id})"; } 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("meta_value='" . $categories[$_GET['frm_cat_id']] . "' and fi.field_key='{$_GET['frm_cat']}'"); } if ($cat_entry_ids) { $where .= " and it.id in (" . implode(',', $cat_entry_ids) . ")"; } } } } if (is_array($options)) { if (!empty($limit) and is_numeric($limit)) { $options['limit'] = (int) $limit; } if (is_numeric($options['limit'])) { $num_limit = (int) $options['limit']; $limit = ' LIMIT ' . $options['limit']; } if (!empty($order_by)) { $options['order_by'] = $order_by; } if (!empty($order)) { $options['order'] = $order; } if (isset($options['order_by']) && $options['order_by'] != '') { /*if( $wpdb->has_cap( 'collation' ) ){ $charset_collate = ''; if( !empty($wpdb->charset) ) $charset_collate .= "DEFAULT CHARACTER SET $wpdb->charset"; if( !empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate"; }*/ $order = isset($options['order']) ? ' ' . $options['order'] : ''; if ($options['order_by'] == 'rand') { $order_by = ' RAND()'; } else { if (is_numeric($options['order_by'])) { global $frm_entry_meta, $frm_field; $order_field = $frm_field->getOne($options['order_by']); $order_field->field_options = maybe_unserialize($order_field->field_options); $meta_order = $order_field->type == 'number' ? ' LENGTH(meta_value),' : ''; if (isset($order_field->field_options['post_field']) and $order_field->field_options['post_field']) { $posts = $form_posts; //$frmdb->get_records($frmdb->entries, array('form_id' => $display->form_id, 'post_id >' => 1), '', '', 'id, post_id'); $linked_posts = array(); foreach ($posts as $post_meta) { $linked_posts[$post_meta->post_id] = $post_meta->id; } if ($order_field->field_options['post_field'] == 'post_custom') { $ordered_ids = $wpdb->get_col("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='" . $order_field->field_options['custom_field'] . "' AND post_id in (" . implode(',', array_keys($linked_posts)) . ") ORDER BY meta_value" . $order); $metas = array(); foreach ($ordered_ids as $ordered_id) { $metas[] = array('item_id' => $linked_posts[$ordered_id]); } } else { if ($order_field->field_options['post_field'] != 'post_category') { $ordered_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE ID in (" . implode(',', array_keys($linked_posts)) . ") ORDER BY " . $order_field->field_options['post_field'] . ' ' . $order); $metas = array(); foreach ($ordered_ids as $ordered_id) { $metas[] = array('item_id' => $linked_posts[$ordered_id]); } } } } else { if ($order_field->type == 'number') { $query = "SELECT it.*, meta_value +0 as odr FROM {$frmdb->entry_metas} it LEFT OUTER JOIN {$frmdb->fields} fi ON it.field_id=fi.id WHERE fi.form_id={$display->form_id} and fi.id={$options['order_by']}"; if (isset($entry_ids) and !empty($entry_ids)) { $query .= " AND it.item_id in (" . implode(',', $entry_ids) . ")"; } $query .= " ORDER BY odr {$order} {$limit}"; if ($limit == ' LIMIT 1') { $metas = $wpdb->get_row($query); } else { $metas = $wpdb->get_results($query); } } else { $metas = $frm_entry_meta->getAll('fi.form_id=' . $display->form_id . ' and fi.id=' . $options['order_by'], ' ORDER BY ' . $meta_order . ' meta_value' . $order); //TODO: add previous $where and $limit } } if (isset($metas) and is_array($metas) and !empty($metas)) { if ($order_field->type == 'time' and (!isset($order_field->field_options['clock']) or $order_field->field_options['clock'] == 12)) { $new_order = array(); foreach ($metas as $key => $meta) { $parts = str_replace(array(' PM', ' AM'), '', $meta->meta_value); $parts = explode(':', $parts); if (is_array($parts)) { if (preg_match('/PM/', $meta->meta_value) and (int) $parts[0] != 12 or (int) $parts[0] == 12 and preg_match('/AM/', $meta->meta_value)) { $parts[0] = (int) $parts[0] + 12; } } $new_order[$key] = (int) $parts[0] . $parts[1]; unset($key); unset($meta); } //array with sorted times asort($new_order); $final_order = array(); foreach ($new_order as $key => $time) { $final_order[] = $metas[$key]; unset($key); unset($time); } $metas = $final_order; unset($final_order); } $rev_order = ($order == 'DESC' or $order == '') ? ' ASC' : ' DESC'; foreach ($metas as $meta) { $meta = (array) $meta; $order_by .= 'it.id=' . $meta['item_id'] . $rev_order . ', '; } $order_by = rtrim($order_by, ', '); } else { $order_by .= 'it.created_at' . $order; } } else { $order_by = 'it.' . $options['order_by'] . $order; } } $order_by = ' ORDER BY ' . $order_by; } } if (!empty($page_size) and is_numeric($page_size)) { $options['page_size'] = (int) $page_size; } if (isset($options['page_size']) && is_numeric($options['page_size'])) { global $frm_app_helper; $current_page = FrmAppHelper::get_param('frm-page', 1); $record_where = $where == "it.form_id={$display->form_id}" ? $display->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($options['page_size'], $record_count); $entries = $frm_entry->getPage($current_page, $options['page_size'], $where, $order_by); $page_last_record = $frm_app_helper->getLastRecordNum($record_count, $current_page, $options['page_size']); $page_first_record = $frm_app_helper->getFirstRecordNum($record_count, $current_page, $options['page_size']); if ($page_count > 1) { $pagination = FrmProDisplaysController::get_pagination_file(FRMPRO_VIEWS_PATH . '/displays/pagination.php', compact('current_page', 'record_count', 'page_count', 'page_last_record', 'page_first_record')); } } else { $entries = $frm_entry->getAll($where, $order_by, $limit, true, false); } $filtered_content = apply_filters('frm_display_entries_content', $new_content, $entries, $shortcodes, $display, $show); 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); $odd = $odd == 'odd' ? 'even' : 'odd'; unset($entry); } unset($count); } else { $display_content .= $empty_msg; } } if ($show == 'all') { $display_content .= isset($options['after_content']) ? stripslashes($options['after_content']) : ''; } } $display_content .= apply_filters('frm_after_display_content', $pagination, $display, $show); if ($display->insert_loc == 'after') { $content .= $display_content; } else { if ($display->insert_loc == 'before') { $content = $display_content . $content; } else { if ($filter) { $display_content = apply_filters('the_content', $display_content); } $content = $display_content; } } return $content; }
</td> </tr> <tr class="hide_dyncontent"> <th valign="top" scope="row"><?php _e('Detail Link', 'formidable'); ?> <img src="<?php echo FRM_IMAGES_URL; ?> /tooltip.png" alt="?" class="frm_help" title="<?php printf(__('Example: If parameter name is \'contact\', the url would be like %1$s/selected-page?contact=2. If this entry is linked to a post, the post permalink will be used instead.', 'formidable'), $frm_siteurl); ?> " /></th> <td> <?php if (FrmProAppHelper::rewriting_on() && $frmpro_settings->permalinks) { ?> <select id="type" name="type"> <option value=""></option> <option value="id" <?php selected($values['type'], 'id'); ?> ><?php _e('ID', 'formidable'); ?> </option> <option value="display_key" <?php selected($values['type'], 'display_key'); ?> ><?php _e('Key', 'formidable');
function validate($values) { $errors = array(); if ($values['post_title'] == '') { $errors[] = __('Name cannot be blank', 'formidable'); } if ($values['excerpt'] == __('This is not displayed anywhere, but is just for your reference. (optional)', 'formidable')) { $_POST['excerpt'] = ''; } if ($values['content'] == '') { $errors[] = __('Content cannot be blank', 'formidable'); } if ($values['insert_loc'] != 'none' && $values['post_id'] == '') { $errors[] = __('Page cannot be blank if you want the content inserted automatically', 'formidable'); } if (!empty($values['options']['limit']) && !is_numeric($values['options']['limit'])) { $errors[] = __('Limit must be a number', 'formidable'); } if ($values['show_count'] == 'dynamic') { if ($values['dyncontent'] == '') { $errors[] = __('Dynamic Content cannot be blank', 'formidable'); } if (!FrmProAppHelper::rewriting_on()) { if ($values['param'] == '') { $errors[] = __('Parameter Name cannot be blank if content is dynamic', 'formidable'); } if ($values['type'] == '') { $errors[] = __('Parameter Value cannot be blank if content is dynamic', 'formidable'); } } else { if ($values['type'] == '') { $errors[] = __('Detail Link cannot be blank if content is dynamic', 'formidable'); } } } if (isset($values['options']['where'])) { $_POST['options']['where'] = FrmProAppHelper::reset_keys($values['options']['where']); $_POST['options']['where_is'] = FrmProAppHelper::reset_keys($values['options']['where_is']); $_POST['options']['where_val'] = FrmProAppHelper::reset_keys($values['options']['where_val']); } return $errors; }