Wiki source code of Blog Archive

Version 5.1 by Admin on 2010/03/21 19:07

Show last authors
1 {{include document="Blog.BlogCode"/}}
2 {{velocity filter="none"}}
3 {{html clean="false" wiki="true"}}
4 ##
5 ##
6 ##
7 #macro(displayBlogFullArchive $blogDoc)
8 #getBlogEntriesBaseQuery($query)
9 #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')")
10 ## Create a Jodatime date formatter that will be used to format dates
11 #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM'))
12 #set($tempDate = $xwiki.jodatime.mutableDateTime)
13 #set($currentYear = $xwiki.formatDate($util.date, 'yyyy'))
14 #set($currentMonth = $xwiki.formatDate($util.date, 'M'))
15 #set($firstYear = '')
16 #set($lastYear = '')
17 #foreach($firstEntry in $xwiki.searchDocuments("${query} order by year(publishDate.value)", 1, 0))
18 #set($discard = $xwiki.getDocument($firstEntry))
19 #getEntryObject($discard $entryObj)
20 #getEntryDate($discard $entryObj $firstYear)
21 #set($firstYear = $util.parseInt($xwiki.formatDate($firstYear, 'yyyy')))
22 #end
23 #foreach($lastEntry in $xwiki.searchDocuments("${query} order by year(publishDate.value) desc", 1, 0))
24 #set($discard = $xwiki.getDocument($lastEntry))
25 #getEntryObject($discard $entryObj)
26 #getEntryDate($discard $entryObj $lastYear)
27 #set($lastYear = $util.parseInt($xwiki.formatDate($lastYear, 'yyyy')))
28 #end
29 #if("$!{firstYear}" != '') ## At least one entry exists
30 #foreach($year in [$firstYear..$lastYear])
31 #set($yearArticleCount = $xwiki.countDocuments("${query} and year(publishDate.value) = $year"))
32 #if($yearArticleCount > 0)
33 * [[$year ($yearArticleCount)>>Blog.Archive?space=${blogDoc.space}&year=${year}]]
34 #foreach($month in [1..12])
35 #set($monthArticleCount = $xwiki.countDocuments("${query} and year(publishDate.value) = $year and month(publishDate.value) = $month"))
36 #if($monthArticleCount > 0)
37 $tempDate.setMonthOfYear($month)
38 ** [[$monthFormatter.print($tempDate) (${monthArticleCount})>>Blog.Archive?space=${blogDoc.space}&year=${year}&month=${month}]]
39 #end
40 #end
41 #end
42 #end
43 #else
44 #info($msg.get('xe.blog.archive.noarticle'))
45 #end
46 #end
47 ##
48 ##
49 ##
50 #macro(displayBlogYearArchive $blogDoc $year)
51 = $msg.get('xe.blog.archive.postsyear', [$year]) =
52 #getBlogEntriesBaseQuery($query)
53 #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')")
54 #set($query = "${query} and year(publishDate.value) = $year")
55 ## Create a Jodatime date formatter that will be used to format dates
56 #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM'))
57 #set($tempDate = $xwiki.jodatime.mutableDateTime)
58 #set($yearArticleCount = $xwiki.countDocuments(${query}))
59 #if($yearArticleCount > 0)
60 #foreach($month in [1..12])
61 #set($monthArticleCount = $xwiki.countDocuments("${query} and month(publishDate.value) = $month"))
62 #if($monthArticleCount > 0)
63 $tempDate.setMonthOfYear($month)
64 == [[$monthFormatter.print($tempDate) (${monthArticleCount})>>Blog.Archive?space=${blogDoc.space}&year=${year}&month=${month}]] ==
65 #foreach($entryDoc in $xwiki.wrapDocs($xwiki.searchDocuments("${query} and month(publishDate.value) = $month order by publishDate.value")))
66 #getEntryObject($entryDoc $entryObj)
67 #isPublished($entryObj $isPublished)
68 #isHidden($entryObj $isHidden)
69 * [[$entryDoc.display('title', 'view', $entryObj)>>$entryDoc]]#if(!$isPublished) $msg.get('xe.blog.archive.unpublished')#elseif($isHidden) $msg.get('xe.blog.archive.hidden')#end
70
71 #end
72 #end
73 #end
74 #else
75 #info($msg.get('xe.blog.archive.noarticlesyear'))
76 #end
77 #end
78 ##
79 ##
80 ##
81 #macro(displayBlogMonthArchive $blogDoc $year $month)
82 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM yyyy'))
83 #set($tempDate = $xwiki.jodatime.mutableDateTime)
84 $tempDate.setYear($util.parseInt($year))##
85 $tempDate.setMonthOfYear($util.parseInt($month))##
86 = $msg.get('xe.blog.archive.postsfor') $dateFormatter.print($tempDate) =
87 #getBlogEntriesBaseQuery($query)
88 #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')")
89 #set($query = "${query} and year(publishDate.value) = $year and month(publishDate.value) = $month")
90 #set($monthArticleCount = $xwiki.countDocuments(${query}))
91 #if($monthArticleCount > 0)
92 #foreach($entryDoc in $xwiki.wrapDocs($xwiki.searchDocuments("${query} order by publishDate.value")))
93 #getEntryObject($entryDoc $entryObj)
94 #displayEntry($entryDoc $entryObj true true)
95 #end
96 #else
97 #info($msg.get('xe.blog.archive.noarticlesmonth'))
98 #end
99 #end
100 ##
101 ##
102 ##
103 #set($space = "$!{request.space}")
104 #if($space == '')
105 #set($space = 'Blog')
106 #end
107 #getBlogDocument($space $blogDoc)
108 #set($month = "$!{request.month}")
109 #set($year = "$!{request.year}")
110 #if($year == '')
111 ## 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.
112 #displayBlogFullArchive($blogDoc)
113 #else
114 #if($month == '')
115 ## Show an index of all posts in this year (titles only), with month names as subtitles
116 #displayBlogYearArchive($blogDoc $year)
117 #else
118 ## Show all entries in the month (extract)
119 #displayBlogMonthArchive($blogDoc $year $month)
120 #end
121 #end
122 {{/html}}
123 {{/velocity}}