xmlsitemap_i18n.module 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. // $Id: xmlsitemap_i18n.module,v 1.4 2009/12/23 22:29:16 davereid Exp $
  3. /**
  4. * Implements hook_form_FORM_ID_alter().
  5. *
  6. * Set the regeneration needed flag if multilingual settings are changed.
  7. */
  8. function xmlsitemap_i18n_form_i18n_admin_settings_alter(&$form, $form_state) {
  9. array_unshift($form['#submit'], 'xmlsitemap_form_submit_flag_regenerate');
  10. }
  11. /**
  12. * Implements hook_form_FORM_ID_alter().
  13. *
  14. * Allow the user to have multilingual sitemaps.
  15. */
  16. function xmlsitemap_i18n_form_xmlsitemap_settings_form_alter(&$form, $form_state) {
  17. $form['xmlsitemap']['xmlsitemap_languages']['#options'] = locale_language_list();
  18. $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')));
  19. }
  20. /**
  21. * Implements hook_query_TAG_alter().
  22. *
  23. * @see i18n_db_rewrite_where()
  24. */
  25. function xmlsitemap_i18n_query_xmlsitemap_alter(QueryAlterableInterface $query) {
  26. // Get languages to simplify query building.
  27. $mode = variable_get('i18n_selection_mode', 'simple');
  28. $current = $query->getMetaData('language')->language;
  29. $default = i18n_default_language();
  30. if ($mode == 'mixed' && $current == $default) {
  31. // If mode is mixed but current = default, is the same as 'simple'.
  32. $mode = 'simple';
  33. }
  34. switch ($mode) {
  35. case 'simple':
  36. // Current language and language neutral.
  37. $query->condition('language', array($current, LANGUAGE_NONE));
  38. break;
  39. case 'mixed':
  40. // Mixed current language (if available) or default language (if not) and language neutral.
  41. $query->condition('language', array($current, $default, LANGUAGE_NONE));
  42. break;
  43. case 'default':
  44. // Only default language and language neutral.
  45. $query->condition('language', array($default, LANGUAGE_NONE));
  46. break;
  47. case 'strict':
  48. // Only current language (for nodes), simple for all other types.
  49. $node_condition = db_and();
  50. $node_condition->condition('type', 'node');
  51. $node_condition->condition('language', $current);
  52. $normal_condition = db_and();
  53. $normal_condition->condition('type', 'node', '<>');
  54. $normal_condition->condition('language', array($current, LANGUAGE_NONE));
  55. $condition = db_or();
  56. $condition->condition($node_condition);
  57. $condition->condition($normal_condition);
  58. $query->condition($condition);
  59. break;
  60. case 'off':
  61. // All content. No language conditions apply.
  62. break;
  63. }
  64. }