From ff7b71fd6c37e79135935cf8526c7f0589a695a8 Mon Sep 17 00:00:00 2001 From: RainLoop Team Date: Thu, 14 Aug 2014 22:34:38 +0400 Subject: [PATCH] Code refactoring --- dev/Boots/RainLoopApp.js | 21 +- .../v/0.0.0/app/libraries/RainLoop/Api.php | 10 +- .../0.0.0/app/libraries/RainLoop/Service.php | 70 +++---- rainloop/v/0.0.0/app/templates/Index.html | 4 +- rainloop/v/0.0.0/static/css/app.css | 18 +- rainloop/v/0.0.0/static/js/admin.js | 98 +++++----- rainloop/v/0.0.0/static/js/app.js | 185 +++++++++--------- rainloop/v/0.0.0/static/js/app.min.js | 2 +- rainloop/v/0.0.0/static/js/libs.js | 6 +- 9 files changed, 203 insertions(+), 211 deletions(-) diff --git a/dev/Boots/RainLoopApp.js b/dev/Boots/RainLoopApp.js index d5560d483..9334c8edd 100644 --- a/dev/Boots/RainLoopApp.js +++ b/dev/Boots/RainLoopApp.js @@ -1121,22 +1121,17 @@ RainLoopApp.prototype.bootstart = function () if (bValue) { - if (window.crypto && window.crypto.getRandomValues && RL.capa(Enums.Capa.OpenPGP)) + if (window.$LAB && window.crypto && window.crypto.getRandomValues && RL.capa(Enums.Capa.OpenPGP)) { - $.ajax({ - 'url': RL.link().openPgpJs(), - 'dataType': 'script', - 'cache': true, - 'success': function () { - if (window.openpgp) - { - RL.data().openpgpKeyring = new window.openpgp.Keyring(); - RL.data().capaOpenPGP(true); + window.$LAB.script(window.openpgp ? '' : RL.link().openPgpJs()).wait(function () { + if (window.openpgp) + { + RL.data().openpgpKeyring = new window.openpgp.Keyring(); + RL.data().capaOpenPGP(true); - RL.pub('openpgp.init'); + RL.pub('openpgp.init'); - RL.reloadOpenPgpKeys(); - } + RL.reloadOpenPgpKeys(); } }); } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Api.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Api.php index 430212a5b..ea4a1bca1 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Api.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Api.php @@ -137,8 +137,7 @@ class Api $sEmail = \MailSo\Base\Utils::IdnToAscii($sEmail); $oStorageProvider = \RainLoop\Api::Actions()->StorageProvider(); - - if ($oStorageProvider) + if ($oStorageProvider && $oStorageProvider->IsActive()) { // TwoFactor Auth User Data $oStorageProvider->Clear(null, @@ -157,12 +156,15 @@ class Api \RainLoop\Providers\Storage\Enumerations\StorageType::CONFIG, 'contacts_sync' ); - } \RainLoop\Api::Actions()->SettingsProvider()->ClearByEmail($sEmail); - \RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContactsAndTags($sEmail); + if (\RainLoop\Api::Actions()->AddressBookProvider() && + \RainLoop\Api::Actions()->AddressBookProvider()->IsActive()) + { + \RainLoop\Api::Actions()->AddressBookProvider()->DeleteAllContactsAndTags($sEmail); + } return true; } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php index 6dd256086..745826de4 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Service.php @@ -162,32 +162,18 @@ class Service @header('Content-Type: text/html; charset=utf-8'); $this->oHttp->ServerNoCache(); - $aData = $this->startUpData($bAdmin); + $aTemplateParameters = $this->indexTemplateParameters($bAdmin); $sCacheFileName = ''; if ($this->oActions->Config()->Get('labs', 'cache_system_data', true)) { - $sCacheFileName = 'TMPL:'.$aData['Hash']; + $sCacheFileName = 'TMPL:'.$aTemplateParameters['{{BaseHash}}']; $sResult = $this->oActions->Cacher()->Get($sCacheFileName); } if (0 === \strlen($sResult)) { - $sJsBoot = \file_get_contents(APP_VERSION_ROOT_PATH.'static/js/boot.js'); - $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), array( - '{{BaseRandHash}}' => \md5(\rand(1000, 9000).\microtime(true)), - '{{BaseAppDataScriptLink}}' => ($bAdmin ? './?/AdminAppData/' : './?/AppData/'), - '{{BaseAppFaviconIcoFile}}' => $aData['FaviconIcoLink'], - '{{BaseAppFaviconPngFile}}' => $aData['FaviconPngLink'], - '{{BaseAppAppleTouchFile}}' => $aData['AppleTouchLink'], - '{{BaseAppMainCssLink}}' => $aData['AppCssLink'], - '{{BaseAppBootScriptSource}}' => $sJsBoot, - '{{BaseAppLibsScriptLink}}' => $aData['LibJsLink'], - '{{BaseAppEditorScriptLink}}' => $aData['EditorJsLink'], - '{{BaseAppMainScriptLink}}' => $aData['AppJsLink'], - '{{BaseAppLoadingDescription}}' => \htmlspecialchars($aData['LoadingDescription'], ENT_QUOTES|ENT_IGNORE, 'UTF-8'), - '{{BaseDir}}' => \in_array($aData['Language'], array('ar', 'he', 'ur')) ? 'rtl' : 'ltr' - )); + $sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters); $sResult = \RainLoop\Utils::ClearHtmlOutput($sResult); if (0 < \strlen($sCacheFileName)) @@ -204,6 +190,7 @@ class Service $sResult .= ' [version:'.APP_VERSION; $sResult .= '][time:'.\substr(\microtime(true) - APP_START, 0, 6); $sResult .= '][cached:'.($bCached ? 'true' : 'false'); + $sResult .= '][hash:'.$aTemplateParameters['{{BaseHash}}']; $sResult .= '][session:'.\md5(\RainLoop\Utils::GetShortToken()); $sResult .= '] -->'; } @@ -216,27 +203,12 @@ class Service return $this; } - /** - * @param bool $bAppJsDebug - * @param bool $bAdmin - * - * @return string - */ - private function generateIndexCacheHash($bAppJsDebug, $bAdmin) - { - return \md5(APP_WEB_PATH. - $this->oActions->Config()->Get('webmail', 'loading_description', 'RainLoop'). - \md5($this->oActions->Config()->Get('cache', 'index', '')). - $this->oActions->Plugins()->Hash(). - APP_VERSION.($bAppJsDebug ? 'd' : 'm').($bAdmin ? 'a' : 'w')); - } - /** * @param bool $bAdmin * * @return array */ - private function startUpData($bAdmin) + private function indexTemplateParameters($bAdmin) { $sLanguage = 'en'; $sTheme = 'Default'; @@ -253,18 +225,46 @@ class Service $bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false); $sStaticPrefix = APP_WEB_STATIC_PATH; - return array( + + $aData = array( 'Language' => $sLanguage, 'Theme' => $sTheme, - 'Hash' => $this->generateIndexCacheHash($bAppJsDebug, $bAdmin), 'LoadingDescription' => $this->oActions->Config()->Get('webmail', 'loading_description', 'RainLoop'), 'FaviconIcoLink' => $sStaticPrefix.'favicon.ico', 'FaviconPngLink' => $sStaticPrefix.'favicon.png', 'AppleTouchLink' => $sStaticPrefix.'apple-touch-icon.png', 'AppCssLink' => $sStaticPrefix.'css/app'.($bAppCssDebug ? '' : '.min').'.css', + 'BootJsLink' => $sStaticPrefix.'js/boot.js', 'LibJsLink' => $sStaticPrefix.'js/libs.js', 'EditorJsLink' => $sStaticPrefix.'ckeditor/ckeditor.js', + 'OpenPgpJsLink' => $sStaticPrefix.'js/openpgp.min.js', 'AppJsLink' => $sStaticPrefix.'js/'.($bAdmin ? 'admin' : 'app').($bAppJsDebug ? '' : '.min').'.js' ); + + $aTemplateParameters = array( + '{{BaseAppDataScriptLink}}' => ($bAdmin ? './?/AdminAppData/' : './?/AppData/'), + '{{BaseAppFaviconIcoFile}}' => $aData['FaviconIcoLink'], + '{{BaseAppFaviconPngFile}}' => $aData['FaviconPngLink'], + '{{BaseAppAppleTouchFile}}' => $aData['AppleTouchLink'], + '{{BaseAppMainCssLink}}' => $aData['AppCssLink'], + '{{BaseAppBootScriptLink}}' => $aData['BootJsLink'], + '{{BaseAppLibsScriptLink}}' => $aData['LibJsLink'], + '{{BaseAppEditorScriptLink}}' => $aData['EditorJsLink'], + '{{BaseAppOpenPgpScriptLink}}' => $aData['OpenPgpJsLink'], + '{{BaseAppMainScriptLink}}' => $aData['AppJsLink'], + '{{BaseAppLoadingDescription}}' => \htmlspecialchars($aData['LoadingDescription'], ENT_QUOTES|ENT_IGNORE, 'UTF-8'), + '{{BaseDir}}' => \in_array($aData['Language'], array('ar', 'he', 'ur')) ? 'rtl' : 'ltr' + ); + + $aTemplateParameters['{{BaseHash}}'] = \md5( + \implode('~', array( + \md5($this->oActions->Config()->Get('cache', 'index', '')), + $this->oActions->Plugins()->Hash(), + APP_WEB_PATH, APP_VERSION + )). + \implode('~', $aTemplateParameters) + ); + + return $aTemplateParameters; } } diff --git a/rainloop/v/0.0.0/app/templates/Index.html b/rainloop/v/0.0.0/app/templates/Index.html index 904312a84..37c911c14 100644 --- a/rainloop/v/0.0.0/app/templates/Index.html +++ b/rainloop/v/0.0.0/app/templates/Index.html @@ -24,9 +24,9 @@ - +