Toggle navigation
Log-in
Wiki Index
Page Index
User Index
Blog
Blog Archive
Wiki source code of
Blog Archive
Last modified by
Ricardo Rodríguez Fernández
on 2015/01/28 10:00
Hide line numbers
1: {{include reference="Blog.BlogCode"/}} 2: 3: {{velocity filter="none"}} 4: {{html clean="false" wiki="true"}} 5: ## 6: ## 7: ## 8: #macro(displayBlogFullArchive $blogDoc) 9: #getBlogEntriesBaseQuery($query) 10: #set($query = "${query} and (doc.space = ? or doc.parent = ?)") 11: #set ($queryParams = [$blogDoc.space, $blogDoc.fullName]) 12: ## Create a Jodatime date formatter that will be used to format dates 13: #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM')) 14: #set($tempDate = $xwiki.jodatime.mutableDateTime) 15: #set($currentYear = $xwiki.formatDate($datetool.date, 'yyyy')) 16: #set($currentMonth = $xwiki.formatDate($datetool.date, 'M')) 17: #set($firstYear = '') 18: #set($lastYear = '') 19: #foreach($firstEntry in $services.query.hql("${query} order by year(publishDate.value)").setLimit(1).bindValues($queryParams).execute()) 20: #set($discard = $xwiki.getDocument($firstEntry)) 21: #getEntryObject($discard $entryObj) 22: #getEntryDate($discard $entryObj $firstYear) 23: #set($firstYear = $mathtool.toInteger($xwiki.formatDate($firstYear, 'yyyy'))) 24: #end 25: #foreach($lastEntry in $services.query.hql("${query} order by year(publishDate.value) desc").setLimit(1).bindValues($queryParams).execute()) 26: #set($discard = $xwiki.getDocument($lastEntry)) 27: #getEntryObject($discard $entryObj) 28: #getEntryDate($discard $entryObj $lastYear) 29: #set($lastYear = $mathtool.toInteger($xwiki.formatDate($lastYear, 'yyyy'))) 30: #end 31: #if("$!{firstYear}" != '') ## At least one entry exists 32: #foreach($year in [$firstYear..$lastYear]) 33: #set($yearArticleCount = $services.query.hql("${query} and year(publishDate.value) = $year").bindValues($queryParams).count()) 34: #if($yearArticleCount > 0) 35: #set ($queryString = "space=$escapetool.url($blogDoc.space)&year=${year}") 36: * [[$year ($yearArticleCount)>>Blog.Archive||queryString="${queryString}"]] 37: #foreach($month in [1..12]) 38: #set ($statement = "${query} and year(publishDate.value) = $year and month(publishDate.value) = $month") 39: #set ($monthArticleCount = $services.query.hql($statement).bindValues($queryParams).count()) 40: #if($monthArticleCount > 0) 41: $tempDate.setMonthOfYear($month) 42: #set($queryString = "space=${escapetool.url($blogDoc.space)}&year=${year}&month=${month}") 43: ** [[$monthFormatter.print($tempDate) (${monthArticleCount})>>Blog.Archive||queryString="${queryString}"]] 44: #end 45: #end 46: #end 47: #end 48: #else 49: #info($services.localization.render('xe.blog.archive.noarticle')) 50: #end 51: #end 52: ## 53: ## 54: ## 55: #macro(displayBlogYearArchive $blogDoc $year) 56: = $services.localization.render('xe.blog.archive.postsyear', [$year]) = 57: #getBlogEntriesBaseQuery($query) 58: #set($query = "${query} and (doc.space = ? or doc.parent = ?)") 59: #set($queryParams = [$blogDoc.space, $blogDoc.fullName]) 60: #set($query = "${query} and year(publishDate.value) = $year") 61: ## Create a Jodatime date formatter that will be used to format dates 62: #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM')) 63: #set($tempDate = $xwiki.jodatime.mutableDateTime) 64: #set($yearArticleCount = $services.query.hql($query).bindValues($queryParams).count()) 65: #if($yearArticleCount > 0) 66: #foreach($month in [1..12]) 67: #set($monthArticleCount = $services.query.hql("${query} and month(publishDate.value) = $month").bindValues($queryParams).count()) 68: #if($monthArticleCount > 0) 69: $tempDate.setMonthOfYear($month) 70: #set($queryString = "space=${escapetool.url($blogDoc.space)}&year=${year}&month=${month}") 71: == [[$monthFormatter.print($tempDate) (${monthArticleCount})>>Blog.Archive||queryString="${queryString}"]] == 72: #foreach($entryDoc in $xwiki.wrapDocs($services.query.hql("${query} and month(publishDate.value) = $month order by publishDate.value", $queryParams).execute())) 73: #getEntryObject($entryDoc $entryObj) 74: #isPublished($entryObj $isPublished) 75: #isHidden($entryObj $isHidden) 76: * [[$entryDoc.display('title', 'view', $entryObj)>>$entryDoc]]#if(!$isPublished) $services.localization.render('xe.blog.archive.unpublished')#elseif($isHidden) $services.localization.render('xe.blog.archive.hidden')#end 77: 78: #end 79: #end 80: #end 81: #else 82: #info($services.localization.render('xe.blog.archive.noarticlesyear')) 83: #end 84: #end 85: ## 86: ## 87: ## 88: #macro(displayBlogMonthArchive $blogDoc $year $month) 89: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM yyyy')) 90: #set($tempDate = $xwiki.jodatime.mutableDateTime) 91: $tempDate.setYear($mathtool.toInteger($year))## 92: $tempDate.setMonthOfYear($mathtool.toInteger($month))## 93: = $services.localization.render('xe.blog.archive.postsfor') $dateFormatter.print($tempDate) = 94: #getBlogEntriesBaseQuery($query) 95: #set($query = "${query} and (doc.space = ? or doc.parent = ?)") 96: #set ($queryParams = [$blogDoc.space, $blogDoc.fullName]) 97: #set($query = "${query} and year(publishDate.value) = $year and month(publishDate.value) = $month") 98: #set($monthArticleCount = $services.query.hql($query).bindValues($queryParams).count()) 99: #if($monthArticleCount > 0) 100: #foreach($entryDoc in $xwiki.wrapDocs($services.query.hql("${query} order by publishDate.value").bindValues($queryParams).execute())) 101: #getEntryObject($entryDoc $entryObj) 102: #displayEntry($entryDoc $entryObj true true) 103: #end 104: #else 105: #info($services.localization.render('xe.blog.archive.noarticlesmonth')) 106: #end 107: #end 108: ## 109: ## 110: ## 111: #set($space = "$!{request.space}") 112: #if($space == '') 113: #set($space = 'Blog') 114: #end 115: #getBlogDocument($space $blogDoc) 116: #set ($month = "$!{mathtool.toInteger($request.month)}") 117: #set ($year = "$!{mathtool.toInteger($request.year)}") 118: #if ($year == '') 119: ## Show a brief history of the blog, a tree with first level = years, second level = months, and the number of entries from that year/month in every node. 120: #displayBlogFullArchive($blogDoc) 121: #else 122: #if ($month == '') 123: ## Show an index of all posts in this year (titles only), with month names as subtitles 124: #displayBlogYearArchive($blogDoc $year) 125: #else 126: ## Show all entries in the month (extract) 127: #displayBlogMonthArchive($blogDoc $year $month) 128: #end 129: #end 130: {{/html}} 131: {{/velocity}}