Showing Child Pages as an RSS Feed

I have a client who posts new episodes of a long running show on a new CMSMS page. They asked me if it would be possible to turn these pages into an RSS feed so that when new shows were posted (pages created), the RSS feed would show them. "No problem," I said, and merrily went on my way to figure it out.

What I've come up with already ties into the CGFeedMaker module which were using for a few other feeds on the site, so it made sense to make a feed out of this as well using the same module.

Firstly, install the CGSimpleSmarty module. It allows me to quickly get a list of all the pages that belong to a given parent. However, CGSimpleSmarty doesn't give me all the details I need. I needed to get the creation date of the page, and a URL to the page. Rather than reinventing the wheel to grab these directly from the database, I made a quick UDT that grabs the data from the Content Manager. I called it getcontentobject and the code follows:

global $gCms;
$contentops =& $gCms->GetContentOperations();

$alias = $params['alias'];

$content = $contentops->LoadContentFromAlias($alias);

if( !is_object($content) ) return '';

if( isset($params['assign']) && $params['assign'] != '' )
{
    $smarty->assign($params['assign'],$content);
    return;
}
return $content;

It basically takes a page alias, grabs the full object and assigns it to a smarty variable. Easy enough.

Next, I created a new CGFeedMaker form, called it "shows" and set the basic values for name, URL, etc. Using the default template, I chopped off the last few lines (after {literal}{news assign=junk}{/literal}) and put the following code in:

{$cgsimple->get_children('name-of-page-parent', false, 'items')}
{section name=idx loop=$items step=-1}
<item>
  {get_page_object alias=$items[idx].alias assign='content'}
  <title>{$cgsimple->get_page_title($items[idx].alias)|cms_html_entity_decode}</title>
  <link>{$content->GetUrl()}</link>
  <description>{$cgsimple->get_page_content($items[idx].alias)|trim|strip_tags}</description>
  <pubDate>{$content->GetCreationDate()|rfc_date}</pubDate>
  {capture assign='the_id'}{$items[idx].id}{$items[idx].alias}{/capture}
  <guid>{$the_id|md5}</guid>
</item>
{/section}

Because I wanted the pages to show in reverse order, I used a section tag instead of the usual foreach. This allows me to crawl through the array in reverse. Also, the guid creation is a little sketchy, but it should get the job done for our needs.