Changeset 1761


Ignore:
Timestamp:
2/8/2010 5:24:47 AM (2 years ago)
Author:
lowjoel
Message:

Separate the downloads list printing code into a separate UpdateList? class

Location:
trunk/website/scripts
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/website/scripts/updates/index.php

    r1461 r1761  
    11<?php 
    22require('../database.php'); 
     3require('../updates.php'); 
    34 
    45$action = $_GET['action']; 
    56$version = $_GET['version']; 
    6 if (empty($action) || empty($version) || !eregi('([0-9]+).([0-9]+).([0-9]+).([0-9]+)', $version)) 
     7$versionMatch = array(); 
     8if (empty($action) || empty($version) || !preg_match('/([0-9]+).([0-9]+).([0-9]+).([0-9]+)/', $version, $versionMatch)) 
    79    exit; 
    810 
    911header('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         (Superseded = 0) AND 
    31         (`Type` <> \'build\') AND 
    32         ( 
    33             (MinVersion IS NULL AND MaxVersion IS NULL) OR 
    34             (MinVersion IS NULL AND MaxVersion > \'%1$s\') OR 
    35             (MinVersion <= \'%1$s\' AND MaxVersion IS NULL) OR 
    36             (MinVersion <= \'%1$s\' AND MaxVersion > \'%1$s\') 
    37         ) 
    38     ORDER BY `Type` ASC', $version)); 
    39  
    40 $lastItemType = null; 
    41 while ($row = mysql_fetch_array($query)) 
    42 { 
    43     if ($row['Type'] != $lastItemType) 
    44     { 
    45         if ($lastItemType !== null) 
    46             printf('    </%s>' . "\n", $lastItemType); 
    47         printf('    <%s>' . "\n", $row['Type']); 
    48         $lastItemType = $row['Type']; 
    49     } 
    50  
    51     //Get the link to the download. We got three forms, relative, absolute and query. 
    52     //Relative links are mirrored by SF. 
    53     //Absolute links... are absolute links. 
    54     //Query links are prefixed with ?, they are handled by download.php on the Eraser website. 
    55     if (substr($row['Link'], 0, 1) == '?') 
    56         $link = 'http://' . $_SERVER['SERVER_NAME'] . '/download.php?id=' . $row['DownloadID']; 
    57     else 
    58         $link = $row['Link']; 
    59     printf('        <item name="%s" version="%s" publisher="%s" architecture="%s" filesize="%d">%s</item> 
    60 ', htmlentities($row['Name']), $row['Version'], htmlentities($row['PublisherName']), $row['Architecture'], 
    61             $row['Filesize'], htmlentities($link)); 
    62 } 
    63  
    64 if (!empty($lastItemType)) 
    65     printf('    </%s>' . "\n", $lastItemType); 
    66 echo '</updateList> 
    67 '; 
     12$downloadsList = intval($versionMatch[2]) == 0 ? new UpdateList1() : new UpdateList1_1(); 
     13$downloadsList->Output($version); 
    6814?> 
Note: See TracChangeset for help on using the changeset viewer.