various partial fixes towards improved download page
diff --git a/releng.wtpbuilder/distribution/patches.site/staticDropFiles/miscUtil.php b/releng.wtpbuilder/distribution/patches.site/staticDropFiles/miscUtil.php
index 583231b..9e47298 100644
--- a/releng.wtpbuilder/distribution/patches.site/staticDropFiles/miscUtil.php
+++ b/releng.wtpbuilder/distribution/patches.site/staticDropFiles/miscUtil.php
@@ -4,42 +4,159 @@
 // handy constant to compute file size in megabytes
 
 function fileSizeInMegs($filename) {
-	$onemeg=1024*1024;
-	$zipfilesize=filesize($filename);
-	$zipfilesize=round($zipfilesize/$onemeg, 0);
-	return $zipfilesize;
+    $onemeg=1024*1024;
+    $zipfilesize=filesize($filename);
+    $zipfilesize=round($zipfilesize/$onemeg, 0);
+    return $zipfilesize;
 }
 
 function fileSizeForDisplay($filename) {
-	$onekilo=1024;
-	$onemeg=$onekilo * $onekilo;
-	$criteria = 10 * $onemeg;
-	$scaleChar = "M";
-	$zipfilesize=filesize($filename);
-	if ($zipfilesize > $criteria) {
-		$zipfilesize=round($zipfilesize/$onemeg, 0);
-		$scaleChar = "M";
-	}
-	else {
-		$zipfilesize=round($zipfilesize/$onekilo, 0);
-		$scaleChar = "K";
-	}
-	$result =  "(" . $zipfilesize . $scaleChar . ")";
-	return $result;
+    $onekilo=1024;
+    $onemeg=$onekilo * $onekilo;
+    $criteria = 10 * $onemeg;
+    $scaleChar = "M";
+    $zipfilesize=filesize($filename);
+    if ($zipfilesize > $criteria) {
+        $zipfilesize=round($zipfilesize/$onemeg, 0);
+        $scaleChar = "M";
+    }
+    else {
+        $zipfilesize=round($zipfilesize/$onekilo, 0);
+        $scaleChar = "K";
+    }
+    $result =  "(" . $zipfilesize . $scaleChar . ")";
+    return $result;
 }
 
 
 function displayFileLine($downloadprefix, $filename, $zipfilesize, $fileShortDescription) {
-	echo "<td align=\"right\" valign=\"top\" width=\"10%\">";
-	echo "<a href=\"$downloadprefix$filename\">" . $fileShortDescription . "</a>";
-	echo "</td><td align=\"right\" valign=\"top\" width=\"5%\">";
-	echo $zipfilesize;
-	echo "</td>";
-	echo "<td align=\"right\" valign=\"top\" width=\"5%\">";
-	echo "[<a href=\"checksum/$filename.md5\">md5</a>]";
-	echo "</td>";
+    echo "<td align=\"right\" valign=\"top\" width=\"10%\">";
+    echo "<a href=\"$downloadprefix$filename\">" . $fileShortDescription . "</a>";
+    echo "</td><td align=\"right\" valign=\"top\" width=\"5%\">";
+    echo $zipfilesize;
+    echo "</td>";
+    echo "<td align=\"right\" valign=\"top\" width=\"5%\">";
+    echo "[<a href=\"checksum/$filename.md5\">md5</a>]";
+    echo "</td>";
 }
 
 
+function stream_last_modified($url)
+{
+    if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') > 0)
+    {
+        if (!($fp = @fopen($url, 'r')))
+            return NULL;
 
+        $meta = stream_get_meta_data($fp);
+        for ($j = 0; isset($meta['wrapper_data'][$j]); $j++)
+        {
+            if (strstr(strtolower($meta['wrapper_data'][$j]), 'last-modified'))
+            {
+                $modtime = substr($meta['wrapper_data'][$j], 15);
+                break;
+            }
+        }
+        fclose($fp);
+    }
+    else
+    {
+        $parts = parse_url($url);
+        $host  = $parts['host'];
+        $path  = $parts['path'];
+
+        if (!($fp = @fsockopen($host, 80)))
+            return NULL;
+
+        $req = "HEAD $path HTTP/1.0\r\nUser-Agent: PHP/".phpversion()."\r\nHost: $host:80\r\nAccept: */*\r\n\r\n";
+        fputs($fp, $req);
+
+        while (!feof($fp))
+        {
+            $str = fgets($fp, 4096);
+            if (strstr(strtolower($str), 'last-modified'))
+            {
+                $modtime = substr($str, 15);
+                break;
+            }
+        }
+        fclose($fp);
+    }
+    return isset($modtime) ? strtotime($modtime) : time();
+}
+
+function isMirrored($uriToCheck) {
+    global $debugScript;
+    global $debugFunctions;
+    $localuri = $uriToCheck;
+
+    $debugMirrorList = false;
+    if ($debugScript) {
+        echo "uriToCheck: " . $localuri . "<br />";
+    }
+    // turn off warnings, as sometimes HTML is returned, which causes lots of warnings
+    $holdLevel = error_reporting(E_ERROR);
+    $mirrorsxml=simplexml_load_file(rawurlencode($localuri) . urlencode("&format=xml"));
+    error_reporting($holdLevel);
+
+    $xmlcount = 0;
+    if ($mirrorsxml) {
+        if ($debugFunctions) {
+            echo "root node: " . $mirrorsxml->getName() . "<br />";
+        }
+        if (strcmp($mirrorsxml->getName(), "mirrors") == 0) {
+            foreach ($mirrorsxml->children() as $mirror) {
+                if (strcmp($mirror->getName(),"mirror") == 0) {
+                    $xmlcount=$xmlcount+1;
+                }
+                if ($debugMirrorList) {
+                    print_r($mirror);
+                    echo "<br />";
+                }
+            }
+        }
+        if ($debugFunctions) {
+            echo "Mirror count: " . $xmlcount . "<br />";
+        }
+    }
+    return ($xmlcount > 0);
+
+}
+
+function getPlatform () {
+    global $debugScript;
+    global $debugFunctions;
+    $browser = get_browser(null, true);
+    $rawPlatform = $browser['platform'];
+    if ($debugFunctions) {
+        echo "browser platfrom: " . $rawPlatform . "<br />" ;
+    }
+
+    if ($debugFunctions) {
+        $browserKeys = array_keys($browser);
+        foreach ($browserKeys as $key) {
+            echo $key . ": " . $browser[$key] . "<br />";
+        }
+    }
+    $platform = "unknown";
+    if (strpos($rawPlatform, "Win") === 0) {
+        $platform="windows";
+    } else if (strpos($rawPlatform, "Linux") === 0) {
+        $platform="linux";
+    } else if (strpos($rawPlatform, "Mac") === 0) {
+        $platform="mac";
+    }
+    return $platform;
+}
+
+function getPrereqReferenceOrName($prerequrl, $prereqname) {
+    // todo: we really only need "if exists" so could make a bit more efficient
+    // I tried "file_exists" but is didn't seem to work on my test server
+    if (stream_last_modified($prerequrl)) {
+        $reflink="<a href=\"" . $prerequrl . "\">" . $prereqname . "</a>";
+    } else {
+        $reflink=$prereqname;
+    }
+    return $reflink;
+}
 ?>
diff --git a/releng.wtpbuilder/distribution/wtp.site/staticDropFiles/miscUtil.php b/releng.wtpbuilder/distribution/wtp.site/staticDropFiles/miscUtil.php
index bce77b3..9e47298 100644
--- a/releng.wtpbuilder/distribution/wtp.site/staticDropFiles/miscUtil.php
+++ b/releng.wtpbuilder/distribution/wtp.site/staticDropFiles/miscUtil.php
@@ -46,7 +46,7 @@
     if (function_exists('version_compare') && version_compare(phpversion(), '4.3.0') > 0)
     {
         if (!($fp = @fopen($url, 'r')))
-        return NULL;
+            return NULL;
 
         $meta = stream_get_meta_data($fp);
         for ($j = 0; isset($meta['wrapper_data'][$j]); $j++)
@@ -66,7 +66,7 @@
         $path  = $parts['path'];
 
         if (!($fp = @fsockopen($host, 80)))
-        return NULL;
+            return NULL;
 
         $req = "HEAD $path HTTP/1.0\r\nUser-Agent: PHP/".phpversion()."\r\nHost: $host:80\r\nAccept: */*\r\n\r\n";
         fputs($fp, $req);
@@ -88,17 +88,31 @@
 function isMirrored($uriToCheck) {
     global $debugScript;
     global $debugFunctions;
+    $localuri = $uriToCheck;
+
     $debugMirrorList = false;
-    $mirrorsxml=simplexml_load_file($uriToCheck . "&format=xml");
-    //print_r($mirrorsxml);
+    if ($debugScript) {
+        echo "uriToCheck: " . $localuri . "<br />";
+    }
+    // turn off warnings, as sometimes HTML is returned, which causes lots of warnings
+    $holdLevel = error_reporting(E_ERROR);
+    $mirrorsxml=simplexml_load_file(rawurlencode($localuri) . urlencode("&format=xml"));
+    error_reporting($holdLevel);
 
     $xmlcount = 0;
     if ($mirrorsxml) {
-        foreach ($mirrorsxml->children() as $mirror) {
-            $xmlcount=$xmlcount+1;
-            if ($debugMirrorList) {
-                print_r($mirror);
-                echo "<br />";
+        if ($debugFunctions) {
+            echo "root node: " . $mirrorsxml->getName() . "<br />";
+        }
+        if (strcmp($mirrorsxml->getName(), "mirrors") == 0) {
+            foreach ($mirrorsxml->children() as $mirror) {
+                if (strcmp($mirror->getName(),"mirror") == 0) {
+                    $xmlcount=$xmlcount+1;
+                }
+                if ($debugMirrorList) {
+                    print_r($mirror);
+                    echo "<br />";
+                }
             }
         }
         if ($debugFunctions) {