Convert rss20 to use $path_info_full instead of $ENV{PATH_INFO}.
[blosxom-plugins.git] / gavinc / uf_xfolk_meta
blobe99988c3777e16ba99fd13e558c6bcc043741039
1 # Blosxom Plugin: uf_xfolk_meta
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.001000
4 # Documentation: 'perldoc uf_xfolk_meta'
6 package uf_xfolk_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 # --- Configurable variables -----
15 my %config = (
17   # URL to use as base URL for tag links
18   tagbase => "$blosxom::url/tags",
20   # Extra CSS classes to add to the microformat container e.g. to turn display off
21   class => '',
22   #class => 'nodisplay',
24   # Whether to automatically add microformat to story bodies. If not set, 
25   # you must explicitly add $uf_adr_meta::adr to a template somewhere.
26   auto_append_to_body => 1,
28   # What markup style to use for your adr, if auto-appending. 
29   # 3 styles are currently defined: 
30   # 'div-span' uses a 'div' elt for the container, and 'span' elements for the fields
31   # 'ul' uses a 'ul' list for the container, and 'li' elements for the fields
32   # 'dl' uses a 'dl' list for the container, 'dt' elements for field names, and 
33   #    'dd' elements for the fields themselves
34   #style => 'div-span',
35   #style => 'ul',
36   style => 'dl',
40 # --------------------------------
41 # __END_CONFIG__
43 use vars qw($xfolk);
45 # Attributes which if set will cause us to skip this plugin (looks like an hcard)
46 my @skip_attr = qw(fn name);
48 $config{style} = 'div-span' unless $config{style} eq 'ul' or $config{style} eq 'dl';
50 sub start { 1 }
52 # Return the first existing metadata item key and value given a list of keys
53 sub _get_meta {
54     for my $attr ( @_ ) {
55         my $meta_attr = $attr;
56         $meta_attr =~ s/-/_/g;
57         my $value = $blosxom::meta{$meta_attr};
58         $value = eval "\$meta::$attr" unless defined $value;
59         return wantarray ? ( $attr, $value ) : $value if defined $value;
60     }
61     return wantarray ? () : undef;
64 sub story {
65     my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
67     # Skip if any of the @skip_attr are set
68     for (@skip_attr) {
69         return 1 if $blosxom::meta{$_} || eval "\$meta::$_"; 
70     }
72     my $story_style = _get_meta( 'xfolk_style' ) || $config{style};
73     my $ctag = $story_style eq 'div-span' ? 'div' : $story_style;
74     my $etag = $story_style eq 'div-span' ? 'span' :
75                $story_style eq 'ul' ? 'li' : 'dd';
77     # Required metadata
78     my $url = _get_meta('url', 'taggedlink');
79     my $title = _get_meta('title');
80     my $tags = _get_meta('tags');
81     my $description = _get_meta('description');
82     return 1 unless defined $url && defined $title;
84     $xfolk = '';
85     my $container_classes = 'xfolkentry';
86     if (my $meta_class = _get_meta('xfolk_class')) {
87       $container_classes .= " $meta_class";
88     }
89     else {
90       $container_classes .= " $config{class}" if $config{class};
91     }
92     $xfolk .= qq(<$ctag class="$container_classes">\n);
93     $xfolk .= qq(<dt>URL</dt>) if $story_style eq 'dl';
94     $xfolk .= qq(<$etag class="xfolk_link"><a class="taggedlink" href="$url" title="$title">$title</a></$etag>\n);
95     if ($tags) {
96       $xfolk .= qq(<dt>Tags</dt>) if $story_style eq 'dl';
97       $xfolk .= qq(<$etag class="xfolk_tags">);
98       my @tags = ();
99       for (split /\s*,\s*/, $tags) {
100         push @tags, qq(<a rel="tag" href="$config{tagbase}/$_">$_</a>);
101       }
102       $xfolk .= join ', ', @tags if @tags;
103       $xfolk .= qq(</$etag>\n);
104     }
105     if ($description) {
106       $xfolk .= qq(<dt>Description</dt>) if $story_style eq 'dl';
107       $xfolk .= qq(<$etag class="description">$description</$etag>\n)
108     }
109     $xfolk .= qq(</$ctag>\n);
110     # debug(1, "uf_xfolk_meta: $xfolk\n");
112     my $autoappend = _get_meta( 'xfolk_autoappend' );
113     $autoappend = $config{auto_append_to_body} unless defined $autoappend;
114     return 1 unless $autoappend;
116     $$body_ref .= "\n\n$xfolk\n\n";
118     return 1;
123 __END__
125 =head1 NAME
127 uf_xfolk_meta - plugin to create a 'xfolk' (bookmark) microformat tag 
128 from post metadata
130 =head1 DESCRIPTION
132 uf_xfolk_meta is a plugin to create an 'xfolk' (bookmark) microformat tag 
133 from metadata in your post. The microformat tag is created in the 
134 $uf_xfolk_meta::xfolk variable for use in templates or by other plugins, 
135 or if the 'auto_append_to_body' config variable is set (it is by default), 
136 uf_xfolk_meta will append the tag to your story body automatically.
138 =head2 REQUIRED METADATA ITEMS
140 =over 4
142 =item url (or taggedlink)
144 The URL for the bookmarked page.
146 =item title
148 The title to use for the bookmarked page.
150 =back
152 If any required metadata is missing the plugin just skips the story.
154 =head2 OPTIONAL METADATA ITEMS
156 =over 4
158 =item tags
160 Comma-separated list of tags applying to the bookmarked page.
162 =item description
164 Description or summary of the bookmarked page.
166 =back
168 =head2 Config Elements
170 uf_xfolk_meta also supports a couple of config elements that can be used to
171 override plugin config data on a per-story basis:
173 =over 4
175 =item XFolk-Class (metamail) / xfolk_class (meta)
177 This class (or list of classes) is appended to the class list applied to the
178 top-level xfolk element in the rendered xfolk i.e. it overrides the 
179 'class' config variable. 
181 =item XFolk-Autoappend (metamail) / xfolk_autoappend (meta)
183 This is a flag (0 or 1) indicating whether the rendered xfolk should be 
184 automatically appended to the story body. It overrides the 'auto_append_to_body'
185 config variable.
187 =item XFolk-Style (metamail) / xfolk_style (meta)
189 One of the following styles: 'div-span', 'ul', 'dl', used to render the xfolk. 
190 It overrides the 'style' config variable.
192 =back
194 =head1 USAGE
196 uf_xfolk_meta should be loaded after the meta plugins (meta
197 itself, or the metaclear/metamail/metadir/metafile family).
199 =head1 SEE ALSO
201 Microformats.org: http://www.microformats.org/, http://microformats.org/wiki/xfolk.
203 Blosxom: http://blosxom.sourceforge.net/
205 =head1 AUTHOR
207 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
209 =head1 LICENSE
211 Copyright 2007, Gavin Carr.
213 This plugin is licensed under the same terms as blosxom itself i.e.
215 Permission is hereby granted, free of charge, to any person obtaining a
216 copy of this software and associated documentation files (the "Software"),
217 to deal in the Software without restriction, including without limitation
218 the rights to use, copy, modify, merge, publish, distribute, sublicense,
219 and/or sell copies of the Software, and to permit persons to whom the
220 Software is furnished to do so, subject to the following conditions:
222 The above copyright notice and this permission notice shall be included
223 in all copies or substantial portions of the Software.
225 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
226 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
227 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
228 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
229 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
230 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
231 OTHER DEALINGS IN THE SOFTWARE.
233 =cut
235 # vim:ft=perl