Wiki source code of Archive
Last modified by Jan Rhebergen on 2022/03/12 10:00
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{include reference="Blog.BlogCode"/}} | ||
| 2 | |||
| 3 | {{velocity}} | ||
| 4 | ## | ||
| 5 | ## | ||
| 6 | ## | ||
| 7 | #macro(displayBlogFullArchive $targetDocument) | ||
| 8 | #getAllBlogPostsQueryBasedOnDisplayContext($targetDocument $query $queryParams) | ||
| 9 | #set ($discard = $queryParams.put('creator', $xcontext.user)) | ||
| 10 | #set ($query = "$!{query} and (doc.creator = :creator or (isPublished.value = 1 and hidden.value = 0))") | ||
| 11 | ## Create a Jodatime date formatter that will be used to format dates | ||
| 12 | #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM')) | ||
| 13 | #set($tempDate = $xwiki.jodatime.mutableDateTime) | ||
| 14 | #set($currentYear = $xwiki.formatDate($datetool.date, 'yyyy')) | ||
| 15 | #set($currentMonth = $xwiki.formatDate($datetool.date, 'M')) | ||
| 16 | #set($firstYear = '') | ||
| 17 | #set($lastYear = '') | ||
| 18 | #set ($firstYearQueryObj = $services.query.hql("${query} order by year(publishDate.value)").setLimit(1).addFilter('unique')) | ||
| 19 | #bindQueryParameters($firstYearQueryObj $queryParams) | ||
| 20 | #foreach($firstEntry in $firstYearQueryObj.execute()) | ||
| 21 | #set($discard = $xwiki.getDocument($firstEntry)) | ||
| 22 | #getEntryObject($discard $entryObj) | ||
| 23 | #getEntryDate($discard $entryObj $firstYear) | ||
| 24 | #set($firstYear = $numbertool.toNumber($xwiki.formatDate($firstYear, 'yyyy')).intValue()) | ||
| 25 | #end | ||
| 26 | #set ($lastYearQueryObj = $services.query.hql("${query} order by year(publishDate.value) desc").setLimit(1).addFilter('unique')) | ||
| 27 | #bindQueryParameters($lastYearQueryObj $queryParams) | ||
| 28 | #foreach($lastEntry in $lastYearQueryObj.execute()) | ||
| 29 | #set($discard = $xwiki.getDocument($lastEntry)) | ||
| 30 | #getEntryObject($discard $entryObj) | ||
| 31 | #getEntryDate($discard $entryObj $lastYear) | ||
| 32 | #set($lastYear = $numbertool.toNumber($xwiki.formatDate($lastYear, 'yyyy')).intValue()) | ||
| 33 | #end | ||
| 34 | #if("$!{firstYear}" != '') ## At least one entry exists | ||
| 35 | #foreach($year in [$firstYear..$lastYear]) | ||
| 36 | #set ($yearArticleCountQueryObj = $services.query.hql("${query} and year(publishDate.value) = $year").addFilter('unique')) | ||
| 37 | #bindQueryParameters($yearArticleCountQueryObj $queryParams) | ||
| 38 | #set($yearArticleCount = $yearArticleCountQueryObj.count()) | ||
| 39 | #if($yearArticleCount > 0) | ||
| 40 | #set ($queryString = "sheet=Blog.ArchiveSheet&year=${year}") | ||
| 41 | * [[$year ($yearArticleCount)>>${targetDocument.fullName}||queryString="${queryString}"]] | ||
| 42 | #foreach($month in [1..12]) | ||
| 43 | #set ($statement = "${query} and year(publishDate.value) = $year and month(publishDate.value) = $month") | ||
| 44 | #set ($monthArticleCountQueryObj = $services.query.hql($statement).addFilter('unique')) | ||
| 45 | #bindQueryParameters($monthArticleCountQueryObj $queryParams) | ||
| 46 | #set ($monthArticleCount = $monthArticleCountQueryObj.count()) | ||
| 47 | #if($monthArticleCount > 0) | ||
| 48 | $tempDate.setMonthOfYear($month) | ||
| 49 | #set($queryString = "sheet=Blog.ArchiveSheet&year=${year}&month=${month}") | ||
| 50 | ** [[$monthFormatter.print($tempDate) (${monthArticleCount})>>${targetDocument.fullName}||queryString="${queryString}"]] | ||
| 51 | #end | ||
| 52 | #end | ||
| 53 | #end | ||
| 54 | #end | ||
| 55 | #else | ||
| 56 | #info($services.localization.render('blog.archive.noarticle')) | ||
| 57 | #end | ||
| 58 | #end | ||
| 59 | ## | ||
| 60 | ## | ||
| 61 | ## | ||
| 62 | #macro(displayBlogYearArchive $targetDocument $year) | ||
| 63 | #displayBlogYearArchiveSubTitle($targetDocument $year) | ||
| 64 | #getAllBlogPostsQueryBasedOnDisplayContext($targetDocument $query $queryParams) | ||
| 65 | #set ($discard = $queryParams.put('creator', $xcontext.user)) | ||
| 66 | #set ($query = "$!{query} and (doc.creator = :creator or (isPublished.value = 1 and hidden.value = 0))") | ||
| 67 | #set($query = "${query} and year(publishDate.value) = :year") | ||
| 68 | #set ($discard = $queryParams.put('year', $numbertool.toNumber($year).intValue())) | ||
| 69 | ## Create a Jodatime date formatter that will be used to format dates | ||
| 70 | #set($monthFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM')) | ||
| 71 | #set($tempDate = $xwiki.jodatime.mutableDateTime) | ||
| 72 | #set ($yearArticleCountQueryObj = $services.query.hql($query).addFilter('unique')) | ||
| 73 | #bindQueryParameters($yearArticleCountQueryObj $queryParams) | ||
| 74 | #set($yearArticleCount = $yearArticleCountQueryObj.count()) | ||
| 75 | #if($yearArticleCount > 0) | ||
| 76 | #foreach($month in [1..12]) | ||
| 77 | #set ($monthArticleCountQueryObj = $services.query.hql("${query} and month(publishDate.value) = $month").addFilter('unique')) | ||
| 78 | #bindQueryParameters($monthArticleCountQueryObj $queryParams) | ||
| 79 | #set($monthArticleCount = $monthArticleCountQueryObj.count()) | ||
| 80 | #if($monthArticleCount > 0) | ||
| 81 | $tempDate.setMonthOfYear($month) | ||
| 82 | #set($queryString = "sheet=Blog.ArchiveSheet&year=${year}&month=${month}") | ||
| 83 | (% class="blog-sub-title" %) | ||
| 84 | === [[$monthFormatter.print($tempDate) (${monthArticleCount})>>${targetDocument.fullName}||queryString="${queryString}"]] === | ||
| 85 | #set ($monthArticleQueryObj = $services.query.hql("${query} and month(publishDate.value) = $month order by publishDate.value").addFilter('unique')) | ||
| 86 | #bindQueryParameters($monthArticleQueryObj $queryParams) | ||
| 87 | #foreach($entryDoc in $xwiki.wrapDocs($monthArticleQueryObj.execute())) | ||
| 88 | #getEntryObject($entryDoc $entryObj) | ||
| 89 | #isPublished($entryObj $isPublished) | ||
| 90 | #isHidden($entryObj $isHidden) | ||
| 91 | * [[$entryDoc.display('title', 'view', $entryObj)>>$entryDoc]]#if(!$isPublished) $services.localization.render('blog.archive.unpublished')#elseif($isHidden) $services.localization.render('blog.archive.hidden')#end | ||
| 92 | |||
| 93 | #end | ||
| 94 | #end | ||
| 95 | #end | ||
| 96 | #else | ||
| 97 | #info($services.localization.render('blog.archive.noarticlesyear')) | ||
| 98 | #end | ||
| 99 | #end | ||
| 100 | ## | ||
| 101 | ## | ||
| 102 | ## | ||
| 103 | #macro(displayBlogMonthArchive $targetDocument $year $month) | ||
| 104 | #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('MMMM yyyy')) | ||
| 105 | #set($tempDate = $xwiki.jodatime.mutableDateTime) | ||
| 106 | #set($discard = $tempDate.setYear($numbertool.toNumber($year).intValue())) | ||
| 107 | #set($discard = $tempDate.setMonthOfYear($numbertool.toNumber($month).intValue())) | ||
| 108 | #displayBlogMonthArchiveSubTitle($targetDocument $tempDate) | ||
| 109 | #getAllBlogPostsQueryBasedOnDisplayContext($targetDocument $query $queryParams) | ||
| 110 | #set ($discard = $queryParams.put('creator', $xcontext.user)) | ||
| 111 | #set ($query = "$!{query} and (doc.creator = :creator or (isPublished.value = 1 and hidden.value = 0))") | ||
| 112 | #set($query = "${query} and year(publishDate.value) = :year and month(publishDate.value) = :month") | ||
| 113 | #set ($discard = $queryParams.put('year', $numbertool.toNumber($year).intValue())) | ||
| 114 | #set ($discard = $queryParams.put('month', $numbertool.toNumber($month).intValue())) | ||
| 115 | #set ($monthArticleCountQueryObj = $services.query.hql($query).addFilter('unique')) | ||
| 116 | #bindQueryParameters($monthArticleCountQueryObj $queryParams) | ||
| 117 | #set($monthArticleCount = $monthArticleCountQueryObj.count()) | ||
| 118 | #if($monthArticleCount > 0) | ||
| 119 | #set ($fromDate = "${year}-${month}-01") | ||
| 120 | #set ($toDate =$datetool.toDate('yyyy-M-d', "$fromDate")) | ||
| 121 | #set ($cal = $datetool.getCalendar()) | ||
| 122 | #set ($discard = $cal.setTime($toDate)) | ||
| 123 | ## Get the last day of the month | ||
| 124 | #set ($discard = $cal.add(2, 1))## +1 month | ||
| 125 | #set ($discard = $cal.add(5, -1))## -1 day | ||
| 126 | #set ($toDate = $cal.getTime()) | ||
| 127 | #set ($toDate = $datetool.format('yyyy-M-d', $toDate)) | ||
| 128 | |||
| 129 | #set ($layoutParams = "useSummary=true|displayTitle=true") | ||
| 130 | #if ($targetDocument.space == $defaultBlogSpace && !$targetDocument.getObject($blogCategoryClassname)) | ||
| 131 | #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout) | ||
| 132 | {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" fromDate="$fromDate" toDate="$toDate" layout="$postsLayout" layoutParams="$!layoutParams" paginated='yes' /}} | ||
| 133 | #elseif($targetDocument.getObject($blogCategoryClassname)) | ||
| 134 | #getBlogDocumentForCategoriesSpace($targetDocument.space $blogDoc) | ||
| 135 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 136 | {{blogpostlist category="$targetDocument.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" fromDate="$fromDate" toDate="$toDate" layout="$postsLayout" layoutParams="$!layoutParams" paginated='yes' /}} | ||
| 137 | #elseif($targetDocument.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') | ||
| 138 | #getBlogDocumentForCategoriesSpace($targetDocument.space $blogDoc) | ||
| 139 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 140 | {{blogpostlist category="$targetDocument.space.replaceAll('~', '~~').replaceAll('"', '~"')" fromDate="$fromDate" toDate="$toDate" layout="$postsLayout" layoutParams="$!layoutParams" paginated='yes' /}} | ||
| 141 | #else | ||
| 142 | #getBlogDocument($targetDocument.space $blogDoc) | ||
| 143 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 144 | {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" fromDate="$fromDate" toDate="$toDate" layout="$postsLayout" layoutParams="$!layoutParams" paginated='yes' /}} | ||
| 145 | #end | ||
| 146 | #else | ||
| 147 | #info($services.localization.render('blog.archive.noarticlesmonth')) | ||
| 148 | #end | ||
| 149 | #end | ||
| 150 | ## | ||
| 151 | ## | ||
| 152 | ## | ||
| 153 | ## | ||
| 154 | #macro(getPageTitleBasedOnDisplayContext $targetDocument $theTitle) | ||
| 155 | #if($targetDocument.getObject($blogCategoryClassname) || $targetDocument.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') | ||
| 156 | #getBlogDocumentForCategoriesSpace($targetDocument.space $blogDoc) | ||
| 157 | #set ($categoryTitle = $targetDocument.display('name')) | ||
| 158 | #if ("$!categoryTitle" == '' && !$targetDocument.getObject($blogCategoryClassname))## Categories space WebHome | ||
| 159 | #set ($categoryTitle = $services.localization.render('blog.categories.webhome.title')) | ||
| 160 | #end | ||
| 161 | #else | ||
| 162 | #getBlogDocument($targetDocument.space $blogDoc) | ||
| 163 | #end | ||
| 164 | #set ($macro.title = $blogDoc.display('title')) | ||
| 165 | #if ($blogDoc.fullName == 'Blog.WebHome') | ||
| 166 | #set($macro.title = $services.localization.render('blog.code.title')) | ||
| 167 | #end | ||
| 168 | #if ("$!categoryTitle" != '') | ||
| 169 | #set ($macro.title = "$!{macro.title} - ${categoryTitle}") | ||
| 170 | #end | ||
| 171 | #setVariable("$theTitle" $macro.title) | ||
| 172 | #end | ||
| 173 | ## | ||
| 174 | ## | ||
| 175 | ## | ||
| 176 | ## | ||
| 177 | #macro(displayBlogYearArchiveSubTitle $targetDocument $theYear) | ||
| 178 | #getPageTitleBasedOnDisplayContext($targetDocument $theTitle) | ||
| 179 | |||
| 180 | (% class="blog-sub-title" %) | ||
| 181 | == #if("$!theTitle" != '')${theTitle} -#end $services.localization.render('blog.archive.postsyear', [$theYear]) == | ||
| 182 | #end | ||
| 183 | ## | ||
| 184 | ## | ||
| 185 | ## | ||
| 186 | ## | ||
| 187 | #macro(displayBlogMonthArchiveSubTitle $targetDocument $theDate) | ||
| 188 | #getPageTitleBasedOnDisplayContext($targetDocument $theTitle) | ||
| 189 | |||
| 190 | (% class="blog-sub-title" %) | ||
| 191 | == #if("$!theTitle" != '')${theTitle} -#end $services.localization.render('blog.archive.postsfor') $dateFormatter.print($tempDate) == | ||
| 192 | #end | ||
| 193 | ## | ||
| 194 | ## | ||
| 195 | ## | ||
| 196 | ## | ||
| 197 | #set ($month = "$!numbertool.toNumber($request.month).intValue()") | ||
| 198 | #set ($year = "$!numbertool.toNumber($request.year).intValue()") | ||
| 199 | #if ($year == '') | ||
| 200 | ## 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. | ||
| 201 | #displayBlogFullArchive($doc) | ||
| 202 | #else | ||
| 203 | #if ($month == '') | ||
| 204 | ## Show an index of all posts in this year (titles only), with month names as subtitles | ||
| 205 | #displayBlogYearArchive($doc $year) | ||
| 206 | #else | ||
| 207 | ## Show all entries in the month (extract) | ||
| 208 | (% class="hfeed index" %)((( | ||
| 209 | #displayBlogMonthArchive($doc $year $month) | ||
| 210 | ))) | ||
| 211 | #end | ||
| 212 | #end | ||
| 213 | {{/velocity}} |