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

Show last authors
1 {{include document="Blog.BlogParameters" author="target" /}}
2
3 {{velocity output="false"}}
4 ##
5 ##
6 ##
7 ## Import the blog skin and javascripts.
8 $!xwiki.ssx.use($blogStyleDocumentName)##
9 $!xwiki.jsx.use($blogScriptsDocumentName)##
10 ##
11 ##
12 ##
13 #**
14 * Prints a blog. This is the main macro used in the BlogSheet.
15 *
16 * @param blogDoc the XDocument holding the blog definition object.
17 *###
18 #macro(printBlog $blogDoc)
19 {{include document='Blog.CreatePost'/}}
20 #getBlogEntries($blogDoc $entries)
21 #displayBlog($entries 'index' true true)
22 #displayNavigationLinks($blogDoc)
23 #end
24 ##
25 ##
26 ##
27 #**
28 * Shows blog information. In view mode, the description is printed. In inline edit mode, allows changing
29 * blog settings: title, description, blog type (global or in-space), index display type (fixed size pagination, weekly
30 * index, monthly index, all entries).
31 *
32 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
33 *###
34 #macro(showBlogInfo $blogDoc)
35 #if($blogDoc.getObject($blogClassname))
36 #if($context.action == 'inline')
37 #macro(displayProperty $blogDoc $propname)
38 <dt>#displayPropName($xwiki.getClass($blogClassname).get($propname)):</dt>
39 <dd>$blogDoc.display($propname)</dd>
40 #end
41 <dl>
42 #displayProperty($blogDoc 'title')
43 #displayProperty($blogDoc 'description')
44 #displayProperty($blogDoc 'blogType')
45 #displayProperty($blogDoc 'displayType')
46 #displayProperty($blogDoc 'itemsPerPage')
47 </dl>
48 #else
49 $blogDoc.display('description')
50 #end
51 #elseif($doc.fullName == $blogSheet)
52 = $msg.get('xe.blog.code.blogsheet') =
53 $msg.get('xe.blog.code.sheetexplanation')
54 #else
55 #warning($msg.get('xe.blog.code.notblog'))
56 #end
57 #end
58 ##
59 ##
60 ##
61 #**
62 * Retrieve the blog document, which usually is either <tt>&lt;Space&gt;.WebHome</tt> for whole-spaces blogs, or
63 * <tt>&lt;Space&gt;.Blog</tt> for in-space blogs. If none of these documents contains a blog object, then the first
64 * (alphabetically) document in the target space that contains one is returned. Finally, if no document in the current
65 * space contains a blog object, then <tt>Blog.WebHome</tt> is returned as the default blog.
66 *
67 * @param space A <tt>String</tt>, the name of the space where to search.
68 * @param blogDoc The resulting XDocument.
69 *###
70 #macro(getBlogDocument $space $blogDoc)
71 ## First, try the Space.WebHome, for a whole-space blog
72 #set($blogDoc = $xwiki.getDocument("${space}.WebHome"))
73 #if(!$blogDoc.getObject($blogClassname))
74 ## Second, try the Space.Blog document
75 #set($blogDoc = $xwiki.getDocument("${space}.Blog"))
76 #if(!$blogDoc.getObject($blogClassname))
77 ## Third, try searching for a blog document in the current space
78 #set ($legacyRawf3cf9e4833_1 = $services.query.hql(", BaseObject obj where doc.space = ? and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").setLimit(1).setOffset(0).bindValues([${space}]).execute())
79 #set ($legacyVisiblef3cf9e4833_1 = [])
80 #foreach ($legacyEntryf3cf9e4833_1 in $legacyRawf3cf9e4833_1)
81 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_1))
82 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_1.add($legacyEntryf3cf9e4833_1))
83 #end
84 #end
85 #set($blogDocs = $legacyVisiblef3cf9e4833_1)
86 #if($blogDocs.size() > 0)
87 #set($blogDoc = $xwiki.getDocument($blogDocs.get(0)))
88 #else
89 ## Last, fallback to Blog.WebHome, the default blog
90 #set($blogDoc = $xwiki.getDocument('Blog.WebHome'))
91 #end
92 #end
93 #end
94 #end
95 ##
96 ##
97 ##
98 #**
99 * Retrieve the blog title.
100 *
101 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass<tt> object with the <tt>title</tt> property set.
102 * @param title The resulting title.
103 *###
104 #macro(getBlogTitle $blogDoc $title)
105 #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $title)
106 #end
107 ##
108 ##
109 ##
110 #**
111 * Retrieve the blog description.
112 *
113 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>description</tt>
114 * property set.
115 * @param description The resulting description.
116 *###
117 #macro(getBlogDescription $blogDoc $description)
118 #getBlogProperty($blogDoc 'description' '' $description)
119 #end
120 ##
121 ##
122 ##
123 #**
124 * Retrieves a list of entries to be displayed. The entries are either part of the blog's space, or have the blog
125 * document set as a parent. The number and range of entries returned (from all those belonging to this blog) depends on
126 * the blog display type: paginated (fixed number of entries), weekly (all entries in a week), monthly (all entries in a
127 * month), or all.
128 *
129 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
130 * @param entries The resulting list of entries to display, a list of XDocument names.
131 *###
132 #macro(getBlogEntries $blogDoc $entries)
133 #getBlogEntriesBaseQuery($query)
134 #isBlogGlobal($blogDoc $isGlobal)
135 #if(!$isGlobal)
136 #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')")
137 #end
138 #getBlogDisplayType($blogDoc $displayType)
139 #if($displayType == 'weekly')
140 #getWeeklyBlogEntries($blogDoc $query $entries)
141 #elseif($displayType == 'monthly')
142 #getMonthlyBlogEntries($blogDoc $query $entries)
143 #elseif($displayType == 'all')
144 #getAllBlogEntries($blogDoc $query $entries)
145 #else
146 #getPagedBlogEntries($blogDoc $query $entries)
147 #end
148 #end
149 ##
150 ##
151 ##
152 #**
153 * Retrieves a list of entries to be displayed. The entries are taken from a "page" of the blog, a sequence of documents
154 * defined by the request parameters <tt>ipp</tt> (items per page) and <tt>page</tt> (the current page). Initially the
155 * first page is displayed, with the number of entries defined in the blog object in the <tt>itemsPerPage</tt> property
156 * (10 if not defined).
157 *
158 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
159 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
160 * refined to restrict to a given space, or to a given search criteria, etc.
161 * @param entries The resulting list of entries to display, a list of XDocument names.
162 *###
163 #macro(getPagedBlogEntries $blogDoc $query $entries)
164 #set($totalEntries = $xwiki.countDocuments(${query}))
165 #getBlogProperty($blogDoc 'itemsPerPage' '10' $defaultItemsPerPage)
166 #set($defaultItemsPerPage = $util.parseInt($defaultItemsPerPage))
167 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
168 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
169 #set ($legacyRawf3cf9e4833_2 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())
170 #set ($legacyVisiblef3cf9e4833_2 = [])
171 #foreach ($legacyEntryf3cf9e4833_2 in $legacyRawf3cf9e4833_2)
172 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_2))
173 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_2.add($legacyEntryf3cf9e4833_2))
174 #end
175 #end
176 #set($entries = $legacyVisiblef3cf9e4833_2)
177 #end
178 ##
179 ##
180 ##
181 #**
182 * Retrieves a list of entries to be displayed. The entries are taken from a week of the blog. The target week is
183 * defined by the request parameters <tt>week</tt> (the week number in the year, from 1 to 52) and <tt>year</tt> (4
184 * digit year). Initially the current week is displayed.
185 *
186 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
187 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
188 * refined to restrict to a given space, or to a given search criteria, etc.
189 * @param entries The resulting list of entries to display, a list of XDocument names.
190 *###
191 #macro(getWeeklyBlogEntries $blogDoc $query $entries)
192 #getRequestedWeek($weekDate)
193 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd'))
194 #set($minDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundFloor()))
195 #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling()))
196 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
197 #set($totalEntries = $xwiki.countDocuments(${query}))
198 #set ($legacyRawf3cf9e4833_3 = $services.query.hql("${query} order by publishDate.value desc").execute())
199 #set ($legacyVisiblef3cf9e4833_3 = [])
200 #foreach ($legacyEntryf3cf9e4833_3 in $legacyRawf3cf9e4833_3)
201 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_3))
202 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_3.add($legacyEntryf3cf9e4833_3))
203 #end
204 #end
205 #set($entries = $legacyVisiblef3cf9e4833_3)
206 #end
207 ##
208 ##
209 ##
210 #**
211 * Retrieves a list of entries to be displayed. The entries are taken from a month of the blog. The target month is
212 * defined by the request parameters <tt>month</tt> (the month number, from 1 to 12) and <tt>year</tt> (4
213 * digit year). Initially the current month is displayed.
214 *
215 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
216 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
217 * refined to restrict to a given space, or to a given search criteria, etc.
218 * @param entries The resulting list of entries to display, a list of XDocument names.
219 *###
220 #macro(getMonthlyBlogEntries $blogDoc $query $entries)
221 #getRequestedMonth($monthDate)
222 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd'))
223 #set($minDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundFloor()))
224 #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling()))
225 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
226 #set($totalEntries = $xwiki.countDocuments(${query}))
227 #set ($legacyRawf3cf9e4833_4 = $services.query.hql("${query} order by publishDate.value desc").execute())
228 #set ($legacyVisiblef3cf9e4833_4 = [])
229 #foreach ($legacyEntryf3cf9e4833_4 in $legacyRawf3cf9e4833_4)
230 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_4))
231 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_4.add($legacyEntryf3cf9e4833_4))
232 #end
233 #end
234 #set($entries = $legacyVisiblef3cf9e4833_4)
235 #end
236 ##
237 ##
238 ##
239 #**
240 * Retrieves a list of entries to be displayed. All entries belonging to the current blog are returned.
241 *
242 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
243 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
244 * refined to restrict to a given space, or to a given search criteria, etc.
245 * @param entries The resulting list of entries to display, a list of XDocument names.
246 *###
247 #macro(getAllBlogEntries $blogDoc $query $entries)
248 #set($totalEntries = $xwiki.countDocuments(${query}))
249 #set ($legacyRawf3cf9e4833_5 = $services.query.hql("${query} order by publishDate.value desc").execute())
250 #set ($legacyVisiblef3cf9e4833_5 = [])
251 #foreach ($legacyEntryf3cf9e4833_5 in $legacyRawf3cf9e4833_5)
252 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_5))
253 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_5.add($legacyEntryf3cf9e4833_5))
254 #end
255 #end
256 #set($entries = $legacyVisiblef3cf9e4833_5)
257 #end
258 ##
259 ##
260 ##
261 #**
262 * Retrieves a list of entries to be displayed. Only (and all) unpublished entries are returned.
263 *
264 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
265 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
266 * refined to restrict to a given space, or to a given search criteria, etc.
267 * @param entries The resulting list of entries to display, a list of XDocument names.
268 *###
269 #macro(getUnpublishedBlogEntries $blogDoc $query $entries)
270 #set($query = "${query} and isPublished.value = 0")
271 #set($totalEntries = $xwiki.countDocuments(${query}))
272 #set ($legacyRawf3cf9e4833_6 = $services.query.hql("${query} order by publishDate.value desc").execute())
273 #set ($legacyVisiblef3cf9e4833_6 = [])
274 #foreach ($legacyEntryf3cf9e4833_6 in $legacyRawf3cf9e4833_6)
275 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_6))
276 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_6.add($legacyEntryf3cf9e4833_6))
277 #end
278 #end
279 #set($entries = $legacyVisiblef3cf9e4833_6)
280 #end
281 ##
282 ##
283 ##
284 #**
285 * Retrieves a list of entries to be displayed. The entries are taken from all the wiki, and not from a specific blog.
286 *
287 * @param entries The resulting list of entries to display, a list of XDocument names.
288 *###
289 #macro(getGlobalBlogEntries $entries)
290 #getBlogEntriesBaseQuery($query)
291 #set($totalEntries = $xwiki.countDocuments(${query}))
292 #set($defaultItemsPerPage = 20)
293 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
294 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
295 #set ($legacyRawf3cf9e4833_7 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())
296 #set ($legacyVisiblef3cf9e4833_7 = [])
297 #foreach ($legacyEntryf3cf9e4833_7 in $legacyRawf3cf9e4833_7)
298 #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_7))
299 #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_7.add($legacyEntryf3cf9e4833_7))
300 #end
301 #end
302 #set($entries = $legacyVisiblef3cf9e4833_7)
303 #end
304 ##
305 ##
306 ##
307 #**
308 * Return the base query for selecting blog entries. It filters only visible entries, but does not bind to a specific
309 * blog, nor specify a range or an ordering criteria.
310 *
311 * @param query The basic query for selecting blog entries.
312 *###
313 #macro(getBlogEntriesBaseQuery $query)
314 #getAllBlogPostsQuery($query)
315 #end
316 ##
317 ##
318 ##
319 #**
320 * Checks if the provided blog is global or in-space.
321 *
322 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>blogType</tt> property set.
323 * @param isGlobal The resulting boolean. If the blog object does not define anything, it is considered in-space.
324 *###
325 #macro(isBlogGlobal $blogDoc $isGlobal)
326 #set($isGlobal = false)
327 #getBlogProperty($blogDoc 'blogType' '' $discard)
328 #if($discard == 'global')
329 #set($isGlobal = true)
330 #end
331 #end
332 ##
333 ##
334 ##
335 #**
336 * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a
337 * week), monthly (all entries in a month), or all.
338 *
339 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt>
340 * property set.
341 * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
342 *###
343 #macro(getBlogDisplayType $blogDoc $displayType)
344 #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType)
345 #end
346 ##
347 ##
348 ##
349 #**
350 * Displays a list of entries.
351 *
352 * @param entries The entries to display, a list of XDocument names.
353 * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results,
354 * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently
355 * used values: index, single, category, search, unpublished, hidden.
356 * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content.
357 * @param shouldDisplayTitles If <tt>true</tt>, display the blog title (blog posts shouldn't display the title when they're
358 * displayed alone on their page since it's the page title which is used in this case)
359 *###
360 #macro(displayBlog $entries $displaying $onlyExtract $shouldDisplayTitles)
361 #set($blogDay = '')
362 <div class="hfeed $!{displaying}">
363 <div class="blogDay">
364 #foreach ($entryDoc in $xwiki.wrapDocs($entries))
365 #getEntryObject($entryDoc $entryObj)
366 ## Although all entries should have one of the two objects, better check to be sure.
367 #if("$!{entryObj}" != '')
368 #getEntryDate($entryDoc $entryObj $entryDate)
369 ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet.
370 #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd'))
371 #if($blogDay != $entryDateStr)
372 #if($blogDay != '')
373 </div>
374 <div class="blogDay">
375 #end
376 #displayBlogDate($entryDate)
377 #set ($blogDay = $entryDateStr)
378 #end
379 ## Finally, display the entry.
380 #displayEntry($entryDoc $entryObj $onlyExtract $shouldDisplayTitles)
381 #end
382 #end
383 </div> ## blogDay
384 </div> ## hfeed
385 #end
386 ##
387 ##
388 ##
389 #**
390 * Get the entry object, either a new BlogPost or an old Article.
391 *
392 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
393 * @param entryObj The resulting xobject of the blog post.
394 *###
395 #macro(getEntryObject $entryDoc $entryObj)
396 #set($entryObj = '')
397 #set($entryObj = $entryDoc.getObject("${blogPostClassname}"))
398 #if("$!{entryObj}" == '')
399 #set($entryObj = $entryDoc.getObject("${oldArticleClassname}"))
400 #end
401 #end
402 ##
403 ##
404 ##
405 #**
406 * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is
407 * the document creation date, but can be edited by the user.
408 *
409 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
410 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
411 * @param result The resulting date, an instance of <tt>java.util.Date</tt>.
412 *###
413 #macro(getEntryDate $entryDoc $entryObj $result)
414 #set($result = $entryObj.getProperty('publishDate').value)
415 #end
416 ##
417 ##
418 ##
419 #**
420 * Displays a date, nicely formatted as a calendar page.
421 *
422 * @param date The date to display, an instance of <tt>java.util.Date</tt>.
423 *###
424 #macro(displayBlogDate $date)
425 #set($year = $xwiki.formatDate($date, 'yyyy'))
426 ## 3 letter month name, like Jan, Dec.
427 #set($month = $xwiki.formatDate($date, 'MMM'))
428 ## Uncomment to get a full length month name, like January, December.
429 ## TODO: this could be defined somewhere in the blog style.
430 ## #set($month = $xwiki.formatDate($date, 'MMMM'))
431 #set($day = $xwiki.formatDate($date, 'dd'))
432 <h2 class="blogdate">## title="#formatdateISO($date)">
433 <span class="month">$month</span>
434 <span class="day">$day</span>
435 <span class="year">$year</span>
436 </h2>
437 #end
438 ##
439 ##
440 ##
441 #**
442 * Displays a blog article: management tools, header, content, footer.
443 *
444 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
445 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
446 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
447 * @param shouldDisplayTitle If <tt>true</tt>, display the blog title (blog posts shouldn't display the title
448 * when they're displayed alone on their page since it's the page title which is used in this case)
449 *###
450 #macro(displayEntry $entryDoc $entryObj $onlyExtract $shouldDisplayTitle)
451 ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden
452 #isPublished($entryObj $isPublished)
453 #isHidden($entryObj $isHidden)
454 #if($doc.fullName == $entryDoc.fullName)
455 <div class="hentry single-article">
456 #else
457 <div class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end">
458 #end
459 #displayEntryTools($entryDoc $entryObj)
460 #if($shouldDisplayTitle)
461 #displayEntryTitle($entryDoc $entryObj)
462 #end
463 #if($doc.fullName == $entryDoc.fullName)
464 #if(!$isPublished)
465 #warning($msg.get('xe.blog.code.published'))
466 #elseif($isHidden)
467 #warning($msg.get('xe.blog.code.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 == 'view')
513 {{html wiki="false"}}
514 <div class="blog-entry-toolbox">
515 #displayPublishButton($entryDoc $entryObj)
516 #displayHideShowButton($entryDoc $entryObj)
517 #displayEditButton($entryDoc $entryObj)
518 #displayDeleteButton($entryDoc $entryObj)
519 </div>
520 {{/html}}
521 #end
522 #end
523 ##
524 ##
525 ##
526 #**
527 * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet.
528 *
529 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
530 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
531 * @todo AJAX calls.
532 *###
533 #macro(displayPublishButton $entryDoc $entryObj)
534 #isPublished($entryObj $isPublished)
535 #if(!$isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName))
536 <a href="$blogPublisher.getURL('view', "entryName=${escapetool.url($entryDoc.fullName)}&amp;xredirect=${escapetool.url($thisURL)}")" title="${escapetool.xml($msg.get('xe.blog.code.notpublished'))}">#toolImage('page_white_world' 'publish ')</a>##
537 #end
538 #end
539 ##
540 ##
541 ##
542 #**
543 * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published.
544 *
545 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
546 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
547 *###
548 #macro(displayHideShowButton $entryDoc $entryObj)
549 #isPublished($entryObj $isPublished)
550 #isHidden($entryObj $isHidden)
551 ## Only published articles can be hidden. Unpublished articles are considered already hidden.
552 #if($isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName))
553 #if ($isHidden)
554 <a class="blog-tool-show" href="$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=0&amp;comment=${escapetool.url($msg.get('xe.blog.code.madevisible'))}&amp;xredirect=${escapetool.url($thisURL)}")" title="${escapetool.xml($msg.get('xe.blog.code.makevisible'))}">#toolImage('lock_open', 'show ')</a>##
555 #else
556 <a class="blog-tool-hide" href="$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=1&amp;comment=${escapetool.url($msg.get('xe.blog.code.hid'))}&amp;xredirect=${escapetool.url($thisURL)}")" title="${escapetool.xml($msg.get('xe.blog.code.hide'))}">#toolImage('lock' 'hide ')</a>##
557 #end
558 #end
559 #end
560 ##
561 ##
562 ##
563 #**
564 * Displays the edit button to those that can edit the article.
565 *
566 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
567 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
568 *###
569 #macro(displayEditButton $entryDoc $entryObj)
570 #if($xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName))
571 <a href="$entryDoc.getURL('inline')" title="${escapetool.xml($msg.get('xe.blog.code.editpost'))}">#toolImage('pencil' 'edit ')</a>##
572 #end
573 #end
574 ##
575 ##
576 ##
577 #**
578 * Displays the delete button to those that can edit the article.
579 *
580 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
581 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
582 * @todo AJAX calls.
583 *###
584 #macro(displayDeleteButton $entryDoc $entryObj)
585 #if($xwiki.hasAccessLevel('delete', $context.user, $entryDoc.fullName))
586 <a href="$entryDoc.getURL('delete')" title="${escapetool.xml($msg.get('xe.blog.code.deletepost'))}">#toolImage('cross' 'delete ')</a>##
587 #end
588 #end
589 ##
590 ##
591 ##
592 #**
593 * Displays the title of the entry.
594 *
595 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
596 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
597 *###
598 #macro(displayEntryTitle $entryDoc $entryObj)
599 {{html wiki="false"}}
600 #if($doc.fullName == $entryDoc.fullName)
601 <h1 class="entry-title">$entryDoc.display('title', 'view', $entryObj)</h1>
602 #else
603 <h3 class="entry-title"><a href="$entryDoc.getURL()">$entryDoc.display('title', 'view', $entryObj)</a></h3>
604 #end
605 {{/html}}
606 #end
607 ##
608 ##
609 ##
610 #**
611 * Displays the body of the entry.
612 *
613 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
614 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
615 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
616 *###
617 #macro(displayEntryContent $entryDoc $entryObj $onlyExtract)
618 #set($entryContent = '')
619 <div class="#if($onlyExtract)entry-summary#{else}entry-content#end">
620 #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent)
621 {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntax().toIdString()){{/html}}
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 = $entryObj.getProperty('extract').value)
639 #end
640 #if("$!entryContent" == '')
641 #set($entryContent = $entryObj.getProperty('content').value)
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 #if($entryDoc.syntax == 'xwiki/1.0')
651 #set($entryContent = "${entryContent} <a href='${entryDoc.getURL()}' title='$msg.get('xe.blog.code.readpost')'>...</a>")
652 #else
653 #set($entryContent = "${entryContent} [[...>>${entryDoc}||title='$msg.get('xe.blog.code.readpost')']]")
654 #end
655 #end
656 #end
657 ##
658 ##
659 ##
660 #**
661 * Displays the footer of the entry.
662 *
663 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
664 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
665 *###
666 #macro(displayEntryFooter $entryDoc $entryObj)
667 {{html wiki="false"}}
668 <div class="entry-footer">
669 #isPublished($entryObj $isPublished)
670 #if($isPublished)
671 $msg.get('xe.blog.code.postedby') ##
672 #else
673 $msg.get('xe.blog.code.createdby') ##
674 #end
675 <address class="author vcard">#userfn($entryDoc.creator)</address> ##
676 #getEntryDate($entryDoc $entryObj $entryDate)
677 #listCategories($entryObj) ##
678 ## Since the publish date and update date are not set at the exact same time, there could be a small difference that
679 ## we assume cannot be more than 3 seconds.
680 | <a href="$entryDoc.getURL('view')" rel="bookmark">$msg.get('xe.blog.code.permalink')</a> ##
681 | <a href="$entryDoc.getURL('view', '#Comments')">$entryDoc.comments.size() $msg.get('xe.blog.code.comments')</a> ##
682 </div> ## entry-footer
683 {{/html}}
684 #end
685 ##
686 ##
687 ##
688 #**
689 * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>.
690 *
691 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
692 *###
693 #macro(listCategories $entryObj)
694 #if($entryObj.getxWikiClass().getName() == $blogPostClassname)
695 #set($categories = $entryObj.getProperty('category').value)
696 #set($first = true)
697 #if($categories.size() > 0)
698 #foreach($category in $categories)
699 ## Do not indent
700 #set($categoryDoc = $!xwiki.getDocument($category))
701 #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname}))
702 #if($first)
703 | $msg.get('xe.blog.code.categories')
704 #set($first = false)
705 #else, #end## if first
706 <a rel="tag" href="$xwiki.getURL(${category})">$!{escapetool.xml($!xwiki.getDocument($category).getObject($blogCategoryClassname).getProperty('name').value)}</a>##
707 #end## if isNew
708 #end## foreach
709 #end
710 #end
711 #end
712 ##
713 ##
714 ##
715 #**
716 * Displays blog pagination links (older and newer entries).
717 *
718 * @param blogDoc the XDocument holding the blog definition object.
719 *###
720 #macro(displayNavigationLinks $blogDoc)
721 <div class="clearfloats"></div>
722 #getBlogDisplayType($blogDoc $displayType)
723 #if($displayType == 'weekly')
724 <div class="pagingLinks">
725 #getRequestedWeek($weekDate)
726 $weekDate.addWeeks(-1)##
727 (% class="prevPage" %)**[[&laquo; $msg.get('xe.blog.code.previousweek')>>$doc.name?year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear]]**(%%)
728 #sep()
729 $weekDate.addWeeks(2)## 2 because we already subtracted 1 above
730 (% class="nextPage" %)**[[$msg.get('xe.blog.code.nextweek') &raquo;>>$doc.name?year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear]]**(%%)
731 </div>
732 #elseif($displayType == 'monthly')
733 <div class="pagingLinks">
734 #getRequestedMonth($monthDate)
735 $monthDate.addMonths(-1)##
736 (% class="prevPage" %)**[[&laquo; $msg.get('xe.blog.code.previousmonth')>>$doc.name?year=$monthDate.year&month=$monthDate.monthOfYear]]**(%%)
737 #sep()
738 $monthDate.addMonths(2)## 2 because we already subtracted 1 above
739 (% class="nextPage" %)**[[$msg.get('xe.blog.code.nextmonth') &raquo;>>$doc.name?year=$monthDate.year&month=$monthDate.monthOfYear]]**(%%)
740 </div>
741 #elseif($displayType == 'all')
742 #else
743 ## Paginated
744 #if(($totalPages > 1))
745 #set($queryString = "")
746 #foreach($p in $request.getParameterNames())
747 #if($p != 'page' && $p != 'ipp')
748 #foreach($v in $request.getParameterValues($p))
749 #set($queryString = "${queryString}&amp;${p}=${v}")
750 #end
751 #end
752 #end
753 <div class="pagingLinks">
754 #if ($currentPageNumber < $totalPages)
755 #set($currentPageNumber = $currentPageNumber + 1)
756 (% class="prevPage" %)**[[&laquo; $msg.get('xe.blog.code.olderposts')>>$doc.name?page=${currentPageNumber}&ipp=${itemsPerPage}$queryString]]**(%%)
757 #set($currentPageNumber = $currentPageNumber - 1)
758 #end
759 #if ($currentPageNumber > 1)
760 #if ($currentPageNumber < $totalPages)
761 #sep()
762 #end
763 #set($currentPageNumber = $currentPageNumber - 1)
764 (% class="nextPage" %)**[[$msg.get('xe.blog.code.newerposts') &raquo;>>$doc.name?page=${currentPageNumber}&ipp=${itemsPerPage}$queryString]]**(%%)
765 #set($currentPageNumber = $currentPageNumber + 1)
766 #end
767 <span class="clear"></span>
768 </div> ## pagingLinks
769 #end
770 #end
771 #end
772 ##
773 ##
774 ##
775 #**
776 * Displays a message box with "publish" icon.
777 *
778 * @param message A text message concerning blog article publishing
779 *###
780 #macro(publishMessageBox $message)
781 <div class="plainmessage publish-message">$message</div>
782 #end
783 #**
784 * Displays a message box with "show/hide" icon.
785 *
786 * @param message A text message concerning blog article hiding
787 *###
788 #macro(hideMessageBox $message)
789 <div class="plainmessage hide-message">$message</div>
790 #end
791 ##
792 ##
793 ##
794 #**
795 * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are
796 * <tt>year</tt> and <tt>week</tt>. By default, the current week is used.
797 *
798 * @param monthDate The resulting week, a JODATime MutableDateTime.
799 *###
800 #macro(getRequestedWeek $weekDate)
801 #set($weekDate = $xwiki.jodatime.mutableDateTime)
802 #if("$!{request.year}" != '')
803 $weekDate.setYear($util.parseInt($request.year))
804 #end
805 #if("$!{request.week}" != '')
806 $weekDate.setWeekOfWeekyear($util.parseInt($request.week))
807 #end
808 #end
809 ##
810 ##
811 ##
812 #**
813 * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are
814 * <tt>year</tt> and <tt>month</tt>. By default, the current month is used.
815 *
816 * @param monthDate The resulting month, a JODATime MutableDateTime.
817 *###
818 #macro(getRequestedMonth $monthDate)
819 #set($monthDate = $xwiki.jodatime.mutableDateTime)
820 #if("$!{request.year}" != '')
821 $monthDate.setYear($util.parseInt($request.year))
822 #end
823 #if("$!{request.month}" != '')
824 $monthDate.setMonthOfYear($util.parseInt($request.month))
825 #end
826 #end
827 ##
828 ##
829 ##
830 #**
831 * Retrieve a blog property (title, display type, etc).
832 *
833 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
834 * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties.
835 * @param defaultValue The default value to use in case the blog object does not define one.
836 * @param propertyValue The resulting value.
837 *###
838 #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
839 #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
840 #if($propertyValue == '')
841 #set($propertyValue = $defaultValue)
842 #end
843 #end
844
845 ## Compatibility helpers from the installed Blog 9.15.15 package.
846 #macro(bindQueryParameters $queryObj $queryParams)
847 #set ($output = $queryObj)
848 #foreach( $key in $queryParams.keySet() )
849 #set($output = $queryObj.bindValue($key, $queryParams.get($key)))
850 #end
851 #setVariable("$queryObj" $output)
852 #end
853
854 #macro(blog__actionResponseError $status $text $parameters)
855 $response.setStatus($status)
856 #if($request.ajax)
857 $services.localization.render($text, $!parameters)
858 #else
859 {{error}}$services.localization.render($text, $!parameters){{/error}}
860 #end
861 #end
862
863 #macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit)
864 #if ($layout == 'link')
865 #set ($macro.paginated = 'no')
866 #end
867 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
868 ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%'
869 #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout)
870 #if ("$!layout" == '')
871 #set ($layout = $postsLayout)
872 #end
873 #if ($postsVisiblity == 'recent')
874 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
875 #elseif($postsVisiblity == 'unpublished')
876 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
877 #end
878 #elseif($targetDoc.getObject($blogCategoryClassname))
879 ## Display all posts that are in a category aCategorySpace.aCategory
880 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
881 #getBlogPostsLayout($blogDoc $postsLayout)
882 #if ("$!layout" == '')
883 #set ($layout = $postsLayout)
884 #end
885 #if ($postsVisiblity == 'recent')
886 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
887 #elseif($postsVisiblity == 'unpublished')
888 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
889 #end
890 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
891 ## Display all posts that are in a category aCategorySpace.%
892 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
893 #getBlogPostsLayout($blogDoc $postsLayout)
894 #if ("$!layout" == '')
895 #set ($layout = $postsLayout)
896 #end
897 #if ($postsVisiblity == 'recent')
898 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
899 #elseif($postsVisiblity == 'unpublished')
900 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
901 #end
902 #else
903 ## Display all posts in blog space aBlog
904 #getBlogDocument($targetDoc.space $blogDoc)
905 #getBlogPostsLayout($blogDoc $postsLayout)
906 #if ("$!layout" == '')
907 #set ($layout = $postsLayout)
908 #end
909 #if ($postsVisiblity == 'recent')
910 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
911 #elseif($postsVisiblity == 'unpublished')
912 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
913 #end
914 #end
915 #end
916
917 #macro(displayEntryBlogLocation $entryDoc $entryObj)
918 #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ##
919 #if("$!blogPostsLocation" != "") ##
920 #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ##
921 #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ##
922 #if($doc.documentReference != $blogDocRef) ##
923 #set($blogDoc = $xwiki.getDocument($blogDocRef)) ##
924 #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ##
925 #if($blogObj) (% class="blogrefpath" %)((( ##
926 $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ##
927 )))(%%)##
928 #end
929 #end
930 #end
931 #end
932
933 #macro(getAllBlogPostsQuery $query)
934 #set ($query = $NULL)
935 #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished,
936 IntegerProperty hidden, DateProperty publishDate
937 where doc.fullName <> '$blogPostTemplate' and
938 obj.name=doc.fullName and obj.className='$blogPostClassname' and
939 isPublished.id.id = obj.id and isPublished.id.name = 'published' and
940 hidden.id.id = obj.id and hidden.id.name='hidden' and
941 publishDate.id.id = obj.id and publishDate.id.name='publishDate' and
942 (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))")
943 #end
944
945 #macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams)
946 #set ($query = $NULL)
947 #set ($queryParams = $NULL)
948 #getCategoryAllBlogPostsQuery($resultQuery)
949 #set ($resultQueryParams = {})
950 #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
951 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
952 ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%'
953 #set ($discard = $resultQueryParams.put('space', $targetDoc.space))
954 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
955 #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')")
956 #elseif($targetDoc.getObject($blogCategoryClassname))
957 ## Get all posts that are in a category aCategorySpace.aCategory
958 #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName))
959 #set($resultQuery = "${resultQuery} and (catList=:catList)")
960 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
961 ## Get all posts that are in a category aCategorySpace.%
962 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
963 ## Exclude incategorized posts
964 #set ($excludedCategory = "${targetDoc.space}.WebHome")
965 #if ($targetDoc.space == $defaultBlogSpace)
966 #set ($excludedCategory = "Blog.Categories.WebHome")
967 #end
968 #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory))
969 #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')")
970 #else
971 ## Get all posts in blog space aBlog
972 #getAllBlogPostsQuery($resultQuery)
973 #getBlogPostsLocation($targetDoc.space $postsLocation)
974 #set ($discard = $resultQueryParams.put('space', $postsLocation))
975 #set($resultQuery = "${resultQuery} and doc.space = :space")
976 #end
977 #setVariable("$query" $resultQuery)
978 #setVariable("$queryParams" $resultQueryParams)
979 #end
980
981 #macro(getBlogCategoriesLocation $blogSpace $categoriesLocation)
982 #getBlogDocument($blogSpace $blogDoc)
983 ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility.
984 #set ($defaultBlogCategoryLocation = 'Blog.Categories')
985 #if ($services.blog.hasLegacyCategoryAssignments())
986 #set ($defaultBlogCategoryLocation = 'Blog')
987 #end
988 #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result)
989 #set ($postsLocation = $NULL)
990 #setVariable ("$categoriesLocation" $result)
991 #end
992
993 #macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc)
994 #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())
995 #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace)
996 #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0)))
997 #else
998 ## Fallback to Blog.WebHome, the default blog
999 #set($macro.result = $xwiki.getDocument('Blog.WebHome'))
1000 #end
1001 #set ($blogDoc = $NULL)
1002 #setVariable ("$blogDoc" $macro.result)
1003 #end
1004
1005 #macro(getBlogPostsLayout $blogDoc $postsLayout)
1006 #getBlogProperty($blogDoc 'postsLayout' 'full' $res)
1007 #set ($postsLayout = $NULL)
1008 #setVariable ("$postsLayout" $res)
1009 #end
1010
1011 #macro(getBlogPostsLocation $blogSpace $postsLocation)
1012 #getBlogDocument($blogSpace $blogDoc)
1013 #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result)
1014 #set ($postsLocation = $NULL)
1015 #setVariable ("$postsLocation" $result)
1016 #end
1017
1018 #macro(getCategoryAllBlogPostsQuery $query)
1019 #set ($query = $NULL)
1020 #getAllBlogPostsQuery($baseQuery)
1021 #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList'))
1022 #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'")
1023 #end
1024
1025 #macro(isDefaultBlog $blogDoc $isDefault)
1026 #set ($result = false)
1027 #if ($blogDoc.space == 'Blog')
1028 #set ($result = true)
1029 #end
1030 #setVariable("$isDefault" $result)
1031 #end
1032 {{/velocity}}
1033
1034 \\