diff --git a/mozilla/webtools/addons/public/htdocs/rss.php b/mozilla/webtools/addons/public/htdocs/rss.php index ddc0ac15b70..aefe6979784 100644 --- a/mozilla/webtools/addons/public/htdocs/rss.php +++ b/mozilla/webtools/addons/public/htdocs/rss.php @@ -9,6 +9,59 @@ /** * Pull our input params. */ +$rssapp = (!empty($_GET['app']) && ctype_alpha($_GET['app'])) ? $_GET['app'] : null; +switch (strtolower($rssapp)) { + case 'mozilla': + $clean['app'] = 'mozilla'; + break; + case 'thunderbird': + $clean['app'] = 'thunderbird'; + break; + case 'firefox': + default: + $clean['app'] = 'firefox'; + break; +} + +$rsstype = !empty($_GET['type']) && ctype_alpha($_GET['type']) ? $_GET['type'] : null; +switch (strtolower($rsstype)) { + case 't': + $clean['type'] = 't'; + break; + case 'e': + default: + $clean['type'] = 'e'; + break; +} + +$rsslist = !empty($_GET['list']) && ctype_alpha($_GET['list']) ? $_GET['list'] : null; +switch (strtolower($rsslist)) { + case 'popular': + $rssOrderBy = 'm.downloadcount desc, m.totaldownloads desc, m.rating desc, m.dateupdated desc, m.name asc'; + break; + case 'updated': + $rssOrderBy = 'm.dateupdated desc, m.name asc'; + break; + case 'rated': + $rssOrderBy = 'm.rating desc, m.downloadcount desc, m.name asc'; + break; + case 'newest': + default: + /** + * @TODO change this to dateapproved once the db has this in it. + */ + $rssOrderBy = 'm.dateupdateddesc, m.name asc'; + break; +} + +// Generate our cache_id. +$cache_id = md5($rssapp.$rsstype.$rsslist); + +unset($rssapp); +unset($rsstype); +unset($rsslist); + + /** * CHECK CACHE @@ -18,14 +71,63 @@ */ $tpl = new AMO_Smarty(); -// Set our cache timeout to 1 hour. -$tpl->caching = true; -$tpl->cache_timeout = 3600; +// Set our cache timeout to 2 hours, which is reasonable. +$tpl->caching = 0; +$tpl->cache_timeout = 7200; // Determine our cache_id based on the RSS feed's arguments. if ($tpl->is_cached('rss.tpl',$cache_id)) { + header('Content-Type: text/xml; charset=utf-8'); $tpl->display('rss.tpl',$cache_id); exit; } + +// If we get here, we're going to have to pull DB contents. +require_once('includes.php'); + +// Build query for RSS data. +$sql['app'] = $clean['app']; // Already ok for sql, type was checked (alpha). +$sql['type'] = $clean['type']; // Already ok for sql, type was checked (alpha). + +$_rssSql = " + SELECT DISTINCT + m.id, + m.name as title, + m.type, + m.description, + v.version, + v.vid, + v.dateupdated, + a.appname + FROM + main m + INNER JOIN + version v + ON + v.id = m.id + INNER JOIN + applications a + ON + a.appid = v.appid + WHERE + v.approved = 'yes' AND + a.appname = '{$sql['app']}' AND + m.type = '{$sql['type']}' + GROUP BY + m.id + ORDER BY + {$rssOrderBy} + LIMIT 0,10 +"; + +// Get data, then set the results. +$db->query($_rssSql,SQL_ALL,SQL_ASSOC); +$_rssData = $db->record; +$tpl->assign('data',$_rssData); + +// Set our content-type and spit it out. +header('Content-Type: text/xml; charset=utf-8'); +$tpl->display('rss.tpl',$cache_id); +exit; ?> diff --git a/mozilla/webtools/addons/public/tpl/rss.tpl b/mozilla/webtools/addons/public/tpl/rss.tpl index 5e2a8e2857f..59d653218ba 100644 --- a/mozilla/webtools/addons/public/tpl/rss.tpl +++ b/mozilla/webtools/addons/public/tpl/rss.tpl @@ -4,7 +4,7 @@ https://{$config.host}/{$config.webpath} Mozilla Addons is the place to get extensions and themes for your Mozilla applications. en-US - {$smarty.now|date_format:%Y} The Mozilla Foundation + {$smarty.now|date_format:'%Y'} The Mozilla Foundation {$smarty.now|date_format} 120 @@ -15,10 +15,10 @@ 16 -{foreach item=row} +{foreach item=row from=$data} {$row.dateupdated} - {$row.title} {$row.version} for {$app} + {$row.title} {$row.version} for {$row.appname} https://{$config.host}/{$config.webpath}/addon.php?id={$row.id} {$row.description|escape:html}