Changeset 119


Ignore:
Timestamp:
03/29/2009 03:17:58 PM (3 years ago)
Author:
amir
Message:

Cleaned up the code allowing to edit and post translation.

Location:
trunk/WordPress/plugin/transposh
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/transposh.php

    r117 r119  
    238238        $home_url_quoted = preg_replace("/\//", "\\/", $home_url_quoted); 
    239239 
    240         $enable_auto_translate = get_option(ENABLE_AUTO_TRANSLATE,1) && is_translator(); 
     240        $enable_auto_translate = get_option(ENABLE_AUTO_TRANSLATE,1) && is_translation_allowed(); 
    241241 
    242242        if($wp_rewrite->using_permalinks() && get_option(ENABLE_PERMALINKS_REWRITE)) 
     
    478478 */ 
    479479function add_transposh_css() { 
    480         global $plugin_url, $wp_query; 
    481         if (!isset($wp_query->query_vars[LANG_PARAM])) 
    482         { 
     480        global $plugin_url; 
     481         
     482        if(!is_translation_allowed()) 
     483        { 
     484                //translation not allowed - no need for the transposh.css        
    483485                return; 
    484486        } 
    485  
    486         $lang = $wp_query->query_vars[LANG_PARAM]; 
    487         $editable_langs = get_option(EDITABLE_LANGS); 
    488  
    489         if(strpos($editable_langs, $lang) === FALSE) 
    490         { 
    491                 //not an editable language - no need for any css. 
    492                 return; 
    493         } 
    494  
    495487        //include the transposh.css 
    496488        wp_enqueue_style("transposh","$plugin_url/transposh.css",array(),'1.0.1'); 
     
    505497        global $plugin_url, $wp_query, $lang, $home_url,  $enable_auto_translate; 
    506498 
    507         if (!isset($wp_query->query_vars[LANG_PARAM])) 
    508         { 
     499        if(!is_translation_allowed()) 
     500        { 
     501                //translation not allowed - no need for any js.  
    509502                return; 
    510503        } 
    511         $lang = $wp_query->query_vars[LANG_PARAM]; 
    512         $editable_langs = get_option(EDITABLE_LANGS); 
    513  
    514         if(strpos($editable_langs, $lang) === FALSE) 
    515         { 
    516                 //not an editable language - no need for any js. 
    517                 return; 
    518         } 
    519  
     504         
    520505        $is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM]; 
    521  
    522506        if (!$is_edit_param_enabled && ! $enable_auto_translate) 
    523507        { 
    524                 //TODO: check permission later - for now just make sure we don't load the 
    525                 //js code when it is not needed 
     508                //Not in any translation mode - no need for any js. 
    526509                return; 
    527510        } 
     
    548531} 
    549532 
     533 
     534/** 
     535 * Determine if the currently selected language (taken from the query parameters) is in the admin's list  
     536 * of editable languages and the current user is allowed to translate.  
     537 *   
     538 * @return TRUE if translation allowed otherwise FALSE 
     539 */ 
     540function is_translation_allowed() 
     541{ 
     542        global $wp_query; 
     543 
     544        if(!is_translator()) 
     545        { 
     546                return FALSE; 
     547        } 
     548         
     549        if (!isset($wp_query->query_vars[LANG_PARAM])) 
     550        { 
     551                return FALSE; 
     552        } 
     553         
     554        $lang = $wp_query->query_vars[LANG_PARAM]; 
     555        return is_editable_lang($lang); 
     556} 
     557 
     558/** 
     559 * Determine if the given language in on the list of editable languages 
     560 * @return TRUE if editable othewise FALSE 
     561 */ 
     562function is_editable_lang($lang) 
     563{ 
     564        $editable_langs = get_option(EDITABLE_LANGS); 
     565 
     566        if(strpos($editable_langs, $lang) === FALSE) 
     567        { 
     568                //not an editable language 
     569                return FALSE; 
     570        } 
     571         
     572        return TRUE; 
     573} 
     574 
    550575//Register callbacks 
    551576add_filter('query_vars', 'parameter_queryvars' ); 
  • trunk/WordPress/plugin/transposh/transposh_admin.php

    r101 r119  
    140140        $langs = get_option(EDITABLE_LANGS); 
    141141 
    142         if(strstr($langs, $code)) 
     142        if(strpos($langs, $code) !== FALSE) 
    143143        { 
    144144                return 'checked="checked"'; 
     
    155155{ 
    156156        $langs = get_option(VIEWABLE_LANGS); 
    157         if(strstr($langs, $code)) 
     157        if(strpos($langs, $code) !== FALSE) 
    158158        { 
    159159                return 'checked="checked"'; 
  • trunk/WordPress/plugin/transposh/transposh_db.php

    r117 r119  
    118118        } 
    119119 
    120         //Check that use is allowed to translate 
    121         if(!is_translator()) 
     120        //Check that user is allowed to translate this language 
     121        if(!is_translator() || !is_editable_lang($lang)) 
    122122        { 
    123123                logger("Unauthorized translation attempt " . $_SERVER['REMOTE_ADDR'] , 1); 
     124                header("HTTP/1.0 401 Unauthorized translation"); 
     125                exit; 
    124126        } 
    125127 
Note: See TracChangeset for help on using the changeset viewer.