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; }
function build_calendar($new_content, $entries, $shortcodes, $display, $show = 'one') { if (!$display or $display->show_count != 'calendar') { return $new_content; } global $frm_entry_meta, $wp_locale; $display_options = maybe_unserialize($display->options); $current_year = date_i18n('Y'); $current_month = date_i18n('n'); $year = FrmAppHelper::get_param('frmcal-year', date('Y')); //4 digit year $month = FrmAppHelper::get_param('frmcal-month', $current_month); //Numeric month without leading zeros $timestamp = mktime(0, 0, 0, $month, 1, $year); $maxday = date('t', $timestamp); //Number of days in the given month $this_month = getdate($timestamp); $startday = $this_month['wday']; if ($current_year == $year and $current_month == $month) { $today = date_i18n('j'); } $cal_end = $maxday + $startday; $t = $cal_end > 35 ? 42 : ($cal_end == 28 ? 28 : 35); $extrarows = $t - $maxday - $startday; $show_entres = false; $daily_entries = array(); if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) { $field = FrmField::getOne($display_options['date_field_id']); } if (isset($display_options['edate_field_id']) and is_numeric($display_options['edate_field_id'])) { $efield = FrmField::getOne($display_options['edate_field_id']); } else { $efield = false; } foreach ($entries as $entry) { if (isset($display_options['date_field_id']) and is_numeric($display_options['date_field_id'])) { if (isset($entry->metas)) { $date = isset($entry->metas[$display_options['date_field_id']]) ? $entry->metas[$display_options['date_field_id']] : false; } else { $date = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display_options['date_field_id']); } if ($entry->post_id and !$date) { if ($field) { $field->field_options = maybe_unserialize($field->field_options); if ($field->field_options['post_field']) { $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('form_id' => $display->form_id, 'type' => $field->type, 'field' => $field)); } } } } else { if ($display_options['date_field_id'] == 'updated_at') { $date = $entry->updated_at; $i18n = true; } else { $date = $entry->created_at; $i18n = true; } } if (empty($date)) { continue; } if (isset($il8n) and $il8n) { $date = date_i18n('Y-m-d', strtotime($date)); } else { $date = date('Y-m-d', strtotime($date)); } unset($i18n); $dates = array($date); if (isset($display_options['edate_field_id']) and !empty($display_options['edate_field_id'])) { if (is_numeric($display_options['edate_field_id']) and $efield) { $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $efield); if ($efield and $efield->type == 'number' and is_numeric($edate)) { $edate = date('Y-m-d', strtotime('+' . $edate . ' days', strtotime($date))); } } else { if ($display_options['edate_field_id'] == 'updated_at') { $edate = date_i18n('Y-m-d', strtotime($entry->updated_at)); } else { $edate = date_i18n('Y-m-d', strtotime($entry->created_at)); } } if ($edate and !empty($edate)) { $from_date = strtotime($date); $to_date = strtotime($edate); if (!empty($from_date) and $from_date < $to_date) { for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) { $dates[] = date('Y-m-d', $current_ts); } unset($current_ts); } unset($from_date); unset($to_date); } unset($edate); $used_entries = array(); } unset($date); $dates = apply_filters('frm_show_entry_dates', $dates, $entry); for ($i = 0; $i < $maxday + $startday; $i++) { $day = $i - $startday + 1; if (in_array(date('Y-m-d', strtotime("{$year}-{$month}-{$day}")), $dates)) { $show_entres = true; $daily_entres[$i][] = $entry; } unset($day); } unset($dates); } $day_names = $wp_locale->weekday_abbrev; $day_names = FrmProAppHelper::reset_keys($day_names); //switch keys to order ob_start(); include FRMPRO_VIEWS_PATH . '/displays/calendar.php'; $content = ob_get_contents(); ob_end_clean(); return $content; }
/** * Group entries by month or quarter * * @since 2.0 * * @param array $values * @param array $f_values - additional field values * @param array $labels * @param array $tooltips * @param array $args - arguments */ public static function graph_by_period(&$values, &$f_values, &$labels, &$tooltips, $args) { if (!isset($args['group_by']) || !in_array($args['group_by'], array('month', 'quarter'))) { return; } $labels = FrmProAppHelper::reset_keys($labels); $values = FrmProAppHelper::reset_keys($values); // Loop through labels and change labels to month or quarter foreach ($labels as $key => $label) { if ($args['group_by'] == 'month') { $labels[$key] = date('F Y', strtotime($label)); } else { if ($args['group_by'] == 'quarter') { //Convert date to Y-m-d format $label = date('Y-m-d', strtotime($label)); if (preg_match('/-(01|02|03)-/', $label)) { $labels[$key] = 'Q1 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(04|05|06)-/', $label)) { $labels[$key] = 'Q2 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(07|08|09)-/', $label)) { $labels[$key] = 'Q3 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(10|11|12)-/', $label)) { $labels[$key] = 'Q4 ' . date('Y', strtotime($label)); } } } } } } } // Combine identical labels and values $count = count($labels) - 1; for ($i = 0; $i < $count; $i++) { if ($labels[$i] == $labels[$i + 1]) { unset($labels[$i]); $values[$i + 1] = $values[$i] + $values[$i + 1]; unset($values[$i]); //Group additional field values foreach ($args['ids'] as $field_id) { $f_values[$field_id][$i + 1] = $f_values[$field_id][$i] + $f_values[$field_id][$i + 1]; unset($f_values[$field_id][$i], $field_id); } } } // Reset keys for additional field values foreach ($args['ids'] as $field_id) { $f_values[$field_id] = FrmProAppHelper::reset_keys($f_values[$field_id]); } }
public static function build_calendar($new_content, $entries, $shortcodes, $display, $show = 'one') { if (!$display || $display->frm_show_count != 'calendar' || $show == 'one') { return $new_content; } global $frm_entry_meta, $wp_locale, $frm_field; $current_year = date_i18n('Y'); $current_month = date_i18n('m'); $year = FrmAppHelper::get_param('frmcal-year', date('Y')); //4 digit year $month = FrmAppHelper::get_param('frmcal-month', $current_month); //Numeric month with leading zeros $timestamp = mktime(0, 0, 0, $month, 1, $year); $maxday = date('t', $timestamp); //Number of days in the given month $this_month = getdate($timestamp); $startday = $this_month['wday']; // week_begins = 0 stands for Sunday $week_begins = apply_filters('frm_cal_week_begins', intval(get_option('start_of_week')), $display); if ($week_begins > $startday) { $startday = $startday + 7; } $week_ends = 6 + (int) $week_begins; if ($week_ends > 6) { $week_ends = (int) $week_ends - 7; } if ($current_year == $year and $current_month == $month) { $today = date_i18n('j'); } $daily_entries = array(); if (isset($display->frm_date_field_id) && is_numeric($display->frm_date_field_id)) { $field = $frm_field->getOne($display->frm_date_field_id); } if (isset($display->frm_edate_field_id) && is_numeric($display->frm_edate_field_id)) { $efield = $frm_field->getOne($display->frm_edate_field_id); } else { $efield = false; } foreach ($entries as $entry) { if (isset($display->frm_date_field_id) && is_numeric($display->frm_date_field_id)) { if (isset($entry->metas)) { $date = isset($entry->metas[$display->frm_date_field_id]) ? $entry->metas[$display->frm_date_field_id] : false; } else { $date = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_date_field_id); } if ($entry->post_id && !$date && $field && isset($field->field_options['post_field']) && $field->field_options['post_field']) { $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('form_id' => $display->frm_form_id, 'type' => $field->type, 'field' => $field)); } } else { if ($display->frm_date_field_id == 'updated_at') { $date = $entry->updated_at; $i18n = true; } else { $date = $entry->created_at; $i18n = true; } } if (empty($date)) { continue; } if (isset($i18n) && $i18n) { $date = get_date_from_gmt($date); $date = date_i18n('Y-m-d', strtotime($date)); } else { $date = date('Y-m-d', strtotime($date)); } unset($i18n); $dates = array($date); if (isset($display->frm_edate_field_id) && !empty($display->frm_edate_field_id)) { if (is_numeric($display->frm_edate_field_id) and $efield) { $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $efield); if ($efield && $efield->type == 'number' && is_numeric($edate)) { $edate = date('Y-m-d', strtotime('+' . ($edate - 1) . ' days', strtotime($date))); } } else { if ($display->frm_edate_field_id == 'updated_at') { $edate = get_date_from_gmt($entry->updated_at); $edate = date_i18n('Y-m-d', strtotime($edate)); } else { $edate = get_date_from_gmt($entry->created_at); $edate = date_i18n('Y-m-d', strtotime($edate)); } } if ($edate and !empty($edate)) { $from_date = strtotime($date); $to_date = strtotime($edate); if (!empty($from_date) and $from_date < $to_date) { for ($current_ts = $from_date; $current_ts <= $to_date; $current_ts += 60 * 60 * 24) { $dates[] = date('Y-m-d', $current_ts); } unset($current_ts); } unset($from_date); unset($to_date); } unset($edate); $used_entries = array(); } unset($date); //Recurring events if (isset($display->frm_repeat_event_field_id) && is_numeric($display->frm_repeat_event_field_id)) { if (isset($entry->metas)) { //When is $entry->metas not set? Is it when posts are created? $repeat_period = isset($entry->metas[$display->frm_repeat_event_field_id]) ? $entry->metas[$display->frm_repeat_event_field_id] : false; $stop_repeat = isset($entry->metas[$display->frm_repeat_edate_field_id]) ? $entry->metas[$display->frm_repeat_edate_field_id] : false; } else { //Test this else section $repeat_period = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_repeat_event_field_id); $stop_repeat = $frm_entry_meta->get_entry_meta_by_field($entry->id, $display->frm_repeat_edate_field_id); } //If site is not set to English, convert day(s), week(s), month(s), and year(s) (in repeat_period string) to English //Check for a few common repeat periods like daily, weekly, monthly, and yearly as well $t_strings = array(__('day', 'formidable'), __('days', 'formidable'), __('daily', 'formidable'), __('week', 'formidable'), __('weeks', 'formidable'), __('weekly', 'formidable'), __('month', 'formidable'), __('months', 'formidable'), __('monthly', 'formidable'), __('year', 'formidable'), __('years', 'formidable'), __('yearly', 'formidable')); $t_strings = apply_filters('frm_recurring_strings', $t_strings, $display); $e_strings = array('day', 'days', '1 day', 'week', 'weeks', '1 week', 'month', 'months', '1 month', 'year', 'years', '1 year'); if ($t_strings != $e_strings) { $repeat_period = str_ireplace($t_strings, $e_strings, $repeat_period); } unset($t_strings, $e_strings); //Switch [frmcal-date] for current calendar date (for use in "Third Wednesday of [frmcal-date]") $repeat_period = str_replace('[frmcal-date]', $year . '-' . $month . '-01', $repeat_period); //Filter for repeat_period $repeat_period = apply_filters('frm_repeat_period', $repeat_period, $display); //If repeat period is set and is valid if (!empty($repeat_period) && is_numeric(strtotime($repeat_period))) { //Set up end date to minimize dates array - allow for no end repeat field set, nothing selected for end, or any date if (isset($display->frm_repeat_edate_field_id) && !empty($stop_repeat)) { //If field is selected for recurring end date and the date is not empty $maybe_stop_repeat = strtotime($stop_repeat); } //Repeat until next viewable month $cal_date = $year . '-' . $month . '-01'; $stop_repeat = strtotime('+1 month', strtotime($cal_date)); //If the repeat should end before $stop_repeat (+1 month), use $maybe_stop_repeat if (isset($maybe_stop_repeat) && $maybe_stop_repeat < $stop_repeat) { $stop_repeat = $maybe_stop_repeat; unset($maybe_stop_repeat); } $temp_dates = array(); foreach ($dates as $d) { $last_i = 0; for ($i = strtotime($d); $i <= $stop_repeat; $i = strtotime($repeat_period, $i)) { //Break endless loop if ($i == $last_i) { break; } $last_i = $i; //Add to dates array $temp_dates[] = date('Y-m-d', $i); } unset($last_i); unset($d); } $dates = $temp_dates; unset($repeat_period, $to_date, $start_date, $stop_repeat, $temp_dates); } } $dates = apply_filters('frm_show_entry_dates', $dates, $entry); for ($i = 0; $i < $maxday + $startday; $i++) { $day = $i - $startday + 1; if (in_array(date('Y-m-d', strtotime("{$year}-{$month}-{$day}")), $dates)) { $daily_entres[$i][] = $entry; } unset($day); } unset($dates); } $day_names = $wp_locale->weekday_abbrev; $day_names = FrmProAppHelper::reset_keys($day_names); //switch keys to order if ($week_begins) { for ($i = $week_begins; $i < $week_begins + 7; $i++) { if (!isset($day_names[$i])) { $day_names[$i] = $day_names[$i - 7]; } } unset($i); } ob_start(); include FrmAppHelper::plugin_path() . '/pro/classes/views/displays/calendar.php'; $content = ob_get_contents(); ob_end_clean(); return $content; }
function get_graph_values($field, $args) { global $frm_entry_meta, $frm_field, $frmdb, $wpdb; $values = $labels = $f_values = $f_labels = $rows = $cols = array(); $pie = false; extract($args); $show_key = (int) $show_key; if ($show_key and $show_key < 5) { $show_key = 10; } $options = array('width' => $width, 'height' => $height, 'legend' => 'none'); if (!empty($colors)) { $options['colors'] = $colors; } $options['title'] = preg_replace("/&#?[a-z0-9]{2,8};/i", "", FrmAppHelper::truncate($field->name, $truncate, 0)); if ($show_key) { $options['legend'] = array('position' => 'right', 'textStyle' => array('fontSize' => $show_key)); } $fields = $f_inputs = array(); $fields[$field->id] = $field; if ($ids) { $ids = explode(',', $ids); foreach ($ids as $id_key => $f) { $ids[$id_key] = $f = trim($f); if (!$f or empty($f)) { unset($ids[$id_key]); continue; } if ($add_field = $frm_field->getOne($f)) { $fields[$add_field->id] = $add_field; $ids[$id_key] = $add_field->id; } unset($f); unset($id_key); } } else { $ids = array(); } $cols['xaxis'] = array('type' => 'string'); if ($x_axis) { $x_field = $frm_field->getOne($x_axis); $query = $x_query = "SELECT meta_value, item_id FROM {$frmdb->entry_metas} em"; if (!$x_field) { $x_query = "SELECT id, {$x_axis} FROM {$frmdb->entries} e"; } if ($user_id) { $query .= " LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id)"; if ($x_field) { $x_query .= " LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id)"; } } if ($x_field) { if (isset($allowed_col_types)) { $cols['xaxis'] = array('type' => in_array($x_field->type, $allowed_col_types) ? $x_field->type : 'string', 'id' => $x_field->id); } $options['hAxis'] = array('title' => stripslashes($x_field->name)); $x_query .= " WHERE em.field_id='{$x_field->id}'"; if (!empty($x_start)) { if ($x_field->type == 'date') { $x_start = date('Y-m-d', strtotime($x_start)); } $x_query .= " and meta_value >= '{$x_start}'"; } if (!empty($x_end)) { if ($x_field->type == 'date') { $x_end = date('Y-m-d', strtotime($x_end)); } $x_query .= " and meta_value <= '{$x_end}'"; } } else { $cols['xaxis'] = array('type' => 'string'); $x_query .= " WHERE form_id=" . $field->form_id; if (!empty($x_start)) { if (in_array($x_axis, array('created_at', 'updated_at'))) { $x_start = date('Y-m-d', strtotime($x_start)); } $x_query .= " and e.{$x_axis} >= '{$x_start}'"; } if (!empty($x_end)) { if (in_array($x_axis, array('created_at', 'updated_at'))) { $x_end = date('Y-m-d', strtotime($x_end)) . ' 23:59:59'; } $x_query .= " and e.{$x_axis} <= '{$x_end}'"; } } $q = array(); foreach ($fields as $f_id => $f) { if ($f_id != $field->id) { $q[$f_id] = $query . " WHERE em.field_id='{$f_id}'" . ($user_id ? " AND user_id='{$user_id}'" : ''); } unset($f); unset($f_id); } $query .= " WHERE em.field_id='{$field->id}'"; if ($user_id) { $query .= " AND user_id='{$user_id}'"; $x_query .= " AND user_id='{$user_id}'"; } $inputs = $wpdb->get_results($query, ARRAY_A); $x_inputs = $wpdb->get_results($x_query, ARRAY_A); if (!$x_inputs) { $x_inputs = array('id' => '0'); } unset($query); unset($x_query); foreach ($q as $f_id => $query) { $f_inputs[$f_id] = $wpdb->get_results($query, ARRAY_A); unset($query); } unset($q); } else { if ($user_id) { $inputs = $wpdb->get_col("SELECT meta_value FROM {$frmdb->entry_metas} em LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id) WHERE em.field_id='{$field->id}' AND user_id='{$user_id}'"); } else { $inputs = $frm_entry_meta->get_entry_metas_for_field($field->id); } foreach ($fields as $f_id => $f) { if ($f_id != $field->id) { $f_inputs[$f_id] = $wpdb->get_col("SELECT meta_value FROM {$frmdb->entry_metas} em LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id) WHERE em.field_id='{$f_id}'" . ($user_id ? " AND user_id='{$user_id}'" : '')); } unset($f_id); unset($f); } } $inputs = array_map('maybe_unserialize', $inputs); $inputs = stripslashes_deep($inputs); foreach ($f_inputs as $f_id => $f) { $f = array_map('maybe_unserialize', $f); $f_inputs[$f_id] = stripslashes_deep($f); unset($f_id); unset($f); } if (isset($allowed_col_types)) { //add columns for each field foreach ($fields as $f_id => $f) { $cols[stripslashes($f->name)] = array('type' => in_array($f->type, $allowed_col_types) ? $f->type : 'number', 'id' => $f->id); unset($f); unset($f_id); } unset($allowed_col_types); } $field_options = maybe_unserialize($field->options); $field->field_options = maybe_unserialize($field->field_options); global $frm_posts; if ($frm_posts and isset($frm_posts[$field->form_id])) { $form_posts = $frm_posts[$field->form_id]; } else { $form_posts = $frmdb->get_records($frmdb->entries, array('form_id' => $field->form_id, 'post_id >' => 1), '', '', 'id,post_id'); if (!$frm_posts) { $frm_posts = array(); } $frm_posts[$field->form_id] = $form_posts; } if (!empty($form_posts)) { if (isset($field->field_options['post_field']) and $field->field_options['post_field'] != '') { if ($field->field_options['post_field'] == 'post_category') { $field_options = FrmProFieldsHelper::get_category_options($field); } else { if ($field->field_options['post_field'] == 'post_custom' and $field->field_options['custom_field'] != '') { //check custom fields foreach ($form_posts as $form_post) { $meta_value = get_post_meta($form_post->post_id, $field->field_options['custom_field'], true); if ($meta_value) { if ($x_axis) { $inputs[] = array('meta_value' => $meta_value, 'item_id' => $form_post->id); } else { $inputs[] = $meta_value; } } } } else { //if field is post field if ($field->field_options['post_field'] == 'post_status') { $field_options = FrmProFieldsHelper::get_status_options($field); } foreach ($form_posts as $form_post) { $post_value = $wpdb->get_var("SELECT " . $field->field_options['post_field'] . " FROM {$wpdb->posts} WHERE ID=" . $form_post->post_id); if ($post_value) { if ($x_axis) { $inputs[] = array('meta_value' => $post_value, 'item_id' => $form_post->id); } else { $inputs[] = $post_value; } } } } } } } if ($field->type == 'data') { foreach ($inputs as $k => $i) { if (is_numeric($i)) { if (is_array($inputs[$k]) and isset($inputs[$k]['meta_value'])) { $inputs[$k]['meta_value'] = FrmProFieldsHelper::get_data_value($inputs[$k]['meta_value'], $field, array('truncate' => 'truncate_label')); } else { $inputs[$k] = FrmProFieldsHelper::get_data_value($inputs[$k], $field, array('truncate' => 'truncate_label')); } } unset($k); unset($i); } } if (isset($x_inputs) and $x_inputs) { $x_temp = array(); foreach ($x_inputs as $x_input) { if ($x_field) { $x_temp[$x_input['item_id']] = $x_input['meta_value']; } else { $x_temp[$x_input['id']] = $x_input[$x_axis]; } } $x_inputs = apply_filters('frm_graph_value', $x_temp, $x_field ? $x_field : $x_axis, $args); unset($x_temp); unset($x_input); } if ($x_axis and $inputs) { $y_temp = array(); foreach ($inputs as $input) { $y_temp[$input['item_id']] = $input['meta_value']; } foreach ($ids as $f_id) { if (!isset($f_values[$f_id])) { $f_values[$f_id] = array(); } $f_values[$f_id][key($y_temp)] = 0; unset($f_id); } $inputs = $y_temp; unset($y_temp); unset($input); } $inputs = apply_filters('frm_graph_value', $inputs, $field, $args); foreach ($f_inputs as $f_id => $f) { $temp = array(); foreach ($f as $input) { if (is_array($input)) { $temp[$input['item_id']] = $input['meta_value']; foreach ($ids as $d) { if (!isset($f_values[$d][$input['item_id']])) { $f_values[$d][$input['item_id']] = 0; } unset($d); } } else { $temp[] = $input; } unset($input); } $f_inputs[$f_id] = apply_filters('frm_graph_value', $temp, $fields[$f_id], $args); unset($temp); unset($input); unset($f); } if (in_array($field->type, array('select', 'checkbox', 'radio', '10radio', 'scale')) and (!isset($x_inputs) or !$x_inputs)) { if ($limit == '') { $limit = 10; } $field_opt_count = count($field_options); if ($field_options) { foreach ($field_options as $opt_key => $opt) { $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field->field_options); $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); $count = 0; if (empty($opt)) { continue; } $opt = stripslashes_deep($opt); foreach ($inputs as $in) { if (FrmAppHelper::check_selected($in, $field_val)) { if ($data_type == 'total') { $count += $field_val; } else { $count++; } } } $new_val = FrmAppHelper::truncate($opt, $truncate_label, 2); if ($count > 0 or $field_opt_count < $limit or !$count and $include_zero) { $labels[$new_val] = $new_val; $values[$new_val] = $count; } unset($count); foreach ($f_inputs as $f_id => $f) { foreach ($f as $in) { if (!isset($f_values[$f_id])) { $f_values[$f_id] = array(); } if (!isset($f_values[$f_id][$new_val])) { $f_values[$f_id][$new_val] = 0; } if (FrmAppHelper::check_selected($in, $field_val)) { if ($data_type == 'total') { $f_values[$f_id][$new_val] += $field_val; } else { $f_values[$f_id][$new_val]++; } } unset($in); } unset($f_id); unset($f); } } if ($limit != 10 and count($values) > $limit) { $ordered_vals = $values; arsort($ordered_vals); $l_count = 0; foreach ($ordered_vals as $vkey => $v) { $l_count++; if ($l_count > $limit) { unset($values[$vkey]); unset($labels[$vkey]); } unset($vkey); unset($v); } unset($l_count); unset($ordered_vals); } } if (!in_array($field->type, array('checkbox', '10radio', 'scale'))) { //and count($field_options) == 2 $pie = true; } } else { if ($field->type == 'user_id') { $form = $frmdb->get_one_record($frmdb->forms, array('id' => $field->form_id)); $form_options = maybe_unserialize($form->options); $id_count = array_count_values($inputs); if ($form->editable and (isset($form_options['single_entry']) and isset($form_options['single_entry_type']) and $form_options['single_entry_type'] == 'user')) { //if only one response per user, do a pie chart of users who have submitted the form $users_of_blog = function_exists('get_users') ? get_users() : get_users_of_blog(); $total_users = count($users_of_blog); unset($users_of_blog); $id_count = count($id_count); $not_completed = (int) $total_users - (int) $id_count; $labels = array(__('Completed', 'formidable'), __('Not Completed', 'formidable')); $values = array($id_count, $not_completed); $pie = true; } else { //arsort($id_count); foreach ($id_count as $val => $count) { $user_info = get_userdata($val); $labels[] = $user_info ? $user_info->display_name : __('Deleted User', 'formidable'); $values[] = $count; } if (count($labels) < 10) { $pie = true; } } } else { if (isset($x_inputs) and $x_inputs) { $calc_array = array(); foreach ($inputs as $entry_id => $in) { $entry_id = (int) $entry_id; if (!isset($values[$entry_id])) { $values[$entry_id] = 0; } $labels[$entry_id] = isset($x_inputs[$entry_id]) ? $x_inputs[$entry_id] : ''; if (!isset($calc_array[$entry_id])) { $calc_array[$entry_id] = array('count' => 0); } if ($data_type == 'total' or $data_type == 'average') { $values[$entry_id] += (double) $in; $calc_array[$entry_id]['total'] = $values[$entry_id]; $calc_array[$entry_id]['count']++; } else { $values[$entry_id]++; } unset($entry_id); unset($in); } if ($data_type == 'average') { foreach ($calc_array as $entry_id => $calc) { $values[$entry_id] = $calc['total'] / $calc['count']; unset($entry_id); unset($calc); } } $calc_array = array(); foreach ($f_inputs as $f_id => $f) { if (!isset($calc_array[$f_id])) { $calc_array[$f_id] = array(); } foreach ($f as $entry_id => $in) { $entry_id = (int) $entry_id; if (!isset($labels[$entry_id])) { $labels[$entry_id] = isset($x_inputs[$entry_id]) ? $x_inputs[$entry_id] : ''; $values[$entry_id] = 0; } if (!isset($calc_array[$f_id][$entry_id])) { $calc_array[$f_id][$entry_id] = array('count' => 0); } if (!isset($f_values[$f_id][$entry_id])) { $f_values[$f_id][$entry_id] = 0; } if ($data_type == 'total' or $data_type == 'average') { $f_values[$f_id][$entry_id] += (double) $in; $calc_array[$f_id][$entry_id]['total'] = $f_values[$f_id][$entry_id]; $calc_array[$f_id][$entry_id]['count']++; } else { $f_values[$f_id][$entry_id]++; } unset($entry_id); unset($in); } unset($f_id); unset($f); } if ($data_type == 'average') { foreach ($calc_array as $f_id => $calc) { foreach ($calc as $entry_id => $c) { $f_values[$f_id][$entry_id] = $c['total'] / $c['count']; unset($entry_id); unset($c); } unset($calc); unset($f_id); } } unset($calc_array); } else { if (is_array(reset($inputs))) { $id_count = array_map('implode', $inputs); $id_count = array_count_values(array_map('strtolower', $id_count)); } else { $id_count = array_count_values(array_map('strtolower', $inputs)); arsort($id_count); } $i = 0; foreach ($id_count as $val => $count) { if ($i < $response_count) { if ($field->type == 'user_id') { $user_info = get_userdata($val); $new_val = $user_info->display_name; } else { $new_val = ucwords($val); } $labels[$new_val] = $new_val; $values[$new_val] = $count; } $i++; } foreach ($f_inputs as $f_id => $f) { $id_count = array_count_values(array_map('strtolower', $f)); arsort($id_count); $i = 0; foreach ($id_count as $val => $count) { if ($i < $response_count) { if ($field->type == 'user_id') { $user_info = get_userdata($val); $new_val = $user_info->display_name; } else { $new_val = ucwords($val); } $position = array_search($new_val, $labels); if (!$position) { end($labels); $position = key($labels); $labels[$new_val] = $new_val; $values[$new_val] = 0; } $f_values[$f_id][$new_val] = $count; } $i++; } unset($f_id); unset($f); } } } } if (isset($x_inputs) and $x_inputs) { $used_vals = $calc_array = array(); foreach ($labels as $l_key => $label) { if (empty($label) and (!empty($x_start) or !empty($x_end))) { unset($values[$l_key]); unset($labels[$l_key]); continue; } if (in_array($x_axis, array('created_at', 'updated_at'))) { if ($type == 'pie') { $labels[$l_key] = $label = $inputs[$l_key]; } else { $labels[$l_key] = $label = date('Y-m-d', strtotime($label)); } } if (isset($used_vals[$label])) { $values[$l_key] += $values[$used_vals[$label]]; unset($values[$used_vals[$label]]); foreach ($ids as $f_id) { if (!isset($f_values[$f_id][$l_key])) { $f_values[$f_id][$l_key] = 0; } if (!isset($f_values[$f_id][$used_vals[$label]])) { $f_values[$f_id][$used_vals[$label]] = 0; } $f_values[$f_id][$l_key] += $f_values[$f_id][$used_vals[$label]]; unset($f_values[$f_id][$used_vals[$label]]); unset($f_id); } unset($labels[$used_vals[$label]]); } $used_vals[$label] = $l_key; if ($data_type == 'average') { if (!isset($calc_array[$label])) { $calc_array[$label] = 0; } $calc_array[$label]++; } unset($label); unset($l_key); } if (!empty($calc_array)) { foreach ($calc_array as $label => $calc) { if (isset($used_vals[$label])) { $values[$used_vals[$label]] = $values[$used_vals[$label]] / $calc; foreach ($ids as $f_id) { $f_values[$f_id][$used_vals[$label]] = $f_values[$f_id][$used_vals[$label]] / $calc; unset($f_id); } } unset($label); unset($calc); } } unset($used_vals); } $combine_dates = false; if (isset($x_field) and $x_field and $x_field->type == 'date' or in_array($x_axis, array('created_at', 'updated_at'))) { $combine_dates = apply_filters('frm_combine_dates', true, $x_field); } if ($combine_dates) { if ($include_zero) { $start_timestamp = empty($x_start) ? time() : strtotime($x_start); $end_timestamp = empty($x_end) ? time() : strtotime($x_end); $dates_array = array(); // Get the dates array for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24) { $dates_array[] = date('Y-m-d', $e); } unset($e); // Add the zero count days foreach ($dates_array as $date_str) { if (!in_array($date_str, $labels)) { $labels[$date_str] = $date_str; $values[$date_str] = 0; foreach ($ids as $f_id) { if (!isset($f_values[$f_id][$date_str])) { $f_values[$f_id][$date_str] = 0; } } } } unset($dates_array); unset($start_timestamp); unset($end_timestamp); } asort($labels); global $frmpro_settings; foreach ($labels as $l_key => $l) { if (isset($x_field) and $x_field and $x_field->type == 'date' or in_array($x_axis, array('created_at', 'updated_at'))) { if ($type != 'pie' and preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $l)) { global $frmpro_settings; $labels[$l_key] = FrmProAppHelper::convert_date($l, 'Y-m-d', $frmpro_settings->date_format); } } unset($l_key); unset($l); } $values = FrmProAppHelper::sort_by_array($values, array_keys($labels)); foreach ($ids as $f_id) { $f_values[$f_id] = FrmProAppHelper::sort_by_array($f_values[$f_id], array_keys($labels)); $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]); ksort($f_values[$f_id]); unset($f_id); } } else { if (isset($x_inputs) and $x_inputs) { foreach ($labels as $l_key => $l) { foreach ($ids as $f_id) { //do a last check to make sure all bars/lines have a value for each label if (!isset($f_values[$f_id][$l_key])) { $f_values[$f_id][$l_key] = 0; } unset($fid); } unset($l_key); unset($l); } } foreach ($ids as $f_id) { $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]); ksort($f_values[$f_id]); unset($f_id); } ksort($labels); ksort($values); } $labels = FrmProAppHelper::reset_keys($labels); $values = FrmProAppHelper::reset_keys($values); $return = array('total_count' => count($inputs), 'f_values' => $f_values, 'labels' => $labels, 'values' => $values, 'pie' => $pie, 'combine_dates' => $combine_dates, 'ids' => $ids, 'cols' => $cols, 'rows' => $rows, 'options' => $options, 'fields' => $fields); if (isset($x_inputs)) { $return['x_inputs'] = $x_inputs; } return $return; }
static function get_graph_values($field, $args) { global $frm_entry_meta, $frm_field, $frmdb, $wpdb; $values = $labels = $f_values = $f_labels = $rows = $cols = array(); $pie = false; extract($args); $user_id = (int) $user_id; $show_key = (int) $show_key; if ($show_key and $show_key < 5) { $show_key = 10; } $options = array('width' => $width, 'height' => $height, 'legend' => 'none', 'title' => '', 'titleTextStyle' => ''); if (!empty($colors)) { $options['colors'] = $colors; } if (!empty($title)) { $options['title'] = $title; } else { $options['title'] = preg_replace("/&#?[a-z0-9]{2,8};/i", "", FrmAppHelper::truncate($field->name, $truncate, 0)); } if (!empty($title_size) or !empty($title_font)) { $options['titleTextStyle'] = array('fontSize' => $title_size, 'fontName' => $title_font); } if ($show_key) { $options['legend'] = array('position' => 'right', 'textStyle' => array('fontSize' => $show_key)); } $fields = $f_inputs = array(); $fields[$field->id] = $field; if ($ids) { $ids = explode(',', $ids); foreach ($ids as $id_key => $f) { $ids[$id_key] = $f = trim($f); if (!$f or empty($f)) { unset($ids[$id_key]); continue; } if ($add_field = $frm_field->getOne($f)) { $fields[$add_field->id] = $add_field; $ids[$id_key] = $add_field->id; } unset($f); unset($id_key); } } else { $ids = array(); } $cols['xaxis'] = array('type' => 'string'); if ($atts) { //Sets up variables for get_field_matches function global $frm_post_ids; $entry_ids = array(); $after_where = ''; if (isset($frm_post_ids[$field->id])) { $form_posts = $frm_post_ids[$field->id]; } else { $where_post = array('form_id' => $field->form_id, 'post_id >' => 1, 'is_draft' => 0); if ($user_id) { $where_post['user_id'] = $user_id; } $form_posts = $frmdb->get_records($frmdb->entries, $where_post, '', '', 'id,post_id'); } //Returns the entry IDs for fields being used to filter graph data foreach ($atts as $orig_f => $val) { $entry_ids = FrmProFieldsHelper::get_field_matches(array('entry_ids' => $entry_ids, 'orig_f' => $orig_f, 'val' => $val, 'id' => $field->id, 'atts' => $atts, 'field' => $field, 'form_posts' => $form_posts, 'after_where' => $after_where, 'drafts' => false)); $after_where = true; } } //If start date is set, prepare the start date if ($start_date) { $start_date = $wpdb->prepare('%s', date('Y-m-d', strtotime($start_date))); } //If end date is set, prepare the end date if ($end_date) { $end_date = $wpdb->prepare('%s', date('Y-m-d', strtotime($end_date))); } if ($x_axis) { if (is_numeric($x_axis)) { $x_field = $frm_field->getOne($x_axis); } else { $x_field = false; } $query = $x_query = "SELECT em.meta_value, em.item_id FROM {$frmdb->entry_metas} em"; if (!$x_field) { $x_query = "SELECT id, {$x_axis} FROM {$frmdb->entries} e"; } else { $x_query .= " LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id)"; } $query .= " LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id)"; if ($x_field) { if (isset($allowed_col_types)) { $cols['xaxis'] = array('type' => in_array($x_field->type, $allowed_col_types) ? $x_field->type : 'string', 'id' => $x_field->id); } $options['hAxis'] = array('title' => $x_field->name); $x_query .= " WHERE em.field_id='{$x_field->id}'"; if (!empty($x_start)) { if ($x_field->type == 'date') { $x_start = date('Y-m-d', strtotime($x_start)); } $x_query .= " and meta_value >= '{$x_start}'"; } if (!empty($x_end)) { if ($x_field->type == 'date') { $x_end = date('Y-m-d', strtotime($x_end)); } $x_query .= " and meta_value <= '{$x_end}'"; } } else { $cols['xaxis'] = array('type' => 'string'); $x_query .= " WHERE form_id=" . $field->form_id; if (!empty($x_start)) { if (in_array($x_axis, array('created_at', 'updated_at'))) { $x_start = date('Y-m-d', strtotime($x_start)); } $x_query .= " and e.{$x_axis} >= '{$x_start}'"; } if (!empty($x_end)) { if (in_array($x_axis, array('created_at', 'updated_at'))) { $x_end = date('Y-m-d', strtotime($x_end)) . ' 23:59:59'; } $x_query .= " and e.{$x_axis} <= '{$x_end}'"; } } $q = array(); foreach ($fields as $f_id => $f) { if ($f_id != $field->id) { $q[$f_id] = $query . " WHERE em.field_id=" . (int) $f_id . ($user_id ? " AND user_id='{$user_id}'" : ''); } unset($f); unset($f_id); } $query .= " WHERE em.field_id=" . (int) $field->id; if ($user_id) { //If user_id parameter is set $query .= $wpdb->prepare(" AND user_id=%d", $user_id); $x_query .= $wpdb->prepare(" AND user_id=%d", $user_id); } if ($entry) { //If entry_id parameter is set $query .= " AND em.item_id in ({$entry})"; $x_query .= " AND e.id in ({$entry})"; } if ($start_date) { //If start_date is set $query .= " AND e.created_at >= {$start_date}"; $x_query .= " AND e.created_at >= {$start_date}"; } if ($end_date) { //If end_date is set $query .= " AND e.created_at <= {$end_date}"; $x_query .= " AND e.created_at <= {$end_date}"; } $query .= " AND is_draft=0"; $x_query .= " AND is_draft=0"; //Set up $x_query for data from entries fields. if ($x_field && $x_field->type == 'data') { $linked_field = $x_field->field_options['form_select']; $x_query = str_replace('SELECT em.meta_value, em.item_id', 'SELECT dfe.meta_value, em.item_id', $x_query); $x_query = str_replace($wpdb->prefix . 'frm_item_metas em', $wpdb->prefix . 'frm_item_metas dfe, ' . $wpdb->prefix . 'frm_item_metas em', $x_query); $x_query = str_replace('WHERE', 'WHERE dfe.item_id=em.meta_value AND dfe.field_id=' . $linked_field . ' AND', $x_query); } //If filtering by another field ID if ($atts) { //If there are matching entry IDs, add entry IDs onto query if (!empty($entry_ids)) { //if field is a post field, retrieve inputs differently if (isset($field->field_options['post_field']) and $field->field_options['post_field'] != '') { foreach ($form_posts as $form_post) { if (in_array($form_post->id, $entry_ids)) { $query = $wpdb->get_var($wpdb->prepare("SELECT " . $field->field_options['post_field'] . " FROM {$wpdb->posts} WHERE ID = %d", $form_post->post_id)); $temp_inputs[] = array('meta_value' => $query, 'item_id' => $form_post->id); } unset($form_post); } unset($form_posts); $skip_posts_code = true; } else { $query .= " AND em.item_id in (" . implode(',', $entry_ids) . ")"; } $x_query .= " AND e.id in (" . implode(',', $entry_ids) . ")"; } else { //If entry ids is blank $query = false; $x_query = false; } } if ($query) { $query = apply_filters('frm_graph_query', $query, $field, $args); } if ($x_query) { $x_query = apply_filters('frm_graph_xquery', $x_query, $field, $args); } if (isset($temp_inputs)) { $inputs = $temp_inputs; } else { if ($query) { $inputs = $wpdb->get_results($query, ARRAY_A); } else { $inputs = false; } } if ($x_query) { $x_inputs = $wpdb->get_results($x_query, ARRAY_A); } else { $x_inputs = false; } if (!$x_inputs) { return; } unset($query); unset($x_query); unset($temp_inputs); //If there are multiple fields being graphed foreach ($q as $f_id => $query) { if (!empty($entry_ids)) { //If a filter is set, only get filtered data from additional fields $query .= " AND item_id in (" . implode(',', $entry_ids) . ")"; } else { if ($entry) { //If entry_id parameter is set, only get data for this entry $query .= " AND item_id in ({$entry})"; } } if ($start_date) { $query .= " AND e.created_at >= {$start_date}"; } if ($end_date) { $query .= " AND e.created_at <= {$end_date}"; } $f_inputs[$f_id] = $wpdb->get_results($query, ARRAY_A); unset($query); } unset($q); //If filtering by another field ID } else { if ($atts) { //If there are matching entry IDs, declare inputs if (!empty($entry_ids)) { //If field is a post field, retrieve inputs in a different way - TODO: change database call for post fields so filters like entry ID, start_date, user ID, etc. are included if (isset($field->field_options['post_field']) and $field->field_options['post_field'] != '') { foreach ($form_posts as $form_post) { if (in_array($form_post->id, $entry_ids)) { $post_ids[$form_post->id] = $form_post->post_id; } unset($form_post); } unset($form_posts); if (!empty($post_ids)) { $inputs = $wpdb->get_col("SELECT {$field->field_options['post_field']} FROM {$wpdb->posts} WHERE ID in (" . implode(',', $post_ids) . ")"); } $skip_posts_code = true; } else { $inputs = $wpdb->get_col("SELECT meta_value FROM {$frmdb->entry_metas} em LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id) WHERE is_draft=0 AND em.field_id='" . (int) $field->id . "' AND item_id in (" . implode(',', $entry_ids) . ")" . ($user_id ? " AND user_id=" . (int) $user_id : '') . ($start_date ? " AND e.created_at >= {$start_date}" : '') . ($end_date ? " AND e.created_at <= {$end_date}" : '')); } //If there are multiple fields being graphed foreach ($fields as $f_id => $f) { if ($f_id != $field->id) { $f_inputs[$f_id] = $wpdb->get_col("SELECT meta_value FROM {$frmdb->entry_metas} em LEFT JOIN {$frmdb->entries} e ON (e.id=em.item_id) WHERE is_draft=0 AND em.field_id='{$f_id}' AND item_id in (" . implode(',', $entry_ids) . ")" . ($user_id ? " AND user_id=" . (int) $user_id : '') . ($start_date ? " AND e.created_at >= {$start_date}" : '') . ($end_date ? " AND e.created_at <= {$end_date}" : '')); } unset($f_id); unset($f); } } } else { if ($user_id) { //If UserID is the only filtering parameter defined $inputs = $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas em INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) WHERE is_draft=%d AND em.field_id=%d AND user_id=%d" . ($start_date ? " AND e.created_at >= {$start_date}" : '') . ($end_date ? " AND e.created_at <= {$end_date}" : ''), 0, $field->id, $user_id)); } else { if ($entry) { //If entry ID is the only filtering parameter defined $inputs = $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas em INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) WHERE is_draft=%d AND em.field_id=%d AND em.item_id in ({$entry})", 0, $field->id)); } else { //If no user ID, atts, or x_axis defined $inputs = $wpdb->get_col($wpdb->prepare("SELECT em.meta_value FROM {$wpdb->prefix}frm_item_metas em INNER JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) WHERE em.field_id=%d AND e.is_draft=%d" . ($start_date ? " AND e.created_at >= {$start_date}" : '') . ($end_date ? " AND e.created_at <= {$end_date}" : ''), $field->id, 0)); } } foreach ($fields as $f_id => $f) { //Get the meta_values for additional fields being graphed if ($f_id != $field->id) { $f_where = array(0, $f_id); if ($user_id) { $f_where[] = $user_id; } $f_inputs[$f_id] = $wpdb->get_col($wpdb->prepare("SELECT meta_value FROM {$wpdb->prefix}frm_item_metas em LEFT JOIN {$wpdb->prefix}frm_items e ON (e.id=em.item_id) WHERE is_draft=%d AND em.field_id=%d" . ($user_id ? " AND user_id=%d" : '') . ($entry ? " AND item_id in ({$entry})" : ''), $f_where)); unset($f_where); } unset($f_id); unset($f); } } } if (isset($inputs) && !empty($inputs)) { //Break out any inner arrays (for checkbox or multi-select fields) and add them to the end of the $inputs array if (!$x_axis && ($field->type == 'data' && ($field->field_options['data_type'] == 'checkbox' || $field->field_options['data_type'] == 'select' && $field->field_options['multiple'] == 1) || $field->type == 'checkbox' || $field->type == 'select' && $field->field_options['multiple'] == 1)) { foreach ($inputs as $k => $i) { $i = maybe_unserialize($i); if (!is_array($i)) { unset($k, $i); continue; } unset($inputs[$k]); foreach ($i as $item) { $inputs[] = $item; unset($item); } unset($k, $i); } $inputs = array_values($inputs); } //Strip slashes from inputs $inputs = stripslashes_deep($inputs); } if (isset($form_posts)) { unset($form_posts); } foreach ($f_inputs as $f_id => $f) { $f = array_map('maybe_unserialize', $f); $f_inputs[$f_id] = stripslashes_deep($f); unset($f_id); unset($f); } if (isset($allowed_col_types)) { //add columns for each field $count = 0; foreach ($fields as $f_id => $f) { if (isset($tooltip_label[$count]) && !empty($tooltip_label[$count])) { //If tooltip label is set, change the tooltip label $cols[$tooltip_label[$count]] = array('type' => in_array($f->type, $allowed_col_types) ? $f->type : 'number', 'id' => $f->id); $count++; } else { //if tooltip label is not set, use the field name $cols[$f->name] = array('type' => in_array($f->type, $allowed_col_types) ? $f->type : 'number', 'id' => $f->id); } unset($f); unset($f_id); } unset($allowed_col_types); unset($count); } //Declare $field_options variable. $field_options = $field->options; //Declare $form_posts. This will return empty if the form does not create posts. $query = "SELECT id, post_id FROM {$wpdb->prefix}frm_items WHERE form_id = %d AND post_id >= %d" . ($user_id ? " AND user_id=%d" : '') . ($entry ? " AND id in ({$entry})" : ''); $temp_values = array_filter(array($field->form_id, 1, $user_id)); $form_posts = $wpdb->get_results($wpdb->prepare($query, $temp_values)); unset($query); unset($temp_values); //If form creates posts and graph field is a post field or custom field if (!empty($form_posts)) { if (isset($field->field_options['post_field']) and $field->field_options['post_field'] != '') { if ($field->field_options['post_field'] == 'post_category') { $field_options = FrmProFieldsHelper::get_category_options($field); } else { if ($field->field_options['post_field'] == 'post_custom' and $field->field_options['custom_field'] != '') { //check custom fields foreach ($form_posts as $form_post) { $meta_value = get_post_meta($form_post->post_id, $field->field_options['custom_field'], true); if ($meta_value) { if ($x_axis) { $inputs[] = array('meta_value' => $meta_value, 'item_id' => $form_post->id); } else { $inputs[] = $meta_value; } } } } else { //if field is post field if ($field->field_options['post_field'] == 'post_status') { $field_options = FrmProFieldsHelper::get_status_options($field); } if (!isset($skip_posts_code)) { foreach ($form_posts as $form_post) { $post_value = $wpdb->get_var("SELECT " . $field->field_options['post_field'] . " FROM {$wpdb->posts} WHERE ID=" . $form_post->post_id); if ($post_value) { if ($x_axis) { $inputs[] = array('meta_value' => $post_value, 'item_id' => $form_post->id); } else { $inputs[] = $post_value; } } } } } } } } if ($field->type == 'data') { foreach ($inputs as $k => $i) { if (is_numeric($i)) { if (is_array($inputs[$k]) and isset($inputs[$k]['meta_value'])) { $inputs[$k]['meta_value'] = FrmProFieldsHelper::get_data_value($inputs[$k]['meta_value'], $field, array('truncate' => 'truncate_label')); } else { $inputs[$k] = FrmProFieldsHelper::get_data_value($inputs[$k], $field, array('truncate' => 'truncate_label')); } } unset($k); unset($i); } } if (isset($x_inputs) and $x_inputs) { $x_temp = array(); foreach ($x_inputs as $x_input) { if (!$x_input) { continue; } if ($x_field) { $x_temp[$x_input['item_id']] = $x_input['meta_value']; } else { $x_temp[$x_input['id']] = $x_input[$x_axis]; } } $x_inputs = apply_filters('frm_graph_value', $x_temp, $x_field ? $x_field : $x_axis, $args); unset($x_temp); unset($x_input); } if ($x_axis and $inputs) { $y_temp = array(); foreach ($inputs as $input) { $y_temp[$input['item_id']] = $input['meta_value']; } foreach ($ids as $f_id) { if (!isset($f_values[$f_id])) { $f_values[$f_id] = array(); } $f_values[$f_id][key($y_temp)] = 0; unset($f_id); } $inputs = $y_temp; unset($y_temp); unset($input); } //there is no data, so don't graph if (!isset($inputs) || empty($inputs)) { //TODO: consolidate? return array(); } $inputs = apply_filters('frm_graph_value', $inputs, $field, $args); foreach ($f_inputs as $f_id => $f) { $temp = array(); foreach ($f as $input) { if (is_array($input)) { $temp[$input['item_id']] = $input['meta_value']; foreach ($ids as $d) { if (!isset($f_values[$d][$input['item_id']])) { $f_values[$d][$input['item_id']] = 0; } unset($d); } } else { $temp[] = $input; } unset($input); } $f_inputs[$f_id] = apply_filters('frm_graph_value', $temp, $fields[$f_id], $args); unset($temp); unset($input); unset($f); } $tooltips = array(); if (in_array($field->type, array('select', 'checkbox', 'radio', 'scale')) and (!isset($x_inputs) or !$x_inputs)) { if ($limit == '') { $limit = 10; } if (!in_array($field->type, array('checkbox', 'scale'))) { //and count($field_options) == 2 $pie = true; } //Set default type to pie if field is radio or select $field_opt_count = count($field_options); if ($field_options) { foreach ($field_options as $opt_key => $opt) { $field_val = apply_filters('frm_field_value_saved', $opt, $opt_key, $field->field_options); $opt = apply_filters('frm_field_label_seen', $opt, $opt_key, $field); $count = 0; if (empty($opt)) { continue; } foreach ($inputs as $in) { if (FrmAppHelper::check_selected($in, $field_val)) { if ($data_type == 'total') { $count += $field_val; } else { $count++; } } } $new_val = FrmAppHelper::truncate($opt, $pie && ($type == 'default' || $type == 'pie') ? 50 : $truncate_label, 2); //Prevent label truncation if type is pie if ($count > 0 or $field_opt_count < $limit or !$count and $include_zero) { $labels[$opt] = $new_val; $values[$opt] = $count; $tooltips[$opt] = $opt; } unset($count); foreach ($f_inputs as $f_id => $f) { foreach ($f as $in) { if (!isset($f_values[$f_id])) { $f_values[$f_id] = array(); } if (!isset($f_values[$f_id][$new_val])) { $f_values[$f_id][$new_val] = 0; } if (FrmAppHelper::check_selected($in, $field_val)) { if ($data_type == 'total') { $f_values[$f_id][$new_val] += $field_val; } else { $f_values[$f_id][$new_val]++; } } unset($in); } unset($f_id); unset($f); } } if ($limit != 10 and count($values) > $limit) { $ordered_vals = $values; arsort($ordered_vals); $l_count = 0; foreach ($ordered_vals as $vkey => $v) { $l_count++; if ($l_count > $limit) { unset($values[$vkey]); unset($labels[$vkey]); if (isset($tooltips[$vkey])) { unset($tooltips[$vkey]); } } unset($vkey); unset($v); } unset($l_count); unset($ordered_vals); } } } else { if ($field->type == 'user_id') { $form = $frmdb->get_one_record($wpdb->prefix . 'frm_forms', array('id' => $field->form_id)); $form_options = maybe_unserialize($form->options); $id_count = array_count_values($inputs); if ($form->editable and (isset($form_options['single_entry']) and $form_options['single_entry'] and isset($form_options['single_entry_type']) and $form_options['single_entry_type'] == 'user')) { //if only one response per user, do a pie chart of users who have submitted the form $users_of_blog = get_users(); $total_users = count($users_of_blog); unset($users_of_blog); $id_count = count($id_count); $not_completed = (int) $total_users - (int) $id_count; $labels = array(__('Completed', 'formidable'), __('Not Completed', 'formidable')); $values = array($id_count, $not_completed); $pie = true; } else { //arsort($id_count); foreach ($id_count as $val => $count) { $user_info = get_userdata($val); $labels[] = $user_info ? $user_info->display_name : __('Deleted User', 'formidable'); $values[] = $count; } if (count($labels) < 10) { $pie = true; } } } else { if (isset($x_inputs) and $x_inputs) { $calc_array = array(); foreach ($inputs as $entry_id => $in) { $entry_id = (int) $entry_id; if (!isset($values[$entry_id])) { $values[$entry_id] = 0; } $labels[$entry_id] = isset($x_inputs[$entry_id]) ? $x_inputs[$entry_id] : ''; if (!isset($calc_array[$entry_id])) { $calc_array[$entry_id] = array('count' => 0); } if ($data_type == 'total' or $data_type == 'average') { $values[$entry_id] += (double) $in; $calc_array[$entry_id]['total'] = $values[$entry_id]; $calc_array[$entry_id]['count']++; } else { $values[$entry_id]++; } unset($entry_id); unset($in); } if ($data_type == 'average') { foreach ($calc_array as $entry_id => $calc) { $values[$entry_id] = $calc['total'] / $calc['count']; unset($entry_id); unset($calc); } } $calc_array = array(); foreach ($f_inputs as $f_id => $f) { if (!isset($calc_array[$f_id])) { $calc_array[$f_id] = array(); } foreach ($f as $entry_id => $in) { $entry_id = (int) $entry_id; if (!isset($labels[$entry_id])) { $labels[$entry_id] = isset($x_inputs[$entry_id]) ? $x_inputs[$entry_id] : ''; $values[$entry_id] = 0; } if (!isset($calc_array[$f_id][$entry_id])) { $calc_array[$f_id][$entry_id] = array('count' => 0); } if (!isset($f_values[$f_id][$entry_id])) { $f_values[$f_id][$entry_id] = 0; } if ($data_type == 'total' or $data_type == 'average') { $f_values[$f_id][$entry_id] += (double) $in; $calc_array[$f_id][$entry_id]['total'] = $f_values[$f_id][$entry_id]; $calc_array[$f_id][$entry_id]['count']++; } else { $f_values[$f_id][$entry_id]++; } unset($entry_id); unset($in); } unset($f_id); unset($f); } if ($data_type == 'average') { foreach ($calc_array as $f_id => $calc) { foreach ($calc as $entry_id => $c) { $f_values[$f_id][$entry_id] = $c['total'] / $c['count']; unset($entry_id); unset($c); } unset($calc); unset($f_id); } } unset($calc_array); } else { $id_count = array_count_values(array_map('strtolower', $inputs)); arsort($id_count); $i = 0; foreach ($id_count as $val => $count) { if ($i < $response_count) { if ($field->type == 'user_id') { $user_info = get_userdata($val); $new_val = $user_info->display_name; } else { $new_val = ucwords($val); } $labels[$new_val] = $new_val; $values[$new_val] = $count; } $i++; } foreach ($f_inputs as $f_id => $f) { $id_count = array_count_values(array_map('strtolower', $f)); arsort($id_count); $i = 0; foreach ($id_count as $val => $count) { if ($i < $response_count) { if ($field->type == 'user_id') { $user_info = get_userdata($val); $new_val = $user_info->display_name; } else { $new_val = ucwords($val); } $position = array_search($new_val, $labels); if (!$position) { end($labels); $position = key($labels); $labels[$new_val] = $new_val; $values[$new_val] = 0; } $f_values[$f_id][$new_val] = $count; } $i++; } unset($f_id); unset($f); } } } } if (isset($x_inputs) and $x_inputs) { $used_vals = $calc_array = array(); foreach ($labels as $l_key => $label) { if (empty($label) and (!empty($x_start) or !empty($x_end))) { unset($values[$l_key]); unset($labels[$l_key]); if (isset($tooltips[$l_key])) { unset($tooltips[$l_key]); } continue; } if (in_array($x_axis, array('created_at', 'updated_at'))) { if ($type == 'pie') { $labels[$l_key] = $label = $inputs[$l_key]; } else { $labels[$l_key] = $label = date('Y-m-d', strtotime($label)); } } if (isset($used_vals[$label])) { $values[$l_key] += $values[$used_vals[$label]]; unset($values[$used_vals[$label]]); foreach ($ids as $f_id) { if (!isset($f_values[$f_id][$l_key])) { $f_values[$f_id][$l_key] = 0; } if (!isset($f_values[$f_id][$used_vals[$label]])) { $f_values[$f_id][$used_vals[$label]] = 0; } $f_values[$f_id][$l_key] += $f_values[$f_id][$used_vals[$label]]; unset($f_values[$f_id][$used_vals[$label]]); unset($f_id); } unset($labels[$used_vals[$label]]); } $used_vals[$label] = $l_key; if ($data_type == 'average') { if (!isset($calc_array[$label])) { $calc_array[$label] = 0; } $calc_array[$label]++; } unset($label); unset($l_key); } if (!empty($calc_array)) { foreach ($calc_array as $label => $calc) { if (isset($used_vals[$label])) { $values[$used_vals[$label]] = $values[$used_vals[$label]] / $calc; foreach ($ids as $f_id) { $f_values[$f_id][$used_vals[$label]] = $f_values[$f_id][$used_vals[$label]] / $calc; unset($f_id); } } unset($label); unset($calc); } } unset($used_vals); } $combine_dates = false; if (isset($x_field) and $x_field and $x_field->type == 'date' or in_array($x_axis, array('created_at', 'updated_at'))) { $combine_dates = apply_filters('frm_combine_dates', true, $x_field); } if ($combine_dates) { if ($include_zero) { $start_timestamp = empty($x_start) ? time() : strtotime($x_start); $end_timestamp = empty($x_end) ? time() : strtotime($x_end); $dates_array = array(); // Get the dates array for ($e = $start_timestamp; $e <= $end_timestamp; $e += 60 * 60 * 24) { $dates_array[] = date('Y-m-d', $e); } unset($e); // Add the zero count days foreach ($dates_array as $date_str) { if (!in_array($date_str, $labels)) { $labels[$date_str] = $date_str; $values[$date_str] = 0; foreach ($ids as $f_id) { if (!isset($f_values[$f_id][$date_str])) { $f_values[$f_id][$date_str] = 0; } } } } unset($dates_array); unset($start_timestamp); unset($end_timestamp); } asort($labels); global $frmpro_settings; foreach ($labels as $l_key => $l) { if (isset($x_field) and $x_field and $x_field->type == 'date' or in_array($x_axis, array('created_at', 'updated_at'))) { if ($type != 'pie' and preg_match('/^\\d{4}-\\d{2}-\\d{2}$/', $l)) { global $frmpro_settings; $labels[$l_key] = FrmProAppHelper::convert_date($l, 'Y-m-d', $frmpro_settings->date_format); } } unset($l_key); unset($l); } $values = FrmProAppHelper::sort_by_array($values, array_keys($labels)); $tooltips = FrmProAppHelper::sort_by_array($tooltips, array_keys($labels)); foreach ($ids as $f_id) { $f_values[$f_id] = FrmProAppHelper::sort_by_array($f_values[$f_id], array_keys($labels)); $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]); ksort($f_values[$f_id]); unset($f_id); } } else { if (isset($x_inputs) and $x_inputs) { foreach ($labels as $l_key => $l) { foreach ($ids as $f_id) { //do a last check to make sure all bars/lines have a value for each label if (!isset($f_values[$f_id][$l_key])) { $f_values[$f_id][$l_key] = 0; } unset($fid); } unset($l_key); unset($l); } } foreach ($ids as $f_id) { $f_values[$f_id] = FrmProAppHelper::reset_keys($f_values[$f_id]); ksort($f_values[$f_id]); unset($f_id); } if ($x_order == '1') { ksort($labels); ksort($values); ksort($tooltips); } } $labels = FrmProAppHelper::reset_keys($labels); $values = FrmProAppHelper::reset_keys($values); $tooltips = FrmProAppHelper::reset_keys($tooltips); //Graph by month or quarter if (isset($group_by) && in_array($group_by, array('month', 'quarter'))) { foreach ($labels as $key => $label) { if ($group_by == 'month') { $labels[$key] = date('F Y', strtotime($label)); } else { if ($group_by == 'quarter') { $label = date('Y-m-d', strtotime($label)); //Convert date to Y-m-d format if (preg_match('/-(01|02|03)-/', $label)) { $labels[$key] = 'Q1 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(04|05|06)-/', $label)) { $labels[$key] = 'Q2 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(07|08|09)-/', $label)) { $labels[$key] = 'Q3 ' . date('Y', strtotime($label)); } else { if (preg_match('/-(10|11|12)-/', $label)) { $labels[$key] = 'Q4 ' . date('Y', strtotime($label)); } } } } } } } $count = count($labels) - 1; for ($i = 0; $i < $count; $i++) { if ($labels[$i] == $labels[$i + 1]) { unset($labels[$i]); $values[$i + 1] = $values[$i] + $values[$i + 1]; unset($values[$i]); } } $labels = FrmProAppHelper::reset_keys($labels); $values = FrmProAppHelper::reset_keys($values); } $labels = apply_filters('frm_graph_labels', $labels, $args, $field); $values = apply_filters('frm_final_graph_values', $values, $args, $field); $return = array('total_count' => count($inputs), 'f_values' => $f_values, 'labels' => $labels, 'values' => $values, 'pie' => $pie, 'combine_dates' => $combine_dates, 'ids' => $ids, 'cols' => $cols, 'rows' => $rows, 'options' => $options, 'fields' => $fields, 'tooltips' => $tooltips); if (isset($x_inputs)) { $return['x_inputs'] = $x_inputs; } return $return; }
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; }