xmlsitemap_i18n.module 2.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
// $Id$

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Set the regeneration needed flag if multilingual settings are changed.
 */
function xmlsitemap_i18n_form_i18n_admin_settings_alter(&$form, $form_state) {
  array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
}

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Allow the user to have multilingual sitemaps.
 */
function xmlsitemap_i18n_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
  $form['xmlsitemap']['xmlsitemap_languages']['#options'] = locale_language_list();
  $form['xmlsitemap']['xmlsitemap_languages']['#description'] = t("Each language's sitemap will respect the <a href=\"@i18n-settings\">multilingual content selection mode</a>.", array('@i18n-settings' => url('admin/settings/language/i18n')));
}

/**
 * Implements hook_xmlsitemap_query_alter().
 *
 * @see i18n_db_rewrite_where()
 */
function xmlsitemap_i18n_xmlsitemap_query_alter(array &$query, array &$args, stdClass $language) {
  // Get languages to simplify query building.
  $mode = variable_get('i18n_selection_mode', 'simple');
  //$current = i18n_get_lang();
  $current = $language->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.
      break;
  }
}