Changeset 103


Ignore:
Timestamp:
03/26/2009 09:52:04 AM (3 years ago)
Author:
amir
Message:

Some more refactoring and cleanup.

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

Legend:

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

    r93 r103  
    2626require_once("logging.php"); 
    2727require_once("constants.php"); 
    28  
    29 //The language to which the current page will be translated to. 
    30 $lang; 
     28require_once("globals.php"); 
    3129 
    3230//The html page which starts contains the content being translated 
     
    4543$tr_mark = 0; 
    4644 
    47 //Is the current use is in edit mode. 
    48 $is_edit_mode = FALSE; 
    49  
    5045//Segment identifier within tags (span/img) mainly for use by js code on the client 
    5146$segment_id = 0; 
     
    5651//Is current position within the channel tag, i.e. RSS feed 
    5752$is_in_channel = FALSE; 
    58  
    59 //Indicates whether automatic translation (i.e. google) is enabled for this page 
    60 $enable_auto_translate; 
    6153 
    6254/* 
  • trunk/WordPress/plugin/transposh/transposh.php

    r102 r103  
    2929require_once("logging.php"); 
    3030require_once("constants.php"); 
     31require_once("globals.php"); 
    3132require_once("transposh_db.php"); 
    3233require_once("parser.php"); 
     
    3435require_once("transposh_admin.php"); 
    3536 
    36 // 
    37 // Global variables 
    38 // 
    39  
    40 //Home url of the blog 
    41 $home_url; 
    42  
    43 //Home url of the blog - already quoted and ready for regex 
    44 $home_url_quoted; 
    45  
    46 //The url pointing to the base of the plugin 
    47 $plugin_url; 
    48  
    4937//Error message displayed for the admin in case of failure 
    5038$admin_msg; 
     
    11098function process_anchor_tag($start, $end) 
    11199{ 
    112         global $home_url, $home_url_quoted, $lang, $is_edit_mode, $wp_rewrite; 
     100        global $home_url, $home_url_quoted, $lang, $is_edit_mode, $enable_permalinks_rewrite; 
    113101 
    114102        $href = get_attribute($start, $end, 'href'); 
     
    125113        } 
    126114 
    127         $use_params = FALSE; 
     115        $use_params = !$enable_permalinks_rewrite; 
    128116 
    129117        //Only use params if permalinks are not enabled. 
    130118        //don't fix links pointing to real files as it will cause that the 
    131119        //web server will not be able to locate them 
    132         if(!$wp_rewrite->using_permalinks() || 
    133         stripos($href, '/wp-admin') !== FALSE   || 
    134         stripos($href, '/wp-content') !== FALSE || 
    135         stripos($href, '/wp-login') !== FALSE   || 
    136         stripos($href, '/.php') !== FALSE) 
     120        if(stripos($href, '/wp-admin') !== FALSE   || 
     121           stripos($href, '/wp-content') !== FALSE || 
     122           stripos($href, '/wp-login') !== FALSE   || 
     123           stripos($href, '/.php') !== FALSE) 
    137124        { 
    138125                $use_params = TRUE; 
     
    153140 * param use_params_only - use only parameters as modifiers, i.e. not permalinks 
    154141 */ 
    155 function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only) 
    156 { 
    157         global $home_url, $home_url_quoted; 
    158  
    159         if(!get_option(ENABLE_PERMALINKS_REWRITE)) 
     142function rewrite_url_lang_param($url, $lang, $is_edit, $use_params_only=FALSE) 
     143{ 
     144        global $home_url, $home_url_quoted, $enable_permalinks_rewrite; 
     145 
     146        if(!$enable_permalinks_rewrite) 
    160147        { 
    161148                //override the use only params - admin configured system to not touch permalinks 
     
    233220function init_global_vars() 
    234221{ 
    235         global $home_url, $home_url_quoted, $plugin_url, $enable_auto_translate; 
     222        global $home_url, $home_url_quoted, $plugin_url, $enable_auto_translate,  
     223              $enable_permalinks_rewrite, $wp_rewrite; 
    236224 
    237225        $home_url = get_option('home'); 
     
    243231 
    244232        $enable_auto_translate = get_option(ENABLE_AUTO_TRANSLATE,1) && is_translator(); 
     233         
     234        if($wp_rewrite->using_permalinks() && get_option(ENABLE_PERMALINKS_REWRITE)) 
     235        { 
     236                $enable_permalinks_rewrite = TRUE; 
     237        } 
    245238} 
    246239 
  • trunk/WordPress/plugin/transposh/transposh_widget.php

    r92 r103  
    3535                logger("Enter " . __METHOD__, 4); 
    3636 
    37                 global $wp_rewrite; 
    38  
    3937                $ref=getenv('HTTP_REFERER'); 
    4038                $lang = $_POST[LANG_PARAM]; 
     
    4543                if($lang != "none") 
    4644                { 
    47                         $use_params_only = !$wp_rewrite->using_permalinks(); 
    4845                        $is_edit = $_POST[EDIT_PARAM]; 
    49  
    50                         $ref = rewrite_url_lang_param($ref, $lang, $is_edit, $use_params_only); 
     46                        $ref = rewrite_url_lang_param($ref, $lang, $is_edit); 
    5147                } 
    5248 
     
    8379{ 
    8480        logger("Enter " . __METHOD__, 4); 
    85         global $languages, $wp_query, $wp_rewrite, $plugin_url; 
     81        global $languages, $wp_query, $plugin_url; 
    8682        extract($args); 
    8783 
     
    109105            echo "<div style=\"text-align: left;\" class=\"" . NO_TRANSLATE_CLASS . "\" >"; 
    110106 
    111             $using_permalinks = $wp_rewrite->using_permalinks(); 
    112  
    113                         foreach($languages as $code => $lang2) 
     107            foreach($languages as $code => $lang2) 
    114108                        { 
    115109                                list($language,$flag) = explode (",",$lang2); 
     
    122116                                   ($is_translator && strstr($editable_langs, $code))) 
    123117                                { 
    124                 //$page_url = cleanup_url($page_url); 
    125                                         $page_url2 = rewrite_url_lang_param($page_url, $code, $is_edit, !$using_permalinks); 
     118                                $page_url2 = rewrite_url_lang_param($page_url, $code, $is_edit); 
    126119 
    127120                                        echo "<a href=\"" . $page_url2 . "\">". 
Note: See TracChangeset for help on using the changeset viewer.