xmlsitemap_i18n.module 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * Implements hook_xmlsitemap_context_info().
  4. */
  5. function xmlsitemap_i18n_xmlsitemap_context_info() {
  6. $context['language'] = array(
  7. 'label' => t('Language'),
  8. 'summary callback' => 'locale_language_name',
  9. 'default' => language_default('language'),
  10. );
  11. return $context;
  12. }
  13. /**
  14. * Implements hook_xmlsitemap_context().
  15. */
  16. function xmlsitemap_i18n_xmlsitemap_context() {
  17. $context['language'] = $GLOBALS['language']->language;
  18. return $context;
  19. }
  20. /**
  21. * Implements xmlsitemap_context_url_options().
  22. */
  23. function xmlsitemap_i18n_xmlsitemap_context_url_options(array $context) {
  24. $options = array();
  25. if (isset($context['language'])) {
  26. $options['language'] = xmlsitemap_language_load($context['language']);
  27. }
  28. return $options;
  29. }
  30. /**
  31. * Implements hook_form_FORM_ID_alter().
  32. */
  33. function xmlsitemap_i18n_form_xmlsitemap_sitemap_edit_form_alter(&$form, $form_state) {
  34. $form['context']['language'] = array(
  35. '#type' => 'select',
  36. '#title' => t('Language'),
  37. '#options' => locale_language_list(),
  38. '#default_value' => isset($form['#sitemap']->context['language']) ? $form['#sitemap']->context['language'] : LANGUAGE_NONE,
  39. );
  40. }
  41. /**
  42. * Implements hook_form_FORM_ID_alter().
  43. *
  44. * Set the regeneration needed flag if settings are changed.
  45. */
  46. function xmlsitemap_form_locale_languages_overview_form_alter(&$form, $form_state) {
  47. array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
  48. }
  49. /**
  50. * Implements hook_form_FORM_ID_alter().
  51. *
  52. * Set the regeneration needed flag if multilingual settings are changed.
  53. */
  54. function xmlsitemap_i18n_form_i18n_admin_settings_alter(&$form, $form_state) {
  55. array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
  56. }
  57. /**
  58. * Implements hook_query_TAG_alter().
  59. *
  60. * @see i18n_db_rewrite_where()
  61. */
  62. function xmlsitemap_i18n_query_xmlsitemap_generate_alter(QueryAlterableInterface $query) {
  63. $mode = variable_get('i18n_selection_mode', 'simple');
  64. $sitemap = $query->getMetaData('sitemap');
  65. if (!isset($sitemap->context['language']) || $mode == 'off') {
  66. return;
  67. }
  68. // Get languages to simplify query building.
  69. $current = $sitemap->context['language'];
  70. $default = language_default();
  71. if ($mode == 'mixed' && $current == $default) {
  72. // If mode is mixed but current = default, is the same as 'simple'.
  73. $mode = 'simple';
  74. }
  75. switch ($mode) {
  76. case 'simple':
  77. // Current language and language neutral.
  78. $query->condition('x.language', array($current, LANGUAGE_NONE));
  79. break;
  80. case 'mixed':
  81. // Mixed current language (if available) or default language (if not) and language neutral.
  82. $query->condition('x.language', array($current, $default, LANGUAGE_NONE));
  83. break;
  84. case 'default':
  85. // Only default language and language neutral.
  86. $query->condition('x.language', array($default, LANGUAGE_NONE));
  87. break;
  88. case 'strict':
  89. // Only current language (for nodes), simple for all other types.
  90. $node_condition = db_and();
  91. $node_condition->condition('x.type', 'node');
  92. $node_condition->condition('x.language', $current);
  93. $normal_condition = db_and();
  94. $normal_condition->condition('x.type', 'node', '<>');
  95. $normal_condition->condition('x.language', array($current, LANGUAGE_NONE));
  96. $condition = db_or();
  97. $condition->condition($node_condition);
  98. $condition->condition($normal_condition);
  99. $query->condition($condition);
  100. break;
  101. case 'off':
  102. // All content. No language conditions apply.
  103. break;
  104. }
  105. }