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