| ... |
... |
@@ -1,4 +1,6 @@ |
| 1 |
|
-#includeMacros("Blog.BlogParameters") |
|
1 |
+{{include reference="Blog.BlogParameters" author="target" /}} |
|
2 |
+ |
|
3 |
+{{velocity output="false"}} |
| 2 |
2 |
## |
| 3 |
3 |
## |
| 4 |
4 |
## |
| ... |
... |
@@ -70,22 +70,45 @@ |
| 70 |
70 |
* @param blogDoc The resulting XDocument. |
| 71 |
71 |
*### |
| 72 |
72 |
#macro(getBlogDocument $space $blogDoc) |
| 73 |
|
- ## First, try the Space.WebHome, for a whole-space blog |
| 74 |
|
- #set($blogDoc = $xwiki.getDocument("${space}.WebHome")) |
| 75 |
|
- #if(!$blogDoc.getObject($blogClassname)) |
| 76 |
|
- ## Second, try the Space.Blog document |
| 77 |
|
- #set($blogDoc = $xwiki.getDocument("${space}.Blog")) |
| 78 |
|
- #if(!$blogDoc.getObject($blogClassname)) |
| 79 |
|
- ## Third, try searching for a blog document in the current space |
| 80 |
|
- #set($blogDocs = $services.query.hql(", BaseObject obj where doc.space = '${space}' and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").addFilter('view').execute()) |
| 81 |
|
- #if($blogDocs.size() > 0) |
| 82 |
|
- #set($blogDoc = $xwiki.getDocument($blogDocs.get(0))) |
| 83 |
|
- #else |
| 84 |
|
- ## Last, fallback to Blog.WebHome, the default blog |
| 85 |
|
- #set($blogDoc = $xwiki.getDocument('Blog.WebHome')) |
|
75 |
+ #set ($result = $NULL) |
|
76 |
+ ## Check if the current space has a WebPreferences page that contains a Blog.EnablePanelsConfigurationClass object. |
|
77 |
+ ## It is possible to display a blog's panels info in a page that is not inside a blog and in that case we need to |
|
78 |
+ ## identify the right blog based on a configuration object in a WebPreferences page. |
|
79 |
+ #set ($spaceReference = $services.model.resolveSpace($space)) |
|
80 |
+ #set ($preferencesDocRef = $services.model.createDocumentReference('WebPreferences', $spaceReference)) |
|
81 |
+ #set ($preferencesDoc = $xwiki.getDocument($preferencesDocRef)) |
|
82 |
+ #set ($preferencesObj = $preferencesDoc.getObject('Blog.EnablePanelsConfigurationClass')) |
|
83 |
+ #if ($preferencesObj) |
|
84 |
+ #set ($result = $xwiki.getDocument( $preferencesObj.getValue('blog'))) |
|
85 |
+ #end |
|
86 |
+ ## If no special case occurs (like the previous one), identify a blog by checking the current location from its hierarchy. |
|
87 |
+ #if ("$!result" == '') |
|
88 |
+ ## First, try the Space.WebHome, for a whole-space blog |
|
89 |
+ #set($result = $xwiki.getDocument("${space}.WebHome")) |
|
90 |
+ #if(!$result.getObject($blogClassname)) |
|
91 |
+ ## Second, try the Space.Blog document |
|
92 |
+ #set($result = $xwiki.getDocument("${space}.Blog")) |
|
93 |
+ #if(!$result.getObject($blogClassname)) |
|
94 |
+ ## Third, try searching for a blog document in the current space |
|
95 |
+ ## Prevent the query fail when the space contains dots '.' |
|
96 |
+ #set($blogDocs = $services.query.hql(", BaseObject obj where doc.space = :space and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").setLimit(1).setOffset(0).bindValue('space', $space).execute()) |
|
97 |
+ #if($blogDocs.size() > 0) |
|
98 |
+ #set($result = $xwiki.getDocument($blogDocs.get(0))) |
|
99 |
+ #else |
|
100 |
+ ## Fourth, try searching for a blog document that have the its 'postsLocation' set to the current space |
|
101 |
+ #set($blogDocs = $services.query.hql(", BaseObject obj, StringProperty as postsLocationProp where obj.name = doc.fullName and obj.className = '$blogClassname' and obj.id=postsLocationProp.id.id and postsLocationProp.id.name='postsLocation' and postsLocationProp.value=:postsLocation order by doc.name").setLimit(1).setOffset(0).bindValue('postsLocation', $space).execute()) |
|
102 |
+ #if($blogDocs.size() > 0) |
|
103 |
+ #set($result = $xwiki.getDocument($blogDocs.get(0))) |
|
104 |
+ #else |
|
105 |
+ ## Last, fallback to Blog.WebHome, the default blog |
|
106 |
+ #set($result = $xwiki.getDocument('Blog.WebHome')) |
|
107 |
+ #end |
|
108 |
+ #end |
| 86 |
86 |
#end |
| 87 |
87 |
#end |
| 88 |
88 |
#end |
|
112 |
+ #set ($blogDoc = $NULL) |
|
113 |
+ #setVariable ("$blogDoc" $result) |
| 89 |
89 |
#end |
| 90 |
90 |
## |
| 91 |
91 |
## |
| ... |
... |
@@ -97,7 +97,12 @@ |
| 97 |
97 |
* @param title The resulting title. |
| 98 |
98 |
*### |
| 99 |
99 |
#macro(getBlogTitle $blogDoc $title) |
| 100 |
|
- #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $title) |
|
125 |
+ ## The blog title is the rendered document title. It is displayed as data (never evaluated as |
|
126 |
+ ## Velocity), so an unprivileged user storing script in Blog.BlogClass.title cannot run it. See |
|
127 |
+ ## Blog.BlogSheet, which renders the title literally and falls back to the blog.code.title |
|
128 |
+ ## translation when the stored title is empty. |
|
129 |
+ #set ($title = $NULL) |
|
130 |
+ #setVariable ("$title" $!blogDoc.displayTitle) |
| 101 |
101 |
#end |
| 102 |
102 |
## |
| 103 |
103 |
## |
| ... |
... |
@@ -110,7 +110,9 @@ |
| 110 |
110 |
* @param description The resulting description. |
| 111 |
111 |
*### |
| 112 |
112 |
#macro(getBlogDescription $blogDoc $description) |
| 113 |
|
- #getBlogProperty($blogDoc 'description' '' $description) |
|
143 |
+ #getBlogProperty($blogDoc 'description' '' $result) |
|
144 |
+ #set ($description = $NULL) |
|
145 |
+ #setVariable ("$description" $result) |
| 114 |
114 |
#end |
| 115 |
115 |
## |
| 116 |
116 |
## |
| ... |
... |
@@ -161,8 +161,15 @@ |
| 161 |
161 |
#set($defaultItemsPerPage = $util.parseInt($defaultItemsPerPage)) |
| 162 |
162 |
## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. |
| 163 |
163 |
#preparePagedViewParams($totalEntries $defaultItemsPerPage) |
| 164 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).addFilter('view').execute()) |
|
196 |
+#set ($legacyRawc2c39d3a2e_2 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) |
|
197 |
+#set ($legacyVisiblec2c39d3a2e_2 = []) |
|
198 |
+#foreach ($legacyEntryc2c39d3a2e_2 in $legacyRawc2c39d3a2e_2) |
|
199 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_2)) |
|
200 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_2.add($legacyEntryc2c39d3a2e_2)) |
|
201 |
+ #end |
| 165 |
165 |
#end |
|
203 |
+ #set($entries = $legacyVisiblec2c39d3a2e_2) |
|
204 |
+#end |
| 166 |
166 |
## |
| 167 |
167 |
## |
| 168 |
168 |
## |
| ... |
... |
@@ -183,8 +183,15 @@ |
| 183 |
183 |
#set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling())) |
| 184 |
184 |
#set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") |
| 185 |
185 |
#set($totalEntries = $xwiki.countDocuments(${query})) |
| 186 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").addFilter('view').execute()) |
|
225 |
+#set ($legacyRawc2c39d3a2e_3 = $services.query.hql("${query} order by publishDate.value desc").execute()) |
|
226 |
+#set ($legacyVisiblec2c39d3a2e_3 = []) |
|
227 |
+#foreach ($legacyEntryc2c39d3a2e_3 in $legacyRawc2c39d3a2e_3) |
|
228 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_3)) |
|
229 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_3.add($legacyEntryc2c39d3a2e_3)) |
|
230 |
+ #end |
| 187 |
187 |
#end |
|
232 |
+ #set($entries = $legacyVisiblec2c39d3a2e_3) |
|
233 |
+#end |
| 188 |
188 |
## |
| 189 |
189 |
## |
| 190 |
190 |
## |
| ... |
... |
@@ -205,8 +205,15 @@ |
| 205 |
205 |
#set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling())) |
| 206 |
206 |
#set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") |
| 207 |
207 |
#set($totalEntries = $xwiki.countDocuments(${query})) |
| 208 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").addFilter('view').execute()) |
|
254 |
+#set ($legacyRawc2c39d3a2e_4 = $services.query.hql("${query} order by publishDate.value desc").execute()) |
|
255 |
+#set ($legacyVisiblec2c39d3a2e_4 = []) |
|
256 |
+#foreach ($legacyEntryc2c39d3a2e_4 in $legacyRawc2c39d3a2e_4) |
|
257 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_4)) |
|
258 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_4.add($legacyEntryc2c39d3a2e_4)) |
|
259 |
+ #end |
| 209 |
209 |
#end |
|
261 |
+ #set($entries = $legacyVisiblec2c39d3a2e_4) |
|
262 |
+#end |
| 210 |
210 |
## |
| 211 |
211 |
## |
| 212 |
212 |
## |
| ... |
... |
@@ -220,8 +220,15 @@ |
| 220 |
220 |
*### |
| 221 |
221 |
#macro(getAllBlogEntries $blogDoc $query $entries) |
| 222 |
222 |
#set($totalEntries = $xwiki.countDocuments(${query})) |
| 223 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").addFilter('view').execute()) |
|
276 |
+#set ($legacyRawc2c39d3a2e_5 = $services.query.hql("${query} order by publishDate.value desc").execute()) |
|
277 |
+#set ($legacyVisiblec2c39d3a2e_5 = []) |
|
278 |
+#foreach ($legacyEntryc2c39d3a2e_5 in $legacyRawc2c39d3a2e_5) |
|
279 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_5)) |
|
280 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_5.add($legacyEntryc2c39d3a2e_5)) |
|
281 |
+ #end |
| 224 |
224 |
#end |
|
283 |
+ #set($entries = $legacyVisiblec2c39d3a2e_5) |
|
284 |
+#end |
| 225 |
225 |
## |
| 226 |
226 |
## |
| 227 |
227 |
## |
| ... |
... |
@@ -236,8 +236,15 @@ |
| 236 |
236 |
#macro(getUnpublishedBlogEntries $blogDoc $query $entries) |
| 237 |
237 |
#set($query = "${query} and isPublished.value = 0") |
| 238 |
238 |
#set($totalEntries = $xwiki.countDocuments(${query})) |
| 239 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").addFilter('view').execute()) |
|
299 |
+#set ($legacyRawc2c39d3a2e_6 = $services.query.hql("${query} order by publishDate.value desc").execute()) |
|
300 |
+#set ($legacyVisiblec2c39d3a2e_6 = []) |
|
301 |
+#foreach ($legacyEntryc2c39d3a2e_6 in $legacyRawc2c39d3a2e_6) |
|
302 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_6)) |
|
303 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_6.add($legacyEntryc2c39d3a2e_6)) |
|
304 |
+ #end |
| 240 |
240 |
#end |
|
306 |
+ #set($entries = $legacyVisiblec2c39d3a2e_6) |
|
307 |
+#end |
| 241 |
241 |
## |
| 242 |
242 |
## |
| 243 |
243 |
## |
| ... |
... |
@@ -252,8 +252,15 @@ |
| 252 |
252 |
#set($defaultItemsPerPage = 20) |
| 253 |
253 |
## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. |
| 254 |
254 |
#preparePagedViewParams($totalEntries $defaultItemsPerPage) |
| 255 |
|
- #set($entries = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).addFilter('view').execute()) |
|
322 |
+#set ($legacyRawc2c39d3a2e_7 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) |
|
323 |
+#set ($legacyVisiblec2c39d3a2e_7 = []) |
|
324 |
+#foreach ($legacyEntryc2c39d3a2e_7 in $legacyRawc2c39d3a2e_7) |
|
325 |
+ #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_7)) |
|
326 |
+ #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_7.add($legacyEntryc2c39d3a2e_7)) |
|
327 |
+ #end |
| 256 |
256 |
#end |
|
329 |
+ #set($entries = $legacyVisiblec2c39d3a2e_7) |
|
330 |
+#end |
| 257 |
257 |
## |
| 258 |
258 |
## |
| 259 |
259 |
## |
| ... |
... |
@@ -264,13 +264,7 @@ |
| 264 |
264 |
* @param query The basic query for selecting blog entries. |
| 265 |
265 |
*### |
| 266 |
266 |
#macro(getBlogEntriesBaseQuery $query) |
| 267 |
|
- #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate |
| 268 |
|
- where doc.fullName <> 'Blog.BlogPostTemplate' and |
| 269 |
|
- obj.name = doc.fullName and obj.className = '${blogPostClassname}' and |
| 270 |
|
- publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and |
| 271 |
|
- isPublished.id.id = obj.id and isPublished.id.name = 'published' and |
| 272 |
|
- hidden.id.id = obj.id and hidden.id.name = 'hidden' and |
| 273 |
|
- (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))") |
|
341 |
+ #getAllBlogPostsQuery($query) |
| 274 |
274 |
#end |
| 275 |
275 |
## |
| 276 |
276 |
## |
| ... |
... |
@@ -300,7 +300,9 @@ |
| 300 |
300 |
* @param displayType The resulting string. If the blog object does not define anything, it is considered paginated. |
| 301 |
301 |
*### |
| 302 |
302 |
#macro(getBlogDisplayType $blogDoc $displayType) |
| 303 |
|
- #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType) |
|
371 |
+ #getBlogProperty($blogDoc 'displayType' 'paginated' $result) |
|
372 |
+ #set ($displayType = $NULL) |
|
373 |
+ #setVariable ("$displayType" $result) |
| 304 |
304 |
#end |
| 305 |
305 |
## |
| 306 |
306 |
## |
| ... |
... |
@@ -353,12 +353,16 @@ |
| 353 |
353 |
* @param entryDoc The xdocument of the blog post. Each post resides in its own document. |
| 354 |
354 |
* @param entryObj The resulting xobject of the blog post. |
| 355 |
355 |
*### |
| 356 |
|
-#macro(getEntryObject $entryDoc $entryObj) |
| 357 |
|
- #set($entryObj = '') |
| 358 |
|
- #set($entryObj = $entryDoc.getObject("${blogPostClassname}")) |
| 359 |
|
- #if("$!{entryObj}" == '') |
| 360 |
|
- #set($entryObj = $entryDoc.getObject("${oldArticleClassname}")) |
|
426 |
+#macro(getEntryObject $entryDoc $__entryObj) |
|
427 |
+ #set($result = $entryDoc.getObject("${blogPostClassname}")) |
|
428 |
+ #if(!$result) |
|
429 |
+ #set($result = $entryDoc.getObject("${oldArticleClassname}")) |
| 361 |
361 |
#end |
|
431 |
+ ## NOTE: The reason we put an underscore in front of the variable name is to prevent the following line from |
|
432 |
+ ## overwriting the $entryObj variable that may be defined before this macro is called. Of course, $__entryObj may be |
|
433 |
+ ## overwritten in this case but it's less likely to have such a variable defined before. |
|
434 |
+ #set ($__entryObj = $NULL) |
|
435 |
+ #setVariable ("$__entryObj" $result) |
| 362 |
362 |
#end |
| 363 |
363 |
## |
| 364 |
364 |
## |
| ... |
... |
@@ -372,7 +372,8 @@ |
| 372 |
372 |
* @param result The resulting date, an instance of <tt>java.util.Date</tt>. |
| 373 |
373 |
*### |
| 374 |
374 |
#macro(getEntryDate $entryDoc $entryObj $result) |
| 375 |
|
- #set($result = $entryObj.getProperty('publishDate').value) |
|
449 |
+ #set ($result = $NULL) |
|
450 |
+ #setVariable ("$result" $entryObj.getProperty('publishDate').value) |
| 376 |
376 |
#end |
| 377 |
377 |
## |
| 378 |
378 |
## |
| ... |
... |
@@ -792,8 +792,200 @@ |
| 792 |
792 |
* @param propertyValue The resulting value. |
| 793 |
793 |
*### |
| 794 |
794 |
#macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue) |
| 795 |
|
- #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") |
| 796 |
|
- #if($propertyValue == '') |
| 797 |
|
- #set($propertyValue = $defaultValue) |
|
870 |
+ #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") |
|
871 |
+ #if($result == '') |
|
872 |
+ #set($result = $defaultValue) |
| 798 |
798 |
#end |
|
874 |
+ #set ($propertyValue = $NULL) |
|
875 |
+ #setVariable ("$propertyValue" $result) |
| 799 |
799 |
#end |
|
877 |
+## Compatibility helpers from the installed Blog 9.15.15 package. |
|
878 |
+#macro(bindQueryParameters $queryObj $queryParams) |
|
879 |
+ #set ($output = $queryObj) |
|
880 |
+ #foreach( $key in $queryParams.keySet() ) |
|
881 |
+ #set($output = $queryObj.bindValue($key, $queryParams.get($key))) |
|
882 |
+ #end |
|
883 |
+ #setVariable("$queryObj" $output) |
|
884 |
+#end |
|
885 |
+ |
|
886 |
+#macro(blog__actionResponseError $status $text $parameters) |
|
887 |
+ $response.setStatus($status) |
|
888 |
+ #if($request.ajax) |
|
889 |
+ $services.localization.render($text, $!parameters) |
|
890 |
+ #else |
|
891 |
+ {{error}}$services.localization.render($text, $!parameters){{/error}} |
|
892 |
+ #end |
|
893 |
+#end |
|
894 |
+ |
|
895 |
+#macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit) |
|
896 |
+ #if ($layout == 'link') |
|
897 |
+ #set ($macro.paginated = 'no') |
|
898 |
+ #end |
|
899 |
+ #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) |
|
900 |
+ ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%' |
|
901 |
+ #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout) |
|
902 |
+ #if ("$!layout" == '') |
|
903 |
+ #set ($layout = $postsLayout) |
|
904 |
+ #end |
|
905 |
+ #if ($postsVisiblity == 'recent') |
|
906 |
+ {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
907 |
+ #elseif($postsVisiblity == 'unpublished') |
|
908 |
+ {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
909 |
+ #end |
|
910 |
+ #elseif($targetDoc.getObject($blogCategoryClassname)) |
|
911 |
+ ## Display all posts that are in a category aCategorySpace.aCategory |
|
912 |
+ #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) |
|
913 |
+ #getBlogPostsLayout($blogDoc $postsLayout) |
|
914 |
+ #if ("$!layout" == '') |
|
915 |
+ #set ($layout = $postsLayout) |
|
916 |
+ #end |
|
917 |
+ #if ($postsVisiblity == 'recent') |
|
918 |
+ {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
919 |
+ #elseif($postsVisiblity == 'unpublished') |
|
920 |
+ {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
921 |
+ #end |
|
922 |
+ #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') |
|
923 |
+ ## Display all posts that are in a category aCategorySpace.% |
|
924 |
+ #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) |
|
925 |
+ #getBlogPostsLayout($blogDoc $postsLayout) |
|
926 |
+ #if ("$!layout" == '') |
|
927 |
+ #set ($layout = $postsLayout) |
|
928 |
+ #end |
|
929 |
+ #if ($postsVisiblity == 'recent') |
|
930 |
+ {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
931 |
+ #elseif($postsVisiblity == 'unpublished') |
|
932 |
+ {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
933 |
+ #end |
|
934 |
+ #else |
|
935 |
+ ## Display all posts in blog space aBlog |
|
936 |
+ #getBlogDocument($targetDoc.space $blogDoc) |
|
937 |
+ #getBlogPostsLayout($blogDoc $postsLayout) |
|
938 |
+ #if ("$!layout" == '') |
|
939 |
+ #set ($layout = $postsLayout) |
|
940 |
+ #end |
|
941 |
+ #if ($postsVisiblity == 'recent') |
|
942 |
+ {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
943 |
+ #elseif($postsVisiblity == 'unpublished') |
|
944 |
+ {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
|
945 |
+ #end |
|
946 |
+ #end |
|
947 |
+#end |
|
948 |
+ |
|
949 |
+#macro(displayEntryBlogLocation $entryDoc $entryObj) |
|
950 |
+ #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ## |
|
951 |
+ #if("$!blogPostsLocation" != "") ## |
|
952 |
+ #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ## |
|
953 |
+ #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ## |
|
954 |
+ #if($doc.documentReference != $blogDocRef) ## |
|
955 |
+ #set($blogDoc = $xwiki.getDocument($blogDocRef)) ## |
|
956 |
+ #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ## |
|
957 |
+ #if($blogObj) (% class="blogrefpath" %)((( ## |
|
958 |
+ $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ## |
|
959 |
+ )))(%%)## |
|
960 |
+ #end |
|
961 |
+ #end |
|
962 |
+ #end |
|
963 |
+#end |
|
964 |
+ |
|
965 |
+#macro(getAllBlogPostsQuery $query) |
|
966 |
+ #set ($query = $NULL) |
|
967 |
+ #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished, |
|
968 |
+ IntegerProperty hidden, DateProperty publishDate |
|
969 |
+ where doc.fullName <> '$blogPostTemplate' and |
|
970 |
+ obj.name=doc.fullName and obj.className='$blogPostClassname' and |
|
971 |
+ isPublished.id.id = obj.id and isPublished.id.name = 'published' and |
|
972 |
+ hidden.id.id = obj.id and hidden.id.name='hidden' and |
|
973 |
+ publishDate.id.id = obj.id and publishDate.id.name='publishDate' and |
|
974 |
+ (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))") |
|
975 |
+#end |
|
976 |
+ |
|
977 |
+#macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams) |
|
978 |
+ #set ($query = $NULL) |
|
979 |
+ #set ($queryParams = $NULL) |
|
980 |
+ #getCategoryAllBlogPostsQuery($resultQuery) |
|
981 |
+ #set ($resultQueryParams = {}) |
|
982 |
+ #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%')) |
|
983 |
+ #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) |
|
984 |
+ ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%' |
|
985 |
+ #set ($discard = $resultQueryParams.put('space', $targetDoc.space)) |
|
986 |
+ #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) |
|
987 |
+ #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')") |
|
988 |
+ #elseif($targetDoc.getObject($blogCategoryClassname)) |
|
989 |
+ ## Get all posts that are in a category aCategorySpace.aCategory |
|
990 |
+ #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName)) |
|
991 |
+ #set($resultQuery = "${resultQuery} and (catList=:catList)") |
|
992 |
+ #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') |
|
993 |
+ ## Get all posts that are in a category aCategorySpace.% |
|
994 |
+ #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) |
|
995 |
+ ## Exclude incategorized posts |
|
996 |
+ #set ($excludedCategory = "${targetDoc.space}.WebHome") |
|
997 |
+ #if ($targetDoc.space == $defaultBlogSpace) |
|
998 |
+ #set ($excludedCategory = "Blog.Categories.WebHome") |
|
999 |
+ #end |
|
1000 |
+ #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory)) |
|
1001 |
+ #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')") |
|
1002 |
+ #else |
|
1003 |
+ ## Get all posts in blog space aBlog |
|
1004 |
+ #getAllBlogPostsQuery($resultQuery) |
|
1005 |
+ #getBlogPostsLocation($targetDoc.space $postsLocation) |
|
1006 |
+ #set ($discard = $resultQueryParams.put('space', $postsLocation)) |
|
1007 |
+ #set($resultQuery = "${resultQuery} and doc.space = :space") |
|
1008 |
+ #end |
|
1009 |
+ #setVariable("$query" $resultQuery) |
|
1010 |
+ #setVariable("$queryParams" $resultQueryParams) |
|
1011 |
+#end |
|
1012 |
+ |
|
1013 |
+#macro(getBlogCategoriesLocation $blogSpace $categoriesLocation) |
|
1014 |
+ #getBlogDocument($blogSpace $blogDoc) |
|
1015 |
+ ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility. |
|
1016 |
+ #set ($defaultBlogCategoryLocation = 'Blog.Categories') |
|
1017 |
+ #if ($services.blog.hasLegacyCategoryAssignments()) |
|
1018 |
+ #set ($defaultBlogCategoryLocation = 'Blog') |
|
1019 |
+ #end |
|
1020 |
+ #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result) |
|
1021 |
+ #set ($postsLocation = $NULL) |
|
1022 |
+ #setVariable ("$categoriesLocation" $result) |
|
1023 |
+#end |
|
1024 |
+ |
|
1025 |
+#macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc) |
|
1026 |
+ #set($macro.blogDocs = $services.query.hql(", BaseObject obj, StringProperty as categoriesLocationProp where obj.name = doc.fullName and obj.className = '$blogClassname' and obj.id=categoriesLocationProp.id.id and categoriesLocationProp.id.name='categoriesLocation' and categoriesLocationProp.value=:categoriesLocation order by doc.creationDate").setLimit(1).setOffset(0).bindValue('categoriesLocation', $categoriesSpace).execute()) |
|
1027 |
+ #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace) |
|
1028 |
+ #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0))) |
|
1029 |
+ #else |
|
1030 |
+ ## Fallback to Blog.WebHome, the default blog |
|
1031 |
+ #set($macro.result = $xwiki.getDocument('Blog.WebHome')) |
|
1032 |
+ #end |
|
1033 |
+ #set ($blogDoc = $NULL) |
|
1034 |
+ #setVariable ("$blogDoc" $macro.result) |
|
1035 |
+#end |
|
1036 |
+ |
|
1037 |
+#macro(getBlogPostsLayout $blogDoc $postsLayout) |
|
1038 |
+ #getBlogProperty($blogDoc 'postsLayout' 'full' $res) |
|
1039 |
+ #set ($postsLayout = $NULL) |
|
1040 |
+ #setVariable ("$postsLayout" $res) |
|
1041 |
+#end |
|
1042 |
+ |
|
1043 |
+#macro(getBlogPostsLocation $blogSpace $postsLocation) |
|
1044 |
+ #getBlogDocument($blogSpace $blogDoc) |
|
1045 |
+ #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result) |
|
1046 |
+ #set ($postsLocation = $NULL) |
|
1047 |
+ #setVariable ("$postsLocation" $result) |
|
1048 |
+#end |
|
1049 |
+ |
|
1050 |
+#macro(getCategoryAllBlogPostsQuery $query) |
|
1051 |
+ #set ($query = $NULL) |
|
1052 |
+ #getAllBlogPostsQuery($baseQuery) |
|
1053 |
+ #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList')) |
|
1054 |
+ #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'") |
|
1055 |
+#end |
|
1056 |
+ |
|
1057 |
+#macro(isDefaultBlog $blogDoc $isDefault) |
|
1058 |
+ #set ($result = false) |
|
1059 |
+ #if ($blogDoc.space == 'Blog') |
|
1060 |
+ #set ($result = true) |
|
1061 |
+ #end |
|
1062 |
+ #setVariable("$isDefault" $result) |
|
1063 |
+#end |
|
1064 |
+ |
|
1065 |
+{{/velocity}} |
|
1066 |
+ |