diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index e364aee..137d987 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -90,49 +90,20 @@ 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 * An associative array containing: * - feeds: An array of the feeds to theme. * + * @return string + * An OPML formatted string. + * * @ingroup themeable */ function theme_aggregator_page_opml($variables) { $feeds = $variables['feeds']; - drupal_add_http_header('Content-Type', 'text/xml; charset=utf-8'); - $output = "\n"; $output .= "\n"; $output .= "\n"; @@ -146,7 +117,7 @@ function theme_aggregator_page_opml($variables) { $output .= "\n"; $output .= "\n"; - print $output; + return $output; } /** diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index 4d5dd9a..d03ae84 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -15,6 +15,7 @@ use Drupal\Core\Database\Connection; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; /** @@ -346,11 +347,35 @@ public function sources() { } /** - * @todo Remove aggregator_opml(). + * Generates an OPML representation of all feeds or feeds by category. + * + * @param int $cid + * (optional) If set, feeds are exported only from a category with this ID. + * Otherwise, all feeds are exported. Defaults to NULL. + * + * @return \Symfony\Component\HttpFoundation\Response + * The response containing the OPML. */ public function opmlPage($cid = NULL) { - module_load_include('pages.inc', 'aggregator'); - return aggregator_page_opml($cid); + if ($cid) { + $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' => $cid)); + } + else { + $result = $this->database->query('SELECT * FROM {aggregator_feed} ORDER BY title'); + } + + $feeds = $result->fetchAll(); + $aggregator_page_opml = array( + '#theme' => 'aggregator_page_opml', + '#feeds' => $feeds, + ); + $output = drupal_render($aggregator_page_opml); + + $response = new Response(); + $response->headers->set('Content-Type', 'text/xml; charset=utf-8'); + $response->setContent($output); + + return $response; } }