mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
Merge language into index template
This commit is contained in:
parent
c3c1fc2c0e
commit
fb98ca6fe7
10 changed files with 354 additions and 300 deletions
|
|
@ -149,7 +149,6 @@ win.rl = {
|
|||
}
|
||||
|
||||
loadScript(appData.StaticLibJsLink)
|
||||
.then(() => Promise.all([loadScript(appData.TemplatesLink), loadScript(appData.LangLink)]))
|
||||
.then(() => loadScript(appData.StaticAppJsLink))
|
||||
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
||||
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
|
||||
|
|
|
|||
12
dev/bootstrap.js
vendored
12
dev/bootstrap.js
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { doc, elementById, dropdownVisibility, Settings } from 'Common/Globals';
|
||||
import { doc, dropdownVisibility, Settings } from 'Common/Globals';
|
||||
import { i18n } from 'Common/Translator';
|
||||
|
||||
import { root } from 'Common/Links';
|
||||
|
|
@ -135,15 +135,9 @@ export default (App) => {
|
|||
});
|
||||
};
|
||||
|
||||
window.__APP_BOOT = fErrorCallback => {
|
||||
window.__APP_BOOT = () => {
|
||||
const cb = () => setTimeout(() => {
|
||||
if (rl.TEMPLATES) {
|
||||
elementById('rl-templates').innerHTML = rl.TEMPLATES;
|
||||
setTimeout(() => App.bootstart(), 10);
|
||||
} else {
|
||||
fErrorCallback();
|
||||
}
|
||||
|
||||
setTimeout(() => App.bootstart(), 10);
|
||||
window.__APP_BOOT = null;
|
||||
}, 10);
|
||||
('loading' !== doc.readyState) ? cb() : doc.addEventListener('DOMContentLoaded', cb);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ class Actions
|
|||
use Actions\User;
|
||||
use Actions\Raw;
|
||||
use Actions\Response;
|
||||
use Actions\Localization;
|
||||
use Actions\Themes;
|
||||
|
||||
const AUTH_TFA_SIGN_ME_TOKEN_KEY = 'rltfasmauth';
|
||||
const AUTH_SIGN_ME_TOKEN_KEY = 'rlsmauth';
|
||||
|
|
@ -1102,6 +1104,11 @@ class Actions
|
|||
$oConfig->Save();
|
||||
}
|
||||
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
$sLanguageAdmin = $oConfig->Get('webmail', 'language_admin', 'en');
|
||||
$UserLanguageRaw = $this->detectUserLanguage($bAdmin);
|
||||
$sTheme = $oConfig->Get('webmail', 'theme', 'Default');
|
||||
|
||||
if (!$bAdmin) {
|
||||
$oAccount = $this->getAccountFromToken(false);
|
||||
if ($oAccount) {
|
||||
|
|
@ -1150,7 +1157,64 @@ class Actions
|
|||
if (!empty($aResult['StartupUrl'])) {
|
||||
$aResult['StartupUrl'] = $this->compileLogParams($aResult['StartupUrl'], $oAccount, true);
|
||||
}
|
||||
} else {
|
||||
|
||||
$aResult['ParentEmail'] = $oAccount->ParentEmail();
|
||||
|
||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$aResult['SentFolder'] = (string)$oSettingsLocal->GetConf('SentFolder', '');
|
||||
$aResult['DraftFolder'] = (string)$oSettingsLocal->GetConf('DraftFolder', '');
|
||||
$aResult['SpamFolder'] = (string)$oSettingsLocal->GetConf('SpamFolder', '');
|
||||
$aResult['TrashFolder'] = (string)$oSettingsLocal->GetConf('TrashFolder', '');
|
||||
$aResult['ArchiveFolder'] = (string)$oSettingsLocal->GetConf('ArchiveFolder', '');
|
||||
$aResult['HideUnsubscribed'] = (bool)$oSettingsLocal->GetConf('HideUnsubscribed', $aResult['HideUnsubscribed']);
|
||||
}
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::SETTINGS, $oAccount)) {
|
||||
if ($oSettings instanceof Settings) {
|
||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$sLanguage = (string)$oSettings->GetConf('Language', $sLanguage);
|
||||
}
|
||||
|
||||
$aResult['EditorDefaultType'] = (string)$oSettings->GetConf('EditorDefaultType', $aResult['EditorDefaultType']);
|
||||
$aResult['ShowImages'] = (bool)$oSettings->GetConf('ShowImages', $aResult['ShowImages']);
|
||||
$aResult['RemoveColors'] = (bool)$oSettings->GetConf('RemoveColors', $aResult['RemoveColors']);
|
||||
$aResult['ContactsAutosave'] = (bool)$oSettings->GetConf('ContactsAutosave', $aResult['ContactsAutosave']);
|
||||
$aResult['MPP'] = (int)$oSettings->GetConf('MPP', $aResult['MPP']);
|
||||
$aResult['SoundNotification'] = (bool)$oSettings->GetConf('SoundNotification', $aResult['SoundNotification']);
|
||||
$aResult['DesktopNotifications'] = (bool)$oSettings->GetConf('DesktopNotifications', $aResult['DesktopNotifications']);
|
||||
$aResult['UseCheckboxesInList'] = (bool)$oSettings->GetConf('UseCheckboxesInList', $aResult['UseCheckboxesInList']);
|
||||
$aResult['AllowDraftAutosave'] = (bool)$oSettings->GetConf('AllowDraftAutosave', $aResult['AllowDraftAutosave']);
|
||||
$aResult['AutoLogout'] = (int)$oSettings->GetConf('AutoLogout', $aResult['AutoLogout']);
|
||||
$aResult['Layout'] = (int)$oSettings->GetConf('Layout', $aResult['Layout']);
|
||||
|
||||
if (!$this->GetCapa(false, Enumerations\Capa::AUTOLOGOUT, $oAccount)) {
|
||||
$aResult['AutoLogout'] = 0;
|
||||
}
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) {
|
||||
$aResult['UserBackgroundName'] = (string)$oSettings->GetConf('UserBackgroundName', $aResult['UserBackgroundName']);
|
||||
$aResult['UserBackgroundHash'] = (string)$oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$aResult['UseThreads'] = (bool)$oSettingsLocal->GetConf('UseThreads', $aResult['UseThreads']);
|
||||
$aResult['ReplySameFolder'] = (bool)$oSettingsLocal->GetConf('ReplySameFolder', $aResult['ReplySameFolder']);
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::THEMES, $oAccount)) {
|
||||
$sTheme = (string)$oSettingsLocal->GetConf('Theme', $sTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($oConfig->Get('login', 'allow_languages_on_login', true)
|
||||
&& $oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($UserLanguageRaw, $sLanguage, false);
|
||||
}
|
||||
|
||||
$aResult['DevEmail'] = $oConfig->Get('labs', 'dev_email', '');
|
||||
$aResult['DevPassword'] = $oConfig->Get('labs', 'dev_password', '');
|
||||
|
||||
|
|
@ -1196,97 +1260,28 @@ class Actions
|
|||
|
||||
$aResult['ProjectHash'] = \md5($aResult['AccountHash'] . APP_VERSION . $this->Plugins()->Hash());
|
||||
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
$sLanguageAdmin = $oConfig->Get('webmail', 'language_admin', 'en');
|
||||
$sTheme = $oConfig->Get('webmail', 'theme', 'Default');
|
||||
|
||||
if (!$bAdmin && $oAccount) {
|
||||
$aResult['ParentEmail'] = $oAccount->ParentEmail();
|
||||
|
||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$aResult['SentFolder'] = (string)$oSettingsLocal->GetConf('SentFolder', '');
|
||||
$aResult['DraftFolder'] = (string)$oSettingsLocal->GetConf('DraftFolder', '');
|
||||
$aResult['SpamFolder'] = (string)$oSettingsLocal->GetConf('SpamFolder', '');
|
||||
$aResult['TrashFolder'] = (string)$oSettingsLocal->GetConf('TrashFolder', '');
|
||||
$aResult['ArchiveFolder'] = (string)$oSettingsLocal->GetConf('ArchiveFolder', '');
|
||||
$aResult['HideUnsubscribed'] = (bool)$oSettingsLocal->GetConf('HideUnsubscribed', $aResult['HideUnsubscribed']);
|
||||
}
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::SETTINGS, $oAccount)) {
|
||||
if ($oSettings instanceof Settings) {
|
||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$sLanguage = (string)$oSettings->GetConf('Language', $sLanguage);
|
||||
}
|
||||
|
||||
$aResult['EditorDefaultType'] = (string)$oSettings->GetConf('EditorDefaultType', $aResult['EditorDefaultType']);
|
||||
$aResult['ShowImages'] = (bool)$oSettings->GetConf('ShowImages', $aResult['ShowImages']);
|
||||
$aResult['RemoveColors'] = (bool)$oSettings->GetConf('RemoveColors', $aResult['RemoveColors']);
|
||||
$aResult['ContactsAutosave'] = (bool)$oSettings->GetConf('ContactsAutosave', $aResult['ContactsAutosave']);
|
||||
$aResult['MPP'] = (int)$oSettings->GetConf('MPP', $aResult['MPP']);
|
||||
$aResult['SoundNotification'] = (bool)$oSettings->GetConf('SoundNotification', $aResult['SoundNotification']);
|
||||
$aResult['DesktopNotifications'] = (bool)$oSettings->GetConf('DesktopNotifications', $aResult['DesktopNotifications']);
|
||||
$aResult['UseCheckboxesInList'] = (bool)$oSettings->GetConf('UseCheckboxesInList', $aResult['UseCheckboxesInList']);
|
||||
$aResult['AllowDraftAutosave'] = (bool)$oSettings->GetConf('AllowDraftAutosave', $aResult['AllowDraftAutosave']);
|
||||
$aResult['AutoLogout'] = (int)$oSettings->GetConf('AutoLogout', $aResult['AutoLogout']);
|
||||
$aResult['Layout'] = (int)$oSettings->GetConf('Layout', $aResult['Layout']);
|
||||
|
||||
if (!$this->GetCapa(false, Enumerations\Capa::AUTOLOGOUT, $oAccount)) {
|
||||
$aResult['AutoLogout'] = 0;
|
||||
}
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::USER_BACKGROUND, $oAccount)) {
|
||||
$aResult['UserBackgroundName'] = (string)$oSettings->GetConf('UserBackgroundName', $aResult['UserBackgroundName']);
|
||||
$aResult['UserBackgroundHash'] = (string)$oSettings->GetConf('UserBackgroundHash', $aResult['UserBackgroundHash']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$aResult['UseThreads'] = (bool)$oSettingsLocal->GetConf('UseThreads', $aResult['UseThreads']);
|
||||
$aResult['ReplySameFolder'] = (bool)$oSettingsLocal->GetConf('ReplySameFolder', $aResult['ReplySameFolder']);
|
||||
|
||||
if ($this->GetCapa(false, Enumerations\Capa::THEMES, $oAccount)) {
|
||||
$sTheme = (string)$oSettingsLocal->GetConf('Theme', $sTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$aResult['Auth']) {
|
||||
if (!$bAdmin) {
|
||||
if ($oConfig->Get('login', 'allow_languages_on_login', true) &&
|
||||
$oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage(
|
||||
$this->detectUserLanguage($bAdmin), $sLanguage, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sTheme = $this->ValidateTheme($sTheme);
|
||||
$sStaticCache = $this->StaticCache();
|
||||
|
||||
$sTheme = $this->ValidateTheme($sTheme);
|
||||
$aResult['Theme'] = $sTheme;
|
||||
$aResult['NewThemeLink'] = $this->ThemeLink($sTheme, $bAdmin);
|
||||
|
||||
$aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false);
|
||||
$aResult['LanguageAdmin'] = $this->ValidateLanguage($sLanguageAdmin, '', true);
|
||||
|
||||
$aResult['UserLanguageRaw'] = $this->detectUserLanguage($bAdmin);
|
||||
|
||||
$aResult['UserLanguage'] = $this->ValidateLanguage($aResult['UserLanguageRaw'], '', false, true);
|
||||
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($aResult['UserLanguageRaw'], '', true, true);
|
||||
$aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
||||
if ($bAdmin) {
|
||||
$aResult['LanguageAdmin'] = $this->ValidateLanguage($sLanguageAdmin, '', true);
|
||||
$aResult['UserLanguageAdmin'] = $this->ValidateLanguage($UserLanguageRaw, '', true, true);
|
||||
}
|
||||
|
||||
$aResult['PluginsLink'] = '';
|
||||
if (0 < $this->Plugins()->Count() && $this->Plugins()->HaveJs($bAdmin)) {
|
||||
$aResult['PluginsLink'] = './?/Plugins/0/' . ($bAdmin ? 'Admin' : 'User') . '/' . $sStaticCache . '/';
|
||||
}
|
||||
|
||||
$aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' .
|
||||
($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/';
|
||||
// $aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' .
|
||||
// ($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/';
|
||||
|
||||
// $aResult['TemplatesLink'] = './?/Templates/0/'.($bAdmin ? 'Admin' : 'App').'/'.$sStaticCache.'/';
|
||||
$aResult['TemplatesLink'] = './?/Templates/0/' . ($bAdmin ? 'Admin' : 'App') . '/' . $sStaticCache . '/';
|
||||
// $aResult['TemplatesLink'] = './?/Templates/0/' . ($bAdmin ? 'Admin' : 'App') . '/' . $sStaticCache . '/';
|
||||
|
||||
$bAppJsDebug = !!$this->Config()->Get('labs', 'use_app_debug_js', false);
|
||||
|
||||
|
|
@ -1309,38 +1304,6 @@ class Actions
|
|||
return $aResult;
|
||||
}
|
||||
|
||||
private function getUserLanguagesFromHeader(): array
|
||||
{
|
||||
$aResult = $aList = array();
|
||||
$sAcceptLang = \strtolower($this->Http()->GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||
if (!empty($sAcceptLang) && \preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $sAcceptLang, $aList)) {
|
||||
$aResult = \array_combine($aList[1], $aList[2]);
|
||||
foreach ($aResult as $n => $v) {
|
||||
$aResult[$n] = $v ? $v : 1;
|
||||
}
|
||||
|
||||
\arsort($aResult, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function detectUserLanguage(bool $bAdmin = false): string
|
||||
{
|
||||
$sResult = '';
|
||||
$aLangs = $this->getUserLanguagesFromHeader();
|
||||
|
||||
foreach (\array_keys($aLangs) as $sLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
||||
if (!empty($sLang)) {
|
||||
$sResult = $sLang;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
private function requestSleep(int $iWait = 1, int $iDelay = 1): void
|
||||
{
|
||||
if (0 < $iDelay && 0 < $iWait) {
|
||||
|
|
@ -2130,123 +2093,11 @@ class Actions
|
|||
return $sCache;
|
||||
}
|
||||
|
||||
public function ThemeLink(string $sTheme, bool $bAdmin): string
|
||||
{
|
||||
return './?/Css/0/' . ($bAdmin ? 'Admin' : 'User') . '/-/' . $sTheme . '/-/' . $this->StaticCache() . '/Hash/-/';
|
||||
}
|
||||
|
||||
public function ValidateTheme(string $sTheme): string
|
||||
{
|
||||
return \in_array($sTheme, $this->GetThemes()) ?
|
||||
$sTheme : $this->Config()->Get('themes', 'default', 'Default');
|
||||
}
|
||||
|
||||
public function ValidateLanguage(string $sLanguage, string $sDefault = '', bool $bAdmin = false, bool $bAllowEmptyResult = false): string
|
||||
{
|
||||
$aLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
||||
|
||||
$aHelper = array(
|
||||
'ar' => 'ar-SA',
|
||||
'cs' => 'cs-CZ',
|
||||
'no' => 'nb-NO',
|
||||
'ua' => 'uk-UA',
|
||||
'cn' => 'zh-CN',
|
||||
'zh' => 'zh-CN',
|
||||
'tw' => 'zh-TW',
|
||||
'fa' => 'fa-IR'
|
||||
);
|
||||
|
||||
$sLanguage = isset($aHelper[$sLanguage]) ? $aHelper[$sLanguage] : \strtr($sLanguage, '_', '-');
|
||||
$sDefault = isset($aHelper[$sDefault]) ? $aHelper[$sDefault] : \strtr($sDefault, '_', '-');
|
||||
|
||||
if (\in_array($sLanguage, $aLang)) {
|
||||
return $sLanguage;
|
||||
}
|
||||
|
||||
$sLangCountry = \preg_replace_callback('/-([a-zA-Z]{2})$/', function ($aData) {
|
||||
return \strtoupper($aData[0]);
|
||||
}, $sLanguage);
|
||||
if (\in_array($sLangCountry, $aLang)) {
|
||||
return $sLangCountry;
|
||||
}
|
||||
|
||||
if (\in_array($sDefault, $aLang)) {
|
||||
return $sDefault;
|
||||
}
|
||||
|
||||
if ($bAllowEmptyResult) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$sResult = $this->Config()->Get('webmail', $bAdmin ? 'language_admin' : 'language', 'en');
|
||||
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
||||
}
|
||||
|
||||
public function ValidateContactPdoType(string $sType): string
|
||||
{
|
||||
return \in_array($sType, \RainLoop\Common\PdoAbstract::getAvailableDrivers()) ? $sType : 'sqlite';
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar array $aCache
|
||||
*/
|
||||
public function GetThemes(): array
|
||||
{
|
||||
static $aCache = array();
|
||||
if ($aCache) {
|
||||
return $aCache;
|
||||
}
|
||||
|
||||
$bClear = false;
|
||||
$bDefault = false;
|
||||
$aCache = array();
|
||||
$sDir = APP_VERSION_ROOT_PATH . 'themes';
|
||||
if (\is_dir($sDir)) {
|
||||
$rDirH = \opendir($sDir);
|
||||
if ($rDirH) {
|
||||
while (($sFile = \readdir($rDirH)) !== false) {
|
||||
if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile) && \file_exists($sDir . '/' . $sFile . '/styles.less')) {
|
||||
if ('Default' === $sFile) {
|
||||
$bDefault = true;
|
||||
} else if ('Clear' === $sFile) {
|
||||
$bClear = true;
|
||||
} else {
|
||||
$aCache[] = $sFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($rDirH);
|
||||
}
|
||||
}
|
||||
|
||||
$sDir = APP_INDEX_ROOT_PATH . 'themes'; // custom user themes
|
||||
if (\is_dir($sDir)) {
|
||||
$rDirH = \opendir($sDir);
|
||||
if ($rDirH) {
|
||||
while (($sFile = \readdir($rDirH)) !== false) {
|
||||
if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile) && \file_exists($sDir . '/' . $sFile . '/styles.less')) {
|
||||
$aCache[] = $sFile . '@custom';
|
||||
}
|
||||
}
|
||||
|
||||
\closedir($rDirH);
|
||||
}
|
||||
}
|
||||
|
||||
$aCache = \array_unique($aCache);
|
||||
\sort($aCache);
|
||||
|
||||
if ($bDefault) {
|
||||
\array_unshift($aCache, 'Default');
|
||||
}
|
||||
|
||||
if ($bClear) {
|
||||
\array_push($aCache, 'Clear');
|
||||
}
|
||||
|
||||
return $aCache;
|
||||
}
|
||||
|
||||
public function ProcessTemplate(string $sName, string $sHtml): string
|
||||
{
|
||||
$sHtml = \preg_replace('/<script/i', '<x-script', $sHtml);
|
||||
|
|
@ -2294,55 +2145,6 @@ class Actions
|
|||
\header('Location: ' . $sUrl);
|
||||
}
|
||||
|
||||
public function GetLanguageAndTheme(bool $bAdmin = false): array
|
||||
{
|
||||
$sTheme = $this->Config()->Get('webmail', 'theme', 'Default');
|
||||
|
||||
if ($bAdmin) {
|
||||
$sLanguage = $this->Config()->Get('webmail', 'language_admin', 'en');
|
||||
} else {
|
||||
$oAccount = $this->GetAccount();
|
||||
|
||||
$sLanguage = $this->Config()->Get('webmail', 'language', 'en');
|
||||
|
||||
if ($oAccount) {
|
||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||
if ($oSettings instanceof Settings) {
|
||||
$sLanguage = $oSettings->GetConf('Language', $sLanguage);
|
||||
}
|
||||
|
||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$sTheme = $oSettingsLocal->GetConf('Theme', $sTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sLanguage = $this->ValidateLanguage($sLanguage, '', $bAdmin);
|
||||
$sTheme = $this->ValidateTheme($sTheme);
|
||||
|
||||
return array($sLanguage, $sTheme);
|
||||
}
|
||||
|
||||
public function StaticI18N(string $sKey): string
|
||||
{
|
||||
static $sLang = null;
|
||||
static $aLang = null;
|
||||
|
||||
if (null === $sLang) {
|
||||
$aList = $this->GetLanguageAndTheme();
|
||||
$sLang = $aList[0];
|
||||
}
|
||||
|
||||
if (null === $aLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, 'en');
|
||||
$aLang = \SnappyMail\L10n::load($sLang, 'static');
|
||||
$this->Plugins()->ReadLang($sLang, $aLang);
|
||||
}
|
||||
|
||||
return $aLang[$aKey] ?? $sKey;
|
||||
}
|
||||
|
||||
public function StaticPath(string $sPath): string
|
||||
{
|
||||
return Utils::WebStaticPath() . $sPath;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,157 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Actions;
|
||||
|
||||
trait Localization
|
||||
{
|
||||
/*
|
||||
'DetermineUserLanguage' => (bool)$oConfig->Get('login', 'determine_user_language', true),
|
||||
'AllowLanguagesOnSettings' => (bool) $oConfig->Get('webmail', 'allow_languages_on_settings', true),
|
||||
'AllowLanguagesOnLogin' => (bool) $oConfig->Get('login', 'allow_languages_on_login', true),
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
$sLanguageAdmin = $oConfig->Get('webmail', 'language_admin', 'en');
|
||||
|
||||
$UserLanguageRaw = $this->detectUserLanguage($bAdmin);
|
||||
|
||||
if (!$bAdmin) {
|
||||
$oAccount = $this->getAccountFromToken(false);
|
||||
if ($oAccount) {
|
||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||
if ($oSettings instanceof Settings) {
|
||||
if ($this->GetCapa(false, Enumerations\Capa::SETTINGS, $oAccount)) {
|
||||
if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$sLanguage = (string)$oSettings->GetConf('Language', $sLanguage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$aResult['Auth']) {
|
||||
if ($oConfig->Get('login', 'allow_languages_on_login', true) &&
|
||||
$oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($UserLanguageRaw, $sLanguage, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aResult['Language'] = $this->ValidateLanguage($sLanguage, '', false);
|
||||
$aResult['LanguageAdmin'] = $this->ValidateLanguage($sLanguageAdmin, '', true);
|
||||
|
||||
$aResult['UserLanguage'] = $this->ValidateLanguage($UserLanguageRaw, '', false, true);
|
||||
|
||||
// $aResult['LangLink'] = './?/Lang/0/' . ($bAdmin ? 'Admin' : 'App') . '/' .
|
||||
// ($bAdmin ? $aResult['LanguageAdmin'] : $aResult['Language']) . '/' . $sStaticCache . '/';
|
||||
*/
|
||||
|
||||
public function GetLanguage(bool $bAdmin = false): string
|
||||
{
|
||||
$oConfig = $this->Config();
|
||||
if ($bAdmin) {
|
||||
$sLanguage = $oConfig->Get('webmail', 'language_admin', 'en');
|
||||
} else {
|
||||
$sLanguage = $oConfig->Get('webmail', 'language', 'en');
|
||||
// $oAccount = $this->getAccountFromToken(false);
|
||||
if ($oAccount = $this->GetAccount()) {
|
||||
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||
if ($oSettings instanceof Settings) {
|
||||
// if ($this->GetCapa(false, Enumerations\Capa::SETTINGS, $oAccount)) {
|
||||
// if ($oConfig->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||
$sLanguage = $oSettings->GetConf('Language', $sLanguage);
|
||||
}
|
||||
} else if ($oConfig->Get('login', 'allow_languages_on_login', true) && $oConfig->Get('login', 'determine_user_language', true)) {
|
||||
$sLanguage = $this->ValidateLanguage($this->detectUserLanguage($bAdmin), $sLanguage, false);
|
||||
}
|
||||
}
|
||||
return $this->ValidateLanguage($sLanguage, '', $bAdmin) ?: 'en';
|
||||
}
|
||||
|
||||
public function ValidateLanguage(string $sLanguage, string $sDefault = '', bool $bAdmin = false, bool $bAllowEmptyResult = false): string
|
||||
{
|
||||
$aLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
||||
|
||||
$aHelper = array(
|
||||
'ar' => 'ar-SA',
|
||||
'cs' => 'cs-CZ',
|
||||
'no' => 'nb-NO',
|
||||
'ua' => 'uk-UA',
|
||||
'cn' => 'zh-CN',
|
||||
'zh' => 'zh-CN',
|
||||
'tw' => 'zh-TW',
|
||||
'fa' => 'fa-IR'
|
||||
);
|
||||
|
||||
$sLanguage = isset($aHelper[$sLanguage]) ? $aHelper[$sLanguage] : \strtr($sLanguage, '_', '-');
|
||||
$sDefault = isset($aHelper[$sDefault]) ? $aHelper[$sDefault] : \strtr($sDefault, '_', '-');
|
||||
|
||||
if (\in_array($sLanguage, $aLang)) {
|
||||
return $sLanguage;
|
||||
}
|
||||
|
||||
$sLangCountry = \preg_replace_callback('/-([a-zA-Z]{2})$/', function ($aData) {
|
||||
return \strtoupper($aData[0]);
|
||||
}, $sLanguage);
|
||||
if (\in_array($sLangCountry, $aLang)) {
|
||||
return $sLangCountry;
|
||||
}
|
||||
|
||||
if (\in_array($sDefault, $aLang)) {
|
||||
return $sDefault;
|
||||
}
|
||||
|
||||
if ($bAllowEmptyResult) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$sResult = $this->Config()->Get('webmail', $bAdmin ? 'language_admin' : 'language', 'en');
|
||||
return \in_array($sResult, $aLang) ? $sResult : 'en';
|
||||
}
|
||||
|
||||
private function getUserLanguagesFromHeader(): array
|
||||
{
|
||||
$aResult = $aList = array();
|
||||
$sAcceptLang = \strtolower($this->Http()->GetServer('HTTP_ACCEPT_LANGUAGE', 'en'));
|
||||
if (!empty($sAcceptLang) && \preg_match_all('/([a-z]{1,8}(?:-[a-z]{1,8})?)(?:;q=([0-9.]+))?/', $sAcceptLang, $aList)) {
|
||||
$aResult = \array_combine($aList[1], $aList[2]);
|
||||
foreach ($aResult as $n => $v) {
|
||||
$aResult[$n] = $v ? $v : 1;
|
||||
}
|
||||
|
||||
\arsort($aResult, SORT_NUMERIC);
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function detectUserLanguage(bool $bAdmin): string
|
||||
{
|
||||
$sResult = '';
|
||||
$aLangs = $this->getUserLanguagesFromHeader();
|
||||
|
||||
foreach (\array_keys($aLangs) as $sLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, '', $bAdmin, true);
|
||||
if (!empty($sLang)) {
|
||||
$sResult = $sLang;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $sResult;
|
||||
}
|
||||
|
||||
public function StaticI18N(string $sKey): string
|
||||
{
|
||||
static $sLang = null;
|
||||
static $aLang = null;
|
||||
|
||||
if (null === $sLang) {
|
||||
$sLang = $this->GetLanguage();
|
||||
}
|
||||
|
||||
if (null === $aLang) {
|
||||
$sLang = $this->ValidateLanguage($sLang, 'en');
|
||||
$aLang = \SnappyMail\L10n::load($sLang, 'static');
|
||||
$this->Plugins()->ReadLang($sLang, $aLang);
|
||||
}
|
||||
|
||||
return $aLang[$aKey] ?? $sKey;
|
||||
}
|
||||
}
|
||||
108
snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php
Normal file
108
snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Themes.php
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Actions;
|
||||
|
||||
trait Themes
|
||||
{
|
||||
/*
|
||||
$sTheme = $oConfig->Get('webmail', 'theme', 'Default');
|
||||
if (!$bAdmin && $oAccount) {
|
||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||
if ($this->GetCapa(false, Enumerations\Capa::SETTINGS, $oAccount)) {
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
if ($this->GetCapa(false, Enumerations\Capa::THEMES, $oAccount)) {
|
||||
$sTheme = (string) $oSettingsLocal->GetConf('Theme', $sTheme);
|
||||
$sTheme = $this->ValidateTheme($sTheme);
|
||||
$aResult['Theme'] = $sTheme;
|
||||
$aResult['NewThemeLink'] = $this->ThemeLink($sTheme, $bAdmin);
|
||||
|
||||
if ($oConfig->Get('webmail', 'allow_themes', false)) {
|
||||
$aResult[] = Enumerations\Capa::THEMES;
|
||||
}
|
||||
*/
|
||||
|
||||
public function GetTheme(bool $bAdmin): string
|
||||
{
|
||||
$sTheme = $this->Config()->Get('webmail', 'theme', 'Default');
|
||||
if (!$bAdmin) {
|
||||
if ($oAccount = $this->GetAccount()) {
|
||||
$oSettingsLocal = $this->SettingsProvider(true)->Load($oAccount);
|
||||
if ($oSettingsLocal instanceof Settings) {
|
||||
$sTheme = $oSettingsLocal->GetConf('Theme', $sTheme);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->ValidateTheme($sTheme) ?: 'Default';
|
||||
}
|
||||
|
||||
/**
|
||||
* @staticvar array $aCache
|
||||
*/
|
||||
public function GetThemes(): array
|
||||
{
|
||||
static $aCache = array();
|
||||
if ($aCache) {
|
||||
return $aCache;
|
||||
}
|
||||
|
||||
$bClear = false;
|
||||
$bDefault = false;
|
||||
$aCache = array();
|
||||
$sDir = APP_VERSION_ROOT_PATH . 'themes';
|
||||
if (\is_dir($sDir)) {
|
||||
$rDirH = \opendir($sDir);
|
||||
if ($rDirH) {
|
||||
while (($sFile = \readdir($rDirH)) !== false) {
|
||||
if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile) && \file_exists($sDir . '/' . $sFile . '/styles.less')) {
|
||||
if ('Default' === $sFile) {
|
||||
$bDefault = true;
|
||||
} else if ('Clear' === $sFile) {
|
||||
$bClear = true;
|
||||
} else {
|
||||
$aCache[] = $sFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($rDirH);
|
||||
}
|
||||
}
|
||||
|
||||
$sDir = APP_INDEX_ROOT_PATH . 'themes'; // custom user themes
|
||||
if (\is_dir($sDir)) {
|
||||
$rDirH = \opendir($sDir);
|
||||
if ($rDirH) {
|
||||
while (($sFile = \readdir($rDirH)) !== false) {
|
||||
if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile) && \file_exists($sDir . '/' . $sFile . '/styles.less')) {
|
||||
$aCache[] = $sFile . '@custom';
|
||||
}
|
||||
}
|
||||
|
||||
\closedir($rDirH);
|
||||
}
|
||||
}
|
||||
|
||||
$aCache = \array_unique($aCache);
|
||||
\sort($aCache);
|
||||
|
||||
if ($bDefault) {
|
||||
\array_unshift($aCache, 'Default');
|
||||
}
|
||||
|
||||
if ($bClear) {
|
||||
\array_push($aCache, 'Clear');
|
||||
}
|
||||
|
||||
return $aCache;
|
||||
}
|
||||
|
||||
public function ThemeLink(string $sTheme, bool $bAdmin): string
|
||||
{
|
||||
return './?/Css/0/' . ($bAdmin ? 'Admin' : 'User') . '/-/' . $sTheme . '/-/' . $this->StaticCache() . '/Hash/-/';
|
||||
}
|
||||
|
||||
public function ValidateTheme(string $sTheme): string
|
||||
{
|
||||
return \in_array($sTheme, $this->GetThemes()) ?
|
||||
$sTheme : $this->Config()->Get('themes', 'default', 'Default');
|
||||
}
|
||||
}
|
||||
|
|
@ -159,22 +159,23 @@ class Service
|
|||
}
|
||||
|
||||
$aTemplateParameters = $this->indexTemplateParameters($bAdmin);
|
||||
$sLanguage = $this->oActions->GetLanguage($bAdmin);
|
||||
|
||||
$sCacheFileName = '';
|
||||
if ($this->oActions->Config()->Get('labs', 'cache_system_data', true) && !empty($aTemplateParameters['{{BaseHash}}']))
|
||||
{
|
||||
$sCacheFileName = 'TMPL:'.$aTemplateParameters['{{BaseHash}}'];
|
||||
$sCacheFileName = 'TMPL:'.$sLanguage.$aTemplateParameters['{{BaseHash}}'];
|
||||
$sResult = $this->oActions->Cacher()->Get($sCacheFileName);
|
||||
}
|
||||
|
||||
if (0 === \strlen($sResult))
|
||||
{
|
||||
// $aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
|
||||
$aTemplateParameters['{{BaseLanguage}}'] = $this->oServiceActions->compileLanguage($sLanguage, $bAdmin);
|
||||
$aTemplateParameters['{{BaseTemplates}}'] = $this->oServiceActions->compileTemplates($bAdmin, false);
|
||||
$sResult = \strtr(\file_get_contents(APP_VERSION_ROOT_PATH.'app/templates/Index.html'), $aTemplateParameters);
|
||||
|
||||
$sResult = Utils::ClearHtmlOutput($sResult);
|
||||
if (0 < \strlen($sCacheFileName))
|
||||
{
|
||||
if ($sCacheFileName) {
|
||||
$this->oActions->Cacher()->Set($sCacheFileName, $sResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -209,13 +210,8 @@ class Service
|
|||
return $this->oActions->StaticPath($sPath);
|
||||
}
|
||||
|
||||
private function indexTemplateParameters(bool $bAdmin = false) : array
|
||||
private function indexTemplateParameters(bool $bAdmin) : array
|
||||
{
|
||||
$sLanguage = 'en';
|
||||
$sTheme = 'Default';
|
||||
|
||||
list($sLanguage, $sTheme) = $this->oActions->GetLanguageAndTheme($bAdmin);
|
||||
|
||||
$oConfig = $this->oActions->Config();
|
||||
|
||||
$bAppJsDebug = !!$oConfig->Get('labs', 'use_app_debug_js', false);
|
||||
|
|
@ -232,10 +228,9 @@ class Service
|
|||
'{{BaseAppFaviconPngLinkTag}}' => $sFaviconPngLink ? '<link type="image/png" rel="shortcut icon" href="'.$sFaviconPngLink.'" />' : '',
|
||||
'{{BaseAppFaviconTouchLinkTag}}' => $sAppleTouchLink ? '<link type="image/png" rel="apple-touch-icon" href="'.$sAppleTouchLink.'" />' : '',
|
||||
'{{BaseAppMainCssLink}}' => $this->staticPath('css/'.($bAdmin ? 'admin' : 'app').($bAppCssDebug ? '' : '.min').'.css'),
|
||||
'{{BaseAppThemeCssLink}}' => $this->oActions->ThemeLink($sTheme, $bAdmin),
|
||||
'{{BaseAppBootScriptLink}}' => $this->staticPath('js/'.($bAppJsDebug ? '' : 'min/').'boot'.($bAppJsDebug ? '' : '.min').'.js'),
|
||||
'{{BaseAppThemeCssLink}}' => $this->oActions->ThemeLink($this->oActions->GetTheme($bAdmin), $bAdmin),
|
||||
'{{BaseAppBootScript}}' => \file_get_contents(APP_VERSION_ROOT_PATH.'static/js/min/boot.min.js'),
|
||||
'{{BaseDir}}' => false && \in_array($sLanguage, array('ar', 'he', 'ur')) ? 'rtl' : 'ltr',
|
||||
// '{{BaseDir}}' => false && \in_array($sLanguage, array('ar', 'he', 'ur')) ? 'rtl' : 'ltr',
|
||||
'{{BaseAppManifestLink}}' => $this->staticPath('manifest.json'),
|
||||
'{{BaseAppBootCss}}' => \file_get_contents(APP_VERSION_ROOT_PATH.'static/css/boot.min.css'),
|
||||
'{{LoadingDescriptionEsc}}' => \htmlspecialchars($LoadingDescription, ENT_QUOTES|ENT_IGNORE, 'UTF-8'),
|
||||
|
|
|
|||
|
|
@ -1010,7 +1010,7 @@ class ServiceActions
|
|||
return $bJsOutput ? 'rl.TEMPLATES='.\MailSo\Base\Utils::Php2js($sHtml, $this->Logger()).';' : $sHtml;
|
||||
}
|
||||
|
||||
private function compileLanguage(string $sLanguage, bool $bAdmin = false) : string
|
||||
public function compileLanguage(string $sLanguage, bool $bAdmin = false) : string
|
||||
{
|
||||
$sLanguage = \strtr($sLanguage, '_', '-');
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
// 'zero', 'one', 'two', 'few', 'many', 'other'
|
||||
/* 'zero', 'one', 'two', 'few', 'many', 'other' */
|
||||
plural: n => 1 == n ? 'one' : 'other'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,5 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
// 'zero', 'one', 'two', 'few', 'many', 'other'
|
||||
plural: n => 1 == n ? 'one' : 'other'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@
|
|||
<div id="rl-right"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="rl-templates"></div>
|
||||
</div>
|
||||
<div id="progressjs"><div></div></div>
|
||||
<script type="text/javascript">{{BaseAppBootScript}}</script>
|
||||
<script type="text/javascript">{{BaseAppBootScript}}{{BaseLanguage}}</script>
|
||||
{{BaseTemplates}}
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue