aggregator.api.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <?php
  2. /**
  3. * @file
  4. * Documentation for aggregator API.
  5. */
  6. /**
  7. * @addtogroup hooks
  8. * @{
  9. */
  10. /**
  11. * Create an alternative fetcher for aggregator.module.
  12. *
  13. * A fetcher downloads feed data to a Drupal site. The fetcher is called at the
  14. * first of the three aggregation stages: first, data is downloaded by the
  15. * active fetcher; second, it is converted to a common format by the active
  16. * parser; and finally, it is passed to all active processors, which manipulate
  17. * or store the data.
  18. *
  19. * Modules that define this hook can be set as active fetcher on
  20. * admin/config/services/aggregator. Only one fetcher can be active at a time.
  21. *
  22. * @param $feed
  23. * A feed object representing the resource to be downloaded. $feed->url
  24. * contains the link to the feed. Download the data at the URL and expose it
  25. * to other modules by attaching it to $feed->source_string.
  26. *
  27. * @return
  28. * TRUE if fetching was successful, FALSE otherwise.
  29. *
  30. * @see hook_aggregator_fetch_info()
  31. * @see hook_aggregator_parse()
  32. * @see hook_aggregator_process()
  33. *
  34. * @ingroup aggregator
  35. */
  36. function hook_aggregator_fetch($feed) {
  37. $feed->source_string = mymodule_fetch($feed->url);
  38. }
  39. /**
  40. * Specify the title and short description of your fetcher.
  41. *
  42. * The title and the description provided are shown on
  43. * admin/config/services/aggregator among other places. Use as title the human
  44. * readable name of the fetcher and as description a brief (40 to 80 characters)
  45. * explanation of the fetcher's functionality.
  46. *
  47. * This hook is only called if your module implements hook_aggregator_fetch().
  48. * If this hook is not implemented aggregator will use your module's file name
  49. * as title and there will be no description.
  50. *
  51. * @return
  52. * An associative array defining a title and a description string.
  53. *
  54. * @see hook_aggregator_fetch()
  55. *
  56. * @ingroup aggregator
  57. */
  58. function hook_aggregator_fetch_info() {
  59. return array(
  60. 'title' => t('Default fetcher'),
  61. 'description' => t('Default fetcher for resources available by URL.'),
  62. );
  63. }
  64. /**
  65. * Create an alternative parser for aggregator module.
  66. *
  67. * A parser converts feed item data to a common format. The parser is called
  68. * at the second of the three aggregation stages: first, data is downloaded
  69. * by the active fetcher; second, it is converted to a common format by the
  70. * active parser; and finally, it is passed to all active processors which
  71. * manipulate or store the data.
  72. *
  73. * Modules that define this hook can be set as the active parser on
  74. * admin/config/services/aggregator. Only one parser can be active at a time.
  75. *
  76. * @param $feed
  77. * An object describing the resource to be parsed. $feed->source_string
  78. * contains the raw feed data. The hook implementation should parse this data
  79. * and add the following properties to the $feed object:
  80. * - description: The human-readable description of the feed.
  81. * - link: A full URL that directly relates to the feed.
  82. * - image: An image URL used to display an image of the feed.
  83. * - etag: An entity tag from the HTTP header used for cache validation to
  84. * determine if the content has been changed.
  85. * - modified: The UNIX timestamp when the feed was last modified.
  86. * - items: An array of feed items. The common format for a single feed item
  87. * is an associative array containing:
  88. * - title: The human-readable title of the feed item.
  89. * - description: The full body text of the item or a summary.
  90. * - timestamp: The UNIX timestamp when the feed item was last published.
  91. * - author: The author of the feed item.
  92. * - guid: The global unique identifier (GUID) string that uniquely
  93. * identifies the item. If not available, the link is used to identify
  94. * the item.
  95. * - link: A full URL to the individual feed item.
  96. *
  97. * @return
  98. * TRUE if parsing was successful, FALSE otherwise.
  99. *
  100. * @see hook_aggregator_parse_info()
  101. * @see hook_aggregator_fetch()
  102. * @see hook_aggregator_process()
  103. *
  104. * @ingroup aggregator
  105. */
  106. function hook_aggregator_parse($feed) {
  107. if ($items = mymodule_parse($feed->source_string)) {
  108. $feed->items = $items;
  109. return TRUE;
  110. }
  111. return FALSE;
  112. }
  113. /**
  114. * Specify the title and short description of your parser.
  115. *
  116. * The title and the description provided are shown on
  117. * admin/config/services/aggregator among other places. Use as title the human
  118. * readable name of the parser and as description a brief (40 to 80 characters)
  119. * explanation of the parser's functionality.
  120. *
  121. * This hook is only called if your module implements hook_aggregator_parse().
  122. * If this hook is not implemented aggregator will use your module's file name
  123. * as title and there will be no description.
  124. *
  125. * @return
  126. * An associative array defining a title and a description string.
  127. *
  128. * @see hook_aggregator_parse()
  129. *
  130. * @ingroup aggregator
  131. */
  132. function hook_aggregator_parse_info() {
  133. return array(
  134. 'title' => t('Default parser'),
  135. 'description' => t('Default parser for RSS, Atom and RDF feeds.'),
  136. );
  137. }
  138. /**
  139. * Create a processor for aggregator.module.
  140. *
  141. * A processor acts on parsed feed data. Active processors are called at the
  142. * third and last of the aggregation stages: first, data is downloaded by the
  143. * active fetcher; second, it is converted to a common format by the active
  144. * parser; and finally, it is passed to all active processors that manipulate or
  145. * store the data.
  146. *
  147. * Modules that define this hook can be activated as processor on
  148. * admin/config/services/aggregator.
  149. *
  150. * @param $feed
  151. * A feed object representing the resource to be processed. $feed->items
  152. * contains an array of feed items downloaded and parsed at the parsing stage.
  153. * See hook_aggregator_parse() for the basic format of a single item in the
  154. * $feed->items array. For the exact format refer to the particular parser in
  155. * use.
  156. *
  157. * @see hook_aggregator_process_info()
  158. * @see hook_aggregator_fetch()
  159. * @see hook_aggregator_parse()
  160. *
  161. * @ingroup aggregator
  162. */
  163. function hook_aggregator_process($feed) {
  164. foreach ($feed->items as $item) {
  165. mymodule_save($item);
  166. }
  167. }
  168. /**
  169. * Specify the title and short description of your processor.
  170. *
  171. * The title and the description provided are shown most importantly on
  172. * admin/config/services/aggregator. Use as title the natural name of the
  173. * processor and as description a brief (40 to 80 characters) explanation of the
  174. * functionality.
  175. *
  176. * This hook is only called if your module implements hook_aggregator_process().
  177. * If this hook is not implemented aggregator will use your module's file name
  178. * as title and there will be no description.
  179. *
  180. * @return
  181. * An associative array defining a title and a description string.
  182. *
  183. * @see hook_aggregator_process()
  184. *
  185. * @ingroup aggregator
  186. */
  187. function hook_aggregator_process_info($feed) {
  188. return array(
  189. 'title' => t('Default processor'),
  190. 'description' => t('Creates lightweight records of feed items.'),
  191. );
  192. }
  193. /**
  194. * Remove stored feed data.
  195. *
  196. * Aggregator calls this hook if either a feed is deleted or a user clicks on
  197. * "remove items".
  198. *
  199. * If your module stores feed items for example on hook_aggregator_process() it
  200. * is recommended to implement this hook and to remove data related to $feed
  201. * when called.
  202. *
  203. * @param $feed
  204. * The $feed object whose items are being removed.
  205. *
  206. * @ingroup aggregator
  207. */
  208. function hook_aggregator_remove($feed) {
  209. mymodule_remove_items($feed->fid);
  210. }
  211. /**
  212. * @} End of "addtogroup hooks".
  213. */