From 68fcfd2cf5a3dd82b795e418ca831ee1bdc12fff Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 22 Apr 2022 13:52:08 +0200 Subject: [PATCH] fix ajax responses; re-add statistics link to main-domains for customers Signed-off-by: Michael Kaufmann --- lib/Froxlor/Ajax/Ajax.php | 8 +++++--- lib/Froxlor/Api/Response.php | 1 - lib/Froxlor/UI/Callbacks/Domain.php | 11 ++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index e5c8ee95..9af17e2d 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -121,11 +121,13 @@ class Ajax public function errorResponse($message, int $response_code = 500) { + header("Content-Type: application/json"); return \Froxlor\Api\Response::jsonErrorResponse($message, $response_code); } public function jsonResponse($value, int $response_code = 200) { + header("Content-Type: application/json"); return \Froxlor\Api\Response::jsonResponse($value, $response_code); } @@ -197,7 +199,7 @@ class Ajax ]); } - return $items; + return $this->jsonResponse($items); } else { return $this->errorResponse('No Newsfeeds available at the moment.'); } @@ -210,8 +212,8 @@ class Ajax try { $json_result = \Froxlor\Api\Commands\Froxlor::getLocal($this->userinfo)->checkUpdate(); $result = json_decode($json_result, true)['data']; - echo UI::twig()->render($this->theme . '/misc/version_top.html.twig', $result); - exit; + $result = UI::twig()->render($this->theme . '/misc/version_top.html.twig', $result); + return $this->jsonResponse($result); } catch (Exception $e) { // don't display anything if just not allowed due to permissions if ($e->getCode() != 403) { diff --git a/lib/Froxlor/Api/Response.php b/lib/Froxlor/Api/Response.php index c03d4b29..1ebae861 100644 --- a/lib/Froxlor/Api/Response.php +++ b/lib/Froxlor/Api/Response.php @@ -21,7 +21,6 @@ class Response { public static function jsonResponse($data = null, int $response_code = 200) { - header("Content-Type: application/json"); http_response_code($response_code); return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT); diff --git a/lib/Froxlor/UI/Callbacks/Domain.php b/lib/Froxlor/UI/Callbacks/Domain.php index 42c9e4c9..ae556c3a 100644 --- a/lib/Froxlor/UI/Callbacks/Domain.php +++ b/lib/Froxlor/UI/Callbacks/Domain.php @@ -63,7 +63,16 @@ class Domain public static function domainExternalLink(array $attributes) { - return '' . $attributes['data'] . ''; + $result = '' . $attributes['data'] . ''; + // check for statistics if parentdomainid==0 to show stats-link for customers + if ((int) UI::getCurrentUser()['adminsession'] == 0 && $attributes['fields']['parentdomainid'] == 0) { + $statsapp = 'webalizer'; + if (Settings::Get('system.awstats_enabled') == '1') { + $statsapp = 'awstats'; + } + $result .= ' '; + } + return $result; } public static function canEdit(array $attributes): bool