xmlsitemap.api.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * @file
  4. * Hooks provided by the XML sitemap module.
  5. *
  6. * @ingroup xmlsitemap
  7. */
  8. /**
  9. * @addtogroup hooks
  10. * @{
  11. */
  12. /**
  13. * Provide information on the type of links this module provides.
  14. *
  15. * @see hook_entity_info()
  16. * @see hook_entity_info_alter()
  17. */
  18. function hook_xmlsitemap_link_info() {
  19. return array(
  20. 'mymodule' => array(
  21. 'label' => 'My module',
  22. 'base table' => 'mymodule',
  23. 'entity keys' => array(
  24. // Primary ID key on {base table}
  25. 'id' => 'myid',
  26. // Subtype key on {base table}
  27. 'bundle' => 'mysubtype',
  28. ),
  29. 'path callback' => 'mymodule_path',
  30. 'bundle label' => t('Subtype name'),
  31. 'bundles' => array(
  32. 'mysubtype1' => array(
  33. 'label' => t('My subtype 1'),
  34. 'admin' => array(
  35. 'real path' => 'admin/settings/mymodule/mysubtype1/edit',
  36. 'access arguments' => array('administer mymodule'),
  37. ),
  38. 'xmlsitemap' => array(
  39. 'status' => XMLSITEMAP_STATUS_DEFAULT,
  40. 'priority' => XMLSITEMAP_PRIORITY_DEFAULT,
  41. ),
  42. ),
  43. ),
  44. 'xmlsitemap' => array(
  45. // Callback function to take an array of IDs and save them as sitemap
  46. // links.
  47. 'process callback' => '',
  48. // Callback function used in batch API for rebuilding all links.
  49. 'rebuild callback' => '',
  50. // Callback function called from the XML sitemap settings page.
  51. 'settings callback' => '',
  52. )
  53. ),
  54. );
  55. }
  56. /**
  57. * Alter the data of a sitemap link before the link is saved.
  58. *
  59. * @param $link
  60. * An array with the data of the sitemap link.
  61. */
  62. function hook_xmlsitemap_link_alter(&$link) {
  63. if ($link['type'] == 'mymodule') {
  64. $link['priority'] += 0.5;
  65. }
  66. }
  67. /**
  68. * Inform modules that an XML sitemap link has been created.
  69. *
  70. * @param $link
  71. * Associative array defining an XML sitemap link as passed into
  72. * xmlsitemap_link_save().
  73. *
  74. * @see hook_xmlsitemap_link_update()
  75. */
  76. function hook_xmlsitemap_link_insert(array $link) {
  77. db_insert('mytable')
  78. ->fields(array(
  79. 'link_type' => $link['type'],
  80. 'link_id' => $link['id'],
  81. 'link_status' => $link['status'],
  82. ))
  83. ->execute();
  84. }
  85. /**
  86. * Inform modules that an XML sitemap link has been updated.
  87. *
  88. * @param $link
  89. * Associative array defining an XML sitemap link as passed into
  90. * xmlsitemap_link_save().
  91. *
  92. * @see hook_xmlsitemap_link_insert()
  93. */
  94. function hook_xmlsitemap_link_update(array $link) {
  95. db_update('mytable')
  96. ->fields(array(
  97. 'link_type' => $link['type'],
  98. 'link_id' => $link['id'],
  99. 'link_status' => $link['status'],
  100. ))
  101. ->execute();
  102. }
  103. /**
  104. * Index links for the XML sitemaps.
  105. */
  106. function hook_xmlsitemap_index_links($limit) {
  107. }
  108. /**
  109. * Provide information about contexts available to XML sitemap.
  110. *
  111. * @see hook_xmlsitemap_context_info_alter().
  112. */
  113. function hook_xmlsitemap_context_info() {
  114. $info['vocabulary'] = array(
  115. 'label' => t('Vocabulary'),
  116. 'summary callback' => 'mymodule_xmlsitemap_vocabulary_context_summary',
  117. 'default' => 0,
  118. );
  119. return $info;
  120. }
  121. /**
  122. * Alter XML sitemap context info.
  123. *
  124. * @see hook_xmlsitemap_context_info().
  125. */
  126. function hook_xmlsitemap_context_info_alter(&$info) {
  127. $info['vocabulary']['label'] = t('Site vocabularies');
  128. }
  129. /**
  130. * Provide information about the current context on the site.
  131. *
  132. * @see hook_xmlsitemap_context_alter()
  133. */
  134. function hook_xmlsitemap_context() {
  135. $context = array();
  136. if ($vid = mymodule_get_current_vocabulary()) {
  137. $context['vocabulary'] = $vid;
  138. }
  139. return $context;
  140. }
  141. /**
  142. * Alter the current context information.
  143. *
  144. * @see hook_xmlsitemap_context()
  145. */
  146. function hook_xmlsitemap_context_alter(&$context) {
  147. if (user_access('administer taxonomy')) {
  148. unset($context['vocabulary']);
  149. }
  150. }
  151. /**
  152. * Provide options for the url() function based on an XML sitemap context.
  153. */
  154. function hook_xmlsitemap_context_url_options(array $context) {
  155. }
  156. /**
  157. * Alter the url() options based on an XML sitemap context.
  158. */
  159. function hook_xmlsitemap_context_url_options_alter(array &$options, array $context) {
  160. }
  161. /**
  162. * Alter the query selecting data from {xmlsitemap} during sitemap generation.
  163. *
  164. * @param $query
  165. * A Query object describing the composite parts of a SQL query.
  166. *
  167. * @see hook_query_TAG_alter()
  168. */
  169. function hook_query_xmlsitemap_generate_alter(QueryAlterableInterface $query) {
  170. $sitemap = $query->getMetaData('sitemap');
  171. if (!empty($sitemap->context['vocabulary'])) {
  172. $node_condition = db_and();
  173. $node_condition->condition('type', 'taxonomy_term');
  174. $node_condition->condition('subtype', $sitemap->context['vocabulary']);
  175. $normal_condition = db_and();
  176. $normal_condition->condition('type', 'taxonomy_term', '<>');
  177. $condition = db_or();
  178. $condition->condition($node_condition);
  179. $condition->condition($normal_condition);
  180. $query->condition($condition);
  181. }
  182. }
  183. /**
  184. * Provide information about XML sitemap bulk operations.
  185. */
  186. function hook_xmlsitemap_sitemap_operations() {
  187. }
  188. /**
  189. * Respond to XML sitemap deletion.
  190. *
  191. * This hook is invoked from xmlsitemap_sitemap_delete_multiple() after the XML
  192. * sitemap has been removed from the table in the database.
  193. *
  194. * @param $sitemap
  195. * The XML sitemap object that was deleted.
  196. */
  197. function hook_xmlsitemap_sitemap_delete(stdClass $sitemap) {
  198. db_query("DELETE FROM {mytable} WHERE smid = '%s'", $sitemap->smid);
  199. }
  200. /**
  201. * @} End of "addtogroup hooks".
  202. */