1 # Blosxom Plugin: uf_adr_meta
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
4 # Documentation: 'perldoc uf_adr_meta'
10 # Uncomment next line to enable debug output (don't uncomment debug() lines)
11 #use Blosxom::Debug debug_level => 1;
13 # --- Configuration defaults -----
17 # Extra CSS classes to add to the microformat container e.g. to turn display off
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
37 # --------------------------------
41 # Official adr attributes
42 my @attr = qw(post-office-box extended-address street-address
43 locality region postal-code country-name);
46 'post-office-box' => 'pobox',
47 'street-address' => 'street',
50 'postal-code' => 'postcode',
51 'country-name' => 'country',
53 # Attributes which if set will cause us to skip this plugin (looks like an hcard)
54 my @skip_attr = qw(fn name);
56 $config{style} = 'div-span' unless $config{style} eq 'ul' or $config{style} eq 'dl';
60 # Return the first existing metadata item key and value given a list of keys
63 my $meta_attr = $attr;
64 $meta_attr =~ s/-/_/g;
65 my $value = $blosxom::meta{$meta_attr};
66 $value = eval "\$meta::$attr" unless defined $value;
67 return wantarray ? ( $attr, $value ) : $value if defined $value;
69 return wantarray ? () : undef;
73 my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
75 # Skip if any of the @skip_attr are set
77 return 1 if $blosxom::meta{$_} || eval "\$meta::$_";
80 my $story_style = _get_meta( 'adr_style' ) || $config{style};
81 my $ctag = $story_style eq 'div-span' ? 'div' : $story_style;
82 my $etag = $story_style eq 'div-span' ? 'span' :
83 $story_style eq 'ul' ? 'li' : 'dd';
86 for my $attr ( @attr ) {
87 my $meta_attr = $attr;
88 $meta_attr =~ s/-/_/g;
89 my $value = $blosxom::meta{$meta_attr} || eval "\$meta::$attr"
90 || $blosxom::meta{ $alias{$attr} } || eval "\$meta::$alias{$attr}";
91 next unless defined $value;
92 $adr .= qq(<dt>$attr</dt>) if $story_style eq 'dl';
93 $adr .= qq(<$etag class="$attr">$value</$etag>\n);
96 my $container_classes = 'adr';
97 if (my $meta_class = _get_meta('adr_class')) {
98 $container_classes .= " $meta_class";
101 $container_classes .= " $config{class}" if $config{class};
103 $adr = qq(<$ctag class="$container_classes">\n$adr</$ctag>\n);
104 # debug(1, "uf_adr_meta: $adr\n");
107 my $autoappend = _get_meta( 'adr_autoappend' );
108 $autoappend = $config{auto_append_to_body} unless defined $autoappend;
109 return 1 unless $autoappend;
111 $$body_ref .= "\n\n$adr\n\n";
122 uf_adr_meta - plugin to create an 'adr' microformat tag from post
127 uf_adr_meta is a plugin to create an 'adr' microformat tag from metadata
128 in your post. The microformat tag is created in the $uf_adr_meta::adr
129 variable for use in templates or by other plugins, or if the
130 'auto_append_to_body' config variable is set (it is by default),
131 uf_adr_meta will append the tag to your story body automatically.
133 =head2 OPTIONAL METADATA ITEMS
137 =item post-office-box (alt: pobox)
139 =item extended-address
141 =item street-address (alt: street)
143 =item locality (alt: city)
145 =item region (alt: state)
147 =item country-name (alt: country)
151 =head2 Config Elements
153 uf_adr_meta also supports a couple of config elements that can be used to
154 override plugin config data on a per-story basis:
158 =item Adr-Class (metamail) / adr_class (meta)
160 This class (or list of classes) is appended to the class list applied to the
161 top-level adr element in the rendered adr i.e. it overrides the
162 'class' config variable.
164 =item Adr-Autoappend (metamail) / adr_autoappend (meta)
166 This is a flag (0 or 1) indicating whether the rendered adr should be
167 automatically appended to the story body. It overrides the 'auto_append_to_body'
170 =item Adr-Style (metamail) / adr_style (meta)
172 One of the following styles: 'div-span', 'ul', 'dl', used to render the adr.
173 It overrides the 'style' config variable.
179 uf_adr_meta should be loaded after the meta plugins (meta
180 itself, or the metaclear/metamail/metadir/metafile family).
184 Microformats.org: http://www.microformats.org/, http://microformats.org/wiki/address.
186 Blosxom: http://blosxom.sourceforge.net/
190 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
194 Copyright 2007, Gavin Carr.
196 This plugin is licensed under the same terms as blosxom itself i.e.
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.