function testVCardAddress2LabelParsing()
 {
     // Data
     include "export.vcard/testdata_label2adr.php";
     foreach ($tests as $test) {
         $expected = $test['output'];
         $result = label2adr($test['input']);
         $diff = array_merge(array_diff($expected, $result), array_diff($result, $expected));
         // $this->assert($expected, $result, "gaga");
         $this->assertTrue(count($diff) == 0);
     }
 }
 /**
  * Returns the actual SyncXXX object type.
  *
  * @param string            $folderid           id of the parent folder
  * @param string            $id                 id of the message
  * @param ContentParameters $contentparameters  parameters of the requested message (truncation, mimesupport etc)
  *
  * @access public
  * @return object/false     false if the message could not be retrieved
  */
 public function GetMessage($folderid, $id, $contentparameters)
 {
     global $db, $base_from_where, $domain_id;
     ZLog::Write(LOGLEVEL_DEBUG, 'PhpAddr::GetMessage(' . $folderid . ', ' . $id . ', ..)');
     if ($folderid != "root") {
         return false;
     }
     $types = array('dom' => 'type', 'intl' => 'type', 'postal' => 'type', 'parcel' => 'type', 'home' => 'type', 'work' => 'type', 'pref' => 'type', 'voice' => 'type', 'fax' => 'type', 'msg' => 'type', 'cell' => 'type', 'pager' => 'type', 'bbs' => 'type', 'modem' => 'type', 'car' => 'type', 'isdn' => 'type', 'video' => 'type', 'aol' => 'type', 'applelink' => 'type', 'attmail' => 'type', 'cis' => 'type', 'eworld' => 'type', 'internet' => 'type', 'ibmmail' => 'type', 'mcimail' => 'type', 'powershare' => 'type', 'prodigy' => 'type', 'tlx' => 'type', 'x400' => 'type', 'gif' => 'type', 'cgm' => 'type', 'wmf' => 'type', 'bmp' => 'type', 'met' => 'type', 'pmb' => 'type', 'dib' => 'type', 'pict' => 'type', 'tiff' => 'type', 'pdf' => 'type', 'ps' => 'type', 'jpeg' => 'type', 'qtime' => 'type', 'mpeg' => 'type', 'mpeg2' => 'type', 'avi' => 'type', 'wave' => 'type', 'aiff' => 'type', 'pcm' => 'type', 'x509' => 'type', 'pgp' => 'type', 'text' => 'value', 'inline' => 'value', 'url' => 'value', 'cid' => 'value', 'content-id' => 'value', '7bit' => 'encoding', '8bit' => 'encoding', 'quoted-printable' => 'encoding', 'base64' => 'encoding');
     $message = new SyncContact();
     $sql = "SELECT * FROM {$base_from_where} AND id = " . intval($id);
     $result = mysql_query($sql);
     $addr = mysql_fetch_array($result);
     if (isset($addr['email'])) {
         $message->email1address = $addr['email'];
     }
     if (isset($addr['email2'])) {
         $message->email2address = $addr['email2'];
     }
     if (isset($addr['email3'])) {
         $message->email3address = $addr['email3'];
     }
     if (isset($addr['address']) && trim($addr['address']) != "") {
         $addr_parts = label2adr($addr['address']);
         $message->homestreet = $addr_parts['street'] . " " . $addr_parts['street_nr'];
         $message->homecity = $addr_parts['city'];
         $message->homepostalcode = $addr_parts['zip'];
         // $message->homestate  = ?;
         $message->homecountry = $addr_parts['country'];
     }
     if (isset($addr['address2']) && trim($addr['address2']) != "") {
         $addr_parts = label2adr($addr['address2']);
         $message->businessstreet = $addr_parts['street'] . " " . $addr_parts['street_nr'];
         $message->businesscity = $addr_parts['city'];
         $message->businesspostalcode = $addr_parts['zip'];
         // $message->businessstate  = ?;
         $message->businesscountry = $addr_parts['country'];
     }
     /*
     if(isset($vcard['tel'])){
         foreach($vcard['tel'] as $tel) {
             if(!isset($tel['type'])){
                 $tel['type'] = array();
             }
             if(in_array('car', $tel['type'])){
                 $message->carphonenumber = $tel['val'][0];
             }elseif(in_array('pager', $tel['type'])){
                 $message->pagernumber = $tel['val'][0];
             }elseif(in_array('cell', $tel['type'])){
                 $message->mobilephonenumber = $tel['val'][0];
             }elseif(in_array('home', $tel['type'])){
                 if(in_array('fax', $tel['type'])){
                     $message->homefaxnumber = $tel['val'][0];
                 }elseif(empty($message->homephonenumber)){
                     $message->homephonenumber = $tel['val'][0];
                 }else{
                     $message->home2phonenumber = $tel['val'][0];
                 }
             }elseif(in_array('work', $tel['type'])){
                 if(in_array('fax', $tel['type'])){
                     $message->businessfaxnumber = $tel['val'][0];
                 }elseif(empty($message->businessphonenumber)){
                     $message->businessphonenumber = $tel['val'][0];
                 }else{
                     $message->business2phonenumber = $tel['val'][0];
                 }
             }elseif(empty($message->homephonenumber)){
                 $message->homephonenumber = $tel['val'][0];
             }elseif(empty($message->home2phonenumber)){
                 $message->home2phonenumber = $tel['val'][0];
             }else{
                 $message->radiophonenumber = $tel['val'][0];
             }
         }
     }
     //;;street;city;state;postalcode;country
     if(isset($vcard['adr'])){
         foreach($vcard['adr'] as $adr) {
             if(empty($adr['type'])){
                 $a = 'other';
             }elseif(in_array('home', $adr['type'])){
                 $a = 'home';
             }elseif(in_array('work', $adr['type'])){
                 $a = 'business';
             }else{
                 $a = 'other';
             }
             if(!empty($adr['val'][2])){
                 $b=$a.'street';
                 $message->$b = w2ui($adr['val'][2]);
             }
             if(!empty($adr['val'][3])){
                 $b=$a.'city';
                 $message->$b = w2ui($adr['val'][3]);
             }
             if(!empty($adr['val'][4])){
                 $b=$a.'state';
                 $message->$b = w2ui($adr['val'][4]);
             }
             if(!empty($adr['val'][5])){
                 $b=$a.'postalcode';
                 $message->$b = w2ui($adr['val'][5]);
             }
             if(!empty($adr['val'][6])){
                 $b=$a.'country';
                 $message->$b = w2ui($adr['val'][6]);
             }
         }
     }
     */
     $message->fileas = $addr['firstname'] . " " . $addr['lastname'] != "" ? $addr['firstname'] . " " . $addr['lastname'] != "" : $addr['company'];
     $message->lastname = $addr['lastname'];
     $message->firstname = $addr['firstname'];
     $message->nickname = $addr['nickname'];
     $message->jobtitle = $addr['title'];
     $message->companyname = $addr['company'];
     $message->homephonenumber = $addr['home'];
     $message->mobilephonenumber = $addr['mobile'];
     $message->businessphonenumber = $addr['work'];
     $message->businessfaxnumber = $addr['fax'];
     $message->home2phonenumber = $addr['phone2'];
     $message->body = $addr['notes'];
     $message->picture = $addr['photo'];
     if (isset($addr['bday']) && $addr['bday'] != "" && isset($addr['bmonth']) && $addr['bmonth'] != "" && isset($addr['byear']) && $addr['byear'] != "") {
         $message->birthday = strtotime($addr['bday'] . " " . $addr['bmonth'] . " " . $addr['byear']);
     }
     if (isset($addr['aday']) && $addr['aday'] != "" && isset($addr['amonth']) && $addr['amonth'] != "" && isset($addr['ayear']) && $addr['ayear'] != "") {
         $message->anniversary = strtotime($addr['aday'] . " " . $addr['amonth'] . " " . $addr['ayear']);
     }
     // $message->birthday = strtotime($vcard['bday'][0]['val'][0]);
     /*
             if(!empty($vcard['n'][0]['val'][2]))
                 $message->middlename = w2ui($vcard['n'][0]['val'][2]);
             if(!empty($vcard['n'][0]['val'][3]))
                 $message->title = w2ui($vcard['n'][0]['val'][3]);
             if(!empty($vcard['n'][0]['val'][4]))
                 $message->suffix = w2ui($vcard['n'][0]['val'][4]);
             if(!empty($vcard['bday'][0]['val'][0])){
                 $tz = date_default_timezone_get();
                 date_default_timezone_set('UTC');
                 $message->birthday = strtotime($vcard['bday'][0]['val'][0]);
                 date_default_timezone_set($tz);
             }
             if(!empty($vcard['org'][0]['val'][0]))
                 $message->companyname = w2ui($vcard['org'][0]['val'][0]);
             if(!empty($vcard['note'][0]['val'][0])){
                 $message->body = w2ui($vcard['note'][0]['val'][0]);
                 $message->bodysize = strlen($vcard['note'][0]['val'][0]);
                 $message->bodytruncated = 0;
             }
             if(!empty($vcard['role'][0]['val'][0]))
                 $message->jobtitle = w2ui($vcard['role'][0]['val'][0]);//$vcard['title'][0]['val'][0]
             if(!empty($vcard['url'][0]['val'][0]))
                 $message->webpage = w2ui($vcard['url'][0]['val'][0]);
             if(!empty($vcard['categories'][0]['val']))
                 $message->categories = $vcard['categories'][0]['val'];
     
             if(!empty($vcard['photo'][0]['val'][0]))
                 $message->picture = base64_encode($vcard['photo'][0]['val'][0]);
     */
     return $message;
 }
示例#3
0
function address2vcard($links)
{
    $firstname = utf8_to_latin1($links["firstname"]);
    $middlename = utf8_to_latin1($links["middlename"]);
    $lastname = utf8_to_latin1($links["lastname"]);
    $title = utf8_to_latin1($links["title"]);
    $company = utf8_to_latin1($links["company"]);
    $address = utf8_to_latin1($links["address"]);
    $home = utf8_to_latin1($links["home"]);
    $mobile = utf8_to_latin1($links["mobile"]);
    $work = utf8_to_latin1($links["work"]);
    $fax = utf8_to_latin1($links["fax"]);
    $email = utf8_to_latin1($links["email"]);
    $email2 = utf8_to_latin1($links["email2"]);
    $email3 = utf8_to_latin1($links["email3"]);
    $homepage = utf8_to_latin1($links["homepage"]);
    $bday = utf8_to_latin1($links["bday"]);
    $bmonth_num = utf8_to_latin1($links["bmonth_num"]);
    $byear = utf8_to_latin1($links["byear"]);
    $aday = utf8_to_latin1($links["aday"]);
    $amonth_num = utf8_to_latin1($links["amonth_num"]);
    $ayear = utf8_to_latin1($links["ayear"]);
    $phone2 = utf8_to_latin1($links["phone2"]);
    $address2 = utf8_to_latin1($links["address2"]);
    $result = "BEGIN:VCARD\n";
    $result .= "VERSION:2.1\n";
    $result .= "N:" . (!empty($middlename) ? "{$middlename} " : "") . "{$lastname};{$firstname};;;;\n";
    $result .= "FN:{$firstname}" . (!empty($middlename) ? " {$middlename}" : "") . " {$lastname}\n";
    $result .= "ORG:{$company}\n";
    $result .= "TITLE:{$title}\n";
    $adr = label2adr($address);
    $result .= "ADR;home:" . $adr['pbox'] . ";" . $adr['exta'] . ";" . $adr['addr'] . ";" . $adr['city'] . ";" . $adr['region'] . ";" . $adr['zip'] . ";" . $adr['country'] . "\n";
    $adr = label2adr($address2);
    $result .= "ADR;work:" . $adr['pbox'] . ";" . $adr['exta'] . ";" . $adr['addr'] . ";" . $adr['city'] . ";" . $adr['region'] . ";" . $adr['zip'] . ";" . $adr['country'] . "\n";
    $result .= "TEL;HOME;VOICE:{$home}\n";
    $result .= "TEL;cell;VOICE:{$mobile}\n";
    $result .= "TEL;work;VOICE:{$work}\n";
    $result .= "TEL;fax:{$fax}\n";
    $result .= "TEL;voice:{$phone2}\n";
    $result .= "EMAIL;PREF;INTERNET:{$email}\n";
    $result .= "EMAIL;INTERNET:{$email2}\n";
    $result .= "EMAIL;INTERNET:{$email3}\n";
    $result .= "URL;WORK:{$homepage}\n";
    $result .= "BDAY:" . "{$byear}-" . (strlen($bmonth_num) == 1 ? "0" : "") . "{$bmonth_num}-" . (strlen($bday) == 1 ? "0" : "") . "{$bday}\n";
    $result .= "X-ANNIVERSARY:" . "{$ayear}-" . (strlen($amonth_num) == 1 ? "0" : "") . "{$amonth_num}-" . (strlen($aday) == 1 ? "0" : "") . "{$aday}\n";
    $result .= "END:VCARD\n";
    return $result;
}