private function render_field_value($field, $value) { $output = array(); foreach ((array) $value as $v) { $output[] = awpcp_extra_fields_render_field_single_value($field, $value); } return implode(', ', $output); }
function display_x_fields_data($adid, $single = true) { global $wpdb; $ad = AWPCP_Ad::find_by_id($adid); $fields = awpcp_get_extra_fields_by_category($ad->ad_category_id, array('hide_private' => true, 'context' => $single ? 'single' : 'listings')); $show_empty = get_awpcp_option('show-empty-extra-fields-in-ads'); $visible = array(); foreach ($fields as $i => $field) { $value = (array) get_field_value($adid, $field->field_name); if ($show_empty || !empty($value) && strlen($value[0]) > 0) { $visible[] = array('field' => $field, 'value' => $value); } } $allow_html_in_labels = get_awpcp_option('allow-html-in-extra-field-labels'); $count = count($visible); $columns = get_awpcp_option('display-extra-fields-in-columns', 1); $rows = ceil($count / $columns); $shown = 0; $classes = array('awpcp-extra-fields', 'awpcp-extra-fields-columns-' . $columns, 'clearfix'); $html = '<div class="' . join(' ', $classes) . '">'; foreach ($visible as $i => $data) { $field = $data['field']; $value = $data['value']; $classes = array('cladinfo', 'awpcp-extra-field-' . $field->field_name); $css = awpcp_get_grid_item_css_class($classes, $shown, $columns, $rows); $field_label = stripslashes($field->field_label_view); $field_label = $allow_html_in_labels ? $field_label : esc_html($field_label); if ($show_empty || !empty($value) && strlen($value[0]) > 0) { $html .= '<div class="' . esc_attr(join(' ', $css)) . '">'; $html .= '<label>' . $field_label . ':</label> '; if (count($value) > 1) { $html .= '<ul class="awpcp-extra-field-value-list">'; foreach ($value as $v) { $v = awpcp_extra_fields_render_field_single_value($field, $v); $html .= '<li>' . $v . '</li>'; } $html .= '</ul>'; } else { if (count($value) > 0) { $value = awpcp_extra_fields_render_field_single_value($field, $value[0]); if ($field->field_input_type === 'Textarea Input') { $html .= sprintf('<div class="awpcp-extra-field-value">%s</div>', $value); } else { $html .= sprintf('<span class="awpcp-extra-field-value">%s</span>', $value); } } } $html .= '</div>'; $shown++; } } $html .= '</div>'; return $html; }