| 1 | <?php |
|---|
| 2 | require('../scripts/database.php'); |
|---|
| 3 | |
|---|
| 4 | $action = $_GET['action']; |
|---|
| 5 | $version = $_GET['version']; |
|---|
| 6 | if (empty($action) || empty($version) || !eregi('([0-9]+).([0-9]+).([0-9]+).([0-9]+)', $version)) |
|---|
| 7 | exit; |
|---|
| 8 | |
|---|
| 9 | header('content-type: application/xml'); |
|---|
| 10 | echo '<?xml version="1.0"?> |
|---|
| 11 | <updateList version="1.0">' . "\n"; |
|---|
| 12 | |
|---|
| 13 | //Output the list of mirrors |
|---|
| 14 | $query = mysql_query('SELECT * FROM mirrors ORDER By Continent, Country, City'); |
|---|
| 15 | echo ' <mirrors> |
|---|
| 16 | <mirror location="(automatically decide)">http://downloads.sourceforge.net/eraser/</mirror>' . "\n"; |
|---|
| 17 | while ($row = mysql_fetch_array($query)) |
|---|
| 18 | { |
|---|
| 19 | printf(' <mirror location="%s, %s">%s</mirror>' . "\n", $row['City'], $row['Country'], |
|---|
| 20 | $row['URL']); |
|---|
| 21 | } |
|---|
| 22 | echo ' </mirrors>'; |
|---|
| 23 | |
|---|
| 24 | //Prepare the list of updates |
|---|
| 25 | $query = mysql_query(sprintf('SELECT downloads.*, publishers.Name as PublisherName |
|---|
| 26 | FROM downloads |
|---|
| 27 | INNER JOIN publishers ON |
|---|
| 28 | downloads.PublisherID=publishers.PublisherID |
|---|
| 29 | WHERE |
|---|
| 30 | (MinVersion IS NULL AND MaxVersion IS NULL) OR |
|---|
| 31 | (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR |
|---|
| 32 | (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR |
|---|
| 33 | (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\') |
|---|
| 34 | ORDER BY `Type` ASC', $version)); |
|---|
| 35 | |
|---|
| 36 | $lastItemType = null; |
|---|
| 37 | while ($row = mysql_fetch_array($query)) |
|---|
| 38 | { |
|---|
| 39 | if ($row['Type'] != $lastItemType) |
|---|
| 40 | { |
|---|
| 41 | if ($lastItemType !== null) |
|---|
| 42 | printf(' </%s>' . "\n", $lastItemType); |
|---|
| 43 | printf(' <%s>' . "\n", $row['Type']); |
|---|
| 44 | $lastItemType = $row['Type']; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | //Get the link to the download. We got three forms, relative, absolute and query. |
|---|
| 48 | //Relative links are mirrored by SF. |
|---|
| 49 | //Absolute links... are absolute links. |
|---|
| 50 | //Query links are prefixed with ?, they are handled by download.php on the Eraser website. |
|---|
| 51 | if (substr($row['Link'], 0, 1) == '?') |
|---|
| 52 | $link = $_SERVER['SERVER_NAME'] . '/download.php?id=' . $row['DownloadID']; |
|---|
| 53 | else |
|---|
| 54 | $link = $row['Link']; |
|---|
| 55 | printf(' <item name="%s" version="%s" publisher="%s" architecture="%s" filesize="%d">%s</item> |
|---|
| 56 | ', htmlentities($row['Name']), $row['Version'], htmlentities($row['PublisherName']), $row['Architecture'], |
|---|
| 57 | $row['Filesize'], htmlentities($link)); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | if (!empty($lastItemType)) |
|---|
| 61 | printf(' </%s>' . "\n", $lastItemType); |
|---|
| 62 | echo '</updateList> |
|---|
| 63 | '; |
|---|
| 64 | ?> |
|---|