From 825b8574adc64286f169186db6556c801af7f1ca Mon Sep 17 00:00:00 2001
From: Thomas Lange <code@nerdmind.de>
Date: Mon, 21 Jun 2021 18:32:17 +0200
Subject: Add function parseContentTags

---
 core/functions.php | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/core/functions.php b/core/functions.php
index 1af8e36..6babd91 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -125,6 +125,32 @@ function generatePseudoGUID(Item $Entity) {
 	return sha1(implode('', $attributes));
 }
 
+#===============================================================================
+# 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]
 #===============================================================================
-- 
cgit v1.2.3