dolibarr  9.0.0
vcard.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) Kai Blankenhorn <kaib@bitfolge.de>
3  * Copyright (C) 2005-2017 Laurent Destailleur <eldy@users.sourceforge.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
31 function encode($string)
32 {
33  return str_replace(";","\;",(dol_quoted_printable_encode(utf8_decode($string))));
34 }
35 
36 
45 function dol_quoted_printable_encode($input, $line_max=76)
46 {
47  $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
48  $lines = preg_split("/(\?:\r\n|\r|\n)/", $input);
49  $eol = "\r\n";
50  $linebreak = "=0D=0A";
51  $escape = "=";
52  $output = "";
53 
54  $num = count($lines);
55  for ($j = 0; $j < $num; $j++)
56  {
57  $line = $lines[$j];
58  $linlen = strlen($line);
59  $newline = "";
60  for($i = 0; $i < $linlen; $i++) {
61  $c = substr($line, $i, 1);
62  $dec = ord($c);
63  if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
64  $c = "=20";
65  } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
66  $h2 = floor($dec/16); $h1 = floor($dec%16);
67  $c = $escape.$hex["$h2"].$hex["$h1"];
68  }
69  if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
70  $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
71  $newline = " ";
72  }
73  $newline .= $c;
74  } // end of for
75  $output .= $newline;
76  if ($j<count($lines)-1) $output .= $linebreak;
77  }
78  return trim($output);
79 }
80 
81 
85 class vCard
86 {
87  var $properties;
88  var $filename;
89 
90  //var $encoding="UTF-8";
91  var $encoding="ISO-8859-1;ENCODING=QUOTED-PRINTABLE";
92 
93 
101  function setPhoneNumber($number, $type="")
102  {
103  // 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"
104  $key = "TEL";
105  if ($type!="") $key .= ";".$type;
106  $key.= ";CHARSET=".$this->encoding;
107  $this->properties[$key] = encode($number);
108  }
109 
118  function setPhoto($type, $photo)
119  {
120  // $type = "GIF" | "JPEG"
121  $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
122  }
123 
130  function setFormattedName($name)
131  {
132  $this->properties["FN;CHARSET=".$this->encoding] = encode($name);
133  }
134 
145  function setName($family="", $first="", $additional="", $prefix="", $suffix="")
146  {
147  $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
148  $this->filename = "$first%20$family.vcf";
149  if (empty($this->properties["FN"])) $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
150  }
151 
158  function setBirthday($date)
159  {
160  // $date format is YYYY-MM-DD - RFC 2425 and RFC 2426
161  $this->properties["BDAY"] = dol_print_date($date, 'dayrfc');
162  }
163 
177  function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
178  {
179  // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
180  $key = "ADR";
181  if ($type!="") $key.= ";$type";
182  $key.= ";CHARSET=".$this->encoding;
183  $this->properties[$key] = ";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
184 
185  if ($this->properties["LABEL;$type;CHARSET=".$this->encoding] == "")
186  {
187  //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
188  }
189  }
190 
204  function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
205  {
206  $label = "";
207  if ($postoffice!="") $label.= "$postoffice\r\n";
208  if ($extended!="") $label.= "$extended\r\n";
209  if ($street!="") $label.= "$street\r\n";
210  if ($zip!="") $label.= "$zip ";
211  if ($city!="") $label.= "$city\r\n";
212  if ($region!="") $label.= "$region\r\n";
213  if ($country!="") $country.= "$country\r\n";
214 
215  $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label);
216  }
217 
225  function setEmail($address,$type="internet,pref")
226  {
227  $this->properties["EMAIL;TYPE=".$type] = $address;
228  }
229 
236  function setNote($note)
237  {
238  $this->properties["NOTE;CHARSET=".$this->encoding] = encode($note);
239  }
240 
247  function setTitle($title)
248  {
249  $this->properties["TITLE;CHARSET=".$this->encoding] = encode($title);
250  }
251 
252 
259  function setOrg($org)
260  {
261  $this->properties["ORG;CHARSET=".$this->encoding] = encode($org);
262  }
263 
264 
271  function setProdId($prodid)
272  {
273  $this->properties["PRODID;CHARSET=".$this->encoding] = encode($prodid);
274  }
275 
276 
283  function setUID($uid)
284  {
285  $this->properties["UID;CHARSET=".$this->encoding] = encode($uid);
286  }
287 
288 
296  function setURL($url, $type="")
297  {
298  // $type may be WORK | HOME
299  $key = "URL";
300  if ($type!="") $key.= ";$type";
301  $this->properties[$key] = $url;
302  }
303 
309  function getVCard()
310  {
311  $text = "BEGIN:VCARD\r\n";
312  //$text.= "VERSION:3.0\r\n";
313  $text.= "VERSION:2.1\r\n";
314  foreach($this->properties as $key => $value)
315  {
316  $text.= "$key:$value\r\n";
317  }
318  $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
319  $text.= "MAILER: Dolibarr\r\n";
320  $text.= "END:VCARD\r\n";
321  return $text;
322  }
323 
329  function getFileName()
330  {
331  return $this->filename;
332  }
333 }
setBirthday($date)
mise en forme de l&#39;anniversaire
dol_quoted_printable_encode($input, $line_max=76)
Taken from php documentation comments No more used.
Definition: vcard.class.php:45
setName($family="", $first="", $additional="", $prefix="", $suffix="")
mise en forme du nom complet
setOrg($org)
mise en forme de la societe
encode($string)
Encode a string for vCard.
Definition: vcard.class.php:31
setPhoto($type, $photo)
mise en forme de la photo warning NON TESTE !
Class to buld vCard files.
Definition: vcard.class.php:85
setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
mise en forme du label
getVCard()
permet d&#39;obtenir une vcard
setPhoneNumber($number, $type="")
mise en forme du numero de telephone
setURL($url, $type="")
mise en forme de l&#39;url
setProdId($prodid)
mise en forme du logiciel generateur
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getFileName()
permet d&#39;obtenir le nom de fichier
setTitle($title)
mise en forme de la fonction
setUID($uid)
mise en forme du logiciel generateur
setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
mise en forme de l&#39;adresse
setFormattedName($name)
mise en forme du nom formate
setNote($note)
mise en forme de la note
setEmail($address, $type="internet,pref")
mise en forme de l&#39;email