PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.17.0
GiveWP – Donation Plugin and Fundraising Platform v4.17.0
4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 All 256 releases
give / src / DonationSpam / Akismet / Actions / ValidateDonation.php

ValidateDonation.php in GiveWP – Donation Plugin and Fundraising Platform 4.17.0, at src/DonationSpam/Akismet/Actions/ValidateDonation.php

64 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Give\DonationSpam\Akismet\Actions;
4
5 use Give\DonationSpam\Akismet\API;
6 use Give\DonationSpam\Akismet\DataTransferObjects\CommentCheckArgs;
7 use Give\DonationSpam\Akismet\DataTransferObjects\SpamContext;
8 use Give\DonationSpam\EmailAddressWhiteList;
9 use Give\DonationSpam\Exceptions\SpamDonationException;
10 use Give\Log\Log;
11
12 /**
13 * @since 3.15.0
14 */
15 class ValidateDonation
16 {
17 /**
18 * @var API
19 */
20 protected $akismet;
21
22 /**
23 * @var EmailAddressWhiteList
24 */
25 protected $whitelist;
26
27 /**
28 * @since 3.15.0
29 */
30 public function __construct(API $akismet, EmailAddressWhiteList $whitelist)
31 {
32 $this->akismet = $akismet;
33 $this->whitelist = $whitelist;
34 }
35
36 /**
37 * @since 3.22.0 replaced params to $email, $comment, $firstName, $lastName
38 * @since 3.15.0
39 *
40 * @param string $email
41 * @param string $comment
42 * @param string $firstName
43 * @param string|null $lastName
44 * @throws SpamDonationException
45 */
46 public function __invoke(string $email, string $comment, string $firstName, string $lastName): void
47 {
48 if(!$this->whitelist->validate($email)) {
49
50 $args = CommentCheckArgs::make($comment, $email, $firstName);
51 $response = $this->akismet->commentCheck($args);
52 $spam = 'true' === $response[1];
53
54 if($spam) {
55 $message = "This donor's email ($firstName $lastName - $email) has been flagged as SPAM";
56 if(!give_akismet_is_email_logged($email)) {
57 Log::spam($message, (array) new SpamContext($args, $response));
58 }
59 throw new SpamDonationException($message);
60 }
61 }
62 }
63 }
64