Version 5.1 by superadmin on 2026/12/02 05:36

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

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

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

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

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

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

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

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