<cfsetting enablecfoutputonly=true>

<!---
 | check for new content since last request - all update code should store
 | now() in application.lastchangedate so we can check that here, and thus
 | avoid actually hitting the database unneccessarily
 |
 | code adapted and extended from Pete Freitag's example at:
 | http://www.petefreitag.com/item/235.cfm
 !--->

<cfset checkdate="">

<cftry>
 <!--- need to initialise application.lastchangedate after a server restart --->
 <cfif not structkeyexists(application, 'lastchangedate')>
  <cfquery name="getlastchange" datasource=#request.dsn#>
   SELECT max(added) AS added FROM mapdata
  </cfquery>

  <cfset application.lastchangedate=parsedatetime(getlastchange.uploaded)>
 </cfif>

 <cfheader name="Last-Modified" value=#gethttptimestring(application.lastchangedate)#>

 <cfset headers=gethttprequestdata().headers>

 <cfif structkeyexists(headers, "If-Modified-Since")>
  <cfset checkdate=parsedatetime(headers["If-Modified-Since"])>
  <cfset changedate=application.lastchangedate>

  <cfif datediff("n", changedate, checkdate) gt 0>
   <cfheader statuscode="304" statustext="Not Modified"> 
   <cfabort>
  </cfif>
 </cfif>

 <cfcatch type="any"></cfcatch>
</cftry>

<!--- end of unchanged content check --->

<cfset NumberOfFeedItems = 10>

<cfquery name="getmaps" datasource="#request.dsn#">
 select
  stockcode, areacode, mapdata.title, retail, descriptive, cartographer,
  cartographerlocation, metric, medium, colour, year, added, image, filename
 from mapdata, mapimage, image
 where
  mapdata.publish='yes' and mapdata.deleted='no'
  and mapdata.stockcode=mapimage.map and image.id=mapimage.image
  <!--- and date_add(added, interval #request.parameters.expiryhours# hour) < now() --->
 order by added desc
 limit #numberoffeeditems#
</cfquery>
<cfquery name="getglobes" datasource="#request.dsn#">
select id as stockcode, title, content as descriptive, imagefile as filename, lastchanged as added
from globes
order by lastchanged desc
limit #numberoffeeditems#
</cfquery>
<cfquery name="getbooks" datasource="#request.dsn#">
select stockcode, bookdata.title, descriptive, filename, image, added
from bookdata, bookimage, image
where bookdata.stockcode=bookimage.book and image.id=bookimage.image
order by added desc
limit #numberoffeeditems#
</cfquery>
<cfscript>
 tz=gettimezoneinfo();
 tz=iif(tz.isDSTon, de('+0100'), de('+0000'));
 now=now();
 now="#dateformat(now, 'ddd, dd mmm yyyy')# #timeformat(now, 'HH:mm:ss')# #tz#";
</cfscript>

<cfsavecontent variable="theXML">

<cfoutput><?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns##">

<channel>
<ttl>240</ttl>
 	<title>Latest Maps, Globes and Books from Jonathan Potter Limited</title>
	<link>http://www.jpmaps.co.uk/</link>
 	<image>
  		<url>http://www.jpmaps.co.uk/resources/jpmaps.icon.png</url>
  		<title>Latest Maps, Globes and Books from Jonathan Potter Limited</title>
  		<link>http://www.jpmaps.co.uk/</link>
 	</image>
 	<description>Jonathan Potter Limited - Antique Maps, Charts, Plans, Atlases, Globes and Cartographic Reference Books</description>
 	<language>en</language>
 	<copyright>copyright Jonathan Potter Limited</copyright>
 	<pubDate>#now#</pubDate>
</cfoutput>


<cfloop query="getmaps">
 <cfscript>
  itemtitle=server.entity(lcase(rereplace(title, "<[^>]*>", "", "ALL")));
  summary=rereplace(descriptive, "<[^>]*>", "", "ALL");
  summary=server.entity(replacenocase(summary, "&nbsp;", " ", "ALL"));
  content=rereplacenocase(descriptive, "<img [^>]*>", "", "ALL");
  content=server.entity(replacenocase(content, "&nbsp;", " ", "ALL"));
  date=dateformat(added, "ddd, dd mmm yyyy");
  time=timeformat(added, "HH:mm:ss");
  pubDate=date & " " & time & " " & tz;
  link="http://www.jpmaps.co.uk/map/id.#stockcode#";
 </cfscript>

 <cfoutput>
 <item>
 
  <title>#itemtitle#</title>

  <!---<enclosure url="http://www.jpmaps.co.uk/mapimages/thumbnail/#filename#" type="image/jpeg" />--->
   <description>MAP - #summary#</description>
    <content:encoded><![CDATA[#content#]]></content:encoded>
 <guid isPermaLink="true">#link#</guid>
  <pubDate>#pubDate#</pubDate>
 </item>
 </cfoutput>
</cfloop>

<!--- globes start here --->

<cfloop query="getglobes">
 <cfscript>
  itemtitle=server.entity(lcase(rereplace(title, "<[^>]*>", "", "ALL")));
  summary=rereplace(descriptive, "<[^>]*>", "", "ALL");
  summary=server.entity(replacenocase(summary, "&nbsp;", " ", "ALL"));
  content=rereplacenocase(descriptive, "<img [^>]*>", "", "ALL");
  content=server.entity(replacenocase(content, "&nbsp;", " ", "ALL"));
  date=dateformat(added, "ddd, dd mmm yyyy");
  time=timeformat(added, "HH:mm:ss");
  pubDate=date & " " & time & " " & tz;
  link="http://www.jpmaps.co.uk/globes";
 </cfscript>

 <cfoutput>
 <item>
 
  <title>#itemtitle#</title>

<!---  <enclosure url="http://www.jpmaps.co.uk/contentimages/globes/#filename#" type="image/jpeg" />--->
   <description>GLOBE - #summary#</description>
    <content:encoded><![CDATA[#content#]]></content:encoded>
  <link>http://www.jpmaps.co.uk/globes</link>
  <pubDate>#pubDate#</pubDate>
 </item>
 </cfoutput>
</cfloop>

<!--- books start here --->

<cfloop query="getbooks">
 <cfscript>
  itemtitle=server.entity(lcase(rereplace(title, "<[^>]*>", "", "ALL")));
  summary=rereplace(descriptive, "<[^>]*>", "", "ALL");
  summary=server.entity(replacenocase(summary, "&nbsp;", " ", "ALL"));
  content=rereplacenocase(descriptive, "<img [^>]*>", "", "ALL");
  content=server.entity(replacenocase(content, "&nbsp;", " ", "ALL"));
  date=dateformat(added, "ddd, dd mmm yyyy");
  time=timeformat(added, "HH:mm:ss");
  pubDate=date & " " & time & " " & tz;
  link="http://www.jpmaps.co.uk/book/id.#stockcode#";
 </cfscript>

 <cfoutput>
 <item>
  <title>#itemtitle#</title>

 <!--- <enclosure url="http://www.jpmaps.co.uk/contentimages/books/#image#" type="image/jpeg" />--->
   <description>BOOK - #summary#</description>
    <content:encoded><![CDATA[#content#]]></content:encoded>
 <guid isPermaLink="true">#link#</guid> 
  <pubDate>#pubDate#</pubDate>

 </item>
 </cfoutput>
</cfloop>

<cfoutput>
</channel>
</rss>
</cfoutput>

</cfsavecontent>

<cfcontent type="text/xml">
<cfheader name="Content-Type" value="text/xml; charset=utf-8">
<cfoutput>#thexml#</cfoutput>