Add a bunch of Rael plugins.
[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://www.raelity.org/apps/blosxom/
5 # Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
6
7 package rating;
8
9 # --- Configurable variables -----
10
11 # What's the default rating minimum?
12 my $default_min = 1;
13
14 # What's the default rating maximum?
15 my $default_max = 5;
16
17 # What's the width per rating point for graphical style?
18 my $width = 10;
19
20 # What's the height for graphical style?
21 my $height = 10;
22
23 # Where are the graphical images (rating_below.gif, rating.gif, 
24 # rating_above.gif) kept?
25 my $image_url = "/images";
26
27 # --------------------------------
28
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
33
34 my $min = $meta::rating_min || $default_min;
35 my $max = $meta::rating_max || $default_max;
36
37 $image_url =~ s!/+$!!;
38
39 sub start {
40   1;
41 }
42
43 sub story {
44   my($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
45
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   }
51
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;
58
59   # The textual representation
60   $textual = 
61       '&lt;'
62     . '=' x ($numerical - $min)  
63     . 'O' 
64     . '=' x ($max - $numerical)  
65     . '&gt;';
66
67   # The star representation
68   $star ='*' x  $numerical;
69  
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">};
77
78   return 1;
79 }
80
81 1;
82
83 __END__
84
85 =head1 NAME
86
87 Blosxom Plug-in: rating
88
89 =head1 SYNOPSIS
90
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.
94
95 For example, a story specifying:
96
97   meta-rating: 4
98
99 results in the following flavour template variables and associated 
100 representations (the minimum, in this case, being 1 and maximum being 5):
101
102   $rating::numerical:   4
103
104   $rating::textual:     <===O=>
105
106   $rating::star:        ****
107
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">
112
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.
116
117 A rating lower than the minimum is set to the minimum; a rating higher than
118 the maximum is set to the maximum.
119
120 =head1 PREREQUISITES
121
122 The rating plug-in requires the meta plug-in, available at:
123
124   http://www.raelity.org/apps/blosxom/plugins/meta/meta.individual
125
126 =head1 INSTALLATION
127
128 Drop the rating  plug-in into your Blosxom plugins folder.
129
130 =head1 CONFIGURATION
131
132 The plug-in will just work out of the box without any configuration.  All
133 further configuration is entirely optional.
134
135 # What's the default rating minimum?
136 my $default_min = 1;
137
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.
143
144 # What's the default rating maximum?
145 my $default_max = 5;
146
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.
152
153 # What's the width per rating point for graphical style?
154 my $width = 10;
155
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)..
158
159 # What's the height for graphical style?
160 my $height = 10;
161
162 Sets the height in pixels for each rating point.
163
164 # Where are the graphical images (rating_below.gif, rating.gif, 
165 # rating_above.gif) kept?
166 my $image_url = "/images";
167
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.
171
172 =head1 VERSION
173
174 2003-06-27
175
176 =head1 AUTHOR
177
178 Rael Dornfest  <rael@oreilly.com>, http://www.raelity.org/
179
180 =head1 SEE ALSO
181
182 Blosxom Home/Docs/Licensing: http://www.raelity.org/apps/blosxom/
183
184 Blosxom Plugin Docs: http://www.raelity.org/apps/blosxom/plugin.shtml
185
186 =head1 BUGS
187
188 Address bug reports and comments to the Blosxom mailing list 
189 [http://www.yahoogroups.com/group/blosxom].
190
191 =head1 LICENSE
192
193 Blosxom and this Blosxom Plug-in
194 Copyright 2003, Rael Dornfest 
195
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:
202
203 The above copyright notice and this permission notice shall be included
204 in all copies or substantial portions of the Software.
205
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.