We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin:VCard

Development and Programming

Brian Hildreth's avatar
Brian Hildreth
45 posts
16 years ago
Brian Hildreth's avatar Brian Hildreth

So I was in need of a way to dynamically create vcards for a corporate website that I am working on, and after a little bit of searching, I found this helpful script http://www.troywolf.com/articles/php/class_vcard/

This was perfect because I was using playa relationships to make up the different office locations and contact numbers.

Now, this is a crude hack at getting this to work, but since I was under a tight deadline, I had no choice. Here is what I did.

I created 4 weblogs. 1) a staff weblog that had standard fields in it like first_name, last_name, etc. 2). A board member weblog that was a play field that called in the staff weblog, so that they could simply drag and drop staff members that was board members. Then I created a weblog called office_locations that had standard fields that made up the address like street_address, city, state, etc. and assigned each office entry a category that corrosponded to the locations of the office like Anchorage office, Jacksonville Office, etc. Finally, I created the main contact_pages weblog with multiple categories of Office Locations, Staff members, and Board Members. These categories made up the secondary navigation for the contact page. Then on this weblog I added the previous weblogs of office_staff, board_members, and office_locations as playa fields so they can publish each entry as a individual page.

Then I created a template group called contact that called in the office_pages weblog while pulling from the office_locations category and thus using the realtionship field to call in the playa field of office_locations weblog. Now, since playa rocks and relating entries is a breeze, they could also add the office staff as a related contact point for that particular office.

Now I formatted those as vcard microformats. Here is my main chunk from that template.

{related_entries id="contact_locations"}
<div class="vcard">
<h4 class="fn org">{title} <span class="vcard_link"><a href="http://{url_title_path=%27contact/vcard%27}" title="download company vcard">download company vcard</a></span></h4>
{if office_address}{office_address}{/if}

{if office_city}<span class="locality">{office_city}</span>, {/if}
{if office_state}<span class="region">{office_state}</span>{/if}
{if office_zip}<span class="postal-code">{office_zip}</span>{/if}
{if office_country}<span class="country-name">{/if}

<div class="tel">

<span class="tel">Phone: </span>
<span class="value">{office_phone}</span>

<span class="fax">Fax: </span>
<span class="value">{office_fax}</span>

</div>
{/related_entries}

Now that points to the vcard template via the url_title_path parameter. The vcard template has this in it. Make sure to add the exp:vcard tag at the top of the template.

{exp:vcard}
<?php
$vc = new vcard();
{exp:weblog:entries  weblog="office_locations"}
#$vc->filename = "";
#$vc->revision_date = "{date format="%F %d %Y"}";
/*
Possible values are PUBLIC, PRIVATE, and CONFIDENTIAL. If you leave class
blank, it will default to PUBLIC.
*/
#$vc->class = "";

/*
Contact's name data.
If you leave display_name blank, it will be built using the first and last name.
*/
#$vc->data['display_name'] = "CCI";
$vc->data['first_name'] = "CCI {title}";
$vc->data['last_name'] = "";
#$vc->data['additional_name'] = ""; //Middle name
#$vc->data['name_prefix'] = "";  //Mr. Mrs. Dr.
#$vc->data['name_suffix'] = ""; //DDS, MD, III, other designations.
$vc->data['nickname'] = "";
/*
Contact's company, department, title, profession
*/
$vc->data['company'] = "CCI, Inc";
#$vc->data['department'] = "";
$vc->data['title'] = "";
#$vc->data['role'] = "";
/*
Contact's work address
*/
#$vc->data['work_po_box'] = "";
#$vc->data['work_extended_address'] = "";
$vc->data['work_address'] = "{office_address}";
$vc->data['work_city'] = "{office_city}";
$vc->data['work_state'] = "{office_state}";
$vc->data['work_postal_code'] = "{office_zip}";
#$vc->data['work_country'] = "{office_country}";
/*
Contact's home address
*/
#$vc->data['home_po_box'] = "";
#$vc->data['home_extended_address'] = "";
$vc->data['home_address'] = "";
$vc->data['home_city'] = "";
$vc->data['home_state'] = "";
$vc->data['home_postal_code'] = "";
#$vc->data['home_country'] = "";
/*
Contact's telephone numbers.
*/
$vc->data['office_tel'] = "{office_phone}";
#$vc->data['home_tel'] = "";
$vc->data['cell_tel'] = "";
$vc->data['fax_tel'] = "{office_fax}";
#$vc->data['pager_tel'] = "";
/*
Contact's email addresses
*/
$vc->data['email1'] = "";
#$vc->data['email2'] = "";
/*
Contact's website
*/
$vc->data['url'] = "{site_url}";
/*
Some other contact data.
*/
#$vc->data['photo'] = "";  //Enter a URL.
$vc->data['birthday'] = "";
$vc->data['timezone'] = "{current_time format="%T"}";
/*
If you leave this blank, the class will default to using last_name or company.
*/
#$vc->data['sort_string'] = "";
/*
Notes about this contact.
*/
#$vc->data['note'] = "";
{/exp:weblog:entries}
$vc->download();
?>

This will create the vcard and open the file download box in their browser allowing them to download the vcard. Whhheeeew that was a long post. Sorry about that! So if anyone wants to develop this plugin further where the second php script was included in the plugin, please go right ahead. But anyway, here is the plugin. Like I said crude, but maybe someone else could run with it.

Here is the page with the vcards on it so you can see what I mean http://www.ccialaska.com/index.php/contact/office_locations/

Cheers, Brian

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

I would be really interested if someone developed a plugin of this.

       
Max Lazar's avatar
Max Lazar
337 posts
16 years ago
Max Lazar's avatar Max Lazar

Tag: {exp:vcard3}

Parameters: display_name = “” first_name = “” last_name = “” additional_name = “” name_prefix = “” name_suffix = “” nickname = “” title = “” role = “” department = “” company = “” work_po_box = “” work_extended_address = “” work_address = “” work_city = “” work_state = “” work_postal_code = “” work_country = “” home_po_box = “” home_extended_address = “” home_address = “” home_city = “” home_state = “” home_postal_code = “” home_country = “” office_tel = “” home_tel = “” cell_tel = “” fax_tel = “” pager_tel = “” email1 = “” email2 = “” url = “”{url} photo = “” birthday = “” timezone = “” sort_string = “” note = “”

vcard_name = “”

vcard filename by default is {display_name}, but u can choose u own format.

For example:

{exp:vcard3 
display_name = "TSawyer" 
first_name = "Tom" 
last_name = "Sawyer"
title = "Mister"
cell_tel = "+1 914 218 94885"    
email1 = "[email protected]"
url = "http://MarkTwain.com"
company = "Fence Design"
title = "HR"
note = "2000-plus fence design ideas submitted"
vcard_name = "tsawye"}
       
pushloop's avatar
pushloop
422 posts
16 years ago
pushloop's avatar pushloop

Hoorah! This is what I’ve been working on for the past 2 hrs :D

       
pushloop's avatar
pushloop
422 posts
16 years ago
pushloop's avatar pushloop

Hey Max, I’ve tried it out and ran into a few issues…

What I’m trying to achieve, is to dynamically generate the info in the vCard based on member fields as well as custom member fields, pulling info via exp:member:custom_profile_data, but this seems to break the vcard formatting somehow.

{exp:member:custom_profile_data member_id="{segment_3}"}
{exp:vcard3
display_name = "{screen_name} {medlem_efternamn}"
first_name = "{screen_name}"
last_name = "{medlem_efternamn}"
home_tel = "{medlem_telefon1}"
cell_tel = "{medlem_telefon2}"
home_address = “John Ericssonsgatan 5”
home_city = “Stockholm”
home_postal_code = “11222”
home_country = “Sweden”  
photo = “{avatar_url}{avatar_filename}”
note = "{bio}"
}
{/exp:member:custom_profile_data}

In the code above the member info of my own user is rendered. All these fields except cell_tel is filled, yet when I download the vCard file this is what it contains:

BEGIN:VCARD
VERSION:3.0
CLASS:PUBLIC
PRODID:-//class_vcard from TroyWolf.com//NONSGML Version 1//EN
REV:2009-03-21 19:49:32
FN:André Fredriksson
N:Fredriksson;André;;;

NOTE:Bio info
TZ:+0100
END:VCARD

Also, when using {email} to render my e-mail address, this contains the javascript that protects it, is there a way around this you think?

       
pushloop's avatar
pushloop
422 posts
16 years ago
pushloop's avatar pushloop

Aha, the color coding of the code here gave me a part of the solution, the “”-characters were incorrect. See my code example above.

Now I’m getting this:

BEGIN:VCARD
VERSION:3.0
CLASS:PUBLIC
PRODID:-//class_vcard from TroyWolf.com//NONSGML Version 1//EN
REV:2009-03-21 19:58:00
FN:André Fredriksson
N:Fredriksson;André;;;

ADR;TYPE=home:;;John Ericssonsgatan 5;Stockholm;;11222;Sweden
TEL;TYPE=home,voice:0761-030701
NOTE:Bio info
TZ:+0100
END:VCARD

When importing this to Apple’s Address Book, “CLASS:PUBLIC” is entered together with the note.

       
Max Lazar's avatar
Max Lazar
337 posts
16 years ago
Max Lazar's avatar Max Lazar

hello, pls. check it with attach file. Is it “CLASS:PUBLIC” in the Note field (if “yes” – can u send me file for example by PM)? About email - unfortunately, I only can recommend u to turn off email protect EE functionality. I don’t see another way at this moment.

       
pushloop's avatar
pushloop
422 posts
16 years ago
pushloop's avatar pushloop

Yes, exactly. I just PM’d you the file.

       
Tyssen's avatar
Tyssen
756 posts
16 years ago
Tyssen's avatar Tyssen

Hi Max,

Any idea how you’d go about creating a vCard from a form submission which could then be emailed to a site admin as an attachment?

       
pushloop's avatar
pushloop
422 posts
15 years ago
pushloop's avatar pushloop

Hey Max, did you ever find a solution to my issue?

/A

       
Max Lazar's avatar
Max Lazar
337 posts
15 years ago
Max Lazar's avatar Max Lazar

Hello, I will try to publish the new version with bugfixing on this weekend.

       
Christopher Kennedy's avatar
Christopher Kennedy
44 posts
15 years ago
Christopher Kennedy's avatar Christopher Kennedy

This plugin is definitely on the way to what I really would love. Admittedly, I’m using it for custom weblog entries, not member profiles, but I’d love to donate to keep this going. I’m seeing a few things like the CLASS:PUBLIC showing up in the notes in Address Book, as well as a parsing of the URL returning their Unicode values. Are these in line to be fixed? Additionally, where could I donate? :D

       
Christopher Kennedy's avatar
Christopher Kennedy
44 posts
15 years ago
Christopher Kennedy's avatar Christopher Kennedy

Oh, additionally, is there a way to specify a difference between office and direct line in the vcard template?

       
Max Lazar's avatar
Max Lazar
337 posts
15 years ago
Max Lazar's avatar Max Lazar
Oh, additionally, is there a way to specify a difference between office and direct line in the vcard template?

What did you mean by direct line? You can setup office_tel, home_tel, cell_tel.

p.s. please try version in attachment

       
Christopher Kennedy's avatar
Christopher Kennedy
44 posts
15 years ago
Christopher Kennedy's avatar Christopher Kennedy

That fixes the Notes section info, but now I’m missing the email1 entry, and I’ve got a vCard like the attached.

For reference’s sake, here’s the code I’m using:

{exp:weblog:entries weblog="attorney" limit="1"}
{exp:vcard3 
display_name = "{title}" 
first_name = "{first_name}" 
last_name = "{last_name}"
title = "{prefix}"
cell_tel = "+1 914 218 94885"    
email1 = "{attorney_email}"
url = "http://www.pattersonsheridan.com"
company = "Patterson & Sheridan, LLP"
title = "{job_title}"
vcard_name = "{url_title}"}
{/exp:weblog:entries}

Are there any new changes to the variables in this version?

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.