- Comments: akismet integration, adding a few spam related settings to the package (enablespamprotection, akismetkey etc), minor refactoring.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041482
This commit is contained in:
suhacan
2009-11-20 02:06:46 +00:00
parent da866aed29
commit b759bba2ec
7 changed files with 79 additions and 7 deletions

Binary file not shown.

View File

@@ -0,0 +1,12 @@
BSD License
Copyright (c) 2006, Joel Thoms
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the JOEL.NET nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -4,15 +4,20 @@ using Orchard.Models.Driver;
using Orchard.Models.Records;
namespace Orchard.Comments.Models {
public class CommentSettings : ContentPartForRecord<CommentSettingsRecord> {
}
public class CommentSettingsRecord : ContentPartRecord {
public virtual bool RequireLoginToAddComment { get; set; }
public virtual bool EnableCommentsOnPages { get; set; }
public virtual bool EnableCommentsOnPosts { get; set; }
public virtual bool EnableSpamProtection { get; set; }
public virtual string AkismetKey { get; set; }
}
public class CommentSettingsHandler : ContentHandler {
public CommentSettingsHandler(IRepository<CommentSettingsRecord> repository) {
Filters.Add(new ActivatingFilter<ContentPartForRecord<CommentSettingsRecord>>("site"));
Filters.Add(new ActivatingFilter<CommentSettings>("site"));
Filters.Add(new StorageFilterForRecord<CommentSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
Filters.Add(new TemplateFilterForRecord<CommentSettingsRecord>("CommentSettings"));
}

View File

@@ -31,6 +31,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Joel.Net.Akismet, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\lib\joel.net.akismet\Joel.Net.Akismet.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.ComponentModel.DataAnnotations">

View File

@@ -1,23 +1,60 @@
using Orchard.Comments.Models;
using System;
using System.Web;
using Orchard.Comments.Models;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Models;
using Orchard.Settings;
using Orchard.UI.Notify;
using Joel.Net;
namespace Orchard.Comments.Services {
public interface ICommentValidator : IDependency {
bool ValidateComment(Comment comment);
}
public class CommentValidator : ICommentValidator {
public CommentValidator() {
//This uses an akismet api implementation from http://akismetapi.codeplex.com/
//Since the implementation is trivial, it may make sense to implement it to reduce dependencies.
public class AkismetCommentValidator : ICommentValidator {
private readonly INotifier _notifer;
public AkismetCommentValidator(INotifier notifier) {
_notifer = notifier;
Logger = NullLogger.Instance;
T = NullLocalizer.Instance;
}
public ILogger Logger { get; set; }
public Localizer T { get; set; }
public ISite CurrentSite { get; set; }
#region Implementation of ICommentValidator
public bool ValidateComment(Comment comment) {
//TODO: integrate spam filter.
return true;
CommentSettingsRecord commentSettingsRecord = CurrentSite.As<CommentSettings>().Record;
string akismetKey = commentSettingsRecord.AkismetKey;
bool enableSpamProtection = commentSettingsRecord.EnableSpamProtection;
if (enableSpamProtection == false) {
return true;
}
if (String.IsNullOrEmpty(akismetKey)) {
_notifer.Information(T("Please configure your Akismet key for spam protection"));
return true;
}
Akismet akismetApi = new Akismet(akismetKey, "http://www.orchardproject.net", null);
AkismetComment akismetComment = new AkismetComment {
CommentAuthor = comment.Author,
CommentAuthorEmail = comment.Email,
Blog = comment.SiteName,
CommentAuthorUrl = comment.SiteName,
CommentContent = comment.CommentText,
UserAgent = HttpContext.Current.Request.UserAgent,
};
if (akismetApi.VerifyKey()) {
return akismetApi.CommentCheck(akismetComment);
}
return false;
}
#endregion

View File

@@ -66,7 +66,11 @@
<% else {%> Approved <% } %>
</td>
<td><%= commentEntry.Comment.UserName %></td>
<td><%= commentEntry.Comment.CommentText == null ? String.Empty : commentEntry.Comment.CommentText.Substring(32) %></td>
<td>
<% if (commentEntry.Comment.CommentText != null) {%>
<%= commentEntry.Comment.CommentText.Length > 23 ? commentEntry.Comment.CommentText.Substring(0, 24) : commentEntry.Comment.CommentText %>
<% } %>
</td>
<td><%= commentEntry.Comment.CommentDate %></td>
<td>Link to commented item</td>
</tr>

View File

@@ -16,4 +16,14 @@
<%= Html.EditorFor(x=>x.EnableCommentsOnPosts) %>
<%= Html.ValidationMessage("EnableCommentsOnPosts", "*")%>
</li>
<li>
<%= Html.LabelFor(x=>x.EnableSpamProtection) %>
<%= Html.EditorFor(x=>x.EnableSpamProtection) %>
<%= Html.ValidationMessage("EnableSpamProtection", "*")%>
</li>
<li>
<%= Html.LabelFor(x=>x.AkismetKey) %>
<%= Html.EditorFor(x=>x.AkismetKey) %>
<%= Html.ValidationMessage("AkismetKey", "*")%>
</li>
</ol>