/**
 * Details page tab custom fields.
 *
 * @since 1.0.0
 * @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 = '';
                            }
                            if (!strstr($post->{$type}['htmlvar_name'], 'http')) {
                                $website = 'http://' . $post->{$type}['htmlvar_name'];
                            } else {
                                $website = $post->{$type}['htmlvar_name'];
                            }
                            $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', stripslashes(__($type['site_title'], 'geodirectory')), $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');
                                    }
                                }
                                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 = '';
                            }
                            $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>' . stripslashes($post->{$type}['htmlvar_name']) . '</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 = '';
                            }
                            $option_values = explode(',', $post->{$type}['htmlvar_name']);
                            if ($type['option_values']) {
                                if (strstr($type['option_values'], "/")) {
                                    $option_values = array();
                                    $field_values = explode(',', $type['option_values']);
                                    foreach ($field_values as $data) {
                                        $val = explode('/', $data);
                                        if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) {
                                            $option_values[] = $val[0];
                                        }
                                    }
                                }
                            }
                            $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>' . stripslashes($val) . '</li>';
                                }
                                $html .= '</ul>';
                            } else {
                                $html .= stripslashes(trim($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;
                    }
                    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;
}
 /**
  * Saves listing in the database using given information.
  *
  * @since 1.0.0
  * @package GeoDirectory
  * @global object $wpdb WordPress Database object.
  * @global object $post The current post object.
  * @global object $current_user Current user object.
  * @param array $request_info {
  *    Array of request info arguments.
  *
  *    @type string $action                                  Ajax action name.
  *    @type string $geodir_ajax                             Ajax type.
  *    @type string $ajax_action                             Ajax action.
  *    @type string $listing_type                            Listing type.
  *    @type string $pid                                     Default Post ID.
  *    @type string $preview                                 Todo Desc needed.
  *    @type string $add_listing_page_id                     Add listing page ID.
  *    @type string $post_title                              Listing title.
  *    @type string $post_desc                               Listing Description.
  *    @type string $post_tags                               Listing tags.
  *    @type array  $cat_limit                               Category limit.
  *    @type array  $post_category                           Category IDs.
  *    @type array  $post_category_str                       Category string.
  *    @type string $post_default_category                   Default category ID.
  *    @type string $post_address                            Listing address.
  *    @type string $geodir_location_add_listing_country_val Add listing country value.
  *    @type string $post_country                            Listing country.
  *    @type string $geodir_location_add_listing_region_val  Add listing region value.
  *    @type string $post_region                             Listing region.
  *    @type string $geodir_location_add_listing_city_val    Add listing city value.
  *    @type string $post_city                               Listing city.
  *    @type string $post_zip                                Listing zip.
  *    @type string $post_latitude                           Listing latitude.
  *    @type string $post_longitude                          Listing longitude.
  *    @type string $post_mapview                            Listing mapview. Default "ROADMAP".
  *    @type string $post_mapzoom                            Listing mapzoom Default "9".
  *    @type string $geodir_timing                           Business timing info.
  *    @type string $geodir_contact                          Contact number.
  *    @type string $geodir_email                            Business contact email.
  *    @type string $geodir_website                          Business website.
  *    @type string $geodir_twitter                          Twitter link.
  *    @type string $geodir_facebook                         Facebook link.
  *    @type string $geodir_video                            Video link.
  *    @type string $geodir_special_offers                   Speacial offers.
  *    @type string $post_images                             Post image urls.
  *    @type string $post_imagesimage_limit                  Post images limit.
  *    @type string $post_imagestotImg                       Todo Desc needed.
  *    @type string $geodir_accept_term_condition            Has accepted terms and conditions?.
  *    @type string $geodir_spamblocker                      Todo Desc needed.
  *    @type string $geodir_filled_by_spam_bot               Todo Desc needed.
  *
  * }
  * @param bool $dummy Optional. Is this a dummy listing? Default false.
  * @return int|string|WP_Error Created post id.
  */
 function geodir_save_listing($request_info = array(), $dummy = false)
 {
     global $wpdb, $current_user;
     $last_post_id = '';
     if (isset($_SESSION['listing']) && !$dummy) {
         $request_info = array();
         $request_session = unserialize($_SESSION['listing']);
         $request_info = array_merge($_REQUEST, $request_session);
     } else {
         if (!isset($_SESSION['listing']) && !$dummy) {
             global $post;
             $request_info['pid'] = $post->ID;
             $request_info['post_title'] = $request_info['post_title'];
             $request_info['listing_type'] = $post->post_type;
             $request_info['post_desc'] = $request_info['content'];
         } else {
             if (!$dummy) {
                 return false;
             }
         }
     }
     /**
      * Filter the request_info array.
      *
      * You can use this filter to modify request_info array.
      *
      * @since 1.0.0
      * @package GeoDirectory
      * @param array $request_info See {@see geodir_save_listing()} for accepted args.
      */
     $request_info = apply_filters('geodir_action_get_request_info', $request_info);
     // Check if we need to save post location as new location
     $location_result = geodir_get_default_location();
     if ($location_result->location_id > 0) {
         if (isset($request_info['post_city']) && isset($request_info['post_region'])) {
             $request_info['post_location'] = array('city' => $request_info['post_city'], 'region' => isset($request_info['post_region']) ? $request_info['post_region'] : '', 'country' => isset($request_info['post_country']) ? $request_info['post_country'] : '', 'geo_lat' => isset($request_info['post_latitude']) ? $request_info['post_latitude'] : '', 'geo_lng' => isset($request_info['post_longitude']) ? $request_info['post_longitude'] : '');
             $post_location_info = $request_info['post_location'];
             if ($location_id = geodir_add_new_location($post_location_info)) {
                 $post_location_id = $location_id;
             }
         } else {
             $post_location_id = $location_result->location_id;
         }
     } else {
         $post_location_id = $location_result->location_id;
     }
     if ($dummy) {
         $post_status = 'publish';
     } else {
         $post_status = geodir_new_post_default_status();
     }
     if (isset($request_info['pid']) && $request_info['pid'] != '') {
         $post_status = get_post_status($request_info['pid']);
     }
     /* fix change of slug on every title edit */
     if (!isset($request_info['post_name'])) {
         $request_info['post_name'] = $request_info['post_title'];
         if (!empty($request_info['pid'])) {
             $post_info = get_post($request_info['pid']);
             if (!empty($post_info) && isset($post_info->post_name)) {
                 $request_info['post_name'] = $post_info->post_name;
             }
         }
     }
     $post = array('post_content' => $request_info['post_desc'], 'post_status' => $post_status, 'post_title' => $request_info['post_title'], 'post_name' => $request_info['post_name'], 'post_type' => $request_info['listing_type']);
     /**
      * Called before a listing is saved to the database.
      *
      * @since 1.0.0
      * @param object $post The post object.
      */
     do_action_ref_array('geodir_before_save_listing', $post);
     $send_post_submit_mail = false;
     // unhook this function so it doesn't loop infinitely
     remove_action('save_post', 'geodir_post_information_save', 10, 2);
     if (isset($request_info['pid']) && $request_info['pid'] != '') {
         $post['ID'] = $request_info['pid'];
         $last_post_id = wp_update_post($post);
     } else {
         $last_post_id = wp_insert_post($post);
         if (!$dummy && $last_post_id) {
             $send_post_submit_mail = true;
             // we move post_submit email from here so the rest of the variables are added to the db first(was breaking permalink in email)
             //geodir_sendEmail('','',$current_user->user_email,$current_user->display_name,'','',$request_info,'post_submit',$last_post_id,$current_user->ID);
         }
     }
     // re-hook this function
     add_action('save_post', 'geodir_post_information_save', 10, 2);
     $post_tags = '';
     if (!isset($request_info['post_tags'])) {
         $post_type = $request_info['listing_type'];
         $post_tags = implode(",", wp_get_object_terms($last_post_id, $post_type . '_tags', array('fields' => 'names')));
     }
     $gd_post_info = array("post_title" => $request_info['post_title'], "post_tags" => isset($request_info['post_tags']) ? $request_info['post_tags'] : $post_tags, "post_status" => $post_status, "post_location_id" => $post_location_id, "claimed" => isset($request_info['claimed']) ? $request_info['claimed'] : '', "businesses" => isset($request_info['a_businesses']) ? $request_info['a_businesses'] : '', "submit_time" => time(), "submit_ip" => $_SERVER['REMOTE_ADDR']);
     $payment_info = array();
     $package_info = array();
     $package_info = (array) geodir_post_package_info($package_info, $post);
     $post_package_id = geodir_get_post_meta($last_post_id, 'package_id');
     if (!empty($package_info) && !$post_package_id) {
         if (isset($package_info['days']) && $package_info['days'] != 0) {
             $payment_info['expire_date'] = date('Y-m-d', strtotime("+" . $package_info['days'] . " days"));
         } else {
             $payment_info['expire_date'] = 'Never';
         }
         $payment_info['package_id'] = $package_info['pid'];
         $payment_info['alive_days'] = $package_info['days'];
         $payment_info['is_featured'] = $package_info['is_featured'];
         $gd_post_info = array_merge($gd_post_info, $payment_info);
     }
     $custom_metaboxes = geodir_post_custom_fields('', 'all', $request_info['listing_type']);
     foreach ($custom_metaboxes as $key => $val) {
         $name = $val['name'];
         $type = $val['type'];
         $extrafields = $val['extra_fields'];
         if (trim($type) == 'address') {
             $prefix = $name . '_';
             $address = $prefix . 'address';
             if (isset($request_info[$address]) && $request_info[$address] != '') {
                 $gd_post_info[$address] = $request_info[$address];
             }
             if ($extrafields != '') {
                 $extrafields = unserialize($extrafields);
                 if (!isset($request_info[$prefix . 'city']) || $request_info[$prefix . 'city'] == '') {
                     $location_result = geodir_get_default_location();
                     $gd_post_info[$prefix . 'city'] = $location_result->city;
                     $gd_post_info[$prefix . 'region'] = $location_result->region;
                     $gd_post_info[$prefix . 'country'] = $location_result->country;
                     $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']';
                     // set all overall post location
                 } else {
                     $gd_post_info[$prefix . 'city'] = $request_info[$prefix . 'city'];
                     $gd_post_info[$prefix . 'region'] = $request_info[$prefix . 'region'];
                     $gd_post_info[$prefix . 'country'] = $request_info[$prefix . 'country'];
                     //----------set post locations when import dummy data-------
                     $location_result = geodir_get_default_location();
                     $gd_post_info['post_locations'] = '[' . $location_result->city_slug . '],[' . $location_result->region_slug . '],[' . $location_result->country_slug . ']';
                     // set all overall post location
                     //-----------------------------------------------------------------
                 }
                 if (isset($extrafields['show_zip']) && $extrafields['show_zip'] && isset($request_info[$prefix . 'zip'])) {
                     $gd_post_info[$prefix . 'zip'] = $request_info[$prefix . 'zip'];
                 }
                 if (isset($extrafields['show_map']) && $extrafields['show_map']) {
                     if (isset($request_info[$prefix . 'latitude']) && $request_info[$prefix . 'latitude'] != '') {
                         $gd_post_info[$prefix . 'latitude'] = $request_info[$prefix . 'latitude'];
                     }
                     if (isset($request_info[$prefix . 'longitude']) && $request_info[$prefix . 'longitude'] != '') {
                         $gd_post_info[$prefix . 'longitude'] = $request_info[$prefix . 'longitude'];
                     }
                     if (isset($request_info[$prefix . 'mapview']) && $request_info[$prefix . 'mapview'] != '') {
                         $gd_post_info[$prefix . 'mapview'] = $request_info[$prefix . 'mapview'];
                     }
                     if (isset($request_info[$prefix . 'mapzoom']) && $request_info[$prefix . 'mapzoom'] != '') {
                         $gd_post_info[$prefix . 'mapzoom'] = $request_info[$prefix . 'mapzoom'];
                     }
                 }
                 // show lat lng
                 if (isset($extrafields['show_latlng']) && $extrafields['show_latlng'] && isset($request_info[$prefix . 'latlng'])) {
                     $gd_post_info[$prefix . 'latlng'] = $request_info[$prefix . 'latlng'];
                 }
             }
         } elseif (trim($type) == 'file') {
             if (isset($request_info[$name])) {
                 $request_files = array();
                 if ($request_info[$name] != '') {
                     $request_files = explode(",", $request_info[$name]);
                 }
                 $extrafields = $extrafields != '' ? maybe_unserialize($extrafields) : NULL;
                 geodir_save_post_file_fields($last_post_id, $name, $request_files, $extrafields);
             }
         } elseif (trim($type) == 'datepicker') {
             $datetime = '';
             if ($request_info[$name] != '') {
                 $date_format = geodir_default_date_format();
                 if (isset($val['extra_fields']) && $val['extra_fields'] != '') {
                     $extra_fields = unserialize($val['extra_fields']);
                     $date_format = isset($extra_fields['date_format']) && $extra_fields['date_format'] != '' ? $extra_fields['date_format'] : $date_format;
                 }
                 $search = array('dd', 'mm', 'yy');
                 $replace = array('d', 'm', 'Y');
                 $date_format = str_replace($search, $replace, $date_format);
                 $post_htmlvar_value = $date_format == 'd/m/Y' ? str_replace('/', '-', $request_info[$name]) : $request_info[$name];
                 // PHP doesn't work well with dd/mm/yyyy format
                 $datetime = date("Y-m-d", strtotime($post_htmlvar_value));
             }
             $gd_post_info[$name] = $datetime;
         } else {
             if ($type == 'multiselect') {
                 if (isset($request_info[$name])) {
                     $gd_post_info[$name] = $request_info[$name];
                 } else {
                     if (isset($request_info['gd_field_' . $name])) {
                         $gd_post_info[$name] = '';
                         /* fix de-select for multiselect */
                     }
                 }
             } else {
                 if (isset($request_info[$name])) {
                     $gd_post_info[$name] = $request_info[$name];
                 }
             }
         }
     }
     if (isset($request_info['post_dummy']) && $request_info['post_dummy'] != '') {
         $gd_post_info['post_dummy'] = $request_info['post_dummy'];
     }
     // Save post detail info in detail table
     if (!empty($gd_post_info)) {
         geodir_save_post_info($last_post_id, $gd_post_info);
     }
     // Set categories to the listing
     if (isset($request_info['post_category']) && !empty($request_info['post_category'])) {
         $post_category = array();
         foreach ($request_info['post_category'] as $taxonomy => $cat) {
             if ($dummy) {
                 $post_category = $cat;
             } else {
                 if (!is_array($cat) && strstr($cat, ',')) {
                     $cat = explode(',', $cat);
                 }
                 if (!empty($cat) && is_array($cat)) {
                     $post_category = array_map('intval', $cat);
                 }
             }
             wp_set_object_terms($last_post_id, $post_category, $taxonomy);
         }
         $post_default_category = isset($request_info['post_default_category']) ? $request_info['post_default_category'] : '';
         $post_category_str = isset($request_info['post_category_str']) ? $request_info['post_category_str'] : '';
         geodir_set_postcat_structure($last_post_id, $taxonomy, $post_default_category, $post_category_str);
     }
     $post_tags = '';
     // Set tags to the listing
     if (isset($request_info['post_tags']) && !is_array($request_info['post_tags']) && !empty($request_info['post_tags'])) {
         $post_tags = explode(",", $request_info['post_tags']);
     } elseif (isset($request_info['post_tags']) && is_array($request_info['post_tags'])) {
         if ($dummy) {
             $post_tags = $request_info['post_tags'];
         }
     } else {
         if ($dummy) {
             $post_tags = array($request_info['post_title']);
         }
     }
     if (is_array($post_tags)) {
         $taxonomy = $request_info['listing_type'] . '_tags';
         wp_set_object_terms($last_post_id, $post_tags, $taxonomy);
     }
     // Insert attechment
     if (isset($request_info['post_images']) && !is_wp_error($last_post_id)) {
         if (!$dummy) {
             $tmpimgArr = trim($request_info['post_images'], ",");
             $tmpimgArr = explode(",", $tmpimgArr);
             geodir_save_post_images($last_post_id, $tmpimgArr, $dummy);
         } else {
             geodir_save_post_images($last_post_id, $request_info['post_images'], $dummy);
         }
     } elseif (!isset($request_info['post_images']) || $request_info['post_images'] == '') {
         /* Delete Attachments
         			$postcurr_images = geodir_get_images($last_post_id);
         			
         			$wpdb->query(
         				$wpdb->prepare(
         					"DELETE FROM ".GEODIR_ATTACHMENT_TABLE." WHERE `post_id` = %d",
         					array($last_post_id)
         				)
         			);
         			geodir_remove_attachments($postcurr_images);
         			
         			$gd_post_featured_img = array();
         			$gd_post_featured_img['featured_image'] = '';
         			geodir_save_post_info($last_post_id, $gd_post_featured_img); 
         			*/
     }
     geodir_remove_temp_images();
     geodir_set_wp_featured_image($last_post_id);
     /**
      * Called after a listing is saved to the database and before any email have been sent.
      *
      * @since 1.0.0
      * @param int $last_post_id The saved post ID.
      * @param array $request_info The post details in an array.
      * @see 'geodir_after_save_listinginfo'
      */
     do_action('geodir_after_save_listing', $last_post_id, $request_info);
     //die;
     if ($send_post_submit_mail) {
         // if new post send out email
         $to_name = geodir_get_client_name($current_user->ID);
         geodir_sendEmail('', '', $current_user->user_email, $to_name, '', '', $request_info, 'post_submit', $last_post_id, $current_user->ID);
     }
     /*
      * Unset the session so we don't loop.
      */
     if (isset($_SESSION['listing'])) {
         unset($_SESSION['listing']);
     }
     return $last_post_id;
 }
 function mhk_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);
     $post_package_id = $package_info->pid;
     ob_start();
     $fields_info = geodir_post_custom_fields($post_package_id, 'default', geodir_get_current_posttype(), $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) {
             $html = '';
             $html_var = '';
             $field_icon = '';
             $variables_array = array();
             if ($type['type'] != 'fieldset') {
                 $variables_array['post_id'] = $post->ID;
                 $variables_array['label'] = __($type['site_title'], GEODIRECTORY_TEXTDOMAIN);
                 $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':
                     if ($field_set_start == 1) {
                         echo '</div><div class="geodir-company_info field-group ' . $type['htmlvar_name'] . '"><h2>' . __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . '</h2>';
                     } else {
                         echo '<h2>' . __($type['site_title'], GEODIRECTORY_TEXTDOMAIN) . '</h2>';
                         $field_set_start = 1;
                     }
                     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 = '';
                         }
                         if (!strstr($post->{$type}['htmlvar_name'], 'http')) {
                             $website = 'http://' . $post->{$type}['htmlvar_name'];
                         } else {
                             $website = $post->{$type}['htmlvar_name'];
                         }
                         $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-website" style="' . $field_icon . '">' . $field_icon_af . '<a href="' . $website . '" target="_blank" ><strong>' . stripslashes(__($type['site_title'], GEODIRECTORY_TEXTDOMAIN)) . '</strong></a></span></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']));
                         }
                         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_TEXTDOMAIN) . ': ' : '&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', 'mm', 'yy');
                         $replace = array('d', 'm', 'Y');
                         $date_format = str_replace($search, $replace, $date_format);
                         $value = '';
                         if ($post->{$type}['htmlvar_name'] != '') {
                             $value = date($date_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-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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . $value . '</div>';
                     }
                     break;
                 case 'text':
                     $html_var = $type['htmlvar_name'];
                     if ($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_TEXTDOMAIN).': ' : '&nbsp;';
                         $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                     } elseif ($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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                     }
                     break;
                 case 'radio':
                     $html_var = $type['htmlvar_name'];
                     $html_val = $post->{$type}['htmlvar_name'];
                     if ($post->{$type}['htmlvar_name'] != '') {
                         if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') {
                             $html_val = __('No', GEODIRECTORY_TEXTDOMAIN);
                         } elseif ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') {
                             $html_val = __('Yes', GEODIRECTORY_TEXTDOMAIN);
                         }
                         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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . $html_val . '</div>';
                     }
                     break;
                 case 'checkbox':
                     $html_var = $type['htmlvar_name'];
                     $html_val = $type['htmlvar_name'];
                     if ($post->{$type}['htmlvar_name'] != '') {
                         if ($post->{$type}['htmlvar_name'] == '1') {
                             $html_val = __('Yes', GEODIRECTORY_TEXTDOMAIN);
                         } else {
                             $html_val = __('No', GEODIRECTORY_TEXTDOMAIN);
                         }
                         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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . $html_val . '</div>';
                     }
                     break;
                 case 'select':
                     $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 = '';
                         } 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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</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 = '';
                         }
                         $option_values = explode(',', $post->{$type}['htmlvar_name']);
                         if ($type['option_values']) {
                             if (strstr($type['option_values'], "/")) {
                                 $option_values = array();
                                 $field_values = explode(',', $type['option_values']);
                                 foreach ($field_values as $data) {
                                     $val = explode('/', $data);
                                     if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) {
                                         $option_values[] = $val[0];
                                     }
                                 }
                             }
                         }
                         $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_TEXTDOMAIN) . ': <br />' : '';
                         $html .= '</span>';
                         if (count($option_values) > 1) {
                             $html .= '<ul>';
                             foreach ($option_values as $val) {
                                 $html .= '<li>' . stripslashes($val) . '</li>';
                             }
                             $html .= '</ul>';
                         } else {
                             $html .= stripslashes(trim($post->{$type}['htmlvar_name'], ','));
                         }
                         $html .= '</div>';
                     }
                     break;
                 case 'textarea':
                     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_TEXTDOMAIN).': ' : '';
                         $html .= '</span>' . 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_more_info_html' . $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_TEXTDOMAIN) . ': ' : '';
                         $html .= '</span>' . stripslashes($post->{$type}['htmlvar_name']) . '</div>';
                     }
                     break;
             }
             if ($html) {
                 do_action('geodir_before_show_' . $html_var);
                 if ($html) {
                     echo apply_filters('geodir_show_' . $html_var, $html, $variables_array);
                 }
                 do_action('geodir_after_show_' . $html_var);
             }
         }
         //echo '</div>';
     }
     return $html = ob_get_clean();
 }
function geodir_payment_display_expire_date_on_detail()
{
    global $post;
    $show_expire_date = get_option('geodir_listing_expiry') && get_option('geodir_payment_expire_date_on_detail');
    $html = '';
    if ($show_expire_date && get_current_user_id()) {
        if (geodir_is_page('detail') && !empty($post) && isset($post->post_author) && $post->post_author == get_current_user_id()) {
            $post_expire_date = geodir_get_post_meta($post->ID, 'expire_date', true);
            $post_expire_time = strtotime($post_expire_date);
            $current_date = date_i18n('Y-m-d', current_time('timestamp'));
            $expire_date_text = __('Unknown', GEODIRPAYMENT_TEXTDOMAIN);
            $expire_date_class = 'geodir-expire-unknown';
            if ($post_expire_date != '0000-00-00' && $post_expire_date != '' && (strtolower($post_expire_date) == 'never' || $post_expire_time > strtotime(date('01-01-1970')))) {
                if (strtolower($post_expire_date) == 'never') {
                    $expire_date_text = __('Never', GEODIRPAYMENT_TEXTDOMAIN);
                    $expire_date_class = 'geodir-expire-never';
                } else {
                    $expire_date_text = geodir_payment_time_diff($post_expire_time);
                    $expire_date_text = date_i18n(geodir_default_date_format(), $post_expire_time) . ' (<font class="geodir-expire-diff">' . $expire_date_text . '</font>)';
                    $expire_date_class = $post_expire_time >= strtotime($current_date) ? 'geodir-expire-left' : 'geodir-expire-overdue';
                }
            }
            $html = '<span class="geodir-expire-date ' . $expire_date_class . '"><font class="geodir-expire-label">' . __('Expire date: ', GEODIRPAYMENT_TEXTDOMAIN) . '</font><font class="geodir-expire-text">' . $expire_date_text . '</font></span>';
            $html = '<p class="geodir_expire_date"><i class="fa fa-calendar"></i> ' . $html . '</p>';
        }
    }
    if ($html != '') {
        echo apply_filters('geodir_payment_filter_expire_date_on_detail', $html);
    }
}
Example #5
0
 /**
  * Show listing info depending on field location.
  *
  * @since 1.0.0
  * @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':
                     if ($field_set_start == 1) {
                         echo '</div><div class="geodir-company_info field-group ' . $type['htmlvar_name'] . '"><h2>' . __($type['site_title'], 'geodirectory') . '</h2>';
                     } else {
                         echo '<h2>' . __($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>';
                         } 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 = '';
                         }
                         if (!strstr($post->{$type}['htmlvar_name'], 'http')) {
                             $website = 'http://' . $post->{$type}['htmlvar_name'];
                         } else {
                             $website = $post->{$type}['htmlvar_name'];
                         }
                         $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 $type['site_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', stripslashes(__($type['site_title'], 'geodirectory')), $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:' . stripslashes($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'];
                     if ($post->{$type}['htmlvar_name'] != '') {
                         if ($post->{$type}['htmlvar_name'] == 'f' || $post->{$type}['htmlvar_name'] == '0') {
                             $html_val = __('No', 'geodirectory');
                         } elseif ($post->{$type}['htmlvar_name'] == 't' || $post->{$type}['htmlvar_name'] == '1') {
                             $html_val = __('Yes', '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-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'];
                     $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 = '';
                         } 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']) {
                         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>' . stripslashes($post->{$type}['htmlvar_name']) . '</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 = '';
                         }
                         $option_values = explode(',', $post->{$type}['htmlvar_name']);
                         if ($type['option_values']) {
                             if (strstr($type['option_values'], "/")) {
                                 $option_values = array();
                                 $field_values = explode(',', $type['option_values']);
                                 foreach ($field_values as $data) {
                                     $val = explode('/', $data);
                                     if (isset($val[1]) && in_array($val[1], explode(',', $post->{$type}['htmlvar_name']))) {
                                         $option_values[] = $val[0];
                                     }
                                 }
                             }
                         }
                         $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>' . stripslashes($val) . '</li>';
                             }
                             $html .= '</ul>';
                         } else {
                             $html .= stripslashes(trim($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>' . 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 .= '<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':
                     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();
 }