Skip to content

Commit

Permalink
更新:完成发帖编辑器更改
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Dec 22, 2022
1 parent 81a039a commit 0ee8608
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 51 deletions.
38 changes: 38 additions & 0 deletions app/Plugins/Core/src/Models/PostsOption.php
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Core\src\Models;

use App\Model\Model;

/**
* @property int $id
* @property int $disable_comment
*/
class PostsOption extends Model
{

protected $fillable = ['post_id','id','disable_comment'];

public $timestamps = false;
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'posts_options';

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = ['id' => 'integer', 'disable_comment' => 'integer'];
}
@@ -0,0 +1,27 @@
<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class CreatePostsOptionsTable extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('posts_options', function (Blueprint $table) {
$table->bigIncrements('id');
$table->boolean('disable_comment')->default(false)->comment('禁用评论');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('posts_options');
}
}
@@ -0,0 +1,28 @@
<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

class UpdatePostsOptionsTableAddPostId extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('posts_options', function (Blueprint $table) {
$table->string('post_id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('posts_options', function (Blueprint $table) {
//
});
}
}
19 changes: 8 additions & 11 deletions app/Plugins/Topic/bootstrap.php
Expand Up @@ -105,9 +105,9 @@

// topic create - editor plugins

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

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


Itf()->add('topic-create-editor-menu', 0, [
Expand Down Expand Up @@ -234,15 +234,12 @@
],
]);

//Itf()->add('topic-create-options',0,[
// 'enable' => (function(){
// return true;
// }),
// 'view' => 'Topic::create.options.noupload',
// 'scripts' => [
// //file_hash('tabler/libs/dropzone/dist/dropzone-min.js')
// ]
//]);
Itf()->add('topic-create-options', 0, [
'enable' => (function () {
return true;
}),
'view' => 'Topic::create.options.disable_comment',
]);

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

Expand Down
78 changes: 78 additions & 0 deletions app/Plugins/Topic/resources/assets/js/editor/plugins/sfEmoji.js
@@ -0,0 +1,78 @@
/*
Note: We have included the plugin in the same JavaScript file as the TinyMCE
instance for display purposes only. Tiny recommends not maintaining the plugin
with the TinyMCE instance and using the `external_plugins` option.
*/

tinymce.PluginManager.add('sfEmoji', (editor, url) => {
const tabs = ()=>{
return {
name:"a",
title:"Title",
items: [
{
type: 'iframe', // component type
name: 'sfPreview', // identifier
sandboxed: true,
transparent: true,
}
]
}
}
const openDialog = () => editor.windowManager.open({
title: '表情',
size: "large",
body: {
type: 'tabpanel',
tabs:[
tabs()
]
},
buttons: [
{
type: 'cancel',
text: 'Close'
},
],
});
/* Add a button that opens a window */
editor.ui.registry.addButton('sfEmoji', {
icon:'emoji',
onAction: () => {
/* Open window */
let _openDialog = openDialog();
axios.post("/topic/create/preview",{
_token:csrf_token,
content:editor.getContent()
}).then(r=>{
_openDialog.setData({
sfPreview:r.data
})
})
}
});
/* Adds a menu item, which can then be included in any menu via the menu/menubar configuration */
editor.ui.registry.addMenuItem('sfEmoji', {
text: '表情',
icon:'emoji',
onAction: () => {
/* Open window */
let _openDialog = openDialog();
axios.post("/topic/create/preview",{
_token:csrf_token,
content:editor.getContent()
}).then(r=>{
_openDialog.setData({
sfPreview:r.data
})
})
}
});
/* Return the metadata for the help plugin */
return {
getMetadata: () => ({
name: 'sfEmoji',
url: 'https://www.runpod.cn'
})
};
});
@@ -0,0 +1,11 @@

<div class="col-12">
<div class="card">
<div class="card-body">
<label class="form-check">
<input type="checkbox" name="options[disable_comment]" class="form-check-input"/>
<span class="form-check-label">关闭评论</span>
</label>
</div>
</div>
</div>
27 changes: 0 additions & 27 deletions app/Plugins/Topic/resources/views/create/options/upload.blade.php

This file was deleted.

Expand Up @@ -48,9 +48,9 @@ public function handler($data, \Closure $next)
$data = $data['basis'];
unset($data['content']);
$result = [];
$result['basis']=$data;
$result['basis'] = $data;
$result['restoredraft'] = true;
return redirect()->with('danger', $validator->errors()->first())->url('topic/create?'.http_build_query($result))->go();
return redirect()->with('danger', $validator->errors()->first())->url('topic/create?' . http_build_query($result))->go();
}
$data = $this->create($data);
return $next($data);
Expand Down Expand Up @@ -91,8 +91,8 @@ public function create($data)
Post::query()->where('id', $post->id)->update(['topic_id' => $topic->id]);
$this->topic_keywords($topic, $_content);
$this->at_user($topic, $_content);
$data['topic_id']= $topic->id;
$data['post_id']= $post->id;
$data['topic_id'] = $topic->id;
$data['post_id'] = $post->id;
return $data;
}

Expand Down
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Create;

use App\Plugins\Core\src\Models\PostsOption;
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;

#[\App\Plugins\Topic\src\Annotation\Topic\CreateLastMiddleware]
class PostsOptionsMiddleware implements MiddlewareInterface
{
public function handler($data, \Closure $next)
{
$post_id = $data['post_id'];
if (! PostsOption::query()->where('post_id', $post_id)->exists()) {
$post_options = PostsOption::create([
'post_id' => $post_id,
]);
} else {
$post_options = PostsOption::query()->where('post_id', $post_id)->first()->id;
}
$data['posts_options'] = $post_options;
return $next($data);
}
}
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\Topic\src\Handler\Topic\Middleware\Create;

use App\Plugins\Core\src\Models\PostsOption;
use App\Plugins\Topic\src\Handler\Topic\Middleware\MiddlewareInterface;

#[\App\Plugins\Topic\src\Annotation\Topic\CreateLastMiddleware]
class SetDisableCommentMiddleware implements MiddlewareInterface
{
public function handler($data, \Closure $next)
{
$disable_comment = (bool) request()->input('options.disable_comment', false);
$posts_options_id = $data['posts_options']['id'];
PostsOption::query()->where('id', $posts_options_id)->update([
'disable_comment' => $disable_comment,
]);
return $next($data);
}
}
34 changes: 25 additions & 9 deletions app/Plugins/User/src/Models/UserUpload.php
@@ -1,16 +1,24 @@
<?php

declare (strict_types=1);
declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
* @document https://github.com/zhuchunshu/super-forum
* @contact laravel@88.com
* @license https://github.com/zhuchunshu/super-forum/blob/master/LICENSE
*/
namespace App\Plugins\User\src\Models;

use App\Model\Model;
use App\Plugins\Topic\src\Models\Topic;
use Carbon\Carbon;

/**
* @property int $id
* @property string $user_id
* @property string $path
* @property string $url
* @property int $id
* @property string $user_id
* @property string $path
* @property string $url
* @property Carbon $created_at
* @property Carbon $updated_at
*/
Expand All @@ -22,20 +30,28 @@ class UserUpload extends Model
* @var string
*/
protected $table = 'user_upload';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['user_id','created_at','updated_at','path','url'];
protected $fillable = ['user_id', 'created_at', 'updated_at', 'path', 'url', 'post_id'];

/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = ['id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

public function user(){
return $this->belongsTo(User::class,"user_id","id");
public function user()
{
return $this->belongsTo(User::class, 'user_id', 'id');
}

public function topic()
{
return $this->belongsTo(Topic::class, 'topic_id', 'id');
}
}
}

0 comments on commit 0ee8608

Please sign in to comment.