-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
80 lines (67 loc) · 3.13 KB
/
bootstrap.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
69
70
71
72
73
74
75
76
77
78
79
80
<?php
use App\Services\Hook;
use Blessing\Filter;
use Blessing\Rejection;
use Illuminate\Contracts\Events\Dispatcher;
use LittleSkin\TextureModeration\Controllers\ModerationController;
use LittleSkin\TextureModeration\Listeners\OnTextureDeleted;
use LittleSkin\TextureModeration\Listeners\OnTextureUploaded;
use LittleSkin\TextureModeration\Models\ModerationRecord;
use LittleSkin\TextureModeration\ReviewState;
use LittleSkin\TextureModeration\RecordSource;
return function (Filter $filter, Dispatcher $events) {
$events->listen('texture.uploaded', OnTextureUploaded::class);
$events->listen('texture.deleted', OnTextureDeleted::class);
$filter->add('can_update_texture_privacy', function ($can, $texture) {
// private to public
if (!$texture->public) {
$record = ModerationRecord::where('tid', $texture->tid)->first();
if (!$record) {
$result = ModerationController::start($texture, RecordSource::ON_PRIVACY_UPDATED);
return $result ? $result : $texture;
} elseif ($record->review_state === ReviewState::MANUAL) {
return new Rejection(trans('LittleSkin\TextureModeration::skinlib.manual_tip'));
} elseif ($record->review_state === ReviewState::REJECTED) {
return new Rejection(trans('LittleSkin\TextureModeration::skinlib.rejected'));
}
}
return $texture;
});
Hook::addScriptFileToPage(plugin_assets('texture-moderation', 'js/texture-moderation.js'), ['admin/texture-moderation']);
Hook::addRoute(function () {
Route::namespace('LittleSkin\TextureModeration\Controllers')
->middleware(['web', 'auth', 'role:admin'])
->prefix('admin/texture-moderation')
->group(function () {
Route::get('', 'TextureModerationController@show');
Route::post('review', 'TextureModerationController@review');
Route::get('list', 'TextureModerationController@manage');
});
Route::namespace('LittleSkin\TextureModeration\Controllers')
->middleware(['web', 'auth', 'role:admin'])
->prefix('admin/moderation-whitelist')
->group(function () {
Route::get('', 'WhitelistController@show');
Route::post('', 'WhitelistController@add');
Route::delete('', 'WhitelistController@delete');
});
});
Hook::addMenuItem('admin', 4001, [
'title' => '材质审核',
'link' => 'admin/texture-moderation',
'icon' => 'fa-shield-alt',
]);
Hook::addMenuItem('admin', 4002, [
'title' => '免审用户',
'link' => 'admin/moderation-whitelist',
'icon' => 'fa-list-alt',
]);
$filter->add('grid:skinlib.show', function ($grid) {
$texture = request()->route()->parameter('texture');
$record = ModerationRecord::where('tid', $texture->tid)->first();
if (optional($record)->review_state === ReviewState::MANUAL) {
array_unshift($grid['widgets'][0][1], 'LittleSkin\TextureModeration::texture-detail-tip');
}
return $grid;
});
};