3 users online. Create an account or sign in to join them.Users

Search

Has anybody managed to create vCard type files from a datasource?

Never tried, but they're just plain text so you can output these with XSLT to achieve the correct syntax. Try the Content Type Mappings extension if you want to set specific mime-type headers.

This is what my content-type-mappings declarations look like:

###### CONTENT-TYPE-MAPPINGS ######
        'content-type-mappings' => array(
            'xml' => 'text/xml; charset=utf-8',
            'text' => 'text/plain; charset=utf-8',
            'vcf' => 'application/vcf; charset=utf-8',
        ),
        ########

This is my stylesheet:

 <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text" media-type="application/vcf" encoding="utf-8"/>

<xsl:template match="data/contact-details/entry">
    <xsl:text>BEGIN:VCARD&#x0D;&#x0A;</xsl:text>
    <xsl:text>VERSION:3.0&#x0D;&#x0A;</xsl:text>
    <xsl:text>N:</xsl:text><xsl:value-of select="last-name"/><xsl:text>;</xsl:text><xsl:value-of select="first-name"/><xsl:text>;;;&#x0D;&#x0A;</xsl:text>
    <xsl:text>FN:</xsl:text><xsl:value-of select="first-name"/><xsl:text> </xsl:text><xsl:value-of select="last-name"/><xsl:text>&#x0D;&#x0A;</xsl:text>
    <xsl:text>EMAIL;type=INTERNET;type=WORK;type=pref:</xsl:text><xsl:value-of select="email"/><xsl:text>&#x0D;&#x0A;</xsl:text>
    <xsl:text>END:VCARD&#x0D;&#x0A;</xsl:text>
</xsl:template>

</xsl:stylesheet>

and this is the final result

    2011-11-09
        01:31
        2011
        11
        09
        +00:00
        Simplicity
        Contact Details
        http://localhost/simplicity
        http://localhost/simplicity/workspace
        contact-details
        contact-details
        80
        /contact-details/
        /
        http://localhost/simplicity/contact-details/
        5242880
        2.2.4
        ovidiust
        8cdd7ac4fb288aa027917e0f00e1b7f61a0a48b7
        live



        Contact Details
        BEGIN:VCARD
VERSION:3.0
N:Spatacian;Ovidiu;;;
FN:Ovidiu Spatacian
EMAIL;type=INTERNET;type=WORK;type=pref:me@ovidiust.com
END:VCARD

I don't know what I'm doing wrong. Could anyone please help?

Try this...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:output method="text" media-type="application/vcf" encoding="utf-8"/>

    <xsl:template match="/">
        <xsl:apply-templates select="data/contact-details/entry"/>
    </xsl:template>

    <xsl:template match="contact-details/entry">
        <xsl:text>BEGIN:VCARD&#x0D;&#x0A;</xsl:text>
        <xsl:text>VERSION:3.0&#x0D;&#x0A;</xsl:text>
        <xsl:text>N:</xsl:text><xsl:value-of select="last-name"/><xsl:text>;</xsl:text><xsl:value-of select="first-name"/><xsl:text>;;;&#x0D;&#x0A;</xsl:text>
        <xsl:text>FN:</xsl:text><xsl:value-of select="first-name"/><xsl:text> </xsl:text><xsl:value-of select="last-name"/><xsl:text>&#x0D;&#x0A;</xsl:text>
        <xsl:text>EMAIL;type=INTERNET;type=WORK;type=pref:</xsl:text><xsl:value-of select="email"/><xsl:text>&#x0D;&#x0A;</xsl:text>
        <xsl:text>END:VCARD&#x0D;&#x0A;</xsl:text>
    </xsl:template>

</xsl:stylesheet>

Thank you bzerangue. That works.

I've noticed that even with the 'vcf' => 'application/vcf; charset=utf-8' in the config.php the header of the file is still a html type and it doesn't download on iphone instead safari iphone reads it straight into the browser. Is this a bug in symphony?

I have the same problem with .ics files (iCal). The resulting file still has a html header.

A friend of mine managed to create a .vcf file with php that would download on iphone iOS 5. This is the php code. Does anybody know how to get the same result with xsl in Symphony?

<?php
/*$vcf = "BEGIN:VCARD
VERSION:3.0
N:Doe;John;;;
FN:John Doe
EMAIL;type=INTERNET;type=WORK;type=pref:test@example.com
TEL;type=WORK;type=pref:1234567
TEL;type=CELL:7654321
END:VCARD";

//set correct content-type-header
header('Content-type: text/x-vcard; charset=utf-8');
header('Content-Disposition: attachment; filename="contact.vcf"');
echo $vcf;
exit;*/
$ical = "BEGIN:VCALENDAR
CALSCALE:GREGORIAN
X-WR-TIMEZONE;VALUE=TEXT:Europe/Bucharest
METHOD:PUBLISH
PRODID:-//Test Prodid//iCal 1.0//EN
X-WR-CALNAME;VALUE=TEXT:Test Name
VERSION:2.0
BEGIN:VEVENT
SEQUENCE:5
DTSTART;TZID=Europe/Bucharest:20111128T140000
DTSTAMP:20111128T011706Z
SUMMARY:Test Summary
UID:EC9439B1-FF65-11D6-9973-003065F99D04
DTEND;TZID=Europe/Bucharest:Europe/BucharestT150000
BEGIN:VALARM
TRIGGER;VALUE=DURATION:-P1D
ACTION:DISPLAY
DESCRIPTION:Event reminder
END:VALARM
END:VEVENT
END:VCALENDAR";

//set correct content-type-header
header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="calendar.ics"');
echo $ical;
exit;

In order to enforce the download you probably also need to set the Content-Disposition header. I don't know if the Content Type Mappings extension can do that, though.

Is there a way to hard-code it?

I created an event that handles the downloading of private files in the Resources section of our intranet. Access to the directory has been locked down via an .htaccess file, but the files can be downloaded by a logged-in member via the Download File event.

Thank you guys. Eventually I've managed to get the files with the correct headers. Unfortunately Safari refuses to download any .vcf files and open them in Contacts.

The only other option is to display a form only to iphone visitors where they can insert their email address and get the .vcf file sent to their inbox. From there, strangely, they can add it to their Contacts. I know that I can attach a send-email filter to a Symphony event. But how would I attach a file (which is in fact a dynamic Symphony page) to an email message?

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details