aboutsummaryrefslogtreecommitdiffstats
path: root/core/functions.php
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2024-02-05 17:44:46 +0100
committerThomas Lange <code@nerdmind.de>2024-02-05 17:53:06 +0100
commit8b1314e416ada633ae6c866c9fac7124e6d3a3e4 (patch)
tree2b44a31d914ed58dbe5bc7f56df7f56ffc35b7b0 /core/functions.php
parent9be821773ee684172bddd4acfbb1e56cd7e7c938 (diff)
downloadblog-8b1314e416ada633ae6c866c9fac7124e6d3a3e4.tar.gz
blog-8b1314e416ada633ae6c866c9fac7124e6d3a3e4.tar.xz
blog-8b1314e416ada633ae6c866c9fac7124e6d3a3e4.zip
Add (CATEGORY|PAGE|POST|USER)_URL content function
These content functions will return the pure URL to the corresponding entity instead of a Markdown formatted link like the other functions.
Diffstat (limited to 'core/functions.php')
-rw-r--r--core/functions.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/functions.php b/core/functions.php
index 7384c88..6350ff1 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -330,6 +330,17 @@ function getEntityMarkdownLink($ns, $id, $text = NULL, $info = NULL): string {
return sprintf('[%s](%s "%s")', $text, $href, $info);
}
+#===========================================================================
+# Callback for (CATEGORY|PAGE|POST|USER)_URL content function
+#===========================================================================
+function getEntityURL($ns, $id): string {
+ if(!$Entity = Application::getRepository($ns)->find($id)) {
+ return sprintf('`{%s_URL: *Reference error*}`', strtoupper($ns));
+ }
+
+ return Application::getEntityURL($Entity);
+}
+
#===============================================================================
# Function for use in templates to get data of a category
#===============================================================================
@@ -423,3 +434,31 @@ FunctionParser::register('POST', function($id, $text = NULL, $title = NULL) {
FunctionParser::register('USER', function($id, $text = NULL, $title = NULL) {
return getEntityMarkdownLink('User', $id, $text, $title);
});
+
+#===========================================================================
+# Get URL to a category entity
+#===========================================================================
+FunctionParser::register('CATEGORY_URL', function($id) {
+ return getEntityURL('Category', $id);
+});
+
+#===========================================================================
+# Get URL to a page entity
+#===========================================================================
+FunctionParser::register('PAGE_URL', function($id) {
+ return getEntityURL('Page', $id);
+});
+
+#===========================================================================
+# Get URL to a post entity
+#===========================================================================
+FunctionParser::register('POST_URL', function($id) {
+ return getEntityURL('Post', $id);
+});
+
+#===========================================================================
+# Get URL to a user entity
+#===========================================================================
+FunctionParser::register('USER_URL', function($id) {
+ return getEntityURL('User', $id);
+});