| ... |
... |
@@ -313,7 +313,13 @@ |
| 313 |
313 |
* @param query The basic query for selecting blog entries. |
| 314 |
314 |
*### |
| 315 |
315 |
#macro(getBlogEntriesBaseQuery $query) |
| 316 |
|
- #getAllBlogPostsQuery($query) |
|
316 |
+ #set ($query = ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate |
|
317 |
+ where doc.fullName <> 'Blog.BlogPostTemplate' and |
|
318 |
+ obj.name = doc.fullName and obj.className = '${blogPostClassname}' and |
|
319 |
+ publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and |
|
320 |
+ isPublished.id.id = obj.id and isPublished.id.name = 'published' and |
|
321 |
+ hidden.id.id = obj.id and hidden.id.name = 'hidden' and |
|
322 |
+ (doc.creator = '$context.user' or (isPublished.value = 1 and hidden.value = 0))") |
| 317 |
317 |
#end |
| 318 |
318 |
## |
| 319 |
319 |
## |
| ... |
... |
@@ -840,191 +840,3 @@ |
| 840 |
840 |
#set($propertyValue = $defaultValue) |
| 841 |
841 |
#end |
| 842 |
842 |
#end |
| 843 |
|
-## Compatibility helpers from the installed Blog 9.15.15 package. |
| 844 |
|
-#macro(bindQueryParameters $queryObj $queryParams) |
| 845 |
|
- #set ($output = $queryObj) |
| 846 |
|
- #foreach( $key in $queryParams.keySet() ) |
| 847 |
|
- #set($output = $queryObj.bindValue($key, $queryParams.get($key))) |
| 848 |
|
- #end |
| 849 |
|
- #setVariable("$queryObj" $output) |
| 850 |
|
-#end |
| 851 |
|
- |
| 852 |
|
-#macro(blog__actionResponseError $status $text $parameters) |
| 853 |
|
- $response.setStatus($status) |
| 854 |
|
- #if($request.ajax) |
| 855 |
|
- $services.localization.render($text, $!parameters) |
| 856 |
|
- #else |
| 857 |
|
- {{error}}$services.localization.render($text, $!parameters){{/error}} |
| 858 |
|
- #end |
| 859 |
|
-#end |
| 860 |
|
- |
| 861 |
|
-#macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit) |
| 862 |
|
- #if ($layout == 'link') |
| 863 |
|
- #set ($macro.paginated = 'no') |
| 864 |
|
- #end |
| 865 |
|
- #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) |
| 866 |
|
- ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%' |
| 867 |
|
- #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout) |
| 868 |
|
- #if ("$!layout" == '') |
| 869 |
|
- #set ($layout = $postsLayout) |
| 870 |
|
- #end |
| 871 |
|
- #if ($postsVisiblity == 'recent') |
| 872 |
|
- {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 873 |
|
- #elseif($postsVisiblity == 'unpublished') |
| 874 |
|
- {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 875 |
|
- #end |
| 876 |
|
- #elseif($targetDoc.getObject($blogCategoryClassname)) |
| 877 |
|
- ## Display all posts that are in a category aCategorySpace.aCategory |
| 878 |
|
- #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) |
| 879 |
|
- #getBlogPostsLayout($blogDoc $postsLayout) |
| 880 |
|
- #if ("$!layout" == '') |
| 881 |
|
- #set ($layout = $postsLayout) |
| 882 |
|
- #end |
| 883 |
|
- #if ($postsVisiblity == 'recent') |
| 884 |
|
- {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 885 |
|
- #elseif($postsVisiblity == 'unpublished') |
| 886 |
|
- {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 887 |
|
- #end |
| 888 |
|
- #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') |
| 889 |
|
- ## Display all posts that are in a category aCategorySpace.% |
| 890 |
|
- #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) |
| 891 |
|
- #getBlogPostsLayout($blogDoc $postsLayout) |
| 892 |
|
- #if ("$!layout" == '') |
| 893 |
|
- #set ($layout = $postsLayout) |
| 894 |
|
- #end |
| 895 |
|
- #if ($postsVisiblity == 'recent') |
| 896 |
|
- {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 897 |
|
- #elseif($postsVisiblity == 'unpublished') |
| 898 |
|
- {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 899 |
|
- #end |
| 900 |
|
- #else |
| 901 |
|
- ## Display all posts in blog space aBlog |
| 902 |
|
- #getBlogDocument($targetDoc.space $blogDoc) |
| 903 |
|
- #getBlogPostsLayout($blogDoc $postsLayout) |
| 904 |
|
- #if ("$!layout" == '') |
| 905 |
|
- #set ($layout = $postsLayout) |
| 906 |
|
- #end |
| 907 |
|
- #if ($postsVisiblity == 'recent') |
| 908 |
|
- {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 909 |
|
- #elseif($postsVisiblity == 'unpublished') |
| 910 |
|
- {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} |
| 911 |
|
- #end |
| 912 |
|
- #end |
| 913 |
|
-#end |
| 914 |
|
- |
| 915 |
|
-#macro(displayEntryBlogLocation $entryDoc $entryObj) |
| 916 |
|
- #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ## |
| 917 |
|
- #if("$!blogPostsLocation" != "") ## |
| 918 |
|
- #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ## |
| 919 |
|
- #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ## |
| 920 |
|
- #if($doc.documentReference != $blogDocRef) ## |
| 921 |
|
- #set($blogDoc = $xwiki.getDocument($blogDocRef)) ## |
| 922 |
|
- #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ## |
| 923 |
|
- #if($blogObj) (% class="blogrefpath" %)((( ## |
| 924 |
|
- $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ## |
| 925 |
|
- )))(%%)## |
| 926 |
|
- #end |
| 927 |
|
- #end |
| 928 |
|
- #end |
| 929 |
|
-#end |
| 930 |
|
- |
| 931 |
|
-#macro(getAllBlogPostsQuery $query) |
| 932 |
|
- #set ($query = $NULL) |
| 933 |
|
- #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished, |
| 934 |
|
- IntegerProperty hidden, DateProperty publishDate |
| 935 |
|
- where doc.fullName <> '$blogPostTemplate' and |
| 936 |
|
- obj.name=doc.fullName and obj.className='$blogPostClassname' and |
| 937 |
|
- isPublished.id.id = obj.id and isPublished.id.name = 'published' and |
| 938 |
|
- hidden.id.id = obj.id and hidden.id.name='hidden' and |
| 939 |
|
- publishDate.id.id = obj.id and publishDate.id.name='publishDate' and |
| 940 |
|
- (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))") |
| 941 |
|
-#end |
| 942 |
|
- |
| 943 |
|
-#macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams) |
| 944 |
|
- #set ($query = $NULL) |
| 945 |
|
- #set ($queryParams = $NULL) |
| 946 |
|
- #getCategoryAllBlogPostsQuery($resultQuery) |
| 947 |
|
- #set ($resultQueryParams = {}) |
| 948 |
|
- #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%')) |
| 949 |
|
- #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) |
| 950 |
|
- ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%' |
| 951 |
|
- #set ($discard = $resultQueryParams.put('space', $targetDoc.space)) |
| 952 |
|
- #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) |
| 953 |
|
- #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')") |
| 954 |
|
- #elseif($targetDoc.getObject($blogCategoryClassname)) |
| 955 |
|
- ## Get all posts that are in a category aCategorySpace.aCategory |
| 956 |
|
- #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName)) |
| 957 |
|
- #set($resultQuery = "${resultQuery} and (catList=:catList)") |
| 958 |
|
- #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') |
| 959 |
|
- ## Get all posts that are in a category aCategorySpace.% |
| 960 |
|
- #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) |
| 961 |
|
- ## Exclude incategorized posts |
| 962 |
|
- #set ($excludedCategory = "${targetDoc.space}.WebHome") |
| 963 |
|
- #if ($targetDoc.space == $defaultBlogSpace) |
| 964 |
|
- #set ($excludedCategory = "Blog.Categories.WebHome") |
| 965 |
|
- #end |
| 966 |
|
- #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory)) |
| 967 |
|
- #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')") |
| 968 |
|
- #else |
| 969 |
|
- ## Get all posts in blog space aBlog |
| 970 |
|
- #getAllBlogPostsQuery($resultQuery) |
| 971 |
|
- #getBlogPostsLocation($targetDoc.space $postsLocation) |
| 972 |
|
- #set ($discard = $resultQueryParams.put('space', $postsLocation)) |
| 973 |
|
- #set($resultQuery = "${resultQuery} and doc.space = :space") |
| 974 |
|
- #end |
| 975 |
|
- #setVariable("$query" $resultQuery) |
| 976 |
|
- #setVariable("$queryParams" $resultQueryParams) |
| 977 |
|
-#end |
| 978 |
|
- |
| 979 |
|
-#macro(getBlogCategoriesLocation $blogSpace $categoriesLocation) |
| 980 |
|
- #getBlogDocument($blogSpace $blogDoc) |
| 981 |
|
- ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility. |
| 982 |
|
- #set ($defaultBlogCategoryLocation = 'Blog.Categories') |
| 983 |
|
- #if ($services.blog.hasLegacyCategoryAssignments()) |
| 984 |
|
- #set ($defaultBlogCategoryLocation = 'Blog') |
| 985 |
|
- #end |
| 986 |
|
- #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result) |
| 987 |
|
- #set ($postsLocation = $NULL) |
| 988 |
|
- #setVariable ("$categoriesLocation" $result) |
| 989 |
|
-#end |
| 990 |
|
- |
| 991 |
|
-#macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc) |
| 992 |
|
- #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()) |
| 993 |
|
- #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace) |
| 994 |
|
- #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0))) |
| 995 |
|
- #else |
| 996 |
|
- ## Fallback to Blog.WebHome, the default blog |
| 997 |
|
- #set($macro.result = $xwiki.getDocument('Blog.WebHome')) |
| 998 |
|
- #end |
| 999 |
|
- #set ($blogDoc = $NULL) |
| 1000 |
|
- #setVariable ("$blogDoc" $macro.result) |
| 1001 |
|
-#end |
| 1002 |
|
- |
| 1003 |
|
-#macro(getBlogPostsLayout $blogDoc $postsLayout) |
| 1004 |
|
- #getBlogProperty($blogDoc 'postsLayout' 'full' $res) |
| 1005 |
|
- #set ($postsLayout = $NULL) |
| 1006 |
|
- #setVariable ("$postsLayout" $res) |
| 1007 |
|
-#end |
| 1008 |
|
- |
| 1009 |
|
-#macro(getBlogPostsLocation $blogSpace $postsLocation) |
| 1010 |
|
- #getBlogDocument($blogSpace $blogDoc) |
| 1011 |
|
- #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result) |
| 1012 |
|
- #set ($postsLocation = $NULL) |
| 1013 |
|
- #setVariable ("$postsLocation" $result) |
| 1014 |
|
-#end |
| 1015 |
|
- |
| 1016 |
|
-#macro(getCategoryAllBlogPostsQuery $query) |
| 1017 |
|
- #set ($query = $NULL) |
| 1018 |
|
- #getAllBlogPostsQuery($baseQuery) |
| 1019 |
|
- #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList')) |
| 1020 |
|
- #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'") |
| 1021 |
|
-#end |
| 1022 |
|
- |
| 1023 |
|
-#macro(isDefaultBlog $blogDoc $isDefault) |
| 1024 |
|
- #set ($result = false) |
| 1025 |
|
- #if ($blogDoc.space == 'Blog') |
| 1026 |
|
- #set ($result = true) |
| 1027 |
|
- #end |
| 1028 |
|
- #setVariable("$isDefault" $result) |
| 1029 |
|
-#end |
| 1030 |
|
- |