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