FireFox download counter in ColdFusion

FireFox has a realtime download counter on their Spread Firefox site. They syndicate the counter as RSS, and there are lots of code snippets available to put it on your site. I found one that was in CF, but it didn't work. So I wrote my own and added it to this site in the top right. Here's the code:

<cfset feedUrl = "http://feeds.spreadfirefox.com/downloads/firefox">
<cfparam name="errorsFound" default="0">
<cftry>
   <cfhttp url="#feedURL#" method="get" timeout="3" throwonerror="true"/>
<cfcatch type="any">
   <cfset errorsFound = 1>
</cfcatch>
</cftry>
<cfif errorsFound eq 0>
   <cfset dloadFeed = XMLParse(cfhttp.filecontent)>
   <cfset numDownloads = dloadFeed.rss.channel.item.description.XmlText>
   <div style="font-size:8pt; font-weight:bold; font-family: arial; text-align:center;">
   <cfoutput>#NumberFormat(numDownloads,",")#</cfoutput>
   downloads and
   counting!</div>
<cfelse>
   <div style="font-size:8pt; font-weight:bold; font-family: arial; text-align:center;">
   &nbsp;<br />&nbsp;<br />&nbsp;<br />&nbsp;<br />
   </div>
</cfif>

I had a bug in it that I fixed today. Well, not really a bug. If the rss feed doesn't respond, the page will just spin until it hits the default timeout in the CF server. Today I added the code that sets a timeout, and if it doesn't get a response in 3 seconds, the code just displays a blank section. I put the blank section in so it looks good on my site, but you can modify it as best fits your site.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Blog Owner