-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpamFilter.php
More file actions
56 lines (45 loc) · 1.82 KB
/
Copy pathSpamFilter.php
File metadata and controls
56 lines (45 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Modules\IP2Location;
use Lightning\Tools\Configuration;
use Lightning\Tools\Messages\SpamFilterInterface;
use Modules\IP2Location\Model\Range;
class SpamFilter implements SpamFilterInterface {
/**
* @param array $message
*
* @return int
* 5 if it was found in the blacklist or 0 if not
*/
public static function getScore(&$message) {
if (!empty($message['IP'])) {
if ($location = Range::loadByIP($message['IP'])) {
$config = Configuration::get('modules.ip2location');
$message['country_code'] = $location['country_code'];
$message['country'] = $location['country'];
$message['region'] = $location['region'];
$message['city'] = $location['city'];
// Check white and blacklists.
foreach (['whitelist', 'blacklist'] as $list) {
// If the IP's country is in this list
if (in_array($location['country_code'], $config[$list . '_countries'])) {
// Add information about what was found.
// Then return this lists value.
$message['ip2location_filter'] = 'Country found in ' . $list;
return $config[$list . '_score'];
}
}
} else {
$message['country_code'] = '-';
$message['country'] = '-';
$message['region'] = '-';
$message['city'] = '-';
}
}
$message['ip2location_filter'] = 'Country not found in any list';
// The IP address was not found, do not rate it as spam.
return 0;
}
public static function flagAsSpam($message) {
// At this time, this RBL is read only.
}
}