forked from reficul/toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.php
More file actions
executable file
·201 lines (178 loc) · 5.29 KB
/
Application.php
File metadata and controls
executable file
·201 lines (178 loc) · 5.29 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
/**
* @brief Dev Toolbox: Base Application Class
* @author -storm_author-
* @copyright -storm_copyright-
* @package Invision Community
* @subpackage Dev Toolbox: Base
* @since 02 Apr 2018
* @version -storm_version-
*/
namespace IPS\toolbox;
use IPS\Application;
use IPS\Output;
use IPS\Theme;
use const IPS\ROOT_PATH;
use function array_merge;
use function is_array;
use function ob_end_clean;
use function ob_get_clean;
use function ob_start;
use function preg_replace_callback;
use function str_replace;
/**
* Dev Toolbox: Base Application Class
*/
class _Application extends Application
{
public static $toolBoxApps = [
'toolbox',
'toolbox',
'dtproxy',
'dtprofiler',
];
/**
* @var string
*/
protected static $baseDir = \IPS\ROOT_PATH . '/applications/toolbox/sources/vendor/';
protected static $loaded = \false;
public static function loadAutoLoader(): void
{
if (static::$loaded === \false) {
static::$loaded = \true;
require static::$baseDir . '/autoload.php';
\IPS\IPS::$PSR0Namespaces['Generator'] = ROOT_PATH . '/applications/toolbox/sources/Generator/';
}
}
public static function templateSlasher($source)
{
$replace = [
'array_slice',
'boolval',
'chr',
'count',
'doubleval',
'floatval',
'func_get_args',
'func_get_args',
'func_num_args',
'get_called_class',
'get_class',
'gettype',
'in_array',
'intval',
'is_array',
'is_bool',
'is_double',
'is_float',
'is_int',
'is_integer',
'is_long',
'is_null',
'is_numeric',
'is_object',
'is_real',
'is_resource',
'is_string',
'ord',
'strval',
'function_exists',
'is_callable',
'extension_loaded',
'dirname',
'constant',
'define',
'call_user_func',
'call_user_func_array',
];
foreach ($replace as $value) {
$rep = '\\' . $value;
$callback = function ($m) use ($rep) {
return $rep;
};
$source = preg_replace_callback("#(?<!\\\\)\b" . $value . '\b#u', $callback, $source);
$source = str_replace(
['function \\', 'const \\', "::\\", "$\\", "->\\"],
[
'function ',
'const ',
'::',
'$',
'->',
],
$source
);
}
return $source;
}
public static function addJsVar(array $jsVars): void
{
foreach ($jsVars as $key => $jsVar) {
Output::i()->jsVars[$key] = $jsVar;
}
}
public static function addJs($js, $location = 'front', $app = 'toolbox'): void
{
if (!is_array($js)) {
$js = [$js];
}
$jsFiles[] = Output::i()->jsFiles;
foreach ($js as $file) {
$file .= '.js';
$jsFiles[] = Output::i()->js($file, $app, $location);
}
Output::i()->jsFiles = array_merge(...$jsFiles);
}
public static function getAdminer()
{
\IPS\toolbox\Application::addCss(['adminer']);
$_GET["username"] = "michael";
$content = '<div id="toolboxAdminer">';
ob_start();
include(\IPS\ROOT_PATH . '/applications/toolbox/sources/Profiler/Adminer.php');
$content .= ob_get_clean();
ob_end_clean();
$content .= "</div>";
return $content;
}
public static function addCss($css, $location = 'front', $app = 'toolbox'): void
{
if (!is_array($css)) {
$css = [$css];
}
$cssFiles[] = Output::i()->cssFiles;
foreach ($css as $file) {
$file .= '.css';
$cssFiles[] = Theme::i()->css($file, $app, $location);
}
Output::i()->cssFiles = array_merge(...$cssFiles);
}
public static function specialHooks()
{
$apps = array();
foreach (static::applications() as $application) {
if (\count($application->extensions('toolbox', 'SpecialHooks'))) {
$apps[$application->directory] = $application;
}
}
return $apps;
}
public static function getThemeId()
{
$location = \IPS\Dispatcher::hasInstance() ? \IPS\Dispatcher::i()->controllerLocation : null;
if (isset(\IPS\Request::i()->admin) && \IPS\Request::i()->admin === 1) {
$location = 'admin';
}
if ($location === 'admin' && \defined('DT_THEME_ID_ADMIN') && DT_THEME_ID_ADMIN !== 0) {
return DT_THEME_ID_ADMIN;
}
return DT_THEME_ID;
}
/**
* @inheritdoc
*/
protected function get__icon()
{
return 'wrench';
}
}