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