Remove user customized theme (simplification)

Added theme folders (regardless of the RainLoop version)
This commit is contained in:
RainLoop Team 2014-05-06 01:38:49 +04:00
parent f3823333d7
commit d08689759d
26 changed files with 125 additions and 618 deletions

View file

@ -990,14 +990,12 @@ class Actions
'LoginDefaultDomain' => $oConfig->Get('login', 'default_domain', ''),
'DetermineUserLanguage' => (bool) $oConfig->Get('login', 'determine_user_language', true),
'AllowThemes' => (bool) $oConfig->Get('webmail', 'allow_themes', true),
'AllowCustomTheme' => (bool) $oConfig->Get('webmail', 'allow_custom_theme', true),
'ChangePasswordIsAllowed' => false,
'ContactsIsAllowed' => false,
'JsHash' => \md5(\RainLoop\Utils::GetConnectionToken()),
'UseImapThread' => (bool) $oConfig->Get('labs', 'use_imap_thread', false),
'UseImapSubscribe' => (bool) $oConfig->Get('labs', 'use_imap_list_subscribe', true),
'AllowAppendMessage' => (bool) $oConfig->Get('labs', 'allow_message_append', false),
'CdnStaticDomain' => $oConfig->Get('labs', 'cdn_static_domain', ''),
'Plugins' => array()
);
@ -1148,7 +1146,7 @@ class Actions
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
$sTheme = $oConfig->Get('webmail', 'theme', 'Default');
$aResult['Themes'] = $this->GetThemes($bAdmin);
$aResult['Themes'] = $this->GetThemes();
$aResult['Languages'] = $this->GetLanguages();
$aResult['AllowLanguagesOnSettings'] = (bool) $oConfig->Get('webmail', 'allow_languages_on_settings', true);
$aResult['AllowLanguagesOnLogin'] = (bool) $oConfig->Get('login', 'allow_languages_on_login', true);
@ -1173,8 +1171,6 @@ class Actions
$aResult['EnableTwoFactor'] = false;
$aResult['ParentEmail'] = '';
$aResult['InterfaceAnimation'] = \RainLoop\Enumerations\InterfaceAnimation::NORMAL;
$aResult['CustomThemeType'] = \RainLoop\Enumerations\CustomThemeType::LIGHT;
$aResult['CustomThemeImg'] = '';
if (!$bAdmin && $oSettings instanceof \RainLoop\Settings)
{
@ -1204,8 +1200,6 @@ class Actions
$aResult['Layout'] = (int) $oSettings->GetConf('Layout', $aResult['Layout']);
$aResult['UseCheckboxesInList'] = (bool) $oSettings->GetConf('UseCheckboxesInList', $aResult['UseCheckboxesInList']);
$aResult['InterfaceAnimation'] = (string) $oSettings->GetConf('InterfaceAnimation', $aResult['InterfaceAnimation']);
$aResult['CustomThemeType'] = (string) $oSettings->GetConf('CustomThemeType', $aResult['CustomThemeType']);
$aResult['CustomThemeImg'] = (string) $oSettings->GetConf('CustomThemeImg', $aResult['CustomThemeImg']);
$aResult['DisplayName'] = $oSettings->GetConf('DisplayName', $aResult['DisplayName']);
$aResult['ReplyTo'] = $oSettings->GetConf('ReplyTo', $aResult['ReplyTo']);
@ -1219,13 +1213,6 @@ class Actions
$aResult['InterfaceAnimation'] = \RainLoop\Enumerations\InterfaceAnimation::NONE === $aResult['InterfaceAnimation']
? $aResult['InterfaceAnimation'] : \RainLoop\Enumerations\InterfaceAnimation::NORMAL;
if (!in_array($aResult['CustomThemeType'], array(
\RainLoop\Enumerations\CustomThemeType::LIGHT, \RainLoop\Enumerations\CustomThemeType::DARK
)))
{
$aResult['CustomThemeType'] = \RainLoop\Enumerations\CustomThemeType::LIGHT;
}
if (0 < \strlen($aResult['ParentEmail']))
{
$aResult['AllowGoogleSocial'] = false;
@ -1237,10 +1224,6 @@ class Actions
$sTheme = $this->ValidateTheme($sTheme);
$sNewThemeLink = APP_INDEX_FILE.'?/Css/0/'.($bAdmin ? 'Admin' : 'User').'/-/'.($bAdmin ? 'Default' : $sTheme).'/-/'.$sStaticCache.'/';
if (!$bAdmin && 0 < \strlen($sAuthAccountHash) && 'Custom' === $sTheme)
{
$sNewThemeLink = \str_replace('/Css/0/User/-/Custom/-/', '/Css/'.$sAuthAccountHash.'/User/-/Custom/-/', $sNewThemeLink);
}
$bUserLanguage = false;
if (!$bAdmin && !$aResult['Auth'] && !empty($_COOKIE['rllang']) &&
@ -2079,7 +2062,6 @@ class Actions
});
$this->setConfigFromParams($oConfig, 'AllowThemes', 'webmail', 'allow_themes', 'bool');
$this->setConfigFromParams($oConfig, 'AllowCustomTheme', 'webmail', 'allow_custom_theme', 'bool');
$this->setConfigFromParams($oConfig, 'AllowLanguagesOnSettings', 'webmail', 'allow_languages_on_settings', 'bool');
$this->setConfigFromParams($oConfig, 'AllowLanguagesOnLogin', 'login', 'allow_languages_on_login', 'bool');
$this->setConfigFromParams($oConfig, 'AllowCustomLogin', 'login', 'allow_custom_login', 'bool');
@ -3245,12 +3227,6 @@ class Actions
$oSettings->SetConf('Theme', $this->ValidateLanguage($oConfig->Get('webmail', 'theme', 'Default')));
}
$this->setSettingsFromParams($oSettings, 'CustomThemeType', 'string', function ($sCustomThemeType) {
return \in_array($sCustomThemeType, array(
\RainLoop\Enumerations\CustomThemeType::LIGHT, \RainLoop\Enumerations\CustomThemeType::DARK)) ?
$sCustomThemeType : \RainLoop\Enumerations\CustomThemeType::LIGHT;
});
$this->setSettingsFromParams($oSettings, 'MPP', 'int', function ($iValue) {
return (int) (\in_array($iValue, array(10, 20, 30, 50, 100, 150, 200, 300)) ? $iValue : 20);
});
@ -5871,91 +5847,6 @@ class Actions
return $this->DefaultResponse(__FUNCTION__, $mResponse);
}
/**
* @return array
*/
public function UploadBackground()
{
$oAccount = $this->getAccountFromToken();
$sInputName = 'uploader';
$mResponse = false;
$iError = UploadError::UNKNOWN;
$iSizeLimit = 1024 * 1024;
if ($oAccount)
{
$iError = UPLOAD_ERR_OK;
$_FILES = isset($_FILES) ? $_FILES : null;
if (isset($_FILES, $_FILES[$sInputName], $_FILES[$sInputName]['name'], $_FILES[$sInputName]['tmp_name'], $_FILES[$sInputName]['size']))
{
$iError = (isset($_FILES[$sInputName]['error'])) ? (int) $_FILES[$sInputName]['error'] : UPLOAD_ERR_OK;
if (UPLOAD_ERR_OK === $iError && 0 < $iSizeLimit && $iSizeLimit < (int) $_FILES[$sInputName]['size'])
{
$iError = UploadError::CONFIG_SIZE;
}
if (UPLOAD_ERR_OK === $iError && !\in_array(\strtolower($_FILES[$sInputName]['type']), array('image/png', 'image/jpg', 'image/jpeg')))
{
$iError = UploadError::FILE_TYPE;
}
$sSavedName = 'upload-post-'.md5($_FILES[$sInputName]['name'].$_FILES[$sInputName]['tmp_name']);
if (UPLOAD_ERR_OK === $iError)
{
if (!$this->FilesProvider()->MoveUploadedFile($oAccount, $sSavedName, $_FILES[$sInputName]['tmp_name']))
{
$iError = UploadError::ON_SAVING;
}
$mData = $this->FilesProvider()->GetFile($oAccount, $sSavedName);
if ($mData)
{
$this->StorageProvider()->Put($oAccount,
\RainLoop\Providers\Storage\Enumerations\StorageType::USER, 'CustomThemeBackground',
'data:'.$_FILES[$sInputName]['type'].';base64,'.base64_encode(
\stream_get_contents($mData)
)
);
}
if (\is_resource($mData))
{
\fclose($mData);
}
unset($mData);
$this->FilesProvider()->Clear($oAccount, $sSavedName);
$mResponse = $_FILES[$sInputName]['name'];
}
}
else if (!isset($_FILES) || !is_array($_FILES) || 0 === count($_FILES))
{
$iError = UPLOAD_ERR_INI_SIZE;
}
else
{
$iError = UploadError::EMPTY_FILES_DATA;
}
}
if (UPLOAD_ERR_OK !== $iError)
{
$iClientError = UploadClientError::NORMAL;
$sError = $this->getUploadErrorMessageByCode($iError, $iClientError);
if (!empty($sError))
{
return $this->FalseResponse(__FUNCTION__, $iClientError, $sError);
}
}
return $this->DefaultResponse(__FUNCTION__, $mResponse);
}
/**
* @return bool
*
@ -6324,14 +6215,13 @@ class Actions
/**
* @staticvar array $aCache
* @param bool $bAdmin = false
*
* @return array
*/
public function GetThemes($bAdmin = false)
public function GetThemes()
{
static $aCache = null;
if (is_array($aCache))
if (\is_array($aCache))
{
return $aCache;
}
@ -6340,16 +6230,16 @@ class Actions
$bDefault = false;
$sList = array();
$sDir = APP_VERSION_ROOT_PATH.'themes';
if (@is_dir($sDir))
if (@\is_dir($sDir))
{
$rDirH = opendir($sDir);
$rDirH = \opendir($sDir);
if ($rDirH)
{
while (($sFile = readdir($rDirH)) !== false)
while (($sFile = \readdir($rDirH)) !== false)
{
if ('.' !== $sFile{0} && is_dir($sDir.'/'.$sFile) && file_exists($sDir.'/'.$sFile.'/styles.less'))
if ('.' !== $sFile{0} && \is_dir($sDir.'/'.$sFile) && \file_exists($sDir.'/'.$sFile.'/styles.less'))
{
if ('Default' !== $sFile && 'Clear' !== $sFile && 'Custom' !== $sFile)
if ('Default' !== $sFile && 'Clear' !== $sFile)
{
$sList[] = $sFile;
}
@ -6370,20 +6260,35 @@ class Actions
}
}
sort($sList);
if ($bDefault)
$sDir = APP_INDEX_ROOT_PATH.'themes'; // custom user themes
if (@\is_dir($sDir))
{
array_unshift($sList, 'Default');
}
if ($bClear)
{
array_push($sList, 'Clear');
$rDirH = \opendir($sDir);
if ($rDirH)
{
while (($sFile = \readdir($rDirH)) !== false)
{
if ('.' !== $sFile{0} && \is_dir($sDir.'/'.$sFile) && \file_exists($sDir.'/'.$sFile.'/styles.less'))
{
$sList[] = $sFile.'@custom';
}
}
@\closedir($rDirH);
}
}
if (!$bAdmin && $this->Config()->Get('webmail', 'allow_custom_theme', true))
$sList = \array_unique($sList);
\sort($sList);
if ($bDefault)
{
array_push($sList, 'Custom');
\array_unshift($sList, 'Default');
}
if ($bClear)
{
\array_push($sList, 'Clear');
}
$aCache = $sList;

View file

@ -62,7 +62,6 @@ class Application extends \RainLoop\Config\AbstractConfig
'theme' => array('Default', 'Theme used by default'),
'allow_themes' => array(true, 'Allow theme selection on settings screen'),
'allow_custom_theme' => array(true, ''),
'language' => array('en', 'Language used by default'),
'allow_languages_on_settings' => array(true, 'Allow language selection on settings screen'),
@ -238,7 +237,6 @@ Enables caching in the system'),
'repo_type' => array('stable'),
'custom_repo' => array(''),
'additional_repo' => array(''),
'cdn_static_domain' => array(''),
'curl_proxy' => array(''),
'curl_proxy_auth' => array(''),
'in_iframe' => array(false),

View file

@ -1,9 +0,0 @@
<?php
namespace RainLoop\Enumerations;
class CustomThemeType
{
const LIGHT = 'Light';
const DARK = 'Dark';
}

View file

@ -222,7 +222,6 @@ class Service
{
return \md5(APP_WEB_PATH.
$this->oActions->Config()->Get('webmail', 'loading_description', 'RainLoop').
$this->oActions->Config()->Get('labs', 'cdn_static_domain', '').
\md5($this->oActions->Config()->Get('cache', 'index', '')).
$this->oActions->Plugins()->Hash().
APP_VERSION.($bAppJsDebug ? 'd' : 'm').($bAdmin ? 'a' : 'w'));
@ -248,14 +247,8 @@ class Service
$bAppJsDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_js', false);
$bAppCssDebug = !!$this->oActions->Config()->Get('labs', 'use_app_debug_css', false);
$sCdnStaticDomain = $this->oActions->Config()->Get('labs', 'cdn_static_domain', '');
$sStaticPrefix = APP_WEB_STATIC_PATH;
if (0 < \strlen($sCdnStaticDomain))
{
$sStaticPrefix = \trim($sCdnStaticDomain, ' /\\').'/'.APP_VERSION.'/static/';
}
return array(
'Language' => $sLanguage,
'Theme' => $sTheme,

View file

@ -519,9 +519,6 @@ class ServiceActions
public function ServiceCss()
{
$sResult = '';
$bCustom = false;
$oAccount = null;
$oSettings = null;
$bAdmin = !empty($this->aPaths[2]) && 'Admin' === $this->aPaths[2];
$bJson = !empty($this->aPaths[7]) && 'Json' === $this->aPaths[7];
@ -539,24 +536,22 @@ class ServiceActions
if (!empty($this->aPaths[4]))
{
$sTheme = $this->oActions->ValidateTheme($this->aPaths[4]);
if ('Custom' === $sTheme && !empty($this->aPaths[1]) && '0' !== $this->aPaths[1])
$sRealTheme = $sTheme;
$bCustomTheme = '@custom' === \substr($sTheme, -7);
if ($bCustomTheme)
{
$bCustom = true;
$oAccount = $this->oActions->GetAccount(false);
if ($oAccount)
{
$oSettings = $this->oActions->SettingsProvider()->Load($oAccount);
}
$sRealTheme = \substr($sTheme, 0, -7);
}
$bCacheEnabled = $this->Config()->Get('labs', 'cache_system_data', true);
if ($bCacheEnabled && !$bCustom)
if ($bCacheEnabled)
{
$this->oActions->verifyCacheByKey($this->sQuery);
}
$sCacheFileName = '';
if ($bCacheEnabled && !$bCustom)
if ($bCacheEnabled)
{
$sCacheFileName = 'THEMES/PLUGINS:'.$sTheme.':'.$this->Plugins()->Hash();
$sResult = $this->Cacher()->Get($sCacheFileName);
@ -574,39 +569,22 @@ class ServiceActions
$aResult = array();
$sThemeFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sRealTheme.'/styles.less';
$sThemeExtFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sRealTheme.'/ext.less';
$sThemeValuesFile = APP_VERSION_ROOT_PATH.'app/templates/Themes/values.less';
if ($bCustom)
{
$sThemeFile = APP_VERSION_ROOT_PATH.'app/templates/Themes/custom-values-light.less';
if ($oSettings)
{
if (\RainLoop\Enumerations\CustomThemeType::LIGHT === (string) $oSettings->GetConf('CustomThemeType', \RainLoop\Enumerations\CustomThemeType::LIGHT))
{
$sThemeFile = APP_VERSION_ROOT_PATH.'app/templates/Themes/custom-values-light.less';
}
else
{
$sThemeFile = APP_VERSION_ROOT_PATH.'app/templates/Themes/custom-values-dark.less';
}
}
}
else
{
$sThemeFile = APP_VERSION_ROOT_PATH.'themes/'.$sTheme.'/styles.less';
}
$sThemeTemplateFile = APP_VERSION_ROOT_PATH.'app/templates/Themes/template.less';
if (\file_exists($sThemeFile) && \file_exists($sThemeTemplateFile) && \file_exists($sThemeValuesFile))
{
$aResult[] = '@base: "'.APP_WEB_PATH.'themes/'.$sTheme.'/";';
$aResult[] = '@base: "'.($bCustomTheme ? '' : APP_WEB_PATH).'themes/'.$sRealTheme.'/";';
$aResult[] = \file_get_contents($sThemeValuesFile);
$aResult[] = \file_get_contents($sThemeFile);
$aResult[] = \file_get_contents($sThemeTemplateFile);
if (\file_exists(APP_VERSION_ROOT_PATH.'themes/'.$sTheme.'/ext.less'))
if (\file_exists($sThemeExtFile))
{
$aResult[] = \file_get_contents(APP_VERSION_ROOT_PATH.'themes/'.$sTheme.'/ext.less');
$aResult[] = \file_get_contents($sThemeExtFile);
}
}
@ -614,16 +592,7 @@ class ServiceActions
$sResult = $oLess->compile(\implode("\n", $aResult));
if ($bCustom && $oAccount)
{
$mData = $this->oActions->StorageProvider()->Get($oAccount, \RainLoop\Providers\Storage\Enumerations\StorageType::USER, 'CustomThemeBackground', '');
if (!empty($mData) && 'data:' === \substr($mData, 0, 5))
{
$sResult = \str_replace('background-image:link', 'background-image:url("'.$mData.'")', $sResult);
}
}
if ($bCacheEnabled && !$bCustom)
if ($bCacheEnabled)
{
if (0 < \strlen($sCacheFileName))
{
@ -637,7 +606,7 @@ class ServiceActions
}
}
if ($bCacheEnabled && !$bCustom)
if ($bCacheEnabled)
{
$this->oActions->cacheByKey($this->sQuery);
}