2024.8.23
Loading...
Searching...
No Matches
ajax.nodejs.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
10
global
$bearsamppBins
,
$bearsamppLang
;
11
12
/**
13
* This script generates a JSON-encoded array containing the status and versions of Node.js.
14
* It checks if Node.js is enabled and sets the status accordingly.
15
* Then, it loops through the Node.js version list, adding versions to the 'versions' key.
16
* Finally, it encodes the result array into a JSON format and echoes it.
17
*
18
* @global object $bearsamppBins Provides access to various binaries including Node.js.
19
* @global object $bearsamppLang Provides access to language strings for localization.
20
*
21
* @return void
22
*/
23
$result
= array(
24
'status'
=>
''
,
25
'versions'
=>
''
26
);
27
28
// Status
29
/**
30
* Checks if Node.js is enabled and sets the status in the result array.
31
* If enabled, sets the status to a success badge with the 'ENABLED' label.
32
* If disabled, sets the status to a danger badge with the 'DISABLED' label.
33
*/
34
if
(
$bearsamppBins
->getNodejs()->isEnable()) {
35
$result
[
'status'
] =
'<span class="float-end badge text-bg-success">'
.
$bearsamppLang
->getValue(
Lang::ENABLED
) .
'</span>'
;
36
}
else
{
37
$result
[
'status'
] =
'<span class="float-end badge text-bg-danger">'
.
$bearsamppLang
->getValue(
Lang::DISABLED
) .
'</span>'
;
38
}
39
40
// Versions
41
/**
42
* Loops through the list of Node.js versions and adds them to the 'versions' key in the result array.
43
* The current version is highlighted with a primary badge, while other versions are shown with a secondary badge.
44
*/
45
foreach
(
$bearsamppBins
->getNodejs()->getVersionList() as $version) {
46
if
($version !=
$bearsamppBins
->getNodejs()->getVersion()) {
47
$result
[
'versions'
] .=
'<span class="m-1 badge text-bg-secondary">'
. $version .
'</span>'
;
48
}
else
{
49
$result
[
'versions'
] .=
'<span class="m-1 badge text-bg-primary">'
.
$bearsamppBins
->getNodejs()->getVersion() .
'</span>'
;
50
}
51
}
52
53
// Output the result as a JSON-encoded string
54
echo json_encode(
$result
);
$result
$result
Definition
ajax.nodejs.php:23
$bearsamppBins
global $bearsamppBins
Definition
ajax.nodejs.php:10
$bearsamppLang
global $bearsamppLang
Definition
ajax.nodejs.php:10
Lang\ENABLED
const ENABLED
Definition
class.lang.php:42
Lang\DISABLED
const DISABLED
Definition
class.lang.php:36
Bearsampp-development
sandbox
core
resources
homepage
ajax
ajax.nodejs.php
Generated by
1.11.0