xmlsitemap.api.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. // $Id: xmlsitemap.api.php,v 1.4 2009/12/23 22:29:16 davereid Exp $
  3. /**
  4. * @file
  5. * Hooks provided by the XML sitemap module.
  6. *
  7. * @ingroup xmlsitemap
  8. */
  9. /**
  10. * @addtogroup hooks
  11. * @{
  12. */
  13. /**
  14. * Provide information on the type of links this module provides.
  15. */
  16. function hook_xmlsitemap_link_info() {
  17. return array(
  18. 'mymodule' => array(
  19. 'purge' => TRUE, // A boolean if this link type can be purged during a rebuild.
  20. ),
  21. );
  22. }
  23. /**
  24. * Retrieve a array of links to include in the sitemap.
  25. *
  26. * @return
  27. * An array of link arrays with the following keys and values:
  28. * - 'type' => The type of link (node, user, kitten, etc.).
  29. * - 'id' => The ID of the link ($node->nid, $user->uid, etc.).
  30. * - 'loc' => The un-aliased Drupal path to the item.
  31. * - 'lastmod' => The UNIX timestmap of when the item was last modified.
  32. * - 'changefreq' => The interval, in seconds, between the last set of changes.
  33. * - 'priority' => An optional priority value between 0.0 and 1.0.
  34. */
  35. function hook_xmlsitemap_links() {
  36. $links = array();
  37. $links[] = array(
  38. 'type' => 'mymodule',
  39. 'id' => 1,
  40. 'loc' => 'mymodule/menu/path',
  41. 'lastmod' => 346245692,
  42. 'changefreq' => 4600,
  43. );
  44. return $links;
  45. }
  46. /**
  47. * Provide batch information for hook_xmlsitemap_links().
  48. *
  49. * It is highly recommended that if your module has a lot of items that could
  50. * be sitemap links, that you implement this hook.
  51. *
  52. * All you need to do to implement this hook is add the required $context
  53. * information.
  54. *
  55. * The optional current value will provide the offset parameter to
  56. * hook_xmlsitemap_links() and should get records that are greater than this
  57. * value. The default value is 0.
  58. *
  59. * The max (count) value will allow the batch to know when it is finished. This
  60. * value is required.
  61. */
  62. function hook_xmlsitemap_links_batch_info() {
  63. return array(
  64. 'current' => 0,
  65. // This value is used to start selecting items (WHERE id > current).
  66. 'max' => db_query("SELECT COUNT(id) FROM {mymodule}")->fetchField(),
  67. // This should be the total number of items to process.
  68. );
  69. }
  70. /**
  71. * Alter the data of a sitemap link before the link is saved.
  72. *
  73. * @param $link
  74. * An array with the data of the sitemap link.
  75. */
  76. function hook_xmlsitemap_link_alter(&$link) {
  77. if ($link['type'] == 'mymodule') {
  78. $link['priority'] += 0.5;
  79. }
  80. }
  81. /**
  82. * @} End of "addtogroup hooks".
  83. */