Last modified by superadmin on 2026/12/02 07:12

From version Icon 5.1 Icon
edited by superadmin
on 2026/12/02 05:36
Change comment: There is no comment for this version
To version Icon 6.1
edited by superadmin
on 2026/12/02 07:12
Change comment: There is no comment for this version

Summary

Details

Icon Page properties
Content
... ... @@ -72,29 +72,45 @@
72 72   * @param blogDoc The resulting XDocument.
73 73   *###
74 74  #macro(getBlogDocument $space $blogDoc)
75 - ## First, try the Space.WebHome, for a whole-space blog
76 - #set($blogDoc = $xwiki.getDocument("${space}.WebHome"))
77 - #if(!$blogDoc.getObject($blogClassname))
78 - ## Second, try the Space.Blog document
79 - #set($blogDoc = $xwiki.getDocument("${space}.Blog"))
80 - #if(!$blogDoc.getObject($blogClassname))
81 - ## Third, try searching for a blog document in the current space
82 -#set ($legacyRawc2c39d3a2e_1 = $services.query.hql(", BaseObject obj where doc.space = '${space}' and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").execute())
83 -#set ($legacyVisiblec2c39d3a2e_1 = [])
84 -#foreach ($legacyEntryc2c39d3a2e_1 in $legacyRawc2c39d3a2e_1)
85 - #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryc2c39d3a2e_1))
86 - #set ($legacyVisibilityDiscard = $legacyVisiblec2c39d3a2e_1.add($legacyEntryc2c39d3a2e_1))
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')))
87 87   #end
88 -#end
89 - #set($blogDocs = $legacyVisiblec2c39d3a2e_1)
90 - #if($blogDocs.size() > 0)
91 - #set($blogDoc = $xwiki.getDocument($blogDocs.get(0)))
92 - #else
93 - ## Last, fallback to Blog.WebHome, the default blog
94 - #set($blogDoc = $xwiki.getDocument('Blog.WebHome'))
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
95 95   #end
96 96   #end
97 97   #end
112 + #set ($blogDoc = $NULL)
113 + #setVariable ("$blogDoc" $result)
98 98  #end
99 99  ##
100 100  ##
... ... @@ -407,12 +407,16 @@
407 407   * @param entryDoc The xdocument of the blog post. Each post resides in its own document.
408 408   * @param entryObj The resulting xobject of the blog post.
409 409   *###
410 -#macro(getEntryObject $entryDoc $entryObj)
411 - #set($entryObj = '')
412 - #set($entryObj = $entryDoc.getObject("${blogPostClassname}"))
413 - #if("$!{entryObj}" == '')
414 - #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}"))
415 415   #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)
416 416  #end
417 417  ##
418 418  ##
... ... @@ -426,7 +426,8 @@
426 426   * @param result The resulting date, an instance of <tt>java.util.Date</tt>.
427 427   *###
428 428  #macro(getEntryDate $entryDoc $entryObj $result)
429 - #set($result = $entryObj.getProperty('publishDate').value)
449 + #set ($result = $NULL)
450 + #setVariable ("$result" $entryObj.getProperty('publishDate').value)
430 430  #end
431 431  ##
432 432  ##

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

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

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

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

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

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

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