-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
149 lines (131 loc) · 5.14 KB
/
Copy pathinit.php
File metadata and controls
149 lines (131 loc) · 5.14 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
/**
* Logs Viewer plugin bootstrap.
*/
declare(strict_types=1);
$rootDir = defined('ROOT_DIR') ? ROOT_DIR : dirname(__DIR__, 2);
require_once $rootDir . '/engine/core/support/base/BasePlugin.php';
require_once $rootDir . '/engine/core/support/helpers/UrlHelper.php';
if (! function_exists('addHook')) {
require_once $rootDir . '/engine/includes/functions.php';
}
// Загружаем ClassAutoloader для регистрации классов
if (file_exists($rootDir . '/engine/core/system/ClassAutoloader.php')) {
require_once $rootDir . '/engine/core/system/ClassAutoloader.php';
}
// Загружаем сервис для работы с логами
$logsServiceFile = dirname(__FILE__) . '/src/Services/LogsService.php';
if (file_exists($logsServiceFile)) {
require_once $logsServiceFile;
}
class LogsViewPlugin extends BasePlugin
{
private string $pluginDir;
public function __construct()
{
parent::__construct();
$reflection = new ReflectionClass($this);
$this->pluginDir = dirname($reflection->getFileName());
}
public function init(): void
{
addHook('admin_register_routes', [$this, 'registerAdminRoute'], 10, 1);
addFilter('admin_menu', [$this, 'registerAdminMenu'], 15);
addFilter('settings_categories', [$this, 'registerSettingsCategory'], 10);
}
public function registerAdminRoute($router): void
{
$pageFile = $this->pluginDir . '/src/admin/pages/LogsViewAdminPage.php';
if (file_exists($pageFile)) {
// Регистрируем класс в автозагрузчике
if (isset($GLOBALS['engineAutoloader'])) {
$autoloader = $GLOBALS['engineAutoloader'];
if ($autoloader instanceof ClassAutoloader ||
(is_object($autoloader) && method_exists($autoloader, 'addClassMap'))) {
$autoloader->addClassMap([
'LogsViewAdminPage' => $pageFile
]);
}
}
require_once $pageFile;
if (class_exists('LogsViewAdminPage')) {
$router->add(['GET', 'POST'], 'logs-view', 'LogsViewAdminPage');
}
}
}
/**
* @param array<int, array<string, mixed>> $menu
*/
public function registerAdminMenu(array $menu): array
{
// Ищем существующее меню "Система"
$found = false;
foreach ($menu as &$item) {
if (isset($item['page']) && $item['page'] === 'system') {
if (!isset($item['submenu'])) {
$item['submenu'] = [];
}
$item['submenu'][] = [
'text' => 'Логи',
'icon' => 'fas fa-file-alt',
'href' => UrlHelper::admin('logs-view'),
'page' => 'logs-view',
'order' => 1,
'permission' => 'admin.logs.view',
];
$found = true;
break;
}
}
// Если меню "Система" не найдено, создаем его
if (!$found) {
$menu[] = [
'text' => 'Система',
'icon' => 'fas fa-server',
'href' => '#',
'page' => 'system',
'order' => 60,
'permission' => null,
'submenu' => [
[
'text' => 'Логи',
'icon' => 'fas fa-file-alt',
'href' => UrlHelper::admin('logs-view'),
'page' => 'logs-view',
'order' => 1,
'permission' => 'admin.logs.view',
],
],
];
}
return $menu;
}
/**
* Реєстрація в категоріях налаштувань
*
* Додає плагін до категорії "Система" на сторінці /admin/settings
*
* @param array<string, mixed> $categories Поточні категорії
* @return array<string, mixed> Оновлені категорії
*/
public function registerSettingsCategory(array $categories): array
{
// Перевіряємо, чи плагін активний
$pluginManager = function_exists('pluginManager') ? pluginManager() : null;
if (!$pluginManager || !method_exists($pluginManager, 'isPluginActive') || !$pluginManager->isPluginActive('logs-view')) {
return $categories;
}
// Додаємо до категорії "Система"
if (isset($categories['system'])) {
$categories['system']['items'][] = [
'title' => 'Логи',
'description' => 'Перегляд системних логів',
'url' => UrlHelper::admin('logs-view'),
'icon' => 'fas fa-file-alt',
'permission' => 'admin.logs.view',
];
}
return $categories;
}
}
return new LogsViewPlugin();