Toggle navigation
Log-in
myITGuide
Page Index
User Index
Application Index
Global
Wiki Index
Home
Blog
Links
Database
SQL Server
Cassandra
BigData
PostgreSQL
Redis
MariaDB
MongoDB
Tools
T-SQL
Powershell
Python
Scala
R
Jupyter
Java
Solution
Streaming
Spark
Storm
Search
Solr
ElasticSearch
Kafka
Puppet
Kibana
Docker
Kubernetes
OS
Windows
Linux
About
About Us
Email Us
Blog
Macros for the Blog Categories
Wiki source code of
Macros for the Blog Categories
Last modified by superadmin on 2016/12/20 10:05
Copy
Export
Print preview
View Source
Siblings
Content
Comments
Information
×
Export
Office Formats
Export as PDF
Other Formats
Export as HTML
Hide line numbers
1: {{include reference="Blog.BlogCode"/}} 2: 3: {{velocity output="false"}} 4: ## 5: ## 6: ## 7: #** 8: * Retrieves the list of blog entries from a given category. Entries belonging to subcategories 9: * are not returned. 10: * 11: * @param category The name of the category (XDocument full name, for example 'MyBlog.Fishing'). 12: * @param articles Return parameter, where the list of entries is placed. 13: * @param total Return parameter, where the total number of entries belonging to this category is 14: * placed. Useful for a paginated view. 15: *### 16: #macro(getEntriesForCategory $category $entries $totalEntries) 17: #set ($entries = $NULL) 18: #set ($totalEntries = $NULL) 19: #if ("$!{blogCategoryEntriesCache.containsKey($!{category})}" == 'true') 20: #setVariable ("$entries" $blogCategoryEntriesCache.get($!{category}).get(0)) 21: #setVariable ("$totalEntries" $blogCategoryEntriesCache.get($!{category}).get(1)) 22: #preparePagedViewParams ($totalEntries 10) 23: #else 24: #getCategoriesHierarchy ('' $tree) 25: #set ($subcategories = []) 26: #getSubcategories ($tree $category $subcategories) 27: #set ($categories = [${category}]) 28: #set ($discard = $categories.addAll(${subcategories})) 29: #set ($parameters = '?') 30: #foreach ($subcategory in $subcategories) 31: #set ($parameters = $parameters.concat(', ?')) 32: #end 33: #getBlogEntriesBaseQuery ($query) 34: #set ($query = ", DBStringListProperty as categories join categories.list as category${query} and obj.id = categories.id.id and categories.id.name='category' and category in (${parameters})") 35: #set ($totalResult = $services.query.hql($query).bindValues($categories).count()) 36: #preparePagedViewParams ($totalResult 10) 37: #set ($result = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).bindValues($categories).execute()) 38: #if ("$!{blogCategoryEntriesCache.containsKey($!{category})}" == '') 39: #set ($blogCategoryEntriesCache = {}) 40: #end 41: #set ($discard = $blogCategoryEntriesCache.put("$!{category}", [$result, $totalResult])) 42: #setVariable ("$entries" $result) 43: #setVariable ("$totalEntries" $totalResult) 44: #end 45: #end 46: #macro(getSubcategories $tree $category $subcategories) 47: #if(!$subcategories.contains($category)) 48: #foreach($subcategory in $tree.get($category)) 49: #set($discard = $subcategories.add($subcategory)) 50: #getSubcategories($tree $subcategory $subcategories) 51: #end 52: #end 53: #end 54: ## 55: ## 56: ## 57: #** 58: * Builds a tree of categories, respecting the parent<->subcategory relation. Each node holds the 59: * full name of the category's document. The root of the tree is 'Blog.Categories'. 60: * 61: * @param space The space where to search for categories. If this parameter is an emptry string or 62: * null, all the categories in the wiki are returned. 63: * @param tree Return parameter, HashMap<String, List<String>> structure holding the categories 64: * hierarchy, where the key is the name of a category, and the value contains the names of 65: * all its subcategories. To obtain the full hierarchy, start with the key 'Blog.Categories'. 66: *### 67: #macro(getCategoriesHierarchy $space $tree) 68: #set ($tree = $NULL) 69: #if ("$!{blogCategoriesHierarchyCache.containsKey($!{space})}" == 'true') 70: #setVariable ("$tree" $blogCategoriesHierarchyCache.get($!{space})) 71: #else 72: #set ($result = {}) 73: #set($query = ', BaseObject obj where ') 74: #if("$!space" != '') 75: #set($query = "${query}doc.space = '${space}' and ") 76: #end 77: #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' order by doc.name") 78: #foreach($category in $services.query.hql($query).execute()) 79: #set($categoryDoc = $xwiki.getDocument($category)) 80: #set($categoryParent = "$!categoryDoc.parent") 81: #if($categoryParent == '') 82: #set($categoryParent = $defaultCategoryParent) 83: #end 84: #if(!$result.containsKey($categoryParent)) 85: #set($discard = $result.put($categoryParent, [])) 86: #end 87: #set($discard = $result.get($categoryParent).add($category)) 88: #end 89: #if ("$!{blogCategoriesHierarchyCache.containsKey($!{space})}" == '') 90: #set ($blogCategoriesHierarchyCache = {}) 91: #end 92: #set ($discard = $blogCategoriesHierarchyCache.put("$!{space}", $result)) 93: #setVariable ("$tree" $result) 94: #end 95: #end 96: ## 97: ## 98: ## 99: #** 100: * Displays the category hierarchy held in the <tt>tree</tt> parameter. 101: * 102: * @param tree The category hierarchy, a HashMap<String, List<String>> structure, where the key 103: * is the name of a category, and the value contains the names of all its subcategories. 104: * @param displayMethod Selects how to display the category tree. Possible values are: 105: * <ul> 106: * <li><em>"simple"</em>: tree with links to the category pages.</li> 107: * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li> 108: * <li><em>"option"</em>: wraps each category name in an <option> element, to be used 109: * in a select box.</li> 110: * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights 111: * allow such actions.</li> 112: * </ul> 113: * For any other value, the default ("simple") is considered. 114: *### 115: #macro(displayCategoriesHierarchy $tree $displayMethod) 116: #set($processedCategories = []) 117: #displayCategoriesHierarchyRecursive($tree $defaultCategoryParent 1 $displayMethod) 118: #end 119: ## 120: ## 121: ## 122: #** 123: * Displays recursively the category hierarchy held in the <tt>tree</tt> parameter, starting at 124: * the node indicated by the <tt>root</tt> parameter, which is on the <tt>level</tt>th level in 125: * the tree. 126: * 127: * @param tree The category hierarchy HashMap<String, List<String>> structure, where the key 128: * is the name of a category, and the value contains the names of all its subcategories. 129: * @param root The full name of the document containing the category that is to be considered the 130: * root of the displayed subtree. 131: * @param level The current depth of the tree, used for proper indentation. 132: * @param displayMethod Selects how to display the category tree. Possible values are: 133: * <ul> 134: * <li><em>"simple"</em>: tree with links to the category pages.</li> 135: * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li> 136: * <li><em>"option"</em>: wraps each category name in an <option> element, to be used 137: * in a select box.</li> 138: * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights 139: * allow such actions.</li> 140: * </ul> 141: * For any other value, the default ("simple") is considered. 142: *### 143: #macro(displayCategoriesHierarchyRecursive $tree $root $level $displayMethod) 144: #if(!$processedCategories) 145: #set($processedCategories = []) 146: #end 147: #foreach($item in $tree.get($root)) 148: #if(!$processedCategories.contains($item)) 149: #set($discard = $processedCategories.add($item)) 150: #displayCategory($item $level $displayMethod) 151: #displayCategoriesHierarchyRecursive($tree $item $mathtool.add($level, 1) $displayMethod) 152: #end 153: #end 154: #if($displayMethod == "selectable") 155: <input type="hidden" name="${blogPostClassname}_$!{entryObj.number}_category" value="" /> 156: #end 157: #end 158: ## 159: ## 160: ## 161: #** 162: * Displays a category as part of a category hierarchy. 163: * 164: * @param name The full name of the document containing the category to be displayed. 165: * @param level The depth where this category is in the tree, used for proper indentation. 166: * @param displayMethod Selects how to display the category tree. Possible values are: 167: * <ul> 168: * <li><em>"simple"</em>: tree with links to the category pages.</li> 169: * <li><em>"selectable"</em>: each category name in the tree is preceded by a checkbox.</li> 170: * <li><em>"option"</em>: wraps each category name in an <option> element, to be used 171: * in a select box.</li> 172: * <li><em>"editable"</em>: displays links to delete and edit each category, if the rights 173: * allow such actions.</li> 174: * </ul> 175: * For any other value, the default ("simple") is considered. 176: *### 177: #macro(displayCategory $name $level $displayMethod) 178: #if("$!displayMethod" == "option") 179: #displayOptionCategory($name $level) 180: #elseif("$!displayMethod" == "selectable") 181: #displaySelectableCategory($name $level) 182: #elseif("$!displayMethod" == "editable") 183: #displayEditableCategory($name $level) 184: #else 185: #displaySimpleCategory($name $level) 186: #end 187: #end 188: ## 189: ## 190: ## 191: #** 192: * Displays a category as part of a category hierarchy, preceded by a checkbox that allows choosing 193: * this category for a blog entry. 194: * 195: * @param name The full name of the document containing the category to be displayed. 196: * @param level The depth where this category is in the tree, used for proper indentation. 197: *### 198: #macro(displaySelectableCategory $name $level) 199: #set($categoryDoc = $xwiki.getDocument($name)) 200: #set($addCategURL = $doc.getURL('view', $escapetool.url({ 201: 'xaction': 'showAddCategory', 202: 'parentCategory' : $name 203: }))) 204: #set($addEntryParams = false) 205: #if($isBlogPost) 206: #set($entry = $xwiki.getDocument($doc.fullName)) 207: #set($entryObj = $isBlogPost) 208: #set($addEntryParams = true) 209: #elseif("$!request.entry" != '' && "$!request.entryObjNb" != '') 210: #set($entry = $xwiki.getDocument($request.entry)) 211: #set($entryObj = $entry.getObject($blogPostClassname, $mathtool.toInteger($request.entryObjNb))) 212: #set($addEntryParams = true) 213: #end 214: #if($isBlogPost || $addEntryParams) 215: ## parentCategory must be the last param 216: #set($addCategURL = $doc.getURL('view', $escapetool.url({ 217: 'xaction': 'showAddCategory', 218: 'entry': $entry.fullName, 219: 'entryObjNb': $entryObj.number, 220: 'parentCategory': $name 221: }))) 222: #end 223: #foreach($i in [1..$level])*#end ## 224: <span class="blog-category-level"><span class="blog-category">## 225: <label id='blog_category_${services.rendering.escape(${escapetool.xml($name)}, $doc.syntax)}' title="#getCategoryDescription($categoryDoc)"><input name="${blogPostClassname}_$!{entryObj.number}_category" value="$services.rendering.escape(${escapetool.xml($name)}, $doc.syntax)" type="checkbox"#if($entryObj.getProperty('category').getValue().contains($name)) checked="checked" #end/> #getCategoryName($categoryDoc)</label>## 226: </span>## 227: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && ("$!{request.xaction}" != "showAddCategory" || "$!{request.parentCategory}" != $name)) 228: <span class="blog-category-tools">## 229: <a href="$escapetool.xml($addCategURL)" class="tool add-subcategory">#toolImage('add')</a>## 230: </span>## 231: #end 232: </span> 233: #end 234: ## 235: ## 236: ## 237: #** 238: * Displays a form for creating a new category. If a parentCategory parameter is present in the 239: * query string, the parent category is set accordingly. Otherwise, the form provides a selection 240: * control for choosing the parent category among existing categories. 241: *### 242: ## DO NOT CHANGE INDENTATION 243: #macro(addCategoryForm) #set($addCategURL = $doc.getURL()) #if("$!request.entry" != '') #set($addCategURL = "${addCategURL}?entry=$escapetool.url($request.entry)&entryObjNb=$escapetool.url($!request.entryObjNb)")#end<form action="${addCategURL}" method="post" class="category-add-form"><div class='create-category'> <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> <input type="hidden" name="xaction" value="create"/> <label>$services.localization.render('xe.blog.categories.new')<br/> <input type="text" name="newCategoryName" class="category-name-input" /></label><br/>#if("$!{request.parentCategory}" == "")<label>#* $services.localization.render('xe.blog.categories.parent')*# Subcategory of:<br/> <select name="newCategoryParent" id="blog_category_selectBox" class="category-add-input"> <option value="${defaultCategoryParent}" selected="selected">None</option> $!processedCategories.clear() #displayCategoriesHierarchy($tree 'option') </select> <br/></label>#else<input type="hidden" name="newCategoryParent" value="${escapetool.xml($request.parentCategory)}"/>#end<span class="buttonwrapper"><input class="button" type="submit" value="Add" /></span> <a class="btn btn-default" href="$doc.getURL()">Cancel</a> </div></form> #end 244: ## 245: ## 246: ## 247: #** 248: * Displays a form for renaming a category. 249: *### 250: ## DO NOT CHANGE INDENTATION 251: #macro(renameCategoryForm)## 252: <form action="$doc.getURL()" method="post" class="category-rename-form"><div class='rename-category'>## 253: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 254: <input type="hidden" name="xaction" value="rename"/>## 255: <input type="hidden" name="category" value="${escapetool.xml($request.category)}"/>## 256: <label>$services.localization.render('xe.blog.categories.newName')<br/> <input type="text" name="newCategoryName" class="category-name-input" /></label><br/>## 257: <span class="buttonwrapper"><input class="button" type="submit" value="Rename" /></span> ## 258: <a class="btn btn-default" href="$doc.getURL()">Cancel</a>## 259: </div></form>## 260: #end 261: ## 262: ## 263: ## 264: #** 265: * Displays a category as part of a category hierarchy, followed by links for editing and deleting 266: * this category, if the current user has the rights to perform these actions. 267: * 268: * @param name The full name of the document containing the category to be displayed. 269: * @param level The depth where this category is in the tree, used for proper indentation. 270: *### 271: ## DO NOT CHANGE INDENTATION 272: #macro(displayEditableCategory $name $level) 273: #getEntriesForCategory($name $discard $totalEntries) 274: #set($nameUrl = $escapetool.url($name)) 275: #foreach($i in [1..$level])*#end ## 276: <span class="blog-category-level"><span class="blog-category">## 277: <a href="$services.rendering.escape($xwiki.getURL('Blog.CategoryRss', 'view', "xpage=plain&category=$nameUrl"), $doc.syntax)" title="RSS">#toolImage('rss')</a> ## 278: <span class="wikilink"><a href="$services.rendering.escape($xwiki.getURL($name), $doc.syntax)">#getCategoryName($xwiki.getDocument($name)) <span class="itemCount">($totalEntries)</span></a></span></span>## 279: <span class="blog-category-tools">## 280: #if($xwiki.hasAccessLevel('delete', $xcontext.user, $name) && ("$!{request.xaction}" != 'showRenameCategory' || "$!{request.category}" != $name))<a href="$services.rendering.escape($xwiki.getURL('Blog.ManageCategories', 'view', "xaction=showRenameCategory&category=$nameUrl"), $doc.syntax)" class="tool rename">#toolImage('pencil')</a>#end## 281: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && ("$!{request.xaction}" != "showAddCategory" || "$!{request.parentCategory}" != $name))<a href="$services.rendering.escape($xwiki.getURL('Blog.ManageCategories', 'view', "xaction=showAddCategory&parentCategory=$nameUrl"), $doc.syntax)" class="tool add-subcategory">#toolImage('add')</a>#end## 282: #if($xwiki.hasAccessLevel('delete', $xcontext.user, $name)) <a href="$services.rendering.escape($xwiki.getURL('Blog.ManageCategories', 'view', "xaction=delete&category=$nameUrl&form_token=$!{services.csrf.getToken()}"), $doc.syntax)" class="tool delete">#toolImage('cross')</a>#end## 283: </span>## 284: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && "$!{request.xaction}" == "showRenameCategory" && "$!{request.category}" == $name) #renameCategoryForm() #end## 285: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName) && "$!{request.xaction}" == "showAddCategory" && "$!{request.parentCategory}" == $name) #addCategoryForm() #end## 286: </span> 287: #end 288: ## 289: ## 290: ## 291: #** 292: * Displays a category as part of a category hierarchy, wrapped in an <option> element, to 293: * be used in a select box. 294: * 295: * @param name The full name of the document containing the category to be displayed. 296: * @param level The depth where this category is in the tree, used for proper indentation. 297: *### 298: #macro(displayOptionCategory $name $level) 299: <option id="blog_category_${services.rendering.escape(${escapetool.xml($name)}, $doc.syntax)}_option" value="$services.rendering.escape(${escapetool.xml($name)}, $doc.syntax)">#if($level > 1)#foreach($i in [2..$level]) #end#end#getCategoryName($xwiki.getDocument($name))</option> 300: #end 301: ## 302: ## 303: ## 304: #** 305: * Displays a category as part of a category hierarchy, wrapped in a link. 306: * 307: * @param name The full name of the document containing the category to be displayed. 308: * @param level The depth where this category is in the tree, used for proper indentation. 309: *### 310: #macro(displaySimpleCategory $name $level) 311: #getEntriesForCategory($name $discard $totalEntries) 312: #set($nameUrl = $escapetool.url($name)) 313: #getCallingDocument($callingDocument) 314: #foreach($i in [1..$level])*#end (% class="blog-category-level" %)((( [[#toolImage('rss')>>Blog.CategoryRss||queryString="xpage=plain&category=$nameUrl" title="RSS"]] <span class="wikilink"><a href="$services.rendering.escape($xwiki.getURL($name), $callingDocument.syntax)">#getCategoryName($xwiki.getDocument($name)) <span class="itemCount">($totalEntries)</span></a></span>))) 315: #end 316: ## 317: ## 318: ## 319: #** 320: * Prints the name of a category, indicated by its document. 321: * The result is XML-escaped and Wiki syntax escaped. 322: * 323: * @param categoryDoc The document containing the category to be displayed. 324: *### 325: #macro(getCategoryName $categoryDoc) 326: ## Don't indent! 327: #set($result = "$!categoryDoc.getObject(${blogCategoryClassname}).getProperty('name').value.trim()")## 328: #if($result == '') 329: #set($result = $categoryDoc.name) 330: #end 331: ## Escape wiki syntax, if any. 332: #getCallingDocument($callingDocument) 333: #set ($result = "$services.rendering.escape($result, $callingDocument.syntax)") 334: ## Escape HTML, if any. 335: $escapetool.xml($result)## 336: #end 337: ## 338: ## 339: ## 340: #** 341: * Return the calling document to make the various API work when called from the context of a Panel and from a wiki page 342: *### 343: #macro(getCallingDocument $callingDocument) 344: #if ("$!paneldoc" != '') 345: #setVariable ("$callingDocument" $paneldoc) 346: #else 347: #setVariable ("$callingDocument" $doc) 348: #end 349: #end 350: ## 351: ## 352: ## 353: #** 354: * Prints the description of a category, indicated by its document. 355: * The result is XML-escaped 356: * 357: * @param categoryDoc The document containing the category to be displayed. 358: *### 359: #macro(getCategoryDescription $categoryDoc) 360: ## Don't indent! 361: $escapetool.xml($!categoryDoc.getObject(${blogCategoryClassname}).getProperty('description').value.trim())## 362: #end 363: ## 364: ## 365: ## 366: #** 367: * Generates a form for creating a new category. The form allows to enter the name of the new 368: * category, and select a parent category from the existing ones. 369: * 370: * @param tree The category hierarchy, a HashMap<String, List<String>> structure, where the key 371: * is the name of a category, and the value contains the names of all its subcategories. 372: * @todo When javascript is disabled, a link to "Manage categories" should be displayed instead. 373: * This "form" should be created from javascript. 374: *### 375: #macro(showCreateCategoryBoxWithForm $tree) 376: <form action="$doc.getURL()" method="post"> 377: #showCreateCategoryBox($tree) 378: </form> 379: #end 380: #** 381: * Generates a box for creating a new category. This allows to enter the name of the new 382: * category, and select a parent category from the existing ones. Note that this does not create 383: * a HTML form element, but requires one to be defined already as its ancestor. 384: * 385: * @param tree The category hierarchy HashMap<String, List<String>> structure, where the key 386: * is the name of a category, and the value contains the names of all its subcategories. 387: * @todo When javascript is disabled, a link to "Manage categories" should be displayed instead. 388: * This "form" should be created from javascript. 389: *### 390: #macro(showCreateCategoryBox $tree) 391: <div class='create-category'> 392: <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> 393: <input type="hidden" name="xaction" value="create"/> 394: <label>$services.localization.render('xe.blog.categories.new') <input type="text" name="newCategoryName" /></label> 395: <label>$services.localization.render('xe.blog.categories.parent') 396: <select name="newCategoryParent" id="blog_category_selectBox"> 397: <option value="${defaultCategoryParent}" selected="selected">None</option> 398: $!processedCategories.clear()## 399: #displayCategoriesHierarchy($tree 'option') 400: </select> 401: </label> 402: <span class="buttonwrapper"><input class="button" type="button" value="Add" id="blog_AddCategoryButton" /></span> 403: </div> 404: #end 405: ## 406: ## 407: ## 408: #macro(displayCategoryManagementTree $space $displayType) 409: <div class="blog-categories-list"> 410: #getCategoriesHierarchy("$!{space}" $tree) 411: #displayCategoriesHierarchy($tree $displayType) 412: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $doc.fullName)) 413: #set($addCategURL = $doc.getURL('view', $escapetool.url({ 414: 'xaction' : 'showAddCategory', 415: 'parentCategory' : '' 416: }))) 417: #if($isBlogPost || ("$!request.entry" != '' && "$!request.entryObjNb" != '')) 418: #set($entryParam = $!doc.fullName) 419: #set($entryObjNbParam = $!entryObj.number) 420: #if(!$isBlogPost) 421: #set($entryParam = $!request.entry) 422: #set($entryObjNbParam = $!request.entryObjNb) 423: #end 424: #set($addCategURL = $doc.getURL('view', $escapetool.url({ 425: 'xaction' : 'showAddCategory', 426: 'parentCategory' : '', 427: 'entry' : $entryParam, 428: 'entryObjNb' : $entryObjNbParam 429: }))) 430: #end 431: * <span class="blog-add-category-label">$services.icon.renderHTML('add') <a href="$escapetool.xml($addCategURL)">$services.localization.render('xe.blog.categories.addcategory')</a></span> 432: #if("$!{request.xaction}" == "showAddCategory" && "$!{request.parentCategory}" == "") #addCategoryForm() #end 433: #end 434: 435: 436: </div> 437: #end 438: ## 439: ## 440: ## 441: #** 442: * Deletes a category, moving all the subcategories to its parent and removing this category from 443: * all existing blog entries. 444: * 445: * @param category The full name of the document containing the category to be deleted. 446: *### 447: #macro(deleteCategory $category) 448: #set($categoryDoc = $xwiki.getDocument($category)) 449: #set($categoryParent = "$!categoryDoc.parent") 450: #if($categoryParent == '') 451: #set($categoryParent = "{$defaultCategoryParent}") 452: #end 453: #set($parameterValues = ["$!{category}"]) 454: #set($query = ', BaseObject obj where ') 455: #if($space != '') 456: #set($query = "${query}doc.space = '${space}' and ") 457: #end 458: #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' and doc.fullName <> 'Blog.CategoryTemplate' and doc.parent = ? order by doc.name") 459: 460: #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute()) 461: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) 462: #set($subcategoryDoc = $xwiki.getDocument($item)) 463: $subcategoryDoc.setParent($categoryParent) 464: $subcategoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedParent'), true) 465: #end 466: #end 467: #set($query = ', BaseObject obj, DBStringListProperty categories join categories.list as category where ') 468: #if($space != '') 469: #set($query = "${query}doc.space = '${space}' and ") 470: #end 471: #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogPostClassname}' and doc.fullName <> 'Blog.BlogPostTemplate' and categories.id.id = obj.id and categories.id.name = 'category' and category = ? order by doc.name") 472: #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute()) 473: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) 474: #set($blogEntryDoc = $xwiki.getDocument($item)) 475: #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.remove($category)) 476: $blogEntryDoc.save($services.localization.render('xe.blog.manageCategories.comment.removedDeletedCategory'), true) 477: #end 478: #end 479: $categoryDoc.delete() 480: #end 481: ## 482: ## 483: ## 484: #** 485: * Renames a category, updating all the subcategories and all existing blog entries. 486: * 487: * @param category The full name of the document containing the category to be renamed. 488: * @param newCategoryName The new name of the category. 489: *### 490: #macro(renameCategory $category $newCategoryName) 491: #set($categoryDoc = $xwiki.getDocument($category)) 492: #set($newCategoryDoc = $xwiki.getDocument($newCategoryName)) 493: #set($parameterValues = ["$!{category}"]) 494: #set($query = ', BaseObject obj where ') 495: #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogCategoryClassname}' and doc.fullName <> 'Blog.CategoryTemplate' and doc.parent = ? order by doc.name") 496: #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute()) 497: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) 498: #set($subcategoryDoc = $xwiki.getDocument($item)) 499: $subcategoryDoc.setParent($newCategoryDoc.fullName) 500: $subcategoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedParent'), true) 501: #end 502: #end 503: #set($query = ', BaseObject obj, DBStringListProperty categories join categories.list as category where ') 504: #set($query = "${query}obj.name = doc.fullName and obj.className = '${blogPostClassname}' and doc.fullName <> 'Blog.BlogPostTemplate' and categories.id.id = obj.id and categories.id.name = 'category' and category = ? order by doc.name") 505: #foreach($item in $services.query.hql($query).bindValues($parameterValues).execute()) 506: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $item) && $!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) 507: #set($blogEntryDoc = $xwiki.getDocument($item)) 508: #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.remove($category)) 509: #set($discard = $blogEntryDoc.getObject(${blogPostClassname}).getProperty('category').value.add($newCategoryDoc.fullName)) 510: $blogEntryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedRenamedCategory'), true) 511: #end 512: #end 513: #if ($!{services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) 514: $categoryDoc.getObject('Blog.CategoryClass').set('name', $newCategoryName) 515: $categoryDoc.save($services.localization.render('xe.blog.manageCategories.comment.updatedCategory'), true) 516: $categoryDoc.rename($newCategoryName) 517: #end 518: #end 519: {{/velocity}}
Recent Blog Posts
My Technology Roadmap
Blog Categories
All
News
(1)
Other
(0)
Personal
(0)
Blog Archive
2017
(1)