This commit is contained in:
the-djmaze 2023-01-26 20:02:48 +01:00
parent 188b419910
commit d65d77ef2f
3 changed files with 42 additions and 23 deletions

View file

@ -79,6 +79,10 @@ export const
* @returns {string} * @returns {string}
*/ */
themePreviewLink = theme => { themePreviewLink = theme => {
if (theme.endsWith('@nextcloud')) {
theme = theme.slice(0, theme.length - 10).trim();
return OC().webroot + '/themes/' + encodeURI(theme) + '/snappymail.png';
}
let path = 'webVersionPath'; let path = 'webVersionPath';
if (theme.endsWith('@custom')) { if (theme.endsWith('@custom')) {
theme = theme.slice(0, theme.length - 7).trim(); theme = theme.slice(0, theme.length - 7).trim();

View file

@ -59,6 +59,7 @@ export const
convertThemeName = theme => theme convertThemeName = theme => theme
.replace(/@custom$/, '') .replace(/@custom$/, '')
.replace(/@nextcloud$/, '')
.replace(/([A-Z])/g, ' $1') .replace(/([A-Z])/g, ' $1')
.replace(/[^a-zA-Z0-9]+/g, ' ') .replace(/[^a-zA-Z0-9]+/g, ' ')
.trim(); .trim();

View file

@ -54,16 +54,25 @@ trait Themes
} }
$sDir = APP_INDEX_ROOT_PATH . 'themes'; // custom user themes $sDir = APP_INDEX_ROOT_PATH . 'themes'; // custom user themes
if (\is_dir($sDir)) { if (\is_dir($sDir) && ($rDirH = \opendir($sDir))) {
$rDirH = \opendir($sDir); while (($sFile = \readdir($rDirH)) !== false) {
if ($rDirH) { if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile)
&& (\file_exists("{$sDir}/{$sFile}/styles.css") || \file_exists("{$sDir}/{$sFile}/styles.less"))) {
$aCache[] = $sFile . '@custom';
}
}
\closedir($rDirH);
}
if (\class_exists('OC', false)) {
$sDir = \OC::$SERVERROOT . '/themes'; // custom user themes
if (\is_dir($sDir) && ($rDirH = \opendir($sDir))) {
while (($sFile = \readdir($rDirH)) !== false) { while (($sFile = \readdir($rDirH)) !== false) {
if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile) if ('.' !== $sFile[0] && \is_dir($sDir . '/' . $sFile)
&& (\file_exists("{$sDir}/{$sFile}/styles.css") || \file_exists("{$sDir}/{$sFile}/styles.less"))) { && (\file_exists("{$sDir}/{$sFile}/snappymail.css") || \file_exists("{$sDir}/{$sFile}/snappymail.less"))) {
$aCache[] = $sFile . '@custom'; $aCache[] = $sFile . '@nextcloud';
} }
} }
\closedir($rDirH); \closedir($rDirH);
} }
} }
@ -89,28 +98,33 @@ trait Themes
public function compileCss(string $sTheme, bool $bAdmin, bool $bMinified = false) : string public function compileCss(string $sTheme, bool $bAdmin, bool $bMinified = false) : string
{ {
$bCustomTheme = '@custom' === \substr($sTheme, -7);
if ($bCustomTheme) {
$sTheme = \substr($sTheme, 0, -7);
}
$mResult = array(); $mResult = array();
$sBase = ($bCustomTheme ? \RainLoop\Utils::WebPath() : \RainLoop\Utils::WebVersionPath())
. "themes/{$sTheme}/";
$bLess = false; $bLess = false;
$sThemeCSSFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sTheme.'/styles.css'; if ('@nextcloud' === \substr($sTheme, -10)) {
$sBase = \OC::$WEBROOT . '/';
$sThemeCSSFile = \OC::$SERVERROOT . '/themes/' . \str_replace('@nextcloud', '/snappymail.css', $sTheme);
} else {
$bCustomTheme = '@custom' === \substr($sTheme, -7);
if ($bCustomTheme) {
$sTheme = \substr($sTheme, 0, -7);
$sBase = \RainLoop\Utils::WebPath();
} else {
$sBase = \RainLoop\Utils::WebVersionPath();
}
$sBase .= "themes/{$sTheme}/";
$sThemeCSSFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sTheme.'/styles.css';
if (!\is_file($sThemeCSSFile)) {
$sThemeCSSFile = \str_replace('styles.css', 'styles.less', $sThemeCSSFile);
if (\is_file($sThemeCSSFile)) {
$bLess = true;
$mResult[] = "@base: \"{$sBase}\";";
$mResult[] = \file_get_contents($sThemeCSSFile);
}
}
}
if (\is_file($sThemeCSSFile)) { if (\is_file($sThemeCSSFile)) {
$mResult[] = \file_get_contents($sThemeCSSFile); $mResult[] = \file_get_contents($sThemeCSSFile);
} else {
$sThemeCSSFile = \str_replace('styles.css', 'styles.less', $sThemeCSSFile);
if (\is_file($sThemeCSSFile)) {
$bLess = true;
$mResult[] = "@base: \"{$sBase}\";";
$mResult[] = \file_get_contents($sThemeCSSFile);
}
} }
$mResult[] = $this->Plugins()->CompileCss($bAdmin, $bLess, $bMinified); $mResult[] = $this->Plugins()->CompileCss($bAdmin, $bLess, $bMinified);