Skip to content

Commit

Permalink
Added some code for staging/debugging changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jan 25, 2016
1 parent 8496d69 commit f13d1df
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions feed/index.php
Expand Up @@ -4,6 +4,7 @@
require_once 'XML/Feed/Parser.php';

$disable_cache = true;
$staging = false;

// !!! FIXME: there has got to be a better way to do this. Maybe move to
// !!! FIXME: the formal XML writer classes.
Expand Down Expand Up @@ -149,6 +150,8 @@ function process_item($item, $url)

function recache($subreddit, $fname, $url)
{
global $staging;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Expand Down Expand Up @@ -177,7 +180,10 @@ function recache($subreddit, $fname, $url)
' xmlns:media="http://search.yahoo.com/mrss/"><channel>');

$oururl = $_SERVER['PHP_SELF'];

$title = "inline reddit: $subreddit";
if ($staging)
$title = "[STAGING] $title";

$channel = array(
title => $title,
Expand Down Expand Up @@ -246,10 +252,10 @@ function recache($subreddit, $fname, $url)

function verify_cache($fname, $url, $subreddit, $maxage)
{
global $disable_cache;
global $disable_cache, $staging;
$rc = (($maxage < 0) ? false : @filemtime($fname));
$retval = true;
if ( $disable_cache || ($rc === false) || (($rc + $maxage) < time()) )
if ( $disable_cache || $staging || ($rc === false) || (($rc + $maxage) < time()) )
$retval = recache($subreddit, $fname, $url);
return $retval;
} // verify_cache
Expand Down Expand Up @@ -369,6 +375,9 @@ function verify_cache($fname, $url, $subreddit, $maxage)
if ($use_google)
$feedurl = "http://www.google.com/reader/public/atom/feed/$feedurl";

if ($staging)
$cachefname = "$cachefname-staging";

if (!verify_cache($cachefname, $feedurl, $subreddit, 60))
{
header('HTTP/1.0 503 Service unavailable');
Expand All @@ -378,7 +387,17 @@ function verify_cache($fname, $url, $subreddit, $maxage)
exit(0);
} // if

header('Content-Type: text/xml; charset=UTF-8');
if (!$staging)
header('Content-Type: text/xml; charset=UTF-8');
else
{
header('Content-Type: text/plain; charset=UTF-8');
print("\n\n\nSTAGING!\n\n\n");
} // else

@readfile($cachefname); // dump the XML we generated to the client and gtfo.

if ($staging)
unlink($cachefname); // staging!

?>

0 comments on commit f13d1df

Please sign in to comment.