X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModeration%2FDomainPatternBlocklist.php;h=259225c491e5812aff30fc0d069ddb6c965cc265;hb=739ca603bc388c97a11a8d6a4843396bf5d52088;hp=33bd189d6d56fb6b595dc74d19c724abac153a14;hpb=1810b32c26683bb94fee10de2ffe18de1a7e85bf;p=friendica.git diff --git a/src/Moderation/DomainPatternBlocklist.php b/src/Moderation/DomainPatternBlocklist.php index 33bd189d6d..259225c491 100644 --- a/src/Moderation/DomainPatternBlocklist.php +++ b/src/Moderation/DomainPatternBlocklist.php @@ -1,6 +1,6 @@ $pattern, - 'reason' => $reason ?? self::DEFAULT_REASON, + 'reason' => $reason, ]; $update = true; @@ -78,7 +75,7 @@ class DomainPatternBlocklist if (!$update) { $blocklist[] = [ 'domain' => $pattern, - 'reason' => $reason ?? self::DEFAULT_REASON, + 'reason' => $reason, ]; } @@ -87,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 @@ -105,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'); @@ -121,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 @@ -147,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 */ @@ -159,19 +165,12 @@ class DomainPatternBlocklist $blocklist = []; while (($data = fgetcsv($fp, 1000)) !== false) { - $domain = $data[0]; - if (count($data) == 0) { - $reason = self::DEFAULT_REASON; - } else { - $reason = $data[1]; - } - - $data = [ - 'domain' => $domain, - 'reason' => $reason + $item = [ + 'domain' => $data[0], + 'reason' => $data[1] ?? '', ]; - if (!in_array($data, $blocklist)) { - $blocklist[] = $data; + if (!in_array($item, $blocklist)) { + $blocklist[] = $item; } }