diff options
author | Thomas Lange <code@nerdmind.de> | 2021-06-21 18:32:17 +0200 |
---|---|---|
committer | Thomas Lange <code@nerdmind.de> | 2021-06-21 18:32:17 +0200 |
commit | 825b8574adc64286f169186db6556c801af7f1ca (patch) | |
tree | 1ad44b9a5eb0a0b78066946d6b763eba0d487e5d | |
parent | 5e1f5a639f1f3d8b064d4254fd3d81239c393cc6 (diff) | |
download | blog-825b8574adc64286f169186db6556c801af7f1ca.tar.gz blog-825b8574adc64286f169186db6556c801af7f1ca.tar.xz blog-825b8574adc64286f169186db6556c801af7f1ca.zip |
Add function parseContentTags
-rw-r--r-- | core/functions.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/core/functions.php b/core/functions.php index 1af8e36..6babd91 100644 --- a/core/functions.php +++ b/core/functions.php @@ -126,6 +126,32 @@ function generatePseudoGUID(Item $Entity) { } #=============================================================================== +# Parse content tags +#=============================================================================== +function parseContentTags(string $text): string { + $entity_tags = '#\{(POST|PAGE|USER)\[([0-9]+)\]\}#'; + + $text = preg_replace_callback($entity_tags, function($matches) { + $namespace = ucfirst(strtolower($matches[1])).'\\Factory'; + + try { + $Entity = $namespace::build($matches[2]); + return Application::getEntityURL($Entity); + } catch(Exception $Exception) { + return '{undefined}'; + } + }, $text); + + $base_tag = '#\{BASE\[\"([^"]+)\"\]\}#'; + $file_tag = '#\{FILE\[\"([^"]+)\"\]\}#'; + + $text = preg_replace($base_tag, \Application::getURL('$1'), $text); + $text = preg_replace($file_tag, \Application::getFileURL('$1'), $text); + + return $text; +} + +#=============================================================================== # Parser for datetime formatted strings [YYYY-MM-DD HH:II:SS] #=============================================================================== function parseDatetime($datetime, $format): string { |