2009-12-08 07:37:47 +08:00
|
|
|
using System.Linq;
|
2010-03-03 03:11:22 +08:00
|
|
|
using System.Web;
|
2009-11-21 07:31:49 +08:00
|
|
|
using System.Web.Mvc;
|
2010-03-03 04:10:49 +08:00
|
|
|
using System.Web.Routing;
|
2010-03-03 03:11:22 +08:00
|
|
|
using System.Xml.Linq;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Blogs.Models;
|
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-10-14 06:42:36 +08:00
|
|
|
using Orchard.Blogs.ViewModels;
|
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;
|
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-03-03 04:10:49 +08:00
|
|
|
private readonly RouteCollection _routeCollection;
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-10-14 06:42:36 +08:00
|
|
|
public BlogController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, IBlogSlugConstraint blogSlugConstraint, RouteCollection routeCollection, IShapeHelperFactory shapeHelperFactory) {
|
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-03-03 04:10:49 +08:00
|
|
|
_routeCollection = routeCollection;
|
2010-03-03 03:11:22 +08:00
|
|
|
Logger = NullLogger.Instance;
|
2010-09-17 16:00:24 +08:00
|
|
|
Shape = shapeHelperFactory.CreateHelper();
|
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);
|
|
|
|
|
|
|
|
var viewModel = Shape.ViewModel()
|
|
|
|
.ContentItems(list);
|
|
|
|
|
|
|
|
return View(viewModel);
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2009-11-24 01:34:46 +08:00
|
|
|
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
2010-10-14 06:42:36 +08:00
|
|
|
public ActionResult Item(string blogSlug, int page) {
|
|
|
|
const int pageSize = 10;
|
|
|
|
|
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-14 06:42:36 +08:00
|
|
|
BlogPart blog = _blogService.Get(correctedSlug);
|
2009-11-21 07:31:49 +08:00
|
|
|
if (blog == null)
|
2010-10-15 02:30:58 +08:00
|
|
|
return HttpNotFound();
|
2009-11-21 07:31:49 +08:00
|
|
|
|
2010-10-15 02:15:22 +08:00
|
|
|
var blogPosts = _blogPostService.Get(blog, (page - 1)*pageSize, pageSize).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"));
|
2010-10-14 06:42:36 +08:00
|
|
|
|
|
|
|
var list = Shape.List();
|
|
|
|
list.AddRange(blogPosts);
|
|
|
|
|
2010-10-15 12:12:08 +08:00
|
|
|
var blogShape = _services.ContentManager.BuildDisplay(blog);
|
2010-10-14 06:42:36 +08:00
|
|
|
var model = new DisplayBlogViewModel {
|
2010-10-15 12:12:08 +08:00
|
|
|
Blog = blogShape,
|
2010-10-14 06:42:36 +08:00
|
|
|
BlogPostList = list,
|
|
|
|
Page = page,
|
|
|
|
PageSize = pageSize
|
|
|
|
};
|
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
return View(model);
|
2010-10-14 06:42:36 +08:00
|
|
|
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
2010-03-03 03:11:22 +08:00
|
|
|
|
2010-03-03 04:10:49 +08:00
|
|
|
public ActionResult LiveWriterManifest(string blogSlug) {
|
2010-03-03 03:11:22 +08:00
|
|
|
Logger.Debug("Live Writer Manifest requested");
|
|
|
|
|
2010-07-23 02:08:14 +08:00
|
|
|
BlogPart blogPart = _blogService.Get(blogSlug);
|
2010-03-03 04:10:49 +08:00
|
|
|
|
2010-07-23 02:08:14 +08:00
|
|
|
if (blogPart == null)
|
2010-10-15 02:30:58 +08:00
|
|
|
return HttpNotFound();
|
2010-03-03 04:10:49 +08:00
|
|
|
|
2010-03-03 03:11:22 +08:00
|
|
|
const string manifestUri = "http://schemas.microsoft.com/wlw/manifest/weblog";
|
|
|
|
|
|
|
|
var options = new XElement(
|
|
|
|
XName.Get("options", manifestUri),
|
|
|
|
new XElement(XName.Get("clientType", manifestUri), "Metaweblog"),
|
2010-03-03 04:10:49 +08:00
|
|
|
new XElement(XName.Get("supportsSlug", manifestUri), "Yes"),
|
|
|
|
new XElement(XName.Get("supportsKeywords", manifestUri), "Yes"));
|
|
|
|
|
2010-03-03 03:11:22 +08:00
|
|
|
|
|
|
|
var doc = new XDocument(new XElement(
|
|
|
|
XName.Get("manifest", manifestUri),
|
|
|
|
options));
|
|
|
|
|
|
|
|
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
|
|
return Content(doc.ToString(), "text/xml");
|
|
|
|
}
|
2010-03-03 04:10:49 +08:00
|
|
|
|
|
|
|
public ActionResult Rsd(string blogSlug) {
|
|
|
|
Logger.Debug("RSD requested");
|
|
|
|
|
2010-07-23 02:08:14 +08:00
|
|
|
BlogPart blogPart = _blogService.Get(blogSlug);
|
2010-03-03 04:10:49 +08:00
|
|
|
|
2010-07-23 02:08:14 +08:00
|
|
|
if (blogPart == null)
|
2010-10-15 02:30:58 +08:00
|
|
|
return HttpNotFound();
|
2010-03-03 04:10:49 +08:00
|
|
|
|
|
|
|
const string manifestUri = "http://archipelago.phrasewise.com/rsd";
|
|
|
|
|
|
|
|
var urlHelper = new UrlHelper(ControllerContext.RequestContext, _routeCollection);
|
|
|
|
var url = urlHelper.Action("", "", new { Area = "XmlRpc" });
|
|
|
|
|
|
|
|
var options = new XElement(
|
|
|
|
XName.Get("service", manifestUri),
|
2010-05-15 03:23:16 +08:00
|
|
|
new XElement(XName.Get("engineName", manifestUri), "Orchard CMS"),
|
2010-03-03 04:10:49 +08:00
|
|
|
new XElement(XName.Get("engineLink", manifestUri), "http://orchardproject.net"),
|
|
|
|
new XElement(XName.Get("homePageLink", manifestUri), "http://orchardproject.net"),
|
|
|
|
new XElement(XName.Get("apis", manifestUri),
|
|
|
|
new XElement(XName.Get("api", manifestUri),
|
|
|
|
new XAttribute("name", "MetaWeblog"),
|
|
|
|
new XAttribute("preferred", true),
|
|
|
|
new XAttribute("apiLink", url),
|
2010-07-23 02:08:14 +08:00
|
|
|
new XAttribute("blogID", blogPart.Id))));
|
2010-03-03 04:10:49 +08:00
|
|
|
|
|
|
|
var doc = new XDocument(new XElement(
|
|
|
|
XName.Get("rsd", manifestUri),
|
|
|
|
new XAttribute("version", "1.0"),
|
|
|
|
options));
|
|
|
|
|
|
|
|
Response.Cache.SetCacheability(HttpCacheability.NoCache);
|
|
|
|
return Content(doc.ToString(), "text/xml");
|
|
|
|
}
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
}
|