-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.php
More file actions
43 lines (37 loc) · 1.92 KB
/
Copy pathextend.php
File metadata and controls
43 lines (37 loc) · 1.92 KB
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
<?php
use Flarum\Extend;
use Flarum\Frontend\Document;
use Flarum\Settings\SettingsRepositoryInterface;
use LinkRobins\HtmlWidget\Api\Controller\ShowWidgetController;
return [
(new Extend\Frontend('forum'))
->js(__DIR__ . '/js/dist/forum.js')
->css(__DIR__ . '/less/forum.less')
// A short revision hash of the widget's settings, injected into the boot
// payload so the frontend can cache-bust the content request. The body
// itself is NOT serialised here (it stays behind the on-demand endpoint);
// only this ~12-char hash rides along, so a settings change changes the
// fetch URL and a normal reload shows the new content without a hard
// refresh, while unchanged content still caches.
->content(function (Document $document) {
$settings = resolve(SettingsRepositoryInterface::class);
$document->payload['linkrobins-html-widget.rev'] = substr(sha1(
$settings->get('linkrobins-html-widget.title', '') . '|' .
$settings->get('linkrobins-html-widget.icon', '') . '|' .
$settings->get('linkrobins-html-widget.body', '') . '|' .
$settings->get('linkrobins-html-widget.backgroundColor', '')
), 0, 12);
}),
(new Extend\Frontend('admin'))
->js(__DIR__ . '/js/dist/admin.js'),
new Extend\Locales(__DIR__ . '/locale'),
// Widget content is fetched on demand from this endpoint when the widget
// renders, rather than serialised into the forum payload on every request.
(new Extend\Routes('api'))
->get('/linkrobins-html-widget', 'linkrobins-html-widget.show', ShowWidgetController::class),
(new Extend\Settings())
->default('linkrobins-html-widget.title', '')
->default('linkrobins-html-widget.icon', '')
->default('linkrobins-html-widget.body', '')
->default('linkrobins-html-widget.backgroundColor', ''),
];