-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathextend.php
88 lines (67 loc) · 2.86 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
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
* This file is part of fof/geoip.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FoF\GeoIP;
use Flarum\Api\Controller;
use Flarum\Api\Serializer\BasicUserSerializer;
use Flarum\Api\Serializer\CurrentUserSerializer;
use Flarum\Api\Serializer\PostSerializer;
use Flarum\Extend;
use Flarum\Frontend\Document;
use Flarum\Post\Post;
use Flarum\Settings\Event\Saving;
use FoF\GeoIP\Api\GeoIP;
return [
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/resources/less/admin.less')
->content(function (Document $document) {
$document->payload['fof-geoip.services'] = array_keys(GeoIP::$services);
}),
(new Extend\Model(Post::class))
->relationship('ip_info', Model\IPInfoRelationship::class),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Event())
->listen(Saving::class, Listeners\RemoveErrorsOnSettingsUpdate::class)
->subscribe(Listeners\RetrieveIP::class),
(new Extend\ApiSerializer(PostSerializer::class))
->relationship('ip_info', Api\AttachRelation::class),
(new Extend\ApiController(Controller\ListPostsController::class))
->addInclude('ip_info'),
(new Extend\ApiController(Controller\ShowPostController::class))
->addInclude('ip_info'),
(new Extend\ApiController(Controller\CreatePostController::class))
->addInclude('ip_info'),
(new Extend\ApiController(Controller\UpdatePostController::class))
->addInclude('ip_info'),
(new Extend\ApiController(Controller\ShowDiscussionController::class))
->addInclude('posts.ip_info'),
(new Extend\Settings())
->default('fof-geoip.service', 'ipapi')
->default('fof-geoip.showFlag', false)
->serializeToForum('fof-geoip.showFlag', 'fof-geoip.showFlag', 'boolval'),
(new Extend\Routes('api'))
->get('/ip_info/{ip}', 'fof-geoip.api.ip_info', Api\Controller\ShowIpInfoController::class),
(new Extend\Console())
->command(Console\LookupUnknownIPsCommand::class),
(new Extend\User())
->registerPreference('showIPCountry', 'boolval', false),
(new Extend\ApiSerializer(BasicUserSerializer::class))
->attributes(Api\BasicUserAttributes::class),
(new Extend\ApiSerializer(CurrentUserSerializer::class))
->attributes(Api\CurrentUserAttributes::class),
(new Extend\Conditional())
->whenExtensionEnabled('fof-default-user-preferences', fn () => [
(new \FoF\DefaultUserPreferences\Extend\RegisterUserPreferenceDefault())
->default('showIPCountry', false, 'bool'),
]),
];