You are here

function i18n_db_rewrite_sql in Internationalization 5

Same name and namespace in other branches
  1. 5.3 i18n.module \i18n_db_rewrite_sql()
  2. 5.2 i18n.module \i18n_db_rewrite_sql()
  3. 6 i18n.module \i18n_db_rewrite_sql()

Implementation of hook_db_rewrite_sql()

File

./i18n.module, line 724
Internationalization (i18n) module

Code

function i18n_db_rewrite_sql($query, $primary_table, $primary_key) {

  // Some exceptions for query rewrites
  $mode = i18n_selection_mode();

  // drupal_set_message("i18n_db_rewrite mode=$mode query=$query");
  if ($mode == 'off') {
    return;
  }

  // Special case. Selection mode is 'strict' but this should be only for node queries
  if ($mode == 'strict' && $primary_table != 'n' && $primary_table != 'node') {
    $mode = 'simple';
  }
  switch ($primary_table) {
    case 'n':
    case 'node':
    case 'nc':

      // For node_comment table, added in 5.2
      // Node queries.
      // When loading specific nodes, language conditions shouldn't apply
      if (preg_match("/WHERE.*\\s{$primary_table}.nid\\s*=\\s*(\\d|%d)/", $query)) {
        return;
      }

      // If language conditions already there, get out
      if (preg_match("/i18n/", $query)) {
        return;
      }
      $result['join'] = "LEFT JOIN {i18n_node} i18n ON {$primary_table}.nid = i18n.nid";
      $result['where'] = i18n_db_rewrite_where('i18n', $mode);
      return $result;
    case 't':
    case 'v':

      // Taxonomy queries
      // When loading specific terms, vocabs, language conditions shouldn't apply
      if (preg_match("/WHERE.* {$primary_table}\\.tid\\s*(=\\s*\\d|IN)/", $query)) {
        return;
      }

      // Taxonomy for specific node
      if (preg_match("/WHERE r\\.nid = \\%d/", $query)) {
        return;
      }
      $result['where'] = i18n_db_rewrite_where($primary_table, $mode);
      return $result;
    case 'm':

      // Should not apply for menu administration pages
      if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'menu') {
        return;
      }

      // Menu queries. Rewrite mode is always 'simple' to avoid trouble with cache
      $result['where'] = i18n_db_rewrite_where($primary_table, 'simple');
      return $result;
  }
}