Changeset 578
- Timestamp:
- 01/04/2011 10:21:53 AM (17 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 4 added
- 4 edited
-
js/jquery.ui.menu.js (added)
-
js/l (added)
-
js/l/es.js (added)
-
js/l/he.js (added)
-
js/transposhedit.js (modified) (13 diffs)
-
transposh.php (modified) (1 diff)
-
wp/transposh_ajax.php (modified) (1 diff)
-
wp/transposh_db.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/js/transposhedit.js
r571 r578 16 16 */ 17 17 18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, window, VKI_attach, VKI_show, VKI_close */18 /*global Date, Math, alert, escape, clearTimeout, document, jQuery, setTimeout, t_jp, t_jl, window, VKI_attach, VKI_show, VKI_close */ 19 19 (function ($) { // closure 20 21 function __(str){ 22 var s; 23 if(typeof(t_jl) === 'object' && (s=t_jl[str]) ) return s; 24 return str; 25 } 26 27 var l = { 28 en: 'English', 29 af: 'Afrikaans', 30 sq: 'Shqip', 31 ar: 'Ø§ÙØ¹Ø±ØšÙØ©', 32 hy: 'ÕÕ¡ÕµÕ¥ÖÕ¥Õ¶', 33 az: 'azÉrbaycan dili', 34 eu: 'Euskara', 35 be: 'ÐелаÑÑÑкаÑ', 36 bg: 'ÐÑлгаÑÑкО', 37 ca: 'Català ', 38 zh: 'äžæ - ç®äœ', 39 'zh-tw': 'äžæ - 挢å', 40 hr: 'Hrvatski', 41 cs: 'ÄeÅ¡tina', 42 da: 'Dansk', 43 nl: 'Nederlands', 44 eo: 'Esperanto', 45 et: 'Eesti keel', 46 fi: 'Suomi', 47 fr: 'Français', 48 gl: 'Galego', 49 ka: 'á¥áá áá£áá', 50 de: 'Deutsch', 51 el: 'ÎλληΜικά', 52 ht: 'Kreyòl ayisyen', 53 he: '×¢×ך×ת', 54 hi: 'à€¹à€¿à€šà¥à€Šà¥; à€¹à€¿à€à€Šà¥', 55 hu: 'Magyar', 56 is: 'Ãslenska', 57 id: 'Bahasa Indonesia', 58 ga: 'Gaeilge', 59 it: 'Italiano', 60 ja: 'æ¥æ¬èª', 61 ko: 'ì°ëЬë§', 62 la: 'latÄ«na', 63 lv: 'LatvieÅ¡u valoda', 64 lt: 'Lietuvių kalba', 65 mk: 'ЌакеЎПМÑкО ÑазОк', 66 ms: 'Bahasa Melayu', 67 mt: 'Malti', 68 no: 'Norsk', 69 fa: 'ÙØ§Ø±Ø³Û', 70 pl: 'Polski', 71 pt: 'Português', 72 ro: 'RomânÄ', 73 ru: 'Ð ÑÑÑкОй', 74 sr: 'CÑпÑкО ÑезОк', 75 sk: 'SlovenÄina', 76 sl: 'SlovenÅ¡Äina', //slovenian 77 es: 'Español', 78 sw: 'Kiswahili', 79 sv: 'svenska', 80 tl: 'Tagalog', // fhilipino 81 th: 'àž àž²àž©àž²à¹àžàž¢', 82 tr: 'TÃŒrkçe', 83 uk: 'УкÑаÑМÑÑка', 84 ur: 'اردÙ', 85 vi: 'Tiếng Viá»t', 86 cy: 'Cymraeg', 87 yi: '××ÖŽ××ש' 88 } 20 89 21 90 var prefix = t_jp.prefix, 22 91 idprefix = "#" + prefix; 23 function fix_page_human(token, translation) { 92 93 function fix_page_human(token, translation, source) { 24 94 //reset to the original content - the unescaped version if translation is empty 25 95 // TODO! … … 31 101 var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1), 32 102 img = $(idprefix + "img_" + img_segment_id); 33 $(idprefix + img_segment_id).attr('data-source', 0); // source is 0 human 34 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green').addClass('tr-icon-green'); 35 // TODO if ($.trim(translation).length !== 0) { remove green on zero length? 36 103 $(idprefix + img_segment_id).attr('data-source', source); // source is 0 human 104 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green') 105 if (source == 0) { 106 img.addClass('tr-icon-green'); 107 } else if (source) { 108 img.addClass('tr-icon-yellow'); 109 } 37 110 }; 38 111 // rewrite text for all matching items at once … … 56 129 // push translations 57 130 // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 58 fix_page_human(token, translation );131 fix_page_human(token, translation, 0); 59 132 var data = { 60 133 ln0: t_jp.lang, … … 147 220 148 221 function confirm_close() { 149 $('<div id="dial" title="Close without saving?"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>You have made a change to the translation. Are you sure you want to discard it?</p></div>').appendTo("body").dialog({ 150 bgiframe: true, 222 $('<div id="dial" title="'+__('Close without saving?')+'"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>'+__('You have made a change to the translation. Are you sure you want to discard it?') + '</p></div>').appendTo("body").dialog({ 151 223 resizable: false, 152 // height: 140,153 224 modal: true, 154 225 overlay: { … … 160 231 $(idprefix + "translation").data('changed', false); 161 232 $(this).dialog('close'); 162 $(idprefix + "d -tabs").dialog('close');233 $(idprefix + "dialog").dialog('close'); 163 234 }, 164 235 Cancel: function () { … … 169 240 } 170 241 242 function history_dialog(segment_id){ 243 var dialog = idprefix + "historydialog", left = "left", right = "right"; 244 /*if ($(dialog).length) { 245 $(dialog).dialog('open'); 246 return; 247 }*/ 248 if (jQuery("html").attr("dir") === 'rtl') { 249 right = 'left'; 250 left = 'right'; 251 } 252 253 $(dialog).remove(); 254 //$(idprefix+'historydialog').remove(); 255 256 $('<div id="' + prefix + 'historydialog" title="' + __('History') + '">'+__('Loading...')+'</div>').appendTo("body"); 257 $(dialog).css('padding', 0).dialog({ 258 width: '450px', 259 // dialogClass: 'ui-widget-shadow', 260 show: 'slide'//, 261 //stack: true 262 }); 263 $.ajax({ 264 url: t_jp.post_url, 265 data: { 266 tr_token_hist: $(idprefix + segment_id).attr('data-token'), 267 lang: t_jp.lang 268 }, 269 dataType: "json", 270 success: function(data) { 271 var icon, icontitle, iconline, delline; 272 $(dialog).empty().append( 273 '<table width="100%">' + 274 '<col style="width: 80%;">' + 275 '<col>' + 276 '<col>' + 277 '<thead>'+ 278 '<tr> ' + 279 '<th>'+__('Translated')+'</th><th>'+__('By')+'</th><th>'+__('At')+'</th>' + 280 '</tr>' + 281 '</thead>' + 282 '<tbody>' + 283 '</tbody>' + 284 '</table>'); 285 $.each(data, function(index, row) { 286 switch(row.source) 287 { 288 case '1': 289 icon = 'tr-icon-google'; 290 icontitle = __('google'); 291 break; 292 case '2': 293 icon = 'tr-icon-bing'; 294 icontitle = __('bing'); 295 break; 296 case '3': 297 icon = 'tr-icon-apertium'; 298 icontitle = __('apertium'); 299 break; 300 default: 301 icon = 'ui-icon-person'; 302 icontitle = __('human translation'); 303 } 304 if (row.user_login === null) { 305 row.user_login = row.translated_by; 306 } 307 iconline = '<span class="ui-button ui-widget ui-button-icon-only" style="width: 18px; border: 0px; margin-' + right + ': 3px"><span title="' + icontitle + '" style="cursor: default;" class="ui-button-icon-primary ui-icon ' + icon + '"></span><span class="ui-button-text" style="display: inline-block; "></span></span>' 308 if (row.can_delete) { 309 delline = '<span class="' + prefix + 'delete" title="' + __('delete') + '" style="width: 18px; margin-' + left + ': 3px">'; 310 } else { 311 delline = ''; 312 } 313 $(dialog + " tbody").append('<tr><td>' + row.translated + '</td><td id="' + prefix +'histby">' + iconline + row.user_login + '</td><td id="' + prefix +'histstamp">' +row.timestamp + delline + '</td></tr>'); 314 }); 315 $(idprefix + "histby," + idprefix + "histstamp").css('white-space','nowrap'); 316 $(dialog + " th").addClass('ui-widget-header').css('padding', '3px'); 317 $(dialog + " td").addClass('ui-widget-content').css('padding', '3px'); 318 $("." + prefix + "delete").button({ 319 icons: { 320 primary: "ui-icon-circle-close" 321 }, 322 text: false 323 }).click(function() { 324 var row = $(this).parents('tr'); 325 $.ajax({ 326 url: t_jp.post_url, 327 data: { 328 tr_token_hist: $(idprefix + segment_id).attr('data-token'), 329 timestamp: $(this).parents('tr').children(":last").text(), 330 action: 'delete', 331 lang: t_jp.lang 332 }, 333 dataType: "json", 334 success: function(data) { 335 if (data === false) { 336 $(row).children().addClass('ui-state-error'); 337 } else { 338 console.log (data); 339 console.log($(idprefix + segment_id).attr('data-token'),data.translated, data.source); 340 $(row).empty(); 341 fix_page_human($(idprefix + segment_id).attr('data-token'),data.translated, data.source); 342 // var translation = $(idprefix + 'translation').val(), 343 //token = $(idprefix + segment_id).attr('data-token'); 344 // we allow approval on computer generated translations too 345 // if ($(idprefix + 'translation').data("changed") || $(idprefix + segment_id).attr('data-source') !== "0") { 346 // ajax_translate_human(token, translation); 347 348 } 349 } 350 }); 351 }); 352 $("." + prefix + "delete .ui-button-text").css('display','inline-block'); 353 } 354 }); 355 356 } 171 357 //Open translation dialog 172 358 function translate_dialog(segment_id) { 173 359 //only add button is bing support is defined for the language 174 var bingbutton = '', googlebutton = '', apertiumbutton = '', floatr = 'right', previcon = 'prev', nexticon = 'next', dialog = idprefix + "dialog";360 var bingbutton = '', googlebutton = '', apertiumbutton = '', right = 'right', left = 'left', previcon = 'prev', nexticon = 'next', dialog = idprefix + "dialog"; 175 361 if (jQuery("html").attr("dir") === 'rtl') { 176 floatr = 'left'; 362 right = 'left'; 363 left = 'right'; 177 364 previcon = 'next'; 178 365 nexticon = 'prev'; … … 180 367 181 368 if (t_jp.msn) { 182 bingbutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'bing"> bing suggest</button>';369 bingbutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'bing">'+__('bing suggest')+'</button>'; 183 370 } 184 371 // Only add button if google supports said language 185 372 if (t_jp.google) { 186 googlebutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'google"> google suggest</button>';373 googlebutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'google">'+__('google suggest')+'</button>'; 187 374 } 188 375 if (t_jp.apertium) { 189 apertiumbutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'apertium"> apertium suggest</button>';376 apertiumbutton = '<button class="' + prefix + 'suggest" id="' + prefix + 'apertium">'+__('apertium suggest')+'</button>'; 190 377 } 191 378 192 379 // this is our current way of cleaning up, might reconsider? 193 380 $(dialog).remove(); 194 $('<div id="' + prefix + 'dialog" title="' + t_jp.edit_box_title + '"/>').appendTo("body"); 195 //.tabs('add', t_jp.post_url + '?tr_token_hist=' + $(idprefix + segment_id).attr('data-token') + '&lang=' + t_jp.lang, t_jp.edit_box_history) 196 197 // fix for templates messing with li -not needed, tabs gone 198 // $(idprefix + "d-tabs li").css("list-style-type", "none").css("list-style-position", "outside"); 381 $('<div id="' + prefix + 'dialog" title="' + __('Edit Translation') + '"/>').appendTo("body"); 382 383 var segmentlang = $(idprefix + segment_id).attr('data-srclang'); 384 if (segmentlang === undefined ) { 385 segmentlang = t_jp.olang; 386 } 199 387 200 388 $(dialog).css("padding", "1px").append( 201 389 '<div style="width: 100%">' + 202 '<label for="original">' + t_jp.edit_box_original+ '</label>' +390 '<label for="original">' + __('Original text') +' (<span id="'+prefix+'orglang">'+l[segmentlang]+'</span>)'+ '</label>' + 203 391 '<textarea cols="80" row="3" name="original" id="' + prefix + 'original" readonly="y"/>' + 204 392 '<span id="' + prefix + 'utlbar">' + 205 '<button id="' + prefix + 'flag"> read alternate translations</button>' +206 '<button id="' + prefix + 'prev"> previous translation</button>' +207 '<button id="' + prefix + 'zoom"> find on page</button>' +208 '<button id="' + prefix + 'next"> next translation</button>' +393 '<button id="' + prefix + 'flag">'+__('read alternate translations')+'</button>' + 394 '<button id="' + prefix + 'prev">'+__('previous translation')+'</button>' + 395 '<button id="' + prefix + 'zoom">'+__('find on page')+'</button>' + 396 '<button id="' + prefix + 'next">'+__('next translation')+'</button>' + 209 397 '</span>' + 210 '<label for="translation">' + t_jp.edit_box_translate_to+ '</label>' +398 '<label for="translation">' + __('Translate to') + '</label>' + 211 399 '<textarea cols="80" row="3" name="translation" lang="' + t_jp.lang + '"id="' + prefix + 'translation"/>' + 212 400 '<span id="' + prefix + 'ltlbar">' + 213 '<button id="' + prefix + 'keyboard">virtual keyboard</button>' + 401 '<button id="' + prefix + 'history">'+__('view translation log')+'</button>' + 402 '<button id="' + prefix + 'keyboard">'+__('virtual keyboard')+'</button>' + 214 403 googlebutton + 215 404 bingbutton + 216 405 apertiumbutton + 217 '<button id="' + prefix + 'approve"> approve translation</button>' +406 '<button id="' + prefix + 'approve">'+__('approve translation')+'</button>' + 218 407 '</span>' + 219 '</div>' 408 '</div>' 220 409 ); 221 410 222 411 // toolbars should float... 223 412 $(idprefix + 'utlbar,' + idprefix + 'ltlbar').css({ 224 'float' : floatr 225 }).addClass('ui-widget-header ui-corner-all'); 226 413 'float' : right 414 }).buttonset(); 415 // rtl fix for buttonsets 416 if (jQuery("html").attr("dir") === 'rtl') { 417 jQuery('#tr_utlbar button:first').addClass('ui-corner-right').removeClass('ui-icon-left'); 418 jQuery('#tr_utlbar button:last').addClass('ui-corner-left').removeClass('ui-icon-right'); 419 jQuery('#tr_ltlbar button:first').addClass('ui-corner-right').removeClass('ui-icon-left'); 420 jQuery('#tr_ltlbar button:last').addClass('ui-corner-left').removeClass('ui-icon-right'); 421 } 227 422 // css for textareas 228 423 $(dialog + ' textarea').css({ … … 245 440 }, 246 441 text: false 247 }); 442 }).click(function () { 443 if ($(idprefix + "langmenu").length) { 444 $(idprefix + "langmenu").toggle(); 445 } else { 446 // We will show languages that have a human translation on the server 447 $.xLazyLoader({ 448 js: [t_jp.plugin_url + '/js/jquery.ui.menu.js'], 449 success: function () { 450 $.ajax({ 451 url: t_jp.post_url, 452 data: { 453 tr_token_alt: $(idprefix + segment_id).attr('data-token') 454 }, 455 dataType: "json", 456 success: function(data) { 457 var itemlang 458 if (!(itemlang = $(idprefix + segment_id).attr('data-srclang'))) { 459 itemlang = t_jp.olang; 460 } 461 var liflag = '<li data-translated="' + $(idprefix + segment_id).attr('data-orig') + '"><a href="#">' + l[itemlang] + '</a></li>' 462 $(data).each(function(index, item) { 463 if (item.lang !== t_jp.lang) { 464 liflag = liflag + '<li data-translated="' + item.translated + '"><a href="#">' + l[item.lang] + '</a></li>' 465 } 466 }); 467 $('<ul style="position: absolute; top: 0px" id="' + prefix + 'langmenu">' + liflag).appendTo(dialog); 468 469 $(idprefix + "langmenu").menu({ 470 select: function(event, ui) { 471 $(this).hide(); 472 $(idprefix + "original").val(ui.item.attr('data-translated')); 473 $(idprefix + "orglang").text(ui.item.text()).addClass('ui-state-highlight'); 474 if (l[itemlang] === ui.item.text()) { 475 $(idprefix + "orglang").removeClass('ui-state-highlight'); 476 } 477 }, 478 input: $(this) 479 }).show().css({ 480 top:0, 481 left:0 482 }).position({ 483 my: right + ' top', 484 at: left +' top', 485 of: $(idprefix + 'flag') 486 }); 487 } 488 }); 489 } 490 }); 491 } 492 }); 493 248 494 $(idprefix + 'prev').button({ 249 495 icons: { … … 305 551 } 306 552 553 $(idprefix + 'history').button({ 554 icons: { 555 primary: "ui-icon-clipboard" 556 }, 557 text: false 558 }).click(function () { 559 history_dialog(segment_id) 560 }); 561 307 562 $(idprefix + 'keyboard').button({ 308 563 icons: { … … 398 653 // time to create the dialog 399 654 $(dialog).dialog({ 400 //bgiframe: true,401 655 //modal: true, 402 656 //width: 'auto', … … 407 661 }); 408 662 409 // remove virtual keyboard on close663 // remove virtual keyboard and history on close 410 664 $(dialog).bind("dialogclose", function (event, ui) { 411 665 if (typeof VKI_close === 'function') { 412 666 VKI_close(jQuery(idprefix + "translation").get(0)); 413 667 } 414 }); 415 668 $(idprefix+'historydialog').remove(); 669 }); 670 416 671 // show confirmation dialog before closing 417 672 $(dialog).bind('dialogbeforeclose', function (event, ui) { … … 432 687 img = $(idprefix + 'img_' + translated_id); 433 688 img.click(function () { 434 // if we detect that $.ui is missing (TODO - check tabs - etal) we load it first, the added or solves a jquery tools conflict 689 // if we detect that $.ui is missing (TODO - check tabs - etal) we load it first, the added or solves a jquery tools conflict !!!!!!!!!!! 435 690 if (typeof $.fn.tabs !== 'function' || typeof $.fn.dialog !== 'function') { 436 691 $.ajaxSetup({ … … 442 697 css: ['http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/themes/ui-lightness/jquery-ui.css'], 443 698 success: function () { 444 translate_dialog(translated_id); 699 // Load locale - todo - better... 700 if (t_jp.locale) { 701 $.xLazyLoader({ 702 js: [t_jp.plugin_url + '/js/l/'+t_jp.lang+'.js'], 703 success: function () { 704 translate_dialog(translated_id); 705 } 706 }); 707 } else { 708 translate_dialog(translated_id); 709 } 445 710 } 446 711 }); 447 712 }); 448 713 } else { 449 translate_dialog(translated_id); 714 if (t_jp.locale) { 715 $.xLazyLoader({ 716 js: [t_jp.plugin_url + '/js/l/'+t_jp.lang+'.js'], 717 success: function () { 718 translate_dialog(translated_id); 719 } 720 }); 721 } else { 722 translate_dialog(translated_id); 723 } 450 724 } 451 725 return false; -
trunk/WordPress/plugin/transposh/transposh.php
r571 r578 663 663 if ($this->edit_mode) { 664 664 $script_params['edit'] = 1; 665 $script_params['edit_box_title'] = _x('Edit Translation', 'Edit Interface', TRANSPOSH_TEXT_DOMAIN); 666 $script_params['edit_box_translate'] = _x('Translate', 'Edit Interface', TRANSPOSH_TEXT_DOMAIN); 667 $script_params['edit_box_history'] = _x('History', 'Edit Interface', TRANSPOSH_TEXT_DOMAIN); 668 $script_params['edit_box_original'] = _x('Original Text', 'Edit Interface', TRANSPOSH_TEXT_DOMAIN); 669 $script_params['edit_box_translate_to'] = _x('Translate To', 'Edit Interface', TRANSPOSH_TEXT_DOMAIN); 665 if (file_exists($this->transposh_plugin_dir.TRANSPOSH_DIR_JS.'/l/'.$this->target_language.'.js')) { 666 $script_params['locale'] = 1; 667 } 670 668 } 671 669 // 'l10n_print_after' => 'try{convertEntities(inlineEditL10n);}catch(e){};' -
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r510 r578 45 45 // getting translation history 46 46 elseif (isset($_GET['tr_token_hist'])) { 47 // deleting 48 if (isset($_GET['action']) && $_GET['action'] == 'delete') { 49 $my_transposh_plugin->database->del_translation_history($_GET['tr_token_hist'], $_GET['lang'], $_GET['timestamp']); 50 } 47 51 $my_transposh_plugin->database->get_translation_history($_GET['tr_token_hist'], $_GET['lang']); 52 } 53 // getting translation alternates 54 elseif (isset($_GET['tr_token_alt'])) { 55 $my_transposh_plugin->database->get_translation_alt($_GET['tr_token_alt']); 48 56 } 49 57 // getting phrases of a post (if we are in admin) -
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r550 r578 148 148 if (!$originals) return; 149 149 logger($originals, 4); 150 $where = ''; 150 151 foreach ($originals as $original => $truth) { 151 152 $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); … … 438 439 439 440 $rows = $GLOBALS['wpdb']->get_results($query); 440 logger($rows, 4); 441 // TODO: work with json 442 //header("Content-type: text/javascript"); 443 //echo json_encode($rows); 444 if ($rows !== FALSE) { 445 echo '<table>' . 446 '<thead>' . 447 '<tr>' . 448 '<th>Translated</th><th/><th>By</th><th>At</th>' . 449 '</tr>' . 450 '</thead>' . 451 '<tbody>'; 452 foreach ($rows as $row) { 453 if (is_null($row->user_login)) 454 $row->user_login = $row->translated_by; 455 echo "<tr><td>{$row->translated}</td><td source=\"{$row->source}\"/><td user_id=\"{$row->translated_by}\">{$row->user_login}</td><td>{$row->timestamp}</td></tr>"; 456 } 457 echo '</tbody></table>'; 458 } 459 441 for ($i = 0; $i < count($rows); $i++) { 442 if (($rows[$i]->translated_by == $_SERVER['REMOTE_ADDR'] && $rows[$i]->source == '0') || (is_user_logged_in() && current_user_can(TRANSLATOR)) || current_user_can('manage_options')) { 443 $rows[$i]->can_delete = true; 444 } 445 } 446 // sending as json 447 // CHECK!!! header("Content-type: application/json"); 448 echo json_encode($rows); 449 exit; 450 } 451 452 /** 453 * Delete a specific translation history from the logs 454 * @param string $token 455 * @param string $lang 456 * @param string $timestamp 457 */ 458 function del_translation_history($token, $lang, $timestamp) { 459 $original = transposh_utils::base64_url_decode($token); 460 $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); 461 $lang = $GLOBALS['wpdb']->escape($lang); 462 $timestamp = $GLOBALS['wpdb']->escape($timestamp); 463 header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION); 464 $query = "SELECT translated, translated_by, timestamp, source " . 465 "FROM {$this->translation_log_table} " . 466 "WHERE original='$original' AND lang='$lang' AND timestamp='$timestamp' " . 467 "ORDER BY timestamp DESC"; 468 $rows = $GLOBALS['wpdb']->get_results($query); 469 // We only delete if we found something to delete and it is allowed to delete it (user either did that - by ip, has the translator role or is an admin) 470 if (!empty($rows) && (($rows[0]->translated_by == $_SERVER['REMOTE_ADDR'] && $rows[0]->source == '0') || (is_user_logged_in() && current_user_can(TRANSLATOR)) || current_user_can('manage_options'))) { 471 // delete faulty record 472 $query = "DELETE " . 473 "FROM {$this->translation_log_table} " . 474 "WHERE original='$original' AND lang='$lang' AND timestamp='$timestamp'"; 475 $GLOBALS['wpdb']->query($query); 476 // retrieve last translation 477 $query = "SELECT translated, source " . 478 "FROM {$this->translation_log_table} " . 479 "WHERE original='$original' AND lang='$lang' " . 480 "ORDER BY timestamp DESC"; 481 $rows = $GLOBALS['wpdb']->get_results($query); 482 483 // delete and revert to last in database 484 $delvalues = "(original ='$original' AND lang='$lang')"; 485 $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues"; 486 logger($update, 3); 487 $result = $GLOBALS['wpdb']->query($update); 488 if (!empty($rows)) { 489 $values = "('" . $original . "','" . $rows[0]->translated . "','" . $lang . "','" . $rows[0]->source . "')"; 490 $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES $values"; 491 logger($update, 3); 492 $result = $GLOBALS['wpdb']->query($update); 493 } else { 494 // there is nothing to revert to... 495 $rows[0]->translated = ''; 496 } 497 echo json_encode($rows[0]); 498 } else { 499 echo json_encode(false); 500 } 501 exit; 502 } 503 504 /** 505 * Get translation alternatives for some translation. 506 * @param string $token 507 */ 508 function get_translation_alt($token) { 509 510 //$ref = getenv('HTTP_REFERER'); 511 $original = transposh_utils::base64_url_decode($token); 512 logger("Inside alt for $original ($token)", 4); 513 514 if (!isset($original)) { 515 exit; 516 } 517 518 // Check permissions 519 if (!($this->transposh->is_translator())) { 520 logger("Unauthorized alt request " . $_SERVER['REMOTE_ADDR'], 1); 521 header('HTTP/1.0 401 Unauthorized alt request'); 522 exit; 523 } 524 logger('Passed check for editable and translator', 4); 525 526 // The original content is encoded as base64 before it is sent (i.e. token), after we 527 // decode it should just the same after it was parsed. 528 // TODO - check if needed later 529 $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); 530 531 // add our own custom header - so we will know that we got here 532 // TODO - move to ajax file? 533 header('Transposh: v-' . TRANSPOSH_PLUGIN_VER . ' db_version-' . DB_VERSION); 534 535 $query = "SELECT translated, lang " . 536 "FROM {$this->translation_table} " . 537 "WHERE original='$original' AND source=0 " . 538 "ORDER BY lang"; 539 logger("query is $query"); 540 $rows = $GLOBALS['wpdb']->get_results($query); 541 542 echo json_encode($rows); 460 543 exit; 461 544 }
Note: See TracChangeset
for help on using the changeset viewer.
