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