-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.php
81 lines (65 loc) · 2.16 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* This file is part of the phpCacheAdmin.
* Copyright (c) Róbert Kelčák (https://kelcak.com/)
*/
declare(strict_types=1);
use Composer\InstalledVersions;
use RobiNN\Pca\Admin;
use RobiNN\Pca\Config;
use RobiNN\Pca\Http;
use RobiNN\Pca\Template;
if (PHP_VERSION_ID < 80200) {
exit('<strong>PHP >= 8.2 is required.</strong><br>The current version of php is: '.PHP_VERSION);
}
// Always display errors
ini_set('display_errors', 'On');
ini_set('display_startup_errors', 'On');
error_reporting(E_ALL);
$path = __DIR__.'/';
if (is_file(__DIR__.'/vendor/autoload.php')) {
require_once __DIR__.'/vendor/autoload.php';
if (!extension_loaded('redis') &&
InstalledVersions::isInstalled('predis/predis') === false &&
is_file($path.'predis.phar')
) {
require_once 'phar://'.$path.'predis.phar/vendor/autoload.php';
}
} else {
require_once __DIR__.'/src/functions.php';
autoload($path);
}
if (is_callable(Config::get('auth'))) {
Config::get('auth')();
$auth = true;
}
$tpl = new Template();
$admin = new Admin($tpl);
$nav = array_map(static fn ($d_dashboard) => $d_dashboard->dashboardInfo(), $admin->dashboards);
$current = $admin->currentDashboard();
$dashboard = $admin->getDashboard($current);
$info = $dashboard->dashboardInfo();
$tpl->addGlobal('current', $current);
if (isset($_GET['ajax'])) {
echo $dashboard->ajax();
} else {
if (isset($_GET['moreinfo']) || isset($_GET['form']) || isset($_GET['view'], $_GET['key'])) {
$back_url = Http::queryString(['db', 's']);
}
if (isset($info['colors'])) {
$colors = '';
foreach ((array) $info['colors'] as $key => $color) {
$colors .= '--primary-color-'.$key.':'.$color.';';
}
}
echo $tpl->render('layout', [
'colors' => $colors ?? null,
'site_title' => $info['title'],
'nav' => $nav,
'logout_url' => isset($auth) ? Http::queryString([], ['logout' => 'yes']) : null,
'version' => Admin::VERSION,
'repo' => 'https://github.com/RobiNN1/phpCacheAdmin',
'back_url' => $back_url ?? null,
'dashboard' => $dashboard->dashboard(),
]);
}