From b3e7d46351d9eec188ea73b960d9eb109d8b6bf2 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 23 Mar 2020 15:01:24 +1000 Subject: [PATCH] Add tagcategories->getTagHtml helper --- ext/tag_categories/main.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 0ca1a7c9..24560c0b 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -127,6 +127,27 @@ class TagCategories extends Extension return $tc_keyed_dict; } + public function getTagHtml(string $tag, $tag_category_dict, string $extra_text = '') + { + $h_tag_no_underscores = str_replace("_", " ", $tag); + + // we found a tag, see if it's valid! + $h_tag_split = explode(':', $tag, 2); + if ((count($h_tag_split) > 1) and array_key_exists($h_tag_split[0], $tag_category_dict)) { + $category = $h_tag_split[0]; + $h_tag = $h_tag_split[1]; + $tag_category_css = ' tag_category_'.$category; + $tag_category_style = 'style="color:'.html_escape($tag_category_dict[$category]['color']).';" '; + $h_tag_no_underscores = str_replace("_", " ", $h_tag); + + $h_tag_no_underscores = ''.$h_tag_no_underscores.$extra_text.''; + } else { + $h_tag_no_underscores .= $extra_text; + } + + return $h_tag_no_underscores; + } + public function page_update() { global $user, $database;