WordPress.org

Plugin Directory

Changeset 624201


Ignore:
Timestamp:
11/12/12 20:41:14 (17 months ago)
Author:
Chouby
Message:

bug corrections

Location:
polylang/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • polylang/trunk/include/api.php

    r623673 r624201  
    6262    function icl_object_id($id, $type, $return_original_if_missing, $lang = false) { 
    6363        global $polylang; 
    64         return isset($polylang) && ($lang = $lang ? $lang : pll_current_language()) && ($tr_id = $polylang->object_id($id, $type, $lang)) ? $tr_id : 
     64        return isset($polylang) && ($lang = $lang ? $lang : pll_current_language()) && ($tr_id = $polylang->get_translation($type, $id, $lang)) ? $tr_id : 
    6565            ($return_original_if_missing ? $id : null); 
    6666    } 
  • polylang/trunk/include/base.php

    r623673 r624201  
    1111    // used to cache results 
    1212    private $languages_list = array(); 
     13    private $language = array(); 
    1314    private $links = array(); 
    1415 
     
    6364 
    6465    // returns the language by its id or its slug 
    65     // Note: it seems that a numeric value is better for performance (3.2.1) 
     66    // Note: it seems that get_term_by slug is not cached (3.2.1) 
    6667    function get_language($value) { 
    67         $lang = is_object($value) ? $value : 
    68             ((is_numeric($value) || (int) $value) ? get_term((int) $value, 'language') : 
    69             (is_string($value) ? get_term_by('slug', $value , 'language') : // seems it is not cached in 3.2.1 
    70             false)); 
    71         return isset($lang) && $lang && !is_wp_error($lang) ? $lang : false; 
     68        if (is_object($value)) 
     69            return $value; 
     70 
     71        if (isset($this->language[$value])) 
     72            return $this->language[$value]; 
     73 
     74        $lang = (is_numeric($value) || (int) $value) ? get_term((int) $value, 'language') : 
     75            (is_string($value) ? get_term_by('slug', $value , 'language') : false); 
     76        return isset($lang) && $lang && !is_wp_error($lang) ? ($this->language[$value] = $lang) : false; 
    7277    } 
    7378 
     
    101106    } 
    102107 
    103     // returns the id of the translation of a port or term 
    104     // created for compatibility with the WPML API function icl_object_id 
    105     function object_id($id, $type, $lang) { 
    106         return in_array($type, $this->post_types) ? $this->get_translation('post', $id, $lang) : 
    107             (in_array($type, $this->taxonomies) ? $this->get_translation('term', $id, $lang) : false); 
    108     } 
    109  
    110108    // returns the id of the translation of a post or term 
    111109    // $type: either 'post' or 'term' 
     
    120118    // returns an array of translations of a post or term 
    121119    function get_translations($type, $id) { 
     120        $type = ($type == 'post' || in_array($type, $this->post_types)) ? 'post' : (($type == 'term' || in_array($type, $this->taxonomies)) ? 'term' : false); 
    122121        // maybe_unserialize due to useless serialization in versions < 0.9 
    123         return maybe_unserialize(get_metadata($type, $id, '_translations', true));  
     122        return $type ? maybe_unserialize(get_metadata($type, $id, '_translations', true)) : array();  
    124123    } 
    125124 
  • polylang/trunk/include/core.php

    r623673 r624201  
    7474 
    7575        // prevents redirection of the homepage 
    76         add_filter('redirect_canonical', array(&$this, 'redirect_canonical'), 10, 2); 
     76        add_filter('redirect_canonical', array(&$this, 'stop_redirect_canonical'), 10, 2); 
    7777 
    7878        // redirects incoming links to the proper URL when adding the language code to all urls 
    7979        if ($this->options['force_lang'] && get_option('permalink_structure') && PLL_LANG_EARLY) 
    80             add_action('template_redirect',  array(&$this, 'redirect_canonical_with_lang'), 20); // after Wordpress redirect_canonical 
     80            add_action('template_redirect',  array(&$this, 'redirect_canonical'), 20); // after Wordpress redirect_canonical 
    8181 
    8282        // adds javascript at the end of the document 
     
    560560 
    561561    // prevents redirection of the homepage when using page on front 
    562     function redirect_canonical($redirect_url, $requested_url) { 
     562    function stop_redirect_canonical($redirect_url, $requested_url) { 
    563563        return $requested_url == home_url('/') || strpos($requested_url, $this->page_link('', get_option('page_on_front'))) !== false ? false : $redirect_url; 
    564564    } 
    565565 
    566566    // redirects incoming links to the proper URL when adding the language code to all urls 
    567     function redirect_canonical_with_lang() { 
    568         $requested_url  = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
     567    function redirect_canonical($requested_url = false, $do_redirect = true) { 
     568        if (!$requested_url) 
     569            $requested_url  = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
     570 
    569571        if (is_single() || is_page()) { 
    570572            global $post; 
     
    577579                $redirect_url = get_term_link((int)$obj->term_id, $obj->taxonomy); 
    578580        } 
    579         if (isset($redirect_url) && !is_wp_error($redirect_url) && $redirect_url != $requested_url) { 
    580             wp_redirect($redirect_url, 301); 
    581             exit; 
    582         } 
     581 
     582        if (!isset($redirect_url) || is_wp_error($redirect_url) || $redirect_url == $requested_url) 
     583            return false; 
     584 
     585        if ($do_redirect) { 
     586            // protect against chained redirects 
     587            if (!$this->redirect_canonical($redirect_url, false) ) { 
     588                wp_redirect($redirect_url, 301); 
     589                exit; 
     590            }  
     591            else 
     592                return false; 
     593        } 
     594 
     595        return $redirect_url; 
    583596    } 
    584597 
     
    822835                // direct call from the theme 
    823836                (isset($trace['file']) && strpos($trace['file'], $theme) !== false && 
    824                     in_array($trace['function'], array('home_url', 'bloginfo', 'get_bloginfo')) ); 
     837                    in_array($trace['function'], array('home_url', 'get_home_url', 'bloginfo', 'get_bloginfo')) ); 
    825838 
    826839            if ($ok) 
     
    847860            return $this->home_urls[$language->slug][$is_search] = $this->page_link('', $id); 
    848861 
    849         return $this->home_urls[$language->slug][$is_search] = get_term_link($language, 'language'); 
     862        return $this->home_urls[$language->slug][$is_search] = trailingslashit(get_term_link($language, 'language')); 
    850863    } 
    851864 
  • polylang/trunk/polylang.php

    r623673 r624201  
    33Plugin Name: Polylang 
    44Plugin URI: http://wordpress.org/extend/plugins/polylang/ 
    5 Version: 0.9.4.8 
     5Version: 0.9.4.9 
    66Author: F. Demarle 
    77Description: Adds multilingual capability to Wordpress 
     
    2727*/ 
    2828 
    29 define('POLYLANG_VERSION', '0.9.4.8'); 
     29define('POLYLANG_VERSION', '0.9.4.9'); 
    3030define('PLL_MIN_WP_VERSION', '3.1'); 
    3131 
  • polylang/trunk/readme.txt

    r623673 r624201  
    106106* Bug correction: on some installation strings translations do not work with some special characters 
    107107* Bug correction: incoming links are not redirected to canonical url when adding the language code to all urls and hiding the code for the default language 
     108* Bug correction: search form does not work in non default language when using permalinks without trailing slash 
    108109 
    109110= 0.9.4 (2012-10-23) = 
Note: See TracChangeset for help on using the changeset viewer.