forked from kajla/errorpages
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompile.php
More file actions
66 lines (61 loc) · 1.84 KB
/
Copy pathcompile.php
File metadata and controls
66 lines (61 loc) · 1.84 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$translations = require_once(__DIR__ . '/translations.php');
$themes = [];
$themeIterator = new DirectoryIterator(__DIR__ . '/themes');
foreach ($themeIterator as $theme) {
if ($theme->isDir() && !$theme->isDot()) {
$themes[] = $theme->getFilename();
}
}
$statusCodes = [
400,
401,
403,
404,
405,
406,
408,
413,
414,
417,
500,
502,
503,
504,
];
foreach ($themes as $theme) {
$loader = new Twig_Loader_Filesystem([__DIR__ . '/themes/' . $theme], __DIR__ . '/themes/' . $theme);
$twig = new Twig_Environment($loader, ['debug' => true]);
$twig->addExtension(new Twig_Extension_Debug());
foreach ($statusCodes as $statusCode) {
if (
file_exists(__DIR__ . '/themes/' . $theme . '/' . $statusCode . '.html.twig') &&
array_key_exists($statusCode, $translations['errorPages'])
) {
$data = $translations['errorPages'][$statusCode];
$data['languageCodes'] = array_keys($translations['languages']);
$data['languages'] = $translations['languages'];
$data['defaultLanguageCode'] = 'en';
$data['statusCode'] = $statusCode;
if (!file_exists(__DIR__ . '/compiled/' . $theme)) {
mkdir(__DIR__ . '/compiled/' . $theme);
}
file_put_contents(
__DIR__ . '/compiled/' . $theme . '/' . $statusCode . '.html',
$twig->render($statusCode . '.html.twig', $data)
);
foreach ($translations['languages'] as $languageCode => $languageName) {
$data = $translations['errorPages'][$statusCode];
$data['languageCodes'] = [$languageCode];
$data['languages'] = [$languageCode => $languageName];
$data['defaultLanguageCode'] = $languageCode;
$data['statusCode'] = $statusCode;
file_put_contents(
__DIR__ . '/compiled/' . $theme . '/' . $statusCode . '.' . $languageCode . '.html',
$twig->render($statusCode . '.html.twig', $data)
);
}
}
}
}