mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 09:21:46 +08:00 
			
		
		
		
	update: theme
This commit is contained in:
		| @@ -7,6 +7,8 @@ use App\Models\User; | ||||
| use App\Utils\CacheKey; | ||||
| use App\Utils\Helper; | ||||
| use Illuminate\Console\Command; | ||||
| use Illuminate\Filesystem\Filesystem; | ||||
| use Illuminate\Foundation\Console\ConfigCacheCommand; | ||||
| use Illuminate\Support\Facades\Cache; | ||||
| use Matriphe\Larinfo; | ||||
|  | ||||
| @@ -43,6 +45,5 @@ class Test extends Command | ||||
|      */ | ||||
|     public function handle() | ||||
|     { | ||||
|         abort(500, 123); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -8,6 +8,8 @@ use App\Services\TelegramService; | ||||
| use Illuminate\Http\Request; | ||||
| use App\Utils\Dict; | ||||
| use App\Http\Controllers\Controller; | ||||
| use Illuminate\Support\Facades\Artisan; | ||||
| use Illuminate\Support\Facades\File; | ||||
| use Illuminate\Support\Facades\Mail; | ||||
|  | ||||
| class ConfigController extends Controller | ||||
| @@ -118,10 +120,6 @@ class ConfigController extends Controller | ||||
|             ], | ||||
|             'frontend' => [ | ||||
|                 'frontend_theme' => config('v2board.frontend_theme', 'v2board'), | ||||
|                 'frontend_theme_sidebar' => config('v2board.frontend_theme_sidebar', 'light'), | ||||
|                 'frontend_theme_header' => config('v2board.frontend_theme_header', 'dark'), | ||||
|                 'frontend_theme_color' => config('v2board.frontend_theme_color', 'default'), | ||||
|                 'frontend_background_url' => config('v2board.frontend_background_url'), | ||||
|                 'frontend_admin_path' => config('v2board.frontend_admin_path', 'admin'), | ||||
|                 'frontend_customer_service_method' => config('v2board.frontend_customer_service_method', 0), | ||||
|                 'frontend_customer_service_id' => config('v2board.frontend_customer_service_id'), | ||||
| @@ -172,15 +170,18 @@ class ConfigController extends Controller | ||||
|     public function save(ConfigSave $request) | ||||
|     { | ||||
|         $data = $request->validated(); | ||||
|         $array = \Config::get('v2board'); | ||||
|         foreach ($data as $k => $v) { | ||||
|             if (!in_array($k, array_keys($request->validated()))) { | ||||
|                 abort(500, '参数' . $k . '不在规则内,禁止修改'); | ||||
|         $config = config('v2board'); | ||||
|         foreach ($config as $k => $v) { | ||||
|             if (!in_array($k, array_keys(ConfigSave::RULES))) { | ||||
|                 unset($config[$k]); | ||||
|                 continue; | ||||
|             } | ||||
|             if (isset($data[$k])) { | ||||
|                 $config[$k] = $data[$k]; | ||||
|             } | ||||
|             $array[$k] = $v; | ||||
|         } | ||||
|         $data = var_export($array, 1); | ||||
|         if (!\File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) { | ||||
|         $data = var_export($config, 1); | ||||
|         if (!File::put(base_path() . '/config/v2board.php', "<?php\n return $data ;")) { | ||||
|             abort(500, '修改失败'); | ||||
|         } | ||||
|         if (function_exists('opcache_reset')) { | ||||
| @@ -188,7 +189,7 @@ class ConfigController extends Controller | ||||
|                 abort(500, '缓存清除失败,请卸载或检查opcache配置状态'); | ||||
|             } | ||||
|         } | ||||
|         \Artisan::call('config:cache'); | ||||
|         Artisan::call('config:cache'); | ||||
|         return response([ | ||||
|             'data' => true | ||||
|         ]); | ||||
|   | ||||
| @@ -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 | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -6,6 +6,113 @@ use Illuminate\Foundation\Http\FormRequest; | ||||
|  | ||||
| class ConfigSave extends FormRequest | ||||
| { | ||||
|     const RULES = [ | ||||
|         // invite & commission | ||||
|         'safe_mode_enable' => 'in:0,1', | ||||
|         'invite_force' => 'in:0,1', | ||||
|         'invite_commission' => 'integer', | ||||
|         'invite_gen_limit' => 'integer', | ||||
|         'invite_never_expire' => 'in:0,1', | ||||
|         'commission_first_time_enable' => 'in:0,1', | ||||
|         'commission_auto_check_enable' => 'in:0,1', | ||||
|         'commission_withdraw_limit' => 'nullable|numeric', | ||||
|         'commission_withdraw_method' => 'nullable|array', | ||||
|         'withdraw_close_enable' => 'in:0,1', | ||||
|         'commission_distribution_enable' => 'in:0,1', | ||||
|         'commission_distribution_l1' => 'nullable|numeric', | ||||
|         'commission_distribution_l2' => 'nullable|numeric', | ||||
|         'commission_distribution_l3' => 'nullable|numeric', | ||||
|         // site | ||||
|         'stop_register' => 'in:0,1', | ||||
|         'email_verify' => 'in:0,1', | ||||
|         'app_name' => '', | ||||
|         'app_description' => '', | ||||
|         'app_url' => 'nullable|url', | ||||
|         'subscribe_url' => 'nullable', | ||||
|         'try_out_enable' => 'in:0,1', | ||||
|         'try_out_plan_id' => 'integer', | ||||
|         'try_out_hour' => 'numeric', | ||||
|         'email_whitelist_enable' => 'in:0,1', | ||||
|         'email_whitelist_suffix' => 'nullable|array', | ||||
|         'email_gmail_limit_enable' => 'in:0,1', | ||||
|         'recaptcha_enable' => 'in:0,1', | ||||
|         'recaptcha_key' => '', | ||||
|         'recaptcha_site_key' => '', | ||||
|         'tos_url' => 'nullable|url', | ||||
|         'currency' => '', | ||||
|         'currency_symbol' => '', | ||||
|         'register_limit_by_ip_enable' => 'in:0,1', | ||||
|         'register_limit_count' => 'integer', | ||||
|         'register_limit_expire' => 'integer', | ||||
|         // subscribe | ||||
|         'plan_change_enable' => 'in:0,1', | ||||
|         'reset_traffic_method' => 'in:0,1,2', | ||||
|         'surplus_enable' => 'in:0,1', | ||||
|         'new_order_event_id' => 'in:0,1', | ||||
|         'renew_order_event_id' => 'in:0,1', | ||||
|         'change_order_event_id' => 'in:0,1', | ||||
|         // server | ||||
|         'server_token' => 'nullable|min:16', | ||||
|         'server_license' => 'nullable', | ||||
|         'server_log_enable' => 'in:0,1', | ||||
|         'server_v2ray_domain' => '', | ||||
|         'server_v2ray_protocol' => '', | ||||
|         // alipay | ||||
|         'alipay_enable' => 'in:0,1', | ||||
|         'alipay_appid' => 'nullable|integer|min:16', | ||||
|         'alipay_pubkey' => 'max:2048', | ||||
|         'alipay_privkey' => 'max:2048', | ||||
|         // stripe | ||||
|         'stripe_alipay_enable' => 'in:0,1', | ||||
|         'stripe_wepay_enable' => 'in:0,1', | ||||
|         'stripe_card_enable' => 'in:0,1', | ||||
|         'stripe_sk_live' => '', | ||||
|         'stripe_pk_live' => '', | ||||
|         'stripe_webhook_key' => '', | ||||
|         'stripe_currency' => 'in:hkd,usd,sgd,eur,gbp,jpy,cad', | ||||
|         // bitpayx | ||||
|         'bitpayx_name' => '', | ||||
|         'bitpayx_enable' => 'in:0,1', | ||||
|         'bitpayx_appsecret' => '', | ||||
|         // mGate | ||||
|         'mgate_name' => '', | ||||
|         'mgate_enable' => 'in:0,1', | ||||
|         'mgate_url' => 'nullable|url', | ||||
|         'mgate_app_id' => '', | ||||
|         'mgate_app_secret' => '', | ||||
|         // Epay | ||||
|         'epay_name' => '', | ||||
|         'epay_enable' => 'in:0,1', | ||||
|         'epay_url' => 'nullable|url', | ||||
|         'epay_pid' => '', | ||||
|         'epay_key' => '', | ||||
|         // frontend | ||||
|         'frontend_theme' => '', | ||||
|         'frontend_admin_path' => '', | ||||
|         'frontend_customer_service_method' => '', | ||||
|         'frontend_customer_service_id' => '', | ||||
|         // email | ||||
|         'email_template' => '', | ||||
|         'email_host' => '', | ||||
|         'email_port' => '', | ||||
|         'email_username' => '', | ||||
|         'email_password' => '', | ||||
|         'email_encryption' => '', | ||||
|         'email_from_address' => '', | ||||
|         // telegram | ||||
|         'telegram_bot_enable' => 'in:0,1', | ||||
|         'telegram_bot_token' => '', | ||||
|         'telegram_discuss_id' => '', | ||||
|         'telegram_channel_id' => '', | ||||
|         'telegram_discuss_link' => 'nullable|url', | ||||
|         // app | ||||
|         'windows_version' => '', | ||||
|         'windows_download_url' => '', | ||||
|         'macos_version' => '', | ||||
|         'macos_download_url' => '', | ||||
|         'android_version' => '', | ||||
|         'android_download_url' => '' | ||||
|     ]; | ||||
|     /** | ||||
|      * Get the validation rules that apply to the request. | ||||
|      * | ||||
| @@ -13,117 +120,7 @@ class ConfigSave extends FormRequest | ||||
|      */ | ||||
|     public function rules() | ||||
|     { | ||||
|         return [ | ||||
|             // invite & commission | ||||
|             'safe_mode_enable' => 'in:0,1', | ||||
|             'invite_force' => 'in:0,1', | ||||
|             'invite_commission' => 'integer', | ||||
|             'invite_gen_limit' => 'integer', | ||||
|             'invite_never_expire' => 'in:0,1', | ||||
|             'commission_first_time_enable' => 'in:0,1', | ||||
|             'commission_auto_check_enable' => 'in:0,1', | ||||
|             'commission_withdraw_limit' => 'nullable|numeric', | ||||
|             'commission_withdraw_method' => 'nullable|array', | ||||
|             'withdraw_close_enable' => 'in:0,1', | ||||
|             'commission_distribution_enable' => 'in:0,1', | ||||
|             'commission_distribution_l1' => 'nullable|numeric', | ||||
|             'commission_distribution_l2' => 'nullable|numeric', | ||||
|             'commission_distribution_l3' => 'nullable|numeric', | ||||
|             // site | ||||
|             'stop_register' => 'in:0,1', | ||||
|             'email_verify' => 'in:0,1', | ||||
|             'app_name' => '', | ||||
|             'app_description' => '', | ||||
|             'app_url' => 'nullable|url', | ||||
|             'subscribe_url' => 'nullable', | ||||
|             'try_out_enable' => 'in:0,1', | ||||
|             'try_out_plan_id' => 'integer', | ||||
|             'try_out_hour' => 'numeric', | ||||
|             'email_whitelist_enable' => 'in:0,1', | ||||
|             'email_whitelist_suffix' => 'nullable|array', | ||||
|             'email_gmail_limit_enable' => 'in:0,1', | ||||
|             'recaptcha_enable' => 'in:0,1', | ||||
|             'recaptcha_key' => '', | ||||
|             'recaptcha_site_key' => '', | ||||
|             'tos_url' => 'nullable|url', | ||||
|             'currency' => '', | ||||
|             'currency_symbol' => '', | ||||
|             'register_limit_by_ip_enable' => 'in:0,1', | ||||
|             'register_limit_count' => 'integer', | ||||
|             'register_limit_expire' => 'integer', | ||||
|             // subscribe | ||||
|             'plan_change_enable' => 'in:0,1', | ||||
|             'reset_traffic_method' => 'in:0,1,2', | ||||
|             'surplus_enable' => 'in:0,1', | ||||
|             'new_order_event_id' => 'in:0,1', | ||||
|             'renew_order_event_id' => 'in:0,1', | ||||
|             'change_order_event_id' => 'in:0,1', | ||||
|             // server | ||||
|             'server_token' => 'nullable|min:16', | ||||
|             'server_license' => 'nullable', | ||||
|             'server_log_enable' => 'in:0,1', | ||||
|             'server_v2ray_domain' => '', | ||||
|             'server_v2ray_protocol' => '', | ||||
|             // alipay | ||||
|             'alipay_enable' => 'in:0,1', | ||||
|             'alipay_appid' => 'nullable|integer|min:16', | ||||
|             'alipay_pubkey' => 'max:2048', | ||||
|             'alipay_privkey' => 'max:2048', | ||||
|             // stripe | ||||
|             'stripe_alipay_enable' => 'in:0,1', | ||||
|             'stripe_wepay_enable' => 'in:0,1', | ||||
|             'stripe_card_enable' => 'in:0,1', | ||||
|             'stripe_sk_live' => '', | ||||
|             'stripe_pk_live' => '', | ||||
|             'stripe_webhook_key' => '', | ||||
|             'stripe_currency' => 'in:hkd,usd,sgd,eur,gbp,jpy,cad', | ||||
|             // bitpayx | ||||
|             'bitpayx_name' => '', | ||||
|             'bitpayx_enable' => 'in:0,1', | ||||
|             'bitpayx_appsecret' => '', | ||||
|             // mGate | ||||
|             'mgate_name' => '', | ||||
|             'mgate_enable' => 'in:0,1', | ||||
|             'mgate_url' => 'nullable|url', | ||||
|             'mgate_app_id' => '', | ||||
|             'mgate_app_secret' => '', | ||||
|             // Epay | ||||
|             'epay_name' => '', | ||||
|             'epay_enable' => 'in:0,1', | ||||
|             'epay_url' => 'nullable|url', | ||||
|             'epay_pid' => '', | ||||
|             'epay_key' => '', | ||||
|             // frontend | ||||
|             'frontend_theme' => '', | ||||
|             'frontend_theme_sidebar' => 'in:dark,light', | ||||
|             'frontend_theme_header' => 'in:dark,light', | ||||
|             'frontend_theme_color' => 'in:default,darkblue,black,green', | ||||
|             'frontend_background_url' => 'nullable|url', | ||||
|             'frontend_admin_path' => '', | ||||
|             'frontend_customer_service_method' => '', | ||||
|             'frontend_customer_service_id' => '', | ||||
|             // email | ||||
|             'email_template' => '', | ||||
|             'email_host' => '', | ||||
|             'email_port' => '', | ||||
|             'email_username' => '', | ||||
|             'email_password' => '', | ||||
|             'email_encryption' => '', | ||||
|             'email_from_address' => '', | ||||
|             // telegram | ||||
|             'telegram_bot_enable' => 'in:0,1', | ||||
|             'telegram_bot_token' => '', | ||||
|             'telegram_discuss_id' => '', | ||||
|             'telegram_channel_id' => '', | ||||
|             'telegram_discuss_link' => 'nullable|url', | ||||
|             // app | ||||
|             'windows_version' => '', | ||||
|             'windows_download_url' => '', | ||||
|             'macos_version' => '', | ||||
|             'macos_download_url' => '', | ||||
|             'android_version' => '', | ||||
|             'android_download_url' => '' | ||||
|         ]; | ||||
|         return self::RULES; | ||||
|     } | ||||
|  | ||||
|     public function messages() | ||||
|   | ||||
| @@ -117,7 +117,7 @@ class AdminRoute | ||||
|             // Theme | ||||
|             $router->get ('/theme/getThemes', 'Admin\\ThemeController@getThemes'); | ||||
|             $router->post('/theme/saveThemeConfig', 'Admin\\ThemeController@saveThemeConfig'); | ||||
|             $router->get ('/theme/getThemeConfig', 'Admin\\ThemeController@getThemeConfig'); | ||||
|             $router->post('/theme/getThemeConfig', 'Admin\\ThemeController@getThemeConfig'); | ||||
|         }); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user