Toggle navigation
Log-in
myITGuide
Page Index
User Index
Application Index
Global
Wiki Index
Home
Blog
Links
Database
SQL Server
Cassandra
BigData
PostgreSQL
Redis
MariaDB
MongoDB
Tools
T-SQL
Powershell
Python
Scala
R
Jupyter
Java
Solution
Streaming
Spark
Storm
Search
Solr
ElasticSearch
Kafka
Puppet
Kibana
Docker
Kubernetes
OS
Windows
Linux
About
About Us
Email Us
Blog
Macros for displaying Blog-related RSS feeds
Wiki source code of
Macros for displaying Blog-related RSS feeds
Last modified by superadmin on 2016/12/20 10:05
Hide line numbers
1: {{include reference="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>$services.localization.render('xe.blog.code.description.space', [$blogDoc.space])</description> 113: #getWikiLogo($logoUrl) 114: <image rdf:resource="$logoUrl"/> 115: <dc:language>$blogDoc.defaultLocale</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: #set ($mainDoc = $xwiki.getDocument($services.model.resolveDocument('', 'default', $doc.documentReference.extractReference('WIKI')))) 142: <channel rdf:about="$mainDoc.getExternalURL()"> 143: <title>$escapetool.xml($mainDoc.plainTitle)</title> 144: <link>$mainDoc.getExternalURL()</link> 145: ## TODO: Add a Description field in the blog class 146: <description>$services.localization.render('xe.blog.code.description.wiki')</description> 147: #getWikiLogo($logoUrl) 148: <image rdf:resource="$logoUrl"/> 149: <dc:rights>$escapetool.xml($xwiki.spaceCopyright)</dc:rights> 150: <dc:publisher>XWiki</dc:publisher> 151: <items> 152: <rdf:Seq> 153: ## This is just a list of blog entries, which are detailed below. 154: #foreach ($entryDoc in $entries) 155: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 156: <rdf:li rdf:resource="$entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")" /> 157: #end 158: #end 159: </rdf:Seq> 160: </items> 161: </channel> 162: #end 163: ## 164: ## 165: ## 166: #** 167: * Print the blog channel description: title, link, description, logo, creator, copyright, and the list of entries. 168: * 169: * @param blogDoc The XDocument corresponding to the blog to be displayed. 170: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 171: *### 172: #macro(printBlogCategoryRssChannelDescription $categoryDoc $entries) 173: <channel rdf:about="$categoryDoc.getURL()"> 174: <title>$services.localization.render($categoryDoc.getValue('name'))</title> 175: <link>$categoryDoc.getExternalURL()</link> 176: ## TODO: Add a Description field in the blog class 177: <description>$services.localization.render('xe.blog.code.description.category', [$categoryDoc.display('name')])</description> 178: <dc:rights>$escapetool.xml($xwiki.spaceCopyright)</dc:rights> 179: <items> 180: <rdf:Seq> 181: ## This is just a list of blog entries, which are detailed below. 182: #foreach ($entryDoc in $entries) 183: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 184: <rdf:li rdf:resource="$entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")" /> 185: #end 186: #end 187: </rdf:Seq> 188: </items> 189: </channel> 190: #end 191: ## 192: ## 193: ## 194: #** 195: * Print the blog image description. Currently, this is the logo of the wiki. 196: * 197: * @param blogDoc The XDocument corresponding to the displayed blog. 198: *### 199: #macro(printBlogRssImage $blogDoc) 200: #getWikiLogo($logoUrl) 201: <image rdf:about="$logoUrl"> 202: <title>Wiki Logo</title> 203: <url>$logoUrl</url> 204: <link>$blogDoc.getExternalURL()</link> 205: </image> 206: #end 207: ## 208: ## 209: ## 210: #** 211: * Print the syndicated blog entries. These are the detailed "item"s, which must be referenced above, in the channel 212: * description, as otherwise they are ignored. 213: * 214: * @param entries The entries to display. Usually, these are the last entries belonging to the blog. 215: *### 216: #macro(printBlogRssItems $entries) 217: ## Print all the entry details 218: #foreach ($entryDoc in $entries) 219: #if($xwiki.hasAccessLevel('view', ${entryDoc.fullName})) 220: #printBlogRssItem($entryDoc) 221: #end 222: #end 223: #end 224: ## 225: ## 226: ## 227: #** 228: * Print a blog entry in the RSS feed. besides the mandatory RSS elements (title, link, and description), also print 229: * some metadata in the Dublin Core vocabulary (creator, categories, date). 230: * 231: * @param entryDoc The XDocument corresponding to the displayed blog entry. 232: *### 233: #macro(printBlogRssItem $entryDoc) 234: #set($entryUrl = $entryDoc.getExternalURL('view', "language=${entryDoc.realLanguage}")) 235: #getEntryObject($entryDoc $entryObj) 236: #getEntryContent($entryDoc $entryObj true $entryContent) 237: #if($!entryDoc.syntax.toIdString() == 'xwiki/1.0') 238: #set($desc = $entryContent) 239: #else 240: #set($desc = $entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntax().toIdString())) 241: #end 242: #set($desc = $escapetool.xml($desc)) 243: <item rdf:about="$entryUrl"> 244: <title>$escapetool.xml($entryDoc.display("title", "view", $entryObj))</title> 245: <link>$entryUrl</link> 246: <description>$desc</description> 247: ## Some metadata, using the Dublin Core extension to RSS. 248: ## TODO: Display this in a better way. 249: <dc:subject>$escapetool.xml($entryObj.display('category', 'view'))</dc:subject> 250: <dc:date>$dateFormatter.print($entryDoc.date.time)</dc:date> 251: <dc:creator>$escapetool.xml($xwiki.getUserName($entryDoc.creator, false))</dc:creator> 252: #if($entryDoc.creator != $entryDoc.author) 253: <dc:contributor> 254: <rdf:Description link="$xwiki.getURL($entryDoc.author)"> 255: <rdf:value>$escapetool.xml($xwiki.getUserName($entryDoc.author, false))</rdf:value> 256: </rdf:Description> 257: </dc:contributor> 258: #end 259: </item> 260: #end 261: ## 262: ## 263: ## 264: #** 265: * Print the end of the RSS: close the root element. 266: *### 267: #macro(printBlogRssFooter) 268: </rdf:RDF> 269: #end 270: ## 271: ## 272: ## 273: #** 274: * Normally, this should be a Template eXtension, which would be used to display a blog as a RSS feed. Since TX are not 275: * yet implemented, the target blog should be passed in the URL. This macro determines exactly which blog should be 276: * syndicated. If the "blog" request parameter is not present, then the default Blog is used. 277: * 278: * @param blogDoc The resulting XDocument of the target blog. 279: *### 280: #macro(getTargetBlog $blogDoc) 281: #if("$!{request.blog}" != '') 282: #set($result = $xwiki.getDocument($request.blog)) 283: #else 284: #getBlogDocument('Blog' $result) 285: #end 286: #set ($blogDoc = $NULL) 287: #setVariable ("$blogDoc" $result) 288: ## TODO: Check if the document has a Blog.BlogClass object. 289: #end 290: ## 291: ## 292: ## 293: #macro(printFieldContent $entryDoc $entryObj $fieldName) 294: $escapetool.xml($entryDoc.display($fieldName, 'view', $entryObj))#end 295: ## 296: ## 297: ## 298: #macro(getWikiLogo $logoUrl) 299: #set ($path = $xwiki.getSkinFile($xwiki.getSkinPreference('logo', 'logo.png'))) 300: #set ($port = '') 301: #if (($request.scheme == 'http') && ($request.serverPort != 80)) 302: #set ($port = ":${request.serverPort}") 303: #elseif (($request.scheme == 'https') && ($request.serverPort != 443)) 304: #set ($port = ":${request.serverPort}") 305: #end 306: #set ($logoUrl = $NULL) 307: #setVariable ("$logoUrl" "${request.scheme}://${request.serverName}${port}${path}") 308: #end 309: {{/velocity}}