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

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