Hide last authors
Vincent Massol 12.1 1 {{include reference="Blog.BlogParameters"/}}
Admin 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 ##
Thomas Mortagne 20.1 11 ## import the hierarchy for the path the blog post footer (in displayEntryBlogLocation)
12 #template('hierarchy_macros.vm')##
Admin 1.1 13 ##
14 ##
15 #**
16 * Prints a blog. This is the main macro used in the BlogSheet.
17 *
18 * @param blogDoc the XDocument holding the blog definition object.
19 *###
20 #macro(printBlog $blogDoc)
Vincent Massol 12.1 21 {{include reference='Blog.CreatePost'/}}
Thomas Mortagne 20.1 22
23 ## Use the blogPostList macro to display the blogposts
24 ## The blogPostList is used only in case of 'all' or 'paged' blog display type because the blogPostList macro
25 ## do not support FTM the monthly and weekly blog display types
26 #getBlogDisplayType($blogDoc $displayType)
27 #if ($displayType == 'weekly' || $displayType == 'monthly')
28 #getBlogEntries($blogDoc $entries)
29 #displayBlog($entries 'index' true true)
30 #displayNavigationLinks($blogDoc)
31 #else
32 #getBlogDisplayType($blogDoc $displayType)
33 #set ($paginated = 'no')
34 #if ($displayType == 'paginated')
35 #set ($paginated = 'yes')
36 #end
37 #getBlogPostsLayout($blogDoc $postsLayout)
38 (% class="hfeed index" %)((({{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$paginated" layout="$!postsLayout.replaceAll('~', '~~').replaceAll('"', '~"')" /}})))
39 #end
Admin 1.1 40 #end
41 ##
42 ##
43 ##
44 #**
Vincent Massol 4.1 45 * Shows blog information. In view mode, the description is printed. In edit mode, allows changing blog settings: title,
46 * description, blog type (global or in-space), index display type (fixed size pagination, weekly index, monthly index,
47 * all entries).
Admin 1.1 48 *
49 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
50 *###
51 #macro(showBlogInfo $blogDoc)
52 #if($blogDoc.getObject($blogClassname))
Vincent Massol 4.1 53 ## Keep testing for inline action for backward compatibility with older blogs.
54 #if($xcontext.action == 'edit' || $xcontext.action == 'inline')
Admin 1.1 55 #macro(displayProperty $blogDoc $propname)
Marius Dumitru Florea 9.1 56 ; #displayPropName($xwiki.getClass($blogClassname).get($propname)):
57 : $blogDoc.display($propname)
Admin 1.1 58 #end
Marius Dumitru Florea 9.1 59 #displayProperty($blogDoc 'title')
60 #displayProperty($blogDoc 'description')
61 #displayProperty($blogDoc 'displayType')
62 #displayProperty($blogDoc 'itemsPerPage')
Thomas Mortagne 20.1 63 #displayProperty($blogDoc 'postsLayout')
64 #displayProperty($blogDoc 'postsLayoutParameters')
Admin 1.1 65 #else
66 $blogDoc.display('description')
67 #end
68 #elseif($doc.fullName == $blogSheet)
Thomas Mortagne 20.1 69 = $services.localization.render('blog.code.blogsheet') =
70 {{translation key='blog.code.sheetexplanation'/}}
Admin 1.1 71 #else
Thomas Mortagne 20.1 72 {{warning}}{{translation key='blog.code.notblog'/}}{{/warning}}
Admin 1.1 73 #end
74 #end
75 ##
76 ##
77 ##
78 #**
79 * Retrieve the blog document, which usually is either <tt>&lt;Space&gt;.WebHome</tt> for whole-spaces blogs, or
80 * <tt>&lt;Space&gt;.Blog</tt> for in-space blogs. If none of these documents contains a blog object, then the first
81 * (alphabetically) document in the target space that contains one is returned. Finally, if no document in the current
82 * space contains a blog object, then <tt>Blog.WebHome</tt> is returned as the default blog.
83 *
84 * @param space A <tt>String</tt>, the name of the space where to search.
85 * @param blogDoc The resulting XDocument.
86 *###
87 #macro(getBlogDocument $space $blogDoc)
Thomas Mortagne 20.1 88 #set ($result = $NULL)
89 ## Check if the current space has a WebPreferences page that contains a Blog.EnablePanelsConfigurationClass object.
90 ## 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
91 ## identify the right blog based on a configuration object in a WebPreferences page.
92 #set ($spaceReference = $services.model.resolveSpace($space))
93 #set ($preferencesDocRef = $services.model.createDocumentReference('WebPreferences', $spaceReference))
94 #set ($preferencesDoc = $xwiki.getDocument($preferencesDocRef))
95 #set ($preferencesObj = $preferencesDoc.getObject('Blog.EnablePanelsConfigurationClass'))
96 #if ($preferencesObj)
97 #set ($result = $xwiki.getDocument( $preferencesObj.getValue('blog')))
98 #end
99 ## If no special case occurs (like the previous one), identify a blog by checking the current location from its hierarchy.
100 #if ("$!result" == '')
101 ## First, try the Space.WebHome, for a whole-space blog
102 #set($result = $xwiki.getDocument("${space}.WebHome"))
Vincent Massol 3.1 103 #if(!$result.getObject($blogClassname))
Thomas Mortagne 20.1 104 ## Second, try the Space.Blog document
105 #set($result = $xwiki.getDocument("${space}.Blog"))
106 #if(!$result.getObject($blogClassname))
107 ## Third, try searching for a blog document in the current space
108 ## Prevent the query fail when the space contains dots '.'
109 #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())
110 #if($blogDocs.size() > 0)
111 #set($result = $xwiki.getDocument($blogDocs.get(0)))
112 #else
113 ## Fourth, try searching for a blog document that have the its 'postsLocation' set to the current space
114 #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())
115 #if($blogDocs.size() > 0)
116 #set($result = $xwiki.getDocument($blogDocs.get(0)))
117 #else
118 ## Last, fallback to Blog.WebHome, the default blog
119 #set($result = $xwiki.getDocument('Blog.WebHome'))
120 #end
121 #end
Admin 1.1 122 #end
123 #end
124 #end
Vincent Massol 8.1 125 #set ($blogDoc = $NULL)
Vincent Massol 3.1 126 #setVariable ("$blogDoc" $result)
Admin 1.1 127 #end
128 ##
129 ##
130 ##
131 #**
132 * Retrieve the blog title.
133 *
134 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass<tt> object with the <tt>title</tt> property set.
135 * @param title The resulting title.
136 *###
137 #macro(getBlogTitle $blogDoc $title)
Thomas Mortagne 13.1 138 ## Titles can contain velocity code (most commonly translations), so we should evaluate them.
Vincent Massol 8.1 139 #set ($title = $NULL)
Thomas Mortagne 13.1 140 #setVariable ("$title" $!blogDoc.displayTitle)
Admin 1.1 141 #end
142 ##
143 ##
144 ##
145 #**
146 * Retrieve the blog description.
147 *
148 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>description</tt>
149 * property set.
150 * @param description The resulting description.
151 *###
152 #macro(getBlogDescription $blogDoc $description)
Vincent Massol 3.1 153 #getBlogProperty($blogDoc 'description' '' $result)
Vincent Massol 8.1 154 #set ($description = $NULL)
Vincent Massol 3.1 155 #setVariable ("$description" $result)
Admin 1.1 156 #end
157 ##
158 ##
159 ##
160 #**
161 * Retrieves a list of entries to be displayed. The entries are either part of the blog's space, or have the blog
162 * document set as a parent. The number and range of entries returned (from all those belonging to this blog) depends on
163 * the blog display type: paginated (fixed number of entries), weekly (all entries in a week), monthly (all entries in a
164 * month), or all.
165 *
166 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
167 * @param entries The resulting list of entries to display, a list of XDocument names.
168 *###
169 #macro(getBlogEntries $blogDoc $entries)
Vincent Massol 3.1 170 #if (!$entries)
171 #setVariable ("$entries" [])
172 #end
Thomas Mortagne 20.1 173 #getAllBlogPostsQuery($query)
174 #isDefaultBlog($blogDoc $isDefault)
175 #set($queryParams = {})
176 #if ($isDefault)
177 #getCategoryAllBlogPostsQuery($query)
178 #set($query = "${query} and (doc.creator = :creator or (isPublished.value = 1 and hidden.value = 0)) and (doc.space = :space or catList like :catList escape '!')")
179 #set($discard = $queryParams.put('creator', $xcontext.user))
180 #set($discard = $queryParams.put('space', $blogDoc.space))
181 #set($sanitizedBlogSpace = $blogDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
182 #set($discard = $queryParams.put('catList', $sanitizedBlogSpace))
183 #else
184 #set($query = "${query} and (doc.space = :space or doc.parent = :parent)")
185 #getBlogPostsLocation($blogDoc.space $blogPostsLocation)
186 #set($discard = $queryParams.put('space', $blogPostsLocation))
187 #set($discard = $queryParams.put('parent', $blogDoc.space))
Admin 1.1 188 #end
189 #getBlogDisplayType($blogDoc $displayType)
190 #if($displayType == 'weekly')
Thomas Mortagne 20.1 191 #getWeeklyBlogEntries($blogDoc $query $entries $queryParams)
Admin 1.1 192 #elseif($displayType == 'monthly')
Thomas Mortagne 20.1 193 #getMonthlyBlogEntries($blogDoc $query $entries $queryParams)
Admin 1.1 194 #elseif($displayType == 'all')
Thomas Mortagne 20.1 195 #getAllBlogEntries($blogDoc $query $entries $queryParams)
Admin 1.1 196 #else
Thomas Mortagne 20.1 197 #getPagedBlogEntries($blogDoc $query $entries $queryParams)
Admin 1.1 198 #end
199 #end
200 ##
201 ##
202 ##
203 #**
204 * Retrieves a list of entries to be displayed. The entries are taken from a "page" of the blog, a sequence of documents
205 * defined by the request parameters <tt>ipp</tt> (items per page) and <tt>page</tt> (the current page). Initially the
206 * first page is displayed, with the number of entries defined in the blog object in the <tt>itemsPerPage</tt> property
207 * (10 if not defined).
208 *
209 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
210 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
211 * refined to restrict to a given space, or to a given search criteria, etc.
212 * @param entries The resulting list of entries to display, a list of XDocument names.
Thomas Mortagne 20.1 213 * @param queryParams The parameters to bind with the query.
Admin 1.1 214 *###
Thomas Mortagne 20.1 215 #macro(getPagedBlogEntries $blogDoc $query $entries $queryParams)
Vincent Massol 3.1 216 #if (!$entries)
217 #setVariable ("$entries" [])
218 #end
Thomas Mortagne 20.1 219 #set($countQueryObj = $services.query.hql($query).addFilter("unique"))
220 #set($queryObj = $services.query.hql("${query} order by publishDate.value desc"))
221 #bindQueryParameters($countQueryObj $queryParams)
222 #bindQueryParameters($queryObj $queryParams)
223 #set($totalEntries = $countQueryObj.count())
Admin 1.1 224 #getBlogProperty($blogDoc 'itemsPerPage' '10' $defaultItemsPerPage)
Vincent Massol 8.1 225 #set($defaultItemsPerPage = $mathtool.toInteger($defaultItemsPerPage))
Admin 1.1 226 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
227 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
Thomas Mortagne 20.1 228 #set($discard = $entries.addAll($queryObj.setLimit($itemsPerPage).setOffset($startAt).addFilter("unique").execute()))
Admin 1.1 229 #end
230 ##
231 ##
232 ##
233 #**
234 * Retrieves a list of entries to be displayed. The entries are taken from a week of the blog. The target week is
235 * defined by the request parameters <tt>week</tt> (the week number in the year, from 1 to 52) and <tt>year</tt> (4
236 * digit year). Initially the current week is displayed.
237 *
238 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
239 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
240 * refined to restrict to a given space, or to a given search criteria, etc.
241 * @param entries The resulting list of entries to display, a list of XDocument names.
Thomas Mortagne 20.1 242 * @param queryParams The parameters to bind with the query.
Admin 1.1 243 *###
Thomas Mortagne 20.1 244 #macro(getWeeklyBlogEntries $blogDoc $query $entries $queryParams)
Vincent Massol 3.1 245 #if (!$entries)
246 #setVariable ("$entries" [])
247 #end
Admin 1.1 248 #getRequestedWeek($weekDate)
249 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd'))
250 #set($minDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundFloor()))
251 #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling()))
252 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
Thomas Mortagne 20.1 253 #set($countQueryObj = $services.query.hql($query).addFilter("unique"))
254 #set($queryObj = $services.query.hql("${query} order by publishDate.value desc").addFilter("unique"))
255 #bindQueryParameters($countQueryObj $queryParams)
256 #bindQueryParameters($queryObj $queryParams)
257 #set($totalEntries = $countQueryObj.count())
258 #set($discard = $entries.addAll($queryObj.execute()))
Admin 1.1 259 #end
260 ##
261 ##
262 ##
263 #**
264 * Retrieves a list of entries to be displayed. The entries are taken from a month of the blog. The target month is
265 * defined by the request parameters <tt>month</tt> (the month number, from 1 to 12) and <tt>year</tt> (4
266 * digit year). Initially the current month is displayed.
267 *
268 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
269 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
270 * refined to restrict to a given space, or to a given search criteria, etc.
271 * @param entries The resulting list of entries to display, a list of XDocument names.
Thomas Mortagne 20.1 272 * @param queryParams The parameters to bind with the query.
Admin 1.1 273 *###
274 #macro(getMonthlyBlogEntries $blogDoc $query $entries)
Vincent Massol 3.1 275 #if (!$entries)
276 #setVariable ("$entries" [])
277 #end
Admin 1.1 278 #getRequestedMonth($monthDate)
279 #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd'))
280 #set($minDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundFloor()))
281 #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling()))
282 #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'")
Thomas Mortagne 20.1 283 #set($countQueryObj = $services.query.hql($query).addFilter("unique"))
284 #set($queryObj = $services.query.hql("${query} order by publishDate.value desc").addFilter("unique"))
285 #bindQueryParameters($countQueryObj $queryParams)
286 #bindQueryParameters($queryObj $queryParams)
287 #set($totalEntries = $countQueryObj.count())
288 #set($discard = $entries.addAll($queryObj.execute()))
Admin 1.1 289 #end
290 ##
291 ##
292 ##
293 #**
294 * Retrieves a list of entries to be displayed. All entries belonging to the current blog are returned.
295 *
296 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
297 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
298 * refined to restrict to a given space, or to a given search criteria, etc.
299 * @param entries The resulting list of entries to display, a list of XDocument names.
Thomas Mortagne 20.1 300 * @param queryParams The parameters to bind with the query.
Admin 1.1 301 *###
Thomas Mortagne 20.1 302 #macro(getAllBlogEntries $blogDoc $query $entries $queryParams)
Vincent Massol 3.1 303 #if (!$entries)
304 #setVariable ("$entries" [])
305 #end
Thomas Mortagne 20.1 306 #set($countQueryObj = $services.query.hql($query).addFilter("unique"))
307 #set($queryObj = $services.query.hql("${query} order by publishDate.value desc").addFilter("unique"))
308 #bindQueryParameters($countQueryObj $queryParams)
309 #bindQueryParameters($queryObj $queryParams)
310 #set($totalEntries = $countQueryObj.count())
311 #set($discard = $entries.addAll($queryObj.execute()))
Admin 1.1 312 #end
313 ##
314 ##
315 ##
316 #**
317 * Retrieves a list of entries to be displayed. Only (and all) unpublished entries are returned.
318 *
319 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
320 * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be
321 * refined to restrict to a given space, or to a given search criteria, etc.
Thomas Mortagne 20.1 322 * @param queryParams The parameters to bind with the query.
Admin 1.1 323 * @param entries The resulting list of entries to display, a list of XDocument names.
324 *###
Thomas Mortagne 20.1 325 #macro(getUnpublishedBlogEntries $blogDoc $query $queryParams $entries)
Vincent Massol 3.1 326 #if (!$entries)
327 #setVariable ("$entries" [])
328 #end
Admin 1.1 329 #set($query = "${query} and isPublished.value = 0")
Thomas Mortagne 20.1 330 #set ($countQueryObj = $services.query.hql($query).addFilter("unique"))
331 #set ($queryObj = $services.query.hql("${query} order by publishDate.value desc").addFilter("unique"))
332 #bindQueryParameters($countQueryObj $queryParams)
333 #bindQueryParameters($queryObj $queryParams)
334 #set($totalEntries = $countQueryObj.count())
335 #set($discard = $entries.addAll($queryObj.execute()))
Admin 1.1 336 #end
337 ##
338 ##
339 ##
340 #**
341 * Retrieves a list of entries to be displayed. The entries are taken from all the wiki, and not from a specific blog.
342 *
343 * @param entries The resulting list of entries to display, a list of XDocument names.
344 *###
345 #macro(getGlobalBlogEntries $entries)
Vincent Massol 3.1 346 #if (!$entries)
347 #setVariable ("$entries" [])
348 #end
Thomas Mortagne 20.1 349 #getAllBlogPostsQuery($query)
Vincent Massol 10.1 350 #set($totalEntries = $services.query.hql($query).count())
Admin 1.1 351 #set($defaultItemsPerPage = 20)
352 ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt.
353 #preparePagedViewParams($totalEntries $defaultItemsPerPage)
Vincent Massol 10.1 354 #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()))
Admin 1.1 355 #end
356 #**
357 * Return the base query for selecting blog entries. It filters only visible entries, but does not bind to a specific
358 * blog, nor specify a range or an ordering criteria.
Thomas Mortagne 20.1 359 *
360 * This macro is a duplicate of #getAllBlogPostsQuery($query). Keep it in case it's used outside, in custom code.
361 *
Admin 1.1 362 * @param query The basic query for selecting blog entries.
Thomas Mortagne 20.1 363 *#
Admin 1.1 364 #macro(getBlogEntriesBaseQuery $query)
Thomas Mortagne 20.1 365 #getAllBlogPostsQuery($query)
366 #end
367 #**
368 * Return the Query for selecting the all wiki blog posts without filtering
369 *
370 * @param query The basic query for selecting blog entries.
371 *#
372 #macro(getAllBlogPostsQuery $query)
Vincent Massol 8.1 373 #set ($query = $NULL)
Thomas Mortagne 20.1 374 #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished,
375 IntegerProperty hidden, DateProperty publishDate
376 where doc.fullName <> '$blogPostTemplate' and
377 obj.name=doc.fullName and obj.className='$blogPostClassname' and
378 isPublished.id.id = obj.id and isPublished.id.name = 'published' and
379 hidden.id.id = obj.id and hidden.id.name='hidden' and
380 publishDate.id.id = obj.id and publishDate.id.name='publishDate' and
381 (doc.creator = '$xcontext.user' or (isPublished.value = 1 and hidden.value = 0))")
Admin 1.1 382 #end
383 ##
384 ##
385 ##
Thomas Mortagne 20.1 386 ###**
387 * Return the Query for selecting the all wiki blog posts with categories filtering
Admin 1.1 388 *
Thomas Mortagne 20.1 389 * @param query The basic query for selecting blog entries.
Admin 1.1 390 *###
Thomas Mortagne 20.1 391 #macro(getCategoryAllBlogPostsQuery $query)
392 #set ($query = $NULL)
393 #getAllBlogPostsQuery($baseQuery)
394 #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList'))
395 #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'")
Admin 1.1 396 #end
397 ##
398 ##
399 ##
400 #**
401 * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a
402 * week), monthly (all entries in a month), or all.
403 *
404 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt>
405 * property set.
406 * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
407 *###
408 #macro(getBlogDisplayType $blogDoc $displayType)
Vincent Massol 3.1 409 #getBlogProperty($blogDoc 'displayType' 'paginated' $result)
Vincent Massol 8.1 410 #set ($displayType = $NULL)
Vincent Massol 3.1 411 #setVariable ("$displayType" $result)
Admin 1.1 412 #end
413 ##
414 ##
415 ##
416 #**
417 * Displays a list of entries.
418 *
419 * @param entries The entries to display, a list of XDocument names.
420 * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results,
421 * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently
422 * used values: index, single, category, search, unpublished, hidden.
423 * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content.
424 * @param shouldDisplayTitles If <tt>true</tt>, display the blog title (blog posts shouldn't display the title when they're
425 * displayed alone on their page since it's the page title which is used in this case)
426 *###
427 #macro(displayBlog $entries $displaying $onlyExtract $shouldDisplayTitles)
428 #set($blogDay = '')
Marius Dumitru Florea 9.1 429 (% class="hfeed $!{displaying}" %)(((
430 (% class="blogDay" %)(((
Admin 1.1 431 #foreach ($entryDoc in $xwiki.wrapDocs($entries))
432 #getEntryObject($entryDoc $entryObj)
433 ## Although all entries should have one of the two objects, better check to be sure.
434 #if("$!{entryObj}" != '')
435 #getEntryDate($entryDoc $entryObj $entryDate)
436 ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet.
437 #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd'))
438 #if($blogDay != $entryDateStr)
439 #if($blogDay != '')
Marius Dumitru Florea 9.1 440 )))
441 (% class="blogDay" %)(((
Admin 1.1 442 #end
443 #displayBlogDate($entryDate)
444 #set ($blogDay = $entryDateStr)
445 #end
446 ## Finally, display the entry.
Thomas Mortagne 20.1 447 #displayEntry($entryDoc $entryObj $onlyExtract $shouldDisplayTitles true)
Admin 1.1 448 #end
449 #end
Marius Dumitru Florea 9.1 450 )))## blogDay
451 )))## hfeed
Admin 1.1 452 #end
453 ##
454 ##
455 ##
456 #**
457 * Get the entry object, either a new BlogPost or an old Article.
458 *
459 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
460 * @param entryObj The resulting xobject of the blog post.
461 *###
Vincent Massol 12.1 462 #macro(getEntryObject $entryDoc $__entryObj)
Vincent Massol 3.1 463 #set($result = $entryDoc.getObject("${blogPostClassname}"))
464 #if(!$result)
465 #set($result = $entryDoc.getObject("${oldArticleClassname}"))
Admin 1.1 466 #end
Vincent Massol 12.1 467 ## NOTE: The reason we put an underscore in front of the variable name is to prevent the following line from
468 ## overwriting the $entryObj variable that may be defined before this macro is called. Of course, $__entryObj may be
469 ## overwritten in this case but it's less likely to have such a variable defined before.
470 #set ($__entryObj = $NULL)
471 #setVariable ("$__entryObj" $result)
Admin 1.1 472 #end
473 ##
474 ##
475 ##
476 #**
477 * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is
478 * the document creation date, but can be edited by the user.
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 result The resulting date, an instance of <tt>java.util.Date</tt>.
483 *###
484 #macro(getEntryDate $entryDoc $entryObj $result)
Vincent Massol 8.1 485 #set ($result = $NULL)
Vincent Massol 3.1 486 #setVariable ("$result" $entryObj.getProperty('publishDate').value)
Admin 1.1 487 #end
488 ##
489 ##
490 ##
491 #**
492 * Displays a date, nicely formatted as a calendar page.
493 *
494 * @param date The date to display, an instance of <tt>java.util.Date</tt>.
495 *###
496 #macro(displayBlogDate $date)
497 #set($year = $xwiki.formatDate($date, 'yyyy'))
498 ## 3 letter month name, like Jan, Dec.
499 #set($month = $xwiki.formatDate($date, 'MMM'))
500 ## Uncomment to get a full length month name, like January, December.
501 ## TODO: this could be defined somewhere in the blog style.
502 ## #set($month = $xwiki.formatDate($date, 'MMMM'))
503 #set($day = $xwiki.formatDate($date, 'dd'))
Marius Dumitru Florea 9.1 504 (% class="blogdate" %)
505 == (% class="month" %)$month(%%) (% class="day" %)$day(%%) (% class="year" %)$year(%%) ==
Admin 1.1 506 #end
507 ##
508 ##
509 ##
510 #**
511 * Displays a blog article: management tools, header, content, footer.
512 *
513 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
514 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
515 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
516 * @param shouldDisplayTitle If <tt>true</tt>, display the blog title (blog posts shouldn't display the title
517 * when they're displayed alone on their page since it's the page title which is used in this case)
Thomas Mortagne 20.1 518 * @param shouldDisplayActions If <tt>true</tt>, display the blog post actions buttons
Admin 1.1 519 *###
Thomas Mortagne 20.1 520 #macro(displayEntry $entryDoc $entryObj $onlyExtract $shouldDisplayTitle $shouldDisplayActions)
Admin 1.1 521 ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden
522 #isPublished($entryObj $isPublished)
523 #isHidden($entryObj $isHidden)
524 #if($doc.fullName == $entryDoc.fullName)
Marius Dumitru Florea 9.1 525 (% class="hentry single-article" %)(((
Admin 1.1 526 #else
Marius Dumitru Florea 9.1 527 (% class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end" %)(((
Admin 1.1 528 #end
Thomas Mortagne 20.1 529 #if ($shouldDisplayActions)
530 #displayEntryTools($entryDoc $entryObj)
531 #end
Admin 1.1 532 #if($shouldDisplayTitle)
533 #displayEntryTitle($entryDoc $entryObj)
534 #end
535 #if($doc.fullName == $entryDoc.fullName)
536 #if(!$isPublished)
Thomas Mortagne 20.1 537 {{warning}}{{translation key='blog.code.published'/}}{{/warning}}
Admin 1.1 538 #elseif($isHidden)
Thomas Mortagne 20.1 539 {{warning}}{{translation key='blog.code.hidden'/}}{{/warning}}
Admin 1.1 540 #end
541 #end
542 #displayEntryContent($entryDoc $entryObj $onlyExtract)
543 #displayEntryFooter($entryDoc $entryObj)
Marius Dumitru Florea 9.1 544 )))## hentry
Admin 1.1 545 #end
546 ##
547 ##
548 ##
549 #**
550 * Checks if the provided blog is published or not.
551 *
552 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
553 * @param isPublished The resulting boolean, true if the entry is considered published.
554 *###
555 #macro(isPublished $entryObj $isPublished)
Vincent Massol 8.1 556 #set ($isPublished = $NULL)
Admin 1.1 557 ## This should work for both old articles, which don't have the 'published' property at all, and
558 ## are considered published by default, and new entries, that should have 1 if published.
Vincent Massol 3.1 559 #if ("$!{entryObj.getProperty('published').value}" != '0')
560 #setVariable ("$isPublished" true)
561 #else
562 #setVariable ("$isPublished" false)
563 #end
Admin 1.1 564 #end
565 ##
566 ##
567 ##
568 #**
569 * Checks if the provided blog is hidden or not.
570 *
571 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass.
572 * @param isHiddel The resulting boolean, true if the entry is considered hidden.
573 *###
574 #macro(isHidden $entryObj $isHidden)
Vincent Massol 8.1 575 #set ($isHidden = $NULL)
Admin 1.1 576 ## This should work for both old articles, which don't have the 'hidden' property at all, and
577 ## are considered visible by default, and new entries, that should have 1 if hidden.
Vincent Massol 3.1 578 #if ("$!{entryObj.getProperty('hidden').value}" == '1')
579 #setVariable ("$isHidden" true)
580 #else
581 #setVariable ("$isHidden" false)
582 #end
Admin 1.1 583 #end
584 ##
585 ##
586 ##
587 #**
588 * Displays several "tools" for manipulating blog posts: hide/show, publish, edit.
589 *
590 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
591 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
592 *###
593 #macro(displayEntryTools $entryDoc $entryObj)
Admin 2.1 594 #if($xcontext.action == 'view')
Marius Dumitru Florea 9.1 595 (% class="blog-entry-toolbox" %)(((
Admin 1.1 596 #displayPublishButton($entryDoc $entryObj)
597 #displayHideShowButton($entryDoc $entryObj)
598 #displayEditButton($entryDoc $entryObj)
599 #displayDeleteButton($entryDoc $entryObj)
Marius Dumitru Florea 9.1 600 )))
Admin 1.1 601 #end
602 #end
603 ##
604 ##
605 ##
606 #**
607 * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet.
608 *
609 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
610 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
611 * @todo AJAX calls.
612 *###
613 #macro(displayPublishButton $entryDoc $entryObj)
614 #isPublished($entryObj $isPublished)
Admin 2.1 615 #if(!$isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName))
Thomas Mortagne 20.1 616 [[#toolImage('world')>>path:$blogPublisher.getURL('view', "entryName=${escapetool.url($entryDoc.fullName)}&xredirect=${escapetool.url($thisURL)}&form_token=$!{services.csrf.getToken()}")||title="$services.localization.render('blog.code.notpublished')"]]##
Admin 1.1 617 #end
618 #end
619 ##
620 ##
621 ##
622 #**
623 * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published.
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(displayHideShowButton $entryDoc $entryObj)
629 #isPublished($entryObj $isPublished)
630 #isHidden($entryObj $isHidden)
631 ## Only published articles can be hidden. Unpublished articles are considered already hidden.
Admin 2.1 632 #if($isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName))
Vincent Massol 15.1 633 #set ($queryString = {
634 'xredirect' : $thisURL,
635 'form_token' : $services.csrf.getToken()
636 })
Admin 1.1 637 #if ($isHidden)
Vincent Massol 15.1 638 #set ($discard = $queryString.putAll({
639 "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden" : 0,
Thomas Mortagne 20.1 640 'comment' : $services.localization.render('blog.code.madevisible')
Vincent Massol 15.1 641 }))
642 #set ($lockURL = $entryDoc.getURL('save', $escapetool.url($queryString)))
Thomas Mortagne 20.1 643 [[#toolImage('unlock')>>path:$lockURL||class="blog-tool-show" title="$services.localization.render('blog.code.makevisible')"]]##
Admin 1.1 644 #else
Vincent Massol 15.1 645 #set ($discard = $queryString.putAll({
646 "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden" : 1,
Thomas Mortagne 20.1 647 'comment' : $services.localization.render('blog.code.hid')
Vincent Massol 15.1 648 }))
649 #set ($lockURL = $entryDoc.getURL('save', $escapetool.url($queryString)))
Thomas Mortagne 20.1 650 [[#toolImage('lock')>>path:$lockURL||class="blog-tool-hide" title="$services.localization.render('blog.code.hide')"]]##
Admin 1.1 651 #end
652 #end
653 #end
654 ##
655 ##
656 ##
657 #**
658 * Displays the edit button to those that can edit the article.
659 *
660 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
661 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
662 *###
663 #macro(displayEditButton $entryDoc $entryObj)
Admin 2.1 664 #if($xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName))
Vincent Massol 4.1 665 ## Call getDefaultEditMode() for backward compatibility with older blog posts.
Thomas Mortagne 20.1 666 [[#toolImage('pencil')>>path:$entryDoc.getURL('edit')||title="$services.localization.render('blog.code.editpost')"]]##
Admin 1.1 667 #end
668 #end
669 ##
670 ##
671 ##
672 #**
673 * Displays the delete button to those that can edit the article.
674 *
675 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
676 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
677 * @todo AJAX calls.
678 *###
679 #macro(displayDeleteButton $entryDoc $entryObj)
Admin 2.1 680 #if($xwiki.hasAccessLevel('delete', $xcontext.user, $entryDoc.fullName))
Thomas Mortagne 20.1 681 [[#toolImage('cross')>>path:$entryDoc.getURL('delete')||title="$services.localization.render('blog.code.deletepost')"]]##
Admin 1.1 682 #end
683 #end
684 ##
685 ##
686 ##
687 #**
688 * Displays the title of the entry.
689 *
690 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
691 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
692 *###
693 #macro(displayEntryTitle $entryDoc $entryObj)
694 #if($doc.fullName == $entryDoc.fullName)
Marius Dumitru Florea 9.1 695 (% class="entry-title" %)
Thomas Mortagne 20.1 696 = $services.rendering.escape($entryDoc.display('title', 'view', $entryObj), $xwiki.getCurrentContentSyntaxId()) =
Admin 1.1 697 #else
Marius Dumitru Florea 9.1 698 (% class="entry-title" %)
Thomas Mortagne 20.1 699 === [[$services.rendering.escape($entryDoc.display('title', 'view', $entryObj),$xwiki.getCurrentContentSyntaxId())>>doc:$services.rendering.escape($services.model.serialize($entryDoc.getDocumentReference(),'default'),$xwiki.getCurrentContentSyntaxId())]] ===
Admin 1.1 700 #end
701 #end
702 ##
703 ##
704 ##
705 #**
706 * Displays the body of the entry.
707 *
708 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
709 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
710 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
711 *###
712 #macro(displayEntryContent $entryDoc $entryObj $onlyExtract)
Marius Dumitru Florea 9.1 713 (% class="#if($onlyExtract)entry-summary#{else}entry-content#end" %)(((
Admin 1.1 714 #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent)
Thomas Mortagne 21.1 715 ## FIXME: This causes the blog's content to not be annotatable. See http://jira.xwiki.org/browse/XWIKI-6328
Guillaume Delhumeau 14.1 716 ## Should probably be replaced by a display macro call with a reference to the object property holding the post's content
Thomas Mortagne 21.1 717 {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.syntax.toIdString()){{/html}}
Marius Dumitru Florea 9.1 718 ))) ## entry-content
Vincent Massol 12.1 719 (% class="clearfloats" %)((()))
Admin 1.1 720 #end
721 ##
722 ##
723 ##
724 #**
725 * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content
726 * of the <tt>extract</tt> field (if not empty).
727 *
728 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
729 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
730 * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content.
731 * @param entryContent The resulting content.
732 *###
733 #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent)
Vincent Massol 3.1 734 #if ($onlyExtract)
Thomas Mortagne 20.1 735 ## Note: We trim the summary so that if there's some white space it won't cause the summary to be used instead
736 ## of the content.
737 #set ($macro.result = $entryObj.getProperty('extract').value.trim())
Admin 1.1 738 #end
Thomas Mortagne 20.1 739 #if("$!macro.result" == '')
740 #set($macro.result = $entryObj.getProperty('content').value)
Admin 1.1 741 #* Disabled until the content can be cleanly cut.
Vincent Massol 3.1 742 * #if($onlyExtract && $result.length()>$maxchars)
Thomas Mortagne 20.1 743 * #set($i = $macro.result.lastIndexOf(" ", $maxchars))
Admin 1.1 744 * #set($i = $i + 1)
Thomas Mortagne 20.1 745 * #set($macro.result = "${macro.result.substring(0,$i)} *[...>${entryDoc.fullName}]*")
Admin 1.1 746 * #end
747 ## *###
748 #else
Vincent Massol 3.1 749 #if($entryDoc.syntax.toIdString() == 'xwiki/1.0')
Thomas Mortagne 20.1 750 #set($macro.result = "${macro.result} <a href='${entryDoc.getURL()}' title='$services.localization.render('blog.code.readpost')'>...</a>")
751 #elseif($entryDoc.syntax.toIdString() == 'xwiki/2.0' || $entryDoc.syntax.toIdString() == 'xwiki/2.1')
752 #set($macro.result = "${macro.result} [[...>>${services.rendering.escape($entryDoc.getFullName(), $entryDoc.getSyntax())}||title='$services.localization.render('blog.code.readpost')']]")
Admin 1.1 753 #end
754 #end
Vincent Massol 8.1 755 #set ($entryContent = $NULL)
Thomas Mortagne 20.1 756 #setVariable ("$entryContent" $macro.result)
Admin 1.1 757 #end
758 ##
759 ##
760 ##
761 #**
762 * Displays the footer of the entry.
763 *
764 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
765 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
766 *###
767 #macro(displayEntryFooter $entryDoc $entryObj)
Marius Dumitru Florea 9.1 768 (% class="entry-footer" %)(((
Admin 1.1 769 #isPublished($entryObj $isPublished)
Vincent Massol 12.1 770 (% class='entry-author-label' %)
Admin 1.1 771 #if($isPublished)
Thomas Mortagne 20.1 772 {{translation key='blog.code.postedby'/}} ##
Admin 1.1 773 #else
Thomas Mortagne 20.1 774 {{translation key='blog.code.createdby'/}} ##
Admin 1.1 775 #end
Thomas Mortagne 16.1 776 {{html wiki="false" clean="false"}}<span class='author vcard'>#userfn($entryDoc.creator)</span>{{/html}} ##
Admin 1.1 777 #getEntryDate($entryDoc $entryObj $entryDate)
Vincent Massol 12.1 778 #listCategories($entryObj) #*
Admin 1.1 779 ## Since the publish date and update date are not set at the exact same time, there could be a small difference that
780 ## we assume cannot be more than 3 seconds.
Thomas Mortagne 20.1 781 *#(% class="separator" %)·(%%) [[{{translation key='blog.code.permalink'/}}>>$services.rendering.escape($entryDoc,'xwiki/2.0')||rel="bookmark"]] ##
782 #if ($showcomments)
783 (% class="separator" %)·(%%) [[{{translation key='blog.code.comments'/}}>>$services.rendering.escape($entryDoc,'xwiki/2.0')||anchor="Comments"]] (% class="itemCount" %)($entryDoc.comments.size())(%%) ##
784 #end ##
785 #if($entryDoc != $doc) ##
786 #displayEntryBlogLocation($entryDoc $entryObj) ##
787 #end
Marius Dumitru Florea 9.1 788 )))## entry-footer
Admin 1.1 789 #end
790 ##
791 ##
Thomas Mortagne 20.1 792 #**
793 * Display the blog for the entry (if it is not the currently displayed blog)
794 *
795 * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
796 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
797 *###
798 #macro(displayEntryBlogLocation $entryDoc $entryObj)
799 #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ##
800 #if("$!blogPostsLocation" != "") ##
801 #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ##
802 #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ##
803 #if($doc.documentReference != $blogDocRef) ##
804 #set($blogDoc = $xwiki.getDocument($blogDocRef)) ##
805 #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ##
806 #if($blogObj) (% class="blogrefpath" %)((( ##
807 $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ##
808 )))(%%)##
809 #end
810 #end
811 #end
812 #end
Admin 1.1 813 ##
Thomas Mortagne 21.1 814 ##
815 ##
816 ##
Admin 1.1 817 #**
818 * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>.
819 *
820 * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass.
821 *###
822 #macro(listCategories $entryObj)
823 #if($entryObj.getxWikiClass().getName() == $blogPostClassname)
824 #set($categories = $entryObj.getProperty('category').value)
825 #set($first = true)
826 #if($categories.size() > 0)
827 #foreach($category in $categories)
Vincent Massol 12.1 828 #set($categoryDoc = $!xwiki.getDocument($category))
829 #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname}))
830 #if($foreach.count == 1)
Thomas Mortagne 20.1 831 (% class='separator' %)·(%%) $services.localization.render('blog.code.categories') ##
Vincent Massol 12.1 832 #else
833 , ##
834 #end##
Thomas Mortagne 20.1 835 [[$!{categoryDoc.getObject($blogCategoryClassname).getValue('name')}>>${category}||rel='tag']]##
Vincent Massol 12.1 836 #end##
837 #end##
Admin 1.1 838 #end
839 #end
840 #end
841 ##
842 ##
843 ##
844 #**
845 * Displays blog pagination links (older and newer entries).
846 *
847 * @param blogDoc the XDocument holding the blog definition object.
848 *###
849 #macro(displayNavigationLinks $blogDoc)
Marius Dumitru Florea 9.1 850 (% class="clearfloats" %)((()))
Admin 1.1 851 #getBlogDisplayType($blogDoc $displayType)
852 #if($displayType == 'weekly')
Marius Dumitru Florea 9.1 853 (% class="pagingLinks" %)(((
Admin 1.1 854 #getRequestedWeek($weekDate)
855 $weekDate.addWeeks(-1)##
Thomas Mortagne 20.1 856 (% class="prevPage" %)**[[« {{translation key='blog.code.previousweek'/}}>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear" class="button"]]**(%%)
Admin 1.1 857 #sep()
858 $weekDate.addWeeks(2)## 2 because we already subtracted 1 above
Thomas Mortagne 20.1 859 (% class="nextPage" %)**[[{{translation key='blog.code.nextweek'/}} »>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear" class="button"]]**(%%)
Marius Dumitru Florea 9.1 860 )))
Admin 1.1 861 #elseif($displayType == 'monthly')
Marius Dumitru Florea 9.1 862 (% class="pagingLinks" %)(((
Admin 1.1 863 #getRequestedMonth($monthDate)
864 $monthDate.addMonths(-1)##
Thomas Mortagne 20.1 865 (% class="prevPage" %)**[[« {{translation key='blog.code.previousmonth'/}}>>$services.rendering.escape($doc.name,$doc.syntax)||queryString="year=$monthDate.year&month=$monthDate.monthOfYear" class="button"]]**(%%)
Admin 1.1 866 #sep()
867 $monthDate.addMonths(2)## 2 because we already subtracted 1 above
Thomas Mortagne 20.1 868 (% class="nextPage" %)**[[{{translation key='blog.code.nextmonth'/}} »>>$services.rendering.escape($doc.name,$doc.syntax)||queryString="year=$monthDate.year&month=$monthDate.monthOfYear" class="button"]]**(%%)
Marius Dumitru Florea 9.1 869 )))
Admin 1.1 870 #elseif($displayType == 'all')
871 #else
872 ## Paginated
873 #if(($totalPages > 1))
Vincent Massol 8.1 874 #set($queryString = '')
Admin 1.1 875 #foreach($p in $request.getParameterNames())
876 #if($p != 'page' && $p != 'ipp')
877 #foreach($v in $request.getParameterValues($p))
Thomas Mortagne 20.1 878 #set($queryString = "${queryString}&${escapetool.url($p)}=${escapetool.url($v)}")
Admin 1.1 879 #end
880 #end
881 #end
Marius Dumitru Florea 9.1 882 (% class="pagingLinks" %)(((
Admin 1.1 883 #if ($currentPageNumber < $totalPages)
884 #set($currentPageNumber = $currentPageNumber + 1)
Thomas Mortagne 20.1 885 (% class="prevPage" %)**[[« {{translation key='blog.code.olderposts'/}}>>$services.rendering.escape($doc.name,$doc.syntax)||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString" class="button"]]**(%%)
Admin 1.1 886 #set($currentPageNumber = $currentPageNumber - 1)
887 #end
888 #if ($currentPageNumber > 1)
889 #if ($currentPageNumber < $totalPages)
890 #sep()
891 #end
892 #set($currentPageNumber = $currentPageNumber - 1)
Thomas Mortagne 20.1 893 (% class="nextPage" %)**[[{{translation key='blog.code.newerposts'/}} »>>$services.rendering.escape($doc.name,$doc.syntax)||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString" class="button"]]**(%%)
Admin 1.1 894 #set($currentPageNumber = $currentPageNumber + 1)
895 #end
Marius Dumitru Florea 9.1 896 (% class="clear" %)(%%)
897 )))## pagingLinks
Admin 1.1 898 #end
899 #end
900 #end
901 ##
902 ##
903 ##
904 #**
905 * Displays a message box with "publish" icon.
906 *
907 * @param message A text message concerning blog article publishing
908 *###
909 #macro(publishMessageBox $message)
Vincent Massol 17.1 910 (% class="plainmessage publish-message" %)((($services.icon.render('world') $message)))
Admin 1.1 911 #end
912 #**
913 * Displays a message box with "show/hide" icon.
914 *
915 * @param message A text message concerning blog article hiding
916 *###
917 #macro(hideMessageBox $message)
Vincent Massol 17.1 918 (% class="plainmessage hide-message" %)((($services.icon.render('unlock') $message)))
Admin 1.1 919 #end
920 ##
921 ##
922 ##
923 #**
924 * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are
925 * <tt>year</tt> and <tt>week</tt>. By default, the current week is used.
926 *
927 * @param monthDate The resulting week, a JODATime MutableDateTime.
928 *###
929 #macro(getRequestedWeek $weekDate)
Vincent Massol 8.1 930 #set ($weekDate = $NULL)
Vincent Massol 3.1 931 #setVariable ("$weekDate" $xwiki.jodatime.mutableDateTime)
Admin 1.1 932 #if("$!{request.year}" != '')
Vincent Massol 8.1 933 $weekDate.setYear($mathtool.toInteger($request.year))
Admin 1.1 934 #end
935 #if("$!{request.week}" != '')
Vincent Massol 8.1 936 $weekDate.setWeekOfWeekyear($mathtool.toInteger($request.week))
Admin 1.1 937 #end
938 #end
939 ##
940 ##
941 ##
942 #**
943 * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are
944 * <tt>year</tt> and <tt>month</tt>. By default, the current month is used.
945 *
946 * @param monthDate The resulting month, a JODATime MutableDateTime.
947 *###
948 #macro(getRequestedMonth $monthDate)
Vincent Massol 8.1 949 #set ($monthDate = $NULL)
Vincent Massol 3.1 950 #setVariable ("$monthDate" $xwiki.jodatime.mutableDateTime)
Admin 1.1 951 #if("$!{request.year}" != '')
Vincent Massol 8.1 952 $monthDate.setYear($mathtool.toInteger($request.year))
Admin 1.1 953 #end
954 #if("$!{request.month}" != '')
Vincent Massol 8.1 955 $monthDate.setMonthOfYear($mathtool.toInteger($request.month))
Admin 1.1 956 #end
957 #end
958 ##
959 ##
960 ##
961 #**
962 * Retrieve a blog property (title, display type, etc).
963 *
964 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
965 * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties.
966 * @param defaultValue The default value to use in case the blog object does not define one.
967 * @param propertyValue The resulting value.
968 *###
969 #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
Vincent Massol 3.1 970 #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
971 #if($result == '')
972 #set($result = $defaultValue)
Admin 1.1 973 #end
Vincent Massol 8.1 974 #set ($propertyValue = $NULL)
Vincent Massol 3.1 975 #setVariable ("$propertyValue" $result)
Admin 1.1 976 #end
Admin 6.1 977
978 #**
979 * If an error occurs when executing an action, set a specific response status and display an error message.
980 *
981 * @param status The response status.
982 * @param text The user readable error to be displayed. Can be a translation key.
983 * @param parameters The parameters to use when decoding the translation key.
984 *###
985 #macro(blog__actionResponseError $status $text $parameters)
986 $response.setStatus($status)
987 #if($request.ajax)
Marius Dumitru Florea 9.1 988 $services.localization.render($text, $!parameters)
Admin 6.1 989 #else
Marius Dumitru Florea 9.1 990 {{error}}$services.localization.render($text, $!parameters){{/error}}
Admin 6.1 991 #end
992 #end
Thomas Mortagne 20.1 993 ##
994 ##
995 ##
996 #**
997 * Check if a blog is the Default blog (The one in the 'Blog' space).
998 *
999 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object.
1000 * @param isDefault The resulting boolean.
1001 *###
1002 #macro(isDefaultBlog $blogDoc $isDefault)
1003 #set ($result = false)
1004 #if ($blogDoc.space == 'Blog')
1005 #set ($result = true)
1006 #end
1007 #setVariable("$isDefault" $result)
1008 #end
1009 ##
1010 ##
1011 ##
1012 #**
1013 * Retrieve the blog posts location (space).
1014 *
1015 * @param blogSpace The blog space. It should contain a document with a <tt>Blog.BlogClass</tt> object
1016 * @param postsLocation The resulting location.
1017 *###
1018 #macro(getBlogPostsLocation $blogSpace $postsLocation)
1019 #getBlogDocument($blogSpace $blogDoc)
1020 #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result)
1021 #set ($postsLocation = $NULL)
1022 #setVariable ("$postsLocation" $result)
1023 #end
1024 ##
1025 ##
1026 ##
1027 #**
1028 * Retrieve the blog categories location (space).
1029 *
1030 * @param blogSpace The blog space. It should contain a document with a <tt>Blog.BlogClass</tt> object
1031 * @param categoriesLocation The resulting location.
1032 *###
1033 #macro(getBlogCategoriesLocation $blogSpace $categoriesLocation)
1034 #getBlogDocument($blogSpace $blogDoc)
1035 #getBlogProperty($blogDoc 'categoriesLocation' 'Blog' $result)
1036 #set ($postsLocation = $NULL)
1037 #setVariable ("$categoriesLocation" $result)
1038 #end
1039 ###**
1040 * Return the Query for selecting the blog posts based on the context where the posts are displayed.
1041 * for example there is 4 different panel contexts:
1042 * aBlog.aPost or aBlog.WebHome
1043 * aCategorySpace.aCategory
1044 * aCategorySpace.WebHome
1045 * Blog.aPost or Blog.WebHome
1046 *
1047 * @param query The query for selecting blog entries.
1048 * @param queryParams The parameters to bind with the generated query.
1049 * @param targetDoc The document in which the articles will be displayed.
1050 *###
1051 #macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams)
1052 #set ($query = $NULL)
1053 #set ($queryParams = $NULL)
1054 #getCategoryAllBlogPostsQuery($resultQuery)
1055 #set ($resultQueryParams = {})
1056 #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
1057 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
1058 ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%'
1059 #set ($discard = $resultQueryParams.put('space', $targetDoc.space))
1060 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
1061 #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')")
1062 #elseif($targetDoc.getObject($blogCategoryClassname))
1063 ## Get all posts that are in a category aCategorySpace.aCategory
1064 #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName))
1065 #set($resultQuery = "${resultQuery} and (catList=:catList)")
1066 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
1067 ## Get all posts that are in a category aCategorySpace.%
1068 #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
1069 ## Exclude incategorized posts
1070 #set ($excludedCategory = "${targetDoc.space}.WebHome")
1071 #if ($targetDoc.space == $defaultBlogSpace)
1072 #set ($excludedCategory = "Blog.Categories.WebHome")
1073 #end
1074 #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory))
1075 #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')")
1076 #else
1077 ## Get all posts in blog space aBlog
1078 #getAllBlogPostsQuery($resultQuery)
1079 #getBlogPostsLocation($targetDoc.space $postsLocation)
1080 #set ($discard = $resultQueryParams.put('space', $postsLocation))
1081 #set($resultQuery = "${resultQuery} and doc.space = :space")
1082 #end
1083 #setVariable("$query" $resultQuery)
1084 #setVariable("$queryParams" $resultQueryParams)
1085 #end
1086 ##
1087 ##
1088 ##
1089 ###**
1090 * Display blog posts based on the context where the posts are displayed.
1091 * for example there is 4 different panel contexts:
1092 * aBlog.aPost or aBlog.WebHome
1093 * aCategorySpace.aCategory
1094 * aCategorySpace.WebHome
1095 * Blog.aPost or Blog.WebHome
1096 *
1097 * @param targetDoc The document in which the articles will be displayed.
1098 * @param postsVisiblity The visibility of the posts to display: recent, unpublished, ...
1099 * @param layout Layout of the the posts to display
1100 * @param layoutParams additional layout parameters, it is a string like 'param1=val1|...|paramN=valueN'
1101 * @param limit the number of posts to display
1102 *###
1103 #macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit)
1104 #if ($postLayout == 'full')
1105 #set ($macro.paginated = 'yes')
1106 #end
1107 #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
1108 ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%'
1109 #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout)
1110 #if ("$!layout" == '')
1111 #set ($layout = $postsLayout)
1112 #end
1113 #if ($postsVisiblity == 'recent')
1114 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" limit="$limit" /}}
1115 #elseif($postsVisiblity == 'unpublished')
1116 {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
1117 #end
1118 #elseif($targetDoc.getObject($blogCategoryClassname))
1119 ## Display all posts that are in a category aCategorySpace.aCategory
1120 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
1121 #getBlogPostsLayout($blogDoc $postsLayout)
1122 #if ("$!layout" == '')
1123 #set ($layout = $postsLayout)
1124 #end
1125 #if ($postsVisiblity == 'recent')
1126 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" limit="$limit" /}}
1127 #elseif($postsVisiblity == 'unpublished')
1128 {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
1129 #end
1130 #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
1131 ## Display all posts that are in a category aCategorySpace.%
1132 #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
1133 #getBlogPostsLayout($blogDoc $postsLayout)
1134 #if ("$!layout" == '')
1135 #set ($layout = $postsLayout)
1136 #end
1137 #if ($postsVisiblity == 'recent')
1138 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" limit="$limit" /}}
1139 #elseif($postsVisiblity == 'unpublished')
1140 {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
1141 #end
1142 #else
1143 ## Display all posts in blog space aBlog
1144 #getBlogDocument($targetDoc.space $blogDoc)
1145 #getBlogPostsLayout($blogDoc $postsLayout)
1146 #if ("$!layout" == '')
1147 #set ($layout = $postsLayout)
1148 #end
1149 #if ($postsVisiblity == 'recent')
1150 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" limit="$limit" /}}
1151 #elseif($postsVisiblity == 'unpublished')
1152 {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
1153 #end
1154 #end
1155 #end
1156 ##
1157 ##
1158 ##
1159 #**
1160 * Bind parameters to a query object.
1161 *
1162 * @param queryObj The query object (org.xwiki.query.internal.ScriptQuery object)
1163 * @param queryParams the query parameters.
1164 *###
1165 #macro(bindQueryParameters $queryObj $queryParams)
1166 #set ($output = $queryObj)
1167 #foreach( $key in $queryParams.keySet() )
1168 #set($output = $queryObj.bindValue($key, $queryParams.get($key)))
1169 #end
1170 #setVariable("$queryObj" $output)
1171 #end
1172 ##
1173 ##
1174 ##
1175 #**
1176 * Determines the blogposts layout: Default layout (Calendar), Image thumbnail
1177 *
1178 * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>postsLayout</tt>
1179 * property set.
1180 * @param postsLayout The resulting string. If the blog object does not define anything, it is considered full (default).
1181 *###
1182 #macro(getBlogPostsLayout $blogDoc $postsLayout)
1183 #getBlogProperty($blogDoc 'postsLayout' 'full' $res)
1184 #set ($postsLayout = $NULL)
1185 #setVariable ("$postsLayout" $res)
1186 #end
1187 ##
1188 ##
1189 ##
1190 #**
1191 * Retrieve the blog document of a categories space, which is the blog descriptor that have its categoriesLocation property set to the categories space
1192 *
1193 * @param categoriesSpace A <tt>String</tt>, the name of the space.
1194 * @param blogDoc The resulting XDocument.
1195 *###
1196 #macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc)
1197 #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())
1198 #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace)
1199 #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0)))
1200 #else
1201 ## Fallback to Blog.WebHome, the default blog
1202 #set($macro.result = $xwiki.getDocument('Blog.WebHome'))
1203 #end
1204 #set ($blogDoc = $NULL)
1205 #setVariable ("$blogDoc" $macro.result)
1206 #end
Admin 1.1 1207 {{/velocity}}

Get Connected