cleanup rss2.php

- removed excessive string catenation, replaced with variable substitution
- consolidated http/https protocol checks
- simplified host header parse (centralized)
- moved cache file to /tmp, to remove need to custom permission directory in webdir

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
elij 2009-09-27 16:43:34 -07:00 committed by Loui Chang
parent 907f27cb82
commit a8bf1108b4
2 changed files with 12 additions and 21 deletions

View file

@ -1,24 +1,26 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR . '../lang'); set_include_path(get_include_path() . PATH_SEPARATOR . '../lib' . PATH_SEPARATOR . '../lang');
include_once("aur.inc"); include_once("aur.inc");
include_once("feedcreator.class.php"); include_once("feedcreator.class.php");
#detect prefix
$protocol = $_SERVER["HTTPS"]=='on' ? "https" : "http";
$host = $_SERVER['HTTP_HOST'];
#If there's a cached version <1hr old, won't regenerate now #If there's a cached version <1hr old, won't regenerate now
$rss = new UniversalFeedCreator(); $rss = new UniversalFeedCreator();
$rss->useCached("RSS2.0", "xml/newestpkg.xml", 1800); $rss->useCached("RSS2.0", "/tmp/aur-newestpkg.xml", 1800);
#All the general RSS setup #All the general RSS setup
$rss->title = "AUR Newest Packages"; $rss->title = "AUR Newest Packages";
$rss->description = "The latest and greatest packages in the AUR"; $rss->description = "The latest and greatest packages in the AUR";
$rss->link = "http" . ($_SERVER["HTTPS"]=='on'?"s":"") . "://".$_SERVER['HTTP_HOST']; $rss->link = "${protocol}://{$host}";
$rss->syndicationURL = "http" . ($_SERVER["HTTPS"]=='on'?"s":"") . "://".$_SERVER['HTTP_HOST']."/rss2.php"; $rss->syndicationURL = "{$protocol}://{$host}/rss2.php";
$image = new FeedImage(); $image = new FeedImage();
$image->title = "AUR"; $image->title = "AUR";
$image->url = "http" . ($_SERVER["HTTPS"]=='on'?"s":"") . "://".$_SERVER['HTTP_HOST']."/images/AUR-logo-80.png"; $image->url = "{$protocol}://{$host}/images/AUR-logo-80.png";
$image->link = "http" . ($_SERVER["HTTPS"]=='on'?"s":"") . "://".$_SERVER['HTTP_HOST']; $image->link = $rss->link;
$image->description = "AUR Newest Packages Feed"; $image->description = "AUR Newest Packages Feed";
$rss->image = $image; $rss->image = $image;
@ -30,26 +32,17 @@ $q.= "ORDER BY SubmittedTS DESC ";
$q.= "LIMIT 0 , 20"; $q.= "LIMIT 0 , 20";
$result = db_query($q, $dbh); $result = db_query($q, $dbh);
$protocol = 'http';
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')
$protocol = 'https';
while ($row = mysql_fetch_assoc($result)) { while ($row = mysql_fetch_assoc($result)) {
$item = new FeedItem(); $item = new FeedItem();
$item->title = $row["Name"]; $item->title = $row["Name"];
$item->link = "{$protocol}://{$host}/packages.php?ID={$row["ID"]}";
$item->link = $protocol . "://".$_SERVER['HTTP_HOST'] .
'/packages.php?ID='.$row["ID"];
$item->description = $row["Description"]; $item->description = $row["Description"];
$item->date = intval($row["SubmittedTS"]); $item->date = intval($row["SubmittedTS"]);
$item->source = $protocol . "://".$_SERVER['HTTP_HOST']; $item->source = "{$protocol}://{$host}";
$item->author = username_from_id($row["MaintainerUID"]); $item->author = username_from_id($row["MaintainerUID"]);
$rss->addItem($item); $rss->addItem($item);
} }
#save it so that useCached() can find it #save it so that useCached() can find it
$rss->saveFeed("RSS2.0","xml/newestpkg.xml",true); $rss->saveFeed("RSS2.0","/tmp/aur-newestpkg.xml",true);

View file

@ -1,2 +0,0 @@
This is where the server will create the RSS feed file.
This directory should be writeable by the the webserver.