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

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

Generated on Fri Dec 13 2013 17:57:02 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1