simple_sitemap.api.php 3.5 KB
Newer Older
1
<?php
gbyte.co's avatar
gbyte.co committed
2

3 4
/**
 * @file
5
 * Hooks provided by the Simple XML Sitemap module.
6 7 8 9 10 11 12 13 14 15 16 17
 */

/**
 * @addtogroup hooks
 * @{
 */

/**
 * Alter the generated link data before the sitemap is saved.
 * This hook gets invoked for every sitemap chunk generated.
 *
 * @param array &$links
18 19
 *   Array containing multilingual links generated for each path to be indexed
 *
gbyte.co's avatar
gbyte.co committed
20
 * @param string $sitemap_variant
21
 */
22
function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
23 24

  // Remove German URL for a certain path in the hreflang sitemap.
25
  foreach ($links as $key => $link) {
26
    if ($link['meta']['path'] === 'node/1') {
gbyte.co's avatar
gbyte.co committed
27

28
      // Remove 'loc' URL if it points to a german site.
29
      if ($link['langcode'] === 'de') {
30
        unset($links[$key]);
31
      }
gbyte.co's avatar
gbyte.co committed
32

33 34 35
      // If this 'loc' URL points to a non-german site, make sure to remove
      // its german alternate URL.
      else {
36 37 38
        if ($link['alternate_urls']['de']) {
          unset($links[$key]['alternate_urls']['de']);
        }
39 40
      }
    }
41 42 43
  }
}

44
/**
gbyte.co's avatar
gbyte.co committed
45
 * Add arbitrary links to the sitemap.
46 47
 *
 * @param array &$arbitrary_links
gbyte.co's avatar
gbyte.co committed
48
 * @param string $sitemap_variant
49
 */
50
function hook_simple_sitemap_arbitrary_links_alter(array &$arbitrary_links, $sitemap_variant) {
51

52
  // Add an arbitrary link to all sitemap variants.
53
  $arbitrary_links[] = [
54
    'url' => 'http://some-arbitrary-link/',
55
    'priority' => '0.5',
gbyte.co's avatar
gbyte.co committed
56 57

    // An ISO8601 formatted date.
58
    'lastmod' => '2012-10-12T17:40:30+02:00',
gbyte.co's avatar
gbyte.co committed
59

60
    'changefreq' => 'weekly',
gbyte.co's avatar
gbyte.co committed
61
    'images' => [
gbyte.co's avatar
gbyte.co committed
62
      ['path' => 'http://path-to-image.png']
gbyte.co's avatar
gbyte.co committed
63 64 65 66 67 68 69
    ],

    // Add alternate URLs for every language of a multilingual site.
    // Not necessary for monolingual sites.
    'alternate_urls' => [
      'en' => 'http://this-is-your-life.net/de/tyler',
      'de' => 'http://this-is-your-life.net/en/tyler',
gbyte.co's avatar
gbyte.co committed
70
    ]
71
  ];
72 73 74 75 76 77 78 79 80

  // Add an arbitrary link to the 'fight_club' sitemap variant only.
  switch ($sitemap_variant) {
    case 'fight_club':
      $arbitrary_links[] = [
        'url' => 'http://this-is-your-life.net/tyler',
      ];
      break;
  }
81 82 83 84 85 86 87
}

/**
 * Alters the sitemap attributes shortly before XML document generation.
 * Attributes can be added, changed and removed.
 *
 * @param array &$attributes
gbyte.co's avatar
gbyte.co committed
88
 * @param string $sitemap_variant
89
 */
90
function hook_simple_sitemap_attributes_alter(array &$attributes, $sitemap_variant) {
91 92 93 94 95 96

  // Remove the xhtml attribute e.g. if no xhtml sitemap elements are present.
  unset($attributes['xmlns:xhtml']);
}

/**
gbyte.co's avatar
gbyte.co committed
97
 * Alters attributes of the sitemap index shortly before XML document generation.
98 99 100
 * Attributes can be added, changed and removed.
 *
 * @param array &$index_attributes
gbyte.co's avatar
gbyte.co committed
101
 * @param string $sitemap_variant
102
 */
103
function hook_simple_sitemap_index_attributes_alter(array &$index_attributes, $sitemap_variant) {
104 105 106 107 108

  // Add some attribute to the sitemap index.
  $index_attributes['name'] = 'value';
}

gbyte.co's avatar
gbyte.co committed
109
/**
gbyte.co's avatar
gbyte.co committed
110
 * Alter properties of and remove URL generator plugins.
gbyte.co's avatar
gbyte.co committed
111
 *
112
 * @param array $url_generators
gbyte.co's avatar
gbyte.co committed
113
 */
114
function hook_simple_sitemap_url_generators_alter(array &$url_generators) {
gbyte.co's avatar
gbyte.co committed
115

gbyte.co's avatar
gbyte.co committed
116
  // Remove the entity generator.
117 118 119 120
  unset($url_generators['entity']);
}

/**
gbyte.co's avatar
gbyte.co committed
121
 * Alter properties of and remove sitemap generator plugins.
122 123 124 125 126 127 128 129 130 131
 *
 * @param array $sitemap_generators
 */
function hook_simple_sitemap_sitemap_generators_alter(array &$sitemap_generators) {

  // Remove the default generator.
  unset($sitemap_generators['default']);
}

/**
132 133
 * Alter properties of and remove sitemap type plugins.
 *
134 135
 * @param array $sitemap_types
 */
136 137
function hook_simple_sitemap_sitemap_types_alter(array &$sitemap_types) {

138 139
}

140 141 142
/**
 * @} End of "addtogroup hooks".
 */