1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Implements hook_menu().
|
5
|
*/
|
6
|
function aggregator_test_menu() {
|
7
|
$items['aggregator/test-feed'] = array(
|
8
|
'title' => 'Test feed static last modified date',
|
9
|
'description' => "A cached test feed with a static last modified date.",
|
10
|
'page callback' => 'aggregator_test_feed',
|
11
|
'access arguments' => array('access content'),
|
12
|
'type' => MENU_CALLBACK,
|
13
|
);
|
14
|
return $items;
|
15
|
}
|
16
|
|
17
|
/**
|
18
|
* Page callback. Generates a test feed and simulates last-modified and etags.
|
19
|
*
|
20
|
* @param $use_last_modified
|
21
|
* Set TRUE to send a last modified header.
|
22
|
* @param $use_etag
|
23
|
* Set TRUE to send an etag.
|
24
|
*/
|
25
|
function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
|
26
|
$last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
|
27
|
$etag = drupal_hash_base64($last_modified);
|
28
|
|
29
|
$if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) : FALSE;
|
30
|
$if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ? stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : FALSE;
|
31
|
|
32
|
// Send appropriate response. We respond with a 304 not modified on either
|
33
|
// etag or on last modified.
|
34
|
if ($use_last_modified) {
|
35
|
drupal_add_http_header('Last-Modified', gmdate(DATE_RFC7231, $last_modified));
|
36
|
}
|
37
|
if ($use_etag) {
|
38
|
drupal_add_http_header('ETag', $etag);
|
39
|
}
|
40
|
// Return 304 not modified if either last modified or etag match.
|
41
|
if ($last_modified == $if_modified_since || $etag == $if_none_match) {
|
42
|
drupal_add_http_header('Status', '304 Not Modified');
|
43
|
return;
|
44
|
}
|
45
|
|
46
|
// The following headers force validation of cache:
|
47
|
drupal_add_http_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
|
48
|
drupal_add_http_header('Cache-Control', 'must-revalidate');
|
49
|
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
|
50
|
|
51
|
// Read actual feed from file.
|
52
|
$file_name = DRUPAL_ROOT . '/' . drupal_get_path('module', 'aggregator') . '/tests/aggregator_test_rss091.xml';
|
53
|
$handle = fopen($file_name, 'r');
|
54
|
$feed = fread($handle, filesize($file_name));
|
55
|
fclose($handle);
|
56
|
|
57
|
print $feed;
|
58
|
}
|