From a3654a3bebe898cc741e5a0c26435e60d2bbf6f3 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 12 Dec 2013 19:06:32 +0400 Subject: [PATCH] New plugins hooks (contacts suggections). --- dev/Boots/RainLoopApp.js | 3 - .../0.0.0/app/libraries/RainLoop/Actions.php | 57 ++++++++++++++----- .../libraries/RainLoop/Config/Application.php | 2 +- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/dev/Boots/RainLoopApp.js b/dev/Boots/RainLoopApp.js index bd85e8df2..f7f20434e 100644 --- a/dev/Boots/RainLoopApp.js +++ b/dev/Boots/RainLoopApp.js @@ -12,9 +12,6 @@ function RainLoopApp() this.oRemote = null; this.oCache = null; - this.iSuggestionsLimit = Utils.pInt(this.settingsGet('SuggestionsLimit')); - this.iSuggestionsLimit = 0 === this.iSuggestionsLimit ? 20 : this.iSuggestionsLimit; - this.quotaDebounce = _.debounce(this.quota, 1000 * 30); $.wakeUp(function () { diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php index f2d5a4595..6ccbd11a5 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -894,7 +894,6 @@ class Actions 'LoginDefaultDomain' => $oConfig->Get('login', 'default_domain', ''), 'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true), 'AllowCustomTheme' => (bool) $oConfig->Get('webmail', 'allow_custom_theme', true), - 'SuggestionsLimit' => (int) $oConfig->Get('labs', 'suggestions_limit', 50), 'ChangePasswordIsAllowed' => false, 'ContactsIsAllowed' => false, 'JsHash' => \md5(\RainLoop\Utils::GetConnectionToken()), @@ -4087,8 +4086,6 @@ class Actions */ public function DoContactSave() { - $iStart = \time(); - $oAccount = $this->getAccountFromToken(); $bResult = false; @@ -4125,11 +4122,6 @@ class Actions $bResult = $oPab->ContactSave($oAccount, $oContact); } - if (\time() === $iStart) - { - sleep(1); - } - return $this->DefaultResponse(__FUNCTION__, array( 'RequestUid' => $sRequestUid, 'ResultID' => $bResult ? $oContact->IdContact : '', @@ -4145,12 +4137,49 @@ class Actions $oAccount = $this->getAccountFromToken(); $sQuery = \trim($this->GetActionParam('Query', '')); + $iLimit = (int) $this->Config()->Get('contacts', 'suggestions_limit', 20); $aResult = array(); - $oPab = $this->PersonalAddressBookProvider($oAccount); - if (0 < \strlen($sQuery) && $oPab->IsActive()) + + $this->Plugins()->RunHook('ajax.suggestions-input-parameters', array(&$sQuery, &$iLimit, $oAccount)); + + $iLimit = (int) $iLimit; + if (5 > $iLimit) { - $aResult = $oPab->GetSuggestions($oAccount, $sQuery); + $iLimit = 5; + } + + $this->Plugins()->RunHook('ajax.suggestions-pre', array(&$aResult, $sQuery, $oAccount, $iLimit)); + + if ($iLimit > \count($aResult) && 0 < \strlen($sQuery)) + { + // Personal Address Book + $oPab = $this->PersonalAddressBookProvider($oAccount); + if ($oPab && $oPab->IsActive()) + { + $aSuggestions = $oPab->GetSuggestions($oAccount, $sQuery, $iLimit); + if (0 === \count($aResult)) + { + $aResult = $aSuggestions; + } + else + { + $aResult = \array_merge($aResult, $aSuggestions); + } + } + } + + if ($iLimit < \count($aResult)) + { + $aResult = \array_slice($aResult, 0, $iLimit); + } + + // Plugins + $this->Plugins()->RunHook('ajax.suggestions-post', array(&$aResult, $sQuery, $oAccount, $iLimit)); + + if ($iLimit < \count($aResult)) + { + $aResult = \array_slice($aResult, 0, $iLimit); } return $this->DefaultResponse(__FUNCTION__, $aResult); @@ -4190,9 +4219,9 @@ class Actions $sFolder = $this->GetActionParam('Folder', ''); $bSetAction = '1' === (string) $this->GetActionParam('SetAction', '0'); - $aUids = explode(',', (string) $this->GetActionParam('Uids', '')); - $aFilteredUids = array_filter($aUids, function (&$sUid) { - $sUid = (int) trim($sUid); + $aUids = \explode(',', (string) $this->GetActionParam('Uids', '')); + $aFilteredUids = \array_filter($aUids, function (&$sUid) { + $sUid = (int) \trim($sUid); return 0 < $sUid; }); diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php index 220d01261..a03b86eda 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Config/Application.php @@ -83,6 +83,7 @@ class Application extends \RainLoop\Config\AbstractConfig 'contacts' => array( 'enable' => array(false, 'Enable contacts'), + 'suggestions_limit' => array(30), 'type' => array('mysql', ''), 'pdo_dsn' => array('mysql:host=127.0.0.1;port=3306;dbname=rainloop', ''), 'pdo_user' => array('root', ''), @@ -205,7 +206,6 @@ Enables caching in the system'), 'use_app_debug_css' => array(false), 'login_fault_delay' => array(1), 'log_ajax_response_write_limit' => array(300), - 'suggestions_limit' => array(50), 'determine_user_language' => array(true), 'use_imap_sort' => array(false), 'use_imap_force_selection' => array(false),