How To Publish Reviews As RSS Feeds

CUSTOMIZING RSS FEEDS -- Review Foundry Tutorial 06

Adjust Text:  a a a a
« Review Foundry User Manual   |   Tutorial Table Of Contents   |   Obtain Review Foundry »


CUSTOMIZING RSS FEEDS

Editing An RSS Feed

On occasion, after creating either a custom RSS feed or a bulk RSS feed in Review Foundry, you will discover you need to modify some aspect of the feed. Either you need information from a column not already present in the feed (discussed in the next section) or you need to change some minor aspect of the feed, such as the number of items output. To do this, simply pull up the RSS table (custom case), or the RSSThingReview table (bulk case) in the Database control panel and edit the relevant record as you would any other table record.

Be careful when editing fields in the RSS and RSSThingReview tables. For example, the RSS.file_name column is derived from the RSS.identifier column, which itself should have unique values in the table. Furthermore, there are constraints on the RSS.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 the feed entirely and recreating it from scratch.

Adding Columns To An RSS Feed

Only 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, Item.price and Item.running_time. To get that information into a feed you start by adding the column names to the exported_columns field of the RSS table (custom case), or the RSSThingReview table (bulk case). Multiple exported 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. Moreover, the XSL stylesheets are only used to format the data appearing in a feed viewed directly on your site. What about when your feed is being viewed on another site? In this case you probably have a PHP-based script that is formatting the feeds on request. This was discussed earlier, when both MagpieRSS and FoundryRSS were offered as RSS formatting options.

In the case of MagpieRSS your exported column namespace e: 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/foundry/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";
		}
	}

The same thing spelled out in the corresponding Smarty template for FoundryRSS would be this:

// somewhere inside our FoundryRSS template that formats an RSS feed...

	[% foreach from=$s.rss.channel.item item=item %]

		[%* specify a link to the source for the feed *%]

		<br/><a href="[% $item.link %]">[% $item.title %]</a><br/>

		[%* if both the price and running_time are available, print them *%]

		[% if $item.e_price && $item.e_running_time %]

			<br/>Price: $ [% $item.e_price %]
			<br/>Running Time: [% $item.e_running_time %] minutes
		[% /if %]
	[% /foreach %]

Again, notice that in the FoundryRSS case the exported columns appear with the e_ prefix as the namespace has been flattened to accomodate Smarty's adhorrence of the colon in a variable name.

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 currently no mechanism in Review Foundry to handle such extra columns).

Next Section: GOOGLE REVIEWS

« Table of Contents


Copyright © 2004 Random Mouse Software. All Rights Reserved.