dolibarr  7.0.0-beta
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  { // $type = "GIF" | "JPEG"
120  $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
121  }
122 
129  function setFormattedName($name)
130  {
131  $this->properties["FN;CHARSET=".$this->encoding] = encode($name);
132  }
133 
144  function setName($family="", $first="", $additional="", $prefix="", $suffix="")
145  {
146  $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix);
147  $this->filename = "$first%20$family.vcf";
148  if (empty($this->properties["FN"])) $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
149  }
150 
157  function setBirthday($date)
158  {
159  // $date format is YYYY-MM-DD - RFC 2425 and RFC 2426
160  $this->properties["BDAY"] = dol_print_date($date, 'dayrfc');
161  }
162 
176  function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL")
177  {
178  // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
179  $key = "ADR";
180  if ($type!="") $key.= ";$type";
181  $key.= ";CHARSET=".$this->encoding;
182  $this->properties[$key] = ";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
183 
184  if ($this->properties["LABEL;$type;CHARSET=".$this->encoding] == "")
185  {
186  //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
187  }
188  }
189 
203  function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
204  $label = "";
205  if ($postoffice!="") $label.= "$postoffice\r\n";
206  if ($extended!="") $label.= "$extended\r\n";
207  if ($street!="") $label.= "$street\r\n";
208  if ($zip!="") $label.= "$zip ";
209  if ($city!="") $label.= "$city\r\n";
210  if ($region!="") $label.= "$region\r\n";
211  if ($country!="") $country.= "$country\r\n";
212 
213  $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label);
214  }
215 
223  function setEmail($address,$type="internet,pref")
224  {
225  $this->properties["EMAIL;TYPE=".$type] = $address;
226  }
227 
234  function setNote($note)
235  {
236  $this->properties["NOTE;CHARSET=".$this->encoding] = encode($note);
237  }
238 
245  function setTitle($title)
246  {
247  $this->properties["TITLE;CHARSET=".$this->encoding] = encode($title);
248  }
249 
250 
257  function setOrg($org)
258  {
259  $this->properties["ORG;CHARSET=".$this->encoding] = encode($org);
260  }
261 
262 
269  function setProdId($prodid)
270  {
271  $this->properties["PRODID;CHARSET=".$this->encoding] = encode($prodid);
272  }
273 
274 
281  function setUID($uid)
282  {
283  $this->properties["UID;CHARSET=".$this->encoding] = encode($uid);
284  }
285 
286 
294  function setURL($url, $type="")
295  {
296  // $type may be WORK | HOME
297  $key = "URL";
298  if ($type!="") $key.= ";$type";
299  $this->properties[$key] = $url;
300  }
301 
307  function getVCard()
308  {
309  $text = "BEGIN:VCARD\r\n";
310  //$text.= "VERSION:3.0\r\n";
311  $text.= "VERSION:2.1\r\n";
312  foreach($this->properties as $key => $value)
313  {
314  $text.= "$key:$value\r\n";
315  }
316  $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
317  $text.= "MAILER: Dolibarr\r\n";
318  $text.= "END:VCARD\r\n";
319  return $text;
320  }
321 
327  function getFileName()
328  {
329  return $this->filename;
330  }
331 
332 }
setBirthday($date)
mise en forme de l'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'obtenir une vcard
setPhoneNumber($number, $type="")
mise en forme du numero de telephone
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
setURL($url, $type="")
mise en forme de l'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'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'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'email