一般动作
登录
Wiki:
BROPEN
▼
:
Document Index
»
Space:
Blog
▼
:
Document Index
»
Page:
BlogCode
搜索
default
页面动作
导出
▼
:
以PDF格式导出
以RTF格式导出
以HTML格式导出
更多动作
▼
:
打印预览
察看源码
欢迎进入Wiki
»
The Wiki Blog
»
Macros for the Blog application
Wiki源代码
Macros for the Blog application
在2013-10-09 15:03上被
Administrator
修改
内容
·
评论
(0)
·
附件
(0)
·
记录
·
信息
隐藏行号
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: ; #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: #getBlogProperty($blogDoc 'title' $!blogDoc.displayTitle $result) 100: #set ($title = $NULL) 101: #setVariable ("$title" $result) 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: #set ($entryObj = $NULL) 389: #setVariable ("$entryObj" $result) 390: #end 391: ## 392: ## 393: ## 394: #** 395: * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is 396: * the document creation date, but can be edited by the user. 397: * 398: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 399: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 400: * @param result The resulting date, an instance of <tt>java.util.Date</tt>. 401: *### 402: #macro(getEntryDate $entryDoc $entryObj $result) 403: #set ($result = $NULL) 404: #setVariable ("$result" $entryObj.getProperty('publishDate').value) 405: #end 406: ## 407: ## 408: ## 409: #** 410: * Displays a date, nicely formatted as a calendar page. 411: * 412: * @param date The date to display, an instance of <tt>java.util.Date</tt>. 413: *### 414: #macro(displayBlogDate $date) 415: #set($year = $xwiki.formatDate($date, 'yyyy')) 416: ## 3 letter month name, like Jan, Dec. 417: #set($month = $xwiki.formatDate($date, 'MMM')) 418: ## Uncomment to get a full length month name, like January, December. 419: ## TODO: this could be defined somewhere in the blog style. 420: ## #set($month = $xwiki.formatDate($date, 'MMMM')) 421: #set($day = $xwiki.formatDate($date, 'dd')) 422: (% class="blogdate" %) 423: == (% class="month" %)$month(%%) (% class="day" %)$day(%%) (% class="year" %)$year(%%) == 424: #end 425: ## 426: ## 427: ## 428: #** 429: * Displays a blog article: management tools, header, content, footer. 430: * 431: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 432: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 433: * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 434: * @param shouldDisplayTitle If <tt>true</tt>, display the blog title (blog posts shouldn't display the title 435: * when they're displayed alone on their page since it's the page title which is used in this case) 436: *### 437: #macro(displayEntry $entryDoc $entryObj $onlyExtract $shouldDisplayTitle) 438: ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden 439: #isPublished($entryObj $isPublished) 440: #isHidden($entryObj $isHidden) 441: #if($doc.fullName == $entryDoc.fullName) 442: (% class="hentry single-article" %)((( 443: #else 444: (% class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end" %)((( 445: #end 446: #displayEntryTools($entryDoc $entryObj) 447: #if($shouldDisplayTitle) 448: #displayEntryTitle($entryDoc $entryObj) 449: #end 450: #if($doc.fullName == $entryDoc.fullName) 451: #if(!$isPublished) 452: {{warning}}{{translation key='xe.blog.code.published'/}}{{/warning}} 453: #elseif($isHidden) 454: {{warning}}{{translation key='xe.blog.code.hidden'/}}{{/warning}} 455: #end 456: #end 457: #displayEntryContent($entryDoc $entryObj $onlyExtract) 458: #displayEntryFooter($entryDoc $entryObj) 459: )))## hentry 460: #end 461: ## 462: ## 463: ## 464: #** 465: * Checks if the provided blog is published or not. 466: * 467: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 468: * @param isPublished The resulting boolean, true if the entry is considered published. 469: *### 470: #macro(isPublished $entryObj $isPublished) 471: #set ($isPublished = $NULL) 472: ## This should work for both old articles, which don't have the 'published' property at all, and 473: ## are considered published by default, and new entries, that should have 1 if published. 474: #if ("$!{entryObj.getProperty('published').value}" != '0') 475: #setVariable ("$isPublished" true) 476: #else 477: #setVariable ("$isPublished" false) 478: #end 479: #end 480: ## 481: ## 482: ## 483: #** 484: * Checks if the provided blog is hidden or not. 485: * 486: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass. 487: * @param isHiddel The resulting boolean, true if the entry is considered hidden. 488: *### 489: #macro(isHidden $entryObj $isHidden) 490: #set ($isHidden = $NULL) 491: ## This should work for both old articles, which don't have the 'hidden' property at all, and 492: ## are considered visible by default, and new entries, that should have 1 if hidden. 493: #if ("$!{entryObj.getProperty('hidden').value}" == '1') 494: #setVariable ("$isHidden" true) 495: #else 496: #setVariable ("$isHidden" false) 497: #end 498: #end 499: ## 500: ## 501: ## 502: #** 503: * Displays several "tools" for manipulating blog posts: hide/show, publish, edit. 504: * 505: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 506: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 507: *### 508: #macro(displayEntryTools $entryDoc $entryObj) 509: #if($xcontext.action == 'view') 510: (% class="blog-entry-toolbox" %)((( 511: #displayPublishButton($entryDoc $entryObj) 512: #displayHideShowButton($entryDoc $entryObj) 513: #displayEditButton($entryDoc $entryObj) 514: #displayDeleteButton($entryDoc $entryObj) 515: ))) 516: #end 517: #end 518: ## 519: ## 520: ## 521: #** 522: * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet. 523: * 524: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 525: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 526: * @todo AJAX calls. 527: *### 528: #macro(displayPublishButton $entryDoc $entryObj) 529: #isPublished($entryObj $isPublished) 530: #if(!$isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 531: [[{{html clean="false"}}#toolImage('page_white_world' 'publish '){{/html}}>>path:$blogPublisher.getURL('view', "entryName=${escapetool.url($entryDoc.fullName)}&xredirect=${escapetool.url($thisURL)}&form_token=$!{services.csrf.getToken()}")||title="${escapetool.xml($services.localization.render('xe.blog.code.notpublished'))}"]]## 532: #end 533: #end 534: ## 535: ## 536: ## 537: #** 538: * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published. 539: * 540: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 541: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 542: *### 543: #macro(displayHideShowButton $entryDoc $entryObj) 544: #isPublished($entryObj $isPublished) 545: #isHidden($entryObj $isHidden) 546: ## Only published articles can be hidden. Unpublished articles are considered already hidden. 547: #if($isPublished && $entryDoc.creator == $xcontext.user && $xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 548: #if ($isHidden) 549: [[{{html clean="false"}}#toolImage('lock_open', 'show '){{/html}}>>path:$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=0&comment=${escapetool.url($services.localization.render('xe.blog.code.madevisible'))}&xredirect=${escapetool.url($thisURL)}&form_token=$!{services.csrf.getToken()}")||class="blog-tool-show" title="${escapetool.xml($services.localization.render('xe.blog.code.makevisible'))}"]]## 550: #else 551: [[{{html clean="false"}}#toolImage('lock', 'hide '){{/html}}>>path:$entryDoc.getURL('save', "${entryObj.getxWikiClass().getName()}_${entryObj.number}_hidden=1&comment=${escapetool.url($services.localization.render('xe.blog.code.hid'))}&xredirect=${escapetool.url($thisURL)}&form_token=$!{services.csrf.getToken()}")||class="blog-tool-hide" title="${escapetool.xml($services.localization.render('xe.blog.code.hide'))}"]]## 552: #end 553: #end 554: #end 555: ## 556: ## 557: ## 558: #** 559: * Displays the edit button to those that can edit the article. 560: * 561: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 562: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 563: *### 564: #macro(displayEditButton $entryDoc $entryObj) 565: #if($xwiki.hasAccessLevel('edit', $xcontext.user, $entryDoc.fullName)) 566: ## Call getDefaultEditMode() for backward compatibility with older blog posts. 567: [[{{html clean="false"}}#toolImage('pencil' 'edit '){{/html}}>>path:$entryDoc.getURL('edit')||title="${escapetool.xml($services.localization.render('xe.blog.code.editpost'))}"]]## 568: #end 569: #end 570: ## 571: ## 572: ## 573: #** 574: * Displays the delete button to those that can edit the article. 575: * 576: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 577: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 578: * @todo AJAX calls. 579: *### 580: #macro(displayDeleteButton $entryDoc $entryObj) 581: #if($xwiki.hasAccessLevel('delete', $xcontext.user, $entryDoc.fullName)) 582: [[{{html clean="false"}}#toolImage('cross' 'delete '){{/html}}>>path:$entryDoc.getURL('delete')||title="${escapetool.xml($services.localization.render('xe.blog.code.deletepost'))}"]]## 583: #end 584: #end 585: ## 586: ## 587: ## 588: #** 589: * Displays the title of the entry. 590: * 591: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 592: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 593: *### 594: #macro(displayEntryTitle $entryDoc $entryObj) 595: #if($doc.fullName == $entryDoc.fullName) 596: (% class="entry-title" %) 597: = $entryDoc.display('title', 'view', $entryObj) = 598: #else 599: (% class="entry-title" %) 600: === [[$entryDoc.display('title', 'view', $entryObj)>>doc:$entryDoc]] === 601: #end 602: #end 603: ## 604: ## 605: ## 606: #** 607: * Displays the body of the entry. 608: * 609: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 610: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 611: * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. 612: *### 613: #macro(displayEntryContent $entryDoc $entryObj $onlyExtract) 614: (% class="#if($onlyExtract)entry-summary#{else}entry-content#end" %)((( 615: #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent) 616: {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.syntax.toIdString()){{/html}} 617: ))) ## entry-content 618: #end 619: ## 620: ## 621: ## 622: #** 623: * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content 624: * of the <tt>extract</tt> field (if not empty). 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: * @param entryContent The resulting content. 630: *### 631: #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent) 632: #if ($onlyExtract) 633: #set ($result = $entryObj.getProperty('extract').value) 634: #end 635: #if("$!result" == '') 636: #set($result = $entryObj.getProperty('content').value) 637: #* Disabled until the content can be cleanly cut. 638: * #if($onlyExtract && $result.length()>$maxchars) 639: * #set($i = $result.lastIndexOf(" ", $maxchars)) 640: * #set($i = $i + 1) 641: * #set($result = "${result.substring(0,$i)} *[...>${entryDoc.fullName}]*") 642: * #end 643: ## *### 644: #else 645: #if($entryDoc.syntax.toIdString() == 'xwiki/1.0') 646: #set($result = "${result} <a href='${entryDoc.getURL()}' title='$services.localization.render('xe.blog.code.readpost')'>...</a>") 647: #else 648: #set($result = "${result} [[...>>${entryDoc}||title='$services.localization.render('xe.blog.code.readpost')']]") 649: #end 650: #end 651: #set ($entryContent = $NULL) 652: #setVariable ("$entryContent" $result) 653: #end 654: ## 655: ## 656: ## 657: #** 658: * Displays the footer of the entry. 659: * 660: * @param entryDoc The xdocument of the blog post. Each post resides in its own document. 661: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 662: *### 663: #macro(displayEntryFooter $entryDoc $entryObj) 664: (% class="entry-footer" %)((( 665: #isPublished($entryObj $isPublished) 666: #if($isPublished) 667: {{translation key='xe.blog.code.postedby'/}} ## 668: #else 669: {{translation key='xe.blog.code.createdby'/}} ## 670: #end 671: {{html wiki="false"}} 672: <address class="author vcard">#userfn($entryDoc.creator)</address> ## 673: #getEntryDate($entryDoc $entryObj $entryDate) 674: #listCategories($entryObj) ## 675: ## Since the publish date and update date are not set at the exact same time, there could be a small difference that 676: ## we assume cannot be more than 3 seconds. 677: {{/html}} 678: (% class="separator" %)·(%%) [[{{translation key='xe.blog.code.permalink'/}}>>$entryDoc||rel="bookmark"]] ## 679: (% class="separator" %)·(%%) [[{{translation key='xe.blog.code.comments'/}}>>$entryDoc||anchor="Comments"]] (% class="itemCount" %)($entryDoc.comments.size())(%%) ## 680: )))## entry-footer 681: #end 682: ## 683: ## 684: ## 685: #** 686: * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>. 687: * 688: * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. 689: *### 690: #macro(listCategories $entryObj) 691: #if($entryObj.getxWikiClass().getName() == $blogPostClassname) 692: #set($categories = $entryObj.getProperty('category').value) 693: #set($first = true) 694: #if($categories.size() > 0) 695: #foreach($category in $categories) 696: ## Do not indent 697: #set($categoryDoc = $!xwiki.getDocument($category)) 698: #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname})) 699: #if($first) 700: <span class="separator">·</span> $services.localization.render('xe.blog.code.categories') 701: #set($first = false) 702: #else, #end## if first 703: <a rel="tag" href="$xwiki.getURL(${category})">$!{escapetool.xml($!xwiki.getDocument($category).getObject($blogCategoryClassname).getProperty('name').value)}</a>## 704: #end## if isNew 705: #end## foreach 706: #end 707: #end 708: #end 709: ## 710: ## 711: ## 712: #** 713: * Displays blog pagination links (older and newer entries). 714: * 715: * @param blogDoc the XDocument holding the blog definition object. 716: *### 717: #macro(displayNavigationLinks $blogDoc) 718: (% class="clearfloats" %)((())) 719: #getBlogDisplayType($blogDoc $displayType) 720: #if($displayType == 'weekly') 721: (% class="pagingLinks" %)((( 722: #getRequestedWeek($weekDate) 723: $weekDate.addWeeks(-1)## 724: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.previousweek'/}}>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear"]]**(%%) 725: #sep() 726: $weekDate.addWeeks(2)## 2 because we already subtracted 1 above 727: (% class="nextPage" %)**[[{{translation key='xe.blog.code.nextweek'/}} »>>$doc.name||queryString="year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear"]]**(%%) 728: ))) 729: #elseif($displayType == 'monthly') 730: (% class="pagingLinks" %)((( 731: #getRequestedMonth($monthDate) 732: $monthDate.addMonths(-1)## 733: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.previousmonth'/}}>>$doc.name||queryString="year=$monthDate.year&month=$monthDate.monthOfYear"]]**(%%) 734: #sep() 735: $monthDate.addMonths(2)## 2 because we already subtracted 1 above 736: (% class="nextPage" %)**[[{{translation key='xe.blog.code.nextmonth'/}} »>>$doc.name||queryString="year=$monthDate.year&month=$monthDate.monthOfYear"]]**(%%) 737: ))) 738: #elseif($displayType == 'all') 739: #else 740: ## Paginated 741: #if(($totalPages > 1)) 742: #set($queryString = '') 743: #foreach($p in $request.getParameterNames()) 744: #if($p != 'page' && $p != 'ipp') 745: #foreach($v in $request.getParameterValues($p)) 746: #set($queryString = "${queryString}&${p}=${v}") 747: #end 748: #end 749: #end 750: (% class="pagingLinks" %)((( 751: #if ($currentPageNumber < $totalPages) 752: #set($currentPageNumber = $currentPageNumber + 1) 753: (% class="prevPage" %)**[[« {{translation key='xe.blog.code.olderposts'/}}>>$doc.name||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString"]]**(%%) 754: #set($currentPageNumber = $currentPageNumber - 1) 755: #end 756: #if ($currentPageNumber > 1) 757: #if ($currentPageNumber < $totalPages) 758: #sep() 759: #end 760: #set($currentPageNumber = $currentPageNumber - 1) 761: (% class="nextPage" %)**[[{{translation key='xe.blog.code.newerposts'/}} »>>$doc.name||queryString="page=${currentPageNumber}&ipp=${itemsPerPage}$queryString"]]**(%%) 762: #set($currentPageNumber = $currentPageNumber + 1) 763: #end 764: (% class="clear" %)(%%) 765: )))## pagingLinks 766: #end 767: #end 768: #end 769: ## 770: ## 771: ## 772: #** 773: * Displays a message box with "publish" icon. 774: * 775: * @param message A text message concerning blog article publishing 776: *### 777: #macro(publishMessageBox $message) 778: (% class="plainmessage publish-message" %)((($message))) 779: #end 780: #** 781: * Displays a message box with "show/hide" icon. 782: * 783: * @param message A text message concerning blog article hiding 784: *### 785: #macro(hideMessageBox $message) 786: (% class="plainmessage hide-message" %)((($message))) 787: #end 788: ## 789: ## 790: ## 791: #** 792: * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are 793: * <tt>year</tt> and <tt>week</tt>. By default, the current week is used. 794: * 795: * @param monthDate The resulting week, a JODATime MutableDateTime. 796: *### 797: #macro(getRequestedWeek $weekDate) 798: #set ($weekDate = $NULL) 799: #setVariable ("$weekDate" $xwiki.jodatime.mutableDateTime) 800: #if("$!{request.year}" != '') 801: $weekDate.setYear($mathtool.toInteger($request.year)) 802: #end 803: #if("$!{request.week}" != '') 804: $weekDate.setWeekOfWeekyear($mathtool.toInteger($request.week)) 805: #end 806: #end 807: ## 808: ## 809: ## 810: #** 811: * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are 812: * <tt>year</tt> and <tt>month</tt>. By default, the current month is used. 813: * 814: * @param monthDate The resulting month, a JODATime MutableDateTime. 815: *### 816: #macro(getRequestedMonth $monthDate) 817: #set ($monthDate = $NULL) 818: #setVariable ("$monthDate" $xwiki.jodatime.mutableDateTime) 819: #if("$!{request.year}" != '') 820: $monthDate.setYear($mathtool.toInteger($request.year)) 821: #end 822: #if("$!{request.month}" != '') 823: $monthDate.setMonthOfYear($mathtool.toInteger($request.month)) 824: #end 825: #end 826: ## 827: ## 828: ## 829: #** 830: * Retrieve a blog property (title, display type, etc). 831: * 832: * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. 833: * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties. 834: * @param defaultValue The default value to use in case the blog object does not define one. 835: * @param propertyValue The resulting value. 836: *### 837: #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue) 838: #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") 839: #if($result == '') 840: #set($result = $defaultValue) 841: #end 842: #set ($propertyValue = $NULL) 843: #setVariable ("$propertyValue" $result) 844: #end 845: 846: #** 847: * If an error occurs when executing an action, set a specific response status and display an error message. 848: * 849: * @param status The response status. 850: * @param text The user readable error to be displayed. Can be a translation key. 851: * @param parameters The parameters to use when decoding the translation key. 852: *### 853: #macro(blog__actionResponseError $status $text $parameters) 854: $response.setStatus($status) 855: #if($request.ajax) 856: $services.localization.render($text, $!parameters) 857: #else 858: {{error}}$services.localization.render($text, $!parameters){{/error}} 859: #end 860: #end 861: {{/velocity}}
Recent Blog Posts
Blog Categories
News
(16)
Other
(0)
Personal
(0)
Blog Archive
当前没有文章......
快速链接
首页
新闻动态
FAQ