From 1974cb5217afb68bb52ec4887d05c7aadc2399c4 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Tue, 22 Feb 2022 11:37:30 +0100 Subject: [PATCH] do updatecheck Signed-off-by: Michael Kaufmann --- lib/Froxlor/Ajax/Ajax.php | 9 ++++++++- lib/Froxlor/UI/Response.php | 19 +++++++++++++------ templates/Froxlor/misc/alert.html.twig | 2 +- templates/Froxlor/misc/version_top.html.twig | 8 ++++++++ .../Froxlor/src/js/components/updatecheck.js | 12 +++--------- templates/Froxlor/userarea.html.twig | 7 +++---- 6 files changed, 36 insertions(+), 21 deletions(-) create mode 100644 templates/Froxlor/misc/version_top.html.twig diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index cc74e529..11aa92e6 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -1,4 +1,5 @@ addGlobal('s', $this->session); + // TODO: set variables from current session try { - return \Froxlor\Api\Commands\Froxlor::getLocal([ + $json_result = \Froxlor\Api\Commands\Froxlor::getLocal([ 'adminid' => 1, 'adminsession' => 1, 'change_serversettings' => 1, 'loginname' => 'updatecheck' ])->checkUpdate(); + $result = json_decode($json_result, true)['data']; + echo UI::twig()->render($this->theme . '/misc/version_top.html.twig', $result); + exit; } catch (Exception $e) { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } diff --git a/lib/Froxlor/UI/Response.php b/lib/Froxlor/UI/Response.php index 63450b39..4353353c 100644 --- a/lib/Froxlor/UI/Response.php +++ b/lib/Froxlor/UI/Response.php @@ -132,15 +132,22 @@ class Response public static function dynamic_error($message) { - global $userinfo, $s, $header, $footer, $lng, $theme; + global $lng; $_SESSION['requestData'] = $_POST; - $link = ''; + $link_ref = ''; if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) !== false) { - $link = '' . $lng['panel']['back'] . ''; + $link_ref = htmlentities($_SERVER['HTTP_REFERER']); } - $error = $message; - eval("echo \"" . Template::getTemplate('misc/error', '1') . "\";"); - exit(); + + \Froxlor\UI\Panel\UI::twigBuffer('misc/alert.html.twig', [ + 'type' => 'danger', + 'btntype' => 'light', + 'heading' => $lng['error']['error'], + 'alert_msg' => $message, + 'redirect_link' => $link_ref + ]); + \Froxlor\UI\Panel\UI::twigOutputBuffer(); + exit; } /** diff --git a/templates/Froxlor/misc/alert.html.twig b/templates/Froxlor/misc/alert.html.twig index 00e4dba3..b6d910eb 100644 --- a/templates/Froxlor/misc/alert.html.twig +++ b/templates/Froxlor/misc/alert.html.twig @@ -18,7 +18,7 @@ {% endif %} {% if redirect_link %}

- {% if type == 'danger' %}{{ lng('panel.back') }}{% else %}{{ lng('success.clickheretocontinue') }}{% endif %} + {% if type == 'danger' %}{{ lng('panel.back') }}{% else %}{{ lng('success.clickheretocontinue') }}{% endif %}

{% endif %} diff --git a/templates/Froxlor/misc/version_top.html.twig b/templates/Froxlor/misc/version_top.html.twig new file mode 100644 index 00000000..0870a770 --- /dev/null +++ b/templates/Froxlor/misc/version_top.html.twig @@ -0,0 +1,8 @@ + + {% if isnewerversion == 0 %} + + {% else %} + + {% endif %} + {{ version }} + diff --git a/templates/Froxlor/src/js/components/updatecheck.js b/templates/Froxlor/src/js/components/updatecheck.js index 0b0d2d72..866bb4dc 100644 --- a/templates/Froxlor/src/js/components/updatecheck.js +++ b/templates/Froxlor/src/js/components/updatecheck.js @@ -3,21 +3,15 @@ $(document).ready(function () { * updatecheck */ if (document.getElementById('updatecheck')) { - let role = ""; - - if (typeof $("#updatecheck").data("role") !== "undefined") { - role = "&role=" + $("#newsfeed").data("role"); - } - $.ajax({ - url: "lib/ajax.php?action=updatecheck" + role + "&theme=" + window.$theme + "&s=" + window.$session, + url: "lib/ajax.php?action=updatecheck&theme=" + window.$theme + "&s=" + window.$session, type: "GET", success: function (data) { - $("#newsfeeditems").html(data); + $("#updatecheck").html(data); }, error: function (request, status, error) { console.log(request, status, error) - $("#newsfeeditems").html(''); + $("#updatecheck").html(''); } }); } diff --git a/templates/Froxlor/userarea.html.twig b/templates/Froxlor/userarea.html.twig index 6f934a32..9f77c761 100644 --- a/templates/Froxlor/userarea.html.twig +++ b/templates/Froxlor/userarea.html.twig @@ -32,11 +32,10 @@