Server | Status |
---|---|
GitHub Actions | |
GitHub Actions | |
NuGet |
A Piranha CMS module providing spam detection for page and post comments.
Project page: zon3.se/spamdetector
Source code: github.com/jensbrak/SpamDetector
NuGet package: nuget.org/packages/Zon3.SpamDetector/
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.
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.
.NET 8
Zon3.SpamDetector.Localization
Microsoft.Extensions.Http
version 8Microsoft.Extensions.Localization
version 8Piranha
version 11Piranha.Manager
version 11- Also: An Akismet API key
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
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.
- 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
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.
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).
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).
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.
Found an issue with the module? Feedback or ideas about it?
Visit the GitHub page of the module and submit an issue.
Issues: github.com/jensbrak/SpamDetector/issues
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