cvs: phpweb / get_download.php
| From: | Gabor Hojtsy | Date: | Sat, 03 May 2003 20:08:57 +0000 |
| Subject: | cvs: phpweb / get_download.php | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-17267@lists.php.net to get a copy of this message | ||
goba Sat May 3 16:08:57 2003 EDT
Modified files:
/phpweb get_download.php
Log:
Rewrite the page to support automatic mirror
suggestion if active mirrors are in the user's
country
-> Put the mirror table printout into a function
-> Call this function for every table printed out
based on current conditions
Index: phpweb/get_download.php
diff -u phpweb/get_download.php:1.14 phpweb/get_download.php:1.15
--- phpweb/get_download.php:1.14 Sat May 3 11:49:18 2003
+++ phpweb/get_download.php Sat May 3 16:08:57 2003
@@ -39,71 +39,100 @@
<p>
Please choose the mirror closest to you from which to download the file.
- The current mirror is highlighted in yellow, but you may have better luck
- with a different mirror, especially if the current mirror is busy. Mirror
- sites detected to be out of date or disfunctional are not listed for your
- convenience.
+ The current mirror is highlighted in yellow, mirror sites detected to be
+ out of date or disfunctional are not listed for your convenience.
</p>
-<div align="center">
-<table border="0" cellpadding="3" cellspacing="1"
width="500">
<?php
-
-// Maintain previous country code information
-$prevcc = 'aa';
-
-// Go through all mirror sites and print out download links
-$MURLS = array_keys($MIRRORS);
-foreach ($MURLS as $murl) {
-
- // If the mirror is not all right, skip it
- // Virtual mirrors *are listed* here, because local unofficial
- // mirrors can be used in this way for download.
- if (mirror_status($murl) != MIRROR_OK) { continue; }
-
- // Get country code, print out a
- // country header, if it is a new one
- $country = mirror_country($murl);
- if ($prevcc != $country) {
- echo '<tr><td colspan="3"></td></tr>' .
"\n";
- echo '<tr bgcolor="#cccccc"><td width="40"
align="center">';
- print_image('flags/' . strtolower($country) . '.png',
$COUNTRIES[$country], FALSE, 'CLASS="flag"');
- echo '<br /></td>';
- echo '<td colspan="2"><b>' . $COUNTRIES[$country] .
'</b><br /></td>';
- echo '</tr>' . "\n";
- }
- // We print out a line for the current mirror
- $thismirror = ($MYSITE == $murl);
+// If we have a valid country, and we have at least one mirror
+// in that country, provide some intro text and the list of mirrors
+if (i2c_valid_country()) {
+ $close = count_mirrors($COUNTRY);
+ if ($close > 0) {
+ $mnum = (($close > 1) ? "mirrors" : "mirror");
+ echo "<p>We have automatically detected the following $mnum to be close\n"
.
+ "to you. If you use a mirror close to you for downloads and for\n" .
+ "you usual daily work, you will get better response times.</p>\n";
+ mirror_list($COUNTRY);
+ echo "<p>Here is the list of all the other sites in case our detection\n" .
+ "done something wrong, or the local mirror sites are busy.\n";
+ mirror_list('', $COUNTRY);
+ } else { mirror_list(); }
+} else { mirror_list(); }
+
+// List mirrors for download with a possible country matching
+function mirror_list($cmatch = '', $cnomatch = '') {
+
+ // Print out start of the table centered
+ echo '<div align="center">' . "\n" .
+ '<table border="0" cellpadding="3" cellspacing="1"
width="500">' . "\n";
+
+ // Maintain previous country code information
+ $prevcc = 'aa';
- // Highlight this mirror if it is the current one
- echo '<tr bgcolor="' . ($thismirror ? '#ffffcc' :
'#e0e0e0') . '">' . "\n";
+ // Go through all mirror sites and print out download links
+ $MURLS = array_keys($MIRRORS);
+ foreach ($MURLS as $murl) {
+
+ // If the mirror is not all right, skip it
+ // Virtual mirrors *are listed* here, because local unofficial
+ // mirrors can be used in this way for download.
+ if (mirror_status($murl) != MIRROR_OK) { continue; }
+
+ // Get the country code and check if it is
+ // matching the country provided (or does not
+ // match the country, which it should not be)
+ $country = mirror_country($murl);
+ if (!empty($cmatch) && $country != $cmatch) { continue; }
+ if (!empty($cnomatch) && $country == $cnomatch) { continue; }
+
+ // Print out a country header, if a new country is found
+ if ($prevcc != $country) {
+ echo '<tr><td colspan="3"></td></tr>' .
"\n";
+ echo '<tr bgcolor="#cccccc"><td width="40"
align="center">';
+ print_image(
+ 'flags/' . strtolower($country) . '.png',
+ $COUNTRIES[$country],
+ FALSE,
+ 'CLASS="flag"'
+ );
+ echo '<br /></td>';
+ echo '<td colspan="2"><b>' . $COUNTRIES[$country] .
'</b><br /></td>';
+ echo '</tr>' . "\n";
+ }
+
+ // We print out a line for the current mirror
+ $thismirror = ($MYSITE == $murl);
+
+ // Highlight this mirror if it is the current one
+ echo '<tr bgcolor="' . ($thismirror ? '#ffffcc' :
'#e0e0e0') . '">' . "\n";
+
+ // Print out caret (in bold if current mirror)
+ echo '<td bgcolor="#ffffff" align="right">';
+ print_image( ($thismirror ? 'caret-r.gif' : 'caret-rg.gif') );
+ echo '<br /></td>' . "\n";
+
+ // Print out mirror site download link
+ echo '<td><small>';
+ $mirrorshort = substr($murl, strpos($murl, '//') + 2, -1);
+ $mirrorname = ($thismirror ? "this" : $mirrorshort);
+ print_link("/get/$df/from/$mirrorname/mirror", $mirrorshort);
+ echo '</small><br /></td>' . "\n";
+
+ // Print out mirror provider's name
+ echo '<td><small>';
+ echo mirror_provider($murl);
+ echo '</small><br /></td>' . "\n";
- // Print out caret (in bold if current mirror)
- echo '<td bgcolor="#ffffff" align="right">';
- print_image( ($thismirror ? 'caret-r.gif' : 'caret-rg.gif') );
- echo '<br /></td>' . "\n";
-
- // Print out mirror site download link
- echo '<td><small>';
- $mirrorshort = substr($murl, strpos($murl, '//') + 2, -1);
- $mirrorname = ($thismirror ? "this" : $mirrorshort);
- print_link("/get/$df/from/$mirrorname/mirror", $mirrorshort);
- echo '</small><br /></td>' . "\n";
-
- // Print out mirror provider's name
- echo '<td><small>';
- echo mirror_provider($murl);
- echo '</small><br /></td>' . "\n";
+ // End row for this mirror
+ echo "</tr>\n";
- // End row for this mirror
- echo "</tr>\n";
+ // Maintain previous country code
+ $prevcc = $country;
+ }
- // Maintain previous country code
- $prevcc = $country;
+ echo "</table>\n</div>\n";
}
-?>
-</table>
-</div>
-<?php commonFooter(); ?>
+commonFooter();