48 $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
49 $lines = preg_split(
"/(\?:\r\n|\r|\n)/", $input);
51 $linebreak =
"=0D=0A";
56 for ($j = 0; $j < $num; $j++) {
58 $linlen = strlen($line);
60 for ($i = 0; $i < $linlen; $i++) {
61 $c = substr($line, $i, 1);
63 if (($dec == 32) && ($i == ($linlen - 1))) {
65 } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) {
66 $h2 = floor($dec / 16);
67 $h1 = floor($dec % 16);
68 $c = $escape.$hex[
"$h2"].$hex[
"$h1"];
70 if ((strlen($newline) + strlen($c)) >= $line_max) {
71 $output .= $newline.$escape.$eol;
77 if ($j < count($lines) - 1) {
78 $output .= $linebreak;
103 public $encoding =
"ENCODING=QUOTED-PRINTABLE";
120 $key .=
";VALUE=uri";
122 $this->properties[$key] =
'tel:'.$number;
137 $this->properties[
"PHOTO;MEDIATYPE=$type"] = $photo;
149 $this->properties[
"FN;".$this->encoding] =
encode($name);
162 public function setName($family =
"", $first =
"", $additional =
"", $prefix =
"", $suffix =
"")
166 $this->filename =
"$first%20$family.vcf";
167 if (empty($this->properties[
"FN"])) {
168 $this->
setFormattedName(trim(
"$prefix $first $additional $family $suffix"));
199 public function setAddress($postoffice =
"", $extended =
"", $street =
"", $city =
"", $region =
"", $zip =
"", $country =
"", $type =
"", $label =
"")
207 $key .=
';LABEL="'.encode($label).
'"';
209 $key .=
";".$this->encoding;
231 public function setLabel($postoffice =
"", $extended =
"", $street =
"", $city =
"", $region =
"", $zip =
"", $country =
"", $type =
"HOME")
234 if ($postoffice !=
"") {
235 $label .=
"$postoffice\r\n";
237 if ($extended !=
"") {
238 $label .=
"$extended\r\n";
241 $label .=
"$street\r\n";
247 $label .=
"$city\r\n";
250 $label .=
"$region\r\n";
252 if ($country !=
"") {
253 $country .=
"$country\r\n";
256 $this->properties[
"LABEL;$type;".$this->encoding] =
encode($label);
272 $this->properties[$key] = $address;
283 $this->properties[
"NOTE;".$this->encoding] =
encode($note);
294 $this->properties[
"TITLE;".$this->encoding] =
encode($title);
306 $this->properties[
"ORG;".$this->encoding] =
encode($org);
318 $this->properties[
"PRODID"] =
encode($prodid);
330 $this->properties[
"UID"] =
encode($uid);
348 $this->properties[$key] = $url;
358 $text =
"BEGIN:VCARD\r\n";
359 $text .=
"VERSION:4.0\r\n";
361 foreach ($this->properties as $key => $value) {
362 $newkey = preg_replace(
'/-.*$/',
'', $key);
363 $text .= $newkey.
":".$value.
"\r\n";
365 $text .=
"REV:".date(
"Ymd").
"T".date(
"His").
"Z\r\n";
367 $text .=
"END:VCARD\r\n";
378 return $this->filename;
393 global $dolibarr_main_instance_unique_id;
395 $this->
setProdId(
'Dolibarr '.DOL_VERSION);
397 $this->setUid(
'DOLIBARR-USERID-'.
dol_trunc(md5(
'vcard'.$dolibarr_main_instance_unique_id), 8,
'right',
'UTF-8', 1).
'-'.$object->id);
398 $this->
setName($object->lastname, $object->firstname,
"", $object->civility_code,
"");
404 $this->
setPhoto($mimetype, $urlphoto);
408 if ($object->office_phone) {
415 if ($object->user_mobile) {
418 if ($object->office_fax) {
422 if (!empty($object->socialnetworks)) {
423 foreach ($object->socialnetworks as $key => $val) {
425 if ($key ==
'linkedin') {
426 if (!preg_match(
'/^http/', $val)) {
427 $urlsn =
'https://www.'.$key.
'.com/company/'.urlencode($val);
431 } elseif ($key ==
'youtube') {
432 if (!preg_match(
'/^http/', $val)) {
433 $urlsn =
'https://www.'.$key.
'.com/user/'.urlencode($val);
438 if (!preg_match(
'/^http/', $val)) {
439 $urlsn =
'https://www.'.$key.
'.com/'.urlencode($val);
445 $this->properties[
"SOCIALPROFILE;TYPE=WORK-".$key] = $key.
':'.$urlsn;
450 $country = $object->country_code ? $object->country :
'';
452 if ($object->address || $object->town || $object->state || $object->zip || $object->country) {
453 $this->
setAddress(
"",
"", $object->address, $object->town, $object->state, $object->zip, $country,
"");
457 if ($object->email) {
458 $this->
setEmail($object->email,
"TYPE=WORK");
464 if ($object->note_public) {
465 $this->
setNote($object->note_public);
473 if (!empty($object->url)) {
474 $this->
setURL($object->url,
"");
477 if (is_object($company)) {
479 if ($company->typent_code !=
'TE_PRIVATE') {
480 $this->
setOrg($company->name);
483 $this->
setURL($company->url,
"");
485 if ($company->phone && $company->phone != $object->office_phone) {
488 if ($company->fax && $company->fax != $object->office_fax) {
491 if ($company->address || $company->town || $company->state || $company->zip || $company->country) {
492 $this->
setAddress(
"",
"", $company->address, $company->town, $company->state, $company->zip, $company->country,
"TYPE=WORK");
495 if ($company->email && $company->email != $object->email) {
496 $this->
setEmail($company->email,
"TYPE=WORK");
531 if ($object->birth) {