Last modified by Hal Eden on 2010/08/22 20:09

From version Icon 7.1
edited by Hal Eden
on 2010/08/22 20:09
Change comment: There is no comment for this version
To version Icon 5.1 Icon
edited by superadmin
on 2026/12/02 00:12
Change comment: There is no comment for this version

Summary

Details

Icon Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.haleden
1 +XWiki.superadmin
Content
... ... @@ -102,12 +102,7 @@
102 102   * @param title The resulting title.
103 103   *###
104 104  #macro(getBlogTitle $blogDoc $title)
105 - ## The blog title is the rendered document title. It is displayed as data (never evaluated as
106 - ## Velocity), so an unprivileged user storing script in Blog.BlogClass.title cannot run it. See
107 - ## Blog.BlogSheet, which renders the title literally and falls back to the blog.code.title
108 - ## translation when the stored title is empty.
109 - #set ($title = $NULL)
110 - #setVariable ("$title" $!blogDoc.displayTitle)
105 + #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $title)
111 111  #end
112 112  ##
113 113  ##
... ... @@ -120,9 +120,7 @@
120 120   * @param description The resulting description.
121 121   *###
122 122  #macro(getBlogDescription $blogDoc $description)
123 - #getBlogProperty($blogDoc 'description' '' $result)
124 - #set ($description = $NULL)
125 - #setVariable ("$description" $result)
118 + #getBlogProperty($blogDoc 'description' '' $description)
126 126  #end
127 127  ##
128 128  ##
... ... @@ -318,7 +318,13 @@
318 318   * @param query The basic query for selecting blog entries.
319 319   *###
320 320  #macro(getBlogEntriesBaseQuery $query)
321 - #getAllBlogPostsQuery($query)
314 + #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate
315 + where doc.fullName <> '${blogPostTemplate}' and
316 + obj.name = doc.fullName and obj.className = '${blogPostClassname}' and
317 + publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and
318 + isPublished.id.id = obj.id and isPublished.id.name = 'published' and
319 + hidden.id.id = obj.id and hidden.id.name = 'hidden' and
320 + (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))")
322 322  #end
323 323  ##
324 324  ##
... ... @@ -348,9 +348,7 @@
348 348   * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated.
349 349   *###
350 350  #macro(getBlogDisplayType $blogDoc $displayType)
351 - #getBlogProperty($blogDoc 'displayType' 'paginated' $result)
352 - #set ($displayType = $NULL)
353 - #setVariable ("$displayType" $result)
350 + #getBlogProperty($blogDoc 'displayType' 'paginated' $displayType)
354 354  #end
355 355  ##
356 356  ##
... ... @@ -845,201 +845,11 @@
845 845   * @param propertyValue The resulting value.
846 846   *###
847 847  #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue)
848 - #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
849 - #if($result == '')
850 - #set($result = $defaultValue)
845 + #set($propertyValue = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}")
846 + #if($propertyValue == '')
847 + #set($propertyValue = $defaultValue)
851 851   #end
852 - #set ($propertyValue = $NULL)
853 - #setVariable ("$propertyValue" $result)
854 854  #end
855 -
856 -## Compatibility helpers from the installed Blog 9.15.15 package.
857 -#macro(bindQueryParameters $queryObj $queryParams)
858 - #set ($output = $queryObj)
859 - #foreach( $key in $queryParams.keySet() )
860 - #set($output = $queryObj.bindValue($key, $queryParams.get($key)))
861 - #end
862 - #setVariable("$queryObj" $output)
863 -#end
864 -
865 -#macro(blog__actionResponseError $status $text $parameters)
866 - $response.setStatus($status)
867 - #if($request.ajax)
868 - $services.localization.render($text, $!parameters)
869 - #else
870 - {{error}}$services.localization.render($text, $!parameters){{/error}}
871 - #end
872 -#end
873 -
874 -#macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit)
875 - #if ($layout == 'link')
876 - #set ($macro.paginated = 'no')
877 - #end
878 - #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
879 - ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%'
880 - #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout)
881 - #if ("$!layout" == '')
882 - #set ($layout = $postsLayout)
883 - #end
884 - #if ($postsVisiblity == 'recent')
885 - {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
886 - #elseif($postsVisiblity == 'unpublished')
887 - {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
888 - #end
889 - #elseif($targetDoc.getObject($blogCategoryClassname))
890 - ## Display all posts that are in a category aCategorySpace.aCategory
891 - #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
892 - #getBlogPostsLayout($blogDoc $postsLayout)
893 - #if ("$!layout" == '')
894 - #set ($layout = $postsLayout)
895 - #end
896 - #if ($postsVisiblity == 'recent')
897 - {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
898 - #elseif($postsVisiblity == 'unpublished')
899 - {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
900 - #end
901 - #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
902 - ## Display all posts that are in a category aCategorySpace.%
903 - #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc)
904 - #getBlogPostsLayout($blogDoc $postsLayout)
905 - #if ("$!layout" == '')
906 - #set ($layout = $postsLayout)
907 - #end
908 - #if ($postsVisiblity == 'recent')
909 - {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
910 - #elseif($postsVisiblity == 'unpublished')
911 - {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
912 - #end
913 - #else
914 - ## Display all posts in blog space aBlog
915 - #getBlogDocument($targetDoc.space $blogDoc)
916 - #getBlogPostsLayout($blogDoc $postsLayout)
917 - #if ("$!layout" == '')
918 - #set ($layout = $postsLayout)
919 - #end
920 - #if ($postsVisiblity == 'recent')
921 - {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
922 - #elseif($postsVisiblity == 'unpublished')
923 - {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}}
924 - #end
925 - #end
926 -#end
927 -
928 -#macro(displayEntryBlogLocation $entryDoc $entryObj)
929 - #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ##
930 - #if("$!blogPostsLocation" != "") ##
931 - #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ##
932 - #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ##
933 - #if($doc.documentReference != $blogDocRef) ##
934 - #set($blogDoc = $xwiki.getDocument($blogDocRef)) ##
935 - #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ##
936 - #if($blogObj) (% class="blogrefpath" %)((( ##
937 - $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ##
938 - )))(%%)##
939 - #end
940 - #end
941 - #end
942 -#end
943 -
944 -#macro(getAllBlogPostsQuery $query)
945 - #set ($query = $NULL)
946 - #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished,
947 - IntegerProperty hidden, DateProperty publishDate
948 - where doc.fullName <> '$blogPostTemplate' and
949 - obj.name=doc.fullName and obj.className='$blogPostClassname' and
950 - isPublished.id.id = obj.id and isPublished.id.name = 'published' and
951 - hidden.id.id = obj.id and hidden.id.name='hidden' and
952 - publishDate.id.id = obj.id and publishDate.id.name='publishDate' and
953 - (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))")
954 -#end
955 -
956 -#macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams)
957 - #set ($query = $NULL)
958 - #set ($queryParams = $NULL)
959 - #getCategoryAllBlogPostsQuery($resultQuery)
960 - #set ($resultQueryParams = {})
961 - #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%'))
962 - #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname))
963 - ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%'
964 - #set ($discard = $resultQueryParams.put('space', $targetDoc.space))
965 - #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
966 - #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')")
967 - #elseif($targetDoc.getObject($blogCategoryClassname))
968 - ## Get all posts that are in a category aCategorySpace.aCategory
969 - #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName))
970 - #set($resultQuery = "${resultQuery} and (catList=:catList)")
971 - #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet')
972 - ## Get all posts that are in a category aCategorySpace.%
973 - #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace))
974 - ## Exclude incategorized posts
975 - #set ($excludedCategory = "${targetDoc.space}.WebHome")
976 - #if ($targetDoc.space == $defaultBlogSpace)
977 - #set ($excludedCategory = "Blog.Categories.WebHome")
978 - #end
979 - #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory))
980 - #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')")
981 - #else
982 - ## Get all posts in blog space aBlog
983 - #getAllBlogPostsQuery($resultQuery)
984 - #getBlogPostsLocation($targetDoc.space $postsLocation)
985 - #set ($discard = $resultQueryParams.put('space', $postsLocation))
986 - #set($resultQuery = "${resultQuery} and doc.space = :space")
987 - #end
988 - #setVariable("$query" $resultQuery)
989 - #setVariable("$queryParams" $resultQueryParams)
990 -#end
991 -
992 -#macro(getBlogCategoriesLocation $blogSpace $categoriesLocation)
993 - #getBlogDocument($blogSpace $blogDoc)
994 - ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility.
995 - #set ($defaultBlogCategoryLocation = 'Blog.Categories')
996 - #if ($services.blog.hasLegacyCategoryAssignments())
997 - #set ($defaultBlogCategoryLocation = 'Blog')
998 - #end
999 - #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result)
1000 - #set ($postsLocation = $NULL)
1001 - #setVariable ("$categoriesLocation" $result)
1002 -#end
1003 -
1004 -#macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc)
1005 - #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())
1006 - #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace)
1007 - #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0)))
1008 - #else
1009 - ## Fallback to Blog.WebHome, the default blog
1010 - #set($macro.result = $xwiki.getDocument('Blog.WebHome'))
1011 - #end
1012 - #set ($blogDoc = $NULL)
1013 - #setVariable ("$blogDoc" $macro.result)
1014 -#end
1015 -
1016 -#macro(getBlogPostsLayout $blogDoc $postsLayout)
1017 - #getBlogProperty($blogDoc 'postsLayout' 'full' $res)
1018 - #set ($postsLayout = $NULL)
1019 - #setVariable ("$postsLayout" $res)
1020 -#end
1021 -
1022 -#macro(getBlogPostsLocation $blogSpace $postsLocation)
1023 - #getBlogDocument($blogSpace $blogDoc)
1024 - #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result)
1025 - #set ($postsLocation = $NULL)
1026 - #setVariable ("$postsLocation" $result)
1027 -#end
1028 -
1029 -#macro(getCategoryAllBlogPostsQuery $query)
1030 - #set ($query = $NULL)
1031 - #getAllBlogPostsQuery($baseQuery)
1032 - #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList'))
1033 - #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'")
1034 -#end
1035 -
1036 -#macro(isDefaultBlog $blogDoc $isDefault)
1037 - #set ($result = false)
1038 - #if ($blogDoc.space == 'Blog')
1039 - #set ($result = true)
1040 - #end
1041 - #setVariable("$isDefault" $result)
1042 -#end
1043 1043  {{/velocity}}
1044 1044  
1045 1045  \\