[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: vcard.class.php 734 2005-10-31 02:53:15Z stingrey $ 4 * Modified PHP vCard class v2.0 5 */ 6 7 /*************************************************************************** 8 PHP vCard class v2.0 9 (cKai Blankenhorn 10 www.bitfolge.de/en 11 kaib@bitfolge.de 12 13 This program is free software; you can redistribute it and/or 14 modify it under the terms of the GNU General Public License 15 as published by the Free Software Foundation; either version 2 16 of the License, or (at your option) any later version. 17 18 This program is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details. 22 23 You should have received a copy of the GNU General Public License 24 along with this program; if not, write to the Free Software 25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 26 ***************************************************************************/ 27 28 function encode($string) { 29 return escape(quoted_printable_encode($string)); 30 } 31 32 function escape($string) { 33 return str_replace(';',"\;",$string); 34 } 35 36 // taken from PHP documentation comments 37 function quoted_printable_encode($input, $line_max = 76) { 38 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); 39 $lines = preg_split("/(?:\r\n|\r|\n)/", $input); 40 $eol = "\r\n"; 41 $linebreak = '=0D=0A'; 42 $escape = '='; 43 $output = ''; 44 45 for ($j=0;$j<count($lines);$j++) { 46 $line = $lines[$j]; 47 $linlen = strlen($line); 48 $newline = ''; 49 50 for($i = 0; $i < $linlen; $i++) { 51 $c = substr($line, $i, 1); 52 $dec = ord($c); 53 54 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only 55 $c = '=20'; 56 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required 57 $h2 = floor($dec/16); 58 $h1 = floor($dec%16); 59 $c = $escape.$hex["$h2"] . $hex["$h1"]; 60 } 61 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted 62 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay 63 $newline = " "; 64 } 65 $newline .= $c; 66 } // end of for 67 $output .= $newline; 68 if ($j<count($lines)-1) { 69 $output .= $linebreak; 70 } 71 } 72 73 return trim($output); 74 } 75 76 class vCard { 77 var $properties; 78 var $filename; 79 80 function setPhoneNumber($number, $type='') { 81 // 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" 82 $key = 'TEL'; 83 if ($type!='') { 84 $key .= ';'. $type; 85 } 86 $key.= ';ENCODING=QUOTED-PRINTABLE'; 87 88 $this->properties[$key] = quoted_printable_encode($number); 89 } 90 91 // UNTESTED !!! 92 function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" 93 $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); 94 } 95 96 function setFormattedName($name) { 97 $this->properties['FN'] = quoted_printable_encode($name); 98 } 99 100 function setName($family='', $first='', $additional='', $prefix='', $suffix='') { 101 $this->properties['N'] = "$family;$first;$additional;$prefix;$suffix"; 102 $this->filename = "$first%20$family.vcf"; 103 if ($this->properties['FN']=='') { 104 $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); 105 } 106 } 107 108 function setBirthday($date) { // $date format is YYYY-MM-DD 109 $this->properties['BDAY'] = $date; 110 } 111 112 function setAddress($postoffice='', $extended='', $street='', $city='', $region='', $zip='', $country='', $type='HOME;POSTAL') { 113 // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" 114 $key = 'ADR'; 115 if ($type!='') { 116 $key.= ";$type"; 117 } 118 119 $key.= ';ENCODING=QUOTED-PRINTABLE'; 120 $this->properties[$key] = encode($name).';'.encode($extended).';'.encode($street).';'.encode($city).';'.encode($region).';'.encode($zip).';'.encode($country); 121 122 if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == '') { 123 //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); 124 } 125 } 126 127 function setLabel($postoffice='', $extended='', $street='', $city='', $region='', $zip='', $country='', $type='HOME;POSTAL') { 128 $label = ''; 129 if ($postoffice!='') { 130 $label.= $postoffice; 131 $label.= "\r\n"; 132 } 133 134 if ($extended!='') { 135 $label.= $extended; 136 $label.= "\r\n"; 137 } 138 139 if ($street!='') { 140 $label.= $street; 141 $label.= "\r\n"; 142 } 143 144 if ($zip!='') { 145 $label.= $zip .' '; 146 } 147 148 if ($city!='') { 149 $label.= $city; 150 $label.= "\r\n"; 151 } 152 153 if ($region!='') { 154 $label.= $region; 155 $label.= "\r\n"; 156 } 157 158 if ($country!='') { 159 $country.= $country; 160 $label.= "\r\n"; 161 } 162 163 $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label); 164 } 165 166 function setEmail($address) { 167 $this->properties['EMAIL;INTERNET'] = $address; 168 } 169 170 function setNote($note) { 171 $this->properties['NOTE;ENCODING=QUOTED-PRINTABLE'] = quoted_printable_encode($note); 172 } 173 174 function setURL($url, $type='') { 175 // $type may be WORK | HOME 176 $key = 'URL'; 177 if ($type!='') { 178 $key.= ";$type"; 179 } 180 181 $this->properties[$key] = $url; 182 } 183 184 function getVCard() { 185 $text = 'BEGIN:VCARD'; 186 $text.= "\r\n"; 187 $text.= 'VERSION:2.1'; 188 $text.= "\r\n"; 189 190 foreach($this->properties as $key => $value) { 191 $text.= "$key:$value\r\n"; 192 } 193 194 $text.= 'REV:'. date('Y-m-d') .'T'. date('H:i:s') .'Z'; 195 $text.= "\r\n"; 196 $text.= 'MAILER:PHP vCard class by Kai Blankenhorn'; 197 $text.= "\r\n"; 198 $text.= 'END:VCARD'; 199 $text.= "\r\n"; 200 201 return $text; 202 } 203 204 function getFileName() { 205 return $this->filename; 206 } 207 } 208 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |