1 # Blosxom Plugin: tagcloud
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
4 # Documentation: See the bottom of this file or type: perldoc tagcloud
9 use vars qw(%config $cloud);
11 # Uncomment next line to enable debug output (don't uncomment debug() lines)
12 #use Blosxom::Debug debug_level => 1;
14 # --- Configuration defaults -----
18 # tagcloud requires a hashref containing 'tag => count' pairs
19 tag_hashref => $tags::tag_counts,
22 tagcloud_prefix => qq(<p class="tagcloud">\n),
23 tagcloud_suffix => qq(</p>\n),
28 entry_type => 'posting',
30 # Tags to omit from tagcloud
31 tagcloud_blacklist => [ 'Now Playing' ],
35 # ---------------------------------
37 my %tagcloud_blacklist = map { $_ => 1 } @{$config{tagcloud_blacklist}};
42 eval { $config{tag_hashref} }
43 or warn "[tagcloud] tag_hashref not set - skipping"
49 my $tag_hashref = $config{tag_hashref};
50 return unless keys %$tag_hashref;
55 for (keys %$tag_hashref) {
56 next if exists $tagcloud_blacklist{ $_ };
57 next if $tag_hashref->{$_} < $config{min_tag_no};
58 $tags{$_} = $tag_hashref->{$_};
59 $min = $tag_hashref->{$_} if $min > $tag_hashref->{$_} || ! $min;
60 $max = $tag_hashref->{$_} if $max < $tag_hashref->{$_};
62 return unless keys %tags;
64 my $diff = $max - $min;
67 for my $tag (sort { lc $a cmp lc $b } keys %tags) {
69 $label .= " ($tags{$tag})" if $config{show_tag_no};
70 my $url_tag = _url_escape($tag);
71 my $url = "$blosxom::url/tags/$url_tag";
72 my $plural = $tags{$tag} == 1 ? '' : 's';
73 my $title = sprintf "%s %s%s tagged", $tags{$tag}, $config{entry_type}, $plural;
74 my $tag_percent = int($config{min_size} +
75 ((($config{max_size}-$config{min_size})/$diff) * ($tags{$tag}-$min+1)));
76 my $style = 'white-space: nowrap;';
77 $style .= qq(font-size: $tag_percent%;") if $diff;
78 push @tagcloud, qq(<a href="$url" rel="tag" title="$title" style="$style">$label</a>);
81 $cloud = sprintf "%s%s%s",
82 $config{tagcloud_prefix}, join(', ', @tagcloud), $config{tagcloud_suffix};
87 $s =~ s/[^0-9A-Za-z,.:]/sprintf('%%%02X', ord($&))/seg;
98 tagcloud - blosxom plugin to set a $tagcloud::cloud template variable
99 given an arbitrary set of tags and counts
104 tagcloud is a blosxom plugin which sets a $tagcloud::cloud template
105 variable given an arbitrary set of tags and counts. It was developed
106 for use with the L<tags> plugin.
111 tagcloud should be loaded after the plugin that is generating its tag
119 Blosxom: http://blosxom.sourceforge.net/
122 =head1 ACKNOWLEDGEMENTS
124 Portions of this plugin were swiped verbatim from xtaran's excellent
130 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
135 Copyright 2007, Gavin Carr.
137 This plugin is licensed under the same terms as blosxom itself i.e.
139 Permission is hereby granted, free of charge, to any person obtaining a
140 copy of this software and associated documentation files (the "Software"),
141 to deal in the Software without restriction, including without limitation
142 the rights to use, copy, modify, merge, publish, distribute, sublicense,
143 and/or sell copies of the Software, and to permit persons to whom the
144 Software is furnished to do so, subject to the following conditions:
146 The above copyright notice and this permission notice shall be included
147 in all copies or substantial portions of the Software.
149 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
150 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
152 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
153 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
154 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
155 OTHER DEALINGS IN THE SOFTWARE.