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