From 2572073a7ec5d63bd9fcc614d1947e0ede8f8170 Mon Sep 17 00:00:00 2001 From: Romain d'Alverny Date: Fri, 11 May 2012 10:45:33 +0000 Subject: new get_download_link() --- en/downloads/get/lib.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'en/downloads/get/lib.php') diff --git a/en/downloads/get/lib.php b/en/downloads/get/lib.php index 5217153f0..472a8b7fd 100644 --- a/en/downloads/get/lib.php +++ b/en/downloads/get/lib.php @@ -62,9 +62,11 @@ class NoMirrorFoundError extends Exception {} /** * TODO use aliases, so that downloads asking for alpha3 get redirected to beta1 for instance? (on migration) */ -function get_info_for_product($product) +function get_info_for_product($product, $def_file = null) { - $defs = parse_ini_file('definitions.ini', true); + $def_file = is_null($def_file) ? 'definitions.ini' : $def_file; + + $defs = parse_ini_file($def_file, true); if (array_key_exists($product, $defs)) { return $defs[$product]; @@ -93,11 +95,33 @@ function get_info_for_product($product) function get_mirrors_for($file, $locale = null, $country = null) { - include '../../../lib/Downloads.php'; + //include '../../../lib/Downloads.php'; $mirrors = Downloads::get_all_mirrors(); $wsd = new Downloads(); $one = $wsd->prepare_download(true, $country); return array($one, $mirrors); +} + +/** + * Simplifies things. + * + * @param array $product, _one_ product definition array, as returned from the definitions.ini + * @param boolean $torrent_preferred do we prefer to get a torrent, if available? + * + * @return string +*/ +function get_download_link($product, $torrent_preferred = false) +{ + if ($torrent_preferred === true + && isset($product['torrent']) + && strlen($product['torrent']) > 0) { + + $path = $product['torrent']; + } else { + $path = $product['path'] . '/' . $product['file']; + } + + return '$MIRROR/' . $path; } \ No newline at end of file -- cgit v1.2.1