Skip to content

Commit

Permalink
Link back to server manager when reloading custom CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Sep 18, 2013
1 parent e47b56b commit 9c55f48
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions customcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
die('server not found');
}

header('Content-Type: text/css'); // the CSS file should specify a charset
$invalidate = isset($_REQUEST['invalidate']);

if (!$invalidate) header('Content-Type: text/css'); // the CSS file should specify a charset

$serverdata =& $PokemonServers[$server];
$customcssuri = @$serverdata['customcss'];
Expand All @@ -27,14 +29,14 @@

// echo '/* ', $customcssuri, ' */';

if (!isset($_REQUEST['invalidate']) && $lastmodified && (($timenow - $lastmodified) < 3600)) {
if (!$invalidate && $lastmodified && (($timenow - $lastmodified) < 3600)) {
// Don't check for modifications more than once an hour.
readfile($cssfile);
die();
}

$curl = curl_init($customcssuri);
if ($lastmodified && !isset($_REQUEST['invalidate'])) {
if ($lastmodified && !$invalidate) {
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', $lastmodified)
));
Expand Down Expand Up @@ -68,13 +70,26 @@
$outputcss = $filter->cleanCSS($curlret, $config, $context);

file_put_contents($cssfile, $outputcss);
echo $outputcss;
if (!$invalidate) echo $outputcss;
} else {
// Either no modifications (status: 304) or an error condition.
if ($invalidate) die('Error: custom CSS file not found');
if ($lastmodified) readfile($cssfile);
}
touch($cssfile, $timenow); // Don't check again for an hour.
} else if (file_exists($cssfile)) {
if ($invalidate) die('Error: custom CSS file not found');
readfile($cssfile);
}
curl_close($curl);

if ($invalidate) {
?>
<p>
Done: <?= htmlspecialchars($customcssuri) ?> was reloaded.
</p>
<p>
<a href="http://pokemonshowdown.com/servers/<?= $server ?>">Back to server management</a>
</p>
<?php
}

0 comments on commit 9c55f48

Please sign in to comment.