Page MenuHomePhorge

kolab_sync_data_contacts.php
No OneTemporary

Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None

kolab_sync_data_contacts.php

<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
*
*/
class kolab_sync_data_contacts extends kolab_sync_data
{
/**
* Mapping from ActiveSync Contacts namespace fields
*/
protected $mapping = array(
'Anniversary' => 'anniversary',
'AssistantName' => 'assistant:0',
//'AssistnamePhoneNumber' => 'assistnamephonenumber',
'Birthday' => 'birthday',
'Body' => 'notes',
//'BodySize' => 'bodysize',
//'BodyTruncated' => 'bodytruncated',
//'Business2PhoneNumber' => 'business2phonenumber',
'BusinessAddressCity' => 'address.work.locality',
'BusinessAddressCountry' => 'address.work.country',
'BusinessAddressPostalCode' => 'address.work.code',
'BusinessAddressState' => 'address.work.region',
'BusinessAddressStreet' => 'address.work.street',
'BusinessFaxNumber' => 'phone.workfax.number',
'BusinessPhoneNumber' => 'phone.work.number',
'CarPhoneNumber' => 'phone.car.number',
//'Categories' => 'categories',
//'Category' => 'category',
'Children' => 'children',
//'Child' => 'child',
'CompanyName' => 'organization',
'Department' => 'department',
'Email1Address' => 'email:0',
'Email2Address' => 'email:1',
'Email3Address' => 'email:2',
//'FileAs' => 'fileas', //@TODO: ?
'FirstName' => 'firstname',
//'Home2PhoneNumber' => 'home2phonenumber',
'HomeAddressCity' => 'address.home.locality',
'HomeAddressCountry' => 'address.home.country',
'HomeAddressPostalCode' => 'address.home.code',
'HomeAddressState' => 'address.home.region',
'HomeAddressStreet' => 'address.home.street',
'HomeFaxNumber' => 'phone.homefax.number',
'HomePhoneNumber' => 'phone.home.number',
'JobTitle' => 'jobtitle',
'LastName' => 'surname',
'MiddleName' => 'middlename',
'MobilePhoneNumber' => 'phone.mobile.number',
//'OfficeLocation' => 'officelocation',
'OtherAddressCity' => 'address.office.locality',
'OtherAddressCountry' => 'address.office.country',
'OtherAddressPostalCode' => 'address.office.code',
'OtherAddressState' => 'address.office.region',
'OtherAddressStreet' => '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',
// Mapping from ActiveSync Contacts2 namespace fields
//'CustomerId' => 'customerid',
//'GovernmentId' => 'governmentid',
'IMAddress' => 'im:0',
'IMAddress2' => 'im:1',
'IMAddress3' => 'im:2',
'ManagerName' => 'manager:0',
//'CompanyMainPhone' => 'companymainphone',
//'AccountName' => 'accountname',
'NickName' => 'nickname',
//'MMS' => 'mms',
);
/**
* Kolab object type
*
* @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;
/**
* Default namespace
*
* @var string
*/
protected $defaultNS = 'Contacts';
/**
* Field to sort search results by
*
* @var string
*/
protected $sortField = 'n_fileas';
/**
* Creates model object
*
* @param Syncroton_Model_SyncCollection $collection Collection data
* @param string $serverId Local entry identifier
*/
public function getEntry(Syncroton_Model_SyncCollection $collection, $serverId)
{
$data = is_array($serverId) ? $serverId : $this->getObject($collection->collectionId, $serverId);
$result = array();
// Contacts namespace fields
foreach ($this->mapping as $key => $name) {
$value = $this->getKolabDataItem($data, $name);
switch ($name) {
case 'photo':
if ($value) {
// ActiveSync limits photo size to 48KB (of base64 encoded string)
if (strlen($value) * 1.33 > 48 * 1024) {
continue;
}
}
break;
case 'birthday':
case 'anniversary':
$value = self::date_from_kolab($value);
break;
case 'notes':
$value = $this->setBody($value);
break;
}
if (empty($value) || is_array($value)) {
continue;
}
$result[$key] = $value;
}
return new Syncroton_Model_Contact($result);
}
/**
* convert contact from xml to libkolab array
*
* @param Syncroton_Model_IEntry $data Contact to convert
* @param string $folderId Folder identifier
* @param array $entry Existing entry
*
* @return array Kolab object array
*/
public function toKolab(Syncroton_Model_IEntry $data, $folderId, $entry = null)
{
$contact = !empty($entry) ? $entry : array();
// Contacts namespace fields
foreach ($this->mapping as $key => $name) {
$value = $data->$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;
case 'notes':
$value = $this->getBody($value);
break;
}
$this->setKolabDataItem($contact, $name, $value);
}
return $contact;
}
}

File Metadata

Mime Type
text/x-php
Expires
Sat, Apr 4, 5:26 AM (4 d, 16 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18767016
Default Alt Text
kolab_sync_data_contacts.php (8 KB)

Event Timeline