1. 8.3.x core/modules/aggregator/aggregator.module
  2. 8.0.x core/modules/aggregator/aggregator.module
  3. 8.1.x core/modules/aggregator/aggregator.module
  4. 8.2.x core/modules/aggregator/aggregator.module
  5. 8.4.x core/modules/aggregator/aggregator.module
  6. 4.6.x modules/aggregator.module
  7. 4.7.x modules/aggregator.module
  8. 5.x modules/aggregator/aggregator.module
  9. 6.x modules/aggregator/aggregator.module
  10. 7.x modules/aggregator/aggregator.module

Used to aggregate syndicated content (RSS, RDF, and Atom).

File

core/modules/aggregator/aggregator.module
View source
  1. <?php
  2. /**
  3. * @file
  4. * Used to aggregate syndicated content (RSS, RDF, and Atom).
  5. */
  6. use Drupal\aggregator\Entity\Feed;
  7. use Drupal\Core\Routing\RouteMatchInterface;
  8. /**
  9. * Denotes that a feed's items should never expire.
  10. */
  11. const AGGREGATOR_CLEAR_NEVER = 0;
  12. /**
  13. * Implements hook_help().
  14. */
  15. function aggregator_help($route_name, RouteMatchInterface $route_match) {
  16. switch ($route_name) {
  17. case 'help.page.aggregator':
  18. $path_validator = \Drupal::pathValidator();
  19. $output = '';
  20. $output .= '<h3>' . t('About') . '</h3>';
  21. $output .= '<p>' . t('The Aggregator module is an on-site syndicator and news reader that gathers and displays fresh content from RSS-, RDF-, and Atom-based feeds made available across the web. Thousands of sites (particularly news sites and blogs) publish their latest headlines in feeds, using a number of standardized XML-based formats. For more information, see the <a href=":aggregator-module">online documentation for the Aggregator module</a>.', array(':aggregator-module' => 'https://www.drupal.org/documentation/modules/aggregator')) . '</p>';
  22. $output .= '<h3>' . t('Uses') . '</h3>';
  23. $output .= '<dl>';
  24. // Check if the aggregator sources View is enabled.
  25. if ($url = $path_validator->getUrlIfValid('aggregator/sources')) {
  26. $output .= '<dt>' . t('Viewing feeds') . '</dt>';
  27. $output .= '<dd>' . t('Users view feed content in the <a href=":aggregator">main aggregator display</a>, or by <a href=":aggregator-sources">their source</a> (usually via an RSS feed reader). The most recent content in a feed can be displayed as a block through the <a href=":admin-block">Blocks administration page</a>.', array(':aggregator' => \Drupal::url('aggregator.page_last'), ':aggregator-sources' => $url->toString(), ':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</dd>';
  28. }
  29. $output .= '<dt>' . t('Adding, editing, and deleting feeds') . '</dt>';
  30. $output .= '<dd>' . t('Administrators can add, edit, and delete feeds, and choose how often to check each feed for newly updated items on the <a href=":feededit">Aggregator administration page</a>.', array(':feededit' => \Drupal::url('aggregator.admin_overview'))) . '</dd>';
  31. $output .= '<dt>' . t('Configuring the display of feed items') . '</dt>';
  32. $output .= '<dd>' . t('Administrators can choose how many items are displayed in the listing pages, which HTML tags are allowed in the content of feed items, and whether they should be trimmed to a maximum number of characters on the <a href=":settings">Aggregator settings page</a>.', array(':settings' => \Drupal::url('aggregator.admin_settings'))) . '</dd>';
  33. $output .= '<dt>' . t('Discarding old feed items') . '</dt>';
  34. $output .= '<dd>' . t('Administrators can choose whether to discard feed items that are older than a specified period of time on the <a href=":settings">Aggregator settings page</a>. This requires a correctly configured cron maintenance task (see below).', array(':settings' => \Drupal::url('aggregator.admin_settings'))) . '<dd>';
  35. $output .= '<dt>' . t('<abbr title="Outline Processor Markup Language">OPML</abbr> integration') . '</dt>';
  36. // Check if the aggregator opml View is enabled.
  37. if ($url = $path_validator->getUrlIfValid('aggregator/opml')) {
  38. $output .= '<dd>' . t('A <a href=":aggregator-opml">machine-readable OPML file</a> of all feeds is available. OPML is an XML-based file format used to share outline-structured information such as a list of RSS feeds. Feeds can also be <a href=":import-opml">imported via an OPML file</a>.', array(':aggregator-opml' => $url->toString(), ':import-opml' => \Drupal::url('aggregator.opml_add'))) . '</dd>';
  39. }
  40. $output .= '<dt>' . t('Configuring cron') . '</dt>';
  41. $output .= '<dd>' . t('A working <a href=":cron">cron maintenance task</a> is required to update feeds automatically.', array(':cron' => \Drupal::url('system.cron_settings'))) . '</dd>';
  42. $output .= '</dl>';
  43. return $output;
  44. case 'aggregator.admin_overview':
  45. // Don't use placeholders for possibility to change URLs for translators.
  46. $output = '<p>' . t('Many sites publish their headlines and posts in feeds, using a number of standardized XML-based formats. The aggregator supports <a href="http://en.wikipedia.org/wiki/Rss">RSS</a>, <a href="http://en.wikipedia.org/wiki/Resource_Description_Framework">RDF</a>, and <a href="http://en.wikipedia.org/wiki/Atom_%28standard%29">Atom</a>.') . '</p>';
  47. $output .= '<p>' . t('Current feeds are listed below, and <a href=":addfeed">new feeds may be added</a>. For each feed, the <em>latest items</em> block may be enabled at the <a href=":block">blocks administration page</a>.', array(':addfeed' => \Drupal::url('aggregator.feed_add'), ':block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#')) . '</p>';
  48. return $output;
  49. case 'aggregator.feed_add':
  50. return '<p>' . t('Add a feed in RSS, RDF or Atom format. A feed may only have one entry.') . '</p>';
  51. case 'aggregator.opml_add':
  52. return '<p>' . t('<abbr title="Outline Processor Markup Language">OPML</abbr> is an XML format for exchanging feeds between aggregators. A single OPML document may contain many feeds. Aggregator uses this file to import all feeds at once. Upload a file from your computer or enter a URL where the OPML file can be downloaded.') . '</p>';
  53. }
  54. }
  55. /**
  56. * Implements hook_theme().
  57. */
  58. function aggregator_theme() {
  59. return array(
  60. 'aggregator_feed' => array(
  61. 'render element' => 'elements',
  62. 'file' => 'aggregator.theme.inc',
  63. ),
  64. 'aggregator_item' => array(
  65. 'render element' => 'elements',
  66. 'file' => 'aggregator.theme.inc',
  67. ),
  68. );
  69. }
  70. /**
  71. * Implements hook_entity_extra_field_info().
  72. */
  73. function aggregator_entity_extra_field_info() {
  74. $extra = array();
  75. $extra['aggregator_feed']['aggregator_feed'] = array(
  76. 'display' => array(
  77. 'items' => array(
  78. 'label' => t('Items'),
  79. 'description' => t('Items associated with this feed'),
  80. 'weight' => 0,
  81. ),
  82. // @todo Move to a formatter at https://www.drupal.org/node/2339917.
  83. 'image' => array(
  84. 'label' => t('Image'),
  85. 'description' => t('The feed image'),
  86. 'weight' => 2,
  87. ),
  88. // @todo Move to a formatter at https://www.drupal.org/node/2149845.
  89. 'description' => array(
  90. 'label' => t('Description'),
  91. 'description' => t('The description of this feed'),
  92. 'weight' => 3,
  93. ),
  94. 'more_link' => array(
  95. 'label' => t('More link'),
  96. 'description' => t('A more link to the feed detail page'),
  97. 'weight' => 5,
  98. ),
  99. 'feed_icon' => array(
  100. 'label' => t('Feed icon'),
  101. 'description' => t('An icon that links to the feed URL'),
  102. 'weight' => 6,
  103. ),
  104. ),
  105. );
  106. $extra['aggregator_item']['aggregator_item'] = array(
  107. 'display' => array(
  108. // @todo Move to a formatter at https://www.drupal.org/node/2149845.
  109. 'description' => array(
  110. 'label' => t('Description'),
  111. 'description' => t('The description of this feed item'),
  112. 'weight' => 2,
  113. ),
  114. ),
  115. );
  116. return $extra;
  117. }
  118. /**
  119. * Implements hook_cron().
  120. *
  121. * Queues news feeds for updates once their refresh interval has elapsed.
  122. */
  123. function aggregator_cron() {
  124. $queue = \Drupal::queue('aggregator_feeds');
  125. $ids = \Drupal::entityManager()->getStorage('aggregator_feed')->getFeedIdsToRefresh();
  126. foreach (Feed::loadMultiple($ids) as $feed) {
  127. if ($queue->createItem($feed)) {
  128. // Add timestamp to avoid queueing item more than once.
  129. $feed->setQueuedTime(REQUEST_TIME);
  130. $feed->save();
  131. }
  132. }
  133. // Delete queued timestamp after 6 hours assuming the update has failed.
  134. $ids = \Drupal::entityQuery('aggregator_feed')
  135. ->condition('queued', REQUEST_TIME - (3600 * 6), '<')
  136. ->execute();
  137. if ($ids) {
  138. $feeds = Feed::loadMultiple($ids);
  139. foreach ($feeds as $feed) {
  140. $feed->setQueuedTime(0);
  141. $feed->save();
  142. }
  143. }
  144. }
  145. /**
  146. * Gets the list of allowed tags.
  147. *
  148. * @return array
  149. * The list of allowed tags.
  150. *
  151. * @internal
  152. */
  153. function _aggregator_allowed_tags() {
  154. return preg_split('/\s+|<|>/', \Drupal::config('aggregator.settings')->get('items.allowed_html'), -1, PREG_SPLIT_NO_EMPTY);
  155. }
  156. /**
  157. * Implements hook_preprocess_HOOK() for block templates.
  158. */
  159. function aggregator_preprocess_block(&$variables) {
  160. if ($variables['configuration']['provider'] == 'aggregator') {
  161. $variables['attributes']['role'] = 'complementary';
  162. }
  163. }

Functions

Namesort descending Description
aggregator_cron Implements hook_cron().
aggregator_entity_extra_field_info Implements hook_entity_extra_field_info().
aggregator_help Implements hook_help().
aggregator_preprocess_block Implements hook_preprocess_HOOK() for block templates.
aggregator_theme Implements hook_theme().
_aggregator_allowed_tags Gets the list of allowed tags.

Constants

Namesort descending Description
AGGREGATOR_CLEAR_NEVER Denotes that a feed's items should never expire.