Last modified by superadmin on 2026/12/02 07:12

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