--HG--
branch : dev
This commit is contained in:
jowall
2010-03-01 17:20:54 -08:00
7 changed files with 209 additions and 80 deletions

View File

@@ -98,6 +98,7 @@
<Compile Include="Services\BlogPostService.cs" /> <Compile Include="Services\BlogPostService.cs" />
<Compile Include="Services\IBlogPostService.cs" /> <Compile Include="Services\IBlogPostService.cs" />
<Compile Include="Services\IBlogService.cs" /> <Compile Include="Services\IBlogService.cs" />
<Compile Include="Services\XmlRpcHandler.cs" />
<Compile Include="ViewModels\AdminBlogsViewModel.cs" /> <Compile Include="ViewModels\AdminBlogsViewModel.cs" />
<Compile Include="ViewModels\BlogArchivesViewModel.cs" /> <Compile Include="ViewModels\BlogArchivesViewModel.cs" />
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" /> <Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />

View File

@@ -0,0 +1,138 @@
using System;
using Orchard.Core.XmlRpc;
using Orchard.Core.XmlRpc.Models;
using Orchard.Logging;
namespace Orchard.Blogs.Services {
public class XmlRpcHandler : IXmlRpcHandler {
private readonly IBlogService _blogService;
public XmlRpcHandler(IBlogService blogService) {
_blogService = blogService;
Logger = NullLogger.Instance;
}
public ILogger Logger { get; set; }
public void Process(XmlRpcContext context) {
var uriBuilder = new UriBuilder(context.HttpContext.Request.Url) {
Path =
context.HttpContext.Request.
ApplicationPath,
Query = string.Empty
};
if (context.Request.MethodName == "blogger.getUsersBlogs") {
var a = new XRpcArray();
foreach (var blog in _blogService.Get()) {
a.Add(new XRpcStruct()
.Set("url", uriBuilder.Path + blog.Slug)
.Set("blogid", blog.Id)
.Set("blogName", blog.Name));
}
context.Response = new XRpcMethodResponse().Add(a);
}
if (context.Request.MethodName == "metaWeblog.newPost") {
var result = MetaWeblogNewPost(
Convert.ToString(context.Request.Params[0].Value),
Convert.ToString(context.Request.Params[1].Value),
Convert.ToString(context.Request.Params[2].Value),
(XRpcStruct)context.Request.Params[3].Value,
Convert.ToBoolean(context.Request.Params[4].Value));
context.Response = new XRpcMethodResponse().Add(result);
}
if (context.Request.MethodName == "metaWeblog.getPost") {
var result = MetaWeblogGetPost(
Convert.ToInt32(context.Request.Params[0].Value),
Convert.ToString(context.Request.Params[1].Value),
Convert.ToString(context.Request.Params[2].Value));
context.Response = new XRpcMethodResponse().Add(result);
}
if (context.Request.MethodName == "metaWeblog.editPost") {
var result = MetaWeblogEditPost(
Convert.ToInt32(context.Request.Params[0].Value),
Convert.ToString(context.Request.Params[1].Value),
Convert.ToString(context.Request.Params[2].Value),
(XRpcStruct)context.Request.Params[3].Value,
Convert.ToBoolean(context.Request.Params[4].Value));
context.Response = new XRpcMethodResponse().Add(result);
}
}
private int MetaWeblogNewPost(
string blogId,
string user,
string password,
XRpcStruct content,
bool publish) {
//var title = content.Optional<string>("title");
//var description = content.Optional<string>("description");
//var pageRevision = _pageManager.CreatePage(new CreatePageParams(title, null, "TwoColumns"));
//pageRevision.Contents.First().Content = description;
//if (publish) {
// if (string.IsNullOrEmpty(pageRevision.Slug))
// pageRevision.Slug = "slug" + pageRevision.Page.Id;
// _pageManager.Publish(pageRevision, new PublishOptions());
//}
//return pageRevision.Page.Id;
return 1;
}
private XRpcStruct MetaWeblogGetPost(
int postId,
string user,
string password) {
//var pageRevision = _pageManager.GetLastRevision(postId);
//var url = "http://localhost/orchard/" + pageRevision.Slug;
//return new XRpcStruct()
// .Set("userid", 37)
// .Set("postid", pageRevision.Page.Id)
// .Set("description", pageRevision.Contents.First().Content)
// .Set("title", pageRevision.Title)
// .Set("link", url)
// .Set("permaLink", url);
throw new NotImplementedException();
}
private bool MetaWeblogEditPost(
int postId,
string user,
string password,
XRpcStruct content,
bool publish) {
//var pageRevision = _pageManager.AcquireDraft(postId);
//var title = content.Optional<string>("title");
//var description = content.Optional<string>("description");
//pageRevision.Title = title;
//pageRevision.Contents.First().Content = description;
//if (publish) {
// if (string.IsNullOrEmpty(pageRevision.Slug))
// pageRevision.Slug = "slug" + postId;
// _pageManager.Publish(pageRevision, new PublishOptions());
//}
//return true;
throw new NotImplementedException();
}
}
}

View File

@@ -1,74 +1,63 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<BlogPost>>" %>
<%@ Import Namespace="Orchard.Themes"%>
<%@ Import Namespace="Orchard.Extensions"%>
<%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ Import Namespace="Orchard.Mvc.ViewModels"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%> <%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<div class="summary"> <div class="summary">
<div class="properties"> <div class="properties">
<h3><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPostEdit(Model.Item.Blog.Slug, Model.Item.Id))%></h3> <h3><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPostEdit(Model.Item.Blog.Slug, Model.Item.Id))%></h3>
<ul> <ul>
<li> <li><%
<%if (Model.IsPublished) if (Model.Item.HasPublished) { %>
{ %> <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%=_Encoded("Online") %>" title="<%=_Encoded("The page is currently online") %>" /><%=_Encoded(" Published")%><%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/online.gif") %>" alt="<%=_Encoded("Online") %>" title="<%=_Encoded("The page is currently online") %>" /><%=_Encoded(" Published")%> }
<% } else { %>
else <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%=_Encoded("Offline") %>" title="<%=_Encoded("The page is currently offline") %>" /><%=_Encoded(" Not Published")%><%
{ %> } %>&nbsp;&#124;&nbsp;
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/offline.gif") %>" alt="<%=_Encoded("Offline") %>" title="<%=_Encoded("The page is currently offline") %>" /><%=_Encoded(" Not Published")%>
<% } %>
&nbsp;&#124;&nbsp;
</li> </li>
<li><%
<li> if (Model.Item.HasDraft) { %>
<% if (Model.IsDraft) { %> <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%=_Encoded("Draft") %>" title="<%=_Encoded("The post has a draft") %>" /><%=Html.PublishedState(Model.Item)%><%
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/draft.gif") %>" alt="<%=_Encoded("Draft") %>" title="<%=_Encoded("The post has a draft") %>" /><%=Html.PublishedState(Model.Item)%> }
<% } else { %>
else <%=_Encoded("No draft")%><%
{ %> } %>&nbsp;&#124;&nbsp;
<%=_Encoded("No draft")%>
<% } %>
&nbsp;&#124;&nbsp;
</li> </li>
<li><%
<%--This should show publised date, last modified, or scheduled. if (Model.Item.ScheduledPublishUtc.HasValue && Model.Item.ScheduledPublishUtc.Value > DateTime.UtcNow) { %>
<li> <img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/scheduled.gif") %>" alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The post is scheduled for publishing") %>" /><%=_Encoded("Scheduled")%>
<img class="icon" src="<%=ResolveUrl("~/Modules/Orchard.Blogs/Content/Admin/images/scheduled.gif") %>" alt="<%=_Encoded("Scheduled") %>" title="<%=_Encoded("The post is scheduled for publishing") %>" /><%=_Encoded("Scheduled")%> <%=Html.DateTime(Model.Item.ScheduledPublishUtc.Value, "M/d/yyyy h:mm tt")%><%
&nbsp;&#124;&nbsp; }
</li>--%> else if (Model.Item.IsPublished) { %>
<%=_Encoded("Published: ") + Html.PublishedWhen(Model.Item) %><%
<li> }
<%=_Encoded("By {0}", Model.Item.Creator.UserName)%> else { %>
</li> <%=_Encoded("Last modified: {todo}") %><%
</ul> } %>&nbsp;&#124;&nbsp;
</li>
<li><%=_Encoded("By {0}", Model.Item.Creator.UserName)%></li>
</ul>
</div> </div>
<div class="related"><%
<div class="related"> if (Model.Item.HasPublished){ %>
<a href="<%=Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug) %>" title="<%=_Encoded("View Post")%>"><%=_Encoded("View")%></a><%=_Encoded(" | ")%><%
<%if (Model.IsPublished){ %> if (Model.Item.HasDraft) { %>
<a href="<%=Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug) %>" title="<%=_Encoded("View Post")%>"><%=_Encoded("View")%></a><%=_Encoded(" | ")%> <a href="#" title="<%=_Encoded("Publish Draft")%>"><%=_Encoded("Publish Draft")%></a><%=_Encoded(" | ")%><%
<% } %> } %>
<a href="#" title="<%=_Encoded("Unpublish Post")%>"><%=_Encoded("Unpublish")%></a><%=_Encoded(" | ")%><%
<a href="<%=Url.BlogPostEdit(Model.Item.Blog.Slug, Model.Item.Id) %>" title="<%=_Encoded("Edit Post")%>"><%=_Encoded("Edit")%></a><%=_Encoded(" | ")%> }
else { %>
<%if (Model.Item.ContentItem.VersionRecord.Published == false) { // todo: (heskew) be smart about this and maybe have other contextual actions - including view/preview for view up there ^^ <a href="#" title="<%=_Encoded("Publish Post")%>"><%=_Encoded("Publish")%></a><%=_Encoded(" | ")%><%
using (Html.BeginFormAntiForgeryPost(Url.BlogPostPublish(Model.Item.Blog.Slug, Model.Item.Id), FormMethod.Post, new { @class = "inline" })) { %> } %>
<a href="<%=Url.BlogPostEdit(Model.Item.Blog.Slug, Model.Item.Id) %>" title="<%=_Encoded("Edit Post")%>"><%=_Encoded("Edit")%></a><%=_Encoded(" | ")%><%--
if (Model.Item.ContentItem.VersionRecord.Published == false) { // todo: (heskew) be smart about this and maybe have other contextual actions - including view/preview for view up there ^^
using (Html.BeginFormAntiForgeryPost(Url.BlogPostPublish(Model.Item.Blog.Slug, Model.Item.Id), FormMethod.Post, new { @class = "inline" })) { %>
<button type="submit" class="linkButton" title="<%=_Encoded("Publish") %>"><%=_Encoded("Publish")%></button><%=_Encoded(" | ")%><% <button type="submit" class="linkButton" title="<%=_Encoded("Publish") %>"><%=_Encoded("Publish")%></button><%=_Encoded(" | ")%><%
} }
} %> }--%><%
using (Html.BeginFormAntiForgeryPost(Url.BlogPostDelete(Model.Item.Blog.Slug, Model.Item.Id), FormMethod.Post, new { @class = "inline" })) { %>
<% using (Html.BeginFormAntiForgeryPost(Url.BlogPostDelete(Model.Item.Blog.Slug, Model.Item.Id), FormMethod.Post, new { @class = "inline" })) { %> <button type="submit" class="linkButton" title="<%=_Encoded("Delete") %>"><%=_Encoded("Delete") %></button><%
<button type="submit" class="linkButton" title="<%=_Encoded("Delete") %>"><%=_Encoded("Delete") %></button> } %>
<%
} %>
<br /><%Html.Zone("meta");%> <br /><%Html.Zone("meta");%>
</div> </div>
<div style="clear:both;"></div> <div style="clear:both;"></div>
</div> </div>

View File

@@ -10,10 +10,11 @@
<div class="secondary"> <div class="secondary">
<% Html.Zone("secondary");%> <% Html.Zone("secondary");%>
<fieldset> <fieldset>
<input class="button primaryAction" type="submit" name="submit.Save" value="<%=_Encoded("Save") %>"/> <input class="button primaryAction" type="submit" name="submit.Save" value="<%=_Encoded("Save") %>"/><%
<% if (Model.IsDraft) { %> //TODO: (erikpo) In the future, remove the HasPublished check so the user can delete the content item from here if the choose to
<%=Html.ActionLink(T("Discard Draft").ToString(), "DiscardDraft", new { Area = "Orchard.Blogs", Controller = "BlogPostAdmin", id=Model.Item.Id }, new { @class = "button" })%> if (Model.Item.HasDraft && Model.Item.HasPublished) { %>
<% } %> <%=Html.ActionLink(T("Discard Draft").ToString(), "DiscardDraft", new { Area = "Orchard.Blogs", Controller = "BlogPostAdmin", id=Model.Item.Id }, new { @class = "button" })%><%
} %>
</fieldset> </fieldset>
</div> </div>
</div> </div>

View File

@@ -10,10 +10,11 @@
<div class="secondary"> <div class="secondary">
<% Html.Zone("secondary");%> <% Html.Zone("secondary");%>
<fieldset> <fieldset>
<input class="button primaryAction" type="submit" name="submit.Save" value="<%=_Encoded("Save") %>"/> <input class="button primaryAction" type="submit" name="submit.Save" value="<%=_Encoded("Save") %>"/><%
<% if (Model.IsDraft) { %> //TODO: (erikpo) In the future, remove the HasPublished check so the user can delete the content item from here if the choose to
<%=Html.ActionLink(T("Discard Draft").ToString(), "DiscardDraft", new { Area = "Orchard.Pages", Controller = "Admin", Model.Item.Id }, new { @class = "button" })%> if (Model.Item.HasDraft && Model.Item.HasPublished) { %>
<% } %> <%=Html.ActionLink(T("Discard Draft").ToString(), "DiscardDraft", new { Area = "Orchard.Pages", Controller = "Admin", Model.Item.Id }, new { @class = "button" })%><%
} %>
</fieldset> </fieldset>
</div> </div>
</div> </div>

View File

@@ -116,9 +116,18 @@ namespace Orchard.Mvc.Html {
return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull; return value.HasValue ? htmlHelper.DateTime(value.Value) : defaultIfNull;
} }
//TODO: (erikpo) This format should come from a site setting public static string DateTime(this HtmlHelper htmlHelper, DateTime? value, string defaultIfNull, string customFormat) {
return value.HasValue ? htmlHelper.DateTime(value.Value, customFormat) : defaultIfNull;
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime value) { public static string DateTime(this HtmlHelper htmlHelper, DateTime value) {
return value.ToString("MMM d yyyy h:mm tt"); //TODO: (erikpo) This default format should come from a site setting
return htmlHelper.DateTime(value, "MMM d yyyy h:mm tt");
}
public static string DateTime(this HtmlHelper htmlHelper, DateTime value, string customFormat) {
//TODO: (erikpo) In the future, convert this to "local" time before calling ToString
return value.ToString(customFormat);
} }
#endregion #endregion

View File

@@ -36,16 +36,6 @@ namespace Orchard.Mvc.ViewModels {
public string TemplateName { get; set; } public string TemplateName { get; set; }
public string Prefix { get; set; } public string Prefix { get; set; }
public ZoneCollection Zones { get; private set; } public ZoneCollection Zones { get; private set; }
public bool IsPublished {
get { return Item != null && Item.VersionRecord != null && Item.VersionRecord.Published; }
}
public bool IsLatest {
get { return Item != null && Item.VersionRecord != null && Item.VersionRecord.Latest; }
}
public bool IsDraft {
get { return IsLatest && !IsPublished; }
}
} }
public class ContentItemViewModel<TPart> : ContentItemViewModel where TPart : IContent { public class ContentItemViewModel<TPart> : ContentItemViewModel where TPart : IContent {