com web/php: Download system tweaks: error.php include/do-download.inc include/get-download.inc include/site.inc styles/mirror.css
| From: | Hannes Magnusson | Date: | Thu, 21 Nov 2013 19:25:45 +0000 |
| Subject: | com web/php: Download system tweaks: error.php include/do-download.inc include/get-download.inc include/site.inc styles/mirror.css | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-17159@lists.php.net to get a copy of this message | ||
Commit: af21c99842e98703c0a929847a5dfa58d2fd4eb6
Author: Hannes Magnusson <bjori@mongodb.com> Thu, 21 Nov 2013 11:25:45 -0800
Parents: 9050dae5abafb1937ff04be1c888e54b08a6a6ec
Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=af21c99842e98703c0a929847a5dfa58d2fd4eb6
Log:
Download system tweaks
Remove reduntant/duplicate code between do-download and get-download
Also make this page more interesting when the download is missing from
this specific mirror by give the choise of going to other mirrors to check.
Rather then blindly go to the download file though we go to the same page
on the other mirror so we can check if the file exists there before giving
the link to the actual real file.
This also makes it a lot easier to work with on developers checkouts
Changed paths:
M error.php
M include/do-download.inc
M include/get-download.inc
M include/site.inc
M styles/mirror.css
Diff:
diff --git a/error.php b/error..php
index 9e1dbe9..fdeb89d 100644
--- a/error.php
+++ b/error.php
@@ -172,7 +172,13 @@ if (preg_match("!^get/([^/]+)/from/([^/]+)(/mirror)?$!", $URI,
$dlinfo)) {
// Start the download process
status_header(200);
include $_SERVER['DOCUMENT_ROOT'] . "/include/do-download.inc";
- download_file($mr, $df);
+ $filename = get_actual_download_file($df);
+ if ($filename) {
+ download_file($mr, $filename);
+ } else {
+ /* The file didn't exist on this server.. ask the user to pick another mirror */
+ include $_SERVER['DOCUMENT_ROOT'] . "/include/get-download.inc";
+ }
exit;
}
diff --git a/include/do-download.inc b/include/do-download.inc
index 095a70d..f9d4254 100644
--- a/include/do-download.inc
+++ b/include/do-download.inc
@@ -8,11 +8,8 @@
we would like to know about (PHP binary or source).
*/
-// Download a file from a mirror site
-function download_file($mirror, $file)
+function get_actual_download_file($file)
{
- global $MYSITE;
-
// Could be a normal download or a manual download file
$possible_files = array($file => TRUE, "manual/$file" => FALSE);
@@ -24,44 +21,13 @@ function download_file($mirror, $file)
break;
}
}
-
- // No downloadable file found
- if ($found === FALSE) {
- status_header(404);
- site_header("Download not found");
-
- // If user comes from a mirror selection page, provide a backlink
- if (isset($_SERVER['HTTP_REFERER']) &&
preg_match("!/from/a/mirror$!", $_SERVER['HTTP_REFERER'])) {
- $moreinfo = ", or <a
href=\"".htmlspecialchars($_SERVER['HTTP_REFERER'],ENT_QUOTES,'UTF-8')."\">reconsider
your mirror selection</a>";
- } else { $moreinfo = ""; }
-
- // An executable was requested (temp fix for rsync change)
- if (preg_match("!\\.exe$!", $name)) {
- $info = "<p>
- This mirror site is improperly setup, and thus has
- no copy of the executable file you requested. Please
- <a href=\"/mirrors\">select a different
- mirror site</a> to get the file, until this site gets
- fixed.
-</p>";
- }
- else {
- $info = "<p>
- The file you requested (<strong> " . htmlspecialchars($file, ENT_QUOTES,
"UTF-8") . " </strong>) is not found on
- this server (<strong>{$MYSITE}</strong>). If this file is a
- recent addition to our downloads, then it is possible that this
- particular server is not yet updated to host that file for download.
- Please come back to this server later{$moreinfo}.
-</p>";
- }
-
- echo <<<EOT
-<h1>Download not found</h1>
-{$info}
-EOT;
- site_footer();
- exit;
- }
+
+ return $found;
+}
+// Download a file from a mirror site
+function download_file($mirror, $file)
+{
+ global $MYSITE;
// Redirect to the particular file
if (!headers_sent()) {
diff --git a/include/get-download.inc b/include/get-download.inc
index f46d73e..f05a61e 100644
--- a/include/get-download.inc
+++ b/include/get-download.inc
@@ -26,52 +26,51 @@ foreach ($possible_files as $name) {
}
}
+// Print out common header
+site_header('Get Download', $site_config);
+
+echo '<div id="mirrors-container">';
+$size = 0;
// No downloadable file found
if ($file === FALSE) {
- site_header("Download not found", $site_config);
-
$info = "<p>
The file you requested (<strong> " . htmlspecialchars($df, ENT_QUOTES,
"UTF-8") . " </strong>) is not found on
- this server (<strong>{$MYSITE}</strong>). If this file is a
- recent addition to our downloads, then it is possible that this
- particular server is not yet updated to host that file for download.
- Please come back to this server later, or start the download from
- another mirror site.
-</p>";
+ this server (<strong>{$MYSITE}</strong>). Please try another mirror listed
below</p>";
echo <<<EOT
<h1>Download not found</h1>
{$info}
EOT;
- site_footer();
- exit;
-}
+} else {
+ // Set local file name
+ $local_file = $_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $file;
+ // Try to get filesize to display
+ $size = @filesize($local_file)+11;
-// Set local file name
-$local_file = $_SERVER['DOCUMENT_ROOT'] . '/distributions/' . $file;
-// Print out common header
-site_header('Get Download', $site_config);
?>
-<div id="mirrors-container">
<h1>Choose mirror site for download</h1>
<p>
You have chosen to download the following file:
- <strong class="filename"><?php echo $df ?></strong><br />
-</p>
-
+<span class="download-file">
+ <strong class="filename"><?php echo $df ?>
+</strong>
<?php
-// Try to get filesize to display
-$size = @filesize($local_file);
if ($size) {
- echo '<small>' . number_format($size, 0, '.', ',') . '
bytes</small><br />';
+ echo '<small>(' . number_format($size, 0, '.', ',') .
' bytes)</small>';
}
?>
+</span>
+</p>
+<?php
+}
+?>
+
<div class="mirrors-list">
-<?php print_full_mirror_list($df); ?>
+<?php print_full_mirror_list($df, $size); ?>
</div>
</div>
diff --git a/include/site.inc b/include/site.inc
index c930534..95bf870 100644
--- a/include/site.inc
+++ b/include/site.inc
@@ -211,7 +211,7 @@ function organise_mirrors($mirrors) {
}
return $retval;
}
-function print_full_mirror_list($download_file = null) {
+function print_full_mirror_list($download_file = null, $direct_download = false) {
global $COUNTRIES, $COUNTRY, $MIRRORS;
$groupped = organise_mirrors($MIRRORS);
@@ -221,16 +221,16 @@ function print_full_mirror_list($download_file = null) {
echo "<p>We have automatically detected the following $mnum to be close to
you</p>";
if (isset($groupped[$COUNTRY])) {
- print_mirror_box($COUNTRIES[$COUNTRY], $COUNTRY, $groupped[$COUNTRY], $download_file,
true);
+ print_mirror_box($COUNTRIES[$COUNTRY], $COUNTRY, $groupped[$COUNTRY], $download_file,
$direct_download, true);
echo "<br />";
}
}
foreach($groupped as $mirrorcode => $country) {
- print_mirror_box($COUNTRIES[$mirrorcode], $mirrorcode, $country, $download_file, false);
+ print_mirror_box($COUNTRIES[$mirrorcode], $mirrorcode, $country, $download_file,
$direct_download, false);
}
}
-function print_mirror_box($countryname, $countrycode, $mirrors, $file = null, $homecountry = false)
{
+function print_mirror_box($countryname, $countrycode, $mirrors, $file = null, $direct_download =
false, $homecountry = false) {
?>
<div class="mirror <?php echo $homecountry ? "homecountry" :
""?>">
<div class="title"><?php echo $countryname; ?>
@@ -243,7 +243,8 @@ function print_mirror_box($countryname, $countrycode, $mirrors, $file = null, $h
<?php
$url = substr($mirror["url"], strpos($mirror["url"], '//') + 2,
-1);
if ($file) {
- $url = "/get/$file/from/$url/mirror";
+ $what = $direct_download ? "this" : "a";
+ $url = $mirror["url"] . "get/$file/from/$what/mirror";
}
?>
<div class="entry">
diff --git a/styles/mirror.css b/styles/mirror.css
index 9983885..0469929 100644
--- a/styles/mirror.css
+++ b/styles/mirror.css
@@ -45,13 +45,19 @@ div#usernotes a.usernotes-voted:hover {
font-size: 1.7em;
}
-#mirrors-container .filename {
+#mirrors-container .download-file small {
+ text-align: right;
+ padding-left: 25px;
+ font-size: 0.7em;
+}
+#mirrors-container .download-file {
display: block;
padding: 20px;
border: 1px;
font-size: 1.4em;
background-color: #EEE;
text-align: center;
+ margin: 0;
}