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 $config{tag_hashref} = $tags::tag_counts;
22 $config{tagcloud_prefix} = qq(<p class="tagcloud">\n);
23 $config{tagcloud_suffix} = qq(</p>\n);
24 $config{show_tag_no} = 0;
25 $config{min_tag_no} = 2;
26 $config{min_size} = 75;
27 $config{max_size} = 200;
28 $config{entry_type} = 'posting';
30 # Tags to omit from tagcloud
31 $config{tagcloud_blacklist} = [ 'Now Playing' ];
33 # ---------------------------------
36 #blosxom::load_config( \%config, 'tagcloud' );
38 my %tagcloud_blacklist = map { $_ => 1 } @{$config{tagcloud_blacklist}};
43 eval { $config{tag_hashref} }
44 or warn "[tagcloud] tag_hashref not set - skipping"
50 my $tag_hashref = $config{tag_hashref};
51 return unless keys %$tag_hashref;
56 for (keys %$tag_hashref) {
57 next if exists $tagcloud_blacklist{ $_ };
58 next if $tag_hashref->{$_} < $config{min_tag_no};
59 $tags{$_} = $tag_hashref->{$_};
60 $min = $tag_hashref->{$_} if $min > $tag_hashref->{$_} || ! $min;
61 $max = $tag_hashref->{$_} if $max < $tag_hashref->{$_};
63 return unless keys %tags;
65 my $diff = $max - $min;
68 for my $tag (sort { lc $a cmp lc $b } keys %tags) {
70 $label .= " ($tags{$tag})" if $config{show_tag_no};
71 my $url_tag = _url_escape($tag);
72 my $url = "$blosxom::url/tags/$url_tag";
73 my $plural = $tags{$tag} == 1 ? '' : 's';
74 my $title = sprintf "%s %s%s tagged", $tags{$tag}, $config{entry_type}, $plural;
75 my $tag_percent = int($config{min_size} +
76 ((($config{max_size}-$config{min_size})/$diff) * ($tags{$tag}-$min+1)));
77 my $style = 'white-space: nowrap;';
78 $style .= qq(font-size: $tag_percent%;") if $diff;
79 push @tagcloud, qq(<a href="$url" rel="tag" title="$title" style="$style">$label</a>);
82 $cloud = sprintf "%s%s%s",
83 $config{tagcloud_prefix}, join(', ', @tagcloud), $config{tagcloud_suffix};
88 $s =~ s/[^0-9A-Za-z,.:]/sprintf('%%%02X', ord($&))/seg;
99 tagcloud - blosxom plugin to set a $tagcloud::cloud template variable
100 given an arbitrary set of tags and counts
105 tagcloud is a blosxom plugin which sets a $tagcloud::cloud template
106 variable given an arbitrary set of tags and counts. It was developed
107 for use with the L<tags> plugin.
112 tagcloud should be loaded after the plugin that is generating its tag
120 Blosxom: http://blosxom.sourceforge.net/
123 =head1 ACKNOWLEDGEMENTS
125 Portions of this plugin were swiped verbatim from xtaran's excellent
131 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
136 Copyright 2007, Gavin Carr.
138 This plugin is licensed under the same terms as blosxom itself i.e.
140 Permission is hereby granted, free of charge, to any person obtaining a
141 copy of this software and associated documentation files (the "Software"),
142 to deal in the Software without restriction, including without limitation
143 the rights to use, copy, modify, merge, publish, distribute, sublicense,
144 and/or sell copies of the Software, and to permit persons to whom the
145 Software is furnished to do so, subject to the following conditions:
147 The above copyright notice and this permission notice shall be included
148 in all copies or substantial portions of the Software.
150 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
151 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
152 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
153 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
154 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
155 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
156 OTHER DEALINGS IN THE SOFTWARE.