CardDAV (pre-alpha/unstable)

This commit is contained in:
RainLoop Team 2013-12-23 04:06:48 +04:00
parent 0ec965bccb
commit 599e934b4a
76 changed files with 6984 additions and 1512 deletions

View file

@ -8,6 +8,11 @@ abstract class AbstractProvider
* @var \RainLoop\Account
*/
protected $oAccount;
/**
* @var \MailSo\Log\Logger
*/
protected $oLogger = null;
/**
* @return bool
@ -24,4 +29,23 @@ abstract class AbstractProvider
{
$this->oAccount = $oAccount;
}
/**
* @param \MailSo\Log\Logger $oLogger
*/
public function SetLogger($oLogger)
{
if ($oLogger instanceof \MailSo\Log\Logger)
{
$this->oLogger = $oLogger;
}
}
/**
* @return \MailSo\Log\Logger|null
*/
public function Logger()
{
return $this->oLogger;
}
}

View file

@ -71,6 +71,17 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
$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
@ -97,29 +108,29 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sEmail
* @param \RainLoop\Providers\PersonalAddressBook\Classes\Contact $oContact
*
* @return bool
*/
public function ContactSave($oAccount, &$oContact)
public function ContactSave($sEmail, &$oContact)
{
return $this->IsActive() ? $this->oDriver->ContactSave($oAccount, $oContact) : false;
return $this->IsActive() ? $this->oDriver->ContactSave($sEmail, $oContact) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sEmail
* @param array $aContactIds
*
* @return bool
*/
public function DeleteContacts($oAccount, $aContactIds)
public function DeleteContacts($sEmail, $aContactIds)
{
return $this->IsActive() ? $this->oDriver->DeleteContacts($oAccount, $aContactIds) : false;
return $this->IsActive() ? $this->oDriver->DeleteContacts($sEmail, $aContactIds) : false;
}
/**
* @param \RainLoop\Account|mixed $mAccountOrId
* @param string $sEmail
* @param int $iOffset = 0
* @param type $iLimit = 20
* @param string $sSearch = ''
@ -127,9 +138,9 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
*
* @return array
*/
public function GetContacts($mAccountOrId, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
public function GetContacts($sEmail, $iOffset = 0, $iLimit = 20, $sSearch = '', &$iResultCount = 0)
{
return $this->IsActive() ? $this->oDriver->GetContacts($mAccountOrId,
return $this->IsActive() ? $this->oDriver->GetContacts($sEmail,
$iOffset, $iLimit, $sSearch, $iResultCount) : array();
}
@ -146,7 +157,7 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sEmail
* @param string $sSearch
* @param int $iLimit = 20
*
@ -154,20 +165,20 @@ class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($oAccount, $sSearch, $iLimit = 20)
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20)
{
return $this->IsActive() ? $this->oDriver->GetSuggestions($oAccount, $sSearch, $iLimit) : array();
return $this->IsActive() ? $this->oDriver->GetSuggestions($sEmail, $sSearch, $iLimit) : array();
}
/**
* @param \RainLoop\Account $oAccount
* @param string $sEmail
* @param array $aEmails
* @param bool $bCreateAuto = true
* @param bool $bCreateAuto = true
*
* @return bool
*/
public function IncFrec($oAccount, $aEmails, $bCreateAuto = true)
public function IncFrec($sEmail, $aEmails, $bCreateAuto = true)
{
return $this->IsActive() ? $this->oDriver->IncFrec($oAccount, $aEmails, $bCreateAuto) : false;
return $this->IsActive() ? $this->oDriver->IncFrec($sEmail, $aEmails, $bCreateAuto) : false;
}
}

View file

@ -2,7 +2,10 @@
namespace RainLoop\Providers\PersonalAddressBook\Classes;
use RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType;
use
RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType,
RainLoop\Providers\PersonalAddressBook\Classes\Property
;
class Contact
{
@ -21,16 +24,6 @@ class Contact
*/
public $Display;
/**
* @var string
*/
public $DisplayName;
/**
* @var string
*/
public $DisplayEmail;
/**
* @var int
*/
@ -56,6 +49,21 @@ class Contact
*/
public $ReadOnly;
/**
* @var string
*/
public $CardDavData;
/**
* @var string
*/
public $CardDavHash;
/**
* @var int
*/
public $CardDavSize;
public function __construct()
{
$this->Clear();
@ -67,19 +75,25 @@ class Contact
$this->IdContactStr = '';
$this->IdUser = 0;
$this->Display = '';
$this->DisplayName = '';
$this->DisplayEmail = '';
$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()
public function UpdateDependentValues($bReparseVcard = true)
{
$sDisplayName = '';
$sDisplayEmail = '';
$sLastName = '';
$sFirstName = '';
$sEmail = '';
$sOther = '';
$oFullNameProperty = null;
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
{
@ -87,16 +101,33 @@ class Contact
{
$oProperty->ScopeType = $this->ScopeType;
$oProperty->UpdateDependentValues();
if ('' === $sDisplayName && \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::FULLNAME === $oProperty->Type &&
0 < \strlen($oProperty->Value))
if (!$oFullNameProperty && PropertyType::FULLNAME === $oProperty->Type)
{
$sDisplayName = $oProperty->Value;
$oFullNameProperty =& $oProperty;
}
else if ('' === $sDisplayEmail && $oProperty->IsEmail() &&
0 < \strlen($oProperty->Value))
if (0 < \strlen($oProperty->Value))
{
$sDisplayEmail = $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::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES,
)))
{
$sOther = $oProperty->Value;
}
}
}
}
@ -106,10 +137,55 @@ class Contact
$this->IdContactStr = \Sabre\DAV\UUIDUtil::getUUID();
}
$this->DisplayName = $sDisplayName;
$this->DisplayEmail = $sDisplayEmail;
$sDisplay = '';
if (0 < \strlen($sLastName) || 0 < \strlen($sFirstName))
{
$sDisplay = \trim($sLastName.' '.$sFirstName);
}
$this->Display = 0 < \strlen($sDisplayName) ? $sDisplayName : (!empty($sDisplayEmail) ? $sDisplayEmail : '');
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;
}
if (!empty($this->CardDavData))
{
$this->CardDavHash = \md5($this->CardDavData);
$this->CardDavSize = \strlen($this->CardDavData);
}
else
{
$this->CardDavHash = '';
$this->CardDavSize = 0;
}
}
/**
@ -129,19 +205,183 @@ class Contact
return \array_unique($aResult);
}
/**
* @param string $sVCard
*/
public function ParseVCard($sVCard)
{
$bNew = empty($this->IdContact);
if (!$bNew)
{
$this->Properties = array();
}
$oVCard = null;
$aProperties = array();
try
{
$oVCard = \Sabre\VObject\Reader::read($sVCard);
}
catch (\Exception $oExc) {}
if ($oVCard && $oVCard->UID)
{
$this->IdContactStr = (string) $oVCard->UID;
if (isset($oVCard->FN) && '' !== \trim($oVCard->FN))
{
$aProperties[] = new Property(PropertyType::FULLNAME, \trim($oVCard->FN));
}
if (isset($oVCard->NICKNAME) && '' !== \trim($oVCard->NICKNAME))
{
$aProperties[] = new Property(PropertyType::NICK_NAME, \trim($oVCard->NICKNAME));
}
// if (isset($oVCard->NOTE) && '' !== \trim($oVCard->NOTE))
// {
// $aProperties[] = new Property(PropertyType::NOTE, \trim($oVCard->NOTE));
// }
if (isset($oVCard->N))
{
$aNames = $oVCard->N->getParts();
foreach ($aNames as $iIndex => $sValue)
{
$sValue = \trim($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))
{
foreach($oVCard->EMAIL as $oEmail)
{
$oTypes = $oEmail ? $oEmail['TYPE'] : null;
$sEmail = $oTypes ? \trim((string) $oEmail) : '';
if ($oTypes && 0 < \strlen($sEmail))
{
if ($oTypes->has('WORK'))
{
$aProperties[] = new Property(PropertyType::EMAIl_BUSSINES, $sEmail);
}
else
{
$aProperties[] = new Property(PropertyType::EMAIl_PERSONAL, $sEmail);
}
}
}
}
if (isset($oVCard->TEL))
{
foreach($oVCard->TEL as $oTel)
{
$oTypes = $oTel ? $oTel['TYPE'] : null;
$sTel = $oTypes ? \trim((string) $oTel) : '';
if ($oTypes && 0 < \strlen($sTel))
{
if ($oTypes->has('VOICE'))
{
if ($oTypes->has('WORK'))
{
$aProperties[] = new Property(PropertyType::PHONE_BUSSINES, $sTel);
}
else
{
$aProperties[] = new Property(PropertyType::PHONE_PERSONAL, $sTel);
}
}
else if ($oTypes->has('CELL'))
{
if ($oTypes->has('WORK'))
{
$aProperties[] = new Property(PropertyType::MOBILE_BUSSINES, $sTel);
}
else
{
$aProperties[] = new Property(PropertyType::MOBILE_PERSONAL, $sTel);
}
}
else if ($oTypes->has('FAX'))
{
if ($oTypes->has('WORK'))
{
$aProperties[] = new Property(PropertyType::FAX_BUSSINES, $sTel);
}
else
{
$aProperties[] = new Property(PropertyType::FAX_PERSONAL, $sTel);
}
}
else if ($oTypes->has('WORK'))
{
$aProperties[] = new Property(PropertyType::MOBILE_BUSSINES, $sTel);
}
else
{
$aProperties[] = new Property(PropertyType::MOBILE_PERSONAL, $sTel);
}
}
}
}
$this->Properties = $aProperties;
$this->CardDavData = $sVCard;
}
$this->UpdateDependentValues(false);
}
/**
* @return string
*/
public function ToVCardObject()
public function ToVCardObject($sPreVCard = '')
{
$this->UpdateDependentValues();
// $this->UpdateDependentValues();
$oVCard = new \Sabre\VObject\Component\VCard('VCARD');
$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';
$sFirstName = $sSurName = '';
unset($oVCard->FN, $oVCard->EMAIL, $oVCard->TEL);
$sFirstName = $sLastName = $sMiddleName = $sSuffix = $sPrefix = '';
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\PersonalAddressBook\Classes\Property */ &$oProperty)
{
if ($oProperty)
@ -151,55 +391,55 @@ class Contact
case PropertyType::FULLNAME:
$oVCard->FN = $oProperty->Value;
break;
case PropertyType::NICK:
case PropertyType::NICK_NAME:
$oVCard->NICKNAME = $oProperty->Value;
break;
case PropertyType::EMAIl_PERSONAL:
case PropertyType::EMAIl_OTHER:
$oVCard->add('EMAIL', $oProperty->Value, array('TYPE' => 'INTERNET', 'TYPE' => 'HOME'));
$oVCard->add('EMAIL', $oProperty->Value, array('TYPE' => array('INTERNET', 'HOME')));
break;
case PropertyType::EMAIl_BUSSINES:
$oVCard->add('EMAIL', $oProperty->Value, array('TYPE' => 'INTERNET', 'TYPE' => 'WORK'));
$oVCard->add('EMAIL', $oProperty->Value, array('TYPE' => array('INTERNET', 'WORK')));
break;
case PropertyType::PHONE_PERSONAL:
case PropertyType::PHONE_OTHER:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => 'VOICE', 'TYPE' => 'HOME'));
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('VOICE', 'HOME')));
break;
case PropertyType::PHONE_BUSSINES:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => 'VOICE', 'TYPE' => 'WORK'));
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('VOICE', 'WORK')));
break;
case PropertyType::MOBILE_PERSONAL:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('CELL', 'HOME')));
break;
case PropertyType::MOBILE_BUSSINES:
case PropertyType::MOBILE_OTHER:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => 'VOICE', 'TYPE' => 'CELL'));
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('CELL', 'WORK')));
break;
case PropertyType::FAX_PERSONAL:
case PropertyType::FAX_OTHER:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => 'FAX', 'TYPE' => 'HOME'));
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('FAX', 'HOME')));
break;
case PropertyType::FAX_BUSSINES:
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => 'FAX', 'TYPE' => 'WORK'));
$oVCard->add('TEL', $oProperty->Value, array('TYPE' => array('FAX', 'WORK')));
break;
case PropertyType::FIRST_NAME:
$sFirstName = $oProperty->Value;
break;
case PropertyType::SUR_NAME:
$sSurName = $oProperty->Value;
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;
}
}
}
$oVCard->UID = $this->VCardUID();
// $oVCard->N = array(
// $sSurName,
// $sFirstName,
// '',
// '',
// '',
// ''
// );
$oVCard->UID = $this->IdContactStr;
$oVCard->N = array($sLastName, $sFirstName, $sMiddleName, $sPrefix, $sSuffix);
$oVCard->REV = gmdate('Ymd').'T'.gmdate('His').'Z';
return $oVCard;
}
@ -207,10 +447,8 @@ class Contact
/**
* @return string
*/
public function VCardUID()
public function VCardUri()
{
return $this->IdContactStr.'.vcf';
}
}

View file

@ -41,9 +41,13 @@ class Property
*/
public $Frec;
public function __construct()
public function __construct(
$iType = \RainLoop\Providers\PersonalAddressBook\Enumerations\PropertyType::UNKNOWN, $sValue = '')
{
$this->Clear();
$this->Type = $iType;
$this->Value = $sValue;
}
public function Clear()
@ -66,7 +70,7 @@ class Property
public function IsEmail()
{
return \in_array($this->Type, array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES
));
}
@ -76,9 +80,9 @@ class Property
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_BUSSINES, PropertyType::FAX_OTHER
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES,
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES,
PropertyType::FAX_BUSSINES
));
}

View file

@ -9,31 +9,30 @@ class PropertyType
const FULLNAME = 10;
const FIRST_NAME = 15;
const SUR_NAME = 16;
const LAST_NAME = 16;
const MIDDLE_NAME = 17;
const NICK = 18;
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 DESCRIPTION = 110;
const NOTE = 110;
const CUSTOM = 250;
}

View file

@ -92,6 +92,32 @@ class PdoPersonalAddressBook
return 0 < $iId ? (string) $iId : '';
}
/**
* @param string $sEmail
* @return string
*/
public function GetCtagByEmail($sEmail)
{
$sResult = '0';
$iUserID = $this->getUserId($sEmail);
if (0 < $iUserID)
{
$oStmt = $this->prepareAndExecute('SELECT MAX(id_prop) as max_value FROM rainloop_pab_properties WHERE id_user = :id_user',
array(':id_user' => array($iUserID, \PDO::PARAM_INT)));
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if ($aFetch && !empty($aFetch[0]['max_value']))
{
$sResult = 'RL-CTAG-'.((string) $aFetch[0]['max_value']);
}
}
}
return $sResult;
}
/**
* @param string $sEmail
* @param bool $bCreate = false
@ -142,7 +168,7 @@ class PdoPersonalAddressBook
$this->Sync();
$iUserID = $this->getUserId($sEmail);
$iIdContact = \strlen($oContact->IdContact) && \is_numeric($oContact->IdContact) ? (int) $oContact->IdContact : 0;
$iIdContact = 0 < \strlen($oContact->IdContact) && \is_numeric($oContact->IdContact) ? (int) $oContact->IdContact : 0;
$bUpdate = 0 < $iIdContact;
@ -166,8 +192,10 @@ class PdoPersonalAddressBook
{
$aFreq = $this->getContactFreq($iUserID, $iIdContact);
$sSql = 'UPDATE rainloop_pab_contacts SET id_contact_str = :id_contact_str, display = :display, display_name = :display_name, display_email = :display_email, '.
'scope_type = :scope_type, changed = :changed WHERE id_user = :id_user AND id_contact = :id_contact';
$sSql = 'UPDATE rainloop_pab_contacts SET id_contact_str = :id_contact_str, display = :display, '.
'scope_type = :scope_type, changed = :changed, '.
'carddav_data = :carddav_data, carddav_hash = :carddav_hash, carddav_size = :carddav_size '.
'WHERE id_user = :id_user AND id_contact = :id_contact';
$this->prepareAndExecute($sSql,
array(
@ -175,10 +203,12 @@ class PdoPersonalAddressBook
':id_contact' => array($iIdContact, \PDO::PARAM_INT),
':id_contact_str' => array($oContact->IdContactStr, \PDO::PARAM_STR),
':display' => array($oContact->Display, \PDO::PARAM_STR),
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
':carddav_data' => array($oContact->CardDavData, \PDO::PARAM_STR),
':carddav_hash' => array($oContact->CardDavHash, \PDO::PARAM_STR),
':carddav_size' => array($oContact->CardDavSize, \PDO::PARAM_INT)
)
);
@ -194,18 +224,20 @@ class PdoPersonalAddressBook
else
{
$sSql = 'INSERT INTO rainloop_pab_contacts '.
'( id_user, id_contact_str, display, display_name, display_email, scope_type, changed) VALUES '.
'(:id_user, :id_contact_str, :display, :display_name, :display_email, :scope_type, :changed)';
'( id_user, id_contact_str, display, scope_type, changed, carddav_data, carddav_hash, carddav_size) VALUES '.
'(:id_user, :id_contact_str, :display, :scope_type, :changed, :carddav_data, :carddav_hash, :carddav_size)';
$this->prepareAndExecute($sSql,
array(
':id_user' => array($iUserID, \PDO::PARAM_INT),
':id_contact_str' => array($oContact->IdContactStr, \PDO::PARAM_STR),
':display' => array($oContact->Display, \PDO::PARAM_STR),
':display_name' => array($oContact->DisplayName, \PDO::PARAM_STR),
':display_email' => array($oContact->DisplayEmail, \PDO::PARAM_STR),
':scope_type' => array($oContact->ScopeType, \PDO::PARAM_INT),
':changed' => array($oContact->Changed, \PDO::PARAM_INT)
':changed' => array($oContact->Changed, \PDO::PARAM_INT),
':carddav_data' => array($oContact->CardDavData, \PDO::PARAM_STR),
':carddav_hash' => array($oContact->CardDavHash, \PDO::PARAM_STR),
':carddav_size' => array($oContact->CardDavSize, \PDO::PARAM_INT)
)
);
@ -356,9 +388,9 @@ class PdoPersonalAddressBook
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '').
') AND (prop_value LIKE :search ESCAPE \'=\' OR ('.
'prop_type IN ('.\implode(',', 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
PropertyType::PHONE_PERSONAL, PropertyType::PHONE_BUSSINES,
PropertyType::MOBILE_PERSONAL, PropertyType::MOBILE_BUSSINES,
PropertyType::FAX_PERSONAL, PropertyType::FAX_BUSSINES
)).') AND prop_value_custom LIKE :search_custom_phone'.
')) GROUP BY id_contact, id_prop';
@ -467,8 +499,6 @@ class PdoPersonalAddressBook
$oContact->IdContact = (string) $iIdContact;
$oContact->IdContactStr = isset($aItem['id_contact_str']) ? (string) $aItem['id_contact_str'] : '';
$oContact->Display = isset($aItem['display']) ? (string) $aItem['display'] : '';
$oContact->DisplayName = isset($aItem['display_name']) ? (string) $aItem['display_name'] : '';
$oContact->DisplayEmail = isset($aItem['display_email']) ? (string) $aItem['display_email'] : '';
$oContact->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
@ -551,8 +581,10 @@ class PdoPersonalAddressBook
$iUserID = $this->getUserId($sEmail);
$sSql = 'SELECT * FROM rainloop_pab_contacts '.
'WHERE id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '')
'WHERE ('.
'id_user = :id_user'.
($this->bConsiderShare ? ' OR scope_type = :scope_type_share_all' : '').
')'
;
$aParams = array(
@ -584,6 +616,7 @@ class PdoPersonalAddressBook
if ($oStmt)
{
$aFetch = $oStmt->fetchAll(\PDO::FETCH_ASSOC);
if (\is_array($aFetch) && 0 < \count($aFetch))
{
foreach ($aFetch as $aItem)
@ -596,12 +629,14 @@ class PdoPersonalAddressBook
$oContact->IdContact = (string) $iIdContact;
$oContact->IdContactStr = isset($aItem['id_contact_str']) ? (string) $aItem['id_contact_str'] : '';
$oContact->Display = isset($aItem['display']) ? (string) $aItem['display'] : '';
$oContact->DisplayName = isset($aItem['display_name']) ? (string) $aItem['display_name'] : '';
$oContact->DisplayEmail = isset($aItem['display_email']) ? (string) $aItem['display_email'] : '';
$oContact->ScopeType = isset($aItem['scope_type']) ? (int) $aItem['scope_type'] :
\RainLoop\Providers\PersonalAddressBook\Enumerations\ScopeType::DEFAULT_;
$oContact->Changed = isset($aItem['changed']) ? (int) $aItem['changed'] : 0;
$oContact->ReadOnly = $iUserID !== (isset($aItem['id_user']) ? (int) $aItem['id_user'] : 0);
$oContact->CardDavData = empty($aItem['carddav_data']) ? '' : (string) $aItem['carddav_data'];
$oContact->CardDavHash = empty($aItem['carddav_hash']) ? \md5($oContact->CardDavData) : (string) $aItem['carddav_hash'];
$oContact->CardDavSize = empty($aItem['carddav_size']) ? \strlen($oContact->CardDavData) : (int) $aItem['carddav_size'];
}
}
}
@ -674,7 +709,7 @@ class PdoPersonalAddressBook
$iUserID = $this->getUserId($sEmail);
$sTypes = implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::FULLNAME
));
$sSql = 'SELECT id_contact, id_prop, prop_type, prop_value FROM rainloop_pab_properties '.
@ -716,7 +751,7 @@ class PdoPersonalAddressBook
$aIdContacts[$iIdContact] = $iIdContact;
$iType = isset($aItem['prop_type']) ? (int) $aItem['prop_type'] : PropertyType::UNKNOWN;
if (\in_array($iType, array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME)))
if (\in_array($iType, array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::FULLNAME)))
{
if (!\in_array($iIdContact, $aSkipIds))
{
@ -745,7 +780,7 @@ class PdoPersonalAddressBook
$oStmt->closeCursor();
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER, PropertyType::FULLNAME
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::FULLNAME
));
$sSql = 'SELECT id_prop, id_contact, prop_type, prop_value FROM rainloop_pab_properties '.
@ -771,8 +806,7 @@ class PdoPersonalAddressBook
{
$aNames[$iIdContact] = $aItem['prop_value'];
}
else if (\in_array($iType,
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
else if (\in_array($iType, array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES)))
{
if (!isset($aEmails[$iIdContact]))
{
@ -804,8 +838,7 @@ class PdoPersonalAddressBook
}
}
}
else if (\in_array($iType,
array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER)))
else if (\in_array($iType, array(PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES)))
{
$aResult[] = array((string) $aItem['prop_value'],
isset($aNames[$iIdContact]) ? (string) $aNames[$iIdContact] : '');
@ -858,7 +891,7 @@ class PdoPersonalAddressBook
$iUserID = $this->getUserId($sEmail);
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES
));
$aExists = array();
@ -1203,6 +1236,9 @@ SQLITEINITIAL;
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD id_contact_str varchar(128) NOT NULL DEFAULT \'\' AFTER id_contact;',
'ALTER TABLE rainloop_pab_contacts ADD carddav_data MEDIUMTEXT;',
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash varchar(128) NOT NULL DEFAULT \'\';',
'ALTER TABLE rainloop_pab_contacts ADD carddav_size int UNSIGNED NOT NULL DEFAULT 0;',
'CREATE TABLE IF NOT EXISTS rainloop_pab_users_hashes (
id_user int UNSIGNED NOT NULL,
pass_hash varchar(128) NOT NULL
@ -1214,6 +1250,9 @@ SQLITEINITIAL;
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD id_contact_str varchar(128) NOT NULL DEFAULT \'\';',
'ALTER TABLE rainloop_pab_contacts ADD carddav_data TEXT;',
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash varchar(128) NOT NULL DEFAULT \'\';',
'ALTER TABLE rainloop_pab_contacts ADD carddav_size integer NOT NULL DEFAULT 0;',
'CREATE TABLE rainloop_pab_users_hashes (
id_user integer NOT NULL,
pass_hash varchar(128) NOT NULL
@ -1225,6 +1264,9 @@ SQLITEINITIAL;
1 => $this->getInitialTablesArray($this->sDsnType),
2 => array(
'ALTER TABLE rainloop_pab_contacts ADD id_contact_str text NOT NULL DEFAULT \'\';',
'ALTER TABLE rainloop_pab_contacts ADD carddav_data text;',
'ALTER TABLE rainloop_pab_contacts ADD carddav_hash text NOT NULL DEFAULT \'\';',
'ALTER TABLE rainloop_pab_contacts ADD carddav_size integer NOT NULL DEFAULT 0;',
'CREATE TABLE rainloop_pab_users_hashes (
id_user integer NOT NULL,
pass_hash text NOT NULL
@ -1246,7 +1288,7 @@ SQLITEINITIAL;
$aResult = array();
$sTypes = \implode(',', array(
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES, PropertyType::EMAIl_OTHER
PropertyType::EMAIl_PERSONAL, PropertyType::EMAIl_BUSSINES
));
$sSql = 'SELECT prop_value, prop_frec FROM rainloop_pab_properties WHERE id_user = :id_user AND id_contact = :id_contact AND prop_type IN ('.$sTypes.')';