Changeset 155


Ignore:
Timestamp:
04/18/2009 09:00:06 PM (3 years ago)
Author:
ofer
Message:

Initial move to jQuery UI instead of OverLIBMWS

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

Legend:

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

    r146 r155  
    77 */ 
    88 
    9 #overDiv { 
     9/*#overDiv { 
    1010    border: 0px;  
    1111    text-align:center; 
     
    2727#overDiv table tr:hover { 
    2828    background-color:#225588;} 
    29  
     29*/ 
    3030.post .postbody .tr_img_, .attachment .tr_img_, .navigation .alignleft .tr_img_, .navigation .alignright .tr_img_, 
    3131.tr_img_ { 
     
    3838 */ 
    3939 
    40 .olbgD { 
     40/*.olbgD { 
    4141    background-color:#225588;} 
    4242 
     
    7474    font-size:4px; 
    7575    line-height:4px;} 
    76  
     76*/ 
    7777/* 
    7878 *  Overlibmws library - popup with MODAL form 
    7979 */ 
    8080 
     81/* 
    8182.olraisedBlue { 
    8283    text-align:center;  
     
    99100    color: #000000;} 
    100101 
     102*/ 
  • trunk/WordPress/plugin/transposh/js/transposh.js

    r146 r155  
    1616 */ 
    1717 
    18 function display_dialog(caption, content) 
     18/*function display_dialog(caption, content) 
    1919{         
    2020overlib(content, 
     
    3737                WRAP, STICKY, SCROLL, MIDX,0, MIDY,0); 
    3838} 
     39*/ 
    3940 
    4041//Show tooltip over a translated text 
    41 function hint(original) 
     42/*function hint(original) 
    4243{ 
    4344    overlib('<bdo dir="ltr">'+ original +'</bdo>', 
     
    4546                TEXTFONTCLASS,'oltxtD', 
    4647                AUTOSTATUS,WRAP); 
    47 } 
     48}*/ 
    4849 
    4950// fetch translation from google translate... 
    5051function getgt() 
    5152{ 
    52         google.language.translate(jQuery("#tr_original_unescaped").text(), "", transposh_params['lang'], function(result) { 
     53        google.language.translate(jQuery("#tr_original").val(), "", transposh_params['lang'], function(result) { 
    5354                  if (!result.error) { 
    5455                    jQuery("#tr_translation").val(jQuery("<div>"+result.translation+"</div>").text()); 
     
    119120} 
    120121 
    121 //Open translation dialog  
    122 function translate_dialog(original, trans, segment_id) 
    123 { 
    124 caption='Edit Translation'; 
    125 //alert (this.id); 
    126 var dialog = ''+ 
    127     ('<form id="tr_form" name="transposh_edit_form" method="post" action="' + transposh_params['post_url'] + '"><div>') + 
    128      '<p dir="ltr">Original text<br \/><textarea id="tr_original_unescaped" cols="60" rows="3" readonly="readyonly">' + 
    129        original + '</textarea> <\/p>' + 
    130     '<p>Translate to<br \/><input class="olinput" type="text" id="tr_translation" name="translation" size="80" value="'+ trans + 
    131     '"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' + 
    132     '<input type="hidden" name="translation_posted" value= "1">' + 
    133     '<p><input class="olinput" onclick="getgt()" type="button" value="Get Suggestion!"/>&nbsp;<input class="olinput" type="submit" value="Translate"/><\/p>' + 
    134     ('<\/div><\/form>'); 
    135  
    136         display_dialog(caption, dialog); 
    137  
    138         // attach handler to form's submit event  
    139         jQuery('#tr_form').submit(function() {  
    140         var translation = jQuery('#tr_translation').val(); 
    141                          
    142         ajax_translate(original,translation,0,segment_id); 
    143          
    144         // return false to prevent normal browser submit and page navigation  
    145         return false; 
    146          
    147     }); 
    148  
    149 } 
    150122//function for auto translation 
    151123 
     
    180152}); 
    181153 
     154//Open translation dialog  
     155/*function translate_dialog(original, trans, segment_id) 
     156{ 
     157caption='Edit Translation'; 
     158//alert (this.id); 
     159var dialog = ''+ 
     160    ('<form id="tr_form" name="transposh_edit_form" method="post" action="' + transposh_params['post_url'] + '"><div>') + 
     161     '<p dir="ltr">Original text<br \/><textarea id="tr_original_unescaped" cols="60" rows="3" readonly="readyonly">' + 
     162       original + '</textarea> <\/p>' + 
     163    '<p>Translate to<br \/><input class="olinput" type="text" id="tr_translation" name="translation" size="80" value="'+ trans + 
     164    '"' + 'onfocus="OLmEdit=1;" onblur="OLmEdit=0;"<\/p>' + 
     165    '<input type="hidden" name="translation_posted" value= "1">' + 
     166    '<p><input class="olinput" onclick="getgt()" type="button" value="Get Suggestion!"/>&nbsp;<input class="olinput" type="submit" value="Translate"/><\/p>' + 
     167    ('<\/div><\/form>'); 
     168 
     169        display_dialog(caption, dialog); 
     170 
     171        // attach handler to form's submit event  
     172        jQuery('#tr_form').submit(function() {  
     173        var translation = jQuery('#tr_translation').val(); 
     174                         
     175        ajax_translate(original,translation,0,segment_id); 
     176         
     177        // return false to prevent normal browser submit and page navigation  
     178        return false; 
     179         
     180    }); 
     181}*/ 
     182 
     183function translate_dialog(original, trans, segment_id) { 
     184        jQuery("#tabs").remove(); 
     185        jQuery('<div id="tabs" title="Edit Translation"/>').appendTo("body"); 
     186        jQuery("#tabs").append('<ul/>').tabs({ cache: true }); 
     187        jQuery("#tabs").tabs('add','#tabs-1','Translate'); 
     188        jQuery("#tabs").tabs('add','index.php?tr_token_hist='+jQuery("#tr_" + segment_id).attr('token')+'&lang='+transposh_params['lang'],'History'); 
     189        jQuery("#tabs-1").append( 
     190                        '<form>' +       
     191                        '<fieldset>' + 
     192                        '<label for="original">Original Text</label>' + 
     193                        '<input type="text" name="original" id="tr_original" class="text ui-widget-content ui-corner-all" readonly="y"/>' + 
     194                        '<label for="translation">Translate To</label>' + 
     195                        '<input type="text" name="translation" id="tr_translation" value="" class="text ui-widget-content ui-corner-all"/>' + 
     196                        '</fieldset>' + 
     197                        '</form>'); 
     198        jQuery("#tr_original").val(original); 
     199        jQuery("#tr_translation").val(trans); 
     200        jQuery("#tabs").css("text-align","left"); 
     201        jQuery("#tabs-1 label").css("display","block"); 
     202        jQuery("#tabs-1 input.text").css({'margin-bottom':'12px', 'width' : '95%', 'padding' : '.4em'}); 
     203        jQuery("#tabs").bind('tabsload', function(event, ui) { 
     204                //TODO, formatting here, not server side 
     205                jQuery("table",ui.panel).addClass("ui-widget ui-widget-content").css({'width' : '95%', 'padding' : '0'}); 
     206                jQuery("table thead tr",ui.panel).addClass("ui-widget-header"); 
     207        }); 
     208        jQuery("#tabs").tabs().dialog({ 
     209                bgiframe: true, 
     210                modal: true, 
     211                width: 460, 
     212                buttons: { 
     213                        Suggest: function() { 
     214                                getgt(); 
     215                        }, 
     216                        Ok: function() { 
     217                                var translation = jQuery('#tr_translation').val(); 
     218                                ajax_translate(original,translation,0,segment_id); 
     219                                jQuery(this).dialog('close'); 
     220                        } 
     221                } 
     222        }).css("padding",0).dialog('open'); 
     223} 
     224 
    182225google.load("language", "1"); 
    183226jQuery(document).ready( 
  • trunk/WordPress/plugin/transposh/transposh.php

    r144 r155  
    8383 
    8484/* 
    85  * Init global variables later used throughout this process.  
    86  * Note that at the time that this function is called the wp_query is not initialized,  
    87  * which means that query parameters are not accessiable.  
     85 * Init global variables later used throughout this process. 
     86 * Note that at the time that this function is called the wp_query is not initialized, 
     87 * which means that query parameters are not accessiable. 
    8888 */ 
    8989function init_global_vars() 
     
    134134        { 
    135135                update_translation(); 
     136        } 
     137        elseif ($_GET['tr_token_hist']) { 
     138                get_translation_history($_GET['tr_token_hist'], $_GET['lang']); 
    136139        } 
    137140        else 
     
    337340function add_transposh_css() { 
    338341        global $plugin_url; 
    339          
     342 
    340343        if(!is_editing_permitted() && !is_auto_translate_permitted()) 
    341344        { 
    342                 //translation not allowed - no need for the transposh.css        
     345                //translation not allowed - no need for the transposh.css 
    343346                return; 
    344347        } 
    345348        //include the transposh.css 
    346349        wp_enqueue_style("transposh","$plugin_url/css/transposh.css",array(),'1.0.1'); 
     350        wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/ui-lightness/jquery-ui.css",array(),'1.0.1'); 
    347351        logger("Added transposh_css"); 
    348352} 
     
    358362        if(!is_editing_permitted() && !$enable_auto_translate) 
    359363        { 
    360                 //translation not allowed - no need for any js.  
     364                //translation not allowed - no need for any js. 
    361365                return; 
    362366        } 
    363          
     367 
    364368        $is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM]; 
    365          
     369 
    366370        if (!$is_edit_param_enabled && !$enable_auto_translate) 
    367371        { 
     
    374378        if($is_edit_param_enabled) 
    375379        { 
    376                 wp_enqueue_script("overlibmws","$overlib_dir/overlibmws.js",array(),'1.0'); 
     380                /*wp_enqueue_script("overlibmws","$overlib_dir/overlibmws.js",array(),'1.0'); 
    377381                wp_enqueue_script("overlibmws1","$overlib_dir/overlibmws_filter.js",array("overlibmws"),'1.0'); 
    378382                wp_enqueue_script("overlibmws2","$overlib_dir/overlibmws_modal.js",array("overlibmws1"),'1.0'); 
    379383                wp_enqueue_script("overlibmws3","$overlib_dir/overlibmws_overtwo.js",array("overlibmws2"),'1.0'); 
    380384                wp_enqueue_script("overlibmws4","$overlib_dir/overlibmws_scroll.js",array("overlibmws3"),'1.0'); 
    381                 wp_enqueue_script("overlibmws5","$overlib_dir/overlibmws_shadow.js",array("overlibmws4"),'1.0'); 
     385                wp_enqueue_script("overlibmws5","$overlib_dir/overlibmws_shadow.js",array("overlibmws4"),'1.0');*/ 
     386                wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js",array("jquery"),'1.7.1'); 
    382387        } 
    383388 
     
    385390        { 
    386391                $post_url = $home_url . '/index.php'; 
    387                 wp_enqueue_script("jquerymin","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2'); 
     392                wp_deregister_script('jquery'); 
     393                wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2'); 
    388394                wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1'); 
    389                 wp_enqueue_script("transposh","$plugin_url/js/transposh.js?post_url=$post_url&lang={$lang}",array("jquerymin"),'1.0'); 
     395                wp_enqueue_script("transposh","$plugin_url/js/transposh.js?post_url=$post_url&lang={$lang}",array("jquery"),'1.0'); 
    390396        } 
    391397} 
     
    393399 
    394400/** 
    395  * Determine if the currently selected language (taken from the query parameters) is in the admin's list  
    396  * of editable languages and the current user is allowed to translate.  
    397  *   
     401 * Determine if the currently selected language (taken from the query parameters) is in the admin's list 
     402 * of editable languages and the current user is allowed to translate. 
     403 * 
    398404 * @return TRUE if translation allowed otherwise FALSE 
    399405 */ 
     
    406412                return FALSE; 
    407413        } 
    408          
     414 
    409415        if (!isset($wp_query->query_vars[LANG_PARAM])) 
    410416        { 
    411417                return FALSE; 
    412418        } 
    413          
     419 
    414420        $lang = $wp_query->query_vars[LANG_PARAM]; 
    415421        return is_editable_lang($lang); 
     
    429435                return FALSE; 
    430436        } 
    431          
     437 
    432438        return TRUE; 
    433439} 
     
    435441 
    436442/** 
    437  * Determine if the currently selected language (taken from the query parameters) is in the admin's list  
     443 * Determine if the currently selected language (taken from the query parameters) is in the admin's list 
    438444 * of editable languages and that automatic translation has been enabled. 
    439  * Note that any user can auto translate. i.e. ignore permissions.   
    440  *   
     445 * Note that any user can auto translate. i.e. ignore permissions. 
     446 * 
    441447 * @return TRUE if automatic translation allowed otherwise FALSE 
    442448 */ 
     
    449455                return FALSE; 
    450456        } 
    451          
     457 
    452458        if (!isset($wp_query->query_vars[LANG_PARAM])) 
    453459        { 
    454460                return FALSE; 
    455461        } 
    456          
     462 
    457463        $lang = $wp_query->query_vars[LANG_PARAM]; 
    458464        return is_editable_lang($lang); 
     
    460466/** 
    461467 * Callback from parser allowing to overide the global setting of url rewriting using permalinks. 
    462  * Some urls should be modified only by adding parameters and should be identified by this  
     468 * Some urls should be modified only by adding parameters and should be identified by this 
    463469 * function. 
    464470 * @param $href 
     
    468474{ 
    469475        $use_params = FALSE; 
    470          
     476 
    471477        //don't fix links pointing to real files as it will cause that the 
    472478        //web server will not be able to locate them 
     
    478484                $use_params = TRUE; 
    479485        } 
    480          
     486 
    481487        return $use_params; 
    482488} 
  • trunk/WordPress/plugin/transposh/transposh_db.php

    r148 r155  
    210210} 
    211211 
     212/* 
     213 * A new translation has been posted, update the translation database. 
     214 */ 
     215function get_translation_history($token, $lang) 
     216{ 
     217        global $wpdb; 
     218 
     219        $ref=getenv('HTTP_REFERER'); 
     220        $original =  base64_url_decode($token); 
     221 
     222        // check params 
     223        logger("Enter " . __FILE__ . " Params: $original , $translation, $lang, $ref", 3); 
     224        if(!isset($original) || !isset($lang)) 
     225        { 
     226                logger("Enter " . __FILE__ . " missing params: $original, $lang," . $ref, 0); 
     227                return; 
     228        } 
     229 
     230        //Check permissions, first the lanugage must be on the edit list. Then either the user 
     231        //is a translator or automatic translation if it is enabled. 
     232        if(!(is_editable_lang($lang) && is_translator())) 
     233        { 
     234                logger("Unauthorized history request " . $_SERVER['REMOTE_ADDR'] , 1); 
     235                header("HTTP/1.0 401 Unauthorized history"); 
     236                exit; 
     237        } 
     238 
     239        $table_name = $wpdb->prefix . TRANSLATIONS_LOG; 
     240 
     241        //The original content is encoded as base64 before it is sent (i.e. token), after we 
     242        //decode it should just the same after it was parsed. 
     243        $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); 
     244 
     245        //add  our own custom header - so we will know that we got here 
     246        header("Transposh: ver-<%VERSION%> db_version-". DB_VERSION); 
     247 
     248        $query = "SELECT translated, translated_by, timestamp, source FROM $table_name WHERE original='$original' AND lang='$lang' ORDER BY timestamp DESC"; 
     249        //echo $query; 
     250        $rows = $wpdb->get_results($query); 
     251 
     252        if($rows !== FALSE) 
     253        { 
     254                echo '<table>' . 
     255                '<thead>'. 
     256                        '<tr>'. 
     257                                '<th>Translated</th><th>By</th><th>At</th>'. 
     258                        '</tr>'. 
     259                '</thead>'. 
     260                '<tbody>'; 
     261                foreach ($rows as $row) : 
     262                        echo "<tr><td>{$row->translated}</td><td>{$row->translated_by}</td><td>{$row->timestamp}</td></tr>"; 
     263                endforeach; 
     264                echo '</tbody></table>'; 
     265        } 
     266 
     267        exit; 
     268} 
    212269 
    213270/* 
Note: See TracChangeset for help on using the changeset viewer.