blob: 80ea283a320a840e0355a366142a2f0054620f99 (
plain)
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
|
<?php
// Create cache dir
if (!file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache")) {
mkdir($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache");
}
function cacheCheck(string $page) {
/* // If something goes wrong, use cache anyway
$cache = true;
// Get a list of enabled widgets
$widgets = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/widgets.json"));
if (json_last_error() != JSON_ERROR_NONE) { // If data is corrupted, silently think there are no widgets
$list = [];
rlgps("Warning: Widget information is corrupted");
} else {
$list = $widgets->list;
}
// Check if there is (at least) one widget that disables cache
foreach ($list as $widget) {
$data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/widgets/$widget/feature.json"));
if (json_last_error() == JSON_ERROR_NONE) {
if (isset($data->cache)) {
if (is_bool($data->cache)) {
$cache = $data->cache;
if ($data->cache == false) {
rlgps("Widget \"$widget\" prevents the use of cache");
}
}
}
} else {
rlgps("Warning: Metadata for the widget \"$widget\" is corrupted");
}
}
// Check if an update has been installed
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/last_version")) {
if (file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/last_version") == file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/api/version")) {} else {
$cache = false;
require $_SERVER['DOCUMENT_ROOT'] . "/api/admin/cache_content_reset.php";
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/last_version", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/api/version"));
}
} else {
$cache = false;
require $_SERVER['DOCUMENT_ROOT'] . "/api/admin/cache_content_reset.php";
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/last_version", file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/api/version"));
}
// Is there any widget that disables cache?
if ($cache) { // no
// Does the cached version exists?
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/page-" . $page)) { // yes
header("X-FNS-NeutronCache: yes");
echo(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/cache/page-" . $page)); // So let's output it
require_once $_SERVER['DOCUMENT_ROOT'] . "/resources/private/debug.php";debugDump(); // And debug if needed
return true;
} else { // no
header("X-FNS-NeutronCache: no");
return false; // Let the engine-cyclic render the page
}
} else { // yes
header("X-FNS-NeutronCache: no");
return false; // Let the engine-cyclic render the page
} */
// Cache is now completely disabled due to problems
return false;
}
|