From 84e2ec0f19f55fd8b9e14fbc3586072e99acfe4f Mon Sep 17 00:00:00 2001 From: HFO4 <912394456@qq.com> Date: Mon, 11 Mar 2019 16:21:17 +0800 Subject: [PATCH] Feat: Theme config --- application/index/controller/Home.php | 2 +- application/index/controller/Share.php | 4 +- application/index/controller/Viewer.php | 4 +- application/index/model/Option.php | 19 ++- application/index/view/home/home.html | 44 +----- application/index/view/share/share_dir.html | 46 +----- .../index/view/share/share_single.html | 44 +----- .../index/view/share/share_single_old.html | 148 ------------------ application/index/view/viewer/markdown.html | 44 +----- application/index/view/viewer/video.html | 44 +----- application/version.json | 2 +- mysql.sql | 9 +- 12 files changed, 41 insertions(+), 369 deletions(-) delete mode 100644 application/index/view/share/share_single_old.html diff --git a/application/index/controller/Home.php b/application/index/controller/Home.php index cbf882bc..acff3421 100644 --- a/application/index/controller/Home.php +++ b/application/index/controller/Home.php @@ -30,7 +30,7 @@ class Home extends Controller{ } $policyData["max_size"] = $policyData["max_size"]/(1024*1024); return view('home', [ - 'options' => Option::getValues(['basic','upload']), + 'options' => Option::getValues(['basic','upload'],$this->userObj->userSQLData), 'userInfo' => $userInfo, 'extLimit' => $extLimit, 'policyData' => $policyData, diff --git a/application/index/controller/Share.php b/application/index/controller/Share.php index 1f9d051b..f373275f 100644 --- a/application/index/controller/Share.php +++ b/application/index/controller/Share.php @@ -30,7 +30,7 @@ class Share extends Controller{ $shareObj->numIncrease("view_num"); if($shareObj->shareData["source_type"] == "dir"){ return view('share_dir', [ - 'options' => Option::getValues(['basic','share']), + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), 'userInfo' => $shareObj->shareOwner->userSQLData, 'dirData' => $shareObj->dirData, 'shareData' => $shareObj->shareData, @@ -42,7 +42,7 @@ class Share extends Controller{ ]); }else{ return view('share_single', [ - 'options' => Option::getValues(['basic','share']), + 'options' => Option::getValues(['basic','share'],$this->userObj->userSQLData), 'userInfo' => $shareObj->shareOwner->userSQLData, 'fileData' => $shareObj->fileData, 'shareData' => $shareObj->shareData, diff --git a/application/index/controller/Viewer.php b/application/index/controller/Viewer.php index dd77076f..edbcad29 100644 --- a/application/index/controller/Viewer.php +++ b/application/index/controller/Viewer.php @@ -34,7 +34,7 @@ class Viewer extends Controller{ $url = "/Share/Preview/".input("get.shareKey"); } return view('video', [ - 'options' => Option::getValues(['basic']), + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), 'userInfo' => $userInfo, 'groupData' => $groupData, 'url' => $url, @@ -55,7 +55,7 @@ class Viewer extends Controller{ $url = "/Share/Content/".input("get.shareKey"); } return view('markdown', [ - 'options' => Option::getValues(['basic']), + 'options' => Option::getValues(['basic'],$this->userObj->userSQLData), 'userInfo' => $userInfo, 'groupData' => $groupData, 'url' => $url, diff --git a/application/index/model/Option.php b/application/index/model/Option.php index b85836d5..e2d42c9f 100644 --- a/application/index/model/Option.php +++ b/application/index/model/Option.php @@ -5,10 +5,27 @@ use think\Model; use think\Db; class Option extends Model{ - static function getValues($groups = ['basic']){ + static function getValues($groups = ['basic'],$userInfo=null){ $t = Db::name('options')->where('option_type','in',$groups)->column('option_value','option_name'); + if(in_array("basic",$groups)){ + return array_merge($t,self::getThemeOptions($t,$userInfo)); + } return $t; } + + static function getThemeOptions($basicOptions,$userInfo){ + $themes = json_decode($basicOptions["themes"],true); + if($userInfo==null){ + return ["themeColor"=>$basicOptions["defaultTheme"],"themeConfig"=>$themes[$basicOptions["defaultTheme"]]]; + }else{ + $userOptions = json_decode($userInfo["options"],true); + if(empty($userOptions)||!array_key_exists("preferTheme",$userOptions)||!array_key_exists($userOptions["preferTheme"],$themes)){ + return ["themeColor"=>$basicOptions["defaultTheme"],"themeConfig"=>$themes[$basicOptions["defaultTheme"]]]; + } + return ["themeColor"=>$userOptions["preferTheme"],"themeConfig"=>$themes[$userOptions["preferTheme"]]]; + } + } + static function getValue($optionName){ return Db::name('options')->where('option_name',$optionName)->value('option_value'); } diff --git a/application/index/view/home/home.html b/application/index/view/home/home.html index a59ab323..5b44fc39 100644 --- a/application/index/view/home/home.html +++ b/application/index/view/home/home.html @@ -5,6 +5,7 @@ + 我的文件 - {$options.siteName} - - - - -