Changeset 513 for trunk/WordPress/plugin/transposh/wp/transposh_db.php
- Timestamp:
- 08/23/2010 03:32:14 AM (21 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r507 r513 59 59 if (!TP_ENABLE_CACHE) return false; 60 60 $cached = false; 61 $key = $ original . '___' . $lang;61 $key = $lang . '_' . $original; 62 62 if (function_exists('apc_fetch')) { 63 63 $cached = apc_fetch($key, $rc); … … 71 71 } elseif (function_exists('eaccelerator_get')) { 72 72 $cached = eaccelerator_get($key); 73 if ($cached === null) 74 return false; //TODO - unfortunantly null storing does not work here.. 75 logger('eaccelerator', 5); 76 } 77 logger("Cached: $original", 5); 73 if ($cached === null) return false; 74 //TODO - unfortunantly null storing does not work here.. 75 logger('eaccelerator', 5); 76 } 77 logger("Cache fetched: $original => $cached", 3); 78 if ($cached !== null) $cached = explode('_', $cached, 2); 78 79 return $cached; 79 80 } … … 89 90 function cache_store($original, $lang, $translated, $ttl) { 90 91 if (!TP_ENABLE_CACHE) return false; 91 $key = $original . '___' . $lang; 92 $cache_entry = $translated; 92 $key = $lang . '_' . $original; 93 if ($translated !== null) { 94 $translated = implode('_', $translated); 95 } 93 96 //If we don't have translation still we want to have it in cache 94 97 //update cache FIXME, do we really need this null to ""? 95 if ($cache_entry == NULL) {96 $cache_entry = "";97 }98 98 if (function_exists('apc_store')) { 99 $rc = apc_store($key, $ cache_entry, $ttl);99 $rc = apc_store($key, $translated, $ttl); 100 100 } elseif (function_exists('xcache_set')) { 101 $rc = xcache_set($key, $ cache_entry, $ttl);101 $rc = xcache_set($key, $translated, $ttl); 102 102 } elseif (function_exists('eaccelerator_put')) { 103 $rc = eaccelerator_put($key, $ cache_entry, $ttl);103 $rc = eaccelerator_put($key, $translated, $ttl); 104 104 } 105 105 106 106 if ($rc) { 107 logger("Stored in cache: $original => {$translated[0]},{$translated[1]}", 3); 107 logger("Stored in cache: $original => {$translated}", 3); 108 } else { 109 logger("Didn't cache: $original => {$translated}", 3); 108 110 } 109 111 return $rc; … … 164 166 // we are saving in the array and not directly to cache, because cache might not exist... 165 167 foreach ($rows as $row) { 166 $this->translations[$row['original']] = array( stripslashes($row['translated']), $row['source']);168 $this->translations[$row['original']] = array($row['source'], stripslashes($row['translated'])); 167 169 } 168 170 logger($this->translations, 5); … … 175 177 * @param string $original 176 178 * @param string $lang 177 * @return array list( translation,source)179 * @return array list(source,translation) 178 180 */ 179 181 function fetch_translation($original, $lang) { 180 $translated = NULL;181 logger(" Enter: $original", 4);182 $translated = null; 183 logger("Fetching for: $original-$lang", 4); 182 184 //The original is saved in db in its escaped form 183 185 $original = $GLOBALS['wpdb']->escape(html_entity_decode($original, ENT_NOQUOTES, 'UTF-8')); … … 191 193 if ($this->translations[$original]) { 192 194 $translated = $this->translations[$original]; 193 logger("prefetch result for $original >>> {$this->translations[$original][0]} ({$this->translations[$original][1]})", 4);195 logger("prefetch result for $original >>> {$this->translations[$original][0]} ({$this->translations[$original][1]})", 3); 194 196 } else { 195 197 $query = "SELECT * FROM {$this->translation_table} WHERE original = '$original' and lang = '$lang' "; 196 198 $row = $GLOBALS['wpdb']->get_row($query); 197 199 198 if ($row !== FALSE) {200 if ($row !== null) { 199 201 $translated_text = stripslashes($row->translated); 200 $translated = array($translated_text, $row->source); 201 202 logger("db result for $original >>> $translated_text ($lang) ({$row->source})", 4); 202 $translated = array($row->source, $translated_text); 203 logger("db result for $original >>> $translated_text ($lang) ({$row->source})", 3); 203 204 } 204 205 } … … 218 219 */ 219 220 function fetch_original($translation, $lang) { 220 $original = NULL;221 $original = null; 221 222 logger("Enter: $translation", 4); 222 223 … … 224 225 $translation = $GLOBALS['wpdb']->escape(html_entity_decode($translation, ENT_NOQUOTES, 'UTF-8')); 225 226 // The translation might be cached (notice the additional postfix) 226 $cached = $this->cache_fetch( $translation . '_R_', $lang);227 $cached = $this->cache_fetch('R_' . $translation, $lang); 227 228 if ($cached !== false) { 228 229 logger("Exit from cache: $cached", 4); … … 237 238 $row = $GLOBALS['wpdb']->get_row($query); 238 239 239 if ($row !== FALSE) {240 if ($row !== null) { 240 241 $original = stripslashes($row->original); 241 242 logger("db result for $translation >>> $original ($lang) ({$row->source})", 4); … … 244 245 245 246 // we can store the result in the cache (or the fact we don't have one) 246 $this->cache_store( $translation . '_R_', $lang, $original, TP_CACHE_TTL);247 $this->cache_store('R_' . $translation, $lang, $original, TP_CACHE_TTL); 247 248 248 249 logger("Exit: $translation/$original", 4); … … 647 648 648 649 } 650 649 651 ?>
Note: See TracChangeset
for help on using the changeset viewer.
