Fix: bug #29396 : Export 'éè...' du .vcf mal compris par Outlook.

This commit is contained in:
Laurent Destailleur 2010-04-13 23:30:11 +00:00
parent b33b1c56b8
commit 59c791e826

View File

@ -28,24 +28,26 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
***************************************************************************/ ***************************************************************************/
/** /**
\file htdocs/includes/vcard/vcard.class.php * \file htdocs/includes/vcard/vcard.class.php
\brief Classe permettant de creer un fichier vcard. * \brief Classe permettant de creer un fichier vcard.
\author Kai Blankenhorn. * \author Kai Blankenhorn.
\version 2.0 * \version 2.0
*
Ensemble des fonctions permettant de creer un fichier vcard. * Ensemble des fonctions permettant de creer un fichier vcard.
*/ */
function encode($string) { function encode($string) {
return escape(dol_quoted_printable_encode($string)); //return escape($string);
return escape(dol_quoted_printable_encode(utf8_decode($string)));
} }
function escape($string) { function escape($string) {
return str_replace(";","\;",$string); return str_replace(";","\;",$string);
} }
// taken from php documentation comments /** \brief Taken from php documentation comments
* No more used
*/
function dol_quoted_printable_encode($input, $line_max = 76) { function dol_quoted_printable_encode($input, $line_max = 76) {
$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
$lines = preg_split("/(\?:\r\n|\r|\n)/", $input); $lines = preg_split("/(\?:\r\n|\r|\n)/", $input);
@ -80,18 +82,21 @@ function dol_quoted_printable_encode($input, $line_max = 76) {
} }
/** \class vCard /** \class vCard
\brief Classe permettant de cr<EFBFBD>er un fichier vcard \brief Classe permettant de creer un fichier vcard
Ensemble des fonctions permettant de cr<EFBFBD>er un fichier vcard Ensemble des fonctions permettant de creer un fichier vcard
*/ */
class vCard { class vCard {
var $properties; var $properties;
var $filename; var $filename;
//var $encoding="UTF-8";
var $encoding="ISO-8859-1;ENCODING=QUOTED-PRINTABLE";
/** /**
\brief mise en forme du num<EFBFBD>ro de t<EFBFBD>lephone \brief mise en forme du numero de telephone
\param number num<EFBFBD>ro de t<EFBFBD>l<EFBFBD>phone \param number numero de telephone
\param type \param type
*/ */
@ -99,8 +104,8 @@ class vCard {
// type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE" // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE"
$key = "TEL"; $key = "TEL";
if ($type!="") $key .= ";".$type; if ($type!="") $key .= ";".$type;
$key.= ";ENCODING=QUOTED-PRINTABLE"; $key.= ";CHARSET=".$this->encoding;
$this->properties[$key] = dol_quoted_printable_encode($number); $this->properties[$key] = encode($number);
} }
/** /**
@ -121,7 +126,7 @@ class vCard {
*/ */
function setFormattedName($name) { function setFormattedName($name) {
$this->properties["FN"] = dol_quoted_printable_encode($name); $this->properties["FN;CHARSET=".$this->encoding] = encode($name);
} }
/** /**
@ -134,7 +139,7 @@ class vCard {
*/ */
function setName($family="", $first="", $additional="", $prefix="", $suffix="") { function setName($family="", $first="", $additional="", $prefix="", $suffix="") {
$this->properties["N"] = "$family;$first;$additional;$prefix;$suffix"; $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
$this->filename = "$first%20$family.vcf"; $this->filename = "$first%20$family.vcf";
if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
} }
@ -164,10 +169,10 @@ class vCard {
// $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
$key = "ADR"; $key = "ADR";
if ($type!="") $key.= ";$type"; if ($type!="") $key.= ";$type";
$key.= ";ENCODING=QUOTED-PRINTABLE"; $key.= ";CHARSET=".$this->encoding;
$this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") { if ($this->properties["LABEL;$type;CHARSET=".$this->encoding] == "") {
//$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
} }
} }
@ -194,7 +199,7 @@ class vCard {
if ($region!="") $label.= "$region\r\n"; if ($region!="") $label.= "$region\r\n";
if ($country!="") $country.= "$country\r\n"; if ($country!="") $country.= "$country\r\n";
$this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($label); $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label);
} }
/** /**
@ -212,7 +217,7 @@ class vCard {
*/ */
function setNote($note) { function setNote($note) {
$this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($note); $this->properties["NOTE;CHARSET=".$this->encoding] = encode($note);
} }
/** /**
@ -220,7 +225,7 @@ class vCard {
\param title \param title
*/ */
function setTitle($title) { function setTitle($title) {
$this->properties["TITLE;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($title); $this->properties["TITLE;CHARSET=".$this->encoding] = encode($title);
} }
@ -229,7 +234,7 @@ class vCard {
\param org \param org
*/ */
function setOrg($org) { function setOrg($org) {
$this->properties["ORG;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($org); $this->properties["ORG;CHARSET=".$this->encoding] = encode($org);
} }
@ -238,7 +243,7 @@ class vCard {
\param prodid \param prodid
*/ */
function setProdId($prodid) { function setProdId($prodid) {
$this->properties["PRODID;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($prodid); $this->properties["PRODID;CHARSET=".$this->encoding] = encode($prodid);
} }
@ -247,7 +252,7 @@ class vCard {
\param uid \param uid
*/ */
function setUID($uid) { function setUID($uid) {
$this->properties["UID;ENCODING=QUOTED-PRINTABLE"] = dol_quoted_printable_encode($uid); $this->properties["UID;CHARSET=".$this->encoding] = encode($uid);
} }
@ -269,7 +274,8 @@ class vCard {
function getVCard() { function getVCard() {
$text = "BEGIN:VCARD\r\n"; $text = "BEGIN:VCARD\r\n";
$text.= "VERSION:3.0\r\n"; //$text.= "VERSION:3.0\r\n";
$text.= "VERSION:2.1\r\n";
foreach($this->properties as $key => $value) { foreach($this->properties as $key => $value) {
$text.= "$key:$value\r\n"; $text.= "$key:$value\r\n";
} }