From: <lu...@us...> - 2009-02-15 23:01:48
|
Revision: 8985 http://armagetronad.svn.sourceforge.net/armagetronad/?rev=8985&view=rev Author: luke-jr Date: 2009-02-15 22:03:47 +0000 (Sun, 15 Feb 2009) Log Message: ----------- basic LATEST redirector Modified Paths: -------------- tools/resource-repo/htaccess Added Paths: ----------- tools/resource-repo/latest.php Modified: tools/resource-repo/htaccess =================================================================== --- tools/resource-repo/htaccess 2009-02-15 21:51:43 UTC (rev 8984) +++ tools/resource-repo/htaccess 2009-02-15 22:03:47 UTC (rev 8985) @@ -16,4 +16,6 @@ RewriteRule ^(map-0\.(1(|-exp)|2\.8_beta3)\.dtd$) /resource/.old/$1 [R=301] # end of 0.2.8 rewrites +RewriteRule ^(.*\-)LATEST(\.[^\/]+)$ /.latest.php + ErrorDocument 404 /.404redirect.php Added: tools/resource-repo/latest.php =================================================================== --- tools/resource-repo/latest.php (rev 0) +++ tools/resource-repo/latest.php 2009-02-15 22:03:47 UTC (rev 8985) @@ -0,0 +1,53 @@ +<?php + +// NOTE: This is only on the master, to ensure we don't miss a brand new ver +require('.trymaster.php'); + +header('HTTP/1.0 500 Internal Server Error'); +$respfx = "resource/"; + +preg_match('/^(?:\/?resource\/)?([^?#]*)(?:\?.*)?$/', $_SERVER['REQUEST_URI'], $M); +$f = $M[1]; + +{ + preg_match('/^(.*\/)(.*\-)LATEST(\.[^\/]+)$/', $f, $M); + $dir = $M[1]; + $fre = '/^' . preg_quote($M[2]) . '(.*)' . preg_quote($M[3]) . '$/'; + $dh = opendir("$respfx$dir"); + if (!$dh) + die("No dir handle"); + $newest = array(); + while (($fe = readdir($dh)) !== false) + { + if (!preg_match($fre, $fe, $M)) + continue; + if (isset($newest['version'])) + { + if (version_compare($newest['version'], $M[1], '>')) + continue; + if ($newest['version'] > $M[1]) + continue; + } + $newest = array( + 'file' => $M[0], + 'version' => $M[1], + ); + } + if (!isset($newest['file'])) + { + header('HTTP/1.0 404 Resource Not Found'); + die('404 Resource Not Found'); + } + $filepath = $dir . $newest['file']; + $abspath = "$respfx$filepath"; + $URI = "http://" . $_SERVER['HTTP_HOST'] . "/$abspath"; + header("HTTP/1.0 307 Dynamic resource"); + header("Location: $URI"); + $reqheaders = array_change_key_case(getallheaders(), CASE_LOWER); + if ($reqheaders['x-please-follow-redirects']) + { + header("X-Content-Included: target-content"); + readfile($abspath); + } + die(); +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |