forked from imorland/flarum-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
74 lines (60 loc) · 2.2 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
69
70
71
72
73
74
<?php
/**
* Diff Extension for Flarum.
*
* LICENSE: For the full copyright and license information,
* please view the LICENSE file that was distributed
* with this source code.
*
* @author Hasan Özbey <[email protected]>
* @copyright 2020
* @license The MIT License
*
* @version Release: 1.0.8
*
* @link https://github.com/the-turk/flarum-diff
*/
namespace IanM\Diff;
use Flarum\Api\Serializer\BasicPostSerializer;
use Flarum\Extend;
use Flarum\Post\Post;
use Illuminate\Contracts\Events\Dispatcher;
use IanM\Diff\Api\Controllers;
use IanM\Diff\Api\Serializers\DiffSerializer;
use IanM\Diff\Console\ArchiveCommand;
use IanM\Diff\Models\Diff;
return [
(new Extend\Routes('api'))
->get('/diff', 'diff.index', Controllers\ListDiffController::class)
->delete('/diff/{id}', 'diff.delete', Controllers\DeleteDiffController::class)
->post('/diff/{id}', 'diff.rollback', Controllers\RollbackToDiffController::class),
(new Extend\Frontend('admin'))
->css(__DIR__.'/less/admin.less')
->js(__DIR__.'/js/dist/admin.js'),
(new Extend\Frontend('forum'))
->css(__DIR__.'/less/forum.less')
->js(__DIR__.'/js/dist/forum.js'),
(new Extend\Locales(__DIR__.'/locale')),
// GetModelRelationship event is deprecated by
// https://github.com/flarum/core/pull/2100
(new Extend\Model(Post::class))
->hasMany('diff', Diff::class, 'post_id'),
static function (Dispatcher $events) {
$events->subscribe(Listeners\PostActions::class);
$events->subscribe(Listeners\AddDiffRelationship::class);
$events->subscribe(Listeners\UserPreferences::class);
//$app->register(Providers\ConsoleProvider::class);
},
(new Extend\Console())
->command(ArchiveCommand::class),
(new Extend\ApiSerializer(BasicPostSerializer::class))
->hasMany('diff', DiffSerializer::class),
(new Extend\Settings())
->serializeToForum('textFormattingForDiffPreviews', 'the-turk-diff.textFormatting', function ($value) {
if ($value === '' || $value === null) {
// Default value
$value = true;
}
return (bool) $value;
}),
];