Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions textpattern/lib/txplib_misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -4548,6 +4548,7 @@ function get_lastmod($unix_ts = null)

function handle_lastmod($unix_ts = null, $exit = true)
{
// Disable caching when not in production
if (get_pref('production_status') != 'live') {
header('Cache-Control: no-cache, no-store, max-age=0');
}
Expand All @@ -4564,16 +4565,20 @@ function handle_lastmod($unix_ts = null, $exit = true)
$etag = base_convert($unix_ts, 10, 32);
header('ETag: "' . $etag . '"');

// Get timestamp from request caching headers
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$hims = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$imsd = ($hims) ? strtotime($hims) : 0;
} elseif (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$hinm = trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"');
$inmd = ($hinm) ? base_convert(explode('-gzip', $hinm)[0], 32, 10) : 0;
$hinm_apache_gzip_workaround = explode('-gzip', $hinm);
$hinm_apache_gzip_workaround = $hinm_apache_gzip_workaround[0];
$inmd = ($hinm) ? base_convert($hinm_apache_gzip_workaround, 32, 10) : 0;
}

// Check request timestamps against the current timestamp
if ((isset($imsd) && $imsd >= $unix_ts) ||
(isset($inmd) && $inmd >= $unix_ts)) { return;
(isset($inmd) && $inmd >= $unix_ts)) {
log_hit('304');

header('Content-Length: 0');
Expand All @@ -4583,7 +4588,11 @@ function handle_lastmod($unix_ts = null, $exit = true)
if ($exit) {
exit();
}

return array('304', $last);
}

return array('200', $last);
}
}

Expand Down
7 changes: 6 additions & 1 deletion textpattern/publish/atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,15 @@ function atom()

handle_lastmod(max($dates));

// Get timestamp from request caching headers
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$hims = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$imsd = ($hims) ? strtotime($hims) : 0;
} elseif (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$hinm = trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"');
$inmd = ($hinm) ? base_convert(explode('-gzip', $hinm)[0], 32, 10) : 0;
$hinm_apache_gzip_workaround = explode('-gzip', $hinm);
$hinm_apache_gzip_workaround = $hinm_apache_gzip_workaround[0];
$inmd = ($hinm) ? base_convert($hinm_apache_gzip_workaround, 32, 10) : 0;
}
if (isset($imsd) || isset($inmd)) {
$clfd = max(intval($imsd), intval($inmd));
Expand All @@ -313,6 +316,7 @@ function atom()
strpos($_SERVER["HTTP_A_IM"], "feed") &&
isset($clfd) && $clfd > 0) {

// Remove articles with timestamps older than the request timestamp
foreach($articles as $id => $entry) {
if ($dates[$id] <= $clfd) {
unset($articles[$id]);
Expand All @@ -321,6 +325,7 @@ function atom()
}
}

// Indicate that instance manipulation was applied
if ($cutarticles) {
header("HTTP/1.1 226 IM Used");
header("Cache-Control: IM", false);
Expand Down
7 changes: 6 additions & 1 deletion textpattern/publish/rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,15 @@ function rss()

handle_lastmod(max($dates));

// Get timestamp from request caching headers
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
$hims = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$imsd = ($hims) ? strtotime($hims) : 0;
} elseif (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
$hinm = trim(trim($_SERVER['HTTP_IF_NONE_MATCH']), '"');
$inmd = ($hinm) ? base_convert(explode('-gzip', $hinm)[0], 32, 10) : 0;
$hinm_apache_gzip_workaround = explode('-gzip', $hinm);
$hinm_apache_gzip_workaround = $hinm_apache_gzip_workaround[0];
$inmd = ($hinm) ? base_convert($hinm_apache_gzip_workaround, 32, 10) : 0;
}
if (isset($imsd) || isset($inmd)) {
$clfd = max(intval($imsd), intval($inmd));
Expand All @@ -238,6 +241,7 @@ function rss()
strpos($_SERVER["HTTP_A_IM"], "feed") &&
isset($clfd) && $clfd > 0) {

// Remove articles with timestamps older than the request timestamp
foreach($articles as $id => $entry) {
if ($dates[$id] <= $clfd) {
unset($articles[$id]);
Expand All @@ -246,6 +250,7 @@ function rss()
}
}

// Indicate that instance manipulation was applied
if ($cutarticles) {
header("HTTP/1.1 226 IM Used");
header("Cache-Control: IM", false);
Expand Down