Wiki source code of Macros for the Blog application
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{include document="Blog.BlogParameters" author="target" /}} | ||
| 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 inline edit mode, allows changing | ||
| 29 | * blog settings: title, description, blog type (global or in-space), index display type (fixed size pagination, weekly | ||
| 30 | * index, monthly index, 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 | #if($context.action == 'inline') | ||
| 37 | #macro(displayProperty $blogDoc $propname) | ||
| 38 | <dt>#displayPropName($xwiki.getClass($blogClassname).get($propname)):</dt> | ||
| 39 | <dd>$blogDoc.display($propname)</dd> | ||
| 40 | #end | ||
| 41 | <dl> | ||
| 42 | #displayProperty($blogDoc 'title') | ||
| 43 | #displayProperty($blogDoc 'description') | ||
| 44 | #displayProperty($blogDoc 'blogType') | ||
| 45 | #displayProperty($blogDoc 'displayType') | ||
| 46 | #displayProperty($blogDoc 'itemsPerPage') | ||
| 47 | </dl> | ||
| 48 | #else | ||
| 49 | $blogDoc.display('description') | ||
| 50 | #end | ||
| 51 | #elseif($doc.fullName == $blogSheet) | ||
| 52 | = $msg.get('xe.blog.code.blogsheet') = | ||
| 53 | $msg.get('xe.blog.code.sheetexplanation') | ||
| 54 | #else | ||
| 55 | #warning($msg.get('xe.blog.code.notblog')) | ||
| 56 | #end | ||
| 57 | #end | ||
| 58 | ## | ||
| 59 | ## | ||
| 60 | ## | ||
| 61 | #** | ||
| 62 | * Retrieve the blog document, which usually is either <tt><Space>.WebHome</tt> for whole-spaces blogs, or | ||
| 63 | * <tt><Space>.Blog</tt> for in-space blogs. If none of these documents contains a blog object, then the first | ||
| 64 | * (alphabetically) document in the target space that contains one is returned. Finally, if no document in the current | ||
| 65 | * space contains a blog object, then <tt>Blog.WebHome</tt> is returned as the default blog. | ||
| 66 | * | ||
| 67 | * @param space A <tt>String</tt>, the name of the space where to search. | ||
| 68 | * @param blogDoc The resulting XDocument. | ||
| 69 | *### | ||
| 70 | #macro(getBlogDocument $space $blogDoc) | ||
| 71 | ## First, try the Space.WebHome, for a whole-space blog | ||
| 72 | #set($blogDoc = $xwiki.getDocument("${space}.WebHome")) | ||
| 73 | #if(!$blogDoc.getObject($blogClassname)) | ||
| 74 | ## Second, try the Space.Blog document | ||
| 75 | #set($blogDoc = $xwiki.getDocument("${space}.Blog")) | ||
| 76 | #if(!$blogDoc.getObject($blogClassname)) | ||
| 77 | ## Third, try searching for a blog document in the current space | ||
| 78 | #set ($legacyRawf3cf9e4833_1 = $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()) | ||
| 79 | #set ($legacyVisiblef3cf9e4833_1 = []) | ||
| 80 | #foreach ($legacyEntryf3cf9e4833_1 in $legacyRawf3cf9e4833_1) | ||
| 81 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_1)) | ||
| 82 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_1.add($legacyEntryf3cf9e4833_1)) | ||
| 83 | #end | ||
| 84 | #end | ||
| 85 | #set($blogDocs = $legacyVisiblef3cf9e4833_1) | ||
| 86 | #if($blogDocs.size() > 0) | ||
| 87 | #set($blogDoc = $xwiki.getDocument($blogDocs.get(0))) | ||
| 88 | #else | ||
| 89 | ## Last, fallback to Blog.WebHome, the default blog | ||
| 90 | #set($blogDoc = $xwiki.getDocument('Blog.WebHome')) | ||
| 91 | #end | ||
| 92 | #end | ||
| 93 | #end | ||
| 94 | #end | ||
| 95 | ## | ||
| 96 | ## | ||
| 97 | ## | ||
| 98 | #** | ||
| 99 | * Retrieve the blog title. | ||
| 100 | * | ||
| 101 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass<tt> object with the <tt>title</tt> property set. | ||
| 102 | * @param title The resulting title. | ||
| 103 | *### | ||
| 104 | #macro(getBlogTitle $blogDoc $title) | ||
| 105 | ## The blog title is the rendered document title. It is displayed as data (never evaluated as | ||
| 106 | ## Velocity), so an unprivileged user storing script in Blog.BlogClass.title cannot run it. See | ||
| 107 | ## Blog.BlogSheet, which renders the title literally and falls back to the blog.code.title | ||
| 108 | ## translation when the stored title is empty. | ||
| 109 | #set ($title = $NULL) | ||
| 110 | #setVariable ("$title" $!blogDoc.displayTitle) | ||
| 111 | #end | ||
| 112 | ## | ||
| 113 | ## | ||
| 114 | ## | ||
| 115 | #** | ||
| 116 | * Retrieve the blog description. | ||
| 117 | * | ||
| 118 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>description</tt> | ||
| 119 | * property set. | ||
| 120 | * @param description The resulting description. | ||
| 121 | *### | ||
| 122 | #macro(getBlogDescription $blogDoc $description) | ||
| 123 | #getBlogProperty($blogDoc 'description' '' $result) | ||
| 124 | #set ($description = $NULL) | ||
| 125 | #setVariable ("$description" $result) | ||
| 126 | #end | ||
| 127 | ## | ||
| 128 | ## | ||
| 129 | ## | ||
| 130 | #** | ||
| 131 | * Retrieves a list of entries to be displayed. The entries are either part of the blog's space, or have the blog | ||
| 132 | * document set as a parent. The number and range of entries returned (from all those belonging to this blog) depends on | ||
| 133 | * the blog display type: paginated (fixed number of entries), weekly (all entries in a week), monthly (all entries in a | ||
| 134 | * month), or all. | ||
| 135 | * | ||
| 136 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 137 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 138 | *### | ||
| 139 | #macro(getBlogEntries $blogDoc $entries) | ||
| 140 | #getBlogEntriesBaseQuery($query) | ||
| 141 | #isBlogGlobal($blogDoc $isGlobal) | ||
| 142 | #if(!$isGlobal) | ||
| 143 | #set($query = "${query} and (doc.space = '${blogDoc.space}' or doc.parent = '${blogDoc.fullName}')") | ||
| 144 | #end | ||
| 145 | #getBlogDisplayType($blogDoc $displayType) | ||
| 146 | #if($displayType == 'weekly') | ||
| 147 | #getWeeklyBlogEntries($blogDoc $query $entries) | ||
| 148 | #elseif($displayType == 'monthly') | ||
| 149 | #getMonthlyBlogEntries($blogDoc $query $entries) | ||
| 150 | #elseif($displayType == 'all') | ||
| 151 | #getAllBlogEntries($blogDoc $query $entries) | ||
| 152 | #else | ||
| 153 | #getPagedBlogEntries($blogDoc $query $entries) | ||
| 154 | #end | ||
| 155 | #end | ||
| 156 | ## | ||
| 157 | ## | ||
| 158 | ## | ||
| 159 | #** | ||
| 160 | * Retrieves a list of entries to be displayed. The entries are taken from a "page" of the blog, a sequence of documents | ||
| 161 | * defined by the request parameters <tt>ipp</tt> (items per page) and <tt>page</tt> (the current page). Initially the | ||
| 162 | * first page is displayed, with the number of entries defined in the blog object in the <tt>itemsPerPage</tt> property | ||
| 163 | * (10 if not defined). | ||
| 164 | * | ||
| 165 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 166 | * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be | ||
| 167 | * refined to restrict to a given space, or to a given search criteria, etc. | ||
| 168 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 169 | *### | ||
| 170 | #macro(getPagedBlogEntries $blogDoc $query $entries) | ||
| 171 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 172 | #getBlogProperty($blogDoc 'itemsPerPage' '10' $defaultItemsPerPage) | ||
| 173 | #set($defaultItemsPerPage = $util.parseInt($defaultItemsPerPage)) | ||
| 174 | ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. | ||
| 175 | #preparePagedViewParams($totalEntries $defaultItemsPerPage) | ||
| 176 | #set ($legacyRawf3cf9e4833_2 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) | ||
| 177 | #set ($legacyVisiblef3cf9e4833_2 = []) | ||
| 178 | #foreach ($legacyEntryf3cf9e4833_2 in $legacyRawf3cf9e4833_2) | ||
| 179 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_2)) | ||
| 180 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_2.add($legacyEntryf3cf9e4833_2)) | ||
| 181 | #end | ||
| 182 | #end | ||
| 183 | #set($entries = $legacyVisiblef3cf9e4833_2) | ||
| 184 | #end | ||
| 185 | ## | ||
| 186 | ## | ||
| 187 | ## | ||
| 188 | #** | ||
| 189 | * Retrieves a list of entries to be displayed. The entries are taken from a week of the blog. The target week is | ||
| 190 | * defined by the request parameters <tt>week</tt> (the week number in the year, from 1 to 52) and <tt>year</tt> (4 | ||
| 191 | * digit year). Initially the current week is displayed. | ||
| 192 | * | ||
| 193 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 194 | * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be | ||
| 195 | * refined to restrict to a given space, or to a given search criteria, etc. | ||
| 196 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 197 | *### | ||
| 198 | #macro(getWeeklyBlogEntries $blogDoc $query $entries) | ||
| 199 | #getRequestedWeek($weekDate) | ||
| 200 | #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd')) | ||
| 201 | #set($minDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundFloor())) | ||
| 202 | #set($maxDay = $dateFormatter.print($weekDate.toMutableDateTime().weekOfWeekyear().roundCeiling())) | ||
| 203 | #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") | ||
| 204 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 205 | #set ($legacyRawf3cf9e4833_3 = $services.query.hql("${query} order by publishDate.value desc").execute()) | ||
| 206 | #set ($legacyVisiblef3cf9e4833_3 = []) | ||
| 207 | #foreach ($legacyEntryf3cf9e4833_3 in $legacyRawf3cf9e4833_3) | ||
| 208 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_3)) | ||
| 209 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_3.add($legacyEntryf3cf9e4833_3)) | ||
| 210 | #end | ||
| 211 | #end | ||
| 212 | #set($entries = $legacyVisiblef3cf9e4833_3) | ||
| 213 | #end | ||
| 214 | ## | ||
| 215 | ## | ||
| 216 | ## | ||
| 217 | #** | ||
| 218 | * Retrieves a list of entries to be displayed. The entries are taken from a month of the blog. The target month is | ||
| 219 | * defined by the request parameters <tt>month</tt> (the month number, from 1 to 12) and <tt>year</tt> (4 | ||
| 220 | * digit year). Initially the current month is displayed. | ||
| 221 | * | ||
| 222 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 223 | * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be | ||
| 224 | * refined to restrict to a given space, or to a given search criteria, etc. | ||
| 225 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 226 | *### | ||
| 227 | #macro(getMonthlyBlogEntries $blogDoc $query $entries) | ||
| 228 | #getRequestedMonth($monthDate) | ||
| 229 | #set($dateFormatter = $xwiki.jodatime.getDateTimeFormatterForPattern('yyyy-MM-dd')) | ||
| 230 | #set($minDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundFloor())) | ||
| 231 | #set($maxDay = $dateFormatter.print($monthDate.toMutableDateTime().monthOfYear().roundCeiling())) | ||
| 232 | #set($query = "${query} and publishDate.value >= '$minDay' and publishDate.value < '$maxDay'") | ||
| 233 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 234 | #set ($legacyRawf3cf9e4833_4 = $services.query.hql("${query} order by publishDate.value desc").execute()) | ||
| 235 | #set ($legacyVisiblef3cf9e4833_4 = []) | ||
| 236 | #foreach ($legacyEntryf3cf9e4833_4 in $legacyRawf3cf9e4833_4) | ||
| 237 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_4)) | ||
| 238 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_4.add($legacyEntryf3cf9e4833_4)) | ||
| 239 | #end | ||
| 240 | #end | ||
| 241 | #set($entries = $legacyVisiblef3cf9e4833_4) | ||
| 242 | #end | ||
| 243 | ## | ||
| 244 | ## | ||
| 245 | ## | ||
| 246 | #** | ||
| 247 | * Retrieves a list of entries to be displayed. All entries belonging to the current blog 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(getAllBlogEntries $blogDoc $query $entries) | ||
| 255 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 256 | #set ($legacyRawf3cf9e4833_5 = $services.query.hql("${query} order by publishDate.value desc").execute()) | ||
| 257 | #set ($legacyVisiblef3cf9e4833_5 = []) | ||
| 258 | #foreach ($legacyEntryf3cf9e4833_5 in $legacyRawf3cf9e4833_5) | ||
| 259 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_5)) | ||
| 260 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_5.add($legacyEntryf3cf9e4833_5)) | ||
| 261 | #end | ||
| 262 | #end | ||
| 263 | #set($entries = $legacyVisiblef3cf9e4833_5) | ||
| 264 | #end | ||
| 265 | ## | ||
| 266 | ## | ||
| 267 | ## | ||
| 268 | #** | ||
| 269 | * Retrieves a list of entries to be displayed. Only (and all) unpublished entries are returned. | ||
| 270 | * | ||
| 271 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 272 | * @param query The base query for selecting entries. Apart from the base query that selects entries, it can further be | ||
| 273 | * refined to restrict to a given space, or to a given search criteria, etc. | ||
| 274 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 275 | *### | ||
| 276 | #macro(getUnpublishedBlogEntries $blogDoc $query $entries) | ||
| 277 | #set($query = "${query} and isPublished.value = 0") | ||
| 278 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 279 | #set ($legacyRawf3cf9e4833_6 = $services.query.hql("${query} order by publishDate.value desc").execute()) | ||
| 280 | #set ($legacyVisiblef3cf9e4833_6 = []) | ||
| 281 | #foreach ($legacyEntryf3cf9e4833_6 in $legacyRawf3cf9e4833_6) | ||
| 282 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_6)) | ||
| 283 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_6.add($legacyEntryf3cf9e4833_6)) | ||
| 284 | #end | ||
| 285 | #end | ||
| 286 | #set($entries = $legacyVisiblef3cf9e4833_6) | ||
| 287 | #end | ||
| 288 | ## | ||
| 289 | ## | ||
| 290 | ## | ||
| 291 | #** | ||
| 292 | * Retrieves a list of entries to be displayed. The entries are taken from all the wiki, and not from a specific blog. | ||
| 293 | * | ||
| 294 | * @param entries The resulting list of entries to display, a list of XDocument names. | ||
| 295 | *### | ||
| 296 | #macro(getGlobalBlogEntries $entries) | ||
| 297 | #getBlogEntriesBaseQuery($query) | ||
| 298 | #set($totalEntries = $xwiki.countDocuments(${query})) | ||
| 299 | #set($defaultItemsPerPage = 20) | ||
| 300 | ## This macro is defined in the default macros.vm library. It also sets $itemsPerPage and $startAt. | ||
| 301 | #preparePagedViewParams($totalEntries $defaultItemsPerPage) | ||
| 302 | #set ($legacyRawf3cf9e4833_7 = $services.query.hql("${query} order by publishDate.value desc").setLimit($itemsPerPage).setOffset($startAt).execute()) | ||
| 303 | #set ($legacyVisiblef3cf9e4833_7 = []) | ||
| 304 | #foreach ($legacyEntryf3cf9e4833_7 in $legacyRawf3cf9e4833_7) | ||
| 305 | #if ($xwiki.hasAccessLevel('view', $xcontext.user, $legacyEntryf3cf9e4833_7)) | ||
| 306 | #set ($legacyVisibilityDiscard = $legacyVisiblef3cf9e4833_7.add($legacyEntryf3cf9e4833_7)) | ||
| 307 | #end | ||
| 308 | #end | ||
| 309 | #set($entries = $legacyVisiblef3cf9e4833_7) | ||
| 310 | #end | ||
| 311 | ## | ||
| 312 | ## | ||
| 313 | ## | ||
| 314 | #** | ||
| 315 | * Return the base query for selecting blog entries. It filters only visible entries, but does not bind to a specific | ||
| 316 | * blog, nor specify a range or an ordering criteria. | ||
| 317 | * | ||
| 318 | * @param query The basic query for selecting blog entries. | ||
| 319 | *### | ||
| 320 | #macro(getBlogEntriesBaseQuery $query) | ||
| 321 | #getAllBlogPostsQuery($query) | ||
| 322 | #end | ||
| 323 | ## | ||
| 324 | ## | ||
| 325 | ## | ||
| 326 | #** | ||
| 327 | * Checks if the provided blog is global or in-space. | ||
| 328 | * | ||
| 329 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>blogType</tt> property set. | ||
| 330 | * @param isGlobal The resulting boolean. If the blog object does not define anything, it is considered in-space. | ||
| 331 | *### | ||
| 332 | #macro(isBlogGlobal $blogDoc $isGlobal) | ||
| 333 | #set($isGlobal = false) | ||
| 334 | #getBlogProperty($blogDoc 'blogType' '' $discard) | ||
| 335 | #if($discard == 'global') | ||
| 336 | #set($isGlobal = true) | ||
| 337 | #end | ||
| 338 | #end | ||
| 339 | ## | ||
| 340 | ## | ||
| 341 | ## | ||
| 342 | #** | ||
| 343 | * Determines how is the blog index split into pages: paginated (fixed number of entries), weekly (all entries in a | ||
| 344 | * week), monthly (all entries in a month), or all. | ||
| 345 | * | ||
| 346 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object with the <tt>displayType</tt> | ||
| 347 | * property set. | ||
| 348 | * @param displayType The resulting string. If the blog object does not define anything, it is considered paginated. | ||
| 349 | *### | ||
| 350 | #macro(getBlogDisplayType $blogDoc $displayType) | ||
| 351 | #getBlogProperty($blogDoc 'displayType' 'paginated' $result) | ||
| 352 | #set ($displayType = $NULL) | ||
| 353 | #setVariable ("$displayType" $result) | ||
| 354 | #end | ||
| 355 | ## | ||
| 356 | ## | ||
| 357 | ## | ||
| 358 | #** | ||
| 359 | * Displays a list of entries. | ||
| 360 | * | ||
| 361 | * @param entries The entries to display, a list of XDocument names. | ||
| 362 | * @param displaying What exactly is displayed: blog index, a single blog entry, a blog category, search results, | ||
| 363 | * unpublished entries, etc. This will be used as the classname(s) for the container div (hfeed). Currently | ||
| 364 | * used values: index, single, category, search, unpublished, hidden. | ||
| 365 | * @param onlyExtract If <tt>true</tt>, only display the extract of articles where available, otherwise display the full content. | ||
| 366 | * @param shouldDisplayTitles If <tt>true</tt>, display the blog title (blog posts shouldn't display the title when they're | ||
| 367 | * displayed alone on their page since it's the page title which is used in this case) | ||
| 368 | *### | ||
| 369 | #macro(displayBlog $entries $displaying $onlyExtract $shouldDisplayTitles) | ||
| 370 | #set($blogDay = '') | ||
| 371 | <div class="hfeed $!{displaying}"> | ||
| 372 | <div class="blogDay"> | ||
| 373 | #foreach ($entryDoc in $xwiki.wrapDocs($entries)) | ||
| 374 | #getEntryObject($entryDoc $entryObj) | ||
| 375 | ## Although all entries should have one of the two objects, better check to be sure. | ||
| 376 | #if("$!{entryObj}" != '') | ||
| 377 | #getEntryDate($entryDoc $entryObj $entryDate) | ||
| 378 | ## Display a "calendar sheet" for each day. All entries posted on the same day share one such sheet. | ||
| 379 | #set($entryDateStr = $xwiki.formatDate($entryDate, 'yyyyMMMMdd')) | ||
| 380 | #if($blogDay != $entryDateStr) | ||
| 381 | #if($blogDay != '') | ||
| 382 | </div> | ||
| 383 | <div class="blogDay"> | ||
| 384 | #end | ||
| 385 | #displayBlogDate($entryDate) | ||
| 386 | #set ($blogDay = $entryDateStr) | ||
| 387 | #end | ||
| 388 | ## Finally, display the entry. | ||
| 389 | #displayEntry($entryDoc $entryObj $onlyExtract $shouldDisplayTitles) | ||
| 390 | #end | ||
| 391 | #end | ||
| 392 | </div> ## blogDay | ||
| 393 | </div> ## hfeed | ||
| 394 | #end | ||
| 395 | ## | ||
| 396 | ## | ||
| 397 | ## | ||
| 398 | #** | ||
| 399 | * Get the entry object, either a new BlogPost or an old Article. | ||
| 400 | * | ||
| 401 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 402 | * @param entryObj The resulting xobject of the blog post. | ||
| 403 | *### | ||
| 404 | #macro(getEntryObject $entryDoc $entryObj) | ||
| 405 | #set($entryObj = '') | ||
| 406 | #set($entryObj = $entryDoc.getObject("${blogPostClassname}")) | ||
| 407 | #if("$!{entryObj}" == '') | ||
| 408 | #set($entryObj = $entryDoc.getObject("${oldArticleClassname}")) | ||
| 409 | #end | ||
| 410 | #end | ||
| 411 | ## | ||
| 412 | ## | ||
| 413 | ## | ||
| 414 | #** | ||
| 415 | * Gets the date associated with a blog entry. This is the publication date. For unpublished entries, initially this is | ||
| 416 | * the document creation date, but can be edited by the user. | ||
| 417 | * | ||
| 418 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 419 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 420 | * @param result The resulting date, an instance of <tt>java.util.Date</tt>. | ||
| 421 | *### | ||
| 422 | #macro(getEntryDate $entryDoc $entryObj $result) | ||
| 423 | #set($result = $entryObj.getProperty('publishDate').value) | ||
| 424 | #end | ||
| 425 | ## | ||
| 426 | ## | ||
| 427 | ## | ||
| 428 | #** | ||
| 429 | * Displays a date, nicely formatted as a calendar page. | ||
| 430 | * | ||
| 431 | * @param date The date to display, an instance of <tt>java.util.Date</tt>. | ||
| 432 | *### | ||
| 433 | #macro(displayBlogDate $date) | ||
| 434 | #set($year = $xwiki.formatDate($date, 'yyyy')) | ||
| 435 | ## 3 letter month name, like Jan, Dec. | ||
| 436 | #set($month = $xwiki.formatDate($date, 'MMM')) | ||
| 437 | ## Uncomment to get a full length month name, like January, December. | ||
| 438 | ## TODO: this could be defined somewhere in the blog style. | ||
| 439 | ## #set($month = $xwiki.formatDate($date, 'MMMM')) | ||
| 440 | #set($day = $xwiki.formatDate($date, 'dd')) | ||
| 441 | <h2 class="blogdate">## title="#formatdateISO($date)"> | ||
| 442 | <span class="month">$month</span> | ||
| 443 | <span class="day">$day</span> | ||
| 444 | <span class="year">$year</span> | ||
| 445 | </h2> | ||
| 446 | #end | ||
| 447 | ## | ||
| 448 | ## | ||
| 449 | ## | ||
| 450 | #** | ||
| 451 | * Displays a blog article: management tools, header, content, footer. | ||
| 452 | * | ||
| 453 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 454 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 455 | * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. | ||
| 456 | * @param shouldDisplayTitle If <tt>true</tt>, display the blog title (blog posts shouldn't display the title | ||
| 457 | * when they're displayed alone on their page since it's the page title which is used in this case) | ||
| 458 | *### | ||
| 459 | #macro(displayEntry $entryDoc $entryObj $onlyExtract $shouldDisplayTitle) | ||
| 460 | ## Only articles with an explicit hidden setting or an explicit unpublished setting are hidden | ||
| 461 | #isPublished($entryObj $isPublished) | ||
| 462 | #isHidden($entryObj $isHidden) | ||
| 463 | #if($doc.fullName == $entryDoc.fullName) | ||
| 464 | <div class="hentry single-article"> | ||
| 465 | #else | ||
| 466 | <div class="hentry#if(!$isPublished) unpublished-article#elseif($isHidden) hidden-article#end"> | ||
| 467 | #end | ||
| 468 | #displayEntryTools($entryDoc $entryObj) | ||
| 469 | #if($shouldDisplayTitle) | ||
| 470 | #displayEntryTitle($entryDoc $entryObj) | ||
| 471 | #end | ||
| 472 | #if($doc.fullName == $entryDoc.fullName) | ||
| 473 | #if(!$isPublished) | ||
| 474 | #warning($msg.get('xe.blog.code.published')) | ||
| 475 | #elseif($isHidden) | ||
| 476 | #warning($msg.get('xe.blog.code.hidden')) | ||
| 477 | #end | ||
| 478 | #end | ||
| 479 | #displayEntryContent($entryDoc $entryObj $onlyExtract) | ||
| 480 | #displayEntryFooter($entryDoc $entryObj) | ||
| 481 | </div> ## hentry | ||
| 482 | #end | ||
| 483 | ## | ||
| 484 | ## | ||
| 485 | ## | ||
| 486 | #** | ||
| 487 | * Checks if the provided blog is published or not. | ||
| 488 | * | ||
| 489 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 490 | * @param isPublished The resulting boolean, true if the entry is considered published. | ||
| 491 | *### | ||
| 492 | #macro(isPublished $entryObj $isPublished) | ||
| 493 | ## This should work for both old articles, which don't have the 'published' property at all, and | ||
| 494 | ## are considered published by default, and new entries, that should have 1 if published. | ||
| 495 | #set($isPublished = ("$!{entryObj.getProperty('published').value}" != '0')) | ||
| 496 | #end | ||
| 497 | ## | ||
| 498 | ## | ||
| 499 | ## | ||
| 500 | #** | ||
| 501 | * Checks if the provided blog is hidden or not. | ||
| 502 | * | ||
| 503 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass<tt> xclass. | ||
| 504 | * @param isHiddel The resulting boolean, true if the entry is considered hidden. | ||
| 505 | *### | ||
| 506 | #macro(isHidden $entryObj $isHidden) | ||
| 507 | ## This should work for both old articles, which don't have the 'hidden' property at all, and | ||
| 508 | ## are considered visible by default, and new entries, that should have 1 if hidden. | ||
| 509 | #set($isHidden = ("$!{entryObj.getProperty('hidden').value}" == '1')) | ||
| 510 | #end | ||
| 511 | ## | ||
| 512 | ## | ||
| 513 | ## | ||
| 514 | #** | ||
| 515 | * Displays several "tools" for manipulating blog posts: hide/show, publish, edit. | ||
| 516 | * | ||
| 517 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 518 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 519 | *### | ||
| 520 | #macro(displayEntryTools $entryDoc $entryObj) | ||
| 521 | #if($context.action == 'view') | ||
| 522 | {{html wiki="false"}} | ||
| 523 | <div class="blog-entry-toolbox"> | ||
| 524 | #displayPublishButton($entryDoc $entryObj) | ||
| 525 | #displayHideShowButton($entryDoc $entryObj) | ||
| 526 | #displayEditButton($entryDoc $entryObj) | ||
| 527 | #displayDeleteButton($entryDoc $entryObj) | ||
| 528 | </div> | ||
| 529 | {{/html}} | ||
| 530 | #end | ||
| 531 | #end | ||
| 532 | ## | ||
| 533 | ## | ||
| 534 | ## | ||
| 535 | #** | ||
| 536 | * Displays the publish button to the entry <strong>creator</strong>, if the article is not published yet. | ||
| 537 | * | ||
| 538 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 539 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 540 | * @todo AJAX calls. | ||
| 541 | *### | ||
| 542 | #macro(displayPublishButton $entryDoc $entryObj) | ||
| 543 | #isPublished($entryObj $isPublished) | ||
| 544 | #if(!$isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName)) | ||
| 545 | <a href="$blogPublisher.getURL('view', "entryName=${escapetool.url($entryDoc.fullName)}&xredirect=${escapetool.url($thisURL)}")" title="${escapetool.xml($msg.get('xe.blog.code.notpublished'))}">#toolImage('page_white_world' 'publish ')</a>## | ||
| 546 | #end | ||
| 547 | #end | ||
| 548 | ## | ||
| 549 | ## | ||
| 550 | ## | ||
| 551 | #** | ||
| 552 | * Displays the hide or show button to the entry <strong>creator</strong>, if the article is already published. | ||
| 553 | * | ||
| 554 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 555 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 556 | *### | ||
| 557 | #macro(displayHideShowButton $entryDoc $entryObj) | ||
| 558 | #isPublished($entryObj $isPublished) | ||
| 559 | #isHidden($entryObj $isHidden) | ||
| 560 | ## Only published articles can be hidden. Unpublished articles are considered already hidden. | ||
| 561 | #if($isPublished && $entryDoc.creator == $context.user && $xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName)) | ||
| 562 | #if ($isHidden) | ||
| 563 | <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)}")" title="${escapetool.xml($msg.get('xe.blog.code.makevisible'))}">#toolImage('lock_open', 'show ')</a>## | ||
| 564 | #else | ||
| 565 | <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)}")" title="${escapetool.xml($msg.get('xe.blog.code.hide'))}">#toolImage('lock' 'hide ')</a>## | ||
| 566 | #end | ||
| 567 | #end | ||
| 568 | #end | ||
| 569 | ## | ||
| 570 | ## | ||
| 571 | ## | ||
| 572 | #** | ||
| 573 | * Displays the edit button to those that can edit the article. | ||
| 574 | * | ||
| 575 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 576 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 577 | *### | ||
| 578 | #macro(displayEditButton $entryDoc $entryObj) | ||
| 579 | #if($xwiki.hasAccessLevel('edit', $context.user, $entryDoc.fullName)) | ||
| 580 | <a href="$entryDoc.getURL('inline')" title="${escapetool.xml($msg.get('xe.blog.code.editpost'))}">#toolImage('pencil' 'edit ')</a>## | ||
| 581 | #end | ||
| 582 | #end | ||
| 583 | ## | ||
| 584 | ## | ||
| 585 | ## | ||
| 586 | #** | ||
| 587 | * Displays the delete button to those that can edit the article. | ||
| 588 | * | ||
| 589 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 590 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 591 | * @todo AJAX calls. | ||
| 592 | *### | ||
| 593 | #macro(displayDeleteButton $entryDoc $entryObj) | ||
| 594 | #if($xwiki.hasAccessLevel('delete', $context.user, $entryDoc.fullName)) | ||
| 595 | <a href="$entryDoc.getURL('delete')" title="${escapetool.xml($msg.get('xe.blog.code.deletepost'))}">#toolImage('cross' 'delete ')</a>## | ||
| 596 | #end | ||
| 597 | #end | ||
| 598 | ## | ||
| 599 | ## | ||
| 600 | ## | ||
| 601 | #** | ||
| 602 | * Displays the title of the entry. | ||
| 603 | * | ||
| 604 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 605 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 606 | *### | ||
| 607 | #macro(displayEntryTitle $entryDoc $entryObj) | ||
| 608 | {{html wiki="false"}} | ||
| 609 | #if($doc.fullName == $entryDoc.fullName) | ||
| 610 | <h1 class="entry-title">$entryDoc.display('title', 'view', $entryObj)</h1> | ||
| 611 | #else | ||
| 612 | <h3 class="entry-title"><a href="$entryDoc.getURL()">$entryDoc.display('title', 'view', $entryObj)</a></h3> | ||
| 613 | #end | ||
| 614 | {{/html}} | ||
| 615 | #end | ||
| 616 | ## | ||
| 617 | ## | ||
| 618 | ## | ||
| 619 | #** | ||
| 620 | * Displays the body of the entry. | ||
| 621 | * | ||
| 622 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 623 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 624 | * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. | ||
| 625 | *### | ||
| 626 | #macro(displayEntryContent $entryDoc $entryObj $onlyExtract) | ||
| 627 | #set($entryContent = '') | ||
| 628 | <div class="#if($onlyExtract)entry-summary#{else}entry-content#end"> | ||
| 629 | #getEntryContent($entryDoc $entryObj $onlyExtract $entryContent) | ||
| 630 | {{html wiki="false"}}$entryDoc.getRenderedContent($entryContent, $entryDoc.getSyntax().toIdString()){{/html}} | ||
| 631 | </div> ## entry-content | ||
| 632 | #end | ||
| 633 | ## | ||
| 634 | ## | ||
| 635 | ## | ||
| 636 | #** | ||
| 637 | * Extracts the body of the entry that should be displayed. If <tt>onlyExtract</tt> is <tt>true</tt>, display the content | ||
| 638 | * of the <tt>extract</tt> field (if not empty). | ||
| 639 | * | ||
| 640 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 641 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 642 | * @param onlyExtract If <tt>true</tt>, try to display only a summary of the entry, instead of the full content. | ||
| 643 | * @param entryContent The resulting content. | ||
| 644 | *### | ||
| 645 | #macro(getEntryContent $entryDoc $entryObj $onlyExtract $entryContent) | ||
| 646 | #if($onlyExtract) | ||
| 647 | #set($entryContent = $entryObj.getProperty('extract').value) | ||
| 648 | #end | ||
| 649 | #if("$!entryContent" == '') | ||
| 650 | #set($entryContent = $entryObj.getProperty('content').value) | ||
| 651 | #* Disabled until the content can be cleanly cut. | ||
| 652 | * #if($onlyExtract && $content.length()>$maxchars) | ||
| 653 | * #set($i = $content.lastIndexOf(" ", $maxchars)) | ||
| 654 | * #set($i = $i + 1) | ||
| 655 | * #set($content = "${content.substring(0,$i)} *[...>${entryDoc.fullName}]*") | ||
| 656 | * #end | ||
| 657 | ## *### | ||
| 658 | #else | ||
| 659 | #if($entryDoc.syntax == 'xwiki/1.0') | ||
| 660 | #set($entryContent = "${entryContent} <a href='${entryDoc.getURL()}' title='$msg.get('xe.blog.code.readpost')'>...</a>") | ||
| 661 | #else | ||
| 662 | #set($entryContent = "${entryContent} [[...>>${entryDoc}||title='$msg.get('xe.blog.code.readpost')']]") | ||
| 663 | #end | ||
| 664 | #end | ||
| 665 | #end | ||
| 666 | ## | ||
| 667 | ## | ||
| 668 | ## | ||
| 669 | #** | ||
| 670 | * Displays the footer of the entry. | ||
| 671 | * | ||
| 672 | * @param entryDoc The xdocument of the blog post. Each post resides in its own document. | ||
| 673 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 674 | *### | ||
| 675 | #macro(displayEntryFooter $entryDoc $entryObj) | ||
| 676 | {{html wiki="false"}} | ||
| 677 | <div class="entry-footer"> | ||
| 678 | #isPublished($entryObj $isPublished) | ||
| 679 | #if($isPublished) | ||
| 680 | $msg.get('xe.blog.code.postedby') ## | ||
| 681 | #else | ||
| 682 | $msg.get('xe.blog.code.createdby') ## | ||
| 683 | #end | ||
| 684 | <address class="author vcard">#userfn($entryDoc.creator)</address> ## | ||
| 685 | #getEntryDate($entryDoc $entryObj $entryDate) | ||
| 686 | #listCategories($entryObj) ## | ||
| 687 | ## Since the publish date and update date are not set at the exact same time, there could be a small difference that | ||
| 688 | ## we assume cannot be more than 3 seconds. | ||
| 689 | | <a href="$entryDoc.getURL('view')" rel="bookmark">$msg.get('xe.blog.code.permalink')</a> ## | ||
| 690 | | <a href="$entryDoc.getURL('view', '#Comments')">$entryDoc.comments.size() $msg.get('xe.blog.code.comments')</a> ## | ||
| 691 | </div> ## entry-footer | ||
| 692 | {{/html}} | ||
| 693 | #end | ||
| 694 | ## | ||
| 695 | ## | ||
| 696 | ## | ||
| 697 | #** | ||
| 698 | * List the categories an entry belongs to. Used in the footer. The categories are instances of <tt>Blog.CategoryClass</tt>. | ||
| 699 | * | ||
| 700 | * @param entryObj The xobject of the blog post, an instance of the <tt>Blog.BlogPostClass</tt> xclass. | ||
| 701 | *### | ||
| 702 | #macro(listCategories $entryObj) | ||
| 703 | #if($entryObj.getxWikiClass().getName() == $blogPostClassname) | ||
| 704 | #set($categories = $entryObj.getProperty('category').value) | ||
| 705 | #set($first = true) | ||
| 706 | #if($categories.size() > 0) | ||
| 707 | #foreach($category in $categories) | ||
| 708 | ## Do not indent | ||
| 709 | #set($categoryDoc = $!xwiki.getDocument($category)) | ||
| 710 | #if(!$categoryDoc.isNew() && $categoryDoc.getObject(${blogCategoryClassname})) | ||
| 711 | #if($first) | ||
| 712 | | $msg.get('xe.blog.code.categories') | ||
| 713 | #set($first = false) | ||
| 714 | #else, #end## if first | ||
| 715 | <a rel="tag" href="$xwiki.getURL(${category})">$!{escapetool.xml($!xwiki.getDocument($category).getObject($blogCategoryClassname).getProperty('name').value)}</a>## | ||
| 716 | #end## if isNew | ||
| 717 | #end## foreach | ||
| 718 | #end | ||
| 719 | #end | ||
| 720 | #end | ||
| 721 | ## | ||
| 722 | ## | ||
| 723 | ## | ||
| 724 | #** | ||
| 725 | * Displays blog pagination links (older and newer entries). | ||
| 726 | * | ||
| 727 | * @param blogDoc the XDocument holding the blog definition object. | ||
| 728 | *### | ||
| 729 | #macro(displayNavigationLinks $blogDoc) | ||
| 730 | <div class="clearfloats"></div> | ||
| 731 | #getBlogDisplayType($blogDoc $displayType) | ||
| 732 | #if($displayType == 'weekly') | ||
| 733 | <div class="pagingLinks"> | ||
| 734 | #getRequestedWeek($weekDate) | ||
| 735 | $weekDate.addWeeks(-1)## | ||
| 736 | (% class="prevPage" %)**[[« $msg.get('xe.blog.code.previousweek')>>$doc.name?year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear]]**(%%) | ||
| 737 | #sep() | ||
| 738 | $weekDate.addWeeks(2)## 2 because we already subtracted 1 above | ||
| 739 | (% class="nextPage" %)**[[$msg.get('xe.blog.code.nextweek') »>>$doc.name?year=$weekDate.weekyear&week=$weekDate.weekOfWeekyear]]**(%%) | ||
| 740 | </div> | ||
| 741 | #elseif($displayType == 'monthly') | ||
| 742 | <div class="pagingLinks"> | ||
| 743 | #getRequestedMonth($monthDate) | ||
| 744 | $monthDate.addMonths(-1)## | ||
| 745 | (% class="prevPage" %)**[[« $msg.get('xe.blog.code.previousmonth')>>$doc.name?year=$monthDate.year&month=$monthDate.monthOfYear]]**(%%) | ||
| 746 | #sep() | ||
| 747 | $monthDate.addMonths(2)## 2 because we already subtracted 1 above | ||
| 748 | (% class="nextPage" %)**[[$msg.get('xe.blog.code.nextmonth') »>>$doc.name?year=$monthDate.year&month=$monthDate.monthOfYear]]**(%%) | ||
| 749 | </div> | ||
| 750 | #elseif($displayType == 'all') | ||
| 751 | #else | ||
| 752 | ## Paginated | ||
| 753 | #if(($totalPages > 1)) | ||
| 754 | #set($queryString = "") | ||
| 755 | #foreach($p in $request.getParameterNames()) | ||
| 756 | #if($p != 'page' && $p != 'ipp') | ||
| 757 | #foreach($v in $request.getParameterValues($p)) | ||
| 758 | #set($queryString = "${queryString}&${p}=${v}") | ||
| 759 | #end | ||
| 760 | #end | ||
| 761 | #end | ||
| 762 | <div class="pagingLinks"> | ||
| 763 | #if ($currentPageNumber < $totalPages) | ||
| 764 | #set($currentPageNumber = $currentPageNumber + 1) | ||
| 765 | (% class="prevPage" %)**[[« $msg.get('xe.blog.code.olderposts')>>$doc.name?page=${currentPageNumber}&ipp=${itemsPerPage}$queryString]]**(%%) | ||
| 766 | #set($currentPageNumber = $currentPageNumber - 1) | ||
| 767 | #end | ||
| 768 | #if ($currentPageNumber > 1) | ||
| 769 | #if ($currentPageNumber < $totalPages) | ||
| 770 | #sep() | ||
| 771 | #end | ||
| 772 | #set($currentPageNumber = $currentPageNumber - 1) | ||
| 773 | (% class="nextPage" %)**[[$msg.get('xe.blog.code.newerposts') »>>$doc.name?page=${currentPageNumber}&ipp=${itemsPerPage}$queryString]]**(%%) | ||
| 774 | #set($currentPageNumber = $currentPageNumber + 1) | ||
| 775 | #end | ||
| 776 | <span class="clear"></span> | ||
| 777 | </div> ## pagingLinks | ||
| 778 | #end | ||
| 779 | #end | ||
| 780 | #end | ||
| 781 | ## | ||
| 782 | ## | ||
| 783 | ## | ||
| 784 | #** | ||
| 785 | * Displays a message box with "publish" icon. | ||
| 786 | * | ||
| 787 | * @param message A text message concerning blog article publishing | ||
| 788 | *### | ||
| 789 | #macro(publishMessageBox $message) | ||
| 790 | <div class="plainmessage publish-message">$message</div> | ||
| 791 | #end | ||
| 792 | #** | ||
| 793 | * Displays a message box with "show/hide" icon. | ||
| 794 | * | ||
| 795 | * @param message A text message concerning blog article hiding | ||
| 796 | *### | ||
| 797 | #macro(hideMessageBox $message) | ||
| 798 | <div class="plainmessage hide-message">$message</div> | ||
| 799 | #end | ||
| 800 | ## | ||
| 801 | ## | ||
| 802 | ## | ||
| 803 | #** | ||
| 804 | * Determine the requested week, for using in a weekly-indexed blog. The relevant request parameters are | ||
| 805 | * <tt>year</tt> and <tt>week</tt>. By default, the current week is used. | ||
| 806 | * | ||
| 807 | * @param monthDate The resulting week, a JODATime MutableDateTime. | ||
| 808 | *### | ||
| 809 | #macro(getRequestedWeek $weekDate) | ||
| 810 | #set($weekDate = $xwiki.jodatime.mutableDateTime) | ||
| 811 | #if("$!{request.year}" != '') | ||
| 812 | $weekDate.setYear($util.parseInt($request.year)) | ||
| 813 | #end | ||
| 814 | #if("$!{request.week}" != '') | ||
| 815 | $weekDate.setWeekOfWeekyear($util.parseInt($request.week)) | ||
| 816 | #end | ||
| 817 | #end | ||
| 818 | ## | ||
| 819 | ## | ||
| 820 | ## | ||
| 821 | #** | ||
| 822 | * Determine the requested month, for using in a monthly-indexed blog. The relevant request parameters are | ||
| 823 | * <tt>year</tt> and <tt>month</tt>. By default, the current month is used. | ||
| 824 | * | ||
| 825 | * @param monthDate The resulting month, a JODATime MutableDateTime. | ||
| 826 | *### | ||
| 827 | #macro(getRequestedMonth $monthDate) | ||
| 828 | #set($monthDate = $xwiki.jodatime.mutableDateTime) | ||
| 829 | #if("$!{request.year}" != '') | ||
| 830 | $monthDate.setYear($util.parseInt($request.year)) | ||
| 831 | #end | ||
| 832 | #if("$!{request.month}" != '') | ||
| 833 | $monthDate.setMonthOfYear($util.parseInt($request.month)) | ||
| 834 | #end | ||
| 835 | #end | ||
| 836 | ## | ||
| 837 | ## | ||
| 838 | ## | ||
| 839 | #** | ||
| 840 | * Retrieve a blog property (title, display type, etc). | ||
| 841 | * | ||
| 842 | * @param blogDoc The blog document. It should contain a <tt>Blog.BlogClass</tt> object. | ||
| 843 | * @param propertyName The name of the property to be retrieved. One of the <tt>Blog.BlogClass</tt>'s properties. | ||
| 844 | * @param defaultValue The default value to use in case the blog object does not define one. | ||
| 845 | * @param propertyValue The resulting value. | ||
| 846 | *### | ||
| 847 | #macro(getBlogProperty $blogDoc $propertyName $defaultValue $propertyValue) | ||
| 848 | #set($result = "$!{blogDoc.getObject(${blogClassname}).getProperty($propertyName).value}") | ||
| 849 | #if($result == '') | ||
| 850 | #set($result = $defaultValue) | ||
| 851 | #end | ||
| 852 | #set ($propertyValue = $NULL) | ||
| 853 | #setVariable ("$propertyValue" $result) | ||
| 854 | #end | ||
| 855 | |||
| 856 | ## Compatibility helpers from the installed Blog 9.15.15 package. | ||
| 857 | #macro(bindQueryParameters $queryObj $queryParams) | ||
| 858 | #set ($output = $queryObj) | ||
| 859 | #foreach( $key in $queryParams.keySet() ) | ||
| 860 | #set($output = $queryObj.bindValue($key, $queryParams.get($key))) | ||
| 861 | #end | ||
| 862 | #setVariable("$queryObj" $output) | ||
| 863 | #end | ||
| 864 | |||
| 865 | #macro(blog__actionResponseError $status $text $parameters) | ||
| 866 | $response.setStatus($status) | ||
| 867 | #if($request.ajax) | ||
| 868 | $services.localization.render($text, $!parameters) | ||
| 869 | #else | ||
| 870 | {{error}}$services.localization.render($text, $!parameters){{/error}} | ||
| 871 | #end | ||
| 872 | #end | ||
| 873 | |||
| 874 | #macro(displayBlogPostsBasedOnContext $targetDoc $postsVisiblity $layout $layoutParams $limit) | ||
| 875 | #if ($layout == 'link') | ||
| 876 | #set ($macro.paginated = 'no') | ||
| 877 | #end | ||
| 878 | #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) | ||
| 879 | ## Display all posts that are in the default blog space('Blog') or in category 'Blog.%' | ||
| 880 | #getBlogPostsLayout($xwiki.getDocument("${defaultBlogSpace}.WebHome") $postsLayout) | ||
| 881 | #if ("$!layout" == '') | ||
| 882 | #set ($layout = $postsLayout) | ||
| 883 | #end | ||
| 884 | #if ($postsVisiblity == 'recent') | ||
| 885 | {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 886 | #elseif($postsVisiblity == 'unpublished') | ||
| 887 | {{blogpostlist blog="${defaultBlogSpace.replaceAll('~', '~~').replaceAll('"', '~"')}.WebHome" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 888 | #end | ||
| 889 | #elseif($targetDoc.getObject($blogCategoryClassname)) | ||
| 890 | ## Display all posts that are in a category aCategorySpace.aCategory | ||
| 891 | #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) | ||
| 892 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 893 | #if ("$!layout" == '') | ||
| 894 | #set ($layout = $postsLayout) | ||
| 895 | #end | ||
| 896 | #if ($postsVisiblity == 'recent') | ||
| 897 | {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 898 | #elseif($postsVisiblity == 'unpublished') | ||
| 899 | {{blogpostlist category="$targetDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 900 | #end | ||
| 901 | #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') | ||
| 902 | ## Display all posts that are in a category aCategorySpace.% | ||
| 903 | #getBlogDocumentForCategoriesSpace($targetDoc.space $blogDoc) | ||
| 904 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 905 | #if ("$!layout" == '') | ||
| 906 | #set ($layout = $postsLayout) | ||
| 907 | #end | ||
| 908 | #if ($postsVisiblity == 'recent') | ||
| 909 | {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 910 | #elseif($postsVisiblity == 'unpublished') | ||
| 911 | {{blogpostlist category="$targetDoc.space.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 912 | #end | ||
| 913 | #else | ||
| 914 | ## Display all posts in blog space aBlog | ||
| 915 | #getBlogDocument($targetDoc.space $blogDoc) | ||
| 916 | #getBlogPostsLayout($blogDoc $postsLayout) | ||
| 917 | #if ("$!layout" == '') | ||
| 918 | #set ($layout = $postsLayout) | ||
| 919 | #end | ||
| 920 | #if ($postsVisiblity == 'recent') | ||
| 921 | {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='yes' hidden='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 922 | #elseif($postsVisiblity == 'unpublished') | ||
| 923 | {{blogpostlist blog="$blogDoc.fullName.replaceAll('~', '~~').replaceAll('"', '~"')" published='no' layout="$!layout.replaceAll('~', '~~').replaceAll('"', '~"')" layoutParams="$!layoutParams.replaceAll('~', '~~').replaceAll('"', '~"')" paginated="$!macro.paginated" limit="$limit" /}} | ||
| 924 | #end | ||
| 925 | #end | ||
| 926 | #end | ||
| 927 | |||
| 928 | #macro(displayEntryBlogLocation $entryDoc $entryObj) | ||
| 929 | #getBlogPostsLocation($entryDoc.getSpace() $blogPostsLocation) ## | ||
| 930 | #if("$!blogPostsLocation" != "") ## | ||
| 931 | #set($blogSpaceRef = $services.model.resolveSpace($blogPostsLocation)) ## | ||
| 932 | #set($blogDocRef = $services.model.createDocumentReference($services.model.getEntityReference('DOCUMENT', 'default').getName(), $blogSpaceRef)) ## | ||
| 933 | #if($doc.documentReference != $blogDocRef) ## | ||
| 934 | #set($blogDoc = $xwiki.getDocument($blogDocRef)) ## | ||
| 935 | #set($blogObj = $blogDoc.getObject('Blog.BlogClass')) ## | ||
| 936 | #if($blogObj) (% class="blogrefpath" %)((( ## | ||
| 937 | $services.localization.render('blog.code.postedin') {{html clean="false" wiki="false"}} #hierarchy($blogDocRef, {'selfIsActive' : true, 'local': true}) {{/html}} ## | ||
| 938 | )))(%%)## | ||
| 939 | #end | ||
| 940 | #end | ||
| 941 | #end | ||
| 942 | #end | ||
| 943 | |||
| 944 | #macro(getAllBlogPostsQuery $query) | ||
| 945 | #set ($query = $NULL) | ||
| 946 | #setVariable("$query" ", BaseObject as obj, IntegerProperty isPublished, | ||
| 947 | IntegerProperty hidden, DateProperty publishDate | ||
| 948 | where doc.fullName <> '$blogPostTemplate' and | ||
| 949 | obj.name=doc.fullName and obj.className='$blogPostClassname' and | ||
| 950 | isPublished.id.id = obj.id and isPublished.id.name = 'published' and | ||
| 951 | hidden.id.id = obj.id and hidden.id.name='hidden' and | ||
| 952 | publishDate.id.id = obj.id and publishDate.id.name='publishDate' and | ||
| 953 | (doc.creator = '$escapetool.sql($xcontext.user)' or (isPublished.value = 1 and hidden.value = 0))") | ||
| 954 | #end | ||
| 955 | |||
| 956 | #macro(getAllBlogPostsQueryBasedOnDisplayContext $targetDoc $query $queryParams) | ||
| 957 | #set ($query = $NULL) | ||
| 958 | #set ($queryParams = $NULL) | ||
| 959 | #getCategoryAllBlogPostsQuery($resultQuery) | ||
| 960 | #set ($resultQueryParams = {}) | ||
| 961 | #set($sanitizedSpace = $targetDoc.space.replaceAll('([%_!])', '!$1').concat('.%')) | ||
| 962 | #if ($targetDoc.space == $defaultBlogSpace && !$targetDoc.getObject($blogCategoryClassname)) | ||
| 963 | ## Get all posts that are in the default blog space('Blog') or in category 'Blog.%' | ||
| 964 | #set ($discard = $resultQueryParams.put('space', $targetDoc.space)) | ||
| 965 | #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) | ||
| 966 | #set($resultQuery = "${resultQuery} and (doc.space = :space or catList like :catList escape '!')") | ||
| 967 | #elseif($targetDoc.getObject($blogCategoryClassname)) | ||
| 968 | ## Get all posts that are in a category aCategorySpace.aCategory | ||
| 969 | #set ($discard = $resultQueryParams.put('catList', $targetDoc.fullName)) | ||
| 970 | #set($resultQuery = "${resultQuery} and (catList=:catList)") | ||
| 971 | #elseif($targetDoc.getObject('XWiki.DocumentSheetBinding').sheet == 'Blog.CategoriesSheet') | ||
| 972 | ## Get all posts that are in a category aCategorySpace.% | ||
| 973 | #set ($discard = $resultQueryParams.put('catList', $sanitizedSpace)) | ||
| 974 | ## Exclude incategorized posts | ||
| 975 | #set ($excludedCategory = "${targetDoc.space}.WebHome") | ||
| 976 | #if ($targetDoc.space == $defaultBlogSpace) | ||
| 977 | #set ($excludedCategory = "Blog.Categories.WebHome") | ||
| 978 | #end | ||
| 979 | #set ($discard = $resultQueryParams.put('excludedCategory', $excludedCategory)) | ||
| 980 | #set($resultQuery = "${resultQuery} and (catList<>:excludedCategory) and (catList like :catList escape '!')") | ||
| 981 | #else | ||
| 982 | ## Get all posts in blog space aBlog | ||
| 983 | #getAllBlogPostsQuery($resultQuery) | ||
| 984 | #getBlogPostsLocation($targetDoc.space $postsLocation) | ||
| 985 | #set ($discard = $resultQueryParams.put('space', $postsLocation)) | ||
| 986 | #set($resultQuery = "${resultQuery} and doc.space = :space") | ||
| 987 | #end | ||
| 988 | #setVariable("$query" $resultQuery) | ||
| 989 | #setVariable("$queryParams" $resultQueryParams) | ||
| 990 | #end | ||
| 991 | |||
| 992 | #macro(getBlogCategoriesLocation $blogSpace $categoriesLocation) | ||
| 993 | #getBlogDocument($blogSpace $blogDoc) | ||
| 994 | ## Since 9.15, category data may exist in Blog or Blog.Categories. Code supports both paths to maintain backward compatibility. | ||
| 995 | #set ($defaultBlogCategoryLocation = 'Blog.Categories') | ||
| 996 | #if ($services.blog.hasLegacyCategoryAssignments()) | ||
| 997 | #set ($defaultBlogCategoryLocation = 'Blog') | ||
| 998 | #end | ||
| 999 | #getBlogProperty($blogDoc 'categoriesLocation' $defaultBlogCategoryLocation $result) | ||
| 1000 | #set ($postsLocation = $NULL) | ||
| 1001 | #setVariable ("$categoriesLocation" $result) | ||
| 1002 | #end | ||
| 1003 | |||
| 1004 | #macro(getBlogDocumentForCategoriesSpace $categoriesSpace $blogDoc) | ||
| 1005 | #set($macro.blogDocs = $services.query.hql(", BaseObject obj, StringProperty as categoriesLocationProp where obj.name = doc.fullName and obj.className = '$blogClassname' and obj.id=categoriesLocationProp.id.id and categoriesLocationProp.id.name='categoriesLocation' and categoriesLocationProp.value=:categoriesLocation order by doc.creationDate").setLimit(1).setOffset(0).bindValue('categoriesLocation', $categoriesSpace).execute()) | ||
| 1006 | #if($macro.blogDocs.size() > 0 && $categoriesSpace != $defaultBlogSpace) | ||
| 1007 | #set($macro.result = $xwiki.getDocument($macro.blogDocs.get(0))) | ||
| 1008 | #else | ||
| 1009 | ## Fallback to Blog.WebHome, the default blog | ||
| 1010 | #set($macro.result = $xwiki.getDocument('Blog.WebHome')) | ||
| 1011 | #end | ||
| 1012 | #set ($blogDoc = $NULL) | ||
| 1013 | #setVariable ("$blogDoc" $macro.result) | ||
| 1014 | #end | ||
| 1015 | |||
| 1016 | #macro(getBlogPostsLayout $blogDoc $postsLayout) | ||
| 1017 | #getBlogProperty($blogDoc 'postsLayout' 'full' $res) | ||
| 1018 | #set ($postsLayout = $NULL) | ||
| 1019 | #setVariable ("$postsLayout" $res) | ||
| 1020 | #end | ||
| 1021 | |||
| 1022 | #macro(getBlogPostsLocation $blogSpace $postsLocation) | ||
| 1023 | #getBlogDocument($blogSpace $blogDoc) | ||
| 1024 | #getBlogProperty($blogDoc 'postsLocation' $blogDoc.space $result) | ||
| 1025 | #set ($postsLocation = $NULL) | ||
| 1026 | #setVariable ("$postsLocation" $result) | ||
| 1027 | #end | ||
| 1028 | |||
| 1029 | #macro(getCategoryAllBlogPostsQuery $query) | ||
| 1030 | #set ($query = $NULL) | ||
| 1031 | #getAllBlogPostsQuery($baseQuery) | ||
| 1032 | #set ($baseQuery = $baseQuery.replace('DateProperty publishDate', 'DateProperty publishDate, DBStringListProperty as category left join category.list catList')) | ||
| 1033 | #setVariable("$query" "${baseQuery} and obj.id=category.id.id and category.id.name='category'") | ||
| 1034 | #end | ||
| 1035 | |||
| 1036 | #macro(isDefaultBlog $blogDoc $isDefault) | ||
| 1037 | #set ($result = false) | ||
| 1038 | #if ($blogDoc.space == 'Blog') | ||
| 1039 | #set ($result = true) | ||
| 1040 | #end | ||
| 1041 | #setVariable("$isDefault" $result) | ||
| 1042 | #end | ||
| 1043 | {{/velocity}} | ||
| 1044 | |||
| 1045 | \\ |