| 1 | <?php |
|---|
| 2 | abstract class UpdateListBase |
|---|
| 3 | { |
|---|
| 4 | protected abstract function GetVersion(); |
|---|
| 5 | protected abstract function GetDownloads($clientVersion); |
|---|
| 6 | protected abstract function OutputBodyXml($clientVersion); |
|---|
| 7 | |
|---|
| 8 | public function Output($clientVersion) |
|---|
| 9 | { |
|---|
| 10 | $this->OutputHeader(); |
|---|
| 11 | $this->OutputBodyXml($clientVersion); |
|---|
| 12 | $this->OutputFooter(); |
|---|
| 13 | } |
|---|
| 14 | |
|---|
| 15 | private function OutputHeader() |
|---|
| 16 | { |
|---|
| 17 | printf('<?xml version="1.0"?> |
|---|
| 18 | <updateList version="%s"> |
|---|
| 19 | ', $this->GetVersion()); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | protected function OutputDownloads($clientVersion) |
|---|
| 23 | { |
|---|
| 24 | $query = $this->GetDownloads($clientVersion); |
|---|
| 25 | |
|---|
| 26 | $lastItemType = null; |
|---|
| 27 | while ($row = mysql_fetch_array($query)) |
|---|
| 28 | { |
|---|
| 29 | if ($row['Type'] != $lastItemType) |
|---|
| 30 | { |
|---|
| 31 | if ($lastItemType !== null) |
|---|
| 32 | printf(' </%s>' . "\n", $lastItemType); |
|---|
| 33 | printf(' <%s>' . "\n", $row['Type']); |
|---|
| 34 | $lastItemType = $row['Type']; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | //Get the link to the download. We got three forms, relative, absolute and query. |
|---|
| 38 | //Relative links are mirrored by SF. |
|---|
| 39 | //Absolute links... are absolute links. |
|---|
| 40 | //Query links are prefixed with ?, they are handled by download.php on the Eraser website. |
|---|
| 41 | if (substr($row['Link'], 0, 1) == '?') |
|---|
| 42 | $link = 'http://' . $_SERVER['SERVER_NAME'] . '/download.php?id=' . $row['DownloadID']; |
|---|
| 43 | else |
|---|
| 44 | $link = $row['Link']; |
|---|
| 45 | printf(' <item name="%s" version="%s" publisher="%s" architecture="%s" filesize="%d">%s</item> |
|---|
| 46 | ', htmlentities($row['Name']), $row['Version'], htmlentities($row['PublisherName']), $row['Architecture'], |
|---|
| 47 | $row['Filesize'], htmlentities($link)); |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | if (!empty($lastItemType)) |
|---|
| 51 | printf(' </%s>' . "\n", $lastItemType); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | private function OutputFooter() |
|---|
| 55 | { |
|---|
| 56 | printf('</updateList>'); |
|---|
| 57 | } |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | class UpdateList1 extends UpdateListBase |
|---|
| 61 | { |
|---|
| 62 | protected function GetVersion() |
|---|
| 63 | { |
|---|
| 64 | return "1.0"; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | protected function GetDownloads($clientVersion) |
|---|
| 68 | { |
|---|
| 69 | //Prepare the list of updates |
|---|
| 70 | return mysql_query(sprintf('SELECT downloads.*, publishers.Name as PublisherName |
|---|
| 71 | FROM downloads |
|---|
| 72 | INNER JOIN publishers ON |
|---|
| 73 | downloads.PublisherID=publishers.PublisherID |
|---|
| 74 | WHERE |
|---|
| 75 | (Superseded = 0) AND |
|---|
| 76 | (`Type` <> \'build\') AND |
|---|
| 77 | ( |
|---|
| 78 | (MinVersion IS NULL AND MaxVersion IS NULL) OR |
|---|
| 79 | (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR |
|---|
| 80 | (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR |
|---|
| 81 | (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\') |
|---|
| 82 | ) |
|---|
| 83 | ORDER BY `Type` ASC', mysql_real_escape_string($clientVersion))); |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | private function OutputMirrors() |
|---|
| 87 | { |
|---|
| 88 | //Output the list of mirrors |
|---|
| 89 | $query = mysql_query('SELECT * FROM mirrors ORDER By Continent, Country, City'); |
|---|
| 90 | echo ' <mirrors> |
|---|
| 91 | <mirror location="(automatically decide)">http://downloads.sourceforge.net/eraser/</mirror> |
|---|
| 92 | '; |
|---|
| 93 | while ($row = mysql_fetch_array($query)) |
|---|
| 94 | { |
|---|
| 95 | printf(' <mirror location="%s, %s">%s</mirror>' . "\n", $row['City'], $row['Country'], |
|---|
| 96 | $row['URL']); |
|---|
| 97 | } |
|---|
| 98 | echo ' </mirrors>'; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | protected function OutputBodyXml($clientVersion) |
|---|
| 102 | { |
|---|
| 103 | $this->OutputMirrors(); |
|---|
| 104 | $this->OutputDownloads($clientVersion); |
|---|
| 105 | } |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | class UpdateList1_1 extends UpdateListBase |
|---|
| 109 | { |
|---|
| 110 | protected function GetVersion() |
|---|
| 111 | { |
|---|
| 112 | return "1.1"; |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | protected function GetDownloads($clientVersion) |
|---|
| 116 | { |
|---|
| 117 | //Prepare the list of updates |
|---|
| 118 | return mysql_query(sprintf('SELECT downloads.*, publishers.Name as PublisherName |
|---|
| 119 | FROM downloads |
|---|
| 120 | INNER JOIN publishers ON |
|---|
| 121 | downloads.PublisherID=publishers.PublisherID |
|---|
| 122 | WHERE |
|---|
| 123 | (Superseded = 0) AND |
|---|
| 124 | ( |
|---|
| 125 | ( -- Program Updates |
|---|
| 126 | (`Type` <> \'build\') AND |
|---|
| 127 | (MinVersion IS NULL AND MaxVersion IS NULL) OR |
|---|
| 128 | (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR |
|---|
| 129 | (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR |
|---|
| 130 | (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\') |
|---|
| 131 | ) OR |
|---|
| 132 | ( -- Nightly builds greater than our version |
|---|
| 133 | (`Type` = \'build\') AND |
|---|
| 134 | (Version > \'%1$s\') |
|---|
| 135 | ) |
|---|
| 136 | ) |
|---|
| 137 | ORDER BY `Type` ASC', mysql_real_escape_string($clientVersion))); |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | protected function OutputBodyXml($clientVersion) |
|---|
| 141 | { |
|---|
| 142 | $this->OutputDownloads($clientVersion); |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | ?> |
|---|