Skip to content

Commit 12b2e6a

Browse files
committedDec 25, 2022
更新:完成修改评论内容
·
v2.7.7v2.1.7
1 parent 1fc866a commit 12b2e6a

File tree

12 files changed

+365
-95
lines changed

12 files changed

+365
-95
lines changed
 

‎app/Plugins/Comment/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
Itf()->add('create-topic-comment-handle-middleware-end', 0, \App\Plugins\Comment\src\Handler\Middleware\Create\Topic\EndMiddleware::class);
4+
Itf()->add('edit-topic-comment-handle-middleware-end', 0, \App\Plugins\Comment\src\Handler\Middleware\Edit\Topic\EndMiddleware::class);
45

56
Itf()->add('comment-topic-create-editor-external_plugins', 0, [
67
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
@@ -9,7 +10,7 @@
910
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
1011
]);
1112
Itf()->add('comment-topic-create-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
12-
Itf()->add('comment-topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
13+
Itf()->add('comment-topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
1314

1415
Itf()->add('comment-topic-create-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);
1516
Itf()->add('comment-topic-edit-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);

‎app/Plugins/Comment/resources/views/topic/create.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,29 +82,29 @@
8282
let options = {
8383
selector: '#content',
8484
height: 450,
85-
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
86-
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
85+
menu:{!! \App\Plugins\Comment\src\Lib\Create\Editor::menu() !!},
86+
menubar:"{!! \App\Plugins\Comment\src\Lib\Create\Editor::menubar() !!}",
8787
statusbar: true,
8888
elementpath: true,
8989
promotion: false,
90-
plugins: {!! \App\Plugins\Comment\src\Lib\Edit\Editor::plugins() !!},
90+
plugins: {!! \App\Plugins\Comment\src\Lib\Create\Editor::plugins() !!},
9191
language: "zh-Hans",
92-
toolbar: "{!! \App\Plugins\Comment\src\Lib\Edit\Editor::toolbar() !!}",
92+
toolbar: "{!! \App\Plugins\Comment\src\Lib\Create\Editor::toolbar() !!}",
9393
link_default_target: '_blank',
9494
toolbar_mode: 'sliding',
9595
image_advtab: true,
9696
automatic_uploads: true,
9797
convert_urls:false,
98-
external_plugins:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::externalPlugins() !!},
98+
external_plugins:{!! \App\Plugins\Comment\src\Lib\Create\Editor::externalPlugins() !!},
9999
images_upload_handler: image_upload_handler,
100100
init_instance_callback: (editor) => {
101101
@if(request()->has('restoredraft'))
102102
editor.plugins.autosave.restoreDraft()
103103
@endif
104104
},
105105
mobile:{
106-
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
107-
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
106+
menu:{!! \App\Plugins\Comment\src\Lib\Create\Editor::menu() !!},
107+
menubar:"{!! \App\Plugins\Comment\src\Lib\Create\Editor::menubar() !!}",
108108
toolbar_mode: 'scrolling'
109109
},
110110
autosave_ask_before_unload: true,
Lines changed: 103 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,45 @@
11
@extends("App::app")
22

3-
@section('title',"修改id为:".$data->id."的评论")
3+
@section('title',"修改评论")
44

55

66
@section('content')
77

8-
<div class="row justify-content-center">
9-
<div class="col-md-12">
10-
<div class="border-0 card">
8+
<div class="row row-cards justify-content-center">
9+
<div class="col-lg-12">
10+
<ol class="breadcrumb breadcrumb-arrows" aria-label="breadcrumbs">
11+
<li class="breadcrumb-item"><a href="/">首页</a></li>
12+
<li class="breadcrumb-item"><a href="/tags/{{$comment->topic->tag->id}}.html">
13+
{!! $comment->topic->tag->icon !!}
14+
{{$comment->topic->tag->name}}
15+
</a>
16+
</li>
17+
<li class="breadcrumb-item"><a href="/{{$comment->topic->id}}.html">
18+
{{\Hyperf\Utils\Str::limit($comment->topic->title,25)}}
19+
</a>
20+
</li>
21+
<li class="breadcrumb-item"><a href="{{'/' . $comment->topic_id . '.html/' . $comment->id . '?page=' . get_topic_comment_page($comment->id)}}">
22+
ID【{{$comment->id}}】的评论
23+
</a>
24+
</li>
25+
<li class="breadcrumb-item active" aria-current="page"><a href="#">修改评论</a></li>
26+
</ol>
27+
</div>
28+
<div class="col-lg-12">
29+
<div class="card">
1130
<div class="card-header">
12-
<h3 class="card-title"><a class="text-red"
13-
href="/{{$data->topic->id}}.html">{{$data->topic->title}}</a>
14-
下id为{{$data->id}}的评论</h3>
31+
<h3 class="card-title">回帖</h3>
1532
</div>
16-
<div class="card-body" id="vue-comment-topic-edit-form">
17-
<form action="" method="post" @@submit.prevent="submit">
18-
<div class="row">
19-
<div class="mb-3">
20-
<div class="row">
21-
@if(get_options("comment_emoji_close",'false')!=="true" && count((new \App\Plugins\Core\src\Lib\Emoji())->get()))
22-
<div class="col-lg-3">
23-
<div class="card">
24-
<ul class="nav nav-tabs" data-bs-toggle="tabs" style="flex-wrap: inherit;
25-
width: 100%;
26-
height: 3.333333rem;
27-
padding: 0.373333rem 0.32rem 0;
28-
box-sizing: border-box;
29-
/* 下面是实现横向滚动的关键代码 */
30-
display: inline;
31-
float: left;
32-
white-space: nowrap;
33-
overflow-x: scroll;
34-
-webkit-overflow-scrolling: touch; /*解决在ios滑动不顺畅问题*/
35-
overflow-y: hidden;">
36-
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
37-
<li class="nav-item">
38-
<a href="#emoji-list-{{$key}}"
39-
class="nav-link @if ($loop->first) active @endif"
40-
data-bs-toggle="tab">{{$key}}</a>
41-
</li>
42-
@endforeach
43-
</ul>
44-
<div class="card-body">
45-
<div class="tab-content">
46-
@foreach((new \App\Plugins\Core\src\Lib\Emoji())->get() as $key => $value)
47-
<div class="tab-pane @if ($loop->first) active @endif show"
48-
id="emoji-list-{{$key}}"
49-
style="max-height: 220px;overflow-x: hidden;">
50-
<div class="row">
51-
@if($value['type'] === 'image')
52-
@foreach($value['container'] as $emojis)
53-
<div @@click="selectEmoji('{{$emojis['text']}}')"
54-
class="col-3 col-sm-2 col-md-4 col-lg-3 hvr-glow emoji-picker"
55-
emoji-data="{{$emojis['text']}}">{!! $emojis['icon'] !!}</div>
56-
@endforeach
57-
@endif
58-
</div>
59-
</div>
60-
@endforeach
61-
</div>
62-
</div>
63-
</div>
64-
</div>
65-
<div class="col-lg-9">
66-
<div id="vditor"></div>
67-
</div>
68-
@else
69-
<div class="col-md-12">
70-
<div id="vditor"></div>
71-
</div>
72-
@endif
73-
<div class="col-12 mt-3">
74-
<button class="btn btn-primary" style="margin-top: 5px">提交</button>
75-
</div>
76-
</div>
77-
</div>
33+
<div class="card-body">
34+
<form action="/comment/topic/{{$comment->id}}/edit" method="post">
35+
<x-csrf/>
36+
<input type="hidden" name="comment_id" value="{{$comment->id}}">
37+
<div class="mb-3">
38+
<label for="" class="form-label"></label>
39+
<textarea name="content" id="content" rows="3">{!! $comment->post->content !!}</textarea>
40+
</div>
41+
<div class="mb-3 d-flex flex-row-reverse">
42+
<button class="btn btn-primary" type="submit">修改评论</button>
7843
</div>
7944
</form>
8045
</div>
@@ -84,11 +49,74 @@ class="col-3 col-sm-2 col-md-4 col-lg-3 hvr-glow emoji-picker"
8449

8550
@endsection
8651

87-
@section('headers')
88-
<link rel="stylesheet" href="{{ mix('plugins/Topic/css/app.css') }}">
89-
@endsection
9052
@section('scripts')
91-
<script>var comment_id = {{$data->id}}</script>
92-
<script>var topic_id = {{$data->topic_id}}</script>
93-
<script src="{{mix("plugins/Comment/js/edit.js")}}"></script>
53+
<script src="{{file_hash("js/axios.min.js")}}"></script>
54+
<script src="{{file_hash('tabler/libs/tinymce/tinymce.min.js')}}"></script>
55+
<script defer>
56+
const target = document.getElementsByTagName("html")[0]
57+
const body_className = document.getElementsByTagName("html")[0].getAttribute("data-theme");
58+
const observer = new MutationObserver(function (mutations) {
59+
mutations.forEach(function (mutation) {
60+
if (body_className !== document.getElementsByTagName("html")[0].getAttribute("data-theme")) {
61+
location.reload()
62+
}
63+
});
64+
});
65+
66+
observer.observe(target, {attributes: true});
67+
68+
const image_upload_handler = (blobInfo, progress) => new Promise((resolve, reject) => {
69+
const formData = new FormData();
70+
formData.append('file', blobInfo.blob(), blobInfo.filename());
71+
formData.append('_token', csrf_token);
72+
axios.post("/user/upload/image",formData,{
73+
'Content-type' : 'multipart/form-data'
74+
}).then(function(r){
75+
console.log(r)
76+
const data = r.data;
77+
if(data.success){
78+
resolve(data.result.url);
79+
return ;
80+
}
81+
reject({message:'HTTP Error: ' + data.result.msg + ', Error Code: '+data.code,remove: true});
82+
}).catch(function(e){
83+
console.log(e)
84+
})
85+
86+
});
87+
88+
document.addEventListener("DOMContentLoaded", function () {
89+
let options = {
90+
selector: '#content',
91+
height: 450,
92+
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
93+
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
94+
statusbar: true,
95+
elementpath: true,
96+
promotion: false,
97+
plugins: {!! \App\Plugins\Comment\src\Lib\Edit\Editor::plugins() !!},
98+
language: "zh-Hans",
99+
toolbar: "{!! \App\Plugins\Comment\src\Lib\Edit\Editor::toolbar() !!}",
100+
link_default_target: '_blank',
101+
toolbar_mode: 'sliding',
102+
image_advtab: true,
103+
automatic_uploads: true,
104+
convert_urls:false,
105+
external_plugins:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::externalPlugins() !!},
106+
images_upload_handler: image_upload_handler,
107+
mobile:{
108+
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
109+
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
110+
toolbar_mode: 'scrolling'
111+
},
112+
branding:false,
113+
content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }'
114+
}
115+
if (document.body.className === 'theme-dark') {
116+
options.skin = 'oxide-dark';
117+
options.content_css = 'dark';
118+
}
119+
tinyMCE.init(options);
120+
});
121+
</script>
94122
@endsection

‎app/Plugins/Comment/src/Controller/IndexController.php renamed to ‎app/Plugins/Comment/src/Controller/EditTopicCommentController.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
*/
1111
namespace App\Plugins\Comment\src\Controller;
1212

13+
use App\Plugins\Comment\src\Handler\EditTopicComment;
1314
use App\Plugins\Comment\src\Model\TopicComment;
1415
use Hyperf\HttpServer\Annotation\Controller;
1516
use Hyperf\HttpServer\Annotation\GetMapping;
17+
use Hyperf\HttpServer\Annotation\PostMapping;
1618

1719
#[Controller(prefix: '/comment')]
18-
class IndexController
20+
class EditTopicCommentController
1921
{
2022
#[GetMapping(path: 'topic/{id}/edit')]
21-
public function edit_topic_comment($id)
23+
public function index($id)
2224
{
2325
if (! TopicComment::query()->where('id', $id)->exists()) {
2426
return admin_abort('id为:' . $id . '的评论不存在', 404);
2527
}
26-
$data = TopicComment::query()->where('id', $id)->first();
28+
$data = TopicComment::query()->find($id);
2729
$quanxian = false;
2830
if (Authority()->check('admin_topic_edit') && curd()->GetUserClass(auth()->data()->class_id)['permission-value'] > curd()->GetUserClass($data->user->class_id)['permission-value']) {
2931
$quanxian = true;
@@ -34,6 +36,13 @@ public function edit_topic_comment($id)
3436
if ($quanxian === false) {
3537
return admin_abort('无权操作!', 419);
3638
}
37-
return view('Comment::topic.edit', ['data' => $data]);
39+
return view('Comment::topic.edit', ['comment' => $data]);
40+
}
41+
42+
#[PostMapping(path: 'topic/{id}/edit')]
43+
public function update($id)
44+
{
45+
46+
return (new EditTopicComment())->handler($id);
3847
}
3948
}

‎app/Plugins/Comment/src/Handler/CreateTopicComment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CreateTopicComment
2020
public function handler($topic_id)
2121
{
2222
$request = request()->all();
23-
$request[$topic_id] = $topic_id;
23+
$request['topic_id'] = $topic_id;
2424
$handler = function ($request) {
2525
return $request;
2626
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Comment\src\Handler;
12+
13+
use App\Plugins\Comment\src\Annotation\Topic\UpdateFirstMiddleware;
14+
use App\Plugins\Comment\src\Annotation\Topic\UpdateLastMiddleware;
15+
use App\Plugins\Comment\src\Annotation\Topic\UpdateMiddleware;
16+
use Hyperf\Di\Annotation\AnnotationCollector;
17+
18+
class EditTopicComment
19+
{
20+
public function handler($comment_id)
21+
{
22+
$request = request()->all();
23+
$request['comment_id'] = $comment_id;
24+
$handler = function ($request) {
25+
return $request;
26+
};
27+
28+
// 通过中间件
29+
$run = $this->throughMiddleware($handler, $this->middlewares());
30+
return $run($request);
31+
}
32+
33+
/**
34+
* 通过中间件 through the middleware.
35+
* @param $handler
36+
* @param $stack
37+
* @return \Closure|mixed
38+
*/
39+
protected function throughMiddleware($handler, $stack)
40+
{
41+
// 闭包实现中间件功能 closures implement middleware functions
42+
foreach ($stack as $middleware) {
43+
$handler = function ($request) use ($handler, $middleware) {
44+
if ($middleware instanceof \Closure) {
45+
return call_user_func($middleware, $request, $handler);
46+
}
47+
48+
return call_user_func([new $middleware(), 'handler'], $request, $handler);
49+
};
50+
}
51+
return $handler;
52+
}
53+
54+
private function middlewares(): array
55+
{
56+
$middlewares = [];
57+
foreach (AnnotationCollector::getClassesByAnnotation(UpdateFirstMiddleware::class) as $key => $value) {
58+
$middlewares[] = $key;
59+
}
60+
foreach (AnnotationCollector::getClassesByAnnotation(UpdateMiddleware::class) as $key => $value) {
61+
$middlewares[] = $key;
62+
}
63+
foreach (AnnotationCollector::getClassesByAnnotation(UpdateLastMiddleware::class) as $key => $value) {
64+
$middlewares[] = $key;
65+
}
66+
$endMiddlewares = Itf()->get('edit-topic-comment-handle-middleware-end');
67+
krsort($endMiddlewares);
68+
foreach ($endMiddlewares as $value) {
69+
$middlewares[] = $value;
70+
}
71+
return array_reverse($middlewares);
72+
}
73+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Comment\src\Handler\Middleware\Edit\Topic;
12+
13+
use App\Plugins\Comment\src\Model\TopicComment;
14+
use App\Plugins\Core\src\Models\Post;
15+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
16+
use Hyperf\Di\Annotation\Inject;
17+
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
18+
19+
#[\App\Plugins\Comment\src\Annotation\Topic\UpdateMiddleware]
20+
class EditMiddleware implements MiddlewareInterface
21+
{
22+
/**
23+
* @Inject
24+
*/
25+
protected ValidatorFactoryInterface $validationFactory;
26+
27+
public function handler($data, \Closure $next)
28+
{
29+
$validator = $this->validationFactory->make(
30+
$data,
31+
[
32+
'comment_id' => 'required|exists:topic_comment,id',
33+
'content' => 'required|string|min:' . get_options('comment_create_min', 1) . '|max:' . get_options('comment_create_max', 200),
34+
],
35+
[],
36+
[
37+
'comment_id' => '评论ID',
38+
'content' => '评论内容',
39+
]
40+
);
41+
42+
if ($validator->fails()) {
43+
// Handle exception
44+
return redirect()->back()->with('danger', $validator->errors()->first())->go();
45+
}
46+
47+
$comment = TopicComment::query()->find($data['comment_id']);
48+
$quanxian = false;
49+
if (Authority()->check('admin_comment_edit') && auth()->Class()['permission-value'] > curd()->GetUserClass($comment->user->class_id)['permission-value']) {
50+
$quanxian = true;
51+
}
52+
if (Authority()->check('comment_edit') && auth()->id() === $comment->user->id) {
53+
$quanxian = true;
54+
}
55+
if ($quanxian === false) {
56+
return redirect()->back()->with('danger', '无权修改!')->go();
57+
}
58+
59+
if (@$comment->topic->post->options->disable_comment) {
60+
return redirect()->back()->with('danger', '此帖子关闭了评论功能')->go();
61+
}
62+
$data = $this->update($data);
63+
return $next($data);
64+
}
65+
66+
public function update($data)
67+
{
68+
// 过滤xss
69+
$content = xss()->clean($data['content']);
70+
71+
// 解析艾特
72+
$content = replace_all_at($content);
73+
$post_id = TopicComment::query()->find($data['comment_id'])->post_id;
74+
Post::query()->where('id', $post_id)->update([
75+
'content' => $content,
76+
]);
77+
return $data;
78+
}
79+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Comment\src\Handler\Middleware\Edit\Topic;
12+
13+
use App\Plugins\Comment\src\Model\TopicComment;
14+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
15+
16+
class EndMiddleware implements MiddlewareInterface
17+
{
18+
public function handler($data, \Closure $next)
19+
{
20+
$topic_id = TopicComment::query()->find($data['comment_id'])->topic_id;
21+
return redirect()->url('/' . $topic_id . '.html/' . $data['comment_id'] . '?page=' . get_topic_comment_page((int)$data['comment_id']))->with('success', '发表成功!')->go();
22+
}
23+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Comment\src\Handler\Middleware\Edit\Topic;
12+
13+
use App\Plugins\Comment\src\Annotation\Topic\UpdateFirstMiddleware;
14+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
15+
16+
#[UpdateFirstMiddleware]
17+
class FirstMiddleware implements MiddlewareInterface
18+
{
19+
public function handler($data, \Closure $next)
20+
{
21+
if (! auth()->check()) {
22+
return redirect()->back()->with('danger', '未登陆')->go();
23+
}
24+
return $next($data);
25+
}
26+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
11+
namespace App\Plugins\Comment\src\Handler\Middleware\Edit\Topic;
12+
13+
use App\Plugins\Comment\src\Annotation\Topic\UpdateLastMiddleware;
14+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
15+
16+
#[UpdateLastMiddleware]
17+
class LastMiddleware implements MiddlewareInterface
18+
{
19+
public function handler($data, \Closure $next)
20+
{
21+
return $next($data);
22+
}
23+
}

‎app/Plugins/Comment/src/Request/Topic/UpdateComment.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
<?php
22

3+
declare(strict_types=1);
4+
/**
5+
* This file is part of zhuchunshu.
6+
* @link https://github.com/zhuchunshu
7+
* @document https://github.com/zhuchunshu/super-forum
8+
* @contact laravel@88.com
9+
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
10+
*/
311
namespace App\Plugins\Comment\src\Request\Topic;
412

513
use Hyperf\Validation\Request\FormRequest;
@@ -14,19 +22,19 @@ public function authorize(): bool
1422
return true;
1523
}
1624

17-
public function rules():array
25+
public function rules(): array
1826
{
1927
return [
20-
"comment_id" => "required|exists:topic_comment,id",
21-
"content" => "required|string|min:".get_options("comment_reply_min",1)."|max:".get_options("comment_reply_max",200),
28+
'comment_id' => 'required|exists:topic_comment,id',
29+
'content' => 'required|string|min:' . get_options('comment_reply_min', 1) . '|max:' . get_options('comment_reply_max', 200),
2230
];
2331
}
2432

2533
public function attributes(): array
2634
{
2735
return [
28-
"comment_id" => "评论ID",
29-
"content" => __("topic.comment.comment content"),
36+
'comment_id' => '评论ID',
37+
'content' => __('topic.comment.comment content'),
3038
];
3139
}
32-
}
40+
}

‎app/Plugins/Topic/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
// topic create - editor plugins
107107

108108
Itf()->add('topic-create-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
109-
Itf()->add('topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
109+
Itf()->add('topic-edit-editor-plugins', 0, ['importcss', 'searchreplace', 'autolink', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
110110

111111
Itf()->add('topic-create-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);
112112
Itf()->add('topic-edit-editor-toolbar', 0, ['undo', 'redo', '|', 'blocks', '|', 'bold', 'italic', 'underline', 'strikethrough', '|', 'alignleft', 'aligncenter', 'alignright', 'alignjustify', 'outdent', 'indent', 'numlist', 'bullist', '|', 'forecolor', 'backcolor', 'removeformat', 'insertfile', 'image', 'media', 'link', 'sfPreview', 'restoredraft', 'codesample', '|', 'ltr', 'rtl']);

0 commit comments

Comments
 (0)
Please sign in to comment.