Version 3.1 by superadmin on 2026/12/02 00:12

Show last authors
1 #includeMacros("Blog.BlogParameters")
2 ##
3 ##
4 ##
5 ## Import the blog skin and javascripts.
6 $!xwiki.ssx.use($blogStyleDocumentName)##
7 $!xwiki.jsx.use($blogScriptsDocumentName)##
8 ##
9 ##
10 ##
11 #**
12 * Prints a blog. This is the main macro used in the BlogSheet.
13 *
14 * @param blogDoc the XDocument holding the blog definition object.
15 *###
16 #macro(printBlog $blogDoc)
17 #getBlogEntries($blogDoc $entries)
18 #displayBlog($entries 'index' true)
19 #displayNavigationLinks($blogDoc)
20 #includeInContext('Blog.CreatePost')
21 #end
22 ##
23 ##
24 ##
25 #**
26 * Shows blog information. In view mode, the title and description are printed. In inline edit mode, allows changing
27 * blog settings: title, description, blog type (global or in-space), index display type (fixed size pagination, weekly
28 * index, monthly index, all entries).
29 *
30 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
31 *###
32 #macro(showBlogInfo $blogDoc)
33 #if($blogDoc.getObject($blogClassname))
34 #if($context.action == 'inline')
35 #macro(displayProperty $blogDoc $propname)
36 <dt>#displayPropName($xwiki.getClass($blogClassname).get($propname)):</dt>
37 <dd>$blogDoc.display($propname)</dd>
38 #end
39 <dl>
40 #displayProperty($blogDoc 'title')
41 #displayProperty($blogDoc 'description')
42 #displayProperty($blogDoc 'blogType')
43 #displayProperty($blogDoc 'displayType')
44 #displayProperty($blogDoc 'itemsPerPage')
45 </dl>
46 #else
47 #getBlogTitle($blogDoc $title)
48 #if($title != "")
49 1 $title
50 #end
51 $blogDoc.display('description')
52 #end
53 #elseif($doc.fullName == $blogSheet)
54 1 Blog sheet
55 This sheet should be used to display blog documents.
56 #else
57 #warning('This is not a blog document!')
58 #end
59 #end
60 ##
61 ##
62 ##
63 #**
64 * Retrieve the blog document, which usually is either <tt>&lt;Space&gt;.WebHome</tt> for whole-spaces blogs, or
65 * <tt>&lt;Space&gt;.Blog</tt> for in-space blogs. If none of these documents contains a blog object, then the first
66 * (alphabetically) document in the target space that contains one is returned. Finally, if no document in the current
67 * space contains a blog object, then <tt>Blog.WebHome</tt> is returned as the default blog.
68 *
69 * @param space A <tt>String</tt>, the name of the space where to search.
70 * @param blogDoc The resulting XDocument.
71 *###
72 #macro(getBlogDocument $space $blogDoc)
73 ## First, try the Space.WebHome, for a whole-space blog
74 #set($blogDoc = $xwiki.getDocument("${space}.WebHome"))
75 #if(!$blogDoc.getObject($blogClassname))
76 ## Second, try the Space.Blog document
77 #set($blogDoc = $xwiki.getDocument("${space}.Blog"))
78 #if(!$blogDoc.getObject($blogClassname))
79 ## Third, try searching for a blog document in the current space
80 #set ($legacyRawc2c39d3a2e_1 = $services.query.hql(", BaseObject obj where doc.space = '${space}' and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").execute())
81 #set ($legacyVisiblec2c39d3a2e_1 = [])
82 #foreach ($legacyEntryc2c39d3a2e_1 in $legacyRawc2c39d3a2e_1)
83 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_1))
84 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_1.add($legacyEntryc2c39d3a2e_1))
85 #end
86 #end
87 #set($blogDocs = $legacyVisiblec2c39d3a2e_1)
88 #if($blogDocs.size() > 0)
89 #set($blogDoc = $xwiki.getDocument($blogDocs.get(0)))
90 #else
91 ## Last, fallback to Blog.WebHome, the default blog
92 #set($blogDoc = $xwiki.getDocument('Blog.WebHome'))
93 #end
94 #end
95 #end
96 #end
97 ##
98 ##
99 ##
100 #**
101 * Retrieve the blog title.
102 *
103 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass<tt> object with the <tt>title</tt> property set.
104 * @param title The resulting title.
105 *###
106 #macro(getBlogTitle $blogDoc $title)
107 #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $title)
108 #end
109 ##
110 ##
111 ##
112 #**
113 * Retrieve the blog description.
114 *
115 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>description</tt>
116 * property set.
117 * @param description The resulting description.
118 *###
119 #macro(getBlogDescription $blogDoc $description)
120 #getBlogProperty($blogDoc 'description' '' $description)
121 #end
122 ##
123 ##
124 ##
125 #**
126 * Retrieves a list of entries to be displayed. The entries are either part of the blog's space, or have the blog
127 * document set as a parent. The number and range of entries returned (from all those belonging to this blog) depends on
128 * the blog display type: paginated (fixed number of entries), weekly (all entries in a week), monthly (all entries in a
129 * month), or all.
130 *
131 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
132 * @param entries The resulting list of entries to display, a list of XDocument names.
133 *###
134 #macro(getBlogEntries $blogDoc $entries)
135 #getBlogEntriesBaseQuery($query)
136 #isBlogGlobal($blogDoc $isGlobal)
137 #if(!$isGlobal)
138 #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')")
139 #end
140 #getBlogDisplayType($blogDoc $displayType)
141 #if($displayType == 'weekly')
142 #getWeeklyBlogEntries($blogDoc $query $entries)
143 #elseif($displayType == 'monthly')
144 #getMonthlyBlogEntries($blogDoc $query $entries)
145 #elseif($displayType == 'all')
146 #getAllBlogEntries($blogDoc $query $entries)
147 #else
148 #getPagedBlogEntries($blogDoc $query $entries)
149 #end
150 #end
151 ##
152 ##
153 ##
154 #**
155 * Retrieves a list of entries to be displayed. The entries are taken from a "page" of the blog, a sequence of documents
156 * defined by the request parameters <tt>ipp</tt> (items per page) and <tt>page</tt> (the current page). Initially the
157 * first page is displayed, with the number of entries defined in the blog object in the <tt>itemsPerPage</tt> property
158 * (10 if not defined).
159 *
160 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
161 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
162 * refined to restrict to a given space, or to a given search criteria, etc.
163 * @param entries The resulting list of entries to display, a list of XDocument names.
164 *###
165 #macro(getPagedBlogEntries $blogDoc $query $entries)
166 #set($totalEntries = $xwiki.countDocuments(${query}))
167 #getBlogProperty($blogDoc 'itemsPerPage' '10' $defaultItemsPerPage)
168 #set($defaultItemsPerPage = $util.parseInt($defaultItemsPerPage))
169 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
170 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
171 #set ($legacyRawc2c39d3a2e_2 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())
172 #set ($legacyVisiblec2c39d3a2e_2 = [])
173 #foreach ($legacyEntryc2c39d3a2e_2 in $legacyRawc2c39d3a2e_2)
174 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_2))
175 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_2.add($legacyEntryc2c39d3a2e_2))
176 #end
177 #end
178 #set($entries = $legacyVisiblec2c39d3a2e_2)
179 #end
180 ##
181 ##
182 ##
183 #**
184 * Retrieves a list of entries to be displayed. The entries are taken from a week of the blog. The target week is
185 * defined by the request parameters <tt>week</tt> (the week number in the year, from 1 to 52) and <tt>year</tt> (4
186 * digit year). Initially the current week is displayed.
187 *
188 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
189 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
190 * refined to restrict to a given space, or to a given search criteria, etc.
191 * @param entries The resulting list of entries to display, a list of XDocument names.
192 *###
193 #macro(getWeeklyBlogEntries $blogDoc $query $entries)
194 #getRequestedWeek($weekDate)
195 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd"))
196 #set($minDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundFloor()))
197 #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling()))
198 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
199 #set($totalEntries = $xwiki.countDocuments(${query}))
200 #set ($legacyRawc2c39d3a2e_3 = $services.query.hql("${query} order by publishDate.value desc").execute())
201 #set ($legacyVisiblec2c39d3a2e_3 = [])
202 #foreach ($legacyEntryc2c39d3a2e_3 in $legacyRawc2c39d3a2e_3)
203 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_3))
204 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_3.add($legacyEntryc2c39d3a2e_3))
205 #end
206 #end
207 #set($entries = $legacyVisiblec2c39d3a2e_3)
208 #end
209 ##
210 ##
211 ##
212 #**
213 * Retrieves a list of entries to be displayed. The entries are taken from a month of the blog. The target month is
214 * defined by the request parameters <tt>month</tt> (the month number, from 1 to 12) and <tt>year</tt> (4
215 * digit year). Initially the current month is displayed.
216 *
217 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
218 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
219 * refined to restrict to a given space, or to a given search criteria, etc.
220 * @param entries The resulting list of entries to display, a list of XDocument names.
221 *###
222 #macro(getMonthlyBlogEntries $blogDoc $query $entries)
223 #getRequestedMonth($monthDate)
224 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern("yyyy-MM-dd"))
225 #set($minDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundFloor()))
226 #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling()))
227 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
228 #set($totalEntries = $xwiki.countDocuments(${query}))
229 #set ($legacyRawc2c39d3a2e_4 = $services.query.hql("${query} order by publishDate.value desc").execute())
230 #set ($legacyVisiblec2c39d3a2e_4 = [])
231 #foreach ($legacyEntryc2c39d3a2e_4 in $legacyRawc2c39d3a2e_4)
232 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_4))
233 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_4.add($legacyEntryc2c39d3a2e_4))
234 #end
235 #end
236 #set($entries = $legacyVisiblec2c39d3a2e_4)
237 #end
238 ##
239 ##
240 ##
241 #**
242 * Retrieves a list of entries to be displayed. All entries belonging to the current blog are returned.
243 *
244 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
245 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
246 * refined to restrict to a given space, or to a given search criteria, etc.
247 * @param entries The resulting list of entries to display, a list of XDocument names.
248 *###
249 #macro(getAllBlogEntries $blogDoc $query $entries)
250 #set($totalEntries = $xwiki.countDocuments(${query}))
251 #set ($legacyRawc2c39d3a2e_5 = $services.query.hql("${query} order by publishDate.value desc").execute())
252 #set ($legacyVisiblec2c39d3a2e_5 = [])
253 #foreach ($legacyEntryc2c39d3a2e_5 in $legacyRawc2c39d3a2e_5)
254 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_5))
255 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_5.add($legacyEntryc2c39d3a2e_5))
256 #end
257 #end
258 #set($entries = $legacyVisiblec2c39d3a2e_5)
259 #end
260 ##
261 ##
262 ##
263 #**
264 * Retrieves a list of entries to be displayed. Only (and all) unpublished entries are returned.
265 *
266 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
267 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
268 * refined to restrict to a given space, or to a given search criteria, etc.
269 * @param entries The resulting list of entries to display, a list of XDocument names.
270 *###
271 #macro(getUnpublishedBlogEntries $blogDoc $query $entries)
272 #set($query = "${query} and isPublished.value = 0")
273 #set($totalEntries = $xwiki.countDocuments(${query}))
274 #set ($legacyRawc2c39d3a2e_6 = $services.query.hql("${query} order by publishDate.value desc").execute())
275 #set ($legacyVisiblec2c39d3a2e_6 = [])
276 #foreach ($legacyEntryc2c39d3a2e_6 in $legacyRawc2c39d3a2e_6)
277 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_6))
278 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_6.add($legacyEntryc2c39d3a2e_6))
279 #end
280 #end
281 #set($entries = $legacyVisiblec2c39d3a2e_6)
282 #end
283 ##
284 ##
285 ##
286 #**
287 * Retrieves a list of entries to be displayed. The entries are taken from all the wiki, and not from a specific blog.
288 *
289 * @param entries The resulting list of entries to display, a list of XDocument names.
290 *###
291 #macro(getGlobalBlogEntries $entries)
292 #getBlogEntriesBaseQuery($query)
293 #set($totalEntries = $xwiki.countDocuments(${query}))
294 #set($defaultItemsPerPage = 20)
295 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
296 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
297 #set ($legacyRawc2c39d3a2e_7 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())
298 #set ($legacyVisiblec2c39d3a2e_7 = [])
299 #foreach ($legacyEntryc2c39d3a2e_7 in $legacyRawc2c39d3a2e_7)
300 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_7))
301 #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_7.add($legacyEntryc2c39d3a2e_7))
302 #end
303 #end
304 #set($entries = $legacyVisiblec2c39d3a2e_7)
305 #end
306 ##
307 ##
308 ##
309 #**
310 * Return the base query for selecting blog entries. It filters only visible entries, but does not bind to a specific
311 * blog, nor specify a range or an ordering criteria.
312 *
313 * @param query The basic query for selecting blog entries.
314 *###
315 #macro(getBlogEntriesBaseQuery $query)
316 #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate
317 where doc.fullName <> 'Blog.BlogPostTemplate' and
318 obj.name = doc.fullName and obj.className = '${blogPostClassname}' and
319 publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and
320 isPublished.id.id = obj.id and isPublished.id.name = 'published' and
321 hidden.id.id = obj.id and hidden.id.name = 'hidden' and
322 (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))")
323 #end
324 ##
325 ##
326 ##
327 #**
328 * Checks if the provided blog is global or in-space.
329 *
330 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>blogType</tt> property set.
331 * @param isGlobal The resulting boolean. If the blog object does not define anything, it is considered in-space.
332 *###
333 #macro(isBlogGlobal $blogDoc $isGlobal)
334 #set($isGlobal = false)
335 #getBlogProperty($blogDoc 'blogType' '' $discard)
336 #if($discard == 'global')
337 #set($isGlobal = true)
338 #end
339 #end
340 ##
341 ##
342 ##
343 #**
344 * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a
345 * week), monthly (all entries in a month), or all.
346 *
347 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt>
348 * property set.
349 * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
350 *###
351 #macro(getBlogDisplayType $blogDoc $displayType)
352 #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType)
353 #end
354 ##
355 ##
356 ##
357 #**
358 * Displays a list of entries.
359 *
360 * @param entries The entries to display, a list of XDocument names.
361 * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results,
362 * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently
363 * used values: index, single, category, search, unpublished, hidden.
364 * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content.
365 *###
366 #macro(displayBlog $entries $displaying $onlyExtract)
367 #set($blogDay = "")
368 <div class="hfeed $!{displaying}">
369 <div class="blogDay">
370 #foreach ($entry in $entries)
371 #set($entryDoc = $xwiki.getDocument($entry))
372 ## This fails if the document is not accessible, due to access rights.
373 #if($entryDoc.fullName == $entry)
374 #getEntryObject($entryDoc $entryObj)
375 ## Although all entries should have one of the two objects, better check to be sure.
376 #if("$!{entryObj}" != '')
377 #getEntryDate($entryDoc $entryObj $entryDate)
378 ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet.
379 #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd'))
380 #if($blogDay != $entryDateStr)
381 #if($blogDay != '')
382 </div>
383 <div class="blogDay">
384 #end
385 #displayBlogDate($entryDate)
386 #set ($blogDay = $entryDateStr)
387 #end
388 ## Finally, display the entry.
389 #displayEntry($entryDoc $entryObj $onlyExtract)
390 #end
391 #end
392 #end
393 </div> ## blogDay
394 </div> ## hfeed
395 #end
396 ##
397 ##
398 ##
399 #**
400 * Get the entry object, either a new BlogPost or an old Article.
401 *
402 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
403 * @param entryObj The resulting xobject of the blog post.
404 *###
405 #macro(getEntryObject $entryDoc $entryObj)
406 #set($entryObj = '')
407 #set($entryObj = $entryDoc.getObject("${blogPostClassname}"))
408 #if("$!{entryObj}" == '')
409 #set($entryObj = $entryDoc.getObject("${oldArticleClassname}"))
410 #end
411 #end
412 ##
413 ##
414 ##
415 #**
416 * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is
417 * the document creation date, but can be edited by the user.
418 *
419 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
420 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
421 * @param result The resulting date, an instance of <tt>java.util.Date</tt>.
422 *###
423 #macro(getEntryDate $entryDoc $entryObj $result)
424 #set($result = $entryObj.getProperty('publishDate').value)
425 #end
426 ##
427 ##
428 ##
429 #**
430 * Displays a date, nicely formatted as a calendar page.
431 *
432 * @param date The date to display, an instance of <tt>java.util.Date</tt>.
433 *###
434 #macro(displayBlogDate $date)
435 #set($year = $xwiki.formatDate($date, "yyyy"))
436 ## 3 letter month name, like Jan, Dec.
437 #set($month = $xwiki.formatDate($date, "MMM"))
438 ## Uncomment to get a full length month name, like January, December.
439 ## TODO: this could be defined somewhere in the blog style.
440 ## #set($month = $xwiki.formatDate($date, "MMMM"))
441 #set($day = $xwiki.formatDate($date, "dd"))
442 <h2 class="blogdate">## title="#formatdateISO($date)">
443 <span class="month">$month</span>
444 <span class="day">$day</span>
445 <span class="year">$year</span>
446 </h2>
447 #end
448 ##
449 ##
450 ##
451 #**
452 * Displays a blog article: management tools, header, content, footer.
453 *
454 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
455 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
456 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
457 *###
458 #macro(displayEntry $entryDoc $entryObj $onlyExtract)
459 ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden
460 #isPublished($entryObj $isPublished)
461 #isHidden($entryObj $isHidden)
462 #if($doc.fullName == $entryDoc.fullName)
463 <div class="hentry single-article">
464 #else
465 <div class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end">
466 #end
467 #displayEntryTools($entryDoc $entryObj)
468 #displayEntryTitle($entryDoc $entryObj)
469 #if($doc.fullName == $entryDoc.fullName)
470 #if(!$isPublished)
471 #warning('This blog post is not published yet.')
472 #elseif($isHidden)
473 #warning('This blog post is hidden.')
474 #end
475 #end
476 #displayEntryContent($entryDoc $entryObj $onlyExtract)
477 #displayEntryFooter($entryDoc $entryObj)
478 </div> ## hentry
479 #end
480 ##
481 ##
482 ##
483 #**
484 * Checks if the provided blog is published or not.
485 *
486 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
487 * @param isPublished The resulting boolean, true if the entry is considered published.
488 *###
489 #macro(isPublished $entryObj $isPublished)
490 ## This should work for both old articles, which don't have the 'published' property at all, and
491 ## are considered published by default, and new entries, that should have 1 if published.
492 #set($isPublished = ("$!{entryObj.getProperty('published').value}" != '0'))
493 #end
494 ##
495 ##
496 ##
497 #**
498 * Checks if the provided blog is hidden or not.
499 *
500 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass.
501 * @param isHiddel The resulting boolean, true if the entry is considered hidden.
502 *###
503 #macro(isHidden $entryObj $isHidden)
504 ## This should work for both old articles, which don't have the 'hidden' property at all, and
505 ## are considered visible by default, and new entries, that should have 1 if hidden.
506 #set($isHidden = ("$!{entryObj.getProperty('hidden').value}" == '1'))
507 #end
508 ##
509 ##
510 ##
511 #**
512 * Displays several "tools" for manipulating blog posts: hide/show, publish, edit.
513 *
514 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
515 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
516 *###
517 #macro(displayEntryTools $entryDoc $entryObj)
518 #if($context.action != 'preview')
519 <div class="blog-entry-toolbox">
520 #displayPublishButton($entryDoc $entryObj)
521 #displayHideShowButton($entryDoc $entryObj)
522 #displayEditButton($entryDoc $entryObj)
523 #displayDeleteButton($entryDoc $entryObj)
524 </div>
525 #end
526 #end
527 ##
528 ##
529 ##
530 #**
531 * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet.
532 *
533 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
534 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
535 * @todo AJAX calls.
536 *###
537 #macro(displayPublishButton $entryDoc $entryObj)
538 #isPublished($entryObj $isPublished)
539 #if(!$isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel("edit", $context.user, $entryDoc.fullName))
540 <a href="$blogPublisher.getURL('view', "entryName=${util.encodeURI($entryDoc.fullName)}&amp;xredirect=${util.encodeURI($thisURL)}")" title="This blog post is not published yet. Publish it">#toolImage('publish.png' 'publish ')</a>##
541 #end
542 #end
543 ##
544 ##
545 ##
546 #**
547 * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published.
548 *
549 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
550 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
551 *###
552 #macro(displayHideShowButton $entryDoc $entryObj)
553 #isPublished($entryObj $isPublished)
554 #isHidden($entryObj $isHidden)
555 ## Only published articles can be hidden. Unpublished articles are considered already hidden.
556 #if($isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName))
557 #if ($isHidden)
558 <a class="blog-tool-show" href="$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=0&amp;comment=Made%20entry%20visible&amp;xredirect=${util.encodeURI($thisURL)}")" title="This blog post is not visible to other users. Make it visible">#toolImage('show.png', 'show ')</a>##
559 #else
560 <a class="blog-tool-hide" href="$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=1&amp;comment=Hidden%20entry&amp;xredirect=${util.encodeURI($thisURL)}")" title="Hide this blog post from other users">#toolImage('hide.png' 'hide ')</a>##
561 #end
562 #end
563 #end
564 ##
565 ##
566 ##
567 #**
568 * Displays the edit button to those that can edit the article.
569 *
570 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
571 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
572 *###
573 #macro(displayEditButton $entryDoc $entryObj)
574 #if($xwiki.hasAccessLevel("edit", $context.user, $entryDoc.fullName))
575 <a href="$entryDoc.getURL('inline')" title="Edit this blog post">#toolImage('edit.png' 'edit ')</a>##
576 #end
577 #end
578 ##
579 ##
580 ##
581 #**
582 * Displays the delete button to those that can edit the article.
583 *
584 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
585 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
586 * @todo AJAX calls.
587 *###
588 #macro(displayDeleteButton $entryDoc $entryObj)
589 #if($xwiki.hasAccessLevel("delete", $context.user, $entryDoc.fullName))
590 <a href="$entryDoc.getURL('delete')" title="Delete this blog post">#toolImage('delete.png' 'delete ')</a>##
591 #end
592 #end
593 ##
594 ##
595 ##
596 #**
597 * Displays the title of the entry.
598 *
599 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
600 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
601 *###
602 #macro(displayEntryTitle $entryDoc $entryObj)
603 #if($doc.fullName == $entryDoc.fullName)
604 <h1 class="entry-title">$entryDoc.display('title', 'view', $entryObj)</h1>
605 #else
606 <h3 class="entry-title"><a href="$entryDoc.getURL()">$entryDoc.display('title', 'view', $entryObj)</a></h3>
607 #end
608 #end
609 ##
610 ##
611 ##
612 #**
613 * Displays the body of the entry.
614 *
615 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
616 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
617 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
618 *###
619 #macro(displayEntryContent $entryDoc $entryObj $onlyExtract)
620 <div class="#if($onlyExtract)entry-summary#{else}entry-content#end">
621 #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent)
622 ## $doc.display does not render non-1.0 syntaxes.
623 #if($!entryDoc.syntaxId == 'xwiki/1.0')
624 $entryContent
625 #else
626 $entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntaxId())
627 #end
628 </div> ## entry-content
629 #end
630 ##
631 ##
632 ##
633 #**
634 * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content
635 * of the <tt>extract</tt> field (if not empty).
636 *
637 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
638 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
639 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
640 * @param entryContent The resulting content.
641 *###
642 #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent)
643 #if($onlyExtract)
644 #set($entryContent = $entryDoc.display('extract', 'view', $entryObj))
645 #end
646 #if("$!entryContent" == '')
647 #set($entryContent = $entryDoc.display('content', 'view', $entryObj))
648 #* Disabled until the content can be cleanly cut.
649 * #if($onlyExtract && $content.length()>$maxchars)
650 * #set($i = $content.lastIndexOf(" ", $maxchars))
651 * #set($i = $i + 1)
652 * #set($content = "${content.substring(0,$i)} *[...>${entryDoc.fullName}]*")
653 * #end
654 ## *###
655 #else
656 #set($entryContent = "${entryContent} <a href='${entryDoc.getURL()}' title='Read the full entry'>...</a>")
657 #end
658 #end
659 ##
660 ##
661 ##
662 #**
663 * Displays the footer of the entry.
664 *
665 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
666 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
667 *###
668 #macro(displayEntryFooter $entryDoc $entryObj)
669 <div class="entry-footer">
670 #isPublished($entryObj $isPublished)
671 #if($isPublished)
672 Posted by ##
673 #else
674 Created by ##
675 #end
676 <address class="author vcard">#userfn($entryDoc.creator)</address> ##
677 #getEntryDate($entryDoc $entryObj $entryDate)
678 at <abbr class="published" title="#formatdateISO($entryDate)">$xwiki.formatDate($entryDate, "MMM dd, yyyy HH:mm")</abbr>##
679 #listCategories($entryObj)##
680 ## Since the publish date and update date are not set at the exact same time, there could be a small difference that
681 ## we assume cannot be more than 3 seconds.
682 #if($entryDoc.date.time - $entryDate.time > 3000)
683 | Modified by <address class="author vcard">#userfn($entryDoc.author)</address> ##
684 at <abbr class="updated" title="#formatdateISO($entryDoc.date)">$xwiki.formatDate($entryDoc.date, "MMM dd, yyyy HH:mm")</abbr> ##
685 #end
686 | <a href="$entryDoc.getURL('view', '#Comments')">$entryDoc.comments.size() Comment(s)</a> ##
687 | <a href="$entryDoc.getURL('view')" rel="bookmark">Permalink</a>
688 </div> ## entry-footer
689 #end
690 ##
691 ##
692 ##
693 #**
694 * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>.
695 *
696 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
697 *###
698 #macro(listCategories $entryObj)
699 #if($entryObj.getxWikiClass().getName() == $blogPostClassname)
700 #set($categories = $entryObj.getProperty('category').value)
701 #set($first = true)
702 #if($categories.size() > 0)
703 #foreach($category in $categories)
704 ## Do not indent
705 #set($categoryDoc = $!xwiki.getDocument($category))
706 #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname}))
707 #if($first)
708 in
709 #set($first = false)
710 #else, #end## if first
711 <a rel="tag" href="$xwiki.getURL(${category})">$!xwiki.getDocument($category).getObject($blogCategoryClassname).getProperty('name').value</a>##
712 #end## if isNew
713 #end## foreach
714 #end
715 #end
716 #end
717 ##
718 ##
719 ##
720 #**
721 * Displays blog pagination links (older and newer entries).
722 *
723 * @param blogDoc the XDocument holding the blog definition object.
724 *###
725 #macro(displayNavigationLinks $blogDoc)
726 <div class="clearfloats"></div>
727 #getBlogDisplayType($blogDoc $displayType)
728 #if($displayType == 'weekly')
729 <div class="pagingLinks">
730 #getRequestedWeek($weekDate)
731 $weekDate.addWeeks(-1)##
732 <span class="prevPage">*[&laquo; Previous week>$doc.name?year=$weekDate.weekyear&amp;week=$weekDate.weekOfWeekyear]*</span>
733 #sep()
734 $weekDate.addWeeks(2)## 2 because we already subtracted 1 above
735 <span class=" nextPage">*[Next week &raquo;>$doc.name?year=$weekDate.weekyear&amp;week=$weekDate.weekOfWeekyear]*</span>
736 </div>
737 #elseif($displayType == 'monthly')
738 <div class="pagingLinks">
739 #getRequestedMonth($monthDate)
740 $monthDate.addMonths(-1)##
741 <span class="prevPage">*[&laquo; Previous month>$doc.name?year=$monthDate.year&amp;month=$monthDate.monthOfYear]*</span>
742 #sep()
743 $monthDate.addMonths(2)## 2 because we already subtracted 1 above
744 <span class=" nextPage">*[Next month &raquo;>$doc.name?year=$monthDate.year&amp;month=$monthDate.monthOfYear]*</span>
745 </div>
746 #elseif($displayType == 'all')
747 #else
748 ## Paginated
749 #if(($totalPages > 1))
750 #set($queryString = "")
751 #foreach($p in $request.getParameterNames())
752 #if($p != 'page' && $p != 'ipp')
753 #foreach($v in $request.getParameterValues($p))
754 #set($queryString = "${queryString}&amp;${p}=${v}")
755 #end
756 #end
757 #end
758 <div class="pagingLinks">
759 #if ($currentPageNumber < $totalPages)
760 #set($currentPageNumber = $currentPageNumber + 1)
761 <span class="prevPage">*[&laquo; Older posts>$doc.name?page=${currentPageNumber}&amp;ipp=${itemsPerPage}$queryString]*</span>
762 #set($currentPageNumber = $currentPageNumber - 1)
763 #end
764 #if ($currentPageNumber > 1)
765 #if ($currentPageNumber < $totalPages)
766 #sep()
767 #end
768 #set($currentPageNumber = $currentPageNumber - 1)
769 <span class="nextPage">*[Newer posts &raquo;>$doc.name?page=${currentPageNumber}&amp;ipp=${itemsPerPage}$queryString]*</span>
770 #set($currentPageNumber = $currentPageNumber + 1)
771 #end
772 <span class="clear"></span>
773 </div> ## pagingLinks
774 #end
775 #end
776 #end
777 ##
778 ##
779 ##
780 #**
781 * Displays a message box with "publish" icon.
782 *
783 * @param message A text message concerning blog article publishing
784 *###
785 #macro(publishMessageBox $message)
786 <div class="plainmessage publish-message">$message</div>
787 #end
788 #**
789 * Displays a message box with "show/hide" icon.
790 *
791 * @param message A text message concerning blog article hiding
792 *###
793 #macro(hideMessageBox $message)
794 <div class="plainmessage hide-message">$message</div>
795 #end
796 ##
797 ##
798 ##
799 #**
800 * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are
801 * <tt>year</tt> and <tt>week</tt>. By default, the current week is used.
802 *
803 * @param monthDate The resulting week, a JODATime MutableDateTime.
804 *###
805 #macro(getRequestedWeek $weekDate)
806 #set($weekDate = $xwiki.jodatime.mutableDateTime)
807 #if("$!{request.year}" != '')
808 $weekDate.setYear($util.parseInt($request.year))
809 #end
810 #if("$!{request.week}" != '')
811 $weekDate.setWeekOfWeekyear($util.parseInt($request.week))
812 #end
813 #end
814 ##
815 ##
816 ##
817 #**
818 * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are
819 * <tt>year</tt> and <tt>month</tt>. By default, the current month is used.
820 *
821 * @param monthDate The resulting month, a JODATime MutableDateTime.
822 *###
823 #macro(getRequestedMonth $monthDate)
824 #set($monthDate = $xwiki.jodatime.mutableDateTime)
825 #if("$!{request.year}" != '')
826 $monthDate.setYear($util.parseInt($request.year))
827 #end
828 #if("$!{request.month}" != '')
829 $monthDate.setMonthOfYear($util.parseInt($request.month))
830 #end
831 #end
832 ##
833 ##
834 ##
835 #**
836 * Retrieve a blog property (title, display type, etc).
837 *
838 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
839 * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties.
840 * @param defaultValue The default value to use in case the blog object does not define one.
841 * @param propertyValue The resulting value.
842 *###
843 #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
844 #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
845 #if($propertyValue == '')
846 #set($propertyValue = $defaultValue)
847 #end
848 #end

#includeMacros("Blog.BlogCode")
#getBlogEntriesBaseQuery($query)
#set($query = "$!{query} and isPublished.value = 1")
#set($recentEntries = $xwiki.searchDocuments("${query} order by publishDate.value desc", 10, 0))
#if($recentEntries.size() > 0 || $showEmptyPanels)
  #panelheader('Recent Blog Posts')
  #foreach($entryDoc in $xwiki.wrapDocs($recentEntries))
    #getEntryObject($entryDoc $entryObj)

  • [$!{entryDoc.display('title', 'view', $entryObj)}>$!{entryDoc.fullName}]
      #end
      #panelfooter()
    #end

#includeMacros("Blog.BlogCode")
#getBlogEntriesBaseQuery($query)
#set($query = "$!{query} and isPublished.value = 0")
#set($unpublishedEntries = $xwiki.searchDocuments("${query} order by publishDate.value desc", 5, 0))
#if($unpublishedEntries.size() > 0 || $showEmptyPanels)
  #panelheader("Unpublished Posts")
  #foreach($entryDoc in $xwiki.wrapDocs($unpublishedEntries))
    #getEntryObject($entryDoc $entryObj)

  • [$!{entryDoc.display('title', 'view', $entryObj)}>$!{entryDoc.fullName}]
      #end
      [View all ($xwiki.countDocuments($query))>Blog.Unpublished]
      #panelfooter()
    #end

#includeMacros("Blog.CategoriesCode")
#panelheader('Blog Categories')
#getCategoriesHierarchy('Blog' $tree)
#displayCategoriesHierarchy($tree 'simple')
#if($xwiki.hasAdminRights())
  <div style="font-size:75%;">(<a href="$xwiki.getURL('Blog.ManageCategories')">Edit Categories</a>)</div>
#end
#panelfooter()

{{include reference="Blog.BlogCode"/}}

{{velocity}} #getAllBlogPostsQueryBasedOnDisplayContext($doc $query $queryParams) #bindQueryParameters($queryObj $queryParams) {{/velocity}}