This repository has been archived by the owner on Jun 24, 2021. It is now read-only.
forked from hasan-ozbey/flarum-diff
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextend.php
76 lines (62 loc) · 2.39 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
75
76
<?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 <hasanoozbey@gmail.com>
* @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\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Foundation\Paths;
use Flarum\Post\Post;
use IanM\Diff\Api\Controllers;
use IanM\Diff\Api\SerializeDiffsOnPosts;
use IanM\Diff\Api\Serializers\DiffSerializer;
use IanM\Diff\Console\ArchiveCommand;
use IanM\Diff\Models\Diff;
use Illuminate\Console\Scheduling\Event;
use Illuminate\Console\Scheduling\Schedule;
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'),
];