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 --- README | 88 ----------------------------------- README.md | 88 +++++++++++++++++++++++++++++++++++ en/downloads/get/index.php | 111 +++++++++++++++++++++++++++++---------------- en/downloads/get/lib.php | 45 ++++++++++++++---- en/index.php | 10 ++-- 5 files changed, 202 insertions(+), 140 deletions(-) delete mode 100644 README create mode 100644 README.md diff --git a/README b/README deleted file mode 100644 index 668d2cf29..000000000 --- a/README +++ /dev/null @@ -1,88 +0,0 @@ -www.mageia.org source -===================== - - * Code is licensed under: GNU GPL-2.0+, authored/managed by the Web team. - * Content is licensed under CC-By-SA, primarily authored in English, then - translated/ported by many translators in the i18n team. - * See http://wiki.mageia.org/en/Web_team - -How to install -============== - -You'll need a basic Apache/PHP setup, with some modules (mod_geoip). - - -Configuration -============= - -* http://svnweb.mageia.org/adm/puppet/deployment/websites/manifests/init.pp?view=markup -* http://svnweb.mageia.org/adm/puppet/deployment/websites/templates/vhost_www.conf?view=markup -* http://svnweb.mageia.org/adm/puppet/deployment/websites/templates/vhost_static.conf?view=markup - -Note that all contents under g/ are served from http://static.mageia.org/g/ (different server -config to better serve and cache static, non-text contents. - -TODO -==== - -* Permissions in var/tmp/cache/ (rw) -* short_open_tags = false -* error_log directives -* rewrite language tags (and URLs) in "zh-CN" format (and not "zh-cn") - - -Translators -=========== -Most frequent translators for website: - - - en (English) - pivot language - Editors: Romain d'Alverny (rda), Damien Lallement (damsweb) - Proofreaders: Ahmad Samir (ahmad) - - - fr (French) - second pivot language - Marianne Lombard - - - de (German): - Wolfgang Bornath, Sigrid Carrera, Sebastian Schröer (sebixmag), - Thorsten van Lil - - - el (Greek): - Dimitrios Glentadakis - - - es (Spanish): - Diego Bello - - - et (): - Marek Laane - - - fi (Finnish): - - it (Italian): - Diego Righetto (daygo) - - - lv (Latvian): - - - nb (Norwegian): - - - nl (Dutch): - - - pl (Polish): - - - pt (Portuguese): - Adjamilton Júnior - - - ro (Romanian): - Catalin Florin Russen - - - ru (Russian): - - - sl (Slovakian?): - - - tr (Turkish): - Numan Dermidögen, Attila Ontas (tarakbumba) - - - zh-cn (Chinese - PRC): - - - zh-tw (Chinese - traditional): - -Next? - - ? (Persian): Siavash Ghiasvand \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 000000000..668d2cf29 --- /dev/null +++ b/README.md @@ -0,0 +1,88 @@ +www.mageia.org source +===================== + + * Code is licensed under: GNU GPL-2.0+, authored/managed by the Web team. + * Content is licensed under CC-By-SA, primarily authored in English, then + translated/ported by many translators in the i18n team. + * See http://wiki.mageia.org/en/Web_team + +How to install +============== + +You'll need a basic Apache/PHP setup, with some modules (mod_geoip). + + +Configuration +============= + +* http://svnweb.mageia.org/adm/puppet/deployment/websites/manifests/init.pp?view=markup +* http://svnweb.mageia.org/adm/puppet/deployment/websites/templates/vhost_www.conf?view=markup +* http://svnweb.mageia.org/adm/puppet/deployment/websites/templates/vhost_static.conf?view=markup + +Note that all contents under g/ are served from http://static.mageia.org/g/ (different server +config to better serve and cache static, non-text contents. + +TODO +==== + +* Permissions in var/tmp/cache/ (rw) +* short_open_tags = false +* error_log directives +* rewrite language tags (and URLs) in "zh-CN" format (and not "zh-cn") + + +Translators +=========== +Most frequent translators for website: + + - en (English) - pivot language + Editors: Romain d'Alverny (rda), Damien Lallement (damsweb) + Proofreaders: Ahmad Samir (ahmad) + + - fr (French) - second pivot language + Marianne Lombard + + - de (German): + Wolfgang Bornath, Sigrid Carrera, Sebastian Schröer (sebixmag), + Thorsten van Lil + + - el (Greek): + Dimitrios Glentadakis + + - es (Spanish): + Diego Bello + + - et (): + Marek Laane + + - fi (Finnish): + - it (Italian): + Diego Righetto (daygo) + + - lv (Latvian): + + - nb (Norwegian): + + - nl (Dutch): + + - pl (Polish): + + - pt (Portuguese): + Adjamilton Júnior + + - ro (Romanian): + Catalin Florin Russen + + - ru (Russian): + + - sl (Slovakian?): + + - tr (Turkish): + Numan Dermidögen, Attila Ontas (tarakbumba) + + - zh-cn (Chinese - PRC): + + - zh-tw (Chinese - traditional): + +Next? + - ? (Persian): Siavash Ghiasvand \ No newline at end of file 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)

', ''); ?>

-

:-(

diff --git a/en/downloads/get/lib.php b/en/downloads/get/lib.php index 472a8b7fd..975de2291 100644 --- a/en/downloads/get/lib.php +++ b/en/downloads/get/lib.php @@ -1,5 +1,13 @@ + * @license http://www.gnu.org/licenses/gpl-2.0.html GPL-2+ + * @link http://www.mageia.org/ + * */ // note, we use geographical country names @@ -32,7 +40,9 @@ $countries = array( /** * Rewrite city name in the local official language. - * @param string + * + * @param string $name city name + * * @return string */ function rewrite_city($name) @@ -46,13 +56,22 @@ function rewrite_city($name) 'Heraklion' => 'Ηράκλειο', // .gr 'Prague' => 'Praha', // .cz ); - if (array_key_exists($name, $cities)) + if (array_key_exists($name, $cities)) { return $cities[$name]; + } return $name; } -function get($s) { +/** + * Return $_GET value for $s key if it exists. + * + * @param string $s key + * + * @return mixed +*/ +function get($s) +{ return isset($_GET[$s]) ? trim($_GET[$s]) : null; } @@ -60,7 +79,13 @@ class NoProductFoundError extends Exception {} class NoMirrorFoundError extends Exception {} /** - * TODO use aliases, so that downloads asking for alpha3 get redirected to beta1 for instance? (on migration) + * TODO use aliases, so that downloads asking for alpha3 + * get redirected to beta1 for instance? (on migration) + * + * @param array $product array definition + * @param string $def_file definition file + * + * @return array */ function get_info_for_product($product, $def_file = null) { @@ -79,8 +104,8 @@ function get_info_for_product($product, $def_file = null) * Return mirrors for $file. * First mirror returned is the preferred one for auto redirection. * - * @param string $file id of the file to download/find a mirror for - * @param string $locale hint for selecting a mirror + * @param string $file id of the file to download/find a mirror for + * @param string $locale hint for selecting a mirror * @param string $country hint for selecting a mirror * * @return array @@ -92,8 +117,7 @@ function get_info_for_product($product, $def_file = null) * speed * link */ -function get_mirrors_for($file, - $locale = null, $country = null) +function get_mirrors_for($file, $locale = null, $country = null) { //include '../../../lib/Downloads.php'; @@ -107,7 +131,7 @@ function get_mirrors_for($file, /** * Simplifies things. * - * @param array $product, _one_ product definition array, as returned from the definitions.ini + * @param array $product _one_ product definition array * @param boolean $torrent_preferred do we prefer to get a torrent, if available? * * @return string @@ -116,7 +140,8 @@ function get_download_link($product, $torrent_preferred = false) { if ($torrent_preferred === true && isset($product['torrent']) - && strlen($product['torrent']) > 0) { + && strlen($product['torrent']) > 0 + ) { $path = $product['torrent']; } else { diff --git a/en/index.php b/en/index.php index 184f342a4..a6ff50ec8 100644 --- a/en/index.php +++ b/en/index.php @@ -1,4 +1,6 @@ ', $l, $l); ?> - +