Code source wiki de Blog Archive

Modifié par Administrator le 2008/12/22 03:59

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