ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilvCard.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
37 define("ADR_TYPE_NONE", 0);
38 define("ADR_TYPE_DOM", 1);
39 define("ADR_TYPE_INTL", 2);
40 define("ADR_TYPE_POSTAL", 4);
41 define("ADR_TYPE_PARCEL", 8);
42 define("ADR_TYPE_HOME", 16);
43 define("ADR_TYPE_WORK", 32);
44 define("ADR_TYPE_PREF", 64);
45 
51 define("TEL_TYPE_NONE", 0);
52 define("TEL_TYPE_HOME", 1);
53 define("TEL_TYPE_MSG", 2);
54 define("TEL_TYPE_WORK", 4);
55 define("TEL_TYPE_PREF", 8);
56 define("TEL_TYPE_VOICE", 16);
57 define("TEL_TYPE_FAX", 32);
58 define("TEL_TYPE_CELL", 64);
59 define("TEL_TYPE_VIDEO", 128);
60 define("TEL_TYPE_PAGER", 256);
61 define("TEL_TYPE_BBS", 512);
62 define("TEL_TYPE_MODEM", 1024);
63 define("TEL_TYPE_CAR", 2048);
64 define("TEL_TYPE_ISDN", 4096);
65 define("TEL_TYPE_PCS", 8192);
66 
72 define("EMAIL_TYPE_NONE", 0);
73 define("EMAIL_TYPE_INTERNET", 1);
74 define("EMAIL_TYPE_x400", 2);
75 define("EMAIL_TYPE_PREF", 4);
76 
77 class ilvCard
78 {
84  public $types;
85 
91  public $filename;
92 
98  public function __construct($version = "3.0")
99  {
100  $this->types = array(
101  "FN" => "",
102  "N" => "",
103  "NICKNAME" => "",
104  "PHOTO" => array(),
105  "BDAY" => "",
106  "ADR" => array(),
107  "LABEL" => array(),
108  "TEL" => array(),
109  "EMAIL" => array(),
110  "MAILER" => "",
111  "TZ" => "",
112  "GEO" => "",
113  "TITLE" => "",
114  "ROLE" => "",
115  "LOGO" => array(),
116  "AGENT" => "",
117  "ORG" => "",
118  "CATEGORIES" => "",
119  "NOTE" => "",
120  "PRODID" => "",
121  "REV" => "",
122  "SORT-STRING" => "",
123  "SOUND" => array(),
124  "UID" => "",
125  "URL" => "",
126  "VERSION" => "3.0",
127  "CLASS" => "",
128  "KEY" => array()
129  );
130  $this->types["VERSION"] = $version;
131  }
132 
142  public function encode($string)
143  {
144  return escape(quoted_printable_encode($string));
145  }
146 
157  public function fold($string = "", $length = 75)
158  {
159  $folded_string = "";
160  preg_match_all("/(.{1,74})/", $string, $matches);
161  for ($i = 0; $i < count($matches[1]); $i++) {
162  if ($i < (count($matches[1]) - 1)) {
163  $matches[1][$i] .= "\n";
164  }
165  if ($i > 0) {
166  $matches[1][$i] = " " . $matches[1][$i];
167  }
168  $folded_string .= $matches[1][$i];
169  }
170  return $folded_string;
171  }
172 
182  public function escape($string)
183  {
184  $string = preg_replace("/(?<!\\\\)(\\\\)([^;,n\\\\])/", "\${1}\${1}\${2}", $string);
185  $string = preg_replace("/(?<!\\\\);/", "\\;", $string);
186  $string = preg_replace("/(?<!\\\\),/", "\\,", $string);
187  $string = preg_replace("/\n/", "\\n", $string);
188  return $string;
189  }
190 
201  public function &explodeVar($variable, $separator = ",")
202  {
203  $exploded = explode($separator, $variable);
204  foreach ($exploded as $index => $var) {
205  $exploded[$index] = $this->escape($var);
206  }
207  return $exploded;
208  }
209 
218  public function buildVCard()
219  {
220  $vcard = "BEGIN:VCARD\n";
221  $vcard .= "VERSION:" . $this->types["VERSION"] . "\n";
222  foreach ($this->types as $type => $var) {
223  ilLoggerFactory::getLogger('user')->debug(print_r($this->types, true));
224 
225  switch ($type) {
226  case "FN":
227  if (strcmp($this->types["FN"], "") != 0) {
228  $fn = $this->fold("FN:" . $this->types["FN"]) . "\n";
229  } else {
230  $fn = "";
231  }
232  break;
233  case "N":
234  if (strcmp($this->types["N"], "") != 0) {
235  $n = $this->fold("N:" . $this->types["N"]) . "\n";
236  } else {
237  $n = "";
238  }
239  break;
240  case "NICKNAME":
241  if (strcmp($this->types["NICKNAME"], "") != 0) {
242  $nickname = $this->fold("NICKNAME:" . $this->types["NICKNAME"]) . "\n";
243  } else {
244  $nickname = "";
245  }
246  break;
247  case "PHOTO":
248  $photo = "";
249  if (is_array($this->types["PHOTO"])) {
250  if (strcmp($this->types["PHOTO"]["VALUE"], "") != 0) {
251  $photo = $this->fold("PHOTO;VALUE=uri:" . $this->types["PHOTO"]["VALUE"]) . "\n";
252  } elseif (strcmp($this->types["PHOTO"]["ENCODING"], "") != 0) {
253  $photo = "PHOTO;ENCODING=" . $this->types["PHOTO"]["ENCODING"];
254  if (strcmp($this->types["PHOTO"]["TYPE"], "") != 0) {
255  $photo .= ";TYPE=" . $this->types["PHOTO"]["TYPE"];
256  }
257  $photo .= ":" . $this->types["PHOTO"]["PHOTO"];
258  $photo = $this->fold($photo) . "\n";
259  }
260  }
261  break;
262  case "BDAY":
263  if (strcmp($this->types["BDAY"], "") != 0) {
264  $bday = $this->fold("BDAY:" . $this->types["BDAY"]) . "\n";
265  } else {
266  $bday = "";
267  }
268  break;
269  case "ADR":
270  if (count($this->types["ADR"])) {
271  $addresses = "";
272  foreach ($this->types["ADR"] as $key => $address) {
273  $test = "";
274  foreach ($address as $str) {
275  $test .= $str;
276  }
277  if (strcmp($test, "") != 0) {
278  $adr = "ADR";
279  $adr_types = array();
280  if ($address["TYPE"] > 0) {
281  if (($address["TYPE"] & ADR_TYPE_DOM) > 0) {
282  array_push($adr_types, "dom");
283  }
284  if (($address["TYPE"] & ADR_TYPE_INTL) > 0) {
285  array_push($adr_types, "intl");
286  }
287  if (($address["TYPE"] & ADR_TYPE_POSTAL) > 0) {
288  array_push($adr_types, "postal");
289  }
290  if (($address["TYPE"] & ADR_TYPE_PARCEL) > 0) {
291  array_push($adr_types, "parcel");
292  }
293  if (($address["TYPE"] & ADR_TYPE_HOME) > 0) {
294  array_push($adr_types, "home");
295  }
296  if (($address["TYPE"] & ADR_TYPE_WORK) > 0) {
297  array_push($adr_types, "work");
298  }
299  if (($address["TYPE"] & ADR_TYPE_PREF) > 0) {
300  array_push($adr_types, "pref");
301  }
302  $adr .= ";TYPE=" . join(",", $adr_types);
303  }
304  $adr .= ":" . $address["POBOX"] . ";" . $address["EXTENDED_ADDRESS"] .
305  ";" . $address["STREET_ADDRESS"] . ";" . $address["LOCALITY"] .
306  ";" . $address["REGION"] . ";" . $address["POSTAL_CODE"] .
307  ";" . $address["COUNTRY"];
308  $adr = $this->fold($adr) . "\n";
309  $addresses .= $adr;
310  }
311  }
312  $adr = $addresses;
313  } else {
314  $adr = "";
315  }
316  break;
317  case "LABEL":
318  $label = "";
319  if (is_array($this->types["LABEL"])) {
320  if (strcmp($this->types["LABEL"]["LABEL"], "") != 0) {
321  $label = "LABEL";
322  $adr_types = array();
323  if ($this->types["LABEL"]["TYPE"] > 0) {
324  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_DOM) > 0) {
325  array_push($adr_types, "dom");
326  }
327  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_INTL) > 0) {
328  array_push($adr_types, "intl");
329  }
330  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_POSTAL) > 0) {
331  array_push($adr_types, "postal");
332  }
333  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PARCEL) > 0) {
334  array_push($adr_types, "parcel");
335  }
336  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_HOME) > 0) {
337  array_push($adr_types, "home");
338  }
339  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_WORK) > 0) {
340  array_push($adr_types, "work");
341  }
342  if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PREF) > 0) {
343  array_push($adr_types, "pref");
344  }
345  $label .= ";TYPE=" . join(",", $adr_types);
346  }
347  $label .= ":" . $this->types["LABEL"]["LABEL"];
348  $label = $this->fold($label) . "\n";
349  }
350  }
351  break;
352  case "TEL":
353  if (count($this->types["TEL"])) {
354  $phonenumbers = "";
355  foreach ($this->types["TEL"] as $key => $phone) {
356  if (strcmp($phone["TEL"], "") != 0) {
357  $tel = "TEL";
358  $tel_types = array();
359  if ($phone["TYPE"] > 0) {
360  if (($phone["TYPE"] & TEL_TYPE_HOME) > 0) {
361  array_push($tel_types, "home");
362  }
363  if (($phone["TYPE"] & TEL_TYPE_MSG) > 0) {
364  array_push($tel_types, "msg");
365  }
366  if (($phone["TYPE"] & TEL_TYPE_WORK) > 0) {
367  array_push($tel_types, "work");
368  }
369  if (($phone["TYPE"] & TEL_TYPE_PREF) > 0) {
370  array_push($tel_types, "pref");
371  }
372  if (($phone["TYPE"] & TEL_TYPE_VOICE) > 0) {
373  array_push($tel_types, "voice");
374  }
375  if (($phone["TYPE"] & TEL_TYPE_FAX) > 0) {
376  array_push($tel_types, "fax");
377  }
378  if (($phone["TYPE"] & TEL_TYPE_CELL) > 0) {
379  array_push($tel_types, "cell");
380  }
381  if (($phone["TYPE"] & TEL_TYPE_VIDEO) > 0) {
382  array_push($tel_types, "video");
383  }
384  if (($phone["TYPE"] & TEL_TYPE_PAGER) > 0) {
385  array_push($tel_types, "pager");
386  }
387  if (($phone["TYPE"] & TEL_TYPE_BBS) > 0) {
388  array_push($tel_types, "bbs");
389  }
390  if (($phone["TYPE"] & TEL_TYPE_MODEM) > 0) {
391  array_push($tel_types, "modem");
392  }
393  if (($phone["TYPE"] & TEL_TYPE_CAR) > 0) {
394  array_push($tel_types, "car");
395  }
396  if (($phone["TYPE"] & TEL_TYPE_ISDN) > 0) {
397  array_push($tel_types, "isdn");
398  }
399  if (($phone["TYPE"] & TEL_TYPE_PCS) > 0) {
400  array_push($tel_types, "pcs");
401  }
402  $tel .= ";TYPE=" . join(",", $tel_types);
403  }
404  $tel .= ":" . $phone["TEL"];
405  $tel = $this->fold($tel) . "\n";
406  $phonenumbers .= $tel;
407  }
408  }
409  $tel = $phonenumbers;
410  } else {
411  $tel = "";
412  }
413  break;
414  case "EMAIL":
415  if (count($this->types["EMAIL"])) {
416  $emails = "";
417  foreach ($this->types["EMAIL"] as $key => $mail) {
418  if (strcmp($mail["EMAIL"], "") != 0) {
419  $email = "EMAIL";
420  $adr_types = array();
421  if ($mail["TYPE"] > 0) {
422  if (($mail["TYPE"] & EMAIL_TYPE_INTERNET) > 0) {
423  array_push($adr_types, "internet");
424  }
425  if (($mail["TYPE"] & EMAIL_TYPE_x400) > 0) {
426  array_push($adr_types, "x400");
427  }
428  if (($mail["TYPE"] & EMAIL_TYPE_PREF) > 0) {
429  array_push($adr_types, "pref");
430  }
431  $email .= ";TYPE=" . join(",", $adr_types);
432  }
433  $email .= ":" . $mail["EMAIL"];
434  $email = $this->fold($email) . "\n";
435  $emails .= $email;
436  }
437  }
438  $email = $emails;
439  } else {
440  $email = "";
441  }
442  break;
443  case "MAILER":
444  if (strcmp($this->types["MAILER"], "") != 0) {
445  $mailer = $this->fold("MAILER:" . $this->types["MAILER"]) . "\n";
446  } else {
447  $mailer = "";
448  }
449  break;
450  case "TZ":
451  if (strcmp($this->types["TZ"], "") != 0) {
452  $tz = $this->fold("TZ:" . $this->types["TZ"]) . "\n";
453  } else {
454  $tz = "";
455  }
456  break;
457  case "GEO":
458  if (is_array($this->types["GEO"]) and
459  (strcmp($this->types["GEO"]["LAT"], "") != 0) and
460  (strcmp($this->types["GEO"]["LON"], "") != 0)) {
461  $geo = $this->fold("GEO:" . $this->types["GEO"]["LAT"] . ";" . $this->types["GEO"]["LON"]) . "\n";
462  } else {
463  $geo = "";
464  }
465  break;
466  case "TITLE":
467  if (strcmp($this->types["TITLE"], "") != 0) {
468  $title = $this->fold("TITLE:" . $this->types["TITLE"]) . "\n";
469  } else {
470  $title = "";
471  }
472  break;
473  case "ROLE":
474  if (strcmp($this->types["ROLE"], "") != 0) {
475  $role = $this->fold("ROLE:" . $this->types["ROLE"]) . "\n";
476  } else {
477  $role = "";
478  }
479  break;
480  case "LOGO":
481  $logo = "";
482  if (is_array($this->types["LOGO"])) {
483  if (strcmp($this->types["LOGO"]["VALUE"], "") != 0) {
484  $logo = $this->fold("LOGO;VALUE=uri:" . $this->types["LOGO"]["VALUE"]) . "\n";
485  } elseif (strcmp($this->types["LOGO"]["ENCODING"], "") != 0) {
486  $logo = "LOGO;ENCODING=" . $this->types["LOGO"]["ENCODING"];
487  if (strcmp($this->types["LOGO"]["TYPE"], "") != 0) {
488  $logo .= ";TYPE=" . $this->types["LOGO"]["TYPE"];
489  }
490  $logo .= ":" . $this->types["LOGO"]["LOGO"];
491  $logo = $this->fold($logo) . "\n";
492  }
493  }
494  break;
495  case "AGENT":
496  if (strcmp($this->types["AGENT"], "") != 0) {
497  $agent = $this->fold("AGENT:" . $this->types["AGENT"]) . "\n";
498  } else {
499  $agent = "";
500  }
501  break;
502  case "ORG":
503  if (strcmp($this->types["ORG"], "") != 0) {
504  $org = $this->fold("ORG:" . $this->types["ORG"]) . "\n";
505  } else {
506  $org = "";
507  }
508  break;
509  case "CATEGORIES":
510  if (strcmp($this->types["CATEGORIES"], "") != 0) {
511  $categories = $this->fold("CATEGORIES:" . $this->types["CATEGORIES"]) . "\n";
512  } else {
513  $categories = "";
514  }
515  break;
516  case "NOTE":
517  if (strcmp($this->types["NOTE"], "") != 0) {
518  $note = $this->fold("NOTE:" . $this->types["NOTE"]) . "\n";
519  } else {
520  $note = "";
521  }
522  break;
523  case "PRODID":
524  if (strcmp($this->types["PRODID"], "") != 0) {
525  $prodid = $this->fold("PRODID:" . $this->types["PRODID"]) . "\n";
526  } else {
527  $prodid = "";
528  }
529  break;
530  case "REV":
531  if (strcmp($this->types["REV"], "") != 0) {
532  $rev = $this->fold("REV:" . $this->types["REV"]) . "\n";
533  } else {
534  $rev = "";
535  }
536  break;
537  case "SORT-STRING":
538  if (strcmp($this->types["SORT-STRING"], "") != 0) {
539  $sortstring = $this->fold("SORT-STRING:" . $this->types["SORT-STRING"]) . "\n";
540  } else {
541  $sortstring = "";
542  }
543  break;
544  case "SOUND":
545  $sound = "";
546  if (is_array($this->types["SOUND"])) {
547  if (strcmp($this->types["SOUND"]["VALUE"], "") != 0) {
548  $sound = $this->fold("SOUND;VALUE=uri:" . $this->types["SOUND"]["VALUE"]) . "\n";
549  } elseif (strcmp($this->types["SOUND"]["ENCODING"], "") != 0) {
550  $sound = "SOUND;ENCODING=" . $this->types["SOUND"]["ENCODING"];
551  if (strcmp($this->types["SOUND"]["TYPE"], "") != 0) {
552  $sound .= ";TYPE=" . $this->types["SOUND"]["TYPE"];
553  }
554  $sound .= ":" . $this->types["SOUND"]["SOUND"];
555  $sound = $this->fold($sound) . "\n";
556  }
557  }
558  break;
559  case "UID":
560  $uid = "";
561  if (is_array($this->types["UID"])) {
562  if (strcmp($this->types["UID"]["UID"], "") != 0) {
563  $uid = "UID";
564  if (strcmp($this->types["UID"]["TYPE"], "") != 0) {
565  $uid .= ";TYPE=" . $this->types["UID"]["TYPE"];
566  }
567  $uid .= ":" . $this->types["UID"]["UID"];
568  $uid = $this->fold($uid) . "\n";
569  }
570  }
571  break;
572  case "URL":
573  if (strcmp($this->types["URL"], "") != 0) {
574  $url = $this->fold("URL:" . $this->types["URL"]) . "\n";
575  } else {
576  $url = "";
577  }
578  break;
579  case "KEY":
580  $key = "";
581  if (is_array($this->types["KEY"])) {
582  if (strcmp($this->types["KEY"]["KEY"], "") != 0) {
583  $key = "KEY";
584  if (strcmp($this->types["KEY"]["TYPE"], "") != 0) {
585  $key .= ";TYPE=" . $this->types["KEY"]["TYPE"];
586  }
587  if (strcmp($this->types["KEY"]["ENCODING"], "") != 0) {
588  $key .= ";ENCODING=" . $this->types["KEY"]["ENCODING"];
589  }
590  $key .= ":" . $this->types["KEY"]["KEY"];
591  $key = $this->fold($key) . "\n";
592  }
593  }
594  break;
595  case "CLASS":
596  if (strcmp($this->types["CLASS"], "") != 0) {
597  $class = $this->fold("CLASS:" . $this->types["CLASS"]) . "\n";
598  } else {
599  $class = "";
600  }
601  break;
602  }
603  }
604  $vcard .= $fn . $n . $nickname . $photo . $bday . $adr . $label . $tel . $email . $mailer .
605  $tz . $geo . $title . $role . $logo . $agent . $org . $categories . $note . $prodid .
606  $rev . $sortstring . $sound . $uid . $url . $class . $key;
607  $vcard .= "END:vCard\n";
608  return $vcard;
609  }
610 
622  public function quoted_printable_encode($input, $line_max = 76)
623  {
624  $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
625  $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
626  $eol = "\r\n";
627  $linebreak = "=0D=0A";
628  $escape = "=";
629  $output = "";
630 
631  for ($j = 0;$j < count($lines);$j++) {
632  $line = $lines[$j];
633  $linlen = strlen($line);
634  $newline = "";
635  for ($i = 0; $i < $linlen; $i++) {
636  $c = substr($line, $i, 1);
637  $dec = ord($c);
638  if (($dec == 32) && ($i == ($linlen - 1))) { // convert space at eol only
639  $c = "=20";
640  } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required
641  $h2 = floor($dec / 16);
642  $h1 = floor($dec % 16);
643  $c = $escape . $hex["$h2"] . $hex["$h1"];
644  }
645  if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
646  $output .= $newline . $escape . $eol; // soft line break; " =\r\n" is okay
647  $newline = " ";
648  }
649  $newline .= $c;
650  } // end of for
651  $output .= $newline;
652  if ($j < count($lines) - 1) {
653  $output .= $linebreak;
654  }
655  }
656  return trim($output);
657  }
658 
659  // Identification Types
660 //
661  // These types are used in the vCard profile to capture information
662  // associated with the identification and naming of the person or
663  // resource associated with the vCard.
664 
679  public function setFormattedName($formatted_name)
680  {
681  $this->types["FN"] = $this->escape($formatted_name);
682  }
683 
713  public function setName($family_name, $given_name = "", $additional_names = "", $honorific_prefixes = "", $honorific_suffixes = "")
714  {
715  $familynames = &$this->explodeVar($family_name);
716  $givennames = &$this->explodeVar($given_name);
717  $addnames = &$this->explodeVar($additional_names);
718  $prefixes = &$this->explodeVar($honorific_prefixes);
719  $suffixes = &$this->explodeVar($honorific_suffixes);
720 
721  $this->types["N"] =
722  join(",", $familynames) .
723  ";" .
724  join(",", $givennames) .
725  ";" .
726  join(",", $addnames) .
727  ";" .
728  join(",", $prefixes) .
729  ";" .
730  join(",", $suffixes);
731 
732  $this->filename = "$given_name" . "_" . "$family_name" . ".vcf";
733  if (strcmp($this->types["FN"], "") == 0) {
734  $fn = trim("$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
735  $fn = preg_replace("/\s{2,10}/", " ", $fn);
736  $this->setFormattedName($fn);
737  }
738  }
739 
760  public function setNickname($nickname)
761  {
762  $nicknames = &$this->explodeVar($nickname);
763  $this->types["NICKNAME"] = join(",", $nicknames);
764  }
765 
801  public function setPhoto($photo, $type = "")
802  {
803  $value = "";
804  $encoding = "";
805  if (preg_match("/^http/", $photo)) {
806  $value = $this->encode($photo);
807  } else {
808  $encoding = "b";
809  $photo = base64_encode($photo);
810  }
811  $this->types["PHOTO"] = array(
812  "VALUE" => $value,
813  "TYPE" => $type,
814  "ENCODING" => $encoding,
815  "PHOTO" => $photo
816  );
817  }
818 
839  public function setBirthday($year, $month, $day)
840  {
841  if (($year < 1) or ($day < 1) or ($month < 1)) {
842  $this->types["BDAY"] = "";
843  } else {
844  $this->types["BDAY"] = sprintf("%04d-%02d-%02d", $year, $month, $day);
845  }
846  }
847 
848  // Delivery Addressing Types
849 //
850  // These types are concerned with information related to the delivery
851  // addressing or label for the vCard object.
852 
907  public function setAddress(
908  $po_box = "",
909  $extended_address = "",
910  $street_address = "",
911  $locality = "",
912  $region = "",
913  $postal_code = "",
914  $country = "",
916  ) {
917  if ($type == ADR_TYPE_NONE) {
919  }
920  $po_box = join(",", $this->explodeVar($po_box));
921  $extended_address = join(",", $this->explodeVar($extended_address));
922  $street_address = join(",", $this->explodeVar($street_address));
923  $locality = join(",", $this->explodeVar($locality));
924  $region = join(",", $this->explodeVar($region));
925  $postal_code = join(",", $this->explodeVar($postal_code));
926  $country = join(",", $this->explodeVar($country));
927  array_push($this->types["ADR"], array(
928  "POBOX" => $po_box,
929  "EXTENDED_ADDRESS" => $extended_address,
930  "STREET_ADDRESS" => $street_address,
931  "LOCALITY" => $locality,
932  "REGION" => $region,
933  "POSTAL_CODE" => $postal_code,
934  "COUNTRY" => $country,
935  "TYPE" => $type
936  ));
937  }
938 
975  public function setLabel($label = "", $type = ADR_TYPE_NONE)
976  {
977  if ($type == ADR_TYPE_NONE) {
979  }
980  $this->types["LABEL"] = array(
981  "LABEL" => $this->escape($label),
982  "TYPE" => $type
983  );
984  }
985 
986  // Telecommunications Addressing Types
987 //
988  // These types are concerned with information associated with the
989  // telecommunications addressing of the object the vCard represents.
990 
1033  public function setPhone($number = "", $type = TEL_TYPE_VOICE)
1034  {
1035  array_push($this->types["TEL"], array(
1036  "TEL" => $this->escape($number),
1037  "TYPE" => $type
1038  ));
1039  }
1040 
1067  public function setEmail($address = "", $type = EMAIL_TYPE_INTERNET)
1068  {
1069  array_push($this->types["EMAIL"], array(
1070  "EMAIL" => $this->escape($address),
1071  "TYPE" => $type
1072  ));
1073  }
1074 
1095  public function setMailer($name = "")
1096  {
1097  $this->types["MAILER"] = $this->escape($name);
1098  }
1099 
1100  // Geographical Types
1101 //
1102  // These types are concerned with information associated with
1103  // geographical positions or regions associated with the object the
1104  // vCard represents.
1105 
1123  public function setTimezone($zone = "")
1124  {
1125  $this->types["TZ"] = $this->escape($zone);
1126  }
1127 
1162  public function setPosition($latitude = "", $longitude = "")
1163  {
1164  $this->types["GEO"] = array(
1165  "LAT" => $latitude,
1166  "LON" => $longitude
1167  );
1168  }
1169 
1170  // Organizational Types
1171 //
1172  // These types are concerned with information associated with
1173  // characteristics of the organization or organizational units of the
1174  // object the vCard represents.
1175 
1192  public function setTitle($title = "")
1193  {
1194  $this->types["TITLE"] = $this->escape($title);
1195  }
1196 
1217  public function setRole($role = "")
1218  {
1219  $this->types["ROLE"] = $this->escape($role);
1220  }
1221 
1255  public function setLogo($logo, $type = "")
1256  {
1257  $value = "";
1258  $encoding = "";
1259  if (preg_match("/^http/", $logo)) {
1260  $value = $this->encode($logo);
1261  } else {
1262  $encoding = "b";
1263  $logo = base64_encode($logo);
1264  }
1265  $this->types["LOGO"] = array(
1266  "VALUE" => $value,
1267  "TYPE" => $type,
1268  "ENCODING" => $encoding,
1269  "LOGO" => $logo
1270  );
1271  }
1272 
1300  public function setAgent($agent = "")
1301  {
1302  $this->types["AGENT"] = $this->escape($agent);
1303  }
1304 
1326  public function setOrganization($organization = "")
1327  {
1328  $organization = join(";", $this->explodeVar($organization, ";"));
1329  $this->types["ORG"] = $organization;
1330  }
1331 
1332  // Explanatory Types
1333 //
1334  // These types are concerned with additional explanations, such as that
1335  // related to informational notes or revisions specific to the vCard.
1336 
1354  public function setCategories($categories)
1355  {
1356  $categories = join(",", $this->explodeVar($categories));
1357  $this->types["CATEGORIES"] = $categories;
1358  }
1359 
1379  public function setNote($note = "")
1380  {
1381  $this->types["NOTE"] = $this->escape($note);
1382  }
1383 
1403  public function setProductId($product_id = "")
1404  {
1405  $this->types["PRODID"] = $this->escape($product_id);
1406  }
1407 
1429  public function setRevision($revision_date = "")
1430  {
1431  $this->types["REV"] = $this->escape($revision_date);
1432  }
1433 
1477  public function setSortString($string = "")
1478  {
1479  $this->types["SORT-STRING"] = $this->escape($string);
1480  }
1481 
1517  public function setSound($sound = "", $type = "")
1518  {
1519  $value = "";
1520  $encoding = "";
1521  if (preg_match("/^http/", $sound)) {
1522  $value = $this->encode($sound);
1523  } else {
1524  $encoding = "b";
1525  $sound = base64_encode($sound);
1526  }
1527  $this->types["SOUND"] = array(
1528  "VALUE" => $value,
1529  "TYPE" => $type,
1530  "ENCODING" => $encoding,
1531  "SOUND" => $sound
1532  );
1533  }
1534 
1561  public function setUID($uid = "", $type = "")
1562  {
1563  $this->types["UID"] = array(
1564  "UID" => $this->escape($uid),
1565  "TYPE" => $type
1566  );
1567  }
1568 
1585  public function setURL($uri = "")
1586  {
1587  $this->types["URL"] = $this->escape($uri);
1588  }
1589 
1606  public function setVersion($version = "3.0")
1607  {
1608  $this->types["VERSION"] = $version;
1609  }
1610 
1611  // Security Types
1612 //
1613  // These types are concerned with the security of communication pathways
1614  // or access to the vCard.
1615 
1639  public function setClassification($classification = "")
1640  {
1641  $this->types["CLASS"] = $this->escape($classification);
1642  }
1643 
1688  public function setKey($key = "", $type = "")
1689  {
1690  $encoding = "b";
1691  $key = base64_encode($key);
1692  $this->types["KEY"] = array(
1693  "KEY" => $key,
1694  "TYPE" => $type,
1695  "ENCODING" => $encoding
1696  );
1697  }
1698 
1699  public function getFilename()
1700  {
1701  if (strcmp($this->filename, "") == 0) {
1702  return "vcard.vcf";
1703  } else {
1704  return $this->filename;
1705  }
1706  }
1707 
1708  public function getMimetype()
1709  {
1710  return "text/x-vcard";
1711  }
1712 }
if($orgName !==null) if($spconfig->hasValue('contacts')) $email
Definition: metadata.php:201
setCategories($categories)
Sets the value for the vCard CATEGORIES type.
setFormattedName($formatted_name)
Sets the value for the vCard FN type.
setSortString($string="")
Sets the value for the vCard SORT-STRING type.
const TEL_TYPE_CAR
$type
$types
An array containing the vCard types.
const EMAIL_TYPE_INTERNET
setLabel($label="", $type=ADR_TYPE_NONE)
Sets the value for the vCard LABEL type.
const ADR_TYPE_PARCEL
setUID($uid="", $type="")
Sets the value for the vCard UID type.
setBirthday($year, $month, $day)
Sets the value for the vCard BDAY type.
setAgent($agent="")
Sets the value for the vCard AGENT type.
const TEL_TYPE_PREF
const EMAIL_TYPE_x400
$index
Definition: metadata.php:60
const TEL_TYPE_FAX
setOrganization($organization="")
Sets the value for the vCard ORG type.
const ADR_TYPE_DOM
setAddress( $po_box="", $extended_address="", $street_address="", $locality="", $region="", $postal_code="", $country="", $type=ADR_TYPE_NONE)
Sets the value for the vCard ADR type.
$version
Definition: build.php:27
& explodeVar($variable, $separator=",")
Splits a variable into an array using a separator and escapes every value.
setProductId($product_id="")
Sets the value for the vCard PRODID type.
const TEL_TYPE_MODEM
setTitle($title="")
Sets the value for the vCard TITLE type.
setMailer($name="")
Sets the value for the vCard MAILER type.
$filename
The filename of the vCard used when saving the vCard.
const ADR_TYPE_WORK
const TEL_TYPE_VIDEO
setSound($sound="", $type="")
Sets the value for the vCard SOUND type.
setURL($uri="")
Sets the value for the vCard URL type.
setPosition($latitude="", $longitude="")
Sets the value for the vCard GEO type.
const TEL_TYPE_HOME
const TEL_TYPE_WORK
setVersion($version="3.0")
Sets the value for the vCard VERSION type.
const ADR_TYPE_POSTAL
const TEL_TYPE_BBS
fold($string="", $length=75)
Fold a string according to RFC 2425.
buildVCard()
Builds a vCard string out of the attributes of this object.
setTimezone($zone="")
Sets the value for the vCard TZ type.
setNickname($nickname)
Sets the value for the vCard NICKNAME type.
const TEL_TYPE_CELL
setName($family_name, $given_name="", $additional_names="", $honorific_prefixes="", $honorific_suffixes="")
Sets the value for the vCard N type.
$n
Definition: RandomTest.php:85
setLogo($logo, $type="")
Sets the value for the vCard LOGO type.
setKey($key="", $type="")
Sets the value for the vCard KEY type.
encode($string)
Encode data with "b" type encoding according to RFC 2045.
const TEL_TYPE_VOICE
setNote($note="")
Sets the value for the vCard NOTE type.
const TEL_TYPE_MSG
const ADR_TYPE_NONE
RFC 2426 vCard MIME Directory Profile 3.0 class.
const ADR_TYPE_INTL
const ADR_TYPE_HOME
setRevision($revision_date="")
Sets the value for the vCard REV type.
$i
Definition: disco.tpl.php:19
const TEL_TYPE_PAGER
static getLogger($a_component_id)
Get component logger.
$url
setClassification($classification="")
Sets the value for the vCard CLASS type.
const TEL_TYPE_ISDN
setRole($role="")
Sets the value for the vCard ROLE type.
$key
Definition: croninfo.php:18
escape($string)
Escapes a string according to RFC 2426.
quoted_printable_encode($input, $line_max=76)
Creates a quoted printable encoded string according to RFC 2045.
__construct($version="3.0")
ilvCard Constructor
const ADR_TYPE_PREF
const EMAIL_TYPE_PREF
setPhoto($photo, $type="")
Sets the value for the vCard PHOTO type.
setEmail($address="", $type=EMAIL_TYPE_INTERNET)
Sets the value for the vCard EMAIL type.
const TEL_TYPE_PCS
$test
Definition: Utf8Test.php:84
setPhone($number="", $type=TEL_TYPE_VOICE)
Sets the value for the vCard TEL type.