diff --git a/lib/Db/Bookmark.php b/lib/Db/Bookmark.php index a1e043076..0f7e49dd0 100644 --- a/lib/Db/Bookmark.php +++ b/lib/Db/Bookmark.php @@ -30,9 +30,7 @@ * @method int getArchivedFile() * @method setArchivedFile(int $fileId) * @method string getTextContent() - * @method setTextContent(string $content) * @method string getHtmlContent() - * @method setHtmlContent(string $content) * @method string getUserId() * @method setUserId(string $userId) */ @@ -110,6 +108,8 @@ public function setTitle(string $title): void { if (strlen($title) > 1024) { $title = substr($title, 0, 1020) . '…'; } + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + $title = mb_convert_encoding($title, 'UTF-8', 'UTF-8'); $this->setter('title', [$title]); } @@ -118,9 +118,37 @@ public function setDescription(string $desc): void { if (strlen($desc) > 1024) { $desc = substr($desc, 0, 1020) . '…'; } + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + $desc = mb_convert_encoding($desc, 'UTF-8', 'UTF-8'); $this->setter('description', [$desc]); } + public function setTextContent(?string $content): void { + if ($content === null) { + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + $content = mb_convert_encoding($content, 'UTF-8', 'UTF-8'); + } + $this->setter('textContent', [$content]); + } + + public function getTextContent(): string { + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + return mb_convert_encoding($this->textContent, 'UTF-8', 'UTF-8'); + } + + public function setHtmlContent(?string $content): void { + if ($content === null) { + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + $content = mb_convert_encoding($content, 'UTF-8', 'UTF-8'); + } + $this->setter('htmlContent', [$content]); + } + + public function getHtmlContent(): string { + // Remove non-utf-8 characters from string: https://stackoverflow.com/questions/1401317/remove-non-utf8-characters-from-string + return mb_convert_encoding($this->htmlContent, 'UTF-8', 'UTF-8'); + } + public function isWebLink() { return (bool) preg_match('/^https?:/i', $this->getUrl()); }