WordPress.org

Plugin Directory

Changeset 634550


Ignore:
Timestamp:
12/05/12 21:40:52 (17 months ago)
Author:
Chouby
Message:

ajax on frontend with language code in all urls

File:
1 edited

Legend:

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

    r634506 r634550  
    227227    function setup_theme() { 
    228228        // special case for ajax request 
    229         if (isset($_REQUEST['pll_load_front'])) { 
     229        if (isset($_REQUEST['pll_load_front'])) 
    230230            $this->curlang = isset($_REQUEST['lang']) && $_REQUEST['lang'] ? $this->get_language($_REQUEST['lang']) : $this->get_preferred_language(); 
    231             do_action('pll_language_defined'); 
    232             return; 
    233         } 
    234  
    235         $root = $this->options['rewrite']? '' : 'language/'; 
    236  
    237         foreach ($this->get_languages_list() as $language) 
    238             $languages[] = $language->slug; 
    239  
    240         $languages = $GLOBALS['wp_rewrite']->using_permalinks() ? 
    241             '#\/'.$root.'('.implode('|', $languages).')\/#' : 
    242             '#lang=('.implode('|', $languages).')#'; 
    243  
    244         preg_match($languages, trailingslashit($_SERVER['REQUEST_URI']), $matches); 
    245  
    246         // home is resquested 
    247         // some PHP setups turn requests for / into /index.php in REQUEST_URI 
    248         // thanks to Gonçalo Peres for pointing out the issue with queries unknown to WP 
    249         // http://wordpress.org/support/topic/plugin-polylang-language-homepage-redirection-problem-and-solution-but-incomplete?replies=4#post-2729566 
    250         if (str_replace('www.', '', home_url('/')) == trailingslashit((is_ssl() ? 'https://' : 'http://').str_replace('www.', '', $_SERVER['HTTP_HOST']).str_replace(array('index.php', '?'.$_SERVER['QUERY_STRING']), array('', ''), $_SERVER['REQUEST_URI']))) { 
    251             // take care to post preview http://wordpress.org/support/topic/static-frontpage-url-parameter-url-language-information 
    252             if (isset($_GET['preview']) && isset($_GET['p']) && $lg = $this->get_post_language($_GET['p'])) 
    253                 $this->curlang = $lg ? $lg : $this->get_language($this->options['default_lang']); 
    254             else 
    255                 $this->home_requested(); 
    256         } 
    257         // $matches[1] is the slug of the requested language 
    258         elseif ($matches) 
    259             $this->curlang = $this->get_language($matches[1]); 
    260         elseif (false === strpos($_SERVER['SCRIPT_NAME'], 'index.php')) // wp-login, wp-signup, wp-activate 
    261             $this->curlang = $this->get_preferred_language(); 
     231 
     232        // standard case 
    262233        else { 
    263             $this->curlang = $this->get_language($this->options['default_lang']); 
    264             add_action('wp', array(&$this, 'check_language_code_in_url')); // before Wordpress redirect_canonical 
     234            $root = $this->options['rewrite']? '' : 'language/'; 
     235 
     236            foreach ($this->get_languages_list() as $language) 
     237                $languages[] = $language->slug; 
     238 
     239            $languages = $GLOBALS['wp_rewrite']->using_permalinks() ? 
     240                '#\/'.$root.'('.implode('|', $languages).')\/#' : 
     241                '#lang=('.implode('|', $languages).')#'; 
     242 
     243            preg_match($languages, trailingslashit($_SERVER['REQUEST_URI']), $matches); 
     244 
     245            // home is resquested 
     246            // some PHP setups turn requests for / into /index.php in REQUEST_URI 
     247            // thanks to Gonçalo Peres for pointing out the issue with queries unknown to WP 
     248            // http://wordpress.org/support/topic/plugin-polylang-language-homepage-redirection-problem-and-solution-but-incomplete?replies=4#post-2729566 
     249            if (str_replace('www.', '', home_url('/')) == trailingslashit((is_ssl() ? 'https://' : 'http://').str_replace('www.', '', $_SERVER['HTTP_HOST']).str_replace(array('index.php', '?'.$_SERVER['QUERY_STRING']), array('', ''), $_SERVER['REQUEST_URI']))) { 
     250                // take care to post preview http://wordpress.org/support/topic/static-frontpage-url-parameter-url-language-information 
     251                if (isset($_GET['preview']) && isset($_GET['p']) && $lg = $this->get_post_language($_GET['p'])) 
     252                    $this->curlang = $lg ? $lg : $this->get_language($this->options['default_lang']); 
     253                else 
     254                    $this->home_requested(); 
     255            } 
     256            // $matches[1] is the slug of the requested language 
     257            elseif ($matches) 
     258                $this->curlang = $this->get_language($matches[1]); 
     259            elseif (false === strpos($_SERVER['SCRIPT_NAME'], 'index.php')) // wp-login, wp-signup, wp-activate 
     260                $this->curlang = $this->get_preferred_language(); 
     261            else { 
     262                $this->curlang = $this->get_language($this->options['default_lang']); 
     263                add_action('wp', array(&$this, 'check_language_code_in_url')); // before Wordpress redirect_canonical 
     264            } 
    265265        } 
    266266 
     
    828828 
    829829        $theme = get_theme_root(); 
     830        // FIXME can I decrease the size of the array to improve speed? 
    830831        foreach (array_reverse(debug_backtrace(/*!DEBUG_BACKTRACE_PROVIDE_OBJECT|DEBUG_BACKTRACE_IGNORE_ARGS*/)) as $trace) { 
    831832            // search form 
Note: See TracChangeset for help on using the changeset viewer.