Changeset 155
- Timestamp:
- 04/18/2009 09:00:06 PM (3 years ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 4 edited
-
css/transposh.css (modified) (5 diffs)
-
js/transposh.js (modified) (5 diffs)
-
transposh.php (modified) (14 diffs)
-
transposh_db.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/css/transposh.css
r146 r155 7 7 */ 8 8 9 #overDiv {9 /*#overDiv { 10 10 border: 0px; 11 11 text-align:center; … … 27 27 #overDiv table tr:hover { 28 28 background-color:#225588;} 29 29 */ 30 30 .post .postbody .tr_img_, .attachment .tr_img_, .navigation .alignleft .tr_img_, .navigation .alignright .tr_img_, 31 31 .tr_img_ { … … 38 38 */ 39 39 40 .olbgD {40 /*.olbgD { 41 41 background-color:#225588;} 42 42 … … 74 74 font-size:4px; 75 75 line-height:4px;} 76 76 */ 77 77 /* 78 78 * Overlibmws library - popup with MODAL form 79 79 */ 80 80 81 /* 81 82 .olraisedBlue { 82 83 text-align:center; … … 99 100 color: #000000;} 100 101 102 */ -
trunk/WordPress/plugin/transposh/js/transposh.js
r146 r155 16 16 */ 17 17 18 function display_dialog(caption, content)18 /*function display_dialog(caption, content) 19 19 { 20 20 overlib(content, … … 37 37 WRAP, STICKY, SCROLL, MIDX,0, MIDY,0); 38 38 } 39 */ 39 40 40 41 //Show tooltip over a translated text 41 function hint(original)42 /*function hint(original) 42 43 { 43 44 overlib('<bdo dir="ltr">'+ original +'</bdo>', … … 45 46 TEXTFONTCLASS,'oltxtD', 46 47 AUTOSTATUS,WRAP); 47 } 48 }*/ 48 49 49 50 // fetch translation from google translate... 50 51 function getgt() 51 52 { 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) { 53 54 if (!result.error) { 54 55 jQuery("#tr_translation").val(jQuery("<div>"+result.translation+"</div>").text()); … … 119 120 } 120 121 121 //Open translation dialog122 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!"/> <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 event139 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 navigation145 return false;146 147 });148 149 }150 122 //function for auto translation 151 123 … … 180 152 }); 181 153 154 //Open translation dialog 155 /*function translate_dialog(original, trans, segment_id) 156 { 157 caption='Edit Translation'; 158 //alert (this.id); 159 var 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!"/> <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 183 function 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 182 225 google.load("language", "1"); 183 226 jQuery(document).ready( -
trunk/WordPress/plugin/transposh/transposh.php
r144 r155 83 83 84 84 /* 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. 88 88 */ 89 89 function init_global_vars() … … 134 134 { 135 135 update_translation(); 136 } 137 elseif ($_GET['tr_token_hist']) { 138 get_translation_history($_GET['tr_token_hist'], $_GET['lang']); 136 139 } 137 140 else … … 337 340 function add_transposh_css() { 338 341 global $plugin_url; 339 342 340 343 if(!is_editing_permitted() && !is_auto_translate_permitted()) 341 344 { 342 //translation not allowed - no need for the transposh.css 345 //translation not allowed - no need for the transposh.css 343 346 return; 344 347 } 345 348 //include the transposh.css 346 349 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'); 347 351 logger("Added transposh_css"); 348 352 } … … 358 362 if(!is_editing_permitted() && !$enable_auto_translate) 359 363 { 360 //translation not allowed - no need for any js. 364 //translation not allowed - no need for any js. 361 365 return; 362 366 } 363 367 364 368 $is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM]; 365 369 366 370 if (!$is_edit_param_enabled && !$enable_auto_translate) 367 371 { … … 374 378 if($is_edit_param_enabled) 375 379 { 376 wp_enqueue_script("overlibmws","$overlib_dir/overlibmws.js",array(),'1.0');380 /*wp_enqueue_script("overlibmws","$overlib_dir/overlibmws.js",array(),'1.0'); 377 381 wp_enqueue_script("overlibmws1","$overlib_dir/overlibmws_filter.js",array("overlibmws"),'1.0'); 378 382 wp_enqueue_script("overlibmws2","$overlib_dir/overlibmws_modal.js",array("overlibmws1"),'1.0'); 379 383 wp_enqueue_script("overlibmws3","$overlib_dir/overlibmws_overtwo.js",array("overlibmws2"),'1.0'); 380 384 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'); 382 387 } 383 388 … … 385 390 { 386 391 $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'); 388 394 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("jquery min"),'1.0');395 wp_enqueue_script("transposh","$plugin_url/js/transposh.js?post_url=$post_url&lang={$lang}",array("jquery"),'1.0'); 390 396 } 391 397 } … … 393 399 394 400 /** 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 * 398 404 * @return TRUE if translation allowed otherwise FALSE 399 405 */ … … 406 412 return FALSE; 407 413 } 408 414 409 415 if (!isset($wp_query->query_vars[LANG_PARAM])) 410 416 { 411 417 return FALSE; 412 418 } 413 419 414 420 $lang = $wp_query->query_vars[LANG_PARAM]; 415 421 return is_editable_lang($lang); … … 429 435 return FALSE; 430 436 } 431 437 432 438 return TRUE; 433 439 } … … 435 441 436 442 /** 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 438 444 * 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 * 441 447 * @return TRUE if automatic translation allowed otherwise FALSE 442 448 */ … … 449 455 return FALSE; 450 456 } 451 457 452 458 if (!isset($wp_query->query_vars[LANG_PARAM])) 453 459 { 454 460 return FALSE; 455 461 } 456 462 457 463 $lang = $wp_query->query_vars[LANG_PARAM]; 458 464 return is_editable_lang($lang); … … 460 466 /** 461 467 * 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 463 469 * function. 464 470 * @param $href … … 468 474 { 469 475 $use_params = FALSE; 470 476 471 477 //don't fix links pointing to real files as it will cause that the 472 478 //web server will not be able to locate them … … 478 484 $use_params = TRUE; 479 485 } 480 486 481 487 return $use_params; 482 488 } -
trunk/WordPress/plugin/transposh/transposh_db.php
r148 r155 210 210 } 211 211 212 /* 213 * A new translation has been posted, update the translation database. 214 */ 215 function 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 } 212 269 213 270 /*
Note: See TracChangeset
for help on using the changeset viewer.
