Changeset 365
- Timestamp:
- 01/26/2010 11:13:15 PM (2 years ago)
- Location:
- trunk/WordPress/plugin/transposh/wp
- Files:
-
- 2 edited
-
transposh_ajax.php (modified) (1 diff)
-
transposh_db.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/wp/transposh_ajax.php
r346 r365 45 45 46 46 if ($_POST['translation_posted'] == 2) { 47 $my_transposh_plugin->database->update_translation_new();48 }49 else {50 47 $my_transposh_plugin->database->update_translation(); 51 48 } -
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r346 r365 97 97 } 98 98 99 /*100 * A new translation has been posted, update the translation database.101 * This has changed since we now accept multiple translations at once102 */103 function update_translation() {104 105 $ref=getenv('HTTP_REFERER');106 $items = $_POST['items'];107 $lang = $_POST['lang'];108 $source = $_POST['source'];109 // check params110 logger("Enter " . __FILE__ . " Params: $items, $lang, $ref", 53);111 if(!isset($items) || !isset($lang)) {112 logger("Enter " . __FILE__ . " missing Params: $items, $lang, $ref", 1);113 return;114 }115 116 //Check permissions, first the lanugage must be on the edit list. Then either the user117 //is a translator or automatic translation if it is enabled.118 if(!($this->transposh->options->is_editable_language($lang) &&119 ($this->transposh->is_translator() || ($source == 1 && $this->transposh->options->get_enable_auto_translate())))) {120 logger("Unauthorized translation attempt " . $_SERVER['REMOTE_ADDR'] , 1);121 header("HTTP/1.0 401 Unauthorized translation");122 exit;123 }124 125 //add our own custom header - so we will know that we got here126 header("Transposh: v-".TRANSPOSH_PLUGIN_VER." db_version-". DB_VERSION);127 128 // transaction log stuff129 global $user_ID;130 get_currentuserinfo();131 132 // log either the user ID or his IP133 if ('' == $user_ID) {134 $loguser = $_SERVER['REMOTE_ADDR'];135 }136 else {137 $loguser = $user_ID;138 }139 // end tl140 141 // We are now passing all posted items142 for ($i=0;$i<$items;$i++) {143 $original = base64_url_decode($_POST["tk$i"]);144 $translation = $_POST["tr$i"];145 //Decode & remove already escaped character to avoid double escaping146 $translation = $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translation))));147 148 //The original content is encoded as base64 before it is sent (i.e. token), after we149 //decode it should just the same after it was parsed.150 $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8'));151 152 //Here we check we are not redoing stuff153 list($translated_text, $old_source) = $this->fetch_translation($original, $lang);154 if ($translated_text) {155 if ($source == 1) {156 logger("Warning auto-translation for already translated: $original", 0);157 return;158 }159 if ($translation == $GLOBALS['wpdb']->escape(htmlspecialchars(stripslashes(urldecode($translated_text)))) && $old_source == $source) {160 logger("Warning attempt to retranslate with same text: $original, $translation", 0);161 return;162 }163 }164 // Setting the values string for the database (notice how concatanation is handled)165 $values .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $source . "')".(($items != $i+1) ?', ':'');166 // Setting the transaction log records167 $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','".$loguser."','".$source."')".(($items != $i+1) ?', ':'');168 169 // If we have caching - we remove previous entry from cache170 if(ENABLE_APC && function_exists('apc_store')) {171 apc_delete($original .'___'. $lang);172 }173 }174 175 // perform insertion to the database, with one query :)176 $update = "REPLACE INTO ".$GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE." (original, translated, lang, source)177 VALUES $values";178 logger($update,4);179 180 $result = $GLOBALS['wpdb']->query($update);181 182 if($result !== FALSE) {183 // update the transaction log too184 $log = "INSERT INTO ".$GLOBALS['wpdb']->prefix.TRANSLATIONS_LOG." (original, translated, lang, translated_by, source) ".185 "VALUES $logvalues";186 $result = $GLOBALS['wpdb']->query($log);187 188 logger("Inserted to db '$values'" , 3);189 }190 else {191 logger(mysql_error(),0);192 logger("Error !!! failed to insert to db $original , $translation, $lang," , 0);193 header("HTTP/1.0 404 Failed to update language database ".mysql_error());194 }195 // this is a termination for the ajax sequence196 exit;197 }198 199 99 /** 200 100 * A new translation has been posted, update the translation database. 201 101 * This has changed since we now accept multiple translations at once 202 102 * This function accepts a new more "versatile" format 103 * TODO - return some info? 203 104 * @global <type> $user_ID - TODO 204 105 */ 205 function update_translation _new() {106 function update_translation() { 206 107 207 108 $ref=getenv('HTTP_REFERER');
Note: See TracChangeset
for help on using the changeset viewer.
