From 15efc074843a09a5038a553356555c16489be099 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Sat, 13 Nov 2010 11:15:38 -0800 Subject: [PATCH] Some work on getting routing cleaned up for Orchard.Blogs --HG-- branch : dev --- .../Core/Routable/Services/RoutableService.cs | 4 + .../Modules/Orchard.Blogs/AdminMenu.cs | 6 +- .../Controllers/BlogAdminController.cs | 11 +-- .../Controllers/BlogPostAdminController.cs | 65 +++++++++++++--- .../Drivers/RemoteBlogPublishingDriver.cs | 4 +- .../Extensions/UrlHelperExtensions.cs | 77 +++++++------------ .../Modules/Orchard.Blogs/Models/BlogPart.cs | 5 -- .../Routing/BlogSlugConstraintUpdator.cs | 4 +- .../Orchard.Blogs/Services/BlogPostService.cs | 5 +- .../Orchard.Blogs/Services/BlogService.cs | 7 +- .../Orchard.Blogs/Services/XmlRpcHandler.cs | 3 +- .../Views/BlogPost/ListByArchive.cshtml | 7 +- .../Items/Content-Blog.SummaryAdmin.cshtml | 13 ++-- .../Views/Parts/Blogs.Blog.Manage.cshtml | 3 +- .../Views/Parts/Blogs.BlogArchives.cshtml | 4 +- .../Views/Parts/Blogs.RemotePublishing.cshtml | 6 +- 16 files changed, 133 insertions(+), 91 deletions(-) diff --git a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs index 3bdb6ca78..87e06bcc5 100644 --- a/src/Orchard.Web/Core/Routable/Services/RoutableService.cs +++ b/src/Orchard.Web/Core/Routable/Services/RoutableService.cs @@ -113,6 +113,10 @@ namespace Orchard.Core.Routable.Services { : slug; } + public static string GetChildPath(this IRoutableAspect routableAspect, string slug) { + return string.Format("{0}/{1}", routableAspect.Path, slug); + } + public static string GetEffectiveSlug(this IRoutableAspect routableAspect) { var containerPath = routableAspect.GetContainerPath(); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/AdminMenu.cs b/src/Orchard.Web/Modules/Orchard.Blogs/AdminMenu.cs index 92a33c06c..054ee3cd7 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/AdminMenu.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/AdminMenu.cs @@ -1,5 +1,7 @@ using System.Linq; using Orchard.Blogs.Services; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Localization; using Orchard.UI.Navigation; @@ -30,12 +32,12 @@ namespace Orchard.Blogs { } else if (singleBlog != null) menu.Add(T("Manage Blog"), "1.0", - item => item.Action("Item", "BlogAdmin", new { area = "Orchard.Blogs", blogSlug = singleBlog.Slug }).Permission(Permissions.MetaListBlogs)); + item => item.Action("Item", "BlogAdmin", new { area = "Orchard.Blogs", blogSlug = singleBlog.As().Path }).Permission(Permissions.MetaListBlogs)); if (singleBlog != null) menu.Add(T("Create New Post"), "1.1", item => - item.Action("Create", "BlogPostAdmin", new { area = "Orchard.Blogs", blogSlug = singleBlog.Slug }).Permission(Permissions.PublishBlogPost)); + item.Action("Create", "BlogPostAdmin", new { area = "Orchard.Blogs", blogSlug = singleBlog.As().Path }).Permission(Permissions.PublishBlogPost)); menu.Add(T("Create New Blog"), "1.2", item => diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs index 39a7ddc4a..7b2b1867f 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs @@ -6,6 +6,7 @@ using Orchard.Blogs.Routing; using Orchard.Blogs.Services; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; +using Orchard.Core.Routable.Services; using Orchard.Data; using Orchard.DisplayManagement; using Orchard.Localization; @@ -71,11 +72,11 @@ namespace Orchard.Blogs.Controllers { return View(model); } - if (!blog.Has()) - _contentManager.Publish(blog.ContentItem); + _contentManager.Publish(blog.ContentItem); - _blogSlugConstraint.AddSlug((string)model.Slug); - return Redirect(Url.BlogForAdmin((string)model.Slug)); + var slug = blog.As().GetEffectiveSlug(); + _blogSlugConstraint.AddSlug(slug); + return Redirect(Url.BlogForAdmin(blog)); } public ActionResult Edit(string blogSlug) { @@ -103,7 +104,7 @@ namespace Orchard.Blogs.Controllers { if (!ModelState.IsValid) return View(model); - _blogSlugConstraint.AddSlug(blog.Slug); + _blogSlugConstraint.AddSlug(blog.As().GetEffectiveSlug()); Services.Notifier.Information(T("Blog information updated")); return Redirect(Url.BlogsForAdmin()); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs index e9ca608a0..ae124ea83 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostAdminController.cs @@ -1,9 +1,12 @@ +using System; +using System.Reflection; using System.Web.Mvc; using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; using Orchard.Blogs.Services; using Orchard.ContentManagement; using Orchard.ContentManagement.Aspects; +using Orchard.Core.Contents.Settings; using Orchard.Localization; using Orchard.Mvc.AntiForgery; using Orchard.UI.Admin; @@ -39,7 +42,21 @@ namespace Orchard.Blogs.Controllers { } [HttpPost, ActionName("Create")] + [FormValueRequired("submit.Save")] public ActionResult CreatePOST() { + return CreatePOST(contentItem => { + if (!contentItem.Has() && !contentItem.TypeDefinition.Settings.GetModel().Draftable) + Services.ContentManager.Publish(contentItem); + }); + } + + [HttpPost, ActionName("Create")] + [FormValueRequired("submit.Publish")] + public ActionResult CreateAndPublishPOST() { + return CreatePOST(contentItem => Services.ContentManager.Publish(contentItem)); + } + + public ActionResult CreatePOST(Action conditionallyPublish) { if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't create blog post"))) return new HttpUnauthorizedResult(); @@ -55,11 +72,10 @@ namespace Orchard.Blogs.Controllers { return View(model); } - if (!blogPost.Has()) - Services.ContentManager.Publish(blogPost.ContentItem); + conditionallyPublish(blogPost.ContentItem); Services.Notifier.Information(T("Your {0} has been created.", blogPost.TypeDefinition.DisplayName)); - return Redirect(Url.BlogPostEdit((string)model.Blog.Slug, (int)model.ContentItem.Id)); + return Redirect(Url.BlogPostEdit(blogPost)); } //todo: the content shape template has extra bits that the core contents module does not (remove draft functionality) @@ -82,7 +98,21 @@ namespace Orchard.Blogs.Controllers { } [HttpPost, ActionName("Edit")] - public ActionResult EditPOST(string blogSlug, int postId) { + [FormValueRequired("submit.Save")] + public ActionResult EditPOST(string blogSlug, int postId, string returnUrl) { + return EditPOST(blogSlug, postId, returnUrl, contentItem => { + if (!contentItem.Has() && !contentItem.TypeDefinition.Settings.GetModel().Draftable) + Services.ContentManager.Publish(contentItem); + }); + } + + [HttpPost, ActionName("Edit")] + [FormValueRequired("submit.Publish")] + public ActionResult EditAndPublishPOST(string blogSlug, int postId, string returnUrl) { + return EditPOST(blogSlug, postId, returnUrl, contentItem => Services.ContentManager.Publish(contentItem)); + } + + public ActionResult EditPOST(string blogSlug, int postId, string returnUrl, Action conditionallyPublish) { if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't edit blog post"))) return new HttpUnauthorizedResult(); @@ -103,7 +133,11 @@ namespace Orchard.Blogs.Controllers { } Services.Notifier.Information(T("Your {0} has been saved.", blogPost.TypeDefinition.DisplayName)); - return Redirect(Url.BlogPostEdit((BlogPostPart)model.ContentItem.Get(typeof(BlogPostPart)))); + + if (!String.IsNullOrEmpty(returnUrl)) + return Redirect(returnUrl); + + return Redirect(Url.BlogPostEdit(blogPost)); } [ValidateAntiForgeryTokenOrchard] @@ -142,7 +176,7 @@ namespace Orchard.Blogs.Controllers { ActionResult RedirectToEdit(IContent item) { if (item == null || item.As() == null) return HttpNotFound(); - return RedirectToAction("Edit", new { BlogSlug = item.As().BlogPart.Slug, PostId = item.ContentItem.Id }); + return RedirectToAction("Edit", new { BlogSlug = item.As().Path, PostId = item.ContentItem.Id }); } [ValidateAntiForgeryTokenOrchard] @@ -162,7 +196,7 @@ namespace Orchard.Blogs.Controllers { _blogPostService.Delete(post); Services.Notifier.Information(T("Blog post was successfully deleted")); - return Redirect(Url.BlogForAdmin(blogSlug)); + return Redirect(Url.BlogForAdmin(blog)); } [ValidateAntiForgeryTokenOrchard] @@ -181,7 +215,7 @@ namespace Orchard.Blogs.Controllers { _blogPostService.Publish(post); Services.Notifier.Information(T("Blog post successfully published.")); - return Redirect(Url.BlogForAdmin(blog.Slug)); + return Redirect(Url.BlogForAdmin(blog)); } [ValidateAntiForgeryTokenOrchard] @@ -200,7 +234,7 @@ namespace Orchard.Blogs.Controllers { _blogPostService.Unpublish(post); Services.Notifier.Information(T("Blog post successfully unpublished.")); - return Redirect(Url.BlogForAdmin(blog.Slug)); + return Redirect(Url.BlogForAdmin(blog)); } bool IUpdateModel.TryUpdateModel(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { @@ -211,4 +245,17 @@ namespace Orchard.Blogs.Controllers { ModelState.AddModelError(key, errorMessage.ToString()); } } + + public class FormValueRequiredAttribute : ActionMethodSelectorAttribute { + private readonly string _submitButtonName; + + public FormValueRequiredAttribute(string submitButtonName) { + _submitButtonName = submitButtonName; + } + + public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) { + var value = controllerContext.HttpContext.Request.Form[_submitButtonName]; + return !string.IsNullOrEmpty(value); + } + } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RemoteBlogPublishingDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RemoteBlogPublishingDriver.cs index bf0e240b3..86eb6684f 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RemoteBlogPublishingDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/RemoteBlogPublishingDriver.cs @@ -1,5 +1,7 @@ using JetBrains.Annotations; using Orchard.Blogs.Models; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Drivers; using Orchard.Environment.Extensions; @@ -8,7 +10,7 @@ namespace Orchard.Blogs.Drivers { [OrchardFeature("Orchard.Blogs.RemotePublishing")] public class RemoteBlogPublishingDriver : ContentPartDriver { protected override DriverResult Display(BlogPart part, string displayType, dynamic shapeHelper) { - return ContentShape("Parts_Blogs_RemotePublishing", shape => shape.Slug(part.Slug)); + return ContentShape("Parts_Blogs_RemotePublishing", shape => shape.Path(part.As().Path)); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs index aeb7d170e..4d48c5258 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Extensions/UrlHelperExtensions.cs @@ -1,5 +1,8 @@ using System.Web.Mvc; using Orchard.Blogs.Models; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; +using Orchard.Core.Routable.Services; using Orchard.Mvc.Extensions; namespace Orchard.Blogs.Extensions { @@ -12,92 +15,68 @@ namespace Orchard.Blogs.Extensions { return urlHelper.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}); } - public static string Blog(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Item", "Blog", new {blogSlug, area = "Orchard.Blogs"}); + public static string Blog(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.Action("Item", "Blog", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" }); } - public static string BlogLiveWriterManifest(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.AbsoluteAction(() => urlHelper.Action("LiveWriterManifest", "Blog", new { blogSlug, area = "Orchard.Blogs" })); + public static string BlogLiveWriterManifest(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.AbsoluteAction(() => urlHelper.Action("LiveWriterManifest", "Blog", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" })); } - public static string BlogRsd(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "Blog", new { blogSlug, area = "Orchard.Blogs" })); + public static string BlogRsd(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "Blog", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" })); } - public static string BlogArchiveYear(this UrlHelper urlHelper, string blogSlug, int year) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug, archiveData = year.ToString(), area = "Orchard.Blogs" }); + public static string BlogArchiveYear(this UrlHelper urlHelper, BlogPart blogPart, int year) { + return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As().Path, archiveData = year.ToString(), area = "Orchard.Blogs" }); } - public static string BlogArchiveMonth(this UrlHelper urlHelper, string blogSlug, int year, int month) { - return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug, archiveData = string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); + public static string BlogArchiveMonth(this UrlHelper urlHelper, BlogPart blogPart, int year, int month) { + return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As().Path, archiveData = string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); } - public static string BlogArchiveDay(this UrlHelper urlHelper, string blogSlug, int year, int month, int day) { - return urlHelper.Action("ListByArchive", "BlogPost", new {blogSlug, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs"}); + public static string BlogArchiveDay(this UrlHelper urlHelper, BlogPart blogPart, int year, int month, int day) { + return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As().Path, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs" }); } - public static string BlogForAdmin(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Item", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); + public static string BlogForAdmin(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.Action("Item", "BlogAdmin", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" }); } public static string BlogCreate(this UrlHelper urlHelper) { return urlHelper.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}); } - public static string BlogEdit(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Edit", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); + public static string BlogEdit(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.Action("Edit", "BlogAdmin", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" }); } - public static string BlogRemove(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Remove", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); - } - - public static string BlogPost(this UrlHelper urlHelper, BlogPostPart blogPostPart) { - return urlHelper.BlogPost(blogPostPart.BlogPart.Slug, blogPostPart.Slug); - } - - public static string BlogPost(this UrlHelper urlHelper, string blogSlug, string postSlug) { - return urlHelper.Action("Item", "BlogPost", new {blogSlug, postSlug, area = "Orchard.Blogs"}); + public static string BlogRemove(this UrlHelper urlHelper, BlogPart blogPart) { + return urlHelper.Action("Remove", "BlogAdmin", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" }); } public static string BlogPostCreate(this UrlHelper urlHelper, BlogPart blogPart) { - return urlHelper.BlogPostCreate(blogPart.Slug); + return urlHelper.Action("Create", "BlogPostAdmin", new { blogSlug = blogPart.As().Path, area = "Orchard.Blogs" }); } - public static string BlogPostCreate(this UrlHelper urlHelper, string blogSlug) { - return urlHelper.Action("Create", "BlogPostAdmin", new {blogSlug, area = "Orchard.Blogs"}); + public static string BlogPost(this UrlHelper urlHelper, BlogPostPart blogPostPart) { + return urlHelper.Action("Item", "BlogPost", new { blogSlug = blogPostPart.BlogPart.As().Path, postSlug = blogPostPart.As().GetEffectiveSlug(), area = "Orchard.Blogs" }); } public static string BlogPostEdit(this UrlHelper urlHelper, BlogPostPart blogPostPart) { - return urlHelper.BlogPostEdit(blogPostPart.BlogPart.Slug, blogPostPart.Id); - } - - public static string BlogPostEdit(this UrlHelper urlHelper, string blogSlug, int postId) { - return urlHelper.Action("Edit", "BlogPostAdmin", new {blogSlug, postId, area = "Orchard.Blogs"}); + return urlHelper.Action("Edit", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" }); } public static string BlogPostDelete(this UrlHelper urlHelper, BlogPostPart blogPostPart) { - return urlHelper.BlogPostDelete(blogPostPart.BlogPart.Slug, blogPostPart.Id); - } - - public static string BlogPostDelete(this UrlHelper urlHelper, string blogSlug, int postId) { - return urlHelper.Action("Delete", "BlogPostAdmin", new {blogSlug, postId, area = "Orchard.Blogs"}); + return urlHelper.Action("Delete", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" }); } public static string BlogPostPublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) { - return urlHelper.BlogPostPublish(blogPostPart.BlogPart.Slug, blogPostPart.Id); - } - - public static string BlogPostPublish(this UrlHelper urlHelper, string blogSlug, int postId) { - return urlHelper.Action("Publish", "BlogPostAdmin", new { blogSlug, postId, area = "Orchard.Blogs" }); + return urlHelper.Action("Publish", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" }); } public static string BlogPostUnpublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) { - return urlHelper.BlogPostUnpublish(blogPostPart.BlogPart.Slug, blogPostPart.Id); - } - - public static string BlogPostUnpublish(this UrlHelper urlHelper, string blogSlug, int postId) { - return urlHelper.Action("Unpublish", "BlogPostAdmin", new { blogSlug, postId, area = "Orchard.Blogs" }); + return urlHelper.Action("Unpublish", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" }); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPart.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPart.cs index 7aec67522..d536b89a7 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPart.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPart.cs @@ -9,11 +9,6 @@ namespace Orchard.Blogs.Models { set { this.As().Title = value; } } - public string Slug { - get { return this.As().Slug; } - set { this.As().Slug = value; } - } - public string Description { get { return Record.Description; } set { Record.Description = value; } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogSlugConstraintUpdator.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogSlugConstraintUpdator.cs index bb9abf7cb..b3a5e83f8 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogSlugConstraintUpdator.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogSlugConstraintUpdator.cs @@ -1,6 +1,8 @@ using System.Linq; using JetBrains.Annotations; using Orchard.Blogs.Services; +using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Environment; using Orchard.Tasks; @@ -27,7 +29,7 @@ namespace Orchard.Blogs.Routing { } private void Refresh() { - _blogSlugConstraint.SetSlugs(_blogService.Get().Select(b => b.Slug)); + _blogSlugConstraint.SetSlugs(_blogService.Get().Select(b => b.As().Path)); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs index 18d6158ea..9f1af8756 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogPostService.cs @@ -3,9 +3,11 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using Orchard.Blogs.Models; +using Orchard.ContentManagement.Aspects; using Orchard.Core.Common.Models; using Orchard.ContentManagement; using Orchard.Core.Routable.Models; +using Orchard.Core.Routable.Services; using Orchard.Data; using Orchard.Tasks.Scheduling; @@ -27,8 +29,9 @@ namespace Orchard.Blogs.Services { } public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) { + var postSlug = blogPart.As().GetChildPath(slug); return - _contentManager.Query(versionOptions, "BlogPost").Join().Where(rr => rr.Slug == slug). + _contentManager.Query(versionOptions, "BlogPost").Join().Where(rr => rr.Path == postSlug). Join().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List(). SingleOrDefault().As(); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs index 374c07719..158bcf075 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/BlogService.cs @@ -4,6 +4,7 @@ using JetBrains.Annotations; using Orchard.Blogs.Models; using Orchard.Blogs.Routing; using Orchard.ContentManagement; +using Orchard.ContentManagement.Aspects; using Orchard.Core.Routable.Models; namespace Orchard.Blogs.Services { @@ -17,9 +18,9 @@ namespace Orchard.Blogs.Services { _blogSlugConstraint = blogSlugConstraint; } - public BlogPart Get(string slug) { + public BlogPart Get(string path) { return _contentManager.Query() - .Join().Where(rr => rr.Slug == slug) + .Join().Where(rr => rr.Path == path) .List().FirstOrDefault(); } @@ -32,7 +33,7 @@ namespace Orchard.Blogs.Services { public void Delete(BlogPart blogPart) { _contentManager.Remove(blogPart.ContentItem); - _blogSlugConstraint.RemoveSlug(blogPart.Slug); + _blogSlugConstraint.RemoveSlug(blogPart.As().Path); } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs index 6ffd5b499..a079dc202 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Services/XmlRpcHandler.cs @@ -117,8 +117,9 @@ namespace Orchard.Blogs.Services { var array = new XRpcArray(); foreach (var blog in _blogService.Get()) { + var thisBlog = blog; array.Add(new XRpcStruct() - .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blog.Slug))) + .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(thisBlog))) .Set("blogid", blog.Id) .Set("blogName", blog.Name)); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogPost/ListByArchive.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogPost/ListByArchive.cshtml index 3f1d1f716..a0fe9cbeb 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogPost/ListByArchive.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/BlogPost/ListByArchive.cshtml @@ -1,9 +1,10 @@ @using Orchard.Blogs.Extensions; +@using Orchard.Blogs.Models;

@Html.TitleForPage(T("Archives").Text, (string)Model.ArchiveData.Year.ToString(), (string)(Model.ArchiveData.Month > 0 ? new DateTime(Model.ArchiveData.Year, Model.ArchiveData.Month, 1).ToString("MMMM") : null), (string)(Model.ArchiveData.Day > 0 ? Model.ArchiveData.Day.ToString() : null))

@T("Archives") / -@Html.Link((string)Model.ArchiveData.Year.ToString(), Url.BlogArchiveYear((string)Model.Blog.Slug, (int)Model.ArchiveData.Year)) -@(new MvcHtmlString(Model.ArchiveData.Month > 0 ? string.Format(" / {0}", Html.Link((string)Model.ArchiveData.ToDateTime().ToString("MMMM"), Url.BlogArchiveMonth((string)Model.Blog.Slug,(int) Model.ArchiveData.Year, (int)Model.ArchiveData.Month))) : "")) -@(new MvcHtmlString(Model.ArchiveData.Day > 0 ? string.Format(" / {0}", Html.Link((string)Model.ArchiveData.Day.ToString(), Url.BlogArchiveDay((string)Model.Blog.Slug, (int)Model.ArchiveData.Year, (int)Model.ArchiveData.Month, (int)Model.ArchiveData.Day))) : "")) +@Html.Link((string)Model.ArchiveData.Year.ToString(), Url.BlogArchiveYear((BlogPart)Model.Blog, (int)Model.ArchiveData.Year)) +@(new MvcHtmlString(Model.ArchiveData.Month > 0 ? string.Format(" / {0}", Html.Link((string)Model.ArchiveData.ToDateTime().ToString("MMMM"), Url.BlogArchiveMonth((BlogPart)Model.Blog, (int)Model.ArchiveData.Year, (int)Model.ArchiveData.Month))) : "")) +@(new MvcHtmlString(Model.ArchiveData.Day > 0 ? string.Format(" / {0}", Html.Link((string)Model.ArchiveData.Day.ToString(), Url.BlogArchiveDay((BlogPart)Model.Blog, (int)Model.ArchiveData.Year, (int)Model.ArchiveData.Month, (int)Model.ArchiveData.Day))) : ""))
@Display(Model.ContentItems) \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Items/Content-Blog.SummaryAdmin.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Items/Content-Blog.SummaryAdmin.cshtml index 021cd18a0..16b4130bc 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Items/Content-Blog.SummaryAdmin.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Items/Content-Blog.SummaryAdmin.cshtml @@ -5,12 +5,13 @@ @{ Script.Require("ShapesBase"); ContentItem contentItem = Model.ContentItem; + BlogPart blog = (BlogPart)contentItem.Get(typeof(BlogPart)); var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString(); }
-

@Html.Link((string)Model.Title, Url.BlogForAdmin((string)Model.Slug))

+

@Html.Link((string)Model.Title, Url.BlogForAdmin((BlogPart)blog))

@if (Model.Header != null) {
@Display(Model.Header)
} @@ -20,11 +21,11 @@
@if (Model.Content != null) {
@Display(Model.Content)
diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Manage.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Manage.cshtml index 1b2740d3e..5a1cf6c42 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Manage.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Manage.cshtml @@ -1,9 +1,10 @@ @using Orchard.Blogs.Extensions; +@using Orchard.Blogs.Models; @{ Style.Require("BlogsAdmin"); } @if (AuthorizedFor(Orchard.Blogs.Permissions.ManageBlogs)) { } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.BlogArchives.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.BlogArchives.cshtml index 9b6c5910b..7d754653f 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.BlogArchives.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.BlogArchives.cshtml @@ -25,14 +25,14 @@ if (year != lastYear) { } } } else if (archives.Count() > 0) { - @Html.UnorderedList(archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((string)Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") + @Html.UnorderedList(archives, (t, i) => Html.Link(string.Format("{0:MMMM yyyy} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((BlogPart)Model.BlogPart, t.Key.Year, t.Key.Month)), "archiveMonthList") } else {
@T("None found")
diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.RemotePublishing.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.RemotePublishing.cshtml index ce4545bc7..576f2bb0f 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.RemotePublishing.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.RemotePublishing.cshtml @@ -1,6 +1,8 @@ @using Orchard.Blogs.Extensions; +@using Orchard.Blogs.Models; @using Orchard.UI.Resources; @{ - RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest((string)Model.Slug) }); - RegisterLink(new LinkEntry { Rel = "EditURI", Type = "application/rsd+xml", Title = "RSD", Href = Url.BlogRsd((string)Model.Slug) }); + BlogPart blog = Model; + RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest(blog) }); + RegisterLink(new LinkEntry { Rel = "EditURI", Type = "application/rsd+xml", Title = "RSD", Href = Url.BlogRsd(blog) }); } \ No newline at end of file