Skip to content

Commit 1fc866a

Browse files
committedDec 25, 2022
更新:优化发帖,完成高级评论
·
v2.7.7v2.1.7
1 parent 24c4cf4 commit 1fc866a

File tree

15 files changed

+634
-26
lines changed

15 files changed

+634
-26
lines changed
 

‎app/Plugins/Comment/bootstrap.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,139 @@
11
<?php
22

33
Itf()->add('create-topic-comment-handle-middleware-end', 0, \App\Plugins\Comment\src\Handler\Middleware\Create\Topic\EndMiddleware::class);
4+
5+
Itf()->add('comment-topic-create-editor-external_plugins', 0, [
6+
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
7+
]);
8+
Itf()->add('comment-topic-edit-editor-external_plugins', 0, [
9+
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
10+
]);
11+
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+
14+
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']);
15+
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']);
16+
17+
18+
$editor_menu =[
19+
'file' => [
20+
'title' => 'File',
21+
'items' => [
22+
'newdocument',
23+
'restoredraft',
24+
'|',
25+
'sfPreview',
26+
'export',
27+
'|',
28+
'deleteallconversations',
29+
],
30+
],
31+
'edit' => [
32+
'title' => 'Edit',
33+
'items' => [
34+
'undo',
35+
'redo',
36+
'|',
37+
'cut',
38+
'copy',
39+
'paste',
40+
'pastetext',
41+
'|',
42+
'selectall',
43+
'|',
44+
'searchreplace',
45+
],
46+
],
47+
'view' => [
48+
'title' => 'View',
49+
'items' => [
50+
'code',
51+
'|',
52+
'visualaid',
53+
'visualchars',
54+
'visualblocks',
55+
'|',
56+
'spellchecker',
57+
'|',
58+
'preview',
59+
'|',
60+
'showcomments',
61+
],
62+
],
63+
'insert' => [
64+
'title' => 'Insert',
65+
'items' => [
66+
'image',
67+
'link',
68+
'media',
69+
'addcomment',
70+
'pageembed',
71+
'template',
72+
'codesample',
73+
'inserttable',
74+
'|',
75+
'charmap',
76+
'emoticons',
77+
'hr',
78+
'|',
79+
'pagebreak',
80+
'nonbreaking',
81+
'anchor',
82+
'tableofcontents',
83+
],
84+
],
85+
'format' => [
86+
'title' => 'Format',
87+
'items' => [
88+
'bold',
89+
'italic',
90+
'underline',
91+
'strikethrough',
92+
'superscript',
93+
'subscript',
94+
'codeformat',
95+
'|',
96+
'styles',
97+
'blocks',
98+
'fontfamily',
99+
'fontsize',
100+
'align',
101+
'lineheight',
102+
'|',
103+
'forecolor',
104+
'backcolor',
105+
'|',
106+
'language',
107+
'|',
108+
'removeformat',
109+
],
110+
],
111+
'tools' => [
112+
'title' => 'Tools',
113+
'items' => [
114+
'spellchecker',
115+
'spellcheckerlanguage',
116+
'|',
117+
'a11ycheck',
118+
'code',
119+
'wordcount',
120+
],
121+
],
122+
'table' => [
123+
'title' => 'Table',
124+
'items' => [
125+
'inserttable',
126+
'|',
127+
'cell',
128+
'row',
129+
'column',
130+
'|',
131+
'advtablesort',
132+
'|',
133+
'tableprops',
134+
'deletetable',
135+
],
136+
],
137+
];
138+
Itf()->add('comment-topic-create-editor-menu', 0, $editor_menu);
139+
Itf()->add('comment-topic-edit-editor-menu', 0, $editor_menu);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<div class="col-md-12 mb-3">
5656
<x-csrf/>
5757
<input type="hidden" name="topic_id" value="{{$data->id}}">
58-
<textarea name="content" placeholder="说点什么..." class="form-control" data-bs-toggle="autosize" required></textarea>
58+
<textarea name="content" placeholder="说点什么..." class="form-control" data-bs-toggle="autosize" required>{{request()->input('content')}}</textarea>
5959
</div>
6060
<div class="col-12">
6161
<div class="row">
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
@extends('App::app')
2+
@section('title','评论帖子【'.\Hyperf\Utils\Str::limit($topic->title,25).'')
3+
@section('content')
4+
<div class="row row-cards justify-content-center">
5+
<div class="col-lg-12">
6+
<ol class="breadcrumb breadcrumb-arrows" aria-label="breadcrumbs">
7+
<li class="breadcrumb-item"><a href="/">首页</a></li>
8+
<li class="breadcrumb-item"><a href="/tags/{{$topic->tag->id}}.html">
9+
{!! $topic->tag->icon !!}
10+
{{$topic->tag->name}}
11+
</a>
12+
</li>
13+
<li class="breadcrumb-item"><a href="/{{$topic->id}}.html">
14+
{{\Hyperf\Utils\Str::limit($topic->title,25)}}
15+
</a>
16+
</li>
17+
<li class="breadcrumb-item active" aria-current="page"><a href="#">回帖</a></li>
18+
</ol>
19+
</div>
20+
<div class="col-lg-12">
21+
<div class="card">
22+
<div class="card-header">
23+
<h3 class="card-title">回帖</h3>
24+
</div>
25+
<div class="card-body">
26+
<form action="/topic/create/comment/{{$topic->id}}" method="post">
27+
<x-csrf/>
28+
<input type="hidden" name="no_content" value="1">
29+
<input type="hidden" name="topic_id" value="{{$topic->id}}">
30+
<div class="mb-3">
31+
<label for="" class="form-label"></label>
32+
<textarea name="content" id="content" rows="3"></textarea>
33+
</div>
34+
<div class="mb-3 d-flex flex-row-reverse">
35+
<button class="btn btn-primary" type="submit">回帖</button>
36+
</div>
37+
</form>
38+
</div>
39+
</div>
40+
</div>
41+
</div>
42+
@endsection
43+
44+
45+
@section('scripts')
46+
<script src="{{file_hash("js/axios.min.js")}}"></script>
47+
<script src="{{file_hash('tabler/libs/tinymce/tinymce.min.js')}}"></script>
48+
<script defer>
49+
const target = document.getElementsByTagName("html")[0]
50+
const body_className = document.getElementsByTagName("html")[0].getAttribute("data-theme");
51+
const observer = new MutationObserver(function (mutations) {
52+
mutations.forEach(function (mutation) {
53+
if (body_className !== document.getElementsByTagName("html")[0].getAttribute("data-theme")) {
54+
location.reload()
55+
}
56+
});
57+
});
58+
59+
observer.observe(target, {attributes: true});
60+
61+
const image_upload_handler = (blobInfo, progress) => new Promise((resolve, reject) => {
62+
const formData = new FormData();
63+
formData.append('file', blobInfo.blob(), blobInfo.filename());
64+
formData.append('_token', csrf_token);
65+
axios.post("/user/upload/image",formData,{
66+
'Content-type' : 'multipart/form-data'
67+
}).then(function(r){
68+
console.log(r)
69+
const data = r.data;
70+
if(data.success){
71+
resolve(data.result.url);
72+
return ;
73+
}
74+
reject({message:'HTTP Error: ' + data.result.msg + ', Error Code: '+data.code,remove: true});
75+
}).catch(function(e){
76+
console.log(e)
77+
})
78+
79+
});
80+
81+
document.addEventListener("DOMContentLoaded", function () {
82+
let options = {
83+
selector: '#content',
84+
height: 450,
85+
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
86+
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
87+
statusbar: true,
88+
elementpath: true,
89+
promotion: false,
90+
plugins: {!! \App\Plugins\Comment\src\Lib\Edit\Editor::plugins() !!},
91+
language: "zh-Hans",
92+
toolbar: "{!! \App\Plugins\Comment\src\Lib\Edit\Editor::toolbar() !!}",
93+
link_default_target: '_blank',
94+
toolbar_mode: 'sliding',
95+
image_advtab: true,
96+
automatic_uploads: true,
97+
convert_urls:false,
98+
external_plugins:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::externalPlugins() !!},
99+
images_upload_handler: image_upload_handler,
100+
init_instance_callback: (editor) => {
101+
@if(request()->has('restoredraft'))
102+
editor.plugins.autosave.restoreDraft()
103+
@endif
104+
},
105+
mobile:{
106+
menu:{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menu() !!},
107+
menubar:"{!! \App\Plugins\Comment\src\Lib\Edit\Editor::menubar() !!}",
108+
toolbar_mode: 'scrolling'
109+
},
110+
autosave_ask_before_unload: true,
111+
autosave_interval: '1s',
112+
autosave_prefix: '{{config('codefec.app.name')}}-comment-{path}{query}-{id}-',
113+
autosave_restore_when_empty: false,
114+
autosave_retention: '1400m',
115+
branding:false,
116+
content_style: 'body { font-family: -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif; font-size: 14px; -webkit-font-smoothing: antialiased; }'
117+
}
118+
if (document.body.className === 'theme-dark') {
119+
options.skin = 'oxide-dark';
120+
options.content_css = 'dark';
121+
}
122+
tinyMCE.init(options);
123+
});
124+
</script>
125+
@endsection

‎app/Plugins/Comment/src/Controller/CreateTopicCommentController.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,33 @@
1111
namespace App\Plugins\Comment\src\Controller;
1212

1313
use App\Plugins\Comment\src\Handler\CreateTopicComment;
14+
use App\Plugins\Topic\src\Models\Topic;
15+
use App\Plugins\User\src\Middleware\LoginMiddleware;
1416
use Hyperf\HttpServer\Annotation\Controller;
1517
use Hyperf\HttpServer\Annotation\GetMapping;
18+
use Hyperf\HttpServer\Annotation\Middleware;
1619
use Hyperf\HttpServer\Annotation\PostMapping;
1720

1821
#[Controller(prefix: '/topic/create/comment')]
22+
#[Middleware(LoginMiddleware::class)]
1923
class CreateTopicCommentController
2024
{
25+
#[GetMapping(path: '{topic_id}')]
26+
public function index($topic_id)
27+
{
28+
if (! Authority()->check('comment_create')) {
29+
return redirect()->back()->with('danger', '无评论权限')->go();
30+
}
31+
if (! Topic::query()->where(['id' => $topic_id, 'status' => 'publish'])->exists()) {
32+
return redirect()->back()->with('danger', '帖子不存在')->go();
33+
}
34+
$topic = Topic::query()->find($topic_id);
35+
if (@$topic->post->options->disable_comment) {
36+
return redirect()->back()->with('danger', '此帖子关闭了评论功能')->go();
37+
}
38+
return view('Comment::topic.create', ['topic' => $topic]);
39+
}
40+
2141
#[PostMapping(path: '{topic_id}')]
2242
public function store($topic_id)
2343
{

‎app/Plugins/Comment/src/Handler/Middleware/Create/Topic/CreateMiddleware.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,17 @@ public function handler($data, \Closure $next)
4444
if ($validator->fails()) {
4545
// Handle exception
4646
cache()->delete('comment_create_time_' . auth()->id());
47-
return redirect()->url(request()->getHeader('referer')[0] . '?' . http_build_query($data))->with('danger', $validator->errors()->first())->go();
47+
$backUrl = pathinfo(request()->getHeader('referer')[0])['dirname'] . '/' . $data['topic_id'];
48+
$result = [
49+
'content' => $data['no_content'] ?: $data['content'],
50+
'restoredraft' => true,
51+
];
52+
return redirect()->url($backUrl . '?' . http_build_query($result))->with('danger', $validator->errors()->first())->go();
53+
}
54+
$topic = Topic::query()->find($data['topic_id']);
55+
if (@$topic->post->options->disable_comment) {
56+
cache()->delete('comment_create_time_' . auth()->id());
57+
return redirect()->back()->with('danger', '此帖子关闭了评论功能')->go();
4858
}
4959
$data = $this->create($data);
5060
return $next($data);

‎app/Plugins/Comment/src/Handler/Middleware/Create/Topic/EndMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ class EndMiddleware implements MiddlewareInterface
1616
{
1717
public function handler($data, \Closure $next)
1818
{
19-
return redirect()->back()->with('success', '发表成功!')->go();
19+
return redirect()->url('/' . $data['topic_id'] . '.html/' . $data['comment']['id'] . '?page=' . get_topic_comment_page($data['comment']['id']))->with('success', '发表成功!')->go();
2020
}
2121
}

‎app/Plugins/Comment/src/Handler/Middleware/Create/Topic/FirstMiddleware.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ public function handler($data, \Closure $next)
2424
if (! Authority()->check('comment_create')) {
2525
return redirect()->back()->with('danger', '无评论权限')->go();
2626
}
27+
$backUrl = pathinfo(request()->getHeader('referer')[0])['dirname'] . '/' . $data['topic_id'];
28+
$result = [
29+
'content' => @$data['no_content']?:$data['content'],
30+
'restoredraft' => true,
31+
];
2732
if (cache()->has('comment_create_time_' . auth()->id())) {
2833
$time = cache()->get('comment_create_time_' . auth()->id()) - time();
29-
return redirect()->back()->with('danger', '发表评论过于频繁,请 ' . $time . ' 秒后再试')->go();
34+
return redirect()->url($backUrl . '?' . http_build_query($result))->with('danger', '发表评论过于频繁,请 ' . $time . ' 秒后再试')->go();
3035
}
3136
cache()->set('comment_create_time_' . auth()->id(), time() + get_options('comment_create_time', 60), get_options('comment_create_time', 60));
3237
return $next($data);
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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\Lib\Create;
12+
13+
class Editor
14+
{
15+
/**
16+
* 获取编辑器插件列表.
17+
* @return bool|string
18+
* @throws \JsonException
19+
*/
20+
public static function plugins(): bool | string
21+
{
22+
$data = [];
23+
foreach (Itf()->get('comment-topic-create-editor-plugins') as $value) {
24+
foreach ($value as $plugin) {
25+
$data[] = $plugin;
26+
}
27+
}
28+
$data = array_unique($data);
29+
$data = array_values($data);
30+
return json_encode($data, JSON_THROW_ON_ERROR);
31+
}
32+
33+
/**
34+
* 获取编辑器外部插件.
35+
* @return false|string
36+
*/
37+
public static function externalPlugins(): bool | string
38+
{
39+
$data = [];
40+
foreach (Itf()->get('comment-topic-create-editor-external_plugins') as $value) {
41+
foreach ($value as $name => $plugin) {
42+
$data[$name] = $plugin;
43+
}
44+
}
45+
$data = array_unique($data);
46+
return json_encode($data);
47+
}
48+
49+
/**
50+
* 获取编辑器toolbar.
51+
* @return bool|string
52+
*/
53+
public static function toolbar(): bool | string
54+
{
55+
$data = [];
56+
foreach (Itf()->get('comment-topic-create-editor-toolbar') as $value) {
57+
foreach ($value as $toolbar) {
58+
$data[] = $toolbar;
59+
}
60+
}
61+
$data = array_values($data);
62+
$data = implode(' ', $data);
63+
return trim($data);
64+
}
65+
66+
/**
67+
* 获取编辑器menu(菜单).
68+
*/
69+
public static function menu()
70+
{
71+
$data = [];
72+
foreach (Itf()->get('comment-topic-create-editor-menu') as $key => $value) {
73+
foreach ($value as $keys => $menu) {
74+
$data[$keys] = $menu;
75+
}
76+
}
77+
$result = [];
78+
foreach ($data as $key => $value) {
79+
$value['items'] = implode(' ', $value['items']);
80+
$result[$key] = $value;
81+
}
82+
return json_encode($result);
83+
}
84+
85+
/**
86+
* 获取编辑器menubar.
87+
*/
88+
public static function menubar()
89+
{
90+
$data = [];
91+
foreach (Itf()->get('comment-topic-create-editor-menu') as $value) {
92+
foreach ($value as $key => $menu) {
93+
$data[$key] = $menu;
94+
}
95+
}
96+
foreach ($data as $key => $value) {
97+
$result[] = $key;
98+
}
99+
$result = array_values(array_unique($result));
100+
return implode(' ', $result);
101+
}
102+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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\Lib\Edit;
12+
13+
class Editor
14+
{
15+
/**
16+
* 获取编辑器插件列表.
17+
* @return bool|string
18+
* @throws \JsonException
19+
*/
20+
public static function plugins(): bool | string
21+
{
22+
$data = [];
23+
foreach (Itf()->get('comment-topic-edit-editor-plugins') as $value) {
24+
foreach ($value as $plugin) {
25+
$data[] = $plugin;
26+
}
27+
}
28+
$data = array_unique($data);
29+
$data = array_values($data);
30+
return json_encode($data, JSON_THROW_ON_ERROR);
31+
}
32+
33+
/**
34+
* 获取编辑器外部插件.
35+
* @return false|string
36+
*/
37+
public static function externalPlugins(): bool | string
38+
{
39+
$data = [];
40+
foreach (Itf()->get('comment-topic-edit-editor-external_plugins') as $value) {
41+
foreach ($value as $name => $plugin) {
42+
$data[$name] = $plugin;
43+
}
44+
}
45+
$data = array_unique($data);
46+
return json_encode($data);
47+
}
48+
49+
/**
50+
* 获取编辑器toolbar.
51+
* @return bool|string
52+
*/
53+
public static function toolbar(): bool | string
54+
{
55+
$data = [];
56+
foreach (Itf()->get('comment-topic-edit-editor-toolbar') as $value) {
57+
foreach ($value as $toolbar) {
58+
$data[] = $toolbar;
59+
}
60+
}
61+
$data = array_values($data);
62+
$data = implode(' ', $data);
63+
return trim($data);
64+
}
65+
66+
/**
67+
* 获取编辑器menu(菜单).
68+
*/
69+
public static function menu()
70+
{
71+
$data = [];
72+
foreach (Itf()->get('comment-topic-edit-editor-menu') as $key => $value) {
73+
foreach ($value as $keys => $menu) {
74+
$data[$keys] = $menu;
75+
}
76+
}
77+
$result = [];
78+
foreach ($data as $key => $value) {
79+
$value['items'] = implode(' ', $value['items']);
80+
$result[$key] = $value;
81+
}
82+
return json_encode($result);
83+
}
84+
85+
/**
86+
* 获取编辑器menubar.
87+
*/
88+
public static function menubar()
89+
{
90+
$data = [];
91+
foreach (Itf()->get('comment-topic-edit-editor-menu') as $value) {
92+
foreach ($value as $key => $menu) {
93+
$data[$key] = $menu;
94+
}
95+
}
96+
foreach ($data as $key => $value) {
97+
$result[] = $key;
98+
}
99+
$result = array_values(array_unique($result));
100+
return implode(' ', $result);
101+
}
102+
}

‎app/Plugins/Core/src/Lib/Redirect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function url($url): Redirect
2222

2323
public function back(): Redirect
2424
{
25-
$this->url = request()->getHeader('referer')[0];
25+
$this->url = request()->getHeader('referer')[0]?:'/';
2626
return $this;
2727
}
2828

‎app/Plugins/Topic/bootstrap.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@
105105

106106
// topic create - editor plugins
107107

108-
Itf()->add('topic-create-editor-plugins', 0, ['importcss', 'restoredraft', 'searchreplace', 'autolink', 'autosave', 'directionality', 'code', 'visualblocks', 'visualchars', 'image', 'link', 'media', 'codesample', 'table', 'charmap', 'pagebreak', 'nonbreaking', 'advlist', 'lists', 'wordcount', 'charmap', 'quickbars']);
108+
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']);
109110

110111
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']);
112+
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']);
111113

112-
Itf()->add('topic-create-editor-menu', 0, [
114+
115+
$editor_menu =[
113116
'file' => [
114117
'title' => 'File',
115118
'items' => [
@@ -138,9 +141,6 @@
138141
'searchreplace',
139142
],
140143
],
141-
]);
142-
143-
Itf()->add('topic-create-editor-menu', 1, [
144144
'view' => [
145145
'title' => 'View',
146146
'items' => [
@@ -231,7 +231,9 @@
231231
'deletetable',
232232
],
233233
],
234-
]);
234+
];
235+
Itf()->add('topic-create-editor-menu', 0, $editor_menu);
236+
Itf()->add('topic-edit-editor-menu', 0, $editor_menu);
235237

236238
Itf()->add('topic-create-options', 0, [
237239
'enable' => (function () {
@@ -246,6 +248,9 @@
246248
Itf()->add('topic-create-editor-external_plugins', 0, [
247249
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
248250
]);
251+
Itf()->add('topic-edit-editor-external_plugins', 0, [
252+
'sfPreview' => file_hash('plugins/Topic/js/editor/plugins/sfPreview.js'),
253+
]);
249254

250255
Itf()->add('topic-edit-data', 0, [
251256
'enable' => (function () {

‎app/Plugins/Topic/resources/views/create/basis.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
let options = {
6464
selector: '#basis-content',
6565
height: 450,
66-
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
67-
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
66+
menu:{!! \App\Plugins\Topic\src\Lib\Create\Editor::menu() !!},
67+
menubar:"{!! \App\Plugins\Topic\src\Lib\Create\Editor::menubar() !!}",
6868
statusbar: true,
6969
elementpath: true,
7070
promotion: false,
71-
plugins: {!! \App\Plugins\Topic\src\Lib\Editor::plugins() !!},
71+
plugins: {!! \App\Plugins\Topic\src\Lib\Create\Editor::plugins() !!},
7272
language: "zh-Hans",
73-
toolbar: "{!! \App\Plugins\Topic\src\Lib\Editor::toolbar() !!}",
73+
toolbar: "{!! \App\Plugins\Topic\src\Lib\Create\Editor::toolbar() !!}",
7474
link_default_target: '_blank',
7575
toolbar_mode: 'sliding',
7676
image_advtab: true,
@@ -79,16 +79,16 @@
7979
setup : function(ed) {
8080
//console.log(ed)
8181
},
82-
external_plugins:{!! \App\Plugins\Topic\src\Lib\Editor::externalPlugins() !!},
82+
external_plugins:{!! \App\Plugins\Topic\src\Lib\Create\Editor::externalPlugins() !!},
8383
images_upload_handler: image_upload_handler,
8484
init_instance_callback: (editor) => {
8585
@if(request()->has('restoredraft'))
8686
editor.plugins.autosave.restoreDraft()
8787
@endif
8888
},
8989
mobile:{
90-
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
91-
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
90+
menu:{!! \App\Plugins\Topic\src\Lib\Create\Editor::menu() !!},
91+
menubar:"{!! \App\Plugins\Topic\src\Lib\Create\Editor::menubar() !!}",
9292
toolbar_mode: 'scrolling'
9393
},
9494
autosave_ask_before_unload: true,

‎app/Plugins/Topic/resources/views/edit/basis.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,14 @@
6060
let options = {
6161
selector: '#basis-content',
6262
height: 450,
63-
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
64-
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
63+
menu:{!! \App\Plugins\Topic\src\Lib\Edit\Editor::menu() !!},
64+
menubar:"{!! \App\Plugins\Topic\src\Lib\Edit\Editor::menubar() !!}",
6565
statusbar: true,
6666
elementpath: true,
6767
promotion: false,
68-
plugins: {!! \App\Plugins\Topic\src\Lib\Editor::plugins() !!},
68+
plugins: {!! \App\Plugins\Topic\src\Lib\Edit\Editor::plugins() !!},
6969
language: "zh-Hans",
70-
toolbar: "{!! \App\Plugins\Topic\src\Lib\Editor::toolbar() !!}",
70+
toolbar: "{!! \App\Plugins\Topic\src\Lib\Edit\Editor::toolbar() !!}",
7171
link_default_target: '_blank',
7272
toolbar_mode: 'sliding',
7373
image_advtab: true,
@@ -76,16 +76,16 @@
7676
setup : function(ed) {
7777
//console.log(ed)
7878
},
79-
external_plugins:{!! \App\Plugins\Topic\src\Lib\Editor::externalPlugins() !!},
79+
external_plugins:{!! \App\Plugins\Topic\src\Lib\Edit\Editor::externalPlugins() !!},
8080
images_upload_handler: image_upload_handler,
8181
init_instance_callback: (editor) => {
8282
@if(request()->has('restoredraft'))
8383
editor.plugins.autosave.restoreDraft()
8484
@endif
8585
},
8686
mobile:{
87-
menu:{!! \App\Plugins\Topic\src\Lib\Editor::menu() !!},
88-
menubar:"{!! \App\Plugins\Topic\src\Lib\Editor::menubar() !!}",
87+
menu:{!! \App\Plugins\Topic\src\Lib\Edit\Editor::menu() !!},
88+
menubar:"{!! \App\Plugins\Topic\src\Lib\Edit\Editor::menubar() !!}",
8989
toolbar_mode: 'scrolling'
9090
},
9191
autosave_ask_before_unload: true,

‎app/Plugins/Topic/src/Lib/Editor.php renamed to ‎app/Plugins/Topic/src/Lib/Create/Editor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
* @contact laravel@88.com
99
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
1010
*/
11-
namespace App\Plugins\Topic\src\Lib;
11+
namespace App\Plugins\Topic\src\Lib\Create;
1212

1313
class Editor
1414
{
1515
/**
1616
* 获取编辑器插件列表.
1717
* @return bool|string
18+
* @throws \JsonException
1819
*/
1920
public static function plugins(): bool | string
2021
{
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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\Topic\src\Lib\Edit;
12+
13+
class Editor
14+
{
15+
/**
16+
* 获取编辑器插件列表.
17+
* @return bool|string
18+
* @throws \JsonException
19+
*/
20+
public static function plugins(): bool | string
21+
{
22+
$data = [];
23+
foreach (Itf()->get('topic-edit-editor-plugins') as $value) {
24+
foreach ($value as $plugin) {
25+
$data[] = $plugin;
26+
}
27+
}
28+
$data = array_unique($data);
29+
$data = array_values($data);
30+
return json_encode($data, JSON_THROW_ON_ERROR);
31+
}
32+
33+
/**
34+
* 获取编辑器外部插件.
35+
* @return false|string
36+
*/
37+
public static function externalPlugins(): bool | string
38+
{
39+
$data = [];
40+
foreach (Itf()->get('topic-edit-editor-external_plugins') as $value) {
41+
foreach ($value as $name => $plugin) {
42+
$data[$name] = $plugin;
43+
}
44+
}
45+
$data = array_unique($data);
46+
return json_encode($data);
47+
}
48+
49+
/**
50+
* 获取编辑器toolbar.
51+
* @return bool|string
52+
*/
53+
public static function toolbar(): bool | string
54+
{
55+
$data = [];
56+
foreach (Itf()->get('topic-edit-editor-toolbar') as $value) {
57+
foreach ($value as $toolbar) {
58+
$data[] = $toolbar;
59+
}
60+
}
61+
$data = array_values($data);
62+
$data = implode(' ', $data);
63+
return trim($data);
64+
}
65+
66+
/**
67+
* 获取编辑器menu(菜单).
68+
*/
69+
public static function menu()
70+
{
71+
$data = [];
72+
foreach (Itf()->get('topic-edit-editor-menu') as $key => $value) {
73+
foreach ($value as $keys => $menu) {
74+
$data[$keys] = $menu;
75+
}
76+
}
77+
$result = [];
78+
foreach ($data as $key => $value) {
79+
$value['items'] = implode(' ', $value['items']);
80+
$result[$key] = $value;
81+
}
82+
return json_encode($result);
83+
}
84+
85+
/**
86+
* 获取编辑器menubar.
87+
*/
88+
public static function menubar()
89+
{
90+
$data = [];
91+
foreach (Itf()->get('topic-edit-editor-menu') as $value) {
92+
foreach ($value as $key => $menu) {
93+
$data[$key] = $menu;
94+
}
95+
}
96+
foreach ($data as $key => $value) {
97+
$result[] = $key;
98+
}
99+
$result = array_values(array_unique($result));
100+
return implode(' ', $result);
101+
}
102+
}

0 commit comments

Comments
 (0)
Please sign in to comment.