Page principale | Liste alphabétique | Liste des classes | Liste des fichiers | Membres de classe | Membres de fichier

htdocs/lib/vcard/vcard.class.php

Aller à la documentation de ce fichier.
00001 <?PHP 00002 /*************************************************************************** 00003 00004 PHP vCard class v2.0 00005 (c) Kai Blankenhorn 00006 www.bitfolge.de/en 00007 kaib@bitfolge.de 00008 00009 00010 This program is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU General Public License 00012 as published by the Free Software Foundation; either version 2 00013 of the License, or (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 00024 ***************************************************************************/ 00025 00035 function encode($string) { 00036 return escape(quoted_printable_encode($string)); 00037 } 00038 00039 function escape($string) { 00040 return str_replace(";","\;",$string); 00041 } 00042 00043 // taken from PHP documentation comments 00044 function quoted_printable_encode($input, $line_max = 76) { 00045 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 00046 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 00047 $eol = "\r\n"; 00048 $linebreak = "=0D=0A"; 00049 $escape = "="; 00050 $output = ""; 00051 00052 for ($j=0;$j<count($lines);$j++) { 00053 $line = $lines[$j]; 00054 $linlen = strlen($line); 00055 $newline = ""; 00056 for($i = 0; $i < $linlen; $i++) { 00057 $c = substr($line, $i, 1); 00058 $dec = ord($c); 00059 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only 00060 $c = "=20"; 00061 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 00062 $h2 = floor($dec/16); $h1 = floor($dec%16); 00063 $c = $escape.$hex["$h2"].$hex["$h1"]; 00064 } 00065 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 00066 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 00067 $newline = " "; 00068 } 00069 $newline .= $c; 00070 } // end of for 00071 $output .= $newline; 00072 if ($j<count($lines)-1) $output .= $linebreak; 00073 } 00074 return trim($output); 00075 } 00076 00083 class vCard { 00084 var $properties; 00085 var $filename; 00086 00093 function setPhoneNumber($number, $type="") { 00094 // 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" 00095 $key = "TEL"; 00096 if ($type!="") $key .= ";".$type; 00097 $key.= ";ENCODING=QUOTED-PRINTABLE"; 00098 $this->properties[$key] = quoted_printable_encode($number); 00099 } 00100 00108 // UNTESTED !!! 00109 function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" 00110 $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); 00111 } 00112 00118 function setFormattedName($name) { 00119 $this->properties["FN"] = quoted_printable_encode($name); 00120 } 00121 00131 function setName($family="", $first="", $additional="", $prefix="", $suffix="") { 00132 $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix"; 00133 $this->filename = "$first%20$family.vcf"; 00134 if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); 00135 } 00136 00142 function setBirthday($date) { // $date format is YYYY-MM-DD 00143 $this->properties["BDAY"] = $date; 00144 } 00145 00158 function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { 00159 // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" 00160 $key = "ADR"; 00161 if ($type!="") $key.= ";$type"; 00162 $key.= ";ENCODING=QUOTED-PRINTABLE"; 00163 $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); 00164 00165 if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") { 00166 //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); 00167 } 00168 } 00169 00182 function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { 00183 $label = ""; 00184 if ($postoffice!="") $label.= "$postoffice\r\n"; 00185 if ($extended!="") $label.= "$extended\r\n"; 00186 if ($street!="") $label.= "$street\r\n"; 00187 if ($zip!="") $label.= "$zip "; 00188 if ($city!="") $label.= "$city\r\n"; 00189 if ($region!="") $label.= "$region\r\n"; 00190 if ($country!="") $country.= "$country\r\n"; 00191 00192 $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label); 00193 } 00194 00200 function setEmail($address) { 00201 $this->properties["EMAIL;INTERNET"] = $address; 00202 } 00203 00209 function setNote($note) { 00210 $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note); 00211 } 00212 00219 function setURL($url, $type="") { 00220 // $type may be WORK | HOME 00221 $key = "URL"; 00222 if ($type!="") $key.= ";$type"; 00223 $this->properties[$key] = $url; 00224 } 00225 00230 function getVCard() { 00231 $text = "BEGIN:VCARD\r\n"; 00232 $text.= "VERSION:2.1\r\n"; 00233 foreach($this->properties as $key => $value) { 00234 $text.= "$key:$value\r\n"; 00235 } 00236 $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n"; 00237 $text.= "MAILER:PHP vCard class by Kai Blankenhorn\r\n"; 00238 $text.= "END:VCARD\r\n"; 00239 return $text; 00240 } 00241 00246 function getFileName() { 00247 return $this->filename; 00248 } 00249 } 00250 ?>

Généré le Fri Jul 16 08:51:52 2004 pour dolibarr par doxygen 1.3.7