Skip to content

Commit dd49847

Browse files
Flarum 1.3 support
1 parent 77127f9 commit dd49847

8 files changed

+636
-5
lines changed

app/Console/Commands/GetCoreJavascriptHash.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected function getHashForFrontend(string $tag, string $frontend): string
2020
{
2121
$client = new Client();
2222

23-
$response = $client->get("https://raw.githubusercontent.com/flarum/core/$tag/js/dist/$frontend.js");
23+
$response = $client->get("https://raw.githubusercontent.com/flarum/flarum-core/$tag/js/dist/$frontend.js");
2424

2525
return md5(trim(str_replace("//# sourceMappingURL=$frontend.js.map", '', $response->getBody()->getContents())));
2626
}

app/FlarumVersion.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class FlarumVersion
2727
const V1_1_1 = "1.1.1";
2828
const V1_2_0 = "1.2.0";
2929
const V1_2_1 = "1.2.1";
30+
const V1_3_0 = "1.3.0";
3031

3132
// MD5 hash of the javascript of Flarum core, excluding the sourcemap declaration
3233
// Obtained through the GetCoreJavascriptHash command
@@ -45,8 +46,9 @@ class FlarumVersion
4546
'210e1cab71dfa71126a6dfbe8f5f6dff' => self::V1_0_2,
4647
'7fd38d2d84278f0c3aa30ea7d5eab99b' => [self::V1_0_3, self::V1_0_4],
4748
'c3d9c002b7b0b12c3c967723ac41ec77' => [self::V1_1_0, self::V1_1_1],
48-
'7ce80a4947d0a9d3ed59f1c983d6306c' => [self::V1_2_0],
49-
'0cfd2788d28051b38e4b01683f6d025f' => [self::V1_2_1],
49+
'7ce80a4947d0a9d3ed59f1c983d6306c' => self::V1_2_0,
50+
'0cfd2788d28051b38e4b01683f6d025f' => self::V1_2_1,
51+
'a51d05b5a8f67394a0670595ed7339b8' => self::V1_3_0,
5052
];
5153

5254
public array $adminJavascriptHashes = [
@@ -64,8 +66,9 @@ class FlarumVersion
6466
'db21719109058a04bc1fbb2bfb5b35a7' => self::V1_0_1,
6567
'40083f039fe8ec6990aa9fe5095707fa' => [self::V1_0_3, self::V1_0_4],
6668
'74fc375900d66b7c4f14a4aead2febc2' => [self::V1_1_0, self::V1_1_1],
67-
'd2f45e06f2914e9347c95a440e31ac6c' => [self::V1_2_0],
68-
'd57482968b44be46067c3502097394c1' => [self::V1_2_1],
69+
'd2f45e06f2914e9347c95a440e31ac6c' => self::V1_2_0,
70+
'd57482968b44be46067c3502097394c1' => self::V1_2_1,
71+
'10e94240d3c29d41e9a35b439f6ad812' => self::V1_3_0,
6972
];
7073

7174
public static function isBeta7(array $versions): bool

app/FlarumVersionGuesser.php

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function guess(string $html, string $bootScript): array
1919
FlarumVersion::V1_1_1,
2020
FlarumVersion::V1_2_0,
2121
FlarumVersion::V1_2_1,
22+
FlarumVersion::V1_3_0,
2223
];
2324
}
2425

tests/Unit/FlarumVersionGuesserTest.php

+15
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ function testV110Typical()
497497
FlarumVersion::V1_1_1,
498498
FlarumVersion::V1_2_0,
499499
FlarumVersion::V1_2_1,
500+
FlarumVersion::V1_3_0,
500501
], $this->guesser->guess($html, $html));
501502
}
502503

@@ -509,6 +510,20 @@ function testV120Typical()
509510
FlarumVersion::V1_1_1,
510511
FlarumVersion::V1_2_0,
511512
FlarumVersion::V1_2_1,
513+
FlarumVersion::V1_3_0,
514+
], $this->guesser->guess($html, $html));
515+
}
516+
517+
function testV130Typical()
518+
{
519+
$html = file_get_contents(__DIR__ . '/version-guesser/1.3.0-typical.html');
520+
521+
$this->assertEquals([
522+
FlarumVersion::V1_1_0,
523+
FlarumVersion::V1_1_1,
524+
FlarumVersion::V1_2_0,
525+
FlarumVersion::V1_2_1,
526+
FlarumVersion::V1_3_0,
512527
], $this->guesser->guess($html, $html));
513528
}
514529
}

tests/Unit/JavascriptParserTest.php

+84
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,90 @@
77

88
class JavascriptParserTest extends TestCase
99
{
10+
public function testV1_3ForumParser()
11+
{
12+
$parser = new Beta8JavascriptFileParser(file_get_contents(__DIR__ . '/javascript-parser/1.3.0-typical-forum.js'));
13+
14+
$this->assertEquals([
15+
[
16+
'id' => 'flarum-tags',
17+
'checksum' => '846a851c0effe893e242fb61b9c36526',
18+
'size' => 30651,
19+
'dev' => false,
20+
],
21+
[
22+
'id' => 'flarum-mentions',
23+
'checksum' => 'db03b46b5d689201a674066847f9b4d3',
24+
'size' => 17721,
25+
'dev' => false,
26+
],
27+
[
28+
'id' => 'flarum-markdown',
29+
'checksum' => '1ddf76fd6cff74620a166a185b3d6418',
30+
'size' => 4677,
31+
'dev' => false,
32+
],
33+
[
34+
'id' => 'flarum-lock',
35+
'checksum' => '8d6448bc17b0c9c9acc44df09b9a37e1',
36+
'size' => 3301,
37+
'dev' => false,
38+
],
39+
], $parser->extensions());
40+
41+
$this->assertEquals([
42+
[
43+
'id' => 'core',
44+
'checksum' => 'a51d05b5a8f67394a0670595ed7339b8',
45+
'size' => 396064,
46+
],
47+
[
48+
'id' => 'textformatter',
49+
'size' => 61113,
50+
],
51+
], $parser->coreSize());
52+
}
53+
54+
public function testV1_3AdminParser()
55+
{
56+
$parser = new Beta8JavascriptFileParser(file_get_contents(__DIR__ . '/javascript-parser/1.3.0-typical-admin.js'));
57+
58+
$this->assertEquals([
59+
[
60+
'id' => 'flarum-tags',
61+
'checksum' => '38457833be10b9c514ad5934526f72d7',
62+
'size' => 53189,
63+
'dev' => false,
64+
],
65+
[
66+
'id' => 'flarum-mentions',
67+
'checksum' => 'b8efed44245074019524f43a38a3906d',
68+
'size' => 931,
69+
'dev' => false,
70+
],
71+
[
72+
'id' => 'flarum-markdown',
73+
'checksum' => 'f6faab5d9b0976b333d617bfbf3eda08',
74+
'size' => 4677,
75+
'dev' => false,
76+
],
77+
[
78+
'id' => 'flarum-lock',
79+
'checksum' => '1e316a1cdeda0f2b33fd80c32390c191',
80+
'size' => 823,
81+
'dev' => false,
82+
],
83+
], $parser->extensions());
84+
85+
$this->assertEquals([
86+
[
87+
'id' => 'core',
88+
'checksum' => '10e94240d3c29d41e9a35b439f6ad812',
89+
'size' => 328291,
90+
],
91+
], $parser->coreSize());
92+
}
93+
1094
public function testV1_2ForumParser()
1195
{
1296
$parser = new Beta8JavascriptFileParser(file_get_contents(__DIR__ . '/javascript-parser/1.2.0-typical-forum.js'));

tests/Unit/javascript-parser/1.3.0-typical-admin.js

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Unit/javascript-parser/1.3.0-typical-forum.js

+372
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<!doctype html>
2+
<html dir="ltr" lang="en" >
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Flarum 1.3</title>
6+
7+
<link rel="stylesheet" href="http://1.3.flarum.localhost/assets/forum.css?v=9fc1de76">
8+
<link rel="canonical" href="http://1.3.flarum.localhost">
9+
<link rel="preload" href="http://1.3.flarum.localhost/assets/forum.css?v=9fc1de76" as="style">
10+
<link rel="preload" href="http://1.3.flarum.localhost/assets/forum.js?v=886bfd52" as="script">
11+
<link rel="preload" href="http://1.3.flarum.localhost/assets/forum-en.js?v=74b4cca2" as="script">
12+
<link rel="preload" href="http://1.3.flarum.localhost/assets/fonts/fa-solid-900.woff2" as="font" type="font/woff2" crossorigin="">
13+
<link rel="preload" href="http://1.3.flarum.localhost/assets/fonts/fa-regular-400.woff2" as="font" type="font/woff2" crossorigin="">
14+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
15+
<meta name="description" content="">
16+
<meta name="theme-color" content="#4D698E">
17+
</head>
18+
19+
<body>
20+
<div id="app" class="App">
21+
22+
<div id="app-navigation" class="App-navigation"></div>
23+
24+
<div id="drawer" class="App-drawer">
25+
26+
<header id="header" class="App-header">
27+
<div id="header-navigation" class="Header-navigation"></div>
28+
<div class="container">
29+
<h1 class="Header-title">
30+
<a href="http://1.3.flarum.localhost" id="home-link">
31+
Flarum 1.3
32+
</a>
33+
</h1>
34+
<div id="header-primary" class="Header-primary"></div>
35+
<div id="header-secondary" class="Header-secondary"></div>
36+
</div>
37+
</header>
38+
39+
</div>
40+
41+
<main class="App-content">
42+
<div id="content"></div>
43+
44+
<div id="flarum-loading" style="display: none">
45+
Loading...
46+
</div>
47+
48+
<noscript>
49+
<div class="Alert">
50+
<div class="container">
51+
This site is best viewed in a modern browser with JavaScript enabled.
52+
</div>
53+
</div>
54+
</noscript>
55+
56+
<div id="flarum-loading-error" style="display: none">
57+
<div class="Alert">
58+
<div class="container">
59+
Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.
60+
</div>
61+
</div>
62+
</div>
63+
64+
<noscript id="flarum-content">
65+
<div class="container">
66+
<h2>All Discussions</h2>
67+
68+
<ul>
69+
<li>
70+
<a href="http://1.3.flarum.localhost/d/1-hello-world">
71+
Hello World
72+
</a>
73+
</li>
74+
</ul>
75+
76+
77+
</div>
78+
79+
</noscript>
80+
81+
82+
<div class="App-composer">
83+
<div class="container">
84+
<div id="composer"></div>
85+
</div>
86+
</div>
87+
</main>
88+
89+
</div>
90+
91+
92+
93+
94+
<div id="modal"></div>
95+
<div id="alerts"></div>
96+
97+
<script>
98+
document.getElementById('flarum-loading').style.display = 'block';
99+
var flarum = {extensions: {}};
100+
</script>
101+
102+
<script src="http://1.3.flarum.localhost/assets/forum.js?v=886bfd52"></script>
103+
<script src="http://1.3.flarum.localhost/assets/forum-en.js?v=74b4cca2"></script>
104+
105+
<script>
106+
document.getElementById('flarum-loading').style.display = 'none';
107+
108+
try {
109+
flarum.core.app.load({"resources":[{"type":"forums","id":"1","attributes":{"title":"Flarum 1.3","description":"","showLanguageSelector":true,"baseUrl":"http:\/\/1.3.flarum.localhost","basePath":"","baseOrigin":"http:\/\/1.3.flarum.localhost","debug":false,"apiUrl":"http:\/\/1.3.flarum.localhost\/api","welcomeTitle":"Welcome to Flarum 1.3","welcomeMessage":"Enjoy your new forum! Hop over to discuss.flarum.org if you have any questions, or to join our community!","themePrimaryColor":"#4D698E","themeSecondaryColor":"#4D698E","logoUrl":null,"faviconUrl":null,"headerHtml":null,"footerHtml":null,"allowSignUp":true,"defaultRoute":"\/all","canViewForum":true,"canStartDiscussion":false,"canSearchUsers":false,"canBypassTagCounts":false,"minPrimaryTags":"1","maxPrimaryTags":"1","minSecondaryTags":"0","maxSecondaryTags":"3","allowUsernameMentionFormat":true},"relationships":{"groups":{"data":[{"type":"groups","id":"1"},{"type":"groups","id":"2"},{"type":"groups","id":"3"},{"type":"groups","id":"4"}]},"tags":{"data":[{"type":"tags","id":"1"}]}}},{"type":"groups","id":"1","attributes":{"nameSingular":"Admin","namePlural":"Admins","color":"#B72A2A","icon":"fas fa-wrench","isHidden":0}},{"type":"groups","id":"2","attributes":{"nameSingular":"Guest","namePlural":"Guests","color":null,"icon":null,"isHidden":0}},{"type":"groups","id":"3","attributes":{"nameSingular":"Member","namePlural":"Members","color":null,"icon":null,"isHidden":0}},{"type":"groups","id":"4","attributes":{"nameSingular":"Mod","namePlural":"Mods","color":"#80349E","icon":"fas fa-bolt","isHidden":0}},{"type":"tags","id":"1","attributes":{"name":"General","description":null,"slug":"general","color":"#888","backgroundUrl":null,"backgroundMode":null,"icon":null,"discussionCount":1,"position":0,"defaultSort":null,"isChild":false,"isHidden":false,"lastPostedAt":"2022-05-17T17:50:10+00:00","canStartDiscussion":false,"canAddToDiscussion":false}}],"session":{"userId":0,"csrfToken":"swQhP9VCndjXjHi4EtoaL2ltpltVKQBEOimNj1X0"},"locales":{"en":"English"},"locale":"en","apiDocument":{"links":{"first":"http:\/\/1.3.flarum.localhost\/api\/discussions?sort=\u0026page%5Blimit%5D=20"},"data":[{"type":"discussions","id":"1","attributes":{"title":"Hello World","slug":"1-hello-world","commentCount":1,"participantCount":1,"createdAt":"2022-05-17T17:50:10+00:00","lastPostedAt":"2022-05-17T17:50:10+00:00","lastPostNumber":1,"canReply":false,"canRename":false,"canDelete":false,"canHide":false,"canTag":false,"isLocked":false,"canLock":false},"relationships":{"user":{"data":{"type":"users","id":"1"}},"lastPostedUser":{"data":{"type":"users","id":"1"}},"tags":{"data":[{"type":"tags","id":"1"}]}}}],"included":[{"type":"users","id":"1","attributes":{"username":"Admin","displayName":"Admin","avatarUrl":null,"slug":"Admin"}},{"type":"tags","id":"1","attributes":{"name":"General","description":null,"slug":"general","color":"#888","backgroundUrl":null,"backgroundMode":null,"icon":null,"discussionCount":1,"position":0,"defaultSort":null,"isChild":false,"isHidden":false,"lastPostedAt":"2022-05-17T17:50:10+00:00","canStartDiscussion":false,"canAddToDiscussion":false}}]}});
110+
flarum.core.app.bootExtensions(flarum.extensions);
111+
flarum.core.app.boot();
112+
} catch (e) {
113+
var error = document.getElementById('flarum-loading-error');
114+
error.innerHTML += document.getElementById('flarum-content').textContent;
115+
error.style.display = 'block';
116+
throw e;
117+
}
118+
</script>
119+
120+
121+
</body>
122+
</html>

0 commit comments

Comments
 (0)