forked from hasan-ozbey/flarum-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.php
67 lines (53 loc) · 2.17 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
<?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.
*/
namespace TheTurk\Diff;
use Flarum\Api\Serializer\BasicPostSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Foundation\Paths;
use Flarum\Post\Post;
use Illuminate\Console\Scheduling\Event;
use TheTurk\Diff\Api\Controllers;
use TheTurk\Diff\Api\Serializers\DiffSerializer;
use TheTurk\Diff\Api\Serializers\SerializeDiffsOnPosts;
use TheTurk\Diff\Console\ArchiveCommand;
use TheTurk\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')),
(new Extend\Model(Post::class))
->hasMany('diff', Diff::class, 'post_id'),
(new Extend\Event())
->subscribe(Listeners\PostActions::class),
(new Extend\Console())
->command(ArchiveCommand::class)
->schedule(ArchiveCommand::class, function (Event $event) {
/** @var Paths $paths */
$paths = resolve(Paths::class);
$event->weeklyOn(2, '2:00')
->appendOutputTo($paths->storage.(DIRECTORY_SEPARATOR.'logs'.DIRECTORY_SEPARATOR.'diff-archive-task.log'));
}),
(new Extend\ApiSerializer(BasicPostSerializer::class))
->hasMany('diff', DiffSerializer::class),
(new Extend\ApiSerializer(PostSerializer::class))
->attributes(SerializeDiffsOnPosts::class),
(new Extend\Settings())
->serializeToForum('textFormattingForDiffPreviews', 'the-turk-diff.textFormatting', 'boolVal', true),
(new Extend\User())
->registerPreference('diffRenderer', 'strval', 'sideBySide'),
];