5 * Used to aggregate syndicated content (RSS, RDF, and Atom).
8 use Drupal\aggregator\Entity\Feed;
9 use Drupal\Core\Routing\RouteMatchInterface;
12 * Denotes that a feed's items should never expire.
14 * @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
15 * Use \Drupal\aggregator\FeedStorageInterface::CLEAR_NEVER instead.
17 * @see https://www.drupal.org/node/2831620
19 const AGGREGATOR_CLEAR_NEVER = 0;
22 * Implements hook_help().
24 function aggregator_help($route_name, RouteMatchInterface $route_match) {
25 switch ($route_name) {
26 case 'help.page.aggregator':
27 $path_validator = \Drupal::pathValidator();
29 $output .= '<h3>' . t('About') . '</h3>';
30 $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>.', [':aggregator-module' => 'https://www.drupal.org/documentation/modules/aggregator']) . '</p>';
31 $output .= '<h3>' . t('Uses') . '</h3>';
33 // Check if the aggregator sources View is enabled.
34 if ($url = $path_validator->getUrlIfValid('aggregator/sources')) {
35 $output .= '<dt>' . t('Viewing feeds') . '</dt>';
36 $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>.', [':aggregator' => \Drupal::url('aggregator.page_last'), ':aggregator-sources' => $url->toString(), ':admin-block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</dd>';
38 $output .= '<dt>' . t('Adding, editing, and deleting feeds') . '</dt>';
39 $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>.', [':feededit' => \Drupal::url('aggregator.admin_overview')]) . '</dd>';
40 $output .= '<dt>' . t('Configuring the display of feed items') . '</dt>';
41 $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>.', [':settings' => \Drupal::url('aggregator.admin_settings')]) . '</dd>';
42 $output .= '<dt>' . t('Discarding old feed items') . '</dt>';
43 $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).', [':settings' => \Drupal::url('aggregator.admin_settings')]) . '<dd>';
45 $output .= '<dt>' . t('<abbr title="Outline Processor Markup Language">OPML</abbr> integration') . '</dt>';
46 // Check if the aggregator opml View is enabled.
47 if ($url = $path_validator->getUrlIfValid('aggregator/opml')) {
48 $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>.', [':aggregator-opml' => $url->toString(), ':import-opml' => \Drupal::url('aggregator.opml_add')]) . '</dd>';
50 $output .= '<dt>' . t('Configuring cron') . '</dt>';
51 $output .= '<dd>' . t('A working <a href=":cron">cron maintenance task</a> is required to update feeds automatically.', [':cron' => \Drupal::url('system.cron_settings')]) . '</dd>';
55 case 'aggregator.admin_overview':
56 // Don't use placeholders for possibility to change URLs for translators.
57 $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>';
58 $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>.', [':addfeed' => \Drupal::url('aggregator.feed_add'), ':block' => (\Drupal::moduleHandler()->moduleExists('block')) ? \Drupal::url('block.admin_display') : '#']) . '</p>';
61 case 'aggregator.feed_add':
62 return '<p>' . t('Add a feed in RSS, RDF or Atom format. A feed may only have one entry.') . '</p>';
64 case 'aggregator.opml_add':
65 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>';
70 * Implements hook_theme().
72 function aggregator_theme() {
74 'aggregator_feed' => [
75 'render element' => 'elements',
76 'file' => 'aggregator.theme.inc',
78 'aggregator_item' => [
79 'render element' => 'elements',
80 'file' => 'aggregator.theme.inc',
86 * Implements hook_entity_extra_field_info().
88 function aggregator_entity_extra_field_info() {
91 $extra['aggregator_feed']['aggregator_feed'] = [
94 'label' => t('Items'),
95 'description' => t('Items associated with this feed'),
98 // @todo Move to a formatter at https://www.drupal.org/node/2339917.
100 'label' => t('Image'),
101 'description' => t('The feed image'),
104 // @todo Move to a formatter at https://www.drupal.org/node/2149845.
106 'label' => t('Description'),
107 'description' => t('The description of this feed'),
111 'label' => t('More link'),
112 'description' => t('A more link to the feed detail page'),
116 'label' => t('Feed icon'),
117 'description' => t('An icon that links to the feed URL'),
123 $extra['aggregator_item']['aggregator_item'] = [
125 // @todo Move to a formatter at https://www.drupal.org/node/2149845.
127 'label' => t('Description'),
128 'description' => t('The description of this feed item'),
138 * Implements hook_cron().
140 * Queues news feeds for updates once their refresh interval has elapsed.
142 function aggregator_cron() {
143 $queue = \Drupal::queue('aggregator_feeds');
145 $ids = \Drupal::entityManager()->getStorage('aggregator_feed')->getFeedIdsToRefresh();
146 foreach (Feed::loadMultiple($ids) as $feed) {
147 if ($queue->createItem($feed)) {
148 // Add timestamp to avoid queueing item more than once.
149 $feed->setQueuedTime(REQUEST_TIME);
154 // Delete queued timestamp after 6 hours assuming the update has failed.
155 $ids = \Drupal::entityQuery('aggregator_feed')
156 ->condition('queued', REQUEST_TIME - (3600 * 6), '<')
160 $feeds = Feed::loadMultiple($ids);
161 foreach ($feeds as $feed) {
162 $feed->setQueuedTime(0);
169 * Gets the list of allowed tags.
172 * The list of allowed tags.
176 function _aggregator_allowed_tags() {
177 return preg_split('/\s+|<|>/', \Drupal::config('aggregator.settings')->get('items.allowed_html'), -1, PREG_SPLIT_NO_EMPTY);
181 * Implements hook_preprocess_HOOK() for block templates.
183 function aggregator_preprocess_block(&$variables) {
184 if ($variables['configuration']['provider'] == 'aggregator') {
185 $variables['attributes']['role'] = 'complementary';