69
pack.php
69
pack.php
@@ -129,8 +129,9 @@ function extractPhpCode(string $filePath, bool $minify = false): string {
|
||||
// Remove namespace declarations (we'll inline everything)
|
||||
$content = preg_replace('/namespace\s+[^;]+;\s*/i', '', $content);
|
||||
|
||||
// Remove use statements (we'll use fully qualified names)
|
||||
$content = preg_replace('/use\s+[^;]+;\s*/i', '', $content);
|
||||
// Remove namespace use/import statements (we'll use fully qualified names)
|
||||
// Only match 'use' at the start of a line (namespace imports), not closure 'use' clauses
|
||||
$content = preg_replace('/^use\s+[A-Z\\\\][^;]*;\s*/im', '', $content);
|
||||
|
||||
if ($minify) {
|
||||
// Remove multi-line comments but preserve strings
|
||||
@@ -302,38 +303,64 @@ $output .= <<<'BOOTSTRAP'
|
||||
// BOOTSTRAP
|
||||
// ============================================================================
|
||||
|
||||
// Override View class to use embedded views
|
||||
class AleShell2_PackedView extends AleShell2_View {
|
||||
public function render(string $template, array $data = []): string {
|
||||
// Packed View class for embedded views (standalone, not extending AleShell2_View)
|
||||
class AleShell2_PackedView {
|
||||
private static array $sharedData = [];
|
||||
|
||||
public static function share(string $key, mixed $value): void {
|
||||
self::$sharedData[$key] = $value;
|
||||
}
|
||||
|
||||
public static function render(string $view, array $data = []): string {
|
||||
global $ALESHELL_VIEWS;
|
||||
|
||||
$templateKey = $template;
|
||||
$templateKey = $view;
|
||||
|
||||
if (!isset($ALESHELL_VIEWS[$templateKey])) {
|
||||
return "View not found: {$template}";
|
||||
return "View not found: {$view}";
|
||||
}
|
||||
|
||||
$viewContent = $ALESHELL_VIEWS[$templateKey];
|
||||
|
||||
// Merge shared data
|
||||
$data = array_merge(self::$sharedData, $data);
|
||||
|
||||
// Extract data to local scope
|
||||
extract($data);
|
||||
extract($data, EXTR_SKIP);
|
||||
|
||||
// Capture output
|
||||
ob_start();
|
||||
eval('?>' . $viewContent);
|
||||
$content = ob_get_clean();
|
||||
|
||||
// If using layout, wrap content
|
||||
if ($template !== 'layouts.main' && $template !== 'auth.login') {
|
||||
if (isset($ALESHELL_VIEWS['layouts.main'])) {
|
||||
$layoutContent = $ALESHELL_VIEWS['layouts.main'];
|
||||
ob_start();
|
||||
eval('?>' . $layoutContent);
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
public static function renderWithLayout(string $view, string $layout = 'layouts.main', array $data = []): string {
|
||||
$data['content'] = self::render($view, $data);
|
||||
return self::render($layout, $data);
|
||||
}
|
||||
|
||||
public static function partial(string $partial, array $data = []): string {
|
||||
return self::render('components.' . $partial, $data);
|
||||
}
|
||||
|
||||
public static function e(string $value): string {
|
||||
return htmlspecialchars($value, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
}
|
||||
|
||||
public static function formatBytes(int $bytes, int $precision = 2): string {
|
||||
return AleShell2_View::formatBytes($bytes, $precision);
|
||||
}
|
||||
|
||||
public static function formatTime(int $timestamp, string $format = 'Y-m-d H:i:s'): string {
|
||||
return AleShell2_View::formatTime($timestamp, $format);
|
||||
}
|
||||
|
||||
public static function fileIcon(string $filename, bool $isDirectory = false): string {
|
||||
return AleShell2_View::fileIcon($filename, $isDirectory);
|
||||
}
|
||||
|
||||
public static function highlightLang(string $filename): string {
|
||||
return AleShell2_View::highlightLang($filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class SystemController extends BaseController
|
||||
$this->render($response, 'modules.system', [
|
||||
'currentModule' => 'system',
|
||||
'pageTitle' => 'System Info - AleShell2',
|
||||
'systemInfo' => $this->getSystemInfo(),
|
||||
'systemInfo' => $this->getDetailedSystemInfo(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class SystemController extends BaseController
|
||||
*/
|
||||
public function info(Request $request, Response $response, array $params): void
|
||||
{
|
||||
$this->success($response, $this->getSystemInfo());
|
||||
$this->success($response, $this->getDetailedSystemInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,9 +88,9 @@ class SystemController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect all system information
|
||||
* Collect all system information (detailed)
|
||||
*/
|
||||
private function getSystemInfo(): array
|
||||
private function getDetailedSystemInfo(): array
|
||||
{
|
||||
return [
|
||||
'server' => $this->getServerInfo(),
|
||||
@@ -119,7 +119,7 @@ class SystemController extends BaseController
|
||||
'current_uid' => getmyuid(),
|
||||
'current_gid' => getmygid(),
|
||||
'process_id' => getmypid(),
|
||||
'uptime' => $this->getUptime(),
|
||||
'uptime' => $this->getDetailedUptime(),
|
||||
'load_average' => $this->getLoadAverage(),
|
||||
];
|
||||
}
|
||||
@@ -283,20 +283,20 @@ class SystemController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system uptime
|
||||
* Get detailed system uptime
|
||||
*/
|
||||
private function getUptime(): string
|
||||
private function getDetailedUptime(): string
|
||||
{
|
||||
if (is_readable('/proc/uptime')) {
|
||||
$uptime = (float)explode(' ', file_get_contents('/proc/uptime'))[0];
|
||||
return $this->formatUptime($uptime);
|
||||
return $this->formatDetailedUptime($uptime);
|
||||
}
|
||||
|
||||
if (PHP_OS_FAMILY === 'Darwin') {
|
||||
$boottime = shell_exec('sysctl -n kern.boottime 2>/dev/null');
|
||||
if (preg_match('/sec = (\d+)/', $boottime, $matches)) {
|
||||
$uptime = time() - (int)$matches[1];
|
||||
return $this->formatUptime($uptime);
|
||||
return $this->formatDetailedUptime($uptime);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,9 +304,9 @@ class SystemController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* Format uptime seconds to human readable
|
||||
* Format uptime seconds to human readable (detailed)
|
||||
*/
|
||||
private function formatUptime(float $seconds): string
|
||||
private function formatDetailedUptime(float $seconds): string
|
||||
{
|
||||
$days = floor($seconds / 86400);
|
||||
$hours = floor(($seconds % 86400) / 3600);
|
||||
@@ -338,18 +338,4 @@ class SystemController extends BaseController
|
||||
|
||||
return ['1min' => 'unknown', '5min' => 'unknown', '15min' => 'unknown'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Format bytes to human readable
|
||||
*/
|
||||
private function formatBytes(int $bytes, int $precision = 2): string
|
||||
{
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, $precision) . ' ' . $units[$i];
|
||||
}
|
||||
}
|
||||
|
||||
Referencia en una nueva incidencia
Block a user