<?php
use Drupal\Component\Utility\Crypt;
function aggregator_test_menu() {
$items['aggregator/test-feed'] = array(
'title' => 'Test feed static last modified date',
'description' => "A cached test feed with a static last modified date.",
'page callback' => 'aggregator_test_feed',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
$items['aggregator/redirect'] = array(
'title' => 'Test feed with a redirect',
'description' => "A feed that redirects to another one",
'page callback' => 'aggregator_test_redirect',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
$last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
$etag = Crypt::hashBase64($last_modified);
$if_modified_since = strtotime(Drupal::request()->server
->get('HTTP_IF_MODIFIED_SINCE'));
$if_none_match = stripslashes(Drupal::request()->server
->get('HTTP_IF_NONE_MATCH'));
if ($use_last_modified) {
drupal_add_http_header('Last-Modified', gmdate(DATE_RFC1123, $last_modified));
}
if ($use_etag) {
drupal_add_http_header('ETag', $etag);
}
if ($last_modified == $if_modified_since || $etag == $if_none_match) {
drupal_add_http_header('Status', '304 Not Modified');
return;
}
drupal_add_http_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
drupal_add_http_header('Cache-Control', 'must-revalidate');
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
$file_name = __DIR__ . '/aggregator_test_rss091.xml';
$handle = fopen($file_name, 'r');
$feed = fread($handle, filesize($file_name));
fclose($handle);
print $feed;
}
function aggregator_test_redirect() {
drupal_goto('aggregator/test-feed', array(), 301);
}