• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilvCard.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00038 define ("ADR_TYPE_NONE",   0);
00039 define ("ADR_TYPE_DOM",    1);
00040 define ("ADR_TYPE_INTL",   2);
00041 define ("ADR_TYPE_POSTAL", 4);
00042 define ("ADR_TYPE_PARCEL", 8);
00043 define ("ADR_TYPE_HOME",  16);
00044 define ("ADR_TYPE_WORK",  32);
00045 define ("ADR_TYPE_PREF",  64);
00046 
00052 define ("TEL_TYPE_NONE",     0);
00053 define ("TEL_TYPE_HOME",     1);
00054 define ("TEL_TYPE_MSG",      2);
00055 define ("TEL_TYPE_WORK",     4);
00056 define ("TEL_TYPE_PREF",     8);
00057 define ("TEL_TYPE_VOICE",   16);
00058 define ("TEL_TYPE_FAX",     32);
00059 define ("TEL_TYPE_CELL",    64);
00060 define ("TEL_TYPE_VIDEO",  128);
00061 define ("TEL_TYPE_PAGER",  256);
00062 define ("TEL_TYPE_BBS",    512);
00063 define ("TEL_TYPE_MODEM", 1024);
00064 define ("TEL_TYPE_CAR",   2048);
00065 define ("TEL_TYPE_ISDN",  4096);
00066 define ("TEL_TYPE_PCS",   8192);
00067 
00073 define ("EMAIL_TYPE_NONE",     0);
00074 define ("EMAIL_TYPE_INTERNET", 1);
00075 define ("EMAIL_TYPE_x400",     2);
00076 define ("EMAIL_TYPE_PREF",     4);
00077 
00078 class ilvCard 
00079 {
00085         var $types;
00086 
00092         var $filename;
00093         
00099         function ilvCard($version = "3.0")
00100         {
00101                 $this->types = array(
00102                         "FN" => "",
00103                         "N" => "",
00104                         "NICKNAME" => "",
00105                         "PHOTO" => array(),
00106                         "BDAY" => "",
00107                         "ADR" => array(),
00108                         "LABEL" => array(),
00109                         "TEL" => array(),
00110                         "EMAIL" => array(),
00111                         "MAILER" => "",
00112                         "TZ" => "",
00113                         "GEO" => "",
00114                         "TITLE" => "",
00115                         "ROLE" => "",
00116                         "LOGO" => array(),
00117                         "AGENT" => "",
00118                         "ORG" => "",
00119                         "CATEGORIES" => "",
00120                         "NOTE" => "",
00121                         "PRODID" => "",
00122                         "REV" => "",
00123                         "SORT-STRING" => "",
00124                         "SOUND" => array(),
00125                         "UID" => "",
00126                         "URL" => "",
00127                         "VERSION" => "3.0",
00128                         "CLASS" => "",
00129                         "KEY" => array()
00130                 );
00131                 $this->types["VERSION"] = $version;
00132         }
00133         
00143         function encode($string) 
00144         {
00145                 return escape(quoted_printable_encode($string));
00146         }
00147         
00158         function fold($string = "", $length = 75)
00159         {
00160                 $folded_string = "";
00161                 preg_match_all("/(.{1,74})/", $string, $matches);
00162                 for ($i = 0; $i < count($matches[1]); $i++)
00163                 {
00164                         if ($i < (count($matches[1])-1))
00165                         {
00166                                 $matches[1][$i] .= "\n";
00167                         }
00168                         if ($i > 0)
00169                         {
00170                                 $matches[1][$i] = " " . $matches[1][$i];
00171                         }
00172                         $folded_string .= $matches[1][$i];
00173                 }
00174                 return $folded_string;
00175         }
00176         
00186         function escape($string) 
00187         {
00188                 $string = preg_replace("/(?<!\\\\)(\\\\)([^;,n\\\\])/", "\${1}\${1}\${2}", $string);
00189                 $string = preg_replace("/(?<!\\\\);/", "\\;", $string);
00190                 $string = preg_replace("/(?<!\\\\),/", "\\,", $string);
00191                 $string = preg_replace("/\n/","\\n", $string);
00192                 return $string;
00193         }
00194         
00205         function &explodeVar($variable, $separator = ",") 
00206         {
00207                 $exploded = explode($separator, $variable);
00208                 foreach ($exploded as $index => $var)
00209                 {
00210                         $exploded[$index] = $this->escape($var);
00211                 }
00212                 return $exploded;
00213         }
00214         
00223         function buildVCard()
00224         {
00225                 $vcard = "BEGIN:VCARD\n";
00226                 $vcard .= "VERSION:" . $this->types["VERSION"] . "\n";
00227                 foreach ($this->types as $type => $var)
00228                 {
00229                         switch ($type)
00230                         {
00231                                 case "FN":
00232                                         if (strcmp($this->types["FN"], "") != 0)
00233                                         {
00234                                                 $fn = $this->fold("FN:" . $this->types["FN"]) . "\n";
00235                                         }
00236                                         else
00237                                         {
00238                                                 $fn = "";
00239                                         }
00240                                         break;
00241                                 case "N":
00242                                         if (strcmp($this->types["N"], "") != 0)
00243                                         {
00244                                                 $n = $this->fold("N:" . $this->types["N"]) . "\n";
00245                                         }
00246                                         else
00247                                         {
00248                                                 $n = "";
00249                                         }
00250                                         break;
00251                                 case "NICKNAME":
00252                                         if (strcmp($this->types["NICKNAME"], "") != 0)
00253                                         {
00254                                                 $nickname = $this->fold("NICKNAME:" . $this->types["NICKNAME"]) . "\n";
00255                                         }
00256                                         else
00257                                         {
00258                                                 $nickname = "";
00259                                         }
00260                                         break;
00261                                 case "PHOTO":
00262                                         if (strcmp($this->types["PHOTO"]["VALUE"], "") != 0)
00263                                         {
00264                                                 $photo = $this->fold("PHOTO;VALUE=uri:" . $this->types["PHOTO"]["VALUE"]) . "\n";
00265                                         }
00266                                         elseif (strcmp($this->types["PHOTO"]["ENCODING"], "") != 0)
00267                                         {
00268                                                 $photo = "PHOTO;ENCODING=" . $this->types["PHOTO"]["ENCODING"];
00269                                                 if (strcmp($this->types["PHOTO"]["TYPE"], "") != 0)
00270                                                 {
00271                                                         $photo .= ";TYPE=" . $this->types["PHOTO"]["TYPE"];
00272                                                 }
00273                                                 $photo .= ":" . $this->types["PHOTO"]["PHOTO"];
00274                                                 $photo = $this->fold($photo) . "\n";
00275                                         }
00276                                         else
00277                                         {
00278                                                 $photo = "";
00279                                         }
00280                                         break;
00281                                 case "BDAY":
00282                                         if (strcmp($this->types["BDAY"], "") != 0)
00283                                         {
00284                                                 $bday = $this->fold("BDAY:" . $this->types["BDAY"]) . "\n";
00285                                         }
00286                                         else
00287                                         {
00288                                                 $bday = "";
00289                                         }
00290                                         break;
00291                                 case "ADR":
00292                                         if (count($this->types["ADR"]))
00293                                         {
00294                                                 $addresses = "";
00295                                                 foreach ($this->types["ADR"] as $key => $address)
00296                                                 {
00297                                                         $test = "";
00298                                                         foreach ($address as $str)
00299                                                         {
00300                                                                 $test .= $str;
00301                                                         }
00302                                                         if (strcmp($test, "") != 0)
00303                                                         {
00304                                                                 $adr = "ADR";
00305                                                                 $adr_types = array();
00306                                                                 if ($address["TYPE"] > 0)
00307                                                                 {
00308                                                                         if (($address["TYPE"] & ADR_TYPE_DOM) > 0)
00309                                                                         {
00310                                                                                 array_push($adr_types, "dom");
00311                                                                         }
00312                                                                         if (($address["TYPE"] & ADR_TYPE_INTL) > 0)
00313                                                                         {
00314                                                                                 array_push($adr_types, "intl");
00315                                                                         }
00316                                                                         if (($address["TYPE"] & ADR_TYPE_POSTAL) > 0)
00317                                                                         {
00318                                                                                 array_push($adr_types, "postal");
00319                                                                         }
00320                                                                         if (($address["TYPE"] & ADR_TYPE_PARCEL) > 0)
00321                                                                         {
00322                                                                                 array_push($adr_types, "parcel");
00323                                                                         }
00324                                                                         if (($address["TYPE"] & ADR_TYPE_HOME) > 0)
00325                                                                         {
00326                                                                                 array_push($adr_types, "home");
00327                                                                         }
00328                                                                         if (($address["TYPE"] & ADR_TYPE_WORK) > 0)
00329                                                                         {
00330                                                                                 array_push($adr_types, "work");
00331                                                                         }
00332                                                                         if (($address["TYPE"] & ADR_TYPE_PREF) > 0)
00333                                                                         {
00334                                                                                 array_push($adr_types, "pref");
00335                                                                         }
00336                                                                         $adr .= ";TYPE=" . join(",", $adr_types);
00337                                                                 }
00338                                                                 $adr .= ":" . $address["POBOX"] . ";" . $address["EXTENDED_ADDRESS"] .
00339                                                                         ";" . $address["STREET_ADDRESS"] . ";" . $address["LOCALITY"] .
00340                                                                         ";" . $address["REGION"] . ";" . $address["POSTAL_CODE"] .
00341                                                                         ";" . $address["COUNTRY"];
00342                                                                 $adr = $this->fold($adr) . "\n";
00343                                                                 $addresses .= $adr;
00344                                                         }
00345                                                 }
00346                                                 $adr = $addresses;
00347                                         }
00348                                         else
00349                                         {
00350                                                 $adr = "";
00351                                         }
00352                                         break;
00353                                 case "LABEL":
00354                                         if (strcmp($this->types["LABEL"]["LABEL"], "") != 0)
00355                                         {
00356                                                 $label = "LABEL";
00357                                                 $adr_types = array();
00358                                                 if ($this->types["LABEL"]["TYPE"] > 0)
00359                                                 {
00360                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_DOM) > 0)
00361                                                         {
00362                                                                 array_push($adr_types, "dom");
00363                                                         }
00364                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_INTL) > 0)
00365                                                         {
00366                                                                 array_push($adr_types, "intl");
00367                                                         }
00368                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_POSTAL) > 0)
00369                                                         {
00370                                                                 array_push($adr_types, "postal");
00371                                                         }
00372                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PARCEL) > 0)
00373                                                         {
00374                                                                 array_push($adr_types, "parcel");
00375                                                         }
00376                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_HOME) > 0)
00377                                                         {
00378                                                                 array_push($adr_types, "home");
00379                                                         }
00380                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_WORK) > 0)
00381                                                         {
00382                                                                 array_push($adr_types, "work");
00383                                                         }
00384                                                         if (($this->types["LABEL"]["TYPE"] & ADR_TYPE_PREF) > 0)
00385                                                         {
00386                                                                 array_push($adr_types, "pref");
00387                                                         }
00388                                                         $label .= ";TYPE=" . join(",", $adr_types);
00389                                                 }
00390                                                 $label .= ":" . $this->types["LABEL"]["LABEL"];
00391                                                 $label = $this->fold($label) . "\n";
00392                                         }
00393                                         else
00394                                         {
00395                                                 $label = "";
00396                                         }
00397                                         break;
00398                                 case "TEL":
00399                                         if (count($this->types["TEL"]))
00400                                         {
00401                                                 $phonenumbers = "";
00402                                                 foreach ($this->types["TEL"] as $key => $phone)
00403                                                 {
00404                                                         if (strcmp($phone["TEL"], "") != 0)
00405                                                         {
00406                                                                 $tel = "TEL";
00407                                                                 $tel_types = array();
00408                                                                 if ($phone["TYPE"] > 0)
00409                                                                 {
00410                                                                         if (($phone["TYPE"] & TEL_TYPE_HOME) > 0)
00411                                                                         {
00412                                                                                 array_push($tel_types, "home");
00413                                                                         }
00414                                                                         if (($phone["TYPE"] & TEL_TYPE_MSG) > 0)
00415                                                                         {
00416                                                                                 array_push($tel_types, "msg");
00417                                                                         }
00418                                                                         if (($phone["TYPE"] & TEL_TYPE_WORK) > 0)
00419                                                                         {
00420                                                                                 array_push($tel_types, "work");
00421                                                                         }
00422                                                                         if (($phone["TYPE"] & TEL_TYPE_PREF) > 0)
00423                                                                         {
00424                                                                                 array_push($tel_types, "pref");
00425                                                                         }
00426                                                                         if (($phone["TYPE"] & TEL_TYPE_VOICE) > 0)
00427                                                                         {
00428                                                                                 array_push($tel_types, "voice");
00429                                                                         }
00430                                                                         if (($phone["TYPE"] & TEL_TYPE_FAX) > 0)
00431                                                                         {
00432                                                                                 array_push($tel_types, "fax");
00433                                                                         }
00434                                                                         if (($phone["TYPE"] & TEL_TYPE_CELL) > 0)
00435                                                                         {
00436                                                                                 array_push($tel_types, "cell");
00437                                                                         }
00438                                                                         if (($phone["TYPE"] & TEL_TYPE_VIDEO) > 0)
00439                                                                         {
00440                                                                                 array_push($tel_types, "video");
00441                                                                         }
00442                                                                         if (($phone["TYPE"] & TEL_TYPE_PAGER) > 0)
00443                                                                         {
00444                                                                                 array_push($tel_types, "pager");
00445                                                                         }
00446                                                                         if (($phone["TYPE"] & TEL_TYPE_BBS) > 0)
00447                                                                         {
00448                                                                                 array_push($tel_types, "bbs");
00449                                                                         }
00450                                                                         if (($phone["TYPE"] & TEL_TYPE_MODEM) > 0)
00451                                                                         {
00452                                                                                 array_push($tel_types, "modem");
00453                                                                         }
00454                                                                         if (($phone["TYPE"] & TEL_TYPE_CAR) > 0)
00455                                                                         {
00456                                                                                 array_push($tel_types, "car");
00457                                                                         }
00458                                                                         if (($phone["TYPE"] & TEL_TYPE_ISDN) > 0)
00459                                                                         {
00460                                                                                 array_push($tel_types, "isdn");
00461                                                                         }
00462                                                                         if (($phone["TYPE"] & TEL_TYPE_PCS) > 0)
00463                                                                         {
00464                                                                                 array_push($tel_types, "pcs");
00465                                                                         }
00466                                                                         $tel .= ";TYPE=" . join(",", $tel_types);
00467                                                                 }
00468                                                                 $tel .= ":" . $phone["TEL"];
00469                                                                 $tel = $this->fold($tel) . "\n";
00470                                                                 $phonenumbers .= $tel;
00471                                                         }
00472                                                 }
00473                                                 $tel = $phonenumbers;
00474                                         }
00475                                         else
00476                                         {
00477                                                 $tel = "";
00478                                         }
00479                                         break;
00480                                 case "EMAIL":
00481                                         if (count($this->types["EMAIL"]))
00482                                         {
00483                                                 $emails = "";
00484                                                 foreach ($this->types["EMAIL"] as $key => $mail)
00485                                                 {
00486                                                         if (strcmp($mail["EMAIL"], "") != 0)
00487                                                         {
00488                                                                 $email = "EMAIL";
00489                                                                 $adr_types = array();
00490                                                                 if ($mail["TYPE"] > 0)
00491                                                                 {
00492                                                                         if (($mail["TYPE"] & EMAIL_TYPE_INTERNET) > 0)
00493                                                                         {
00494                                                                                 array_push($adr_types, "internet");
00495                                                                         }
00496                                                                         if (($mail["TYPE"] & EMAIL_TYPE_x400) > 0)
00497                                                                         {
00498                                                                                 array_push($adr_types, "x400");
00499                                                                         }
00500                                                                         if (($mail["TYPE"] & EMAIL_TYPE_PREF) > 0)
00501                                                                         {
00502                                                                                 array_push($adr_types, "pref");
00503                                                                         }
00504                                                                         $email .= ";TYPE=" . join(",", $adr_types);
00505                                                                 }
00506                                                                 $email .= ":" . $mail["EMAIL"];
00507                                                                 $email = $this->fold($email) . "\n";
00508                                                                 $emails .= $email;
00509                                                         }
00510                                                 }
00511                                                 $email = $emails;
00512                                         }
00513                                         else
00514                                         {
00515                                                 $email = "";
00516                                         }
00517                                         break;
00518                                 case "MAILER":
00519                                         if (strcmp($this->types["MAILER"], "") != 0)
00520                                         {
00521                                                 $mailer = $this->fold("MAILER:" . $this->types["MAILER"]) . "\n";
00522                                         }
00523                                         else
00524                                         {
00525                                                 $mailer = "";
00526                                         }
00527                                         break;
00528                                 case "TZ":
00529                                         if (strcmp($this->types["TZ"], "") != 0)
00530                                         {
00531                                                 $tz = $this->fold("TZ:" . $this->types["TZ"]) . "\n";
00532                                         }
00533                                         else
00534                                         {
00535                                                 $tz = "";
00536                                         }
00537                                         break;
00538                                 case "GEO":
00539                                         if ((strcmp($this->types["GEO"]["LAT"], "") != 0) and (strcmp($this->types["GEO"]["LON"], "") != 0))
00540                                         {
00541                                                 $geo = $this->fold("GEO:" . $this->types["GEO"]["LAT"] . ";" . $this->types["GEO"]["LON"]) . "\n";
00542                                         }
00543                                         else
00544                                         {
00545                                                 $geo = "";
00546                                         }
00547                                         break;
00548                                 case "TITLE":
00549                                         if (strcmp($this->types["TITLE"], "") != 0)
00550                                         {
00551                                                 $title = $this->fold("TITLE:" . $this->types["TITLE"]) . "\n";
00552                                         }
00553                                         else
00554                                         {
00555                                                 $title = "";
00556                                         }
00557                                         break;
00558                                 case "ROLE":
00559                                         if (strcmp($this->types["ROLE"], "") != 0)
00560                                         {
00561                                                 $role = $this->fold("ROLE:" . $this->types["ROLE"]) . "\n";
00562                                         }
00563                                         else
00564                                         {
00565                                                 $role = "";
00566                                         }
00567                                         break;
00568                                 case "LOGO":
00569                                         if (strcmp($this->types["LOGO"]["VALUE"], "") != 0)
00570                                         {
00571                                                 $logo = $this->fold("LOGO;VALUE=uri:" . $this->types["LOGO"]["VALUE"]) . "\n";
00572                                         }
00573                                         elseif (strcmp($this->types["LOGO"]["ENCODING"], "") != 0)
00574                                         {
00575                                                 $logo = "LOGO;ENCODING=" . $this->types["LOGO"]["ENCODING"];
00576                                                 if (strcmp($this->types["LOGO"]["TYPE"], "") != 0)
00577                                                 {
00578                                                         $logo .= ";TYPE=" . $this->types["LOGO"]["TYPE"];
00579                                                 }
00580                                                 $logo .= ":" . $this->types["LOGO"]["LOGO"];
00581                                                 $logo = $this->fold($logo) . "\n";
00582                                         }
00583                                         else
00584                                         {
00585                                                 $logo = "";
00586                                         }
00587                                         break;
00588                                 case "AGENT":
00589                                         if (strcmp($this->types["AGENT"], "") != 0)
00590                                         {
00591                                                 $agent = $this->fold("AGENT:" . $this->types["AGENT"]) . "\n";
00592                                         }
00593                                         else
00594                                         {
00595                                                 $agent = "";
00596                                         }
00597                                         break;
00598                                 case "ORG":
00599                                         if (strcmp($this->types["ORG"], "") != 0)
00600                                         {
00601                                                 $org = $this->fold("ORG:" . $this->types["ORG"]) . "\n";
00602                                         }
00603                                         else
00604                                         {
00605                                                 $org = "";
00606                                         }
00607                                         break;
00608                                 case "CATEGORIES":
00609                                         if (strcmp($this->types["CATEGORIES"], "") != 0)
00610                                         {
00611                                                 $categories = $this->fold("CATEGORIES:" . $this->types["CATEGORIES"]) . "\n";
00612                                         }
00613                                         else
00614                                         {
00615                                                 $categories = "";
00616                                         }
00617                                         break;
00618                                 case "NOTE":
00619                                         if (strcmp($this->types["NOTE"], "") != 0)
00620                                         {
00621                                                 $note = $this->fold("NOTE:" . $this->types["NOTE"]) . "\n";
00622                                         }
00623                                         else
00624                                         {
00625                                                 $note = "";
00626                                         }
00627                                         break;
00628                                 case "PRODID":
00629                                         if (strcmp($this->types["PRODID"], "") != 0)
00630                                         {
00631                                                 $prodid = $this->fold("PRODID:" . $this->types["PRODID"]) . "\n";
00632                                         }
00633                                         else
00634                                         {
00635                                                 $prodid = "";
00636                                         }
00637                                         break;
00638                                 case "REV":
00639                                         if (strcmp($this->types["REV"], "") != 0)
00640                                         {
00641                                                 $rev = $this->fold("REV:" . $this->types["REV"]) . "\n";
00642                                         }
00643                                         else
00644                                         {
00645                                                 $rev = "";
00646                                         }
00647                                         break;
00648                                 case "SORT-STRING":
00649                                         if (strcmp($this->types["SORT-STRING"], "") != 0)
00650                                         {
00651                                                 $sortstring = $this->fold("SORT-STRING:" . $this->types["SORT-STRING"]) . "\n";
00652                                         }
00653                                         else
00654                                         {
00655                                                 $sortstring = "";
00656                                         }
00657                                         break;
00658                                 case "SOUND":
00659                                         if (strcmp($this->types["SOUND"]["VALUE"], "") != 0)
00660                                         {
00661                                                 $sound = $this->fold("SOUND;VALUE=uri:" . $this->types["SOUND"]["VALUE"]) . "\n";
00662                                         }
00663                                         elseif (strcmp($this->types["SOUND"]["ENCODING"], "") != 0)
00664                                         {
00665                                                 $sound = "SOUND;ENCODING=" . $this->types["SOUND"]["ENCODING"];
00666                                                 if (strcmp($this->types["SOUND"]["TYPE"], "") != 0)
00667                                                 {
00668                                                         $sound .= ";TYPE=" . $this->types["SOUND"]["TYPE"];
00669                                                 }
00670                                                 $sound .= ":" . $this->types["SOUND"]["SOUND"];
00671                                                 $sound = $this->fold($sound) . "\n";
00672                                         }
00673                                         else
00674                                         {
00675                                                 $sound = "";
00676                                         }
00677                                         break;
00678                                 case "UID":
00679                                         if (strcmp($this->types["UID"]["UID"], "") != 0)
00680                                         {
00681                                                 $uid = "UID";
00682                                                 if (strcmp($this->types["UID"]["TYPE"], "") != 0)
00683                                                 {
00684                                                         $uid .= ";TYPE=" . $this->types["UID"]["TYPE"];
00685                                                 }
00686                                                 $uid .= ":" . $this->types["UID"]["UID"];
00687                                                 $uid = $this->fold($uid) . "\n";
00688                                         }
00689                                         else
00690                                         {
00691                                                 $uid = "";
00692                                         }
00693                                         break;
00694                                 case "URL":
00695                                         if (strcmp($this->types["URL"], "") != 0)
00696                                         {
00697                                                 $url = $this->fold("URL:" . $this->types["URL"]) . "\n";
00698                                         }
00699                                         else
00700                                         {
00701                                                 $url = "";
00702                                         }
00703                                         break;
00704                                 case "KEY":
00705                                         if (strcmp($this->types["KEY"]["KEY"], "") != 0)
00706                                         {
00707                                                 $key = "KEY";
00708                                                 if (strcmp($this->types["KEY"]["TYPE"], "") != 0)
00709                                                 {
00710                                                         $key .= ";TYPE=" . $this->types["KEY"]["TYPE"];
00711                                                 }
00712                                                 if (strcmp($this->types["KEY"]["ENCODING"], "") != 0)
00713                                                 {
00714                                                         $key .= ";ENCODING=" . $this->types["KEY"]["ENCODING"];
00715                                                 }
00716                                                 $key .= ":" . $this->types["KEY"]["KEY"];
00717                                                 $key = $this->fold($key) . "\n";
00718                                         }
00719                                         else
00720                                         {
00721                                                 $key = "";
00722                                         }
00723                                         break;
00724                                 case "CLASS":
00725                                         if (strcmp($this->types["CLASS"], "") != 0)
00726                                         {
00727                                                 $class = $this->fold("CLASS:" . $this->types["CLASS"]) . "\n";
00728                                         }
00729                                         else
00730                                         {
00731                                                 $class = "";
00732                                         }
00733                                         break;
00734                         }
00735                 }
00736                 $vcard .= $fn.$n.$nickname.$photo.$bday.$adr.$label.$tel.$email.$mailer.
00737                         $tz.$geo.$title.$role.$logo.$agent.$org.$categories.$note.$prodid.
00738                         $rev.$sortstring.$sound.$uid.$url.$class.$key;
00739                 $vcard .= "END:vCard\n";
00740                 return $vcard;
00741         }
00742         
00754         function quoted_printable_encode($input, $line_max = 76) {
00755                 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
00756                 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
00757                 $eol = "\r\n";
00758                 $linebreak = "=0D=0A";
00759                 $escape = "=";
00760                 $output = "";
00761         
00762                 for ($j=0;$j<count($lines);$j++) {
00763                         $line = $lines[$j];
00764                         $linlen = strlen($line);
00765                         $newline = "";
00766                         for($i = 0; $i < $linlen; $i++) {
00767                                 $c = substr($line, $i, 1);
00768                                 $dec = ord($c);
00769                                 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
00770                                         $c = "=20"; 
00771                                 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
00772                                         $h2 = floor($dec/16); $h1 = floor($dec%16); 
00773                                         $c = $escape.$hex["$h2"].$hex["$h1"]; 
00774                                 }
00775                                 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
00776                                         $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
00777                                         $newline = "    ";
00778                                 }
00779                                 $newline .= $c;
00780                         } // end of for
00781                         $output .= $newline;
00782                         if ($j<count($lines)-1) $output .= $linebreak;
00783                 }
00784                 return trim($output);
00785         }
00786 
00787 // Identification Types
00788 //
00789 // These types are used in the vCard profile to capture information
00790 // associated with the identification and naming of the person or
00791 // resource associated with the vCard.
00792         
00807         function setFormattedName($formatted_name)
00808         {
00809                 $this->types["FN"] = $this->escape($formatted_name);
00810         }
00811 
00841         function setName($family_name, $given_name = "", $additional_names = "", $honorific_prefixes = "", $honorific_suffixes = "")
00842         {
00843                 $familynames =& $this->explodeVar($family_name);
00844                 $givennames =& $this->explodeVar($given_name);
00845                 $addnames =& $this->explodeVar($additional_names);
00846                 $prefixes =& $this->explodeVar($honorific_prefixes);
00847                 $suffixes =& $this->explodeVar($honorific_suffixes);
00848 
00849                 $this->types["N"] = 
00850                         join(",", $familynames) .
00851                         ";" .
00852                         join(",", $givennames) .
00853                         ";" . 
00854                         join(",", $addnames) .
00855                         ";" .
00856                         join(",", $prefixes) .
00857                         ";" .
00858                         join(",", $suffixes);
00859 
00860                 $this->filename = "$given_name" . "_" . "$family_name" . ".vcf";
00861                 if (strcmp($this->types["FN"], "") == 0)
00862                 {
00863                         $fn = trim("$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
00864                         $fn = preg_replace("/\s{2,10}/", " ", $fn);
00865                         $this->setFormattedName($fn);
00866                 }
00867         }
00868 
00889         function setNickname($nickname)
00890         {
00891                 $nicknames =& $this->explodeVar($nickname);
00892                 $this->types["NICKNAME"] = join(",", $nicknames);
00893         }
00894         
00930         function setPhoto($photo, $type = "")
00931         {
00932                 $value = "";
00933                 $encoding = "";
00934                 if (preg_match("/^http/", $photo))
00935                 {
00936                         $value = $this->encode($photo);
00937                 }
00938                 else
00939                 {
00940                         $encoding = "b";
00941                         $photo = base64_encode($photo);
00942                 }
00943                 $this->types["PHOTO"] = array(
00944                         "VALUE" => $value,
00945                         "TYPE" => $type,
00946                         "ENCODING" => $encoding,
00947                         "PHOTO" => $photo
00948                 );
00949         }
00950 
00971         function setBirthday($year, $month, $day)
00972         {
00973                 if (($year < 1) or ($day < 1) or ($month < 1))
00974                 {
00975                         $this->types["BDAY"] = "";
00976                 }
00977                 else
00978                 {
00979                         $this->types["BDAY"] = sprintf("%04d-%02d-%02d", $year, $month, $day);
00980                 }
00981         }
00982         
00983 // Delivery Addressing Types
00984 //
00985 // These types are concerned with information related to the delivery
00986 // addressing or label for the vCard object.
00987 
01042         function setAddress(
01043                 $po_box = "",
01044                 $extended_address = "",
01045                 $street_address = "",
01046                 $locality = "",
01047                 $region = "",
01048                 $postal_code = "",
01049                 $country = "",
01050                 $type = ADR_TYPE_NONE
01051         )
01052         {
01053                 if ($type == ADR_TYPE_NONE)
01054                 {
01055                         $type = ADR_TYPE_INTL + ADR_TYPE_POSTAL + ADR_TYPE_PARCEL + ADR_TYPE_WORK;
01056                 }
01057                 $po_box = join(",", $this->explodeVar($po_box));
01058                 $extended_address = join(",", $this->explodeVar($extended_address));
01059                 $street_address = join(",", $this->explodeVar($street_address));
01060                 $locality = join(",", $this->explodeVar($locality));
01061                 $region = join(",", $this->explodeVar($region));
01062                 $postal_code = join(",", $this->explodeVar($postal_code));
01063                 $country = join(",", $this->explodeVar($country));
01064                 array_push($this->types["ADR"], array(
01065                         "POBOX" => $po_box,
01066                         "EXTENDED_ADDRESS" => $extended_address,
01067                         "STREET_ADDRESS" => $street_address,
01068                         "LOCALITY" => $locality,
01069                         "REGION" => $region,
01070                         "POSTAL_CODE" => $postal_code,
01071                         "COUNTRY" => $country,
01072                         "TYPE" => $type
01073                 ));
01074         }
01075         
01112         function setLabel($label = "", $type = ADR_TYPE_NONE)
01113         {
01114                 if ($type == ADR_TYPE_NONE)
01115                 {
01116                         $type = ADR_TYPE_INTL + ADR_TYPE_POSTAL+ ADR_TYPE_PARCEL + ADR_TYPE_WORK;
01117                 }
01118                 $this->types["LABEL"] = array(
01119                         "LABEL" => $this->escape($label),
01120                         "TYPE" => $type
01121                 );
01122         }
01123 
01124 // Telecommunications Addressing Types
01125 //
01126 // These types are concerned with information associated with the
01127 // telecommunications addressing of the object the vCard represents.
01128         
01171         function setPhone($number = "", $type = TEL_TYPE_VOICE)
01172         {
01173                 array_push($this->types["TEL"], array(
01174                         "TEL" => $this->escape($number),
01175                         "TYPE" => $type
01176                 ));
01177         }
01178         
01205         function setEmail($address = "", $type = EMAIL_TYPE_INTERNET)
01206         {
01207                 array_push($this->types["EMAIL"], array(
01208                         "EMAIL" => $this->escape($address),
01209                         "TYPE" => $type
01210                 ));
01211         }
01212         
01233         function setMailer($name = "")
01234         {
01235                 $this->types["MAILER"] = $this->escape($name);
01236         }
01237         
01238 // Geographical Types
01239 //
01240 // These types are concerned with information associated with
01241 // geographical positions or regions associated with the object the
01242 // vCard represents.
01243 
01261         function setTimezone($zone = "")
01262         {
01263                 $this->types["TZ"] = $this->escape($zone);
01264         }
01265         
01300         function setPosition($latitude = "", $longitude = "")
01301         {
01302                 $this->types["GEO"] = array(
01303                         "LAT" => $latitude,
01304                         "LON" => $longitude
01305                 );
01306         }
01307         
01308 // Organizational Types
01309 //
01310 // These types are concerned with information associated with
01311 // characteristics of the organization or organizational units of the
01312 // object the vCard represents.
01313 
01330         function setTitle($title = "")
01331         {
01332                 $this->types["TITLE"] = $this->escape($title);
01333         }
01334         
01355         function setRole($role = "")
01356         {
01357                 $this->types["ROLE"] = $this->escape($role);
01358         }
01359         
01393         function setLogo($logo, $type = "")
01394         {
01395                 $value = "";
01396                 $encoding = "";
01397                 if (preg_match("/^http/", $logo))
01398                 {
01399                         $value = $this->encode($logo);
01400                 }
01401                 else
01402                 {
01403                         $encoding = "b";
01404                         $logo = base64_encode($logo);
01405                 }
01406                 $this->types["LOGO"] = array(
01407                         "VALUE" => $value,
01408                         "TYPE" => $type,
01409                         "ENCODING" => $encoding,
01410                         "LOGO" => $logo
01411                 );
01412         }
01413         
01441         function setAgent($agent = "")
01442         {
01443                 $this->types["AGENT"] = $this->escape($agent);
01444         }
01445         
01467         function setOrganization($organization = "")
01468         {
01469                 $organization = join(";", $this->explodeVar($organization, ";"));
01470                 $this->types["ORG"] = $organization;
01471         }
01472         
01473 // Explanatory Types
01474 //
01475 // These types are concerned with additional explanations, such as that
01476 // related to informational notes or revisions specific to the vCard.
01477 
01495         function setCategories($categories)
01496         {
01497                 $categories = join(",", $this->explodeVar($categories));
01498                 $this->types["CATEGORIES"] = $categories;
01499         }
01500         
01520         function setNote($note = "")
01521         {
01522                 $this->types["NOTE"] = $this->escape($note);
01523         }
01524         
01544         function setProductId($product_id = "")
01545         {
01546                 $this->types["PRODID"] = $this->escape($product_id);
01547         }
01548         
01570         function setRevision($revision_date = "")
01571         {
01572                 $this->types["REV"] = $this->escape($revision_date);
01573         }
01574         
01618         function setSortString($string = "")
01619         {
01620                 $this->types["SORT-STRING"] = $this->escape($string);
01621         }
01622         
01658         function setSound($sound = "", $type = "")
01659         {
01660                 $value = "";
01661                 $encoding = "";
01662                 if (preg_match("/^http/", $sound))
01663                 {
01664                         $value = $this->encode($sound);
01665                 }
01666                 else
01667                 {
01668                         $encoding = "b";
01669                         $sound = base64_encode($sound);
01670                 }
01671                 $this->types["SOUND"] = array(
01672                         "VALUE" => $value,
01673                         "TYPE" => $type,
01674                         "ENCODING" => $encoding,
01675                         "SOUND" => $sound
01676                 );
01677         }
01678         
01705         function setUID($uid = "", $type = "")
01706         {
01707                 $this->types["UID"] = array(
01708                         "UID" => $this->escape($uid),
01709                         "TYPE" => $type
01710                 );
01711         }
01712         
01729         function setURL($uri = "")
01730         {
01731                 $this->types["URL"] = $this->escape($uri);
01732         }
01733         
01750         function setVersion($version = "3.0")
01751         {
01752                 $this->types["VERSION"] = $version;
01753         }
01754         
01755 // Security Types
01756 //
01757 // These types are concerned with the security of communication pathways
01758 // or access to the vCard.
01759 
01783         function setClassification($classification = "")
01784         {
01785                 $this->types["CLASS"] = $this->escape($classification);
01786         }
01787         
01832         function setKey($key = "", $type = "")
01833         {
01834                 $encoding = "b";
01835                 $key = base64_encode($key);
01836                 $this->types["KEY"] = array(
01837                         "KEY" => $key,
01838                         "TYPE" => $type,
01839                         "ENCODING" => $encoding
01840                 );
01841         }
01842         
01843         function getFilename()
01844         {
01845                 if (strcmp($this->filename, "") == 0)
01846                 {
01847                         return "vcard.vcf";
01848                 }
01849                 else
01850                 {
01851                         return $this->filename;
01852                 }
01853         }
01854         
01855         function getMimetype()
01856         {
01857                 return "text/x-vcard";
01858         }
01859 }
01860 
01861 ?>

Generated on Fri Dec 13 2013 09:06:35 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1