# Blosxom Plugin: uf_geo_meta # Author(s): Gavin Carr # Version: 0.001000 # Documentation: 'perldoc uf_geo_meta' package uf_geo_meta; use strict; # Uncomment next line to enable debug output (don't uncomment debug() lines) #use Blosxom::Debug debug_level => 1; # --- Configurable variables ----- my %config = (); # Extra CSS classes to add to the microformat container e.g. to turn display off $config{class} = ''; #$config{class} = 'nodisplay'; # Whether to automatically add microformat to story bodies. If not set, # you must explicitly add $uf_adr_meta::adr to a template somewhere. $config{auto_append_to_body} = 1; # What markup style to use for your adr, if auto-appending. # 3 styles are currently defined: # 'div-span' uses a 'div' elt for the container, and 'span' elements for the fields # 'ul' uses a 'ul' list for the container, and 'li' elements for the fields # 'dl' uses a 'dl' list for the container, 'dt' elements for field names, and # 'dd' elements for the fields themselves #$config{style} = 'div-span'; #$config{style} = 'ul'; $config{style} = 'dl'; # -------------------------------- # __END_CONFIG__ use vars qw($geo); # Attributes which if set will cause us to skip this plugin (looks like an adr) my @skip_attr = qw(locality region postal-code country-name city state postcode country); $config{style} = 'div-span' unless $config{style} eq 'ul' or $config{style} eq 'dl'; sub start { 1 } # Return the first existing metadata item key and value given a list of keys sub _get_meta { for my $attr ( @_ ) { my $meta_attr = $attr; $meta_attr =~ s/-/_/g; my $value = $blosxom::meta{$meta_attr}; $value = eval "\$meta::$attr" unless defined $value; return wantarray ? ( $attr, $value ) : $value if defined $value; } return wantarray ? () : undef; } sub story { my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_; # Skip if any of the @skip_attr are set for (@skip_attr) { return 1 if $blosxom::meta{$_} || eval "\$meta::$_"; } my $story_style = _get_meta( 'geo_style' ) || $config{style}; my $ctag = $story_style eq 'div-span' ? 'div' : $story_style; my $etag = $story_style eq 'div-span' ? 'span' : $story_style eq 'ul' ? 'li' : 'dd'; my $sep = ', ' if $story_style eq 'div-span'; my $latitude = _get_meta('latitude'); my $longitude = _get_meta('longitude'); return 1 unless defined $latitude && defined $longitude; $geo = ''; my $container_classes = 'geo'; if (my $meta_class = _get_meta('geo_class')) { $container_classes .= " $meta_class"; } else { $container_classes .= " $config{class}" if $config{class}; } $geo .= qq(<$ctag class="$container_classes">); $geo .= qq(
Latitude
) if $story_style eq 'dl'; $geo .= qq(<$etag class="latitude">$latitude); $geo .= $sep if $story_style = 'div-span'; $geo .= qq(
Longitude
) if $story_style eq 'dl'; $geo .= qq(<$etag class="longitude">$longitude); $geo .= qq(); # debug(1, "uf_geo_meta: $geo\n"); my $autoappend = _get_meta( 'geo_autoappend' ); $autoappend = $config{auto_append_to_body} unless defined $autoappend; return 1 unless $autoappend; $$body_ref .= "\n\n$geo\n\n"; return 1; } 1; __END__ =head1 NAME uf_geo_meta - plugin to create a 'geo' microformat tag from post metadata =head1 DESCRIPTION uf_geo_meta is a plugin to create a 'geo' microformat tag from metadata in your post. The microformat tag is created in the $uf_geo_meta::geo variable for use in templates or by other plugins, or if the 'auto_append_to_body' config variable is set (it is by default), uf_geo_meta will append the tag to your story body automatically. =head2 REQUIRED METADATA ITEMS =over 4 =item latitude A decimal between -90.0 (South Pole) and +90.0 (North Pole), indicating degrees of latitude. =item longitude A decimal between -180.0 (western hemisphere) and +180.0 (eastern hemisphere), indicating degrees of longitude. =back If any required metadata is missing the plugin just skips the story. =head2 Config Elements uf_geo_meta also supports a couple of config elements that can be used to override plugin config data on a per-story basis: =over 4 =item Geo-Class (metamail) / geo_class (meta) This class (or list of classes) is appended to the class list applied to the top-level geo element in the rendered geo i.e. it overrides the 'class' config variable. =item Geo-Autoappend (metamail) / geo_autoappend (meta) This is a flag (0 or 1) indicating whether the rendered geo should be automatically appended to the story body. It overrides the 'auto_append_to_body' config variable. =item Geo-Style (metamail) / geo_style (meta) One of the following styles: 'div-span', 'ul', 'dl', used to render the geo. It overrides the 'style' config variable. =back =head1 EXAMPLE Adding a geo microformat to your post then becomes as simple as: Testing uf_geo_meta Latitude: -33.717770 Longitude: 151.115886 if using metamail, or: Random blog post meta-latitude: -33.717770 meta-longitude: 151.115886 =head1 USAGE uf_geo_meta should be loaded after the meta plugins (meta itself, or the metaclear/metamail/metadir/metafile family). =head1 SEE ALSO Microformats.org: http://www.microformats.org/, http://microformats.org/wiki/geo. Blosxom: http://blosxom.sourceforge.net/ =head1 AUTHOR Gavin Carr , http://www.openfusion.net/ =head1 LICENSE Copyright 2007, Gavin Carr. This plugin is licensed under the same terms as blosxom itself i.e. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =cut # vim:ft=perl