Privacy/GDPR friendly version (removed: Social, Gravatar, Facebook, Google, Twitter, DropBox, OwnCloud)

Also removed: POP3, OAuth2 and update feature
Added: admin password_hash/password_verify
Requires: PHP 7.3+
Replaced: CRLF with LF
Replaced: pclZip with ZipArchive
This commit is contained in:
djmaze 2020-03-09 17:04:17 +01:00
parent 15ceddc202
commit 2cada68f41
293 changed files with 23728 additions and 85420 deletions

View file

@ -4,8 +4,5 @@ namespace RainLoop\Providers\AddressBook;
interface AddressBookInterface
{
/**
* @return bool
*/
public function IsSupported();
}
public function IsSupported() : bool;
}

View file

@ -66,7 +66,7 @@ class Contact
$this->Etag = '';
}
public function PopulateDisplayAndFullNameValue($bForceFullNameReplace = false)
public function PopulateDisplayAndFullNameValue(bool $bForceFullNameReplace = false)
{
$sFullName = '';
$sLastName = '';
@ -161,19 +161,13 @@ class Contact
$this->PopulateDisplayAndFullNameValue();
}
/**
* @return array
*/
public function RegenerateContactStr()
public function RegenerateContactStr() : array
{
$this->IdContactStr = \class_exists('SabreForRainLoop\DAV\Client') ?
\SabreForRainLoop\DAV\UUIDUtil::getUUID() : \MailSo\Base\Utils::Md5Rand();
}
/**
* @return array
*/
public function GetEmails()
public function GetEmails() : array
{
$aResult = array();
foreach ($this->Properties as /* @var $oProperty \RainLoop\Providers\AddressBook\Classes\Property */ &$oProperty)
@ -187,18 +181,12 @@ class Contact
return \array_unique($aResult);
}
/**
* @return string
*/
public function CardDavNameUri()
public function CardDavNameUri() : string
{
return $this->IdContactStr.'.vcf';
}
/**
* @return string
*/
public function ToVCard($sPreVCard = '', $oLogger = null)
public function ToVCard(string $sPreVCard = '', $oLogger = null) : string
{
$this->UpdateDependentValues();
@ -219,7 +207,7 @@ class Contact
{
$oVCard = \SabreForRainLoop\VObject\Reader::read($sPreVCard);
}
catch (\Exception $oExc)
catch (\Throwable $oExc)
{
if ($oLogger)
{
@ -309,10 +297,7 @@ class Contact
return (string) $oVCard->serialize();
}
/**
* @return string
*/
public function ToCsv($bWithHeader = false)
public function ToCsv(bool $bWithHeader = false) : string
{
$aData = array();
if ($bWithHeader)
@ -470,10 +455,8 @@ class Contact
/**
* @param mixed $oProp
* @param bool $bOldVersion
* @return string
*/
private function getPropertyValueHelper($oProp, $bOldVersion)
private function getPropertyValueHelper($oProp, bool $bOldVersion) : string
{
$sValue = \trim($oProp);
if ($bOldVersion && !isset($oProp->parameters['CHARSET']))
@ -495,10 +478,8 @@ class Contact
/**
* @param mixed $oProp
* @param bool $bOldVersion
* @return string
*/
private function addArrayPropertyHelper(&$aProperties, $oArrayProp, $iType)
private function addArrayPropertyHelper(array &$aProperties, $oArrayProp, int $iType) : string
{
foreach ($oArrayProp as $oProp)
{
@ -520,7 +501,7 @@ class Contact
}
}
public function PopulateByVCard($sUid, $sVCard, $sEtag = '', $oLogger = null)
public function PopulateByVCard(string $sUid, string $sVCard, string $sEtag = '', $oLogger = null)
{
if ("\xef\xbb\xbf" === \substr($sVCard, 0, 3))
{
@ -545,7 +526,7 @@ class Contact
{
$oVCard = \SabreForRainLoop\VObject\Reader::read($sVCard);
}
catch (\Exception $oExc)
catch (\Throwable $oExc)
{
if ($oLogger)
{
@ -559,14 +540,10 @@ class Contact
// $oLogger->WriteDump($sVCard);
// }
$bOwnCloud = false;
$aProperties = array();
if ($oVCard)
{
$bOwnCloud = empty($oVCard->PRODID) ? false :
false !== \strpos(\strtolower($oVCard->PRODID), 'owncloud');
$bOldVersion = empty($oVCard->VERSION) ? false :
\in_array((string) $oVCard->VERSION, array('2.1', '2.0', '1.0'));

View file

@ -65,51 +65,33 @@ class Property
$this->Frec = 0;
}
/**
* @return bool
*/
public function IsName()
public function IsName() : bool
{
return \in_array($this->Type, array(PropertyType::FULLNAME, PropertyType::FIRST_NAME,
PropertyType::LAST_NAME, PropertyType::MIDDLE_NAME, PropertyType::NICK_NAME));
}
/**
* @return bool
*/
public function IsEmail()
public function IsEmail() : bool
{
return PropertyType::EMAIl === $this->Type;
}
/**
* @return bool
*/
public function IsPhone()
public function IsPhone() : bool
{
return PropertyType::PHONE === $this->Type;
}
/**
* @return bool
*/
public function IsWeb()
public function IsWeb() : bool
{
return PropertyType::WEB_PAGE === $this->Type;
}
/**
* @return bool
*/
public function IsValueForLower()
public function IsValueForLower() : bool
{
return $this->IsEmail() || $this->IsName() || $this->IsWeb();
}
/**
* @return bool
*/
public function TypesAsArray()
public function TypesAsArray() : bool
{
$aResult = array();
if (!empty($this->TypeStr))
@ -121,10 +103,7 @@ class Property
return $aResult;
}
/**
* @return array
*/
public function TypesUpperAsArray()
public function TypesUpperAsArray() : array
{
return \array_map('strtoupper', $this->TypesAsArray());
}

View file

@ -28,7 +28,7 @@ class PdoAddressBook
*/
private $sPassword;
public function __construct($sDsn, $sUser = '', $sPassword = '', $sDsnType = 'mysql')
public function __construct(string $sDsn, string $sUser = '', string $sPassword = '', string $sDsnType = 'mysql')
{
$this->sDsn = $sDsn;
$this->sUser = $sUser;
@ -38,31 +38,25 @@ class PdoAddressBook
$this->bExplain = false; // debug
}
/**
* @return bool
*/
public function IsSupported()
public function IsSupported() : bool
{
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
return \is_array($aDrivers) ? \in_array($this->sDsnType, $aDrivers) : false;
}
/**
* @return bool
*/
public function IsSharingAllowed()
public function IsSharingAllowed() : bool
{
return $this->IsSupported() && false; // TODO
}
private function flushDeletedContacts($iUserID)
private function flushDeletedContacts(int $iUserID)
{
return !!$this->prepareAndExecute('DELETE FROM rainloop_ab_contacts WHERE id_user = :id_user AND deleted = 1', array(
':id_user' => array($iUserID, \PDO::PARAM_INT)
));
}
private function updateContactEtagAndTime($iUserID, $mID, $sEtag, $iChanged)
private function updateContactEtagAndTime(int $iUserID, int $mID, string $sEtag, int $iChanged)
{
return !!$this->prepareAndExecute('UPDATE rainloop_ab_contacts SET changed = :changed, etag = :etag '.
'WHERE id_user = :id_user AND id_contact = :id_contact', array(
@ -74,7 +68,7 @@ class PdoAddressBook
);
}
private function prepearDatabaseSyncData($iUserID)
private function prepearDatabaseSyncData(int $iUserID)
{
$aResult = array();
$oStmt = $this->prepareAndExecute('SELECT id_contact, id_contact_str, changed, deleted, etag FROM rainloop_ab_contacts WHERE id_user = :id_user', array(
@ -110,7 +104,7 @@ class PdoAddressBook
return $aResult;
}
private function prepearRemoteSyncData($oClient, $sPath)
private function prepearRemoteSyncData($oClient, string $sPath)
{
$mResult = false;
$aResponse = null;
@ -126,7 +120,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -181,7 +175,7 @@ class PdoAddressBook
return $mResult;
}
private function davClientRequest($oClient, $sCmd, $sUrl, $mData = null)
private function davClientRequest($oClient, string $sCmd, string $sUrl, $mData = null)
{
\MailSo\Base\Utils::ResetTimeLimit();
@ -212,7 +206,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($oResponse, \MailSo\Log\Enumerations\Type::INFO, 'DAV');
// }
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -220,13 +214,7 @@ class PdoAddressBook
return $oResponse;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sPath
*
* @return bool
*/
private function detectionPropFind($oClient, $sPath)
private function detectionPropFind(\SabreForRainLoop\DAV\Client $oClient, string $sPath) : bool
{
$aResponse = null;
@ -243,7 +231,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -251,15 +239,7 @@ class PdoAddressBook
return $aResponse;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return array
*/
private function getContactsPaths(&$oClient, $sUser, $sPassword, $sProxy = '')
private function getContactsPaths(\SabreForRainLoop\DAV\Client &$oClient, string $sUser, string $sPassword, string $sProxy = '') : array
{
$aContactsPaths = array();
@ -445,13 +425,7 @@ class PdoAddressBook
return $aContactsPaths;
}
/**
* @param \SabreForRainLoop\DAV\Client $oClient
* @param string $sPath
*
* @return bool
*/
private function checkContactsPath(&$oClient, $sPath)
private function checkContactsPath(\SabreForRainLoop\DAV\Client &$oClient, string $sPath) : bool
{
if (!$oClient)
{
@ -469,7 +443,7 @@ class PdoAddressBook
// $this->oLogger->WriteDump($aResponse);
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$this->oLogger->WriteException($oException);
}
@ -501,7 +475,7 @@ class PdoAddressBook
return $bGood;
}
public function getDavClientFromUrl($sUrl, $sUser, $sPassword, $sProxy = '')
public function getDavClientFromUrl(string $sUrl, string $sUser, string $sPassword, string $sProxy = '')
{
if (!\preg_match('/^http[s]?:\/\//i', $sUrl))
{
@ -553,16 +527,7 @@ class PdoAddressBook
return $oClient;
}
/**
* @param string $sEmail
* @param string $sUrl
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return bool
*/
public function getDavClient($sUrl, $sUser, $sPassword, $sProxy = '')
public function getDavClient(string $sUrl, string $sUser, string $sPassword, string $sProxy = '') : bool
{
if (!\class_exists('SabreForRainLoop\DAV\Client'))
{
@ -655,16 +620,7 @@ class PdoAddressBook
return $oClient;
}
/**
* @param string $sEmail
* @param string $sUrl
* @param string $sUser
* @param string $sPassword
* @param string $sProxy = ''
*
* @return bool
*/
public function Sync($sEmail, $sUrl, $sUser, $sPassword, $sProxy = '')
public function Sync(string $sEmail, string $sUrl, string $sUser, string $sPassword, string $sProxy = '') : bool
{
$this->SyncDatabase();
@ -815,13 +771,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param string $sType = 'vcf'
*
* @return bool
*/
public function Export($sEmail, $sType = 'vcf')
public function Export(string $sEmail, string $sType = 'vcf') : bool
{
$this->SyncDatabase();
@ -861,14 +811,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param \RainLoop\Providers\AddressBook\Classes\Contact $oContact
* @param bool $bSyncDb = true
*
* @return bool
*/
public function ContactSave($sEmail, &$oContact, $bSyncDb = true)
public function ContactSave(string $sEmail, \RainLoop\Providers\AddressBook\Classes\Contact $oContact, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -973,7 +916,7 @@ class PdoAddressBook
}
}
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
throw $oException;
}
@ -981,14 +924,7 @@ class PdoAddressBook
return 0 < $iIdContact;
}
/**
* @param string $sEmail
* @param array $aContactIds
* @param bool $bSyncDb = true
*
* @return bool
*/
public function DeleteContacts($sEmail, $aContactIds, $bSyncDb = true)
public function DeleteContacts(string $sEmail, array $aContactIds, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -1023,13 +959,7 @@ class PdoAddressBook
return true;
}
/**
* @param string $sEmail
* @param bool $bSyncDb = true
*
* @return bool
*/
public function DeleteAllContacts($sEmail, $bSyncDb = true)
public function DeleteAllContacts(string $sEmail, bool $bSyncDb = true) : bool
{
if ($bSyncDb)
{
@ -1046,16 +976,7 @@ class PdoAddressBook
return true;
}
/**
* @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)
public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
{
$this->SyncDatabase();
@ -1246,13 +1167,11 @@ class PdoAddressBook
}
/**
* @param string $sEmail
* @param string $mID
* @param bool $bIsStrID = false
* @param mixed $mID
*
* @return \RainLoop\Providers\AddressBook\Classes\Contact|null
*/
public function GetContactByID($sEmail, $mID, $bIsStrID = false)
public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false)
{
$mID = \trim($mID);
@ -1350,15 +1269,9 @@ class PdoAddressBook
}
/**
* @param string $sEmail
* @param string $sSearch
* @param int $iLimit = 20
*
* @return array
*
* @throws \InvalidArgumentException
*/
public function GetSuggestions($sEmail, $sSearch, $iLimit = 20)
public function GetSuggestions(string $sEmail, string $sSearch, int $iLimit = 20) : array
{
$sSearch = \trim($sSearch);
if (0 === \strlen($sSearch))
@ -1553,14 +1466,7 @@ class PdoAddressBook
return array();
}
/**
* @param string $sEmail
* @param array $aEmails
* @param bool $bCreateAuto = true
*
* @return bool
*/
public function IncFrec($sEmail, $aEmails, $bCreateAuto = true)
public function IncFrec(string $sEmail, array $aEmails, bool $bCreateAuto = true) : bool
{
$self = $this;
$aEmailsObjects = \array_map(function ($mItem) {
@ -1569,7 +1475,7 @@ class PdoAddressBook
{
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
}
catch (\Exception $oException) { unset($oException); }
catch (\Throwable $oException) { unset($oException); }
return $oResult;
}, $aEmails);
@ -1721,10 +1627,7 @@ class PdoAddressBook
));
}
/**
* @return string
*/
public function Test()
public function Test() : string
{
$sResult = '';
try
@ -1735,7 +1638,7 @@ class PdoAddressBook
$sResult = 'Unknown database error';
}
}
catch (\Exception $oException)
catch (\Throwable $oException)
{
$sResult = $oException->getMessage();
if (!empty($sResult) && !\MailSo\Base\Utils::IsAscii($sResult) && !\MailSo\Base\Utils::IsUtf8($sResult))
@ -1752,7 +1655,7 @@ class PdoAddressBook
return $sResult;
}
private function getInitialTablesArray($sDbType)
private function getInitialTablesArray(string $sDbType)
{
switch ($sDbType)
{
@ -1876,10 +1779,7 @@ SQLITEINITIAL;
return $aResult;
}
/**
* @return bool
*/
public function SyncDatabase()
public function SyncDatabase() : bool
{
static $mCache = null;
if (null !== $mCache)
@ -1926,12 +1826,7 @@ SQLITEINITIAL;
return $mCache;
}
/**
* @param int $iUserID
* @param int $iIdContact
* @return array
*/
private function getContactFreq($iUserID, $iIdContact)
private function getContactFreq(int $iUserID, int $iIdContact) : array
{
$aResult = array();
@ -1961,25 +1856,13 @@ SQLITEINITIAL;
return $aResult;
}
/**
* @param string $sSearch
* @param string $sEscapeSign = '='
*
* @return string
*/
private function specialConvertSearchValue($sSearch, $sEscapeSign = '=')
private function specialConvertSearchValue(string $sSearch, string $sEscapeSign = '=') : string
{
return '%'.\str_replace(array($sEscapeSign, '_', '%'),
array($sEscapeSign.$sEscapeSign, $sEscapeSign.'_', $sEscapeSign.'%'), $sSearch).'%';
}
/**
* @param string $sSearch
* @param string $sEscapeSign = '='
*
* @return string
*/
private function specialConvertSearchValueLower($sSearch, $sEscapeSign = '=')
private function specialConvertSearchValueLower(string $sSearch, string $sEscapeSign = '=') : string
{
if (!\MailSo\Base\Utils::FunctionExistsAndEnabled('mb_strtolower'))
{
@ -1991,22 +1874,14 @@ SQLITEINITIAL;
(string) @\mb_strtolower($sSearch, 'UTF-8')).'%';
}
/**
* @param string $sSearch
*
* @return string
*/
private function specialConvertSearchValueCustomPhone($sSearch)
private function specialConvertSearchValueCustomPhone(string $sSearch) : string
{
$sResult = '%'.\preg_replace('/[^\d]/', '', $sSearch).'%';
return '%%' === $sResult ? '' : $sResult;
}
/**
* @return array
*/
protected function getPdoAccessData()
protected function getPdoAccessData() : array
{
return array($this->sDsnType, $this->sDsn, $this->sUser, $this->sPassword);
}
}
}