Skip to content

Commit 0ee8608

Browse files
committedDec 22, 2022
更新:完成发帖编辑器更改
·
v2.7.7v2.1.7
1 parent 81a039a commit 0ee8608

File tree

12 files changed

+317
-51
lines changed

12 files changed

+317
-51
lines changed
 
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Core\src\Models;
12+
13+
use App\Model\Model;
14+
15+
/**
16+
* @property int $id
17+
* @property int $disable_comment
18+
*/
19+
class PostsOption extends Model
20+
{
21+
22+
protected $fillable = ['post_id','id','disable_comment'];
23+
24+
public $timestamps = false;
25+
/**
26+
* The table associated with the model.
27+
*
28+
* @var string
29+
*/
30+
protected $table = 'posts_options';
31+
32+
/**
33+
* The attributes that should be cast to native types.
34+
*
35+
* @var array
36+
*/
37+
protected $casts = ['id' => 'integer', 'disable_comment' => 'integer'];
38+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Hyperf\Database\Schema\Schema;
4+
use Hyperf\Database\Schema\Blueprint;
5+
use Hyperf\Database\Migrations\Migration;
6+
7+
class CreatePostsOptionsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('posts_options', function (Blueprint $table) {
15+
$table->bigIncrements('id');
16+
$table->boolean('disable_comment')->default(false)->comment('禁用评论');
17+
});
18+
}
19+
20+
/**
21+
* Reverse the migrations.
22+
*/
23+
public function down(): void
24+
{
25+
Schema::dropIfExists('posts_options');
26+
}
27+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Hyperf\Database\Schema\Schema;
4+
use Hyperf\Database\Schema\Blueprint;
5+
use Hyperf\Database\Migrations\Migration;
6+
7+
class UpdatePostsOptionsTableAddPostId extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('posts_options', function (Blueprint $table) {
15+
$table->string('post_id');
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('posts_options', function (Blueprint $table) {
25+
//
26+
});
27+
}
28+
}

‎app/Plugins/Topic/bootstrap.php

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

106106
// topic create - editor plugins
107107

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']);
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']);
109109

110-
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', 'codesample', '|', 'ltr', 'rtl']);
110+
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']);
111111

112112

113113
Itf()->add('topic-create-editor-menu', 0, [
@@ -234,15 +234,12 @@
234234
],
235235
]);
236236

237-
//Itf()->add('topic-create-options',0,[
238-
// 'enable' => (function(){
239-
// return true;
240-
// }),
241-
// 'view' => 'Topic::create.options.noupload',
242-
// 'scripts' => [
243-
// //file_hash('tabler/libs/dropzone/dist/dropzone-min.js')
244-
// ]
245-
//]);
237+
Itf()->add('topic-create-options', 0, [
238+
'enable' => (function () {
239+
return true;
240+
}),
241+
'view' => 'Topic::create.options.disable_comment',
242+
]);
246243

247244
Itf()->add('topic-create-handle-middleware-end', 0, \App\Plugins\Topic\src\Handler\Topic\Middleware\Create\CreateEndMiddleware::class);
248245

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Note: We have included the plugin in the same JavaScript file as the TinyMCE
3+
instance for display purposes only. Tiny recommends not maintaining the plugin
4+
with the TinyMCE instance and using the `external_plugins` option.
5+
*/
6+
7+
tinymce.PluginManager.add('sfEmoji', (editor, url) => {
8+
const tabs = ()=>{
9+
return {
10+
name:"a",
11+
title:"Title",
12+
items: [
13+
{
14+
type: 'iframe', // component type
15+
name: 'sfPreview', // identifier
16+
sandboxed: true,
17+
transparent: true,
18+
}
19+
]
20+
}
21+
}
22+
const openDialog = () => editor.windowManager.open({
23+
title: '表情',
24+
size: "large",
25+
body: {
26+
type: 'tabpanel',
27+
tabs:[
28+
tabs()
29+
]
30+
},
31+
buttons: [
32+
{
33+
type: 'cancel',
34+
text: 'Close'
35+
},
36+
],
37+
});
38+
/* Add a button that opens a window */
39+
editor.ui.registry.addButton('sfEmoji', {
40+
icon:'emoji',
41+
onAction: () => {
42+
/* Open window */
43+
let _openDialog = openDialog();
44+
axios.post("/topic/create/preview",{
45+
_token:csrf_token,
46+
content:editor.getContent()
47+
}).then(r=>{
48+
_openDialog.setData({
49+
sfPreview:r.data
50+
})
51+
})
52+
}
53+
});
54+
/* Adds a menu item, which can then be included in any menu via the menu/menubar configuration */
55+
editor.ui.registry.addMenuItem('sfEmoji', {
56+
text: '表情',
57+
icon:'emoji',
58+
onAction: () => {
59+
/* Open window */
60+
let _openDialog = openDialog();
61+
axios.post("/topic/create/preview",{
62+
_token:csrf_token,
63+
content:editor.getContent()
64+
}).then(r=>{
65+
_openDialog.setData({
66+
sfPreview:r.data
67+
})
68+
})
69+
}
70+
});
71+
/* Return the metadata for the help plugin */
72+
return {
73+
getMetadata: () => ({
74+
name: 'sfEmoji',
75+
url: 'https://www.runpod.cn'
76+
})
77+
};
78+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
<div class="col-12">
3+
<div class="card">
4+
<div class="card-body">
5+
<label class="form-check">
6+
<input type="checkbox" name="options[disable_comment]" class="form-check-input"/>
7+
<span class="form-check-label">关闭评论</span>
8+
</label>
9+
</div>
10+
</div>
11+
</div>

‎app/Plugins/Topic/resources/views/create/options/upload.blade.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function handler($data, \Closure $next)
4848
$data = $data['basis'];
4949
unset($data['content']);
5050
$result = [];
51-
$result['basis']=$data;
51+
$result['basis'] = $data;
5252
$result['restoredraft'] = true;
53-
return redirect()->with('danger', $validator->errors()->first())->url('topic/create?'.http_build_query($result))->go();
53+
return redirect()->with('danger', $validator->errors()->first())->url('topic/create?' . http_build_query($result))->go();
5454
}
5555
$data = $this->create($data);
5656
return $next($data);
@@ -91,8 +91,8 @@ public function create($data)
9191
Post::query()->where('id', $post->id)->update(['topic_id' => $topic->id]);
9292
$this->topic_keywords($topic, $_content);
9393
$this->at_user($topic, $_content);
94-
$data['topic_id']= $topic->id;
95-
$data['post_id']= $post->id;
94+
$data['topic_id'] = $topic->id;
95+
$data['post_id'] = $post->id;
9696
return $data;
9797
}
9898

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Handler\Topic\Middleware\Create;
12+
13+
use App\Plugins\Core\src\Models\PostsOption;
14+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
15+
16+
#[\App\Plugins\Topic\src\Annotation\Topic\CreateLastMiddleware]
17+
class PostsOptionsMiddleware implements MiddlewareInterface
18+
{
19+
public function handler($data, \Closure $next)
20+
{
21+
$post_id = $data['post_id'];
22+
if (! PostsOption::query()->where('post_id', $post_id)->exists()) {
23+
$post_options = PostsOption::create([
24+
'post_id' => $post_id,
25+
]);
26+
} else {
27+
$post_options = PostsOption::query()->where('post_id', $post_id)->first()->id;
28+
}
29+
$data['posts_options'] = $post_options;
30+
return $next($data);
31+
}
32+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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\Handler\Topic\Middleware\Create;
12+
13+
use App\Plugins\Core\src\Models\PostsOption;
14+
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;
15+
16+
#[\App\Plugins\Topic\src\Annotation\Topic\CreateLastMiddleware]
17+
class SetDisableCommentMiddleware implements MiddlewareInterface
18+
{
19+
public function handler($data, \Closure $next)
20+
{
21+
$disable_comment = (bool) request()->input('options.disable_comment', false);
22+
$posts_options_id = $data['posts_options']['id'];
23+
PostsOption::query()->where('id', $posts_options_id)->update([
24+
'disable_comment' => $disable_comment,
25+
]);
26+
return $next($data);
27+
}
28+
}
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<?php
22

3-
declare (strict_types=1);
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+
*/
411
namespace App\Plugins\User\src\Models;
512

613
use App\Model\Model;
14+
use App\Plugins\Topic\src\Models\Topic;
715
use Carbon\Carbon;
816

917
/**
10-
* @property int $id
11-
* @property string $user_id
12-
* @property string $path
13-
* @property string $url
18+
* @property int $id
19+
* @property string $user_id
20+
* @property string $path
21+
* @property string $url
1422
* @property Carbon $created_at
1523
* @property Carbon $updated_at
1624
*/
@@ -22,20 +30,28 @@ class UserUpload extends Model
2230
* @var string
2331
*/
2432
protected $table = 'user_upload';
33+
2534
/**
2635
* The attributes that are mass assignable.
2736
*
2837
* @var array
2938
*/
30-
protected $fillable = ['user_id','created_at','updated_at','path','url'];
39+
protected $fillable = ['user_id', 'created_at', 'updated_at', 'path', 'url', 'post_id'];
40+
3141
/**
3242
* The attributes that should be cast to native types.
3343
*
3444
* @var array
3545
*/
3646
protected $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];
3747

38-
public function user(){
39-
return $this->belongsTo(User::class,"user_id","id");
48+
public function user()
49+
{
50+
return $this->belongsTo(User::class, 'user_id', 'id');
51+
}
52+
53+
public function topic()
54+
{
55+
return $this->belongsTo(Topic::class, 'topic_id', 'id');
4056
}
41-
}
57+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
use Hyperf\Database\Migrations\Migration;
12+
use Hyperf\Database\Schema\Blueprint;
13+
use Hyperf\Database\Schema\Schema;
14+
15+
class UpdateUserUploadTableAddPostId extends Migration
16+
{
17+
/**
18+
* Run the migrations.
19+
*/
20+
public function up(): void
21+
{
22+
Schema::table('user_upload', function (Blueprint $table) {
23+
if (! Schema::hasColumn('user_upload', 'post_id')) {
24+
$table->string('post_id');
25+
}
26+
});
27+
}
28+
29+
/**
30+
* Reverse the migrations.
31+
*/
32+
public function down(): void
33+
{
34+
Schema::table('user_upload', function (Blueprint $table) {
35+
36+
});
37+
}
38+
}

0 commit comments

Comments
 (0)
Please sign in to comment.