First working version of RSS, with caching.
git-svn-id: svn://10.0.0.236/trunk@188440 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -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;
|
||||
?>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<link>https://{$config.host}/{$config.webpath}</link>
|
||||
<description>Mozilla Addons is the place to get extensions and themes for your Mozilla applications.</description>
|
||||
<language>en-US</language>
|
||||
<copyright>{$smarty.now|date_format:%Y} The Mozilla Foundation</copyright>
|
||||
<copyright>{$smarty.now|date_format:'%Y'} The Mozilla Foundation</copyright>
|
||||
<lastBuildDate>{$smarty.now|date_format}</lastBuildDate>
|
||||
<ttl>120</ttl>
|
||||
<image>
|
||||
@@ -15,10 +15,10 @@
|
||||
<height>16</height>
|
||||
</image>
|
||||
|
||||
{foreach item=row}
|
||||
{foreach item=row from=$data}
|
||||
<item>
|
||||
<pubDate>{$row.dateupdated}</pubDate>
|
||||
<title>{$row.title} {$row.version} for {$app} </title>
|
||||
<title>{$row.title} {$row.version} for {$row.appname} </title>
|
||||
<link>https://{$config.host}/{$config.webpath}/addon.php?id={$row.id}</link>
|
||||
<description>{$row.description|escape:html}</description>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user