LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / vCard.pm
blobb36bea8cd34d4f2a3063f42ecfe55e4ad29e2218
1 package LJ::vCard;
3 use strict;
5 use base 'Text::vCard';
6 use MIME::Base64;
8 sub new {
9 my $class = shift;
11 my $remote = LJ::get_remote();
13 return $class->new_remote( $remote, @_ );
16 sub new_remote {
17 my $class = shift;
19 my $remote = shift;
20 my $u = shift;
22 my $upic = $u->userpic;
23 my $file = $upic ? $upic->imagedata : undef;
25 my $vcard = $class->SUPER::new;
26 $vcard->UID("$LJ::DOMAIN-uid-$u->{userid}");
27 $vcard->add_node({ 'node_type' => 'ADR', });
28 $vcard->add_node({ 'node_type' => 'N', });
29 $vcard->EMAIL($u->email_visible($remote));
30 $vcard->NICKNAME($u->{user});
31 $vcard->URL($u->journal_base . "/");
33 $u->preload_props(qw(city state zip country
34 aolim icq yahoo msn jabber google_talk skype gizmo));
37 my $node;
39 if ($file) {
40 $node = $vcard->add_node({
41 'node_type' => 'PHOTO;BASE64',
42 });
43 my $photo = encode_base64($file);
44 my $enphoto = "\n " . join("\n ", split(/\n/, $photo));
45 $node->{value} = $enphoto;
48 if ($u->share_contactinfo($remote)) {
49 my @chats = qw(aolim icq yahoo msn jabber google_talk skype gizmo);
50 foreach my $c (@chats) {
51 my $field = uc $c;
52 $field =~ s/_//g;
53 $field = "AIM" if $c eq "aolim";
54 my $value = $u->prop($c)
55 or next;
56 $node = $vcard->add_node({
57 'node_type' => "X-$field;type=WORK;type=pref",
58 });
59 $node->{value} = $value;
63 my $bday = $u->bday_string;
64 if ($bday && $u->can_show_full_bday) {
65 $bday = "0000-$bday" unless $bday =~ /\d\d\d\d/;
66 $node = $vcard->add_node({
67 'node_type' => 'BDAY;value=date',
68 });
69 $node->{value} = $bday;
72 $node= $vcard->add_node({
73 'node_type' => 'X-RSS',
74 });
75 $node->{value} = $u->journal_base . "/data/rss";
77 # Setting values on an address element
78 #$node->[0]->street('123 Fake');
79 if ($u->can_show_location) {
80 $node = $vcard->get({ 'node_type' => 'addresses' });
82 $node->[0]->city($u->prop('city'));
83 $node->[0]->region($u->prop('state'));
84 $node->[0]->post_code($u->prop('zip'));
85 $node->[0]->country($u->prop('country'));
88 $node = $vcard->get({ 'node_type' => 'name' });
90 #$node->[0]->family('Aker');
91 $node->[0]->given($u->{name});
93 return $vcard;
96 package LJ::vCard::Addressbook;
98 use base 'Text::vCard::Addressbook';
100 sub add {
101 my $self = shift;
102 my $vcards = $self->vcards;
104 push @$vcards, @_;