Version 4.1 by superadmin on 2026/12/02 00:14

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 #getAllBlogPostsQuery($query)
317 #end
318 ##
319 ##
320 ##
321 #**
322 * Checks if the provided blog is global or in-space.
323 *
324 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>blogType</tt> property set.
325 * @param isGlobal The resulting boolean. If the blog object does not define anything, it is considered in-space.
326 *###
327 #macro(isBlogGlobal $blogDoc $isGlobal)
328 #set($isGlobal = false)
329 #getBlogProperty($blogDoc 'blogType' '' $discard)
330 #if($discard == 'global')
331 #set($isGlobal = true)
332 #end
333 #end
334 ##
335 ##
336 ##
337 #**
338 * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a
339 * week), monthly (all entries in a month), or all.
340 *
341 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt>
342 * property set.
343 * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
344 *###
345 #macro(getBlogDisplayType $blogDoc $displayType)
346 #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType)
347 #end
348 ##
349 ##
350 ##
351 #**
352 * Displays a list of entries.
353 *
354 * @param entries The entries to display, a list of XDocument names.
355 * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results,
356 * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently
357 * used values: index, single, category, search, unpublished, hidden.
358 * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content.
359 *###
360 #macro(displayBlog $entries $displaying $onlyExtract)
361 #set($blogDay = "")
362 <div class="hfeed $!{displaying}">
363 <div class="blogDay">
364 #foreach ($entry in $entries)
365 #set($entryDoc = $xwiki.getDocument($entry))
366 ## This fails if the document is not accessible, due to access rights.
367 #if($entryDoc.fullName == $entry)
368 #getEntryObject($entryDoc $entryObj)
369 ## Although all entries should have one of the two objects, better check to be sure.
370 #if("$!{entryObj}" != '')
371 #getEntryDate($entryDoc $entryObj $entryDate)
372 ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet.
373 #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd'))
374 #if($blogDay != $entryDateStr)
375 #if($blogDay != '')
376 </div>
377 <div class="blogDay">
378 #end
379 #displayBlogDate($entryDate)
380 #set ($blogDay = $entryDateStr)
381 #end
382 ## Finally, display the entry.
383 #displayEntry($entryDoc $entryObj $onlyExtract)
384 #end
385 #end
386 #end
387 </div> ## blogDay
388 </div> ## hfeed
389 #end
390 ##
391 ##
392 ##
393 #**
394 * Get the entry object, either a new BlogPost or an old Article.
395 *
396 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
397 * @param entryObj The resulting xobject of the blog post.
398 *###
399 #macro(getEntryObject $entryDoc $entryObj)
400 #set($entryObj = '')
401 #set($entryObj = $entryDoc.getObject("${blogPostClassname}"))
402 #if("$!{entryObj}" == '')
403 #set($entryObj = $entryDoc.getObject("${oldArticleClassname}"))
404 #end
405 #end
406 ##
407 ##
408 ##
409 #**
410 * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is
411 * the document creation date, but can be edited by the user.
412 *
413 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
414 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
415 * @param result The resulting date, an instance of <tt>java.util.Date</tt>.
416 *###
417 #macro(getEntryDate $entryDoc $entryObj $result)
418 #set($result = $entryObj.getProperty('publishDate').value)
419 #end
420 ##
421 ##
422 ##
423 #**
424 * Displays a date, nicely formatted as a calendar page.
425 *
426 * @param date The date to display, an instance of <tt>java.util.Date</tt>.
427 *###
428 #macro(displayBlogDate $date)
429 #set($year = $xwiki.formatDate($date, "yyyy"))
430 ## 3 letter month name, like Jan, Dec.
431 #set($month = $xwiki.formatDate($date, "MMM"))
432 ## Uncomment to get a full length month name, like January, December.
433 ## TODO: this could be defined somewhere in the blog style.
434 ## #set($month = $xwiki.formatDate($date, "MMMM"))
435 #set($day = $xwiki.formatDate($date, "dd"))
436 <h2 class="blogdate">## title="#formatdateISO($date)">
437 <span class="month">$month</span>
438 <span class="day">$day</span>
439 <span class="year">$year</span>
440 </h2>
441 #end
442 ##
443 ##
444 ##
445 #**
446 * Displays a blog article: management tools, header, content, footer.
447 *
448 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
449 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
450 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
451 *###
452 #macro(displayEntry $entryDoc $entryObj $onlyExtract)
453 ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden
454 #isPublished($entryObj $isPublished)
455 #isHidden($entryObj $isHidden)
456 #if($doc.fullName == $entryDoc.fullName)
457 <div class="hentry single-article">
458 #else
459 <div class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end">
460 #end
461 #displayEntryTools($entryDoc $entryObj)
462 #displayEntryTitle($entryDoc $entryObj)
463 #if($doc.fullName == $entryDoc.fullName)
464 #if(!$isPublished)
465 #warning('This blog post is not published yet.')
466 #elseif($isHidden)
467 #warning('This blog post is hidden.')
468 #end
469 #end
470 #displayEntryContent($entryDoc $entryObj $onlyExtract)
471 #displayEntryFooter($entryDoc $entryObj)
472 </div> ## hentry
473 #end
474 ##
475 ##
476 ##
477 #**
478 * Checks if the provided blog is published or not.
479 *
480 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
481 * @param isPublished The resulting boolean, true if the entry is considered published.
482 *###
483 #macro(isPublished $entryObj $isPublished)
484 ## This should work for both old articles, which don't have the 'published' property at all, and
485 ## are considered published by default, and new entries, that should have 1 if published.
486 #set($isPublished = ("$!{entryObj.getProperty('published').value}" != '0'))
487 #end
488 ##
489 ##
490 ##
491 #**
492 * Checks if the provided blog is hidden or not.
493 *
494 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass.
495 * @param isHiddel The resulting boolean, true if the entry is considered hidden.
496 *###
497 #macro(isHidden $entryObj $isHidden)
498 ## This should work for both old articles, which don't have the 'hidden' property at all, and
499 ## are considered visible by default, and new entries, that should have 1 if hidden.
500 #set($isHidden = ("$!{entryObj.getProperty('hidden').value}" == '1'))
501 #end
502 ##
503 ##
504 ##
505 #**
506 * Displays several "tools" for manipulating blog posts: hide/show, publish, edit.
507 *
508 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
509 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
510 *###
511 #macro(displayEntryTools $entryDoc $entryObj)
512 #if($context.action != 'preview')
513 <div class="blog-entry-toolbox">
514 #displayPublishButton($entryDoc $entryObj)
515 #displayHideShowButton($entryDoc $entryObj)
516 #displayEditButton($entryDoc $entryObj)
517 #displayDeleteButton($entryDoc $entryObj)
518 </div>
519 #end
520 #end
521 ##
522 ##
523 ##
524 #**
525 * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet.
526 *
527 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
528 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
529 * @todo AJAX calls.
530 *###
531 #macro(displayPublishButton $entryDoc $entryObj)
532 #isPublished($entryObj $isPublished)
533 #if(!$isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel("edit", $context.user, $entryDoc.fullName))
534 <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>##
535 #end
536 #end
537 ##
538 ##
539 ##
540 #**
541 * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published.
542 *
543 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
544 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
545 *###
546 #macro(displayHideShowButton $entryDoc $entryObj)
547 #isPublished($entryObj $isPublished)
548 #isHidden($entryObj $isHidden)
549 ## Only published articles can be hidden. Unpublished articles are considered already hidden.
550 #if($isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName))
551 #if ($isHidden)
552 <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>##
553 #else
554 <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>##
555 #end
556 #end
557 #end
558 ##
559 ##
560 ##
561 #**
562 * Displays the edit button to those that can edit the article.
563 *
564 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
565 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
566 *###
567 #macro(displayEditButton $entryDoc $entryObj)
568 #if($xwiki.hasAccessLevel("edit", $context.user, $entryDoc.fullName))
569 <a href="$entryDoc.getURL('inline')" title="Edit this blog post">#toolImage('edit.png' 'edit ')</a>##
570 #end
571 #end
572 ##
573 ##
574 ##
575 #**
576 * Displays the delete button to those that can edit the article.
577 *
578 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
579 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
580 * @todo AJAX calls.
581 *###
582 #macro(displayDeleteButton $entryDoc $entryObj)
583 #if($xwiki.hasAccessLevel("delete", $context.user, $entryDoc.fullName))
584 <a href="$entryDoc.getURL('delete')" title="Delete this blog post">#toolImage('delete.png' 'delete ')</a>##
585 #end
586 #end
587 ##
588 ##
589 ##
590 #**
591 * Displays the title of the entry.
592 *
593 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
594 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
595 *###
596 #macro(displayEntryTitle $entryDoc $entryObj)
597 #if($doc.fullName == $entryDoc.fullName)
598 <h1 class="entry-title">$entryDoc.display('title', 'view', $entryObj)</h1>
599 #else
600 <h3 class="entry-title"><a href="$entryDoc.getURL()">$entryDoc.display('title', 'view', $entryObj)</a></h3>
601 #end
602 #end
603 ##
604 ##
605 ##
606 #**
607 * Displays the body of the entry.
608 *
609 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
610 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
611 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
612 *###
613 #macro(displayEntryContent $entryDoc $entryObj $onlyExtract)
614 <div class="#if($onlyExtract)entry-summary#{else}entry-content#end">
615 #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent)
616 ## $doc.display does not render non-1.0 syntaxes.
617 #if($!entryDoc.syntaxId == 'xwiki/1.0')
618 $entryContent
619 #else
620 $entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntaxId())
621 #end
622 </div> ## entry-content
623 #end
624 ##
625 ##
626 ##
627 #**
628 * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content
629 * of the <tt>extract</tt> field (if not empty).
630 *
631 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
632 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
633 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
634 * @param entryContent The resulting content.
635 *###
636 #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent)
637 #if($onlyExtract)
638 #set($entryContent = $entryDoc.display('extract', 'view', $entryObj))
639 #end
640 #if("$!entryContent" == '')
641 #set($entryContent = $entryDoc.display('content', 'view', $entryObj))
642 #* Disabled until the content can be cleanly cut.
643 * #if($onlyExtract && $content.length()>$maxchars)
644 * #set($i = $content.lastIndexOf(" ", $maxchars))
645 * #set($i = $i + 1)
646 * #set($content = "${content.substring(0,$i)} *[...>${entryDoc.fullName}]*")
647 * #end
648 ## *###
649 #else
650 #set($entryContent = "${entryContent} <a href='${entryDoc.getURL()}' title='Read the full entry'>...</a>")
651 #end
652 #end
653 ##
654 ##
655 ##
656 #**
657 * Displays the footer of the entry.
658 *
659 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
660 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
661 *###
662 #macro(displayEntryFooter $entryDoc $entryObj)
663 <div class="entry-footer">
664 #isPublished($entryObj $isPublished)
665 #if($isPublished)
666 Posted by ##
667 #else
668 Created by ##
669 #end
670 <address class="author vcard">#userfn($entryDoc.creator)</address> ##
671 #getEntryDate($entryDoc $entryObj $entryDate)
672 at <abbr class="published" title="#formatdateISO($entryDate)">$xwiki.formatDate($entryDate, "MMM dd, yyyy HH:mm")</abbr>##
673 #listCategories($entryObj)##
674 ## Since the publish date and update date are not set at the exact same time, there could be a small difference that
675 ## we assume cannot be more than 3 seconds.
676 #if($entryDoc.date.time - $entryDate.time > 3000)
677 | Modified by <address class="author vcard">#userfn($entryDoc.author)</address> ##
678 at <abbr class="updated" title="#formatdateISO($entryDoc.date)">$xwiki.formatDate($entryDoc.date, "MMM dd, yyyy HH:mm")</abbr> ##
679 #end
680 | <a href="$entryDoc.getURL('view', '#Comments')">$entryDoc.comments.size() Comment(s)</a> ##
681 | <a href="$entryDoc.getURL('view')" rel="bookmark">Permalink</a>
682 </div> ## entry-footer
683 #end
684 ##
685 ##
686 ##
687 #**
688 * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>.
689 *
690 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
691 *###
692 #macro(listCategories $entryObj)
693 #if($entryObj.getxWikiClass().getName() == $blogPostClassname)
694 #set($categories = $entryObj.getProperty('category').value)
695 #set($first = true)
696 #if($categories.size() > 0)
697 #foreach($category in $categories)
698 ## Do not indent
699 #set($categoryDoc = $!xwiki.getDocument($category))
700 #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname}))
701 #if($first)
702 in
703 #set($first = false)
704 #else, #end## if first
705 <a rel="tag" href="$xwiki.getURL(${category})">$!xwiki.getDocument($category).getObject($blogCategoryClassname).getProperty('name').value</a>##
706 #end## if isNew
707 #end## foreach
708 #end
709 #end
710 #end
711 ##
712 ##
713 ##
714 #**
715 * Displays blog pagination links (older and newer entries).
716 *
717 * @param blogDoc the XDocument holding the blog definition object.
718 *###
719 #macro(displayNavigationLinks $blogDoc)
720 <div class="clearfloats"></div>
721 #getBlogDisplayType($blogDoc $displayType)
722 #if($displayType == 'weekly')
723 <div class="pagingLinks">
724 #getRequestedWeek($weekDate)
725 $weekDate.addWeeks(-1)##
726 <span class="prevPage">*[&laquo; Previous week>$doc.name?year=$weekDate.weekyear&amp;week=$weekDate.weekOfWeekyear]*</span>
727 #sep()
728 $weekDate.addWeeks(2)## 2 because we already subtracted 1 above
729 <span class=" nextPage">*[Next week &raquo;>$doc.name?year=$weekDate.weekyear&amp;week=$weekDate.weekOfWeekyear]*</span>
730 </div>
731 #elseif($displayType == 'monthly')
732 <div class="pagingLinks">
733 #getRequestedMonth($monthDate)
734 $monthDate.addMonths(-1)##
735 <span class="prevPage">*[&laquo; Previous month>$doc.name?year=$monthDate.year&amp;month=$monthDate.monthOfYear]*</span>
736 #sep()
737 $monthDate.addMonths(2)## 2 because we already subtracted 1 above
738 <span class=" nextPage">*[Next month &raquo;>$doc.name?year=$monthDate.year&amp;month=$monthDate.monthOfYear]*</span>
739 </div>
740 #elseif($displayType == 'all')
741 #else
742 ## Paginated
743 #if(($totalPages > 1))
744 #set($queryString = "")
745 #foreach($p in $request.getParameterNames())
746 #if($p != 'page' && $p != 'ipp')
747 #foreach($v in $request.getParameterValues($p))
748 #set($queryString = "${queryString}&amp;${p}=${v}")
749 #end
750 #end
751 #end
752 <div class="pagingLinks">
753 #if ($currentPageNumber < $totalPages)
754 #set($currentPageNumber = $currentPageNumber + 1)
755 <span class="prevPage">*[&laquo; Older posts>$doc.name?page=${currentPageNumber}&amp;ipp=${itemsPerPage}$queryString]*</span>
756 #set($currentPageNumber = $currentPageNumber - 1)
757 #end
758 #if ($currentPageNumber > 1)
759 #if ($currentPageNumber < $totalPages)
760 #sep()
761 #end
762 #set($currentPageNumber = $currentPageNumber - 1)
763 <span class="nextPage">*[Newer posts &raquo;>$doc.name?page=${currentPageNumber}&amp;ipp=${itemsPerPage}$queryString]*</span>
764 #set($currentPageNumber = $currentPageNumber + 1)
765 #end
766 <span class="clear"></span>
767 </div> ## pagingLinks
768 #end
769 #end
770 #end
771 ##
772 ##
773 ##
774 #**
775 * Displays a message box with "publish" icon.
776 *
777 * @param message A text message concerning blog article publishing
778 *###
779 #macro(publishMessageBox $message)
780 <div class="plainmessage publish-message">$message</div>
781 #end
782 #**
783 * Displays a message box with "show/hide" icon.
784 *
785 * @param message A text message concerning blog article hiding
786 *###
787 #macro(hideMessageBox $message)
788 <div class="plainmessage hide-message">$message</div>
789 #end
790 ##
791 ##
792 ##
793 #**
794 * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are
795 * <tt>year</tt> and <tt>week</tt>. By default, the current week is used.
796 *
797 * @param monthDate The resulting week, a JODATime MutableDateTime.
798 *###
799 #macro(getRequestedWeek $weekDate)
800 #set($weekDate = $xwiki.jodatime.mutableDateTime)
801 #if("$!{request.year}" != '')
802 $weekDate.setYear($util.parseInt($request.year))
803 #end
804 #if("$!{request.week}" != '')
805 $weekDate.setWeekOfWeekyear($util.parseInt($request.week))
806 #end
807 #end
808 ##
809 ##
810 ##
811 #**
812 * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are
813 * <tt>year</tt> and <tt>month</tt>. By default, the current month is used.
814 *
815 * @param monthDate The resulting month, a JODATime MutableDateTime.
816 *###
817 #macro(getRequestedMonth $monthDate)
818 #set($monthDate = $xwiki.jodatime.mutableDateTime)
819 #if("$!{request.year}" != '')
820 $monthDate.setYear($util.parseInt($request.year))
821 #end
822 #if("$!{request.month}" != '')
823 $monthDate.setMonthOfYear($util.parseInt($request.month))
824 #end
825 #end
826 ##
827 ##
828 ##
829 #**
830 * Retrieve a blog property (title, display type, etc).
831 *
832 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
833 * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties.
834 * @param defaultValue The default value to use in case the blog object does not define one.
835 * @param propertyValue The resulting value.
836 *###
837 #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
838 #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
839 #if($propertyValue == '')
840 #set($propertyValue = $defaultValue)
841 #end
842 #end
843 ## Compatibility helpers from the installed Blog 9.15.15 package.
844 #macro(bindQueryParameters $queryObj $queryParams)
845 #set ($output = $queryObj)
846 #foreach( $key in $queryParams.keySet() )
847 #set($output = $queryObj.bindValue($key, $queryParams.get($key)))
848 #end
849 #setVariable("$queryObj" $output)
850 #end
851
852 #macro(blog__actionResponseError $status $text $parameters)
853 $response.setStatus($status)
854 #if($request.ajax)
855 $services.localization.render($text, $!parameters)
856 #else
857 {{error}}$services.localization.render($text, $!parameters){{/error}}
858 #end
859 #end
860
861 #macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit)
862 #if ($layout == 'link')
863 #set ($macro.paginated = 'no')
864 #end
865 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
866 ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%'
867 #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout)
868 #if ("$!layout" == '')
869 #set ($layout = $postsLayout)
870 #end
871 #if ($postsVisiblity == 'recent')
872 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
873 #elseif($postsVisiblity == 'unpublished')
874 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
875 #end
876 #elseif($targetDoc.getObject($blogCategoryClassname))
877 ## Display all posts that are in a category aCategorySpace.aCategory
878 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
879 #getBlogPostsLayout($blogDoc $postsLayout)
880 #if ("$!layout" == '')
881 #set ($layout = $postsLayout)
882 #end
883 #if ($postsVisiblity == 'recent')
884 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
885 #elseif($postsVisiblity == 'unpublished')
886 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
887 #end
888 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
889 ## Display all posts that are in a category aCategorySpace.%
890 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
891 #getBlogPostsLayout($blogDoc $postsLayout)
892 #if ("$!layout" == '')
893 #set ($layout = $postsLayout)
894 #end
895 #if ($postsVisiblity == 'recent')
896 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
897 #elseif($postsVisiblity == 'unpublished')
898 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
899 #end
900 #else
901 ## Display all posts in blog space aBlog
902 #getBlogDocument($targetDoc.space $blogDoc)
903 #getBlogPostsLayout($blogDoc $postsLayout)
904 #if ("$!layout" == '')
905 #set ($layout = $postsLayout)
906 #end
907 #if ($postsVisiblity == 'recent')
908 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
909 #elseif($postsVisiblity == 'unpublished')
910 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
911 #end
912 #end
913 #end
914
915 #macro(displayEntryBlogLocation $entryDoc $entryObj)
916 #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ##
917 #if("$!blogPostsLocation" != "") ##
918 #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ##
919 #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ##
920 #if($doc.documentReference != $blogDocRef) ##
921 #set($blogDoc = $xwiki.getDocument($blogDocRef)) ##
922 #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ##
923 #if($blogObj) (% class="blogrefpath" %)((( ##
924 $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ##
925 )))(%%)##
926 #end
927 #end
928 #end
929 #end
930
931 #macro(getAllBlogPostsQuery $query)
932 #set ($query = $NULL)
933 #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished,
934 IntegerProperty hidden, DateProperty publishDate
935 where doc.fullName <> '$blogPostTemplate' and
936 obj.name=doc.fullName and obj.className='$blogPostClassname' and
937 isPublished.id.id = obj.id and isPublished.id.name = 'published' and
938 hidden.id.id = obj.id and hidden.id.name='hidden' and
939 publishDate.id.id = obj.id and publishDate.id.name='publishDate' and
940 (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))")
941 #end
942
943 #macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams)
944 #set ($query = $NULL)
945 #set ($queryParams = $NULL)
946 #getCategoryAllBlogPostsQuery($resultQuery)
947 #set ($resultQueryParams = {})
948 #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
949 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
950 ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%'
951 #set ($discard = $resultQueryParams.put('space', $targetDoc.space))
952 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
953 #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')")
954 #elseif($targetDoc.getObject($blogCategoryClassname))
955 ## Get all posts that are in a category aCategorySpace.aCategory
956 #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName))
957 #set($resultQuery = "${resultQuery} and (catList=:catList)")
958 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
959 ## Get all posts that are in a category aCategorySpace.%
960 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
961 ## Exclude incategorized posts
962 #set ($excludedCategory = "${targetDoc.space}.WebHome")
963 #if ($targetDoc.space == $defaultBlogSpace)
964 #set ($excludedCategory = "Blog.Categories.WebHome")
965 #end
966 #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory))
967 #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')")
968 #else
969 ## Get all posts in blog space aBlog
970 #getAllBlogPostsQuery($resultQuery)
971 #getBlogPostsLocation($targetDoc.space $postsLocation)
972 #set ($discard = $resultQueryParams.put('space', $postsLocation))
973 #set($resultQuery = "${resultQuery} and doc.space = :space")
974 #end
975 #setVariable("$query" $resultQuery)
976 #setVariable("$queryParams" $resultQueryParams)
977 #end
978
979 #macro(getBlogCategoriesLocation $blogSpace $categoriesLocation)
980 #getBlogDocument($blogSpace $blogDoc)
981 ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility.
982 #set ($defaultBlogCategoryLocation = 'Blog.Categories')
983 #if ($services.blog.hasLegacyCategoryAssignments())
984 #set ($defaultBlogCategoryLocation = 'Blog')
985 #end
986 #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result)
987 #set ($postsLocation = $NULL)
988 #setVariable ("$categoriesLocation" $result)
989 #end
990
991 #macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc)
992 #set($macro.blogDocs = $services.query.hql(", BaseObject obj, StringProperty as categoriesLocationProp where obj.name = doc.fullName and obj.className = '$blogClassname' and obj.id=categoriesLocationProp.id.id and categoriesLocationProp.id.name='categoriesLocation' and categoriesLocationProp.value=:categoriesLocation order by doc.creationDate").setLimit(1).setOffset(0).bindValue('categoriesLocation', $categoriesSpace).execute())
993 #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace)
994 #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0)))
995 #else
996 ## Fallback to Blog.WebHome, the default blog
997 #set($macro.result = $xwiki.getDocument('Blog.WebHome'))
998 #end
999 #set ($blogDoc = $NULL)
1000 #setVariable ("$blogDoc" $macro.result)
1001 #end
1002
1003 #macro(getBlogPostsLayout $blogDoc $postsLayout)
1004 #getBlogProperty($blogDoc 'postsLayout' 'full' $res)
1005 #set ($postsLayout = $NULL)
1006 #setVariable ("$postsLayout" $res)
1007 #end
1008
1009 #macro(getBlogPostsLocation $blogSpace $postsLocation)
1010 #getBlogDocument($blogSpace $blogDoc)
1011 #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result)
1012 #set ($postsLocation = $NULL)
1013 #setVariable ("$postsLocation" $result)
1014 #end
1015
1016 #macro(getCategoryAllBlogPostsQuery $query)
1017 #set ($query = $NULL)
1018 #getAllBlogPostsQuery($baseQuery)
1019 #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList'))
1020 #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'")
1021 #end
1022
1023 #macro(isDefaultBlog $blogDoc $isDefault)
1024 #set ($result = false)
1025 #if ($blogDoc.space == 'Blog')
1026 #set ($result = true)
1027 #end
1028 #setVariable("$isDefault" $result)
1029 #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}}