public static function get_post_or_meta_value($entry, $field, $atts = array()) { global $frm_entry_meta; if (!is_object($entry)) { global $frm_entry; $entry = $frm_entry->getOne($entry); } if (empty($entry) or empty($field)) { return ''; } if ($entry->post_id) { if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } if (!isset($field->field_options['post_field'])) { $field->field_options['post_field'] = ''; } $links = true; if (isset($atts['links'])) { $links = $atts['links']; } if ($field->type == 'tag' or $field->field_options['post_field']) { $post_args = array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field, 'links' => $links, 'exclude_cat' => $field->field_options['exclude_cat']); foreach (array('show', 'truncate', 'sep') as $p) { if (isset($atts[$p])) { $post_args[$p] = $atts[$p]; } } $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], $post_args); unset($post_args); } else { $value = $frm_entry_meta->get_entry_meta_by_field($entry->id, $field->id); } } else { $value = $frm_entry_meta->get_entry_meta_by_field($entry->id, $field->id); if (($field->type == 'tag' or isset($field->field_options['post_field']) and $field->field_options['post_field'] == 'post_category') and !empty($value)) { $value = maybe_unserialize($value); $new_value = array(); foreach ((array) $value as $tax_id) { if (is_numeric($tax_id)) { $cat = $term = get_term($tax_id, $field->field_options['taxonomy']); $new_value[] = $cat ? $cat->name : $tax_id; unset($cat); } else { $new_value[] = $tax_id; } } $value = $new_value; } } return $value; }
function entry_link_shortcode($atts) { global $user_ID, $frm_entry, $frm_entry_meta, $post; extract(shortcode_atts(array('id' => false, 'field_key' => 'created_at', 'type' => 'list', 'logged_in' => true, 'edit' => true, 'class' => '', 'link_type' => 'page', 'blank_label' => '', 'param_name' => 'entry', 'param_value' => 'key', 'page_id' => false, 'show_delete' => false), $atts)); if (!$id or $logged_in && !$user_ID) { return; } $id = (int) $id; if ($show_delete === 1) { $show_delete = __('Delete', 'formidable'); } $s = FrmAppHelper::get_param('frm_search', false); if ($s) { $entry_ids = FrmProEntriesHelper::get_search_ids($s, $id); } else { $entry_ids = $frm_entry_meta->getEntryIds("fi.form_id='{$id}'"); } if ($entry_ids) { $id_list = implode(',', $entry_ids); $order = $type == 'collapse' ? ' ORDER BY it.created_at DESC' : ''; $where = "it.id in ({$id_list})"; if ($logged_in) { $where .= " and it.form_id='" . $id . "' and it.user_id='" . (int) $user_ID . "'"; } $entries = $frm_entry->getAll($where, $order, '', true); } if (!empty($entries)) { if ($type == 'list') { $content = "<ul class='frm_entry_ul {$class}'>\n"; } else { if ($type == 'collapse') { $content = '<div class="frm_collapse">'; $year = $month = ''; $prev_year = $prev_month = false; } else { $content = "<select id='frm_select_form_{$id}' name='frm_select_form_{$id}' class='{$class}' onchange='location=this.options[this.selectedIndex].value;'>\n <option value='" . get_permalink($post->ID) . "'>{$blank_label}</option>\n"; } } global $frm_field; if ($field_key != 'created_at') { $field = $frm_field->getOne($field_key); } foreach ($entries as $entry) { $action = (isset($_GET) and isset($_GET['frm_action'])) ? 'frm_action' : 'action'; if (isset($_GET) and isset($_GET[$action]) and $_GET[$action] == 'destroy') { if (isset($_GET['entry']) and ($_GET['entry'] == $entry->item_key or $_GET['entry'] == $entry->id)) { continue; } } if ($entry->post_id) { global $wpdb; $post_status = $wpdb->get_var("SELECT post_status FROM {$wpdb->posts} WHERE ID=" . $entry->post_id); if ($post_status != 'publish') { continue; } } $value = ''; $meta = false; if ($field_key && $field_key != 'created_at') { if ($entry->post_id and ($field and $field->field_options['post_field'] or $field->type == 'tag')) { $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field)); } else { $meta = isset($entry->metas[$field_key]) ? $entry->metas[$field_key] : ''; } } else { $meta = reset($entry->metas); } $value = ($field_key == 'created_at' or !isset($meta) or !$meta) ? $value : (is_object($meta) ? $meta->meta_value : $meta); if (empty($value)) { $value = date_i18n(get_option('date_format'), strtotime($entry->created_at)); } else { $value = FrmProEntryMetaHelper::display_value($value, $field, array('type' => $field->type, 'show_filename' => false)); } if ($param_value == 'key') { $args = array($param_name => $entry->item_key); } else { $args = array($param_name => $entry->id); } if ($edit) { $args['frm_action'] = 'edit'; } if ($link_type == 'scroll') { $link = '#' . $entry->item_key; } else { if ($link_type == 'admin') { $link = add_query_arg($args, $_SERVER['REQUEST_URI']); } else { if ($page_id) { $permalink = get_permalink($page_id); } else { $permalink = get_permalink($post->ID); } $link = add_query_arg($args, $permalink); } } unset($args); $current = isset($_GET['entry']) && $_GET['entry'] == $entry->item_key ? true : false; if ($type == 'list') { $content .= "<li><a href='{$link}'>" . stripslashes($value) . "</a>"; if ($show_delete and isset($permalink) and FrmProEntriesHelper::allow_delete($entry)) { $content .= " <a href='" . add_query_arg(array('frm_action' => 'destroy', 'entry' => $entry->id), $permalink) . "' class='frm_delete_list'>{$show_delete}</a>\n"; } $content .= "</li>\n"; } else { if ($type == 'collapse') { $new_year = strftime('%G', strtotime($entry->created_at)); $new_month = strftime('%B', strtotime($entry->created_at)); if ($new_year != $year) { if ($prev_year) { if ($prev_month) { $content .= '</ul></div>'; } $content .= '</div>'; $prev_month = false; } $style = $prev_year ? " style='display:none'" : ''; $triangle = $prev_year ? "e" : "s"; $content .= "\n<div class='frm_year_heading frm_year_heading_{$id}'>\n <span class='ui-icon ui-icon-triangle-1-{$triangle}'></span>\n\n <a>{$new_year}</a></div>\n\n <div class='frm_toggle_container' {$style}>\n"; $prev_year = true; } if ($new_month != $month) { if ($prev_month) { $content .= '</ul></div>'; } $style = $prev_month ? " style='display:none'" : ''; $triangle = $prev_month ? "e" : "s"; $content .= "<div class='frm_month_heading frm_month_heading_{$id}'>\n <span class='ui-icon ui-icon-triangle-1-{$triangle}'></span>\n\n <a>{$new_month}</a>\n</div>\n\n <div class='frm_toggle_container frm_month_listing' {$style}><ul>\n"; $prev_month = true; } $content .= "<li><a href='{$link}'>" . stripslashes($value) . "</a></li>"; $year = $new_year; $month = $new_month; } else { $selected = $current ? ' selected="selected"' : ''; $content .= "<option value='{$link}'{$selected}>" . stripslashes($value) . "</option>\n"; } } } if ($type == 'list') { $content .= "</ul>\n"; } else { if ($type == 'collapse') { if ($prev_year) { $content .= '</div>'; } if ($prev_month) { $content .= '</ul></div>'; } $content .= '</div>'; $content .= "<script type='text/javascript'>jQuery(document).ready(function(\$){ \$('.frm_month_heading_" . $id . ", .frm_year_heading_" . $id . "').toggle(function(){ \$(this).children('.ui-icon-triangle-1-e').addClass('ui-icon-triangle-1-s'); \$(this).children('.ui-icon-triangle-1-s').removeClass('ui-icon-triangle-1-e'); \$(this).next('.frm_toggle_container').fadeIn('slow');},function(){ \$(this).children('.ui-icon-triangle-1-s').addClass('ui-icon-triangle-1-e'); \$(this).children('.ui-icon-triangle-1-e').removeClass('ui-icon-triangle-1-s'); \$(this).next('.frm_toggle_container').hide();});})</script>\n"; } else { $content .= "</select>\n"; if ($show_delete and isset($_GET) and isset($_GET['entry']) and $_GET['entry']) { $content .= " <a href='" . add_query_arg(array('frm_action' => 'destroy', 'entry' => $_GET['entry']), $permalink) . "' class='frm_delete_list'>{$show_delete}</a>\n"; } } } } else { $content = ''; } return $content; }
function get_post_or_meta_value($entry, $field, $atts = array()) { global $frm_entry_meta; if (!is_object($entry)) { global $frm_entry; $entry = $frm_entry->getOne($entry); } $field->field_options = maybe_unserialize($field->field_options); if ($entry->post_id) { if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } if (!isset($field->field_options['post_field'])) { $field->field_options['post_field'] = ''; } $links = true; if (isset($atts['links'])) { $links = $atts['links']; } if ($field->type == 'tag' or $field->field_options['post_field']) { $post_args = array('type' => $field->type, 'form_id' => $field->form_id, 'field' => $field, 'links' => $links, 'exclude_cat' => $field->field_options['exclude_cat']); if (isset($atts['show'])) { $post_args['show'] = $atts['show']; } $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], $post_args); unset($post_args); } else { $value = $frm_entry_meta->get_entry_meta_by_field($entry->id, $field->id); } } else { $value = $frm_entry_meta->get_entry_meta_by_field($entry->id, $field->id); } return $value; }
function setup_edit_vars($record, $table, $fields = '', $default = false) { if (!$record) { return false; } global $frm_entry_meta, $frm_form, $frm_settings, $frm_sidebar_width; $values = array(); $values['id'] = $record->id; foreach (array('name' => $record->name, 'description' => $record->description) as $var => $default_val) { $values[$var] = stripslashes(FrmAppHelper::get_param($var, $default_val)); } if (apply_filters('frm_use_wpautop', true)) { $values['description'] = wpautop($values['description']); } $values['fields'] = array(); if ($fields) { foreach ($fields as $field) { $field->field_options = stripslashes_deep(maybe_unserialize($field->field_options)); if ($default) { $meta_value = $field->default_value; } else { if ($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']) { $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field)); } else { if (isset($record->metas)) { $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false; } else { $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id); } } } $field_type = isset($_POST['field_options']['type_' . $field->id]) ? $_POST['field_options']['type_' . $field->id] : $field->type; $new_value = isset($_POST['item_meta'][$field->id]) ? $_POST['item_meta'][$field->id] : $meta_value; $new_value = maybe_unserialize($new_value); if (is_array($new_value)) { $new_value = stripslashes_deep($new_value); } $field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => stripslashes_deep(maybe_unserialize($field->default_value)), 'name' => stripslashes($field->name), 'description' => stripslashes($field->description), 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), 'options' => stripslashes_deep(maybe_unserialize($field->options)), 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id); /*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){ foreach((array)$field_array['options'] as $opt_key => $opt){ if(!is_array($opt)) $field_array['options'][$opt_key] = array('label' => $opt); unset($opt); unset($opt_key); } }*/ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); foreach ($opt_defaults as $opt => $default_opt) { $field_array[$opt] = ($_POST and isset($_POST['field_options'][$opt . '_' . $field->id])) ? $_POST['field_options'][$opt . '_' . $field->id] : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt); if ($opt == 'blank' and $field_array[$opt] == '') { $field_array[$opt] = __('This field cannot be blank', 'formidable'); } else { if ($opt == 'invalid' and $field_array[$opt] == '') { if ($field_type == 'captcha') { $field_array[$opt] = $frm_settings->re_msg; } else { $field_array[$opt] = $field_array['name'] . ' ' . __('is invalid', 'formidable'); } } } } unset($opt_defaults); if ($field_array['custom_html'] == '') { $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type); } if ($field_array['size'] == '') { $field_array['size'] = $frm_sidebar_width; } $values['fields'][] = apply_filters('frm_setup_edit_fields_vars', stripslashes_deep($field_array), $field, $values['id']); unset($field); } } if ($table == 'entries') { $form = $frm_form->getOne($record->form_id); } else { if ($table == 'forms') { $form = $frm_form->getOne($record->id); } } if ($form) { $form->options = maybe_unserialize($form->options); $values['form_name'] = isset($record->form_id) ? $form->name : ''; if (is_array($form->options)) { foreach ($form->options as $opt => $value) { $values[$opt] = FrmAppHelper::get_param($opt, $value); } } } $form_defaults = FrmFormsHelper::get_default_opts(); $form_defaults['email_to'] = ''; //options to allow blank answers foreach (array('email_to', 'reply_to', 'reply_to_name') as $opt) { if (!isset($values[$opt])) { $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $form_defaults[$opt]; unset($form_defaults[$opt]); unset($opt); } } //don't allow blank answers foreach ($form_defaults as $opt => $default) { if (!isset($values[$opt]) or $values[$opt] == '') { $values[$opt] = ($_POST and isset($_POST['options'][$opt])) ? $_POST['options'][$opt] : $default; } unset($opt); unset($defaut); } if (!isset($values['custom_style'])) { $values['custom_style'] = ($_POST and isset($_POST['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->load_style != 'none'; } if (!isset($values['before_html'])) { $values['before_html'] = isset($_POST['options']['before_html']) ? $_POST['options']['before_html'] : FrmFormsHelper::get_default_html('before'); } if (!isset($values['after_html'])) { $values['after_html'] = isset($_POST['options']['after_html']) ? $_POST['options']['after_html'] : FrmFormsHelper::get_default_html('after'); } if ($table == 'entries') { $values = FrmEntriesHelper::setup_edit_vars($values, $record); } else { if ($table == 'forms') { $values = FrmFormsHelper::setup_edit_vars($values, $record); } } return $values; }
private static function calendar_daily_entries($entry, $display, $args, array &$daily_entries) { $i18n = false; if (is_numeric($display->frm_date_field_id)) { $date = FrmEntryMeta::get_meta_value($entry, $display->frm_date_field_id); if ($entry->post_id && !$date && $args['field'] && isset($args['field']->field_options['post_field']) && $args['field']->field_options['post_field']) { $date = FrmProEntryMetaHelper::get_post_value($entry->post_id, $args['field']->field_options['post_field'], $args['field']->field_options['custom_field'], array('form_id' => $display->frm_form_id, 'type' => $args['field']->type, 'field' => $args['field'])); } } else { $date = $display->frm_date_field_id == 'updated_at' ? $entry->updated_at : $entry->created_at; $i18n = true; } if (empty($date)) { return; } if ($i18n) { $date = FrmAppHelper::get_localized_date('Y-m-d', $date); } else { $date = date('Y-m-d', strtotime($date)); } unset($i18n); $dates = array($date); if (!empty($display->frm_edate_field_id)) { if (is_numeric($display->frm_edate_field_id) && $args['efield']) { $edate = FrmProEntryMetaHelper::get_post_or_meta_value($entry, $args['efield']); if ($args['efield'] && $args['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 = FrmAppHelper::get_localized_date('Y-m-d', $entry->updated_at); } else { $edate = FrmAppHelper::get_localized_date('Y-m-d', $entry->created_at); } } if ($edate && !empty($edate)) { $from_date = strtotime($date); $to_date = strtotime($edate); if (!empty($from_date) && $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, $to_date); } unset($edate); } unset($date); self::get_repeating_dates($entry, $display, $args, $dates); $dates = apply_filters('frm_show_entry_dates', $dates, $entry); for ($i = 0; $i < $args['maxday'] + $args['startday']; $i++) { $day = $i - $args['startday'] + 1; if (in_array(date('Y-m-d', strtotime($args['year'] . '-' . $args['month'] . '-' . $day)), $dates)) { $daily_entries[$i][] = $entry; } unset($day); } }
function get_data_value($value, $field, $atts = array()) { global $frm_field; if (!is_object($field)) { $field = $frm_field->getOne($field); } $linked_field_id = isset($atts['show']) ? $atts['show'] : false; $field->field_options = maybe_unserialize($field->field_options); if (is_numeric($value) and (!isset($field->field_options['form_select']) or $field->field_options['form_select'] != 'taxonomy')) { if (!$linked_field_id and is_numeric($field->field_options['form_select'])) { $linked_field_id = $field->field_options['form_select']; } if ($linked_field_id) { global $frm_entry_meta, $frmdb; $linked_field = $frm_field->getOne($linked_field_id); $linked_field->field_options = maybe_unserialize($linked_field->field_options); if (isset($linked_field->field_options['post_field']) and $linked_field->field_options['post_field']) { global $frmdb; $post_id = $frmdb->get_var($frmdb->entries, array('id' => $value), 'post_id'); if ($post_id) { if (!isset($atts['truncate'])) { $atts['truncate'] = false; } $new_value = FrmProEntryMetaHelper::get_post_value($post_id, $linked_field->field_options['post_field'], $linked_field->field_options['custom_field'], array('form_id' => $linked_field->form_id, 'field' => $linked_field, 'type' => $linked_field->type, 'truncate' => $atts['truncate'])); } else { $new_value = $frm_entry_meta->get_entry_meta_by_field($value, $linked_field->id); } } else { $new_value = $frm_entry_meta->get_entry_meta_by_field($value, $linked_field->id); } $value = !empty($new_value) ? $new_value : $value; if ($linked_field) { if (isset($atts['show']) and !is_numeric($atts['show'])) { $atts['show'] = $linked_field->id; } else { if (isset($atts['show']) and (int) $atts['show'] == $linked_field->id) { unset($atts['show']); } } $value = FrmProFieldsHelper::get_display_value($value, $linked_field, $atts); //get display value } } } return $value; }
header('Content-Type: text/csv; charset=' . $charset, true); header('Expires: ' . gmdate("D, d M Y H:i:s", mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d'), date('Y'))) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); foreach ($form_cols as $col) { echo '"' . FrmProEntriesHelper::encode_value(strip_tags($col->name), $charset, $to_encoding) . '",'; } echo '"' . __('Timestamp', 'formidable') . '","IP","ID","Key"' . "\n"; foreach ($entries as $entry) { foreach ($form_cols as $col) { $field_value = isset($entry->metas[$col->id]) ? $entry->metas[$col->id] : false; if (!$field_value and $entry->post_id) { $col->field_options = maybe_unserialize($col->field_options); if (isset($col->field_options['post_field']) and $col->field_options['post_field']) { $field_value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $col->field_options['post_field'], $col->field_options['custom_field'], array('truncate' => $col->field_options['post_field'] == 'post_category' ? true : false, 'form_id' => $entry->form_id, 'field' => $col, 'type' => $col->type, 'exclude_cat' => isset($col->field_options['exclude_cat']) ? $col->field_options['exclude_cat'] : 0)); } } if ($col->type == 'user_id') { $field_value = FrmProFieldsHelper::get_display_name($field_value); } else { if ($col->type == 'file') { $field_value = FrmProFieldsHelper::get_file_name($field_value); } else { if ($col->type == 'date') { $field_value = FrmProFieldsHelper::get_date($field_value, $wp_date_format); } else { if ($col->type == 'data' && is_numeric($field_value)) { $field_value = FrmProFieldsHelper::get_data_value($field_value, $col); //replace entry id with specified field } else {
private static function fill_field_defaults($field, $record, array &$values, $args) { $post_values = $args['post_values']; if ($args['default']) { $meta_value = $field->default_value; } else { if ($record->post_id && self::pro_is_installed() && isset($field->field_options['post_field']) && $field->field_options['post_field']) { if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field)); } else { $meta_value = FrmEntryMeta::get_meta_value($record, $field->id); } } $field_type = isset($post_values['field_options']['type_' . $field->id]) ? $post_values['field_options']['type_' . $field->id] : $field->type; $new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value; $field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id); $args['field_type'] = $field_type; self::fill_field_opts($field, $field_array, $args); $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']); if (!isset($field_array['unique']) || !$field_array['unique']) { $field_array['unique_msg'] = ''; } $field_array = array_merge($field->field_options, $field_array); $values['fields'][$field->id] = $field_array; }
public static function add_post_value_to_entry($field, &$entry) { if ($entry->post_id && ($field->type == 'tag' || isset($field->field_options['post_field']) && $field->field_options['post_field'])) { $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => $field->field_options['post_field'] == 'post_category', 'form_id' => $entry->form_id, 'field' => $field, 'type' => $field->type, 'exclude_cat' => isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0)); if ($p_val != '') { $entry->metas[$field->id] = $p_val; } } }
public static function get_data_value($value, $field, $atts = array()) { global $frm_field; if (!is_object($field)) { $field = $frm_field->getOne($field); } $orig_val = $value; $linked_field_id = isset($atts['show']) ? $atts['show'] : false; $field->field_options = maybe_unserialize($field->field_options); if (is_numeric($value) and (!isset($field->field_options['form_select']) or $field->field_options['form_select'] != 'taxonomy')) { if (!$linked_field_id and is_numeric($field->field_options['form_select'])) { $linked_field_id = $field->field_options['form_select']; } if ($linked_field_id) { global $frm_entry_meta, $frmdb; $linked_field = $frm_field->getOne($linked_field_id); if ($linked_field and isset($linked_field->field_options['post_field']) and $linked_field->field_options['post_field']) { $post_id = $frmdb->get_var($frmdb->entries, array('id' => $value), 'post_id'); if ($post_id) { if (!isset($atts['truncate'])) { $atts['truncate'] = false; } $new_value = FrmProEntryMetaHelper::get_post_value($post_id, $linked_field->field_options['post_field'], $linked_field->field_options['custom_field'], array('form_id' => $linked_field->form_id, 'field' => $linked_field, 'type' => $linked_field->type, 'truncate' => $atts['truncate'])); } else { $new_value = $frm_entry_meta->get_entry_meta_by_field($value, $linked_field->id); } } else { if ($linked_field) { $new_value = $frm_entry_meta->get_entry_meta_by_field($value, $linked_field->id); } else { //no linked field global $wpdb, $frmdb; $user_id = $wpdb->get_var("SELECT user_id FROM {$frmdb->entries} WHERE id=" . (int) $value); if ($user_id) { $new_value = self::get_display_name($user_id, $linked_field_id, array('blank' => true)); } else { $new_value = ''; } } } $value = (!empty($new_value) or $new_value === 0) ? $new_value : $value; if ($linked_field) { if (isset($atts['show']) and !is_numeric($atts['show'])) { $atts['show'] = $linked_field->id; } else { if (isset($atts['show']) and ((int) $atts['show'] == $linked_field->id or $atts['show'] == $linked_field->field_key)) { unset($atts['show']); } } if (!isset($atts['show']) and isset($atts['show_info'])) { $atts['show'] = $atts['show_info']; } $value = FrmProFieldsHelper::get_display_value($value, $linked_field, $atts); //get display value } } } if ($field->field_options['form_select'] != 'taxonomy' && $value == $orig_val && $field->field_options['data_type'] != 'data') { $value = ''; } if (is_array($value)) { $value = implode(isset($atts['show']) ? $atts['show'] : ', ', $value); } return $value; }
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; }
public static function setup_edit_vars($record, $table, $fields = '', $default = false, $post_values = array()) { if (!$record) { return false; } global $frm_entry_meta, $frm_settings, $frm_vars; if (empty($post_values)) { $post_values = stripslashes_deep($_POST); } $values = array('id' => $record->id, 'fields' => array()); foreach (array('name', 'description') as $var) { $default_val = isset($record->{$var}) ? $record->{$var} : ''; $values[$var] = FrmAppHelper::get_param($var, $default_val); unset($var, $default_val); } if (apply_filters('frm_use_wpautop', true)) { $values['description'] = wpautop(str_replace('<br>', '<br />', $values['description'])); } foreach ((array) $fields as $field) { if ($default) { $meta_value = $field->default_value; } else { if ($record->post_id and class_exists('FrmProEntryMetaHelper') and isset($field->field_options['post_field']) and $field->field_options['post_field']) { if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } $meta_value = FrmProEntryMetaHelper::get_post_value($record->post_id, $field->field_options['post_field'], $field->field_options['custom_field'], array('truncate' => false, 'type' => $field->type, 'form_id' => $field->form_id, 'field' => $field)); } else { if (isset($record->metas)) { $meta_value = isset($record->metas[$field->id]) ? $record->metas[$field->id] : false; } else { $meta_value = $frm_entry_meta->get_entry_meta_by_field($record->id, $field->id); } } } $field_type = isset($post_values['field_options']['type_' . $field->id]) ? $post_values['field_options']['type_' . $field->id] : $field->type; $new_value = isset($post_values['item_meta'][$field->id]) ? maybe_unserialize($post_values['item_meta'][$field->id]) : $meta_value; $field_array = array('id' => $field->id, 'value' => $new_value, 'default_value' => $field->default_value, 'name' => $field->name, 'description' => $field->description, 'type' => apply_filters('frm_field_type', $field_type, $field, $new_value), 'options' => $field->options, 'required' => $field->required, 'field_key' => $field->field_key, 'field_order' => $field->field_order, 'form_id' => $field->form_id); /*if(in_array($field_array['type'], array('checkbox', 'radio', 'select')) and !empty($field_array['options'])){ foreach((array)$field_array['options'] as $opt_key => $opt){ if(!is_array($opt)) $field_array['options'][$opt_key] = array('label' => $opt); unset($opt); unset($opt_key); } }*/ $opt_defaults = FrmFieldsHelper::get_default_field_opts($field_array['type'], $field, true); foreach ($opt_defaults as $opt => $default_opt) { $field_array[$opt] = $post_values && isset($post_values['field_options'][$opt . '_' . $field->id]) ? maybe_unserialize($post_values['field_options'][$opt . '_' . $field->id]) : (isset($field->field_options[$opt]) ? $field->field_options[$opt] : $default_opt); if ($opt == 'blank' and $field_array[$opt] == '') { $field_array[$opt] = $frm_settings->blank_msg; } else { if ($opt == 'invalid' and $field_array[$opt] == '') { if ($field_type == 'captcha') { $field_array[$opt] = $frm_settings->re_msg; } else { $field_array[$opt] = sprintf(__('%s is invalid', 'formidable'), $field_array['name']); } } } } unset($opt_defaults); if ($field_array['custom_html'] == '') { $field_array['custom_html'] = FrmFieldsHelper::get_default_html($field_type); } if ($field_array['size'] == '') { $field_array['size'] = isset($frm_vars['sidebar_width']) ? $frm_vars['sidebar_width'] : ''; } $field_array = apply_filters('frm_setup_edit_fields_vars', $field_array, $field, $values['id']); if (!isset($field_array['unique']) or !$field_array['unique']) { $field_array['unique_msg'] = ''; } foreach ((array) $field->field_options as $k => $v) { if (!isset($field_array[$k])) { $field_array[$k] = $v; } unset($k); unset($v); } $values['fields'][$field->id] = $field_array; unset($field); } $frm_form = new FrmForm(); $form = $frm_form->getOne($table == 'entries' ? $record->form_id : $record->id); unset($frm_form); if ($form) { $values['form_name'] = isset($record->form_id) ? $form->name : ''; if (is_array($form->options)) { foreach ($form->options as $opt => $value) { if (in_array($opt, array('email_to', 'reply_to', 'reply_to_name'))) { $values['notification'][0][$opt] = isset($post_values["notification[0][{$opt}]"]) ? maybe_unserialize($post_values["notification[0][{$opt}]"]) : $value; } $values[$opt] = isset($post_values[$opt]) ? maybe_unserialize($post_values[$opt]) : $value; } } } $form_defaults = FrmFormsHelper::get_default_opts(); //set to posted value or default foreach ($form_defaults as $opt => $default) { if (!isset($values[$opt]) or $values[$opt] == '') { if ($opt == 'notification') { $values[$opt] = ($post_values and isset($post_values[$opt])) ? $post_values[$opt] : $default; foreach ($default as $o => $d) { if ($o == 'email_to') { $d = ''; } //allow blank email address $values[$opt][0][$o] = ($post_values and isset($post_values[$opt][0][$o])) ? $post_values[$opt][0][$o] : $d; unset($o); unset($d); } } else { $values[$opt] = ($post_values and isset($post_values['options'][$opt])) ? $post_values['options'][$opt] : $default; } } else { if ($values[$opt] == 'notification') { foreach ($values[$opt] as $k => $n) { foreach ($default as $o => $d) { if (!isset($n[$o])) { $values[$opt][$k][$o] = ($post_values and isset($post_values[$opt][$k][$o])) ? $post_values[$opt][$k][$o] : $d; } unset($o); unset($d); } unset($k); unset($n); } } } unset($opt); unset($defaut); } if (!isset($values['custom_style'])) { $values['custom_style'] = ($post_values and isset($post_values['options']['custom_style'])) ? $_POST['options']['custom_style'] : $frm_settings->load_style != 'none'; } foreach (array('before', 'after', 'submit') as $h) { if (!isset($values[$h . '_html'])) { $values[$h . '_html'] = isset($post_values['options'][$h . '_html']) ? $post_values['options'][$h . '_html'] : FrmFormsHelper::get_default_html($h); } unset($h); } if ($table == 'entries') { $values = FrmEntriesHelper::setup_edit_vars($values, $record); } else { if ($table == 'forms') { $values = FrmFormsHelper::setup_edit_vars($values, $record, $post_values); } } return $values; }
private static function add_field_values_to_csv(&$row) { foreach (self::$fields as $col) { $field_value = isset(self::$entry->metas[$col->id]) ? self::$entry->metas[$col->id] : false; // Post values need to be retrieved differently if (self::$entry->post_id && ($col->type == 'tag' || isset($col->field_options['post_field']) && $col->field_options['post_field'])) { $field_value = FrmProEntryMetaHelper::get_post_value(self::$entry->post_id, $col->field_options['post_field'], $col->field_options['custom_field'], array('truncate' => $col->field_options['post_field'] == 'post_category' ? true : false, 'form_id' => self::$entry->form_id, 'field' => $col, 'type' => $col->type, 'exclude_cat' => isset($col->field_options['exclude_cat']) ? $col->field_options['exclude_cat'] : 0, 'sep' => self::$separator)); } if (in_array($col->type, array('user_id', 'file', 'date', 'data'))) { $field_value = FrmProFieldsHelper::get_export_val($field_value, $col, self::$entry); } else { if (isset($col->field_options['separate_value']) && $col->field_options['separate_value']) { $sep_value = FrmEntriesHelper::display_value($field_value, $col, array('type' => $col->type, 'post_id' => self::$entry->post_id, 'show_icon' => false, 'entry_id' => self::$entry->id, 'sep' => self::$separator, 'embedded_field_id' => isset(self::$entry->embedded_fields) && isset(self::$entry->embedded_fields[$entry->id]) ? 'form' . self::$entry->embedded_fields[self::$entry->id] : 0)); $row[$col->id . '_label'] = $sep_value; unset($sep_value); } $field_value = maybe_unserialize($field_value); $field_value = apply_filters('frm_csv_value', $field_value, array('field' => $col)); } $row[$col->id] = $field_value; unset($col, $field_value); } }
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; }
private static function entry_link_meta_value($entry, $atts) { $value = ''; if ($atts['field_key'] && $atts['field_key'] != 'created_at') { if ($entry->post_id && ($atts['field'] && $atts['field']->field_options['post_field'] || $atts['field']->type == 'tag')) { $meta = false; $value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $atts['field']->field_options['post_field'], $atts['field']->field_options['custom_field'], array('type' => $atts['field']->type, 'form_id' => $atts['field']->form_id, 'field' => $atts['field'])); } else { $meta = isset($entry->metas[$atts['field']->id]) ? $entry->metas[$atts['field']->id] : ''; } } else { $meta = reset($entry->metas); } self::entry_link_value($entry, $atts, $meta, $value); return $value; }
public static function show_entry_shortcode($atts) { $atts = shortcode_atts(array('id' => false, 'entry' => false, 'fields' => false, 'plain_text' => false, 'user_info' => false, 'include_blank' => false, 'default_email' => false, 'form_id' => false, 'format' => 'text', 'direction' => 'ltr', 'font_size' => '', 'text_color' => '', 'border_width' => '', 'border_color' => '', 'bg_color' => '', 'alt_bg_color' => ''), $atts); extract($atts); if ($format != 'text') { //format options are text, array, or json $plain_text = true; } global $frm_entry; if (!$entry || !is_object($entry)) { if (!$id && !$default_email) { return ''; } if ($id) { $entry = $frm_entry->getOne($id, true); } } if ($entry) { $form_id = $entry->form_id; $id = $entry->id; } if (!$fields || !is_array($fields)) { global $frm_field; $fields = $frm_field->getAll(array('fi.form_id' => $form_id), 'field_order'); } $content = $format != 'text' ? array() : ''; $odd = true; if (!$plain_text) { global $frmpro_settings; $default_settings = array('border_color' => 'dddddd', 'bg_color' => 'f7f7f7', 'text_color' => '444444', 'font_size' => '12px', 'border_width' => '1px', 'alt_bg_color' => 'ffffff'); // merge defaults, global settings, and shortcode options foreach ($default_settings as $key => $setting) { if ($atts[$key] != '') { continue; } if ($frmpro_settings) { if ('alt_bg_color' == $key) { $atts[$key] = $frmpro_settings->bg_color_active; } else { if ('border_width' == $key) { $atts[$key] = $frmpro_settings->field_border_width; } else { $atts[$key] = $frmpro_settings->{$key}; } } } else { $atts[$key] = $setting; } unset($key, $setting); } unset($default_settings); $content .= "<table cellspacing='0' style='font-size:{$atts['font_size']};line-height:135%; border-bottom:{$atts['border_width']} solid #{$atts['border_color']};'><tbody>\r\n"; $bg_color = " style='background-color:#{$atts['bg_color']};'"; $bg_color_alt = " style='background-color:#{$atts['alt_bg_color']};'"; $row_style = "style='text-align:" . ($direction == 'rtl' ? 'right' : 'left') . ";color:#{$atts['text_color']};padding:7px 9px;border-top:{$atts['border_width']} solid #{$atts['border_color']}'"; } foreach ($fields as $f) { if (in_array($f->type, array('divider', 'captcha', 'break', 'html'))) { continue; } if ($entry && !isset($entry->metas[$f->id])) { if ($entry->post_id && ($f->type == 'tag' || isset($f->field_options['post_field']) && $f->field_options['post_field'])) { $p_val = FrmProEntryMetaHelper::get_post_value($entry->post_id, $f->field_options['post_field'], $f->field_options['custom_field'], array('truncate' => $f->field_options['post_field'] == 'post_category' ? true : false, 'form_id' => $entry->form_id, 'field' => $f, 'type' => $f->type, 'exclude_cat' => isset($f->field_options['exclude_cat']) ? $f->field_options['exclude_cat'] : 0)); if ($p_val != '') { $entry->metas[$f->id] = $p_val; } } if (!isset($entry->metas[$f->id]) && !$include_blank && !$default_email) { continue; } $entry->metas[$f->id] = $default_email ? '[' . $f->id . ']' : ''; } $val = ''; if ($entry) { $prev_val = maybe_unserialize($entry->metas[$f->id]); $meta = array('item_id' => $id, 'field_id' => $f->id, 'meta_value' => $prev_val, 'field_type' => $f->type); $val = $default_email ? $prev_val : apply_filters('frm_email_value', $prev_val, (object) $meta, $entry); } else { if ($default_email) { $val = '[' . $f->id . ']'; } } if ($f->type == 'textarea' and !$plain_text) { $val = str_replace(array("\r\n", "\r", "\n"), ' <br/>', $val); } //Remove signature from default-message shortcode if ($f->type == 'signature' && !$default_email) { continue; } if (is_array($val) && $format == 'text') { $val = implode(', ', $val); } $fname = $default_email ? '[' . $f->id . ' show=field_label]' : $f->name; if ($format != 'text') { $content[$f->field_key] = $val; } else { if ($plain_text) { if ('rtl' == $direction) { $content .= $val . ' :' . $fname . "\r\n\r\n"; } else { $content .= $fname . ': ' . $val . "\r\n\r\n"; } } else { if (!$default_email) { $content .= '<tr' . ($odd ? $bg_color : $bg_color_alt) . '>'; if ('rtl' == $direction) { $content .= "<td {$row_style}>{$val}</td><th {$row_style}>" . $fname . "</th>"; } else { $content .= "<th {$row_style}>" . $fname . "</th><td {$row_style}>{$val}</td>"; } $content .= '</tr>' . "\r\n"; $odd = $odd ? false : true; } else { $content .= '[if ' . $f->id . ']<tr style="[frm-alt-color]">'; if ('rtl' == $direction) { $content .= "<td {$row_style}>{$val}</td><th {$row_style}>" . $fname . "</th>"; } else { $content .= "<th {$row_style}>" . $fname . "</th><td {$row_style}>{$val}</td>"; } $content .= "</tr>\r\n[/if {$f->id}]"; } } } unset($fname, $f); } if ($user_info) { if (isset($entry->description)) { $data = maybe_unserialize($entry->description); } else { if ($default_email) { $entry->ip = '[ip]'; $data = array('browser' => '[browser]', 'referrer' => '[referrer]'); } } if ($format != 'text') { $content['ip'] = $entry->ip; $content['browser'] = $data['browser']; $content['referrer'] = $data['referrer']; } else { if ($plain_text) { $content .= "\r\n\r\n" . __('User Information', 'formidable') . "\r\n"; if ('rtl' == $direction) { $content .= $entry->ip . ' :' . __('IP Address', 'formidable') . "\r\n"; $content .= $data['browser'] . ' :' . __('User-Agent (Browser/OS)', 'formidable') . "\r\n"; $content .= $data['referrer'] . ' :' . __('Referrer', 'formidable') . "\r\n"; } else { $content .= __('IP Address', 'formidable') . ': ' . $entry->ip . "\r\n"; $content .= __('User-Agent (Browser/OS)', 'formidable') . ': ' . $data['browser'] . "\r\n"; $content .= __('Referrer', 'formidable') . ': ' . $data['referrer'] . "\r\n"; } } else { $content .= '<tr' . ($odd ? $bg_color : $bg_color_alt) . '>'; if ('rtl' == $direction) { $content .= "<td {$row_style}>" . $entry->ip . "</td><th {$row_style}>" . __('IP Address', 'formidable') . "</th>"; } else { $content .= "<th {$row_style}>" . __('IP Address', 'formidable') . "</th><td {$row_style}>" . $entry->ip . "</td>"; } $content .= '</tr>' . "\r\n"; $odd = $odd ? false : true; if (isset($data['browser'])) { $content .= '<tr' . ($odd ? $bg_color : $bg_color_alt) . '>'; if ('rtl' == $direction) { $content .= "<td {$row_style}>" . $data['browser'] . "</td><th {$row_style}>" . __('User-Agent (Browser/OS)', 'formidable') . "</th>"; } else { $content .= "<th {$row_style}>" . __('User-Agent (Browser/OS)', 'formidable') . "</th><td {$row_style}>" . $data['browser'] . "</td>"; } $content .= '</tr>' . "\r\n"; } $odd = $odd ? false : true; if (isset($data['referrer'])) { $content .= '<tr' . ($odd ? $bg_color : $bg_color_alt) . '>'; if ('rtl' == $direction) { $content .= "<td {$row_style}>" . str_replace("\r\n", '<br/>', $data['referrer']) . "</td><th {$row_style}>" . __('Referrer', 'formidable') . "</th>"; } else { $content .= "<th {$row_style}>" . __('Referrer', 'formidable') . "</th><td {$row_style}>" . str_replace("\r\n", '<br/>', $data['referrer']) . "</td>"; } $content .= '</tr>' . "\r\n"; } } } } if (!$plain_text) { $content .= '</tbody></table>'; } if ($format == 'json') { $content = json_encode($content); } return $content; }
/** * Get the displayed value for Dynamic field that imports data from a post field * Called from self::get_linked_field_val */ private static function get_linked_post_field_val($value, $atts, $linked_field) { global $wpdb; $post_id = FrmDb::get_var($wpdb->prefix . 'frm_items', array('id' => $value), 'post_id'); if ($post_id) { if (!isset($atts['truncate'])) { $atts['truncate'] = false; } $new_value = FrmProEntryMetaHelper::get_post_value($post_id, $linked_field->field_options['post_field'], $linked_field->field_options['custom_field'], array('form_id' => $linked_field->form_id, 'field' => $linked_field, 'type' => $linked_field->type, 'truncate' => $atts['truncate'])); } else { $new_value = FrmEntryMeta::get_entry_meta_by_field($value, $linked_field->id); } return $new_value; }
/** * Prepare the saved value for display * @return string */ public static function display_value($value, $field, $atts = array()) { $defaults = array('type' => '', 'html' => false, 'show_filename' => true, 'truncate' => false, 'sep' => ', ', 'post_id' => 0, 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0, 'return_array' => false); $atts = wp_parse_args($atts, $defaults); $atts = apply_filters('frm_display_value_atts', $atts, $field, $value); if (!isset($field->field_options['post_field'])) { $field->field_options['post_field'] = ''; } if (!isset($field->field_options['custom_field'])) { $field->field_options['custom_field'] = ''; } if (FrmAppHelper::pro_is_installed() && $atts['post_id'] && ($field->field_options['post_field'] || $atts['type'] == 'tag')) { $atts['pre_truncate'] = $atts['truncate']; $atts['truncate'] = true; $atts['exclude_cat'] = isset($field->field_options['exclude_cat']) ? $field->field_options['exclude_cat'] : 0; $value = FrmProEntryMetaHelper::get_post_value($atts['post_id'], $field->field_options['post_field'], $field->field_options['custom_field'], $atts); $atts['truncate'] = $atts['pre_truncate']; } if ($value == '') { return $value; } $value = apply_filters('frm_display_value_custom', maybe_unserialize($value), $field, $atts); $value = apply_filters('frm_display_' . $field->type . '_value_custom', $value, compact('field', 'atts')); $new_value = ''; if (is_array($value) && $atts['type'] != 'file') { foreach ($value as $val) { if (is_array($val)) { //TODO: add options for display (li or ,) $new_value .= implode($atts['sep'], $val); if ($atts['type'] != 'data') { $new_value .= '<br/>'; } } unset($val); } } if (!empty($new_value)) { $value = $new_value; } else { if (is_array($value) && $atts['type'] != 'file' && !$atts['return_array']) { $value = implode($atts['sep'], $value); } } if ($atts['truncate'] && $atts['type'] != 'image') { $value = FrmAppHelper::truncate($value, 50); } if (!$atts['keepjs'] && !is_array($value)) { $value = wp_kses_post($value); } return apply_filters('frm_display_value', $value, $field, $atts); }
header('Content-Type: text/csv; charset=' . $charset, true); header('Expires: ' . gmdate("D, d M Y H:i:s", mktime(date('H') + 2, date('i'), date('s'), date('m'), date('d'), date('Y'))) . ' GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); foreach ($form_cols as $col) { echo '"' . FrmProEntriesHelper::encode_value(strip_tags($col->name), $charset, $to_encoding) . '",'; } echo '"' . __('Timestamp', 'formidable') . '","IP","ID","Key"' . "\n"; foreach ($entries as $entry) { foreach ($form_cols as $col) { $field_value = isset($entry->metas[$col->id]) ? $entry->metas[$col->id] : false; if (!$field_value and $entry->post_id) { $col->field_options = maybe_unserialize($col->field_options); if (isset($col->field_options['post_field']) and $col->field_options['post_field']) { $field_value = FrmProEntryMetaHelper::get_post_value($entry->post_id, $col->field_options['post_field'], $col->field_options['custom_field'], array('truncate' => false, 'form_id' => $entry->form_id, 'field' => $col, 'type' => $col->type)); } } if ($col->type == 'user_id') { $field_value = FrmProFieldsHelper::get_display_name($field_value); } else { if ($col->type == 'file') { $field_value = FrmProFieldsHelper::get_file_name($field_value); } else { if ($col->type == 'date') { $field_value = FrmProFieldsHelper::get_date($field_value, $wp_date_format); } else { if ($col->type == 'data' && is_numeric($field_value)) { $field_value = FrmProFieldsHelper::get_data_value($field_value, $col); //replace entry id with specified field } else {