tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / gavinc / storytags
1 # Blosxom Plugin: storytags
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.003000
4 # Documentation: See the bottom of this file or type: perldoc storytags
5 # Requires: tags
6 # Follows: tags
7
8 package storytags;
9
10 use strict;
11
12 # Uncomment next line to enable debug output (don't uncomment debug() lines)
13 #use Blosxom::Debug debug_level => 1;
14
15 use vars qw(%config $taglist @taglist);
16
17 # --- Configuration variables -----
18
19 %config = ();
20
21 # Formatting strings
22 $config{prefix} = 'Tags: ';
23 $config{suffix} = '. ';
24
25 # ---------------------------------
26 # __END_CONFIG__
27
28 $taglist = '';
29
30 sub start { 1 }
31
32 # Set $taglist
33 sub story {
34     my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
35
36     return 1 unless $tags::tag_cache 
37              && ref $tags::tag_cache 
38              && keys %{ $tags::tag_cache };
39     return 1 unless defined $tags::tag_cache->{"$path/$filename"};
40
41     @taglist = ();
42     @taglist = sort { lc $a cmp lc $b } split /\s*,\s*/, 
43       $tags::tag_cache->{"$path/$filename"}->{tags}
44         if defined $tags::tag_cache->{"$path/$filename"}->{tags};
45     $taglist = _format_taglist( \@taglist );
46
47     return 1;
48 }
49
50 sub _format_taglist {
51     my ($tags) = @_;
52     return '' unless @$tags;
53     return $config{prefix}
54            . join(', ', 
55                map { qq(<a href="$blosxom::url/tags/$_" rel="tag">$_</a>) }
56                @$tags
57            )
58            . $config{suffix};
59 }
60
61 1;
62
63 __END__
64
65 =head1 NAME
66
67 storytags - blosxom plugin to format a per-story $storytags::taglist string
68 and @storytags::taglist array of tags
69
70 =head1 DESCRIPTION
71
72 L<storytags> is a blosxom plugin to format a per-story $storytags::taglist 
73 string, and a @storytags::taglist array of tags. The $taglist is a 
74 comma-separated list of the tags defined for the story, prefixed by 
75 $config{prefix}, and suffixed by $config{suffix}. If no tags are 
76 defined, then $taglist will be the empty string '' (i.e. no prefix and 
77 suffix are added). @taglist is a simple array of the tags for the story,
78 and an empty array if none are set.
79
80 The default values for 'prefix' and 'suffix' are 'Tags: ' and '. ' 
81 respectively, so a typical $taglist might look like:
82
83     Tags: dogs, cats, pets.
84
85 =head1 USAGE
86
87 L<storytags> requires the L<tags> plugin, and should be loaded AFTER
88 L<tags>. It has no other ordering dependencies.
89
90 =head1 ACKNOWLEDGEMENTS
91
92 This plugin was inspired by xtaran's excellent L<tagging> plugin,
93 which includes similar functionality.
94
95 =head1 SEE ALSO
96
97 L<tags>, L<tagcloud>, xtaran's L<tagging>.
98
99 Blosxom: http://blosxom.sourceforge.net/
100
101 =head1 AUTHOR
102
103 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
104
105 =head1 LICENSE
106
107 Copyright 2007, Gavin Carr.
108
109 This plugin is licensed under the same terms as blosxom itself i.e.
110
111 Permission is hereby granted, free of charge, to any person obtaining a
112 copy of this software and associated documentation files (the "Software"),
113 to deal in the Software without restriction, including without limitation
114 the rights to use, copy, modify, merge, publish, distribute, sublicense,
115 and/or sell copies of the Software, and to permit persons to whom the
116 Software is furnished to do so, subject to the following conditions:
117
118 The above copyright notice and this permission notice shall be included
119 in all copies or substantial portions of the Software.
120
121 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
122 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
123 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
124 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
125 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
126 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
127 OTHER DEALINGS IN THE SOFTWARE.
128
129 =cut
130
131 # vim:ft=perl:sw=4
132