Ignore:
Timestamp:
03/03/2009 10:34:39 AM (3 years ago)
Author:
ofer
Message:

RSS becomes translateable due to hack, removed lots of whitespaces

File:
1 edited

Legend:

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

    r55 r57  
    6262//The url pointing to the base of the plugin 
    6363$plugin_url; 
    64                               
     64 
    6565//Error message displayed for the admin in case of failure 
    6666$admin_msg; 
     
    7070 * Called when the buffer containing the original page is flused. Triggers the 
    7171 * translation process. 
    72  *  
    73  */  
     72 * 
     73 */ 
    7474function process_page(&$buffer) { 
    75      
     75 
    7676    global $wp_query, $tr_page, $page, $pos, $lang, $plugin_url, $is_edit_mode, $wpdb, 
    7777           $table_name; 
    78      
     78 
    7979    $start_time = microtime(TRUE); 
    80      
     80 
    8181    if (!isset($wp_query->query_vars[LANG_PARAM])) 
    8282    { 
    8383        //No language code - avoid further processing. 
    8484        return $buffer; 
    85          
     85 
    8686    } 
    8787 
     
    9494        return $buffer; 
    9595    } 
    96      
    97      
     96 
     97 
    9898    $page = $buffer; 
    9999 
     
    105105        //user has the required permissions 
    106106        $editable_langs = get_option(EDITABLE_LANGS); 
    107          
     107 
    108108        if(is_translator() && strstr($editable_langs, $lang)) 
    109109        { 
    110110            $is_edit_mode = TRUE; 
    111111        } 
    112          
    113     } 
    114      
     112 
     113    } 
     114 
    115115    logger("translating " . $_SERVER['REQUEST_URI'] . " to: $lang", 1); 
    116      
     116 
    117117    //translate the entire page 
    118118    process_html(); 
    119      
     119 
    120120    $end_time = microtime(TRUE); 
    121121 
    122122    logger("Translation completed in " . ($end_time - $start_time) . " seconds", 1); 
    123      
     123 
    124124    //return the translated page unless it is empty, othewise return the original 
    125125    return (strlen($tr_page) > 0 ? $tr_page : $page); 
     
    128128/* 
    129129 * Fix links on the page. href needs to be modified to include 
    130  * lang specifier and editing mode.  
     130 * lang specifier and editing mode. 
    131131 * 
    132132 */ 
     
    134134{ 
    135135    global $home_url, $home_url_quoted, $lang, $is_edit_mode, $wp_rewrite; 
    136      
     136 
    137137    $href = get_attribute($start, $end, 'href'); 
    138138 
     
    149149 
    150150    $use_params = FALSE; 
    151      
    152     //Only use params if permalinks are not enabled.  
     151 
     152    //Only use params if permalinks are not enabled. 
    153153    //don't fix links pointing to real files as it will cause that the 
    154154    //web server will not be able to locate them 
    155     if(!$wp_rewrite->using_permalinks() ||    
     155    if(!$wp_rewrite->using_permalinks() || 
    156156       stripos($href, '/wp-admin') !== FALSE   || 
    157157       stripos($href, '/wp-content') !== FALSE || 
     
    171171 
    172172/* 
    173  * Update the given url to include language params.  
     173 * Update the given url to include language params. 
    174174 * param url - the original url to rewrite 
    175175 * param lang - language code 
     
    186186        $use_params_only = TRUE; 
    187187    } 
    188      
     188 
    189189    if($is_edit) 
    190190    { 
    191191        $params = EDIT_PARAM . '=1&'; 
    192          
     192 
    193193    } 
    194194 
     
    210210        //Cleanup extra & 
    211211        $url = preg_replace("/&&+/", "&", $url); 
    212              
     212 
    213213            //Cleanup extra ? 
    214214        $url = preg_replace("/\?\?+/", "?", $url); 
     
    219219 
    220220/* 
    221  * Fetch translation from db or cache.  
     221 * Fetch translation from db or cache. 
    222222 * Returns the translated string or NULL if not available. 
    223223 */ 
     
    226226    global $wpdb, $lang, $table_name; 
    227227    $translated = NULL; 
    228      
    229     logger("Enter " . __METHOD__ . " $original", 4); 
     228 
     229    logger("Enter " . __METHOD__ . ": $original", 4); 
    230230    if(ENABLE_APC && function_exists('apc_fetch')) 
    231231    { 
     
    233233        if($rc === TRUE) 
    234234        { 
    235             return $cached; 
    236         } 
    237     } 
    238      
    239     $query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' ";  
     235                logger("Exit from cache " . __METHOD__ . ": $cached", 4); 
     236                return $cached; 
     237        } 
     238    } 
     239 
     240    $query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' "; 
    240241    $row = $wpdb->get_row($query); 
    241      
     242 
    242243    if($row !== FALSE) 
    243244    { 
    244245        $translated = $row->translated; 
    245246        $translated = stripslashes($translated); 
    246          
     247 
    247248        logger("db result for $original >>> $translated ($lang)" , 3); 
    248249    } 
    249      
    250      
     250 
     251 
    251252    if(ENABLE_APC && function_exists('apc_store')) 
    252253    { 
     
    257258            $cache_entry = ""; 
    258259        } 
    259          
     260 
    260261        //update cache 
    261262        $rc = apc_store($original . $lang, $cache_entry, 3600); 
     
    265266        } 
    266267    } 
    267      
    268     logger("Exit " . __METHOD__ . " $translated", 4); 
     268 
     269    logger("Exit " . __METHOD__ . ": $translated", 4); 
    269270    return $translated; 
    270271} 
     
    278279{ 
    279280    global $plugin_url; 
    280      
     281 
    281282    $overlib_dir = "$plugin_url/js/overlibmws"; 
    282      
     283 
    283284    $js = "\n<script type=\"text/javascript\" src=\"$overlib_dir/overlibmws.js\"></script>"; 
    284285    $js .= "\n<script type=\"text/javascript\" src=\"$overlib_dir/overlibmws_filter.js\"></script>"; 
     
    297298/* 
    298299 * Return the img tag that will added to enable editing a translatable 
    299  * item on the page.  
     300 * item on the page. 
    300301 * param segement_id The id (number) identifying this segment. Needs to be 
    301302         placed within the img tag for use on client side operation (jquery) 
     
    305306    global $plugin_url, $lang, $home_url; 
    306307    $url = $home_url . '/index.php'; 
    307      
    308     //For use in javascript, make the following changes:  
     308 
     309    //For use in javascript, make the following changes: 
    309310    //1. Add slashes to escape the inner text 
    310311    //2. Convert the html special characters 
     
    318319    } 
    319320 
    320     $img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\" id=\"" . IMG_PREFIX . "$segment_id\"  
    321            onclick=\"translate_dialog('$original','$translation','$lang','$url', '$segment_id'); return false;\"  
    322            onmouseover=\"hint('$original'); return true;\"  
     321    $img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\" id=\"" . IMG_PREFIX . "$segment_id\" 
     322           onclick=\"translate_dialog('$original','$translation','$lang','$url', '$segment_id'); return false;\" 
     323           onmouseover=\"hint('$original'); return true;\" 
    323324           onmouseout=\"nd()\" />"; 
    324      
     325 
    325326    return $img; 
    326327} 
     
    346347        return; 
    347348    } 
    348    
    349     //include the transposh.css  
     349 
     350    //include the transposh.css 
    350351        echo "<link rel=\"stylesheet\" href=\"$plugin_url/transposh.css\" type=\"text/css\" />"; 
    351352 
     
    359360{ 
    360361    global $home_url, $home_url_quoted, $plugin_url, $table_name, $wpdb; 
    361      
     362 
    362363    $home_url = get_option('home'); 
    363364    $local_dir = preg_replace("/.*\//", "", dirname(__FILE__)); 
    364      
     365 
    365366    $plugin_url= $home_url . "/wp-content/plugins/$local_dir"; 
    366367    $home_url_quoted = preg_quote($home_url); 
     
    372373 
    373374/* 
    374  * A new translation has been posted, update the translation database.  
     375 * A new translation has been posted, update the translation database. 
    375376 * 
    376377 */ 
     
    378379{ 
    379380    global $wpdb, $table_name; 
    380      
     381 
    381382    $ref=getenv('HTTP_REFERER'); 
    382383    $original = $_POST['original']; 
    383384    $translation = $_POST['translation']; 
    384385    $lang = $_POST['lang']; 
    385      
     386 
    386387    if(!isset($original) || !isset($translation) || !isset($lang)) 
    387388    { 
     
    397398    } 
    398399 
    399     //Decode & remove already escaped character to avoid double escaping  
     400    //Decode & remove already escaped character to avoid double escaping 
    400401    $original    = $wpdb->escape(stripslashes(urldecode($original))); 
    401402    $translation = $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translation)))); 
    402          
     403 
    403404    $update = "REPLACE INTO  $table_name (original, translated, lang) 
    404405                VALUES ('" . $original . "','" . $translation . "','" . $lang . "')"; 
     
    455456        logger("Error !!! failed to update transaction log:  $loguser, $original ,$translation, $lang" , 0); 
    456457    } 
    457      
     458 
    458459} 
    459460 
     
    467468{ 
    468469    global $languages; 
    469      
     470 
    470471    $default = get_option(DEFAULT_LANG); 
    471472    if(!$languages[$default]) 
     
    500501 
    501502/* 
    502  * Page generation completed - flush buffer.  
     503 * Page generation completed - flush buffer. 
    503504 */ 
    504505function on_shutdown() 
     
    520521        return $rule; 
    521522    } 
    522      
     523 
    523524    $newRules = array(); 
    524525    $lang_prefix="([a-z]{2,2}(\-[a-z]{2,2})?)/"; 
     
    526527    $lang_parameter= "&" . LANG_PARAM . '=$matches[1]'; 
    527528 
    528     //catch the root url  
     529    //catch the root url 
    529530    $newRules[$lang_prefix."?$"] = "index.php?lang=\$matches[1]"; 
    530531    logger("\t" . $lang_prefix."?$" . "  --->  " . "index.php?lang=\$matches[1]"); 
     
    533534        $original_key = $key; 
    534535        $original_value = $value; 
    535          
     536 
    536537        $key = $lang_prefix . $key; 
    537538 
     
    544545 
    545546        $value .= $lang_parameter; 
    546          
     547 
    547548        logger("\t" . $key . "  --->  " . $value); 
    548                  
     549 
    549550 
    550551        $newRules[$key] = $value; 
     
    571572 
    572573/* 
    573  * Setup the translation database.  
    574  * 
    575  */ 
    576 function setup_db()  
     574 * Setup the translation database. 
     575 * 
     576 */ 
     577function setup_db() 
    577578{ 
    578579 
     
    584585    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 
    585586    { 
    586         logger("Attempting to create table $table_name", 0);  
     587        logger("Attempting to create table $table_name", 0); 
    587588        $sql = "CREATE TABLE " . $table_name . " (original VARCHAR(256) NOT NULL, 
    588589                                                  lang CHAR(5) NOT NULL, 
    589590                                                  translated VARCHAR(256), 
    590591                                                  PRIMARY KEY (original, lang)) "; 
    591          
    592                                       
     592 
     593 
    593594        dbDelta($sql); 
    594595 
     
    598599 
    599600        $result = $wpdb->query($insert); 
    600          
     601 
    601602        if($result === FALSE) 
    602603        { 
    603             logger("Error failed to create $table_name !!!", 0);  
     604            logger("Error failed to create $table_name !!!", 0); 
    604605        } 
    605606        else 
    606607        { 
    607             logger("Table $table_name was created successfuly", 0);  
     608            logger("Table $table_name was created successfuly", 0); 
    608609            add_option(TRANSPOSH_DB_VERSION, DB_VERSION); 
    609610        } 
     
    614615    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) 
    615616    { 
    616         logger("Attempting to create table $table_name", 0);  
     617        logger("Attempting to create table $table_name", 0); 
    617618        $sql = "CREATE TABLE " . $table_name . " (original VARCHAR(256) NOT NULL, 
    618619                                                  lang CHAR(5) NOT NULL, 
     
    621622                                                  timestamp TIMESTAMP, 
    622623                                                  PRIMARY KEY (original, lang, timestamp)) "; 
    623          
    624                                       
     624 
     625 
    625626        dbDelta($sql); 
    626627    } 
    627      
     628 
    628629    logger("Exit " . __METHOD__  ); 
    629630} 
     
    645646    if(get_option(ANONYMOUS_TRANSLATION)) 
    646647    { 
    647         //if anonymous translation is allowed - let anyone enjoy it  
     648        //if anonymous translation is allowed - let anyone enjoy it 
    648649        return TRUE; 
    649650    } 
    650      
     651 
    651652    return FALSE; 
    652653} 
    653           
    654  
    655 /* 
    656  * Plugin activated.  
     654 
     655 
     656/* 
     657 * Plugin activated. 
    657658 * 
    658659 */ 
     
    666667    add_filter('rewrite_rules_array', 'update_rewrite_rules'); 
    667668    $wp_rewrite->flush_rules(); 
    668          
     669 
    669670    logger("plugin_activate exit: " . dirname(__FILE__)); 
    670671} 
     
    681682    remove_filter('rewrite_rules_array', 'update_rewrite_rules'); 
    682683    $wp_rewrite->flush_rules(); 
    683      
     684 
    684685    logger("plugin_deactivate exit: " . dirname(__FILE__)); 
    685686} 
    686687 
    687688/* 
    688  * Callback from admin_notices - display error message to the admin.  
     689 * Callback from admin_notices - display error message to the admin. 
    689690 * 
    690691 */ 
     
    693694    global $admin_msg; 
    694695    logger("Enter " . __METHOD__, 0); 
    695      
     696 
    696697    echo '<div class="updated"><p>'; 
    697698    echo 'Error has occured in the installation process of the translation plugin: <br>'; 
    698      
     699 
    699700    echo $admin_msg; 
    700      
     701 
    701702    if (function_exists('deactivate_plugins') ) { 
    702703        deactivate_plugins("transposh/translate.php", "translate.php"); 
     
    711712 * Callback when all plugins have been loaded. Serves as the location 
    712713 * to check that the plugin loaded successfully else trigger notification 
    713  * to the admin and deactivate plugin.  
     714 * to the admin and deactivate plugin. 
    714715 * 
    715716 */ 
     
    722723    { 
    723724        $admin_msg = "Failed to locate the translation table  <em> " . TRANSLATIONS_TABLE . "</em> in local database. <br>"; 
    724          
     725 
    725726        logger("Messsage to admin: $admin_msg", 0); 
    726727        //Some error occured - notify admin and deactivate plugin 
     
    733734    { 
    734735        $admin_msg = "Translation database version ($db_version) is not comptabile with this plugin (". DB_VERSION . ")  <br>"; 
    735          
     736 
    736737        logger("Messsage to admin: $admin_msg", 0); 
    737738        //Some error occured - notify admin and deactivate plugin 
     
    740741} 
    741742 
    742 //Register callbacks  
     743//Register callbacks 
    743744add_action('wp_head', 'add_custom_css'); 
    744745add_filter('query_vars', 'parameter_queryvars' ); 
Note: See TracChangeset for help on using the changeset viewer.