Changeset 79 for trunk/WordPress/plugin/transposh/transposh.php
- Timestamp:
- 03/19/2009 03:14:56 PM (3 years ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/transposh.php (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/transposh.php
r76 r79 220 220 /* 221 221 * Fetch translation from db or cache. 222 * Returns the translated string or NULL if not available.223 * TODO: // will an array work?222 * Returns An array that contains the translated string and it source. 223 * Will return NULL if no translation is available. 224 224 */ 225 225 function fetch_translation($original) … … 228 228 $translated = NULL; 229 229 logger("Enter " . __METHOD__ . ": $original", 4); 230 logger("Original was: $original", 3); 231 $original = $wpdb->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); 232 logger("Original is: $original", 3); 230 231 //The original is saved in db in its escaped form 232 $original = $wpdb->escape($original); 233 233 234 if(ENABLE_APC && function_exists('apc_fetch')) 234 235 { … … 335 336 $url = $home_url . '/index.php'; 336 337 338 //Use base64 encoding to make that when the page is translated (i.e. update_translation) we 339 //get back exactlly the same string without having the client decode/encode it in anyway. 340 $token = base64_encode($original); 341 337 342 //For use in javascript, make the following changes: 338 343 //1. Add slashes to escape the inner text … … 351 356 } 352 357 353 $img = "<img src=\"$plugin_url/translate$add_img.png\" alt=\"translate\" id=\"" . IMG_PREFIX . "$segment_id\"358 $img = "<img src=\"$plugin_url/translate$add_img.png\" token=\"$token\" alt=\"translate\" id=\"" . IMG_PREFIX . "$segment_id\" 354 359 onclick=\"translate_dialog('$original','$translation','$segment_id'); return false;\" 355 360 onmouseover=\"hint('$original'); return true;\" 356 361 onmouseout=\"nd()\" />"; 357 358 return $img;362 363 return $img; 359 364 } 360 365 … … 405 410 406 411 /* 407 * Helper function for annoying strings from php escape (%u2019)408 */409 function utf8_urldecode($str) {410 $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str));411 return html_entity_decode($str,null,'UTF-8');;412 }413 414 /*415 412 * A new translation has been posted, update the translation database. 416 413 * … … 421 418 422 419 $ref=getenv('HTTP_REFERER'); 423 $original = $_POST['original'];420 $original = base64_decode($_POST['token'], TRUE); 424 421 $translation = $_POST['translation']; 425 422 $lang = $_POST['lang']; … … 439 436 440 437 //Decode & remove already escaped character to avoid double escaping 441 // TODO: remove logging?442 logger("origwas:" .$original,4);443 $original = utf8_urldecode($original);444 logger("orig2:" .$original,4);445 $original = $wpdb->escape(stripslashes(urldecode(html_entity_decode($original, null, 'UTF-8'))));446 logger("orig:" .$original,4);447 438 $translation = $wpdb->escape(htmlspecialchars(stripslashes(urldecode($translation)))); 448 449 //TODO: Check more escaping... 450 439 440 //The original content is encoded as base64 before it is sent (i.e. token), after we 441 //decode it should just the same after it was parsed. 442 $original = $wpdb->escape($original); 443 451 444 $update = "REPLACE INTO $table_name (original, translated, lang, source) 452 445 VALUES ('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')"; … … 462 455 { 463 456 apc_delete($original .'___'. $lang); 464 // TODO: update cache465 //$rc = apc_store($original .'___'. $lang, $cache_entry, 3600);466 //if($rc === TRUE)467 //{468 // logger("Stored in cache: $original => $translated", 3);469 //}470 457 } 471 458 … … 635 622 $table_name = $wpdb->prefix . TRANSLATIONS_TABLE; 636 623 637 //if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)638 //{639 624 logger("Attempting to create table $table_name", 0); 640 625 $sql = "CREATE TABLE $table_name (original VARCHAR(256) NOT NULL, … … 647 632 dbDelta($sql); 648 633 649 // TODO: remove this?650 //Verify that newly created table is ready for use.651 //$insert = "INSERT INTO " . $table_name . " (original, translated, lang) " .652 //"VALUES ('Hello','Hi There','zz')";653 654 //$result = $wpdb->query($insert);655 656 //if($result === FALSE)657 //{658 //logger("Error failed to create $table_name !!!", 0);659 //}660 //else661 //{662 // logger("Table $table_name was created successfuly", 0);663 //}664 //}665 634 666 635 $table_name = $wpdb->prefix . TRANSLATIONS_LOG; 667 636 668 //if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)669 //{670 637 logger("Attempting to create table $table_name", 0); 671 638 $sql = "CREATE TABLE " . $table_name . " (original VARCHAR(256) NOT NULL, … … 679 646 680 647 dbDelta($sql); 681 // TODO: check682 648 update_option(TRANSPOSH_DB_VERSION, DB_VERSION); 683 649 } … … 757 723 758 724 if (function_exists('deactivate_plugins') ) { 759 deactivate_plugins( "transposh/translate.php", "translate.php");725 deactivate_plugins(get_plugin_name(), "translate.php"); 760 726 echo '<br> This plugin has been automatically deactivated.'; 761 727 } … … 788 754 } 789 755 790 // TODO: This is wrong? and also deactivation fails 791 if (get_option(TRANSPOSH_DB_VERSION) == NULL) 756 if ($db_version != DB_VERSION) 792 757 { 793 758 $admin_msg = "Failed to locate the translation table <em> " . TRANSLATIONS_TABLE . "</em> in local database. <br>";
Note: See TracChangeset
for help on using the changeset viewer.
