b02dfc1d59eaa451be39b8777c0bafbd978cd886
[matthijs/upstream/blosxom-plugins.git] / gavinc / hcard
1 # Blosxom Plugin: hcard
2 # Author(s): Gavin Carr <gavin@openfusion.com.au>
3 # Version: 0.001000
4 # Documentation: 'perldoc hcard'
5 # Requires: metaclear, metamail, uf_hcard_meta
6
7 package hcard;
8
9 use strict;
10 use IO::File;
11
12 # Uncomment next line to enable debug output (don't uncomment debug() lines)
13 #use Blosxom::Debug debug_level => 1;
14
15 # --- Configuration defaults -----
16
17 my %config = (
18
19   # Where is the hcard metadata?
20   hcard_meta_file => "$blosxom::datadir/hcard.yml",
21
22 );
23
24 # --------------------------------
25
26 use vars qw($hcard);
27 $hcard = '';
28
29 sub start {
30     # Check $hcard_meta_file exists
31     unless (-f $config{hcard_meta_file}) {
32         warn "(hcard) cannot find hcard_meta_file file '$config{hcard_meta_file}' - aborting\n";
33         return 0;
34     }
35     return 1;
36 }
37
38 sub skip {
39     my $hcard_fh = IO::File->new( $config{hcard_meta_file}, 'r' )
40         or warn "(hcard) cannot open hcard_meta_file file '$config{hcard_meta_file}': $! - aborting\n"
41             and return 0;
42     my @hcard_data = <$hcard_fh>;
43     my $hcard_title = $hcard_data[0];
44     chomp $hcard_title;
45     my $hcard_body = join '', @hcard_data[ 1 .. $#hcard_data ];
46     $hcard_fh->close;
47     # debug(1, "hcard_body: $hcard_body");
48
49     unless ($hcard_body) {
50         warn "(hcard) no data found in hcard_meta_file file '$config{hcard_meta_file}' - aborting\n";
51         return 0;
52     }
53   
54     # Fake story calls to metaclear, metamail and uf_hcard_meta to render the hcard
55     my @story_args = ( undef, undef, undef, undef, \$hcard_title, \$hcard_body );
56     metaclear::story( @story_args );
57     metamail::story( @story_args );
58     uf_hcard_meta::story( @story_args );
59
60     $hcard = $uf_hcard_meta::hcard;
61
62     return 0;
63 }
64
65 1;
66
67 __END__
68
69 =head1 NAME
70
71 hcard - blosxom plugin to set a global $hcard::hcard variable for use in templates
72
73 =head1 DESCRIPTION
74
75 L<hcard> is a blosxom plugin to set a global $hcard::hcard variable for use in 
76 templates. It is intended to allow you to set up a global hcard for yourself
77 to be displayed somewhere in your blog template.
78
79 To use, simply define the set of hcard data you want to use in the 'hcard_meta_file'
80 file ($blosxom::datadir/hcard.yml, by default).
81
82 =head1 EXAMPLES
83
84 Here's an example hcard.yml for me:
85
86     Name: Gavin Carr
87     Organisation: Open Fusion
88     Role: Chief Geek
89     Email: gavin@openfusion.com.au
90     URL: http://www.openfusion.net/
91     Suburb: Wahroonga
92     State: NSW
93     Postcode: 2076
94     Country: Australia
95     Latitude: -33.717718
96     Longitude: 151.117158
97     HCard-Class: nodisplay
98     HCard-Style: div-span
99
100 =head1 USAGE
101
102 L<hcard> requires the L<uf_hcard_meta>, L<metaclear>, and L<metamail> plugins, 
103 but has no particular ordering requirements with respect to them.
104
105 =head1 SEE ALSO
106
107 L<uf_hcard_meta>, L<metaclear>, L<metamail>.
108
109 Microformats.org: http://www.microformats.org/, http://microformats.org/wiki/hcard.
110
111 Blosxom: http://blosxom.sourceforge.net/
112
113 =head1 AUTHOR
114
115 Gavin Carr <gavin@openfusion.com.au>, http://www.openfusion.net/
116
117 =head1 LICENSE
118
119 Copyright 2007, Gavin Carr.
120
121 This plugin is licensed under the same terms as blosxom itself i.e.
122
123 Permission is hereby granted, free of charge, to any person obtaining a
124 copy of this software and associated documentation files (the "Software"),
125 to deal in the Software without restriction, including without limitation
126 the rights to use, copy, modify, merge, publish, distribute, sublicense,
127 and/or sell copies of the Software, and to permit persons to whom the
128 Software is furnished to do so, subject to the following conditions:
129
130 The above copyright notice and this permission notice shall be included
131 in all copies or substantial portions of the Software.
132
133 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
134 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
135 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
136 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
137 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
138 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
139 OTHER DEALINGS IN THE SOFTWARE.
140
141 =cut
142
143 # vim:ft=perl:sw=4