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