From 8b1314e416ada633ae6c866c9fac7124e6d3a3e4 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Mon, 5 Feb 2024 17:44:46 +0100 Subject: 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. --- core/functions.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) 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); +}); -- cgit v1.2.3