Changeset 1926
- Timestamp:
- 4/16/2010 2:03:12 PM (3 years ago)
- Location:
- trunk/website/scripts
- Files:
-
- 2 edited
-
Download.php (modified) (6 diffs)
-
updates.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/website/scripts/Download.php
r1914 r1926 8 8 9 9 require_once('Database.php'); 10 require_once('Publisher.php'); 10 11 11 12 /** … … 16 17 protected $ID; 17 18 protected $Downloads; 19 protected $Superseded; 20 18 21 protected $Name; 19 22 protected $Released; 20 protected $Superseded; 23 protected $Type; 24 protected $Version; 25 protected $Publisher; 26 protected $Architecture; 27 protected $Filesize; 21 28 protected $Link; 22 29 … … 29 36 { 30 37 $pdo = new Database(); 31 $statement = $pdo->prepare('SELECT Name, Released, Superseded, Link FROM downloads WHERE DownloadID=?'); 38 $statement = $pdo->prepare('SELECT Name, Superseded, Released, Type, Version, PublisherID, 39 Architecture, Filesize, Link FROM downloads WHERE DownloadID=?'); 32 40 $statement->bindParam(1, $downloadId); 33 41 $statement->execute(); … … 35 43 //Set the name, release date and supersedence as well as the link. 36 44 $statement->bindColumn('Name', $this->Name); 45 $statement->bindColumn('Superseded', $this->Superseded); 37 46 $statement->bindColumn('Released', $this->Released); 38 $statement->bindColumn('Superseded', $this->Superseded); 47 $statement->bindColumn('Type', $this->Type); 48 $statement->bindColumn('Version', $this->Version); 49 $statement->bindColumn('PublisherID', $this->Publisher); 50 $statement->bindColumn('Architecture', $this->Architecture); 51 $statement->bindColumn('Filesize', $this->Filesize); 39 52 $statement->bindColumn('Link', $this->Link); 40 53 if ($statement->fetch() === false) … … 56 69 public function __get($name) 57 70 { 58 return $this->$name; 71 switch ($name) 72 { 73 case 'Publisher': 74 return new Publisher($this->Publisher); 75 default: 76 return $this->$name; 77 } 59 78 } 60 79 … … 76 95 default: 77 96 throw new ErrorException(sprintf('The property %s does not exist or cannot be writte to.', $name)); 97 } 98 } 99 100 /** 101 * Gets the link to the download that can be referenced publicly. 102 * 103 * @return string The URL to this download. 104 */ 105 public function GetDisplayedLink() 106 { 107 if (preg_match('/http(s{0,1}):\/\/(.*)/', $this->Link)) 108 { 109 return $this->Link; 110 } 111 else if (substr($this->Link, 0, 1) == '?') 112 { 113 return sprintf('http://%s/download.php?id=%d', $_SERVER['SERVER_NAME'], $this->ID); 114 } 115 else 116 { 117 throw new Exception('Unknown download link'); 78 118 } 79 119 } -
trunk/website/scripts/updates.php
r1763 r1926 1 1 <?php 2 require_once('Database.php'); 3 require_once('Download.php'); 4 5 /** 6 * Base class for all update lists types. 7 */ 2 8 abstract class UpdateListBase 3 9 { 10 /** 11 * Gets the version of the update list generated. 12 * 13 * @return string 14 */ 4 15 protected abstract function GetVersion(); 16 17 /** 18 * Gets the updates that the client may require. 19 * 20 * @param string $clientVersion The version string of the client. 21 * @return array An array of Download objects which will be presented to the client. 22 */ 5 23 protected abstract function GetUpdates($clientVersion); 24 25 /** 26 * Triggers the generation of the update body for the client. 27 * 28 * @param string $clientVersion The version string of the client. 29 */ 6 30 protected abstract function OutputBodyXml($clientVersion); 7 31 32 /** 33 * Generates an update list for a client with the given version string. 34 * 35 * @param string $clientVersion The version string of the client. 36 */ 8 37 public function Output($clientVersion) 9 38 { … … 22 51 protected function OutputUpdates($clientVersion) 23 52 { 24 $ query= $this->GetUpdates($clientVersion);53 $updates = $this->GetUpdates($clientVersion); 25 54 26 55 $lastItemType = null; 27 while ($row = mysql_fetch_array($query))56 foreach ($updates as $update) 28 57 { 29 if ($row['Type'] != $lastItemType) 58 //Output the closing type tag and open a new type tag for the new update type. 59 if ($update->Type != $lastItemType) 30 60 { 31 61 if ($lastItemType !== null) 32 62 printf(' </%s>' . "\n", $lastItemType); 33 printf(' <%s>' . "\n", $ row['Type']);34 $lastItemType = $ row['Type'];63 printf(' <%s>' . "\n", $update->Type); 64 $lastItemType = $update->Type; 35 65 } 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']; 66 67 //Print the download entry. 45 68 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));69 ', htmlentities($update->Name), $update->Version, htmlentities($update->Publisher->Name), $update->Architecture, 70 $update->Filesize, htmlentities($update->GetDisplayedLink())); 48 71 } 49 72 … … 68 91 { 69 92 //Prepare the list of updates 70 return mysql_query(sprintf('SELECT downloads.*, publishers.Name as PublisherName 93 $pdo = new Database(); 94 $statement = $pdo->prepare('SELECT DownloadID 71 95 FROM downloads 72 INNER JOIN publishers ON73 downloads.PublisherID=publishers.PublisherID74 96 WHERE 75 97 (Superseded = 0) AND … … 77 99 ( 78 100 (MinVersion IS NULL AND MaxVersion IS NULL) OR 79 (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR101 (MinVersion IS NULL AND MaxVersion > :Version) OR 80 102 (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR 81 (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\')103 (MinVersion <= \'%1$s\' AND MaxVersion > :Version) 82 104 ) 83 ORDER BY `Type` ASC', mysql_real_escape_string($clientVersion))); 105 ORDER BY `Type` ASC'); 106 $statement->bindParam('Version', $clientVersion); 107 $statement->execute(); 108 109 $result = array(); 110 $downloadId = null; 111 $statement->bindColumn('DownloadID', $downloadId); 112 while ($statement->fetch()) 113 $result[] = new Download($downloadId); 114 115 return $result; 84 116 } 85 117 … … 87 119 { 88 120 //Output the list of mirrors 89 $query = mysql_query('SELECT * FROM mirrors ORDER By Continent, Country, City'); 121 $pdo = new Database(); 122 $statement = $pdo->query('SELECT * FROM mirrors ORDER By Continent, Country, City'); 90 123 echo ' <mirrors> 91 124 <mirror location="(automatically decide)">http://downloads.sourceforge.net/eraser/</mirror> 92 125 '; 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>'; 126 127 $statement->bindColumn('City', $city); 128 $statement->bindColumn('Country', $country); 129 $statement->bindColumn('URL', $url); 130 while ($statement->fetch()) 131 printf(' <mirror location="%s, %s">%s</mirror>' . "\n", $city, $country, $url); 132 echo ' </mirrors>' . "\n"; 99 133 } 100 134 … … 116 150 { 117 151 //Prepare the list of updates 118 return mysql_query(sprintf('SELECT downloads.*, publishers.Name as PublisherName 152 $pdo = new Database(); 153 $statement = $pdo->prepare('SELECT DownloadID 119 154 FROM downloads 120 INNER JOIN publishers ON121 downloads.PublisherID=publishers.PublisherID122 155 WHERE 123 156 (Superseded = 0) AND … … 126 159 (`Type` <> \'build\') AND 127 160 (MinVersion IS NULL AND MaxVersion IS NULL) OR 128 (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR161 (MinVersion IS NULL AND MaxVersion > :Version) OR 129 162 (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR 130 (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\')163 (MinVersion <= \'%1$s\' AND MaxVersion > :Version) 131 164 ) OR 132 165 ( -- Nightly builds greater than our version 133 166 (`Type` = \'build\') AND 134 (Version > \'%1$s\')167 (Version > :Version) 135 168 ) 136 169 ) 137 ORDER BY `Type` ASC', mysql_real_escape_string($clientVersion))); 170 ORDER BY `Type` ASC'); 171 $statement->bindParam('Version', $clientVersion); 172 $statement->execute(); 173 174 $result = array(); 175 $downloadId = null; 176 $statement->bindColumn('DownloadID', $downloadId); 177 while ($statement->fetch()) 178 $result[] = new Download($downloadId); 179 180 return $result; 138 181 } 139 182
Note: See TracChangeset
for help on using the changeset viewer.
