2006-03-21 14:19:38 +01:00
|
|
|
<?php
|
2006-07-10 00:59:22 +02:00
|
|
|
/**
|
|
|
|
* Addressbook - SIF parser
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Lars Kneschke <lkneschke@egroupware.org>
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2009-11-16 09:04:18 +01:00
|
|
|
* @author Joerg Lehrke <jlehrke@noc.de>
|
2006-07-10 00:59:22 +02:00
|
|
|
* @package addressbook
|
2008-05-10 14:02:49 +02:00
|
|
|
* @subpackage export
|
2006-07-10 00:59:22 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-05-10 14:02:49 +02:00
|
|
|
* @version $Id$
|
2006-07-10 00:59:22 +02:00
|
|
|
*/
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2008-05-10 14:02:49 +02:00
|
|
|
class addressbook_sif extends addressbook_bo
|
2006-07-10 00:59:22 +02:00
|
|
|
{
|
|
|
|
var $sifMapping = array(
|
|
|
|
'Anniversary' => '',
|
|
|
|
'AssistantName' => 'assistent',
|
|
|
|
'AssistantTelephoneNumber' => 'tel_assistent',
|
|
|
|
'BillingInformation' => '',
|
|
|
|
'Birthday' => 'bday',
|
|
|
|
'Body' => 'note',
|
|
|
|
'Business2TelephoneNumber' => '',
|
|
|
|
'BusinessAddressCity' => 'adr_one_locality',
|
|
|
|
'BusinessAddressCountry' => 'adr_one_countryname',
|
|
|
|
'BusinessAddressPostalCode' => 'adr_one_postalcode',
|
|
|
|
'BusinessAddressPostOfficeBox' => 'adr_one_street2',
|
|
|
|
'BusinessAddressState' => 'adr_one_region',
|
|
|
|
'BusinessAddressStreet' => 'adr_one_street',
|
|
|
|
'BusinessFaxNumber' => 'tel_fax',
|
|
|
|
'BusinessTelephoneNumber' => 'tel_work',
|
|
|
|
'CallbackTelephoneNumber' => '',
|
|
|
|
'CarTelephoneNumber' => 'tel_car',
|
|
|
|
'Categories' => 'cat_id',
|
|
|
|
'Children' => '',
|
|
|
|
'Companies' => '',
|
|
|
|
'CompanyMainTelephoneNumber' => '',
|
|
|
|
'CompanyName' => 'org_name',
|
|
|
|
'ComputerNetworkName' => '',
|
|
|
|
'Department' => 'org_unit',
|
|
|
|
'Email1Address' => 'email',
|
|
|
|
'Email1AddressType' => '',
|
|
|
|
'Email2Address' => 'email_home',
|
|
|
|
'Email2AddressType' => '',
|
|
|
|
'Email3Address' => '',
|
|
|
|
'Email3AddressType' => '',
|
|
|
|
'FileAs' => 'n_fileas',
|
|
|
|
'FirstName' => 'n_given',
|
|
|
|
'Hobby' => '',
|
|
|
|
'Home2TelephoneNumber' => '',
|
|
|
|
'HomeAddressCity' => 'adr_two_locality',
|
|
|
|
'HomeAddressCountry' => 'adr_two_countryname',
|
|
|
|
'HomeAddressPostalCode' => 'adr_two_postalcode',
|
|
|
|
'HomeAddressPostOfficeBox' => 'adr_two_street2',
|
|
|
|
'HomeAddressState' => 'adr_two_region',
|
|
|
|
'HomeAddressStreet' => 'adr_two_street',
|
|
|
|
'HomeFaxNumber' => 'tel_fax_home',
|
|
|
|
'HomeTelephoneNumber' => 'tel_home',
|
|
|
|
'Importance' => '',
|
|
|
|
'Initials' => '',
|
|
|
|
'JobTitle' => 'title',
|
|
|
|
'Language' => '',
|
|
|
|
'LastName' => 'n_family',
|
|
|
|
'ManagerName' => '',
|
|
|
|
'MiddleName' => 'n_middle',
|
|
|
|
'Mileage' => '',
|
|
|
|
'MobileTelephoneNumber' => 'tel_cell',
|
|
|
|
'NickName' => '',
|
|
|
|
'OfficeLocation' => 'room',
|
|
|
|
'OrganizationalIDNumber' => '',
|
|
|
|
'OtherAddressCity' => '',
|
|
|
|
'OtherAddressCountry' => '',
|
|
|
|
'OtherAddressPostalCode' => '',
|
|
|
|
'OtherAddressPostOfficeBox' => '',
|
|
|
|
'OtherAddressState' => '',
|
|
|
|
'OtherAddressStreet' => '',
|
|
|
|
'OtherFaxNumber' => '',
|
|
|
|
'OtherTelephoneNumber' => 'tel_other',
|
|
|
|
'PagerNumber' => 'tel_pager',
|
|
|
|
'PrimaryTelephoneNumber' => 'tel_prefer',
|
|
|
|
'Profession' => 'role',
|
|
|
|
'RadioTelephoneNumber' => '',
|
|
|
|
'Sensitivity' => 'private',
|
|
|
|
'Spouse' => '',
|
|
|
|
'Subject' => '',
|
|
|
|
'Suffix' => 'n_suffix',
|
|
|
|
'TelexNumber' => '',
|
|
|
|
'Title' => 'n_prefix',
|
|
|
|
'WebPage' => 'url',
|
|
|
|
'YomiCompanyName' => '',
|
|
|
|
'YomiFirstName' => '',
|
|
|
|
'YomiLastName' => '',
|
|
|
|
'HomeWebPage' => 'url_home',
|
|
|
|
'Folder' => '',
|
|
|
|
);
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
// standard headers
|
|
|
|
const xml_decl = '<?xml version="1.0" encoding="UTF-8"?>';
|
|
|
|
const SIF_decl = '<SIFVersion>1.1</SIFVersion>';
|
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
function startElement($_parser, $_tag, $_attributes) {
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
function endElement($_parser, $_tag) {
|
|
|
|
if(!empty($this->sifMapping[$_tag])) {
|
2007-09-21 17:08:56 +02:00
|
|
|
$this->contact[$this->sifMapping[$_tag]] = trim($this->sifData);
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-10 00:59:22 +02:00
|
|
|
unset($this->sifData);
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
function characterData($_parser, $_data) {
|
|
|
|
$this->sifData .= $_data;
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
function siftoegw($sifData) {
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
#$tmpfname = tempnam('/tmp/sync/contents','sifc_');
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
#$handle = fopen($tmpfname, "w");
|
2009-11-16 09:04:18 +01:00
|
|
|
#fwrite($handle, $sifData);
|
2006-07-10 00:59:22 +02:00
|
|
|
#fclose($handle);
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
$this->xml_parser = xml_parser_create('UTF-8');
|
|
|
|
xml_set_object($this->xml_parser, $this);
|
|
|
|
xml_parser_set_option($this->xml_parser, XML_OPTION_CASE_FOLDING, false);
|
|
|
|
xml_set_element_handler($this->xml_parser, "startElement", "endElement");
|
|
|
|
xml_set_character_data_handler($this->xml_parser, "characterData");
|
|
|
|
$this->strXmlData = xml_parse($this->xml_parser, $sifData);
|
|
|
|
if(!$this->strXmlData) {
|
|
|
|
error_log(sprintf("XML error: %s at line %d",
|
|
|
|
xml_error_string(xml_get_error_code($this->xml_parser)),
|
|
|
|
xml_get_current_line_number($this->xml_parser)));
|
|
|
|
return false;
|
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
foreach($this->contact as $key => $value) {
|
2009-11-16 09:04:18 +01:00
|
|
|
$value = preg_replace('/<\!\[CDATA\[(.+)\]\]>/Usim', '$1', $value);
|
2006-07-10 00:59:22 +02:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, 'utf-8');
|
|
|
|
switch($key) {
|
|
|
|
case 'cat_id':
|
SyncML patches from patrick.bihan-faou-AT-mindstep.com (without
logout+mbstring stuff), small modification to use the already exiting
methodes to generate full name and fileas)
The code is commited to trunk only at the moment to allow testing of it.
If everything goes well, we intend to commit it to 1.4 branch too.
Here's the original description of the patch by Patrick:
- handles the default config for current versions of funambol (i.e. the
scard/stask/snote/scal locations)
- tries to be a bit smarter on how the data content should be encoded
based on what the client specified (sif+base64/vcard, / fragmented or
not, etc.)
- workaround a bug in some versions of funambol, where funambol does not
specify the proper sif type for the type of requested data
- imported patch #117 from egw's tracker
- make sure that the logs generated by the horde code go to stderr so
they can be view in the webserver's logs
- as much as possible reduce code duplication. For example, the
categories are handled in the parent classes for both the SIF avn VCAL
formats for each type of data (addressbook,infolog,calendar).
- make sure the code can handle more than one categories in each
direction
- treat the 'sony ericsson' vendor string just like 'sonyericsson', the
newer phones apparently have a space in the vendor string... (this
touches some files in the icalsrv as well)
- handle notes: these should now work with everything (funambol or
other)
- remove more code duplication: the syncml "api" for the various data
types (calendar, contacts, infolog) is now common for both the vcard and
sif data formats (cf the files that need to be removed)
- handle the "privat" filter in infolog like the "private" filter (some
part of the code use the name without the trailing e)
- imported patch # 267 from egw's tracker
2007-09-29 12:29:48 +02:00
|
|
|
if(!empty($value))
|
|
|
|
{
|
|
|
|
$finalContact[$key] = implode(",", $this->find_or_add_categories(explode(';', $value)));
|
2006-07-10 00:59:22 +02:00
|
|
|
}
|
2007-10-12 07:38:48 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$finalContact[$key] = '';
|
|
|
|
}
|
2006-07-10 00:59:22 +02:00
|
|
|
break;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
case 'private':
|
2007-10-12 07:38:48 +02:00
|
|
|
$finalContact[$key] = (int) ($value > 0); // eGW private is 0 (public) or 1 (private), SIF seems to use 0 and 2
|
2006-07-10 00:59:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$finalContact[$key] = $value;
|
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
|
|
|
}
|
SyncML patches from patrick.bihan-faou-AT-mindstep.com (without
logout+mbstring stuff), small modification to use the already exiting
methodes to generate full name and fileas)
The code is commited to trunk only at the moment to allow testing of it.
If everything goes well, we intend to commit it to 1.4 branch too.
Here's the original description of the patch by Patrick:
- handles the default config for current versions of funambol (i.e. the
scard/stask/snote/scal locations)
- tries to be a bit smarter on how the data content should be encoded
based on what the client specified (sif+base64/vcard, / fragmented or
not, etc.)
- workaround a bug in some versions of funambol, where funambol does not
specify the proper sif type for the type of requested data
- imported patch #117 from egw's tracker
- make sure that the logs generated by the horde code go to stderr so
they can be view in the webserver's logs
- as much as possible reduce code duplication. For example, the
categories are handled in the parent classes for both the SIF avn VCAL
formats for each type of data (addressbook,infolog,calendar).
- make sure the code can handle more than one categories in each
direction
- treat the 'sony ericsson' vendor string just like 'sonyericsson', the
newer phones apparently have a space in the vendor string... (this
touches some files in the icalsrv as well)
- handle notes: these should now work with everything (funambol or
other)
- remove more code duplication: the syncml "api" for the various data
types (calendar, contacts, infolog) is now common for both the vcard and
sif data formats (cf the files that need to be removed)
- handle the "privat" filter in infolog like the "private" filter (some
part of the code use the name without the trailing e)
- imported patch # 267 from egw's tracker
2007-09-29 12:29:48 +02:00
|
|
|
|
|
|
|
$this->fixup_contact($finalContact);
|
2006-07-10 00:59:22 +02:00
|
|
|
return $finalContact;
|
|
|
|
}
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
/**
|
|
|
|
* Search an exactly matching entry (used for slow sync)
|
|
|
|
*
|
|
|
|
* @param string $_sifdata
|
|
|
|
* @return boolean/int/string contact-id or false, if not found
|
|
|
|
*/
|
2009-11-16 09:04:18 +01:00
|
|
|
function search($_sifdata, $contentID=null, $relax=false)
|
2006-07-10 00:59:22 +02:00
|
|
|
{
|
2009-11-16 09:04:18 +01:00
|
|
|
$result = false;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
if($contact = $this->siftoegw($_sifdata)) {
|
|
|
|
if ($contentID) {
|
|
|
|
$contact['contact_id'] = $contentID;
|
|
|
|
}
|
|
|
|
$result = $this->find_contact($contact, $relax);
|
2006-07-10 00:59:22 +02:00
|
|
|
}
|
2009-11-16 09:04:18 +01:00
|
|
|
return $result;
|
2006-07-10 00:59:22 +02:00
|
|
|
}
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
/**
|
|
|
|
* import a vard into addressbook
|
|
|
|
*
|
|
|
|
* @return int contact id
|
|
|
|
* @param string $_vcard the vcard
|
2006-07-10 01:35:16 +02:00
|
|
|
* @param int/string $_abID=null the internal addressbook id or !$_abID for a new enty
|
2009-11-16 09:04:18 +01:00
|
|
|
* @param boolean $merge=false merge data with existing entry
|
2006-07-10 00:59:22 +02:00
|
|
|
*/
|
2009-11-16 09:04:18 +01:00
|
|
|
function addSIF($_sifdata, $_abID=null, $merge=false)
|
2006-07-10 00:59:22 +02:00
|
|
|
{
|
|
|
|
#error_log('ABID: '.$_abID);
|
|
|
|
#error_log(base64_decode($_sifdata));
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
if(!$contact = $this->siftoegw($_sifdata)) {
|
|
|
|
return false;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
|
|
|
|
2006-07-10 01:35:16 +02:00
|
|
|
if($_abID) {
|
2006-07-10 00:59:22 +02:00
|
|
|
// update entry
|
|
|
|
$contact['id'] = $_abID;
|
|
|
|
}
|
|
|
|
return $this->save($contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-16 09:04:18 +01:00
|
|
|
* return a sifc
|
2006-07-10 00:59:22 +02:00
|
|
|
*
|
|
|
|
* @param int $_id the id of the contact
|
|
|
|
* @return string containing the vcard
|
|
|
|
*/
|
|
|
|
function getSIF($_id)
|
|
|
|
{
|
2009-11-16 09:04:18 +01:00
|
|
|
$sysCharSet = $GLOBALS['egw']->translation->charset();
|
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
$fields = array_unique(array_values($this->sifMapping));
|
|
|
|
sort($fields);
|
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
if(!($entry = $this->read($_id))) {
|
2006-07-10 00:59:22 +02:00
|
|
|
return false;
|
|
|
|
}
|
2009-11-16 09:04:18 +01:00
|
|
|
|
|
|
|
$sifContact = self::xml_decl . "\n<contact>" . self::SIF_decl;
|
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
#error_log(print_r($entry,true));
|
2006-03-21 14:19:38 +01:00
|
|
|
|
SyncML patches from patrick.bihan-faou-AT-mindstep.com (without
logout+mbstring stuff), small modification to use the already exiting
methodes to generate full name and fileas)
The code is commited to trunk only at the moment to allow testing of it.
If everything goes well, we intend to commit it to 1.4 branch too.
Here's the original description of the patch by Patrick:
- handles the default config for current versions of funambol (i.e. the
scard/stask/snote/scal locations)
- tries to be a bit smarter on how the data content should be encoded
based on what the client specified (sif+base64/vcard, / fragmented or
not, etc.)
- workaround a bug in some versions of funambol, where funambol does not
specify the proper sif type for the type of requested data
- imported patch #117 from egw's tracker
- make sure that the logs generated by the horde code go to stderr so
they can be view in the webserver's logs
- as much as possible reduce code duplication. For example, the
categories are handled in the parent classes for both the SIF avn VCAL
formats for each type of data (addressbook,infolog,calendar).
- make sure the code can handle more than one categories in each
direction
- treat the 'sony ericsson' vendor string just like 'sonyericsson', the
newer phones apparently have a space in the vendor string... (this
touches some files in the icalsrv as well)
- handle notes: these should now work with everything (funambol or
other)
- remove more code duplication: the syncml "api" for the various data
types (calendar, contacts, infolog) is now common for both the vcard and
sif data formats (cf the files that need to be removed)
- handle the "privat" filter in infolog like the "private" filter (some
part of the code use the name without the trailing e)
- imported patch # 267 from egw's tracker
2007-09-29 12:29:48 +02:00
|
|
|
// fillup some defaults such as n_fn and n_fileas is needed
|
|
|
|
$this->fixup_contact($entry);
|
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
foreach($this->sifMapping as $sifField => $egwField)
|
|
|
|
{
|
|
|
|
if(empty($egwField)) continue;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
#error_log("$sifField => $egwField");
|
|
|
|
#error_log('VALUE1: '.$entry[0][$egwField]);
|
2006-07-20 15:32:02 +02:00
|
|
|
$value = $GLOBALS['egw']->translation->convert($entry[$egwField], $sysCharSet, 'utf-8');
|
2006-07-10 00:59:22 +02:00
|
|
|
#error_log('VALUE2: '.$value);
|
2006-03-21 14:19:38 +01:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
switch($sifField)
|
2006-04-26 16:02:17 +02:00
|
|
|
{
|
2006-07-10 00:59:22 +02:00
|
|
|
case 'Sensitivity':
|
|
|
|
$value = 2 * $value; // eGW private is 0 (public) or 1 (private)
|
2008-05-10 14:02:49 +02:00
|
|
|
$sifContact .= "<$sifField>$value</$sifField>";
|
2006-07-10 00:59:22 +02:00
|
|
|
break;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
case 'Folder':
|
|
|
|
# skip currently. This is the folder where Outlook stores the contact.
|
|
|
|
#$sifContact .= "<$sifField>/</$sifField>";
|
|
|
|
break;
|
2008-05-10 14:02:49 +02:00
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
case 'Categories':
|
|
|
|
if(!empty($value)) {
|
|
|
|
$value = implode("; ", $this->get_categories($value));
|
|
|
|
$value = $GLOBALS['egw']->translation->convert($value, $sysCharSet, 'utf-8');
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-10 00:59:22 +02:00
|
|
|
default:
|
2009-11-16 09:04:18 +01:00
|
|
|
$value = @htmlspecialchars(trim($value), ENT_QUOTES, 'utf-8');
|
|
|
|
$sifContact .= "<$sifField>$value</$sifField>";
|
2006-07-10 00:59:22 +02:00
|
|
|
break;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
|
|
|
}
|
2006-07-10 00:59:22 +02:00
|
|
|
$sifContact .= "</contact>";
|
|
|
|
|
2009-11-16 09:04:18 +01:00
|
|
|
return $sifContact;
|
2006-03-21 14:19:38 +01:00
|
|
|
}
|
2006-07-10 00:59:22 +02:00
|
|
|
}
|