Output RSS feed using Calendar module

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Output RSS feed using Calendar module

Post by kermit »

Output RSS using Calendar module

Quick-n-Dirty templates for the Calendar Module which outputs a basic RSS 2.0 feed, which can then be reused on other sites or subscribed to by site visitors.

This is my first draft, there's bound to be a problem somewhere ;) but it seems to work OK here with the limited testing I've done. Note that I haven't yet had a chance to 'import' the resulting feed in anything other than the RSS capabilities of Firefox 2.

The goal is to have a single Calendar instance which can share its event listings with multiple CMSMS installations.

RSS feeds are a natural extension of a calendar system; am a bit surprised and puzzled at the lack of such a feature in anything available for CMSMS.


Step 1.  Create a new CMSMS page template, CalendarRSS20, which contains the following:

Code: Select all

<?xml version="1.0"?>
<rss version="2.0">
    <channel>
    <title>{sitename} Events</title>
    <link>{root_url}</link>
    <description>Events scheduled on the {sitename} calendar</description>
    <language>en-us</language>
    <pubDate>{modified_date format="%A, %d %b %Y %H:%M:%S %z"}</pubDate>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
{content}
    </channel>
</rss>
Advanced: you can change the title and description above if you want.

Step 2.  Create a new Calendar module template, CalendarRSSfeed, which contains the following:

Code: Select all

{foreach from=$events key=key item=event}

{if $event.event_date_start ne ''}
	{assign var=rssStartDate value=$event.event_date_start|date_format:"%D"}{* editable date format *}
{else}
	{assign var=rssStartDate value=''}
{/if}
	
{if $event.event_date_end|date_format:"%Y%m%d" gt $event.event_date_start|date_format:"%Y%m%d"}{* dont edit these formats *}
	{assign var=rssEndDate value=$event.event_date_end|date_format:"%D"}{* editable date format *}
{else}
	{assign var=rssEndDate value=''}
{/if}
	
{if $event.event_summary ne ''}
	{assign var=rssEventSummary value=$event.event_summary|escape:'html'}
{elseif $event.event_details ne''}
	{assign var=rssEventSummary value=$event.event_details|escape:'html'}
{else}
	{assign var=rssEventSummary value=''}
{/if}

    <item>
        <title>{$event.event_title}</title>
        <link>{$event.url}</link>
        <description>{if $rssStartDate ne ''}<div class="calendar-rss-date">{$rssStartDate}{if $rssEndDate ne ''} {$lang.to} {$rssEndDate}{/if}</div>{/if}{if $rssEventSummary ne ''}<div class="calendar-rss-summary">{$rssEventSummary}</div>{/if}</description>
        <guid isPermaLink="true">{$event.url}</guid>
    </item>
  
{/foreach}
Advanced: You can change some things in the above, such as date formats of ASSIGNed date variables or the output description html.


Step 3.  Create a new page that uses the above page template (Step 1), aliased as "events-rss", which contains the following content:

Code: Select all

{cms_module module='Calendar' display='upcominglist' dbupcominglisttemplate='CalendarRSSfeed' limit='25'}
Advanced: You may customize categories, output limits, etc. in the module call. Once you've tested the feed, uncheck 'show in menu' if you don't want the feed to show up in your menus.


Step 4.  If you are publishing the RSS feed on a web site, you can use the two classes in the output to help style the event listings using CSS: calendar-rss-date and calendar-rss-summary. The item description output is simply:

Code: Select all

<div class="calendar-rss-date">[[DATE]]</div><div class="calendar-rss-summary">[[SUMMARY]]</div>
where [[DATE]] is the start date (M/D/Y) if defined. the end date is appended to it (M/D/Y to M/D/Y) if it is at least one day in the future from start date. Date format in the output can be changed (see above).

where [[SUMMARY]] is either the event summary or event details (if summary field is empty)

and if either [[DATE]] or [[SUMMARY]] would be empty, that entire container is omitted from the output for that event.

It would be up to your RSS import module or script to assign a class or tag to item titles and to wrap entire items around a container for styling purposes.

Notes: Cannot do anything here about the HTML comments appended to the end of pages (including the feed output by the above) by CMSMS. Those comments are added after-the-fact by CMSMS's index.php.

Unless you keep the feed page's entry in the menu or link to it some other way, no one will know it exists, which may or may not be the desired setup. If you want a visitor's browser to 'autodiscover' the feed, add a line to your site's metadata; perhaps something like this:

Code: Select all

<link rel="alternate" type="application/rss+xml" title="{sitename} Event Calendar Feed" href="{cms_selflink href='events-rss'}" />
Testing and development environment: Calendar module v0.8.1 on CMSMS version 1.2 and 1.2.5

If you improve upon this, please reply to this post and share your goodies. ;)

EOF 05JUN08/2000CST

EDIT 06JUN08/0305CST - fixed a typo in a calendar template variable
EDIT 09JUN08/1115CST - fixed closing div tags in calendar template output

(the attachment is a text file version of this post)
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

Last edited by kermit on Mon Jun 09, 2008 5:16 pm, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
cyberman

Re: Output RSS feed using Calendar module

Post by cyberman »

Great work - thanks!
mrjamie

Re: Output RSS feed using Calendar module

Post by mrjamie »

awesome, works like a charm!
User avatar
myshko
Forum Members
Forum Members
Posts: 102
Joined: Wed Feb 07, 2007 2:36 pm

Re: Output RSS feed using Calendar module

Post by myshko »

Great stuff Kermit, I've done something similar but have different feeds setup using one template:

Step 1. Change your page template to the following:

Code: Select all


{capture assign='captured_content'}{content}{/capture}
<?xml version="1.0"?>
<rss version="2.0">
    <channel>
    <title>{sitename} - {eval var=$feed_content}</title>
    <link>{root_url}</link>
    <description>{eval var=$feed_content} from {sitename}</description>
    <language>en-us</language>
    <pubDate>{modified_date format="%A, %d %b %Y %H:%M:%S %z"}</pubDate>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	{$captured_content}
    </channel>
</rss>

This captures the {content} output and allows you to use smarty variables wthin it.

Step 2. In your content template (ie, Calendar) Add a line to set a variable defining the feed content type, News, Links, articles, events, comments...

Code: Select all


{assign var='feed_content' value=Events}

This allows you to use one page template for multiple rss feeds, for any recurring content. Just assign a different variable in each.

D
cyberman

Re: Output RSS feed using Calendar module

Post by cyberman »

deadhike wrote:

Code: Select all

{capture assign='captured_content'}{content}{/capture}
A separate capture is not needed ... content tag has an assign option too ;)

Code: Select all

{content assign='captured_content'}
User avatar
myshko
Forum Members
Forum Members
Posts: 102
Joined: Wed Feb 07, 2007 2:36 pm

Re: Output RSS feed using Calendar module

Post by myshko »

Wahey,

Sweet, thanks cyberman ;)

I use that for changing page titles also. Makes things easier.

D
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

Hi, first of all thanks for sharing your code.
I guess I've found an error, but I still cannot solve it. The links inside the feed doesn't seem to work properly, in fact they doesn't link the event page.

That's my feed:

http://www.addiopizzocatania.org/public ... events-rss

that's an event link (wrong):

http://www.addiopizzocatania.org/public ... eturnid=77

and that is the right link:

http://www.addiopizzocatania.org/public ... eturnid=66

As you can see, they differ only in cntnt01returnid parameter (77 vs 66)

This url is generated inside CalendarRSSfeed template in this line:

        {$event.url}

and the same $event.url is used inside my upcoming list template, giving me the right link. That's my upcoming list:
http://www.addiopizzocatania.org/public ... calendario

Any ideas?
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

I guess I've found a workaroung: I have to put an empty returnid inside url, but how can I do it, without modifying the Calendar Module source code?
alby

Re: Output RSS feed using Calendar module

Post by alby »

OOpabloOO wrote: I guess I've found a workaroung: I have to put an empty returnid inside url, but how can I do it, without modifying the Calendar Module source code?
Check your content because there is:


Alby
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

alby wrote:
OOpabloOO wrote: I guess I've found a workaroung: I have to put an empty returnid inside url, but how can I do it, without modifying the Calendar Module source code?
Check your content because there is:


Alby
sorry, but I don't get it... what's the problem in here? That code is generated inside the Event template:



If I don't specify the table_id parameter,  it is substituted by an auto-generated code like calendar-cntnt.... and so on, but how can be this the problem? That id is useful for something else than CSS styling?
Last edited by OOpabloOO on Sat Sep 06, 2008 11:01 pm, edited 1 time in total.
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

solved
It's a little bit dirty solution, but it works... I've just created the url by myself, toggling out the bad cntnt01returnid parameter

Inside CalendarRSSfeed, just replace:

Code: Select all

        <link>{$event.url}</link>
with

Code: Select all

<link>{root_url}/index.php?mact=Calendar,cntnt01,default,0&cntnt01event_id={$event.event_id}&cntnt01display=event&cntnt01lang=it_IT&cntnt01detailpage=</link>
If there's a better and more elegant solution, my ears are wide open  ;D
alby

Re: Output RSS feed using Calendar module

Post by alby »

OOpabloOO wrote: solved
It's a little bit dirty solution, but it works... I've just created the url by myself, toggling out the bad cntnt01returnid parameter
W3 don't valide this

Alby
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

You are tryingo to validate the wrong link.
The right one is this:

http://validator.w3.org/feed/check.cgi? ... events-rss
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm

Re: Output RSS feed using Calendar module

Post by Russ »

Nice idea, but I've always found an iCal feed is better?
OOpabloOO
New Member
New Member
Posts: 7
Joined: Sat Aug 02, 2008 6:40 pm

Re: Output RSS feed using Calendar module

Post by OOpabloOO »

Russ wrote: Nice idea, but I've always found an iCal feed is better?
Does Calendar Module support iCal? Or I have to create it by myself?
Post Reply

Return to “Tips and Tricks”