Update flavourpathinfo to use Blosxom::Debug.
[blosxom-plugins.git] / general / rating
bloba56fac74abb794294687042d4bf3623c6ba22804
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/
6 package rating;
8 # --- Configurable variables -----
10 # What's the default rating minimum?
11 my $default_min = 1;
13 # What's the default rating maximum?
14 my $default_max = 5;
16 # What's the width per rating point for graphical style?
17 my $width = 10;
19 # What's the height for graphical style?
20 my $height = 10;
22 # Where are the graphical images (rating_below.gif, rating.gif, 
23 # rating_above.gif) kept?
24 my $image_url = "/images";
26 # --------------------------------
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
33 my $min = $meta::rating_min || $default_min;
34 my $max = $meta::rating_max || $default_max;
36 $image_url =~ s!/+$!!;
38 sub start {
39   1;
42 sub story {
43   my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
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   }
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;
58   # The textual representation
59   $textual = 
60       '&lt;'
61     . '=' x ($numerical - $min)  
62     . 'O' 
63     . '=' x ($max - $numerical)  
64     . '&gt;';
66   # The star representation
67   $star ='*' x  $numerical;
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">};
77   return 1;
82 __END__
84 =head1 NAME
86 Blosxom Plug-in: rating
88 =head1 SYNOPSIS
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.
94 For example, a story specifying:
96   meta-rating: 4
98 results in the following flavour template variables and associated 
99 representations (the minimum, in this case, being 1 and maximum being 5):
101   $rating::numerical:   4
103   $rating::textual:     <===O=>
105   $rating::star:        ****
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">
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.
116 A rating lower than the minimum is set to the minimum; a rating higher than
117 the maximum is set to the maximum.
119 =head1 PREREQUISITES
121 The rating plug-in requires the meta plug-in, available at:
123   http://www.raelity.org/apps/blosxom/plugins/meta/meta.individual
125 =head1 INSTALLATION
127 Drop the rating  plug-in into your Blosxom plugins folder.
129 =head1 CONFIGURATION
131 The plug-in will just work out of the box without any configuration.  All
132 further configuration is entirely optional.
134 # What's the default rating minimum?
135 my $default_min = 1;
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.
143 # What's the default rating maximum?
144 my $default_max = 5;
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.
152 # What's the width per rating point for graphical style?
153 my $width = 10;
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)..
158 # What's the height for graphical style?
159 my $height = 10;
161 Sets the height in pixels for each rating point.
163 # Where are the graphical images (rating_below.gif, rating.gif, 
164 # rating_above.gif) kept?
165 my $image_url = "/images";
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.
171 =head1 VERSION
173 2003-06-27
175 =head1 AUTHOR
177 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
179 This plugin is now maintained by the Blosxom Sourceforge Team,
180 <blosxom-devel@lists.sourceforge.net>.
182 =head1 SEE ALSO
184 Blosxom Home/Docs/Licensing: http://blosxom.sourceforge.net/
186 Blosxom Plugin Docs: http://blosxom.sourceforge.net/documentation/users/plugins.html
188 =head1 BUGS
190 None known; please send bug reports and feedback to the Blosxom
191 development mailing list <blosxom-devel@lists.sourceforge.net>.
193 =head1 LICENSE
195 Blosxom and this Blosxom Plug-in
196 Copyright 2003, Rael Dornfest 
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:
205 The above copyright notice and this permission notice shall be included
206 in all copies or substantial portions of the Software.
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.