Changeset 365


Ignore:
Timestamp:
01/26/2010 11:13:15 PM (2 years ago)
Author:
ofer
Message:

Remove old database update method which is no longer used

Location:
trunk/WordPress/plugin/transposh/wp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/wp/transposh_ajax.php

    r346 r365  
    4545 
    4646    if ($_POST['translation_posted'] == 2) { 
    47         $my_transposh_plugin->database->update_translation_new(); 
    48     } 
    49     else { 
    5047        $my_transposh_plugin->database->update_translation(); 
    5148    } 
  • trunk/WordPress/plugin/transposh/wp/transposh_db.php

    r346 r365  
    9797    } 
    9898 
    99     /* 
    100  * A new translation has been posted, update the translation database. 
    101  * This has changed since we now accept multiple translations at once 
    102     */ 
    103     function update_translation() { 
    104  
    105         $ref=getenv('HTTP_REFERER'); 
    106         $items = $_POST['items']; 
    107         $lang = $_POST['lang']; 
    108         $source = $_POST['source']; 
    109         // check params 
    110         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 user 
    117         //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 here 
    126         header("Transposh: v-".TRANSPOSH_PLUGIN_VER." db_version-". DB_VERSION); 
    127  
    128         // transaction log stuff 
    129         global $user_ID; 
    130         get_currentuserinfo(); 
    131  
    132         // log either the user ID or his IP 
    133         if ('' == $user_ID) { 
    134             $loguser = $_SERVER['REMOTE_ADDR']; 
    135         } 
    136         else { 
    137             $loguser = $user_ID; 
    138         } 
    139         // end tl 
    140  
    141         // We are now passing all posted items 
    142         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 escaping 
    146             $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 we 
    149             //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 stuff 
    153             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 records 
    167             $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','".$loguser."','".$source."')".(($items != $i+1) ?', ':''); 
    168  
    169             // If we have caching - we remove previous entry from cache 
    170             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 too 
    184             $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 sequence 
    196         exit; 
    197     } 
    198  
    19999    /** 
    200100     * A new translation has been posted, update the translation database. 
    201101     * This has changed since we now accept multiple translations at once 
    202102     * This function accepts a new more "versatile" format 
     103     * TODO - return some info? 
    203104     * @global <type> $user_ID - TODO 
    204105     */ 
    205     function update_translation_new() { 
     106    function update_translation() { 
    206107 
    207108        $ref=getenv('HTTP_REFERER'); 
Note: See TracChangeset for help on using the changeset viewer.