mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge dev tip
--HG-- branch : dev
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Navigation;
|
||||
|
||||
namespace Orchard.Blogs {
|
||||
@@ -10,10 +11,12 @@ namespace Orchard.Blogs {
|
||||
_blogService = blogService;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
builder.Add("Blogs", "2", BuildMenu);
|
||||
builder.Add(T("Blogs"), "2", BuildMenu);
|
||||
}
|
||||
|
||||
private void BuildMenu(NavigationItemBuilder menu) {
|
||||
@@ -22,20 +25,20 @@ namespace Orchard.Blogs {
|
||||
var singleBlog = blogCount == 1 ? blogs.ElementAt(0) : null;
|
||||
|
||||
if (blogCount > 0 && singleBlog == null)
|
||||
menu.Add("Manage Blogs", "1.0",
|
||||
menu.Add(T("Manage Blogs"), "1.0",
|
||||
item =>
|
||||
item.Action("List", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.MetaListBlogs));
|
||||
else if (singleBlog != null)
|
||||
menu.Add("Manage Blog", "1.0",
|
||||
menu.Add(T("Manage Blog"), "1.0",
|
||||
item =>
|
||||
item.Action("Item", "BlogAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.MetaListBlogs));
|
||||
|
||||
menu.Add("Add New Blog", "1.1",
|
||||
menu.Add(T("Add New Blog"), "1.1",
|
||||
item =>
|
||||
item.Action("Create", "BlogAdmin", new {area = "Orchard.Blogs"}).Permission(Permissions.ManageBlogs));
|
||||
|
||||
if (singleBlog != null)
|
||||
menu.Add("Add New Post", "1.2",
|
||||
menu.Add(T("Add New Post"), "1.2",
|
||||
item =>
|
||||
item.Action("Create", "BlogPostAdmin", new {area = "Orchard.Blogs", blogSlug = singleBlog.Slug}).Permission(Permissions.PublishBlogPost));
|
||||
}
|
||||
|
128
src/Orchard.Web/Modules/Orchard.Blogs/Commands/BlogCommands.cs
Normal file
128
src/Orchard.Web/Modules/Orchard.Blogs/Commands/BlogCommands.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Commands;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Navigation.Models;
|
||||
using Orchard.Security;
|
||||
using System.IO;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Core.Navigation.Services;
|
||||
|
||||
namespace Orchard.Blogs.Commands {
|
||||
public class BlogCommands : DefaultOrchardCommandHandler {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IMembershipService _membershipService;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IMenuService _menuService;
|
||||
|
||||
public BlogCommands(
|
||||
IContentManager contentManager,
|
||||
IMembershipService membershipService,
|
||||
IBlogService blogService,
|
||||
IMenuService menuService) {
|
||||
_contentManager = contentManager;
|
||||
_membershipService = membershipService;
|
||||
_blogService = blogService;
|
||||
_menuService = menuService;
|
||||
}
|
||||
|
||||
[OrchardSwitch]
|
||||
public string FeedUrl { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string Slug { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string Title { get; set; }
|
||||
|
||||
[OrchardSwitch]
|
||||
public string MenuText { get; set; }
|
||||
|
||||
[CommandName("blog create")]
|
||||
[CommandHelp("blog create /Slug:<slug> /Title:<title> [/MenuText:<menu text>]\r\n\t" + "Creates a new Blog")]
|
||||
[OrchardSwitches("Slug,Title,MenuText")]
|
||||
public string Create() {
|
||||
var admin = _membershipService.GetUser("admin");
|
||||
|
||||
if(!IsSlugValid(Slug)) {
|
||||
return "Invalid Slug provided. Blog creation failed.";
|
||||
}
|
||||
|
||||
var blog = _contentManager.New("blog");
|
||||
blog.As<ICommonAspect>().Owner = admin;
|
||||
blog.As<RoutableAspect>().Slug = Slug;
|
||||
blog.As<RoutableAspect>().Title = Title;
|
||||
if ( !String.IsNullOrWhiteSpace(MenuText) ) {
|
||||
blog.As<MenuPart>().OnMainMenu = true;
|
||||
blog.As<MenuPart>().MenuPosition = _menuService.Get().Select(menuPart => menuPart.MenuPosition).Max() + 1 + ".0";
|
||||
blog.As<MenuPart>().MenuText = MenuText;
|
||||
}
|
||||
_contentManager.Create(blog);
|
||||
|
||||
return "Blog created successfully";
|
||||
}
|
||||
|
||||
[CommandName("blog import")]
|
||||
[CommandHelp("blog import /Slug:<slug> /FeedUrl:<feed url>\r\n\t" + "Import all items from <feed url> into the blog at the specified <slug>")]
|
||||
[OrchardSwitches("FeedUrl,Slug")]
|
||||
public string Import() {
|
||||
var admin = _membershipService.GetUser("admin");
|
||||
|
||||
XDocument doc;
|
||||
|
||||
try {
|
||||
Context.Output.WriteLine("Loading feed...");
|
||||
doc = XDocument.Load(FeedUrl);
|
||||
Context.Output.WriteLine("Found {0} items", doc.Descendants("item").Count());
|
||||
}
|
||||
catch ( Exception ex ) {
|
||||
Context.Output.WriteLine(T("An error occured while loading the file: " + ex.Message));
|
||||
return "Import terminated.";
|
||||
}
|
||||
|
||||
var blog = _blogService.Get(Slug);
|
||||
|
||||
if ( blog == null ) {
|
||||
return "Blog not found at specified slug: " + Slug;
|
||||
}
|
||||
|
||||
foreach ( var item in doc.Descendants("item") ) {
|
||||
string postName = item.Element("title").Value;
|
||||
|
||||
Context.Output.WriteLine("Adding post: {0}...", postName.Substring(0, Math.Min(postName.Length, 40)));
|
||||
var post = _contentManager.New("blogpost");
|
||||
post.As<ICommonAspect>().Owner = admin;
|
||||
post.As<ICommonAspect>().Container = blog;
|
||||
post.As<RoutableAspect>().Slug = Slugify(postName);
|
||||
post.As<RoutableAspect>().Title = postName;
|
||||
post.As<BodyAspect>().Text = item.Element("description").Value;
|
||||
_contentManager.Create(post);
|
||||
}
|
||||
|
||||
|
||||
return "Import feed completed.";
|
||||
}
|
||||
|
||||
private static string Slugify(string slug) {
|
||||
var dissallowed = new Regex(@"[/:?#\[\]@!$&'()*+,;=\s]+");
|
||||
|
||||
slug = dissallowed.Replace(slug, "-");
|
||||
slug = slug.Trim('-');
|
||||
|
||||
if ( slug.Length > 1000 )
|
||||
slug = slug.Substring(0, 1000);
|
||||
|
||||
return slug.ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static bool IsSlugValid(string slug) {
|
||||
// see http://tools.ietf.org/html/rfc3987 for prohibited chars
|
||||
return slug == null || String.IsNullOrEmpty(slug.Trim()) || Regex.IsMatch(slug, @"^[^/:?#\[\]@!$&'()*+,;=\s]+$");
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,6 +9,7 @@ namespace Orchard.Blogs.Models {
|
||||
|
||||
public string Name {
|
||||
get { return this.As<RoutableAspect>().Title; }
|
||||
set { this.As<RoutableAspect>().Title = value; }
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Need a data type for slug
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<RootNamespace>Orchard.Blogs</RootNamespace>
|
||||
<AssemblyName>Orchard.Blogs</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<MvcBuildViews>true</MvcBuildViews>
|
||||
<MvcBuildViews>false</MvcBuildViews>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
@@ -66,6 +66,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\BlogCommands.cs" />
|
||||
<Compile Include="Controllers\BlogAdminController.cs" />
|
||||
<Compile Include="Drivers\BlogDriver.cs" />
|
||||
<Compile Include="Controllers\BlogPostAdminController.cs" />
|
||||
@@ -122,6 +123,7 @@
|
||||
<Content Include="Scripts\jquery.ui.widget.js" />
|
||||
<Content Include="Scripts\jquery.utils.js" />
|
||||
<Content Include="Scripts\ui.timepickr.js" />
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Styles\archives.css" />
|
||||
<Content Include="Styles\datetime.css" />
|
||||
<Content Include="Styles\images\ui-bg_flat_0_aaaaaa_40x100.png" />
|
||||
|
3
src/Orchard.Web/Modules/Orchard.Blogs/Styles/admin.css
Normal file
3
src/Orchard.Web/Modules/Orchard.Blogs/Styles/admin.css
Normal file
@@ -0,0 +1,3 @@
|
||||
.blogdescription {
|
||||
margin-top:1em;
|
||||
}
|
@@ -2,8 +2,8 @@
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<h1 class="withActions">
|
||||
<a href="<%=Url.BlogForAdmin(Model.Item.Slug) %>"><%: Html.TitleForPage(Model.Item.Name) %></a>
|
||||
<h1><a href="<%=Url.BlogForAdmin(Model.Item.Slug) %>"><%: Html.TitleForPage(Model.Item.Name) %></a>
|
||||
|
||||
</h1>
|
||||
<% Html.Zone("manage"); %><%--
|
||||
<form>
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<a href="<%=Url.BlogPostCreate(Model.Item) %>" title="<%: T("New Post") %>"><%: T("New Post") %></a><%: T(" | ")%>
|
||||
<a href="<%=Url.BlogEdit(Model.Item.Slug) %>" title="<%: T("Settings") %>"><%: T("Settings") %></a><%: T(" | ")%>
|
||||
<%-- todo: (heskew) this is waaaaa too verbose. need template helpers for all ibuttons --%>
|
||||
<% using (Html.BeginFormAntiForgeryPost(Url.BlogDelete(Model.Item.Slug), FormMethod.Post, new { @class = "inline" })) { %>
|
||||
<% using (Html.BeginFormAntiForgeryPost(Url.BlogDelete(Model.Item.Slug), FormMethod.Post, new { @class = "inline link" })) { %>
|
||||
<button type="submit" class="linkButton" title="<%: T("Remove") %>"><%: T("Remove") %></button><%
|
||||
} %>
|
||||
</div>
|
||||
|
@@ -2,6 +2,7 @@
|
||||
<%@ Import Namespace="Orchard.Blogs"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%><%
|
||||
Html.RegisterStyle("admin.css");
|
||||
if (AuthorizedFor(Permissions.ManageBlogs)) { %>
|
||||
<div class="folderProperties">
|
||||
<p><a href="<%=Url.BlogEdit(Model.Slug) %>" class="edit"><%: T("Edit") %></a></p>
|
||||
|
Reference in New Issue
Block a user