From 261ab1364aa40384b0315be60e78cd89ea7fe661 Mon Sep 17 00:00:00 2001 From: winter Date: Sun, 23 Feb 2025 18:32:09 +0000 Subject: implement policies --- Digitigrade/Policy/BasicCensor.php | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Digitigrade/Policy/BasicCensor.php (limited to 'Digitigrade/Policy/BasicCensor.php') diff --git a/Digitigrade/Policy/BasicCensor.php b/Digitigrade/Policy/BasicCensor.php new file mode 100644 index 0000000..5866488 --- /dev/null +++ b/Digitigrade/Policy/BasicCensor.php @@ -0,0 +1,47 @@ +words = $words; + $this->replacement = $replacement; + } + + public function checkNote(Note $note): bool { + foreach ($this->words as $w) { + if (isset($note->summary)) + $note->summary = str_replace($w, $this->replacement, $note->summary); + $note->plainContent = str_replace($w, $this->replacement, $note->plainContent); + foreach ($note->formattedContent as $type => $content) { + $note->formattedContent[$type] = str_replace($w, $this->replacement, $content); + } + } + return true; + } + + public function checkActor(Actor $actor): bool { + foreach ($this->words as $w) { + $actor->displayName = str_replace($w, $this->replacement, $actor->displayName); + if (isset($actor->pronouns)) + $actor->pronouns = str_replace($w, $this->replacement, $actor->pronouns); + if (isset($actor->bio)) + $actor->bio = str_replace($w, $this->replacement, $actor->bio); + } + return true; + } +} \ No newline at end of file -- cgit v1.3