X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModeration%2FDomainPatternBlocklist.php;h=259225c491e5812aff30fc0d069ddb6c965cc265;hb=e0686ac1d9932286ba56e0299cd9c3813f5afd9b;hp=a57b5f04cbf2437a24ce5c45f02fbe979e822b15;hpb=6e7823eaaa97db85f4816dd8411280ff9f82c743;p=friendica.git diff --git a/src/Moderation/DomainPatternBlocklist.php b/src/Moderation/DomainPatternBlocklist.php index a57b5f04cb..259225c491 100644 --- a/src/Moderation/DomainPatternBlocklist.php +++ b/src/Moderation/DomainPatternBlocklist.php @@ -1,6 +1,6 @@ config = $config; - $this->db = $db; - $this->emailer = $emailer; - $this->l10n = $l10n; - $this->baseUrl = $baseUrl; + $this->config = $config; } public function get(): array @@ -62,17 +45,13 @@ class DomainPatternBlocklist public function set(array $blocklist): bool { - $result = $this->config->set('system', 'blocklist', $blocklist); - if ($result) { - $this->notifyAll(); - } - - return $result; + return $this->config->set('system', 'blocklist', $blocklist); } /** * @param string $pattern * @param string $reason + * * @return int 0 if the block list couldn't be saved, 1 if the pattern was added, 2 if it was updated in place */ public function addPattern(string $pattern, string $reason): int @@ -105,6 +84,7 @@ class DomainPatternBlocklist /** * @param string $pattern + * * @return int 0 if the block list couldn't be saved, 1 if the pattern wasn't found, 2 if it was removed */ public function removePattern(string $pattern): int @@ -123,6 +103,12 @@ class DomainPatternBlocklist return $found ? ($this->set($blocklist) ? 2 : 0) : 1; } + /** + * @param string $filename + * + * @return void + * @throws Exception + */ public function exportToFile(string $filename) { $fp = fopen($filename, 'w'); @@ -139,6 +125,7 @@ class DomainPatternBlocklist * Appends to the local block list all the patterns from the provided list that weren't already present. * * @param array $blocklist + * * @return int The number of patterns actually added to the block list */ public function append(array $blocklist): int @@ -165,6 +152,7 @@ class DomainPatternBlocklist * Extracts a server domain pattern block list from the provided CSV file name. Deduplicates the list based on patterns. * * @param string $filename + * * @return array * @throws Exception */ @@ -182,56 +170,10 @@ class DomainPatternBlocklist 'reason' => $data[1] ?? '', ]; if (!in_array($item, $blocklist)) { - $blocklist[] = $data; + $blocklist[] = $item; } } return $blocklist; } - - /** - * Sends a system email to all the node users about a change in the block list. Sends a single email to each unique - * email address among the valid users. - * - * @return int The number of recipients that were sent an email - * @throws HTTPException\InternalServerErrorException - * @throws HTTPException\UnprocessableEntityException - */ - public function notifyAll(): int - { - // Gathering all non-system parent users who verified their email address and aren't blocked or about to be deleted - // We sort on language to minimize the number of actual language switches during the email build loop - $recipients = $this->db->selectToArray( - 'user', - ['username', 'email', 'language'], - ['`uid` > 0 AND `parent-uid` = 0 AND `verified` AND NOT `account_removed` AND NOT `account_expired` AND NOT `blocked`'], - ['group_by' => ['email'], 'order' => ['language']] - ); - if (!$recipients) { - return 0; - } - - foreach ($recipients as $recipient) { - $this->l10n->withLang($recipient['language']); - $email = $this->emailer->newSystemMail() - ->withMessage( - $this->l10n->t('[%s] Notice of remote server domain pattern block list update', $this->emailer->getSiteEmailName()), - $this->l10n->t( - 'Dear %s, - -You are receiving this email because the Friendica node at %s where you are registered as a user updated their remote server domain pattern block list. - -Please review the updated list at %s at your earliest convenience.', - $recipient['username'], - $this->baseUrl->get(), - $this->baseUrl . '/friendica' - ) - ) - ->withRecipient($recipient['email']) - ->build(); - $this->emailer->send($email); - } - - return count($recipients); - } }