Browse Source

add switch control

Vien 5 years ago
parent
commit
2f960bb3c8

+ 2 - 1
.gitignore

@@ -13,4 +13,5 @@ yarn-error.log
 */.DS_Store
 .idea/
 /.idea
-.idea/*
+.idea/*
+composer.lock

+ 273 - 0
app/Http/Controllers/Admin/Index/SwitchController.php

@@ -0,0 +1,273 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Index;
+
+use App\Models\Blog\Article;
+use App\Models\Blog\ArticleTag;
+use App\Models\Blog\Category;
+use App\Models\Blog\Tag;
+use App\Models\Index\Information;
+use App\Models\Index\Link;
+use App\Models\Index\Switches;
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\Auth;
+
+class SwitchController extends Controller
+{
+    //
+    public function edit(Request $request)
+    {
+        $switches = Switches::query()
+            ->select( 'id', 'name', 'status', 'extra')
+            ->get()->toArray();
+
+        $dict = array();
+
+        foreach ($switches as $switch) {
+            $extra = json_decode($switch['extra'], true);
+            $dict[$switch['name']] = array('status' => intval($switch['status']) == 1,
+                'extra' => is_null($extra) ? [] : $extra);
+        }
+
+        $sidebar = [
+            "carousel" => [
+                "open" => $dict['carousel']['status'], // 是(true)否(false)开启 默认true 开启务必设置banners
+                "banners" => $dict['carousel']['extra']
+            ],
+            "motto" => [ // 座右铭
+                "open" => $dict['motto']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['motto']['extra']['title'], // 标题
+                "content" => $dict['motto']['extra']['content'] // 内容
+            ],
+            "tag" => [ // 标签
+                "open" => $dict['tag']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['tag']['extra']['title'], // 标题
+                "count" => intval($dict['tag']['extra']['count']), // 展示数量
+            ],
+            "category" => [ // 分类
+                "open" => $dict['category']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['category']['extra']['title'], // 标题
+                "count" => intval($dict['category']['extra']['count']), // 展示数量
+            ],
+            "hot" => [ // 最热文章
+                "open" => $dict['hot']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['hot']['extra']['title'], // 标题
+                "count" => intval($dict['hot']['extra']['count']), // 展示数量
+            ],
+            "latest" => [ // 最新文章
+                "open" => $dict['latest']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['latest']['extra']['title'], // 标题
+                "count" => intval($dict['latest']['extra']['count']), // 展示数量
+            ],
+            "popular" => [ // 刚有人看的文章
+                "open" => $dict['popular']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['popular']['extra']['title'], // 标题
+                "count" => intval($dict['popular']['extra']['count']), // 展示数量
+            ],
+        ];
+
+        $adsense_script = $dict['adsense']['extra'];
+        $adsense = [
+            "open" => $dict['adsense']['status'], // Google AdSense Auto AD 开关 默认关闭 开启需要在后台中添加 AdSense代码
+            "script" => array_key_exists('script', $adsense_script) ? $adsense_script['script'] : ""
+        ];
+        $counter_script = $dict['counter']['extra'];
+        $counter = [
+            "open" => $dict['counter']['status'], // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
+            "script" => array_key_exists('script', $counter_script) ? $counter_script['script'] : ""
+        ];
+
+        $switches = ['sidebar' => $sidebar, 'adsense' => $adsense, 'counter' => $counter];
+
+        return view('admin.switch.edit', ['switches' => $switches]);
+    }
+
+    public function update(Request $request)
+    {
+        $input = $request->input();
+//        $this->validate($request, [
+//            "carousel-switch" => "required",
+//            "carousel-image-1" => "required",
+//            "carousel-url-1" => "required",
+//            "carousel-description-1" => "required",
+//            "carousel-image-2" => "required",
+//            "carousel-url-2" => "required",
+//            "carousel-description-2" => "required",
+//            "carousel-image-3" => "required",
+//            "carousel-url-3" => "required",
+//            "carousel-description-3" => "required",
+//            "motto-switch" => "required",
+//            "motto-title" => "required",
+//            "motto-content" => "required",
+//            "tag-switch" => "required",
+//            "tag-title" => "required",
+//            "tag-count" => "required",
+//            "category-switch" => "required",
+//            "category-title" => "required",
+//            "category-count" => "required",
+//            "hot-switch" => "required",
+//            "hot-title" => "required",
+//            "hot-count" => "required",
+//            "latest-switch" => "required",
+//            "latest-title" => "required",
+//            "latest-count" => "required",
+//            "popular-switch" => "required",
+//            "popular-title" => "required",
+//            "popular-count" => "required",
+//            "adsense-switch" => "required",
+//            "adsense-script" => "required",
+//            "counter-switch" => "required",
+//            "counter-script" => "required"
+//        ]);
+
+        $carouselswitch = isset($input["carousel-switch"]) ? 1 : 0;
+        $carouselimage1 = $input["carousel-image-1"];
+        $carouselurl1 = $input["carousel-url-1"];
+        $carouseldescription1 = $input["carousel-description-1"];
+        $carouselimage2 = $input["carousel-image-2"];
+        $carouselurl2 = $input["carousel-url-2"];
+        $carouseldescription2 = $input["carousel-description-2"];
+        $carouselimage3 = $input["carousel-image-3"];
+        $carouselurl3 = $input["carousel-url-3"];
+        $carouseldescription3 = $input["carousel-description-3"];
+        $mottoswitch = isset($input["motto-switch"]) ? 1 : 0;
+        $mottotitle = $input["motto-title"];
+        $mottocontent = $input["motto-content"];
+        $tagswitch = isset($input["tag-switch"]) ? 1 : 0;
+        $tagtitle = $input["tag-title"];
+        $tagcount = $input["tag-count"];
+        $categoryswitch = isset($input["category-switch"]) ? 1 : 0;
+        $categorytitle = $input["category-title"];
+        $categorycount = $input["category-count"];
+        $hotswitch = isset($input["hot-switch"]) ? 1 : 0;
+        $hottitle = $input["hot-title"];
+        $hotcount = $input["hot-count"];
+        $latestswitch = isset($input["latest-switch"]) ? 1 : 0;
+        $latesttitle = $input["latest-title"];
+        $latestcount = $input["latest-count"];
+        $popularswitch = isset($input["popular-switch"]) ? 1 : 0;
+        $populartitle = $input["popular-title"];
+        $popularcount = $input["popular-count"];
+        $adsenseswitch = isset($input["adsense-switch"]) ? 1 : 0;
+        $adsensescript = isset($input["adsense-script"]) ? $input["adsense-script"] : "";
+        $counterswitch = isset($input["counter-switch"]) ? 1 : 0;
+        $counterscript = isset($input["counter-script"]) ? $input["counter-script"] : "";
+
+        $adsense = Switches::query()->where("name", "=", "adsense")->first();
+
+        $adsense->status = $adsenseswitch;
+        $adsense->extra = json_encode(["script" => $adsensescript], JSON_UNESCAPED_UNICODE);
+        $adsense->save();
+        
+        $counter = Switches::query()->where("name", "=", "counter")->first();
+        $counter->status = $counterswitch;
+        $counter->extra = json_encode(["script" => $counterscript], JSON_UNESCAPED_UNICODE);
+        $counter->save();
+        
+        $motto = Switches::query()->where("name", "=", "motto")->first();
+        $motto->status = $mottoswitch;
+        $motto->extra = json_encode(["title" => $mottotitle, "content" => $mottocontent], JSON_UNESCAPED_UNICODE);
+        $motto->save();
+        
+        $tag = Switches::query()->where("name", "=", "tag")->first();
+        $tag->status = $tagswitch;
+        $tag->extra = json_encode(["title" => $tagtitle, "count" => $tagcount], JSON_UNESCAPED_UNICODE);
+        $tag->save();
+        
+        $category = Switches::query()->where("name", "=", "category")->first();
+        $category->status = $categoryswitch;
+        $category->extra = json_encode(["title" => $categorytitle, "count" => $categorycount], JSON_UNESCAPED_UNICODE);
+        $category->save();
+        
+        $hot = Switches::query()->where("name", "=", "hot")->first();
+        $hot->status = $hotswitch;
+        $hot->extra = json_encode(["title" => $hottitle, "count" => $hotcount], JSON_UNESCAPED_UNICODE);
+        $hot->save();
+        
+        $latest = Switches::query()->where("name", "=", "latest")->first();
+        $latest->status = $latestswitch;
+        $latest->extra = json_encode(["title" => $latesttitle, "count" => $latestcount], JSON_UNESCAPED_UNICODE);
+        $latest->save();
+        
+        $popular = Switches::query()->where("name", "=", "popular")->first();
+        $popular->status = $popularswitch;
+        $popular->extra = json_encode(["title" => $populartitle, "count" => $popularcount], JSON_UNESCAPED_UNICODE);
+        $popular->save();
+        
+        $carousel = Switches::query()->where("name", "=", "carousel")->first();
+        $carousel->status = $carouselswitch;
+        $carousel->extra = json_encode([
+            ["image" => $carouselimage1, "url" => $carouselurl1, "description" => $carouseldescription1],
+            ["image" => $carouselimage2, "url" => $carouselurl2, "description" => $carouseldescription2],
+            ["image" => $carouselimage3, "url" => $carouselurl3, "description" => $carouseldescription3]
+            ], JSON_UNESCAPED_UNICODE);
+        $carousel->save();
+
+//        $baidu_autopush = Switches::query()->where("name", "=", "baidu_autopush")->first();
+
+        $switches = Switches::query()
+            ->select( 'id', 'name', 'status', 'extra')
+            ->get()->toArray();
+
+        $dict = array();
+
+        foreach ($switches as $switch) {
+            $extra = json_decode($switch['extra'], true);
+            $dict[$switch['name']] = array('status' => intval($switch['status']) == 1,
+                'extra' => is_null($extra) ? [] : $extra);
+        }
+
+        $sidebar = [
+            "carousel" => [
+                "open" => $dict['carousel']['status'], // 是(true)否(false)开启 默认true 开启务必设置banners
+                "banners" => $dict['carousel']['extra']
+            ],
+            "motto" => [ // 座右铭
+                "open" => $dict['motto']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['motto']['extra']['title'], // 标题
+                "content" => $dict['motto']['extra']['content'] // 内容
+            ],
+            "tag" => [ // 标签
+                "open" => $dict['tag']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['tag']['extra']['title'], // 标题
+                "count" => intval($dict['tag']['extra']['count']), // 展示数量
+            ],
+            "category" => [ // 分类
+                "open" => $dict['category']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['category']['extra']['title'], // 标题
+                "count" => intval($dict['category']['extra']['count']), // 展示数量
+            ],
+            "hot" => [ // 最热文章
+                "open" => $dict['hot']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['hot']['extra']['title'], // 标题
+                "count" => intval($dict['hot']['extra']['count']), // 展示数量
+            ],
+            "latest" => [ // 最新文章
+                "open" => $dict['latest']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['latest']['extra']['title'], // 标题
+                "count" => intval($dict['latest']['extra']['count']), // 展示数量
+            ],
+            "popular" => [ // 刚有人看的文章
+                "open" => $dict['popular']['status'], // 是(true)否(false)开启 默认true,
+                "title" => $dict['popular']['extra']['title'], // 标题
+                "count" => intval($dict['popular']['extra']['count']), // 展示数量
+            ],
+        ];
+
+        $adsense_script = $dict['adsense']['extra'];
+        $adsense = [
+            "open" => $dict['adsense']['status'], // Google AdSense Auto AD 开关 默认关闭 开启需要在后台中添加 AdSense代码
+            "script" => array_key_exists('script', $adsense_script) ? $adsense_script['script'] : ""
+        ];
+        $counter_script = $dict['counter']['extra'];
+        $counter = [
+            "open" => $dict['counter']['status'], // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
+            "script" => array_key_exists('script', $counter_script) ? $counter_script['script'] : ""
+        ];
+
+        $switches = ['sidebar' => $sidebar, 'adsense' => $adsense, 'counter' => $counter];
+
+        return view('admin.switch.edit', ['switches' => $switches])->with(['message' => 'success']);
+    }
+}

+ 1 - 1
app/Http/Controllers/Home/Blog/ArticleController.php

@@ -16,7 +16,7 @@ class ArticleController extends CommonController
     //
     public function index(Request $request)
     {
-        $size = 20;
+        $size = 15;
         $data = Article::with('category:id,cate_name')
             ->select( 'cate_id', 'slug', 'title', 'read_count', 'created_at', 'is_top', 'description')
             ->orderByDesc('is_top')->orderByDesc('created_at');

+ 13 - 0
app/Models/Index/Switches.php

@@ -0,0 +1,13 @@
+<?php
+
+namespace App\Models\Index;
+
+use App\Models\Base\BaseModel;
+
+class Switches extends BaseModel
+{
+    //
+    protected $table = 'switch';
+//    protected $fillable = ['article_id', 'tag_id'];
+//    public $timestamps = false;
+}

+ 68 - 3
app/Providers/InitServiceProvider.php

@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use App\Models\Index\Information;
+use App\Models\Index\Switches;
 use Illuminate\Support\ServiceProvider;
 
 class InitServiceProvider extends ServiceProvider
@@ -26,11 +27,10 @@ class InitServiceProvider extends ServiceProvider
     {
         //
         $information = Information::query()
-            ->select( 'site_title', 'site_keywords', 'site_description', 'author_name', 'author_intro', 'author_avatar', 'navigation')
+            ->select('site_title', 'site_keywords', 'site_description', 'author_name', 'author_intro', 'author_avatar', 'navigation')
             ->first();
 
 
-
         if ($information) {
             $blog = [
                 "name" => $information->site_title,
@@ -49,9 +49,74 @@ class InitServiceProvider extends ServiceProvider
             $this->app->get('config')->set('vienblog.author', $author);
         }
 
+        $switches = Switches::query()
+            ->select('name', 'status', 'extra')
+            ->get()->all();
+
+        if ($switches) {
+            $dict = array();
 
-//        $article = $article->toArray();
+            foreach ($switches as $switch) {
+                $extra = json_decode($switch['extra'], true);
+                $dict[$switch['name']] = array('status' => intval($switch['status']) == 1,
+                    'extra' => is_null($extra) ? [] : $extra);
+            }
 
+            $sidebar = [
+                "carousel" => [
+                    "open" => $dict['carousel']['status'], // 是(true)否(false)开启 默认true 开启务必设置banners
+                    "banners" => $dict['carousel']['extra']
+                ],
+                "motto" => [ // 座右铭
+                    "open" => $dict['motto']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['motto']['extra']['title'], // 标题
+                    "content" => $dict['motto']['extra']['content'] // 内容
+                ],
+                "tag" => [ // 标签
+                    "open" => $dict['tag']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['tag']['extra']['title'], // 标题
+                    "count" => intval($dict['tag']['extra']['count']), // 展示数量
+                ],
+                "category" => [ // 分类
+                    "open" => $dict['category']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['category']['extra']['title'], // 标题
+                    "count" => intval($dict['category']['extra']['count']), // 展示数量
+                ],
+                "hot" => [ // 最热文章
+                    "open" => $dict['hot']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['hot']['extra']['title'], // 标题
+                    "count" => intval($dict['hot']['extra']['count']), // 展示数量
+                ],
+                "latest" => [ // 最新文章
+                    "open" => $dict['latest']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['latest']['extra']['title'], // 标题
+                    "count" => intval($dict['latest']['extra']['count']), // 展示数量
+                ],
+                "popular" => [ // 刚有人看的文章
+                    "open" => $dict['popular']['status'], // 是(true)否(false)开启 默认true,
+                    "title" => $dict['popular']['extra']['title'], // 标题
+                    "count" => intval($dict['popular']['extra']['count']), // 展示数量
+                ],
+            ];
+
+            $adsense_script = $dict['adsense']['extra'];
+            $adsense = [
+                "open" => $dict['adsense']['status'], // Google AdSense Auto AD 开关 默认关闭 开启需要在后台中添加 AdSense代码
+                "script" => array_key_exists('script', $adsense_script) ? $adsense_script['script'] : ""
+            ];
+            $counter_script = $dict['counter']['extra'];
+            $counter = [
+                "open" => $dict['counter']['status'], // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
+                "script" => array_key_exists('script', $counter_script) ? $counter_script['script'] : ""
+            ];
+
+            $this->app->get('config')->set('vienblog.sidebar', $sidebar);
+            $this->app->get('config')->set('vienblog.ad', $adsense);
+            $this->app->get('config')->set('vienblog.counter', $counter);
+            $this->app->get('config')->set('vienblog.baidu.auto_push', $dict['baidu_autopush']['status']);
+
+//            dump($this->app->get('config')->get('vienblog'));
+        }
 
     }
 }

+ 1 - 1
config/vienblog.php

@@ -130,7 +130,7 @@ return [
     "counter" => [
         "open" => false, // 统计工具(例如百度统计、StatCounter等) 开关 默认关闭 开启需要在后台中添加相关代码
         "script" => ""
-        ],
+    ],
     "baidu" => [ // 提交站内链接给百度 请先登录百度站长平台验证站长身份 从而获得相应的信息用于下面配置
         "auto_push" => false, // 百度自动推送 开关 默认关闭 用于自动提交页面链接给百度收录
         "manual_push" => [ // 主动推送

+ 2 - 2
database/seeds/SiteSwitchSeeder.php

@@ -15,14 +15,14 @@ class SiteSwitchSeeder extends Seeder
         DB::table('switch')->insert([
             'name' => 'adsense',
             'status' => 0,
-            'extra' => '',
+            'extra' => '{"script": ""}',
             'created_at' => 1553745930,
             'updated_at' => 1553745930,
         ]);
         DB::table('switch')->insert([
             'name' => "counter",
             'status' => 0,
-            'extra' => '',
+            'extra' => '{"script": ""}',
             'created_at' => 1553745930,
             'updated_at' => 1553745930,
         ]);

+ 1 - 1
resources/views/admin/info/edit.blade.php

@@ -4,7 +4,7 @@
     <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
         @include('admin.layouts.alert')
         <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
-            <h2 class="h2">管理员信息</h2>
+            <h2 class="h2">网站信息</h2>
             <div class="btn-toolbar mb-2 mb-md-0">
                 <button type="submit" class="btn btn-sm btn-primary mr-1"
                         onclick="event.preventDefault();document.getElementById('edit-form').submit();">

+ 10 - 1
resources/views/admin/layouts/menu.blade.php

@@ -33,7 +33,16 @@
                 <a class="nav-link" href="{{ route('admin.info.edit', '1') }}">
                     {{--<span data-feather="users"></span>--}}
                     {{--<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>--}}
-                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>                    网站信息
+                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-settings"><circle cx="12" cy="12" r="3"></circle><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"></path></svg>
+                    网站信息
+                </a>
+            </li>
+            <li class="nav-item">
+                <a class="nav-link" href="{{ route('admin.switch.edit', '1') }}">
+                    {{--<span data-feather="users"></span>--}}
+                    {{--<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>--}}
+                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-toggle-left"><rect x="1" y="5" width="22" height="14" rx="7" ry="7"></rect><circle cx="8" cy="12" r="3"></circle></svg>
+                    其他设置
                 </a>
             </li>
         </ul>

+ 264 - 0
resources/views/admin/switch/edit.blade.php

@@ -0,0 +1,264 @@
+@extends('admin.layouts.app')
+
+@section('content')
+    <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
+        @include('admin.layouts.alert')
+        <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
+            <h2 class="h2">设置</h2>
+            <div class="btn-toolbar mb-2 mb-md-0">
+                <button type="submit" class="btn btn-sm btn-primary mr-1"
+                        onclick="event.preventDefault();document.getElementById('edit-form').submit();">
+                    提交
+                </button>
+            </div>
+        </div>
+
+        {{--<canvas class="my-4" id="myChart" width="900" height="380"></canvas>--}}
+        <form action="{{ route('admin.switch.update') }}" id="edit-form" method="post">
+            @csrf
+            <h3>Carousel</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['carousel']['open'] == 1 ? "checked" : "" }}
+                           id="carousel-switch" name="carousel-switch">
+                    <label class="custom-control-label" for="carousel-switch">开关</label>
+                </div>
+
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-3">
+                    <label for="carousel-image-1">图片地址1</label>
+                    <input type="text" class="form-control" id="carousel-image-1" name="carousel-image-1"
+                           value="{{ $switches['sidebar']['carousel']['banners'][0]['image'] }}" required>
+
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-1">跳转链接1</label>
+                    <input type="text" class="form-control" id="carousel-url-1" name="carousel-url-1"
+                           value="{{ $switches['sidebar']['carousel']['banners'][0]['url'] }}" required/>
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-1">相关描述1</label>
+                    <input type="text" class="form-control" id="carousel-description-1" name="carousel-description-1"
+                           value="{{ $switches['sidebar']['carousel']['banners'][0]['description'] }}" required/>
+                </div>
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-3">
+                    <label for="carousel-image-2">图片地址2</label>
+                    <input type="text" class="form-control" id="carousel-image-2" name="carousel-image-2"
+                           value="{{ $switches['sidebar']['carousel']['banners'][1]['image'] }}" required>
+
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-2">跳转链接2</label>
+                    <input type="text" class="form-control" id="carousel-url-2" name="carousel-url-2"
+                           value="{{ $switches['sidebar']['carousel']['banners'][1]['url'] }}" required/>
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-2">相关描述2</label>
+                    <input type="text" class="form-control" id="carousel-description-2" name="carousel-description-2"
+                           value="{{ $switches['sidebar']['carousel']['banners'][1]['description'] }}" required/>
+                </div>
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-3">
+                    <label for="carousel-image-3">图片地址3</label>
+                    <input type="text" class="form-control" id="carousel-image-3" name="carousel-image-3"
+                           value="{{ $switches['sidebar']['carousel']['banners'][2]['image'] }}" required>
+
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-3">跳转链接3</label>
+                    <input type="text" class="form-control" id="carousel-url-3" name="carousel-url-3"
+                           value="{{ $switches['sidebar']['carousel']['banners'][2]['url'] }}" required/>
+                </div>
+                <div class="form-group col-md-3">
+                    <label for="carousel-url-3">相关描述3</label>
+                    <input type="text" class="form-control" id="carousel-description-3" name="carousel-description-3"
+                           value="{{ $switches['sidebar']['carousel']['banners'][2]['description'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Motto</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['motto']['open'] == 1 ? "checked" : "" }}
+                           id="motto-switch" name="motto-switch">
+                    <label class="custom-control-label" for="motto-switch">开关</label>
+                </div>
+
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="motto-title">标题</label>
+                    <input type="text" class="form-control" id="motto-title" name="motto-title"
+                           value="{{ $switches['sidebar']['motto']['title'] }}" required>
+
+                </div>
+                <div class="form-group col-md-4">
+                    <label for="motto-content">内容</label>
+                    <input type="text" class="form-control" id="motto-content" name="motto-content"
+                           value="{{ $switches['sidebar']['motto']['content'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Tag</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['tag']['open'] == 1 ? "checked" : "" }}
+                           id="tag-switch" name="tag-switch">
+                    <label class="custom-control-label" for="tag-switch">开关</label>
+                </div>
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="tag-title">标题</label>
+                    <input type="text" class="form-control" id="tag-title" name="tag-title"
+                           value="{{ $switches['sidebar']['tag']['title'] }}" required>
+                </div>
+                <div class="form-group col-md-1">
+                    <label for="tag-count">数量</label>
+                    <input type="text" class="form-control" id="tag-count" name="tag-count"
+                           value="{{ $switches['sidebar']['tag']['count'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Category</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['category']['open'] == 1 ? "checked" : "" }}
+                           id="category-switch" name="category-switch">
+                    <label class="custom-control-label" for="category-switch">开关</label>
+                </div>
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="category-title">标题</label>
+                    <input type="text" class="form-control" id="category-title" name="category-title"
+                           value="{{ $switches['sidebar']['category']['title'] }}" required>
+                </div>
+                <div class="form-group col-md-1">
+                    <label for="category-count">数量</label>
+                    <input type="text" class="form-control" id="category-count" name="category-count"
+                           value="{{ $switches['sidebar']['category']['count'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Hot</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['hot']['open'] == 1 ? "checked" : "" }}
+                           id="hot-switch" name="hot-switch">
+                    <label class="custom-control-label" for="hot-switch">开关</label>
+                </div>
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="hot-title">标题</label>
+                    <input type="text" class="form-control" id="hot-title" name="hot-title"
+                           value="{{ $switches['sidebar']['hot']['title'] }}" required>
+                </div>
+                <div class="form-group col-md-1">
+                    <label for="hot-count">数量</label>
+                    <input type="text" class="form-control" id="hot-count" name="hot-count"
+                           value="{{ $switches['sidebar']['hot']['count'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Latest</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['latest']['open'] == 1 ? "checked" : "" }}
+                           id="latest-switch" name="latest-switch">
+                    <label class="custom-control-label" for="latest-switch">开关</label>
+                </div>
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="latest-title">标题</label>
+                    <input type="text" class="form-control" id="latest-title" name="latest-title"
+                           value="{{ $switches['sidebar']['latest']['title'] }}" required>
+                </div>
+                <div class="form-group col-md-1">
+                    <label for="latest-count">数量</label>
+                    <input type="text" class="form-control" id="latest-count" name="latest-count"
+                           value="{{ $switches['sidebar']['latest']['count'] }}" required/>
+                </div>
+            </div>
+
+            <h3>Popular</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['sidebar']['popular']['open'] == 1 ? "checked" : "" }}
+                           id="popular-switch" name="popular-switch">
+                    <label class="custom-control-label" for="popular-switch">开关</label>
+                </div>
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-4">
+                    <label for="popular-title">标题</label>
+                    <input type="text" class="form-control" id="popular-title" name="popular-title"
+                           value="{{ $switches['sidebar']['popular']['title'] }}" required>
+                </div>
+                <div class="form-group col-md-1">
+                    <label for="popular-count">数量</label>
+                    <input type="text" class="form-control" id="popular-count" name="popular-count"
+                           value="{{ $switches['sidebar']['popular']['count'] }}" required/>
+                </div>
+            </div>
+
+            <h3>AdSense</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['adsense']['open'] == 1 ? "checked" : "" }}
+                           id="adsense-switch" name="adsense-switch">
+                    <label class="custom-control-label" for="adsense-switch">开关</label>
+                </div>
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-6">
+                    <label for="adsense-script">谷歌AdSense代码</label>
+                    <textarea class="form-control" id="adsense-script" name="adsense-script"
+                              placeholder="谷歌AdSense代码" rows="5">
+                            {{ $switches['adsense']['script'] }}
+                        </textarea>
+                </div>
+            </div>
+
+            <h3>Counter</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $switches['counter']['open'] == 1 ? "checked" : "" }}
+                           id="counter-switch" name="counter-switch">
+                    <label class="custom-control-label" for="counter-switch">开关</label>
+                </div>
+            </div>
+            <div class="form-row">
+                <div class="form-group col-md-6">
+                    <label for="counter-script">流量统计代码</label>
+                    <textarea class="form-control" id="counter-script" name="counter-script"
+                              placeholder="流量统计代码" rows="5">
+                            {{ $switches['counter']['script'] }}
+                        </textarea>
+                </div>
+            </div>
+
+            <button type="submit" class="mt-2 ml-3 btn btn-sm btn-primary">提交</button>
+        </form>
+    </main>
+@endsection

+ 6 - 6
resources/views/home/layouts/app.blade.php

@@ -35,9 +35,9 @@
     @show
     @section('css_ext')@show
     @section('ads')
-        @if(env('APP_DEBUG') == false and config('vienblog.ad.open') == true)
+        @if(!env('APP_DEBUG') and config('vienblog.ad.open'))
             {{--@include('ads.adsense')--}}
-            {{ config('vienblog.ad.script') }}
+            {!! config('vienblog.ad.script') !!}
         @endif
     @show
 
@@ -47,9 +47,9 @@
 @yield('content')
 
 @section('counter')
-    @if(env('APP_DEBUG') == false and config('vienblog.counter.open') == true)
-{{--        @include('counters.counter')--}}
-        {{ config('vienblog.counter.script') }}
+    @if(!env('APP_DEBUG') and config('vienblog.counter.open'))
+        {{--        @include('counters.counter')--}}
+        {!! config('vienblog.counter.script') !!}
     @endif
 @show
 
@@ -70,7 +70,7 @@
 @show
 @section('js_ext')
 @show
-@if(env('APP_DEBUG') == false and config('vienblog.baidu.auto_push') == true)
+@if(!env('APP_DEBUG') and config('vienblog.baidu.auto_push'))
     <script>
         (function () {
             var bp = document.createElement('script');

+ 2 - 0
routes/web.php

@@ -51,6 +51,8 @@ Route::group(['prefix' => 'admin', ], function () {
 
         Route::get('/info/{id}', 'Admin\Index\InfoController@edit')->name('admin.info.edit');
         Route::post('/info', 'Admin\Index\InfoController@update')->name('admin.info.update');
+        Route::get('/switches', 'Admin\Index\SwitchController@edit')->name('admin.switch.edit');
+        Route::post('/switches', 'Admin\Index\SwitchController@update')->name('admin.switch.update');
     });
 });