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-01-28 07:52:07 +08:00
|
|
|
using Orchard.Blogs.Extensions;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Blogs.Models;
|
|
|
|
using Orchard.Blogs.Services;
|
2009-11-24 00:26:24 +08:00
|
|
|
using Orchard.Blogs.ViewModels;
|
2010-01-19 14:29:58 +08:00
|
|
|
using Orchard.Core.Feeds;
|
2010-03-03 03:11:22 +08:00
|
|
|
using Orchard.Logging;
|
2009-11-21 07:31:49 +08:00
|
|
|
using Orchard.Mvc.Results;
|
|
|
|
|
|
|
|
namespace Orchard.Blogs.Controllers {
|
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-01-19 14:29:58 +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-01-19 14:29:58 +08:00
|
|
|
public BlogController(
|
|
|
|
IOrchardServices services,
|
|
|
|
IBlogService blogService,
|
2010-03-03 04:10:49 +08:00
|
|
|
IFeedManager feedManager,
|
|
|
|
RouteCollection routeCollection) {
|
2010-01-12 05:05:24 +08:00
|
|
|
_services = services;
|
2009-11-21 07:31:49 +08:00
|
|
|
_blogService = blogService;
|
2010-01-19 14:29:58 +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;
|
2009-11-21 07:31:49 +08:00
|
|
|
}
|
|
|
|
|
2010-03-03 03:11:22 +08:00
|
|
|
protected ILogger Logger { get; set; }
|
|
|
|
|
2009-12-03 09:37:45 +08:00
|
|
|
public ActionResult List() {
|
2009-12-08 17:21:13 +08:00
|
|
|
var model = new BlogsViewModel {
|
2010-01-12 05:05:24 +08:00
|
|
|
Blogs = _blogService.Get().Select(b => _services.ContentManager.BuildDisplayModel(b, "Summary"))
|
2009-12-08 17:21:13 +08:00
|
|
|
};
|
2009-12-08 14:31:44 +08:00
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
return View(model);
|
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
|
2009-11-21 08:38:41 +08:00
|
|
|
public ActionResult Item(string blogSlug) {
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
2009-11-21 07:31:49 +08:00
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
var model = new BlogViewModel {
|
2010-01-12 05:05:24 +08:00
|
|
|
Blog = _services.ContentManager.BuildDisplayModel(blog, "Detail")
|
2009-12-08 17:21:13 +08:00
|
|
|
};
|
|
|
|
|
2010-01-19 14:29:58 +08:00
|
|
|
_feedManager.Register(blog);
|
|
|
|
|
2009-12-08 17:21:13 +08:00
|
|
|
return View(model);
|
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-03-03 04:10:49 +08:00
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
Blog blog = _blogService.Get(blogSlug);
|
|
|
|
|
|
|
|
if (blog == null)
|
|
|
|
return new NotFoundResult();
|
|
|
|
|
|
|
|
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),
|
|
|
|
new XElement(XName.Get("engineName", manifestUri), "Orchar CMS"),
|
|
|
|
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),
|
|
|
|
new XAttribute("blogID", blog.Id))));
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|