/**
 * Details page tab custom fields.
 *
 * @since 1.0.0
 * @since 1.5.7 Custom fields option values added to db translation.
 *              Changes to display url fields title.
 * @package GeoDirectory
 * @global object $post The current post object.
 * @param array $tabs_arr Tabs array {@see geodir_detail_page_tab_headings_change()}.
 * @return array Modified tabs array.
 */
function geodir_detail_page_custom_field_tab($tabs_arr)
{
    global $post;
    $post_type = geodir_get_current_posttype();
    $all_postypes = geodir_get_posttypes();
    if (!empty($tabs_arr) && $post_type != '' && in_array($post_type, $all_postypes) && (geodir_is_page('detail') || geodir_is_page('preview'))) {
        $package_info = array();
        $package_info = geodir_post_package_info($package_info, $post);
        $post_package_id = $package_info->pid;
        $fields_location = 'detail';
        $custom_fields = geodir_post_custom_fields($post_package_id, 'default', $post_type, $fields_location);
        if (!empty($custom_fields)) {
            $parse_custom_fields = array();
            foreach ($custom_fields as $field) {
                $field = stripslashes_deep($field);
                // strip slashes
                $type = $field;
                $field_name = $field['htmlvar_name'];
                if (empty($geodir_post_info) && geodir_is_page('preview') && $field_name != '' && !isset($post->{$field_name}) && isset($_REQUEST[$field_name])) {
                    $post->{$field_name} = $_REQUEST[$field_name];
                }
                if (isset($field['show_as_tab']) && $field['show_as_tab'] == 1 && (isset($post->{$field_name}) && $post->{$field_name} != '' || $field['type'] == 'fieldset') && in_array($field['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) {
                    if ($type['type'] == 'datepicker' && ($post->{$type}['htmlvar_name'] == '' || $post->{$type}['htmlvar_name'] == '0000-00-00')) {
                        continue;
                    }
                    $parse_custom_fields[] = $field;
                }
            }
            $custom_fields = $parse_custom_fields;
        }
        if (!empty($custom_fields)) {
            $field_set_start = 0;
            $fieldset_count = 0;
            $fieldset = '';
            $total_fields = count($custom_fields);
            $count_field = 0;
            $fieldset_arr = array();
            $i = 0;
            $geodir_post_info = isset($post->ID) && !empty($post->ID) ? geodir_get_post_info($post->ID) : NULL;
            foreach ($custom_fields as $field) {
                $count_field++;
                $field_name = $field['htmlvar_name'];
                if (empty($geodir_post_info) && geodir_is_page('preview') && $field_name != '' && !isset($post->{$field_name}) && isset($_REQUEST[$field_name])) {
                    $post->{$field_name} = $_REQUEST[$field_name];
                }
                if (isset($field['show_as_tab']) && $field['show_as_tab'] == 1 && (isset($post->{$field_name}) && $post->{$field_name} != '' || $field['type'] == 'fieldset') && in_array($field['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) {
                    $label = $field['site_title'] != '' ? $field['site_title'] : $field['admin_title'];
                    $site_title = trim($field['site_title']);
                    $type = $field;
                    $html = '';
                    $html_var = $field_name;
                    $field_icon = '';
                    $variables_array = array();
                    if ($type['type'] == 'datepicker' && ($post->{$type}['htmlvar_name'] == '' || $post->{$type}['htmlvar_name'] == '0000-00-00')) {
                        continue;
                    }
                    if ($type['type'] != 'fieldset') {
                        $i++;
                        $variables_array['post_id'] = $post->ID;
                        $variables_array['label'] = __($type['site_title'], 'geodirectory');
                        $variables_array['value'] = '';
                        $variables_array['value'] = $post->{$type}['htmlvar_name'];
                    }
                    if (strpos($type['field_icon'], 'http') !== false) {
                        $field_icon = ' background: url(' . $type['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;';
                    } elseif (strpos($type['field_icon'], 'fa fa-') !== false) {
                        $field_icon = '<i class="' . $type['field_icon'] . '"></i>';
                    }
                    switch ($type['type']) {
                        case 'fieldset':
                            $i = 0;
                            $fieldset_count++;
                            $field_set_start = 1;
                            $fieldset_arr[$fieldset_count]['htmlvar_name'] = 'gd_tab_' . $fieldset_count;
                            $fieldset_arr[$fieldset_count]['label'] = $label;
                            break;
                        case 'url':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                if ($type['name'] == 'geodir_facebook') {
                                    $field_icon_af = '<i class="fa fa-facebook-square"></i>';
                                } elseif ($type['name'] == 'geodir_twitter') {
                                    $field_icon_af = '<i class="fa fa-twitter-square"></i>';
                                } else {
                                    $field_icon_af = '<i class="fa fa-link"></i>';
                                }
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $a_url = geodir_parse_custom_field_url($post->{$type}['htmlvar_name']);
                            $website = !empty($a_url['url']) ? $a_url['url'] : '';
                            $title = !empty($a_url['label']) ? $a_url['label'] : $type['site_title'];
                            $title = $title != '' ? __(stripslashes($title), 'geodirectory') : '';
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            // all search engines that use the nofollow value exclude links that use it from their ranking calculation
                            $rel = strpos($website, get_site_url()) !== false ? '' : 'rel="nofollow"';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-website" style="' . $field_icon . '">' . $field_icon_af . ' <a href="' . $website . '" target="_blank" ' . $rel . ' ><strong>' . apply_filters('geodir_custom_field_website_name', $title, $website, $post->ID) . '</strong></a></span></div>';
                            break;
                        case 'phone':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '<i class="fa fa-phone"></i>';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-contact" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                            break;
                        case 'time':
                            $value = '';
                            if ($post->{$type}['htmlvar_name'] != '') {
                                //$value = date('h:i',strtotime($post->$type['htmlvar_name']));
                                $value = date(get_option('time_format'), strtotime($post->{$type}['htmlvar_name']));
                            }
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '<i class="fa fa-clock-o"></i>';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . stripslashes($value) . '</div>';
                            break;
                        case 'datepicker':
                            $date_format = geodir_default_date_format();
                            if ($type['extra_fields'] != '') {
                                $date_format = unserialize($type['extra_fields']);
                                $date_format = $date_format['date_format'];
                            }
                            $search = array('dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy');
                            //jQuery UI datepicker format
                            $replace = array('d', 'j', 'l', 'm', 'n', 'F', 'Y');
                            //PHP date format
                            $date_format = str_replace($search, $replace, $date_format);
                            $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $post->{$type}['htmlvar_name']) : $post->{$type}['htmlvar_name'];
                            // PHP doesn't work well with dd/mm/yyyy format
                            $value = '';
                            if ($post->{$type}['htmlvar_name'] != '') {
                                $value = date($date_format, strtotime($post_htmlvar_value));
                            }
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '<i class="fa fa-calendar"></i>';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-datepicker" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . $value . '</div>';
                            break;
                        case 'text':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                            break;
                        case 'radio':
                            if ($post->{$type}['htmlvar_name'] != '') {
                                if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') {
                                    $html_val = __('No', 'geodirectory');
                                } else {
                                    if ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') {
                                        $html_val = __('Yes', 'geodirectory');
                                    } else {
                                        $html_val = __($post->{$type}['htmlvar_name'], 'geodirectory');
                                        if (!empty($type['option_values'])) {
                                            $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                                            if (!empty($cf_option_values)) {
                                                foreach ($cf_option_values as $cf_option_value) {
                                                    if (isset($cf_option_value['value']) && $cf_option_value['value'] == $post->{$type}['htmlvar_name']) {
                                                        $html_val = $cf_option_value['label'];
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (strpos($field_icon, 'http') !== false) {
                                    $field_icon_af = '';
                                } else {
                                    if ($field_icon == '') {
                                        $field_icon_af = '';
                                    } else {
                                        $field_icon_af = $field_icon;
                                        $field_icon = '';
                                    }
                                }
                                $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                                $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-radio" style="' . $field_icon . '">' . $field_icon_af;
                                if ($field_set_start == 1 && $site_title != '') {
                                    $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                                }
                                $html .= ' </span>' . $html_val . '</div>';
                            }
                            break;
                        case 'checkbox':
                            $html_var = $type['htmlvar_name'];
                            $html_val = $type['htmlvar_name'];
                            if ((int) $post->{$html_var} == 1) {
                                if ($post->{$type}['htmlvar_name'] == '1') {
                                    $html_val = __('Yes', 'geodirectory');
                                } else {
                                    $html_val = __('No', 'geodirectory');
                                }
                                if (strpos($field_icon, 'http') !== false) {
                                    $field_icon_af = '';
                                } else {
                                    if ($field_icon == '') {
                                        $field_icon_af = '';
                                    } else {
                                        $field_icon_af = $field_icon;
                                        $field_icon = '';
                                    }
                                }
                                $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                                $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-checkbox" style="' . $field_icon . '">' . $field_icon_af;
                                if ($field_set_start == 1 && $site_title != '') {
                                    $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                                }
                                $html .= ' </span>' . $html_val . '</div>';
                            }
                            break;
                        case 'select':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $field_value = __($post->{$type}['htmlvar_name'], 'geodirectory');
                            if (!empty($type['option_values'])) {
                                $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                                if (!empty($cf_option_values)) {
                                    foreach ($cf_option_values as $cf_option_value) {
                                        if (isset($cf_option_value['value']) && $cf_option_value['value'] == $post->{$type}['htmlvar_name']) {
                                            $field_value = $cf_option_value['label'];
                                        }
                                    }
                                }
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . $field_value . '</div>';
                            break;
                        case 'multiselect':
                            if (is_array($post->{$type}['htmlvar_name'])) {
                                $post->{$type}['htmlvar_name'] = implode(', ', $post->{$type}['htmlvar_name']);
                            }
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $field_values = explode(',', trim($post->{$type}['htmlvar_name'], ","));
                            $option_values = array();
                            if (!empty($type['option_values'])) {
                                $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                                if (!empty($cf_option_values)) {
                                    foreach ($cf_option_values as $cf_option_value) {
                                        if (isset($cf_option_value['value']) && in_array($cf_option_value['value'], $field_values)) {
                                            $option_values[] = $cf_option_value['label'];
                                        }
                                    }
                                }
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>';
                            if (count($option_values) > 1) {
                                $html .= '<ul>';
                                foreach ($option_values as $val) {
                                    $html .= '<li>' . $val . '</li>';
                                }
                                $html .= '</ul>';
                            } else {
                                $html .= $post->{$type}['htmlvar_name'];
                            }
                            $html .= '</div>';
                            break;
                        case 'email':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '<i class="fa fa-envelope"></i>';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                            break;
                        case 'textarea':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= '</span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>';
                            break;
                        case 'html':
                            if (strpos($field_icon, 'http') !== false) {
                                $field_icon_af = '';
                            } elseif ($field_icon == '') {
                                $field_icon_af = '';
                            } else {
                                $field_icon_af = $field_icon;
                                $field_icon = '';
                            }
                            $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                            $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                            if ($field_set_start == 1 && $site_title != '') {
                                $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                            }
                            $html .= ' </span>' . wpautop(stripslashes($post->{$type}['htmlvar_name'])) . '</div>';
                            break;
                        case 'file':
                            $html_var = $type['htmlvar_name'];
                            if (!empty($post->{$type}['htmlvar_name'])) {
                                $files = explode(",", $post->{$type}['htmlvar_name']);
                                if (!empty($files)) {
                                    $extra_fields = !empty($type['extra_fields']) ? maybe_unserialize($type['extra_fields']) : NULL;
                                    $allowed_file_types = !empty($extra_fields['gd_file_types']) && is_array($extra_fields['gd_file_types']) && !in_array("*", $extra_fields['gd_file_types']) ? $extra_fields['gd_file_types'] : '';
                                    $file_paths = '';
                                    foreach ($files as $file) {
                                        if (!empty($file)) {
                                            $filetype = wp_check_filetype($file);
                                            $image_name_arr = explode('/', $file);
                                            $curr_img_dir = $image_name_arr[count($image_name_arr) - 2];
                                            $filename = end($image_name_arr);
                                            $img_name_arr = explode('.', $filename);
                                            $arr_file_type = wp_check_filetype($filename);
                                            if (empty($arr_file_type['ext']) || empty($arr_file_type['type'])) {
                                                continue;
                                            }
                                            $uploaded_file_type = $arr_file_type['type'];
                                            $uploaded_file_ext = $arr_file_type['ext'];
                                            if (!empty($allowed_file_types) && !in_array($uploaded_file_ext, $allowed_file_types)) {
                                                continue;
                                                // Invalid file type.
                                            }
                                            //$allowed_file_types = array('application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain');
                                            $image_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/x-icon');
                                            // If the uploaded file is image
                                            if (in_array($uploaded_file_type, $image_file_types)) {
                                                $file_paths .= '<div class="geodir-custom-post-gallery" class="clearfix">';
                                                $file_paths .= '<a href="' . $file . '">';
                                                $file_paths .= geodir_show_image(array('src' => $file), 'thumbnail', false, false);
                                                $file_paths .= '</a>';
                                                $file_paths .= '</div>';
                                            } else {
                                                $ext_path = '_' . $html_var . '_';
                                                $filename = explode($ext_path, $filename);
                                                $file_paths .= '<a href="' . $file . '" target="_blank">' . $filename[count($filename) - 1] . '</a>';
                                            }
                                        }
                                    }
                                    if (strpos($field_icon, 'http') !== false) {
                                        $field_icon_af = '';
                                    } else {
                                        if ($field_icon == '') {
                                            $field_icon_af = '';
                                        } else {
                                            $field_icon_af = $field_icon;
                                            $field_icon = '';
                                        }
                                    }
                                    $geodir_odd_even = $field_set_start == 1 && $i % 2 == 0 ? 'geodir_more_info_even' : 'geodir_more_info_odd';
                                    $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . ' geodir-custom-file-box" style="clear:both;"><span class="geodir-i-file" style="display:inline-block;vertical-align:top;padding-right:14px;' . $field_icon . '">' . $field_icon_af;
                                    if ($field_set_start == 1 && $site_title != '') {
                                        $html .= ' ' . __($site_title, 'geodirectory') . ': ';
                                    }
                                    $html .= ' </span>' . $file_paths . '</div>';
                                }
                            }
                            break;
                    }
                    /**
                     * Filter custom field output in tab.
                     *
                     * @since 1.5.6
                     *
                     * @param string $html_var The HTML variable name for the field.
                     * @param string $html Custom field unfiltered HTML.
                     * @param array $variables_array Custom field variables array.
                     */
                    $html = apply_filters("geodir_tab_show_{$html_var}", $html, $variables_array);
                    if ($field_set_start == 1) {
                        $add_html = false;
                        if ($type['type'] == 'fieldset' && $fieldset_count > 1) {
                            if ($fieldset != '') {
                                $add_html = true;
                                $label = $fieldset_arr[$fieldset_count - 1]['label'];
                                $htmlvar_name = $fieldset_arr[$fieldset_count - 1]['htmlvar_name'];
                            }
                            $fieldset_html = $fieldset;
                            $fieldset = '';
                        } else {
                            $fieldset .= $html;
                            if ($total_fields == $count_field && $fieldset != '') {
                                $add_html = true;
                                $label = $fieldset_arr[$fieldset_count]['label'];
                                $htmlvar_name = $fieldset_arr[$fieldset_count]['htmlvar_name'];
                                $fieldset_html = $fieldset;
                            }
                        }
                        if ($add_html) {
                            $tabs_arr[$htmlvar_name] = array('heading_text' => __($label, 'geodirectory'), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, $htmlvar_name), 'tab_content' => '<div class="geodir-company_info field-group">' . $fieldset_html . '</html>');
                        }
                    } else {
                        if ($html != '') {
                            $tabs_arr[$field['htmlvar_name']] = array('heading_text' => __($label, 'geodirectory'), 'is_active_tab' => false, 'is_display' => apply_filters('geodir_detail_page_tab_is_display', true, $field['htmlvar_name']), 'tab_content' => $html);
                        }
                    }
                }
            }
        }
    }
    return $tabs_arr;
}
 /**
  * Show listing info depending on field location.
  *
  * @since 1.0.0
  * @since 1.5.7 Custom fields option values added to db translation.
  *              Changes to display url fields title.
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global object $post The current post object.
  * @param string $fields_location In which page you are going to place this custom fields?. Ex: listing, detail etc.
  * @return string Returns listing info html.
  */
 function geodir_show_listing_info($fields_location = '')
 {
     global $post, $preview, $wpdb;
     $payment_info = array();
     $package_info = array();
     $package_info = geodir_post_package_info($package_info, $post);
     //return;
     $post_package_id = $package_info->pid;
     $p_type = geodir_get_current_posttype() ? geodir_get_current_posttype() : $post->post_type;
     ob_start();
     $fields_info = geodir_post_custom_fields($post_package_id, 'default', $p_type, $fields_location);
     if (!empty($fields_info)) {
         //echo '<div class="geodir-company_info field-group">';
         $field_set_start = 0;
         if ($fields_location == 'detail') {
             $i = 1;
         }
         foreach ($fields_info as $type) {
             $type = stripslashes_deep($type);
             // strip slashes
             $html = '';
             $html_var = '';
             $field_icon = '';
             $variables_array = array();
             if ($fields_location == 'detail' && isset($type['show_as_tab']) && (int) $type['show_as_tab'] == 1 && in_array($type['type'], array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) {
                 continue;
             }
             if ($type['type'] != 'fieldset') {
                 $variables_array['post_id'] = $post->ID;
                 $variables_array['label'] = __($type['site_title'], 'geodirectory');
                 $variables_array['value'] = '';
                 if (isset($post->{$type['htmlvar_name']})) {
                     $variables_array['value'] = $post->{$type['htmlvar_name']};
                 }
             }
             //if($type['field_icon'])
             if (strpos($type['field_icon'], 'http') !== false) {
                 $field_icon = ' background: url(' . $type['field_icon'] . ') no-repeat left center;background-size:18px 18px;padding-left: 21px;';
             } elseif (strpos($type['field_icon'], 'fa fa-') !== false) {
                 $field_icon = '<i class="' . $type['field_icon'] . '"></i>';
             }
             //else{$field_icon = $type['field_icon'];}
             switch ($type['type']) {
                 case 'fieldset':
                     $fieldset_class = 'fieldset-' . sanitize_title_with_dashes($type['site_title']);
                     if ($field_set_start == 1) {
                         echo '</div><div class="geodir-company_info field-group ' . $type['htmlvar_name'] . '"><h2 class="' . $fieldset_class . '">' . __($type['site_title'], 'geodirectory') . '</h2>';
                     } else {
                         echo '<h2 class="' . $fieldset_class . '">' . __($type['site_title'], 'geodirectory') . '</h2>';
                         $field_set_start = 1;
                     }
                     break;
                 case 'address':
                     $html_var = $type['htmlvar_name'] . '_address';
                     if ($type['extra_fields']) {
                         $extra_fields = unserialize($type['extra_fields']);
                         $addition_fields = '';
                         if (!empty($extra_fields)) {
                             /**
                              * Filter "show city in address" value.
                              *
                              * @since 1.0.0
                              */
                             $show_city_in_address = apply_filters('geodir_show_city_in_address', false);
                             if (isset($extra_fields['show_city']) && $extra_fields['show_city'] && $show_city_in_address) {
                                 $field = $type['htmlvar_name'] . '_city';
                                 if ($post->{$field}) {
                                     $addition_fields .= ', ' . $post->{$field};
                                 }
                             }
                             if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) {
                                 $field = $type['htmlvar_name'] . '_zip';
                                 if ($post->{$field}) {
                                     $addition_fields .= ', ' . $post->{$field};
                                 }
                             }
                         }
                     }
                     /*if($type['extra_fields'])
                     		{
                     			
                     			$extra_fields = unserialize($type['extra_fields']);
                     			
                     			$addition_fields = '';
                     			
                     			if(!empty($extra_fields))
                     			{
                     				if($extra_fields['show_city'])
                     				{
                     					$field = $type['htmlvar_name'].'_city';
                     					if($post->$field)
                     					{
                     						$addition_fields .= ', '.$post->$field;
                     					}
                     				}
                     				
                     				if($extra_fields['show_region'])
                     				{
                     					$field = $type['htmlvar_name'].'_region';
                     					if($post->$field)
                     					{
                     						$addition_fields .= ', '.$post->$field;
                     					}
                     				}
                     				
                     				if($extra_fields['show_country'])
                     				{
                     					$field = $type['htmlvar_name'].'_country';
                     					if($post->$field)
                     					{
                     						$addition_fields .= ', '.$post->$field;
                     					}
                     				}
                     				
                     				if($extra_fields['show_zip'])
                     				{
                     					$field = $type['htmlvar_name'].'_zip';
                     					if($post->$field)
                     					{
                     						$addition_fields .= ', '.$post->$field;
                     					}
                     				}
                     				
                     			}
                     		
                     		}*/
                     if ($post->{$html_var}) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-home"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"  itemscope itemtype="http://schema.org/PostalAddress">';
                         $html .= '<span class="geodir-i-location" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '&nbsp;';
                         $html .= '</span>';
                         //print_r($_POST);
                         if ($preview) {
                             $html .= stripslashes($post->{$html_var}) . $addition_fields . '</p></div>';
                         } else {
                             if ($post->post_address) {
                                 $html .= '<span itemprop="streetAddress">' . $post->post_address . '</span><br>';
                             }
                             if ($post->post_city) {
                                 $html .= '<span itemprop="addressLocality">' . $post->post_city . '</span><br>';
                             }
                             if ($post->post_region) {
                                 $html .= '<span itemprop="addressRegion">' . $post->post_region . '</span><br>';
                             }
                             if ($post->post_zip) {
                                 $html .= '<span itemprop="postalCode">' . $post->post_zip . '</span><br>';
                             }
                             if ($post->post_country) {
                                 $html .= '<span itemprop="addressCountry">' . __($post->post_country, 'geodirectory') . '</span><br>';
                             }
                             $html .= '</div>';
                         }
                     }
                     $variables_array['value'] = $post->{$html_var};
                     break;
                 case 'url':
                     $html_var = $type['htmlvar_name'];
                     if ($post->{$type['htmlvar_name']}) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             if ($type['name'] == 'geodir_facebook') {
                                 $field_icon_af = '<i class="fa fa-facebook-square"></i>';
                             } elseif ($type['name'] == 'geodir_twitter') {
                                 $field_icon_af = '<i class="fa fa-twitter-square"></i>';
                             } else {
                                 $field_icon_af = '<i class="fa fa-link"></i>';
                             }
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $a_url = geodir_parse_custom_field_url($post->{$type['htmlvar_name']});
                         $website = !empty($a_url['url']) ? $a_url['url'] : '';
                         $title = !empty($a_url['label']) ? $a_url['label'] : $type['site_title'];
                         if (!empty($type['default_value'])) {
                             $title = $type['default_value'];
                         }
                         $title = $title != '' ? __(stripslashes($title), 'geodirectory') : '';
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         // all search engines that use the nofollow value exclude links that use it from their ranking calculation
                         $rel = strpos($website, get_site_url()) !== false ? '' : 'rel="nofollow"';
                         /**
                          * Filter custom field website name.
                          *
                          * @since 1.0.0
                          *
                          * @param string $title Website Title.
                          * @param string $website Website URL.
                          * @param int $post->ID Post ID.
                          */
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-website" style="' . $field_icon . '">' . $field_icon_af . '<a href="' . $website . '" target="_blank" ' . $rel . ' ><strong>' . apply_filters('geodir_custom_field_website_name', $title, $website, $post->ID) . '</strong></a></span></div>';
                     }
                     break;
                 case 'phone':
                     $html_var = $type['htmlvar_name'];
                     if ($post->{$type['htmlvar_name']}) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-phone"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-contact" style="' . $field_icon . '">' . $field_icon_af . ($html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '&nbsp;');
                         $html .= '</span><a href="tel:' . preg_replace('/[^0-9+]/', '', $post->{$type['htmlvar_name']}) . '">' . stripslashes($post->{$type['htmlvar_name']}) . '</a></div>';
                     }
                     break;
                 case 'time':
                     $html_var = $type['htmlvar_name'];
                     if ($post->{$type['htmlvar_name']}) {
                         $value = '';
                         if ($post->{$type['htmlvar_name']} != '') {
                             //$value = date('h:i',strtotime($post->{$type['htmlvar_name']}));
                             $value = date(get_option('time_format'), strtotime($post->{$type['htmlvar_name']}));
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-clock-o"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '&nbsp;';
                         $html .= '</span>' . stripslashes($value) . '</div>';
                     }
                     break;
                 case 'datepicker':
                     if ($post->{$type['htmlvar_name']}) {
                         $date_format = geodir_default_date_format();
                         if ($type['extra_fields'] != '') {
                             $date_format = unserialize($type['extra_fields']);
                             $date_format = $date_format['date_format'];
                         }
                         $search = array('dd', 'd', 'DD', 'mm', 'm', 'MM', 'yy');
                         //jQuery UI datepicker format
                         $replace = array('d', 'j', 'l', 'm', 'n', 'F', 'Y');
                         //PHP date format
                         $date_format = str_replace($search, $replace, $date_format);
                         $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $post->{$type['htmlvar_name']}) : $post->{$type['htmlvar_name']};
                         // PHP doesn't work well with dd/mm/yyyy format
                         $value = '';
                         if ($post->{$type['htmlvar_name']} != '' && $post->{$type['htmlvar_name']} != "0000-00-00") {
                             $value = date($date_format, strtotime($post_htmlvar_value));
                         } else {
                             continue;
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-calendar"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-datepicker" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . $value . '</div>';
                     }
                     break;
                 case 'text':
                     $html_var = $type['htmlvar_name'];
                     if (isset($post->{$type['htmlvar_name']}) && $post->{$type['htmlvar_name']} != '' && $type['htmlvar_name'] == 'geodir_timing') {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-clock-o"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-time" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '&nbsp;';
                         $html .= '</span>' . stripslashes($post->{$type['htmlvar_name']}) . '</div>';
                     } elseif (isset($post->{$type['htmlvar_name']}) && $post->{$type['htmlvar_name']}) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . stripslashes($post->{$type['htmlvar_name']}) . '</div>';
                     }
                     break;
                 case 'radio':
                     $html_var = $type['htmlvar_name'];
                     $html_val = __($post->{$type['htmlvar_name']}, 'geodirectory');
                     if ($post->{$type['htmlvar_name']} != '') {
                         if ($post->{$type['htmlvar_name']} == 'f' || $post->{$type['htmlvar_name']} == '0') {
                             $html_val = __('No', 'geodirectory');
                         } else {
                             if ($post->{$type['htmlvar_name']} == 't' || $post->{$type['htmlvar_name']} == '1') {
                                 $html_val = __('Yes', 'geodirectory');
                             } else {
                                 if (!empty($type['option_values'])) {
                                     $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                                     if (!empty($cf_option_values)) {
                                         foreach ($cf_option_values as $cf_option_value) {
                                             if (isset($cf_option_value['value']) && $cf_option_value['value'] == $post->{$type['htmlvar_name']}) {
                                                 $html_val = $cf_option_value['label'];
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-radio" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . $html_val . '</div>';
                     }
                     break;
                 case 'checkbox':
                     $html_var = $type['htmlvar_name'];
                     if ((int) $post->{$html_var} == 1) {
                         if ($post->{$type['htmlvar_name']} == '1') {
                             $html_val = __('Yes', 'geodirectory');
                         } else {
                             $html_val = __('No', 'geodirectory');
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-checkbox" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . $html_val . '</div>';
                     }
                     break;
                 case 'select':
                     $html_var = $type['htmlvar_name'];
                     if ($post->{$type['htmlvar_name']}) {
                         $field_value = __($post->{$type}['htmlvar_name'], 'geodirectory');
                         if (!empty($type['option_values'])) {
                             $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                             if (!empty($cf_option_values)) {
                                 foreach ($cf_option_values as $cf_option_value) {
                                     if (isset($cf_option_value['value']) && $cf_option_value['value'] == $post->{$type}['htmlvar_name']) {
                                         $field_value = $cf_option_value['label'];
                                     }
                                 }
                             }
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . $field_value . '</div>';
                     }
                     break;
                 case 'multiselect':
                     $html_var = $type['htmlvar_name'];
                     if (!empty($post->{$type['htmlvar_name']})) {
                         if (is_array($post->{$type['htmlvar_name']})) {
                             $post->{$type['htmlvar_name']} = implode(', ', $post->{$type['htmlvar_name']});
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $field_values = explode(',', trim($post->{$type}['htmlvar_name'], ","));
                         $option_values = array();
                         if (!empty($type['option_values'])) {
                             $cf_option_values = geodir_string_values_to_options(stripslashes_deep($type['option_values']), true);
                             if (!empty($cf_option_values)) {
                                 foreach ($cf_option_values as $cf_option_value) {
                                     if (isset($cf_option_value['value']) && in_array($cf_option_value['value'], $field_values)) {
                                         $option_values[] = $cf_option_value['label'];
                                     }
                                 }
                             }
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>';
                         if (count($option_values) > 1) {
                             $html .= '<ul>';
                             foreach ($option_values as $val) {
                                 $html .= '<li>' . $val . '</li>';
                             }
                             $html .= '</ul>';
                         } else {
                             $html .= $post->{$type}['htmlvar_name'];
                         }
                         $html .= '</div>';
                     }
                     break;
                 case 'email':
                     if ($type['htmlvar_name'] == 'geodir_email' && !(geodir_is_page('detail') || geodir_is_page('preview'))) {
                         continue;
                         // Remove Send Enquiry | Send To Friend from listings page
                     }
                     if ($type['htmlvar_name'] == 'geodir_email' && (isset($package_info->sendtofriend) && $package_info->sendtofriend || $post->{$type['htmlvar_name']})) {
                         $b_send_inquiry = '';
                         $b_sendtofriend = '';
                         $html = '';
                         if (!$preview) {
                             $b_send_inquiry = 'b_send_inquiry';
                             $b_sendtofriend = 'b_sendtofriend';
                             $html = '<input type="hidden" name="geodir_popup_post_id" value="' . $post->ID . '" /><div class="geodir_display_popup_forms"></div>';
                         }
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '<i class="fa fa-envelope"></i>';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html .= '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af;
                         $seperator = '';
                         if ($post->{$type['htmlvar_name']}) {
                             $html .= '<a href="javascript:void(0);" class="' . $b_send_inquiry . '" >' . SEND_INQUIRY . '</a>';
                             $seperator = ' | ';
                         }
                         if (isset($package_info->sendtofriend) && $package_info->sendtofriend) {
                             $html .= $seperator . '<a href="javascript:void(0);" class="' . $b_sendtofriend . '">' . SEND_TO_FRIEND . '</a>';
                         }
                         $html .= '</span></div>';
                         if (isset($_REQUEST['send_inquiry']) && $_REQUEST['send_inquiry'] == 'success') {
                             $html .= '<p class="sucess_msg">' . SEND_INQUIRY_SUCCESS . '</p>';
                         } elseif (isset($_REQUEST['sendtofrnd']) && $_REQUEST['sendtofrnd'] == 'success') {
                             $html .= '<p class="sucess_msg">' . SEND_FRIEND_SUCCESS . '</p>';
                         } elseif (isset($_REQUEST['emsg']) && $_REQUEST['emsg'] == 'captch') {
                             $html .= '<p class="error_msg_fix">' . WRONG_CAPTCH_MSG . '</p>';
                         }
                         /*if(!$preview){require_once (geodir_plugin_path().'/geodirectory-templates/popup-forms.php');}*/
                     } else {
                         if ($post->{$type['htmlvar_name']}) {
                             if (strpos($field_icon, 'http') !== false) {
                                 $field_icon_af = '';
                             } elseif ($field_icon == '') {
                                 $field_icon_af = '<i class="fa fa-envelope"></i>';
                             } else {
                                 $field_icon_af = $field_icon;
                                 $field_icon = '';
                             }
                             $geodir_odd_even = '';
                             if ($fields_location == 'detail') {
                                 $geodir_odd_even = 'geodir_more_info_odd';
                                 if ($i % 2 == 0) {
                                     $geodir_odd_even = 'geodir_more_info_even';
                                 }
                                 $i++;
                             }
                             $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-email" style="' . $field_icon . '">' . $field_icon_af;
                             $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                             $html .= '</span><span class="geodir-email-address-output">';
                             $email = stripslashes($post->{$type['htmlvar_name']});
                             if ($e_split = explode('@', $email)) {
                                 /**
                                  * Filter email custom field name output.
                                  *
                                  * @since 1.5.3
                                  *
                                  * @param string $email The email string being output.
                                  * @param array $type Custom field variables array.
                                  */
                                 $email_name = apply_filters('geodir_email_field_name_output', $email, $type);
                                 $html .= "<script>document.write('<a href=\"mailto:'+'{$e_split['0']}' + '@' + '{$e_split['1']}'+'\">{$email_name}</a>')</script>";
                             } else {
                                 $html .= $email;
                             }
                             $html .= '</span></div>';
                         }
                     }
                     break;
                 case 'file':
                     $html_var = $type['htmlvar_name'];
                     if (!empty($post->{$type['htmlvar_name']})) {
                         $files = explode(",", $post->{$type['htmlvar_name']});
                         if (!empty($files)) {
                             $extra_fields = !empty($type['extra_fields']) ? maybe_unserialize($type['extra_fields']) : NULL;
                             $allowed_file_types = !empty($extra_fields['gd_file_types']) && is_array($extra_fields['gd_file_types']) && !in_array("*", $extra_fields['gd_file_types']) ? $extra_fields['gd_file_types'] : '';
                             $file_paths = '';
                             foreach ($files as $file) {
                                 if (!empty($file)) {
                                     // $filetype = wp_check_filetype($file);
                                     $image_name_arr = explode('/', $file);
                                     $curr_img_dir = $image_name_arr[count($image_name_arr) - 2];
                                     $filename = end($image_name_arr);
                                     $img_name_arr = explode('.', $filename);
                                     $arr_file_type = wp_check_filetype($filename);
                                     if (empty($arr_file_type['ext']) || empty($arr_file_type['type'])) {
                                         continue;
                                     }
                                     $uploaded_file_type = $arr_file_type['type'];
                                     $uploaded_file_ext = $arr_file_type['ext'];
                                     if (!empty($allowed_file_types) && !in_array($uploaded_file_ext, $allowed_file_types)) {
                                         continue;
                                         // Invalid file type.
                                     }
                                     //$allowed_file_types = array('application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'text/csv', 'text/plain');
                                     $image_file_types = array('image/jpg', 'image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'image/x-icon');
                                     // If the uploaded file is image
                                     if (in_array($uploaded_file_type, $image_file_types)) {
                                         $file_paths .= '<div class="geodir-custom-post-gallery" class="clearfix">';
                                         $file_paths .= '<a href="' . $file . '">';
                                         $file_paths .= geodir_show_image(array('src' => $file), 'thumbnail', false, false);
                                         $file_paths .= '</a>';
                                         //$file_paths .= '<img src="'.$file.'"  />';
                                         $file_paths .= '</div>';
                                     } else {
                                         $ext_path = '_' . $html_var . '_';
                                         $filename = explode($ext_path, $filename);
                                         $file_paths .= '<a href="' . $file . '" target="_blank">' . $filename[count($filename) - 1] . '</a>';
                                     }
                                 }
                             }
                             if (strpos($field_icon, 'http') !== false) {
                                 $field_icon_af = '';
                             } elseif ($field_icon == '') {
                                 $field_icon_af = '';
                             } else {
                                 $field_icon_af = $field_icon;
                                 $field_icon = '';
                             }
                             $geodir_odd_even = '';
                             if ($fields_location == 'detail') {
                                 $geodir_odd_even = 'geodir_more_info_odd';
                                 if ($i % 2 == 0) {
                                     $geodir_odd_even = 'geodir_more_info_even';
                                 }
                                 $i++;
                             }
                             $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' geodir-custom-file-box ' . $type['htmlvar_name'] . '"><div class="geodir-i-select" style="' . $field_icon . '">' . $field_icon_af;
                             $html .= '<span style="display: inline-block; vertical-align: top; padding-right: 14px;">';
                             $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                             $html .= '</span>';
                             $html .= $file_paths . '</div></div>';
                         }
                     }
                     break;
                 case 'textarea':
                     $html_var = $type['htmlvar_name'];
                     if (!empty($post->{$type['htmlvar_name']})) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . wpautop(stripslashes($post->{$type['htmlvar_name']})) . '</div>';
                     }
                     break;
                 case 'html':
                     if (!empty($post->{$type['htmlvar_name']})) {
                         if (strpos($field_icon, 'http') !== false) {
                             $field_icon_af = '';
                         } elseif ($field_icon == '') {
                             $field_icon_af = '';
                         } else {
                             $field_icon_af = $field_icon;
                             $field_icon = '';
                         }
                         $geodir_odd_even = '';
                         if ($fields_location == 'detail') {
                             $geodir_odd_even = 'geodir_more_info_odd';
                             if ($i % 2 == 0) {
                                 $geodir_odd_even = 'geodir_more_info_even';
                             }
                             $i++;
                         }
                         $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $type['htmlvar_name'] . '" style="clear:both;"><span class="geodir-i-text" style="' . $field_icon . '">' . $field_icon_af;
                         $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                         $html .= '</span>' . wpautop(stripslashes($post->{$type['htmlvar_name']})) . '</div>';
                     }
                     break;
                 case 'taxonomy':
                     $html_var = $type['htmlvar_name'];
                     if ($html_var == $post->post_type . 'category' && !empty($post->{$html_var})) {
                         $post_taxonomy = $post->post_type . 'category';
                         $field_value = $post->{$html_var};
                         $links = array();
                         $terms = array();
                         $termsOrdered = array();
                         if (!is_array($field_value)) {
                             $field_value = explode(",", trim($field_value, ","));
                         }
                         $field_value = array_unique($field_value);
                         if (!empty($field_value)) {
                             foreach ($field_value as $term) {
                                 $term = trim($term);
                                 if ($term != '') {
                                     $term = get_term_by('id', $term, $html_var);
                                     if (is_object($term)) {
                                         $links[] = "<a href='" . esc_attr(get_term_link($term, $post_taxonomy)) . "'>" . $term->name . "</a>";
                                         $terms[] = $term;
                                     }
                                 }
                             }
                             if (!empty($links)) {
                                 // order alphabetically
                                 asort($links);
                                 foreach (array_keys($links) as $key) {
                                     $termsOrdered[$key] = $terms[$key];
                                 }
                                 $terms = $termsOrdered;
                             }
                         }
                         $html_value = !empty($links) && !empty($terms) ? wp_sprintf('%l', $links, (object) $terms) : '';
                         if ($html_value != '') {
                             if (strpos($field_icon, 'http') !== false) {
                                 $field_icon_af = '';
                             } else {
                                 if ($field_icon == '') {
                                     $field_icon_af = '';
                                 } else {
                                     $field_icon_af = $field_icon;
                                     $field_icon = '';
                                 }
                             }
                             $geodir_odd_even = '';
                             if ($fields_location == 'detail') {
                                 $geodir_odd_even = 'geodir_more_info_odd';
                                 if ($i % 2 == 0) {
                                     $geodir_odd_even = 'geodir_more_info_even';
                                 }
                                 $i++;
                             }
                             $html = '<div class="geodir_more_info ' . $geodir_odd_even . ' ' . $type['css_class'] . ' ' . $html_var . '" style="clear:both;"><span class="geodir-i-taxonomy geodir-i-category" style="' . $field_icon . '">' . $field_icon_af;
                             $html .= trim($type['site_title']) ? __($type['site_title'], 'geodirectory') . ': ' : '';
                             $html .= '</span> ' . $html_value . '</div>';
                         }
                     }
                     break;
             }
             if ($html) {
                 /**
                  * Called before a custom fields is output on the frontend.
                  *
                  * @since 1.0.0
                  * @param string $html_var The HTML variable name for the field.
                  */
                 do_action("geodir_before_show_{$html_var}");
                 /**
                  * Filter custom field output.
                  *
                  * @since 1.0.0
                  *
                  * @param string $html_var The HTML variable name for the field.
                  * @param string $html Custom field unfiltered HTML.
                  * @param array $variables_array Custom field variables array.
                  */
                 if ($html) {
                     echo apply_filters("geodir_show_{$html_var}", $html, $variables_array);
                 }
                 /**
                  * Called after a custom fields is output on the frontend.
                  *
                  * @since 1.0.0
                  * @param string $html_var The HTML variable name for the field.
                  */
                 do_action("geodir_after_show_{$html_var}");
             }
         }
         //echo '</div>';
     }
     return $html = ob_get_clean();
 }