| 1 | <cfsetting enablecfoutputonly=true showdebugoutput=false> |
|---|
| 2 | <cfprocessingdirective pageencoding="utf-8"> |
|---|
| 3 | <!--- |
|---|
| 4 | Name : RSS |
|---|
| 5 | Author : Raymond Camden |
|---|
| 6 | Created : March 12, 2003 |
|---|
| 7 | Last Updated : May 18, 2007 |
|---|
| 8 | History : Reset history for version 5.0 |
|---|
| 9 | : Note that I'm not doing RSS feeds by day or month anymore, so that code is marked for removal (maybe) |
|---|
| 10 | : Added additionalTitle support for cats |
|---|
| 11 | : Cache for main RSS (rkc 7/10/06) |
|---|
| 12 | : Rob Wilkerson added code to handle noting/returning headers for aggregators (rkc 4/19/07) |
|---|
| 13 | http://musetracks.instantspot.com/blog/index.cfm/2007/4/19/BlogCFC-Enhancement |
|---|
| 14 | : Fix bug where no entries - also support N categories (rkc 5/18/07) |
|---|
| 15 | : DanS fix for unreleased entries, cap url.byentry to 35 (rkc 11/17/07) |
|---|
| 16 | Purpose : Blog RSS feed. |
|---|
| 17 | ---> |
|---|
| 18 | |
|---|
| 19 | <cfif isDefined("url.mode") and url.mode is "full"> |
|---|
| 20 | <cfset mode = "full"> |
|---|
| 21 | <cfelse> |
|---|
| 22 | <cfset mode = "short"> |
|---|
| 23 | </cfif> |
|---|
| 24 | |
|---|
| 25 | <!--- only allow 1 or 2 ---> |
|---|
| 26 | <cfif isDefined("url.version") and url.version is 1> |
|---|
| 27 | <cfset version = 1> |
|---|
| 28 | <cfelse> |
|---|
| 29 | <cfset version = 2> |
|---|
| 30 | </cfif> |
|---|
| 31 | |
|---|
| 32 | <cfset params = structNew()> |
|---|
| 33 | <!---// dgs: only get released items //---> |
|---|
| 34 | <cfset params.releasedonly = true /> |
|---|
| 35 | |
|---|
| 36 | <cfset additionalTitle = ""> |
|---|
| 37 | |
|---|
| 38 | <cfif isDefined("url.mode2")> |
|---|
| 39 | <cfif url.mode2 is "day" and isDefined("url.day") and isDefined("url.month") and isDefined("url.year")> |
|---|
| 40 | <cfset params.byDay = val(url.day)> |
|---|
| 41 | <cfset params.byMonth = val(url.month)> |
|---|
| 42 | <cfset params.byYear = val(url.year)> |
|---|
| 43 | <cfelseif url.mode2 is "month" and isDefined("url.month") and isDefined("url.year")> |
|---|
| 44 | <cfset params.byMonth = val(url.month)> |
|---|
| 45 | <cfset params.byYear = val(url.year)> |
|---|
| 46 | <cfelseif url.mode2 is "cat" and isDefined("url.catid")> |
|---|
| 47 | <!--- can be a list ---> |
|---|
| 48 | <cfset additionalTitle = ""> |
|---|
| 49 | <cfset params.byCat = ""> |
|---|
| 50 | <cfloop index="x" from="1" to="#listLen(url.catid)#"> |
|---|
| 51 | <cfset cat = listGetAt(url.catid, x)> |
|---|
| 52 | <!--- set to 35 ---> |
|---|
| 53 | <cfset cat = left(cat, 35)> |
|---|
| 54 | <cfset params.byCat = listAppend(params.byCat, cat)> |
|---|
| 55 | <cftry> |
|---|
| 56 | <cfset additionalTitle = additionalTitle & " - " & application.blog.getCategory(cat).categoryname> |
|---|
| 57 | <cfcatch></cfcatch> |
|---|
| 58 | </cftry> |
|---|
| 59 | </cfloop> |
|---|
| 60 | <cfelseif url.mode2 is "entry"> |
|---|
| 61 | <cfset params.byEntry = left(url.entry,35)> |
|---|
| 62 | </cfif> |
|---|
| 63 | </cfif> |
|---|
| 64 | |
|---|
| 65 | <!--- Only cache if not isdefined mode 2 ---> |
|---|
| 66 | <!--- In other words, cache just the main view ---> |
|---|
| 67 | <!--- Therefore, our cache name needs to just care about mode and version ---> |
|---|
| 68 | <cfset cachename = application.applicationname & "_rss_" & mode & version> |
|---|
| 69 | <cfif structKeyExists(url, "mode2")> |
|---|
| 70 | <cfset disabled = true> |
|---|
| 71 | <cfelse> |
|---|
| 72 | <cfset disabled = false> |
|---|
| 73 | </cfif> |
|---|
| 74 | |
|---|
| 75 | <cfsavecontent variable="variables.feedXML"> |
|---|
| 76 | <cfmodule template="tags/scopecache.cfm" cachename="#cachename#" scope="application" timeout="#application.timeout#" disabled="#disabled#"> |
|---|
| 77 | <cfoutput>#application.blog.generateRSS(mode=mode,params=params,version=version,additionalTitle=additionalTitle)#</cfoutput> |
|---|
| 78 | </cfmodule> |
|---|
| 79 | </cfsavecontent> |
|---|
| 80 | |
|---|
| 81 | <cfset variables.lastModified = XMLSearch ( XMLParse ( variables.feedXML ), '//item[1]/pubDate' ) /> |
|---|
| 82 | <cfif arrayLen(variables.lastModified) is 0> |
|---|
| 83 | <cfset variables.lastModified = ""> |
|---|
| 84 | <cfelse> |
|---|
| 85 | <cfset variables.lastModified = variables.lastModified[1].XMLText /> |
|---|
| 86 | </cfif> |
|---|
| 87 | <cfset variables.ETag = hash ( variables.lastModified ) /> |
|---|
| 88 | |
|---|
| 89 | <cfset variables.request = getHTTPRequestData() /> |
|---|
| 90 | <cfset variables.headers = variables.request.headers /> |
|---|
| 91 | |
|---|
| 92 | <cfif structKeyExists ( variables.headers, 'If-Modified-Since' ) and variables.headers['If-Modified-Since'] eq variables.lastModified> |
|---|
| 93 | <cfif structKeyExists ( variables.headers, 'If-None-Match' ) and variables.headers['If-None-Match'] eq variables.ETag> |
|---|
| 94 | <cfheader statuscode="304" statustext="Not Modified" /> |
|---|
| 95 | <cfexit /> |
|---|
| 96 | <cfelse> |
|---|
| 97 | <!--- |
|---|
| 98 | <cflog file="rss" text="ETag value don't match '#variables.eTag#'" /> |
|---|
| 99 | ---> |
|---|
| 100 | </cfif> |
|---|
| 101 | <cfelse> |
|---|
| 102 | <!--- |
|---|
| 103 | <cflog file="rss" text="Last modified dates don't match" /> |
|---|
| 104 | ---> |
|---|
| 105 | </cfif> |
|---|
| 106 | |
|---|
| 107 | <cftry> |
|---|
| 108 | <cfheader name="Last-Modified" value="#variables.lastModified#" /> |
|---|
| 109 | <cfheader name="ETag" value="#variables.ETag#" /> |
|---|
| 110 | |
|---|
| 111 | <cfcontent type="text/xml; chartset=utf-8"><cfoutput>#variables.feedXML#</cfoutput> |
|---|
| 112 | <cfcatch> |
|---|
| 113 | <cfmail to="#application.blog.getProperty("ownerEmail")#" from="#application.blog.getProperty("ownerEmail")#" subject="rss bug" type="html"> |
|---|
| 114 | #application.resourceBundle.getResource("type")#=#cfcatch.type# |
|---|
| 115 | <hr> |
|---|
| 116 | #application.resourceBundle.getResource("message")#=#cfcatch.message# |
|---|
| 117 | <hr> |
|---|
| 118 | #application.resourceBundle.getResource("detail")#=#cfcatch.detail# |
|---|
| 119 | <cfdump var="#cfcatch#"> |
|---|
| 120 | </cfmail> |
|---|
| 121 | <!--- Logic is - if they filtered incorrectly, revert to default, if not, abort ---> |
|---|
| 122 | <cfif cgi.query_string neq ""> |
|---|
| 123 | <cflocation url="rss.cfm"> |
|---|
| 124 | <cfelse> |
|---|
| 125 | <cfabort> |
|---|
| 126 | </cfif> |
|---|
| 127 | </cfcatch> |
|---|
| 128 | </cftry> |
|---|
| 129 | |
|---|