urmi_downloader_converter/settings/index.php

784 lines
27 KiB
PHP
Executable File

<?php
// settings/index.php
// Start session to store settings
session_start();
// Define settings file path - save in same directory as this file
$settings_file = 'settings.json';
$logo_file = 'logo.png';
// Default settings
$default_settings = [
'video_format' => 'h264',
'audio_format' => 'mp3',
'video_bitrate' => '1000k',
'audio_bitrate' => '128k',
'resolution' => '1280x720',
'frame_rate' => '30',
'gop' => '30',
];
// Initialize settings from JSON file or use defaults
if (file_exists($settings_file)) {
$settings_json = file_get_contents($settings_file);
$settings = json_decode($settings_json, true);
// Merge with defaults if any keys are missing
foreach ($default_settings as $key => $value) {
if (!isset($settings[$key])) {
$settings[$key] = $value;
}
}
} else {
$settings = $default_settings;
}
// Handle form submission
$message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate video format
$allowed_video_formats = ['mpeg2', 'h264', 'h265', 'vp9', 'av1'];
if (isset($_POST['video_format']) && in_array($_POST['video_format'], $allowed_video_formats)) {
$settings['video_format'] = $_POST['video_format'];
}
// Validate audio format
$allowed_audio_formats = ['mp2', 'mp3', 'aac'];
if (isset($_POST['audio_format']) && in_array($_POST['audio_format'], $allowed_audio_formats)) {
$settings['audio_format'] = $_POST['audio_format'];
}
// Update other settings
$settings['video_bitrate'] = $_POST['video_bitrate'] ?? $settings['video_bitrate'];
$settings['audio_bitrate'] = $_POST['audio_bitrate'] ?? $settings['audio_bitrate'];
$settings['resolution'] = $_POST['resolution'] ?? $settings['resolution'];
$settings['frame_rate'] = $_POST['frame_rate'] ?? $settings['frame_rate'];
$settings['gop'] = $_POST['gop'] ?? $settings['gop'];
// Handle logo upload
if (isset($_FILES['logo']) && $_FILES['logo']['error'] === UPLOAD_ERR_OK) {
// Check if GD library is available
if (!extension_loaded('gd')) {
$message = "GD library not available for image processing!";
} else {
$allowed_types = ['image/png'];
$file_type = mime_content_type($_FILES['logo']['tmp_name']);
if (in_array($file_type, $allowed_types)) {
// Move uploaded file
$target_path = $logo_file;
if (move_uploaded_file($_FILES['logo']['tmp_name'], $target_path)) {
// Process image with GD library to make it square
$image = imagecreatefrompng($target_path);
if ($image !== false) {
$width = imagesx($image);
$height = imagesy($image);
// Calculate square dimensions (use smaller dimension)
$size = min($width, $height);
// Create square canvas
$square = imagecreatetruecolor(128, 128);
// Fill with transparent background
$transparent = imagecolorallocatealpha($square, 0, 0, 0, 127);
imagefill($square, 0, 0, $transparent);
// Calculate position to center the image
$x = ($width - $size) / 2;
$y = ($height - $size) / 2;
// Copy and resize to square
imagecopyresampled($square, $image, 0, 0, $x, $y, 128, 128, $size, $size);
// Save the processed image
imagepng($square, $target_path);
// Free memory
imagedestroy($image);
imagedestroy($square);
$message = "Logo uploaded and processed successfully!";
} else {
$message = "Error processing image with GD library!";
}
} else {
$message = "Error uploading logo!";
}
} else {
$message = "Only PNG images are allowed!";
}
}
}
// Handle logo removal
if (isset($_POST['remove_logo']) && $_POST['remove_logo'] == '1') {
if (file_exists($logo_file)) {
unlink($logo_file);
$message = "Logo removed successfully!";
}
}
// Save settings to JSON file
$settings_json = json_encode($settings, JSON_PRETTY_PRINT);
if (file_put_contents($settings_file, $settings_json) !== false) {
$message .= " Settings saved successfully!";
} else {
$message = "Error saving settings!";
}
}
// Save settings to session as backup
$_SESSION['settings'] = $settings;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Settings</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
color: #fff;
min-height: 100vh;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.container {
max-width: 800px;
width: 100%;
background: rgba(13, 19, 33, 0.85);
backdrop-filter: blur(12px);
border-radius: 20px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7);
overflow: hidden;
border: 1px solid rgba(92, 107, 192, 0.3);
transform: translateZ(0);
position: relative;
}
.container::before {
content: '';
position: absolute;
top: -2px;
left: -2px;
right: -2px;
bottom: -2px;
background: linear-gradient(45deg, #1a2a6c, #2a5298, #4facfe, #00f2fe, #1a2a6c);
z-index: -1;
border-radius: 22px;
animation: gradient 15s ease infinite;
background-size: 400% 400%;
}
@keyframes gradient {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.header {
background: linear-gradient(90deg, #1a2a6c, #2a5298);
padding: 30px;
text-align: center;
position: relative;
border-bottom: 2px solid rgba(92, 107, 192, 0.5);
transform: translateZ(0);
}
.header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
background: linear-gradient(to right, #4facfe, #00f2fe);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
position: relative;
display: inline-block;
}
.header h1::after {
content: '';
position: absolute;
bottom: -5px;
left: 50%;
transform: translateX(-50%);
width: 80%;
height: 2px;
background: linear-gradient(to right, transparent, #4facfe, #00f2fe, transparent);
border-radius: 50%;
}
.header p {
font-size: 1.1rem;
opacity: 0.9;
margin-top: 10px;
}
.content {
padding: 30px;
}
.form-group {
margin-bottom: 25px;
position: relative;
transform: translateZ(0);
}
.form-group label {
display: block;
margin-bottom: 10px;
font-weight: 600;
font-size: 1.1rem;
color: #4facfe;
display: flex;
align-items: center;
gap: 10px;
position: relative;
/* Fix for label visibility */
z-index: 2;
}
.form-group label::before {
content: '';
position: absolute;
left: -25px;
top: 50%;
transform: translateY(-50%);
width: 12px;
height: 12px;
border-radius: 50%;
background: #4facfe;
box-shadow: 0 0 10px rgba(79, 172, 254, 0.7);
z-index: 1;
}
input, select {
width: 100%;
padding: 15px;
border: 2px solid rgba(92, 107, 192, 0.5);
border-radius: 12px;
background: rgba(13, 19, 33, 0.7);
color: #fff;
font-size: 1rem;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(5px);
position: relative;
z-index: 1;
}
input:focus, select:focus {
outline: none;
border-color: #4facfe;
box-shadow: 0 0 20px rgba(79, 172, 254, 0.6);
transform: translateY(-2px);
}
input:focus {
box-shadow: 0 0 20px rgba(79, 172, 254, 0.6), 0 0 0 3px rgba(79, 172, 254, 0.2);
}
.btn {
background: linear-gradient(90deg, #1a2a6c, #2a5298);
color: white;
padding: 16px 30px;
border: none;
border-radius: 12px;
cursor: pointer;
font-size: 1.1rem;
font-weight: 600;
width: 100%;
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
letter-spacing: 1px;
text-transform: uppercase;
position: relative;
overflow: hidden;
z-index: 1;
transform: translateZ(0);
}
.btn::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
transition: 0.5s;
z-index: -1;
}
.btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
background: linear-gradient(90deg, #2a5298, #1a2a6c);
}
.btn:hover::before {
left: 100%;
}
.btn:active {
transform: translateY(0);
}
.message {
padding: 15px;
margin: 20px 0;
border-radius: 12px;
text-align: center;
font-weight: 500;
animation: fadeIn 0.5s ease;
backdrop-filter: blur(5px);
border: 1px solid;
transform: translateZ(0);
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-10px); }
to { opacity: 1; transform: translateY(0); }
}
.success {
background: rgba(46, 204, 113, 0.2);
border: 1px solid rgba(46, 204, 113, 0.5);
color: #2ecc71;
}
.error {
background: rgba(231, 76, 60, 0.2);
border: 1px solid rgba(231, 76, 60, 0.5);
color: #e74c3c;
}
.format-note {
background: rgba(92, 107, 192, 0.2);
border: 1px solid rgba(92, 107, 192, 0.4);
border-radius: 12px;
padding: 20px;
margin: 25px 0;
font-size: 0.95rem;
transform: translateZ(0);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
.format-note h3 {
color: #4facfe;
margin-bottom: 15px;
display: flex;
align-items: center;
gap: 10px;
}
.format-note h3 i {
margin-right: 10px;
}
.format-note p {
margin: 8px 0;
display: flex;
align-items: center;
gap: 10px;
}
.format-note p i {
margin-right: 10px;
color: #4facfe;
}
.footer {
text-align: center;
padding: 25px;
background: rgba(13, 19, 33, 0.9);
border-top: 1px solid rgba(92, 107, 192, 0.3);
font-size: 1.1rem;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
transform: translateZ(0);
}
.footer i {
color: #e74c3c;
margin: 0 5px;
font-size: 1.3rem;
animation: heartbeat 1.5s infinite;
}
@keyframes heartbeat {
0% { transform: scale(1); }
50% { transform: scale(1.2); }
100% { transform: scale(1); }
}
.footer p {
margin: 5px 0;
}
.settings-info {
background: rgba(13, 19, 33, 0.7);
border: 1px solid rgba(92, 107, 192, 0.3);
border-radius: 12px;
padding: 20px;
margin-bottom: 25px;
font-size: 0.9rem;
transform: translateZ(0);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
.settings-info p {
margin: 8px 0;
display: flex;
justify-content: space-between;
}
.settings-info strong {
color: #4facfe;
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(79, 172, 254, 0.4); }
70% { box-shadow: 0 0 0 10px rgba(79, 172, 254, 0); }
100% { box-shadow: 0 0 0 0 rgba(79, 172, 254, 0); }
}
.floating {
animation: floating 3s ease-in-out infinite;
}
@keyframes floating {
0% { transform: translateY(0px); }
50% { transform: translateY(-10px); }
100% { transform: translateY(0px); }
}
.glow {
text-shadow: 0 0 10px rgba(79, 172, 254, 0.7);
}
.input-group {
display: flex;
gap: 10px;
}
.input-group input {
flex: 1;
}
.input-group input:first-child {
border-radius: 12px 0 0 12px;
}
.input-group input:last-child {
border-radius: 0 12px 12px 0;
}
@media (max-width: 768px) {
.container {
margin: 10px;
border-radius: 15px;
}
.header h1 {
font-size: 2rem;
}
.content {
padding: 20px;
}
.input-group {
flex-direction: column;
}
.input-group input {
border-radius: 12px;
}
}
.animate-on-load {
animation: slideIn 0.8s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(30px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.form-group:nth-child(1) { animation-delay: 0.1s; }
.form-group:nth-child(2) { animation-delay: 0.2s; }
.form-group:nth-child(3) { animation-delay: 0.3s; }
.form-group:nth-child(4) { animation-delay: 0.4s; }
.form-group:nth-child(5) { animation-delay: 0.5s; }
.form-group:nth-child(6) { animation-delay: 0.6s; }
.form-group:nth-child(7) { animation-delay: 0.7s; }
.form-group {
animation: slideIn 0.5s ease-out forwards;
opacity: 0;
transform: translateY(20px);
}
.form-group.animate {
animation: slideIn 0.5s ease-out forwards;
}
.btn-container {
margin-top: 20px;
}
.logo-container {
text-align: center;
margin: 20px 0;
}
.logo-preview {
width: 128px;
height: 128px;
margin: 0 auto;
border-radius: 0; /* Changed from 50% to 0 for square shape */
overflow: hidden;
border: 2px solid rgba(92, 107, 192, 0.5);
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
background: rgba(13, 19, 33, 0.7);
display: flex;
justify-content: center;
align-items: center;
position: relative;
margin-bottom: 15px;
}
.logo-preview img {
width: 100%;
height: 100%;
object-fit: contain;
display: block;
}
.logo-preview .no-logo {
color: #4facfe;
font-size: 0.9rem;
text-align: center;
padding: 10px;
}
.logo-actions {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 10px;
}
.logo-actions button {
padding: 8px 15px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 0.9rem;
transition: all 0.3s;
}
.upload-btn {
background: rgba(92, 107, 192, 0.3);
color: #4facfe;
}
.remove-btn {
background: rgba(231, 76, 60, 0.3);
color: #e74c3c;
}
.logo-actions button:hover {
transform: translateY(-2px);
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}
.logo-preview::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border: 2px dashed rgba(92, 107, 192, 0.3);
border-radius: 50%;
pointer-events: none;
}
/* Fix for logo preview */
.logo-preview img {
display: block;
max-width: 100%;
max-height: 100%;
}
.logo-preview img[src=""] {
display: none;
}
</style>
</head>
<body>
<div class="container animate-on-load">
<div class="header">
<h1 class="glow"><i class="fas fa-cog"></i> Video Settings</h1>
<p>Configure your video processing parameters</p>
</div>
<div class="content">
<?php if ($message): ?>
<div class="message <?php echo (strpos($message, 'Error') !== false) ? 'error' : 'success'; ?>">
<?php echo $message; ?>
</div>
<?php endif; ?>
<div class="settings-info">
<p><strong>Current Settings:</strong>
<span>Video: <?php echo htmlspecialchars($settings['video_format']); ?></span> |
<span>Audio: <?php echo htmlspecialchars($settings['audio_format']); ?></span>
</p>
</div>
<div class="logo-container">
<h3><i class="fas fa-image"></i> Logo Management</h3>
<br>
<div class="logo-preview">
<?php if (file_exists($logo_file)): ?>
<img src="<?php echo htmlspecialchars($logo_file); ?>?v=<?php echo time(); ?>" alt="Logo Preview" id="logo-preview">
<?php else: ?>
<div class="no-logo">No logo uploaded</div>
<?php endif; ?>
</div>
<div class="logo-actions">
<form method="POST" action="" enctype="multipart/form-data" style="display: inline;">
<input type="file" name="logo" id="logo" accept="image/png" style="display: none;" onchange="this.form.submit()">
<button type="button" class="upload-btn" onclick="document.getElementById('logo').click()">
<i class="fas fa-upload"></i> Upload Logo
</button>
</form>
<?php if (file_exists($logo_file)): ?>
<form method="POST" action="" style="display: inline;">
<input type="hidden" name="remove_logo" value="1">
<button type="submit" class="remove-btn">
<i class="fas fa-trash"></i> Remove Logo
</button>
</form>
<?php endif; ?>
</div>
</div>
<div class="format-note">
<h3><i class="fas fa-info-circle"></i> Format Restrictions</h3>
<p><i class="fas fa-video"></i> Video format is limited to: MPEG-2, H.264, H.265, VP9, and AV1</p>
<p><i class="fas fa-music"></i> Audio format is limited to: MP2, MP3, and AAC</p>
</div>
<form method="POST" action="">
<div class="form-group">
<label for="video_format"><i class="fas fa-film"></i> Video Format</label>
<select name="video_format" id="video_format">
<option value="mpeg2" <?php echo ($settings['video_format'] === 'mpeg2') ? 'selected' : ''; ?>>MPEG-2</option>
<option value="h264" <?php echo ($settings['video_format'] === 'h264') ? 'selected' : ''; ?>>H.264</option>
<option value="h265" <?php echo ($settings['video_format'] === 'h265') ? 'selected' : ''; ?>>H.265</option>
<option value="vp9" <?php echo ($settings['video_format'] === 'vp9') ? 'selected' : ''; ?>>VP9</option>
<option value="av1" <?php echo ($settings['video_format'] === 'av1') ? 'selected' : ''; ?>>AV1</option>
</select>
</div>
<div class="form-group">
<label for="audio_format"><i class="fas fa-music"></i> Audio Format</label>
<select name="audio_format" id="audio_format">
<option value="mp2" <?php echo ($settings['audio_format'] === 'mp2') ? 'selected' : ''; ?>>MP2</option>
<option value="mp3" <?php echo ($settings['audio_format'] === 'mp3') ? 'selected' : ''; ?>>MP3</option>
<option value="aac" <?php echo ($settings['audio_format'] === 'aac') ? 'selected' : ''; ?>>AAC</option>
</select>
</div>
<div class="form-group">
<label for="video_bitrate"><i class="fas fa-tachometer-alt"></i> Video Bitrate</label>
<input type="text" name="video_bitrate" id="video_bitrate" value="<?php echo htmlspecialchars($settings['video_bitrate']); ?>">
</div>
<div class="form-group">
<label for="audio_bitrate"><i class="fas fa-volume-up"></i> Audio Bitrate</label>
<input type="text" name="audio_bitrate" id="audio_bitrate" value="<?php echo htmlspecialchars($settings['audio_bitrate']); ?>">
</div>
<div class="form-group">
<label for="resolution"><i class="fas fa-expand"></i> Resolution</label>
<select name="resolution" id="resolution">
<option value="720x576" <?php echo ($settings['resolution'] === '720x576') ? 'selected' : ''; ?>>720x576 (PAL)</option>
<option value="720x480" <?php echo ($settings['resolution'] === '720x480') ? 'selected' : ''; ?>>720x480 (NTSC)</option>
<option value="1280x720" <?php echo ($settings['resolution'] === '1280x720') ? 'selected' : ''; ?>>1280x720 (HD 720p)</option>
<option value="1920x1080" <?php echo ($settings['resolution'] === '1920x1080') ? 'selected' : ''; ?>>1920x1080 (HD 1080p)</option>
<option value="2560x1440" <?php echo ($settings['resolution'] === '2560x1440') ? 'selected' : ''; ?>>2560x1440 (QHD 1440p)</option>
<option value="3840x2160" <?php echo ($settings['resolution'] === '3840x2160') ? 'selected' : ''; ?>>3840x2160 (4K UHD)</option>
<option value="4096x2160" <?php echo ($settings['resolution'] === '4096x2160') ? 'selected' : ''; ?>>4096x2160 (4K DCI)</option>
</select>
</div>
<div class="form-group">
<label for="frame_rate"><i class="fas fa-play-circle"></i> Frame Rate (fps)</label>
<input type="text" name="frame_rate" id="frame_rate" value="<?php echo htmlspecialchars($settings['frame_rate']); ?>">
</div>
<div class="form-group">
<label for="gop"><i class="fas fa-layer-group"></i> GOP (Group of Pictures)</label>
<input type="text" name="gop" id="gop" value="<?php echo htmlspecialchars($settings['gop']); ?>">
</div>
<div class="btn-container">
<button type="submit" class="btn pulse"><i class="fas fa-save"></i> Save Settings</button>
</div>
</form>
</div>
<div class="footer">
<p>Made with <i class="fas fa-heart"></i> from ShreeBhattJi</p>
</div>
</div>
<script>
// Ensure logo preview works properly
document.addEventListener('DOMContentLoaded', function() {
const logoPreview = document.getElementById('logo-preview');
if (logoPreview) {
// Add error handling for image loading
logoPreview.addEventListener('error', function() {
console.log('Logo preview failed to load');
// Show fallback message
const container = logoPreview.parentElement;
container.innerHTML = '<div class="no-logo">Logo failed to load</div>';
});
}
});
</script>
</body>
</html>