diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 06e3cb2..5315722 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -141,6 +141,10 @@ function aggregator_menu() { 'title' => 'Categories', 'route_name' => 'aggregator.categories', ); + $items['aggregator/opml'] = array( + 'title' => 'OPML feed', + 'route_name' => 'aggregator_opml', + ); $items['aggregator/categories/%aggregator_category'] = array( 'title callback' => '_aggregator_category_title', 'title arguments' => array(2), diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index cd938e7..5032123 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -6,8 +6,87 @@ */ use Drupal\aggregator\Entity\Feed; +use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Entity\EntityInterface; + +/** + * Page callback: Displays all the items captured from the particular feed. + * + * @param \Drupal\aggregator\Entity\Feed $feed + * The feed for which to display all items. + * + * @return string + * The rendered list of items for the feed. + * + * @see aggregator_menu() + */ +function aggregator_page_source(Feed $feed) { + $feed_source = entity_view($feed, 'default'); + + // It is safe to include the fid in the query because it's loaded from the + // database by aggregator_feed_load(). + $items = aggregator_load_feed_items('source', $feed); + + return _aggregator_page_list($items, arg(3), $feed_source); +} + +/** + * Form constructor to show all items captured from a feed. + * + * @param $feed + * The feed for which to list all of the aggregated items. + * + * @return string + * The rendered list of items for the feed. + * + * @see aggregator_menu() + * @see aggregator_page_source() + * @ingroup forms + */ +function aggregator_page_source_form($form, $form_state, $feed) { + return aggregator_page_source($feed); +} + +/** + * Form constructor to list items aggregated in a category. + * + * @param $category + * The category for which to list all of the aggregated items. + * + * @return string + * The rendered list of items for the feed. + * + * @see aggregator_menu() + * @ingroup forms + */ +function aggregator_page_category($category) { + drupal_add_feed('aggregator/rss/' . $category->cid, Drupal::config('system.site')->get('name') . ' ' . t('aggregator - @title', array('@title' => $category->title))); + + // It is safe to include the cid in the query because it's loaded from the + // database by aggregator_category_load(). + $items = aggregator_load_feed_items('category', $category); + + return _aggregator_page_list($items, arg(3)); +} + +/** + * Form constructor to list items aggregated in a category. + * + * @param $category + * The category for which to list all of the aggregated items. + * + * @return string + * The rendered list of items for the feed. + * + * @see aggregator_menu() + * @see aggregator_page_category() + * @ingroup forms + */ +function aggregator_page_category_form($form, $form_state, $category) { + return aggregator_page_category($category); +} + /** * Loads and optionally filters feed items. * @@ -104,36 +183,6 @@ function template_preprocess_aggregator_item(&$variables) { } /** - * Page callback: Generates an OPML representation of all feeds. - * - * @param $cid - * (optional) If set, feeds are exported only from a category with this ID. - * Otherwise, all feeds are exported. Defaults to NULL. - * - * @return string - * An OPML formatted string. - * - * @see aggregator_menu() - * - * @deprecated Use \Drupal\aggregator\Controller\AggregatorController::opmlPage() - */ -function aggregator_page_opml($cid = NULL) { - if ($cid) { - $result = db_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title', array(':cid' => $cid)); - } - else { - $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); - } - - $feeds = $result->fetchAll(); - $aggregator_page_opml = array( - '#theme' => 'aggregator_page_opml', - '#feeds' => $feeds, - ); - return drupal_render($aggregator_page_opml); -} - -/** * Prints the OPML page for the feed. * * @param array $variables @@ -144,9 +193,8 @@ function aggregator_page_opml($cid = NULL) { */ function theme_aggregator_page_opml($variables) { $feeds = $variables['feeds']; - - drupal_add_http_header('Content-Type', 'text/xml; charset=utf-8'); - + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml; charset=utf-8'); $output = "\n"; $output .= "\n"; $output .= "\n"; diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index e05c4d9..fc7d64c 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -147,3 +147,10 @@ aggregator.opml_page: cid: null requirements: _permission: 'access news feeds' + +aggregator_opml: + pattern: 'aggregator/opml' + defaults: + _controller: '\Drupal\aggregator\Controller\AggregatorController::opml' + requirements: + _permission: 'administer news feeds' diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index bfbf5b0..6327773 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -23,6 +23,20 @@ class AggregatorController extends ControllerBase implements ContainerInjectionInterface { /** + * Stores the Entity manager. + * + * @var \Drupal\Core\Entity\EntityManager + */ + protected $entityManager; + + /** + * The configuration factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** * The database connection. * * @var \Drupal\Core\Database\Connection; @@ -353,4 +367,32 @@ public function opmlPage($cid = NULL) { return aggregator_page_opml($cid); } +/** + * Generates an OPML representation of all feeds. + * + * @param \Drupal\aggregator\FeedInterface $aggregator_feed + * (optional) If set, feeds are exported only from a category with this ID. + * Otherwise, all feeds are exported. Defaults to NULL. + * + * @return array + * A render array as expected by drupal_render(). + */ + public function opml(FeedInterface $aggregator_feed = NULL) { + if ($aggregator_feed) { + $result = $this->database->query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = :cid ORDER BY title', + array( + ':cid' => $aggregator_feed, + ) + ); + } + else { + $result = $this->database->query(db_query('SELECT * FROM {aggregator_feed} ORDER BY title')); + } + $feeds = $result->fetchAllAssoc('title'); + $aggregator_page_opml = array( + '#theme' => 'aggregator_page_opml', + '#feeds' => $feeds, + ); + return $aggregator_page_opml; + } }