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;
|
2010-11-01 14:54:37 +08:00
|
|
|
using Orchard.Blogs.Extensions;
|
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-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;
|
2010-03-03 04:10:49 +08:00
|
|
|
private readonly RouteCollection _routeCollection;
|
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-01 14:54:37 +08:00
|
|
|
IFeedManager feedManager,
|
2010-10-16 08:24:30 +08:00
|
|
|
RouteCollection routeCollection,
|
|
|
|
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 04:10:49 +08:00
|
|
|
_routeCollection = routeCollection;
|
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);
|
|
|
|
|
|
|
|
var viewModel = Shape.ViewModel()
|
|
|
|
.ContentItems(list);
|
|
|
|
|
|
|
|
return View(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"));
|
|
|
|
var 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-01 14:54:37 +08:00
|
|
|
var hasNextPage = _blogPostService.Get(blogPart, pager.GetStartIndex(pager.Page + 1), 1).Any();
|
|
|
|
blog.Content.Add(Shape.Pager(pager).HasNextPage(hasNextPage), "Content:after");
|
|
|
|
|
2010-10-18 16:28:39 +08:00
|
|
|
return View(blog);
|
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
|
|
|
}
|
|
|
|
}
|