Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F8199141
kolab_sync_data_contacts.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
10 KB
Referenced Files
None
Subscribers
None
kolab_sync_data_contacts.php
View Options
<?php
/**
*
*/
class
kolab_sync_data_contacts
extends
kolab_sync_data
{
protected
$_mapping
=
array
(
// ActiveSync => Kolab (libkolab)
'Anniversary'
=>
'anniversary'
,
'AssistantName'
=>
'assistant:0'
,
//'AssistnamePhoneNumber' => 'assistnamephonenumber',
'Birthday'
=>
'birthday'
,
//'Body' => 'notes', // handled separately in class methods
//'BodySize' => 'bodysize',
//'BodyTruncated' => 'bodytruncated',
//'Business2PhoneNumber' => 'business2phonenumber',
'BusinessCity'
=>
'address.work.locality'
,
'BusinessCountry'
=>
'address.work.country'
,
'BusinessPostalCode'
=>
'address.work.code'
,
'BusinessState'
=>
'address.work.region'
,
'BusinessStreet'
=>
'address.work.street'
,
'BusinessFaxNumber'
=>
'phone.workfax.number'
,
'BusinessPhoneNumber'
=>
'phone.work.number'
,
'CarPhoneNumber'
=>
'phone.car.number'
,
//'Categories' => 'categories',
//'Category' => 'category',
//'Children' => 'children', // -> array of Child elements, handled separately
//'Child' => 'child',
'CompanyName'
=>
'organization'
,
'Department'
=>
'department'
,
'Email1Address'
=>
'email:0'
,
'Email2Address'
=>
'email:1'
,
'Email3Address'
=>
'email:2'
,
//'FileAs' => 'fileas', //@TODO: ?
'FirstName'
=>
'firstname'
,
//'Home2PhoneNumber' => 'home2phonenumber',
'HomeCity'
=>
'address.home.locality'
,
'HomeCountry'
=>
'address.home.country'
,
'HomePostalCode'
=>
'address.home.code'
,
'HomeState'
=>
'address.home.region'
,
'HomeStreet'
=>
'address.home.street'
,
'HomeFaxNumber'
=>
'tel_fax_home'
,
'HomePhoneNumber'
=>
'tel_home'
,
'JobTitle'
=>
'jobtitle'
,
'LastName'
=>
'surname'
,
'MiddleName'
=>
'middlename'
,
'MobilePhoneNumber'
=>
'phone.mobile.number'
,
//'OfficeLocation' => 'officelocation',
'OtherCity'
=>
'address.office.locality'
,
'OtherCountry'
=>
'address.office.country'
,
'OtherPostalCode'
=>
'address.office.code'
,
'OtherState'
=>
'address.office.region'
,
'OtherStreet'
=>
'address.office.street'
,
'PagerNumber'
=>
'phone.pager.number'
,
//'RadioPhoneNumber' => 'radiophonenumber',
'Spouse'
=>
'spouse'
,
'Suffix'
=>
'suffix'
,
'Title'
=>
'prefix'
,
'WebPage'
=>
'website.homepage.url'
,
//'YomiCompanyName' => 'yomicompanyname',
//'YomiFirstName' => 'yomifirstname',
//'YomiLastName' => 'yomilastname',
//'Rtf' => 'rtf',
'Picture'
=>
'photo'
);
/**
* name of Tine 2.0 backend application
*
* @var string
*/
protected
$_applicationName
=
'Addressbook'
;
/**
* name of Tine 2.0 model to use
*
* @var string
*/
protected
$_modelName
=
'contact'
;
/**
* type of the default folder
*
* @var int
*/
protected
$_defaultFolderType
=
Syncroton_Command_FolderSync
::
FOLDERTYPE_CONTACT
;
/**
* default container for new entries
*
* @var string
*/
protected
$_defaultFolder
=
'Contacts'
;
/**
* type of user created folders
*
* @var int
*/
protected
$_folderType
=
Syncroton_Command_FolderSync
::
FOLDERTYPE_CONTACT_USER_CREATED
;
/**
* name of property which defines the filterid for different content classes
*
* @var string
*/
protected
$_filterProperty
=
'contactsfilter_id'
;
/**
* field to sort search results by
*
* @var string
*/
protected
$_sortField
=
'n_fileas'
;
/**
* append contact data to xml element
*
* @param DOMElement $_domParrent the parrent xml node
* @param array $_collectionData
* @param string $_serverId the local entry id
*/
public
function
appendXML
(
DOMElement
$_domParrent
,
$_collectionData
,
$_serverId
)
{
$_domParrent
->
ownerDocument
->
documentElement
->
setAttributeNS
(
'http://www.w3.org/2000/xmlns/'
,
'xmlns:Contacts'
,
'uri:Contacts'
);
$data
=
is_array
(
$_serverId
)
?
$_serverId
:
$this
->
getObject
(
$_collectionData
[
'folder'
],
$_serverId
);
foreach
(
$this
->
_mapping
as
$key
=>
$name
)
{
$value
=
$this
->
getKolabDataItem
(
$data
,
$name
);
if
(
empty
(
$value
))
{
continue
;
}
switch
(
$name
)
{
case
'photo'
:
// ActiveSync limits photo to 48KB (of base64 encoded string)
if
(
strlen
(
$value
)
>
48
*
1024
)
{
continue
;
}
break
;
}
if
(
empty
(
$value
)
||
is_array
(
$value
))
{
continue
;
}
// strip off any non printable control characters
if
(!
ctype_print
(
$value
))
{
$value
=
$this
->
removeControlChars
(
$value
);
}
$node
=
$_domParrent
->
ownerDocument
->
createElementNS
(
'uri:Contacts'
,
$key
);
$node
->
appendChild
(
$_domParrent
->
ownerDocument
->
createTextNode
(
$value
));
$_domParrent
->
appendChild
(
$node
);
}
if
(!
empty
(
$data
[
'notes'
]))
{
$value
=
$data
[
'notes'
];
// strip off any non printable control characters
if
(!
ctype_print
(
$value
))
{
$value
=
$this
->
removeControlChars
(
$value
);
}
if
(
version_compare
(
$this
->
_device
->
acsversion
,
'12.0'
,
'>='
)
===
true
)
{
$body
=
$_domParrent
->
appendChild
(
new
DOMElement
(
'Body'
,
null
,
'uri:AirSyncBase'
));
$body
->
appendChild
(
new
DOMElement
(
'Type'
,
1
,
'uri:AirSyncBase'
));
$dataTag
=
new
DOMElement
(
'Data'
,
null
,
'uri:AirSyncBase'
);
// ... append it to parent node aka append it to the document ...
$body
->
appendChild
(
$dataTag
);
// ... and now add the content (DomText takes care of special chars)
$dataTag
->
appendChild
(
new
DOMText
(
$value
));
}
else
{
// create a new DOMElement ...
$node
=
new
DOMElement
(
'Body'
,
null
,
'uri:Contacts'
);
// ... append it to parent node aka append it to the document ...
$_domParrent
->
appendChild
(
$node
);
// ... and now add the content (DomText takes care of special chars)
$node
->
appendChild
(
new
DOMText
(
$value
));
}
}
if
(!
empty
(
$data
[
'children'
]))
{
$children
=
$_domParrent
->
appendChild
(
new
DOMElement
(
'Children'
,
null
,
'uri:Contacts'
));
foreach
(
$data
[
'children'
]
as
$child
)
{
if
(!
empty
(
$child
))
{
if
(!
ctype_print
(
$child
))
{
$child
=
$this
->
removeControlChars
(
$child
);
}
$children
->
appendChild
(
new
DOMElement
(
'Child'
,
$child
,
'uri:Contacts'
));
}
}
}
}
/**
* convert contact from xml to Addressbook_Model_Contact
*
* @param SimpleXMLElement $_data Contact to convert
* @param array $_entry Existing entry
*
* @return array
*/
public
function
toKolab
(
SimpleXMLElement
$_data
,
$_entry
=
null
)
{
$contact
=
!
empty
(
$_entry
)
?
$_entry
:
array
();
$xmlData
=
$_data
->
children
(
'uri:Contacts'
);
foreach
(
$this
->
_mapping
as
$key
=>
$name
)
{
$value
=
(
string
)
$xmlData
->
$key
;
switch
(
$name
)
{
case
'address.work.street'
:
if
(
strtolower
(
$this
->
_device
->
devicetype
)
==
'palm'
)
{
// palm pre sends the whole address in the <Contacts:BusinessStreet> tag
$value
=
null
;
}
break
;
case
'email:0'
:
case
'email:1'
:
case
'email:2'
:
// android send email address as
// Lars Kneschke <l.kneschke@metaways.de>
if
(
preg_match
(
'/(.*)<(.+@[^@]+)>/'
,
$value
,
$matches
))
{
$value
=
trim
(
$matches
[
2
]);
}
break
;
case
'website.homepage.url'
:
// remove facebook urls
if
(
preg_match
(
'/^fb:
\/\/
/'
,
$value
))
{
$value
=
null
;
}
break
;
}
$this
->
setKolabDataItem
(
$contact
,
$name
,
$value
);
}
// set body
if
(
version_compare
(
$this
->
_device
->
acsversion
,
'12.0'
,
'>='
)
===
true
)
{
$airSyncBase
=
$_data
->
children
(
'uri:AirSyncBase'
);
$contact
[
'notes'
]
=
isset
(
$airSyncBase
->
Body
)
?
(
string
)
$airSyncBase
->
Body
->
Data
:
null
;
}
else
{
$contact
[
'notes'
]
=
isset
(
$xmlData
->
Body
)
?
(
string
)
$xmlData
->
Body
:
null
;
}
// set children
$contact
[
'children'
]
=
array
();
if
(
isset
(
$xmlData
->
Children
))
{
foreach
(
$xmlData
->
Children
->
children
as
$child
)
{
$contact
[
'children'
][]
=
(
string
)
$child
;
}
}
return
$contact
;
}
/**
* convert contact from xml to Addressbook_Model_ContactFilter
*
* @param SimpleXMLElement $_data
* @return array
*/
protected
function
_toTineFilterArray
(
SimpleXMLElement
$_data
)
{
/*
$xmlData = $_data->children('uri:Contacts');
$filterArray = array();
foreach($this->_mapping as $fieldName => $value) {
if (isset($xmlData->$fieldName)) {
$filterArray[] = array(
'field' => $value,
'operator' => 'equals',
'value' => (string)$xmlData->$fieldName
);
}
}
return $filterArray;
*/
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jul 8, 10:11 PM (1 d, 7 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1052129
Default Alt Text
kolab_sync_data_contacts.php (10 KB)
Attached To
Mode
R4 syncroton
Attached
Detach File
Event Timeline
Log In to Comment