Zon3.SpamDetector
1.5.0
dotnet add package Zon3.SpamDetector --version 1.5.0
NuGet\Install-Package Zon3.SpamDetector -Version 1.5.0
<PackageReference Include="Zon3.SpamDetector" Version="1.5.0" />
paket add Zon3.SpamDetector --version 1.5.0
#r "nuget: Zon3.SpamDetector, 1.5.0"
// Install Zon3.SpamDetector as a Cake Addin #addin nuget:?package=Zon3.SpamDetector&version=1.5.0 // Install Zon3.SpamDetector as a Cake Tool #tool nuget:?package=Zon3.SpamDetector&version=1.5.0
SpamDetector
Server | Status |
---|---|
GitHub Actions | |
GitHub Actions | |
NuGet |
Description
A Piranha CMS module providing spam detection for page and post comments.
About
Project page: zon3.se/spamdetector<br> Source code: github.com/jensbrak/SpamDetector<br> NuGet package: nuget.org/packages/Zon3.SpamDetector/<br> <br> Piranha CMS provides a feature to allow visitors to comment posts and pages. Out of the box, there is no mechanism to prevent spamming the site with unsolicited comments. This module adds automatic spam detection functionality for submitted comments. It does so by using the free to use Akismet service for spam detection. Once configured, the module will intercept all comments before they are published. If considered spam, the comment is marked as not approved, effectively stopping it from being published. If not considered spam, the comment is marked as approved and is published.
Note
While providing working antispam functionality, the purpose of this module was primarly to explore and learn about Piranha. The documentation and samples are helpful when writing a module with one exception: Manager support. I wanted to see what it took to make a module with full Manager support, including persistance, localization (while keeping the look and feel of the internal Piranha modules). In other words: You might have use for this module even if antispam/comments are not of interest - if you just want to understand how Manager support can be added to a custom Piranha module. There's no claim that this is the right way to do it, however.
Dependencies
.NET 8
Zon3.SpamDetector.Localization
Microsoft.Extensions.Http
version 8Microsoft.Extensions.Localization
version 8Piranha
version 11Piranha.Manager
version 11- Also: An Akismet API key
Demo
Please go ahead and try it out by posting a comment with a greeting on my blog. It runs PiranhaCMS with this module active. If your comment is directly visible it's been classified by akismet as non-spam and approved by the SpamDetector module as a valid comment. If not, stop spamming! (Or report a bug to me 😉 )
My PiranhaCMS demo site: zon3.se
Installation
See Instructions below and/or the example Startup.cs
(for Piranha prior version 10.0.3) or Program.cs
(for Piranha version 10.0.3 and up). The files are from the piranha.razor template with relevant code added.
Code adjustments in your Piranha project
- Get and add the SpamDetector module to your Piranha project, either by source or package:
- Using source code: Downloading the source code and add a project reference to
Zon3.SpamDetector.csproj
+Zon3.SpamDetector.localization.csproj
OR - Using NuGet package manager: Add the SpamDetector and SpamDetector.Localization packages as a NuGet dependencies
- Using source code: Downloading the source code and add a project reference to
- Add a reference to
Zon3.SpamDetector
in your Piranha project startup file (Program.cs for Piranha version 10.0.3 and up, Startup.cs otherwise) - In startup file add code to register SpamDetector service and middleware and attach it to the proper hook:
- Register
SpamDetector
service - Register
SpamDetector
middleware - Register a Comment validation hook and call
SpamDetector.ReviewAsync(Comment c)
to get validation result. - Make sure the hook use the validation to set the comment status (
IsApproved
)
- Register
Settings
Once installed, the module is accessed and configured via Piranha Manager, under Settings
in the menu.
Values that are mandatory are marked with (Required). Without these properly set, the module won't work.
Module settings
These settings control the module:
- (Required) Module enabled : use this to turn the module on or off.
- (Required) Test mode enabled: use this while setting up and testing the module. This will advice Akismet that comments sent are for testing purposes only. Don't forget to turn off once the module is setup and testing is done.
- (Required) API URL: the personal, site-specific API key to use to make calls to Akismet (see akismet.com/development/api).
Site settings
These settings are sent to Akismet along with the comments to help review the content submitted:
- (Required) URL: The full URL of the frontpage of the blog/site using the SpamDetector module.
- Language: The language(s) used by the site (ie the expected languages of the comments submitted). A comma separated list of ISO 639-1 formatted for all languages used by the site.
- Encoding: The character encoding for the form values of submitted comments ('Your name', 'your email address', 'An (optional) URL to your website' and 'Your awesome comment').
- User role: The user role of the user who submitted the comment (if any).
Localization
The module itself supports localization, it works similar to how Piranha is localized. Note: the support is not complete: the texts with module info does not yet support localization.
Issues and feedback
Found an issue with the module? Feedback or ideas about it?<br> Visit the GitHub page of the module and submit an issue.<br> <br> Issues: github.com/jensbrak/SpamDetector/issues
Further reading
Selected links relevant to this module:
- Piranha Modules:
- Piranha Hooks:
- Akismet API documentation:
- Related Piranha issues:
- Redesign of Hooks: github.com/PiranhaCMS/piranha.core/issues/1236
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Localization (>= 8.0.3)
- Piranha (>= 11.0.0)
- Piranha.Manager (>= 11.0.0)
- Zon3.SpamDetector.Localization (>= 1.5.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.