How To Publish Reviews As RSS Feeds
|
|
« Red Queen User Manual
|
Tutorial Table Of Contents
|
Obtain Red Queen »
CUSTOMIZING RSS FEEDSEditing An RSS FeedOn occasion, after creating an RSS feed in Red Queen, you will discover you need to modify some aspect of it. To do this, simply pull up the RSS table in the Database control panel and edit the relevant record as you would any other table record. Your changes will be reflected in the feed the next time the feed is updated (either via a cron job that runs the rss_reviews.pl script in the /admin directory, or by deactivating and reactivating the feed). Be careful when editing fields. For example, the file_name column is derived from the identifier column which itself should have unique values in the table. Furthermore, there are constraints on the population_method column (so avoid changing that unless you know what you are doing). The best advice here is to stick to trivial changes only. If you need to make any major change to a feed, consider deleting it entirely and recreating from scratch. Adding Columns To An RSS FeedOnly those columns that are required to create a feed are pulled from the database. But this does not mean you cannot add extra information to a feed. For example, suppose that you had added two custom columns to your Item table to hold the price and running time (in minutes) of a DVD. These columns are named, say, price and running_time. To get that information into a feed you start by adding the column names to the exported_columns variable of an RSS feed (multiple columns should be separated by whitespace). When exported columns are defined in an RSS feed they appear in the feed under the e namespace. This means the information cannot be confused with the variables in the default namespace. So you might see something like the following in an individual <item> in the feed: <e:price>19.95</e:price> <e:running_time>94</e:running_time> Using your parsing method of choice you can extract this pricing and movie length information and add it to your reformatted feed. Dealing with namespaces does complicate life a little, however. If you are using XSL to format the feed you will need to do something like this: <!-- to select the exported price column --> <xsl:apply-templates select="*[local-name()='price']" /> <!-- note that we handle the namespace issue by using * which actually selects the 'price' variable from ANY namespace. then to print the price value... --> <xsl:template match="*[local-name()='price']"> <xsl:apply-templates /> </xsl:template> XSL formatting can easily get a lot more complicated than what has been shown above, so you might prefer to tackle the problem of customization using the PHP-based MagpieRSS parser. In this case your e namespace becomes an array from which the various components can be pulled out:
// somewhere inside our MagpieRSS PHP script that parses an RSS feed...
$url = 'http://www.mydomain.com/some/path/to/redqueen/rss/some_named_rss_feed.xml';
$rss = fetch_rss( $url );
foreach ($rss->items as $item)
{
// specify a link to the source for the feed
$href = $item['link'];
$title = $item['title'];
echo "<br/><a href=\"$href\">$title</a><br/>";
// if both the price and running_time are available, print them
$e = $item['e'];
if ( isset( $e['price'] ) && isset( $e['running_time'] ) )
{
$price = $e['price'];
$running_time = $e['running_time'];
echo "<br/>Price: \$ $price";
echo "<br/>Running Time: $running_time minutes";
}
}
Note that this discussion of exported, or custom, columns refers only to extra columns that you might add to the Item, Member or Supplier tables. You cannot add custom columns to the Review table and have them show up in your RSS feeds (the reason is that there is no mechanism in Red Queen to handle such extra columns). Next Section: GOOGLE REVIEWS Copyright © 2004 Random Mouse Software. All Rights Reserved. | |||||||||