Sample iTunes Feed

Overview

Building an iTunes feed is relatively straightforward in ColdFusion. The trick in FarCry Framework is knowing where to put the code. This example is taken directly from the webDU Developer Conference website.

Suitable for applications running FarCry Core 5.1+

webDU Podcast

This example is taken from the webDU Developer Conference podcast:

The site has a content type called mxSession which contains data about individual conference sessions in the agenda.

Building a Feed

A feed is essentially a collection of content items, for example conference sessions. When you are thinking of a collection of objects you should be using a "type webskin" (aka a Collection or List View). The type webskin applies to the entire content type and not just an individual instance of that type.

Type webskins do not have the standard stobj property structure. They typically start with a call to the database for a group of content items. In this example we have a query inline that grabs relevant session objectids. You may want to encapsulate such a query in a function call.

View Security

Depending on your installation, you may need to ensure that the view feediTunes.cfm is actually visible to anonymous users. By default only views prefixed with display and execute are available. You can add the view to the anonymous role by logging into the webtop. Go to ADMIN > Roles > View permissions and add the feed* prefix to the list available.

Complete Code

You Must Change the Code To Suit Your Application

Obviously you can't just grab this code and plonk it into your own site. You will need to look at the structure of the code and make changes accordingly. It's here for demonstration purposes only, and to kick start your own development.

./webskin/mxSession/feediTunes.cfm
<cfsetting enablecfoutputonly="true" /> 
<!--- @@Copyright: Copyright (c) 2009 Daemon Pty Limited. All rights reserved. --->
<!--- @@displayname: iTunes Feed --->
<!--- @@description: feeditunes --->
<!--- @@author: Geoffrey Bowers on 2009-05-29 --->

<!--- import tag libraries --->
<cfimport taglib="/farcry/core/tags/webskin" prefix="skin" />

<!--- deactivate the tray --->
<cfset request.bHideContextMenu = true />

<!--- create local objects --->
<cfset oSession = application.fapi.getContentType("mxSession") />
<cfset oSpeaker = application.fapi.getContentType("mxSpeaker") />

<!--- get relevant sessions for podcast --->
<cfquery datasource="#application.dsn#" name="qSessions" maxrows="250">
SELECT objectid FROM mxSession
WHERE status = 'approved'
AND MP3PODCAST <> ''
ORDER BY datetimelastupdated DESC
</cfquery>


<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.apple.com/itunes/store/podcaststechspecs.html -->
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
	<title>WebDU 2009</title>
	<link>http://webdu.com.au</link>
	<language>en-us</language>
	<copyright>&##x2117; &amp; &##xA9; 2009 Daemon Pty Ltd</copyright>
	<itunes:subtitle>Sessions from the mighty WebDU 2009 Conference.</itunes:subtitle>
	<itunes:author>Rob Rohan</itunes:author>
	<itunes:summary>
The premier Antipodean web technology conference, webDU encompasses a broad spectrum of 
web technologies and techniques. webDU is the must attend annual event for anyone building 
a better Internet.
	</itunes:summary>
	<description>
The premier Antipodean web technology conference, webDU encompasses a broad spectrum of
web technologies and techniques. webDU is the must attend annual event for anyone building 
a better Internet.
	</description>

	<itunes:owner>
		<itunes:name>Daemon.com.au</itunes:name>
		<itunes:email>geoff@daemon.com.au</itunes:email>
	</itunes:owner>
	
	<image>
		<url>http://s3.amazonaws.com/webdu2009/podcast144_400.jpg</url>
		<title>WebDU 2009</title><!-- should match channel title -->
		<link>http://webdu.com.au</link>
	</image>
	
	<itunes:image href="http://s3.amazonaws.com/webdu2009/podcast600_600.jpg" />

	<itunes:category text="Technology">
		<itunes:category text="Gadgets"/>
		<itunes:category text="Tech News"/>
		<itunes:category text="Software How-To"/>
	</itunes:category>
	
	<itunes:explicit>no</itunes:explicit>
	<!-- //////////////////////////////////////////////////////////////////// -->
</cfoutput>

<cfoutput query="qSessions">
	<cftry>
	<cfset stSession = osession.getdata(objectid=qSessions.objectid) />
	<cfset stSpeaker = ospeaker.getdata(objectid=stsession.aSpeakerID[1]) />
	<item>
		<title>#xmlFormat(stsession.title)#</title>
		<pubDate>#dateformat(stsession.datetimelastupdated, "dddd, dd mmmm yyyy")# 
#timeFormat(stsession.datetimelastupdated, "medium")#</pubDate>
		<enclosure url='#stsession.mp3podcast#' 
<cfif isNumeric(stsession.medialength) AND stsession.medialength gt 0>length='#round(stsession.mediaLength)#' </cfif>
type='#stsession.mediaType#' />
		<itunes:duration>#stsession.mediaDuration#</itunes:duration>
		<itunes:author>#xmlFormat(stspeaker.title)#</itunes:author>
		<guid>#stsession.mp3podcast#</guid>
	</item>
	<cfcatch>
		<!--- <cfdump var="#cfcatch#" /> --->
		<!--- suppress error in output --->
	</cfcatch>
	</cftry>
</cfoutput>

<cfoutput>

	<!-- /////////////////////////////////////////////// -->
</channel>
</rss>
</cfoutput>

<cfsetting enablecfoutputonly="false" />