| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\DonationSpam\Akismet\DataTransferObjects; |
| 4 |
|
| 5 |
/** |
| 6 |
* @since 4.9.0 add #[AllowDynamicProperties] |
| 7 |
* @since 3.15.0 |
| 8 |
*/ |
| 9 |
#[\AllowDynamicProperties] |
| 10 |
class CommentCheckArgs |
| 11 |
{ |
| 12 |
public $blog; |
| 13 |
public $blog_lang; |
| 14 |
public $blog_charset; |
| 15 |
public $user_ip; |
| 16 |
public $user_agent; |
| 17 |
public $referrer; |
| 18 |
public $comment_type; |
| 19 |
public $comment_content; |
| 20 |
public $comment_author; |
| 21 |
public $comment_author_email; |
| 22 |
|
| 23 |
/** |
| 24 |
* @since 4.16.0 handle undefined server variables gracefully |
| 25 |
* @since 3.22.0 updated params to receive |
| 26 |
* @since 3.15.0 |
| 27 |
*/ |
| 28 |
public static function make(string $comment, string $email, string $firstName): CommentCheckArgs |
| 29 |
{ |
| 30 |
$self = new self(); |
| 31 |
|
| 32 |
$self->comment_type = 'contact-form'; |
| 33 |
$self->comment_content = $comment; |
| 34 |
$self->comment_author = $firstName; |
| 35 |
$self->comment_author_email = $email; |
| 36 |
|
| 37 |
$self->blog = get_option('home'); |
| 38 |
$self->blog_lang = get_locale(); |
| 39 |
$self->blog_charset = get_option('blog_charset'); |
| 40 |
|
| 41 |
$self->user_ip = $_SERVER['REMOTE_ADDR'] ?? ''; |
| 42 |
$self->user_agent = $_SERVER['HTTP_USER_AGENT'] ?? ''; |
| 43 |
$self->referrer = $_SERVER['HTTP_REFERER'] ?? ''; |
| 44 |
|
| 45 |
// Append additional server variables. |
| 46 |
foreach ( $_SERVER as $key => $value ) { |
| 47 |
if ( ! in_array( $key, [ 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ], true ) ) { |
| 48 |
$self->$key = $value; |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
return $self; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* @since 3.15.0 |
| 57 |
*/ |
| 58 |
public function toHttpQuery(): string |
| 59 |
{ |
| 60 |
return http_build_query(get_object_vars($this)); |
| 61 |
} |
| 62 |
} |
| 63 |
|