diff options
author | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:38:16 +0200 |
---|---|---|
committer | Minteck <nekostarfan@gmail.com> | 2021-08-24 15:38:16 +0200 |
commit | 529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105 (patch) | |
tree | 8a50c30271b9b328cde0d907b1441f2dabdc341b /Neutron-trunk/api/engine-cyclic/includes | |
parent | 15e4724761c50b30803df1811a525c85058f70bf (diff) | |
download | electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.tar.gz electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.tar.bz2 electrode-529ffcbfa97ab51a64a97f6dff08aeb2bc0cc105.zip |
Update
Diffstat (limited to 'Neutron-trunk/api/engine-cyclic/includes')
4 files changed, 106 insertions, 0 deletions
diff --git a/Neutron-trunk/api/engine-cyclic/includes/cache.php b/Neutron-trunk/api/engine-cyclic/includes/cache.php new file mode 100644 index 0000000..80ea283 --- /dev/null +++ b/Neutron-trunk/api/engine-cyclic/includes/cache.php @@ -0,0 +1,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; +}
\ No newline at end of file diff --git a/Neutron-trunk/api/engine-cyclic/includes/getPageContent.php b/Neutron-trunk/api/engine-cyclic/includes/getPageContent.php new file mode 100644 index 0000000..31b202c --- /dev/null +++ b/Neutron-trunk/api/engine-cyclic/includes/getPageContent.php @@ -0,0 +1,14 @@ +<?php + +function getPageContent() { + rlgps("getPageContent() call"); + global $MPCMSRendererPageMarkup; + global $MPCMSRendererPageMarkupDN; + global $MPCMSRendererPageNameValue; + + if (isset($MPCMSRendererPageMarkup) && isset($MPCMSRendererPageMarkupDN)) { + return $MPCMSRendererPageMarkup; + } else { + return file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/pages/" . $MPCMSRendererPageNameValue); + } +}
\ No newline at end of file diff --git a/Neutron-trunk/api/engine-cyclic/includes/getPageName.php b/Neutron-trunk/api/engine-cyclic/includes/getPageName.php new file mode 100644 index 0000000..e364493 --- /dev/null +++ b/Neutron-trunk/api/engine-cyclic/includes/getPageName.php @@ -0,0 +1,18 @@ +<?php + +function getPageName() { + rlgps("getPageName() call"); + global $MPCMSRendererPageMarkup; + global $MPCMSRendererPageMarkupDN; + global $MPCMSRendererPageNameValue; + + if (isset($MPCMSRendererPageMarkup) && isset($MPCMSRendererPageMarkupDN)) { + return $MPCMSRendererPageMarkupDN; + } else { + if ($MPCMSRendererPageNameValue == "index") { + return file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/data/webcontent/sitename"); + } else { + return file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/" . $MPCMSRendererPageNameValue . "/pagename"); + } + } +}
\ No newline at end of file diff --git a/Neutron-trunk/api/engine-cyclic/includes/includes.php b/Neutron-trunk/api/engine-cyclic/includes/includes.php new file mode 100644 index 0000000..05f0f23 --- /dev/null +++ b/Neutron-trunk/api/engine-cyclic/includes/includes.php @@ -0,0 +1,4 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/api/engine-cyclic/includes/getPageName.php"; +require_once $_SERVER['DOCUMENT_ROOT'] . "/api/engine-cyclic/includes/getPageContent.php";
\ No newline at end of file |