![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/.cursor-server/data/User/History/-6c8a90d2/ |
<?php
// AJAX Page Loader - Loads page content without full page refresh
// Preserves global player state across navigation
session_start();
require_once 'config/database.php';
// Set JSON header
header('Content-Type: application/json');
// Get requested page and parameters
$page = $_GET['page'] ?? '';
$params = $_GET;
unset($params['page']); // Remove page parameter
// Security: Only allow specific pages
$allowedPages = [
'track' => 'track.php',
'artist_profile' => 'artist_profile.php',
'artists' => 'artists.php',
'library' => 'library.php',
'dashboard' => 'dashboard.php',
'community' => 'community_fixed.php',
'studio' => 'studio.php',
'events' => 'events.php',
'charts' => 'charts.php',
'messages' => 'messages.php',
'notifications' => 'notifications.php',
'artist_dashboard' => 'artist_dashboard.php',
'event_details' => 'event_details.php',
'admin' => 'admin.php',
'checkout' => 'checkout.php'
];
if (!isset($allowedPages[$page])) {
echo json_encode(['success' => false, 'error' => 'Invalid page']);
exit;
}
$targetFile = $allowedPages[$page];
if (!file_exists($targetFile)) {
echo json_encode(['success' => false, 'error' => 'Page not found']);
exit;
}
try {
// Start output buffering to capture the page content
ob_start();
// Set up $_GET parameters for the target page
foreach ($params as $key => $value) {
$_GET[$key] = $value;
}
// Include the target page
include $targetFile;
// Get the captured content
$content = ob_get_clean();
// Extract just the main content (everything between <body> tags or main content area)
// This prevents duplicate headers/footers
if (preg_match('/<body[^>]*>(.*)<\/body>/s', $content, $matches)) {
$bodyContent = $matches[1];
// Remove header and footer includes to avoid duplicates
$bodyContent = preg_replace('/<header[^>]*>.*?<\/header>/s', '', $bodyContent);
$bodyContent = preg_replace('/<nav[^>]*>.*?<\/nav>/s', '', $bodyContent);
$bodyContent = preg_replace('/<!-- Global Player.*?-->/s', '', $bodyContent);
// Extract main content area if it exists
if (preg_match('/<main[^>]*>(.*)<\/main>/s', $bodyContent, $mainMatches)) {
$content = $mainMatches[1];
} else if (preg_match('/<div[^>]*class="[^"]*main-content[^"]*"[^>]*>(.*)<\/div>/s', $bodyContent, $mainMatches)) {
$content = $mainMatches[1];
} else {
$content = $bodyContent;
}
}
// Return successful response
echo json_encode([
'success' => true,
'content' => $content,
'page' => $page,
'title' => $page === 'track' ? 'Track Details' : ucfirst($page),
'url' => $targetFile . '?' . http_build_query($params)
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'error' => 'Failed to load page: ' . $e->getMessage()
]);
}
?>