+# Create the url for a given tag. Depending on the tag and link type given,
+# this adds to, removes or replaces the current tag list. The link type given
+# is one of the keys of %base_url
+sub make_tag_link {
+ my ($link, $tag, %attrs) = @_;
+ my $filter_tags = CGI::param('-tags');
+ my $conj = (CGI::param('-conj') eq 'and' ? '&-conj=and' : '');
+ # If we're linking to ourselves, the currently selected tag list is not
+ # empty, and this tag is not in there yet, prefix the link with the
+ # current filter list.
+ my $tags;
+ if (($link_cloud eq 'blosxom') and $filter_tags) {
+ if ($filter_tags =~ /(^|,)\Q$tag\E($|,)/) {
+ # The tag is already in there, remove it
+ $tags = $filter_tags;
+ $tags =~ s/\Q,$tag,\E/,/ || $tags =~ s/(^|,)\Q$tag\E($|,)//;
+ } else {
+ # The tag is not in there, add it
+ $tags = "$filter_tags,$tag";
+ }
+ $tags = &url_escape($tags);
+ $tags .= $conj;
+ } else {
+ # We're linking externally, or don't have a filter yet. Just use the
+ # selected tag as the filter
+ $tags = &url_escape($tag);
+ }
+
+ # Set the href attribute
+ $attrs{href} = "$base_url{$link}$tags";
+
+ # Generate attribute values
+ my $attrs = join('',
+ map { $val = blosxom::blosxom_html_escape($attrs{$_});
+ qq! $_="$val"!;
+ } keys %attrs);
+
+ return "<a$attrs>" . blosxom::blosxom_html_escape($tag) . "</a>";
+}
+
+