Merge branch 'master' into es17.01

This commit is contained in:
2017-03-08 20:55:50 +01:00

View File

@@ -68,49 +68,87 @@ feature -- Handler
local local
r: CMS_RESPONSE r: CMS_RESPONSE
mesg: CMS_CUSTOM_RESPONSE_MESSAGE mesg: CMS_CUSTOM_RESPONSE_MESSAGE
l_xml: STRING
l_cache: CMS_FILE_STRING_8_CACHE l_cache: CMS_FILE_STRING_8_CACHE
l_not_modified: BOOLEAN
l_sitemap_xml: detachable STRING
l_last_modified: detachable DATE_TIME
d: HTTP_DATE
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
create l_cache.make (api.files_location.extended ("modules").extended ("sitemap").extended ("sitemap.xml")) create l_cache.make (api.files_location.extended ("modules").extended ("sitemap").extended ("sitemap.xml"))
if if
l_cache.exists and then l_cache.exists and then
not l_cache.expired (Void, 7*24*60*60) and then not l_cache.expired (Void, 24*60*60) -- 1 day
attached l_cache.item as l_cached_xml
then then
create mesg.make ({HTTP_STATUS_CODE}.ok) l_last_modified := l_cache.cache_date_time
mesg.header.put_content_type ("application/xml") if attached req.http_if_modified_since as l_http_if_modified_since then
mesg.set_payload (l_cached_xml) create d.make_from_string (l_http_if_modified_since)
res.send (mesg) if not d.has_error then
elseif attached sitemap (r) as l_sitemap then if d.date_time >= l_last_modified then
create l_xml.make (1_024) -- Not Modified!
l_xml.append ("<?xml version=%"1.0%" encoding=%"utf-8%"?>%N") l_not_modified := True
l_xml.append ("<?xml-stylesheet type=%"text/xsl%" href=%"" + r.absolute_url ("/module/" + name + "/files/sitemap.xsl", Void) + "%"?>%N") end
l_xml.append ("<urlset xmlns=%"http://www.sitemaps.org/schemas/sitemap/0.9%">%N") end
across
l_sitemap as ic
loop
l_xml.append (" <url>%N")
l_xml.append (" <loc>" + r.absolute_url (ic.item.link.location, Void) + "</loc>%N")
l_xml.append (" <lastmod>"); append_date_output (ic.item.date, l_xml); l_xml.append ("</lastmod>%N")
l_xml.append (" <changefreq>" + ic.item.change_frequency + "</changefreq>%N")
l_xml.append (" <priority>" + ic.item.priority.out + "</priority>%N")
l_xml.append (" </url>%N")
end end
l_xml.append ("</urlset>%N")
l_cache.put (l_xml)
if l_not_modified then
res.set_status_code ({HTTP_STATUS_CODE}.not_modified)
res.header.put_content_type ("application/xml")
res.header.put_last_modified (l_last_modified)
res.flush
else
l_sitemap_xml := l_cache.item
end
else
create l_last_modified.make_now_utc
end
if l_not_modified then
-- response sent!
else
if l_sitemap_xml = Void then
l_sitemap_xml := new_sitemap_xml (r)
if l_sitemap_xml /= Void then
l_cache.put (l_sitemap_xml)
else
l_cache.delete
end
end
if l_sitemap_xml /= Void then
create mesg.make ({HTTP_STATUS_CODE}.ok) create mesg.make ({HTTP_STATUS_CODE}.ok)
mesg.header.put_content_type ("application/xml") mesg.header.put_content_type ("application/xml")
mesg.header.put_header ("Accept-Ranges: bytes") mesg.header.put_header ("Accept-Ranges: bytes")
mesg.header.put_header ("Vary: Accept-Encoding,User-Agent") mesg.header.put_header ("Vary: Accept-Encoding,User-Agent")
mesg.set_payload (l_xml) mesg.header.put_last_modified (l_last_modified)
-- mesg.header.put_cache_control ("max-age=" + (24*60*60).out)
mesg.set_payload (l_sitemap_xml)
res.send (mesg) res.send (mesg)
else else
create {NOT_FOUND_ERROR_CMS_RESPONSE} r.make (req, res, api) create {NOT_FOUND_ERROR_CMS_RESPONSE} r.make (req, res, api)
r.execute r.execute
end end
end end
end
new_sitemap_xml (r: CMS_RESPONSE): detachable STRING
do
if attached sitemap (r) as l_sitemap then
create Result.make (1_024)
Result.append ("<?xml version=%"1.0%" encoding=%"utf-8%"?>%N")
Result.append ("<?xml-stylesheet type=%"text/xsl%" href=%"" + r.absolute_url ("/module/" + name + "/files/sitemap.xsl", Void) + "%"?>%N")
Result.append ("<urlset xmlns=%"http://www.sitemaps.org/schemas/sitemap/0.9%">%N")
across
l_sitemap as ic
loop
Result.append (" <url>%N")
Result.append (" <loc>" + r.absolute_url (ic.item.link.location, Void) + "</loc>%N")
Result.append (" <lastmod>"); append_date_output (ic.item.date, Result); Result.append ("</lastmod>%N")
Result.append (" <changefreq>" + ic.item.change_frequency + "</changefreq>%N")
Result.append (" <priority>" + ic.item.priority.out + "</priority>%N")
Result.append (" </url>%N")
end
Result.append ("</urlset>%N")
end
end
append_date_output (dt: DATE_TIME; a_output: STRING) append_date_output (dt: DATE_TIME; a_output: STRING)
--| 2017-02-07T21:09:21+00:00 --| 2017-02-07T21:09:21+00:00