From b3e7d46351d9eec188ea73b960d9eb109d8b6bf2 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 23 Mar 2020 15:01:24 +1000 Subject: [PATCH 1/3] 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; From 9484c9173c7a40232f069d72297e9a1341cfa27f Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 23 Mar 2020 15:02:09 +1000 Subject: [PATCH 2/3] Colour tag categories in tag list+map --- ext/tag_list/main.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index d692c5f7..470d7321 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -288,6 +288,10 @@ class TagList extends Extension if ($config->get_bool(TagListConfig::PAGES)) { $html .= $this->build_az(); } + if (class_exists('TagCategories')) { + $this->tagcategories = new TagCategories; + $tag_category_dict = $this->tagcategories->getKeyedDict(); + } foreach ($tag_data as $row) { $h_tag = html_escape($row['tag']); $size = sprintf("%.2f", (float)$row['scaled']); @@ -296,6 +300,9 @@ class TagList extends Extension $size = 0.5; } $h_tag_no_underscores = str_replace("_", " ", $h_tag); + if (class_exists('TagCategories')) { + $h_tag_no_underscores = $this->tagcategories->getTagHtml(html_escape($h_tag), $tag_category_dict); + } $html .= " $h_tag_no_underscores \n"; } @@ -347,6 +354,11 @@ class TagList extends Extension */ mb_internal_encoding('UTF-8'); + if (class_exists('TagCategories')) { + $this->tagcategories = new TagCategories; + $tag_category_dict = $this->tagcategories->getKeyedDict(); + } + $lastLetter = ""; # postres utf8 string sort ignores punctuation, so we get "aza, a-zb, azc" # which breaks down into "az, a-, az" :( @@ -361,7 +373,10 @@ class TagList extends Extension } $link = $this->theme->tag_link($tag); $h_tag = html_escape($tag); - $html .= "$h_tag ($count)\n"; + if (class_exists('TagCategories')) { + $h_tag = $this->tagcategories->getTagHtml($h_tag, $tag_category_dict, " ($count)"); + } + $html .= "$h_tag\n"; } if (SPEED_HAX) { From a83c460b70033a29ed52f6d9cf1a32cc449948d4 Mon Sep 17 00:00:00 2001 From: Daniel Oaks Date: Mon, 23 Mar 2020 21:22:30 +1000 Subject: [PATCH 3/3] Fix double-escaping pointed out by Shish <3 --- ext/tag_categories/main.php | 6 +++--- ext/tag_list/main.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/tag_categories/main.php b/ext/tag_categories/main.php index 24560c0b..f3ea8d4d 100644 --- a/ext/tag_categories/main.php +++ b/ext/tag_categories/main.php @@ -127,12 +127,12 @@ class TagCategories extends Extension return $tc_keyed_dict; } - public function getTagHtml(string $tag, $tag_category_dict, string $extra_text = '') + public function getTagHtml(string $h_tag, $tag_category_dict, string $extra_text = '') { - $h_tag_no_underscores = str_replace("_", " ", $tag); + $h_tag_no_underscores = str_replace("_", " ", $h_tag); // we found a tag, see if it's valid! - $h_tag_split = explode(':', $tag, 2); + $h_tag_split = explode(':', $h_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]; diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 470d7321..538b027d 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -301,7 +301,7 @@ class TagList extends Extension } $h_tag_no_underscores = str_replace("_", " ", $h_tag); if (class_exists('TagCategories')) { - $h_tag_no_underscores = $this->tagcategories->getTagHtml(html_escape($h_tag), $tag_category_dict); + $h_tag_no_underscores = $this->tagcategories->getTagHtml($h_tag, $tag_category_dict); } $html .= " $h_tag_no_underscores \n"; }