-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
68 lines (56 loc) · 2.09 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* This file is part of imdong/flarum-ext-spam-alert.
*
* Copyright (c) 2023 ImDong.
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace ImDong\SpamAlert;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Api\Serializer\BasicPostSerializer;
use Flarum\Post\Post;
use Flarum\User\User;
use ImDong\SpamAlert\Attribute\PostAttribute;
use ImDong\SpamAlert\Common\Defined;
use ImDong\SpamAlert\Event\PostSetSpam;
use ImDong\SpamAlert\Notification\PostSpamHidedBlueprint;
return [
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js')
,
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/less/forum.less')
,
new Extend\Locales(__DIR__ . '/locale'),
// 设置默认值
(new Extend\Settings())
// 默认折叠次数
->default(Defined::key('to-folding-number'), 5)
->serializeToForum(Defined::key('btn-name'), Defined::key('btn-name'))
->serializeToForum(Defined::key('to-folding-number'), Defined::key('to-folding-number')),
// 添加文章的关联查询
(new Extend\Model(Post::class))
// 标记过垃圾的用户列表
->belongsToMany('spams', User::class, PostSpam::class, 'post_id', 'create_user_id')
->cast('is_spam_hide', 'boolean')
,
// 给 post 回复添加一些额外的字段
(new Extend\ApiSerializer(BasicPostSerializer::class))
->attributes(PostAttribute::class),
// 通知事件
(new Extend\Notification())
->type(PostSpamHidedBlueprint::class, PostSerializer::class, ['alert']),
// 挂钩事件
(new Extend\Event())
// 被隐藏时发送通知消息
->listen(Event\PostSetSpamHide::class, Listener\SendNotificationWhenPostIsSpamHide::class)
// 被标记 Spam 时检查是否需要隐藏
->listen(Event\PostSetSpam::class, Listener\PostSetSpamWhenHide::class)
// 修改文档内容时
->subscribe(Listener\SaveSpamToDatabase::class)
,
];