Download the PHP package morrelinko/spam-detector without Composer
On this page you can find all versions of the php package morrelinko/spam-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download morrelinko/spam-detector
More information about morrelinko/spam-detector
Files in morrelinko/spam-detector
Package spam-detector
Short Description An extensible simple spam detector library
License MIT
Informations about the package spam-detector
Spam Detector
Spam Filter is a simple library for detecting spam messages. It follows the open closed principle by introducing Spam Detectors which are just separate classes used to extend the spam filter detecting capabilities.
Installation
Spam Filter library can be loaded into your projects using Composer or by loading the inbuilt autoloader.
Composer Installation
You can define the spam filter as a dependency in your project. Below is a minimal setup required
Using autoload.php
If you are not using composer for your dependency (which you should) there is a simple autoloader packaged with this library which you can just 'include()' into your project files
Setup
This should be done once throughout your app
Usage
Each time you call the check()
method on a string, it returns a SpamResult
Object which holds the ... hmm ... spam check result.
You could provide more information about the entity trying to perform the action you are checking against the spam detector.
<?php
$check = $spamDetector->check(array(
'name' => 'johndoe',
'email' => '[email protected]',
'text' => 'Hello, this is some clean comment John Doe is trying to post'
));
if ($check->passed()) {
// Post comment
}
Some detectors will require these extra information to `perform`...
Currently Supported Spam Detectors
1. BlackList Detector:
The black list detector flags a string as a spam if it contains any of one or more words that has been added to the black list. Strings could be formed from Regular Expressions or a Character Sequence.
2. LinkRife Detector:
The link rifle detector checks if a text contains too many links based on the max links allowed and the percentage ratio of links to words.. You can also modify these values to your taste.
Creating your own custom Detector
You create a detector simply by creating a class that implements the SpamDetectorInterface
which defines the following contract.
interface SpamDetectorInterface
{
public function detect($data);
}
The prepared data passed as the argument is made up of an array with these values.
- 'name' => Optional name of the user. Could be username or full name [This is provided by you].
- 'email' => Optional e-mail address of the user [This is provided by you]
- 'text' => The content of the message [This is provided by you]
- 'ip' => The IP address of the user
- 'user_agent': The browser user-agent of the user
If your detector returns true
then the text is flagged as spam otherwise not spam if false is returned.
Below is an example of a "fantastic" spam detector that checks if a text is above 200 words and flags it as spam.
Its not usable, its just an example.
After creating your spam detector, you add it using the registerDetector()
method in the SpamFilter
Licence
The MIT License (MIT). Please see License File for more information.
Enjoy!!