General Actions:
Log-in
Wiki:
L3D's Wiki
▼
:
Document Index
»
Space:
Blog
▼
:
Document Index
»
Page:
RssCode
Search
Page Actions:
Export
▼
:
Export as PDF
Export as RTF
Export as HTML
More actions
▼
:
Print preview
View Source
Welcome to your wiki
»
Macros for displaying Blog-related RSS feeds
Wiki source code of
Macros for displaying Blog-related RSS feeds
Last modified by
Administrator
on 2008/12/21 17:59
Content
·
Comments
(0)
·
Attachments
(0)
·
History
·
Information
Hide line numbers
1: #includeMacros("Blog.BlogCode") 2: ## 3: ## 4: ## 5: #** 6: * Display a blog as a RSS feed. The output corresponds to the RSS 1.0 specification, and it makes use of the Dublin 7: * Core module to specify metadata. 8: * 9: * @param blogDoc The XDocument corresponding to the blog to be syndicated. 10: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 11: *### 12: #macro(displayBlogRss $blogDoc $entries) 13: {pre} 14: ## Create a Jodatime date formatter that will be used to format dates 15: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd'T'hh:mm:ssZZ")) 16: ## Set the right mimetype 17: $!response.setContentType('application/rdf+xml')## 18: #setBlogRssCacheSettings() 19: #printBlogRssHeader() 20: #printBlogRssChannelDescription($blogDoc $entries) 21: #printBlogRssImage($blogDoc) 22: #printBlogRssItems($entries) 23: #printBlogRssFooter() 24: {/pre} 25: #end 26: ## 27: ## 28: ## 29: #** 30: * Display blog entries from all the wiki as a RSS feed. The output corresponds to the RSS 1.0 specification, and it 31: * makes use of the Dublin Core module to specify metadata. 32: * 33: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 34: *### 35: #macro(displayGlobalBlogRss $entries) 36: {pre} 37: ## Create a Jodatime date formatter that will be used to format dates 38: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd'T'hh:mm:ssZZ")) 39: ## Set the right mimetype 40: $!response.setContentType('application/rdf+xml')## 41: #setBlogRssCacheSettings() 42: #printBlogRssHeader() 43: #printGlobalBlogRssChannelDescription($entries) 44: #printWikiRssImage($blogDoc) 45: #printBlogRssItems($entries) 46: #printBlogRssFooter() 47: {/pre} 48: #end 49: ## 50: ## 51: ## 52: #** 53: * Display blog entries belonging to a target category as a RSS feed. The output corresponds to the RSS 1.0 54: * specification, and it makes use of the Dublin Core module to specify metadata. 55: * 56: * @param blogDoc The XDocument corresponding to the blog to be syndicated. 57: * @param categoryDoc The XDocument corresponding to the blog category to be syndicated. 58: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 59: *### 60: #macro(displayBlogCategoryRss $blogDoc $categoryDoc $entries) 61: {pre} 62: ## Create a Jodatime date formatter that will be used to format dates 63: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd'T'hh:mm:ssZZ")) 64: ## Set the right mimetype 65: $!response.setContentType('application/rdf+xml')## 66: #setBlogRssCacheSettings() 67: #printBlogRssHeader() 68: #printBlogCategoryRssChannelDescription($categoryDoc $entries) 69: #printBlogRssItems($entries) 70: #printBlogRssFooter() 71: {/pre} 72: #end 73: ## 74: ## 75: ## 76: #** 77: * Set the proper cache settings, both for the client (HTTP headers) and for the server (rendering cache). 78: *### 79: #macro(setBlogRssCacheSettings) 80: ## Internally cache the rendered RSS for 30 minutes, for better performance 81: ## TODO: This is disabled for security reasons. Since the cache doesn't take into account the current user, it might 82: ## serve hidden/unpublished entries to non-creators. 83: ## $!context.setCacheDuration(1800) 84: ## Instruct the client to cache the response for 1 hour 85: #set($expires = $xwiki.jodatime.getMutableDateTime())## 86: $!expires.addHours(1)## 87: ## TODO: This has no effect, as the core contains a no-cache setting in com.xpn.xwiki.web.Utils 88: $!response.setDateHeader('Expires', $expires.millis)## 89: $!response.setHeader('Cache-Control', 'public')## 90: #end 91: ## 92: ## 93: ## 94: #** 95: * Print the start of the RSS: XML declaration and open root element. 96: *### 97: #macro(printBlogRssHeader) 98: <?xml version="1.0" encoding="$xwiki.encoding" ?> 99: <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/"> 100: #end 101: ## 102: ## 103: ## 104: #** 105: * Print the blog channel description: title, link, description, logo, creator, copyright, and the list of entries. 106: * 107: * @param blogDoc The XDocument corresponding to the blog to be displayed. 108: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 109: *### 110: #macro(printBlogRssChannelDescription $blogDoc $entries) 111: <channel rdf:about="$blogDoc.getURL()"> 112: #getBlogTitle($blogDoc $title) 113: <title>$title</title> 114: <link>$blogDoc.getExternalURL()</link> 115: ## TODO: Add a Description field in the blog class 116: <description>Most recent blog posts in the $blogDoc.space space</description> 117: #getWikiLogo($logoUrl) 118: <image rdf:resource="$logoUrl"/> 119: <dc:language>$blogDoc.defaultLanguage</dc:language> 120: <dc:rights>$escapetool.xml($xwiki.webCopyright)</dc:rights> 121: ## TODO: Usually this is not something meaningful. Maybe add some Blog object properties for these. 122: ## <dc:publisher>$escapetool.xml($xwiki.getUserName($blogDoc.author, false))</dc:publisher> 123: ## <dc:creator>$escapetool.xml($xwiki.getUserName($blogDoc.creator, false))</dc:creator> 124: <items> 125: <rdf:Seq> 126: ## This is just a list of blog entries, which are detailed below. 127: #foreach ($entryDoc in $entries) 128: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 129: <rdf:li rdf:resource="$entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")" /> 130: #end 131: #end 132: </rdf:Seq> 133: </items> 134: </channel> 135: #end 136: ## 137: ## 138: ## 139: #** 140: * Print the wiki-wide channel description: title, link, description, logo, creator, copyright, and the list of entries. 141: * 142: * @param entries The entries to display. Usually, these are the last entries published in the wiki. 143: *### 144: #macro(printGlobalBlogRssChannelDescription $entries) 145: ## TODO: Replace hardcoded Main.WebHome with a setting once the core provides this information. 146: #set($mainDoc = $xwiki.getDocument('Main.WebHome')) 147: <channel rdf:about="$mainDoc.getExternalURL()"> 148: <title>$mainDoc.displayTitle</title> 149: <link>$mainDoc.getExternalURL()</link> 150: ## TODO: Add a Description field in the blog class 151: <description>Most recent blog posts in the wiki</description> 152: #getWikiLogo($logoUrl) 153: <image rdf:resource="$logoUrl"/> 154: <dc:rights>$escapetool.xml($xwiki.webCopyright)</dc:rights> 155: <dc:publisher>XWiki</dc:publisher> 156: <items> 157: <rdf:Seq> 158: ## This is just a list of blog entries, which are detailed below. 159: #foreach ($entryDoc in $entries) 160: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 161: <rdf:li rdf:resource="$entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")" /> 162: #end 163: #end 164: </rdf:Seq> 165: </items> 166: </channel> 167: #end 168: ## 169: ## 170: ## 171: #** 172: * Print the blog channel description: title, link, description, logo, creator, copyright, and the list of entries. 173: * 174: * @param blogDoc The XDocument corresponding to the blog to be displayed. 175: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 176: *### 177: #macro(printBlogCategoryRssChannelDescription $categoryDoc $entries) 178: <channel rdf:about="$categoryDoc.getURL()"> 179: <title>$categoryDoc.display('name')</title> 180: <link>$categoryDoc.getExternalURL()</link> 181: ## TODO: Add a Description field in the blog class 182: <description>Most recent blog posts in the $categoryDoc.display('name') category</description> 183: <dc:rights>$escapetool.xml($xwiki.webCopyright)</dc:rights> 184: <items> 185: <rdf:Seq> 186: ## This is just a list of blog entries, which are detailed below. 187: #foreach ($entryDoc in $entries) 188: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 189: <rdf:li rdf:resource="$entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")" /> 190: #end 191: #end 192: </rdf:Seq> 193: </items> 194: </channel> 195: #end 196: ## 197: ## 198: ## 199: #** 200: * Print the blog image description. Currently, this is the logo of the wiki. 201: * 202: * @param blogDoc The XDocument corresponding to the displayed blog. 203: *### 204: #macro(printBlogRssImage $blogDoc) 205: #getWikiLogo($logoUrl) 206: <image rdf:about="$logoUrl"> 207: <title>Wiki Logo</title> 208: <url>$logoUrl</url> 209: <link>$blogDoc.getExternalURL()</link> 210: </image> 211: #end 212: ## 213: ## 214: ## 215: #** 216: * Print the syndicated blog entries. These are the detailed "item"s, which must be referenced above, in the channel 217: * description, as otherwise they are ignored. 218: * 219: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 220: *### 221: #macro(printBlogRssItems $entries) 222: ## Print all the entry details 223: #foreach ($entryDoc in $entries) 224: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 225: #printBlogRssItem($entryDoc) 226: #end 227: #end 228: #end 229: ## 230: ## 231: ## 232: #** 233: * Print a blog entry in the RSS feed. besides the mandatory RSS elements (title, link, and description), also print 234: * some metadata in the Dublin Core vocabulary (creator, categories, date). 235: * 236: * @param entryDoc The XDocument corresponding to the displayed blog entry. 237: *### 238: #macro(printBlogRssItem $entryDoc) 239: #set($entryUrl = $entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")) 240: #getEntryObject($entryDoc $entryObj) 241: #getEntryContent($entryDoc $entryObj true $entryContent) 242: #if($!entryDoc.syntaxId == 'xwiki/1.0') 243: #set($desc = $entryContent) 244: #else 245: #set($desc = $entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntaxId())) 246: #end 247: #set($desc = $escapetool.xml($desc)) 248: <item rdf:about="$entryUrl"> 249: <title>$escapetool.xml($entryDoc.display("title", "view", $entryObj))</title> 250: <link>$entryUrl</link> 251: <description>$desc</description> 252: ## Some metadata, using the Dublin Core extension to RSS. 253: ## TODO: Display this in a better way. 254: <dc:subject>$escapetool.xml($entryObj.display('category', 'view'))</dc:subject> 255: <dc:date>$dateFormatter.print($entryDoc.date.time)</dc:date> 256: <dc:creator>$escapetool.xml($xwiki.getUserName($entryDoc.creator, false))</dc:creator> 257: #if($entryDoc.creator != $entryDoc.author) 258: <dc:contributor> 259: <rdf:Description link="$xwiki.getURL($entryDoc.author)"> 260: <rdf:value>$escapetool.xml($xwiki.getUserName($entryDoc.author, false))</rdf:value> 261: </rdf:Description> 262: </dc:contributor> 263: #end 264: </item> 265: #end 266: ## 267: ## 268: ## 269: #** 270: * Print the end of the RSS: close the root element. 271: *### 272: #macro(printBlogRssFooter) 273: </rdf:RDF> 274: #end 275: ## 276: ## 277: ## 278: #** 279: * Normally, this should be a Template eXtension, which would be used to display a blog as a RSS feed. Since TX are not 280: * yet implemented, the target blog should be passed in the URL. This macro determines exactly which blog should be 281: * syndicated. If the "blog" request parameter is not present, then the default Blog is used. 282: * 283: * @param blogDoc The resulting XDocument of the target blog. 284: *### 285: #macro(getTargetBlog $blogDoc) 286: #if("$!{request.blog}" != '') 287: #set($blogDoc = $xwiki.getDocument($request.blog)) 288: #else 289: #getBlogDocument('Blog' $blogDoc) 290: #end 291: ## TODO: Check if the document has a Blog.BlogClass object. 292: #end 293: ## 294: ## 295: ## 296: #macro(printFieldContent $entryDoc $entryObj $fieldName) 297: $escapetool.xml($entryDoc.display($fieldName, 'view', $entryObj))#end 298: ## 299: ## 300: ## 301: #macro(getWikiLogo $logoUrl) 302: #set($logoUrl = $xwiki.getSkinFile($xwiki.getSkinPreference('logo', 'logo.png'))) 303: #set($port = '') 304: #if(($request.scheme == 'http') && ($request.serverPort != 80)) 305: #set($port = ":${request.serverPort}") 306: #elseif(($request.scheme == 'https') && ($request.serverPort != 443)) 307: #set($port = ":${request.serverPort}") 308: #end 309: #set($logoUrl = "${request.scheme}://${request.serverName}${port}$logoUrl") 310: #end
Quick Links
L3D Calendar
Wiki Dashboard
Document Index
Blog
Sandbox