Allowed contacts for ownCloud package. + contacts suggestions improvements.

This commit is contained in:
RainLoop Team 2015-04-28 22:21:17 +04:00
parent 1d61ea347f
commit 56a11e5833
5 changed files with 97 additions and 49 deletions

View file

@ -235,74 +235,77 @@ class Actions
*/
private function fabrica($sName, $oAccount = null)
{
$oResult = null;
$mResult = null;
$this->Plugins()
->RunHook('main.fabrica', array($sName, &$oResult), false)
->RunHook('main.fabrica[2]', array($sName, &$oResult, $oAccount), false)
->RunHook('main.fabrica', array($sName, &$mResult), false)
->RunHook('main.fabrica[2]', array($sName, &$mResult, $oAccount), false)
;
if (null === $oResult)
if (null === $mResult)
{
switch ($sName)
{
case 'files':
// RainLoop\Providers\Files\IFiles
$oResult = new \RainLoop\Providers\Files\FileStorage(APP_PRIVATE_DATA.'storage/files');
$mResult = new \RainLoop\Providers\Files\FileStorage(APP_PRIVATE_DATA.'storage/files');
break;
case 'storage':
case 'storage-local':
// RainLoop\Providers\Storage\IStorage
$oResult = new \RainLoop\Providers\Storage\FileStorage(
$mResult = new \RainLoop\Providers\Storage\FileStorage(
APP_PRIVATE_DATA.'storage', 'storage-local' === $sName);
break;
case 'settings':
case 'settings-local':
// RainLoop\Providers\Settings\ISettings
$oResult = new \RainLoop\Providers\Settings\DefaultSettings(
$mResult = new \RainLoop\Providers\Settings\DefaultSettings(
$this->StorageProvider('settings-local' === $sName));
break;
case 'login':
// \RainLoop\Providers\Login\LoginInterface
$oResult = new \RainLoop\Providers\Login\DefaultLogin();
$mResult = new \RainLoop\Providers\Login\DefaultLogin();
break;
case 'domain':
// \RainLoop\Providers\Domain\DomainAdminInterface
$oResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains', $this->Cacher());
$mResult = new \RainLoop\Providers\Domain\DefaultDomain(APP_PRIVATE_DATA.'domains', $this->Cacher());
break;
case 'filters':
// \RainLoop\Providers\Filters\FiltersInterface
$oResult = new \RainLoop\Providers\Filters\SieveStorage(
$mResult = new \RainLoop\Providers\Filters\SieveStorage(
$this->Plugins(), $this->Config()
);
break;
case 'address-book':
// \RainLoop\Providers\AddressBook\AddressBookInterface
if (!\RainLoop\Utils::IsOwnCloud()) // disabled for ownCloud
{
$sDsn = \trim($this->Config()->Get('contacts', 'pdo_dsn', ''));
$sUser = \trim($this->Config()->Get('contacts', 'pdo_user', ''));
$sPassword = (string) $this->Config()->Get('contacts', 'pdo_password', '');
$sDsn = \trim($this->Config()->Get('contacts', 'pdo_dsn', ''));
$sUser = \trim($this->Config()->Get('contacts', 'pdo_user', ''));
$sPassword = (string) $this->Config()->Get('contacts', 'pdo_password', '');
$sDsnType = $this->ValidateContactPdoType(\trim($this->Config()->Get('contacts', 'type', 'sqlite')));
if ('sqlite' === $sDsnType)
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook(
'sqlite:'.APP_PRIVATE_DATA.'AddressBook.sqlite', '', '', 'sqlite');
}
else
{
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
}
$sDsnType = $this->ValidateContactPdoType(\trim($this->Config()->Get('contacts', 'type', 'sqlite')));
if ('sqlite' === $sDsnType)
{
$mResult = new \RainLoop\Providers\AddressBook\PdoAddressBook(
'sqlite:'.APP_PRIVATE_DATA.'AddressBook.sqlite', '', '', 'sqlite');
}
else
{
$mResult = new \RainLoop\Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
}
break;
case 'suggestions':
// \RainLoop\Providers\Suggestions\ISuggestions
// $oResult = new \RainLoop\Providers\Suggestions\TestSuggestions();
if (\RainLoop\Utils::IsOwnCloud())
if (null === $mResult)
{
$oResult = new \RainLoop\Providers\Suggestions\OwnCloudSuggestions();
$mResult = array();
}
// \RainLoop\Providers\Suggestions\ISuggestions
// $mResult[] = new \RainLoop\Providers\Suggestions\TestSuggestions();
if (\is_array($mResult) && \RainLoop\Utils::IsOwnCloud())
{
$mResult[] = new \RainLoop\Providers\Suggestions\OwnCloudSuggestions();
}
break;
@ -311,19 +314,22 @@ class Actions
break;
case 'two-factor-auth':
// \RainLoop\Providers\TwoFactorAuth\TwoFactorAuthInterface
$oResult = new \RainLoop\Providers\TwoFactorAuth\GoogleTwoFactorAuth();
$mResult = new \RainLoop\Providers\TwoFactorAuth\GoogleTwoFactorAuth();
break;
}
}
if ($oResult && \method_exists($oResult, 'SetLogger'))
foreach (\is_array($mResult) ? $mResult : array($mResult) as $oItem)
{
$oResult->SetLogger($this->Logger());
if ($oItem && \method_exists($oItem, 'SetLogger'))
{
$oItem->SetLogger($this->Logger());
}
}
$this->Plugins()->RunHook('filter.fabrica', array($sName, &$oResult, $oAccount), false);
$this->Plugins()->RunHook('filter.fabrica', array($sName, &$mResult, $oAccount), false);
return $oResult;
return $mResult;
}
/**
@ -827,7 +833,8 @@ class Actions
{
if (null === $this->oSuggestionsProvider)
{
$this->oSuggestionsProvider = new \RainLoop\Providers\Suggestions($this->fabrica('suggestions'));
$this->oSuggestionsProvider = new \RainLoop\Providers\Suggestions(
$this->fabrica('suggestions'));
}
return $this->oSuggestionsProvider;
@ -7071,8 +7078,7 @@ class Actions
$oSuggestionsProvider = $this->SuggestionsProvider();
if ($oSuggestionsProvider && $oSuggestionsProvider->IsActive())
{
$iSuggestionLimit = $iLimit - \count($aResult);
$aSuggestionsProviderResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iSuggestionLimit);
$aSuggestionsProviderResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iLimit);
if (\is_array($aSuggestionsProviderResult) && 0 < \count($aSuggestionsProviderResult))
{
$aResult = \array_merge($aResult, $aSuggestionsProviderResult);

View file

@ -5,31 +5,72 @@ namespace RainLoop\Providers;
class Suggestions extends \RainLoop\Providers\AbstractProvider
{
/**
* @var \RainLoop\Providers\Suggestions\ISuggestions
* @var \RainLoop\Providers\Suggestions\ISuggestions[]
*/
private $oDriver;
private $aDrivers;
/**
* @param \RainLoop\Providers\Suggestions\ISuggestions|null $oDriver = null
* @param \RainLoop\Providers\Suggestions\ISuggestions[]|null $aDriver = null
*
* @return void
*/
public function __construct($oDriver = null)
public function __construct($aDriver = null)
{
$this->oDriver = $oDriver;
if (\is_array($aDriver))
{
$aDriver = \array_filter($aDriver, function ($oDriver) {
return $oDriver instanceof \RainLoop\Providers\Suggestions\ISuggestions;
});
}
$this->aDrivers = \is_array($aDriver) && 0 < \count($aDriver) ? $aDriver : null;
}
/**
* @param \RainLoop\Account $oAccount
* @param \RainLoop\Model\Account $oAccount
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
*/
public function Process(\RainLoop\Account $oAccount, $sQuery, $iLimit = 20)
public function Process($oAccount, $sQuery, $iLimit = 20)
{
return $this->oDriver && $this->IsActive() && 0 < \strlen($sQuery) ?
$this->oDriver->Process($oAccount, $sQuery, $iLimit = 20) : array();
$aResult = array();
$aSuggestions = array();
if ($oAccount instanceof \RainLoop\Model\Account &&
$this->IsActive() && \is_array($this->aDrivers) && 0 < \strlen($sQuery))
{
foreach ($this->aDrivers as $oDriver)
{
$aSubs = null;
if ($oDriver)
{
$aSubs = $oDriver->Process($oAccount, $sQuery, $iLimit);
if (\is_array($aSubs) && 0 < \count($aSubs))
{
$aSuggestions = \array_merge($aSuggestions, $aSubs);
}
}
}
}
$aCache = array();
foreach ($aSuggestions as $aItem) // remove duplicates
{
$sLine = \implode('~~', $aItem);
if (!isset($aCache[$sLine]))
{
$aCache[$sLine] = true;
$aResult[] = $aItem;
}
}
if ($iLimit < \count($aResult))
{
$aResult = \array_slice($aResult, 0, $iLimit);
}
return $aResult;
}
/**
@ -37,6 +78,6 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
*/
public function IsActive()
{
return $this->oDriver instanceof \RainLoop\Providers\Suggestions\ISuggestions;
return \is_array($this->aDrivers) && 0 < \count($this->aDrivers);
}
}

View file

@ -9,7 +9,7 @@ interface ISuggestions
* @param string $sQuery
* @param int $iLimit = 20
*
* @return array
* @return array [['email@1', 'name_1'], ['email@2', 'name_2']]
*/
public function Process($oAccount, $sQuery, $iLimit = 20);
}

View file

@ -15,7 +15,7 @@ class TestSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
{
return array(
array($oAccount->Email(), ''),
array('xxx@xxx', 'xxx')
array('email@domain.com', 'name')
);
}
}