mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 12:09:41 +08:00
- BBcode support for url,url with anchor and image bbcodes for the content body.
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Orchard.ContentManagement;
|
||||
using System.Text.RegularExpressions;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Drivers;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Core.Common.ViewModels;
|
||||
@@ -19,7 +20,7 @@ namespace Orchard.Core.Common.Controllers {
|
||||
|
||||
// \/\/ Haackalicious on many accounts - don't copy what has been done here for the wrapper \/\/
|
||||
protected override DriverResult Display(BodyAspect part, string displayType) {
|
||||
var model = new BodyDisplayViewModel { BodyAspect = part };
|
||||
var model = new BodyDisplayViewModel { BodyAspect = part, Text = BbcodeReplace(part.Text)};
|
||||
return Combined(
|
||||
Services.Authorizer.Authorize(Permissions.ChangeOwner) ? ContentPartTemplate(model, "Parts/ManageWrapperPre").Location("primary", "5") : null,
|
||||
Services.Authorizer.Authorize(Permissions.ChangeOwner) ? ContentPartTemplate(model, "Parts/Manage").Location("primary", "5") : null,
|
||||
@@ -37,5 +38,18 @@ namespace Orchard.Core.Common.Controllers {
|
||||
updater.TryUpdateModel(model, Prefix, null, null);
|
||||
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5");
|
||||
}
|
||||
|
||||
// Can be moved somewhere else once we have IoC enabled body text filters.
|
||||
private static string BbcodeReplace(string bodyText) {
|
||||
Regex urlRegex = new Regex(@"\[url\]([^\]]+)\[\/url\]");
|
||||
Regex urlRegexWithLink = new Regex(@"\[url=([^\]]+)\]([^\]]+)\[\/url\]");
|
||||
Regex imgRegex = new Regex(@"\[img\]([^\]]+)\[\/img\]");
|
||||
|
||||
bodyText = urlRegex.Replace(bodyText, "<a href=\"$1\">$1</a>");
|
||||
bodyText = urlRegexWithLink.Replace(bodyText, "<a href=\"$1\">$2</a>");
|
||||
bodyText = imgRegex.Replace(bodyText, "<img src=\"$1\" />");
|
||||
|
||||
return bodyText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,5 +3,6 @@
|
||||
namespace Orchard.Core.Common.ViewModels {
|
||||
public class BodyDisplayViewModel {
|
||||
public BodyAspect BodyAspect { get; set; }
|
||||
public string Text { get; set; }
|
||||
}
|
||||
}
|
@@ -1,3 +1,3 @@
|
||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BodyDisplayViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
|
||||
<%=Model.BodyAspect.Record.Text %>
|
||||
<%=Model.Text %>
|
@@ -6,4 +6,4 @@
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2>
|
||||
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
|
||||
<div class="content"><%=Model.Item.Text ?? string.Format("<p><em>{0}</em></p>", _Encoded("there's no content for this blog post"))%></div>
|
||||
<div class="content"><% Html.Zone("primary", ":manage :metadata");%></div>
|
||||
|
@@ -1,6 +1,9 @@
|
||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Orchard.Pages.Models.Page>>" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
<%@ Import Namespace="Orchard.ContentManagement"%>
|
||||
<%@ Import Namespace="Orchard.Core.Common.Models"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||
<h3><a href="<%=Url.Action(T("Item").ToString(), "Page", new { slug = Model.Item.Slug }) %>"><%=Html.Encode(Model.Item.Title) %></a></h3>
|
||||
<div class="content"><%=Model.Item.As<BodyAspect>().Text ?? T("<p><em>there's no content for this blog post</em></p>").ToString() %></div>
|
||||
<div class="content">
|
||||
<% Html.Zone("primary", ":manage :metadata"); %>
|
||||
</div>
|
@@ -6,4 +6,6 @@
|
||||
<%@ Import Namespace="Orchard.Blogs.Models"%>
|
||||
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2>
|
||||
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
|
||||
<div class="postsummary"><%=Model.Item.Text ?? string.Format("<p><em>{0}</em></p>", _Encoded("there's no content for this blog post"))%></div>
|
||||
<div class="postsummary">
|
||||
<% Html.Zone("primary", ":manage :metadata"); %>
|
||||
</div>
|
||||
|
@@ -9,4 +9,6 @@
|
||||
|
||||
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div>
|
||||
|
||||
<div class="postsummary"><%=Model.Item.Text ?? string.Format("<p><em>{0}</em></p>", _Encoded("there's no content for this blog post"))%></div>
|
||||
<div class="postsummary">
|
||||
<% Html.Zone("primary", ":manage :metadata"); %>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user