예제 #1
0
/**
 * Sets a key and value in $wp object if the current page is a geodir page.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param object $wp WordPress object.
 */
function geodir_set_is_geodir_page($wp)
{
    if (!is_admin()) {
        //$wp->query_vars['gd_is_geodir_page'] = false;
        //print_r()
        if (empty($wp->query_vars) || !array_diff(array_keys($wp->query_vars), array('preview', 'page', 'paged', 'cpage'))) {
            if (get_option('geodir_set_as_home')) {
                $wp->query_vars['gd_is_geodir_page'] = true;
            }
        }
        if (!isset($wp->query_vars['gd_is_geodir_page']) && isset($wp->query_vars['page_id'])) {
            if ($wp->query_vars['page_id'] == geodir_add_listing_page_id() || $wp->query_vars['page_id'] == geodir_preview_page_id() || $wp->query_vars['page_id'] == geodir_success_page_id() || $wp->query_vars['page_id'] == geodir_location_page_id()) {
                $wp->query_vars['gd_is_geodir_page'] = true;
            }
        }
        if (!isset($wp->query_vars['gd_is_geodir_page']) && isset($wp->query_vars['pagename'])) {
            $page = get_page_by_path($wp->query_vars['pagename']);
            if (!empty($page) && ($page->ID == geodir_add_listing_page_id() || $page->ID == geodir_preview_page_id() || $page->ID == geodir_success_page_id() || $page->ID == geodir_location_page_id())) {
                $wp->query_vars['gd_is_geodir_page'] = true;
            }
        }
        if (!isset($wp->query_vars['gd_is_geodir_page']) && isset($wp->query_vars['post_type']) && $wp->query_vars['post_type'] != '') {
            $requested_post_type = $wp->query_vars['post_type'];
            // check if this post type is geodirectory post types
            $post_type_array = geodir_get_posttypes();
            if (in_array($requested_post_type, $post_type_array)) {
                $wp->query_vars['gd_is_geodir_page'] = true;
            }
        }
        if (!isset($wp->query_vars['gd_is_geodir_page'])) {
            $geodir_taxonomis = geodir_get_taxonomies('', true);
            foreach ($geodir_taxonomis as $taxonomy) {
                if (array_key_exists($taxonomy, $wp->query_vars)) {
                    $wp->query_vars['gd_is_geodir_page'] = true;
                    break;
                }
            }
        }
        if (!isset($wp->query_vars['gd_is_geodir_page']) && isset($wp->query_vars['author_name']) && isset($_REQUEST['geodir_dashbord'])) {
            $wp->query_vars['gd_is_geodir_page'] = true;
        }
        if (!isset($wp->query_vars['gd_is_geodir_page']) && isset($_REQUEST['geodir_search'])) {
            $wp->query_vars['gd_is_geodir_page'] = true;
        }
        //echo $wp->query_vars['gd_is_geodir_page'] ;
        /*echo "<pre>" ;
        		print_r($wp) ;
        		echo "</pre>" ;
        	//	exit();
        			*/
    }
    // end of is admin
}
/**
 * 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);
    }
}
/**
 * Adds rel='canonical' tag to links.
 *
 * @since 1.0.0
 * @package GeoDirectory_Location_Manager
 *
 * @global object $wp WordPress object.
 */
function geodir_location_rel_canonical()
{
    global $wp;
    if (isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == geodir_location_page_id()) {
        $link = geodir_get_location_link();
        if (get_option('geodir_set_as_home') && $link == geodir_get_location_link('base')) {
            $link = get_bloginfo('url');
        } else {
            if (get_option('permalink_structure') != '') {
                $link = trim($link);
                $link = rtrim($link, "/") . "/";
            }
        }
        echo "<link rel='canonical' href='{$link}' />\n";
    }
}
예제 #4
0
/**
 * page title & breadcrumb functions.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @global object $wp WordPress object.
 * @param string $page The page type.
 * @param string $class The class of the HTML element.
 */
function enfold_detail_title($page, $class)
{
    //echo '###'.$page;
    global $wp;
    if (isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == geodir_location_page_id() && !isset($_GET['geodir_signup'])) {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        echo avia_title();
    } elseif ($page == 'details-page') {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        echo avia_title();
    } elseif ($page == 'listings-page' || $page == 'search-page') {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        ob_start();
        // Start buffering;
        geodir_action_listings_title();
        $gd_title = ob_get_clean();
        $title_p = explode('">', $gd_title);
        $title = str_replace('</h1></header>', "", $title_p[2]);
        //print_r($title_p);
        echo avia_title(array('title' => $title));
    } elseif ($page == 'author-page') {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        ob_start();
        // Start buffering;
        geodir_action_author_page_title();
        $gd_title = ob_get_clean();
        $gd_title = str_replace('<h1>', "", $gd_title);
        $gd_title = str_replace('</h1>', "", $gd_title);
        echo avia_title(array('title' => $gd_title));
    } elseif ($page == 'add-listing-page') {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        echo avia_title();
    } elseif ($page == 'add-listing-page') {
        add_action('avia_breadcrumbs_trail', 'enfold_detail_breadcrum', 8, 2);
        echo avia_title();
    }
}
/**
 * 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;
}
/**
 * Add the location variables in session.
 *
 * @since 1.0.0
 *
 * @param object $wp The WordPress object.
 */
function geodir_set_location_var_in_session_in_core($wp)
{
    //$wp->geodir_query_vars = $wp->query_vars ;
    // this code will determine when a user wants to switch location
    // Query Vars will have page_id parameter
    // check if query var has page_id and that page id is location page
    geodir_set_is_geodir_page($wp);
    if (!get_option('geodir_set_as_home')) {
        if (empty($wp->query_vars) || !array_diff(array_keys($wp->query_vars), array('preview', 'page', 'paged', 'cpage'))) {
            if ('page' == get_option('show_on_front')) {
                $wp->query_vars['page_id'] = get_option('page_on_front');
            }
        }
    }
    if (isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == geodir_location_page_id()) {
        $gd_country = '';
        $gd_region = '';
        $gd_city = '';
        if (isset($wp->query_vars['gd_country']) && $wp->query_vars['gd_country'] != '') {
            $gd_country = urldecode($wp->query_vars['gd_country']);
        }
        if (isset($wp->query_vars['gd_region']) && $wp->query_vars['gd_region'] != '') {
            $gd_region = urldecode($wp->query_vars['gd_region']);
        }
        if (isset($wp->query_vars['gd_city']) && $wp->query_vars['gd_city'] != '') {
            $gd_city = urldecode($wp->query_vars['gd_city']);
        }
        if (!($gd_country == '' && $gd_region == '' && $gd_city == '')) {
            $default_location = geodir_get_default_location();
            if (get_option('geodir_add_location_url')) {
                if (get_option('geodir_show_location_url') != 'all') {
                    if ($gd_region == '') {
                        if (isset($_SESSION['gd_region'])) {
                            $gd_region = $_SESSION['gd_region'];
                        } else {
                            $gd_region = $default_location->region_slug;
                        }
                    }
                    if ($gd_city == '') {
                        if (isset($_SESSION['gd_city'])) {
                            $gd_city = $_SESSION['gd_city'];
                        } else {
                            $gd_city = $default_location->city_slug;
                        }
                        $base_location_link = geodir_get_location_link('base');
                        wp_redirect($base_location_link . '/' . $gd_country . '/' . $gd_region . '/' . $gd_city);
                        exit;
                    }
                }
            }
            $args = array('what' => 'city', 'city_val' => $gd_city, 'region_val' => $gd_region, 'country_val' => $gd_country, 'country_column_name' => 'country_slug', 'region_column_name' => 'region_slug', 'city_column_name' => 'city_slug', 'location_link_part' => false, 'compare_operator' => '');
            $location_array = function_exists('geodir_get_location_array') ? geodir_get_location_array($args) : array();
            if (!empty($location_array)) {
                $_SESSION['gd_multi_location'] = 1;
                $_SESSION['gd_country'] = $gd_country;
                $_SESSION['gd_region'] = $gd_region;
                $_SESSION['gd_city'] = $gd_city;
                $wp->query_vars['gd_country'] = $gd_country;
                $wp->query_vars['gd_region'] = $gd_region;
                $wp->query_vars['gd_city'] = $gd_city;
            } else {
                unset($_SESSION['gd_multi_location'], $_SESSION['gd_city'], $_SESSION['gd_region'], $_SESSION['gd_country']);
            }
        } else {
            unset($_SESSION['gd_multi_location'], $_SESSION['gd_city'], $_SESSION['gd_region'], $_SESSION['gd_country']);
        }
    } else {
        if (isset($wp->query_vars['post_type']) && $wp->query_vars['post_type'] != '') {
            if (!is_admin()) {
                $requested_post_type = $wp->query_vars['post_type'];
                // check if this post type is geodirectory post types
                $post_type_array = geodir_get_posttypes();
                if (in_array($requested_post_type, $post_type_array)) {
                    // now u can apply geodirectory related manipulation.
                }
            }
        } else {
            // check if a geodirectory taxonomy is set
            $gd_country = '';
            $gd_region = '';
            $gd_city = '';
            $is_geodir_taxonomy = false;
            $is_geodir_taxonomy_term = false;
            // the last term is real geodirectory taxonomy term or not
            $is_geodir_location_found = false;
            $geodir_taxonomy = '';
            $geodir_post_type = '';
            $geodir_term = '';
            $geodir_set_location_session = true;
            $geodir_taxonomis = geodir_get_taxonomies('', true);
            foreach ($geodir_taxonomis as $taxonomy) {
                if (array_key_exists($taxonomy, $wp->query_vars)) {
                    $is_geodir_taxonomy = true;
                    $geodir_taxonomy = $taxonomy;
                    $geodir_post_type = str_replace('category', '', $taxonomy);
                    $geodir_post_type = str_replace('_tags', '', $geodir_post_type);
                    $geodir_term = $wp->query_vars[$geodir_taxonomy];
                    break;
                }
            }
            // now get an array of all terms seperated by '/'
            $geodir_terms = explode('/', $geodir_term);
            $geodir_last_term = end($geodir_terms);
            if ($is_geodir_taxonomy) {
                $wp->query_vars['post_type'] = $geodir_post_type;
                // now check if last term is a post of geodirectory post types
                $geodir_post = get_posts(array('name' => $geodir_last_term, 'posts_per_page' => 1, 'post_type' => $geodir_post_type));
                if (empty($geodir_post)) {
                    $geodir_post = get_posts(array('name' => $geodir_last_term, 'posts_per_page' => 1, 'post_type' => $geodir_post_type, 'post_status' => 'draft', 'suppress_filters' => false));
                }
                if (!empty($geodir_post)) {
                    if ($geodir_post[0]->post_status != 'publish') {
                        foreach ($wp->query_vars as $key => $vars) {
                            unset($wp->query_vars[$key]);
                        }
                        $wp->query_vars['error'] = '404';
                        // set it as 404 if post exists but its status is not published yet
                    } else {
                        //$wp->query_vars[$geodir_taxonomy] = str_replace( '/'.$geodir_last_term , ''  , $geodir_term);
                        $wp->query_vars[$geodir_post_type] = $geodir_last_term;
                        $wp->query_vars['name'] = $geodir_last_term;
                    }
                    $geodir_term = str_replace('/' . $geodir_last_term, '', $geodir_term, $post_title_replace_count);
                    if (!$post_title_replace_count) {
                        $geodir_term = str_replace($geodir_last_term, '', $geodir_term, $post_title_replace_count);
                    }
                    $geodir_terms = explode('/', $geodir_term);
                    $geodir_last_term = end($geodir_terms);
                    $geodir_set_location_session = false;
                    //return ;
                }
                $geodir_location_terms = '';
                // if last term is not a post then check if last term is a term of the specific texonomy or not
                if (geodir_term_exists($geodir_last_term, $geodir_taxonomy)) {
                    $is_geodir_taxonomy_term = true;
                    $geodir_set_location_session = false;
                }
                // now check if there is location parts in the url or not
                if (get_option('geodir_add_location_url')) {
                    $default_location = geodir_get_default_location();
                    if (get_option('geodir_show_location_url') == 'all') {
                        if (count($geodir_terms) >= 3) {
                            $gd_country = urldecode($geodir_terms[0]);
                            $gd_region = urldecode($geodir_terms[1]);
                            $gd_city = urldecode($geodir_terms[2]);
                        } else {
                            if (count($geodir_terms) >= 2) {
                                $gd_country = urldecode($geodir_terms[0]);
                                $gd_region = urldecode($geodir_terms[1]);
                            } else {
                                if (count($geodir_terms) >= 1) {
                                    $gd_country = urldecode($geodir_terms[0]);
                                }
                            }
                        }
                        if (strtolower($default_location->country_slug) == strtolower($gd_country) && strtolower($default_location->region_slug) == strtolower($gd_region) && strtolower($default_location->city_slug) == strtolower($gd_city)) {
                            $is_geodir_location_found = true;
                        }
                        // if location has not been found for country , region and city then search for country and region only
                        if (!$is_geodir_location_found) {
                            $gd_city = '';
                            if (strtolower($default_location->country_slug) == strtolower($gd_country) && strtolower($default_location->region_slug) == strtolower($gd_region)) {
                                $is_geodir_location_found = true;
                            }
                        }
                        // if location has not been found for country , region  then search for country only
                        if (!$is_geodir_location_found) {
                            $gd_city = '';
                            $gd_region = '';
                            if (strtolower($default_location->country_slug) == strtolower($gd_country)) {
                                $is_geodir_location_found = true;
                            }
                        }
                    } else {
                        $gd_city = $geodir_terms[0];
                        if (strtolower($default_location->city_slug) == strtolower($gd_city)) {
                            $is_geodir_location_found = true;
                            $gd_region = $default_location->region_slug;
                            $gd_country = $default_location->country_slug;
                        }
                    }
                    // if locaton still not found then clear location related session variables
                    if ($is_geodir_location_found && $geodir_set_location_session) {
                        $_SESSION['gd_multi_location'] = 1;
                        $_SESSION['gd_country'] = $gd_country;
                        $_SESSION['gd_region'] = $gd_region;
                        $_SESSION['gd_city'] = $gd_city;
                    }
                    if (get_option('geodir_show_location_url') != 'all') {
                        $gd_country = '';
                        $gd_region = '';
                    }
                    if ($is_geodir_location_found) {
                        $wp->query_vars['gd_country'] = $gd_country;
                        $wp->query_vars['gd_region'] = $gd_region;
                        $wp->query_vars['gd_city'] = $gd_city;
                    } else {
                        $gd_country = '';
                        $gd_region = '';
                        $gd_city = '';
                    }
                }
                $wp->query_vars[$geodir_taxonomy] = $geodir_term;
                // eliminate location related terms from taxonomy term
                if ($gd_country != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_country) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                if ($gd_region != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_region) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                if ($gd_city != '') {
                    $wp->query_vars[$geodir_taxonomy] = preg_replace('/' . urlencode($gd_city) . '/', '', $wp->query_vars[$geodir_taxonomy], 1);
                }
                $wp->query_vars[$geodir_taxonomy] = str_replace('///', '', $wp->query_vars[$geodir_taxonomy]);
                $wp->query_vars[$geodir_taxonomy] = str_replace('//', '', $wp->query_vars[$geodir_taxonomy]);
                $wp->query_vars[$geodir_taxonomy] = trim($wp->query_vars[$geodir_taxonomy], '/');
                if ($wp->query_vars[$geodir_taxonomy] == '') {
                    unset($wp->query_vars[$geodir_taxonomy]);
                } else {
                    if (!$is_geodir_taxonomy_term) {
                        foreach ($wp->query_vars as $key => $vars) {
                            unset($wp->query_vars[$key]);
                        }
                        $wp->query_vars['error'] = '404';
                    }
                }
            }
        }
    }
    if (isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
        $wp->query_vars['gd_country'] = $_SESSION['gd_country'];
        $wp->query_vars['gd_region'] = $_SESSION['gd_region'];
        $wp->query_vars['gd_city'] = $_SESSION['gd_city'];
    }
    // now check if there is location parts in the url or not
    if (get_option('geodir_add_location_url')) {
        if (get_option('geodir_show_location_url') != 'all') {
            if (isset($wp->query_vars['gd_country'])) {
                $wp->query_vars['gd_country'] = '';
            }
            if (isset($wp->query_vars['gd_region'])) {
                $wp->query_vars['gd_region'] = '';
            }
        }
    } else {
        if (isset($wp->query_vars['gd_country'])) {
            $wp->query_vars['gd_country'] = '';
        }
        if (isset($wp->query_vars['gd_region'])) {
            $wp->query_vars['gd_region'] = '';
        }
        if (isset($wp->query_vars['gd_city'])) {
            $wp->query_vars['gd_city'] = '';
        }
    }
}
예제 #7
0
 /**
  * breadcrumbs.
  *
  * @since 1.0.0
  * @package GeoDirectory
  */
 function x_breadcrumbs()
 {
     if (x_get_option('x_breadcrumb_display', '1')) {
         //
         // 1. Delimiter between crumbs.
         // 2. Output text for the "Home" link.
         // 3. Link to the home page.
         // 4. Tag before the current crumb.
         // 5. Tag after the current crumb.
         // 6. Get page title.
         // 7. Get blog title.
         // 8. Get shop title.
         //
         global $post, $wp;
         if (geodir_is_page('detail') || geodir_is_page('listing') || isset($wp->query_vars['page_id']) && $wp->query_vars['page_id'] == geodir_location_page_id()) {
             geodir_breadcrumb();
         } else {
             $stack = x_get_stack();
             $delimiter = ' <span class="delimiter"><i class="x-icon-angle-right"></i></span> ';
             // 1
             $home_text = '<span class="home"><i class="x-icon-home"></i></span>';
             // 2
             $home_link = home_url();
             // 3
             $current_before = '<span class="current">';
             // 4
             $current_after = '</span>';
             // 5
             $page_title = get_the_title();
             // 6
             $blog_title = get_the_title(get_option('page_for_posts', true));
             // 7
             $shop_title = get_theme_mod('x_' . $stack . '_shop_title');
             // 8
             if (function_exists('woocommerce_get_page_id')) {
                 $shop_url = x_get_shop_link();
                 $shop_link = '<a href="' . $shop_url . '">' . $shop_title . '</a>';
             }
             if (is_front_page()) {
                 echo '<div class="x-breadcrumbs">' . $current_before . $home_text . $current_after . '</div>';
             } elseif (is_home()) {
                 echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter . $current_before . $blog_title . $current_after . '</div>';
             } else {
                 echo '<div class="x-breadcrumbs"><a href="' . $home_link . '">' . $home_text . '</a>' . $delimiter;
                 if (is_category()) {
                     $the_cat = get_category(get_query_var('cat'), false);
                     if ($the_cat->parent != 0) {
                         echo get_category_parents($the_cat->parent, TRUE, $delimiter);
                     }
                     echo $current_before . single_cat_title('', false) . $current_after;
                 } elseif (x_is_product_category()) {
                     echo $shop_link . $delimiter . $current_before . single_cat_title('', false) . $current_after;
                 } elseif (x_is_product_tag()) {
                     echo $shop_link . $delimiter . $current_before . single_tag_title('', false) . $current_after;
                 } elseif (is_search()) {
                     echo $current_before . __('Search Results for ', '__x__') . '&#8220;' . get_search_query() . '&#8221;' . $current_after;
                 } elseif (is_singular('post')) {
                     if (get_option('page_for_posts') == is_front_page()) {
                         echo $current_before . $page_title . $current_after;
                     } else {
                         echo '<a href="' . get_permalink(get_option('page_for_posts')) . '" title="' . esc_attr(__('See All Posts', '__x__')) . '">' . $blog_title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
                     }
                 } elseif (x_is_portfolio()) {
                     echo $current_before . get_the_title() . $current_after;
                 } elseif (x_is_portfolio_item()) {
                     $link = x_get_parent_portfolio_link();
                     $title = x_get_parent_portfolio_title();
                     echo '<a href="' . $link . '" title="' . esc_attr(__('See All Posts', '__x__')) . '">' . $title . '</a>' . $delimiter . $current_before . $page_title . $current_after;
                 } elseif (x_is_product()) {
                     echo $shop_link . $delimiter . $current_before . $page_title . $current_after;
                 } elseif (is_page() && !$post->post_parent) {
                     echo $current_before . $page_title . $current_after;
                 } elseif (is_page() && $post->post_parent) {
                     $parent_id = $post->post_parent;
                     $breadcrumbs = array();
                     while ($parent_id) {
                         $page = get_page($parent_id);
                         $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
                         $parent_id = $page->post_parent;
                     }
                     $breadcrumbs = array_reverse($breadcrumbs);
                     for ($i = 0; $i < count($breadcrumbs); $i++) {
                         echo $breadcrumbs[$i];
                         if ($i != count($breadcrumbs) - 1) {
                             echo $delimiter;
                         }
                     }
                     echo $delimiter . $current_before . $page_title . $current_after;
                 } elseif (is_tag()) {
                     echo $current_before . single_tag_title('', false) . $current_after;
                 } elseif (is_author()) {
                     global $author;
                     $userdata = get_userdata($author);
                     echo $current_before . __('Posts by ', '__x__') . '&#8220;' . $userdata->display_name . $current_after . '&#8221;';
                 } elseif (is_404()) {
                     echo $current_before . __('404 (Page Not Found)', '__x__') . $current_after;
                 } elseif (is_archive()) {
                     if (x_is_shop()) {
                         echo $current_before . $shop_title . $current_after;
                     } else {
                         echo $current_before . __('Archives ', '__x__') . $current_after;
                     }
                 }
                 if (get_query_var('paged')) {
                     echo ' <span class="current" style="white-space: nowrap;">(' . __('Page', '__x__') . ' ' . get_query_var('paged') . ')</span>';
                 }
                 echo '</div>';
             }
         }
     }
 }