2024.8.23
Loading...
Searching...
No Matches
ajax.php.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/**
11 * Retrieves status, versions, extensions count, PEAR version, and extensions list information
12 * and returns it as a JSON-encoded array.
13 *
14 * This script checks the status of PHP (enabled or disabled), lists all PHP versions available,
15 * counts the total and loaded PHP extensions, retrieves the PEAR version, and compiles a list of PHP extensions
16 * with their respective statuses and versions. The output is JSON-encoded, making it suitable for use in web applications
17 * where such information might be displayed to the user.
18 *
19 * @global object $bearsamppBins Provides access to system binaries and their configurations.
20 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
21 *
22 * @return void Outputs a JSON string that can be parsed by JavaScript or other languages to display PHP configuration details.
23 */
25
26/**
27 * Generates a JSON-encoded array containing the status, versions, extension count, PEAR version, and a list of PHP extensions.
28 *
29 * @global object $bearsamppBins Provides access to system binaries and their configurations.
30 * @global object $bearsamppLang Provides language support for retrieving language-specific values.
31 *
32 * @return void Outputs a JSON string that can be parsed by JavaScript or other languages to display PHP configuration details.
33 */
34$result = array(
35 'status' => '',
36 'versions' => '',
37 'extscount' => '',
38 'pearversion' => '',
39 'extslist' => '',
40);
41
42/**
43 * Checks if PHP is enabled and sets the status in the result array.
44 */
45if ($bearsamppBins->getPhp()->isEnable()) {
46 $result['status'] = '<span class="float-end badge text-bg-success">' . $bearsamppLang->getValue(Lang::ENABLED) . '</span>';
47} else {
48 $result['status'] = '<span class="float-end badge text-bg-danger">' . $bearsamppLang->getValue(Lang::DISABLED) . '</span>';
49}
50
51/**
52 * Retrieves the list of PHP versions and sets it in the result array.
53 */
54foreach ($bearsamppBins->getPhp()->getVersionList() as $version) {
55 if ($version != $bearsamppBins->getPhp()->getVersion()) {
56 $result['versions'] .= '<span class="m-1 badge text-bg-secondary">' . $version . '</span>';
57 } else {
58 $result['versions'] .= '<span class="m-1 badge text-bg-primary">' . $bearsamppBins->getPhp()->getVersion() . '</span>';
59 }
60}
61
62/**
63 * Counts the total and loaded PHP extensions and sets the count in the result array.
64 */
65$exts = count($bearsamppBins->getPhp()->getExtensions());
66$extsLoaded = count($bearsamppBins->getPhp()->getExtensionsLoaded());
67$result['extscount'] .= '<span class="m-1 float-end badge text-bg-primary">' . $extsLoaded . ' / ' . $exts . '</span>';
68
69/**
70 * Retrieves the PEAR version and sets it in the result array.
71 */
72$result['pearversion'] .= '<span class="m-1 float-end badge text-bg-primary">' . $bearsamppBins->getPhp()->getPearVersion(true) . '</span>';
73
74/**
75 * Retrieves the list of PHP extensions from the configuration and sets it in the result array.
76 */
77foreach ($bearsamppBins->getPhp()->getExtensionsFromConf() as $extName => $extStatus) {
78 if ($extStatus == ActionSwitchPhpExtension::SWITCH_ON) {
79 $result['extslist'] .= '<span class="p-1 col-xs-12 col-md-2"><i class="fa-regular fa-circle-check"></i> <strong>' . $extName . ' <sup>' . phpversion(substr($extName, 4)) . '</sup></strong></span>';
80 } else {
81 $result['extslist'] .= '<span class="p-1 col-xs-12 col-md-2"><i class="fa-regular fa-circle"></i> ' . $extName . '</span>';
82 }
83}
84
85/**
86 * Outputs the result array as a JSON-encoded string.
87 */
88echo json_encode($result);
$result
Definition ajax.php.php:34
foreach($bearsamppBins->getPhp() ->getVersionList() as $version) $exts
Definition ajax.php.php:65
global $bearsamppBins
Definition ajax.php.php:24
global $bearsamppLang
Definition ajax.php.php:24
$extsLoaded
Definition ajax.php.php:66
const ENABLED
const DISABLED