simple_sitemap.api.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the Simple XML sitemap module.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Alter the generated link data before the sitemap is saved.
  12. * This hook gets invoked for every sitemap chunk generated.
  13. *
  14. * @param array &$links
  15. * Array containing multilingual links generated for each path to be indexed
  16. *
  17. * @param string|null $sitemap_variant
  18. */
  19. function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
  20. // Remove German URL for a certain path in the hreflang sitemap.
  21. foreach ($links as $key => $link) {
  22. if ($link['path'] === 'node/1') {
  23. // Remove 'loc' URL if it points to a german site.
  24. if ($link['langcode'] === 'de') {
  25. unset($links[$key]);
  26. }
  27. // If this 'loc' URL points to a non-german site, make sure to remove
  28. // its german alternate URL.
  29. else {
  30. if ($link['alternate_urls']['de']) {
  31. unset($links[$key]['alternate_urls']['de']);
  32. }
  33. }
  34. }
  35. }
  36. }
  37. /**
  38. * Add arbitrary links to the sitemap.
  39. *
  40. * @param array &$arbitrary_links
  41. * @param string|null $sitemap_variant
  42. */
  43. function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links, $sitemap_variant) {
  44. // Add an arbitrary link to all sitemap variants.
  45. $arbitrary_links[] = [
  46. 'url' => 'http://some-arbitrary-link/',
  47. 'priority' => '0.5',
  48. // An ISO8601 formatted date.
  49. 'lastmod' => '2012-10-12T17:40:30+02:00',
  50. 'changefreq' => 'weekly',
  51. 'images' => [
  52. ['path' => 'http://path-to-image.png']
  53. ],
  54. // Add alternate URLs for every language of a multilingual site.
  55. // Not necessary for monolingual sites.
  56. 'alternate_urls' => [
  57. 'en' => 'http://this-is-your-life.net/de/tyler',
  58. 'de' => 'http://this-is-your-life.net/en/tyler',
  59. ]
  60. ];
  61. // Add an arbitrary link to the 'fight_club' sitemap variant only.
  62. switch ($sitemap_variant) {
  63. case 'fight_club':
  64. $arbitrary_links[] = [
  65. 'url' => 'http://this-is-your-life.net/tyler',
  66. ];
  67. break;
  68. }
  69. }
  70. /**
  71. * Alters the sitemap attributes shortly before XML document generation.
  72. * Attributes can be added, changed and removed.
  73. *
  74. * @param array &$attributes
  75. * @param string|null $sitemap_variant
  76. */
  77. function hook_simple_sitemap_attributes_alter(array &$attributes, $sitemap_variant) {
  78. // Remove the xhtml attribute e.g. if no xhtml sitemap elements are present.
  79. unset($attributes['xmlns:xhtml']);
  80. }
  81. /**
  82. * Alters attributes of the sitemap index shortly before XML document generation.
  83. * Attributes can be added, changed and removed.
  84. *
  85. * @param array &$index_attributes
  86. * @param string|null $sitemap_variant
  87. */
  88. function hook_simple_sitemap_index_attributes_alter(array &$index_attributes, $sitemap_variant) {
  89. // Add some attribute to the sitemap index.
  90. $index_attributes['name'] = 'value';
  91. }
  92. /**
  93. * Alter properties of and remove URL generator plugins.
  94. *
  95. * @param array $url_generators
  96. */
  97. function hook_simple_sitemap_url_generators_alter(array &$url_generators) {
  98. // Remove the entity generator.
  99. unset($url_generators['entity']);
  100. }
  101. /**
  102. * Alter properties of and remove sitemap generator plugins.
  103. *
  104. * @param array $sitemap_generators
  105. */
  106. function hook_simple_sitemap_sitemap_generators_alter(array &$sitemap_generators) {
  107. // Remove the default generator.
  108. unset($sitemap_generators['default']);
  109. }
  110. /**
  111. * Alter properties of and remove sitemap type plugins.
  112. *
  113. * @param array $sitemap_types
  114. */
  115. function hook_simple_sitemap_sitemap_types_alter(array &$sitemap_types) {
  116. }
  117. /**
  118. * @} End of "addtogroup hooks".
  119. */