Prevent usage of Less

This commit is contained in:
the-djmaze 2022-02-15 14:48:32 +01:00
parent 29cbd0fbb6
commit 7838aee0f1
4 changed files with 27 additions and 13 deletions

View file

@ -99,25 +99,31 @@ trait Themes
$sTheme = \substr($sTheme, 0, -7);
}
$aResult = array();
$sThemeCSSFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sTheme.'/styles.css';
$sThemeLessFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sTheme.'/styles.less';
$mResult = array();
$sBase = ($bCustomTheme ? \RainLoop\Utils::WebPath() : \RainLoop\Utils::WebVersionPath())
. "themes/{$sTheme}/";
$bLess = false;
$sThemeCSSFile = ($bCustomTheme ? APP_INDEX_ROOT_PATH : APP_VERSION_ROOT_PATH).'themes/'.$sTheme.'/styles.css';
if (\is_file($sThemeCSSFile)) {
$aResult[] = \preg_replace('@(url\(["\']?)(\\./)?([a-z]+[^:a-z])@',
"\$1{$sBase}\$3",
\str_replace('@{base}', $sBase, \file_get_contents($sThemeCSSFile)));
} else if (\is_file($sThemeLessFile)) {
$aResult[] = "@base: \"{$sBase}\";";
$aResult[] = \file_get_contents($sThemeLessFile);
$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);
}
}
$aResult[] = $this->Plugins()->CompileCss($bAdmin);
$mResult[] = $this->Plugins()->CompileCss($bAdmin, $bLess);
return (new \LessPHP\lessc())->compile(\implode("\n", $aResult));
$mResult = \preg_replace('@(url\(["\']?)(\\./)?([a-z]+[^:a-z])@',
"\$1{$sBase}\$3",
\str_replace('@{base}', $sBase, \implode("\n", $mResult)));
return $bLess ? (new \LessPHP\lessc())->compile($mResult) : $mResult;
}
}

View file

@ -167,13 +167,14 @@ class Manager
return $this->bIsEnabled && \count($this->aJs[$bAdminScope ? 1 : 0]);
}
public function CompileCss(bool $bAdminScope = false) : string
public function CompileCss(bool $bAdminScope, bool &$bLess) : string
{
$aResult = array();
if ($this->bIsEnabled) {
foreach ($this->aCss[$bAdminScope ? 1 : 0] as $sFile) {
if (\is_readable($sFile)) {
$aResult[] = \file_get_contents($sFile);
$bLess = $bLess || \str_ends_with($sFile, '.less');
}
}
}

View file

@ -26,6 +26,13 @@ if (!function_exists('str_starts_with')) {
return 0 === strncmp($haystack, $needle, strlen($needle));
}
}
if (!function_exists('str_ends_with')) {
function str_ends_with(string $haystack, string $needle) : bool
{
$length = strlen($needle);
return $length ? substr($haystack, -$length) === $needle : true;
}
}
if (!defined('APP_VERSION')) {
define('APP_VERSION', basename(__DIR__));