Suggestion Provider

OwnCloud Suggestion Driver
This commit is contained in:
RainLoop Team 2015-02-12 10:35:31 +04:00
parent d30292d500
commit 000711086a
15 changed files with 194 additions and 190 deletions

View file

@ -13,20 +13,7 @@ OCP\User::checkAdminUser();
OCP\Util::addScript('rainloop', 'admin');
$bInstalledLocaly = file_exists(__DIR__.'/app/index.php');
if ($bInstalledLocaly)
{
$oTemplate = new OCP\Template('rainloop', 'admin-local');
$oTemplate->assign('rainloop-admin-panel-link',
OC_RainLoop_Helper::getAppUrl().'?admin');
}
else
{
$oTemplate = new OCP\Template('rainloop', 'admin');
$oTemplate->assign('rainloop-admin-panel-link', '');
$oTemplate->assign('rainloop-url', OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$oTemplate->assign('rainloop-path', OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
}
$oTemplate = new OCP\Template('rainloop', 'admin-local');
$oTemplate->assign('rainloop-admin-panel-link', OC_RainLoop_Helper::getAppUrl().'?admin');
$oTemplate->assign('rainloop-autologin', OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false));
return $oTemplate->fetchPage();

View file

@ -17,32 +17,20 @@ $sUrl = '';
$sPath = '';
$bAutologin = false;
$bInstalledLocaly = file_exists(__DIR__.'/../app/index.php');
if (isset($_POST['appname']) && 'rainloop' === $_POST['appname'] &&
($bInstalledLocaly ? true : isset($_POST['rainloop-url'], $_POST['rainloop-path'])))
if (isset($_POST['appname']) && 'rainloop' === $_POST['appname'])
{
OCP\Config::setAppValue('rainloop', 'rainloop-autologin', isset($_POST['rainloop-autologin']) ?
'1' === $_POST['rainloop-autologin'] : false);
if (!$bInstalledLocaly)
{
OCP\Config::setAppValue('rainloop', 'rainloop-url', $_POST['rainloop-url']);
OCP\Config::setAppValue('rainloop', 'rainloop-path', $_POST['rainloop-path']);
$sUrl = OCP\Config::getAppValue('rainloop', 'rainloop-url', '');
$sPath = OCP\Config::getAppValue('rainloop', 'rainloop-path', '');
}
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
}
else
{
sleep(1);
OC_JSON::error(array('Message' => 'Invalid Argument(s)', 'Url' => $sUrl, 'Path' => $sPath));
OC_JSON::error(array('Message' => 'Invalid Argument(s)'));
return false;
}
sleep(1);
OCP\JSON::success(array('Message' => 'Saved successfully', 'Url' => $sUrl, 'Path' => $sPath));
OCP\JSON::success(array('Message' => 'Saved successfully'));
return true;

View file

@ -13,7 +13,7 @@ if (@file_exists(__DIR__.'/app/index.php'))
$sUser = OCP\User::getUser();
if ($bAutologin)
if (OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false))
{
$sEmail = $sUser;
$sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-autologin-password', '');

View file

@ -21,18 +21,13 @@ if (OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false))
OCP\Util::connectHook('OC_User', 'post_setPassword', 'OC_RainLoop_Helper', 'changePassword');
}
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
OCP\Util::addScript('rainloop', 'rainloop');
if (('' !== $sUrl && '' !== $sPath) || OC_User::isAdminUser(OC_User::getUser()))
{
OCP\Util::addScript('rainloop', 'rainloop');
OCP\App::addNavigationEntry(array(
'id' => 'rainloop_index',
'order' => 10,
'href' => OCP\Util::linkToRoute('rainloop_index'),
'icon' => OCP\Util::imagePath('rainloop', 'mail.png'),
'name' => 'Email'
));
OCP\App::addNavigationEntry(array(
'id' => 'rainloop_index',
'order' => 10,
'href' => OCP\Util::linkTo('rainloop', 'index.php'),
'icon' => OCP\Util::imagePath('rainloop', 'mail.png'),
'name' => 'Email'
));
}

View file

@ -15,57 +15,9 @@ OCP\App::setActiveNavigationEntry('rainloop_index');
include_once OC_App::getAppPath('rainloop').'/lib/RainLoopHelper.php';
$sUrl = '';
$sPath = '';
$sUrl = OC_RainLoop_Helper::normalizeUrl(OC_RainLoop_Helper::getAppUrl());
$bInstalledLocaly = file_exists(__DIR__.'/app/index.php');
if ($bInstalledLocaly)
{
$sUrl = OC_RainLoop_Helper::getAppUrl();
$sPath = __DIR__.'/app/';
}
else
{
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
}
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
if ('' === $sUrl || '' === $sPath)
{
$oTemplate = new OCP\Template('rainloop', 'index-empty', 'user');
}
else
{
$sUrl = OC_RainLoop_Helper::normalizeUrl($sUrl);
if ($bInstalledLocaly)
{
$sResultUrl = $sUrl.'?OwnCloudAuth';
}
else
{
$sUser = OCP\User::getUser();
if ($bAutologin)
{
$sEmail = $sUser;
$sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-autologin-password', '');
}
else
{
$sEmail = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-email', '');
$sEncodedPassword = OCP\Config::getUserValue($sUser, 'rainloop', 'rainloop-password', '');
}
$sDecodedPassword = OC_RainLoop_Helper::decodePassword($sEncodedPassword, md5($sEmail));
$sSsoHash = OC_RainLoop_Helper::getSsoHash($sPath, $sEmail, $sDecodedPassword);
$sResultUrl = empty($sSsoHash) ? $sUrl.'?sso' : $sUrl.'?sso&hash='.$sSsoHash;
}
$oTemplate = new OCP\Template('rainloop', 'index', 'user');
$oTemplate->assign('rainloop-url', $sResultUrl);
}
$oTemplate = new OCP\Template('rainloop', 'index', 'user');
$oTemplate->assign('rainloop-iframe-url', OC_RainLoop_Helper::normalizeUrl($sUrl).'?OwnCloudAuth');
$oTemplate->printpage();

View file

@ -7,13 +7,9 @@ class OC_RainLoop_Helper
*/
public static function getAppUrl()
{
if (class_exists('\\OC\\URLGenerator') && isset(\OC::$server))
if (class_exists('\\OCP\\Util'))
{
$oUrlGenerator = new \OC\URLGenerator(\OC::$server->getConfig());
if ($oUrlGenerator)
{
return $oUrlGenerator->linkToRoute('rainloop_app');
}
return OCP\Util::linkToRoute('rainloop_app');
}
$sRequestUri = empty($_SERVER['REQUEST_URI']) ? '': trim($_SERVER['REQUEST_URI']);
@ -105,14 +101,8 @@ class OC_RainLoop_Helper
$sEmail = $sUser;
$sPassword = $aParams['password'];
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
if ('' !== $sUrl && '' !== $sPath)
{
$sPassword = self::encodePassword($sPassword, md5($sEmail));
return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-autologin-password', $sPassword);
}
return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-autologin-password',
self::encodePassword($sPassword, md5($sEmail)));
}
return false;
@ -133,16 +123,15 @@ class OC_RainLoop_Helper
$sEmail = $sUser;
$sPassword = $aParams['password'];
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
OCP\Util::writeLog('rainloop', 'rainloop|login: Setting new RainLoop password for '.$sEmail, OCP\Util::DEBUG);
if ('' !== $sUrl && '' !== $sPath)
{
OCP\Util::writeLog('rainloop', 'rainloop|login: Setting new RainLoop password for '.$sEmail, OCP\Util::DEBUG);
OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-autologin-password',
self::encodePassword($sPassword, md5($sEmail)));
$sPassword = self::encodePassword($sPassword, md5($sEmail));
return OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password', $sPassword);
}
OCP\Config::setUserValue($sUser, 'rainloop', 'rainloop-password',
self::encodePassword($sPassword, md5($sEmail)));
return true;
}
return false;

View file

@ -14,19 +14,7 @@ OCP\App::checkAppEnabled('rainloop');
OCP\Util::addScript('rainloop', 'personal');
$sUrl = '';
$sPath = '';
$bAutologin = OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false);
$bInstalledLocaly = file_exists(__DIR__.'/app/index.php');
if (!$bInstalledLocaly)
{
$sUrl = trim(OCP\Config::getAppValue('rainloop', 'rainloop-url', ''));
$sPath = trim(OCP\Config::getAppValue('rainloop', 'rainloop-path', ''));
}
if ($bAutologin || (!$bInstalledLocaly && ('' === $sUrl || '' === $sPath)))
if (OCP\Config::getAppValue('rainloop', 'rainloop-autologin', false))
{
$oTemplate = new OCP\Template('rainloop', 'empty');
}

View file

@ -1,31 +0,0 @@
<div class="section">
<form id="mail-rainloop-admin-form" action="#" method="post">
<input type="hidden" name="requesttoken" value="<?php echo $_['requesttoken'] ?>" id="requesttoken">
<input type="hidden" name="appname" value="rainloop">
<fieldset class="personalblock">
<h2><?php p($l->t('RainLoop Webmail')); ?></h2>
<br />
<p>
<?php p($l->t('RainLoop Webmail URL')); ?>:
<br />
<input type="text" style="width:300px;" id="rainloop-url" name="rainloop-url" value="<?php echo $_['rainloop-url']; ?>" placeholder="https://" />
<br />
<br />
<?php p($l->t('Absolute (full) path to RainLoop Webmail installation')); ?>:
<br />
<input type="text" style="width:300px;" id="rainloop-path" name="rainloop-path" value="<?php echo $_['rainloop-path']; ?>" />
<br />
<br />
<input type="checkbox" id="rainloop-autologin" id="rainloop-autologin" name="rainloop-autologin" value="1" <?php if ($_['rainloop-autologin']): ?>checked="checked"<?php endif; ?> />
<label for="rainloop-autologin">
<?php p($l->t('Automatically login with ownCloud user credentials')); ?>
</label>
<br />
<br />
<input type="button" id="rainloop-save-button" name="rainloop-save-button" value="<?php p($l->t('Save')); ?>" />
&nbsp;&nbsp;<span class="rainloop-result-desc"></span>
</p>
</fieldset>
</form>
</div>

View file

@ -1,3 +1,3 @@
<div style="box-sizing: border-box; width: 100%; height: 100%; padding: 0px; margin: 0px; background-color: #383c43; position: relative; overflow: hidden;"
><iframe id="rliframe" style="border: none; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;" tabindex="-1" frameborder="0"
src="<?php echo $_['rainloop-url']; ?>"></iframe></div><?php OCP\Util::addScript('rainloop', 'resize');
<div style="box-sizing: border-box; width: 100%; height: 100%; padding: 0px; margin: 0px; background-color: #383c43; position: relative; overflow: hidden;"
><iframe id="rliframe" style="border: none; width: 100%; height: 100%; position: absolute; top: 0px; left: 0px; right: 0px; bottom: 0px;" tabindex="-1" frameborder="0"
src="<?php echo $_['rainloop-iframe-url']; ?>"></iframe></div><?php OCP\Util::addScript('rainloop', 'resize');

View file

@ -557,7 +557,7 @@ gulp.task('rainloop:start', ['js:lint', 'rainloop:copy', 'rainloop:setup']);
gulp.task('rainloop', ['rainloop:start', 'rainloop:zip', 'rainloop:md5', 'rainloop:clean']);
gulp.task('owncloud', ['rainloop:owncloud:copy',
'rainloop:owncloud:copy-rainloop',
'rainloop:owncloud:copy-rainloop', 'rainloop:owncloud:copy-rainloop:clean',
'rainloop:owncloud:setup', 'rainloop:owncloud:zip', 'rainloop:owncloud:md5', 'rainloop:owncloud:clean']);
//WATCH
@ -567,12 +567,13 @@ gulp.task('watch', ['fast'], function() {
});
// ALIASES
gulp.task('w', ['watch']);
gulp.task('f', ['fast']);
gulp.task('rl', ['rainloop']);
gulp.task('build', ['rainloop']);
gulp.task('b', ['build']);
gulp.task('js:hint', ['js:lint']);
gulp.task('own', ['owncloud']);
gulp.task('js:hint', ['js:lint']);
gulp.task('rl', ['rainloop']);
gulp.task('w', ['watch']);
gulp.task('f', ['fast']);
gulp.task('o', ['owncloud']);
gulp.task('b', ['build']);
gulp.task('h', ['js:lint']);

View file

@ -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);

View file

@ -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();
}
/**

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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')
);
}
}