Wiki source code of Manage blogs on this wiki
Last modified by Jan Rhebergen on 2021/02/27 22:16
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{include reference="Blog.BlogCode"/}} |
| 2 | |||
| 3 | {{template name="locationPicker_macros.vm" /}} | ||
| 4 | |||
| 5 | {{velocity}} | ||
| 6 | #if($hasAdmin) | ||
| 7 | ## | ||
| 8 | ## | ||
| 9 | ## List existing blogs. | ||
| 10 | ## TODO: Display the number of articles in each blog | ||
| 11 | ## TODO: Provide some management links: delete, edit title, configure... | ||
| 12 | ## | ||
| 13 | #set ($discard = $xwiki.jsx.use('Blog.Management')) | ||
| 14 | == $services.localization.render('blog.manage.existing') == | ||
| 15 | |||
| 16 | {{blogs/}} | ||
| 17 | ## | ||
| 18 | ## | ||
| 19 | ## New blog | ||
| 20 | ## | ||
| 21 | |||
| 22 | == $services.localization.render('blog.manage.createnew') == | ||
| 23 | |||
| 24 | #if ("$!request.createBlog" != '') | ||
| 25 | #set($title = "$!request.blogTitle") | ||
| 26 | #if($title != '') | ||
| 27 | #set($blogParentPage = "$!request.blogParent") | ||
| 28 | #set($blogPageName = "$!request.blogName") | ||
| 29 | |||
| 30 | #if($blogPageName == '') | ||
| 31 | {{warning}}$services.localization.render('blog.manage.nopage'){{/warning}} | ||
| 32 | |||
| 33 | #else | ||
| 34 | #set($blogDocName = "${blogPageName}") | ||
| 35 | #if ("$!blogParentPage" != '') | ||
| 36 | #set($blogDocName = "${blogParentPage}.${blogDocName}") | ||
| 37 | #end | ||
| 38 | #if ($xwiki.exists("${blogDocName}.WebHome")) | ||
| 39 | {{warning}}$services.localization.render('blog.manage.unallowed_page'){{/warning}} | ||
| 40 | |||
| 41 | #else | ||
| 42 | #if (!$services.csrf.isTokenValid("$!request.form_token")) | ||
| 43 | {{error}}$services.localization.render('platform.wiki.csrf.error'){{/error}} | ||
| 44 | |||
| 45 | #else | ||
| 46 | ## Create the Blog | ||
| 47 | #set ($blogDoc = $xwiki.getDocument("${blogDocName}.WebHome")) | ||
| 48 | #set ($blogObj = $blogDoc.getObject('Blog.BlogClass', true)) | ||
| 49 | #set ($discard = $blogObj.set('title', $title)) | ||
| 50 | #set ($discard = $blogObj.set('displayType', 'paginated')) | ||
| 51 | #set ($discard = $blogObj.set('itemsPerPage', 10)) | ||
| 52 | #set ($categoriesLocation = "${blogDocName}.Categories") | ||
| 53 | #set ($postsLocation = "${blogDocName}") | ||
| 54 | #set ($discard = $blogObj.set('categoriesLocation', $categoriesLocation)) | ||
| 55 | #set ($discard = $blogObj.set('postsLocation', $postsLocation)) | ||
| 56 | #if ("$!request.postsLayout" != '') | ||
| 57 | #set ($discard = $blogObj.set('postsLayout', $request.postsLayout)) | ||
| 58 | #end | ||
| 59 | #set ($discard = $blogDoc.save()) | ||
| 60 | |||
| 61 | ## Create the categories page | ||
| 62 | #set ($categoriesDoc = $xwiki.getDocument("${categoriesLocation}.WebHome")) | ||
| 63 | #set ($sheetBindingObj = $categoriesDoc.getObject('XWiki.DocumentSheetBinding', true)) | ||
| 64 | #set ($discard = $sheetBindingObj.set('sheet', 'Blog.CategoriesSheet')) | ||
| 65 | #set ($discard = $categoriesDoc.save()) | ||
| 66 | |||
| 67 | ## Create the Default categories | ||
| 68 | #if ("$!request.createDefaultCategories" != '') | ||
| 69 | #foreach($categoryName in ['News', 'Other', 'Personal']) | ||
| 70 | #set ($discard = $xwiki.copyDocument("Blog.${categoryName}", "${categoriesLocation}.${categoryName}")) | ||
| 71 | #set ($categoryDoc = $xwiki.getDocument("${categoriesLocation}.${categoryName}")) | ||
| 72 | #set ($discard = $categoryDoc.setParent("${categoriesLocation}.WebHome")) | ||
| 73 | #set ($discard = $categoryDoc.save()) | ||
| 74 | #end | ||
| 75 | #end | ||
| 76 | |||
| 77 | ## Create the WebPreferences page | ||
| 78 | #if ("$!request.enablePanels" != '') | ||
| 79 | #set ($webPreferencesName = "${blogDocName}.WebPreferences") | ||
| 80 | #set ($webPreferencesDoc = $xwiki.getDocument($webPreferencesName)) | ||
| 81 | #set ($discard = $webPreferencesDoc.setHidden(true)) | ||
| 82 | #set ($xwikiPreferencesObj = $webPreferencesDoc.getObject('XWiki.XWikiPreferences', true)) | ||
| 83 | #set ($discard = $xwikiPreferencesObj.set('showRightPanels', 1)) | ||
| 84 | #set ($discard = $xwikiPreferencesObj.set('rightPanels', 'Blog.RecentPostsPanel,Blog.UnpublishedPanel,Blog.CategoriesPanel,Blog.ArchivePanel,Blog.RelatedBlogsPanel,Blog.AllBlogsPanel')) | ||
| 85 | #set ($discard = $webPreferencesDoc.save()) | ||
| 86 | #end | ||
| 87 | |||
| 88 | $response.sendRedirect($blogDoc.getURL()) | ||
| 89 | #end | ||
| 90 | #end | ||
| 91 | #end | ||
| 92 | #else | ||
| 93 | {{warning}}$services.localization.render('blog.manage.notitle'){{/warning}} | ||
| 94 | |||
| 95 | #end | ||
| 96 | #end | ||
| 97 | ## | ||
| 98 | ## Show the form | ||
| 99 | {{html clean="false" wiki="true"}} | ||
| 100 | <form action="${xwiki.getURL('Blog.Management')}" id="newBlog" method="post" class="xform"> | ||
| 101 | #locationPicker({ | ||
| 102 | 'id': 'blogLocation', | ||
| 103 | 'title': { | ||
| 104 | 'label': 'blog.manage.location.title', | ||
| 105 | 'hint': 'blog.manage.location.title.hint', | ||
| 106 | 'name': 'blogTitle', | ||
| 107 | 'value': '', | ||
| 108 | 'placeholder': 'blog.manage.location.title.placeholder' | ||
| 109 | }, | ||
| 110 | 'preview': { | ||
| 111 | 'label': 'core.create.locationPreview.label', | ||
| 112 | 'hint': 'blog.manage.locationPreview.hint' | ||
| 113 | }, | ||
| 114 | 'parent': { | ||
| 115 | 'label': 'core.create.spaceReference.label', | ||
| 116 | 'hint': 'core.create.spaceReference.hint', | ||
| 117 | 'name': 'blogParent', | ||
| 118 | 'reference': $doc.documentReference.parent.parent, | ||
| 119 | 'placeholder': 'core.create.spaceReference.placeholder' | ||
| 120 | }, | ||
| 121 | 'name': { | ||
| 122 | 'label': 'core.create.name.label', | ||
| 123 | 'hint': 'core.create.name.hint', | ||
| 124 | 'name': 'blogName', | ||
| 125 | 'value': '', | ||
| 126 | 'placeholder': 'core.create.name.placeholder' | ||
| 127 | } | ||
| 128 | }) | ||
| 129 | <div> | ||
| 130 | <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> | ||
| 131 | <input type="hidden" name="createBlog" value="1"/> | ||
| 132 | <dl> | ||
| 133 | <dt> | ||
| 134 | <label for="blogSpace">$services.localization.render('blog.manage.categories_location')</label> | ||
| 135 | <span class="xHint">$services.localization.render('blog.manage.categoriesLocationPreview.hint')</span> | ||
| 136 | </dt> | ||
| 137 | <dd><div id="catLocation"> | ||
| 138 | <div class="breadcrumb-container"> | ||
| 139 | <ol id="blogCategoriesLocation" class="breadcrumb"></ol> | ||
| 140 | </div> | ||
| 141 | </dd> | ||
| 142 | </dl> | ||
| 143 | <dl> | ||
| 144 | <dt><label for="blogSpace">$services.localization.render('blog.manage.enable_panels')</label> | ||
| 145 | <input type="checkbox" name="enablePanels" value="1" checked="checked" /> | ||
| 146 | </dt> | ||
| 147 | </dl> | ||
| 148 | <dl> | ||
| 149 | <dt><label for="blogSpace">$services.localization.render('blog.manage.create_default_categories')</label> | ||
| 150 | <input type="checkbox" name="createDefaultCategories" value="1" checked="checked" /> | ||
| 151 | </dt> | ||
| 152 | </dl> | ||
| 153 | <dl> | ||
| 154 | <dt><label for="blogSpace">$services.localization.render('blog.manage.post.layout')</label> | ||
| 155 | #set ( $class = $xwiki.getClass("Blog.BlogClass")) | ||
| 156 | #set ($postLayouts = $class.get('postsLayout').getMapValues()) | ||
| 157 | #set ($postLayoutsList = $class.get('postsLayout').getListValues()) | ||
| 158 | #set ($firstLayout = '') | ||
| 159 | #if ($postLayoutsList.size() > 0) | ||
| 160 | #set ($firstLayout = $postLayoutsList[0]) | ||
| 161 | #end | ||
| 162 | <select name="postsLayout"> | ||
| 163 | #foreach ($item in $postLayouts.entrySet()) | ||
| 164 | #set ($translation = $services.localization.get("Blog.BlogClass_postsLayout.${item.key}")) | ||
| 165 | <option value="${escapetool.xml($item.key)}" #if("$!item.key" == $firstLayout)selected="selected"#end > | ||
| 166 | #if ("$!translation" != '') | ||
| 167 | $!services.localization.render("Blog.BlogClass_postsLayout.${item.key}") | ||
| 168 | #else | ||
| 169 | $!item.value.value | ||
| 170 | #end | ||
| 171 | </option> | ||
| 172 | #end | ||
| 173 | </select> | ||
| 174 | </dt> | ||
| 175 | </dl> | ||
| 176 | <input class="button" type="submit" value="${escapetool.xml($services.localization.render('blog.manage.create'))}"/> | ||
| 177 | </div> | ||
| 178 | </form> | ||
| 179 | {{/html}} | ||
| 180 | #else | ||
| 181 | {{html}} | ||
| 182 | #xwikimessageboxstart($services.localization.render('error') $services.localization.render('notallowed')) | ||
| 183 | #xwikimessageboxend() | ||
| 184 | {{/html}} | ||
| 185 | #end | ||
| 186 | {{/velocity}} |