Revert rss20 to using $ENV{PATH_INFO} in self link.
[blosxom-plugins.git] / gavinc / uf_adr_meta
bloba3d2f8b8381b7d9bc42a24e020a8470769cc0b38
1 # Blosxom Plugin: uf_adr_meta
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.001000
4 # Documentation: 'perldoc uf_adr_meta'
6 package uf_adr_meta;
8 use strict;
10 # Uncomment next line to enable debug output (don't uncomment debug() lines)
11 #use Blosxom::Debug debug_level => 1;
13 # --- Configuration defaults -----
15 my %config = (
17   # Extra CSS classes to add to the microformat container e.g. to turn display off
18   class => '',
19   #class => 'nodisplay',
21   # Whether to automatically add microformat to story bodies. If not set, 
22   # you must explicitly add $uf_adr_meta::adr to a template somewhere.
23   auto_append_to_body => 1,
25   # What markup style to use for your adr, if auto-appending. 
26   # 3 styles are currently defined: 
27   # 'div-span' uses a 'div' elt for the container, and 'span' elements for the fields
28   # 'ul' uses a 'ul' list for the container, and 'li' elements for the fields
29   # 'dl' uses a 'dl' list for the container, 'dt' elements for field names, and 
30   #    'dd' elements for the fields themselves
31   #style => 'div-span',
32   #style => 'ul',
33   style => 'dl',
37 # --------------------------------
38 # __END_CONFIG__
40 use vars qw($adr);
42 # Official adr attributes
43 my @attr = qw(post-office-box extended-address street-address
44               locality region postal-code country-name);
45 # Attribute aliases
46 my %alias = (
47     'post-office-box'       => 'pobox',
48     'street-address'        => 'street',
49     locality                => 'city',
50     region                  => 'state',
51     'postal-code'           => 'postcode',
52     'country-name'          => 'country',
54 # Attributes which if set will cause us to skip this plugin (looks like an hcard)
55 my @skip_attr = qw(fn name);
57 $config{style} = 'div-span' unless $config{style} eq 'ul' or $config{style} eq 'dl';
59 sub start { 1 }
61 # Return the first existing metadata item key and value given a list of keys
62 sub _get_meta {
63     for my $attr ( @_ ) {
64         my $meta_attr = $attr;
65         $meta_attr =~ s/-/_/g;
66         my $value = $blosxom::meta{$meta_attr};
67         $value = eval "\$meta::$attr" unless defined $value;
68         return wantarray ? ( $attr, $value ) : $value if defined $value;
69     }
70     return wantarray ? () : undef;
73 sub story {
74     my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
76     # Skip if any of the @skip_attr are set
77     for (@skip_attr) {
78         return 1 if $blosxom::meta{$_} || eval "\$meta::$_"; 
79     }
81     my $story_style = _get_meta( 'adr_style' ) || $config{style};
82     my $ctag = $story_style eq 'div-span' ? 'div' : $story_style;
83     my $etag = $story_style eq 'div-span' ? 'span' :
84                $story_style eq 'ul' ? 'li' : 'dd';
86     $adr = '';
87     for my $attr ( @attr ) {
88         my $meta_attr = $attr;
89         $meta_attr =~ s/-/_/g;
90         my $value = $blosxom::meta{$meta_attr} || eval "\$meta::$attr" 
91                  || $blosxom::meta{ $alias{$attr} } || eval "\$meta::$alias{$attr}";
92         next unless defined $value;
93         $adr .= qq(<dt>$attr</dt>) if $story_style eq 'dl';
94         $adr .= qq(<$etag class="$attr">$value</$etag>\n);
95     }
96     if ($adr) {
97       my $container_classes = 'adr';
98       if (my $meta_class = _get_meta('adr_class')) {
99         $container_classes .= " $meta_class";
100       }
101       else {
102         $container_classes .= " $config{class}" if $config{class};
103       }
104       $adr = qq(<$ctag class="$container_classes">\n$adr</$ctag>\n);
105       # debug(1, "uf_adr_meta: $adr\n");
106     }
108     my $autoappend = _get_meta( 'adr_autoappend' );
109     $autoappend = $config{auto_append_to_body} unless defined $autoappend;
110     return 1 unless $autoappend;
112     $$body_ref .= "\n\n$adr\n\n";
114     return 1;
119 __END__
121 =head1 NAME
123 uf_adr_meta - plugin to create an 'adr' microformat tag from post 
124 metadata
126 =head1 DESCRIPTION
128 uf_adr_meta is a plugin to create an 'adr' microformat tag from metadata 
129 in your post. The microformat tag is created in the $uf_adr_meta::adr 
130 variable for use in templates or by other plugins, or if the 
131 'auto_append_to_body' config variable is set (it is by default), 
132 uf_adr_meta will append the tag to your story body automatically.
134 =head2 OPTIONAL METADATA ITEMS
136 =over 4
138 =item post-office-box (alt: pobox)
140 =item extended-address 
142 =item street-address (alt: street)
144 =item locality (alt: city)
146 =item region (alt: state)
148 =item country-name (alt: country)
150 =back
152 =head2 Config Elements
154 uf_adr_meta also supports a couple of config elements that can be used to
155 override plugin config data on a per-story basis:
157 =over 4
159 =item Adr-Class (metamail) / adr_class (meta)
161 This class (or list of classes) is appended to the class list applied to the
162 top-level adr element in the rendered adr i.e. it overrides the 
163 'class' config variable. 
165 =item Adr-Autoappend (metamail) / adr_autoappend (meta)
167 This is a flag (0 or 1) indicating whether the rendered adr should be 
168 automatically appended to the story body. It overrides the 'auto_append_to_body'
169 config variable.
171 =item Adr-Style (metamail) / adr_style (meta)
173 One of the following styles: 'div-span', 'ul', 'dl', used to render the adr. 
174 It overrides the 'style' config variable.
176 =back
178 =head1 USAGE
180 uf_adr_meta should be loaded after the meta plugins (meta
181 itself, or the metaclear/metamail/metadir/metafile family).
183 =head1 SEE ALSO
185 Microformats.org: http://www.microformats.org/, http://microformats.org/wiki/address.
187 Blosxom: http://blosxom.sourceforge.net/
189 =head1 AUTHOR
191 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
193 =head1 LICENSE
195 Copyright 2007, Gavin Carr.
197 This plugin is licensed under the same terms as blosxom itself i.e.
199 Permission is hereby granted, free of charge, to any person obtaining a
200 copy of this software and associated documentation files (the "Software"),
201 to deal in the Software without restriction, including without limitation
202 the rights to use, copy, modify, merge, publish, distribute, sublicense,
203 and/or sell copies of the Software, and to permit persons to whom the
204 Software is furnished to do so, subject to the following conditions:
206 The above copyright notice and this permission notice shall be included
207 in all copies or substantial portions of the Software.
209 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
210 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
211 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
212 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
213 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
214 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
215 OTHER DEALINGS IN THE SOFTWARE.
217 =cut
219 # vim:ft=perl