Wiki source code of Blog Archive

Last modified by Ecaterina Valica on 2018/09/25 12:51

Hide last authors
Ecaterina Valica 8.1 1 {{include reference="Blog.BlogCode"/}}
Ludovic Dubost 1.1 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)
Ecaterina Valica 8.1 15 #set($currentYear = $xwiki.formatDate($datetool.date, 'yyyy'))
16 #set($currentMonth = $xwiki.formatDate($datetool.date, 'M'))
Ludovic Dubost 1.1 17 #set($firstYear = '')
18 #set($lastYear = '')
Ecaterina Valica 8.1 19 #foreach($firstEntry in $services.query.hql("${query} order by year(publishDate.value)").setLimit(1).bindValues($queryParams).execute())
Ludovic Dubost 1.1 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
Ecaterina Valica 8.1 25 #foreach($lastEntry in $services.query.hql("${query} order by year(publishDate.value) desc").setLimit(1).bindValues($queryParams).execute())
Ludovic Dubost 1.1 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])
Ecaterina Valica 8.1 33 #set($yearArticleCount = $services.query.hql("${query} and year(publishDate.value) = $year").bindValues($queryParams).count())
Ludovic Dubost 1.1 34 #if($yearArticleCount > 0)
Ecaterina Valica 8.1 35 #set ($queryString = "space=$escapetool.url($blogDoc.space)&year=${year}")
36 * [[$year ($yearArticleCount)>>Blog.Archive||queryString="${queryString}"]]
Ludovic Dubost 1.1 37 #foreach($month in [1..12])
Ecaterina Valica 8.1 38 #set ($statement = "${query} and year(publishDate.value) = $year and month(publishDate.value) = $month")
39 #set ($monthArticleCount = $services.query.hql($statement).bindValues($queryParams).count())
Ludovic Dubost 1.1 40 #if($monthArticleCount > 0)
41 $tempDate.setMonthOfYear($month)
Ecaterina Valica 8.1 42 #set($queryString = "space=${escapetool.url($blogDoc.space)}&year=${year}&month=${month}")
43 ** [[$monthFormatter.print($tempDate) (${monthArticleCount})>>Blog.Archive||queryString="${queryString}"]]
Ludovic Dubost 1.1 44 #end
45 #end
46 #end
47 #end
48 #else
Ecaterina Valica 7.1 49 #info($services.localization.render('xe.blog.archive.noarticle'))
Ludovic Dubost 1.1 50 #end
51 #end
52 ##
53 ##
54 ##
55 #macro(displayBlogYearArchive $blogDoc $year)
Ecaterina Valica 7.1 56 = $services.localization.render('xe.blog.archive.postsyear', [$year]) =
Ludovic Dubost 1.1 57 #getBlogEntriesBaseQuery($query)
58 #set($query = "${query} and (doc.space = ? or doc.parent = ?)")
Ecaterina Valica 8.1 59 #set($queryParams = [$blogDoc.space, $blogDoc.fullName])
Ludovic Dubost 1.1 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)
Ecaterina Valica 8.1 64 #set($yearArticleCount = $services.query.hql($query).bindValues($queryParams).count())
Ludovic Dubost 1.1 65 #if($yearArticleCount > 0)
66 #foreach($month in [1..12])
Ecaterina Valica 8.1 67 #set($monthArticleCount = $services.query.hql("${query} and month(publishDate.value) = $month").bindValues($queryParams).count())
Ludovic Dubost 1.1 68 #if($monthArticleCount > 0)
69 $tempDate.setMonthOfYear($month)
Ecaterina Valica 8.1 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()))
Ludovic Dubost 1.1 73 #getEntryObject($entryDoc $entryObj)
74 #isPublished($entryObj $isPublished)
75 #isHidden($entryObj $isHidden)
Ecaterina Valica 7.1 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
Ludovic Dubost 1.1 77
78 #end
79 #end
80 #end
81 #else
Ecaterina Valica 7.1 82 #info($services.localization.render('xe.blog.archive.noarticlesyear'))
Ludovic Dubost 1.1 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))##
Ecaterina Valica 7.1 93 = $services.localization.render('xe.blog.archive.postsfor') $dateFormatter.print($tempDate) =
Ludovic Dubost 1.1 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")
Ecaterina Valica 8.1 98 #set($monthArticleCount = $services.query.hql($query).bindValues($queryParams).count())
Ludovic Dubost 1.1 99 #if($monthArticleCount > 0)
Ecaterina Valica 8.1 100 #foreach($entryDoc in $xwiki.wrapDocs($services.query.hql("${query} order by publishDate.value").bindValues($queryParams).execute()))
Ludovic Dubost 1.1 101 #getEntryObject($entryDoc $entryObj)
102 #displayEntry($entryDoc $entryObj true true)
103 #end
104 #else
Ecaterina Valica 7.1 105 #info($services.localization.render('xe.blog.archive.noarticlesmonth'))
Ludovic Dubost 1.1 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}}