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