You are here

function xmlsitemap_i18n_query_xmlsitemap_generate_alter in XML sitemap 6.2

Same name and namespace in other branches
  1. 7.2 xmlsitemap_i18n/xmlsitemap_i18n.module \xmlsitemap_i18n_query_xmlsitemap_generate_alter()

Implements hook_query_xmlsitemap_generate_alter().

See also

i18n_db_rewrite_where()

File

xmlsitemap_i18n/xmlsitemap_i18n.module, line 69

Code

function xmlsitemap_i18n_query_xmlsitemap_generate_alter(array &$query, array &$args, stdClass $sitemap) {
  $mode = variable_get('i18n_selection_mode', 'simple');
  if (!isset($sitemap->context['language']) || $mode == 'off') {
    return;
  }

  // Get languages to simplify query building.
  $current = $sitemap->context['language'];
  $default = i18n_default_language();
  if ($mode == 'mixed' && $current == $default) {

    // If mode is mixed but current = default, is the same as 'simple'.
    $mode = 'simple';
  }
  switch ($mode) {
    case 'simple':

      // Current language and language neutral.
      $query['WHERE'] .= " AND x.language IN ('%s', '')";
      $args[] = $current;
      break;
    case 'mixed':

      // Mixed current language (if available) or default language (if not) and language neutral.
      $query['WHERE'] .= " AND x.language IN ('%s', '%s', '')";
      $args[] = $current;
      $args[] = $default;
      break;
    case 'default':

      // Only default language and language neutral.
      $query['WHERE'] .= " AND x.language IN ('%s', '')";
      $args[] = $default;
      break;
    case 'strict':

      // Only current language (for nodes), simple for all other types.
      $query['WHERE'] .= " AND ((x.type = 'node' AND x.language = '%s') OR (x.type <> 'node' AND x.language IN ('%s', '')))";
      $args[] = $current;
      $args[] = $current;
      break;
    case 'off':

      // All content. No language conditions apply. Handled by if statement
      // above.
      break;
  }
}