ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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 switch ($type)
229 {
230 case "FN":
231 if (strcmp($this->types["FN"], "") != 0)
232 {
233 $fn = $this->fold("FN:" . $this->types["FN"]) . "\n";
234 }
235 else
236 {
237 $fn = "";
238 }
239 break;
240 case "N":
241 if (strcmp($this->types["N"], "") != 0)
242 {
243 $n = $this->fold("N:" . $this->types["N"]) . "\n";
244 }
245 else
246 {
247 $n = "";
248 }
249 break;
250 case "NICKNAME":
251 if (strcmp($this->types["NICKNAME"], "") != 0)
252 {
253 $nickname = $this->fold("NICKNAME:" . $this->types["NICKNAME"]) . "\n";
254 }
255 else
256 {
257 $nickname = "";
258 }
259 break;
260 case "PHOTO":
261 $photo = "";
262 if (is_array($this->types["PHOTO"]))
263 {
264 if (strcmp($this->types["PHOTO"]["VALUE"], "") != 0)
265 {
266 $photo = $this->fold("PHOTO;VALUE=uri:" . $this->types["PHOTO"]["VALUE"]) . "\n";
267 }
268 elseif (strcmp($this->types["PHOTO"]["ENCODING"], "") != 0)
269 {
270 $photo = "PHOTO;ENCODING=" . $this->types["PHOTO"]["ENCODING"];
271 if (strcmp($this->types["PHOTO"]["TYPE"], "") != 0)
272 {
273 $photo .= ";TYPE=" . $this->types["PHOTO"]["TYPE"];
274 }
275 $photo .= ":" . $this->types["PHOTO"]["PHOTO"];
276 $photo = $this->fold($photo) . "\n";
277 }
278 }
279 break;
280 case "BDAY":
281 if (strcmp($this->types["BDAY"], "") != 0)
282 {
283 $bday = $this->fold("BDAY:" . $this->types["BDAY"]) . "\n";
284 }
285 else
286 {
287 $bday = "";
288 }
289 break;
290 case "ADR":
291 if (count($this->types["ADR"]))
292 {
293 $addresses = "";
294 foreach ($this->types["ADR"] as $key => $address)
295 {
296 $test = "";
297 foreach ($address as $str)
298 {
299 $test .= $str;
300 }
301 if (strcmp($test, "") != 0)
302 {
303 $adr = "ADR";
304 $adr_types = array();
305 if ($address["TYPE"] > 0)
306 {
307 if (($address["TYPE"] & ADR_TYPE_DOM) > 0)
308 {
309 array_push($adr_types, "dom");
310 }
311 if (($address["TYPE"] & ADR_TYPE_INTL) > 0)
312 {
313 array_push($adr_types, "intl");
314 }
315 if (($address["TYPE"] & ADR_TYPE_POSTAL) > 0)
316 {
317 array_push($adr_types, "postal");
318 }
319 if (($address["TYPE"] & ADR_TYPE_PARCEL) > 0)
320 {
321 array_push($adr_types, "parcel");
322 }
323 if (($address["TYPE"] & ADR_TYPE_HOME) > 0)
324 {
325 array_push($adr_types, "home");
326 }
327 if (($address["TYPE"] & ADR_TYPE_WORK) > 0)
328 {
329 array_push($adr_types, "work");
330 }
331 if (($address["TYPE"] & ADR_TYPE_PREF) > 0)
332 {
333 array_push($adr_types, "pref");
334 }
335 $adr .= ";TYPE=" . join(",", $adr_types);
336 }
337 $adr .= ":" . $address["POBOX"] . ";" . $address["EXTENDED_ADDRESS"] .
338 ";" . $address["STREET_ADDRESS"] . ";" . $address["LOCALITY"] .
339 ";" . $address["REGION"] . ";" . $address["POSTAL_CODE"] .
340 ";" . $address["COUNTRY"];
341 $adr = $this->fold($adr) . "\n";
342 $addresses .= $adr;
343 }
344 }
345 $adr = $addresses;
346 }
347 else
348 {
349 $adr = "";
350 }
351 break;
352 case "LABEL":
353 $label = "";
354 if (is_array($this->types["LABEL"]))
355 {
356 if (strcmp($this->types["LABEL"]["LABEL"], "") != 0)
357 {
358 $label = "LABEL";
359 $adr_types = array();
360 if ($this->types["LABEL"]["TYPE"] > 0)
361 {
362 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_DOM) > 0)
363 {
364 array_push($adr_types, "dom");
365 }
366 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_INTL) > 0)
367 {
368 array_push($adr_types, "intl");
369 }
370 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_POSTAL) > 0)
371 {
372 array_push($adr_types, "postal");
373 }
374 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PARCEL) > 0)
375 {
376 array_push($adr_types, "parcel");
377 }
378 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_HOME) > 0)
379 {
380 array_push($adr_types, "home");
381 }
382 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_WORK) > 0)
383 {
384 array_push($adr_types, "work");
385 }
386 if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PREF) > 0)
387 {
388 array_push($adr_types, "pref");
389 }
390 $label .= ";TYPE=" . join(",", $adr_types);
391 }
392 $label .= ":" . $this->types["LABEL"]["LABEL"];
393 $label = $this->fold($label) . "\n";
394 }
395 }
396 break;
397 case "TEL":
398 if (count($this->types["TEL"]))
399 {
400 $phonenumbers = "";
401 foreach ($this->types["TEL"] as $key => $phone)
402 {
403 if (strcmp($phone["TEL"], "") != 0)
404 {
405 $tel = "TEL";
406 $tel_types = array();
407 if ($phone["TYPE"] > 0)
408 {
409 if (($phone["TYPE"] & TEL_TYPE_HOME) > 0)
410 {
411 array_push($tel_types, "home");
412 }
413 if (($phone["TYPE"] & TEL_TYPE_MSG) > 0)
414 {
415 array_push($tel_types, "msg");
416 }
417 if (($phone["TYPE"] & TEL_TYPE_WORK) > 0)
418 {
419 array_push($tel_types, "work");
420 }
421 if (($phone["TYPE"] & TEL_TYPE_PREF) > 0)
422 {
423 array_push($tel_types, "pref");
424 }
425 if (($phone["TYPE"] & TEL_TYPE_VOICE) > 0)
426 {
427 array_push($tel_types, "voice");
428 }
429 if (($phone["TYPE"] & TEL_TYPE_FAX) > 0)
430 {
431 array_push($tel_types, "fax");
432 }
433 if (($phone["TYPE"] & TEL_TYPE_CELL) > 0)
434 {
435 array_push($tel_types, "cell");
436 }
437 if (($phone["TYPE"] & TEL_TYPE_VIDEO) > 0)
438 {
439 array_push($tel_types, "video");
440 }
441 if (($phone["TYPE"] & TEL_TYPE_PAGER) > 0)
442 {
443 array_push($tel_types, "pager");
444 }
445 if (($phone["TYPE"] & TEL_TYPE_BBS) > 0)
446 {
447 array_push($tel_types, "bbs");
448 }
449 if (($phone["TYPE"] & TEL_TYPE_MODEM) > 0)
450 {
451 array_push($tel_types, "modem");
452 }
453 if (($phone["TYPE"] & TEL_TYPE_CAR) > 0)
454 {
455 array_push($tel_types, "car");
456 }
457 if (($phone["TYPE"] & TEL_TYPE_ISDN) > 0)
458 {
459 array_push($tel_types, "isdn");
460 }
461 if (($phone["TYPE"] & TEL_TYPE_PCS) > 0)
462 {
463 array_push($tel_types, "pcs");
464 }
465 $tel .= ";TYPE=" . join(",", $tel_types);
466 }
467 $tel .= ":" . $phone["TEL"];
468 $tel = $this->fold($tel) . "\n";
469 $phonenumbers .= $tel;
470 }
471 }
472 $tel = $phonenumbers;
473 }
474 else
475 {
476 $tel = "";
477 }
478 break;
479 case "EMAIL":
480 if (count($this->types["EMAIL"]))
481 {
482 $emails = "";
483 foreach ($this->types["EMAIL"] as $key => $mail)
484 {
485 if (strcmp($mail["EMAIL"], "") != 0)
486 {
487 $email = "EMAIL";
488 $adr_types = array();
489 if ($mail["TYPE"] > 0)
490 {
491 if (($mail["TYPE"] & EMAIL_TYPE_INTERNET) > 0)
492 {
493 array_push($adr_types, "internet");
494 }
495 if (($mail["TYPE"] & EMAIL_TYPE_x400) > 0)
496 {
497 array_push($adr_types, "x400");
498 }
499 if (($mail["TYPE"] & EMAIL_TYPE_PREF) > 0)
500 {
501 array_push($adr_types, "pref");
502 }
503 $email .= ";TYPE=" . join(",", $adr_types);
504 }
505 $email .= ":" . $mail["EMAIL"];
506 $email = $this->fold($email) . "\n";
507 $emails .= $email;
508 }
509 }
510 $email = $emails;
511 }
512 else
513 {
514 $email = "";
515 }
516 break;
517 case "MAILER":
518 if (strcmp($this->types["MAILER"], "") != 0)
519 {
520 $mailer = $this->fold("MAILER:" . $this->types["MAILER"]) . "\n";
521 }
522 else
523 {
524 $mailer = "";
525 }
526 break;
527 case "TZ":
528 if (strcmp($this->types["TZ"], "") != 0)
529 {
530 $tz = $this->fold("TZ:" . $this->types["TZ"]) . "\n";
531 }
532 else
533 {
534 $tz = "";
535 }
536 break;
537 case "GEO":
538 if (is_array($this->types["GEO"]) and
539 (strcmp($this->types["GEO"]["LAT"], "") != 0) and
540 (strcmp($this->types["GEO"]["LON"], "") != 0))
541 {
542 $geo = $this->fold("GEO:" . $this->types["GEO"]["LAT"] . ";" . $this->types["GEO"]["LON"]) . "\n";
543 }
544 else
545 {
546 $geo = "";
547 }
548 break;
549 case "TITLE":
550 if (strcmp($this->types["TITLE"], "") != 0)
551 {
552 $title = $this->fold("TITLE:" . $this->types["TITLE"]) . "\n";
553 }
554 else
555 {
556 $title = "";
557 }
558 break;
559 case "ROLE":
560 if (strcmp($this->types["ROLE"], "") != 0)
561 {
562 $role = $this->fold("ROLE:" . $this->types["ROLE"]) . "\n";
563 }
564 else
565 {
566 $role = "";
567 }
568 break;
569 case "LOGO":
570 $logo = "";
571 if (is_array($this->types["LOGO"]))
572 {
573 if (strcmp($this->types["LOGO"]["VALUE"], "") != 0)
574 {
575 $logo = $this->fold("LOGO;VALUE=uri:" . $this->types["LOGO"]["VALUE"]) . "\n";
576 }
577 elseif (strcmp($this->types["LOGO"]["ENCODING"], "") != 0)
578 {
579 $logo = "LOGO;ENCODING=" . $this->types["LOGO"]["ENCODING"];
580 if (strcmp($this->types["LOGO"]["TYPE"], "") != 0)
581 {
582 $logo .= ";TYPE=" . $this->types["LOGO"]["TYPE"];
583 }
584 $logo .= ":" . $this->types["LOGO"]["LOGO"];
585 $logo = $this->fold($logo) . "\n";
586 }
587 }
588 break;
589 case "AGENT":
590 if (strcmp($this->types["AGENT"], "") != 0)
591 {
592 $agent = $this->fold("AGENT:" . $this->types["AGENT"]) . "\n";
593 }
594 else
595 {
596 $agent = "";
597 }
598 break;
599 case "ORG":
600 if (strcmp($this->types["ORG"], "") != 0)
601 {
602 $org = $this->fold("ORG:" . $this->types["ORG"]) . "\n";
603 }
604 else
605 {
606 $org = "";
607 }
608 break;
609 case "CATEGORIES":
610 if (strcmp($this->types["CATEGORIES"], "") != 0)
611 {
612 $categories = $this->fold("CATEGORIES:" . $this->types["CATEGORIES"]) . "\n";
613 }
614 else
615 {
616 $categories = "";
617 }
618 break;
619 case "NOTE":
620 if (strcmp($this->types["NOTE"], "") != 0)
621 {
622 $note = $this->fold("NOTE:" . $this->types["NOTE"]) . "\n";
623 }
624 else
625 {
626 $note = "";
627 }
628 break;
629 case "PRODID":
630 if (strcmp($this->types["PRODID"], "") != 0)
631 {
632 $prodid = $this->fold("PRODID:" . $this->types["PRODID"]) . "\n";
633 }
634 else
635 {
636 $prodid = "";
637 }
638 break;
639 case "REV":
640 if (strcmp($this->types["REV"], "") != 0)
641 {
642 $rev = $this->fold("REV:" . $this->types["REV"]) . "\n";
643 }
644 else
645 {
646 $rev = "";
647 }
648 break;
649 case "SORT-STRING":
650 if (strcmp($this->types["SORT-STRING"], "") != 0)
651 {
652 $sortstring = $this->fold("SORT-STRING:" . $this->types["SORT-STRING"]) . "\n";
653 }
654 else
655 {
656 $sortstring = "";
657 }
658 break;
659 case "SOUND":
660 $sound = "";
661 if (is_array($this->types["SOUND"]))
662 {
663 if (strcmp($this->types["SOUND"]["VALUE"], "") != 0)
664 {
665 $sound = $this->fold("SOUND;VALUE=uri:" . $this->types["SOUND"]["VALUE"]) . "\n";
666 }
667 elseif (strcmp($this->types["SOUND"]["ENCODING"], "") != 0)
668 {
669 $sound = "SOUND;ENCODING=" . $this->types["SOUND"]["ENCODING"];
670 if (strcmp($this->types["SOUND"]["TYPE"], "") != 0)
671 {
672 $sound .= ";TYPE=" . $this->types["SOUND"]["TYPE"];
673 }
674 $sound .= ":" . $this->types["SOUND"]["SOUND"];
675 $sound = $this->fold($sound) . "\n";
676 }
677 }
678 break;
679 case "UID":
680 $uid = "";
681 if (is_array($this->types["UID"]))
682 {
683 if (strcmp($this->types["UID"]["UID"], "") != 0)
684 {
685 $uid = "UID";
686 if (strcmp($this->types["UID"]["TYPE"], "") != 0)
687 {
688 $uid .= ";TYPE=" . $this->types["UID"]["TYPE"];
689 }
690 $uid .= ":" . $this->types["UID"]["UID"];
691 $uid = $this->fold($uid) . "\n";
692 }
693 }
694 break;
695 case "URL":
696 if (strcmp($this->types["URL"], "") != 0)
697 {
698 $url = $this->fold("URL:" . $this->types["URL"]) . "\n";
699 }
700 else
701 {
702 $url = "";
703 }
704 break;
705 case "KEY":
706 $key = "";
707 if (is_array($this->types["KEY"]))
708 {
709 if (strcmp($this->types["KEY"]["KEY"], "") != 0)
710 {
711 $key = "KEY";
712 if (strcmp($this->types["KEY"]["TYPE"], "") != 0)
713 {
714 $key .= ";TYPE=" . $this->types["KEY"]["TYPE"];
715 }
716 if (strcmp($this->types["KEY"]["ENCODING"], "") != 0)
717 {
718 $key .= ";ENCODING=" . $this->types["KEY"]["ENCODING"];
719 }
720 $key .= ":" . $this->types["KEY"]["KEY"];
721 $key = $this->fold($key) . "\n";
722 }
723 }
724 break;
725 case "CLASS":
726 if (strcmp($this->types["CLASS"], "") != 0)
727 {
728 $class = $this->fold("CLASS:" . $this->types["CLASS"]) . "\n";
729 }
730 else
731 {
732 $class = "";
733 }
734 break;
735 }
736 }
737 $vcard .= $fn.$n.$nickname.$photo.$bday.$adr.$label.$tel.$email.$mailer.
738 $tz.$geo.$title.$role.$logo.$agent.$org.$categories.$note.$prodid.
739 $rev.$sortstring.$sound.$uid.$url.$class.$key;
740 $vcard .= "END:vCard\n";
741 return $vcard;
742 }
743
755 function quoted_printable_encode($input, $line_max = 76) {
756 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
757 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
758 $eol = "\r\n";
759 $linebreak = "=0D=0A";
760 $escape = "=";
761 $output = "";
762
763 for ($j=0;$j<count($lines);$j++) {
764 $line = $lines[$j];
765 $linlen = strlen($line);
766 $newline = "";
767 for($i = 0; $i < $linlen; $i++) {
768 $c = substr($line, $i, 1);
769 $dec = ord($c);
770 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
771 $c = "=20";
772 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
773 $h2 = floor($dec/16); $h1 = floor($dec%16);
774 $c = $escape.$hex["$h2"].$hex["$h1"];
775 }
776 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
777 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
778 $newline = " ";
779 }
780 $newline .= $c;
781 } // end of for
782 $output .= $newline;
783 if ($j<count($lines)-1) $output .= $linebreak;
784 }
785 return trim($output);
786 }
787
788// Identification Types
789//
790// These types are used in the vCard profile to capture information
791// associated with the identification and naming of the person or
792// resource associated with the vCard.
793
808 function setFormattedName($formatted_name)
809 {
810 $this->types["FN"] = $this->escape($formatted_name);
811 }
812
842 function setName($family_name, $given_name = "", $additional_names = "", $honorific_prefixes = "", $honorific_suffixes = "")
843 {
844 $familynames =& $this->explodeVar($family_name);
845 $givennames =& $this->explodeVar($given_name);
846 $addnames =& $this->explodeVar($additional_names);
847 $prefixes =& $this->explodeVar($honorific_prefixes);
848 $suffixes =& $this->explodeVar($honorific_suffixes);
849
850 $this->types["N"] =
851 join(",", $familynames) .
852 ";" .
853 join(",", $givennames) .
854 ";" .
855 join(",", $addnames) .
856 ";" .
857 join(",", $prefixes) .
858 ";" .
859 join(",", $suffixes);
860
861 $this->filename = "$given_name" . "_" . "$family_name" . ".vcf";
862 if (strcmp($this->types["FN"], "") == 0)
863 {
864 $fn = trim("$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
865 $fn = preg_replace("/\s{2,10}/", " ", $fn);
866 $this->setFormattedName($fn);
867 }
868 }
869
890 function setNickname($nickname)
891 {
892 $nicknames =& $this->explodeVar($nickname);
893 $this->types["NICKNAME"] = join(",", $nicknames);
894 }
895
931 function setPhoto($photo, $type = "")
932 {
933 $value = "";
934 $encoding = "";
935 if (preg_match("/^http/", $photo))
936 {
937 $value = $this->encode($photo);
938 }
939 else
940 {
941 $encoding = "b";
942 $photo = base64_encode($photo);
943 }
944 $this->types["PHOTO"] = array(
945 "VALUE" => $value,
946 "TYPE" => $type,
947 "ENCODING" => $encoding,
948 "PHOTO" => $photo
949 );
950 }
951
972 function setBirthday($year, $month, $day)
973 {
974 if (($year < 1) or ($day < 1) or ($month < 1))
975 {
976 $this->types["BDAY"] = "";
977 }
978 else
979 {
980 $this->types["BDAY"] = sprintf("%04d-%02d-%02d", $year, $month, $day);
981 }
982 }
983
984// Delivery Addressing Types
985//
986// These types are concerned with information related to the delivery
987// addressing or label for the vCard object.
988
1043 function setAddress(
1044 $po_box = "",
1045 $extended_address = "",
1046 $street_address = "",
1047 $locality = "",
1048 $region = "",
1049 $postal_code = "",
1050 $country = "",
1051 $type = ADR_TYPE_NONE
1052 )
1053 {
1054 if ($type == ADR_TYPE_NONE)
1055 {
1057 }
1058 $po_box = join(",", $this->explodeVar($po_box));
1059 $extended_address = join(",", $this->explodeVar($extended_address));
1060 $street_address = join(",", $this->explodeVar($street_address));
1061 $locality = join(",", $this->explodeVar($locality));
1062 $region = join(",", $this->explodeVar($region));
1063 $postal_code = join(",", $this->explodeVar($postal_code));
1064 $country = join(",", $this->explodeVar($country));
1065 array_push($this->types["ADR"], array(
1066 "POBOX" => $po_box,
1067 "EXTENDED_ADDRESS" => $extended_address,
1068 "STREET_ADDRESS" => $street_address,
1069 "LOCALITY" => $locality,
1070 "REGION" => $region,
1071 "POSTAL_CODE" => $postal_code,
1072 "COUNTRY" => $country,
1073 "TYPE" => $type
1074 ));
1075 }
1076
1113 function setLabel($label = "", $type = ADR_TYPE_NONE)
1114 {
1115 if ($type == ADR_TYPE_NONE)
1116 {
1118 }
1119 $this->types["LABEL"] = array(
1120 "LABEL" => $this->escape($label),
1121 "TYPE" => $type
1122 );
1123 }
1124
1125// Telecommunications Addressing Types
1126//
1127// These types are concerned with information associated with the
1128// telecommunications addressing of the object the vCard represents.
1129
1172 function setPhone($number = "", $type = TEL_TYPE_VOICE)
1173 {
1174 array_push($this->types["TEL"], array(
1175 "TEL" => $this->escape($number),
1176 "TYPE" => $type
1177 ));
1178 }
1179
1206 function setEmail($address = "", $type = EMAIL_TYPE_INTERNET)
1207 {
1208 array_push($this->types["EMAIL"], array(
1209 "EMAIL" => $this->escape($address),
1210 "TYPE" => $type
1211 ));
1212 }
1213
1234 function setMailer($name = "")
1235 {
1236 $this->types["MAILER"] = $this->escape($name);
1237 }
1238
1239// Geographical Types
1240//
1241// These types are concerned with information associated with
1242// geographical positions or regions associated with the object the
1243// vCard represents.
1244
1262 function setTimezone($zone = "")
1263 {
1264 $this->types["TZ"] = $this->escape($zone);
1265 }
1266
1301 function setPosition($latitude = "", $longitude = "")
1302 {
1303 $this->types["GEO"] = array(
1304 "LAT" => $latitude,
1305 "LON" => $longitude
1306 );
1307 }
1308
1309// Organizational Types
1310//
1311// These types are concerned with information associated with
1312// characteristics of the organization or organizational units of the
1313// object the vCard represents.
1314
1331 function setTitle($title = "")
1332 {
1333 $this->types["TITLE"] = $this->escape($title);
1334 }
1335
1356 function setRole($role = "")
1357 {
1358 $this->types["ROLE"] = $this->escape($role);
1359 }
1360
1394 function setLogo($logo, $type = "")
1395 {
1396 $value = "";
1397 $encoding = "";
1398 if (preg_match("/^http/", $logo))
1399 {
1400 $value = $this->encode($logo);
1401 }
1402 else
1403 {
1404 $encoding = "b";
1405 $logo = base64_encode($logo);
1406 }
1407 $this->types["LOGO"] = array(
1408 "VALUE" => $value,
1409 "TYPE" => $type,
1410 "ENCODING" => $encoding,
1411 "LOGO" => $logo
1412 );
1413 }
1414
1442 function setAgent($agent = "")
1443 {
1444 $this->types["AGENT"] = $this->escape($agent);
1445 }
1446
1468 function setOrganization($organization = "")
1469 {
1470 $organization = join(";", $this->explodeVar($organization, ";"));
1471 $this->types["ORG"] = $organization;
1472 }
1473
1474// Explanatory Types
1475//
1476// These types are concerned with additional explanations, such as that
1477// related to informational notes or revisions specific to the vCard.
1478
1496 function setCategories($categories)
1497 {
1498 $categories = join(",", $this->explodeVar($categories));
1499 $this->types["CATEGORIES"] = $categories;
1500 }
1501
1521 function setNote($note = "")
1522 {
1523 $this->types["NOTE"] = $this->escape($note);
1524 }
1525
1545 function setProductId($product_id = "")
1546 {
1547 $this->types["PRODID"] = $this->escape($product_id);
1548 }
1549
1571 function setRevision($revision_date = "")
1572 {
1573 $this->types["REV"] = $this->escape($revision_date);
1574 }
1575
1619 function setSortString($string = "")
1620 {
1621 $this->types["SORT-STRING"] = $this->escape($string);
1622 }
1623
1659 function setSound($sound = "", $type = "")
1660 {
1661 $value = "";
1662 $encoding = "";
1663 if (preg_match("/^http/", $sound))
1664 {
1665 $value = $this->encode($sound);
1666 }
1667 else
1668 {
1669 $encoding = "b";
1670 $sound = base64_encode($sound);
1671 }
1672 $this->types["SOUND"] = array(
1673 "VALUE" => $value,
1674 "TYPE" => $type,
1675 "ENCODING" => $encoding,
1676 "SOUND" => $sound
1677 );
1678 }
1679
1706 function setUID($uid = "", $type = "")
1707 {
1708 $this->types["UID"] = array(
1709 "UID" => $this->escape($uid),
1710 "TYPE" => $type
1711 );
1712 }
1713
1730 function setURL($uri = "")
1731 {
1732 $this->types["URL"] = $this->escape($uri);
1733 }
1734
1751 function setVersion($version = "3.0")
1752 {
1753 $this->types["VERSION"] = $version;
1754 }
1755
1756// Security Types
1757//
1758// These types are concerned with the security of communication pathways
1759// or access to the vCard.
1760
1784 function setClassification($classification = "")
1785 {
1786 $this->types["CLASS"] = $this->escape($classification);
1787 }
1788
1833 function setKey($key = "", $type = "")
1834 {
1835 $encoding = "b";
1836 $key = base64_encode($key);
1837 $this->types["KEY"] = array(
1838 "KEY" => $key,
1839 "TYPE" => $type,
1840 "ENCODING" => $encoding
1841 );
1842 }
1843
1844 function getFilename()
1845 {
1846 if (strcmp($this->filename, "") == 0)
1847 {
1848 return "vcard.vcf";
1849 }
1850 else
1851 {
1852 return $this->filename;
1853 }
1854 }
1855
1856 function getMimetype()
1857 {
1858 return "text/x-vcard";
1859 }
1860}
1861
1862?>
$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
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