aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-06-21 18:32:17 +0200
committerThomas Lange <code@nerdmind.de>2021-06-21 18:32:17 +0200
commit825b8574adc64286f169186db6556c801af7f1ca (patch)
tree1ad44b9a5eb0a0b78066946d6b763eba0d487e5d /core
parent5e1f5a639f1f3d8b064d4254fd3d81239c393cc6 (diff)
downloadblog-825b8574adc64286f169186db6556c801af7f1ca.tar.gz
blog-825b8574adc64286f169186db6556c801af7f1ca.tar.xz
blog-825b8574adc64286f169186db6556c801af7f1ca.zip
Add function parseContentTags
Diffstat (limited to 'core')
-rw-r--r--core/functions.php26
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 {