Changeset 505 for trunk/WordPress/plugin/transposh/wp/transposh_db.php
- Timestamp:
- 08/12/2010 03:45:29 AM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/wp/transposh_db.php
r504 r505 34 34 /** @var transposh_plugin father class */ 35 35 private $transposh; 36 /** @var array holds prefetched translations */ 36 37 private $translations; 38 /** @var string translation table name */ 39 private $translation_table; 40 /** @var string translation log table name */ 41 private $translation_log_table; 37 42 38 43 /** … … 41 46 function transposh_database(&$transposh) { 42 47 $this->transposh = &$transposh; 48 $this->translation_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 49 $this->translation_log_table = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG; 43 50 } 44 51 … … 140 147 // If we have nothing, we will do nothing 141 148 if (!$where) return; 142 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 143 $query = "SELECT original, translated, source FROM $table_name WHERE ($where) and lang = '$lang' "; 149 $query = "SELECT original, translated, source FROM {$this->translation_table} WHERE ($where) and lang = '$lang' "; 144 150 $rows = $GLOBALS['wpdb']->get_results($query, ARRAY_A); 145 151 if (empty($rows)) return; … … 175 181 logger("prefetch result for $original >>> {$this->translations[$original][0]} ({$this->translations[$original][1]})", 4); 176 182 } else { 177 178 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 179 $query = "SELECT * FROM $table_name WHERE original = '$original' and lang = '$lang' "; 183 $query = "SELECT * FROM {$this->translation_table} WHERE original = '$original' and lang = '$lang' "; 180 184 $row = $GLOBALS['wpdb']->get_row($query); 181 185 … … 218 222 logger("prefetch result for $translation >>> {$this->translations[$translation][0]} ({$this->translations[$translation][1]})", 3); 219 223 } else { 220 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 221 $query = "SELECT * FROM $table_name WHERE translated = '$translation' and lang = '$lang' "; 224 $query = "SELECT * FROM {$this->translation_table} WHERE translated = '$translation' and lang = '$lang' "; 222 225 $row = $GLOBALS['wpdb']->get_row($query); 223 226 … … 333 336 // If we have caching - we remove previous entry from cache 334 337 $this->cache_delete($original, $lang); 338 // TODO - maybe store value here? 335 339 } 336 340 … … 342 346 VALUES $values"; */ 343 347 //so we'll delete all values and insert them... 344 $update = "DELETE FROM " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE. " WHERE $delvalues";348 $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues"; 345 349 logger($update, 3); 346 350 $result = $GLOBALS['wpdb']->query($update); 347 $update = "INSERT INTO " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE. " (original, translated, lang, source) VALUES $values";351 $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES $values"; 348 352 logger($update, 3); 349 353 $result = $GLOBALS['wpdb']->query($update); … … 351 355 // if the insertion worked, we will update the transaction log 352 356 if ($result !== FALSE) { 353 $log = "INSERT INTO " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG. " (original, translated, lang, translated_by, source) " .357 $log = "INSERT INTO " . $this->translation_log_table . " (original, translated, lang, translated_by, source) " . 354 358 "VALUES $logvalues"; 355 359 $result = $GLOBALS['wpdb']->query($log); … … 403 407 logger('Passed check for editable and translator', 4); 404 408 405 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;406 logger("table is $table_name", 4);407 408 409 // The original content is encoded as base64 before it is sent (i.e. token), after we 409 410 // decode it should just the same after it was parsed. … … 414 415 415 416 $query = "SELECT translated, translated_by, timestamp, source, user_login " . 416 "FROM $table_name" .417 "FROM {$this->translation_log_table} " . 417 418 "LEFT JOIN {$GLOBALS['wpdb']->prefix}users ON translated_by = {$GLOBALS['wpdb']->prefix}users.id " . 418 419 "WHERE original='$original' AND lang='$lang' " . … … 450 451 */ 451 452 function get_all_human_translation_history($date ="null", $limit = "") { 452 453 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG;454 logger("table is $table_name", 4);455 456 453 if ($date != "null") 457 454 $dateterm = "and UNIX_TIMESTAMP(timestamp) > $date"; 458 455 if ($limit) $limitterm = "LIMIT $limit"; 459 456 $query = "SELECT original, lang, translated, translated_by, UNIX_TIMESTAMP(timestamp) as timestamp " . 460 "FROM $table_name" .457 "FROM {$this->translation_log_table} " . 461 458 "WHERE source= 0 $dateterm " . 462 459 "ORDER BY timestamp ASC $limitterm"; … … 478 475 479 476 if ($installed_ver != DB_VERSION) { 480 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 481 482 logger("Attempting to create table $table_name", 0); 477 logger("Attempting to create table {$this->translation_table}", 0); 483 478 // notice - keep every field on a new line or dbdelta fails 484 479 $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY"); 485 $sql = "CREATE TABLE $table_name(480 $sql = "CREATE TABLE {$this->translation_table} ( 486 481 original TEXT NOT NULL, 487 482 lang CHAR(5) NOT NULL, … … 493 488 dbDelta($sql); 494 489 495 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG; 496 497 logger("Attempting to create table $table_name", 0); 490 logger("Attempting to create table {$this->translation_log_table}", 0); 498 491 // notice - keep every field on a new line or dbdelta fails 492 // this should be removed in a far future... 499 493 $GLOBALS['wpdb']->query("ALTER TABLE $table_name DROP PRIMARY KEY"); 500 $sql = "CREATE TABLE $table_name(494 $sql = "CREATE TABLE {$this->translation_log_table} ( 501 495 original text NOT NULL, 502 496 lang CHAR(5) NOT NULL, … … 520 514 function db_stats() { 521 515 echo "<h4>Database stats</h4>"; 522 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE; 523 $log_table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG; 524 $query = "SELECT count(*) as count FROM `$table_name`"; 516 $query = "SELECT count(*) as count FROM `{$this->translation_table}`"; 525 517 $rows = $GLOBALS['wpdb']->get_results($query); 526 518 foreach ($rows as $row) { … … 529 521 } 530 522 531 $query = "SELECT count(*) as count,lang FROM ` $table_name` WHERE source='0' GROUP BY `lang` ORDER BY `count` DESC LIMIT 3";523 $query = "SELECT count(*) as count,lang FROM `{$this->translation_table}` WHERE source='0' GROUP BY `lang` ORDER BY `count` DESC LIMIT 3"; 532 524 $rows = $GLOBALS['wpdb']->get_results($query); 533 525 foreach ($rows as $row) { … … 537 529 538 530 echo "<h4>Recent activity</h4>"; 539 $query = "SELECT * FROM ` $log_table_name` WHERE source='0' ORDER BY `timestamp` DESC LIMIT 3";531 $query = "SELECT * FROM `{$this->translation_log_table}` WHERE source='0' ORDER BY `timestamp` DESC LIMIT 3"; 540 532 $rows = $GLOBALS['wpdb']->get_results($query); 541 533 foreach ($rows as $row) { … … 554 546 */ 555 547 function get_orignal_phrases_for_search_term($term, $language) { 556 $table_name = $GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE;557 548 $n = '%'; 558 549 $term = addslashes_gpc($term); 559 $query = "SELECT original 560 FROM `$table_name`561 WHERE `lang` LIKE '$language'562 AND `translated` LIKE '{$n}{$term}{$n}'";550 $query = "SELECT original" . 551 " FROM `{$this->translation_table}`" . 552 " WHERE `lang` LIKE '$language'" . 553 " AND `translated` LIKE '{$n}{$term}{$n}'"; 563 554 //TODO wait for feedbacks to see if we should put a limit here. 564 555 … … 594 585 function cleanup($days = 0) { 595 586 $days = intval($days); // some security 596 $cleanup = 'DELETE ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . ' ,' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG.597 ' FROM ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE.598 ' INNER JOIN ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG.599 ' ON ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . '.original = ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG. '.original' .600 ' AND ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE . '.lang = ' . $GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG. '.lang' .601 ' WHERE ' . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE. '.source > 0' .587 $cleanup = 'DELETE ' . $this->translation_table . ' ,' . $this->translation_log_table . 588 ' FROM ' . $this->translation_table . 589 ' INNER JOIN ' . $this->translation_log_table . 590 ' ON ' . $this->translation_table . '.original = ' . $this->translation_log_table . '.original' . 591 ' AND ' . $this->translation_table . '.lang = ' . $this->translation_log_table . '.lang' . 592 ' WHERE ' . $this->translation_table . '.source > 0' . 602 593 " AND timestamp < SUBDATE(NOW(),$days)"; 603 594 $result = $GLOBALS['wpdb']->query($cleanup); … … 623 614 $logvalues .= "('" . $original . "','" . $translation . "','" . $lang . "','" . $by . "',FROM_UNIXTIME(" . $timestamp . "),'" . $source . "')"; 624 615 625 $update = "DELETE FROM " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE. " WHERE $delvalues";616 $update = "DELETE FROM " . $this->translation_table . " WHERE $delvalues"; 626 617 logger($update, 3); 627 618 $result = $GLOBALS['wpdb']->query($update); 628 $update = "INSERT INTO " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_TABLE. " (original, translated, lang, source) VALUES $values";619 $update = "INSERT INTO " . $this->translation_table . " (original, translated, lang, source) VALUES $values"; 629 620 logger($update, 3); 630 621 $result = $GLOBALS['wpdb']->query($update); … … 632 623 if ($result !== FALSE) { 633 624 // update the transaction log too 634 $log = "INSERT INTO " . $ GLOBALS['wpdb']->prefix . TRANSLATIONS_LOG. " (original, translated, lang, translated_by, timestamp, source) " .625 $log = "INSERT INTO " . $this->translation_log_table . " (original, translated, lang, translated_by, timestamp, source) " . 635 626 "VALUES $logvalues"; 636 627 logger($log, 3);
Note: See TracChangeset
for help on using the changeset viewer.
