| ... |
... |
@@ -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,29 +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 ($legacyRawc2c39d3a2e_1 = $services.query.hql(", BaseObject obj where doc.space = '${space}' and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").execute()) |
| 81 |
|
-#set ($legacyVisiblec2c39d3a2e_1 = []) |
| 82 |
|
-#foreach ($legacyEntryc2c39d3a2e_1 in $legacyRawc2c39d3a2e_1) |
| 83 |
|
- #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_1)) |
| 84 |
|
- #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_1.add($legacyEntryc2c39d3a2e_1)) |
|
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 |
85 |
#end |
| 86 |
|
-#end |
| 87 |
|
- #set($blogDocs = $legacyVisiblec2c39d3a2e_1) |
| 88 |
|
- #if($blogDocs.size() > 0) |
| 89 |
|
- #set($blogDoc = $xwiki.getDocument($blogDocs.get(0))) |
| 90 |
|
- #else |
| 91 |
|
- ## Last, fallback to Blog.WebHome, the default blog |
| 92 |
|
- #set($blogDoc = $xwiki.getDocument('Blog.WebHome')) |
|
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 |
| 93 |
93 |
#end |
| 94 |
94 |
#end |
| 95 |
95 |
#end |
|
112 |
+ #set ($blogDoc = $NULL) |
|
113 |
+ #setVariable ("$blogDoc" $result) |
| 96 |
96 |
#end |
| 97 |
97 |
## |
| 98 |
98 |
## |
| ... |
... |
@@ -104,7 +104,12 @@ |
| 104 |
104 |
* @param title The resulting title. |
| 105 |
105 |
*### |
| 106 |
106 |
#macro(getBlogTitle $blogDoc $title) |
| 107 |
|
- #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) |
| 108 |
108 |
#end |
| 109 |
109 |
## |
| 110 |
110 |
## |
| ... |
... |
@@ -117,7 +117,9 @@ |
| 117 |
117 |
* @param description The resulting description. |
| 118 |
118 |
*### |
| 119 |
119 |
#macro(getBlogDescription $blogDoc $description) |
| 120 |
|
- #getBlogProperty($blogDoc 'description' '' $description) |
|
143 |
+ #getBlogProperty($blogDoc 'description' '' $result) |
|
144 |
+ #set ($description = $NULL) |
|
145 |
+ #setVariable ("$description" $result) |
| 121 |
121 |
#end |
| 122 |
122 |
## |
| 123 |
123 |
## |
| ... |
... |
@@ -343,7 +343,9 @@ |
| 343 |
343 |
* @param displayType The resulting string. If the blog object does not define anything, it is considered paginated. |
| 344 |
344 |
*### |
| 345 |
345 |
#macro(getBlogDisplayType $blogDoc $displayType) |
| 346 |
|
- #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType) |
|
371 |
+ #getBlogProperty($blogDoc 'displayType' 'paginated' $result) |
|
372 |
+ #set ($displayType = $NULL) |
|
373 |
+ #setVariable ("$displayType" $result) |
| 347 |
347 |
#end |
| 348 |
348 |
## |
| 349 |
349 |
## |
| ... |
... |
@@ -396,12 +396,16 @@ |
| 396 |
396 |
* @param entryDoc The xdocument of the blog post. Each post resides in its own document. |
| 397 |
397 |
* @param entryObj The resulting xobject of the blog post. |
| 398 |
398 |
*### |
| 399 |
|
-#macro(getEntryObject $entryDoc $entryObj) |
| 400 |
|
- #set($entryObj = '') |
| 401 |
|
- #set($entryObj = $entryDoc.getObject("${blogPostClassname}")) |
| 402 |
|
- #if("$!{entryObj}" == '') |
| 403 |
|
- #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}")) |
| 404 |
404 |
#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) |
| 405 |
405 |
#end |
| 406 |
406 |
## |
| 407 |
407 |
## |
| ... |
... |
@@ -415,7 +415,8 @@ |
| 415 |
415 |
* @param result The resulting date, an instance of <tt>java.util.Date</tt>. |
| 416 |
416 |
*### |
| 417 |
417 |
#macro(getEntryDate $entryDoc $entryObj $result) |
| 418 |
|
- #set($result = $entryObj.getProperty('publishDate').value) |
|
449 |
+ #set ($result = $NULL) |
|
450 |
+ #setVariable ("$result" $entryObj.getProperty('publishDate').value) |
| 419 |
419 |
#end |
| 420 |
420 |
## |
| 421 |
421 |
## |
| ... |
... |
@@ -835,10 +835,12 @@ |
| 835 |
835 |
* @param propertyValue The resulting value. |
| 836 |
836 |
*### |
| 837 |
837 |
#macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue) |
| 838 |
|
- #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") |
| 839 |
|
- #if($propertyValue == '') |
| 840 |
|
- #set($propertyValue = $defaultValue) |
|
870 |
+ #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") |
|
871 |
+ #if($result == '') |
|
872 |
+ #set($result = $defaultValue) |
| 841 |
841 |
#end |
|
874 |
+ #set ($propertyValue = $NULL) |
|
875 |
+ #setVariable ("$propertyValue" $result) |
| 842 |
842 |
#end |
| 843 |
843 |
## Compatibility helpers from the installed Blog 9.15.15 package. |
| 844 |
844 |
#macro(bindQueryParameters $queryObj $queryParams) |
| ... |
... |
@@ -1028,3 +1028,5 @@ |
| 1028 |
1028 |
#setVariable("$isDefault" $result) |
| 1029 |
1029 |
#end |
| 1030 |
1030 |
|
|
1065 |
+{{/velocity}} |
|
1066 |
+ |