mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
Suggestion Provider
OwnCloud Suggestion Driver
This commit is contained in:
parent
d30292d500
commit
000711086a
15 changed files with 194 additions and 190 deletions
|
|
@ -278,31 +278,37 @@ class Actions
|
|||
$oResult = new \RainLoop\Providers\Filters\SieveStorage(
|
||||
$this->Plugins(), $this->Config()
|
||||
);
|
||||
|
||||
$oResult->SetLogger($this->Logger());
|
||||
break;
|
||||
case 'address-book':
|
||||
// \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||
|
||||
$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)
|
||||
if (!\RainLoop\Utils::IsOwnCloud()) // disabled for ownCloud
|
||||
{
|
||||
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook(
|
||||
'sqlite:'.APP_PRIVATE_DATA.'AddressBook.sqlite', '', '', 'sqlite');
|
||||
}
|
||||
else
|
||||
{
|
||||
$oResult = new \RainLoop\Providers\AddressBook\PdoAddressBook($sDsn, $sUser, $sPassword, $sDsnType);
|
||||
}
|
||||
$sDsn = \trim($this->Config()->Get('contacts', 'pdo_dsn', ''));
|
||||
$sUser = \trim($this->Config()->Get('contacts', 'pdo_user', ''));
|
||||
$sPassword = (string) $this->Config()->Get('contacts', 'pdo_password', '');
|
||||
|
||||
$oResult->SetLogger($this->Logger());
|
||||
$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);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'suggestions':
|
||||
// \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||
// $oResult = new \RainLoop\Providers\Suggestions\TestSuggestions();
|
||||
|
||||
if (\RainLoop\Utils::IsOwnCloud())
|
||||
{
|
||||
$oResult = new \RainLoop\Providers\Suggestions\OwnCloudSuggestions();
|
||||
}
|
||||
|
||||
break;
|
||||
case 'change-password':
|
||||
// \RainLoop\Providers\ChangePassword\ChangePasswordInterface
|
||||
|
|
@ -314,6 +320,11 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
if ($oResult && \method_exists($oResult, 'SetLogger'))
|
||||
{
|
||||
$oResult->SetLogger($this->Logger());
|
||||
}
|
||||
|
||||
$this->Plugins()->RunHook('filter.fabrica', array($sName, &$oResult, $oAccount), false);
|
||||
|
||||
return $oResult;
|
||||
|
|
@ -2085,6 +2096,7 @@ class Actions
|
|||
'accounts'
|
||||
);
|
||||
|
||||
$aAccounts = array();
|
||||
if ('' !== $sAccounts && '{' === \substr($sAccounts, 0, 1))
|
||||
{
|
||||
$aAccounts = @\json_decode($sAccounts, true);
|
||||
|
|
@ -6589,6 +6601,20 @@ class Actions
|
|||
}
|
||||
}
|
||||
|
||||
if ($iLimit > \count($aResult) && 0 < \strlen($sQuery))
|
||||
{
|
||||
$oSuggestionsProvider = $this->SuggestionsProvider();
|
||||
if ($oSuggestionsProvider && $oSuggestionsProvider->IsActive())
|
||||
{
|
||||
$iSuggestionLimit = $iLimit - \count($aResult);
|
||||
$aSuggestionsProviderResult = $oSuggestionsProvider->Process($oAccount, $sQuery, $iSuggestionLimit);
|
||||
if (\is_array($aSuggestionsProviderResult) && 0 < \count($aSuggestionsProviderResult))
|
||||
{
|
||||
$aResult = \array_merge($aResult, $aSuggestionsProviderResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($iLimit < \count($aResult))
|
||||
{
|
||||
$aResult = \array_slice($aResult, 0, $iLimit);
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@ class Suggestions extends \RainLoop\Providers\AbstractProvider
|
|||
/**
|
||||
* @param \RainLoop\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process(\RainLoop\Account $oAccount, $sQuery)
|
||||
public function Process(\RainLoop\Account $oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
return $this->oDriver && $this->IsActive() && 0 < \strlen($sQuery) ? $this->oDriver->Process($oAccount, $sQuery) : array();
|
||||
return $this->oDriver && $this->IsActive() && 0 < \strlen($sQuery) ?
|
||||
$this->oDriver->Process($oAccount, $sQuery, $iLimit = 20) : array();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Suggestions;
|
||||
|
||||
class OwnCloudSuggestions implements \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||
{
|
||||
/**
|
||||
* @var \MailSo\Log\Logger
|
||||
*/
|
||||
private $oLogger;
|
||||
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
$aResult = array();
|
||||
|
||||
try
|
||||
{
|
||||
if (!$oAccount || !\RainLoop\Utils::IsOwnCloud() ||
|
||||
!\class_exists('\\OCP\\Contacts') || !\OCP\Contacts::isEnabled())
|
||||
{
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
$aSearchResult = \OCP\Contacts::search($sQuery, array('FN', 'EMAIL'));
|
||||
|
||||
foreach ($aSearchResult as $aContact)
|
||||
{
|
||||
if (0 >= $iLimit)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$sUid = empty($aContact['UID']) ? '' : $aContact['UID'];
|
||||
if (!empty($sUid))
|
||||
{
|
||||
$sFullName = isset($aContact['FN']) ? \trim($aContact['FN']) : '';
|
||||
$mEmails = isset($aContact['EMAIL']) ? $aContact['EMAIL'] : '';
|
||||
|
||||
if (!\is_array($mEmails))
|
||||
{
|
||||
$mEmails = array($mEmails);
|
||||
}
|
||||
|
||||
foreach ($mEmails as $sEmail)
|
||||
{
|
||||
$sEmail = \trim($sEmail);
|
||||
if (!empty($sEmail))
|
||||
{
|
||||
$iLimit--;
|
||||
$aResult[$sUid] = array($sEmail, $sFullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($aSearchResult);
|
||||
|
||||
$aResult = \array_values($aResult);
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
{
|
||||
if ($this->oLogger)
|
||||
{
|
||||
$this->oLogger->WriteException($oException);
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \MailSo\Log\Logger $oLogger
|
||||
*/
|
||||
public function SetLogger($oLogger)
|
||||
{
|
||||
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,9 @@ interface SuggestionsInterface
|
|||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process(\RainLoop\Model\Account $oAccount, $sQuery);
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\Suggestions;
|
||||
|
||||
class TestSuggestions implements \RainLoop\Providers\Suggestions\SuggestionsInterface
|
||||
{
|
||||
/**
|
||||
* @param \RainLoop\Model\Account $oAccount
|
||||
* @param string $sQuery
|
||||
* @param int $iLimit = 20
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function Process($oAccount, $sQuery, $iLimit = 20)
|
||||
{
|
||||
return array(
|
||||
array($oAccount->Email(), ''),
|
||||
array('xxx@xxx', 'xxx')
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue