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