- Fixing a bug related to tag sanitization and cleaning up some dependencies.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043220
This commit is contained in:
suhacan
2009-12-04 20:47:24 +00:00
parent 4e93b3e601
commit 2917d86c0c
7 changed files with 28 additions and 37 deletions

View File

@@ -135,10 +135,6 @@
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
<Name>Orchard.Core</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Comments\Orchard.Comments.csproj">
<Project>{14C049FD-B35B-415A-A824-87F26B26E7FD}</Project>
<Name>Orchard.Comments</Name>
</ProjectReference>
<ProjectReference Include="..\Orchard.Users\Orchard.Users.csproj">
<Project>{79AED36E-ABD0-4747-93D3-8722B042454B}</Project>
<Name>Orchard.Users</Name>

View File

@@ -1,12 +1,10 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Blog>" %>
<%@ Import Namespace="Orchard.Comments.Models"%>
<%@ Import Namespace="Orchard.Models"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Blogs.Models"%>
<h3><a href="<%=Url.BlogForAdmin(Model.Slug) %>"><%=Html.Encode(Model.Name) %></a></h3>
<div class="meta">
<% var postCount = Model.PostCount; %><a href="<%=Url.BlogForAdmin(Model.Slug) %>"><%=string.Format("{0} post{1}", postCount, postCount == 1 ? "" : "s") %></a>
| <%var commentCount = (new Random()).Next(0, 1000); // Model.As<HasComments>().Comments.Count(); %><a href="#"><%=string.Format("{0} comment{1}", commentCount, commentCount == 1 ? "" : "s") %></a></div>
<% var postCount = Model.PostCount; %><a href="<%=Url.BlogForAdmin(Model.Slug) %>"><%=string.Format("{0} post{1}", postCount, postCount == 1 ? "" : "s") %></a></div>
<%--<p>[list of authors] [modify blog access]</p>--%>
<p><%=Model.Description %></p>
<p class="actions">

View File

@@ -1,5 +1,4 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BlogPost>" %>
<%@ Import Namespace="Orchard.Comments.Models"%>
<%@ Import Namespace="Orchard.Models"%>
<%@ Import Namespace="Orchard.Blogs.Extensions"%>
<%@ Import Namespace="Orchard.Core.Common.Models"%>
@@ -7,7 +6,6 @@
<h3><a href="<%=Url.BlogPostEdit(Model.Blog.Slug, Model.Slug) %>"><%=Html.Encode(Model.Title) %></a></h3>
<div class="meta">
<%=Html.Published() %>
| <%var commentCount = Model.As<HasComments>().Comments.Count(); %><a href="#"><%=string.Format("{0} comment{1}", commentCount, commentCount == 1 ? "" : "s") %></a>
</div>
<div class="content"><%=Model.Body ?? "<p><em>there's no content for this blog post</em></p>" %></div>
<p class="actions">

View File

@@ -6,6 +6,7 @@ using Orchard.Localization;
using Orchard.Logging;
using Orchard.Models;
using Orchard.Settings;
using Orchard.Tags.Helpers;
using Orchard.Tags.Models;
using Orchard.Tags.Services;
using Orchard.Tags.ViewModels;
@@ -54,7 +55,7 @@ namespace Orchard.Tags.Controllers {
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
return new HttpUnauthorizedResult();
if (!String.IsNullOrEmpty(newTagName)) {
foreach (var tagName in ParseCommaSeparatedTagNames(newTagName)) {
foreach (var tagName in TagHelpers.ParseCommaSeparatedTagNames(newTagName)) {
if (_tagService.GetTagByName(tagName) == null) {
_tagService.CreateTag(tagName);
}
@@ -80,7 +81,7 @@ namespace Orchard.Tags.Controllers {
try {
if (!_authorizer.Authorize(Permissions.CreateTag, T("Couldn't create tag")))
return new HttpUnauthorizedResult();
List<string> tagNames = ParseCommaSeparatedTagNames(tags);
List<string> tagNames = TagHelpers.ParseCommaSeparatedTagNames(tags);
_tagService.UpdateTagsForContentItem(taggedContentId, tagNames);
if (!String.IsNullOrEmpty(returnUrl)) {
return Redirect(returnUrl);
@@ -96,17 +97,6 @@ namespace Orchard.Tags.Controllers {
}
}
private static List<string> ParseCommaSeparatedTagNames(string tags) {
IEnumerable<string> tagNames = tags.Split(',');
List<string> sanitizedTagNames = new List<string>();
foreach (var tagName in tagNames) {
if (!String.IsNullOrEmpty(tagName)) {
sanitizedTagNames.Add(tagName);
}
}
return sanitizedTagNames;
}
public ActionResult Search(string tagName) {
try {
Tag tag = _tagService.GetTagByName(tagName);

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Orchard.Tags.Helpers {
public class TagHelpers {
public static List<string> ParseCommaSeparatedTagNames(string tags) {
if (String.IsNullOrEmpty(tags)) {
return new List<string>();
}
IEnumerable<string> tagNames = tags.Split(',');
List<string> sanitizedTagNames = new List<string>();
foreach (var tagName in tagNames) {
string sanitizedTagName = tagName.Trim();
if (!String.IsNullOrEmpty(sanitizedTagName)) {
sanitizedTagNames.Add(sanitizedTagName);
}
}
return sanitizedTagNames;
}
}
}

View File

@@ -5,6 +5,7 @@ using Orchard.Data;
using Orchard.Models;
using Orchard.Models.Driver;
using Orchard.Models.ViewModels;
using Orchard.Tags.Helpers;
using Orchard.Tags.Services;
namespace Orchard.Tags.Models {
@@ -50,7 +51,7 @@ namespace Orchard.Tags.Models {
TagsViewModel viewModel = new TagsViewModel();
context.Updater.TryUpdateModel(viewModel, String.Empty, null, null);
List<string> tagNames = ParseCommaSeparatedTagNames(viewModel.Tags);
List<string> tagNames = TagHelpers.ParseCommaSeparatedTagNames(viewModel.Tags);
_tagService.UpdateTagsForContentItem(context.ContentItem.Id, tagNames);
context.AddEditor(new TemplateViewModel(context.ContentItem.Get<HasTags>()));
@@ -70,20 +71,6 @@ namespace Orchard.Tags.Models {
}
}
private static List<string> ParseCommaSeparatedTagNames(string tags) {
if (String.IsNullOrEmpty(tags)) {
return new List<string>();
}
IEnumerable<string> tagNames = tags.Split(',');
List<string> sanitizedTagNames = new List<string>();
foreach (var tagName in tagNames) {
if (!String.IsNullOrEmpty(tagName)) {
sanitizedTagNames.Add(tagName);
}
}
return sanitizedTagNames;
}
public class TagsViewModel {
public string Tags { get; set; }
}

View File

@@ -64,6 +64,7 @@
<Compile Include="AdminMenu.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Helpers\TagHelpers.cs" />
<Compile Include="Models\Tag.cs" />
<Compile Include="Models\TagSettings.cs" />
<Compile Include="Models\TagsHandler.cs" />