2009-12-08 07:37:47 +08:00
|
|
|
using System.Linq;
|
2009-11-21 07:31:49 +08:00
|
|
|
using System.Web.Mvc;
|
2010-11-01 14:54:37 +08:00
|
|
|
using Orchard.Blogs.Extensions;
|
2010-03-05 16:24:53 +08:00
|
|
|
using Orchard.Blogs.Routing;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Blogs.Services;
|
2010-11-01 14:54:37 +08:00
|
|
|
using Orchard.Core.Feeds;
|
2010-09-17 16:00:24 +08:00
|
|
|
using Orchard.DisplayManagement;
|
2010-03-03 03:11:22 +08:00
|
|
|
using Orchard.Logging;
|
2010-10-01 07:37:32 +08:00
|
|
|
using Orchard.Themes;
|
2010-11-01 14:54:37 +08:00
|
|
|
using Orchard.UI.Navigation;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
|
|
|
namespace Orchard.Blogs.Controllers {
|
2010-10-01 07:37:32 +08:00
|
|
|
[Themed]
|
2010-01-12 06:07:03 +08:00
|
|
|
public class BlogController : Controller {
|
2010-01-12 05:05:24 +08:00
|
|
|
private readonly IOrchardServices _services;
|
2009-11-21 07:31:49 +08:00
|
|
|
private readonly IBlogService _blogService;
|
2010-10-14 06:42:36 +08:00
|
|
|
private readonly IBlogPostService _blogPostService;
|
2010-03-05 16:24:53 +08:00
|
|
|
private readonly IBlogSlugConstraint _blogSlugConstraint;
|
2010-11-01 14:54:37 +08:00
|
|
|
private readonly IFeedManager _feedManager;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-10-16 08:24:30 +08:00
|
|
|
public BlogController(
|
|
|
|
IOrchardServices services,
|
|
|
|
IBlogService blogService,
|
|
|
|
IBlogPostService blogPostService,
|
|
|
|
IBlogSlugConstraint blogSlugConstraint,
|
2010-11-18 07:36:57 +08:00
|
|
|
IFeedManager feedManager,
|
2010-10-16 08:24:30 +08:00
|
|
|
IShapeFactory shapeFactory) {
|
2010-01-12 05:05:24 +08:00
|
|
|
_services = services;
|
2009-11-21 07:31:49 +08:00
|
|
|
_blogService = blogService;
|
2010-10-14 06:42:36 +08:00
|
|
|
_blogPostService = blogPostService;
|
2010-03-05 16:24:53 +08:00
|
|
|
_blogSlugConstraint = blogSlugConstraint;
|
2010-11-01 14:54:37 +08:00
|
|
|
_feedManager = feedManager;
|
2010-03-03 03:11:22 +08:00
|
|
|
Logger = NullLogger.Instance;
|
2010-10-16 08:24:30 +08:00
|
|
|
Shape = shapeFactory;
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2010-09-17 16:00:24 +08:00
|
|
|
dynamic Shape { get; set; }
|
2010-03-03 03:11:22 +08:00
|
|
|
protected ILogger Logger { get; set; }
|
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
public ActionResult List() {
|
2010-10-15 02:15:22 +08:00
|
|
|
var blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
|
2009-12-08 14:31:44 +08:00
|
|
|
|
2010-09-17 16:00:24 +08:00
|
|
|
var list = Shape.List();
|
|
|
|
list.AddRange(blogs);
|
|
|
|
|
2010-11-19 03:21:43 +08:00
|
|
|
dynamic viewModel = Shape.ViewModel()
|
2010-09-17 16:00:24 +08:00
|
|
|
.ContentItems(list);
|
|
|
|
|
2010-11-20 09:42:30 +08:00
|
|
|
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
2010-11-19 03:21:43 +08:00
|
|
|
return View((object)viewModel);
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2010-11-01 14:54:37 +08:00
|
|
|
public ActionResult Item(string blogSlug, Pager pager) {
|
2010-03-05 16:24:53 +08:00
|
|
|
var correctedSlug = _blogSlugConstraint.FindSlug(blogSlug);
|
|
|
|
if (correctedSlug == null)
|
2010-10-15 02:30:58 +08:00
|
|
|
return HttpNotFound();
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-10-16 05:40:35 +08:00
|
|
|
var blogPart = _blogService.Get(correctedSlug);
|
|
|
|
if (blogPart == null)
|
2010-10-15 02:30:58 +08:00
|
|
|
return HttpNotFound();
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-11-01 14:54:37 +08:00
|
|
|
_feedManager.Register(blogPart);
|
|
|
|
var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize)
|
2010-10-16 05:40:35 +08:00
|
|
|
.Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
|
2010-11-19 03:21:43 +08:00
|
|
|
dynamic blog = _services.ContentManager.BuildDisplay(blogPart);
|
2010-10-14 06:42:36 +08:00
|
|
|
|
|
|
|
var list = Shape.List();
|
|
|
|
list.AddRange(blogPosts);
|
2010-10-16 05:40:35 +08:00
|
|
|
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
|
2010-10-14 06:42:36 +08:00
|
|
|
|
2010-11-02 15:25:25 +08:00
|
|
|
var totalItemCount = _blogPostService.PostCount(blogPart);
|
|
|
|
blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after");
|
2010-11-01 14:54:37 +08:00
|
|
|
|
2010-11-20 09:42:30 +08:00
|
|
|
// Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
|
2010-11-19 03:21:43 +08:00
|
|
|
return View((object)blog);
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|