Last commit broke more than was fixed - this reverts most changes

This commit is contained in:
Miles Lott 2003-12-05 11:17:12 +00:00
parent 67047e145d
commit 2e69a4dfe8

View File

@ -1,9 +1,12 @@
<?php <?php
/**************************************************************************\ /**************************************************************************\
* phpGroupWare API - VCard import/export class * * phpGroupWare API - VCard import/export class *
* This file written by Miles Lott <milos@groupwhere.org> * * This file written by Miles Lott <milosch@phpgroupware.org> *
* Parse vcards->contacts class fields, and vice-versa * * Parse vcards->contacts class fields, and vice-versa *
* Copyright (C) 2001-2004 Miles Lott * * Copyright (C) 2001 Miles Lott *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ * * ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it * * This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by * * under the terms of the GNU Lesser General Public License as published by *
@ -113,7 +116,7 @@
*/ */
function in_file($filename='') function in_file($filename='')
{ {
if(!$filename) if (!$filename)
{ {
return array(); return array();
} }
@ -121,22 +124,22 @@
$buffer = array(); $buffer = array();
$fp = fopen($filename,'r'); $fp = fopen($filename,'r');
while($data = fgets($fp,8000)) while ($data = fgets($fp,8000))
{ {
list($name,$value,$extra) = split(':', $data); list($name,$value,$extra) = split(':', $data);
if(substr($value,0,5) == 'http') if (substr($value,0,5) == 'http')
{ {
$value = $value . ':'.$extra; $value = $value . ':'.$extra;
} }
if($name && $value) if ($name && $value)
{ {
reset($this->import); reset($this->import);
while(list($fname,$fvalue) = each($this->import)) while ( list($fname,$fvalue) = each($this->import) )
{ {
if(strstr(strtolower($name), $this->import[$fname])) if ( strstr(strtolower($name), $this->import[$fname]) )
{ {
$value = trim($value); $value = trim($value);
$value = str_replace('=0D=0A',"\n",$value); $value = ereg_replace("=0D=0A","\n",$value);
$buffer += array($name => $value); $buffer += array($name => $value);
} }
} }
@ -166,7 +169,7 @@
'address3' => 'address3' 'address3' => 'address3'
); );
while(list($fname,$fvalue) = each($all_fields)) while (list($fname,$fvalue) = each($all_fields))
{ {
if($buffer[$fname]) if($buffer[$fname])
{ {
@ -185,37 +188,37 @@
function _parse_in($buffer) function _parse_in($buffer)
{ {
/* Following is a lot of pain and little magic */ /* Following is a lot of pain and little magic */
while(list($name,$value) = @each($buffer)) while ( list($name,$value) = @each($buffer) )
{ {
$field = split(';',$name); $field = split(';',$name);
$field[0] = str_replace("A\.",'',$field[0]); $field[0] = ereg_replace("A\.",'',$field[0]);
$field[0] = str_replace("B\.",'',$field[0]); $field[0] = ereg_replace("B\.",'',$field[0]);
$field[0] = str_replace("C\.",'',$field[0]); $field[0] = ereg_replace("C\.",'',$field[0]);
$field[0] = str_replace("D\.",'',$field[0]); $field[0] = ereg_replace("D\.",'',$field[0]);
$values = split(';',$value); $values = split(';',$value);
if($field[1]) if ($field[1])
{ {
//echo $field[0]; //echo $field[0];
switch($field[0]) switch ($field[0])
{ {
case 'LABEL': case 'LABEL':
$entry['label'] = str_replace('=0D=0A',"\n",$values[0]); $entry['label'] = ereg_replace('=0D=0A',"\n",$values[0]);
break; break;
case 'NOTE': case 'NOTE':
$entry['note'] = str_replace('=0D=0A',"\n",$values[0]); $entry['note'] = ereg_replace('=0D=0A',"\n",$values[0]);
break; break;
case 'ADR': case 'ADR':
switch($field[1]) switch ($field[1])
{ {
case 'INTL': case 'INTL':
switch($field[2]) switch ($field[2])
{ {
case 'WORK': case 'WORK':
if(!stristr($buffer['adr_one_type'],$field[1])) if ( !stristr($buffer['adr_one_type'],$field[1]))
{ {
$entry['adr_one_type'] .= 'intl;'; $entry['adr_one_type'] .= 'intl;';
} }
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -226,11 +229,11 @@
} }
break; break;
case 'HOME': case 'HOME':
if(!stristr($buffer['adr_two_type'],$field[1])) if ( !stristr($buffer['adr_two_type'],$field[1]) )
{ {
$entry['adr_two_type'] .= 'intl;'; $entry['adr_two_type'] .= 'intl;';
} }
if(!$buffer['adr_two_street']) if (!$buffer['adr_two_street'])
{ {
$entry['adr_two_street'] = $values[2]; $entry['adr_two_street'] = $values[2];
$entry['adr_two_locality'] = $values[3]; $entry['adr_two_locality'] = $values[3];
@ -244,14 +247,14 @@
} }
break; break;
case 'DOM': case 'DOM':
switch($field[2]) switch ($field[2])
{ {
case 'WORK': case 'WORK':
if(!stristr($buffer['adr_one_type'],$field[1])) if ( !stristr($buffer['adr_one_type'],$field[1]))
{ {
$entry['adr_one_type'] .= 'dom;'; $entry['adr_one_type'] .= 'dom;';
} }
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -262,11 +265,11 @@
} }
break; break;
case 'HOME': case 'HOME':
if(!stristr($buffer['adr_two_type'],$field[1])) if ( !stristr($buffer['adr_two_type'],$field[1]) )
{ {
$entry['adr_two_type'] .= 'dom;'; $entry['adr_two_type'] .= 'dom;';
} }
if(!$buffer['adr_two_street']) if (!$buffer['adr_two_street'])
{ {
$entry['adr_two_street'] = $values[2]; $entry['adr_two_street'] = $values[2];
$entry['adr_two_locality'] = $values[3]; $entry['adr_two_locality'] = $values[3];
@ -280,14 +283,14 @@
} }
break; break;
case 'PARCEL': case 'PARCEL':
switch($field[2]) switch ($field[2])
{ {
case 'WORK': case 'WORK':
if(!stristr($buffer['adr_one_type'],$field[1])) if ( !stristr($buffer['adr_one_type'],$field[1]))
{ {
$entry['adr_one_type'] .= 'parcel;'; $entry['adr_one_type'] .= 'parcel;';
} }
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -298,11 +301,11 @@
} }
break; break;
case 'HOME': case 'HOME':
if(!stristr($buffer['adr_two_type'],$field[1])) if ( !stristr($buffer['adr_two_type'],$field[1]) )
{ {
$entry['adr_two_type'] .= 'parcel;'; $entry['adr_two_type'] .= 'parcel;';
} }
if(!$buffer['adr_two_street']) if (!$buffer['adr_two_street'])
{ {
$entry['adr_two_street'] = $values[2]; $entry['adr_two_street'] = $values[2];
$entry['adr_two_locality'] = $values[3]; $entry['adr_two_locality'] = $values[3];
@ -316,14 +319,14 @@
} }
break; break;
case 'POSTAL': case 'POSTAL':
switch($field[2]) switch ($field[2])
{ {
case 'WORK': case 'WORK':
if(!stristr($buffer['adr_one_type'],$field[1])) if ( !stristr($buffer['adr_one_type'],$field[1]))
{ {
$entry['adr_one_type'] .= 'postal;'; $entry['adr_one_type'] .= 'postal;';
} }
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -334,11 +337,11 @@
} }
break; break;
case 'HOME': case 'HOME':
if(!stristr($buffer['adr_two_type'],$field[1])) if ( !stristr($buffer['adr_two_type'],$field[1]) )
{ {
$entry['adr_two_type'] .= 'postal;'; $entry['adr_two_type'] .= 'postal;';
} }
if(!$buffer['adr_two_street']) if (!$buffer['adr_two_street'])
{ {
$entry['adr_two_street'] = $values[2]; $entry['adr_two_street'] = $values[2];
$entry['adr_two_locality'] = $values[3]; $entry['adr_two_locality'] = $values[3];
@ -352,7 +355,7 @@
} }
break; break;
case 'WORK': case 'WORK':
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -370,7 +373,7 @@
$entry['adr_two_countryname'] = $values[6]; $entry['adr_two_countryname'] = $values[6];
break; break;
default: default:
if(!$buffer['adr_one_street']) if (!$buffer['adr_one_street'])
{ {
$entry['address2'] = $values[1]; $entry['address2'] = $values[1];
$entry['adr_one_street'] = $values[2]; $entry['adr_one_street'] = $values[2];
@ -383,105 +386,106 @@
} }
break; break;
case 'TEL': // RB 2001/05/07 added for Lotus Organizer ueses TEL;{WORK|HOME};{VOICE|FAX}[;PREF] case 'TEL': // RB 2001/05/07 added for Lotus Organizer ueses TEL;{WORK|HOME};{VOICE|FAX}[;PREF]
if($field[2] == 'FAX' && ($field[1] == 'WORK' || $field[i] == 'HOME')) if ($field[2] == 'FAX' && ($field[1] == 'WORK' || $field[i] == 'HOME'))
{ {
/* TODO This is PHP4 only */
array_shift($field); // --> ignore the WORK or HOME if FAX follows, HOME;FAX and HOME;TEL are maped later array_shift($field); // --> ignore the WORK or HOME if FAX follows, HOME;FAX and HOME;TEL are maped later
} }
switch($field[1]) switch ($field[1])
{ {
case 'PREF': case 'PREF':
//echo $field[2].' is preferred'; //echo $field[2].' is preferred';
if($field[2]) if ($field[2])
{ {
$buffer['tel_prefer'] .= strtolower($field[2]) . ';'; $buffer['tel_prefer'] .= strtolower($field[2]) . ';';
} }
break; break;
case 'WORK': // RB don't overwrite TEL;WORK;VOICE (main nr.) with TEL;WORK, TEL;WORK --> tel_isdn case 'WORK': // RB don't overwrite TEL;WORK;VOICE (main nr.) with TEL;WORK, TEL;WORK --> tel_isdn
$entry[$buffer['tel_work'] ? 'tel_isdn' : 'tel_work'] = $values[0]; $entry[$buffer['tel_work'] ? 'tel_isdn' : 'tel_work'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'HOME': // RB don't overwrite TEL;HOME;VOICE (main nr.) with TEL;HOME, TEL;HOME --> ophone case 'HOME': // RB don't overwrite TEL;HOME;VOICE (main nr.) with TEL;HOME, TEL;HOME --> ophone
$entry[$buffer['tel_home'] ? 'ophone' : 'tel_home' ] = $values[0]; $entry[$buffer['tel_home'] ? 'ophone' : 'tel_home' ] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'VOICE': case 'VOICE':
$entry['tel_voice'] = $values[0]; $entry['tel_voice'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'FAX': case 'FAX':
if($entry['tel_fax']) if ($entry['tel_fax'])
{ {
// RB don't overwrite TEL;WORK;FAX with TEL;HOME;FAX, TEL;HOME;FAX --> ophone // RB don't overwrite TEL;WORK;FAX with TEL;HOME;FAX, TEL;HOME;FAX --> ophone
$entry['ophone'] = $values[0] . ' Fax'; $entry['ophone'] = $values[0] . ' Fax';
break; break;
} }
$entry['tel_fax'] = $values[0]; $entry['tel_fax'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'MSG': case 'MSG':
$entry['tel_msg'] = $values[0]; $entry['tel_msg'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'CELL': case 'CELL':
$entry['tel_cell'] = $values[0]; $entry['tel_cell'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'PAGER': case 'PAGER':
$entry['tel_pager'] = $values[0]; $entry['tel_pager'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'BBS': case 'BBS':
$entry['tel_bbs'] = $values[0]; $entry['tel_bbs'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'MODEM': case 'MODEM':
$entry['tel_modem'] = $values[0]; $entry['tel_modem'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'CAR': case 'CAR':
$entry['tel_car'] = $values[0]; $entry['tel_car'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'ISDN': case 'ISDN':
$entry['tel_isdn'] = $values[0]; $entry['tel_isdn'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
break; break;
case 'VIDEO': case 'VIDEO':
$entry['tel_video'] = $values[0]; $entry['tel_video'] = $values[0];
if($field[2] == 'PREF') if ($field[2] == 'PREF')
{ {
$entry['tel_prefer'] .= strtolower($field[1]) . ';'; $entry['tel_prefer'] .= strtolower($field[1]) . ';';
} }
@ -491,7 +495,7 @@
} }
break; break;
case 'EMAIL': case 'EMAIL':
switch($field[1]) switch ($field[1])
{ {
case 'WORK': case 'WORK':
$entry['email'] = $values[0]; $entry['email'] = $values[0];
@ -506,7 +510,7 @@
{ {
$entry['email_type'] = $field[2]; $entry['email_type'] = $field[2];
} }
elseif(!$buffer['email']) elseif (!$buffer['email'])
{ {
$entry['email'] = $values[0]; $entry['email'] = $values[0];
$entry['email_type'] = $field[1]; $entry['email_type'] = $field[1];
@ -523,12 +527,12 @@
} }
else else
{ {
switch($field[0]) switch ($field[0])
{ {
case 'N': case 'N':
reset($this->names); reset($this->names);
$j=0; $j=0;
while(list($myname,$myval) = each($this->names)) while(list($myname,$myval) = each($this->names) )
{ {
$namel = 'n_' . $myname; $namel = 'n_' . $myname;
$entry[$namel] = $values[$j]; $entry[$namel] = $values[$j];
@ -551,24 +555,27 @@
$entry['url'] = $values[0]; $entry['url'] = $values[0];
break; break;
case 'NOTE': case 'NOTE':
$entry['note'] = str_replace('=0D=0A',"\n",$values[0]); $entry['note'] = ereg_replace('=0D=0A',"\n",$values[0]);
break; break;
case 'KEY': case 'KEY':
$entry['key'] = str_replace('=0D=0A',"\n",$values[0]); $entry['key'] = ereg_replace('=0D=0A',"\n",$values[0]);
break; break;
case 'LABEL': case 'LABEL':
$entry['label'] = str_replace('=0D=0A',"\n",$values[0]); $entry['label'] = ereg_replace('=0D=0A',"\n",$values[0]);
break; break;
case 'BDAY': #1969-12-31 OR 19691231 case 'BDAY': #1969-12-31
$tmp = split('-',$values[0]); if(strlen($values[0]) == 8)
if($tmp[0])
{
$entry['bday'] = $tmp[1] . '/' . $tmp[2] . '/' . $tmp[0];
}
elseif(strlen($values[0]) == 8)
{ {
$entry['bday'] = substr($values[0],0,4) . '/' . substr($values[0],4,2) . '/' . substr($values[0],6,2); $entry['bday'] = substr($values[0],0,4) . '/' . substr($values[0],4,2) . '/' . substr($values[0],6,2);
} }
else
{
$tmp = split('-',$values[0]);
if($tmp[0])
{
$entry['bday'] = $tmp[1] . '/' . $tmp[2] . '/' . $tmp[0];
}
}
break; break;
case 'ORG': // RB 2001/05/07 added for Lotus Organizer: ORG:Company;Department case 'ORG': // RB 2001/05/07 added for Lotus Organizer: ORG:Company;Department
$entry['org_name'] = $values[0]; $entry['org_name'] = $values[0];
@ -581,11 +588,11 @@
$entry['adr_one_type'] = substr($buffer['adr_one_type'],0,-1); $entry['adr_one_type'] = substr($buffer['adr_one_type'],0,-1);
$entry['adr_two_type'] = substr($buffer['adr_two_type'],0,-1); $entry['adr_two_type'] = substr($buffer['adr_two_type'],0,-1);
if(count($street = split("\r*\n",$buffer['adr_one_street'],3)) > 1) if (count($street = split("\r*\n",$buffer['adr_one_street'],3)) > 1)
{ {
$entry['adr_one_street'] = $street[0]; // RB 2001/05/08 added for Lotus Organizer to split multiline adresses $entry['adr_one_street'] = $street[0]; // RB 2001/05/08 added for Lotus Organizer to split multiline adresses
$entry['address2'] = $street[1]; $entry['address2'] = $street[1];
$entry['address3'] = $street[2]; $entry['address3'] = $street[2];
} }
return $entry; return $entry;
@ -593,7 +600,7 @@
// Takes an array of contacts class fields/values, turns it into a vcard string: // Takes an array of contacts class fields/values, turns it into a vcard string:
// //
// for($i=0;$i<count($buffer);$i++) { // for ($i=0;$i<count($buffer);$i++) {
// $vcards .= $this->vcard->out($buffer[$i]); // $vcards .= $this->vcard->out($buffer[$i]);
// } // }
// //
@ -602,35 +609,29 @@
$entry = ''; $entry = '';
$header = 'BEGIN:VCARD' . "\n"; $header = 'BEGIN:VCARD' . "\n";
$header .= 'VERSION:2.1' . "\n"; $header .= 'VERSION:2.1' . "\n";
$header .= 'X-EGROUPWARE-FILE-AS:eGroupWare.org' . "\n"; $header .= 'X-PHPGROUPWARE-FILE-AS:phpGroupWare.org' . "\n";
reset($this->export); reset($this->export);
while(list($name,$value) = each($this->export)) while ( list($name,$value) = each($this->export) )
{ {
if(!empty($buffer[$value])) if (!empty($buffer[$value]))
{ {
$mult = explode(';',$value); $mult = explode(';',$value);
if(!$mult[1]) if (!$mult[1])
{ // Normal { // Normal
if(strstr($buffer[$value],"\r\n") || strstr($buffer[$value],"\n")) if (strstr($buffer[$value],"\r\n") || strstr($buffer[$value],"\n"))
{ {
$buffer[$value] = str_replace("\r\n","=0D=0A",$buffer[$value]); $buffer[$value] = ereg_replace("\r\n","=0D=0A",$buffer[$value]);
$buffer[$value] = str_replace("\n","=0D=0A",$buffer[$value]); $buffer[$value] = ereg_replace("\n","=0D=0A",$buffer[$value]);
$entry .= $value . ';QUOTED-PRINTABLE:' . $buffer[$value]."\n"; $entry .= $value . ';QUOTED-PRINTABLE:' . $buffer[$value]."\n";
} }
elseif($value == 'BDAY') elseif ($value == 'BDAY')
{ {
$tmp = split('/',$buffer[$value]); # 12/31/1969 -> 1969-12-31 $tmp = split('/',$buffer[$value]); # 12/31/1969 -> 1969-12-31
if($tmp[0]) if ($tmp[0])
{ {
if(strlen($tmp[0]) == 1) if (strlen($tmp[0]) == 1) { $tmp[0] = '0'.$tmp[0]; }
{ if (strlen($tmp[0]) == 1) { $tmp[1] = '0'.$tmp[1]; }
$tmp[0] = '0'.$tmp[0];
}
if(strlen($tmp[0]) == 1)
{
$tmp[1] = '0'.$tmp[1];
}
$entry .= 'BDAY:' . $tmp[2] . '-' . $tmp[0] . '-' . $tmp[1] . "\n"; $entry .= 'BDAY:' . $tmp[2] . '-' . $tmp[0] . '-' . $tmp[1] . "\n";
} }
} }
@ -641,10 +642,10 @@
} }
else else
{ {
switch($mult[0]) switch ($mult[0])
{ {
case 'N': case 'N':
switch($mult[1]) switch ($mult[1])
{ {
case 'PREFIX': case 'PREFIX':
$prefix = ';' . $buffer[$value]; $prefix = ';' . $buffer[$value];
@ -664,7 +665,7 @@
} }
break; break;
case 'ORG': case 'ORG':
switch($mult[1]) switch ($mult[1])
{ {
case 'NAME': case 'NAME':
$org_name = $buffer[$value]; $org_name = $buffer[$value];
@ -675,18 +676,18 @@
} }
break; break;
case 'ADR': case 'ADR':
switch($mult[1]) switch ($mult[1])
{ {
case 'TYPE': case 'TYPE':
$types = explode(';',$buffer[$value]); $types = explode(';',$buffer[$value]);
if($types[1]) if ($types[1])
{ {
while($type = each($types)) while ( $type = each($types) )
{ {
$typei[$i][$mult[2]] .= ';' . strtoupper($type[1]); $typei[$i][$mult[2]] .= ';' . strtoupper($type[1]);
} }
} }
elseif($types[0]) elseif ($types[0])
{ {
$typei[$i][$mult[2]] .= ';' . strtoupper($types[0]); $typei[$i][$mult[2]] .= ';' . strtoupper($types[0]);
} }
@ -713,20 +714,20 @@
{ {
case 'PREFER': case 'PREFER':
$prefer = explode(';',$buffer[$value]); $prefer = explode(';',$buffer[$value]);
if($prefer[1]) if ($prefer[1])
{ {
while($pref = strtoupper(each($prefer))) while ($pref = strtoupper(each($prefer)))
{ {
$prefi[$i][$pref] = ';PREF'; $prefi[$i][$pref] = ';PREF';
} }
//echo 'PREF1'; //echo 'PREF1';
} }
elseif($prefer[0]) elseif ($prefer[0])
{ {
$prefi[$i][strtoupper($prefer[0])] = ';PREF'; $prefi[$i][strtoupper($prefer[0])] = ';PREF';
//echo 'PREF='.strtoupper($prefer[0]); //echo 'PREF='.strtoupper($prefer[0]);
} }
elseif($buffer[$value]) elseif ($buffer[$value])
{ {
$prefi[$i][$buffer[$value]] = ';PREF'; $prefi[$i][$buffer[$value]] = ';PREF';
//echo 'PREF3'; //echo 'PREF3';
@ -748,14 +749,8 @@
switch($mult[1]) switch($mult[1])
{ {
case 'TYPE': case 'TYPE':
if($mult[2] == 'WORK') if ($mult[2] == 'WORK') { $emailtype = ';' . $buffer[$value]; }
{ if ($mult[2] == 'HOME') { $hemailtype = ';' . $buffer[$value]; }
$emailtype = ';' . $buffer[$value];
}
if($mult[2] == 'HOME')
{
$hemailtype = ';' . $buffer[$value];
}
break; break;
case 'WORK': case 'WORK':
$newval = 'A.'.$value; $newval = 'A.'.$value;
@ -771,57 +766,54 @@
break; break;
default: default:
break; break;
} //end switch($mult[0]) } //end switch ($mult[0])
} //end else } //end else
} //end if(!empty) } //end if (!empty)
} //end while } //end while
if($lastname && $firstname) if ($lastname && $firstname)
{ {
$entries .= $header; $entries .= $header;
$entries .= 'N:' . $lastname . $firstname . $middle . $prefix . $suffix . "\n"; $entries .= 'N:' . $lastname . $firstname . $middle . $prefix . $suffix . "\n";
$entries .= $entry; $entries .= $entry;
if(!$buffer['FN']) if (!$buffer['FN'])
{ {
if($lastname || $firstname) if ($lastname || $firstname )
{ {
$entries .= 'FN:' . substr($firstname,1) . ' ' . $lastname . "\n"; $entries .= 'FN:' . substr($firstname,1) . ' ' . $lastname . "\n";
} }
} }
if($org_name || $org_unit) if ($org_name || $org_unit)
{ {
$entries .= 'ORG:' . $org_name . $org_unit . "\n"; $entries .= 'ORG:' . $org_name . $org_unit . "\n";
} }
$workattr = str_replace('ADR;','',$workattr); $workattr = ereg_replace('ADR;','',$workattr);
$homeattr = str_replace('ADR;','',$homeattr); $homeattr = ereg_replace('ADR;','',$homeattr);
if(!$buffer['EXT']) if (!$buffer['EXT']) { $buffer['EXT'] = ';'; }
{ if ($workaddr)
$buffer['EXT'] = ';';
}
if($workaddr)
{ {
$work = 'A.ADR;' . $workattr . ':;' . $buffer['EXT'] . substr($workaddr,0,-1) . "\n"; $work = 'A.ADR;' . $workattr . ':;' . $buffer['EXT'] . substr($workaddr,0,-1) . "\n";
if(!$buffer['LABEL']) if (!$buffer['LABEL'])
{ {
$wlabel = substr($workaddr,0,-1); $wlabel = substr($workaddr,0,-1);
$wlabel = str_replace(';','=0D=0A',$wlabel); $wlabel = ereg_replace(';','=0D=0A',$wlabel);
//$wlabel = str_replace('(',',',$wlabel); //$wlabel = ereg_replace('(',',',$wlabel);
//$wlabel = str_replace(')',',',$wlabel); //$wlabel = ereg_replace(')',',',$wlabel);
$wlabel = 'LABEL;WORK;QUOTED-PRINTABLE:' . $wlabel . "\n"; $wlabel = 'LABEL;WORK;QUOTED-PRINTABLE:' . $wlabel . "\n";
} }
} }
if($homeaddr) if ($homeaddr)
{ {
$home = 'B.ADR;'.$homeattr.':;;'.substr($homeaddr,0,-1)."\n"; $home = 'B.ADR;'.$homeattr.':;;'.substr($homeaddr,0,-1)."\n";
$hlabel = substr($homeaddr,0,-1); $hlabel = substr($homeaddr,0,-1);
$hlabel = str_replace(';','=0D=0A',$hlabel); $hlabel = ereg_replace(';','=0D=0A',$hlabel);
//$hlabel = str_replace('(',',',$hlabel); //$hlabel = ereg_replace('(',',',$hlabel);
//$hlabel = str_replace(')',',',$hlabel); //$hlabel = ereg_replace(')',',',$hlabel);
$hlabel = 'LABEL;HOME;QUOTED-PRINTABLE:' . $hlabel . "\n"; $hlabel = 'LABEL;HOME;QUOTED-PRINTABLE:' . $hlabel . "\n";
} }
$entries = str_replace('PUBKEY','KEY',$entries); $entries = ereg_replace('PUBKEY','KEY',$entries);
$entries .= $work . $home . $wlabel . $hlabel . 'END:VCARD' . "\n"; $entries .= $work . $home . $wlabel . $hlabel . 'END:VCARD' . "\n";
$entries .= "\n"; $entries .= "\n";