From bb9f45b1153d82359fef052a0a04147d4b794704 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 21 Jun 2021 18:33:23 +0200 Subject: Add function parseEntityContent --- core/functions.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/functions.php b/core/functions.php index 6babd91..98c99c3 100644 --- a/core/functions.php +++ b/core/functions.php @@ -151,6 +151,38 @@ function parseContentTags(string $text): string { return $text; } +#=============================================================================== +# Parse entity content +#=============================================================================== +function parseEntityContent(Item $Item): string { + switch($class = get_class($Item)) { + case 'Page\Item': + $prefix = 'PAGE'; + break; + case 'Post\Item': + $prefix = 'POST'; + break; + case 'User\Item': + $prefix = 'USER'; + break; + default: + $error = 'Unknown config prefix for %s entities.'; + throw new Exception(sprintf($error, $class)); + } + + $Parsedown = new Parsedown(); + $Parsedown->setUrlsLinked(FALSE); + + $text = parseContentTags($Item->attr('body')); + + if(Application::get("$prefix.EMOTICONS")) { + $text = parseUnicodeEmoticons($text); + $text = parseEmoticons($text); + } + + return $Parsedown->text($text); +} + #=============================================================================== # Parser for datetime formatted strings [YYYY-MM-DD HH:II:SS] #=============================================================================== -- cgit v1.2.3