Aarrgghh!!

One guy's take on the web, programming, cigars, politics, Philadelphia, and whatever else comes to mind.

RSS 2.0 Creator

Explanation

I recently went looking for a ColdFusion RSS creator. I couldn't find anything stand-alone that just did it, so I made it. Hopefully, someone else can use it, or tell me where this was already done.

I worked off of the RSS 2.0 specification, and omitted the textInput, rating, or cloud elements. All the rest are there. You instatiate the CFC, set its base information, add elements to it, and return it as a variable. From there you can do whatever you like with it, right it to a flat file, return directly to the user, etc.

Sample Usage

This sample will yield this result: Sample Feed.

		


1: <!--- Example Code for Calling the RSS.cfc component. --->
2: <cfsetting showdebugoutput="no" />
3: 
4: 
5: <!--- Create and initialize RSS cfc as an Object --->
6: <cfobject component="rss" name="rssObj" />
7: <cfinvoke component="#rssObj#" method="init" />
8: 
9: <!--- Create the main feed details. --->
10: <cfinvoke component="#rssObj#" method="create">
11: 	<cfinvokeargument name="title" value="Aarrgghh!! Test Feed"/>
12: 	<cfinvokeargument name="description" value="Just a test feed to show off Rss creation."/>
13: 	<cfinvokeargument name="link" value="http://www.numtopia.com/terry/"/>
14: </cfinvoke>
15: 
16: <!--- Add an item to the feed. --->
17: <cfinvoke component="#rssObj#" method="addItem">
18: 	<cfinvokeargument name="title" value="Craig's Life in 19 Inches"/>
19: 	<cfinvokeargument name="description" value="<p>Did you get your tickets to My Life in 19 Inches</a> yet?</p>"/>
20: 	<cfinvokeargument name="link" value="http://www.numtopia.com/terry/blog/archives/2006/07/craigs_life_in_19_inches.cfm"/>
21: 	<cfinvokeargument name="author" value="terry@numtopia.com (Terrence Ryan)"/>
22: 	<cfinvokeargument name="pubDate" value="#Now()#"/>
23: 	<cfinvokeargument name="guid" value="http://www.numtopia.com/terry/blog/archives/2006/07/craigs_life_in_19_inches.cfm"/>
24: </cfinvoke>
25: 
26: <!--- Add categories to that item.  --->
27: <cfinvoke component="#rssObj#" method="addCategoryToItem">
28: 	<cfinvokeargument name="category" value="Philadelphia"/>
29: </cfinvoke>
30: 
31: <cfinvoke component="#rssObj#" method="addCategoryToItem">
32: 	<cfinvokeargument name="category" value="Entertainment"/>
33: </cfinvoke>
34: 
35: <!--- Add another item.  --->
36: <cfinvoke component="#rssObj#" method="addItem">
37: 	<cfinvokeargument name="title" value="Life is Good"/>
38: 	<cfinvokeargument name="description" value="<p>I'm sitting in Mahogany, a cigar bar in Philadelphia, smoking a cigar, enjoying free WiFi and learning Model-Glue. </p>"/>
39: 	<cfinvokeargument name="link" value="http://www.numtopia.com/terry/blog/archives/2006/06/life_is_good.cfm"/>
40: 	<cfinvokeargument name="author" value="terry@numtopia.com (Terrence Ryan)"/>
41: 	<cfinvokeargument name="pubDate" value="#Now()#"/>
42: 	<cfinvokeargument name="guid" value="http://www.numtopia.com/terry/blog/archives/2006/06/life_is_good.cfm"/>
43: </cfinvoke>
44: 
45: <!--- Add an enclosure to that item.  --->
46: <cfinvoke component="#rssObj#" method="addEnclosureToItem">
47: 	<cfinvokeargument name="item" value="1"/>
48: 	<cfinvokeargument name="url" value="http://www.scripting.com/mp3s/weatherReportSuite.mp3"/>
49: 	<cfinvokeargument name="length" value="12216320"/>
50: 	<cfinvokeargument name="type" value="audio/mpeg"/>
51: </cfinvoke>
52: 
53: <!--- Add categories to these items. --->
54: <cfinvoke component="#rssObj#" method="addCategoryToItem">
55: 	<cfinvokeargument name="category" value="ColdFusion"/>
56: </cfinvoke>
57: 
58: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
59: 	<cfinvokeargument name="category" value="Cigars"/>
60: </cfinvoke>
61: 
62: <!--- I forgot to add a category to the first item.  --->
63: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
64: 	<cfinvokeargument name="item" value="1"/>
65: 	<cfinvokeargument name="category" value="Live shows"/>
66: </cfinvoke>
67: 
68: <!--- Dude, I should totally add all of those categories to the feed.  --->
69: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
70: 	<cfinvokeargument name="category" value="Philadelphia"/>
71: </cfinvoke>
72: 
73: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
74: 	<cfinvokeargument name="category" value="Entertainment"/>
75: </cfinvoke>
76: 
77: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
78: 	<cfinvokeargument name="category" value="Live shows"/>
79: </cfinvoke>
80: 
81: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
82: 	<cfinvokeargument name="category" value="ColdFusion"/>
83: </cfinvoke>
84: 
85: <cfinvoke component="#rssObj#" method="addCategoryToFeed">
86: 	<cfinvokeargument name="category" value="Cigars"/>
87: </cfinvoke>
88: 
89: 
90: <!--- Add some skip hours as a proof of concept --->
91: <cfinvoke component="#rssObj#" method="addSkipHourToFeed">
92: 	<cfinvokeargument name="hourToSkip" value="0"/>
93: </cfinvoke>
94: <cfinvoke component="#rssObj#" method="addSkipHourToFeed">
95: 	<cfinvokeargument name="hourToSkip" value="1"/>
96: </cfinvoke>
97: 
98: <!--- Add some skip days as a proof of concept --->
99: <cfinvoke component="#rssObj#" method="addSkipDayToFeed">
100: 	<cfinvokeargument name="dayToSkip" value="Sunday"/>
101: </cfinvoke>
102: <cfinvoke component="#rssObj#" method="addSkipDayToFeed">
103: 	<cfinvokeargument name="dayToSkip" value="Saturday"/>
104: </cfinvoke>
105: 
106: <!--- Return the feed. --->
107: <cfinvoke component="#rssObj#" method="getFeed" returnvariable="test" />
108: 
109: <cfcontent type="text/xml" />
110: <cfoutput>#test#</cfoutput>
111: 



This sample will yield this result: Sample Feed.

Source

rss.cfc

Documentation

RSS.cfc Documentation

Download

RSS.zip