-
Notifications
You must be signed in to change notification settings - Fork 1
/
akismet.php
144 lines (132 loc) · 3.38 KB
/
akismet.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/**
Akismet plugin for the PHP Fat-Free Framework
The contents of this file are subject to the terms of the GNU General
License Version 3.0. You may not use this file except in
compliance with the license. Any of the license terms and conditions
can be waived if you get permission from the copyright holder.
Copyright (c) 2009-2012 F3::Factory
Bong Cosca <[email protected]>
@package Akismet
@version 2.0.12
**/
//! Akismet API adaptor
class Akismet extends Base {
//@{ Locale-specific error/exception messages
const
TEXT_VerifyFail='Akismet verification failed';
//@}
static
//! Akismet key verification flag
$verified=FALSE,
//! Verification key (NULL if unverified/invalid)
$key=NULL;
/**
Akismet key verification
@return boolean
@param $key string
@public
**/
static function verify($key) {
$response=Web::http(
'GET http://rest.akismet.com/1.1/verify-key',
http_build_query(
array(
'key'=>$key,
'blog'=>'http://'.$_SERVER['SERVER_NAME']
)
)
);
if (preg_match('/invalid/i',$response)) {
trigger_error(self::TEXT_VerifyFail);
self::$key=NULL;
}
else
self::$key=$key;
return self::$key;
}
/**
Forward content for spam checking
@return boolean
@param $text string
@param $author string
@param $email string
@param $url string
@public
**/
static function check($text,$author,$email,$url) {
$response=Web::http(
'GET http://'.self::$key.'.rest.akismet.com/1.1/comment-check',
http_build_query(
array(
'comment_content'=>$text,
'comment_author'=>$author,
'comment_author_email'=>$email,
'comment_author_url'=>$url,
'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
'referrer'=>$_SERVER['HTTP_REFERER'],
'blog'=>'http://'.$_SERVER['SERVER_NAME'],
'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
$_SERVER['REQUEST_URI']
)
)
);
return (boolean)$response;
}
/**
Report content that was not marked as spam
@return boolean
@param $text string
@param $author string
@param $email string
@param $url string
@public
**/
static function spam($text,$author,$email,$url) {
$response=Web::http(
'GET http://'.self::$key.'.rest.akismet.com/1.1/submit-spam',
http_build_query(
array(
'comment_content'=>$text,
'comment_author'=>$author,
'comment_author_email'=>$email,
'comment_author_url'=>$url,
'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
'referrer'=>$_SERVER['HTTP_REFERER'],
'blog'=>'http://'.$_SERVER['SERVER_NAME'],
'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
$_SERVER['REQUEST_URI']
)
)
);
return (boolean)$response;
}
/**
Report content as a false positive
@return boolean
@param $text string
@param $author string
@param $email string
@param $url string
@public
**/
static function ham($text,$author,$email,$url) {
$response=Web::http(
'GET http://'.self::$key.'.rest.akismet.com/1.1/submit-ham',
http_build_query(
array(
'comment_content'=>$text,
'comment_author'=>$author,
'comment_author_email'=>$email,
'comment_author_url'=>$url,
'user_agent'=>$_SERVER['HTTP_USER_AGENT'],
'referrer'=>$_SERVER['HTTP_REFERER'],
'blog'=>'http://'.$_SERVER['SERVER_NAME'],
'permalink'=>'http://'.$_SERVER['SERVER_NAME'].'/'.
$_SERVER['REQUEST_URI']
)
)
);
return (boolean)$response;
}
}