public static function email_value($value, $meta, $entry) { if ($entry->id != $meta->item_id) { $entry = FrmEntry::getOne($meta->item_id); } $field = FrmField::getOne($meta->field_id); if (!$field) { return $value; } if (FrmField::is_option_true($field, 'post_field')) { $value = self::get_post_or_meta_value($entry, $field, array('truncate' => true)); $value = maybe_unserialize($value); } switch ($field->type) { case 'user_id': $value = FrmProFieldsHelper::get_display_name($value); break; case 'data': if (is_array($value)) { $new_value = array(); foreach ($value as $val) { $new_value[] = FrmProFieldsHelper::get_data_value($val, $field); } $value = $new_value; } else { $value = FrmProFieldsHelper::get_data_value($value, $field); } break; case 'file': $value = FrmProFieldsHelper::get_file_name($value); break; case 'date': $value = FrmProFieldsHelper::get_date($value); } if (is_array($value)) { $new_value = ''; foreach ($value as $val) { if (is_array($val)) { // This will affect checkboxes inside of repeating sections $new_value .= implode(', ', $val) . "\n"; } } if ($new_value != '') { $value = $new_value; } else { // Only keep non-empty values in array $value = array_filter($value); } } return $value; }
public static function display_value($value, $field, $atts = array()) { global $wpdb, $frm_field; $defaults = array('type' => '', 'show_icon' => true, 'show_filename' => true, 'truncate' => false, 'sep' => ', ', 'post_id' => 0, 'form_id' => $field->form_id, 'field' => $field, 'keepjs' => 0); $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 ($atts['post_id'] and ($field->field_options['post_field'] or $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 = maybe_unserialize($value); $value = apply_filters('frm_display_value_custom', $value, $field, $atts); $new_value = ''; if (is_array($value)) { 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)) { $value = implode($atts['sep'], $value); } } if ($atts['truncate'] and $atts['type'] != 'image') { $value = FrmAppHelper::truncate($value, 50); } if ($atts['type'] == 'image') { $value = '<img src="' . $value . '" height="50px" alt="" />'; } else { if ($atts['type'] == 'user_id') { $value = FrmProFieldsHelper::get_display_name($value); } else { if ($atts['type'] == 'file') { $old_value = explode(', ', $value); $value = ''; foreach ($old_value as $mid) { $value .= '<div class="frm_file_container">'; if ($atts['show_icon']) { $img = FrmProFieldsHelper::get_file_icon($mid); $value .= $img; if ($atts['show_filename'] and $img and preg_match("/wp-includes\\/images\\/crystal/", $img)) { //prevent two filenames $atts['show_filename'] = $show_filename = false; } unset($img); } if ($atts['show_icon'] and $atts['show_filename']) { $value .= '<br/>'; } if ($atts['show_filename']) { $value .= FrmProFieldsHelper::get_file_name($mid); } if (isset($show_filename)) { //if skipped filename, show it for the next file $atts['show_filename'] = true; unset($show_filename); } $value .= '</div>'; } } else { if ($atts['type'] == 'date') { $value = FrmProFieldsHelper::get_date($value); } else { if ($atts['type'] == 'data') { if (!is_numeric($value)) { $value = explode($atts['sep'], $value); if (is_array($value)) { $new_value = ''; foreach ($value as $entry_id) { if (!empty($new_value)) { $new_value .= $atts['sep']; } if (is_numeric($entry_id)) { $dval = FrmProFieldsHelper::get_data_value($entry_id, $field, $atts); if (is_array($dval)) { $dval = implode($atts['sep'], $dval); } $new_value .= $dval; } else { $new_value .= $entry_id; } } $value = $new_value; } } else { //replace item id with specified field $new_value = FrmProFieldsHelper::get_data_value($value, $field, $atts); if ($field->field_options['data_type'] == 'data' or $field->field_options['data_type'] == '') { $linked_field = $frm_field->getOne($field->field_options['form_select']); if ($linked_field->type == 'file') { $old_value = explode(', ', $new_value); $new_value = ''; foreach ($old_value as $v) { $new_value .= '<img src="' . $v . '" height="50px" alt="" />'; if ($atts['show_filename']) { $new_value .= '<br/>' . $v; } unset($v); } } else { $new_value = $value; } } $value = $new_value; } } } } } } if (!$atts['keepjs']) { $value = wp_kses_post($value); } return apply_filters('frm_display_value', $value, $field, $atts); }
function display_value($value, $field, $atts = array()) { global $wpdb; $defaults = array('type' => '', 'show_icon' => true, 'show_filename' => true, 'truncate' => false, 'sep' => ', ', 'post_id' => 0, 'form_id' => $field->form_id, 'field' => $field); $atts = wp_parse_args($atts, $defaults); $field->field_options = maybe_unserialize($field->field_options); 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 ($atts['post_id'] and ($field->field_options['post_field'] or $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 = maybe_unserialize($value); if (is_array($value)) { $value = stripslashes_deep($value); } $value = apply_filters('frm_display_value_custom', $value, $field, $atts); $new_value = ''; if (is_array($value)) { 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)) { $value = implode($atts['sep'], $value); } } if ($atts['truncate'] and $atts['type'] != 'image') { $value = FrmAppHelper::truncate($value, 50); } if ($atts['type'] == 'image') { $value = '<img src="' . $value . '" height="50px" alt="" />'; } else { if ($atts['type'] == 'user_id') { $value = FrmProFieldsHelper::get_display_name($value); } else { if ($atts['type'] == 'file') { $old_value = $value; $value = ''; if ($atts['show_icon']) { $value .= FrmProFieldsHelper::get_file_icon($old_value); } if ($atts['show_icon'] and $atts['show_filename']) { $value .= '<br/>'; } if ($atts['show_filename']) { $value .= FrmProFieldsHelper::get_file_name($old_value); } } else { if ($atts['type'] == 'date') { $value = FrmProFieldsHelper::get_date($value); } else { if ($atts['type'] == 'data') { if (!is_numeric($value)) { $value = explode($atts['sep'], $value); if (is_array($value)) { $new_value = ''; foreach ($value as $entry_id) { if (!empty($new_value)) { $new_value .= $atts['sep']; } if (is_numeric($entry_id)) { $new_value .= FrmProFieldsHelper::get_data_value($entry_id, $field, $atts); } else { $new_value .= $entry_id; } } $value = $new_value; } } else { //replace item id with specified field $value = FrmProFieldsHelper::get_data_value($value, $field, $atts); if ($field->field_options['data_type'] == 'data' or $field->field_options['data_type'] == '') { $linked_field = FrmField::getOne($field->field_options['form_select']); if ($linked_field->type == 'file') { $old_value = $value; $value = '<img src="' . $value . '" height="50px" alt="" />'; if ($atts['show_filename']) { $value .= '<br/>' . $old_value; } } } } } } } } } $value = stripslashes_deep($value); return apply_filters('frm_display_value', $value, $field, $atts); }
function get_display_value($replace_with, $field, $atts = array()) { $sep = isset($atts['sep']) ? $atts['sep'] : ', '; if ($field->type == 'user_id') { $user_info = isset($atts['show']) ? $atts['show'] : 'display_name'; $replace_with = FrmProFieldsHelper::get_display_name($replace_with, $user_info, $atts); if (is_array($replace_with)) { $new_val = ''; foreach ($replace_with as $key => $val) { if (!empty($new_val)) { $new_val .= ', '; } $new_val .= $key . '. ' . $val; } $replace_with = $new_val; } } else { if ($field->type == 'date') { if (isset($atts['time_ago'])) { $atts['format'] = 'Y-m-d H:i:s'; } if (!isset($atts['format'])) { $atts['format'] = false; } $replace_with = FrmProFieldsHelper::get_date($replace_with, $atts['format']); if (isset($atts['time_ago'])) { $replace_with = FrmProAppHelper::human_time_diff(strtotime($replace_with), strtotime(date_i18n('Y-m-d'))); } } else { if (is_numeric($replace_with) and $field->type == 'file') { //size options are thumbnail, medium, large, or full $size = isset($atts['size']) ? $atts['size'] : 'thumbnail'; if ($size != 'id') { $replace_with = FrmProFieldsHelper::get_media_from_id($replace_with, $size); } } else { if ($field->type == 'data') { //and (is_numeric($replace_with) or is_array($replace_with)) $field->field_options = maybe_unserialize($field->field_options); if (isset($field->field_options['form_select']) and $field->field_options['form_select'] == 'taxonomy') { return $replace_with; } $replace_with = explode($sep, $replace_with); if (isset($atts['show'])) { if (in_array($atts['show'], array('key', 'created-at', 'created_at', 'updated-at', 'updated_at', 'post_id'))) { global $frm_entry; if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = ''; foreach ($linked_ids as $linked_id) { $linked_entry = FrmEntry::getOne($linked_id); if (!empty($replace_with)) { $replace_with .= $sep; } if ($atts['show'] == 'created-at') { $replace_with .= $linked_entry->created_at; } else { if ($atts['show'] == 'updated-at') { $replace_with .= $linked_entry->updated_at; } else { if ($atts['show'] == 'key') { $replace_with .= $linked_entry->item_key; } else { $replace_with .= isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key; } } } } } else { $linked_entry = FrmEntry::getOne($replace_with); if ($atts['show'] == 'created-at') { $replace_with = $linked_entry->created_at; } else { if ($atts['show'] == 'updated-at') { $replace_with = $linked_entry->updated_at; } else { if ($atts['show'] == 'key') { $replace_with = $linked_entry->item_key; } else { $replace_with = isset($linked_entry->{$atts['show']}) ? $linked_entry->{$atts['show']} : $linked_entry->item_key; } } } } } else { if ($atts['show'] == 'id') { if (is_array($replace_with)) { $replace_with = implode($sep, $replace_with); } //just keep the value since it's already the id } else { if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = array(); foreach ($linked_ids as $linked_id) { $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts); if ($linked_id != $new_val) { $replace_with[] = $new_val; } unset($new_val); } $replace_with = implode($sep, $replace_with); } else { $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts); } } } } else { if (is_array($replace_with)) { $linked_ids = $replace_with; $replace_with = array(); foreach ($linked_ids as $linked_id) { $new_val = FrmProFieldsHelper::get_data_value($linked_id, $field, $atts); if ($linked_id != $new_val) { $replace_with[] = $new_val; } unset($new_val); } $replace_with = implode($sep, $replace_with); } else { $replace_with = FrmProFieldsHelper::get_data_value($replace_with, $field, $atts); } } } else { if ($field->type == 'textarea') { $autop = isset($atts['wpautop']) ? $atts['wpautop'] : true; if (apply_filters('frm_use_wpautop', $autop)) { $replace_with = wpautop($replace_with); } unset($autop); } else { if ($field->type == 'number') { if (!isset($atts['decimal'])) { $num = explode('.', $replace_with); $atts['decimal'] = isset($num[1]) ? strlen($num[1]) : 0; } if (!isset($atts['dec_point'])) { $atts['dec_point'] = '.'; } if (!isset($atts['thousands_sep'])) { $atts['thousands_sep'] = ''; } $replace_with = number_format($replace_with, $atts['decimal'], $atts['dec_point'], $atts['thousands_sep']); } } } } } } $replace_with = stripslashes_deep($replace_with); return $replace_with; }
public static function &filter_display_value($value, $field, $atts = array()) { $defaults = array('html' => 0, 'type' => $field->type, 'keepjs' => 0); $atts = array_merge($defaults, $atts); switch ($atts['type']) { case 'user_id': $value = FrmProFieldsHelper::get_display_name($value); break; case 'date': $value = FrmProFieldsHelper::get_date($value); break; case 'file': $old_value = $value; if ($atts['html']) { $value = '<div class="frm_file_container">'; } else { $value = ''; } foreach ((array) $old_value as $mid) { if ($atts['html']) { $img = FrmProFieldsHelper::get_file_icon($mid); $value .= $img; if ($atts['show_filename'] && $img && preg_match('/wp-includes\\/images\\/(crystal|media)/', $img)) { //prevent two filenames $atts['show_filename'] = $show_filename = false; } unset($img); if ($atts['html'] && $atts['show_filename']) { $value .= '<br/>' . FrmProFieldsHelper::get_file_name($mid) . '<br/>'; } if (isset($show_filename)) { //if skipped filename, show it for the next file $atts['show_filename'] = true; unset($show_filename); } } else { if ($mid) { $value .= FrmProFieldsHelper::get_file_name($mid) . $atts['sep']; } } } $value = rtrim($value, $atts['sep']); if ($atts['html']) { $value .= '</div>'; } break; case 'data': if (!is_numeric($value)) { if (!is_array($value)) { $value = explode($atts['sep'], $value); } if (is_array($value)) { $new_value = ''; foreach ($value as $entry_id) { if (!empty($new_value)) { $new_value .= $atts['sep']; } if (is_numeric($entry_id)) { $new_value .= FrmProFieldsHelper::get_data_value($entry_id, $field, $atts); } else { $new_value .= $entry_id; } } $value = $new_value; } } else { //replace item id with specified field $new_value = FrmProFieldsHelper::get_data_value($value, $field, $atts); if (FrmProField::is_list_field($field)) { $linked_field = FrmField::getOne($field->field_options['form_select']); if ($linked_field && $linked_field->type == 'file') { $old_value = explode(', ', $new_value); $new_value = ''; foreach ($old_value as $v) { $new_value .= '<img src="' . esc_url($v) . '" class="frm_image_from_url" alt="" />'; if ($atts['show_filename']) { $new_value .= '<br/>' . $v; } unset($v); } } else { $new_value = $value; } } $value = $new_value; } break; case 'image': $value = FrmProFieldsHelper::get_image_display_value($value, array('html' => true)); break; } if (!$atts['keepjs']) { $value = FrmAppHelper::recursive_function_map($value, 'wp_kses_post'); } return FrmEntriesController::filter_display_value($value, $field, $atts); }
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 { $checked_values = maybe_unserialize($field_value); $checked_values = apply_filters('frm_csv_value', $checked_values, array('field' => $col)); if (is_array($checked_values)) { if ($col->type == 'data') { $field_value = ''; foreach ($checked_values as $checked_value) { if (!empty($field_value)) { $field_value .= ', '; } $field_value .= FrmProFieldsHelper::get_data_value($checked_value, $col);