Wiki source code of Blog Archive

Version 1.1 by Ludovic Dubost on 2008/12/22 03:59

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