Exemplo n.º 1
0
/**
 * Returns the term link with parameters.
 *
 * @since 1.0.0
 * @package GeoDirectory
 * @param string $termlink The term link
 * @param object $term Not yet implemented.
 * @param string $taxonomy The taxonomy name.
 * @return string The term link.
 */
function geodir_term_link($termlink, $term, $taxonomy)
{
    //echo '###'.$termlink;
    $geodir_taxonomies = geodir_get_taxonomies('', true);
    if (isset($taxonomy) && !empty($geodir_taxonomies) && in_array($taxonomy, $geodir_taxonomies)) {
        global $geodir_add_location_url;
        $include_location = false;
        $request_term = array();
        $listing_slug = geodir_get_listing_slug($taxonomy);
        //echo $listing_slug ;
        if ($geodir_add_location_url != NULL && $geodir_add_location_url != '') {
            if ($geodir_add_location_url && get_option('geodir_add_location_url')) {
                $include_location = true;
            }
        } elseif (get_option('geodir_add_location_url') && isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
            $include_location = true;
        }
        if ($include_location) {
            $request_term = geodir_get_current_location_terms('query_vars');
            if (!empty($request_term)) {
                $url_separator = '';
                //get_option('geodir_listingurl_separator');
                if (get_option('permalink_structure') != '') {
                    $old_listing_slug = '/' . $listing_slug . '/';
                    $request_term = implode("/", $request_term);
                    //$new_listing_slug = '/'.$listing_slug.'/'.rtrim($request_term,'/').'/'.$url_separator.'/';
                    $new_listing_slug = '/' . $listing_slug . '/' . $request_term . '/';
                    $termlink = substr_replace($termlink, $new_listing_slug, strpos($termlink, $old_listing_slug), strlen($old_listing_slug));
                } else {
                    $termlink = geodir_getlink($termlink, $request_term);
                }
            }
        }
        // Alter the CPT slug is WPML is set to do so
        if (function_exists('icl_object_id')) {
            global $sitepress;
            $post_type = str_replace("category", "", $taxonomy);
            $termlink = $sitepress->post_type_archive_link_filter($termlink, $post_type);
        }
    }
    //echo '###2'.$termlink;
    return $termlink;
}
/**
 * Returns the term link with parameters.
 *
 * @since 1.0.0
 * @since 1.5.7 Changes for the neighbourhood system improvement.
 * @package GeoDirectory
 * @param string $termlink The term link
 * @param object $term Not yet implemented.
 * @param string $taxonomy The taxonomy name.
 * @return string The term link.
 */
function geodir_term_link($termlink, $term, $taxonomy)
{
    $geodir_taxonomies = geodir_get_taxonomies('', true);
    if (isset($taxonomy) && !empty($geodir_taxonomies) && in_array($taxonomy, $geodir_taxonomies)) {
        global $geodir_add_location_url;
        $include_location = false;
        $request_term = array();
        $listing_slug = geodir_get_listing_slug($taxonomy);
        if ($geodir_add_location_url != NULL && $geodir_add_location_url != '') {
            if ($geodir_add_location_url && get_option('geodir_add_location_url')) {
                $include_location = true;
            }
        } elseif (get_option('geodir_add_location_url') && isset($_SESSION['gd_multi_location']) && $_SESSION['gd_multi_location'] == 1) {
            $include_location = true;
        }
        if ($include_location) {
            global $post;
            $location_manager = defined('POST_LOCATION_TABLE') ? true : false;
            $neighbourhood_active = $location_manager && get_option('location_neighbourhoods') ? true : false;
            if (geodir_is_page('detail') && isset($post->country_slug)) {
                $location_terms = array('gd_country' => $post->country_slug, 'gd_region' => $post->region_slug, 'gd_city' => $post->city_slug);
                if ($neighbourhood_active && !empty($location_terms['gd_city']) && !empty($_SESSION['gd_neighbourhood'])) {
                    $location_terms['gd_neighbourhood'] = $_SESSION['gd_neighbourhood'];
                }
            } else {
                $location_terms = geodir_get_current_location_terms('query_vars');
            }
            $geodir_show_location_url = get_option('geodir_show_location_url');
            $location_terms = geodir_remove_location_terms($location_terms);
            if (!empty($location_terms)) {
                $url_separator = '';
                //get_option('geodir_listingurl_separator');
                if (get_option('permalink_structure') != '') {
                    $old_listing_slug = '/' . $listing_slug . '/';
                    $request_term = implode("/", $location_terms);
                    $new_listing_slug = '/' . $listing_slug . '/' . $request_term . '/';
                    $termlink = substr_replace($termlink, $new_listing_slug, strpos($termlink, $old_listing_slug), strlen($old_listing_slug));
                } else {
                    $termlink = geodir_getlink($termlink, $request_term);
                }
            }
        }
        // Alter the CPT slug is WPML is set to do so
        /* we can replace this with the below function
           if(function_exists('icl_object_id')){
               global $sitepress;
               $post_type = str_replace("category","",$taxonomy);
               $termlink = $sitepress->post_type_archive_link_filter( $termlink, $post_type);
           }*/
        // Alter the CPT slug if WPML is set to do so
        if (function_exists('icl_object_id')) {
            $post_types = get_option('geodir_post_types');
            $post_type = str_replace("category", "", $taxonomy);
            $post_type = str_replace("_tags", "", $post_type);
            $slug = $post_types[$post_type]['rewrite']['slug'];
            if (gd_wpml_slug_translation_turned_on($post_type)) {
                global $sitepress;
                $default_lang = $sitepress->get_default_language();
                $language_code = gd_wpml_get_lang_from_url($termlink);
                if (!$language_code) {
                    $language_code = $default_lang;
                }
                $org_slug = $slug;
                $slug = apply_filters('wpml_translate_single_string', $slug, 'WordPress', 'URL slug: ' . $slug, $language_code);
                if (!$slug) {
                    $slug = $org_slug;
                }
                $termlink = trailingslashit(preg_replace("/" . preg_quote($org_slug, "/") . "/", $slug, $termlink, 1));
            }
        }
    }
    return $termlink;
}
Exemplo n.º 3
0
/**
 * Retrieve the term link.
 *
 * @since 1.1.6
 *
 * @param string $termlink Term link URL.
 * @param object $term Term object.
 * @param string $taxonomy Taxonomy slug.
 * $return string The term link
 */
function geodir_cpt_term_link($termlink, $term, $taxonomy)
{
    if (geodir_cpt_no_location($taxonomy, true)) {
        $location_vars = geodir_get_current_location_terms('query_vars');
        if (!empty($location_vars)) {
            $listing_slug = geodir_get_listing_slug($taxonomy);
            if (get_option('permalink_structure')) {
                $location_vars = implode('/', $location_vars);
                $old_listing_slug = '/' . $listing_slug . '/' . $location_vars . '/';
                $new_listing_slug = '/' . $listing_slug . '/';
                $termlink = substr_replace($termlink, $new_listing_slug, strpos($termlink, $old_listing_slug), strlen($old_listing_slug));
            } else {
                $termlink = esc_url(remove_query_arg(array('gd_country', 'gd_region', 'gd_city'), $termlink));
            }
        }
    }
    return $termlink;
}