Browse Source

theme pink && watermark

Vien 5 years ago
parent
commit
b09884f91f

+ 0 - 3
.env.example

@@ -42,6 +42,3 @@ PUSHER_APP_CLUSTER=mt1
 
 MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
 MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
-
-THEME=gray
-WATERMARK=

+ 4 - 3
README.md

@@ -21,9 +21,10 @@ Github: [laravel-blog](https://github.com/luvvien/laravel-blog) ,欢迎Star。
 
 ## 更新
 
-- 20200405 后台功能添加(网站信息管理) 需要执行 `php artisan migrate` 和 `php artisan db:seed --class=SiteInfoSeeder`
-- 20200418 后台功能添加(网站设置,添加开关和统计代码等后台管理)需要执行 `php artisan migrate` 和 `php artisan db:seed --class=SiteSwitchSeeder`
-- 20200429 后台功能添加(图片上传功能) 需要执行 `php artisan migrate`
+- 20200520 功能添加(图片自动水印),添加粉色主题 更新后需要执行 `php artisan migrate` 和 `php artisan db:seed --class=SettingSeeder`
+- 20200429 后台功能添加(图片上传功能) 更新后需要执行 `php artisan migrate`
+- 20200418 后台功能添加(网站设置,添加开关和统计代码等后台管理)更新后需要执行 `php artisan migrate` 和 `php artisan db:seed --class=SiteSwitchSeeder`
+- 20200405 后台功能添加(网站信息管理) 更新后需要执行 `php artisan migrate` 和 `php artisan db:seed --class=SiteInfoSeeder`
 
 **注意:如果执行seed提示找不到,请执行`composer dump-autoload`后再执行**
 

+ 59 - 0
app/Http/Controllers/Admin/Index/SettingController.php

@@ -0,0 +1,59 @@
+<?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\Setting;
+use App\Models\Index\Switches;
+use Illuminate\Http\Request;
+use App\Http\Controllers\Controller;
+use Illuminate\Support\Facades\Auth;
+
+class SettingController extends Controller
+{
+    //
+    public function edit(Request $request)
+    {
+        $setting = self::setting();
+        return view('admin.setting.edit', ['setting' => $setting]);
+    }
+
+    public function update(Request $request)
+    {
+        $input = $request->input();
+//
+        $watermark_open = isset($input["watermark-open"]);
+        $watermark_content = $input["watermark-content"];
+        $theme = $input["theme"];
+
+        $setting_arr = [
+            "watermark" => [
+                "open" => $watermark_open,
+                "content" => $watermark_content
+            ],
+            "theme" => $theme
+        ];
+
+        $setting_json = json_encode($setting_arr, JSON_UNESCAPED_UNICODE);
+
+        $setting = Setting::query()->first();
+        $setting->json = $setting_json;
+        $setting->save();
+
+        return view('admin.setting.edit', ['setting' => $setting_arr])->with(['message' => 'success']);
+    }
+
+    private function setting()
+    {
+        $setting = Setting::query()
+            ->select('json')
+            ->first();
+        $setting = json_decode($setting->json, true);
+        return $setting;
+    }
+}

+ 4 - 2
app/Http/Controllers/Admin/Index/UploadController.php

@@ -51,9 +51,11 @@ class UploadController extends Controller
         ) {
             $path = $request->file->store(date('Ymd'), config('vienblog.disks.files'));
             $url = Storage::disk(config('vienblog.disks.files'))->url($path);
-            if (env('WATERMARK', '')) {
+//            if (env('WATERMARK', '')) {
+            if (config('vienblog.setting.watermark.open')) {
                 try {
-                    watermark(public_path($url), public_path($url), env('WATERMARK'));
+//                    watermark(public_path($url), public_path($url), env('WATERMARK'));
+                    watermark(public_path($url), public_path($url), config('vienblog.setting.watermark.content'));
                 }catch (\Exception $e) {}
             }
 //            return response()->json(['filename' => $url]);

+ 2 - 2
app/Http/Controllers/Admin/UploadController.php

@@ -25,9 +25,9 @@ class UploadController extends Controller
             $path = $request->file->store(date('Ymd'), config('vienblog.disks.article_image'));
             $url = Storage::disk(config('vienblog.disks.article_image'))->url($path);
 
-            if (env('WATERMARK', '')) {
+            if (config('vienblog.setting.watermark.open')) {
                 try {
-                    watermark(public_path($url), public_path($url), env('WATERMARK'));
+                    watermark(public_path($url), public_path($url), config('vienblog.setting.watermark.content'));
                 }catch (\Exception $e) {}
             }
 

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

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

+ 7 - 0
app/Providers/InitServiceProvider.php

@@ -3,6 +3,7 @@
 namespace App\Providers;
 
 use App\Models\Index\Information;
+use App\Models\Index\Setting;
 use App\Models\Index\Switches;
 use Illuminate\Support\ServiceProvider;
 
@@ -128,6 +129,12 @@ class InitServiceProvider extends ServiceProvider
                 $this->app->get('config')->set('vienblog.baidu.manual_push', $baidu_push);
 //            dump($this->app->get('config')->get('vienblog'));
             }
+
+            $setting = Setting::query()
+                ->select('json')
+                ->first();
+            $this->app->get('config')->set('vienblog.setting', json_decode($setting->json, true));
+
         } catch (\Exception $e) {
 
         }

+ 7 - 0
config/vienblog.php

@@ -139,5 +139,12 @@ return [
             "domain" => "https://baidu.com", // 主动推送的博客地址
             "api" => "http://data.zz.baidu.com/urls?site=https://baidu.com&token=lLC6nY5KkflD8Pz2" // 主动推送接口调用地址
         ]
+    ],
+    "setting" => [
+        "watermark" => [
+            "open"=> false,
+            "content" => "VienBlog.com"
+        ],
+        "theme" => "gray" // pink
     ]
 ];

+ 34 - 0
database/migrations/2020_05_20_091222_create_setting_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateSettingTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('setting', function (Blueprint $table) {
+            $table->increments('id');
+            $table->longText('json')->nullable()->comment('setting');
+            $table->integer('updated_at');
+            $table->integer('created_at');
+            $table->integer('deleted_at')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('setting');
+    }
+}

+ 1 - 0
database/seeds/DatabaseSeeder.php

@@ -15,5 +15,6 @@ class DatabaseSeeder extends Seeder
          $this->call(FriendLinkTableSeeder::class);
          $this->call(SiteInfoSeeder::class);
          $this->call(SiteSwitchSeeder::class);
+         $this->call(SettingSeeder::class);
     }
 }

+ 29 - 0
database/seeds/SettingSeeder.php

@@ -0,0 +1,29 @@
+<?php
+
+use Illuminate\Database\Seeder;
+
+class SettingSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        //
+        $setting = [
+            "watermark" => [
+                "open" => false,
+                "content" => "VienBlog.com"
+            ],
+            "theme" => "gray"
+        ];
+        DB::table('setting')->insert([
+            'json' => json_encode($setting, JSON_UNESCAPED_UNICODE),
+            'created_at' => 1553745930,
+            'updated_at' => 1553745930,
+        ]);
+
+    }
+}

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

@@ -38,7 +38,15 @@
                 </a>
             </li>
             <li class="nav-item">
-                <a class="nav-link" href="{{ route('admin.switch.edit', '1') }}">
+                <a class="nav-link" href="{{ route('admin.setting.edit') }}">
+                    {{--<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-command"><path d="M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"></path></svg>
+                    更多功能
+                </a>
+            </li>
+            <li class="nav-item">
+                <a class="nav-link" href="{{ route('admin.switch.edit') }}">
                     {{--<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>

+ 52 - 0
resources/views/admin/setting/edit.blade.php

@@ -0,0 +1,52 @@
+@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.setting.update') }}" id="edit-form" method="post">
+            @csrf
+            <h3>Watermark</h3>
+            <div class="form-group">
+                <div class="custom-control custom-switch">
+                    <input type="checkbox" class="custom-control-input"
+                           {{ $setting['watermark']['open'] == 1 ? "checked" : "" }}
+                           id="watermark-open" name="watermark-open">
+                    <label class="custom-control-label" for="watermark-open">开关</label>
+                </div>
+
+            </div>
+
+            <div class="form-row">
+                <div class="form-group col-md-6">
+                    <label for="watermark-content">水印内容</label>
+                    <input class="form-control" id="watermark-content" name="watermark-content" value="{{  $setting['watermark']['content'] }}"/>
+                </div>
+            </div>
+
+            <h3>Theme</h3>
+            <div class="form-row">
+                <div class="form-group col-md-6">
+                    <label for="theme">主题颜色</label>
+                    {{--<input class="form-control" id="theme" name="theme" value="{{ $setting['theme'] }}"/>--}}
+                    <select class="custom-select mr-sm-2" id="theme" name="theme">
+                        <option value="gray" {{ $setting['theme'] == "gray" ? "selected" : "" }}>gray</option>
+                        <option value="pink" {{ $setting['theme'] == "pink" ? "selected" : "" }}>pink</option>
+                    </select>
+                </div>
+            </div>
+
+            <button type="submit" class="mt-2 ml-3 btn btn-sm btn-primary">提交</button>
+        </form>
+    </main>
+@endsection

+ 2 - 1
resources/views/home/layouts/app.blade.php

@@ -32,7 +32,8 @@
     {{--    <link href="{{ asset('css/base.css') }}" rel="stylesheet">--}}
     @section('css')
         <link href="{{ mix('/css/web.css') }}" rel="stylesheet" type="text/css"/>
-        <link href="{{ mix('/css/'.env('THEME', 'gray').'.css') }}" rel="stylesheet" type="text/css"/>
+{{--        <link href="{{ mix('/css/'.env('THEME', 'gray').'.css') }}" rel="stylesheet" type="text/css"/>--}}
+        <link href="{{ mix('/css/'.config('vienblog.setting.theme').'.css') }}" rel="stylesheet" type="text/css"/>
     @show
     @section('css_ext')@show
     @section('ads')

+ 2 - 0
routes/web.php

@@ -57,6 +57,8 @@ Route::group(['prefix' => 'admin', ], function () {
         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');
+        Route::get('/settings', 'Admin\Index\SettingController@edit')->name('admin.setting.edit');
+        Route::post('/settings', 'Admin\Index\SettingController@update')->name('admin.setting.update');
     });
 });