-
Notifications
You must be signed in to change notification settings - Fork 20
/
extend.php
120 lines (94 loc) · 4.64 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace V17Development\FlarumBlog;
// Flarum classes
use Flarum\Api\Controller as FlarumController;
use Flarum\Api\Serializer\BasicDiscussionSerializer;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Extend;
use Flarum\Discussion\Discussion;
use Flarum\Discussion\Event\Saving;
use Flarum\Discussion\Filter\DiscussionFilterer;
use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Tags\Api\Serializer\TagSerializer;
// Controllers
use V17Development\FlarumBlog\Controller\BlogOverviewController;
use V17Development\FlarumBlog\Controller\BlogItemController;
use V17Development\FlarumBlog\Controller\BlogComposerController;
// Access
use V17Development\FlarumBlog\Access\ScopeDiscussionVisibility;
// API controllers
use V17Development\FlarumBlog\Api\AttachForumSerializerAttributes;
use V17Development\FlarumBlog\Api\AttatchTagSerializerAttributes;
use V17Development\FlarumBlog\Api\Controller\CreateBlogMetaController;
use V17Development\FlarumBlog\Api\Controller\UpdateBlogMetaController;
use V17Development\FlarumBlog\Api\Controller\UploadDefaultBlogImageController;
use V17Development\FlarumBlog\Api\Controller\DeleteDefaultBlogImageController;
use V17Development\FlarumBlog\Api\Serializer\BlogMetaSerializer;
// Listeners
use V17Development\FlarumBlog\Listeners\CreateBlogMetaOnDiscussionCreate;
// Models
use V17Development\FlarumBlog\BlogMeta\BlogMeta;
// Filters
use V17Development\FlarumBlog\Query\FilterDiscussionsForBlogPosts;
use V17Development\FlarumBlog\Query\BlogArticleFilterGambit;
// SEO
use V17Development\FlarumBlog\SeoPage\SeoBlogOverviewMeta;
use V17Development\FlarumBlog\SeoPage\SeoBlogArticleMeta;
use V17Development\FlarumBlog\Subscribers\SeoBlogSubscriber;
$extend = [
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/less/Forum.less')
->route('/blog', 'blog.overview', BlogOverviewController::class)
->route('/blog/compose', 'blog.compose', BlogComposerController::class)
->route('/blog/category/{category}', 'blog.category', BlogOverviewController::class)
->route('/blog/{id:[\d\S]+(?:-[^/]*)?}', 'blog.post', BlogItemController::class)
// Shall we add RSS?
// ->get('/blog/rss.xml', 'blog.rss.xml', RSS::class)
,
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js')
->css(__DIR__ . '/less/Admin.less'),
(new Extend\Routes('api'))
->post('/blogMeta', 'blog.meta', CreateBlogMetaController::class)
->patch('/blogMeta/{id}', 'blog.meta.edit', UpdateBlogMetaController::class)
->post('/blog_default_image', 'blog.default_image.upload', UploadDefaultBlogImageController::class)
->delete('/blog_default_image', 'blog.default_image.delete', DeleteDefaultBlogImageController::class),
new Extend\Locales(__DIR__ . '/locale'),
(new Extend\Model(Discussion::class))
->hasOne('blogMeta', BlogMeta::class, 'discussion_id'),
(new Extend\ModelVisibility(Discussion::class))
->scope(ScopeDiscussionVisibility::class),
(new Extend\ApiController(FlarumController\CreateDiscussionController::class))
->addInclude(['blogMeta', 'firstPost', 'user']),
(new Extend\ApiController(FlarumController\ListDiscussionsController::class))
->addInclude(['blogMeta', 'firstPost', 'user']),
(new Extend\ApiController(FlarumController\ShowDiscussionController::class))
->addInclude(['blogMeta', 'firstPost', 'user']),
(new Extend\ApiController(FlarumController\UpdateDiscussionController::class))
->addInclude(['blogMeta', 'firstPost', 'user']),
(new Extend\ApiSerializer(BasicDiscussionSerializer::class))
->hasOne('blogMeta', BlogMetaSerializer::class),
(new Extend\ApiSerializer(ForumSerializer::class))
->attributes(AttachForumSerializerAttributes::class),
(new Extend\ApiSerializer(TagSerializer::class))
->attributes(AttatchTagSerializerAttributes::class),
(new Extend\Filter(DiscussionFilterer::class))
->addFilterMutator(FilterDiscussionsForBlogPosts::class),
(new Extend\SimpleFlarumSearch(DiscussionSearcher::class))
->addGambit(BlogArticleFilterGambit::class),
];
// Define events
$events = (new Extend\Event)
->listen(Saving::class, CreateBlogMetaOnDiscussionCreate::class);
// Extend Flarum SEO
if (class_exists("V17Development\FlarumSeo\Extend\SEO")) {
$extend[] = (new \V17Development\FlarumSeo\Extend\SEO())
->addExtender("blog_category", SeoBlogOverviewMeta::class)
->addExtender("blog_article", SeoBlogArticleMeta::class);
// Add Blog subscriber event
$events->subscribe(SeoBlogSubscriber::class);
}
// Add events
$extend[] = $events;
return $extend;