本文整理汇总了PHP中FrmDb::get_results方法的典型用法代码示例。如果您正苦于以下问题:PHP FrmDb::get_results方法的具体用法?PHP FrmDb::get_results怎么用?PHP FrmDb::get_results使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FrmDb
的用法示例。
在下文中一共展示了FrmDb::get_results方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form
function form($form_action, $args = array())
{
global $wpdb;
extract($args);
$post_types = FrmProAppHelper::get_custom_post_types();
if (!$post_types) {
return;
}
$post_type = FrmProFormsHelper::post_type($args['values']['id']);
$taxonomies = get_object_taxonomies($post_type);
$action_control = $this;
$echo = true;
$form_id = $form->id;
$display = false;
$displays = array();
$display_ids = FrmDb::get_col($wpdb->postmeta, array('meta_key' => 'frm_form_id', 'meta_value' => $form_id), 'post_ID');
if ($display_ids) {
$query_args = array('pm.meta_key' => 'frm_show_count', 'post_type' => 'frm_display', 'pm.meta_value' => array('dynamic', 'calendar', 'one'), 'p.post_status' => array('publish', 'private'), 'p.ID' => $display_ids);
$displays = FrmDb::get_results($wpdb->posts . ' p LEFT JOIN ' . $wpdb->postmeta . ' pm ON (p.ID = pm.post_ID)', $query_args, 'p.ID, p.post_title', array('order_by' => 'p.post_title ASC'));
if (isset($form_action->post_content['display_id'])) {
// get view from settings
if (is_numeric($form_action->post_content['display_id'])) {
$display = FrmProDisplay::getOne($form_action->post_content['display_id'], false, true);
}
} else {
if (!is_numeric($form_action->post_content['post_content']) && !empty($display_ids)) {
// get auto view
$display = FrmProDisplay::get_form_custom_display($form_id);
if ($display) {
$display = FrmProDisplaysHelper::setup_edit_vars($display, true);
}
}
}
}
// Get array of all custom fields
$custom_fields = array();
if (isset($form_action->post_content['post_custom_fields'])) {
foreach ($form_action->post_content['post_custom_fields'] as $custom_field_opts) {
if (isset($custom_field_opts['meta_name'])) {
$custom_fields[] = $custom_field_opts['meta_name'];
}
unset($custom_field_opts);
}
}
unset($display_ids);
include dirname(__FILE__) . '/post_options.php';
}
示例2: getAll
public static function getAll($where, $order_by = '', $limit = '', $meta = false, $inc_form = true)
{
global $wpdb;
$limit = FrmAppHelper::esc_limit($limit);
$cache_key = maybe_serialize($where) . $order_by . $limit . $inc_form;
$entries = wp_cache_get($cache_key, 'frm_entry');
if (false === $entries) {
$fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
$table = $wpdb->prefix . 'frm_items it ';
if ($inc_form) {
$fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
$table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
}
if (preg_match('/ meta_([0-9]+)/', $order_by, $order_matches)) {
// sort by a requested field
$field_id = (int) $order_matches[1];
$fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
unset($order_matches, $field_id);
}
// prepare the query
$query = 'SELECT ' . $fields . ' FROM ' . $table . FrmAppHelper::prepend_and_or_where(' WHERE ', $where) . $order_by . $limit;
$entries = $wpdb->get_results($query, OBJECT_K);
unset($query);
if (!FrmAppHelper::prevent_caching()) {
wp_cache_set($cache_key, $entries, 'frm_entry', 300);
}
}
if (!$meta || !$entries) {
return stripslashes_deep($entries);
}
unset($meta);
if (!is_array($where) && preg_match('/^it\\.form_id=\\d+$/', $where)) {
$where = array('it.form_id' => substr($where, 11));
}
$meta_where = array('field_id !' => 0);
if ($limit == '' && is_array($where) && count($where) == 1 && isset($where['it.form_id'])) {
$meta_where['fi.form_id'] = $where['it.form_id'];
} else {
$meta_where['item_id'] = array_keys($entries);
}
$metas = FrmDb::get_results($wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id');
unset($meta_where);
if (!$metas) {
return stripslashes_deep($entries);
}
foreach ($metas as $m_key => $meta_val) {
if (!isset($entries[$meta_val->item_id])) {
continue;
}
if (!isset($entries[$meta_val->item_id]->metas)) {
$entries[$meta_val->item_id]->metas = array();
}
$entries[$meta_val->item_id]->metas[$meta_val->field_id] = maybe_unserialize($meta_val->meta_value);
unset($m_key, $meta_val);
}
if (!FrmAppHelper::prevent_caching()) {
foreach ($entries as $entry) {
wp_cache_set($entry->id, $entry, 'frm_entry');
unset($entry);
}
}
return stripslashes_deep($entries);
}
示例3: migrate_to_6
private function migrate_to_6()
{
global $wpdb;
$no_save = array_merge(FrmField::no_save_fields(), array('form', 'hidden', 'user_id'));
$fields = FrmDb::get_results($this->fields, array('type NOT' => $no_save), 'id, field_options');
$default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
<label class="frm_pos_[label_position]">[field_name]
<span class="frm_required">[required_label]</span>
</label>
[input]
[if description]<div class="frm_description">[description]</div>[/if description]
</div>
DEFAULT_HTML;
$old_default_html = <<<DEFAULT_HTML
<div id="frm_field_[id]_container" class="form-field [required_class] [error_class]">
<label class="frm_pos_[label_position]">[field_name]
<span class="frm_required">[required_label]</span>
</label>
[input]
[if description]<p class="frm_description">[description]</p>[/if description]
</div>
DEFAULT_HTML;
$new_default_html = FrmFieldsHelper::get_default_html('text');
foreach ($fields as $field) {
$field->field_options = maybe_unserialize($field->field_options);
if (!FrmField::is_option_empty($field, 'custom_html') || $field->field_options['custom_html'] == $default_html || $field->field_options['custom_html'] == $old_default_html) {
$field->field_options['custom_html'] = $new_default_html;
$wpdb->update($this->fields, array('field_options' => maybe_serialize($field->field_options)), array('id' => $field->id));
}
unset($field);
}
unset($default_html, $old_default_html, $fields);
}
示例4: _check_if_child_entries_moved
/**
* @covers FrmProFieldsHelper::move_entries_to_parent_form
*/
function _check_if_child_entries_moved($args)
{
global $wpdb;
// First check if old frm_items are gone from child form
$items = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "frm_items WHERE form_id=" . $args['form_id']);
$this->assertEmpty($items, 'Rows in wp_frm_items were not deleted when switching from repeating to non-repeating.');
// Check if frm_item_metas were moved to parent entries
$new_child_metas = FrmDb::get_results($wpdb->prefix . 'frm_item_metas m LEFT JOIN ' . $wpdb->prefix . 'frm_items i ON i.id=m.item_id', array('field_id' => $args['children']), 'i.form_id', array('order_by' => 'i.created_at ASC'));
$this->assertNotEmpty($new_child_metas, 'No entries to check (when switching divider to non-repeatable).');
foreach ($new_child_metas as $item_meta) {
$this->assertEquals($args['parent_form_id'], $item_meta->form_id, 'Child entries are not moved to parent form when a divider is switched from repeating to non-repeating.');
}
// Make sure frm_item_metas for repeating section are cleaned up
$rep_meta_values = $wpdb->get_col("SELECT meta_value FROM " . $wpdb->prefix . "frm_item_metas WHERE field_id=" . $args['field_id']);
$this->assertEmpty($rep_meta_values, 'frm_item_metas for repeating section were not deleted when switching to non-repeatable.');
self::_check_if_child_form_deleted($args['form_id']);
}
示例5: _check_if_extra_child_metas_deleted
function _check_if_extra_child_metas_deleted($args)
{
global $wpdb;
// Get number of entries in parent form
$parent_entries = FrmDb::get_results($wpdb->prefix . 'frm_items', array('form_id' => $args['parent_form_id']), 'id');
$entries_for_one_field = FrmDb::get_results($wpdb->prefix . 'frm_item_metas', array('field_id' => reset($args['children'])), 'item_id');
$this->assertEquals(count($parent_entries), count($entries_for_one_field), 'Child item_metas were not deleted when switching a repeating section to non-repeating. Only the item_metas for the first row of each repeating section should be saved.');
}
示例6: get_field_stats
public static function get_field_stats($id, $type = 'total', $user_id = false, $value = false, $round = 100, $limit = '', $atts = array(), $drafts = false)
{
global $wpdb, $frm_post_ids;
$field = FrmField::getOne($id);
if (!$field) {
return 0;
}
$id = $field->id;
if (isset($atts['thousands_sep']) && $atts['thousands_sep']) {
$thousands_sep = $atts['thousands_sep'];
unset($atts['thousands_sep']);
$round = $round == 100 ? 2 : $round;
}
$where = array();
if ($value) {
$slash_val = strpos($value, '\\') === false ? addslashes($value) : $value;
if (FrmField::is_field_with_multiple_values($field)) {
$where[] = array('or' => 1, 'meta_value like' => $value, 'meta_value like ' => $slash_val);
//add extra slashes to match values that are escaped in the database
} else {
//$where_value = $wpdb->prepare(" meta_value = %s", addcslashes( $slash_val, '_%' ) );
$where[] = array('or' => 1, 'meta_value' => $value, 'meta_value ' => addcslashes($slash_val, '_%'));
}
unset($slash_val);
}
//if(!$frm_post_ids)
$frm_post_ids = array();
$post_ids = array();
if (isset($frm_post_ids[$id])) {
$form_posts = $frm_post_ids[$id];
} else {
$where_post = array('form_id' => $field->form_id, 'post_id >' => 1);
if ($drafts != 'both') {
$where_post['is_draft'] = $drafts;
}
if ($user_id) {
$where_post['user_id'] = $user_id;
}
$form_posts = FrmDb::get_results('frm_items', $where_post, 'id,post_id');
$frm_post_ids[$id] = $form_posts;
}
foreach ((array) $form_posts as $form_post) {
$post_ids[$form_post->id] = $form_post->post_id;
}
if ($value) {
$atts[$id] = $value;
}
if (!empty($atts)) {
$entry_ids = array();
if (isset($atts['entry_id']) && $atts['entry_id'] && is_numeric($atts['entry_id'])) {
$entry_ids[] = $atts['entry_id'];
}
$after_where = false;
foreach ($atts as $orig_f => $val) {
// Accommodate for times when users are in Visual tab
$val = str_replace(array('>', '<'), array('>', '<'), $val);
// If first character is a quote, but the last character is not a quote
if (strpos($val, '"') === 0 && substr($val, -1) != '"' || strpos($val, "'") === 0 && substr($val, -1) != "'") {
//parse atts back together if they were broken at spaces
$next_val = array('char' => substr($val, 0, 1), 'val' => $val);
continue;
// If we don't have a previous value that needs to be parsed back together
} else {
if (!isset($next_val)) {
$temp = FrmAppHelper::replace_quotes($val);
foreach (array('"', "'") as $q) {
// Check if <" or >" exists in string and string does not end with ".
if (substr($temp, -1) != $q && (strpos($temp, '<' . $q) || strpos($temp, '>' . $q))) {
$next_val = array('char' => $q, 'val' => $val);
$cont = true;
}
unset($q);
}
unset($temp);
if (isset($cont)) {
unset($cont);
continue;
}
}
}
// If we have a previous value saved that needs to be parsed back together (due to WordPress pullling it apart)
if (isset($next_val)) {
if (substr(FrmAppHelper::replace_quotes($val), -1) == $next_val['char']) {
$val = $next_val['val'] . ' ' . $val;
unset($next_val);
} else {
$next_val['val'] .= ' ' . $val;
continue;
}
}
$entry_ids = self::get_field_matches(compact('entry_ids', 'orig_f', 'val', 'id', 'atts', 'field', 'form_posts', 'after_where', 'drafts'));
$after_where = true;
}
if (empty($entry_ids)) {
if ($type == 'star') {
$stat = '';
ob_start();
include FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/star_disabled.php';
$contents = ob_get_contents();
ob_end_clean();
//.........这里部分代码省略.........
示例7: array
?>
</editable>
<options><?php
echo FrmXMLHelper::prepare_form_options_for_export($form->options);
?>
</options>
<status><?php
echo FrmXMLHelper::cdata($form->status);
?>
</status>
<parent_form_id><?php
echo $form->parent_form_id;
?>
</parent_form_id>
<?php
$fields = FrmDb::get_results($wpdb->prefix . 'frm_fields', array('form_id' => $form->id), '*', array('order_by' => 'field_order'));
foreach ($fields as $field) {
?>
<field>
<id><?php
echo $field->id;
?>
</id>
<field_key><?php
echo FrmXMLHelper::cdata($field->field_key);
?>
</field_key>
<name><?php
echo FrmXMLHelper::cdata($field->name);
?>
</name>
示例8: create_entry_from_post_box
public static function create_entry_from_post_box($post_type, $post = false)
{
if (!$post || !isset($post->ID) || $post_type == 'attachment' || $post_type == 'link') {
return;
}
global $wpdb, $frm_vars;
//don't show the meta box if there is already an entry for this post
$post_entry = FrmDb::get_var($wpdb->prefix . 'frm_items', array('post_id' => $post->ID));
if ($post_entry) {
return;
}
//don't show meta box if no forms are set up to create this post type
$actions = FrmFormAction::get_action_for_form(0, 'wppost');
if (!$actions) {
return;
}
$form_ids = array();
foreach ($actions as $action) {
if ($action->post_content['post_type'] == $post_type && $action->menu_order) {
$form_ids[] = $action->menu_order;
}
}
if (empty($form_ids)) {
return;
}
$forms = FrmDb::get_results('frm_forms', array('id' => $form_ids), 'id, name');
$frm_vars['post_forms'] = $forms;
if (current_user_can('frm_create_entries')) {
add_meta_box('frm_create_entry', __('Create Entry in Form', 'formidable'), 'FrmProEntriesController::render_meta_box_content', null, 'side');
}
}
示例9: wp_cache_get
/**
* @return int count of forms
*/
public static function &get_count()
{
global $wpdb;
$cache_key = 'frm_form_counts';
$counts = wp_cache_get($cache_key, 'counts');
if (false !== $counts) {
return $counts;
}
$results = (array) FrmDb::get_results('frm_forms', array('or' => 1, 'parent_form_id' => null, 'parent_form_id <' => 0), 'status, is_template');
$statuses = array('published', 'draft', 'template', 'trash');
$counts = array_fill_keys($statuses, 0);
foreach ($results as $row) {
if ('trash' != $row->status) {
if ($row->is_template) {
$counts['template']++;
} else {
$counts['published']++;
}
} else {
$counts['trash']++;
}
if ('draft' == $row->status) {
$counts['draft']++;
}
unset($row);
}
$counts = (object) $counts;
wp_cache_set($cache_key, $counts, 'counts');
return $counts;
}
示例10: absint
</is_draft>
<user_id><?php
echo FrmXMLHelper::cdata(FrmProFieldsHelper::get_display_name($entry->user_id, 'user_login'));
?>
</user_id>
<updated_by><?php
echo FrmXMLHelper::cdata(FrmProFieldsHelper::get_display_name($entry->updated_by, 'user_login'));
?>
</updated_by>
<parent_item_id><?php
echo absint($entry->parent_item_id);
?>
</parent_item_id>
<?php
$metas = FrmDb::get_results($wpdb->prefix . 'frm_item_metas', array('item_id' => $entry->id), 'meta_value, field_id');
foreach ($metas as $meta) {
?>
<item_meta>
<field_id><?php
echo absint($meta->field_id);
?>
</field_id>
<meta_value><?php
if (isset($fields[$meta->field_id])) {
$meta->meta_value = FrmProFieldsHelper::get_export_val($meta->meta_value, $fields[$meta->field_id]);
}
echo FrmXMLHelper::cdata($meta->meta_value);
unset($meta);
?>
</meta_value>
示例11: migrate_to_16
/**
* Migrate displays table into wp_posts
*/
private static function migrate_to_16()
{
global $wpdb;
$display_posts = array();
if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->prefix}frm_display'")) {
//only migrate if table exists
$dis = FrmDb::get_results('frm_display');
} else {
$dis = array();
}
foreach ($dis as $d) {
$post = array('post_title' => $d->name, 'post_content' => $d->content, 'post_date' => $d->created_at, 'post_excerpt' => $d->description, 'post_name' => $d->display_key, 'post_status' => 'publish', 'post_type' => 'frm_display');
$post_ID = wp_insert_post($post);
unset($post);
update_post_meta($post_ID, 'frm_old_id', $d->id);
if (!isset($d->show_count) || empty($d->show_count)) {
$d->show_count = 'none';
}
foreach (array('dyncontent', 'param', 'form_id', 'post_id', 'entry_id', 'param', 'type', 'show_count', 'insert_loc') as $f) {
update_post_meta($post_ID, 'frm_' . $f, $d->{$f});
unset($f);
}
$d->options = maybe_unserialize($d->options);
update_post_meta($post_ID, 'frm_options', $d->options);
if (isset($d->options['insert_loc']) && $d->options['insert_loc'] != 'none' && is_numeric($d->options['post_id']) && !isset($display_posts[$d->options['post_id']])) {
$display_posts[$d->options['post_id']] = $post_ID;
}
unset($d, $post_ID);
}
unset($dis);
//get all post_ids from frm_entries
$entry_posts = FrmDb::get_results($wpdb->prefix . 'frm_items', array('post_id >' => 1), 'id, post_id, form_id');
$form_display = array();
foreach ($entry_posts as $ep) {
if (isset($form_display[$ep->form_id])) {
$display_posts[$ep->post_id] = $form_display[$ep->form_id];
} else {
$d = FrmProDisplay::get_auto_custom_display(array('post_id' => $ep->post_id, 'form_id' => $ep->form_id, 'entry_id' => $ep->id));
$display_posts[$ep->post_id] = $form_display[$ep->form_id] = $d ? $d->ID : 0;
unset($d);
}
unset($ep);
}
unset($form_display);
foreach ($display_posts as $post_ID => $d) {
if ($d) {
update_post_meta($post_ID, 'frm_display_id', $d);
}
unset($d, $post_ID);
}
unset($display_posts);
}
示例12: get_entry_meta_info
public static function get_entry_meta_info($entry_id)
{
return FrmDb::get_results('frm_item_metas', array('item_id' => $entry_id));
}
示例13: get_daily_entries
static function get_daily_entries($form, $opts = array(), $type = 'DATE')
{
global $wpdb;
$options = array();
if (isset($opts['colors'])) {
$options['colors'] = explode(',', $opts['colors']);
}
if (isset($opts['bg_color'])) {
$options['backgroundColor'] = $opts['bg_color'];
}
$type = strtoupper($type);
$end_timestamp = time();
//Chart for Entries Submitted
if ($type == 'HOUR') {
$start_timestamp = strtotime('-48 hours');
$title = __('Hourly Entries', 'formidable');
} else {
if ($type == 'MONTH') {
$start_timestamp = strtotime('-1 year');
$end_timestamp = strtotime('+1 month');
$title = __('Monthly Entries', 'formidable');
} else {
if ($type == 'YEAR') {
$start_timestamp = strtotime('-10 years');
$title = __('Yearly Entries', 'formidable');
} else {
$start_timestamp = strtotime('-1 month');
$title = __('Daily Entries', 'formidable');
}
}
}
$query = array('form_id' => $form->id, 'is_draft' => 0);
$args = array();
if ($type == 'HOUR') {
$field = 'created_at';
$query['created_at >'] = date('Y-m-d H', $start_timestamp) . ':00:00';
} else {
$field = 'DATE(created_at)';
$query['created_at >'] = date('Y-m-d', $start_timestamp) . ' 00:00:00';
$args['group_by'] = $type . '(created_at)';
}
$entries_array = FrmDb::get_results('frm_items', $query, $field . ' as endate, COUNT(*) as encount', $args);
$temp_array = $counts_array = $dates_array = array();
// Refactor Array for use later on
foreach ($entries_array as $e) {
$e_key = $e->endate;
if ($type == 'HOUR') {
$e_key = date('Y-m-d H', strtotime($e->endate)) . ':00:00';
} else {
if ($type == 'MONTH') {
$e_key = date('Y-m', strtotime($e->endate)) . '-01';
} else {
if ($type == 'YEAR') {
$e_key = date('Y', strtotime($e->endate)) . '-01-01';
}
}
}
$temp_array[$e_key] = $e->encount;
}
// Get the dates array
if ($type == 'HOUR') {
for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60) {
if (!in_array(date('Y-m-d H', $e) . ':00:00', $dates_array)) {
$dates_array[] = date('Y-m-d H', $e) . ':00:00';
}
}
$date_format = get_option('time_format');
} else {
if ($type == 'MONTH') {
for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 25) {
if (!in_array(date('Y-m', $e) . '-01', $dates_array)) {
$dates_array[] = date('Y-m', $e) . '-01';
}
}
$date_format = 'F Y';
} else {
if ($type == 'YEAR') {
for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24 * 364) {
if (!in_array(date('Y', $e) . '-01-01', $dates_array)) {
$dates_array[] = date('Y', $e) . '-01-01';
}
}
$date_format = 'Y';
} else {
for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24) {
$dates_array[] = date('Y-m-d', $e);
}
$date_format = get_option('date_format');
}
}
}
if (empty($dates_array)) {
return;
}
// Make sure counts array is in order and includes zero click days
foreach ($dates_array as $date_str) {
if (isset($temp_array[$date_str])) {
$counts_array[$date_str] = $temp_array[$date_str];
} else {
$counts_array[$date_str] = 0;
//.........这里部分代码省略.........
示例14: esc_html
?>
</post_password>
<is_sticky><?php
echo esc_html($is_sticky);
?>
</is_sticky>
<?php
if ($post->post_type == 'attachment') {
?>
<attachment_url><?php
echo wp_get_attachment_url($post->ID);
?>
</attachment_url>
<?php
}
$postmeta = FrmDb::get_results($wpdb->postmeta, array('post_id' => $post->ID));
foreach ($postmeta as $meta) {
if (apply_filters('wxr_export_skip_postmeta', false, $meta->meta_key, $meta)) {
continue;
}
?>
<postmeta>
<meta_key><?php
echo esc_html($meta->meta_key);
?>
</meta_key>
<meta_value><?php
echo FrmXMLHelper::cdata($meta->meta_value);
?>
</meta_value>
</postmeta>
示例15: widget
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 == '') {
//.........这里部分代码省略.........