mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-03 04:29:28 +01:00
Reorganized the vCard parser to assign to datebase columns with to following priciples
1. Most qualified field matches EMAIL;INTERNET;WORK wins against EMAIL;INTERNET 2. First field wins (if vCard contains same field twice)
This commit is contained in:
parent
5b263e23eb
commit
ea2d01b1f6
@ -1043,8 +1043,10 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
$pname = strtoupper($pname);
|
$pname = strtoupper($pname);
|
||||||
$vcardRow['uparams'][$pname] = $params;
|
$vcardRow['uparams'][$pname] = $params;
|
||||||
}
|
}
|
||||||
ksort($vcardRow['uparams']);
|
|
||||||
|
|
||||||
|
|
||||||
|
// expand 3.0 TYPE paramters to 2.1 qualifiers
|
||||||
|
$vcardRow['tparams'] = array();
|
||||||
foreach ($vcardRow['uparams'] as $pname => $params)
|
foreach ($vcardRow['uparams'] as $pname => $params)
|
||||||
{
|
{
|
||||||
switch ($pname)
|
switch ($pname)
|
||||||
@ -1057,7 +1059,6 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
{
|
{
|
||||||
$rowTypes[] = strtoupper($param);
|
$rowTypes[] = strtoupper($param);
|
||||||
}
|
}
|
||||||
sort($rowTypes);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1067,33 +1068,42 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
{
|
{
|
||||||
switch ($type)
|
switch ($type)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
case 'OTHER':
|
||||||
|
case 'WORK':
|
||||||
|
case 'HOME':
|
||||||
|
$vcardRow['tparams'][$type] = '';
|
||||||
|
break;
|
||||||
|
case 'CELL':
|
||||||
case 'PAGER':
|
case 'PAGER':
|
||||||
case 'FAX':
|
case 'FAX':
|
||||||
case 'VOICE':
|
case 'VOICE':
|
||||||
case 'OTHER':
|
case 'CAR':
|
||||||
case 'CELL':
|
|
||||||
case 'WORK':
|
|
||||||
case 'HOME':
|
|
||||||
$rowName .= ';' . $type;
|
|
||||||
break;
|
|
||||||
case 'PREF':
|
case 'PREF':
|
||||||
|
case 'X-CUSTOMLABEL-CAR':
|
||||||
if ($vcardRow['name'] == 'TEL')
|
if ($vcardRow['name'] == 'TEL')
|
||||||
{
|
{
|
||||||
$pref_tel = $key;
|
$vcardRow['tparams'][$type] = '';
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 'CAR':
|
|
||||||
case 'X-CUSTOMLABEL-CAR':
|
|
||||||
$rowName = 'TEL;CAR';
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//case 'INTERNET':
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$vcardRow['uparams'] += $vcardRow['tparams'];
|
||||||
|
ksort($vcardRow['uparams']);
|
||||||
|
|
||||||
|
foreach ($vcardRow['uparams'] as $pname => $params)
|
||||||
|
{
|
||||||
|
switch ($pname)
|
||||||
|
{
|
||||||
case 'PREF':
|
case 'PREF':
|
||||||
if (strtoupper($vcardRow['name']) == 'TEL' && !$pref_tel)
|
if ($rowName == 'TEL' && !$pref_tel)
|
||||||
{
|
{
|
||||||
$pref_tel = $key;
|
$pref_tel = $key;
|
||||||
}
|
}
|
||||||
@ -1109,7 +1119,10 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
break;
|
break;
|
||||||
case 'CAR':
|
case 'CAR':
|
||||||
case 'X-CUSTOMLABEL-CAR':
|
case 'X-CUSTOMLABEL-CAR':
|
||||||
$rowName = 'TEL;CAR';
|
if ($rowName == 'TEL')
|
||||||
|
{
|
||||||
|
$rowName = 'TEL;CAR';
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (strpos($pname, 'X-FUNAMBOL-') === 0)
|
if (strpos($pname, 'X-FUNAMBOL-') === 0)
|
||||||
@ -1143,11 +1156,11 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
$rowName = 'URL;X-egw-Ref' . $url++;
|
$rowName = 'URL;X-egw-Ref' . $url++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rowNames[$rowName] = $key;
|
$rowNames[$key] = $rowName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#error_log(print_r($rowNames, true));
|
//error_log(print_r($rowNames, true));
|
||||||
|
|
||||||
// All rowNames of the vCard are now concatenated with their qualifiers.
|
// All rowNames of the vCard are now concatenated with their qualifiers.
|
||||||
// If qualifiers are missing we apply a default strategy.
|
// If qualifiers are missing we apply a default strategy.
|
||||||
@ -1156,50 +1169,52 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
|
|
||||||
$finalRowNames = array();
|
$finalRowNames = array();
|
||||||
|
|
||||||
foreach ($rowNames as $rowName => $vcardKey)
|
foreach ($rowNames as $vcardKey => $rowName)
|
||||||
{
|
{
|
||||||
switch($rowName)
|
switch($rowName)
|
||||||
{
|
{
|
||||||
|
case 'VERSION':
|
||||||
|
break;
|
||||||
case 'ADR':
|
case 'ADR':
|
||||||
if (!isset($rowNames[$rowName . ';WORK'])
|
if (!in_array('ADR;WORK', $rowNames)
|
||||||
&& !isset($finalRowNames[$rowName . ';WORK']))
|
&& !isset($finalRowNames['ADR;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames[$rowName . ';WORK'] = $vcardKey;
|
$finalRowNames['ADR;WORK'] = $vcardKey;
|
||||||
}
|
}
|
||||||
elseif (!isset($rowNames[$rowName . ';HOME'])
|
elseif (!in_array('ADR;HOME', $rowNames)
|
||||||
&& !isset($finalRowNames[$rowName . ';HOME']))
|
&& !isset($finalRowNames['ADR;HOME']))
|
||||||
{
|
{
|
||||||
$finalRowNames[$rowName . ';HOME'] = $vcardKey;
|
$finalRowNames['ADR;HOME'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;FAX':
|
case 'TEL;FAX':
|
||||||
if (!isset($rowNames['TEL;FAX;WORK'])
|
if (!in_array('TEL;FAX;WORK', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;FAX;WORK']))
|
&& !isset($finalRowNames['TEL;FAX;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;FAX;WORK'] = $vcardKey;
|
$finalRowNames['TEL;FAX;WORK'] = $vcardKey;
|
||||||
}
|
}
|
||||||
elseif (!isset($rowNames['TEL;FAX;HOME'])
|
elseif (!in_array('TEL;FAX;HOME', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;FAX;HOME']))
|
&& !isset($finalRowNames['TEL;FAX;HOME']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;FAX;HOME'] = $vcardKey;
|
$finalRowNames['TEL;FAX;HOME'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;WORK':
|
case 'TEL;WORK':
|
||||||
if (!isset($rowNames['TEL;VOICE;WORK'])
|
if (!in_array('TEL;VOICE;WORK', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;VOICE;WORK']))
|
&& !isset($finalRowNames['TEL;VOICE;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;VOICE;WORK'] = $vcardKey;
|
$finalRowNames['TEL;VOICE;WORK'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;HOME':
|
case 'TEL;HOME':
|
||||||
if (!isset($rowNames['TEL;HOME;VOICE'])
|
if (!in_array('TEL;HOME;VOICE', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;HOME;VOICE']))
|
&& !isset($finalRowNames['TEL;HOME;VOICE']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;HOME;VOICE'] = $vcardKey;
|
$finalRowNames['TEL;HOME;VOICE'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;OTHER':
|
case 'TEL;OTHER':
|
||||||
if (!isset($rowNames['TEL;OTHER;VOICE'])
|
if (!in_array('TEL;OTHER;VOICE', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;OTHER;VOICE']))
|
&& !isset($finalRowNames['TEL;OTHER;VOICE']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;OTHER;VOICE'] = $vcardKey;
|
$finalRowNames['TEL;OTHER;VOICE'] = $vcardKey;
|
||||||
@ -1214,77 +1229,78 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;X-egw-Ref1':
|
case 'TEL;X-egw-Ref1':
|
||||||
if (!isset($rowNames['TEL;VOICE;WORK'])
|
if (!in_array('TEL;VOICE;WORK', $rowNames)
|
||||||
&& !isset($rowNames['TEL;WORK'])
|
&& !in_array('TEL;WORK', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;VOICE;WORK']))
|
&& !isset($finalRowNames['TEL;VOICE;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;VOICE;WORK'] = $vcardKey;
|
$finalRowNames['TEL;VOICE;WORK'] = $vcardKey;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'TEL;X-egw-Ref2':
|
case 'TEL;X-egw-Ref2':
|
||||||
if (!isset($rowNames['TEL;HOME;VOICE'])
|
if (!in_array('TEL;HOME;VOICE', $rowNames)
|
||||||
&& !isset($rowNames['TEL;HOME'])
|
&& !in_array('TEL;HOME', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;HOME;VOICE']))
|
&& !isset($finalRowNames['TEL;HOME;VOICE']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;HOME;VOICE'] = $vcardKey;
|
$finalRowNames['TEL;HOME;VOICE'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'TEL;CELL;X-egw-Ref1':
|
case 'TEL;CELL;X-egw-Ref1':
|
||||||
if (!isset($rowNames['TEL;CELL;WORK'])
|
if (!in_array('TEL;CELL;WORK', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;CELL;WORK']))
|
&& !isset($finalRowNames['TEL;CELL;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;CELL;WORK'] = $vcardKey;
|
$finalRowNames['TEL;CELL;WORK'] = $vcardKey;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'TEL;CELL;X-egw-Ref2':
|
case 'TEL;CELL;X-egw-Ref2':
|
||||||
if (!isset($rowNames['TEL;CELL;HOME'])
|
if (!in_array('TEL;CELL;HOME', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;CELL;HOME']))
|
&& !isset($finalRowNames['TEL;CELL;HOME']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;CELL;HOME'] = $vcardKey;
|
$finalRowNames['TEL;CELL;HOME'] = $vcardKey;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'TEL;CELL;X-egw-Ref3':
|
case 'TEL;CELL;X-egw-Ref3':
|
||||||
if (!isset($rowNames['TEL;CAR'])
|
if (!in_array($rowNames['TEL;CAR'])
|
||||||
&& !isset($rowNames['TEL;CAR;VOICE'])
|
&& !in_array('TEL;CAR;VOICE', $rowNames)
|
||||||
&& !isset($rowNames['TEL;CAR;CELL'])
|
&& !in_array('TEL;CAR;CELL', $rowNames)
|
||||||
&& !isset($rowNames['TEL;CAR;CELL;VOICE'])
|
&& !in_array('TEL;CAR;CELL;VOICE', $rowNames)
|
||||||
&& !isset($finalRowNames['TEL;CAR']))
|
&& !isset($finalRowNames['TEL;CAR']))
|
||||||
{
|
{
|
||||||
$finalRowNames['TEL;CAR'] = $vcardKey;
|
$finalRowNames['TEL;CAR'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'EMAIL;X-egw-Ref1':
|
case 'EMAIL;X-egw-Ref1':
|
||||||
if (!isset($rowNames['EMAIL;WORK']) &&
|
if (!in_array('EMAIL;WORK', $rowNames) &&
|
||||||
!isset($finalRowNames['EMAIL;WORK']))
|
!isset($finalRowNames['EMAIL;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['EMAIL;WORK'] = $vcardKey;
|
$finalRowNames['EMAIL;WORK'] = $vcardKey;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'EMAIL;X-egw-Ref2':
|
case 'EMAIL;X-egw-Ref2':
|
||||||
if (!isset($rowNames['EMAIL;HOME']) &&
|
if (!in_array('EMAIL;HOME', $rowNames) &&
|
||||||
!isset($finalRowNames['EMAIL;HOME']))
|
!isset($finalRowNames['EMAIL;HOME']))
|
||||||
{
|
{
|
||||||
$finalRowNames['EMAIL;HOME'] = $vcardKey;
|
$finalRowNames['EMAIL;HOME'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'URL;X-egw-Ref1':
|
case 'URL;X-egw-Ref1':
|
||||||
if (!isset($rowNames['URL;WORK']) &&
|
if (!in_array('URL;WORK', $rowNames) &&
|
||||||
!isset($finalRowNames['URL;WORK']))
|
!isset($finalRowNames['URL;WORK']))
|
||||||
{
|
{
|
||||||
$finalRowNames['URL;WORK'] = $vcardKey;
|
$finalRowNames['URL;WORK'] = $vcardKey;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'URL;X-egw-Ref2':
|
case 'URL;X-egw-Ref2':
|
||||||
if (!isset($rowNames['URL;HOME']) &&
|
if (!in_array('URL;HOME', $rowNames) &&
|
||||||
!isset($finalRowNames['URL;HOME']))
|
!isset($finalRowNames['URL;HOME']))
|
||||||
{
|
{
|
||||||
$finalRowNames['URL;HOME'] = $vcardKey;
|
$finalRowNames['URL;HOME'] = $vcardKey;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'VERSION':
|
|
||||||
break;
|
|
||||||
case 'X-EVOLUTION-ASSISTANT':
|
case 'X-EVOLUTION-ASSISTANT':
|
||||||
$finalRowNames['X-ASSISTANT'] = $vcardKey;
|
if (!isset($finalRowNames['X-ASSISTANT']))
|
||||||
|
{
|
||||||
|
$finalRowNames['X-ASSISTANT'] = $vcardKey;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!isset($finalRowNames[$rowName]))
|
if (!isset($finalRowNames[$rowName]))
|
||||||
@ -1295,9 +1311,7 @@ class addressbook_vcal extends addressbook_bo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#error_log(print_r($finalRowNames, true));
|
//error_log(print_r($finalRowNames, true));
|
||||||
#Horde::logMessage("vCalAddressbook vcardtoegw finalRowNames: " . print_r($finalRowNames, true), __FILE__, __LINE__, PEAR_LOG_DEBUG);
|
|
||||||
|
|
||||||
|
|
||||||
$contact = array();
|
$contact = array();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user