From cc6e29172af4aeeefed1cf97bde5d8a0f2e888cc Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Tue, 28 Aug 2012 16:14:55 +0000 Subject: code style updates --- en/downloads/get/index.php | 111 +++++++++++++++++++++++++++++---------------- 1 file changed, 72 insertions(+), 39 deletions(-) (limited to 'en/downloads/get/index.php') diff --git a/en/downloads/get/index.php b/en/downloads/get/index.php index 9e37ee3d0..7f57a36f9 100644 --- a/en/downloads/get/index.php +++ b/en/downloads/get/index.php @@ -7,21 +7,30 @@ * - download mode (normal or GET[torrent] is set) * - products whitelist with a checksum for each one * - list of available up-to-date mirrors for this product - -product: - id - name - checksums - size - -mirror(product): - name - host - country - city - speed - link - + * + * product: + * - id + * - name + * - checksums + * - size + * + * mirror(product): + * - name + * - host + * - country + * - city + * - speed + * - link + * + * + * PHP version 5.4 + * + * @category Mageia + * @package Mageia\Web\www + * @author rda + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2+ + * @link http://www.mageia.org/ + * */ require 'lib.php'; @@ -50,19 +59,24 @@ $reason = null; try { // TODO simplify and wrap all this in a single interface: // list(dl_template, mirrors) = get_download_options_for(product) + // Step 1. include '../../../lib/Downloads.php'; $product = get_info_for_product($product); $all_mirrors = get_mirrors_for($product['file'], 'en', get('country')); $one_mirror = $all_mirrors[0]; $alt_mirrors = $all_mirrors[1]; - $download_tmpl = get_download_link($product, $torrent); - $download = str_replace('$MIRROR', $one_mirror['mirror_url'], $download_tmpl); + + // Step 2. Make the actual download link against the preferred mirror returned. + $download = str_replace('$MIRROR', $one_mirror['mirror_url'], $download_tmpl); // TODO do not redirect if it's a bot! - $js_redirect = sprintf('', - $download); + $js_redirect = sprintf( + '', + $download + ); + // Step 3. Build alternative mirrors list of links (URL manipulation, HTML) $g_mirs2 = array(); foreach ($alt_mirrors as $country => $mirs): if (substr($country, 0, 3) == '_C:') @@ -76,27 +90,40 @@ try { ksort($g_mirs2); $alternative_mirrors = ''; - foreach ($g_mirs2 as $country => $cities): + foreach ($g_mirs2 as $country => $cities) { $s = array(); foreach ($cities as $city => $mirrors2) { $mirs = array(); foreach ($mirrors2 as $m) { $pm = parse_url($m); $alt_dl_link = str_replace('$MIRROR', $m, $download_tmpl); - $mirs[] = sprintf('%s://%s', - $pm['scheme'], $alt_dl_link, $pm['host']); + $mirs[] = sprintf( + '%s://%s', + $pm['scheme'], $alt_dl_link, $pm['host'] + ); } $s[] = sprintf('%s%s', rewrite_city($city), implode(', ', $mirs)); } $alternative_mirrors .= sprintf('%s%s', count($cities), $country, implode('', $s)); - endforeach; + } + + // Feedback about current mirror location + trigger for alt mirrors. + $dl2_mirror_alt = sprintf( + _t('This %s download mirror is located in %s (%s).'), + $one_mirror['mirror_url'], + $one_mirror['mirror_host'], + rewrite_city($one_mirror['city']) . ', ' . $countries[$one_mirror['country']], + $one_mirror['country'] + ) + . ' ' . _t('If it does not work well for you, check out these other mirrors.'); - $dl2_mirror_alt = sprintf(_t('This %s download mirror is located in %s (%s).'), - $one_mirror['mirror_url'], - $one_mirror['mirror_host'], - rewrite_city($one_mirror['city']) . ', ' . $countries[$one_mirror['country']], - $one_mirror['country']) - . ' ' . _t('If it does not work well for you, check out these other mirrors.'); + + // at the end of this block we expect the following vars to be available from here: + // - $product (mixed) + // - $download (URL) + // - $js_redirect (JS snippet) + // - $alternative_mirrors (HTML snippet) + // - $dl2_mirror_alt (HTML snippet) } catch (NoProductFoundError $e) { // sorry, no such product found/available. redirect? @@ -116,8 +143,7 @@ if (!$download) { header('Status: 404 Not Found'); $title = '404 Not Found'; $js_redirect = null; -} -else { +} else { $title = $product['name']; } @@ -131,10 +157,12 @@ if ($debug) <?php echo $title; ?> | <?php _e('Mageia Downloads') ?> - + @@ -155,7 +183,8 @@ if ($debug) 0) || (isset($product['sha1'])) && strlen($product['sha1']) > 0) - && !$torrent): ?> + && !$torrent + ): ?>

@@ -164,10 +193,15 @@ if ($debug)
 $ sha1sum ", $product['sha1'], "\n"; endif; ?>
 

DO NOT use this ISO. Double-check and try to download again.'); ?>

+
-

+

@@ -190,7 +224,6 @@ if ($debug)

', ''); ?>

-

:-(

-- cgit v1.2.1