|
<?php |
|
// https://akismet.com/development/api/#comment-check |
|
|
|
class qa_akismet { |
|
|
|
function akismet_comment_check( $data ) { |
|
$key = '123456789'; |
|
$data['blog'] = "https://domain.com/forum/"; |
|
$data['user_agent'] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6"; |
|
$data['user_ip'] = qa_remote_ip_address(); |
|
if( empty($data['comment_author']) ){$data['comment_author']=qa_get_logged_in_handle();} |
|
if( empty($data['comment_author_email']) ){$data['comment_author_email']=qa_get_logged_in_email();} |
|
|
|
$request = 'blog='. urlencode($data['blog']) . |
|
'&user_ip='. urlencode($data['user_ip']) . |
|
'&user_agent='. urlencode($data['user_agent']) . |
|
'&comment_type='. urlencode($data['comment_type']) . |
|
'&comment_author='. urlencode($data['comment_author']) . |
|
'&comment_author_email='. urlencode($data['comment_author_email']) . |
|
'&comment_content='. urlencode($data['comment_content']); |
|
$host = $http_host = $key.'.rest.akismet.com'; |
|
$path = '/1.1/comment-check'; |
|
$port = 443; |
|
$akismet_ua = "Question2Answer | Community Forum"; |
|
$content_length = strlen( $request ); |
|
$http_request = "POST $path HTTP/1.0\r\n"; |
|
$http_request .= "Host: $host\r\n"; |
|
$http_request .= "Content-Type: application/x-www-form-urlencoded\r\n"; |
|
$http_request .= "Content-Length: {$content_length}\r\n"; |
|
$http_request .= "User-Agent: {$akismet_ua}\r\n"; |
|
$http_request .= "\r\n"; |
|
$http_request .= $request; |
|
$response = ''; |
|
if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) { |
|
|
|
fwrite( $fs, $http_request ); |
|
|
|
while ( !feof( $fs ) ) |
|
$response .= fgets( $fs, 1160 ); // One TCP-IP packet |
|
fclose( $fs ); |
|
|
|
$response = explode( "\r\n\r\n", $response, 2 ); |
|
} |
|
|
|
// Passes back true (it's spam) or false (it's ham) |
|
if ( 'true' == $response[1] ) |
|
return true; |
|
else |
|
return false; |
|
} |
|
|
|
function filter_question(&$question, &$errors, $oldquestion) { |
|
// Don't check for admins and known users |
|
if (( is_numeric(qa_get_logged_in_level()) and qa_get_logged_in_level() > 49 ) || (is_numeric(qa_get_logged_in_points()) and qa_get_logged_in_points() > 200)) |
|
return; |
|
|
|
// combine question title and content for spam processing |
|
$combined_content = $question['title'].' '.$question['text']; |
|
$check_content = array( |
|
'comment_type' => 'forum-post', |
|
'comment_author_email' => $question['email'], |
|
'comment_content' => $combined_content |
|
); |
|
|
|
if (self::akismet_comment_check($check_content)) { |
|
$question['queued']=true; |
|
} |
|
} |
|
|
|
function filter_answer(&$answer, &$errors, $question, $oldanswer) { |
|
// Don't check for admins and known users |
|
if (( is_numeric(qa_get_logged_in_level()) and qa_get_logged_in_level() > 49 ) || (is_numeric(qa_get_logged_in_points()) and qa_get_logged_in_points() > 200)) |
|
return; |
|
|
|
$check_content = array( |
|
'comment_type' => 'reply', |
|
'comment_author_email' => $answer['email'], |
|
'comment_content' => $answer['text'] |
|
); |
|
|
|
if (self::akismet_comment_check($check_content)) { |
|
$answer['queued']=true; |
|
} |
|
} |
|
|
|
function filter_comment(&$comment, &$errors, $question, $parent, $oldcomment) { |
|
// Don't check for admins and known users |
|
if (( is_numeric(qa_get_logged_in_level()) and qa_get_logged_in_level() > 49 ) || (is_numeric(qa_get_logged_in_points()) and qa_get_logged_in_points() > 200)) |
|
return; |
|
|
|
$check_content = array( |
|
'comment_type' => 'reply', |
|
'comment_author_email' => $comment['email'], |
|
'comment_content' => $comment['text'] |
|
); |
|
|
|
if (self::akismet_comment_check($check_content)) { |
|
$comment['queued']=true; |
|
} |
|
} |
|
|
|
} |
Hey,
Thank you, where to get the "key" from ?