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