<?php

$demoDir = __DIR__;
$files = [];

foreach (scandir($demoDir) as $file) {
    if ($file === '.' || $file === '..' || $file === 'index.php') {
        continue;
    }

    $path = $demoDir . '/' . $file;

    if (!is_file($path) || !preg_match('/\.zip$/i', $file)) {
        continue;
    }

    $map = null;
    $timestamp = null;

    /*
     * Expected filename:
     * 2026-09-25_23-10-49_de_stmarc_hxi.zip
     *
     * Extracts:
     * Date: 2026-09-25
     * Time: 23:10:49
     * Map:  de_stmarc
     */
    if (preg_match(
        '/^(\d{4}-\d{2}-\d{2})_(\d{2}-\d{2}-\d{2})_(.+)_hxi\.zip$/i',
        $file,
        $matches
    )) {
        $timestamp = strtotime(
            $matches[1] . ' ' . str_replace('-', ':', $matches[2])
        );

        $map = $matches[3];
    }

    $files[] = [
        'name' => $file,
        'map' => $map,
        'size' => filesize($path),
        'time' => $timestamp !== false && $timestamp !== null
            ? $timestamp
            : filemtime($path),
    ];
}

/*
 * Newest demos first, using filename timestamps.
 */
usort($files, function ($a, $b) {
    return $b['time'] <=> $a['time'];
});

/*
 * display the latest 100 demos
 */
$files = array_slice($files, 0, 100);

function formatSize($bytes) {
    if ($bytes >= 1073741824) {
        return number_format($bytes / 1073741824, 2) . ' GB';
    }

    if ($bytes >= 1048576) {
        return number_format($bytes / 1048576, 2) . ' MB';
    }

    if ($bytes >= 1024) {
        return number_format($bytes / 1024, 1) . ' KB';
    }

    return $bytes . ' B';
}

function h($value) {
    return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}

?>
<!DOCTYPE html>
<html lang="zh-CN">

<head>

    <meta charset="UTF-8">

    <meta
        name="viewport"
        content="width=device-width, initial-scale=1.0"
    >

    <title>渝中重慶現場錄音</title>

    <!-- Chinese + English font -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    <link
        href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700;800&display=swap"
        rel="stylesheet"
    >

    <style>

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    background: #0a0d12;
}

body {
    color: #e6e8eb;

    font-family:
        "Noto Sans SC",
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background:
        linear-gradient(
            135deg,
            #090c11 0%,
            #11151c 50%,
            #0a0d12 100%
        );
}

        .container {
            position: relative;

            width: min(1050px, calc(100% - 32px));
            margin: 55px auto 35px;
        }

        header {
            margin-bottom: 28px;
            padding: 4px;
        }

        h1 {
            margin: 0 0 8px;

            color: #f5f7fa;

            font-size: 32px;
            line-height: 1.3;
            font-weight: 800;
            letter-spacing: -0.025em;
        }

        .subtitle {
            margin: 0;

            color: #9299a6;

            font-size: 14px;
            line-height: 1.7;
        }

        /*
         * Lightweight demo panel.
         */
        .card {
            overflow: hidden;

            background: #171b22;

            border: 1px solid #292f39;
            border-radius: 12px;

            box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
        }

        .demo {
            display: grid;

            grid-template-columns:
                150px
                minmax(0, 1fr)
                100px
                170px
                220px;

            gap: 20px;
            align-items: center;

            padding: 14px;

            border-bottom: 1px solid #292d35;

            transition: background 0.15s ease;
        }

        .demo:last-child {
            border-bottom: 0;
        }

        .demo:hover {
            background: #20242b;
        }

        .map-image {
            width: 150px;
            height: 84px;

            object-fit: cover;

            border-radius: 8px;

            background: #101217;
            border: 1px solid #303640;
        }

        .demo-name {
            min-width: 0;
        }

        .map-name {
            margin-bottom: 5px;

            color: #f0f2f5;

            font-size: 15px;
            line-height: 1.4;
            font-weight: 600;
        }

        .filename {
            overflow: hidden;

            color: #777f8c;

            font-size: 12px;
            line-height: 1.5;

            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .meta {
            color: #969da8;

            font-size: 13px;
            line-height: 1.5;
        }

        .download {
            display: inline-flex;
            align-items: center;
            justify-content: center;

            min-width: max-content;

            padding: 9px 14px;

            white-space: nowrap;

            border: 1px solid #3b72d1;
            border-radius: 7px;

            background: #2b6de0;
            color: #ffffff;

            text-align: center;
            text-decoration: none;

            font-size: 13px;
            line-height: 1.3;
            font-weight: 600;
        }

        .download:hover {
            background: #3679ed;
        }

        .empty {
            padding: 50px 20px;

            color: #858c97;

            text-align: center;
        }

        footer {
            margin-top: 18px;

            color: #686f7b;

            font-size: 12px;
            line-height: 1.6;

            text-align: center;
        }

        /*
         * Tablet / smaller desktop.
         */
        @media (max-width: 800px) {

            .demo {
                grid-template-columns:
                    100px
                    minmax(0, 1fr)
                    auto;

                gap: 14px;
            }

            .map-image {
                width: 100px;
                height: 64px;
            }

            .meta {
                display: none;
            }

            .download {
                grid-column: 3;
                grid-row: 1;
            }
        }

        /*
         * Phone.
         */
        @media (max-width: 520px) {

            .container {
                width: min(100% - 20px, 1050px);
                margin: 30px auto;
            }

            header {
                margin-bottom: 20px;
            }

            h1 {
                font-size: 25px;
                line-height: 1.4;
            }

            .subtitle {
                font-size: 13px;
            }

            .demo {
                grid-template-columns:
                    80px
                    minmax(0, 1fr);

                gap: 12px;
            }

            .map-image {
                width: 80px;
                height: 55px;
            }

            .download {
                grid-column: 2;
                grid-row: 2;

                width: fit-content;
            }
        }

        /*
         * Very small phones.
         */
        @media (max-width: 380px) {

            .download {
                font-size: 11px;
                padding: 8px 10px;
            }

            .map-name {
                font-size: 14px;
            }

            .filename {
                font-size: 11px;
            }
        }

    </style>

</head>

<body>

<div class="container">

    <header>

        <h1>重慶渝中永恆WLAN派對的遊戲錄影demo檔案庫</h1>

        <p class="subtitle">
            <?= count($files) ?>
            遭到HXI入侵的裝置感謝snoop dogg industries贊助這款遠端存取工具
        </p>

    </header>

    <div class="card">

        <?php if (empty($files)): ?>

            <div class="empty">
                No demos available :( , please contact the administrator!
            </div>

        <?php else: ?>

            <?php foreach ($files as $file): ?>

                <?php

                $map = $file['map'] ?? 'Unknown Map';

                $imagePath =
                    '/demo-maps/' .
                    rawurlencode($map) .
                    '.jpg';

                $imageFile =
                    '/var/www/yuzhong.dev/demo-maps/' .
                    $map .
                    '.jpg';

                if (!is_file($imageFile)) {
                    $imagePath = '/demo-maps/default.jpg';
                }

                ?>

                <div class="demo">

                    <img
                        class="map-image"
                        src="<?= h($imagePath) ?>"
                        alt="<?= h($map) ?>"
                        loading="lazy"
                    >

                    <div class="demo-name">

                        <div class="map-name">
                            <?= h($map) ?>
                        </div>

                        <div
                            class="filename"
                            title="<?= h($file['name']) ?>"
                        >
			<?= h(pathinfo($file['name'], PATHINFO_FILENAME)) ?>
                        </div>

                    </div>

                    <div class="meta">
                        <?= formatSize($file['size']) ?>
                    </div>

                    <div class="meta">
                        <?= date('Y-m-d H:i', $file['time']) ?>
                    </div>

                    <a
                        class="download"
                        href="<?= rawurlencode($file['name']) ?>"
                        download
                    >
                        免費下載Free Download!無病毒
                    </a>

                </div>

            <?php endforeach; ?>

        <?php endif; ?>

    </div>

    <footer>
        © 2026 yuzhong.dev · 版权所有HXI来自重庆市渝中区
    </footer>

</div>

</body>

</html>
