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

@ -35,6 +35,7 @@
this.coreVersionCompare = CoreStore.coreVersionCompare; this.coreVersionCompare = CoreStore.coreVersionCompare;
this.coreRemoteVersionHtmlDesc = ko.computed(function () { this.coreRemoteVersionHtmlDesc = ko.computed(function () {
Translator.trigger();
return Translator.i18n('TAB_ABOUT/HTML_NEW_VERSION', {'VERSION': this.coreRemoteVersion()}); return Translator.i18n('TAB_ABOUT/HTML_NEW_VERSION', {'VERSION': this.coreRemoteVersion()});
}, this); }, this);

View file

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

View file

@ -5,31 +5,72 @@ namespace RainLoop\Providers;
class Suggestions extends \RainLoop\Providers\AbstractProvider 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 * @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 string $sQuery
* @param int $iLimit = 20 * @param int $iLimit = 20
* *
* @return array * @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) ? $aResult = array();
$this->oDriver->Process($oAccount, $sQuery, $iLimit = 20) : 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() 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 string $sQuery
* @param int $iLimit = 20 * @param int $iLimit = 20
* *
* @return array * @return array [['email@1', 'name_1'], ['email@2', 'name_2']]
*/ */
public function Process($oAccount, $sQuery, $iLimit = 20); public function Process($oAccount, $sQuery, $iLimit = 20);
} }

View file

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