From 173b7680386f1b558506095535bd7f33582661b6 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 15 Oct 2020 18:42:47 +0200 Subject: [PATCH] preserve html in content Signed-off-by: Robin Appelman --- lib/Model/ActivityPub/ACore.php | 13 ++++++++----- lib/Model/ActivityPub/Stream.php | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index ee8bfcb7..135de478 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -61,6 +61,7 @@ class ACore extends Item implements JsonSerializable { const AS_USERNAME = 5; const AS_ACCOUNT = 6; const AS_STRING = 7; + const AS_CONTENT = 8; const AS_TAGS = 10; const FORMAT_ACTIVITYPUB = 1; @@ -559,14 +560,16 @@ class ACore extends Item implements JsonSerializable { return $value; case self::AS_STRING: - // try to preserve some whitespace from the html tags - $value = preg_replace("/\
/", "\n", $value); - $value = preg_replace("/\<\/?p>/", "\n", $value); - $value = strip_tags($value); $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5); - return trim($value); + return $value; + + case self::AS_CONTENT: + $value = strip_tags($value, ['a', 'p', 'span', 'br']); + $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5); + + return $value; case self::AS_USERNAME: $value = strip_tags($value); diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 88dd1fdd..a731f2f6 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -424,7 +424,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { } $this->setActivityId($this->validate(self::AS_ID, 'activity_id', $data, '')); - $this->setContent($this->validate(self::AS_STRING, 'content', $data, '')); + $this->setContent($this->validate(self::AS_CONTENT, 'content', $data, '')); $this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, '')); $this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, '')); $this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));