mirror of
https://github.com/v2board/v2board.git
synced 2025-06-16 06:37:53 +08:00
update: theme
This commit is contained in:
@ -20,6 +20,25 @@ class ThemeController extends Controller
|
||||
}, glob($path . '*'));
|
||||
}
|
||||
|
||||
private function initTheme($themeName, $configs)
|
||||
{
|
||||
$data = [];
|
||||
foreach ($configs as $config) {
|
||||
$data[$config['field_name']] = isset($config['default_value']) ? $config['default_value'] : '';
|
||||
}
|
||||
|
||||
$data = var_export($data, 1);
|
||||
if (!File::put(base_path() . "/config/theme/{$themeName}.php", "<?php\n return $data ;")) {
|
||||
abort(500, "{$themeName}初始化失败");
|
||||
}
|
||||
|
||||
try {
|
||||
Artisan::call('config:cache');
|
||||
} catch (\Exception $e) {
|
||||
abort(500, "{$themeName}初始化失败");
|
||||
}
|
||||
}
|
||||
|
||||
public function getThemes()
|
||||
{
|
||||
$themeConfigs = [];
|
||||
@ -28,12 +47,14 @@ class ThemeController extends Controller
|
||||
if (!File::exists($themeConfigFile)) continue;
|
||||
$themeConfig = include($themeConfigFile);
|
||||
if (!isset($themeConfig['configs']) || !is_array($themeConfig)) continue;
|
||||
$themeConfigs[$this->themes] = $themeConfig;
|
||||
$themeConfigs[$theme] = $themeConfig;
|
||||
if (config("theme.{$theme}")) continue;
|
||||
$this->initTheme($theme, $themeConfig['configs']);
|
||||
}
|
||||
return response([
|
||||
'data' => [
|
||||
'themes' => $themeConfigs,
|
||||
'active' => config('v2board.theme', 'v2board')
|
||||
'active' => config('v2board.frontend_theme', 'v2board')
|
||||
]
|
||||
]);
|
||||
}
|
||||
@ -52,7 +73,7 @@ class ThemeController extends Controller
|
||||
{
|
||||
$payload = $request->validate([
|
||||
'name' => 'required|in:' . join(',', $this->themes),
|
||||
'configs' => 'required|array'
|
||||
'config' => 'required|array'
|
||||
]);
|
||||
$themeConfigFile = public_path("theme/{$payload['name']}/config.php");
|
||||
if (!File::exists($themeConfigFile)) abort(500, '主题不存在');
|
||||
@ -60,8 +81,7 @@ class ThemeController extends Controller
|
||||
$validateFields = array_column($themeConfig['configs'], 'field_name');
|
||||
$config = [];
|
||||
foreach ($validateFields as $validateField) {
|
||||
if (!isset($payload['configs'][$validateField])) continue;
|
||||
$config[$validateField] = $payload['configs'][$validateField];
|
||||
$config[$validateField] = isset($payload['config'][$validateField]) ? $payload['config'][$validateField] : '';
|
||||
}
|
||||
|
||||
File::ensureDirectoryExists(base_path() . '/config/theme/');
|
||||
@ -78,7 +98,7 @@ class ThemeController extends Controller
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => config('theme.v2board')
|
||||
'data' => $config
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user