Some work on getting routing cleaned up for Orchard.Blogs

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-13 11:15:38 -08:00
parent e56c682586
commit 15efc07484
16 changed files with 133 additions and 91 deletions

View File

@@ -113,6 +113,10 @@ namespace Orchard.Core.Routable.Services {
: slug; : 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) { public static string GetEffectiveSlug(this IRoutableAspect routableAspect) {
var containerPath = routableAspect.GetContainerPath(); var containerPath = routableAspect.GetContainerPath();

View File

@@ -1,5 +1,7 @@
using System.Linq; using System.Linq;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Localization; using Orchard.Localization;
using Orchard.UI.Navigation; using Orchard.UI.Navigation;
@@ -30,12 +32,12 @@ namespace Orchard.Blogs {
} }
else if (singleBlog != null) else if (singleBlog != null)
menu.Add(T("Manage Blog"), "1.0", 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<IRoutableAspect>().Path }).Permission(Permissions.MetaListBlogs));
if (singleBlog != null) if (singleBlog != null)
menu.Add(T("Create New Post"), "1.1", menu.Add(T("Create New Post"), "1.1",
item => 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<IRoutableAspect>().Path }).Permission(Permissions.PublishBlogPost));
menu.Add(T("Create New Blog"), "1.2", menu.Add(T("Create New Blog"), "1.2",
item => item =>

View File

@@ -6,6 +6,7 @@ using Orchard.Blogs.Routing;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Services;
using Orchard.Data; using Orchard.Data;
using Orchard.DisplayManagement; using Orchard.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
@@ -71,11 +72,11 @@ namespace Orchard.Blogs.Controllers {
return View(model); return View(model);
} }
if (!blog.Has<IPublishingControlAspect>()) _contentManager.Publish(blog.ContentItem);
_contentManager.Publish(blog.ContentItem);
_blogSlugConstraint.AddSlug((string)model.Slug); var slug = blog.As<IRoutableAspect>().GetEffectiveSlug();
return Redirect(Url.BlogForAdmin((string)model.Slug)); _blogSlugConstraint.AddSlug(slug);
return Redirect(Url.BlogForAdmin(blog));
} }
public ActionResult Edit(string blogSlug) { public ActionResult Edit(string blogSlug) {
@@ -103,7 +104,7 @@ namespace Orchard.Blogs.Controllers {
if (!ModelState.IsValid) if (!ModelState.IsValid)
return View(model); return View(model);
_blogSlugConstraint.AddSlug(blog.Slug); _blogSlugConstraint.AddSlug(blog.As<IRoutableAspect>().GetEffectiveSlug());
Services.Notifier.Information(T("Blog information updated")); Services.Notifier.Information(T("Blog information updated"));
return Redirect(Url.BlogsForAdmin()); return Redirect(Url.BlogsForAdmin());
} }

View File

@@ -1,9 +1,12 @@
using System;
using System.Reflection;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Blogs.Extensions; using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects; using Orchard.ContentManagement.Aspects;
using Orchard.Core.Contents.Settings;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Mvc.AntiForgery; using Orchard.Mvc.AntiForgery;
using Orchard.UI.Admin; using Orchard.UI.Admin;
@@ -39,7 +42,21 @@ namespace Orchard.Blogs.Controllers {
} }
[HttpPost, ActionName("Create")] [HttpPost, ActionName("Create")]
[FormValueRequired("submit.Save")]
public ActionResult CreatePOST() { public ActionResult CreatePOST() {
return CreatePOST(contentItem => {
if (!contentItem.Has<IPublishingControlAspect>() && !contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().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<ContentItem> conditionallyPublish) {
if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't create blog post"))) if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't create blog post")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -55,11 +72,10 @@ namespace Orchard.Blogs.Controllers {
return View(model); return View(model);
} }
if (!blogPost.Has<IPublishingControlAspect>()) conditionallyPublish(blogPost.ContentItem);
Services.ContentManager.Publish(blogPost.ContentItem);
Services.Notifier.Information(T("Your {0} has been created.", blogPost.TypeDefinition.DisplayName)); 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) //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")] [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<IPublishingControlAspect>() && !contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().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<ContentItem> conditionallyPublish) {
if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't edit blog post"))) if (!Services.Authorizer.Authorize(Permissions.EditBlogPost, T("Couldn't edit blog post")))
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
@@ -103,7 +133,11 @@ namespace Orchard.Blogs.Controllers {
} }
Services.Notifier.Information(T("Your {0} has been saved.", blogPost.TypeDefinition.DisplayName)); 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] [ValidateAntiForgeryTokenOrchard]
@@ -142,7 +176,7 @@ namespace Orchard.Blogs.Controllers {
ActionResult RedirectToEdit(IContent item) { ActionResult RedirectToEdit(IContent item) {
if (item == null || item.As<BlogPostPart>() == null) if (item == null || item.As<BlogPostPart>() == null)
return HttpNotFound(); return HttpNotFound();
return RedirectToAction("Edit", new { BlogSlug = item.As<BlogPostPart>().BlogPart.Slug, PostId = item.ContentItem.Id }); return RedirectToAction("Edit", new { BlogSlug = item.As<IRoutableAspect>().Path, PostId = item.ContentItem.Id });
} }
[ValidateAntiForgeryTokenOrchard] [ValidateAntiForgeryTokenOrchard]
@@ -162,7 +196,7 @@ namespace Orchard.Blogs.Controllers {
_blogPostService.Delete(post); _blogPostService.Delete(post);
Services.Notifier.Information(T("Blog post was successfully deleted")); Services.Notifier.Information(T("Blog post was successfully deleted"));
return Redirect(Url.BlogForAdmin(blogSlug)); return Redirect(Url.BlogForAdmin(blog));
} }
[ValidateAntiForgeryTokenOrchard] [ValidateAntiForgeryTokenOrchard]
@@ -181,7 +215,7 @@ namespace Orchard.Blogs.Controllers {
_blogPostService.Publish(post); _blogPostService.Publish(post);
Services.Notifier.Information(T("Blog post successfully published.")); Services.Notifier.Information(T("Blog post successfully published."));
return Redirect(Url.BlogForAdmin(blog.Slug)); return Redirect(Url.BlogForAdmin(blog));
} }
[ValidateAntiForgeryTokenOrchard] [ValidateAntiForgeryTokenOrchard]
@@ -200,7 +234,7 @@ namespace Orchard.Blogs.Controllers {
_blogPostService.Unpublish(post); _blogPostService.Unpublish(post);
Services.Notifier.Information(T("Blog post successfully unpublished.")); Services.Notifier.Information(T("Blog post successfully unpublished."));
return Redirect(Url.BlogForAdmin(blog.Slug)); return Redirect(Url.BlogForAdmin(blog));
} }
bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) { bool IUpdateModel.TryUpdateModel<TModel>(TModel model, string prefix, string[] includeProperties, string[] excludeProperties) {
@@ -211,4 +245,17 @@ namespace Orchard.Blogs.Controllers {
ModelState.AddModelError(key, errorMessage.ToString()); 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);
}
}
} }

View File

@@ -1,5 +1,7 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Environment.Extensions; using Orchard.Environment.Extensions;
@@ -8,7 +10,7 @@ namespace Orchard.Blogs.Drivers {
[OrchardFeature("Orchard.Blogs.RemotePublishing")] [OrchardFeature("Orchard.Blogs.RemotePublishing")]
public class RemoteBlogPublishingDriver : ContentPartDriver<BlogPart> { public class RemoteBlogPublishingDriver : ContentPartDriver<BlogPart> {
protected override DriverResult Display(BlogPart part, string displayType, dynamic shapeHelper) { 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<IRoutableAspect>().Path));
} }
} }
} }

View File

@@ -1,5 +1,8 @@
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Services;
using Orchard.Mvc.Extensions; using Orchard.Mvc.Extensions;
namespace Orchard.Blogs.Extensions { namespace Orchard.Blogs.Extensions {
@@ -12,92 +15,68 @@ namespace Orchard.Blogs.Extensions {
return urlHelper.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}); return urlHelper.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"});
} }
public static string Blog(this UrlHelper urlHelper, string blogSlug) { public static string Blog(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.Action("Item", "Blog", new {blogSlug, area = "Orchard.Blogs"}); return urlHelper.Action("Item", "Blog", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" });
} }
public static string BlogLiveWriterManifest(this UrlHelper urlHelper, string blogSlug) { public static string BlogLiveWriterManifest(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.AbsoluteAction(() => urlHelper.Action("LiveWriterManifest", "Blog", new { blogSlug, area = "Orchard.Blogs" })); return urlHelper.AbsoluteAction(() => urlHelper.Action("LiveWriterManifest", "Blog", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" }));
} }
public static string BlogRsd(this UrlHelper urlHelper, string blogSlug) { public static string BlogRsd(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "Blog", new { blogSlug, area = "Orchard.Blogs" })); return urlHelper.AbsoluteAction(() => urlHelper.Action("Rsd", "Blog", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" }));
} }
public static string BlogArchiveYear(this UrlHelper urlHelper, string blogSlug, int year) { public static string BlogArchiveYear(this UrlHelper urlHelper, BlogPart blogPart, int year) {
return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug, archiveData = year.ToString(), area = "Orchard.Blogs" }); return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As<IRoutableAspect>().Path, archiveData = year.ToString(), area = "Orchard.Blogs" });
} }
public static string BlogArchiveMonth(this UrlHelper urlHelper, string blogSlug, int year, int month) { public static string BlogArchiveMonth(this UrlHelper urlHelper, BlogPart blogPart, int year, int month) {
return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug, archiveData = string.Format("{0}/{1}", year, month), area = "Orchard.Blogs" }); return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As<IRoutableAspect>().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) { public static string BlogArchiveDay(this UrlHelper urlHelper, BlogPart blogPart, 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"}); return urlHelper.Action("ListByArchive", "BlogPost", new { blogSlug = blogPart.As<IRoutableAspect>().Path, archiveData = string.Format("{0}/{1}/{2}", year, month, day), area = "Orchard.Blogs" });
} }
public static string BlogForAdmin(this UrlHelper urlHelper, string blogSlug) { public static string BlogForAdmin(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.Action("Item", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); return urlHelper.Action("Item", "BlogAdmin", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" });
} }
public static string BlogCreate(this UrlHelper urlHelper) { public static string BlogCreate(this UrlHelper urlHelper) {
return urlHelper.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}); return urlHelper.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"});
} }
public static string BlogEdit(this UrlHelper urlHelper, string blogSlug) { public static string BlogEdit(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.Action("Edit", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); return urlHelper.Action("Edit", "BlogAdmin", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" });
} }
public static string BlogRemove(this UrlHelper urlHelper, string blogSlug) { public static string BlogRemove(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.Action("Remove", "BlogAdmin", new {blogSlug, area = "Orchard.Blogs"}); return urlHelper.Action("Remove", "BlogAdmin", new { blogSlug = blogPart.As<IRoutableAspect>().Path, 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 BlogPostCreate(this UrlHelper urlHelper, BlogPart blogPart) { public static string BlogPostCreate(this UrlHelper urlHelper, BlogPart blogPart) {
return urlHelper.BlogPostCreate(blogPart.Slug); return urlHelper.Action("Create", "BlogPostAdmin", new { blogSlug = blogPart.As<IRoutableAspect>().Path, area = "Orchard.Blogs" });
} }
public static string BlogPostCreate(this UrlHelper urlHelper, string blogSlug) { public static string BlogPost(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
return urlHelper.Action("Create", "BlogPostAdmin", new {blogSlug, area = "Orchard.Blogs"}); return urlHelper.Action("Item", "BlogPost", new { blogSlug = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postSlug = blogPostPart.As<IRoutableAspect>().GetEffectiveSlug(), area = "Orchard.Blogs" });
} }
public static string BlogPostEdit(this UrlHelper urlHelper, BlogPostPart blogPostPart) { public static string BlogPostEdit(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
return urlHelper.BlogPostEdit(blogPostPart.BlogPart.Slug, blogPostPart.Id); return urlHelper.Action("Edit", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" });
}
public static string BlogPostEdit(this UrlHelper urlHelper, string blogSlug, int postId) {
return urlHelper.Action("Edit", "BlogPostAdmin", new {blogSlug, postId, area = "Orchard.Blogs"});
} }
public static string BlogPostDelete(this UrlHelper urlHelper, BlogPostPart blogPostPart) { public static string BlogPostDelete(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
return urlHelper.BlogPostDelete(blogPostPart.BlogPart.Slug, blogPostPart.Id); return urlHelper.Action("Delete", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" });
}
public static string BlogPostDelete(this UrlHelper urlHelper, string blogSlug, int postId) {
return urlHelper.Action("Delete", "BlogPostAdmin", new {blogSlug, postId, area = "Orchard.Blogs"});
} }
public static string BlogPostPublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) { public static string BlogPostPublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
return urlHelper.BlogPostPublish(blogPostPart.BlogPart.Slug, blogPostPart.Id); return urlHelper.Action("Publish", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" });
}
public static string BlogPostPublish(this UrlHelper urlHelper, string blogSlug, int postId) {
return urlHelper.Action("Publish", "BlogPostAdmin", new { blogSlug, postId, area = "Orchard.Blogs" });
} }
public static string BlogPostUnpublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) { public static string BlogPostUnpublish(this UrlHelper urlHelper, BlogPostPart blogPostPart) {
return urlHelper.BlogPostUnpublish(blogPostPart.BlogPart.Slug, blogPostPart.Id); return urlHelper.Action("Unpublish", "BlogPostAdmin", new { blogSlug = blogPostPart.BlogPart.As<IRoutableAspect>().Path, postId = blogPostPart.Id, area = "Orchard.Blogs" });
}
public static string BlogPostUnpublish(this UrlHelper urlHelper, string blogSlug, int postId) {
return urlHelper.Action("Unpublish", "BlogPostAdmin", new { blogSlug, postId, area = "Orchard.Blogs" });
} }
} }
} }

View File

@@ -9,11 +9,6 @@ namespace Orchard.Blogs.Models {
set { this.As<RoutePart>().Title = value; } set { this.As<RoutePart>().Title = value; }
} }
public string Slug {
get { return this.As<RoutePart>().Slug; }
set { this.As<RoutePart>().Slug = value; }
}
public string Description { public string Description {
get { return Record.Description; } get { return Record.Description; }
set { Record.Description = value; } set { Record.Description = value; }

View File

@@ -1,6 +1,8 @@
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Blogs.Services; using Orchard.Blogs.Services;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Environment; using Orchard.Environment;
using Orchard.Tasks; using Orchard.Tasks;
@@ -27,7 +29,7 @@ namespace Orchard.Blogs.Routing {
} }
private void Refresh() { private void Refresh() {
_blogSlugConstraint.SetSlugs(_blogService.Get().Select(b => b.Slug)); _blogSlugConstraint.SetSlugs(_blogService.Get().Select(b => b.As<IRoutableAspect>().Path));
} }
} }
} }

View File

@@ -3,9 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.Core.Routable.Models; using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.Services;
using Orchard.Data; using Orchard.Data;
using Orchard.Tasks.Scheduling; using Orchard.Tasks.Scheduling;
@@ -27,8 +29,9 @@ namespace Orchard.Blogs.Services {
} }
public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) { public BlogPostPart Get(BlogPart blogPart, string slug, VersionOptions versionOptions) {
var postSlug = blogPart.As<IRoutableAspect>().GetChildPath(slug);
return return
_contentManager.Query(versionOptions, "BlogPost").Join<RoutePartRecord>().Where(rr => rr.Slug == slug). _contentManager.Query(versionOptions, "BlogPost").Join<RoutePartRecord>().Where(rr => rr.Path == postSlug).
Join<CommonPartRecord>().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List(). Join<CommonPartRecord>().Where(cr => cr.Container == blogPart.Record.ContentItemRecord).List().
SingleOrDefault().As<BlogPostPart>(); SingleOrDefault().As<BlogPostPart>();
} }

View File

@@ -4,6 +4,7 @@ using JetBrains.Annotations;
using Orchard.Blogs.Models; using Orchard.Blogs.Models;
using Orchard.Blogs.Routing; using Orchard.Blogs.Routing;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Models; using Orchard.Core.Routable.Models;
namespace Orchard.Blogs.Services { namespace Orchard.Blogs.Services {
@@ -17,9 +18,9 @@ namespace Orchard.Blogs.Services {
_blogSlugConstraint = blogSlugConstraint; _blogSlugConstraint = blogSlugConstraint;
} }
public BlogPart Get(string slug) { public BlogPart Get(string path) {
return _contentManager.Query<BlogPart, BlogPartRecord>() return _contentManager.Query<BlogPart, BlogPartRecord>()
.Join<RoutePartRecord>().Where(rr => rr.Slug == slug) .Join<RoutePartRecord>().Where(rr => rr.Path == path)
.List().FirstOrDefault(); .List().FirstOrDefault();
} }
@@ -32,7 +33,7 @@ namespace Orchard.Blogs.Services {
public void Delete(BlogPart blogPart) { public void Delete(BlogPart blogPart) {
_contentManager.Remove(blogPart.ContentItem); _contentManager.Remove(blogPart.ContentItem);
_blogSlugConstraint.RemoveSlug(blogPart.Slug); _blogSlugConstraint.RemoveSlug(blogPart.As<IRoutableAspect>().Path);
} }
} }
} }

View File

@@ -117,8 +117,9 @@ namespace Orchard.Blogs.Services {
var array = new XRpcArray(); var array = new XRpcArray();
foreach (var blog in _blogService.Get()) { foreach (var blog in _blogService.Get()) {
var thisBlog = blog;
array.Add(new XRpcStruct() array.Add(new XRpcStruct()
.Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(blog.Slug))) .Set("url", urlHelper.AbsoluteAction(() => urlHelper.Blog(thisBlog)))
.Set("blogid", blog.Id) .Set("blogid", blog.Id)
.Set("blogName", blog.Name)); .Set("blogName", blog.Name));
} }

View File

@@ -1,9 +1,10 @@
@using Orchard.Blogs.Extensions; @using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
<h1 class="page-title">@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))</h1> <h1 class="page-title">@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))</h1>
<div class="archive-trail"> <div class="archive-trail">
@T("Archives") / @T("Archives") /
@Html.Link((string)Model.ArchiveData.Year.ToString(), Url.BlogArchiveYear((string)Model.Blog.Slug, (int)Model.ArchiveData.Year)) @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((string)Model.Blog.Slug,(int) Model.ArchiveData.Year, (int)Model.ArchiveData.Month))) : "")) @(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((string)Model.Blog.Slug, (int)Model.ArchiveData.Year, (int)Model.ArchiveData.Month, (int)Model.ArchiveData.Day))) : "")) @(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))) : ""))
</div> </div>
@Display(Model.ContentItems) @Display(Model.ContentItems)

View File

@@ -5,12 +5,13 @@
@{ @{
Script.Require("ShapesBase"); Script.Require("ShapesBase");
ContentItem contentItem = Model.ContentItem; ContentItem contentItem = Model.ContentItem;
BlogPart blog = (BlogPart)contentItem.Get(typeof(BlogPart));
var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString(); var returnUrl = ViewContext.RequestContext.HttpContext.Request.ToUrlString();
} }
<div class="summary" itemscope="itemscope" itemid="@contentItem.Id" itemtype="http://orchardproject.net/data/ContentItem"> <div class="summary" itemscope="itemscope" itemid="@contentItem.Id" itemtype="http://orchardproject.net/data/ContentItem">
<div class="properties"> <div class="properties">
<input type="checkbox" value="@contentItem.Id" name="itemIds"/> <input type="checkbox" value="@contentItem.Id" name="itemIds"/>
<h3>@Html.Link((string)Model.Title, Url.BlogForAdmin((string)Model.Slug))</h3> <h3>@Html.Link((string)Model.Title, Url.BlogForAdmin((BlogPart)blog))</h3>
@if (Model.Header != null) { @if (Model.Header != null) {
<div class="header">@Display(Model.Header)</div> <div class="header">@Display(Model.Header)</div>
} }
@@ -20,11 +21,11 @@
</div> </div>
<div class="related"> <div class="related">
@Display(Model.Actions) @Display(Model.Actions)
<a href="@Url.Blog((string)Model.Slug)" title="@T("View")">@T("View")</a>@T(" | ") <a href="@Url.Blog(blog)" title="@T("View")">@T("View")</a>@T(" | ")
<a href="@Url.BlogForAdmin((string)Model.Slug)" title="@T("List Posts")">@T("List Posts")</a>@T(" | ") <a href="@Url.BlogForAdmin(blog)" title="@T("List Posts")">@T("List Posts")</a>@T(" | ")
<a href="@Url.BlogPostCreate((BlogPart)Model.ContentItem.Get(typeof(BlogPart)))" title="@T("New Post")">@T("New Post")</a>@T(" | ") <a href="@Url.BlogPostCreate(blog)" title="@T("New Post")">@T("New Post")</a>@T(" | ")
<a href="@Url.BlogEdit((string)Model.Slug)" title="@T("Edit")">@T("Edit")</a>@T(" | ") <a href="@Url.BlogEdit(blog)" title="@T("Edit")">@T("Edit")</a>@T(" | ")
<a href="@Url.BlogRemove((string)Model.Slug)" title="@T("Remove")" itemprop="RemoveUrl UnsafeUrl">@T("Remove")</a> <a href="@Url.BlogRemove(blog)" title="@T("Remove")" itemprop="RemoveUrl UnsafeUrl">@T("Remove")</a>
</div> </div>
@if (Model.Content != null) { @if (Model.Content != null) {
<div class="primary">@Display(Model.Content)</div> <div class="primary">@Display(Model.Content)</div>

View File

@@ -1,9 +1,10 @@
@using Orchard.Blogs.Extensions; @using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
@{ @{
Style.Require("BlogsAdmin"); Style.Require("BlogsAdmin");
} }
@if (AuthorizedFor(Orchard.Blogs.Permissions.ManageBlogs)) { @if (AuthorizedFor(Orchard.Blogs.Permissions.ManageBlogs)) {
<div class="item-properties actions"> <div class="item-properties actions">
<p><a href="@Url.BlogEdit((string)Model.ContentPart.Slug)" class="edit">@T("Blog Properties")</a></p> <p><a href="@Url.BlogEdit((BlogPart)Model.ContentPart)" class="edit">@T("Blog Properties")</a></p>
</div> </div>
} }

View File

@@ -25,14 +25,14 @@
if (year != lastYear) { if (year != lastYear) {
<li class="previous"> <li class="previous">
<h4>@year <span>(@yearMonths.Sum(ym => ym.Value))</span></h4> <h4>@year <span>(@yearMonths.Sum(ym => ym.Value))</span></h4>
@Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((string)Model.BlogPart.Slug, t.Key.Year, t.Key.Month)), "archiveMonthList") @Html.UnorderedList(yearMonths, (t, i) => Html.Link(string.Format("{0:MMMM} ({1})", t.Key.ToDateTime(), t.Value), Url.BlogArchiveMonth((BlogPart)Model.BlogPart, t.Key.Year, t.Key.Month)), "archiveMonthList")
</li> </li>
} }
} }
</ul> </ul>
} }
else if (archives.Count() > 0) { 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 { else {
<div class="message info">@T("None found")</div> <div class="message info">@T("None found")</div>

View File

@@ -1,6 +1,8 @@
@using Orchard.Blogs.Extensions; @using Orchard.Blogs.Extensions;
@using Orchard.Blogs.Models;
@using Orchard.UI.Resources; @using Orchard.UI.Resources;
@{ @{
RegisterLink(new LinkEntry { Rel = "wlwmanifest", Type = "application/wlwmanifest+xml", Href = Url.BlogLiveWriterManifest((string)Model.Slug) }); BlogPart blog = Model;
RegisterLink(new LinkEntry { Rel = "EditURI", Type = "application/rsd+xml", Title = "RSD", Href = Url.BlogRsd((string)Model.Slug) }); 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) });
} }