# Blosxom Plugin: uf_xfolk_meta # Author(s): Gavin Carr # Version: 0.001000 # Documentation: 'perldoc uf_xfolk_meta' package uf_xfolk_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 = ( # URL to use as base URL for tag links tagbase => "$blosxom::url/tags", # Extra CSS classes to add to the microformat container e.g. to turn display off class => '', #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. 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 #style => 'div-span', #style => 'ul', style => 'dl', ); # -------------------------------- # __END_CONFIG__ use vars qw($xfolk); # Attributes which if set will cause us to skip this plugin (looks like an hcard) my @skip_attr = qw(fn name); $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( 'xfolk_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'; # Required metadata my $url = _get_meta('url', 'taggedlink'); my $title = _get_meta('title'); my $tags = _get_meta('tags'); my $description = _get_meta('description'); return 1 unless defined $url && defined $title; $xfolk = ''; my $container_classes = 'xfolkentry'; if (my $meta_class = _get_meta('xfolk_class')) { $container_classes .= " $meta_class"; } else { $container_classes .= " $config{class}" if $config{class}; } $xfolk .= qq(<$ctag class="$container_classes">\n); $xfolk .= qq(
URL
) if $story_style eq 'dl'; $xfolk .= qq(<$etag class="xfolk_link">$title\n); if ($tags) { $xfolk .= qq(
Tags
) if $story_style eq 'dl'; $xfolk .= qq(<$etag class="xfolk_tags">); my @tags = (); for (split /\s*,\s*/, $tags) { push @tags, qq(); } $xfolk .= join ', ', @tags if @tags; $xfolk .= qq(\n); } if ($description) { $xfolk .= qq(
Description
) if $story_style eq 'dl'; $xfolk .= qq(<$etag class="description">$description\n) } $xfolk .= qq(\n); # debug(1, "uf_xfolk_meta: $xfolk\n"); my $autoappend = _get_meta( 'xfolk_autoappend' ); $autoappend = $config{auto_append_to_body} unless defined $autoappend; return 1 unless $autoappend; $$body_ref .= "\n\n$xfolk\n\n"; return 1; } 1; __END__ =head1 NAME uf_xfolk_meta - plugin to create a 'xfolk' (bookmark) microformat tag from post metadata =head1 DESCRIPTION uf_xfolk_meta is a plugin to create an 'xfolk' (bookmark) microformat tag from metadata in your post. The microformat tag is created in the $uf_xfolk_meta::xfolk 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_xfolk_meta will append the tag to your story body automatically. =head2 REQUIRED METADATA ITEMS =over 4 =item url (or taggedlink) The URL for the bookmarked page. =item title The title to use for the bookmarked page. =back If any required metadata is missing the plugin just skips the story. =head2 OPTIONAL METADATA ITEMS =over 4 =item tags Comma-separated list of tags applying to the bookmarked page. =item description Description or summary of the bookmarked page. =back =head2 Config Elements uf_xfolk_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 XFolk-Class (metamail) / xfolk_class (meta) This class (or list of classes) is appended to the class list applied to the top-level xfolk element in the rendered xfolk i.e. it overrides the 'class' config variable. =item XFolk-Autoappend (metamail) / xfolk_autoappend (meta) This is a flag (0 or 1) indicating whether the rendered xfolk should be automatically appended to the story body. It overrides the 'auto_append_to_body' config variable. =item XFolk-Style (metamail) / xfolk_style (meta) One of the following styles: 'div-span', 'ul', 'dl', used to render the xfolk. It overrides the 'style' config variable. =back =head1 USAGE uf_xfolk_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/xfolk. 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