- BBcode support for url,url with anchor and image bbcodes for the content body.

--HG--
branch : dev
This commit is contained in:
Suha Can
2010-03-02 14:51:08 -08:00
parent 459fd7f155
commit 6a5d07a67c
7 changed files with 29 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
using Orchard.ContentManagement; using System.Text.RegularExpressions;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers; using Orchard.ContentManagement.Drivers;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Core.Common.ViewModels; 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 \/\/ // \/\/ Haackalicious on many accounts - don't copy what has been done here for the wrapper \/\/
protected override DriverResult Display(BodyAspect part, string displayType) { 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( return Combined(
Services.Authorizer.Authorize(Permissions.ChangeOwner) ? ContentPartTemplate(model, "Parts/ManageWrapperPre").Location("primary", "5") : null, 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, 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); updater.TryUpdateModel(model, Prefix, null, null);
return ContentPartTemplate(model, TemplateName, Prefix).Location("primary", "5"); 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;
}
} }
} }

View File

@@ -3,5 +3,6 @@
namespace Orchard.Core.Common.ViewModels { namespace Orchard.Core.Common.ViewModels {
public class BodyDisplayViewModel { public class BodyDisplayViewModel {
public BodyAspect BodyAspect { get; set; } public BodyAspect BodyAspect { get; set; }
public string Text { get; set; }
} }
} }

View File

@@ -1,3 +1,3 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BodyDisplayViewModel>" %> <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BodyDisplayViewModel>" %>
<%@ Import Namespace="Orchard.Core.Common.ViewModels"%> <%@ Import Namespace="Orchard.Core.Common.ViewModels"%>
<%=Model.BodyAspect.Record.Text %> <%=Model.Text %>

View File

@@ -6,4 +6,4 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2> <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="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>

View File

@@ -1,6 +1,9 @@
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Orchard.Pages.Models.Page>>" %> <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<ContentItemViewModel<Orchard.Pages.Models.Page>>" %>
<%@ Import Namespace="Orchard.Mvc.Html"%>
<%@ Import Namespace="Orchard.ContentManagement"%> <%@ Import Namespace="Orchard.ContentManagement"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%> <%@ Import Namespace="Orchard.Core.Common.Models"%>
<%@ Import Namespace="Orchard.Mvc.ViewModels"%> <%@ 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> <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>

View File

@@ -6,4 +6,6 @@
<%@ Import Namespace="Orchard.Blogs.Models"%> <%@ Import Namespace="Orchard.Blogs.Models"%>
<h2><%=Html.Link(Html.Encode(Model.Item.Title), Url.BlogPost(Model.Item.Blog.Slug, Model.Item.Slug)) %></h2> <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="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>

View File

@@ -9,4 +9,6 @@
<div class="meta"><%=Html.PublishedState(Model.Item) %> | <%Html.Zone("meta");%></div> <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>