WordPress.org

Plugin Directory

Changeset 623673


Ignore:
Timestamp:
11/11/12 12:49:20 (18 months ago)
Author:
Chouby
Message:

improve WPML API compatibility and bug corrections

Location:
polylang/trunk
Files:
9 edited

Legend:

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

    r619846 r623673  
    294294 
    295295                } 
     296                wp_redirect('admin.php?page=mlang&tab=settings'); 
     297                exit; 
    296298                break; 
    297299 
     
    409411        $terms = get_terms($this->taxonomies, array('get'=>'all', 'fields'=>'ids')); 
    410412        $tr_terms = $wpdb->get_col("SELECT term_id FROM $wpdb->termmeta WHERE meta_key = '_language'"); 
    411         $terms = array_unique(array_diff($terms, $tr_terms), SORT_NUMERIC); // array_unique to avoid duplicates if a term is in more than one taxonomy 
     413        $terms = array_unique(array_diff($terms, $tr_terms)); // array_unique to avoid duplicates if a term is in more than one taxonomy 
    412414 
    413415        return apply_filters('pll_get_objects_with_no_lang', empty($posts) && empty($terms) ? false : array('posts' => $posts, 'terms' => $terms)); 
  • polylang/trunk/include/api.php

    r614927 r623673  
    1616function pll_get_post($post_id, $slug = false) { 
    1717    global $polylang; 
    18     $slug = $slug ? $slug : pll_current_language(); 
    19     return isset($polylang) && $slug ? $polylang->get_post($post_id, $slug) : null; 
     18    return isset($polylang) && ($slug = $slug ? $slug : pll_current_language()) ? $polylang->get_post($post_id, $slug) : null; 
    2019} 
    2120 
     
    2322function pll_get_term($term_id, $slug = false) { 
    2423    global $polylang; 
    25     $slug = $slug ? $slug : pll_current_language(); 
    26     return isset($polylang) && $slug ? $polylang->get_term($term_id, $slug) : null; 
     24    return isset($polylang) && ($slug = $slug ? $slug : pll_current_language()) ? $polylang->get_term($term_id, $slug) : null; 
    2725} 
    2826 
     
    5149 
    5250// compatibility with WPML API 
     51add_action('pll_language_defined', 'pll_define_wpml_constants'); 
     52 
     53function pll_define_wpml_constants() { 
     54    if(!defined('ICL_LANGUAGE_CODE')) 
     55    define('ICL_LANGUAGE_CODE', pll_current_language()); 
     56 
     57    if(!defined('ICL_LANGUAGE_NAME')) 
     58    define('ICL_LANGUAGE_NAME', pll_current_language('name')); 
     59} 
     60 
     61if (!function_exists('icl_object_id')) { 
     62    function icl_object_id($id, $type, $return_original_if_missing, $lang = false) { 
     63        global $polylang; 
     64        return isset($polylang) && ($lang = $lang ? $lang : pll_current_language()) && ($tr_id = $polylang->object_id($id, $type, $lang)) ? $tr_id : 
     65            ($return_original_if_missing ? $id : null); 
     66    } 
     67} 
     68 
    5369if (!function_exists('icl_get_home_url')) { 
    5470    function icl_get_home_url() { 
  • polylang/trunk/include/base.php

    r611088 r623673  
    9999            delete_metadata($type, $id, '_translations'); 
    100100        } 
     101    } 
     102 
     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); 
    101108    } 
    102109 
  • polylang/trunk/include/core.php

    r620386 r623673  
    7575        // prevents redirection of the homepage 
    7676        add_filter('redirect_canonical', array(&$this, 'redirect_canonical'), 10, 2); 
     77 
     78        // redirects incoming links to the proper URL when adding the language code to all urls 
     79        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 
    7781 
    7882        // adds javascript at the end of the document 
     
    257261 
    258262        $GLOBALS['l10n']['pll_string'] = $this->mo_import($this->curlang); 
     263        do_action('pll_language_defined'); 
    259264    } 
    260265 
     
    339344                // and finally load user defined strings 
    340345                $GLOBALS['l10n']['pll_string'] = $this->mo_import($this->curlang); 
     346                do_action('pll_language_defined'); 
    341347            } 
    342348        } 
     
    556562    function redirect_canonical($redirect_url, $requested_url) { 
    557563        return $requested_url == home_url('/') || strpos($requested_url, $this->page_link('', get_option('page_on_front'))) !== false ? false : $redirect_url; 
     564    } 
     565 
     566    // 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']; 
     569        if (is_single() || is_page()) { 
     570            global $post; 
     571            if (isset($post->ID) && in_array($post->post_type, $this->post_types)) 
     572                $redirect_url = get_permalink((int)$post->ID); 
     573        } 
     574        elseif (is_category() || is_tag() || is_tax()) { 
     575            $obj = $GLOBALS['wp_query']->get_queried_object(); 
     576            if (in_array($obj->taxonomy, $this->taxonomies)) 
     577                $redirect_url = get_term_link((int)$obj->term_id, $obj->taxonomy); 
     578        } 
     579        if (isset($redirect_url) && !is_wp_error($redirect_url) && $redirect_url != $requested_url) { 
     580            wp_redirect($redirect_url, 301); 
     581            exit; 
     582        } 
    558583    } 
    559584 
  • polylang/trunk/include/languages-form.php

    r582366 r623673  
    182182 
    183183<div class="form-wrap"> 
    184     <form id="options-lang" method="post" action="admin.php?page=mlang&tab=settings" class="validate"> 
     184    <form id="options-lang" method="post" action="admin.php?page=mlang&tab=settings&noheader=true" class="validate"> 
    185185    <?php wp_nonce_field('options-lang', '_wpnonce_options-lang');?> 
    186186    <input type="hidden" name="action" value="options" /> 
  • polylang/trunk/include/list-table.php

    r619846 r623673  
    107107 
    108108    function column_default($item, $column_name) { 
    109         return $item[$column_name]; 
     109        return $column_name == 'string' ? format_to_edit($item[$column_name]) : $item[$column_name]; // don't interpret special chars for the string column 
    110110    } 
    111111 
     
    116116                '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' : 
    117117                '<input name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />'; 
    118             $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>', 
     118            $out .= sprintf('<div class="translation"><label for="%1$s-%2$s">%3$s</label>'.$input_type.'</div>'."\n", 
    119119                esc_attr($key), 
    120120                esc_attr($item['row']), 
    121121                esc_html($key), 
    122                 $item['multiline'] ? esc_textarea($translation) : esc_html($translation)); 
     122                format_to_edit($translation)); // don't interpret special chars 
    123123        } 
    124124        return $out; 
  • polylang/trunk/include/widget.php

    r600613 r623673  
    1010    function widget($args, $instance) { 
    1111        global $polylang; 
    12         if (!(isset($polylang) && $polylang->get_languages_list())) 
     12        if (!(isset($polylang) && $polylang->get_languages_list() && $list = $polylang->the_languages(array_merge($instance, array('echo' => 0))))) 
    1313            return; 
    1414 
     
    2323        if (!$dropdown) 
    2424            echo "<ul>\n"; 
    25         $polylang->the_languages($instance); 
     25        echo $list; 
    2626        if (!$dropdown) 
    2727            echo "</ul>\n"; 
  • polylang/trunk/polylang.php

    r620386 r623673  
    33Plugin Name: Polylang 
    44Plugin URI: http://wordpress.org/extend/plugins/polylang/ 
    5 Version: 0.9.4.6 
     5Version: 0.9.4.8 
    66Author: F. Demarle 
    77Description: Adds multilingual capability to Wordpress 
     8Text Domain: polylang 
     9Domain Path: /languages 
    810*/ 
    911 
     
    2527*/ 
    2628 
    27 define('POLYLANG_VERSION', '0.9.4.6'); 
     29define('POLYLANG_VERSION', '0.9.4.8'); 
    2830define('PLL_MIN_WP_VERSION', '3.1'); 
    2931 
  • polylang/trunk/readme.txt

    r620386 r623673  
    9797 
    9898* The user can now choose the number of languages and strings translations to display 
     99* Add compatibility with the 'icl_object_id' function and ICL_LANGUAGE_CODE and ICL_LANGUAGE_NAME constants from the WPML API 
    99100* Bug correction: post preview does not work when adding the language code to all urls 
    100101* Bug correction: redirect to front page in default language when posting a comment on static front page 
     
    103104* Bug correction: redirect erase 'POST' variables on homepage when adding the language code to all urls 
    104105* Bug correction: English (en_US) loads rtl style when using a localized WordPress package with an rtl language 
     106* Bug correction: on some installation strings translations do not work with some special characters 
     107* 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 
    105108 
    106109= 0.9.4 (2012-10-23) = 
Note: See TracChangeset for help on using the changeset viewer.