1 # Blosxom Plugin: uf_geo_meta
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
4 # Documentation: 'perldoc uf_geo_meta'
10 # Uncomment next line to enable debug output (don't uncomment debug() lines)
11 #use Blosxom::Debug debug_level => 1;
13 # --- Configurable variables -----
17 # Extra CSS classes to add to the microformat container e.g. to turn display off
19 #$config{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 $config{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 #$config{style} = 'div-span';
32 #$config{style} = 'ul';
33 $config{style} = 'dl';
35 # --------------------------------
40 # Attributes which if set will cause us to skip this plugin (looks like an adr)
41 my @skip_attr = qw(locality region postal-code country-name city state postcode country);
43 $config{style} = 'div-span' unless $config{style} eq 'ul' or $config{style} eq 'dl';
47 # Return the first existing metadata item key and value given a list of keys
50 my $meta_attr = $attr;
51 $meta_attr =~ s/-/_/g;
52 my $value = $blosxom::meta{$meta_attr};
53 $value = eval "\$meta::$attr" unless defined $value;
54 return wantarray ? ( $attr, $value ) : $value if defined $value;
56 return wantarray ? () : undef;
60 my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
62 # Skip if any of the @skip_attr are set
64 return 1 if $blosxom::meta{$_} || eval "\$meta::$_";
67 my $story_style = _get_meta( 'geo_style' ) || $config{style};
68 my $ctag = $story_style eq 'div-span' ? 'div' : $story_style;
69 my $etag = $story_style eq 'div-span' ? 'span' :
70 $story_style eq 'ul' ? 'li' : 'dd';
71 my $sep = ', ' if $story_style eq 'div-span';
73 my $latitude = _get_meta('latitude');
74 my $longitude = _get_meta('longitude');
75 return 1 unless defined $latitude && defined $longitude;
78 my $container_classes = 'geo';
79 if (my $meta_class = _get_meta('geo_class')) {
80 $container_classes .= " $meta_class";
83 $container_classes .= " $config{class}" if $config{class};
86 $geo .= qq(<$ctag class="$container_classes">);
87 $geo .= qq(<dt>Latitude</dt>) if $story_style eq 'dl';
88 $geo .= qq(<$etag class="latitude">$latitude</$etag>);
89 $geo .= $sep if $story_style = 'div-span';
90 $geo .= qq(<dt>Longitude</dt>) if $story_style eq 'dl';
91 $geo .= qq(<$etag class="longitude">$longitude</$etag>);
93 # debug(1, "uf_geo_meta: $geo\n");
95 my $autoappend = _get_meta( 'geo_autoappend' );
96 $autoappend = $config{auto_append_to_body} unless defined $autoappend;
97 return 1 unless $autoappend;
99 $$body_ref .= "\n\n$geo\n\n";
110 uf_geo_meta - plugin to create a 'geo' microformat tag from post metadata
114 uf_geo_meta is a plugin to create a 'geo' microformat tag from metadata
115 in your post. The microformat tag is created in the $uf_geo_meta::geo
116 variable for use in templates or by other plugins, or if the
117 'auto_append_to_body' config variable is set (it is by default), uf_geo_meta
118 will append the tag to your story body automatically.
120 =head2 REQUIRED METADATA ITEMS
126 A decimal between -90.0 (South Pole) and +90.0 (North Pole), indicating
131 A decimal between -180.0 (western hemisphere) and +180.0 (eastern hemisphere),
132 indicating degrees of longitude.
136 If any required metadata is missing the plugin just skips the story.
138 =head2 Config Elements
140 uf_geo_meta also supports a couple of config elements that can be used to
141 override plugin config data on a per-story basis:
145 =item Geo-Class (metamail) / geo_class (meta)
147 This class (or list of classes) is appended to the class list applied to the
148 top-level geo element in the rendered geo i.e. it overrides the
149 'class' config variable.
151 =item Geo-Autoappend (metamail) / geo_autoappend (meta)
153 This is a flag (0 or 1) indicating whether the rendered geo should be
154 automatically appended to the story body. It overrides the 'auto_append_to_body'
157 =item Geo-Style (metamail) / geo_style (meta)
159 One of the following styles: 'div-span', 'ul', 'dl', used to render the geo.
160 It overrides the 'style' config variable.
166 Adding a geo microformat to your post then becomes as simple as:
170 Longitude: 151.115886
172 if using metamail, or:
175 meta-latitude: -33.717770
176 meta-longitude: 151.115886
180 uf_geo_meta should be loaded after the meta plugins (meta
181 itself, or the metaclear/metamail/metadir/metafile family).
185 Microformats.org: http://www.microformats.org/,
186 http://microformats.org/wiki/geo.
188 Blosxom: http://blosxom.sourceforge.net/
192 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
196 Copyright 2007, Gavin Carr.
198 This plugin is licensed under the same terms as blosxom itself i.e.
200 Permission is hereby granted, free of charge, to any person obtaining a
201 copy of this software and associated documentation files (the "Software"),
202 to deal in the Software without restriction, including without limitation
203 the rights to use, copy, modify, merge, publish, distribute, sublicense,
204 and/or sell copies of the Software, and to permit persons to whom the
205 Software is furnished to do so, subject to the following conditions:
207 The above copyright notice and this permission notice shall be included
208 in all copies or substantial portions of the Software.
210 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
211 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
212 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
213 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
214 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
215 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
216 OTHER DEALINGS IN THE SOFTWARE.