tagging: Allow using titles in for related stories.
[matthijs/upstream/blosxom-plugins.git] / general / rating
1 # Blosxom Plugin: rating
2 # Author(s): Rael Dornfest <rael@oreilly.com> 
3 # Version: 2003-06-27
4 # Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
5
6 package rating;
7
8 # --- Configurable variables -----
9
10 # What's the default rating minimum?
11 my $default_min = 1;
12
13 # What's the default rating maximum?
14 my $default_max = 5;
15
16 # What's the width per rating point for graphical style?
17 my $width = 10;
18
19 # What's the height for graphical style?
20 my $height = 10;
21
22 # Where are the graphical images (rating_below.gif, rating.gif, 
23 # rating_above.gif) kept?
24 my $image_url = "/images";
25
26 # --------------------------------
27
28 $numerical; # use as $rating::numerical in flavour templates
29 $textual; # use as $rating::textual in flavour templates
30 $graphical; # use as $rating::graphical in flavour templates
31 $star; # use as $rating::star in flavour templates
32
33 my $min = $meta::rating_min || $default_min;
34 my $max = $meta::rating_max || $default_max;
35
36 $image_url =~ s!/+$!!;
37
38 sub start {
39   1;
40 }
41
42 sub story {
43   my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
44
45   # Don't bother unless there's a rating; clear out previous ratings
46   unless ($meta::rating) {
47     ($numerical, $textual, $graphical, $star) = (undef, undef, undef, undef);
48     return 0;
49   }
50
51   # The numerical representation
52   $numerical = $meta::rating || 0;
53   
54   # Sanity checks
55   $numerical < $min and $numerical = $min;
56   $numerical > $max and $numerical = $max;
57
58   # The textual representation
59   $textual = 
60       '&lt;'
61     . '=' x ($numerical - $min)  
62     . 'O' 
63     . '=' x ($max - $numerical)  
64     . '&gt;';
65
66   # The star representation
67   $star ='*' x  $numerical;
68  
69   # The graphical representation
70   $graphical = 
71       qq{<img src="$image_url/rating_below.gif" height="$height" width="} 
72         . ( $width * ( $numerical - $min ) ) . qq{" align="absmiddle">}
73     . qq{<img src="$image_url/rating.gif" height="$height" width="$width" align="absmiddle">}
74     . qq{<img src="$image_url/rating_above.gif" height="$height" width="} 
75         . ( $width * ( $max - $numerical ) ) . qq{" align="absmiddle">};
76
77   return 1;
78 }
79
80 1;
81
82 __END__
83
84 =head1 NAME
85
86 Blosxom Plug-in: rating
87
88 =head1 SYNOPSIS
89
90 For stories specifying a meta-rating value (using the meta plug-in), 
91 this plug-in generates numerical, textual, star, and graphical representations 
92 of said rating for use in a flavour template.
93
94 For example, a story specifying:
95
96   meta-rating: 4
97
98 results in the following flavour template variables and associated 
99 representations (the minimum, in this case, being 1 and maximum being 5):
100
101   $rating::numerical:   4
102
103   $rating::textual:     <===O=>
104
105   $rating::star:        ****
106
107   $rating::graphical: 
108                <img src="/images/rating_below.gif" height="10" width="30">
109                <img src="/images/rating.gif" height="10" width="10">
110                <img src="/images/rating_above.gif" height="10" width="10">
111
112 Simply add one of these template variables wherever you please in your 
113 story.{flavour} (e.g. story.html) flavour template and it'll be replaced
114 on the fly with your rating in the selected style.
115
116 A rating lower than the minimum is set to the minimum; a rating higher than
117 the maximum is set to the maximum.
118
119 =head1 PREREQUISITES
120
121 The rating plug-in requires the meta plug-in, available at:
122
123   http://www.raelity.org/apps/blosxom/plugins/meta/meta.individual
124
125 =head1 INSTALLATION
126
127 Drop the rating  plug-in into your Blosxom plugins folder.
128
129 =head1 CONFIGURATION
130
131 The plug-in will just work out of the box without any configuration.  All
132 further configuration is entirely optional.
133
134 # What's the default rating minimum?
135 my $default_min = 1;
136
137 The default minimum ($default_min) specifies the default minimum for the
138 rating scale.  Besides adjusting the value of $default_min in the 
139 plug-in's configuration section, you can override the minimum on a weblog
140 posting by posting basis by setting a meta-rating_min value in the entry
141 itself.
142
143 # What's the default rating maximum?
144 my $default_max = 5;
145
146 The default maximum ($default_max) specifies the default maximum for the
147 rating scale.  Besides adjusting the value of $default_max in the 
148 plug-in's configuration section, you can override the maximum on a weblog
149 posting by posting basis by setting a meta-rating_max value in the entry
150 itself.
151
152 # What's the width per rating point for graphical style?
153 my $width = 10;
154
155 Sets the width in pixels for each rating point (e.g. a rating of 2 with
156 $width set to 10 results in a bar of 20 pixels wide)..
157
158 # What's the height for graphical style?
159 my $height = 10;
160
161 Sets the height in pixels for each rating point.
162
163 # Where are the graphical images (rating_below.gif, rating.gif, 
164 # rating_above.gif) kept?
165 my $image_url = "/images";
166
167 A relative or absolute URL pointing at the location of 1-pixel 
168 rating_below.gif, rating.gif, and rating_above.gif images for use
169 in creating the graphical representation of the rating.
170
171 =head1 VERSION
172
173 2003-06-27
174
175 =head1 AUTHOR
176
177 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
178
179 This plugin is now maintained by the Blosxom Sourceforge Team,
180 <blosxom-devel@lists.sourceforge.net>.
181
182 =head1 SEE ALSO
183
184 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
185
186 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
187
188 =head1 BUGS
189
190 None known; please send bug reports and feedback to the Blosxom
191 development mailing list <blosxom-devel@lists.sourceforge.net>.
192
193 =head1 LICENSE
194
195 Blosxom and this Blosxom Plug-in
196 Copyright 2003, Rael Dornfest 
197
198 Permission is hereby granted, free of charge, to any person obtaining a
199 copy of this software and associated documentation files (the "Software"),
200 to deal in the Software without restriction, including without limitation
201 the rights to use, copy, modify, merge, publish, distribute, sublicense,
202 and/or sell copies of the Software, and to permit persons to whom the
203 Software is furnished to do so, subject to the following conditions:
204
205 The above copyright notice and this permission notice shall be included
206 in all copies or substantial portions of the Software.
207
208 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
209 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
210 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
211 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
212 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
213 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
214 OTHER DEALINGS IN THE SOFTWARE.