You are here

function i18ntaxonomy_db_rewrite_sql in Internationalization 6

Implementation of hook_db_rewrite_sql().

File

i18ntaxonomy/i18ntaxonomy.module, line 337
i18n taxonomy module

Code

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

  // No rewrite for administration pages or mode = off.
  $mode = i18n_selection_mode();
  if ($mode == 'off' || arg(0) == 'admin') {
    return;
  }
  switch ($primary_table) {
    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, or when using the term_node table.
      if (preg_match("/WHERE r\\.nid = \\%d/", $query)) {
        return;
      }
      if (preg_match("/{term_node}/", $query)) {
        return;
      }
      $result['where'] = i18n_db_rewrite_where($primary_table, 'taxonomy', $mode);
      return $result;
  }
}