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 application
Wiki source code of
Macros for the Blog application
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.BlogParameters"/}} 2: 3: {{velocity output="false"}} 4: ## 5: ## 6: ## 7: ## Import the blog skin and javascripts. 8: $!xwiki.ssx.use($blogStyleDocumentName)## 9: $!xwiki.jsx.use($blogScriptsDocumentName)## 10: ## 11: ## 12: ## 13: #** 14: * Prints a blog. This is the main macro used in the BlogSheet. 15: * 16: * @param blogDoc the XDocument holding the blog definition object. 17: *### 18: #macro(printBlog $blogDoc) 19: {{include reference='Blog.CreatePost'/}} 20: #getBlogEntries($blogDoc $entries) 21: #displayBlog($entries 'index' true true) 22: #displayNavigationLinks($blogDoc) 23: #end 24: ## 25: ## 26: ## 27: #** 28: * Shows blog information. In view mode, the description is printed. In edit mode, allows changing blog settings: title, 29: * description, blog type (global or in-space), index display type (fixed size pagination, weekly index, monthly index, 30: * all entries). 31: * 32: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 33: *### 34: #macro(showBlogInfo $blogDoc) 35: #if($blogDoc.getObject($blogClassname)) 36: ## Keep testing for inline action for backward compatibility with older blogs. 37: #if($xcontext.action == 'edit' || $xcontext.action == 'inline') 38: #macro(displayProperty $blogDoc $propname) 39: ; #displayPropName($xwiki.getClass($blogClassname).get($propname)): 40: : $blogDoc.display($propname) 41: #end 42: #displayProperty($blogDoc 'title') 43: #displayProperty($blogDoc 'description') 44: #displayProperty($blogDoc 'blogType') 45: #displayProperty($blogDoc 'displayType') 46: #displayProperty($blogDoc 'itemsPerPage') 47: #else 48: $blogDoc.display('description') 49: #end 50: #elseif($doc.fullName == $blogSheet) 51: = $services.localization.render('xe.blog.code.blogsheet') = 52: {{translation key='xe.blog.code.sheetexplanation'/}} 53: #else 54: {{warning}}{{translation key='xe.blog.code.notblog'/}}{{/warning}} 55: #end 56: #end 57: ## 58: ## 59: ## 60: #** 61: * Retrieve the blog document, which usually is either <tt><Space>.WebHome</tt> for whole-spaces blogs, or 62: * <tt><Space>.Blog</tt> for in-space blogs. If none of these documents contains a blog object, then the first 63: * (alphabetically) document in the target space that contains one is returned. Finally, if no document in the current 64: * space contains a blog object, then <tt>Blog.WebHome</tt> is returned as the default blog. 65: * 66: * @param space A <tt>String</tt>, the name of the space where to search. 67: * @param blogDoc The resulting XDocument. 68: *### 69: #macro(getBlogDocument $space $blogDoc) 70: ## First, try the Space.WebHome, for a whole-space blog 71: #set($result = $xwiki.getDocument("${space}.WebHome")) 72: #if(!$result.getObject($blogClassname)) 73: ## Second, try the Space.Blog document 74: #set($result = $xwiki.getDocument("${space}.Blog")) 75: #if(!$result.getObject($blogClassname)) 76: ## Third, try searching for a blog document in the current space 77: #set($blogDocs = $services.query.hql(", BaseObject obj where doc.space = ? and obj.name = doc.fullName and obj.className = '$blogClassname' order by doc.name").setLimit(1).setOffset(0).bindValues([${space}]).execute()) 78: #if($blogDocs.size() > 0) 79: #set($result = $xwiki.getDocument($blogDocs.get(0))) 80: #else 81: ## Last, fallback to Blog.WebHome, the default blog 82: #set($result = $xwiki.getDocument('Blog.WebHome')) 83: #end 84: #end 85: #end 86: #set ($blogDoc = $NULL) 87: #setVariable ("$blogDoc" $result) 88: #end 89: ## 90: ## 91: ## 92: #** 93: * Retrieve the blog title. 94: * 95: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass<tt> object with the <tt>title</tt> property set. 96: * @param title The resulting title. 97: *### 98: #macro(getBlogTitle $blogDoc $title) 99: ## Titles can contain velocity code (most commonly translations), so we should evaluate them. 100: #set ($title = $NULL) 101: #setVariable ("$title" $!blogDoc.displayTitle) 102: #end 103: ## 104: ## 105: ## 106: #** 107: * Retrieve the blog description. 108: * 109: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>description</tt> 110: * property set. 111: * @param description The resulting description. 112: *### 113: #macro(getBlogDescription $blogDoc $description) 114: #getBlogProperty($blogDoc 'description' '' $result) 115: #set ($description = $NULL) 116: #setVariable ("$description" $result) 117: #end 118: ## 119: ## 120: ## 121: #** 122: * Retrieves a list of entries to be displayed. The entries are either part of the blog's space, or have the blog 123: * document set as a parent. The number and range of entries returned (from all those belonging to this blog) depends on 124: * the blog display type: paginated (fixed number of entries), weekly (all entries in a week), monthly (all entries in a 125: * month), or all. 126: * 127: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 128: * @param entries The resulting list of entries to display, a list of XDocument names. 129: *### 130: #macro(getBlogEntries $blogDoc $entries) 131: #if (!$entries) 132: #setVariable ("$entries" []) 133: #end 134: #getBlogEntriesBaseQuery($query) 135: #isBlogGlobal($blogDoc $isGlobal) 136: #if(!$isGlobal) 137: #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')") 138: #end 139: #getBlogDisplayType($blogDoc $displayType) 140: #if($displayType == 'weekly') 141: #getWeeklyBlogEntries($blogDoc $query $entries) 142: #elseif($displayType == 'monthly') 143: #getMonthlyBlogEntries($blogDoc $query $entries) 144: #elseif($displayType == 'all') 145: #getAllBlogEntries($blogDoc $query $entries) 146: #else 147: #getPagedBlogEntries($blogDoc $query $entries) 148: #end 149: #end 150: ## 151: ## 152: ## 153: #** 154: * Retrieves a list of entries to be displayed. The entries are taken from a "page" of the blog, a sequence of documents 155: * defined by the request parameters <tt>ipp</tt> (items per page) and <tt>page</tt> (the current page). Initially the 156: * first page is displayed, with the number of entries defined in the blog object in the <tt>itemsPerPage</tt> property 157: * (10 if not defined). 158: * 159: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 160: * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be 161: * refined to restrict to a given space, or to a given search criteria, etc. 162: * @param entries The resulting list of entries to display, a list of XDocument names. 163: *### 164: #macro(getPagedBlogEntries $blogDoc $query $entries) 165: #if (!$entries) 166: #setVariable ("$entries" []) 167: #end 168: #set($totalEntries = $services.query.hql($query).count()) 169: #getBlogProperty($blogDoc 'itemsPerPage' '10' $defaultItemsPerPage) 170: #set($defaultItemsPerPage = $mathtool.toInteger($defaultItemsPerPage)) 171: ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. 172: #preparePagedViewParams($totalEntries $defaultItemsPerPage) 173: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())) 174: #end 175: ## 176: ## 177: ## 178: #** 179: * Retrieves a list of entries to be displayed. The entries are taken from a week of the blog. The target week is 180: * defined by the request parameters <tt>week</tt> (the week number in the year, from 1 to 52) and <tt>year</tt> (4 181: * digit year). Initially the current week is displayed. 182: * 183: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 184: * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be 185: * refined to restrict to a given space, or to a given search criteria, etc. 186: * @param entries The resulting list of entries to display, a list of XDocument names. 187: *### 188: #macro(getWeeklyBlogEntries $blogDoc $query $entries) 189: #if (!$entries) 190: #setVariable ("$entries" []) 191: #end 192: #getRequestedWeek($weekDate) 193: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd')) 194: #set($minDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundFloor())) 195: #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling())) 196: #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") 197: #set($totalEntries = $services.query.hql($query).count()) 198: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").execute())) 199: #end 200: ## 201: ## 202: ## 203: #** 204: * Retrieves a list of entries to be displayed. The entries are taken from a month of the blog. The target month is 205: * defined by the request parameters <tt>month</tt> (the month number, from 1 to 12) and <tt>year</tt> (4 206: * digit year). Initially the current month is displayed. 207: * 208: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 209: * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be 210: * refined to restrict to a given space, or to a given search criteria, etc. 211: * @param entries The resulting list of entries to display, a list of XDocument names. 212: *### 213: #macro(getMonthlyBlogEntries $blogDoc $query $entries) 214: #if (!$entries) 215: #setVariable ("$entries" []) 216: #end 217: #getRequestedMonth($monthDate) 218: #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd')) 219: #set($minDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundFloor())) 220: #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling())) 221: #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") 222: #set($totalEntries = $services.query.hql($query).count()) 223: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").execute())) 224: #end 225: ## 226: ## 227: ## 228: #** 229: * Retrieves a list of entries to be displayed. All entries belonging to the current blog are returned. 230: * 231: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 232: * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be 233: * refined to restrict to a given space, or to a given search criteria, etc. 234: * @param entries The resulting list of entries to display, a list of XDocument names. 235: *### 236: #macro(getAllBlogEntries $blogDoc $query $entries) 237: #if (!$entries) 238: #setVariable ("$entries" []) 239: #end 240: #set($totalEntries = $services.query.hql($query).count()) 241: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").execute())) 242: #end 243: ## 244: ## 245: ## 246: #** 247: * Retrieves a list of entries to be displayed. Only (and all) unpublished entries are returned. 248: * 249: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 250: * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be 251: * refined to restrict to a given space, or to a given search criteria, etc. 252: * @param entries The resulting list of entries to display, a list of XDocument names. 253: *### 254: #macro(getUnpublishedBlogEntries $blogDoc $query $entries) 255: #if (!$entries) 256: #setVariable ("$entries" []) 257: #end 258: #set($query = "${query} and isPublished.value = 0") 259: #set($totalEntries = $services.query.hql($query).count()) 260: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").execute())) 261: #end 262: ## 263: ## 264: ## 265: #** 266: * Retrieves a list of entries to be displayed. The entries are taken from all the wiki, and not from a specific blog. 267: * 268: * @param entries The resulting list of entries to display, a list of XDocument names. 269: *### 270: #macro(getGlobalBlogEntries $entries) 271: #if (!$entries) 272: #setVariable ("$entries" []) 273: #end 274: #getBlogEntriesBaseQuery($query) 275: #set($totalEntries = $services.query.hql($query).count()) 276: #set($defaultItemsPerPage = 20) 277: ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. 278: #preparePagedViewParams($totalEntries $defaultItemsPerPage) 279: #set($discard = $entries.addAll($services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute())) 280: #end 281: ## 282: ## 283: ## 284: #** 285: * Return the base query for selecting blog entries. It filters only visible entries, but does not bind to a specific 286: * blog, nor specify a range or an ordering criteria. 287: * 288: * @param query The basic query for selecting blog entries. 289: *### 290: #macro(getBlogEntriesBaseQuery $query) 291: #set ($query = $NULL) 292: #setVariable ("$query" ", BaseObject obj, IntegerProperty isPublished, IntegerProperty hidden, DateProperty publishDate 293: where doc.fullName <> '${blogPostTemplate}' and 294: obj.name = doc.fullName and obj.className = '${blogPostClassname}' and 295: publishDate.id.id = obj.id and publishDate.id.name = 'publishDate' and 296: isPublished.id.id = obj.id and isPublished.id.name = 'published' and 297: hidden.id.id = obj.id and hidden.id.name = 'hidden' and 298: (doc.creator = '$xcontext.user' or (isPublished.value = 1 and hidden.value = 0))") 299: #end 300: ## 301: ## 302: ## 303: #** 304: * Checks if the provided blog is global or in-space. 305: * 306: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>blogType</tt> property set. 307: * @param isGlobal The resulting boolean. If the blog object does not define anything, it is considered in-space. 308: *### 309: #macro(isBlogGlobal $blogDoc $isGlobal) 310: #getBlogProperty($blogDoc 'blogType' '' $discard) 311: #set ($result = false) 312: #if($discard == 'global') 313: #set($result = true) 314: #end 315: #set ($isGlobal = $NULL) 316: #setVariable ("$isGlobal" $result) 317: #end 318: ## 319: ## 320: ## 321: #** 322: * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a 323: * week), monthly (all entries in a month), or all. 324: * 325: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt> 326: * property set. 327: * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated. 328: *### 329: #macro(getBlogDisplayType $blogDoc $displayType) 330: #getBlogProperty($blogDoc 'displayType' 'paginated' $result) 331: #set ($displayType = $NULL) 332: #setVariable ("$displayType" $result) 333: #end 334: ## 335: ## 336: ## 337: #** 338: * Displays a list of entries. 339: * 340: * @param entries The entries to display, a list of XDocument names. 341: * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results, 342: * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently 343: * used values: index, single, category, search, unpublished, hidden. 344: * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content. 345: * @param shouldDisplayTitles If <tt>true</tt>, display the blog title (blog posts shouldn't display the title when they're 346: * displayed alone on their page since it's the page title which is used in this case) 347: *### 348: #macro(displayBlog $entries $displaying $onlyExtract $shouldDisplayTitles) 349: #set($blogDay = '') 350: (% class="hfeed $!{displaying}" %)((( 351: (% class="blogDay" %)((( 352: #foreach ($entryDoc in $xwiki.wrapDocs($entries)) 353: #getEntryObject($entryDoc $entryObj) 354: ## Although all entries should have one of the two objects, better check to be sure. 355: #if("$!{entryObj}" != '') 356: #getEntryDate($entryDoc $entryObj $entryDate) 357: ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet. 358: #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd')) 359: #if($blogDay != $entryDateStr) 360: #if($blogDay != '') 361: ))) 362: (% class="blogDay" %)((( 363: #end 364: #displayBlogDate($entryDate) 365: #set ($blogDay = $entryDateStr) 366: #end 367: ## Finally, display the entry. 368: #displayEntry($entryDoc $entryObj $onlyExtract $shouldDisplayTitles) 369: #end 370: #end 371: )))## blogDay 372: )))## hfeed 373: #end 374: ## 375: ## 376: ## 377: #** 378: * Get the entry object, either a new BlogPost or an old Article. 379: * 380: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 381: * @param entryObj The resulting xobject of the blog post. 382: *### 383: #macro(getEntryObject $entryDoc $__entryObj) 384: #set($result = $entryDoc.getObject("${blogPostClassname}")) 385: #if(!$result) 386: #set($result = $entryDoc.getObject("${oldArticleClassname}")) 387: #end 388: ## NOTE: The reason we put an underscore in front of the variable name is to prevent the following line from 389: ## overwriting the $entryObj variable that may be defined before this macro is called. Of course, $__entryObj may be 390: ## overwritten in this case but it's less likely to have such a variable defined before. 391: #set ($__entryObj = $NULL) 392: #setVariable ("$__entryObj" $result) 393: #end 394: ## 395: ## 396: ## 397: #** 398: * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is 399: * the document creation date, but can be edited by the user. 400: * 401: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 402: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 403: * @param result The resulting date, an instance of <tt>java.util.Date</tt>. 404: *### 405: #macro(getEntryDate $entryDoc $entryObj $result) 406: #set ($result = $NULL) 407: #setVariable ("$result" $entryObj.getProperty('publishDate').value) 408: #end 409: ## 410: ## 411: ## 412: #** 413: * Displays a date, nicely formatted as a calendar page. 414: * 415: * @param date The date to display, an instance of <tt>java.util.Date</tt>. 416: *### 417: #macro(displayBlogDate $date) 418: #set($year = $xwiki.formatDate($date, 'yyyy')) 419: ## 3 letter month name, like Jan, Dec. 420: #set($month = $xwiki.formatDate($date, 'MMM')) 421: ## Uncomment to get a full length month name, like January, December. 422: ## TODO: this could be defined somewhere in the blog style. 423: ## #set($month = $xwiki.formatDate($date, 'MMMM')) 424: #set($day = $xwiki.formatDate($date, 'dd')) 425: (% class="blogdate" %) 426: == (% class="month" %)$month(%%) (% class="day" %)$day(%%) (% class="year" %)$year(%%) == 427: #end 428: ## 429: ## 430: ## 431: #** 432: * Displays a blog article: management tools, header, content, footer. 433: * 434: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 435: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 436: * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 437: * @param shouldDisplayTitle If <tt>true</tt>, display the blog title (blog posts shouldn't display the title 438: * when they're displayed alone on their page since it's the page title which is used in this case) 439: *### 440: #macro(displayEntry $entryDoc $entryObj $onlyExtract $shouldDisplayTitle) 441: ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden 442: #isPublished($entryObj $isPublished) 443: #isHidden($entryObj $isHidden) 444: #if($doc.fullName == $entryDoc.fullName) 445: (% class="hentry single-article" %)((( 446: #else 447: (% class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end" %)((( 448: #end 449: #displayEntryTools($entryDoc $entryObj) 450: #if($shouldDisplayTitle) 451: #displayEntryTitle($entryDoc $entryObj) 452: #end 453: #if($doc.fullName == $entryDoc.fullName) 454: #if(!$isPublished) 455: {{warning}}{{translation key='xe.blog.code.published'/}}{{/warning}} 456: #elseif($isHidden) 457: {{warning}}{{translation key='xe.blog.code.hidden'/}}{{/warning}} 458: #end 459: #end 460: #displayEntryContent($entryDoc $entryObj $onlyExtract) 461: #displayEntryFooter($entryDoc $entryObj) 462: )))## hentry 463: #end 464: ## 465: ## 466: ## 467: #** 468: * Checks if the provided blog is published or not. 469: * 470: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 471: * @param isPublished The resulting boolean, true if the entry is considered published. 472: *### 473: #macro(isPublished $entryObj $isPublished) 474: #set ($isPublished = $NULL) 475: ## This should work for both old articles, which don't have the 'published' property at all, and 476: ## are considered published by default, and new entries, that should have 1 if published. 477: #if ("$!{entryObj.getProperty('published').value}" != '0') 478: #setVariable ("$isPublished" true) 479: #else 480: #setVariable ("$isPublished" false) 481: #end 482: #end 483: ## 484: ## 485: ## 486: #** 487: * Checks if the provided blog is hidden or not. 488: * 489: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass. 490: * @param isHiddel The resulting boolean, true if the entry is considered hidden. 491: *### 492: #macro(isHidden $entryObj $isHidden) 493: #set ($isHidden = $NULL) 494: ## This should work for both old articles, which don't have the 'hidden' property at all, and 495: ## are considered visible by default, and new entries, that should have 1 if hidden. 496: #if ("$!{entryObj.getProperty('hidden').value}" == '1') 497: #setVariable ("$isHidden" true) 498: #else 499: #setVariable ("$isHidden" false) 500: #end 501: #end 502: ## 503: ## 504: ## 505: #** 506: * Displays several "tools" for manipulating blog posts: hide/show, publish, edit. 507: * 508: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 509: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 510: *### 511: #macro(displayEntryTools $entryDoc $entryObj) 512: #if($xcontext.action == 'view') 513: (% class="blog-entry-toolbox" %)((( 514: #displayPublishButton($entryDoc $entryObj) 515: #displayHideShowButton($entryDoc $entryObj) 516: #displayEditButton($entryDoc $entryObj) 517: #displayDeleteButton($entryDoc $entryObj) 518: ))) 519: #end 520: #end 521: ## 522: ## 523: ## 524: #** 525: * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet. 526: * 527: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 528: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 529: * @todo AJAX calls. 530: *### 531: #macro(displayPublishButton $entryDoc $entryObj) 532: #isPublished($entryObj $isPublished) 533: #if(!$isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 534: [[#toolImage('world')>>path:$blogPublisher.getURL('view', "entryName=${escapetool.url($entryDoc.fullName)}&xredirect=${escapetool.url($thisURL)}&form_token=$!{services.csrf.getToken()}")||title="$services.localization.render('xe.blog.code.notpublished')"]]## 535: #end 536: #end 537: ## 538: ## 539: ## 540: #** 541: * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published. 542: * 543: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 544: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 545: *### 546: #macro(displayHideShowButton $entryDoc $entryObj) 547: #isPublished($entryObj $isPublished) 548: #isHidden($entryObj $isHidden) 549: ## Only published articles can be hidden. Unpublished articles are considered already hidden. 550: #if($isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 551: #set ($queryString = { 552: 'xredirect' : $thisURL, 553: 'form_token' : $services.csrf.getToken() 554: }) 555: #if ($isHidden) 556: #set ($discard = $queryString.putAll({ 557: "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden" : 0, 558: 'comment' : $services.localization.render('xe.blog.code.madevisible') 559: })) 560: #set ($lockURL = $entryDoc.getURL('save', $escapetool.url($queryString))) 561: [[#toolImage('unlock')>>path:$lockURL||class="blog-tool-show" title="$services.localization.render('xe.blog.code.makevisible')"]]## 562: #else 563: #set ($discard = $queryString.putAll({ 564: "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden" : 1, 565: 'comment' : $services.localization.render('xe.blog.code.hid') 566: })) 567: #set ($lockURL = $entryDoc.getURL('save', $escapetool.url($queryString))) 568: [[#toolImage('lock')>>path:$lockURL||class="blog-tool-hide" title="$services.localization.render('xe.blog.code.hide')"]]## 569: #end 570: #end 571: #end 572: ## 573: ## 574: ## 575: #** 576: * Displays the edit button to those that can edit the article. 577: * 578: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 579: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 580: *### 581: #macro(displayEditButton $entryDoc $entryObj) 582: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 583: ## Call getDefaultEditMode() for backward compatibility with older blog posts. 584: [[#toolImage('pencil')>>path:$entryDoc.getURL('edit')||title="$services.localization.render('xe.blog.code.editpost')"]]## 585: #end 586: #end 587: ## 588: ## 589: ## 590: #** 591: * Displays the delete button to those that can edit the article. 592: * 593: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 594: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 595: * @todo AJAX calls. 596: *### 597: #macro(displayDeleteButton $entryDoc $entryObj) 598: #if($xwiki.hasAccessLevel('delete', $xcontext.user, $entryDoc.fullName)) 599: [[#toolImage('cross')>>path:$entryDoc.getURL('delete')||title="$services.localization.render('xe.blog.code.deletepost')"]]## 600: #end 601: #end 602: ## 603: ## 604: ## 605: #** 606: * Displays the title of the entry. 607: * 608: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 609: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 610: *### 611: #macro(displayEntryTitle $entryDoc $entryObj) 612: #if($doc.fullName == $entryDoc.fullName) 613: (% class="entry-title" %) 614: = $entryDoc.display('title', 'view', $entryObj) = 615: #else 616: (% class="entry-title" %) 617: === [[$entryDoc.display('title', 'view', $entryObj)>>doc:$entryDoc]] === 618: #end 619: #end 620: ## 621: ## 622: ## 623: #** 624: * Displays the body of the entry. 625: * 626: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 627: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 628: * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 629: *### 630: #macro(displayEntryContent $entryDoc $entryObj $onlyExtract) 631: (% class="#if($onlyExtract)entry-summary#{else}entry-content#end" %)((( 632: #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent) 633: ## FIXME: This causes the blog's content to not be annotatable. See http://jira.xwiki.org/browse/XWIKI-6328 634: ## Should probably be replaced by a display macro call with a reference to the object property holding the post's content 635: {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.syntax.toIdString()){{/html}} 636: ))) ## entry-content 637: (% class="clearfloats" %)((())) 638: #end 639: ## 640: ## 641: ## 642: #** 643: * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content 644: * of the <tt>extract</tt> field (if not empty). 645: * 646: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 647: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 648: * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 649: * @param entryContent The resulting content. 650: *### 651: #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent) 652: #if ($onlyExtract) 653: #set ($result = $entryObj.getProperty('extract').value) 654: #end 655: #if("$!result" == '') 656: #set($result = $entryObj.getProperty('content').value) 657: #* Disabled until the content can be cleanly cut. 658: * #if($onlyExtract && $result.length()>$maxchars) 659: * #set($i = $result.lastIndexOf(" ", $maxchars)) 660: * #set($i = $i + 1) 661: * #set($result = "${result.substring(0,$i)} *[...>${entryDoc.fullName}]*") 662: * #end 663: ## *### 664: #else 665: #if($entryDoc.syntax.toIdString() == 'xwiki/1.0') 666: #set($result = "${result} <a href='${entryDoc.getURL()}' title='$services.localization.render('xe.blog.code.readpost')'>...</a>") 667: #else 668: #set($result = "${result} [[...>>${entryDoc}||title='$services.localization.render('xe.blog.code.readpost')']]") 669: #end 670: #end 671: #set ($entryContent = $NULL) 672: #setVariable ("$entryContent" $result) 673: #end 674: ## 675: ## 676: ## 677: #** 678: * Displays the footer of the entry. 679: * 680: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 681: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 682: *### 683: #macro(displayEntryFooter $entryDoc $entryObj) 684: (% class="entry-footer" %)((( 685: #isPublished($entryObj $isPublished) 686: (% class='entry-author-label' %) 687: #if($isPublished) 688: {{translation key='xe.blog.code.postedby'/}} ## 689: #else 690: {{translation key='xe.blog.code.createdby'/}} ## 691: #end 692: {{html wiki="false" clean="false"}}<span class='author vcard'>#userfn($entryDoc.creator)</span>{{/html}} ## 693: #getEntryDate($entryDoc $entryObj $entryDate) 694: #listCategories($entryObj) #* 695: ## Since the publish date and update date are not set at the exact same time, there could be a small difference that 696: ## we assume cannot be more than 3 seconds. 697: *#(% class="separator" %)·(%%) [[{{translation key='xe.blog.code.permalink'/}}>>$entryDoc||rel="bookmark"]] ## 698: (% class="separator" %)·(%%) [[{{translation key='xe.blog.code.comments'/}}>>$entryDoc||anchor="Comments"]] (% class="itemCount" %)($entryDoc.comments.size())(%%) ## 699: )))## entry-footer 700: #end 701: ## 702: ## 703: ## 704: #** 705: * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>. 706: * 707: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 708: *### 709: #macro(listCategories $entryObj) 710: #if($entryObj.getxWikiClass().getName() == $blogPostClassname) 711: #set($categories = $entryObj.getProperty('category').value) 712: #set($first = true) 713: #if($categories.size() > 0) 714: #foreach($category in $categories) 715: #set($categoryDoc = $!xwiki.getDocument($category)) 716: #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname})) 717: #if($foreach.count == 1) 718: (% class='separator' %)·(%%) $services.localization.render('xe.blog.code.categories') ## 719: #else 720: , ## 721: #end## 722: [[$!{escapetool.xml($!categoryDoc.getObject($blogCategoryClassname).getValue('name'))}>>${category}||rel='tag']]## 723: #end## 724: #end## 725: #end 726: #end 727: #end 728: ## 729: ## 730: ## 731: #** 732: * Displays blog pagination links (older and newer entries). 733: * 734: * @param blogDoc the XDocument holding the blog definition object. 735: *### 736: #macro(displayNavigationLinks $blogDoc) 737: (% class="clearfloats" %)((())) 738: #getBlogDisplayType($blogDoc $displayType) 739: #if($displayType == 'weekly') 740: (% class="pagingLinks" %)((( 741: #getRequestedWeek($weekDate) 742: $weekDate.addWeeks(-1)## 743: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.previousweek'/}}>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear"]]**(%%) 744: #sep() 745: $weekDate.addWeeks(2)## 2 because we already subtracted 1 above 746: (% class="nextPage" %)**[[{{translation key='xe.blog.code.nextweek'/}} »>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear"]]**(%%) 747: ))) 748: #elseif($displayType == 'monthly') 749: (% class="pagingLinks" %)((( 750: #getRequestedMonth($monthDate) 751: $monthDate.addMonths(-1)## 752: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.previousmonth'/}}>>$doc.name||queryString="year=$monthDate.year&month=$monthDate.monthOfYear"]]**(%%) 753: #sep() 754: $monthDate.addMonths(2)## 2 because we already subtracted 1 above 755: (% class="nextPage" %)**[[{{translation key='xe.blog.code.nextmonth'/}} »>>$doc.name||queryString="year=$monthDate.year&month=$monthDate.monthOfYear"]]**(%%) 756: ))) 757: #elseif($displayType == 'all') 758: #else 759: ## Paginated 760: #if(($totalPages > 1)) 761: #set($queryString = '') 762: #foreach($p in $request.getParameterNames()) 763: #if($p != 'page' && $p != 'ipp') 764: #foreach($v in $request.getParameterValues($p)) 765: #set($queryString = "${queryString}&${p}=${v}") 766: #end 767: #end 768: #end 769: (% class="pagingLinks" %)((( 770: #if ($currentPageNumber < $totalPages) 771: #set($currentPageNumber = $currentPageNumber + 1) 772: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.olderposts'/}}>>$doc.name||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString"]]**(%%) 773: #set($currentPageNumber = $currentPageNumber - 1) 774: #end 775: #if ($currentPageNumber > 1) 776: #if ($currentPageNumber < $totalPages) 777: #sep() 778: #end 779: #set($currentPageNumber = $currentPageNumber - 1) 780: (% class="nextPage" %)**[[{{translation key='xe.blog.code.newerposts'/}} »>>$doc.name||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString"]]**(%%) 781: #set($currentPageNumber = $currentPageNumber + 1) 782: #end 783: (% class="clear" %)(%%) 784: )))## pagingLinks 785: #end 786: #end 787: #end 788: ## 789: ## 790: ## 791: #** 792: * Displays a message box with "publish" icon. 793: * 794: * @param message A text message concerning blog article publishing 795: *### 796: #macro(publishMessageBox $message) 797: (% class="plainmessage publish-message" %)((($services.icon.render('world') $message))) 798: #end 799: #** 800: * Displays a message box with "show/hide" icon. 801: * 802: * @param message A text message concerning blog article hiding 803: *### 804: #macro(hideMessageBox $message) 805: (% class="plainmessage hide-message" %)((($services.icon.render('unlock') $message))) 806: #end 807: ## 808: ## 809: ## 810: #** 811: * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are 812: * <tt>year</tt> and <tt>week</tt>. By default, the current week is used. 813: * 814: * @param monthDate The resulting week, a JODATime MutableDateTime. 815: *### 816: #macro(getRequestedWeek $weekDate) 817: #set ($weekDate = $NULL) 818: #setVariable ("$weekDate" $xwiki.jodatime.mutableDateTime) 819: #if("$!{request.year}" != '') 820: $weekDate.setYear($mathtool.toInteger($request.year)) 821: #end 822: #if("$!{request.week}" != '') 823: $weekDate.setWeekOfWeekyear($mathtool.toInteger($request.week)) 824: #end 825: #end 826: ## 827: ## 828: ## 829: #** 830: * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are 831: * <tt>year</tt> and <tt>month</tt>. By default, the current month is used. 832: * 833: * @param monthDate The resulting month, a JODATime MutableDateTime. 834: *### 835: #macro(getRequestedMonth $monthDate) 836: #set ($monthDate = $NULL) 837: #setVariable ("$monthDate" $xwiki.jodatime.mutableDateTime) 838: #if("$!{request.year}" != '') 839: $monthDate.setYear($mathtool.toInteger($request.year)) 840: #end 841: #if("$!{request.month}" != '') 842: $monthDate.setMonthOfYear($mathtool.toInteger($request.month)) 843: #end 844: #end 845: ## 846: ## 847: ## 848: #** 849: * Retrieve a blog property (title, display type, etc). 850: * 851: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 852: * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties. 853: * @param defaultValue The default value to use in case the blog object does not define one. 854: * @param propertyValue The resulting value. 855: *### 856: #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue) 857: #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") 858: #if($result == '') 859: #set($result = $defaultValue) 860: #end 861: #set ($propertyValue = $NULL) 862: #setVariable ("$propertyValue" $result) 863: #end 864: 865: #** 866: * If an error occurs when executing an action, set a specific response status and display an error message. 867: * 868: * @param status The response status. 869: * @param text The user readable error to be displayed. Can be a translation key. 870: * @param parameters The parameters to use when decoding the translation key. 871: *### 872: #macro(blog__actionResponseError $status $text $parameters) 873: $response.setStatus($status) 874: #if($request.ajax) 875: $services.localization.render($text, $!parameters) 876: #else 877: {{error}}$services.localization.render($text, $!parameters){{/error}} 878: #end 879: #end 880: {{/velocity}}
Recent Blog Posts
My Technology Roadmap
Blog Categories
All
News
(1)
Other
(0)
Personal
(0)
Blog Archive
2017
(1)