WordPress.org

Plugin Directory

Changeset 378604


Ignore:
Timestamp:
04/28/11 22:36:49 (3 years ago)
Author:
leogermani
Message:

[fix] shorter post type name because it has a limit of 20 chars
[mod] function that get the link to the translations

Location:
multi-language-framework/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • multi-language-framework/trunk/functions.php

    r356875 r378604  
    301301    global $wpdb; 
    302302     
    303     $post_type_base = preg_replace('/(.+)_translations_([a-zA-Z]{2})/', "$1", $post_type); 
     303    $post_type_base = preg_replace('/(.+)_t_([a-zA-Z]{2})/', "$1", $post_type); 
    304304     
    305305    $enabled_languages = mlf_get_option('enabled_languages'); 
     
    310310             
    311311        $translation_id = false; 
    312         $p_type = $post_type_base . '_translations_' . $lang;             
    313          
    314         if ($p_type == $post_type_base . '_translations_' . $default_language) 
     312        $p_type = $post_type_base . '_t_' . $lang;             
     313         
     314        if ($p_type == $post_type_base . '_t_' . $default_language) 
    315315            $p_type = $post_type_base; 
    316316 
     
    345345     
    346346    echo '<ul id="languages_list">'; 
    347     foreach ($mlf_config['enabled_languages'] as $lang) { 
    348         $mlf_config['current_language'] = $lang; 
    349         $flag_img = MLF_PLUGIN_URL . $mlf_config['flag_location'] . $mlf_config['flag'][$lang]; 
    350         ?> 
    351         <li> 
    352             <a href="<?php echo mlf_convertURL(); ?>"> 
    353                 <img src="<?php echo $flag_img; ?>" /> 
    354                 <?php echo $mlf_config['language_name'][$lang]; ?> 
    355             </a> 
    356         </li> 
    357         <?php 
    358     } 
     347     
     348    if (is_singular()) { 
     349     
     350        global $wp_query; 
     351        $post = $wp_query->get_queried_object(); 
     352        $other_languages = mlf_get_tranlsations_ids($post->ID, $post->post_type); 
     353         
     354        foreach ($mlf_config['enabled_languages'] as $lang) { 
     355             
     356            if ($originalLanguage == $lang) 
     357                continue; 
     358             
     359            $flag_img = MLF_PLUGIN_URL . $mlf_config['flag_location'] . $mlf_config['flag'][$lang]; 
     360             
     361            // does this entry have a translation? 
     362            if ($other_languages[$lang]) { 
     363                // We have to temporarily change the language to retrieve unflitered permalinks 
     364                $mlf_config['current_language'] = $mlf_config['default_language']; 
     365                $link = get_permalink($other_languages[$lang]); 
     366            } else { 
     367                $mlf_config['current_language'] = $lang; 
     368                $link = mlf_convertURL(); 
     369            } 
     370 
     371            ?> 
     372            <li> 
     373                <a href="<?php echo $link; ?>"> 
     374                    <img src="<?php echo $flag_img; ?>" /> 
     375                    <?php echo $mlf_config['language_name'][$lang]; ?> 
     376                </a> 
     377            </li> 
     378            <?php 
     379             
     380        } 
     381     
     382     
     383    } else { 
     384     
     385     
     386        foreach ($mlf_config['enabled_languages'] as $lang) { 
     387         
     388            if ($originalLanguage == $lang) 
     389                continue; 
     390             
     391            $mlf_config['current_language'] = $lang; 
     392            $flag_img = MLF_PLUGIN_URL . $mlf_config['flag_location'] . $mlf_config['flag'][$lang]; 
     393            ?> 
     394            <li> 
     395                <a href="<?php echo mlf_convertURL(); ?>"> 
     396                    <img src="<?php echo $flag_img; ?>" /> 
     397                    <?php echo $mlf_config['language_name'][$lang]; ?> 
     398                </a> 
     399            </li> 
     400            <?php 
     401             
     402        } 
     403         
     404     
     405    } 
     406     
    359407    echo '</ul>'; 
    360408     
  • multi-language-framework/trunk/parse_query.php

    r356875 r378604  
    2929        $post_type = $wp_query->query_vars['post_type'] ? $wp_query->query_vars['post_type'] : 'post'; 
    3030                 
    31         $wp_query->query_vars['post_type'] = $post_type . '_translations_' . $mlf_config['current_language']; 
     31        $wp_query->query_vars['post_type'] = $post_type . '_t_' . $mlf_config['current_language']; 
    3232     
    3333    } else { 
     
    4242             
    4343            $wp_query->query_vars['post_type'] = $post_type; 
    44             //$wp_query->query_vars['post_type'] = $post_type . '_translations_' . $mlf_config['current_language']; 
     44            //$wp_query->query_vars['post_type'] = $post_type . '_t_' . $mlf_config['current_language']; 
    4545            $wp_query->query_vars['name'] = $wp_query->query_vars['pagename']; 
    4646            $wp_query->query_vars[$wp_query->query_vars['post_type']] =  $wp_query->query_vars['name']; 
     
    5151             
    5252                'post_type' => $post_type, 
    53                 //'post_type' => $post_type . '_translations_' . $mlf_config['current_language'], 
     53                //'post_type' => $post_type . '_t_' . $mlf_config['current_language'], 
    5454                'name' => $wp_query->query_vars['pagename'], 
    5555                $wp_query->query_vars['post_type'] => $wp_query->query_vars['name'] 
     
    7676        global $wpdb, $mlf_config; 
    7777        $post = $wp_query->post; 
    78         $post_type = preg_replace('/(.+)_translations_([a-zA-Z]{2})/', "$1", $post->post_type); 
     78        $post_type = preg_replace('/(.+)_t_([a-zA-Z]{2})/', "$1", $post->post_type); 
    7979         
    80         if (preg_match('/(.+)_translations_([a-zA-Z]{2})/', $post->post_type)) 
    81             $post_lang = preg_replace('/(.+)_translations_([a-zA-Z]{2})/', "$2", $post->post_type); 
     80        if (preg_match('/(.+)_t_([a-zA-Z]{2})/', $post->post_type)) 
     81            $post_lang = preg_replace('/(.+)_t_([a-zA-Z]{2})/', "$2", $post->post_type); 
    8282        else 
    8383            $post_lang = $default_language; 
     
    8888            return; 
    8989         
    90         $post_type_search = $default_language == $mlf_config['current_language'] ? $post_type : $post_type . "_translations_" . $mlf_config['current_language']; 
     90        $post_type_search = $default_language == $mlf_config['current_language'] ? $post_type : $post_type . "_t_" . $mlf_config['current_language']; 
    9191         
    9292        $query = "select * from $wpdb->posts join $wpdb->postmeta on ID = post_id WHERE post_type = '$post_type_search'  
  • multi-language-framework/trunk/post_types.php

    r356883 r378604  
    2323            $labels = (array) $wp_post_types[$p_type]->labels; 
    2424            $labels['name'] .= ' - ' . $language_name[$l]; 
     25            $labels['menu_name'] .= ' - ' . $language_name[$l]; 
    2526             
    2627            switch ($p_type) { 
     
    4647                'supports' => array('title','editor','author','thumbnail','excerpt','comments') 
    4748            );  
    48             register_post_type($p_type . '_translations_' . $l, $args); 
     49             
     50            //TODO: Post types names can only have 20 chars. Ho to deal with it? 
     51             
     52            register_post_type($p_type . '_t_' . $l, $args); 
    4953             
    5054        } 
     
    102106            $post_type = $_POST['post_type']; 
    103107         
    104         $post_type_base = preg_replace('/^(\S+)_translations_\S{2}$/', "$1", $post_type); 
     108        $post_type_base = preg_replace('/^(\S+)_t_\S{2}$/', "$1", $post_type); 
    105109         
    106110        foreach ($enabled_languages as $lang) { 
    107111             
    108112            $translation_id = false; 
    109             $p_type = $post_type_base . '_translations_' . $lang;             
     113            $p_type = $post_type_base . '_t_' . $lang;             
    110114            $flag_img = MLF_PLUGIN_URL . $flag_location . $flag[$lang]; 
    111115             
    112             if ($p_type == $post_type_base . '_translations_' . $default_language) 
     116            if ($p_type == $post_type_base . '_t_' . $default_language) 
    113117                $p_type = $post_type_base; 
    114118 
     
    140144         
    141145        foreach ($enabled_languages as $lang) { 
    142             add_meta_box( 'post_translations',__('Post Translations', 'mlf'),'post_translation_inner_box', $p . '_translations_' . $lang, 'side' ); 
    143             add_meta_box( 'mlf_other_version_id',__('Post Translations', 'mlf'),'mlf_other_versions_box', $p . '_translations_' . $lang, 'normal', 'high' ); 
     146            add_meta_box( 'post_translations',__('Post Translations', 'mlf'),'post_translation_inner_box', $p . '_t_' . $lang, 'side' ); 
     147            add_meta_box( 'mlf_other_version_id',__('Post Translations', 'mlf'),'mlf_other_versions_box', $p . '_t_' . $lang, 'normal', 'high' ); 
    144148        } 
    145149     
     
    181185     
    182186    $post_type = $post->post_type; 
    183     $post_type_base = preg_replace('/^(\S+)_translations_\S{2}$/', "$1", $post->post_type); 
     187    $post_type_base = preg_replace('/^(\S+)_t_\S{2}$/', "$1", $post->post_type); 
    184188     
    185189    $flag_location = mlf_get_option('flag_location'); 
     
    189193         
    190194        $translation_id = false; 
    191         $p_type = $post_type_base . '_translations_' . $lang;             
     195        $p_type = $post_type_base . '_t_' . $lang;             
    192196        $flag_img = MLF_PLUGIN_URL . $flag_location . $flag[$lang]; 
    193197         
    194         if ($p_type == $post_type_base . '_translations_' . $default_language) 
     198        if ($p_type == $post_type_base . '_t_' . $default_language) 
    195199            $p_type = $post_type_base; 
    196200 
     
    329333            $posts->the_post(); 
    330334             
    331             if (preg_match('/^\S+_translations_(\S{2})$/', $post->post_type)) 
    332                 $lang = preg_replace('/^\S+_translations_(\S{2})$/', "$1", $post->post_type); 
     335            if (preg_match('/^\S+_t_(\S{2})$/', $post->post_type)) 
     336                $lang = preg_replace('/^\S+_t_(\S{2})$/', "$1", $post->post_type); 
    333337            else 
    334338                $lang = $default_language; 
  • multi-language-framework/trunk/readme.txt

    r356875 r378604  
    2727 
    2828All the options you set in the admin are language-independent. So you can have a different set of wigets for each language of your site. If you want a widget to allways appear you have to edit the widgets settings for all the languages. 
     29 
     30== Known Issues == 
     31 
     32Will not work with Post types with a name bigger than 15 chars  
  • multi-language-framework/trunk/settings.php

    r356875 r378604  
    4040                    <?php foreach ($wp_post_types as $type_name => $type) : ?> 
    4141                         
    42                         <?php if ($type_name == 'attachment' || $type_name == 'revision' || $type_name == 'nav_menu_item' || preg_match('/_translations_/', $type_name)) continue; ?> 
     42                        <?php if ($type_name == 'attachment' || $type_name == 'revision' || $type_name == 'nav_menu_item' || preg_match('/_t_/', $type_name)) continue; ?> 
    4343                     
    4444                        <input type="checkbox" name="mlf_config[post_types][]" value="<?php echo $type_name; ?>" <?php if (in_array($type_name, $mlf_config['post_types'])) echo 'checked'; ?> > <?php echo $type_name; ?> <br /> 
Note: See TracChangeset for help on using the changeset viewer.