mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-09-06 13:14:18 +08:00
Fixed contacts search (suggestions)
This commit is contained in:
parent
29f579dc4e
commit
f3823333d7
10 changed files with 29 additions and 2542 deletions
|
@ -2,7 +2,7 @@
|
||||||
"name": "RainLoop",
|
"name": "RainLoop",
|
||||||
"title": "RainLoop Webmail",
|
"title": "RainLoop Webmail",
|
||||||
"version": "1.6.6",
|
"version": "1.6.6",
|
||||||
"release": "916",
|
"release": "919",
|
||||||
"description": "Simple, modern & fast web-based email client",
|
"description": "Simple, modern & fast web-based email client",
|
||||||
"homepage": "http://rainloop.net",
|
"homepage": "http://rainloop.net",
|
||||||
"main": "Gruntfile.js",
|
"main": "Gruntfile.js",
|
||||||
|
|
|
@ -58,7 +58,7 @@ class AddressBook extends \RainLoop\Providers\AbstractProvider
|
||||||
*/
|
*/
|
||||||
public function IsSharingAllowed()
|
public function IsSharingAllowed()
|
||||||
{
|
{
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\AddressBookInterface &&
|
return $this->oDriver instanceof \RainLoop\Providers\AddressBook\AddressBookInterface &&
|
||||||
$this->oDriver->IsSharingAllowed();
|
$this->oDriver->IsSharingAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -640,10 +640,15 @@ class PdoAddressBook
|
||||||
// TODO fix this
|
// TODO fix this
|
||||||
$sCustomSearch = '';
|
$sCustomSearch = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sSearchTypes = implode(',', array(
|
||||||
|
PropertyType::EMAIl, PropertyType::FIRST_NAME, PropertyType::LAST_NAME, PropertyType::NICK_NAME,
|
||||||
|
PropertyType::PHONE, PropertyType::WEB_PAGE
|
||||||
|
));
|
||||||
|
|
||||||
$sSql = 'SELECT id_user, id_prop, id_contact FROM rainloop_ab_properties '.
|
$sSql = 'SELECT id_user, id_prop, id_contact FROM rainloop_ab_properties '.
|
||||||
'WHERE (id_user = :id_user) AND (prop_value LIKE :search ESCAPE \'=\''.
|
'WHERE (id_user = :id_user) AND prop_type IN ('.$sSearchTypes.') AND (prop_value LIKE :search ESCAPE \'=\''.
|
||||||
(0 < \strlen($sCustomSearch) ? ' OR prop_type = '.PropertyType::PHONE.' AND prop_value_custom <> \'\' AND prop_value_custom LIKE :search_custom_phone)' : '').
|
(0 < \strlen($sCustomSearch) ? ' OR (prop_type = '.PropertyType::PHONE.' AND prop_value_custom <> \'\' AND prop_value_custom LIKE :search_custom_phone)' : '').
|
||||||
') GROUP BY id_contact, id_prop';
|
') GROUP BY id_contact, id_prop';
|
||||||
|
|
||||||
$aParams = array(
|
$aParams = array(
|
||||||
|
@ -995,7 +1000,6 @@ class PdoAddressBook
|
||||||
if (\is_array($aFetch) && 0 < \count($aFetch))
|
if (\is_array($aFetch) && 0 < \count($aFetch))
|
||||||
{
|
{
|
||||||
$aNames = array();
|
$aNames = array();
|
||||||
$aNicks = array();
|
|
||||||
$aEmails = array();
|
$aEmails = array();
|
||||||
|
|
||||||
foreach ($aFetch as $aItem)
|
foreach ($aFetch as $aItem)
|
||||||
|
@ -1017,7 +1021,7 @@ class PdoAddressBook
|
||||||
$aNames[$iIdContact] = array('', '');
|
$aNames[$iIdContact] = array('', '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$aNames[$iIdContact][PropertyType::LAST_NAME === $iType ? 0 : 1] = $aItem['prop_value'];
|
$aNames[$iIdContact][PropertyType::FIRST_NAME === $iType ? 0 : 1] = $aItem['prop_value'];
|
||||||
}
|
}
|
||||||
else if ((isset($aIdProps[$iIdProp]) || isset($aContactAllAccess[$iIdContact])) &&
|
else if ((isset($aIdProps[$iIdProp]) || isset($aContactAllAccess[$iIdContact])) &&
|
||||||
PropertyType::EMAIl === $iType)
|
PropertyType::EMAIl === $iType)
|
||||||
|
@ -1055,6 +1059,25 @@ class PdoAddressBook
|
||||||
{
|
{
|
||||||
$aResult[] = array($sEmail, $sNickItem);
|
$aResult[] = array($sEmail, $sNickItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$bName && !$bNick)
|
||||||
|
{
|
||||||
|
$aResult[] = array($sEmail, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aNameItem = isset($aNames[$iId]) && \is_array($aNames[$iId]) ? $aNames[$iId] : array('', '');
|
||||||
|
$sNameItem = \trim($aNameItem[0].' '.$aNameItem[1]);
|
||||||
|
if (0 === \strlen($sNameItem))
|
||||||
|
{
|
||||||
|
$sNameItem = isset($aNicks[$iId]) ? $aNicks[$iId] : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($aItems as $sEmail)
|
||||||
|
{
|
||||||
|
$aResult[] = array($sEmail, $sNameItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,341 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers;
|
|
||||||
|
|
||||||
use \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType as PropertyType;
|
|
||||||
|
|
||||||
class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
|
|
||||||
*/
|
|
||||||
private $oDriver;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface $oDriver
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($oDriver)
|
|
||||||
{
|
|
||||||
$this->oDriver = null;
|
|
||||||
if ($oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface)
|
|
||||||
{
|
|
||||||
$this->oDriver = $oDriver;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function Test()
|
|
||||||
{
|
|
||||||
\sleep(1);
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
|
||||||
$this->oDriver->Test() : 'Personal address book driver is not allowed';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsActive()
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
|
|
||||||
$this->oDriver->IsSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsSharingAllowed()
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
|
|
||||||
$this->oDriver->IsSharingAllowed();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsSupported()
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
|
|
||||||
$this->oDriver->IsSupported();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function GetUserUidByEmail($sEmail)
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
|
||||||
$this->oDriver->GetUserUidByEmail($sEmail) : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function GetCtagByEmail($sEmail)
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
|
||||||
$this->oDriver->GetCtagByEmail($sEmail) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param bool $bCreate = false
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function GetUserHashByEmail($sEmail, $bCreate = false)
|
|
||||||
{
|
|
||||||
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface ?
|
|
||||||
$this->oDriver->GetUserHashByEmail($sEmail, $bCreate) : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param bool $bConsiderShare = true
|
|
||||||
*/
|
|
||||||
public function ConsiderShare($bConsiderShare = true)
|
|
||||||
{
|
|
||||||
if ($this->oDriver)
|
|
||||||
{
|
|
||||||
$this->oDriver->ConsiderShare($bConsiderShare);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function ContactSave($sEmail, &$oContact)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->ContactSave($sEmail, $oContact) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aContactIds
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function DeleteContacts($sEmail, $aContactIds)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->DeleteContacts($sEmail, $aContactIds) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param int $iOffset = 0
|
|
||||||
* @param type $iLimit = 20
|
|
||||||
* @param string $sSearch = ''
|
|
||||||
* @param int $iResultCount = 0
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function GetContacts($sEmail, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->GetContacts($sEmail,
|
|
||||||
$iOffset, $iLimit, $sSearch, $iResultCount) : array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param string $sID
|
|
||||||
* @param bool $bIsStrID = false
|
|
||||||
*
|
|
||||||
* @return \RainLoop\Providers\PersonalAddressBook\Classes\Contact|null
|
|
||||||
*/
|
|
||||||
public function GetContactByID($sEmail, $mID, $bIsStrID = false)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->GetContactByID($sEmail, $mID, $bIsStrID) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param string $sSearch
|
|
||||||
* @param int $iLimit = 20
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->GetSuggestions($sEmail, $sSearch, $iLimit) : array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aEmails
|
|
||||||
* @param bool $bCreateAuto = true
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IncFrec($sEmail, $aEmails, $bCreateAuto = true)
|
|
||||||
{
|
|
||||||
return $this->IsActive() ? $this->oDriver->IncFrec($sEmail, $aEmails, $bCreateAuto) : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sCsvName
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
private function csvNameToTypeConvertor($sCsvName)
|
|
||||||
{
|
|
||||||
static $aMap = null;
|
|
||||||
if (null === $aMap)
|
|
||||||
{
|
|
||||||
$aMap = array(
|
|
||||||
'Title' => PropertyType::FULLNAME,
|
|
||||||
'First Name' => PropertyType::FIRST_NAME,
|
|
||||||
'Middle Name' => PropertyType::MIDDLE_NAME,
|
|
||||||
'Last Name' => PropertyType::LAST_NAME,
|
|
||||||
'Suffix' => PropertyType::NAME_SUFFIX,
|
|
||||||
'Business Fax' => PropertyType::FAX_BUSSINES,
|
|
||||||
'Business Phone' => PropertyType::PHONE_BUSSINES,
|
|
||||||
'Business Phone 2' => PropertyType::PHONE_BUSSINES,
|
|
||||||
'Company Main Phone' => PropertyType::PHONE_BUSSINES,
|
|
||||||
'Home Fax' => PropertyType::FAX_PERSONAL,
|
|
||||||
'Home Phone' => PropertyType::PHONE_PERSONAL,
|
|
||||||
'Home Phone 2' => PropertyType::PHONE_PERSONAL,
|
|
||||||
'Mobile Phone' => PropertyType::MOBILE_PERSONAL,
|
|
||||||
'Other Fax' => PropertyType::FAX_OTHER,
|
|
||||||
'Other Phone' => PropertyType::PHONE_OTHER,
|
|
||||||
// 'Primary Phone' => PropertyType::PHONE_PERSONAL,
|
|
||||||
'E-mail Address' => PropertyType::EMAIl_PERSONAL,
|
|
||||||
'E-mail 2 Address' => PropertyType::EMAIl_OTHER,
|
|
||||||
'E-mail 3 Address' => PropertyType::EMAIl_OTHER,
|
|
||||||
'E-mail Display Name' => PropertyType::FULLNAME,
|
|
||||||
'E-mail 2 Display Name' => PropertyType::FULLNAME,
|
|
||||||
'E-mail 3 Display Name' => PropertyType::FULLNAME,
|
|
||||||
'Notes' => PropertyType::NOTE,
|
|
||||||
'Web Page' => PropertyType::WEB_PAGE_PERSONAL,
|
|
||||||
'WebPage' => PropertyType::WEB_PAGE_PERSONAL,
|
|
||||||
);
|
|
||||||
|
|
||||||
$aMap = array_change_key_case($aMap, CASE_LOWER);
|
|
||||||
}
|
|
||||||
|
|
||||||
$sCsvNameLower = \MailSo\Base\Utils::IsAscii($sCsvName) ? \strtolower($sCsvName) : '';
|
|
||||||
return isset($aMap[$sCsvNameLower]) ? $aMap[$sCsvNameLower] : PropertyType::UNKNOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aCsvData
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function ImportCsvArray($sEmail, $aCsvData)
|
|
||||||
{
|
|
||||||
$iCount = 0;
|
|
||||||
if ($this->IsActive() && \is_array($aCsvData) && 0 < \count($aCsvData))
|
|
||||||
{
|
|
||||||
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
|
||||||
foreach ($aCsvData as $aItem)
|
|
||||||
{
|
|
||||||
foreach ($aItem as $sItemName => $sItemValue)
|
|
||||||
{
|
|
||||||
$sItemName = \trim($sItemName);
|
|
||||||
$sItemValue = \trim($sItemValue);
|
|
||||||
|
|
||||||
if (!empty($sItemName) && !empty($sItemValue))
|
|
||||||
{
|
|
||||||
$iType = $this->csvNameToTypeConvertor($sItemName);
|
|
||||||
if (PropertyType::UNKNOWN !== $iType)
|
|
||||||
{
|
|
||||||
$oProp = new \RainLoop\Providers\PersonalAddressBook\Classes\Property();
|
|
||||||
$oProp->Type = $iType;
|
|
||||||
$oProp->Value = $sItemValue;
|
|
||||||
|
|
||||||
$oContact->Properties[] = $oProp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($oContact && 0 < \count($oContact->Properties))
|
|
||||||
{
|
|
||||||
if ($this->ContactSave($sEmail, $oContact))
|
|
||||||
{
|
|
||||||
$iCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$oContact->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($oContact);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $iCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param string $sVcfData
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function ImportVcfFile($sEmail, $sVcfData)
|
|
||||||
{
|
|
||||||
$iCount = 0;
|
|
||||||
if ($this->IsActive() && \is_string($sVcfData))
|
|
||||||
{
|
|
||||||
$sVcfData = \trim($sVcfData);
|
|
||||||
if ("\xef\xbb\xbf" === \substr($sVcfData, 0, 3))
|
|
||||||
{
|
|
||||||
$sVcfData = \substr($sVcfData, 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
$oVCardSplitter = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$oVCardSplitter = new \Sabre\VObject\Splitter\VCard($sVcfData);
|
|
||||||
}
|
|
||||||
catch (\Exception $oExc)
|
|
||||||
{
|
|
||||||
$this->Logger()->WriteException($oExc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($oVCardSplitter)
|
|
||||||
{
|
|
||||||
$oContact = new \RainLoop\Providers\PersonalAddressBook\Classes\Contact();
|
|
||||||
|
|
||||||
$oVCard = null;
|
|
||||||
|
|
||||||
while ($oVCard = $oVCardSplitter->getNext())
|
|
||||||
{
|
|
||||||
if ($oVCard instanceof \Sabre\VObject\Component\VCard)
|
|
||||||
{
|
|
||||||
if (empty($oVCard->UID))
|
|
||||||
{
|
|
||||||
$oVCard->UID = \Sabre\DAV\UUIDUtil::getUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
$oContact->ParseVCard($oVCard, $oVCard->serialize());
|
|
||||||
if (0 < \count($oContact->Properties))
|
|
||||||
{
|
|
||||||
if ($this->ContactSave($sEmail, $oContact))
|
|
||||||
{
|
|
||||||
$iCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$oContact->Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $iCount;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,580 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\PersonalAddressBook\Classes;
|
|
||||||
|
|
||||||
use
|
|
||||||
RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType,
|
|
||||||
RainLoop\Providers\PersonalAddressBook\Classes\Property
|
|
||||||
;
|
|
||||||
|
|
||||||
class Contact
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $IdContact;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $IdContactStr;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $Display;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $ScopeType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $Changed;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $IdPropertyFromSearch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $Properties;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
public $ReadOnly;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $CardDavData;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $CardDavHash;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $CardDavSize;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Clear()
|
|
||||||
{
|
|
||||||
$this->IdContact = '';
|
|
||||||
$this->IdContactStr = '';
|
|
||||||
$this->IdUser = 0;
|
|
||||||
$this->Display = '';
|
|
||||||
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
|
||||||
$this->Changed = \time();
|
|
||||||
$this->IdPropertyFromSearch = 0;
|
|
||||||
$this->Properties = array();
|
|
||||||
$this->ReadOnly = false;
|
|
||||||
|
|
||||||
$this->CardDavData = '';
|
|
||||||
$this->CardDavHash = '';
|
|
||||||
$this->CardDavSize = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function UpdateDependentValues($bReparseVcard = true)
|
|
||||||
{
|
|
||||||
$sLastName = '';
|
|
||||||
$sFirstName = '';
|
|
||||||
$sEmail = '';
|
|
||||||
$sOther = '';
|
|
||||||
|
|
||||||
$oFullNameProperty = null;
|
|
||||||
|
|
||||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
|
||||||
{
|
|
||||||
if ($oProperty)
|
|
||||||
{
|
|
||||||
$oProperty->ScopeType = $this->ScopeType;
|
|
||||||
$oProperty->UpdateDependentValues();
|
|
||||||
|
|
||||||
if (!$oFullNameProperty && PropertyType::FULLNAME === $oProperty->Type)
|
|
||||||
{
|
|
||||||
$oFullNameProperty =& $oProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (0 < \strlen($oProperty->Value))
|
|
||||||
{
|
|
||||||
if ('' === $sEmail && $oProperty->IsEmail())
|
|
||||||
{
|
|
||||||
$sEmail = $oProperty->Value;
|
|
||||||
}
|
|
||||||
else if ('' === $sLastName && PropertyType::LAST_NAME === $oProperty->Type)
|
|
||||||
{
|
|
||||||
$sLastName = $oProperty->Value;
|
|
||||||
}
|
|
||||||
else if ('' === $sFirstName && PropertyType::FIRST_NAME === $oProperty->Type)
|
|
||||||
{
|
|
||||||
$sFirstName = $oProperty->Value;
|
|
||||||
}
|
|
||||||
else if (\in_array($oProperty->Type, array(PropertyType::FULLNAME,
|
|
||||||
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER,
|
|
||||||
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER
|
|
||||||
)))
|
|
||||||
{
|
|
||||||
$sOther = $oProperty->Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (empty($this->IdContactStr))
|
|
||||||
{
|
|
||||||
$this->IdContactStr = \Sabre\DAV\UUIDUtil::getUUID();
|
|
||||||
}
|
|
||||||
|
|
||||||
$sDisplay = '';
|
|
||||||
if (0 < \strlen($sLastName) || 0 < \strlen($sFirstName))
|
|
||||||
{
|
|
||||||
$sDisplay = \trim($sFirstName.' '.$sLastName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('' === $sDisplay && 0 < \strlen($sEmail))
|
|
||||||
{
|
|
||||||
$sDisplay = \trim($sEmail);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('' === $sDisplay)
|
|
||||||
{
|
|
||||||
$sDisplay = $sOther;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->Display = \trim($sDisplay);
|
|
||||||
|
|
||||||
$bNewFull = false;
|
|
||||||
if (!$oFullNameProperty)
|
|
||||||
{
|
|
||||||
$oFullNameProperty = new \RainLoop\Providers\PersonalAddressBook\Classes\Property(PropertyType::FULLNAME, $this->Display);
|
|
||||||
$bNewFull = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$oFullNameProperty->Value = $this->Display;
|
|
||||||
$oFullNameProperty->UpdateDependentValues();
|
|
||||||
|
|
||||||
if ($bNewFull)
|
|
||||||
{
|
|
||||||
$this->Properties[] = $oFullNameProperty;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($bReparseVcard || '' === $this->CardDavData)
|
|
||||||
{
|
|
||||||
$oVCard = $this->ToVCardObject($this->CardDavData);
|
|
||||||
$this->CardDavData = $oVCard ? $oVCard->serialize() : $this->CardDavData;
|
|
||||||
unset($oVCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($this->CardDavData))
|
|
||||||
{
|
|
||||||
$this->CardDavHash = \md5($this->CardDavData);
|
|
||||||
$this->CardDavSize = \strlen($this->CardDavData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->CardDavHash = '';
|
|
||||||
$this->CardDavSize = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function GetEmails()
|
|
||||||
{
|
|
||||||
$aResult = array();
|
|
||||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
|
||||||
{
|
|
||||||
if ($oProperty && $oProperty->IsEmail())
|
|
||||||
{
|
|
||||||
$aResult[] = $oProperty->Value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return \array_unique($aResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param \Sabre\VObject\Document $oVCard
|
|
||||||
* @param string $sCardData
|
|
||||||
*/
|
|
||||||
public function ParseVCard($oVCard, $sVCard)
|
|
||||||
{
|
|
||||||
$bNew = empty($this->IdContact);
|
|
||||||
|
|
||||||
if (!$bNew)
|
|
||||||
{
|
|
||||||
$this->Properties = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$aProperties = array();
|
|
||||||
if ($oVCard)
|
|
||||||
{
|
|
||||||
$bOldVersion = empty($oVCard->VERSION) ? false :
|
|
||||||
\in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));
|
|
||||||
|
|
||||||
$this->IdContactStr = $oVCard->UID ? (string) $oVCard->UID : \Sabre\DAV\UUIDUtil::getUUID();
|
|
||||||
|
|
||||||
if (isset($oVCard->FN) && '' !== \trim($oVCard->FN))
|
|
||||||
{
|
|
||||||
$sValue = \trim($oVCard->FN);
|
|
||||||
if ($bOldVersion && !isset($oVCard->FN->parameters['CHARSET']))
|
|
||||||
{
|
|
||||||
if (0 < \strlen($sValue))
|
|
||||||
{
|
|
||||||
$sEncValue = @\utf8_encode($sValue);
|
|
||||||
if (0 === \strlen($sEncValue))
|
|
||||||
{
|
|
||||||
$sEncValue = $sValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = $sEncValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
|
|
||||||
$aProperties[] = new Property(PropertyType::FULLNAME, $sValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME))
|
|
||||||
{
|
|
||||||
$sValue = \trim($oVCard->NICKNAME);
|
|
||||||
if ($bOldVersion && !isset($oVCard->NICKNAME->parameters['CHARSET']))
|
|
||||||
{
|
|
||||||
if (0 < \strlen($sValue))
|
|
||||||
{
|
|
||||||
$sEncValue = @\utf8_encode($sValue);
|
|
||||||
if (0 === \strlen($sEncValue))
|
|
||||||
{
|
|
||||||
$sEncValue = $sValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = $sEncValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
|
|
||||||
$aProperties[] = new Property(PropertyType::NICK_NAME, $sValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE))
|
|
||||||
// {
|
|
||||||
// $sValue = \trim($oVCard->NOTE);
|
|
||||||
// if ($bOldVersion)
|
|
||||||
// {
|
|
||||||
// if (0 < \strlen($sValue))
|
|
||||||
// {
|
|
||||||
// $sEncValue = @\utf8_encode($sValue);
|
|
||||||
// if (0 === \strlen($sEncValue))
|
|
||||||
// {
|
|
||||||
// $sEncValue = $sValue;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// $sValue = $sEncValue;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// $sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
|
|
||||||
// $aProperties[] = new Property(PropertyType::NOTE, $sValue);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (isset($oVCard->N))
|
|
||||||
{
|
|
||||||
$aNames = $oVCard->N->getParts();
|
|
||||||
foreach ($aNames as $iIndex => $sValue)
|
|
||||||
{
|
|
||||||
$sValue = \trim($sValue);
|
|
||||||
if ($bOldVersion && !isset($oVCard->N->parameters['CHARSET']))
|
|
||||||
{
|
|
||||||
if (0 < \strlen($sValue))
|
|
||||||
{
|
|
||||||
$sEncValue = @\utf8_encode($sValue);
|
|
||||||
if (0 === \strlen($sEncValue))
|
|
||||||
{
|
|
||||||
$sEncValue = $sValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = $sEncValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$sValue = \MailSo\Base\Utils::Utf8Clear($sValue);
|
|
||||||
switch ($iIndex) {
|
|
||||||
case 0:
|
|
||||||
$aProperties[] = new Property(PropertyType::LAST_NAME, $sValue);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
$aProperties[] = new Property(PropertyType::FIRST_NAME, $sValue);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
$aProperties[] = new Property(PropertyType::MIDDLE_NAME, $sValue);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
$aProperties[] = new Property(PropertyType::NAME_PREFIX, $sValue);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$aProperties[] = new Property(PropertyType::NAME_SUFFIX, $sValue);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($oVCard->EMAIL))
|
|
||||||
{
|
|
||||||
$bPref = false;
|
|
||||||
foreach($oVCard->EMAIL as $oEmail)
|
|
||||||
{
|
|
||||||
$oTypes = $oEmail ? $oEmail['TYPE'] : null;
|
|
||||||
$sEmail = $oEmail ? \trim($oEmail->getValue()) : '';
|
|
||||||
|
|
||||||
if (0 < \strlen($sEmail))
|
|
||||||
{
|
|
||||||
if ($oTypes)
|
|
||||||
{
|
|
||||||
$oProp = new Property($oTypes->has('WORK') ? PropertyType::EMAIl_BUSSINES : PropertyType::EMAIl_PERSONAL, $sEmail);
|
|
||||||
if (!$bPref && $oTypes->has('pref'))
|
|
||||||
{
|
|
||||||
$bPref = true;
|
|
||||||
\array_unshift($aProperties, $oProp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
\array_push($aProperties, $oProp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
\array_unshift($aProperties,
|
|
||||||
new Property(PropertyType::EMAIl_PERSONAL, $sEmail));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($oVCard->URL))
|
|
||||||
{
|
|
||||||
foreach($oVCard->URL as $oUrl)
|
|
||||||
{
|
|
||||||
$oTypes = $oUrl ? $oUrl['TYPE'] : null;
|
|
||||||
$sUrl = $oUrl ? \trim((string) $oUrl) : '';
|
|
||||||
|
|
||||||
if (0 < \strlen($sUrl))
|
|
||||||
{
|
|
||||||
\array_push($aProperties,
|
|
||||||
new Property($oTypes && $oTypes->has('WORK') ?
|
|
||||||
PropertyType::WEB_PAGE_BUSSINES : PropertyType::WEB_PAGE_PERSONAL, $sUrl));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($oVCard->TEL))
|
|
||||||
{
|
|
||||||
$bPref = false;
|
|
||||||
foreach($oVCard->TEL as $oTel)
|
|
||||||
{
|
|
||||||
$oTypes = $oTel ? $oTel['TYPE'] : null;
|
|
||||||
$sTel = $oTypes ? \trim((string) $oTel) : '';
|
|
||||||
|
|
||||||
if (0 < \strlen($sTel))
|
|
||||||
{
|
|
||||||
if ($oTypes)
|
|
||||||
{
|
|
||||||
$oProp = null;
|
|
||||||
$bWork = $oTypes->has('WORK');
|
|
||||||
|
|
||||||
switch (true)
|
|
||||||
{
|
|
||||||
case $oTypes->has('VOICE'):
|
|
||||||
$oProp = new Property($bWork ? PropertyType::PHONE_BUSSINES : PropertyType::PHONE_PERSONAL, $sTel);
|
|
||||||
break;
|
|
||||||
case $oTypes->has('CELL'):
|
|
||||||
$oProp = new Property($bWork ? PropertyType::MOBILE_BUSSINES : PropertyType::MOBILE_PERSONAL, $sTel);
|
|
||||||
break;
|
|
||||||
case $oTypes->has('FAX'):
|
|
||||||
$oProp = new Property($bWork ? PropertyType::FAX_BUSSINES : PropertyType::FAX_PERSONAL, $sTel);
|
|
||||||
break;
|
|
||||||
case $oTypes->has('WORK'):
|
|
||||||
$oProp = new Property(PropertyType::MOBILE_BUSSINES, $sTel);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$oProp = new Property(PropertyType::MOBILE_PERSONAL, $sTel);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($oProp)
|
|
||||||
{
|
|
||||||
if (!$bPref && $oTypes->has('pref'))
|
|
||||||
{
|
|
||||||
$bPref = true;
|
|
||||||
\array_unshift($aProperties, $oProp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
\array_push($aProperties, $oProp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
\array_unshift($aProperties,
|
|
||||||
new Property(PropertyType::MOBILE_PERSONAL, $sTel));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->Properties = $aProperties;
|
|
||||||
|
|
||||||
$this->CardDavData = \MailSo\Base\Utils::Utf8Clear($sVCard);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->UpdateDependentValues(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function ToVCardObject($sPreVCard = '')
|
|
||||||
{
|
|
||||||
// $this->UpdateDependentValues();
|
|
||||||
|
|
||||||
$oVCard = null;
|
|
||||||
if (0 < \strlen($sPreVCard))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
$oVCard = \Sabre\VObject\Reader::read($sPreVCard);
|
|
||||||
}
|
|
||||||
catch (\Exception $oExc) {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$oVCard)
|
|
||||||
{
|
|
||||||
$oVCard = new \Sabre\VObject\Component\VCard();
|
|
||||||
}
|
|
||||||
|
|
||||||
$oVCard->VERSION = '3.0';
|
|
||||||
$oVCard->PRODID = '-//RainLoop//'.APP_VERSION.'//EN';
|
|
||||||
|
|
||||||
unset($oVCard->FN, $oVCard->EMAIL, $oVCard->TEL);
|
|
||||||
|
|
||||||
$bPrefEmail = $bPrefPhone = false;
|
|
||||||
$sFirstName = $sLastName = $sMiddleName = $sSuffix = $sPrefix = '';
|
|
||||||
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
|
|
||||||
{
|
|
||||||
if ($oProperty)
|
|
||||||
{
|
|
||||||
switch ($oProperty->Type)
|
|
||||||
{
|
|
||||||
case PropertyType::FULLNAME:
|
|
||||||
$oVCard->FN = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::NICK_NAME:
|
|
||||||
$oVCard->NICKNAME = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::FIRST_NAME:
|
|
||||||
$sFirstName = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::LAST_NAME:
|
|
||||||
$sLastName = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::MIDDLE_NAME:
|
|
||||||
$sMiddleName = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::NAME_SUFFIX:
|
|
||||||
$sSuffix = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::NAME_PREFIX:
|
|
||||||
$sPrefix = $oProperty->Value;
|
|
||||||
break;
|
|
||||||
case PropertyType::EMAIl_PERSONAL:
|
|
||||||
case PropertyType::EMAIl_BUSSINES:
|
|
||||||
case PropertyType::EMAIl_OTHER:
|
|
||||||
$aParams = array('TYPE' => array('INTERNET'));
|
|
||||||
$aParams['TYPE'][] = PropertyType::EMAIl_BUSSINES === $oProperty->Type ? 'WORK' : 'HOME';
|
|
||||||
|
|
||||||
if (!$bPrefEmail)
|
|
||||||
{
|
|
||||||
$bPrefEmail = true;
|
|
||||||
$aParams['TYPE'][] = 'pref';
|
|
||||||
}
|
|
||||||
$oVCard->add('EMAIL', $oProperty->Value, $aParams);
|
|
||||||
break;
|
|
||||||
case PropertyType::WEB_PAGE_PERSONAL:
|
|
||||||
case PropertyType::WEB_PAGE_BUSSINES:
|
|
||||||
case PropertyType::WEB_PAGE_OTHER:
|
|
||||||
$aParams = array('TYPE' => array());
|
|
||||||
$aParams['TYPE'][] = PropertyType::WEB_PAGE_BUSSINES === $oProperty->Type ? 'WORK' : 'HOME';
|
|
||||||
$oVCard->add('URL', $oProperty->Value, $aParams);
|
|
||||||
break;
|
|
||||||
case PropertyType::PHONE_PERSONAL:
|
|
||||||
case PropertyType::PHONE_BUSSINES:
|
|
||||||
case PropertyType::PHONE_OTHER:
|
|
||||||
case PropertyType::MOBILE_PERSONAL:
|
|
||||||
case PropertyType::MOBILE_BUSSINES:
|
|
||||||
case PropertyType::MOBILE_OTHER:
|
|
||||||
case PropertyType::FAX_PERSONAL:
|
|
||||||
case PropertyType::FAX_BUSSINES:
|
|
||||||
case PropertyType::FAX_OTHER:
|
|
||||||
$aParams = array('TYPE' => array());
|
|
||||||
$sType = '';
|
|
||||||
if (\in_array($oProperty->Type, array(PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER)))
|
|
||||||
{
|
|
||||||
$sType = 'VOICE';
|
|
||||||
}
|
|
||||||
else if (\in_array($oProperty->Type, array(PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER)))
|
|
||||||
{
|
|
||||||
$sType = 'CELL';
|
|
||||||
}
|
|
||||||
else if (\in_array($oProperty->Type, array(PropertyType::FAX_PERSONAL, PropertyType::FAX_BUSSINES, PropertyType::FAX_OTHER)))
|
|
||||||
{
|
|
||||||
$sType = 'FAX';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($sType))
|
|
||||||
{
|
|
||||||
$aParams['TYPE'][] = $sType;
|
|
||||||
}
|
|
||||||
|
|
||||||
$aParams['TYPE'][] = \in_array($oProperty->Type, array(
|
|
||||||
PropertyType::PHONE_BUSSINES, PropertyType::MOBILE_BUSSINES, PropertyType::FAX_BUSSINES)) ? 'WORK' : 'HOME';
|
|
||||||
|
|
||||||
if (!$bPrefPhone)
|
|
||||||
{
|
|
||||||
$bPrefPhone = true;
|
|
||||||
$aParams['TYPE'][] = 'pref';
|
|
||||||
}
|
|
||||||
|
|
||||||
$oVCard->add('TEL', $oProperty->Value, $aParams);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$oVCard->UID = $this->IdContactStr;
|
|
||||||
$oVCard->N = array($sLastName, $sFirstName, $sMiddleName, $sPrefix, $sSuffix);
|
|
||||||
$oVCard->REV = \gmdate('Ymd', $this->Changed).'T'.\gmdate('His', $this->Changed).'Z';
|
|
||||||
|
|
||||||
return $oVCard;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function VCardUri()
|
|
||||||
{
|
|
||||||
return $this->IdContactStr.'.vcf';
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,114 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\PersonalAddressBook\Classes;
|
|
||||||
|
|
||||||
use RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
|
|
||||||
|
|
||||||
class Property
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $IdProperty;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $Type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $ScopeType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $TypeCustom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $Value;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $ValueCustom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
public $Frec;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
$iType = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::UNKNOWN, $sValue = '')
|
|
||||||
{
|
|
||||||
$this->Clear();
|
|
||||||
|
|
||||||
$this->Type = $iType;
|
|
||||||
$this->Value = $sValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function Clear()
|
|
||||||
{
|
|
||||||
$this->IdProperty = 0;
|
|
||||||
|
|
||||||
$this->Type = PropertyType::UNKNOWN;
|
|
||||||
$this->ScopeType = \RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
|
|
||||||
$this->TypeCustom = '';
|
|
||||||
|
|
||||||
$this->Value = '';
|
|
||||||
$this->ValueCustom = '';
|
|
||||||
|
|
||||||
$this->Frec = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsEmail()
|
|
||||||
{
|
|
||||||
return \in_array($this->Type, array(
|
|
||||||
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsPhone()
|
|
||||||
{
|
|
||||||
return \in_array($this->Type, array(
|
|
||||||
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES, PropertyType::PHONE_OTHER,
|
|
||||||
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES, PropertyType::MOBILE_OTHER,
|
|
||||||
PropertyType::FAX_PERSONAL, PropertyType::FAX_BUSSINES, PropertyType::FAX_OTHER
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function UpdateDependentValues()
|
|
||||||
{
|
|
||||||
// trimer
|
|
||||||
$this->Value = \trim($this->Value);
|
|
||||||
$this->ValueCustom = \trim($this->ValueCustom);
|
|
||||||
$this->TypeCustom = \trim($this->TypeCustom);
|
|
||||||
|
|
||||||
if (0 < \strlen($this->Value))
|
|
||||||
{
|
|
||||||
// lower
|
|
||||||
if ($this->IsEmail())
|
|
||||||
{
|
|
||||||
$this->Value = \strtolower($this->Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// phones clear value for searching
|
|
||||||
if ($this->IsPhone())
|
|
||||||
{
|
|
||||||
$sPhone = $this->Value;
|
|
||||||
$sPhone = \preg_replace('/^[+]+/', '', $sPhone);
|
|
||||||
$sPhone = \preg_replace('/[^\d]/', '', $sPhone);
|
|
||||||
$this->ValueCustom = $sPhone;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\PersonalAddressBook\Enumerations;
|
|
||||||
|
|
||||||
class PropertyType
|
|
||||||
{
|
|
||||||
const UNKNOWN = 0;
|
|
||||||
|
|
||||||
const FULLNAME = 10;
|
|
||||||
|
|
||||||
const FIRST_NAME = 15;
|
|
||||||
const LAST_NAME = 16;
|
|
||||||
const MIDDLE_NAME = 17;
|
|
||||||
const NICK_NAME = 18;
|
|
||||||
|
|
||||||
const NAME_PREFIX = 20;
|
|
||||||
const NAME_SUFFIX = 21;
|
|
||||||
|
|
||||||
const EMAIl_PERSONAL = 30;
|
|
||||||
const EMAIl_BUSSINES = 31;
|
|
||||||
const EMAIl_OTHER = 32;
|
|
||||||
|
|
||||||
const PHONE_PERSONAL = 50;
|
|
||||||
const PHONE_BUSSINES = 51;
|
|
||||||
const PHONE_OTHER = 52;
|
|
||||||
|
|
||||||
const MOBILE_PERSONAL = 60;
|
|
||||||
const MOBILE_BUSSINES = 61;
|
|
||||||
const MOBILE_OTHER = 62;
|
|
||||||
|
|
||||||
const FAX_PERSONAL = 70;
|
|
||||||
const FAX_BUSSINES = 71;
|
|
||||||
const FAX_OTHER = 72;
|
|
||||||
|
|
||||||
const FACEBOOK = 90;
|
|
||||||
const SKYPE = 91;
|
|
||||||
const GITHUB = 92;
|
|
||||||
|
|
||||||
const NOTE = 110;
|
|
||||||
|
|
||||||
const WEB_PAGE_PERSONAL = 220;
|
|
||||||
const WEB_PAGE_BUSSINES = 221;
|
|
||||||
const WEB_PAGE_OTHER = 222;
|
|
||||||
|
|
||||||
const CUSTOM = 250;
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\PersonalAddressBook\Enumerations;
|
|
||||||
|
|
||||||
class ScopeType
|
|
||||||
{
|
|
||||||
const DEFAULT_ = 0;
|
|
||||||
const SHARE_ALL = 2;
|
|
||||||
}
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,65 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace RainLoop\Providers\PersonalAddressBook;
|
|
||||||
|
|
||||||
interface PersonalAddressBookInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IsSupported();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function ContactSave($sEmail, &$oContact);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aContactIds
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function DeleteContacts($sEmail, $aContactIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aTagsIds
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function DeleteTags($sEmail, $aTagsIds);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param int $iOffset = 0
|
|
||||||
* @param int $iLimit = 20
|
|
||||||
* @param string $sSearch = ''
|
|
||||||
* @param int $iResultCount = 0
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function GetContacts($sEmail, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param string $sSearch
|
|
||||||
* @param int $iLimit = 20
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*
|
|
||||||
* @throws \InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
* @param array $aEmails
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function IncFrec($sEmail, $aEmails);
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue