Files
oddmuse/modules/vcard.pl
2015-08-18 10:48:03 +02:00

65 lines
2.1 KiB
Perl
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Copyright (C) 20112015 Alex Schroeder <alex@gnu.org>
# Copyright (C) 20142015 Aleks-Daniel Jakimenko <alex.jakimenko@gmail.com>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
#
# We just try to autodetect everything.
use strict;
use v5.10;
AddModuleDescription('vcard.pl');
our ($q, $bol, @MyRules);
push(@MyRules, \&hCardRule);
my $addr = qr(\G(\S+ \S+)
(.*)
((?:[A-Z][A-Z]?-)?\d+) (.*)(?:
(.*))?
);
my $email = qr(\G\s*(\S+@\S+)\n?);
my $tel = qr(\G\s*(\S+): (\+?[-0-9 ]+)\n?);
sub hCardRule {
return unless $bol;
my ($fn, $street, $zip, $city, $country) = /$addr/cg;
if ($fn) {
my ($mail) = /$email/cg;
my ($phonetype, $phone) = /$tel/cg;
my $html = $q->span({-class=>'fn'}, $fn) . $q->br();
$html .= $q->span({-class=>'street-address'}, $street) . $q->br();
$html .= $q->span({-class=>'postal-code'}, $zip)
. ' ' . $q->span({-class=>'locality'}, $city);
$html .= $q->br()
. $q->span({-class=>'country-name'}, $country) if $country;
my $hCard = $q->p($html);
$html = '';
$html .= $q->span({-class=>'email'},
$q->a({-href=>'mailto:' . $mail}, $mail)) if $mail;
$html .= $q->br() if $mail and $phone;
$html .= $q->span({-class=>'tel'},
$q->span({-class=>'type'}, $phonetype) . ': '
. $q->span({-class=>'value'}, $phone)) if $phone;
$hCard .= $q->p($html) if $html;
$hCard = $q->div({-class=>'vcard',
-style=>'color:red;'}, $hCard);
return CloseHtmlEnvironments() . $hCard . AddHtmlEnvironment('p');
}
return;
}