37 return str_replace(array(
"\\",
";",
",",
"\r\n",
"\r",
"\n"), array(
"\\\\",
"\\;",
"\\,",
"\\n",
"\\n",
"\\n"), (
string) $string);
51 $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
52 $lines = preg_split(
"/(?:\r\n|\r|\n)/", $input);
54 $linebreak =
"=0D=0A";
59 for ($j = 0; $j < $num; $j++) {
61 $linlen = strlen($line);
63 for ($i = 0; $i < $linlen; $i++) {
64 $c = substr($line, $i, 1);
66 if (($dec == 32) && ($i == ($linlen - 1))) {
68 } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) {
69 $h2 = floor($dec / 16);
70 $h1 = floor($dec % 16);
71 $c = $escape.$hex[(int) $h2].$hex[(
int) $h1];
73 if ((strlen($newline) + strlen(
$c)) >= $line_max) {
74 $output .= $newline.$escape.$eol;
80 if ($j < count($lines) - 1) {
81 $output .= $linebreak;
96 public $properties = [];
107 public $encoding =
"CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE";
118 return trim((
string) preg_replace(
'/[\x00-\x1F\x7F]+/',
' ', (
string) $value));
131 foreach (explode(
';', $this->
cleanValue($type)) as $param) {
132 $param = trim($param);
136 if (stripos($param,
'TYPE=') === 0) {
137 $types[] = substr($param, 5);
138 } elseif (strpos($param,
'=') ===
false) {
145 array_unshift($params,
'TYPE='.implode(
',', $types));
147 return implode(
';', $params);
161 if ($number ===
'') {
166 $key .=
";".$this->normalizeType($type);
168 $key .=
";VALUE=uri";
170 $this->properties[$key] =
'tel:'.preg_replace(
'/[\s.()\/]+/',
'', $number);
189 $this->properties[
"PHOTO;MEDIATYPE=$type"] = $photo;
201 if (trim((
string) $name) ===
'') {
204 $this->properties[
"FN"] =
encode($name);
218 public function setName($family =
"", $first =
"", $additional =
"", $prefix =
"", $suffix =
"")
222 $this->filename = trim(
"$first $family").
'.vcf';
224 if (empty($this->properties[
"FN"])) {
225 $this->
setFormattedName(trim((
string) preg_replace(
'/\s+/',
' ',
"$prefix $first $additional $family $suffix")));
256 public function setAddress($postoffice =
"", $extended =
"", $street =
"", $city =
"", $region =
"", $zip =
"", $country =
"", $type =
"", $label =
"")
259 if (trim($postoffice.$extended.$street.$city.$region.$zip.$country) ===
'') {
264 $key .=
";".$this->normalizeType($type);
267 $key .=
';LABEL="'.str_replace(
'"',
"'", $this->
cleanValue($label)).
'"';
287 public function setLabel($postoffice =
"", $extended =
"", $street =
"", $city =
"", $region =
"", $zip =
"", $country =
"", $type =
"HOME")
290 if ($postoffice !=
"") {
291 $label .=
"$postoffice\r\n";
293 if ($extended !=
"") {
294 $label .=
"$extended\r\n";
297 $label .=
"$street\r\n";
303 $label .=
"$city\r\n";
306 $label .=
"$region\r\n";
308 if ($country !=
"") {
309 $label .=
"$country\r\n";
312 $this->properties[
"LABEL;".$this->normalizeType($type)] =
encode($label);
325 if ($address ===
'') {
329 if ($type ===
"PREF") {
331 } elseif (!empty($type)) {
332 if (stripos($type,
'TYPE=') === 0) {
333 $key .=
";".$this->normalizeType($type);
335 $key .=
";TYPE=".dol_strtolower($type);
338 $this->properties[$key] = $address;
349 if (trim((
string) $note) ===
'') {
352 $this->properties[
"NOTE"] =
encode($note);
363 if (trim((
string) $title) ===
'') {
366 $this->properties[
"TITLE"] =
encode($title);
378 if (trim((
string) $org) ===
'') {
381 $this->properties[
"ORG"] =
encode($org);
393 $this->properties[
"PRODID"] =
encode($prodid);
405 $this->properties[
"UID"] =
encode($uid);
425 $key .=
";".$this->normalizeType($type);
427 $this->properties[$key] = $url;
437 $text =
"BEGIN:VCARD\r\n";
438 $text .=
"VERSION:4.0\r\n";
440 foreach ($this->properties as $key => $value) {
442 if (strpos($key,
'SOCIALPROFILE;') === 0) {
443 $newkey = preg_replace(
'/-[A-Za-z0-9_]*$/',
'', $key);
445 $text .= $this->
foldLine($newkey.
":".$value);
447 $text .=
"REV:".dol_print_date(
dol_now(),
'dayhourxcard',
'gmt').
"\r\n";
449 $text .=
"END:VCARD\r\n";
465 while (strlen($line) > $max) {
467 while ($cut > 0 && (ord($line[$cut]) & 0xC0) == 0x80) {
470 $result .= substr($line, 0, $cut).
"\r\n";
471 $line =
' '.substr($line, $cut);
473 return $result.$line.
"\r\n";
484 if ($filename ===
'' || $filename ===
'.vcf') {
485 $filename =
'vcard.vcf';
503 global $dolibarr_main_instance_unique_id;
505 $this->
setProdId(
'Dolibarr '.DOL_VERSION);
507 $this->
setUID(
'DOL-USERID-'.
dol_trunc(md5(
'vcard'.$dolibarr_main_instance_unique_id), 8,
'right',
'UTF-8', 1).
'-'.
$object->id);
514 $this->
setPhoto($mimetype, $urlphoto);
532 if (!empty(
$object->socialnetworks)) {
533 foreach (
$object->socialnetworks as $key => $val) {
538 if ($key ==
'linkedin') {
539 if (!preg_match(
'/^http/', $val)) {
540 $urlsn =
'https://www.'.$key.
'.com/company/'.urlencode($val);
544 } elseif ($key ==
'youtube') {
545 if (!preg_match(
'/^http/', $val)) {
546 $urlsn =
'https://www.'.$key.
'.com/user/'.urlencode($val);
551 if (!preg_match(
'/^http/', $val)) {
552 $urlsn =
'https://www.'.$key.
'.com/'.urlencode($val);
559 $this->properties[
"SOCIALPROFILE;TYPE=WORK-".preg_replace(
'/[^A-Za-z0-9_]/',
'', $key)] = $key.
':'.$urlsn;
567 $addressalreadyset = 0;
571 $addressalreadyset = 1;
595 if (is_object($company)) {
597 if ($company->typent_code !=
'TE_PRIVATE') {
598 $this->
setOrg($company->name);
601 if (!empty($company->url)) {
602 $this->
setURL($company->url,
"");
605 if ($company->phone && empty(
$object->office_phone)) {
608 if ($company->fax && empty(
$object->office_fax)) {
611 if (($company->address || $company->town || $company->state || $company->zip || $company->country) && !$addressalreadyset) {
612 $this->
setAddress(
"",
"", $company->address, $company->town, $company->state, $company->zip, $company->country,
"TYPE=WORK");
615 if ($company->email && empty(
$object->email)) {
616 $this->
setEmail($company->email,
"TYPE=WORK");
658 $outfilename = $outdir.
'/virtualcard_'.
$object->element.
'_'.
$object->id.
'.vcf';
660 file_put_contents($outfilename, $this->
getVCard());
if(! $sortfield) if(! $sortorder) $object
Class to build vCard files.
setEmail($address, $type="")
Add a e-mail address to this vCard.
setTitle($title)
mise en forme de la fonction
setPhoneNumber($number, $type="")
Format phone number.
setPhoto($type, $photo)
Format photo.
setBirthday($date)
Format the birth date.
setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME")
Address (old standard)
foldLine($line)
Return a line of the card folded as RFC 6350 section 3.2 asks: no more than 75 octets,...
cleanValue($value)
Remove the line breaks and control characters of a value written as is, so it can not add a property ...
setUID($uid)
mise en forme du logiciel generateur
getFileName()
Return name of a file, safe to use in a HTTP header and as a file name (no accent,...
normalizeType($type)
Return the parameters of a type in the vCard 4.0 form: "TYPE=WORK;VOICE" (old form,...
setOrg($org)
mise en forme de la societe
buildVCardString($object, $company, $langs, $urlphoto='', $outdir='')
Return a VCARD string See RFC https://datatracker.ietf.org/doc/html/rfc6350.
setProdId($prodid)
mise en forme du logiciel generateur
setFormattedName($name)
Format name.
setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="", $label="")
Address.
setName($family="", $first="", $additional="", $prefix="", $suffix="")
Format the name.
getVCard()
Return string of a vcard.
setNote($note)
mise en forme de la note
setURL($url, $type="")
mise en forme de l'url
dol_now($mode='gmt')
Return date for now.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
encode($string)
Escape a text value for a vCard 4.0 (RFC 6350 section 3.4): backslash, semicolon, comma and line brea...
dol_quoted_printable_encode($input, $line_max=76)
Taken from php documentation comments No more used.