Interspire Tutorials - http://www.interspire.com/content
Syndicating Content with RSS and ArticleLive
http://www.interspire.com/content/articles/47/1/Syndicating-Content-with-RSS-and-ArticleLive
By Jordie Bodlay
Published on 07/19/2006
 

Most of the news, article and blog websites on the Internet use RSS feeds to syndicate their content to users and other websites. In this article I will give you a brief introduction to RSS and what its uses are, as well as a quick guide on how to include an external RSS feed as a panel in ArticleLive.


Introduction to RSS
RSS stands for Really Simple Syndication (this is widely accepted, although another common term used is Rich Site Summary). It is an XML based standard for syndicating website content. It can be used for any type of frequently updated content, but for the most part it is used to syndicate news, articles and blogs.

We use RSS feeds on our site and also in our products. In ArticleLive NX, it’s used it to syndicate the 10 latest articles, news items and blog posts -- each a separate feed. There is also a feed for each category to display the 10 newest articles for that specific category. In the current release of ActiveKB there is a similar per category feed and for ActiveKB NX 2 (in Beta at the time of writing) we have added feeds for the 10 latest questions and the 10 most popular questions.

There are a few versions of RSS feeds that are popular among various sites. The most popular are RSS 0.91, RSS 1.0 and RSS 2.0. Our products confirm to the RSS 2.0 standard as it allows us a degree of flexibility for extra elements that the earlier standards don’t. MSDN has a great question and answer page for further information on the standards, although it can get rather technical. Mark Pilgrim on XML.com also offers an insight into the syndication standards.

Using RSS Feeds

So, you have an RSS feed link, but what can you do with it? The most common use is to add it to an RSS reader program such as Google Reader, FeedReader, Awasu and their popular online cousin BlogLines.com. Yahoo, MSN and Google also allow you to input feed URL's for your own customized homepage with news stories and articles from websites of your own choosing.

But what if you are a webmaster and want to display a feed from another site on your own web site, or give instructions for how other webmasters can do the same using your feed? One answer is Magpie RSS. This amazing open source PHP application can be up and running in just a few minutes and can save you a lot of hassle if you're considering building your own RSS parser. Magpie RSS is available for download from Sourceforge.

Once downloaded, all you need to do is place the program in a sub folder on your web site (purely to be tidy, it can be placed anywhere). Then run a simple bit of PHP code on your web page:

<?php

include_once('magpierss/rss_fetch.inc');
$rss = fetch_rss("http://www.interspire.com/content/articlerss.php");
echo "<h3>" . $rss->channel['title'] . "</h3><p>";
echo "<ul>";
foreach ($rss->items as $item) {
            $href = $item['link'];
            $title = $item['title'];
            echo '<li><a href="'.$href.'">'.$title.'</a></li>';
}
echo "</ul>";
?>

The above example grabs our article RSS feed and formats it into a bullet point list. You can copy and paste that code, change the URL to another feed and it will work straight away.


Using an RSS Feed as a Panel in ArticleLive

I will now demonstrate how to include a feed as a panel in ArticleLive. The first step is to include the Magpie RSS files. Open up your init.php file (in the base directory of ArticleLive) and locate this code near the top:

ob_start();

Place the include after this line, so it looks like this:

ob_start();
include_once('magpierss/rss_fetch.inc');

Now that we have included the files, the functions will be available to use throughout the entire application. This also means that we can include multiple feeds without including the file more than once.

We now need to create a new panel file set. Navigate to /templates/{your template}/Panels/ and create 2 new files; InterspireArticles.html and InterspireArticles.php (the file names should be exact).

InterspireArticles.php will look like this:

<?php
/*******************************************\
**
*Generic ArticleLive Panel Parsing Class*
**
\*******************************************/
$panelClass = "AL_INTERSPIREARTICLES_PANEL";
if(!class_exists($panelClass)){
    CLASS AL_INTERSPIREARTICLES_PANEL
    {
        var $_htmlFile;
        function AL_INTERSPIREARTICLES_PANEL($HTMLFile)
        {
            $this->_htmlFile = $HTMLFile;
            $tmp = explode("/",$HTMLFile);
            $lastkey = sizeof($tmp)-1;
            $filename = str_replace(".html","",$tmp[$lastkey]);
            $this->_filename = $filename;
        }
        function ParsePanel()
        {
            $htmlPanelData = "";
            $parsedPanelData = "";
            if(file_exists($this->_htmlFile))
            {
                if($fp = @fopen($this->_htmlFile, "rb"))
                {
                    while(!feof($fp))
                    $htmlPanelData .= fgets($fp, 4096);
                    @fclose($fp);
                }
            }
            $rss = fetch_rss("http://www.interspire.com/content/articlerss.php");
            $GLOBALS['title'] = $rss->channel['title'];
            foreach ($rss->items as $item) {
                $href = $item['link'];
                $title = $item['title'];
                $GLOBALS['ArticleList'] .='<div class="ListItem"><a href="'.$href.'" target="_blank">'.$title.'</a></div>';
            }
            $parsedPanelData = $GLOBALS["AL_CLASS_TEMPLATE"]->ParseGL($htmlPanelData);
            return $parsedPanelData;
        }
    }
}
?>

Our InterspireArticles.html file will have the following content:

<table class="Panel RootArticleCategoriesPanel" id="Table1">
      <tr>
            <td class="Heading">
                  %%GLOBAL_title%%
            </td>
      </tr>
      <tr>
            <td style="padding:10px  0px  10px  0px ; ">
                  %%GLOBAL_ArticleList%%
            </td>
      </tr>
</table>

Now all we need to do is open up the directory /templates/{your template}/ and place the placeholder %%Panel.InterspireArticles%% in the appropriate place in the panels HTML code.

We want it to appear on the top of the right hand side, so we will place it before %%Panel.DefaultRightColumnPanel%% in all the main .html files such as Default.html, Articles.html, Blogs.html etc.

Note: The placeholder is determined by the File name. If you created a panel with the file names MyPanel.php and MyPanel.html, then you would use %%Panel.MyPanel%% as the placeholder.

You panel will now show up with the links straight from our the feed. This can be used for any RSS feed and allows your site to be updated with the latest news and information automatically.


Conclusion

As you can see, RSS and syndication in general are powerful tools for displaying content. Because the information is readily available in a standard format, it requires very little effort to have new content and information at your finger tips. If you are using an RSS reader program or website, this standard allows you to gather headlines and content from a wide variety of sites all into one convenient location.

There are many pages with further information on the RSS standard; a simple Google search will return millions of pages as well as information on competing syndicate standards such as Atom.

Content is the king of the Internet, and the race is on for websites to get their content out there and one of the most efficient and effective methods is through syndication.