Theme variable loading.

This commit is contained in:
buddh4 2017-01-22 00:11:02 +01:00
parent 161312ea0c
commit 24fadd51f8
3 changed files with 28 additions and 5971 deletions

View File

@ -12,7 +12,6 @@ use Yii;
use yii\helpers\FileHelper;
use humhub\libs\ThemeHelper;
/**
* @inheritdoc
*/
@ -161,11 +160,16 @@ class Theme extends \yii\base\Theme
*/
public function storeColorsToConfig()
{
$lessFileName = $this->getBasePath() . '/css/theme.less';
if (file_exists($lessFileName)) {
$less = file_get_contents($lessFileName);
// Parse default values
$variables = $this->parseLessVariables(Yii::getAlias('@webroot/less/variables.less'));
// Overwrite theme values
$variables = \yii\helpers\ArrayHelper::merge($variables, $this->parseLessVariables($this->getBasePath() . '/less/variables.less'));
$startDefault = strpos($less, '@default') + 10;
// Set variable settings
foreach($variables as $variable => $value) {
Yii::$app->settings->set('theme.variable.'.$variable, $value);
}
/*$startDefault = strpos($less, '@default') + 10;
$startPrimary = strpos($less, '@primary') + 10;
$startInfo = strpos($less, '@info') + 7;
$startSuccess = strpos($less, '@success') + 10;
@ -178,8 +182,24 @@ class Theme extends \yii\base\Theme
Yii::$app->settings->set('colorInfo', substr($less, $startInfo, $length));
Yii::$app->settings->set('colorSuccess', substr($less, $startSuccess, $length));
Yii::$app->settings->set('colorWarning', substr($less, $startWarning, $length));
Yii::$app->settings->set('colorDanger', substr($less, $startDanger, $length));
Yii::$app->settings->set('colorDanger', substr($less, $startDanger, $length));*/
}
/**
* Parses the given file for less variables and returns an array with variablename as key and the value.
* @param type $lessFile the less file to parse
*/
protected function parseLessVariables($lessFile)
{
if (file_exists($lessFile)) {
$variables = [];
preg_match_all('/@(.*?):\s(.*?);/', file_get_contents($lessFile), $regexResult, PREG_SET_ORDER);
foreach ($regexResult as $regexHit) {
$variables[$regexHit[1]] = $regexHit[2];
}
return $variables;
}
return [];
}
/**

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff