Skip to content

Commit 1b21b36

Browse files
fix: add checks for empty linkbacks, refs #500
1 parent 873c616 commit 1b21b36

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/Handlers/Linkback.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,38 @@
44

55
use AntispamBee\GeneralOptions\IgnoreLinkbacks;
66
use AntispamBee\Helpers\ContentTypeHelper;
7+
use AntispamBee\Helpers\IpHelper;
78

89
class Linkback extends Reaction {
910
protected static $content_type = 'linkback';
1011

11-
public static function process( $reaction ) {
12-
if ( ! ContentTypeHelper::reaction_is_one_of( $reaction, [ 'pingback', 'trackback', 'pings' ], '' ) ) {
13-
return $reaction;
12+
public static function process( $linkback ) {
13+
if ( ! ContentTypeHelper::reaction_is_one_of( $linkback, [ 'pingback', 'trackback', 'pings' ], '' ) ) {
14+
return $linkback;
1415
}
1516

1617
if ( IgnoreLinkbacks::is_active() ) {
17-
return $reaction;
18+
return $linkback;
1819
}
1920

20-
if ( self::is_linkback_title_blog_name( $reaction ) ) {
21-
return self::handle_spam( $reaction, [ 'asb-title-is-blogname' ] );
21+
if ( self::is_linkback_title_blog_name( $linkback ) ) {
22+
return self::handle_spam( $linkback, [ 'asb-title-is-blogname' ] );
2223
}
2324

24-
parent::process( $reaction );
25+
$ip = IpHelper::get_client_ip();
26+
$url = $linkback['comment_author_url'] ?? '';
27+
$body = $linkback['comment_content'];
28+
29+
if ( empty( $url ) || empty( $body ) || empty( $ip ) ) {
30+
return self::handle_spam( $linkback, [ 'asb-empty' ] );
31+
}
32+
33+
parent::process( $linkback );
2534
}
2635

27-
protected static function is_linkback_title_blog_name( $reaction ) {
28-
$body = $reaction['comment_content'];
29-
$blog_name = $reaction['comment_author'];
36+
protected static function is_linkback_title_blog_name( $linkback ) {
37+
$body = $linkback['comment_content'];
38+
$blog_name = $linkback['comment_author'];
3039

3140
preg_match( '/<strong>(.*)<\/strong>\\n\\n/', $body, $matches );
3241
if ( ! isset( $matches[1] ) ) {

0 commit comments

Comments
 (0)