/**
             *
             * @global object $wp WordPress object.
             *
             * @param array $args
             * @param array $instance
             */
            public function widget($args, $instance)
            {
                global $wp;
                extract($args, EXTR_SKIP);
                $title = empty($instance['title']) ? __('Popular Locations', GEODIRLOCATION_TEXTDOMAIN) : apply_filters('geodir_popular_location_widget_title', __($instance['title'], GEODIRLOCATION_TEXTDOMAIN));
                echo $before_widget;
                ?>
			<div class="geodir-category-list-in clearfix">
				<div class="geodir-cat-list clearfix">
				  <?php 
                echo $before_title . __($title) . $after_title;
                ?>
			
			<?php 
                $location_terms = geodir_get_current_location_terms();
                //locations in sessions
                // get all the cities in current region
                $args = array('what' => 'city', 'city_val' => '', 'region_val' => '', 'country_val' => '', 'country_non_restricted' => '', 'region_non_restricted' => '', 'city_non_restricted' => '', 'filter_by_non_restricted' => true, 'compare_operator' => 'like', 'country_column_name' => 'country_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => true, 'order_by' => ' asc ', 'no_of_records' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => ''));
                if (!empty($location_terms)) {
                    if (isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') {
                        $args['region_val'] = $location_terms['gd_region'];
                        $args['country_val'] = $location_terms['gd_country'];
                    } else {
                        if (isset($location_terms['gd_country']) && $location_terms['gd_country'] != '') {
                            $args['country_val'] = $location_terms['gd_country'];
                        }
                    }
                }
                echo $geodir_cities_list = geodir_get_location_array($args, false);
                ?>
            	</div>
            </div>
            <?php 
                echo $after_widget;
            }
/**
 * add location variables in geodirectory title parameter for single post.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wp WordPress object.
 * @param string $title The title parameter.
 * @param object $post Post object.
 * @return string Modified post title.
 */
function geodir_single_post_title($title, $post)
{
    global $wp;
    if ($post->post_title == 'Location' && geodir_is_geodir_page()) {
        $title = defined('GD_LOCATION') ? GD_LOCATION : __('Location', 'geodirectory');
        $location_array = geodir_get_current_location_terms('query_vars');
        if (!empty($location_array)) {
            $location_array = array_reverse($location_array);
            $actual_location_name = function_exists('get_actual_location_name') ? true : false;
            foreach ($location_array as $location_type => $location) {
                $gd_location_link_text = preg_replace('/-(\\d+)$/', '', $location);
                $gd_location_link_text = preg_replace('/[_-]/', ' ', $gd_location_link_text);
                $gd_location_link_text = ucwords($gd_location_link_text);
                $gd_location_link_text = __($gd_location_link_text, 'geodirectory');
                if ($actual_location_name) {
                    $location_type = strpos($location_type, 'gd_') === 0 ? substr($location_type, 3) : $location_type;
                    $gd_location_link_text = get_actual_location_name($location_type, $location, true);
                }
                $title .= ' ' . $gd_location_link_text;
            }
            $gd_post_type = geodir_get_current_posttype();
            $post_type_info = get_post_type_object($gd_post_type);
            if (get_query_var($gd_post_type . 'category')) {
                $gd_taxonomy = $gd_post_type . 'category';
            } else {
                if (get_query_var($gd_post_type . '_tags')) {
                    $gd_taxonomy = $gd_post_type . '_tags';
                }
            }
            if (!empty($gd_taxonomy)) {
                $term_array = explode("/", trim($wp->query_vars[$gd_taxonomy], "/"));
                if (!empty($term_array)) {
                    foreach ($term_array as $term) {
                        $term_link_text = preg_replace('/-(\\d+)$/', '', $term);
                        $term_link_text = preg_replace('/[_-]/', ' ', $term_link_text);
                    }
                    $title .= ' ' . ucwords($term_link_text);
                }
            }
        }
    }
    return $title;
}
/**
 *
 * @global object $wp WordPress object.
 *
 * @param $atts
 * @return string
 */
function geodir_sc_popular_location($atts)
{
    global $wp;
    $location_terms = geodir_get_current_location_terms();
    //locations in sessions
    // get all the cities in current region
    $args = array('what' => 'city', 'city_val' => '', 'region_val' => '', 'country_val' => '', 'country_non_restricted' => '', 'region_non_restricted' => '', 'city_non_restricted' => '', 'filter_by_non_restricted' => true, 'compare_operator' => 'like', 'country_column_name' => 'country_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => true, 'order_by' => ' asc ', 'no_of_records' => '', 'format' => array('type' => 'list', 'container_wrapper' => 'ul', 'container_wrapper_attr' => '', 'item_wrapper' => 'li', 'item_wrapper_attr' => ''));
    if (!empty($location_terms)) {
        if (isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') {
            $args['region_val'] = $location_terms['gd_region'];
            $args['country_val'] = $location_terms['gd_country'];
        } else {
            if (isset($location_terms['gd_country']) && $location_terms['gd_country'] != '') {
                $args['country_val'] = $location_terms['gd_country'];
            }
        }
    }
    ob_start();
    echo '<div class="geodir-sc-popular-location">';
    echo $geodir_cities_list = geodir_get_location_array($args, false);
    echo '</div>';
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
}
/**
 * Adds meta keywords and description for SEO.
 *
 * @since 1.0.0
 * @since 1.5.4 Modified to replace %location% from meta when Yoast SEO plugin active.
 * @package GeoDirectory
 * @global object $wpdb WordPress Database object.
 * @global object $post The current post object.
 * @global object $wp_query WordPress Query object.
 * @global array $geodir_addon_list List of active GeoDirectory extensions.
 */
function geodir_add_meta_keywords()
{
    global $wp, $post, $wp_query, $wpdb, $geodir_addon_list;
    $is_geodir_page = geodir_is_geodir_page();
    if (!$is_geodir_page) {
        return;
    }
    // if non GD page, bail
    $use_gd_meta = true;
    if (class_exists('WPSEO_Frontend') || class_exists('All_in_One_SEO_Pack')) {
        $use_gd_meta = false;
        if (geodir_is_page('search')) {
            $use_gd_meta = true;
        }
    }
    if (!$use_gd_meta) {
        return;
    }
    // bail if Yoast Wordpress SEO or All_in_One_SEO_Pack active.
    $current_term = $wp_query->get_queried_object();
    $all_postypes = geodir_get_posttypes();
    $geodir_taxonomies = geodir_get_taxonomies('', true);
    $meta_desc = '';
    $meta_key = '';
    if (isset($current_term->ID) && $current_term->ID == geodir_location_page_id()) {
        /**
         * Filter SEO meta location description.
         *
         * @since 1.0.0
         */
        $meta_desc = apply_filters('geodir_seo_meta_location_description', '');
        $meta_desc .= '';
    }
    if (have_posts() && is_single() or is_page()) {
        while (have_posts()) {
            the_post();
            if (has_excerpt()) {
                $out_excerpt = strip_tags(strip_shortcodes(get_the_excerpt()));
                if (empty($out_excerpt)) {
                    $out_excerpt = strip_tags(do_shortcode(get_the_excerpt()));
                }
                $out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", $out_excerpt);
            } else {
                $out_excerpt = str_replace(array("\r\n", "\r", "\n"), "", $post->post_content);
                $out_excerpt = strip_tags(strip_shortcodes($out_excerpt));
                if (empty($out_excerpt)) {
                    $out_excerpt = strip_tags(do_shortcode($out_excerpt));
                    // parse short code from content
                }
                $out_excerpt = trim(wp_trim_words($out_excerpt, 35, ''), '.!?,;:-');
            }
            $meta_desc .= $out_excerpt;
        }
    } elseif ((is_category() || is_tag()) && isset($current_term->taxonomy) && in_array($current_term->taxonomy, $geodir_taxonomies)) {
        if (is_category()) {
            $meta_desc .= __("Posts related to Category:", 'geodirectory') . " " . ucfirst(single_cat_title("", FALSE));
        } elseif (is_tag()) {
            $meta_desc .= __("Posts related to Tag:", 'geodirectory') . " " . ucfirst(single_tag_title("", FALSE));
        }
    } elseif (isset($current_term->taxonomy) && in_array($current_term->taxonomy, $geodir_taxonomies)) {
        $meta_desc .= isset($current_term->description) ? $current_term->description : '';
    }
    $geodir_post_type = geodir_get_current_posttype();
    $geodir_post_type_info = get_post_type_object($geodir_post_type);
    $geodir_is_page_listing = geodir_is_page('listing') ? true : false;
    $category_taxonomy = geodir_get_taxonomies($geodir_post_type);
    $tag_taxonomy = geodir_get_taxonomies($geodir_post_type, true);
    $geodir_is_category = isset($category_taxonomy[0]) && get_query_var($category_taxonomy[0]) ? get_query_var($category_taxonomy[0]) : false;
    $geodir_is_tag = isset($tag_taxonomy[0]) && get_query_var($tag_taxonomy[0]) ? true : false;
    $geodir_is_search = geodir_is_page('search') ? true : false;
    $geodir_is_location = geodir_is_page('location') ? true : false;
    $geodir_location_manager = isset($geodir_addon_list['geodir_location_manager']) && ($geodir_addon_list['geodir_location_manager'] = 'yes' ? true : false);
    $godir_location_terms = geodir_get_current_location_terms('query_vars');
    $gd_city = $geodir_location_manager && isset($godir_location_terms['gd_city']) ? $godir_location_terms['gd_city'] : NULL;
    $gd_region = $geodir_location_manager && isset($godir_location_terms['gd_region']) ? $godir_location_terms['gd_region'] : NULL;
    $gd_country = $geodir_location_manager && isset($godir_location_terms['gd_country']) ? $godir_location_terms['gd_country'] : NULL;
    $replace_location = __('Everywhere', 'geodirectory');
    $location_id = NULL;
    if ($geodir_location_manager) {
        $sql = $wpdb->prepare("SELECT location_id FROM " . POST_LOCATION_TABLE . " WHERE city_slug=%s ORDER BY location_id ASC LIMIT 1", array($gd_city));
        $location_id = (int) $wpdb->get_var($sql);
        $location_type = geodir_what_is_current_location();
        if ($location_type == 'city') {
            $replace_location = geodir_get_current_location(array('what' => 'city', 'echo' => false));
        } elseif ($location_type == 'region') {
            $replace_location = geodir_get_current_location(array('what' => 'region', 'echo' => false));
        } elseif ($location_type == 'country') {
            $replace_location = geodir_get_current_location(array('what' => 'country', 'echo' => false));
            $replace_location = __($replace_location, 'geodirectory');
        }
        $country = get_query_var('gd_country');
        $region = get_query_var('gd_region');
        $city = get_query_var('gd_city');
        $current_location = '';
        if ($country != '') {
            $current_location = get_actual_location_name('country', $country, true);
        }
        if ($region != '') {
            $current_location = get_actual_location_name('region', $region);
        }
        if ($city != '') {
            $current_location = get_actual_location_name('city', $city);
        }
        $replace_location = $current_location != '' ? $current_location : $replace_location;
    }
    $geodir_meta_keys = '';
    $geodir_meta_desc = '';
    if ($is_geodir_page && !empty($geodir_post_type_info)) {
        if ($geodir_is_page_listing || $geodir_is_search || geodir_is_page('add-listing')) {
            $geodir_meta_keys = isset($geodir_post_type_info->seo['meta_keyword']) && $geodir_post_type_info->seo['meta_keyword'] != '' ? $geodir_post_type_info->seo['meta_keyword'] : $geodir_meta_keys;
            $geodir_meta_desc = isset($geodir_post_type_info->description) ? $geodir_post_type_info->description : $geodir_meta_desc;
            $geodir_meta_desc = isset($geodir_post_type_info->seo['meta_description']) && $geodir_post_type_info->seo['meta_description'] != '' ? $geodir_post_type_info->seo['meta_description'] : $geodir_meta_desc;
            if ($geodir_is_category) {
                $category = $geodir_is_category ? get_term_by('slug', $geodir_is_category, $category_taxonomy[0]) : NULL;
                if (isset($category->term_id) && !empty($category->term_id)) {
                    $category_id = $category->term_id;
                    $category_desc = trim($category->description) != '' ? trim($category->description) : get_tax_meta($category_id, 'ct_cat_top_desc', false, $geodir_post_type);
                    if ($location_id) {
                        $option_name = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_id;
                        $cat_loc_option = get_option($option_name);
                        $gd_cat_loc_default = !empty($cat_loc_option) && isset($cat_loc_option['gd_cat_loc_default']) && $cat_loc_option['gd_cat_loc_default'] > 0 ? true : false;
                        if (!$gd_cat_loc_default) {
                            $option_name = 'geodir_cat_loc_' . $geodir_post_type . '_' . $category_id . '_' . $location_id;
                            $option = get_option($option_name);
                            $category_desc = isset($option['gd_cat_loc_desc']) && trim($option['gd_cat_loc_desc']) != '' ? trim($option['gd_cat_loc_desc']) : $category_desc;
                        }
                    }
                    $geodir_meta_desc = __("Posts related to Category:", 'geodirectory') . " " . ucfirst(single_cat_title("", FALSE)) . '. ' . $category_desc;
                }
            } else {
                if ($geodir_is_tag) {
                    $geodir_meta_desc = __("Posts related to Tag:", 'geodirectory') . " " . ucfirst(single_tag_title("", FALSE)) . '. ' . $geodir_meta_desc;
                }
            }
        }
    }
    $gd_page = '';
    if (geodir_is_page('home')) {
        $gd_page = 'home';
        $meta_desc = get_option('geodir_meta_desc_homepage') ? get_option('geodir_meta_desc_homepage') : $meta_desc;
    } elseif (geodir_is_page('detail')) {
        $gd_page = 'detail';
        $meta_desc = get_option('geodir_meta_desc_detail') ? get_option('geodir_meta_desc_detail') : $meta_desc;
    } elseif (geodir_is_page('pt')) {
        $gd_page = 'pt';
        $meta_desc = get_option('geodir_meta_desc_pt') ? get_option('geodir_meta_desc_pt') : $meta_desc;
    } elseif (geodir_is_page('listing')) {
        $gd_page = 'listing';
        $meta_desc = get_option('geodir_meta_desc_listing') ? get_option('geodir_meta_desc_listing') : $meta_desc;
    } elseif (geodir_is_page('location')) {
        $gd_page = 'location';
        $meta_desc = get_option('geodir_meta_desc_location') ? get_option('geodir_meta_desc_location') : $meta_desc;
        $meta_desc = apply_filters('geodir_seo_meta_location_description', $meta_desc);
    } elseif (geodir_is_page('search')) {
        $gd_page = 'search';
        $meta_desc = get_option('geodir_meta_desc_search') ? get_option('geodir_meta_desc_search') : $meta_desc;
    } elseif (geodir_is_page('add-listing')) {
        $gd_page = 'add-listing';
        $meta_desc = get_option('geodir_meta_desc_add-listing') ? get_option('geodir_meta_desc_add-listing') : $meta_desc;
    } elseif (geodir_is_page('author')) {
        $gd_page = 'author';
        $meta_desc = get_option('geodir_meta_desc_author') ? get_option('geodir_meta_desc_author') : $meta_desc;
    } elseif (geodir_is_page('login')) {
        $gd_page = 'login';
        $meta_desc = get_option('geodir_meta_desc_login') ? get_option('geodir_meta_desc_login') : $meta_desc;
    } elseif (geodir_is_page('listing-success')) {
        $gd_page = 'listing-success';
        $meta_desc = get_option('geodir_meta_desc_listing-success') ? get_option('geodir_meta_desc_listing-success') : $meta_desc;
    }
    /*
    $geodir_meta_desc = $geodir_meta_desc != '' ? $geodir_meta_desc : $meta_desc;
    if ($geodir_meta_desc != '') {
        $geodir_meta_desc = strip_tags($geodir_meta_desc);
        $geodir_meta_desc = esc_html($geodir_meta_desc);
        $geodir_meta_desc = wp_html_excerpt($geodir_meta_desc, 1000, '.');
        $geodir_meta_desc = isset($replace_location) ? str_replace('%location%', $replace_location, $geodir_meta_desc) : $geodir_meta_desc;
    
        $meta_desc = $geodir_meta_desc != '' ? $geodir_meta_desc : $meta_desc;
    }
    */
    if ($meta_desc) {
        $meta_desc = stripslashes_deep($meta_desc);
        /**
         * Filter page description to replace variables.
         *
         * @since 1.5.4
         * @param string $title The page description including variables.
         * @param string $gd_page The GeoDirectory page type if any.
         */
        $meta_desc = apply_filters('geodir_seo_meta_description_pre', __($meta_desc, 'geodirectory'), $gd_page, '');
        /**
         * Filter SEO meta description.
         *
         * @since 1.0.0
         * @param string $meta_desc Meta description content.
         */
        echo apply_filters('geodir_seo_meta_description', '<meta name="description" content="' . $meta_desc . '" />', $meta_desc);
    }
    // meta keywords
    if (isset($post->post_type) && in_array($post->post_type, $all_postypes)) {
        $place_tags = wp_get_post_terms($post->ID, $post->post_type . '_tags', array("fields" => "names"));
        $place_cats = wp_get_post_terms($post->ID, $post->post_type . 'category', array("fields" => "names"));
        $meta_key .= implode(", ", array_merge((array) $place_cats, (array) $place_tags));
    } else {
        $posttags = get_the_tags();
        if ($posttags) {
            foreach ($posttags as $tag) {
                $meta_key .= $tag->name . ' ';
            }
        } else {
            $tags = get_tags(array('orderby' => 'count', 'order' => 'DESC'));
            $xt = 1;
            foreach ($tags as $tag) {
                if ($xt <= 20) {
                    $meta_key .= $tag->name . ", ";
                }
                $xt++;
            }
        }
    }
    $meta_key = $meta_key != '' ? rtrim(trim($meta_key), ",") : $meta_key;
    $geodir_meta_keys = $geodir_meta_keys != '' ? $meta_key != '' ? $meta_key . ', ' . $geodir_meta_keys : $geodir_meta_keys : $meta_key;
    if ($geodir_meta_keys != '') {
        $geodir_meta_keys = strip_tags($geodir_meta_keys);
        $geodir_meta_keys = esc_html($geodir_meta_keys);
        $geodir_meta_keys = geodir_strtolower($geodir_meta_keys);
        $geodir_meta_keys = wp_html_excerpt($geodir_meta_keys, 1000, '');
        $geodir_meta_keys = str_replace('%location%', $replace_location, $geodir_meta_keys);
        $meta_key = rtrim(trim($geodir_meta_keys), ",");
    }
    if ($meta_key) {
        $meta_key = stripslashes_deep($meta_key);
        /**
         * Filter SEO meta keywords.
         *
         * @since 1.0.0
         * @param string $meta_desc Meta keywords.
         */
        echo apply_filters('geodir_seo_meta_keywords', '<meta name="keywords" content="' . $meta_key . '" />', $meta_key);
    }
}
/**
 * Returns the post type link with parameters.
 *
 * @since 1.0.0
 * @since 1.5.5 Fixed post type archive link for selected location.
 * @package GeoDirectory
 *
 * @global bool $geodir_add_location_url If true it will add location name in url.
 * @global object $post WordPress Post object.
 *
 * @param string $link The post link.
 * @param string $post_type The post type.
 * @return string The modified link.
 */
function geodir_posttype_link($link, $post_type)
{
    global $geodir_add_location_url, $post;
    $location_terms = array();
    if (in_array($post_type, geodir_get_posttypes())) {
        if (get_option('geodir_add_location_url') && isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
            if (geodir_is_page('detail') && !empty($post) && isset($post->country_slug)) {
                $location_terms = array('gd_country' => $post->country_slug, 'gd_region' => $post->region_slug, 'gd_city' => $post->city_slug);
            } else {
                $location_terms = geodir_get_current_location_terms('query_vars');
            }
            $location_terms = geodir_remove_location_terms($location_terms);
            if (!empty($location_terms)) {
                if (get_option('permalink_structure') != '') {
                    $location_terms = implode("/", $location_terms);
                    $location_terms = rtrim($location_terms, '/');
                    $link .= urldecode($location_terms) . '/';
                } else {
                    $link = geodir_getlink($link, $location_terms);
                }
            }
        }
    }
    return $link;
}
Beispiel #6
0
/**
 * Main function that generates breadcrumb for all pages.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wp_query WordPress Query object.
 * @global object $post The current post object.
 */
function geodir_breadcrumb()
{
    global $wp_query, $geodir_add_location_url;
    /**
     * Filter breadcrumb separator.
     *
     * @since 1.0.0
     */
    $separator = apply_filters('geodir_breadcrumb_separator', ' > ');
    if (!is_home()) {
        $breadcrumb = '';
        $url_categoris = '';
        $breadcrumb .= '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
        /**
         * Filter breadcrumb's first link.
         *
         * @since 1.0.0
         */
        $breadcrumb .= '<li>' . apply_filters('geodir_breadcrumb_first_link', '<a href="' . get_option('home') . '">' . __('Home', 'geodirectory') . '</a>') . '</li>';
        $gd_post_type = geodir_get_current_posttype();
        $post_type_info = get_post_type_object($gd_post_type);
        remove_filter('post_type_archive_link', 'geodir_get_posttype_link');
        $listing_link = get_post_type_archive_link($gd_post_type);
        add_filter('post_type_archive_link', 'geodir_get_posttype_link', 10, 2);
        $listing_link = rtrim($listing_link, '/');
        $listing_link .= '/';
        $post_type_for_location_link = $listing_link;
        $location_terms = geodir_get_current_location_terms('query_vars', $gd_post_type);
        $location_link = $post_type_for_location_link;
        if (geodir_is_page('detail') || geodir_is_page('listing')) {
            global $post;
            $is_location_last = '';
            $is_taxonomy_last = '';
            $breadcrumb .= '<li>';
            if (get_query_var($gd_post_type . 'category')) {
                $gd_taxonomy = $gd_post_type . 'category';
            } elseif (get_query_var($gd_post_type . '_tags')) {
                $gd_taxonomy = $gd_post_type . '_tags';
            }
            $breadcrumb .= $separator . '<a href="' . $listing_link . '">' . __(ucfirst($post_type_info->label), 'geodirectory') . '</a>';
            if (!empty($gd_taxonomy) || geodir_is_page('detail')) {
                $is_location_last = false;
            } else {
                $is_location_last = true;
            }
            if (!empty($gd_taxonomy) && geodir_is_page('listing')) {
                $is_taxonomy_last = true;
            } else {
                $is_taxonomy_last = false;
            }
            if (!empty($location_terms)) {
                $geodir_get_locations = function_exists('get_actual_location_name') ? true : false;
                foreach ($location_terms as $key => $location_term) {
                    if ($location_term != '') {
                        $gd_location_link_text = preg_replace('/-(\\d+)$/', '', $location_term);
                        $gd_location_link_text = preg_replace('/[_-]/', ' ', $gd_location_link_text);
                        $gd_location_link_text = ucfirst($gd_location_link_text);
                        $location_term_actual_country = '';
                        $location_term_actual_region = '';
                        $location_term_actual_city = '';
                        if ($geodir_get_locations) {
                            if ($key == 'gd_country') {
                                $location_term_actual_country = get_actual_location_name('country', $location_term, true);
                            } else {
                                if ($key == 'gd_region') {
                                    $location_term_actual_region = get_actual_location_name('region', $location_term, true);
                                } else {
                                    if ($key == 'gd_city') {
                                        $location_term_actual_city = get_actual_location_name('city', $location_term, true);
                                    }
                                }
                            }
                        } else {
                            $location_info = geodir_get_location();
                            if (!empty($location_info) && isset($location_info->location_id)) {
                                if ($key == 'gd_country') {
                                    $location_term_actual_country = __($location_info->country, 'geodirectory');
                                } else {
                                    if ($key == 'gd_region') {
                                        $location_term_actual_region = __($location_info->region, 'geodirectory');
                                    } else {
                                        if ($key == 'gd_city') {
                                            $location_term_actual_city = __($location_info->city, 'geodirectory');
                                        }
                                    }
                                }
                            }
                        }
                        if ($is_location_last && $key == 'gd_country' && !(isset($location_terms['gd_region']) && $location_terms['gd_region'] != '') && !(isset($location_terms['gd_city']) && $location_terms['gd_city'] != '')) {
                            $breadcrumb .= $location_term_actual_country != '' ? $separator . $location_term_actual_country : $separator . $gd_location_link_text;
                        } else {
                            if ($is_location_last && $key == 'gd_region' && !(isset($location_terms['gd_city']) && $location_terms['gd_city'] != '')) {
                                $breadcrumb .= $location_term_actual_region != '' ? $separator . $location_term_actual_region : $separator . $gd_location_link_text;
                            } else {
                                if ($is_location_last && $key == 'gd_city') {
                                    $breadcrumb .= $location_term_actual_city != '' ? $separator . $location_term_actual_city : $separator . $gd_location_link_text;
                                } else {
                                    if (get_option('permalink_structure') != '') {
                                        $location_link .= $location_term . '/';
                                    } else {
                                        $location_link .= "&{$key}=" . $location_term;
                                    }
                                    if ($key == 'gd_country' && $location_term_actual_country != '') {
                                        $gd_location_link_text = $location_term_actual_country;
                                    } else {
                                        if ($key == 'gd_region' && $location_term_actual_region != '') {
                                            $gd_location_link_text = $location_term_actual_region;
                                        } else {
                                            if ($key == 'gd_city' && $location_term_actual_city != '') {
                                                $gd_location_link_text = $location_term_actual_city;
                                            }
                                        }
                                    }
                                    $breadcrumb .= $separator . '<a href="' . $location_link . '">' . $gd_location_link_text . '</a>';
                                }
                            }
                        }
                    }
                }
            }
            if (!empty($gd_taxonomy)) {
                $term_index = 1;
                if (get_query_var($gd_post_type . '_tags')) {
                    $cat_link = $listing_link . 'tags/';
                } else {
                    $cat_link = $listing_link;
                }
                foreach ($location_terms as $key => $location_term) {
                    if ($location_term != '') {
                        if (get_option('permalink_structure') != '') {
                            $cat_link .= $location_term . '/';
                        }
                    }
                }
                $term_array = explode("/", trim($wp_query->query[$gd_taxonomy], "/"));
                foreach ($term_array as $term) {
                    $term_link_text = preg_replace('/-(\\d+)$/', '', $term);
                    $term_link_text = preg_replace('/[_-]/', ' ', $term_link_text);
                    // get term actual name
                    $term_info = get_term_by('slug', $term, $gd_taxonomy, 'ARRAY_A');
                    if (!empty($term_info) && isset($term_info['name']) && $term_info['name'] != '') {
                        $term_link_text = urldecode($term_info['name']);
                    } else {
                        $term_link_text = ucwords(urldecode($term_link_text));
                    }
                    if ($term_index == count($term_array) && $is_taxonomy_last) {
                        $breadcrumb .= $separator . $term_link_text;
                    } else {
                        $cat_link .= $term . '/';
                        $breadcrumb .= $separator . '<a href="' . $cat_link . '">' . $term_link_text . '</a>';
                    }
                    $term_index++;
                }
            }
            if (geodir_is_page('detail')) {
                $breadcrumb .= $separator . get_the_title();
            }
            $breadcrumb .= '</li>';
        } elseif (geodir_is_page('author')) {
            $user_id = get_current_user_id();
            $author_link = get_author_posts_url($user_id);
            $default_author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => 'gd_place'), false);
            /**
             * Filter author page link.
             *
             * @since 1.0.0
             * @param string $default_author_link Default author link.
             * @param int $user_id Author ID.
             */
            $default_author_link = apply_filters('geodir_dashboard_author_link', $default_author_link, $user_id);
            $breadcrumb .= '<li>';
            $breadcrumb .= $separator . '<a href="' . $default_author_link . '">' . __('My Dashboard', 'geodirectory') . '</a>';
            if (isset($_REQUEST['list'])) {
                $author_link = geodir_getlink($author_link, array('geodir_dashbord' => 'true', 'stype' => $_REQUEST['stype']), false);
                /**
                 * Filter author page link.
                 *
                 * @since 1.0.0
                 * @param string $author_link Author page link.
                 * @param int $user_id Author ID.
                 * @param string $_REQUEST['stype'] Post type.
                 */
                $author_link = apply_filters('geodir_dashboard_author_link', $author_link, $user_id, $_REQUEST['stype']);
                $breadcrumb .= $separator . '<a href="' . $author_link . '">' . __(ucfirst($post_type_info->label), 'geodirectory') . '</a>';
                $breadcrumb .= $separator . ucfirst(__('My', 'geodirectory') . ' ' . $_REQUEST['list']);
            } else {
                $breadcrumb .= $separator . __(ucfirst($post_type_info->label), 'geodirectory');
            }
            $breadcrumb .= '</li>';
        } elseif (is_category() || is_single()) {
            $category = get_the_category();
            if (is_category()) {
                $breadcrumb .= '<li>' . $separator . $category[0]->cat_name . '</li>';
            }
            if (is_single()) {
                $breadcrumb .= '<li>' . $separator . '<a href="' . get_category_link($category[0]->term_id) . '">' . $category[0]->cat_name . '</a></li>';
                $breadcrumb .= '<li>' . $separator . get_the_title() . '</li>';
            }
            /* End of my version ##################################################### */
        } else {
            if (is_page()) {
                $page_title = get_the_title();
                if (geodir_is_page('location')) {
                    $page_title = defined('GD_LOCATION') ? GD_LOCATION : __('Location', 'geodirectory');
                }
                $breadcrumb .= '<li>' . $separator;
                $breadcrumb .= stripslashes_deep($page_title);
                $breadcrumb .= '</li>';
            } else {
                if (is_tag()) {
                    $breadcrumb .= "<li> " . $separator . single_tag_title('', false) . '</li>';
                } else {
                    if (is_day()) {
                        $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                        the_time('F jS, Y');
                        $breadcrumb .= '</li>';
                    } else {
                        if (is_month()) {
                            $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                            the_time('F, Y');
                            $breadcrumb .= '</li>';
                        } else {
                            if (is_year()) {
                                $breadcrumb .= "<li> " . $separator . __(" Archive for", 'geodirectory') . " ";
                                the_time('Y');
                                $breadcrumb .= '</li>';
                            } else {
                                if (is_author()) {
                                    $breadcrumb .= "<li> " . $separator . __(" Author Archive", 'geodirectory');
                                    $breadcrumb .= '</li>';
                                } else {
                                    if (isset($_GET['paged']) && !empty($_GET['paged'])) {
                                        $breadcrumb .= "<li>" . $separator . __("Blog Archives", 'geodirectory');
                                        $breadcrumb .= '</li>';
                                    } else {
                                        if (is_search()) {
                                            $breadcrumb .= "<li> " . $separator . __(" Search Results", 'geodirectory');
                                            $breadcrumb .= '</li>';
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        $breadcrumb .= '</ul></div>';
        /**
         * Filter breadcrumb html output.
         *
         * @since 1.0.0
         * @param string $breadcrumb Breadcrumb HTML.
         * @param string $separator Breadcrumb separator.
         */
        echo $breadcrumb = apply_filters('geodir_breadcrumb', $breadcrumb, $separator);
    }
}
/**
 * Returns the post type link with parameters.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param string $link The post link.
 * @param string $post_type The post type.
 * @return string The modified link.
 */
function geodir_posttype_link($link, $post_type)
{
    global $geodir_add_location_url;
    $location_terms = array();
    if (in_array($post_type, geodir_get_posttypes())) {
        if (get_option('geodir_add_location_url') && isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
            $location_terms = geodir_get_current_location_terms('query_vars');
            if (!empty($location_terms)) {
                if (get_option('permalink_structure') != '') {
                    $location_terms = implode("/", $location_terms);
                    $location_terms = rtrim($location_terms, '/');
                    return $link . urldecode($location_terms) . '/';
                } else {
                    return geodir_getlink($link, $location_terms);
                }
            }
        }
    }
    return $link;
}
/**
 * Returns location link based on location type.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param string $which_location Location link type. Default: 'current'.
 * @return bool|string
 */
function geodir_get_location_link($which_location = 'current')
{
    $location_link = get_permalink(geodir_location_page_id());
    if (get_option('permalink_structure') != '') {
        //$location_prefix = get_option('geodir_location_prefix');
        //$location_link = substr_replace($location_link, $location_prefix, strpos($location_link, 'location'), strlen('location'));
    }
    if ($which_location == 'base') {
        return $location_link;
    } else {
        $location_terms = geodir_get_current_location_terms();
        if (!empty($location_terms)) {
            if (get_option('permalink_structure') != '') {
                $location_terms = implode("/", $location_terms);
                $location_terms = rtrim($location_terms, '/');
                $location_link .= $location_terms;
            } else {
                $location_link = geodir_getlink($location_link, $location_terms);
            }
        }
    }
    return $location_link;
}
function geodir_filter_title_variables($title, $gd_page, $sep = '')
{
    if (!$gd_page || !$title) {
        return $title;
    }
    // if no a GD page then bail.
    global $post;
    //print_r($post);
    /*
        %%date%%	                Replaced with the date of the post/page
        %%title%%	                Replaced with the title of the post/page
        %%sitename%%	            The site's name
        %%sitedesc%%	            The site's tagline / description
        %%excerpt%%	                Replaced with the post/page excerpt (or auto-generated if it does not exist)
        %%tag%%	                    Replaced with the current tag/tags
        %%category%%	            Replaced with the post categories (comma separated)
        %%category_description%%	Replaced with the category description
        %%tag_description%%	        Replaced with the tag description
        %%term_description%%	    Replaced with the term description
        %%term_title%%	            Replaced with the term name
        %%searchphrase%%	        Replaced with the current search phrase
        %%sep%%	                    The separator defined in your theme's wp_title() tag.
    
        ADVANCED
        %%pt_single%%	            Replaced with the post type single label
        %%pt_plural%%	            Replaced with the post type plural label
        %%modified%%	            Replaced with the post/page modified time
        %%id%%	                    Replaced with the post/page ID
        %%name%%	                Replaced with the post/page author's 'nicename'
        %%userid%%	                Replaced with the post/page author's userid
        %%page%%	                Replaced with the current page number (i.e. page 2 of 4)
        %%pagetotal%%	            Replaced with the current page total
        %%pagenumber%%	            Replaced with the current page number
    */
    if ($sep == '') {
        /**
         * Filter the page title separator.
         *
         * @since 1.0.0
         * @package GeoDirectory
         * @param string $sep The separator, default: `|`.
         */
        $sep = apply_filters('geodir_page_title_separator', '|');
    }
    if (strpos($title, '%%title%%') !== false) {
        $title = str_replace("%%title%%", $post->post_title, $title);
    }
    if (strpos($title, '%%sitename%%') !== false) {
        $title = str_replace("%%sitename%%", get_bloginfo('name'), $title);
    }
    if (strpos($title, '%%sitedesc%%') !== false) {
        $title = str_replace("%%sitedesc%%", get_bloginfo('description'), $title);
    }
    if (strpos($title, '%%excerpt%%') !== false) {
        $title = str_replace("%%excerpt%%", strip_tags(get_the_excerpt()), $title);
    }
    if (strpos($title, '%%pt_single%%') !== false) {
        $single_name = '';
        if ($gd_page == 'search' || $gd_page == 'author') {
            $geodir_post_types = get_option('geodir_post_types');
            $spt = esc_attr($_REQUEST['stype']);
            if (isset($geodir_post_types[$spt]['labels']['singular_name'])) {
                $single_name = __($geodir_post_types[$spt]['labels']['singular_name'], 'geodirectory');
            }
        } elseif ($gd_page == 'add-listing') {
            $geodir_post_types = get_option('geodir_post_types');
            $spt = isset($_REQUEST['listing_type']) ? esc_attr($_REQUEST['listing_type']) : '';
            if (!$spt && isset($_REQUEST['pid'])) {
                $spt = get_post_type($_REQUEST['pid']);
            }
            if (!$spt) {
                $spt = 'gd_place';
            }
            if (isset($geodir_post_types[$spt]['labels']['singular_name'])) {
                $single_name = __($geodir_post_types[$spt]['labels']['singular_name'], 'geodirectory');
            }
        } elseif ($post->post_type) {
            $geodir_post_types = get_option('geodir_post_types');
            if (isset($geodir_post_types[$post->post_type]['labels']['singular_name'])) {
                $single_name = __($geodir_post_types[$post->post_type]['labels']['singular_name'], 'geodirectory');
            }
        }
        $title = str_replace("%%pt_single%%", $single_name, $title);
    }
    if (strpos($title, '%%pt_plural%%') !== false) {
        $plural_name = '';
        if ($gd_page == 'search' || $gd_page == 'author') {
            $geodir_post_types = get_option('geodir_post_types');
            $spt = esc_attr($_REQUEST['stype']);
            if (isset($geodir_post_types[$spt]['labels']['name'])) {
                $plural_name = __($geodir_post_types[$spt]['labels']['name'], 'geodirectory');
            }
        } elseif ($gd_page == 'add-listing') {
            $geodir_post_types = get_option('geodir_post_types');
            $spt = esc_attr($_REQUEST['listing_type']);
            if (!$spt) {
                $spt = 'gd_place';
            }
            if (isset($geodir_post_types[$spt]['labels']['name'])) {
                $plural_name = __($geodir_post_types[$spt]['labels']['name'], 'geodirectory');
            }
        } elseif (isset($post->post_type) && $post->post_type) {
            $geodir_post_types = get_option('geodir_post_types');
            if (isset($geodir_post_types[$post->post_type]['labels']['name'])) {
                $plural_name = __($geodir_post_types[$post->post_type]['labels']['name'], 'geodirectory');
            }
        }
        $title = str_replace("%%pt_plural%%", $plural_name, $title);
    }
    if (strpos($title, '%%category%%') !== false) {
        $cat_name = '';
        if ($gd_page == 'detail') {
            if ($post->default_category) {
                $cat = get_term($post->default_category, $post->post_type . 'category');
                $cat_name = isset($cat->name) ? $cat->name : '';
            }
        } elseif ($gd_page == 'listing') {
            $queried_object = get_queried_object();
            if (isset($queried_object->name)) {
                $cat_name = $queried_object->name;
            }
        }
        $title = str_replace("%%category%%", $cat_name, $title);
    }
    if (strpos($title, '%%tag%%') !== false) {
        $cat_name = '';
        if ($gd_page == 'detail') {
            if ($post->default_category) {
                $cat = get_term($post->default_category, $post->post_type . 'category');
                $cat_name = isset($cat->name) ? $cat->name : '';
            }
        } elseif ($gd_page == 'listing') {
            $queried_object = get_queried_object();
            if (isset($queried_object->name)) {
                $cat_name = $queried_object->name;
            }
        }
        $title = str_replace("%%tag%%", $cat_name, $title);
    }
    if (strpos($title, '%%id%%') !== false) {
        $ID = isset($post->ID) ? $post->ID : '';
        $title = str_replace("%%id%%", $ID, $title);
    }
    /*
        if(strpos($title,'') !== false){
            $title = str_replace("",,$title);
        }
    
        if(strpos($title,'') !== false){
            $title = str_replace("",,$title);
        }
    */
    if (strpos($title, '%%sep%%') !== false) {
        $title = str_replace("%%sep%%", $sep, $title);
    }
    global $wp;
    // location variables
    $gd_post_type = geodir_get_current_posttype();
    $location_array = geodir_get_current_location_terms('query_vars', $gd_post_type);
    /**
     * Filter the title variables location variables array
     *
     * @since 1.5.5
     * @package GeoDirectory
     * @param array $location_array The array of location variables.
     * @param string $title The title with variables..
     * @param string $gd_page The page being filtered.
     * @param string $sep The separator, default: `|`.
     */
    $location_array = apply_filters('geodir_filter_title_variables_location_arr', $location_array, $title, $gd_page, $sep);
    $location_titles = array();
    if ($gd_page == 'location' && get_query_var('gd_country_full')) {
        if (get_query_var('gd_country_full')) {
            $location_array['gd_country'] = get_query_var('gd_country_full');
        }
        if (get_query_var('gd_region_full')) {
            $location_array['gd_region'] = get_query_var('gd_region_full');
        }
        if (get_query_var('gd_city_full')) {
            $location_array['gd_city'] = get_query_var('gd_city_full');
        }
    }
    $location_single = '';
    $gd_country = isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '' ? $wp->query_vars['gd_country'] : '';
    $gd_region = isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '' ? $wp->query_vars['gd_region'] : '';
    $gd_city = isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '' ? $wp->query_vars['gd_city'] : '';
    $gd_country_actual = $gd_region_actual = $gd_city_actual = '';
    if (function_exists('get_actual_location_name')) {
        $gd_country_actual = $gd_country != '' ? get_actual_location_name('country', $gd_country, true) : $gd_country;
        $gd_region_actual = $gd_region != '' ? get_actual_location_name('region', $gd_region) : $gd_region;
        $gd_city_actual = $gd_city != '' ? get_actual_location_name('city', $gd_city) : $gd_city;
    }
    if ($gd_city != '') {
        if ($gd_city_actual != '') {
            $gd_city = $gd_city_actual;
        } else {
            $gd_city = preg_replace('/-(\\d+)$/', '', $gd_city);
            $gd_city = preg_replace('/[_-]/', ' ', $gd_city);
            $gd_city = __(geodir_ucwords($gd_city), 'geodirectory');
        }
        $location_single = $gd_city;
    } else {
        if ($gd_region != '') {
            if ($gd_region_actual != '') {
                $gd_region = $gd_region_actual;
            } else {
                $gd_region = preg_replace('/-(\\d+)$/', '', $gd_region);
                $gd_region = preg_replace('/[_-]/', ' ', $gd_region);
                $gd_region = __(geodir_ucwords($gd_region), 'geodirectory');
            }
            $location_single = $gd_region;
        } else {
            if ($gd_country != '') {
                if ($gd_country_actual != '') {
                    $gd_country = $gd_country_actual;
                } else {
                    $gd_country = preg_replace('/-(\\d+)$/', '', $gd_country);
                    $gd_country = preg_replace('/[_-]/', ' ', $gd_country);
                    $gd_country = __(geodir_ucwords($gd_country), 'geodirectory');
                }
                $location_single = $gd_country;
            }
        }
    }
    if (!empty($location_array)) {
        $actual_location_name = function_exists('get_actual_location_name') ? true : false;
        $location_array = array_reverse($location_array);
        foreach ($location_array as $location_type => $location) {
            $gd_location_link_text = preg_replace('/-(\\d+)$/', '', $location);
            $gd_location_link_text = preg_replace('/[_-]/', ' ', $gd_location_link_text);
            $location_name = geodir_ucwords($gd_location_link_text);
            $location_name = __($location_name, 'geodirectory');
            if ($actual_location_name) {
                $location_type = strpos($location_type, 'gd_') === 0 ? substr($location_type, 3) : $location_type;
                $location_name = get_actual_location_name($location_type, $location, true);
            }
            $location_titles[] = $location_name;
        }
        if (!empty($location_titles)) {
            $location_titles = array_unique($location_titles);
        }
    }
    if (strpos($title, '%%location%%') !== false) {
        $location = '';
        if ($location_titles) {
            $location = implode(", ", $location_titles);
        }
        $title = str_replace("%%location%%", $location, $title);
    }
    if (strpos($title, '%%in_location%%') !== false) {
        $location = '';
        if ($location_titles) {
            $location = __('in ', 'geodirectory') . implode(", ", $location_titles);
        }
        $title = str_replace("%%in_location%%", $location, $title);
    }
    if (strpos($title, '%%in_location_single%%') !== false) {
        if ($location_single) {
            $location_single = __('in', 'geodirectory') . ' ' . $location_single;
        }
        $title = str_replace("%%in_location_single%%", $location_single, $title);
    }
    if (strpos($title, '%%location_single%%') !== false) {
        $title = str_replace("%%location_single%%", $location_single, $title);
    }
    if (strpos($title, '%%search_term%%') !== false) {
        $search_term = '';
        if (isset($_REQUEST['s'])) {
            $search_term = esc_attr($_REQUEST['s']);
        }
        $title = str_replace("%%search_term%%", $search_term, $title);
    }
    if (strpos($title, '%%search_near%%') !== false) {
        $search_term = '';
        if (isset($_REQUEST['snear'])) {
            $search_term = esc_attr($_REQUEST['snear']);
        }
        $title = str_replace("%%search_near%%", $search_term, $title);
    }
    if (strpos($title, '%%name%%') !== false) {
        $author_name = '';
        if ($author_name = get_the_author()) {
        } else {
            $queried_object = get_queried_object();
            if (isset($queried_object->data->user_nicename)) {
                $author_name = $queried_object->data->user_nicename;
            }
        }
        $title = str_replace("%%name%%", $author_name, $title);
    }
    $title = wptexturize($title);
    $title = convert_chars($title);
    $title = esc_html($title);
    /**
     * Filter the title variables after standard ones have been filtered.
     *
     * @since 1.5.7
     * @package GeoDirectory
     * @param string $title The title with variables.
     * @param array $location_array The array of location variables.
     * @param string $gd_page The page being filtered.
     * @param string $sep The separator, default: `|`.
     */
    return apply_filters('geodir_filter_title_variables_vars', $title, $location_array, $gd_page, $sep);
}
    /**
     * Front-end display content for best of widget.
     *
     * @since 1.3.9
     * @since 1.5.1 Added filter to view all link.
     * @since 1.5.1 Declare function public.
     *
     * @param array $args     Widget arguments.
     * @param array $instance Saved values from database.
     */
    public function widget($args, $instance)
    {
        extract($args);
        /**
         * Filter the best of widget tab layout.
         *
         * @since 1.3.9
         *
         * @param string $instance['tab_layout'] Best of widget tab layout name.
         */
        $tab_layout = empty($instance['tab_layout']) ? 'bestof-tabs-on-top' : apply_filters('bestof_widget_tab_layout', $instance['tab_layout']);
        echo '<div class="bestof-widget-tab-layout ' . $tab_layout . '">';
        echo $before_widget;
        $loc_terms = geodir_get_current_location_terms();
        if ($loc_terms) {
            $cur_location = ' : ' . ucwords(str_replace('-', ' ', end($loc_terms)));
        } else {
            $cur_location = '';
        }
        /**
         * Filter the current location name.
         *
         * @since 1.3.9
         *
         * @param string $cur_location Current location name.
         */
        $cur_location = apply_filters('bestof_widget_cur_location', $cur_location);
        /**
         * Filter the widget title.
         *
         * @since 1.3.9
         *
         * @param string $instance['title'] The widget title.
         */
        $title = empty($instance['title']) ? wp_sprintf(__('Best of %s', 'geodirectory'), get_bloginfo('name') . $cur_location) : apply_filters('bestof_widget_title', __($instance['title'], 'geodirectory'));
        /**
         * Filter the post type.
         *
         * @since 1.3.9
         *
         * @param string $instance['post_type'] The post type.
         */
        $post_type = empty($instance['post_type']) ? 'gd_place' : apply_filters('bestof_widget_post_type', $instance['post_type']);
        /**
         * Filter the listing limit.
         *
         * @since 1.3.9
         *
         * @param int $instance['post_limit'] No. of posts to display.
         */
        $post_limit = empty($instance['post_limit']) ? '5' : apply_filters('bestof_widget_post_limit', $instance['post_limit']);
        /**
         * Filter the category limit.
         *
         * @since 1.3.9
         *
         * @param int $instance['categ_limit'] No. of categories to display.
         */
        $categ_limit = empty($instance['categ_limit']) ? '3' : apply_filters('bestof_widget_categ_limit', $instance['categ_limit']);
        $use_viewing_post_type = !empty($instance['use_viewing_post_type']) ? true : false;
        /**
         * Filter the use of location filter.
         *
         * @since 1.3.9
         *
         * @param int|bool $instance['add_location_filter'] Filter listings using current location.
         */
        $add_location_filter = empty($instance['add_location_filter']) ? '1' : apply_filters('bestof_widget_location_filter', $instance['add_location_filter']);
        // set post type to current viewing post type
        if ($use_viewing_post_type) {
            $current_post_type = geodir_get_current_posttype();
            if ($current_post_type != '' && $current_post_type != $post_type) {
                $post_type = $current_post_type;
            }
        }
        if (isset($instance['character_count'])) {
            /**
             * Filter the widget's excerpt character count.
             *
             * @since 1.3.9
             *
             * @param int $instance['character_count'] Excerpt character count.
             */
            $character_count = apply_filters('bestof_widget_list_character_count', $instance['character_count']);
        } else {
            $character_count = '';
        }
        $category_taxonomy = geodir_get_taxonomies($post_type);
        $term_args = array('hide_empty' => true, 'parent' => 0);
        if (is_tax()) {
            $taxonomy = get_query_var('taxonomy');
            $cur_term = get_query_var('term');
            $term_data = get_term_by('name', $cur_term, $taxonomy);
            $term_args['parent'] = $term_data->term_id;
        }
        $terms = get_terms($category_taxonomy[0], $term_args);
        $term_reviews = geodir_count_reviews_by_terms();
        $a_terms = array();
        foreach ($terms as $term) {
            if ($term->count > 0) {
                if (isset($term_reviews[$term->term_id])) {
                    $term->review_count = $term_reviews[$term->term_id];
                } else {
                    $term->review_count = '0';
                }
                $a_terms[] = $term;
            }
        }
        $terms = geodir_sort_terms($a_terms, 'review_count');
        $query_args = array('posts_per_page' => $post_limit, 'is_geodir_loop' => true, 'post_type' => $post_type, 'gd_location' => $add_location_filter ? true : false, 'order_by' => 'high_review');
        if ($character_count >= 0) {
            $query_args['excerpt_length'] = $character_count;
        }
        $layout = array();
        if ($tab_layout == 'bestof-tabs-as-dropdown') {
            $layout[] = $tab_layout;
        } else {
            $layout[] = 'bestof-tabs-as-dropdown';
            $layout[] = $tab_layout;
        }
        echo $before_title . __($title) . $after_title;
        //term navigation - start
        echo '<div class="geodir-tabs gd-bestof-tabs" id="gd-bestof-tabs" style="position:relative;">';
        $final_html = '';
        foreach ($layout as $tab_layout) {
            $nav_html = '';
            $is_dropdown = $tab_layout == 'bestof-tabs-as-dropdown' ? true : false;
            if ($is_dropdown) {
                $nav_html .= '<select id="geodir_bestof_tab_dd" class="chosen_select" name="geodir_bestof_tab_dd" data-placeholder="' . esc_attr(__('Select Category', 'geodirectory')) . '">';
            } else {
                $nav_html .= '<dl class="geodir-tab-head geodir-bestof-cat-list">';
                $nav_html .= '<dt></dt>';
            }
            $term_icon = geodir_get_term_icon();
            $cat_count = 0;
            foreach ($terms as $cat) {
                $cat_count++;
                if ($cat_count > $categ_limit) {
                    break;
                }
                if ($is_dropdown) {
                    $selected = $cat_count == 1 ? 'selected="selected"' : '';
                    $nav_html .= '<option ' . $selected . ' value="' . $cat->term_id . '">' . ucwords($cat->name) . '</option>';
                } else {
                    if ($cat_count == 1) {
                        $nav_html .= '<dd class="geodir-tab-active">';
                    } else {
                        $nav_html .= '<dd class="">';
                    }
                    $term_icon_url = !empty($term_icon) && isset($term_icon[$cat->term_id]) ? $term_icon[$cat->term_id] : '';
                    $nav_html .= '<a data-termid="' . $cat->term_id . '" href="' . get_term_link($cat, $cat->taxonomy) . '">';
                    $nav_html .= '<img alt="' . $cat->name . ' icon" class="bestof-cat-icon" src="' . $term_icon_url . '"/>';
                    $nav_html .= '<span>';
                    $nav_html .= ucwords($cat->name);
                    $nav_html .= '<small>';
                    if (isset($cat->review_count)) {
                        $num_reviews = $cat->review_count;
                        if ($num_reviews == 0) {
                            $reviews = __('No Reviews', 'geodirectory');
                        } elseif ($num_reviews > 1) {
                            $reviews = $num_reviews . __(' Reviews', 'geodirectory');
                        } else {
                            $reviews = __('1 Review', 'geodirectory');
                        }
                        $nav_html .= $reviews;
                    }
                    $nav_html .= '</small>';
                    $nav_html .= '</span>';
                    $nav_html .= '</a>';
                    $nav_html .= '</dd>';
                }
            }
            if ($is_dropdown) {
                $nav_html .= '</select>';
            } else {
                $nav_html .= '</dl>';
            }
            $final_html .= $nav_html;
        }
        if ($terms) {
            echo $final_html;
        }
        echo '</div>';
        //term navigation - end
        //first term listings by default - start
        $first_term = '';
        if ($terms) {
            $first_term = $terms[0];
            $tax_query = array('taxonomy' => $category_taxonomy[0], 'field' => 'id', 'terms' => $first_term->term_id);
            $query_args['tax_query'] = array($tax_query);
        }
        ?>
        <input type="hidden" id="bestof_widget_post_type" name="bestof_widget_post_type"
               value="<?php 
        echo $post_type;
        ?>
">
        <input type="hidden" id="bestof_widget_post_limit" name="bestof_widget_post_limit"
               value="<?php 
        echo $post_limit;
        ?>
">
        <input type="hidden" id="bestof_widget_taxonomy" name="bestof_widget_taxonomy"
               value="<?php 
        echo $category_taxonomy[0];
        ?>
">
        <input type="hidden" id="bestof_widget_location_filter" name="bestof_widget_location_filter"
               value="<?php 
        if ($add_location_filter) {
            echo 1;
        } else {
            echo 0;
        }
        ?>
">
        <input type="hidden" id="bestof_widget_char_count" name="bestof_widget_char_count"
               value="<?php 
        echo $character_count;
        ?>
">
        <div class="geo-bestof-contentwrap geodir-tabs-content" style="position: relative; z-index: 0;">
            <p id="geodir-bestof-loading" class="geodir-bestof-loading"><i class="fa fa-cog fa-spin"></i></p>
            <?php 
        echo '<div id="geodir-bestof-places">';
        if ($terms) {
            $view_all_link = add_query_arg(array('sort_by' => 'rating_count_desc'), get_term_link($first_term, $first_term->taxonomy));
            /**
             * Filter the page link to view all lisitngs.
             *
             * @since 1.5.1
             *
             * @param array $view_all_link View all listings page link.
             * @param array $post_type The Post type.
             * @param array $first_term The category term object.
             */
            $view_all_link = apply_filters('geodir_bestof_widget_view_all_link', $view_all_link, $post_type, $first_term);
            echo '<h3 class="bestof-cat-title">' . wp_sprintf(__('Best of %s', 'geodirectory'), $first_term->name) . '<a href="' . esc_url($view_all_link) . '">' . __("View all", 'geodirectory') . '</a></h3>';
        }
        geodir_bestof_places_by_term($query_args);
        echo "</div>";
        ?>
        </div>
        <?php 
        //first term listings by default - end
        ?>
        <?php 
        echo $after_widget;
        echo "</div>";
    }
/**
 *
 *
 * @global object $wp WordPress object.
 *
 * @param $breadcrumb
 * @param $saprator
 * @param bool $echo
 * @return string
 */
function geodir_location_breadcrumb($breadcrumb, $saprator, $echo = false)
{
    global $wp;
    if (geodir_is_page('location')) {
        $saprator = str_replace(' ', '&nbsp;', $saprator);
        $location_link = geodir_get_location_link('base');
        $location_prefix = get_option('geodir_location_prefix');
        $breadcrumb = '';
        $breadcrumb .= '<div class="geodir-breadcrumb clearfix"><ul id="breadcrumbs">';
        $breadcrumb .= '<li><a href="' . get_option('home') . '">' . __('Home', GEODIRLOCATION_TEXTDOMAIN) . '</a></li>';
        $breadcrumb .= '<li>' . $saprator;
        $breadcrumb .= '<a href="' . $location_link . '">' . GD_LOCATION . '</a>';
        $breadcrumb .= '</li>';
        /*
        $gd_country = (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] !='') ? $wp->query_vars['gd_country'] : '' ;	
        $gd_region = (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] !='') ? $wp->query_vars['gd_region'] : '' ;
        $gd_city = (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] !='') ? $wp->query_vars['gd_city'] : '' ;
        */
        $locations = geodir_get_current_location_terms();
        $breadcrumb .= '<li>';
        foreach ($locations as $key => $location) {
            if (get_option('permalink_structure') != '') {
                $location_link .= $location;
            } else {
                $location_link .= '&' . $key . '=' . $location;
            }
            $location_link = geodir_location_permalink_url($location_link);
            $location = urldecode($location);
            $location_actual_text = '';
            if ($key == 'gd_country' && ($location_actual = get_actual_location_name('country', $location))) {
                $location_actual_text = get_actual_location_name('country', $location, true);
            } else {
                if ($key == 'gd_region' && ($location_actual = get_actual_location_name('region', $location))) {
                    $location_actual_text = get_actual_location_name('region', $location, true);
                } else {
                    if ($key == 'gd_city' && ($location_actual = get_actual_location_name('city', $location))) {
                        $location_actual_text = get_actual_location_name('city', $location, true);
                    }
                }
            }
            if ($location != end($locations)) {
                $location = preg_replace('/-(\\d+)$/', '', $location);
                $location = preg_replace('/[_-]/', ' ', $location);
                $location = ucwords($location);
                $location = __($location, GEODIRECTORY_TEXTDOMAIN);
                $location_text = $location_actual_text != '' ? $location_actual_text : $location;
                $breadcrumb .= $saprator . '<a href="' . $location_link . '">' . $location_text . '</a>';
            } else {
                $location = preg_replace('/-(\\d+)$/', '', $location);
                $location = preg_replace('/[_-]/', ' ', $location);
                $location = ucwords($location);
                $location = __($location, GEODIRECTORY_TEXTDOMAIN);
                $location_text = $location_actual_text != '' ? $location_actual_text : $location;
                $breadcrumb .= $saprator . $location_text;
            }
        }
        $breadcrumb .= '</li>';
        $breadcrumb .= '</ul></div>';
    }
    if ($echo) {
        echo $breadcrumb;
    } else {
        return $breadcrumb;
    }
}
/**
 * Retrieve the post type archive permalink.
 *
 * @since 1.1.6
 *
 * @param string $link The post type archive permalink.
 * @param string $post_type Post type name.
 * @param string The post type archive permalink.
 */
function geodir_cpt_post_type_archive_link($link, $post_type)
{
    if (geodir_cpt_no_location($post_type)) {
        $location_vars = geodir_get_current_location_terms('query_vars');
        if (!empty($location_vars)) {
            if (get_option('permalink_structure')) {
                $search = implode('/', $location_vars) . '/';
                $replace = '';
                $link = str_replace($search, $replace, $link);
            } else {
                $link = esc_url(remove_query_arg(array('gd_country', 'gd_region', 'gd_city'), $link));
            }
        }
    }
    return $link;
}
/**
 * Get term count for a location.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wpdb WordPress Database object.
 *
 * @param string $count_type Count type. Possible values are 'review_count', 'term_count'.
 * @param null|string $location_name Location name slug. Ex: new-york.
 * @param null|string $location_type Location type. Possible values 'gd_city','gd_region','gd_country'.
 * @param bool $force_update Do you want to force update? default: false.
 * @param bool|array $loc {
 *    Attributes of the location array.
 *
 *    @type string $gd_country The country slug.
 *    @type string $gd_region The region slug.
 *    @type string $gd_city The city slug.
 *
 * }
 * @return array|mixed|void
 */
function geodir_get_loc_term_count($count_type = 'term_count', $location_name = null, $location_type = null, $force_update = false, $loc = false)
{
    //accepted count type: term_count, review_count
    global $wpdb;
    if (!$location_name || !$location_type) {
        $loc = geodir_get_current_location_terms();
        if (isset($loc['gd_city']) && $loc['gd_city'] != '') {
            $location_name = $loc['gd_city'];
            $location_type = 'gd_city';
        } elseif (isset($loc['gd_region']) && $loc['gd_region'] != '') {
            $location_name = $loc['gd_region'];
            $location_type = 'gd_region';
        } elseif (isset($loc['gd_country']) && $loc['gd_country'] != '') {
            $location_name = $loc['gd_country'];
            $location_type = 'gd_country';
        }
    }
    if ($location_name && $location_type) {
        $sql = $wpdb->prepare("SELECT * FROM " . GEODIR_TERM_META . " WHERE location_type=%s AND location_name=%s LIMIT 1", array($location_type, $location_name));
        $row = $wpdb->get_row($sql);
        if ($row) {
            if ($force_update || !$row->{$count_type}) {
                return geodir_insert_term_count_by_loc($location_name, $location_type, $count_type, $row->id, $loc);
            } else {
                $data = unserialize($row->{$count_type});
                return $data;
            }
        } else {
            return geodir_insert_term_count_by_loc($location_name, $location_type, $count_type, null, $loc);
        }
    } else {
        return;
    }
}