ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
37define ("ADR_TYPE_NONE", 0);
38define ("ADR_TYPE_DOM", 1);
39define ("ADR_TYPE_INTL", 2);
40define ("ADR_TYPE_POSTAL", 4);
41define ("ADR_TYPE_PARCEL", 8);
42define ("ADR_TYPE_HOME", 16);
43define ("ADR_TYPE_WORK", 32);
44define ("ADR_TYPE_PREF", 64);
45
51define ("TEL_TYPE_NONE", 0);
52define ("TEL_TYPE_HOME", 1);
53define ("TEL_TYPE_MSG", 2);
54define ("TEL_TYPE_WORK", 4);
55define ("TEL_TYPE_PREF", 8);
56define ("TEL_TYPE_VOICE", 16);
57define ("TEL_TYPE_FAX", 32);
58define ("TEL_TYPE_CELL", 64);
59define ("TEL_TYPE_VIDEO", 128);
60define ("TEL_TYPE_PAGER", 256);
61define ("TEL_TYPE_BBS", 512);
62define ("TEL_TYPE_MODEM", 1024);
63define ("TEL_TYPE_CAR", 2048);
64define ("TEL_TYPE_ISDN", 4096);
65define ("TEL_TYPE_PCS", 8192);
66
72define ("EMAIL_TYPE_NONE", 0);
73define ("EMAIL_TYPE_INTERNET", 1);
74define ("EMAIL_TYPE_x400", 2);
75define ("EMAIL_TYPE_PREF", 4);
76
77class ilvCard
78{
84 var $types;
85
92
98 function ilvCard($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 function encode($string)
143 {
144 return escape(quoted_printable_encode($string));
145 }
146
157 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 {
163 if ($i < (count($matches[1])-1))
164 {
165 $matches[1][$i] .= "\n";
166 }
167 if ($i > 0)
168 {
169 $matches[1][$i] = " " . $matches[1][$i];
170 }
171 $folded_string .= $matches[1][$i];
172 }
173 return $folded_string;
174 }
175
185 function escape($string)
186 {
187 $string = preg_replace("/(?<!\\\\)(\\\\)([^;,n\\\\])/", "\${1}\${1}\${2}", $string);
188 $string = preg_replace("/(?<!\\\\);/", "\\;", $string);
189 $string = preg_replace("/(?<!\\\\),/", "\\,", $string);
190 $string = preg_replace("/\n/","\\n", $string);
191 return $string;
192 }
193
204 function &explodeVar($variable, $separator = ",")
205 {
206 $exploded = explode($separator, $variable);
207 foreach ($exploded as $index => $var)
208 {
209 $exploded[$index] = $this->escape($var);
210 }
211 return $exploded;
212 }
213
222 function buildVCard()
223 {
224 $vcard = "BEGIN:VCARD\n";
225 $vcard .= "VERSION:" . $this->types["VERSION"] . "\n";
226 foreach ($this->types as $type => $var)
227 {
228
229 ilLoggerFactory::getLogger('user')->debug(print_r($this->types,TRUE));
230
231 switch ($type)
232 {
233 case "FN":
234 if (strcmp($this->types["FN"], "") != 0)
235 {
236 $fn = $this->fold("FN:" . $this->types["FN"]) . "\n";
237 }
238 else
239 {
240 $fn = "";
241 }
242 break;
243 case "N":
244 if (strcmp($this->types["N"], "") != 0)
245 {
246 $n = $this->fold("N:" . $this->types["N"]) . "\n";
247 }
248 else
249 {
250 $n = "";
251 }
252 break;
253 case "NICKNAME":
254 if (strcmp($this->types["NICKNAME"], "") != 0)
255 {
256 $nickname = $this->fold("NICKNAME:" . $this->types["NICKNAME"]) . "\n";
257 }
258 else
259 {
260 $nickname = "";
261 }
262 break;
263 case "PHOTO":
264 $photo = "";
265 if (is_array($this->types["PHOTO"]))
266 {
267 if (strcmp($this->types["PHOTO"]["VALUE"], "") != 0)
268 {
269 $photo = $this->fold("PHOTO;VALUE=uri:" . $this->types["PHOTO"]["VALUE"]) . "\n";
270 }
271 elseif (strcmp($this->types["PHOTO"]["ENCODING"], "") != 0)
272 {
273 $photo = "PHOTO;ENCODING=" . $this->types["PHOTO"]["ENCODING"];
274 if (strcmp($this->types["PHOTO"]["TYPE"], "") != 0)
275 {
276 $photo .= ";TYPE=" . $this->types["PHOTO"]["TYPE"];
277 }
278 $photo .= ":" . $this->types["PHOTO"]["PHOTO"];
279 $photo = $this->fold($photo) . "\n";
280 }
281 }
282 break;
283 case "BDAY":
284 if (strcmp($this->types["BDAY"], "") != 0)
285 {
286 $bday = $this->fold("BDAY:" . $this->types["BDAY"]) . "\n";
287 }
288 else
289 {
290 $bday = "";
291 }
292 break;
293 case "ADR":
294 if (count($this->types["ADR"]))
295 {
296 $addresses = "";
297 foreach ($this->types["ADR"] as $key => $address)
298 {
299 $test = "";
300 foreach ($address as $str)
301 {
302 $test .= $str;
303 }
304 if (strcmp($test, "") != 0)
305 {
306 $adr = "ADR";
307 $adr_types = array();
308 if ($address["TYPE"] > 0)
309 {
310 if (($address["TYPE"] & ADR_TYPE_DOM) > 0)
311 {
312 array_push($adr_types, "dom");
313 }
314 if (($address["TYPE"] & ADR_TYPE_INTL) > 0)
315 {
316 array_push($adr_types, "intl");
317 }
318 if (($address["TYPE"] & ADR_TYPE_POSTAL) > 0)
319 {
320 array_push($adr_types, "postal");
321 }
322 if (($address["TYPE"] & ADR_TYPE_PARCEL) > 0)
323 {
324 array_push($adr_types, "parcel");
325 }
326 if (($address["TYPE"] & ADR_TYPE_HOME) > 0)
327 {
328 array_push($adr_types, "home");
329 }
330 if (($address["TYPE"] & ADR_TYPE_WORK) > 0)
331 {
332 array_push($adr_types, "work");
333 }
334 if (($address["TYPE"] & ADR_TYPE_PREF) > 0)
335 {
336 array_push($adr_types, "pref");
337 }
338 $adr .= ";TYPE=" . join(",", $adr_types);
339 }
340 $adr .= ":" . $address["POBOX"] . ";" . $address["EXTENDED_ADDRESS"] .
341 ";" . $address["STREET_ADDRESS"] . ";" . $address["LOCALITY"] .
342 ";" . $address["REGION"] . ";" . $address["POSTAL_CODE"] .
343 ";" . $address["COUNTRY"];
344 $adr = $this->fold($adr) . "\n";
345 $addresses .= $adr;
346 }
347 }
348 $adr = $addresses;
349 }
350 else
351 {
352 $adr = "";
353 }
354 break;
355 case "LABEL":
356 $label = "";
357 if (is_array($this->types["LABEL"]))
358 {
359 if (strcmp($this->types["LABEL"]["LABEL"], "") != 0)
360 {
361 $label = "LABEL";
362 $adr_types = array();
363 if ($this->types["LABEL"]["TYPE"] > 0)
364 {
365 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_DOM) > 0)
366 {
367 array_push($adr_types, "dom");
368 }
369 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_INTL) > 0)
370 {
371 array_push($adr_types, "intl");
372 }
373 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_POSTAL) > 0)
374 {
375 array_push($adr_types, "postal");
376 }
377 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PARCEL) > 0)
378 {
379 array_push($adr_types, "parcel");
380 }
381 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_HOME) > 0)
382 {
383 array_push($adr_types, "home");
384 }
385 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_WORK) > 0)
386 {
387 array_push($adr_types, "work");
388 }
389 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PREF) > 0)
390 {
391 array_push($adr_types, "pref");
392 }
393 $label .= ";TYPE=" . join(",", $adr_types);
394 }
395 $label .= ":" . $this->types["LABEL"]["LABEL"];
396 $label = $this->fold($label) . "\n";
397 }
398 }
399 break;
400 case "TEL":
401 if (count($this->types["TEL"]))
402 {
403 $phonenumbers = "";
404 foreach ($this->types["TEL"] as $key => $phone)
405 {
406 if (strcmp($phone["TEL"], "") != 0)
407 {
408 $tel = "TEL";
409 $tel_types = array();
410 if ($phone["TYPE"] > 0)
411 {
412 if (($phone["TYPE"] & TEL_TYPE_HOME) > 0)
413 {
414 array_push($tel_types, "home");
415 }
416 if (($phone["TYPE"] & TEL_TYPE_MSG) > 0)
417 {
418 array_push($tel_types, "msg");
419 }
420 if (($phone["TYPE"] & TEL_TYPE_WORK) > 0)
421 {
422 array_push($tel_types, "work");
423 }
424 if (($phone["TYPE"] & TEL_TYPE_PREF) > 0)
425 {
426 array_push($tel_types, "pref");
427 }
428 if (($phone["TYPE"] & TEL_TYPE_VOICE) > 0)
429 {
430 array_push($tel_types, "voice");
431 }
432 if (($phone["TYPE"] & TEL_TYPE_FAX) > 0)
433 {
434 array_push($tel_types, "fax");
435 }
436 if (($phone["TYPE"] & TEL_TYPE_CELL) > 0)
437 {
438 array_push($tel_types, "cell");
439 }
440 if (($phone["TYPE"] & TEL_TYPE_VIDEO) > 0)
441 {
442 array_push($tel_types, "video");
443 }
444 if (($phone["TYPE"] & TEL_TYPE_PAGER) > 0)
445 {
446 array_push($tel_types, "pager");
447 }
448 if (($phone["TYPE"] & TEL_TYPE_BBS) > 0)
449 {
450 array_push($tel_types, "bbs");
451 }
452 if (($phone["TYPE"] & TEL_TYPE_MODEM) > 0)
453 {
454 array_push($tel_types, "modem");
455 }
456 if (($phone["TYPE"] & TEL_TYPE_CAR) > 0)
457 {
458 array_push($tel_types, "car");
459 }
460 if (($phone["TYPE"] & TEL_TYPE_ISDN) > 0)
461 {
462 array_push($tel_types, "isdn");
463 }
464 if (($phone["TYPE"] & TEL_TYPE_PCS) > 0)
465 {
466 array_push($tel_types, "pcs");
467 }
468 $tel .= ";TYPE=" . join(",", $tel_types);
469 }
470 $tel .= ":" . $phone["TEL"];
471 $tel = $this->fold($tel) . "\n";
472 $phonenumbers .= $tel;
473 }
474 }
475 $tel = $phonenumbers;
476 }
477 else
478 {
479 $tel = "";
480 }
481 break;
482 case "EMAIL":
483 if (count($this->types["EMAIL"]))
484 {
485 $emails = "";
486 foreach ($this->types["EMAIL"] as $key => $mail)
487 {
488 if (strcmp($mail["EMAIL"], "") != 0)
489 {
490 $email = "EMAIL";
491 $adr_types = array();
492 if ($mail["TYPE"] > 0)
493 {
494 if (($mail["TYPE"] & EMAIL_TYPE_INTERNET) > 0)
495 {
496 array_push($adr_types, "internet");
497 }
498 if (($mail["TYPE"] & EMAIL_TYPE_x400) > 0)
499 {
500 array_push($adr_types, "x400");
501 }
502 if (($mail["TYPE"] & EMAIL_TYPE_PREF) > 0)
503 {
504 array_push($adr_types, "pref");
505 }
506 $email .= ";TYPE=" . join(",", $adr_types);
507 }
508 $email .= ":" . $mail["EMAIL"];
509 $email = $this->fold($email) . "\n";
510 $emails .= $email;
511 }
512 }
513 $email = $emails;
514 }
515 else
516 {
517 $email = "";
518 }
519 break;
520 case "MAILER":
521 if (strcmp($this->types["MAILER"], "") != 0)
522 {
523 $mailer = $this->fold("MAILER:" . $this->types["MAILER"]) . "\n";
524 }
525 else
526 {
527 $mailer = "";
528 }
529 break;
530 case "TZ":
531 if (strcmp($this->types["TZ"], "") != 0)
532 {
533 $tz = $this->fold("TZ:" . $this->types["TZ"]) . "\n";
534 }
535 else
536 {
537 $tz = "";
538 }
539 break;
540 case "GEO":
541 if (is_array($this->types["GEO"]) and
542 (strcmp($this->types["GEO"]["LAT"], "") != 0) and
543 (strcmp($this->types["GEO"]["LON"], "") != 0))
544 {
545 $geo = $this->fold("GEO:" . $this->types["GEO"]["LAT"] . ";" . $this->types["GEO"]["LON"]) . "\n";
546 }
547 else
548 {
549 $geo = "";
550 }
551 break;
552 case "TITLE":
553 if (strcmp($this->types["TITLE"], "") != 0)
554 {
555 $title = $this->fold("TITLE:" . $this->types["TITLE"]) . "\n";
556 }
557 else
558 {
559 $title = "";
560 }
561 break;
562 case "ROLE":
563 if (strcmp($this->types["ROLE"], "") != 0)
564 {
565 $role = $this->fold("ROLE:" . $this->types["ROLE"]) . "\n";
566 }
567 else
568 {
569 $role = "";
570 }
571 break;
572 case "LOGO":
573 $logo = "";
574 if (is_array($this->types["LOGO"]))
575 {
576 if (strcmp($this->types["LOGO"]["VALUE"], "") != 0)
577 {
578 $logo = $this->fold("LOGO;VALUE=uri:" . $this->types["LOGO"]["VALUE"]) . "\n";
579 }
580 elseif (strcmp($this->types["LOGO"]["ENCODING"], "") != 0)
581 {
582 $logo = "LOGO;ENCODING=" . $this->types["LOGO"]["ENCODING"];
583 if (strcmp($this->types["LOGO"]["TYPE"], "") != 0)
584 {
585 $logo .= ";TYPE=" . $this->types["LOGO"]["TYPE"];
586 }
587 $logo .= ":" . $this->types["LOGO"]["LOGO"];
588 $logo = $this->fold($logo) . "\n";
589 }
590 }
591 break;
592 case "AGENT":
593 if (strcmp($this->types["AGENT"], "") != 0)
594 {
595 $agent = $this->fold("AGENT:" . $this->types["AGENT"]) . "\n";
596 }
597 else
598 {
599 $agent = "";
600 }
601 break;
602 case "ORG":
603 if (strcmp($this->types["ORG"], "") != 0)
604 {
605 $org = $this->fold("ORG:" . $this->types["ORG"]) . "\n";
606 }
607 else
608 {
609 $org = "";
610 }
611 break;
612 case "CATEGORIES":
613 if (strcmp($this->types["CATEGORIES"], "") != 0)
614 {
615 $categories = $this->fold("CATEGORIES:" . $this->types["CATEGORIES"]) . "\n";
616 }
617 else
618 {
619 $categories = "";
620 }
621 break;
622 case "NOTE":
623 if (strcmp($this->types["NOTE"], "") != 0)
624 {
625 $note = $this->fold("NOTE:" . $this->types["NOTE"]) . "\n";
626 }
627 else
628 {
629 $note = "";
630 }
631 break;
632 case "PRODID":
633 if (strcmp($this->types["PRODID"], "") != 0)
634 {
635 $prodid = $this->fold("PRODID:" . $this->types["PRODID"]) . "\n";
636 }
637 else
638 {
639 $prodid = "";
640 }
641 break;
642 case "REV":
643 if (strcmp($this->types["REV"], "") != 0)
644 {
645 $rev = $this->fold("REV:" . $this->types["REV"]) . "\n";
646 }
647 else
648 {
649 $rev = "";
650 }
651 break;
652 case "SORT-STRING":
653 if (strcmp($this->types["SORT-STRING"], "") != 0)
654 {
655 $sortstring = $this->fold("SORT-STRING:" . $this->types["SORT-STRING"]) . "\n";
656 }
657 else
658 {
659 $sortstring = "";
660 }
661 break;
662 case "SOUND":
663 $sound = "";
664 if (is_array($this->types["SOUND"]))
665 {
666 if (strcmp($this->types["SOUND"]["VALUE"], "") != 0)
667 {
668 $sound = $this->fold("SOUND;VALUE=uri:" . $this->types["SOUND"]["VALUE"]) . "\n";
669 }
670 elseif (strcmp($this->types["SOUND"]["ENCODING"], "") != 0)
671 {
672 $sound = "SOUND;ENCODING=" . $this->types["SOUND"]["ENCODING"];
673 if (strcmp($this->types["SOUND"]["TYPE"], "") != 0)
674 {
675 $sound .= ";TYPE=" . $this->types["SOUND"]["TYPE"];
676 }
677 $sound .= ":" . $this->types["SOUND"]["SOUND"];
678 $sound = $this->fold($sound) . "\n";
679 }
680 }
681 break;
682 case "UID":
683 $uid = "";
684 if (is_array($this->types["UID"]))
685 {
686 if (strcmp($this->types["UID"]["UID"], "") != 0)
687 {
688 $uid = "UID";
689 if (strcmp($this->types["UID"]["TYPE"], "") != 0)
690 {
691 $uid .= ";TYPE=" . $this->types["UID"]["TYPE"];
692 }
693 $uid .= ":" . $this->types["UID"]["UID"];
694 $uid = $this->fold($uid) . "\n";
695 }
696 }
697 break;
698 case "URL":
699 if (strcmp($this->types["URL"], "") != 0)
700 {
701 $url = $this->fold("URL:" . $this->types["URL"]) . "\n";
702 }
703 else
704 {
705 $url = "";
706 }
707 break;
708 case "KEY":
709 $key = "";
710 if (is_array($this->types["KEY"]))
711 {
712 if (strcmp($this->types["KEY"]["KEY"], "") != 0)
713 {
714 $key = "KEY";
715 if (strcmp($this->types["KEY"]["TYPE"], "") != 0)
716 {
717 $key .= ";TYPE=" . $this->types["KEY"]["TYPE"];
718 }
719 if (strcmp($this->types["KEY"]["ENCODING"], "") != 0)
720 {
721 $key .= ";ENCODING=" . $this->types["KEY"]["ENCODING"];
722 }
723 $key .= ":" . $this->types["KEY"]["KEY"];
724 $key = $this->fold($key) . "\n";
725 }
726 }
727 break;
728 case "CLASS":
729 if (strcmp($this->types["CLASS"], "") != 0)
730 {
731 $class = $this->fold("CLASS:" . $this->types["CLASS"]) . "\n";
732 }
733 else
734 {
735 $class = "";
736 }
737 break;
738 }
739 }
740 $vcard .= $fn.$n.$nickname.$photo.$bday.$adr.$label.$tel.$email.$mailer.
741 $tz.$geo.$title.$role.$logo.$agent.$org.$categories.$note.$prodid.
742 $rev.$sortstring.$sound.$uid.$url.$class.$key;
743 $vcard .= "END:vCard\n";
744 return $vcard;
745 }
746
758 function quoted_printable_encode($input, $line_max = 76) {
759 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
760 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
761 $eol = "\r\n";
762 $linebreak = "=0D=0A";
763 $escape = "=";
764 $output = "";
765
766 for ($j=0;$j<count($lines);$j++) {
767 $line = $lines[$j];
768 $linlen = strlen($line);
769 $newline = "";
770 for($i = 0; $i < $linlen; $i++) {
771 $c = substr($line, $i, 1);
772 $dec = ord($c);
773 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
774 $c = "=20";
775 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
776 $h2 = floor($dec/16); $h1 = floor($dec%16);
777 $c = $escape.$hex["$h2"].$hex["$h1"];
778 }
779 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
780 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
781 $newline = " ";
782 }
783 $newline .= $c;
784 } // end of for
785 $output .= $newline;
786 if ($j<count($lines)-1) $output .= $linebreak;
787 }
788 return trim($output);
789 }
790
791// Identification Types
792//
793// These types are used in the vCard profile to capture information
794// associated with the identification and naming of the person or
795// resource associated with the vCard.
796
811 function setFormattedName($formatted_name)
812 {
813 $this->types["FN"] = $this->escape($formatted_name);
814 }
815
845 function setName($family_name, $given_name = "", $additional_names = "", $honorific_prefixes = "", $honorific_suffixes = "")
846 {
847 $familynames =& $this->explodeVar($family_name);
848 $givennames =& $this->explodeVar($given_name);
849 $addnames =& $this->explodeVar($additional_names);
850 $prefixes =& $this->explodeVar($honorific_prefixes);
851 $suffixes =& $this->explodeVar($honorific_suffixes);
852
853 $this->types["N"] =
854 join(",", $familynames) .
855 ";" .
856 join(",", $givennames) .
857 ";" .
858 join(",", $addnames) .
859 ";" .
860 join(",", $prefixes) .
861 ";" .
862 join(",", $suffixes);
863
864 $this->filename = "$given_name" . "_" . "$family_name" . ".vcf";
865 if (strcmp($this->types["FN"], "") == 0)
866 {
867 $fn = trim("$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
868 $fn = preg_replace("/\s{2,10}/", " ", $fn);
869 $this->setFormattedName($fn);
870 }
871 }
872
893 function setNickname($nickname)
894 {
895 $nicknames =& $this->explodeVar($nickname);
896 $this->types["NICKNAME"] = join(",", $nicknames);
897 }
898
934 function setPhoto($photo, $type = "")
935 {
936 $value = "";
937 $encoding = "";
938 if (preg_match("/^http/", $photo))
939 {
940 $value = $this->encode($photo);
941 }
942 else
943 {
944 $encoding = "b";
945 $photo = base64_encode($photo);
946 }
947 $this->types["PHOTO"] = array(
948 "VALUE" => $value,
949 "TYPE" => $type,
950 "ENCODING" => $encoding,
951 "PHOTO" => $photo
952 );
953 }
954
975 function setBirthday($year, $month, $day)
976 {
977 if (($year < 1) or ($day < 1) or ($month < 1))
978 {
979 $this->types["BDAY"] = "";
980 }
981 else
982 {
983 $this->types["BDAY"] = sprintf("%04d-%02d-%02d", $year, $month, $day);
984 }
985 }
986
987// Delivery Addressing Types
988//
989// These types are concerned with information related to the delivery
990// addressing or label for the vCard object.
991
1046 function setAddress(
1047 $po_box = "",
1048 $extended_address = "",
1049 $street_address = "",
1050 $locality = "",
1051 $region = "",
1052 $postal_code = "",
1053 $country = "",
1054 $type = ADR_TYPE_NONE
1055 )
1056 {
1057 if ($type == ADR_TYPE_NONE)
1058 {
1060 }
1061 $po_box = join(",", $this->explodeVar($po_box));
1062 $extended_address = join(",", $this->explodeVar($extended_address));
1063 $street_address = join(",", $this->explodeVar($street_address));
1064 $locality = join(",", $this->explodeVar($locality));
1065 $region = join(",", $this->explodeVar($region));
1066 $postal_code = join(",", $this->explodeVar($postal_code));
1067 $country = join(",", $this->explodeVar($country));
1068 array_push($this->types["ADR"], array(
1069 "POBOX" => $po_box,
1070 "EXTENDED_ADDRESS" => $extended_address,
1071 "STREET_ADDRESS" => $street_address,
1072 "LOCALITY" => $locality,
1073 "REGION" => $region,
1074 "POSTAL_CODE" => $postal_code,
1075 "COUNTRY" => $country,
1076 "TYPE" => $type
1077 ));
1078 }
1079
1116 function setLabel($label = "", $type = ADR_TYPE_NONE)
1117 {
1118 if ($type == ADR_TYPE_NONE)
1119 {
1121 }
1122 $this->types["LABEL"] = array(
1123 "LABEL" => $this->escape($label),
1124 "TYPE" => $type
1125 );
1126 }
1127
1128// Telecommunications Addressing Types
1129//
1130// These types are concerned with information associated with the
1131// telecommunications addressing of the object the vCard represents.
1132
1175 function setPhone($number = "", $type = TEL_TYPE_VOICE)
1176 {
1177 array_push($this->types["TEL"], array(
1178 "TEL" => $this->escape($number),
1179 "TYPE" => $type
1180 ));
1181 }
1182
1209 function setEmail($address = "", $type = EMAIL_TYPE_INTERNET)
1210 {
1211 array_push($this->types["EMAIL"], array(
1212 "EMAIL" => $this->escape($address),
1213 "TYPE" => $type
1214 ));
1215 }
1216
1237 function setMailer($name = "")
1238 {
1239 $this->types["MAILER"] = $this->escape($name);
1240 }
1241
1242// Geographical Types
1243//
1244// These types are concerned with information associated with
1245// geographical positions or regions associated with the object the
1246// vCard represents.
1247
1265 function setTimezone($zone = "")
1266 {
1267 $this->types["TZ"] = $this->escape($zone);
1268 }
1269
1304 function setPosition($latitude = "", $longitude = "")
1305 {
1306 $this->types["GEO"] = array(
1307 "LAT" => $latitude,
1308 "LON" => $longitude
1309 );
1310 }
1311
1312// Organizational Types
1313//
1314// These types are concerned with information associated with
1315// characteristics of the organization or organizational units of the
1316// object the vCard represents.
1317
1334 function setTitle($title = "")
1335 {
1336 $this->types["TITLE"] = $this->escape($title);
1337 }
1338
1359 function setRole($role = "")
1360 {
1361 $this->types["ROLE"] = $this->escape($role);
1362 }
1363
1397 function setLogo($logo, $type = "")
1398 {
1399 $value = "";
1400 $encoding = "";
1401 if (preg_match("/^http/", $logo))
1402 {
1403 $value = $this->encode($logo);
1404 }
1405 else
1406 {
1407 $encoding = "b";
1408 $logo = base64_encode($logo);
1409 }
1410 $this->types["LOGO"] = array(
1411 "VALUE" => $value,
1412 "TYPE" => $type,
1413 "ENCODING" => $encoding,
1414 "LOGO" => $logo
1415 );
1416 }
1417
1445 function setAgent($agent = "")
1446 {
1447 $this->types["AGENT"] = $this->escape($agent);
1448 }
1449
1471 function setOrganization($organization = "")
1472 {
1473 $organization = join(";", $this->explodeVar($organization, ";"));
1474 $this->types["ORG"] = $organization;
1475 }
1476
1477// Explanatory Types
1478//
1479// These types are concerned with additional explanations, such as that
1480// related to informational notes or revisions specific to the vCard.
1481
1499 function setCategories($categories)
1500 {
1501 $categories = join(",", $this->explodeVar($categories));
1502 $this->types["CATEGORIES"] = $categories;
1503 }
1504
1524 function setNote($note = "")
1525 {
1526 $this->types["NOTE"] = $this->escape($note);
1527 }
1528
1548 function setProductId($product_id = "")
1549 {
1550 $this->types["PRODID"] = $this->escape($product_id);
1551 }
1552
1574 function setRevision($revision_date = "")
1575 {
1576 $this->types["REV"] = $this->escape($revision_date);
1577 }
1578
1622 function setSortString($string = "")
1623 {
1624 $this->types["SORT-STRING"] = $this->escape($string);
1625 }
1626
1662 function setSound($sound = "", $type = "")
1663 {
1664 $value = "";
1665 $encoding = "";
1666 if (preg_match("/^http/", $sound))
1667 {
1668 $value = $this->encode($sound);
1669 }
1670 else
1671 {
1672 $encoding = "b";
1673 $sound = base64_encode($sound);
1674 }
1675 $this->types["SOUND"] = array(
1676 "VALUE" => $value,
1677 "TYPE" => $type,
1678 "ENCODING" => $encoding,
1679 "SOUND" => $sound
1680 );
1681 }
1682
1709 function setUID($uid = "", $type = "")
1710 {
1711 $this->types["UID"] = array(
1712 "UID" => $this->escape($uid),
1713 "TYPE" => $type
1714 );
1715 }
1716
1733 function setURL($uri = "")
1734 {
1735 $this->types["URL"] = $this->escape($uri);
1736 }
1737
1754 function setVersion($version = "3.0")
1755 {
1756 $this->types["VERSION"] = $version;
1757 }
1758
1759// Security Types
1760//
1761// These types are concerned with the security of communication pathways
1762// or access to the vCard.
1763
1787 function setClassification($classification = "")
1788 {
1789 $this->types["CLASS"] = $this->escape($classification);
1790 }
1791
1836 function setKey($key = "", $type = "")
1837 {
1838 $encoding = "b";
1839 $key = base64_encode($key);
1840 $this->types["KEY"] = array(
1841 "KEY" => $key,
1842 "TYPE" => $type,
1843 "ENCODING" => $encoding
1844 );
1845 }
1846
1847 function getFilename()
1848 {
1849 if (strcmp($this->filename, "") == 0)
1850 {
1851 return "vcard.vcf";
1852 }
1853 else
1854 {
1855 return $this->filename;
1856 }
1857 }
1858
1859 function getMimetype()
1860 {
1861 return "text/x-vcard";
1862 }
1863}
1864
1865?>
$n
Definition: RandomTest.php:80
$test
Definition: Utf8Test.php:85
const ADR_TYPE_NONE
RFC 2426 vCard MIME Directory Profile 3.0 class.
const ADR_TYPE_INTL
const TEL_TYPE_HOME
const TEL_TYPE_PCS
const TEL_TYPE_MSG
const TEL_TYPE_MODEM
const ADR_TYPE_WORK
const EMAIL_TYPE_x400
const TEL_TYPE_ISDN
const TEL_TYPE_FAX
const TEL_TYPE_VIDEO
const ADR_TYPE_PREF
const TEL_TYPE_CELL
const ADR_TYPE_HOME
const TEL_TYPE_BBS
const ADR_TYPE_DOM
const TEL_TYPE_CAR
const TEL_TYPE_VOICE
const ADR_TYPE_POSTAL
const EMAIL_TYPE_PREF
const ADR_TYPE_PARCEL
const TEL_TYPE_PREF
const TEL_TYPE_WORK
const TEL_TYPE_PAGER
const EMAIL_TYPE_INTERNET
static getLogger($a_component_id)
Get component logger.
setPhoto($photo, $type="")
Sets the value for the vCard PHOTO type.
setFormattedName($formatted_name)
Sets the value for the vCard FN type.
setRevision($revision_date="")
Sets the value for the vCard REV type.
fold($string="", $length=75)
Fold a string according to RFC 2425.
buildVCard()
Builds a vCard string out of the attributes of this object.
setAddress( $po_box="", $extended_address="", $street_address="", $locality="", $region="", $postal_code="", $country="", $type=ADR_TYPE_NONE)
Sets the value for the vCard ADR type.
setLabel($label="", $type=ADR_TYPE_NONE)
Sets the value for the vCard LABEL type.
setLogo($logo, $type="")
Sets the value for the vCard LOGO type.
setNickname($nickname)
Sets the value for the vCard NICKNAME type.
setSortString($string="")
Sets the value for the vCard SORT-STRING type.
encode($string)
Encode data with "b" type encoding according to RFC 2045.
setName($family_name, $given_name="", $additional_names="", $honorific_prefixes="", $honorific_suffixes="")
Sets the value for the vCard N type.
setClassification($classification="")
Sets the value for the vCard CLASS type.
setPosition($latitude="", $longitude="")
Sets the value for the vCard GEO type.
$types
An array containing the vCard types.
setTimezone($zone="")
Sets the value for the vCard TZ type.
setProductId($product_id="")
Sets the value for the vCard PRODID type.
setOrganization($organization="")
Sets the value for the vCard ORG type.
setSound($sound="", $type="")
Sets the value for the vCard SOUND type.
& explodeVar($variable, $separator=",")
Splits a variable into an array using a separator and escapes every value.
setPhone($number="", $type=TEL_TYPE_VOICE)
Sets the value for the vCard TEL type.
setAgent($agent="")
Sets the value for the vCard AGENT type.
setNote($note="")
Sets the value for the vCard NOTE type.
setVersion($version="3.0")
Sets the value for the vCard VERSION type.
ilvCard($version="3.0")
ilvCard Constructor
setBirthday($year, $month, $day)
Sets the value for the vCard BDAY type.
setURL($uri="")
Sets the value for the vCard URL type.
setKey($key="", $type="")
Sets the value for the vCard KEY type.
quoted_printable_encode($input, $line_max=76)
Creates a quoted printable encoded string according to RFC 2045.
$filename
The filename of the vCard used when saving the vCard.
setEmail($address="", $type=EMAIL_TYPE_INTERNET)
Sets the value for the vCard EMAIL type.
setRole($role="")
Sets the value for the vCard ROLE type.
setTitle($title="")
Sets the value for the vCard TITLE type.
setUID($uid="", $type="")
Sets the value for the vCard UID type.
escape($string)
Escapes a string according to RFC 2426.
setMailer($name="")
Sets the value for the vCard MAILER type.
setCategories($categories)
Sets the value for the vCard CATEGORIES type.
$separator
$url
Definition: shib_logout.php:72