![]() 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/-28d26f47/ |
<?php
session_start();
// Handle AJAX requests
$is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == '1';
// For AJAX requests, we might not have a session, so handle gracefully
if (!$is_ajax) {
// Check if user is logged in for full page loads
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php');
exit;
}
// Include header only for full page loads
include 'includes/header.php';
// Global player is included via footer.php
}
require_once 'config/database.php';
$pdo = getDBConnection();
// For AJAX requests, we might not have a session, so handle gracefully
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
// Get user info
$stmt = $pdo->prepare("SELECT name FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch();
$user_name = $user['name'] ?? 'User';
} else {
// For AJAX requests without session, use a default user or handle differently
$user_id = null;
$user_name = 'Guest';
}
// Get feed tracks - show recent tracks from followed users first, then recent tracks as fallback
if ($user_id) {
// First try to get tracks from followed users
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.prompt,
mt.audio_url,
mt.duration,
mt.created_at,
u.name as artist_name,
u.id as artist_id,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id) as like_count,
(SELECT COUNT(*) FROM track_comments WHERE track_id = mt.id) as comment_count,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id AND user_id = ?) as user_liked
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
JOIN user_follows uf ON mt.user_id = uf.following_id
WHERE uf.follower_id = ? AND mt.status = 'complete'
ORDER BY mt.created_at DESC
LIMIT 10
");
$stmt->execute([$user_id, $user_id]);
$feed_tracks = $stmt->fetchAll();
// If no tracks from followed users, get recent tracks
if (empty($feed_tracks)) {
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.prompt,
mt.audio_url,
mt.duration,
mt.created_at,
u.name as artist_name,
u.id as artist_id,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id) as like_count,
(SELECT COUNT(*) FROM track_comments WHERE track_id = mt.id) as comment_count,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id AND user_id = ?) as user_liked
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
WHERE mt.status = 'complete'
ORDER BY mt.created_at DESC
LIMIT 15
");
$stmt->execute([$user_id]);
$feed_tracks = $stmt->fetchAll();
}
} else {
// For guests, get recent tracks
$stmt = $pdo->prepare("
SELECT
mt.id,
mt.title,
mt.prompt,
mt.audio_url,
mt.duration,
mt.created_at,
u.name as artist_name,
u.id as artist_id,
(SELECT COUNT(*) FROM track_likes WHERE track_id = mt.id) as like_count,
(SELECT COUNT(*) FROM track_comments WHERE track_id = mt.id) as comment_count,
0 as user_liked
FROM music_tracks mt
JOIN users u ON mt.user_id = u.id
WHERE mt.status = 'complete'
ORDER BY mt.created_at DESC
LIMIT 15
");
$stmt->execute();
$feed_tracks = $stmt->fetchAll();
}
// Get suggested users to follow
if ($user_id) {
$stmt = $pdo->prepare("
SELECT
u.id,
u.name,
COUNT(mt.id) as track_count,
(SELECT COUNT(*) FROM user_follows WHERE following_id = u.id) as followers_count
FROM users u
LEFT JOIN music_tracks mt ON u.id = mt.user_id AND mt.status = 'complete'
WHERE u.id NOT IN (
SELECT following_id FROM user_follows WHERE follower_id = ?
) AND u.id != ?
GROUP BY u.id
ORDER BY track_count DESC, followers_count DESC
LIMIT 5
");
$stmt->execute([$user_id, $user_id]);
$suggested_users = $stmt->fetchAll();
} else {
// For guests, show some popular users
$stmt = $pdo->prepare("
SELECT
u.id,
u.name,
COUNT(mt.id) as track_count,
(SELECT COUNT(*) FROM user_follows WHERE following_id = u.id) as followers_count
FROM users u
LEFT JOIN music_tracks mt ON u.id = mt.user_id AND mt.status = 'complete'
GROUP BY u.id
ORDER BY track_count DESC, followers_count DESC
LIMIT 5
");
$stmt->execute();
$suggested_users = $stmt->fetchAll();
}
// Set page variables for header
$page_title = 'Your Feed - SoundStudioPro';
$page_description = 'Discover music from artists you follow. Your personalized AI music feed.';
$current_page = 'feed';
// Include header only for full page loads
if (!isset($_GET['ajax'])) {
include 'includes/header.php';
} else {
// For AJAX requests, wrap content in the proper container structure
echo '<div class="container" id="pageContainer">';
}
?>
<style>
/* Hero Section */
.hero {
padding: 8rem 0 6rem;
text-align: center;
color: white;
background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 50%, #0a0a0a 100%);
position: relative;
overflow: hidden;
margin-bottom: 4rem;
margin-top: 0; /* Account for fixed header */
}
.hero::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(102,126,234,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
opacity: 0.3;
}
.hero-content {
max-width: 90rem;
margin: 0 auto;
position: relative;
z-index: 2;
}
.hero-badge {
display: inline-block;
background: linear-gradient(135deg, rgba(102, 126, 234, 0.2), rgba(118, 75, 162, 0.2));
color: #667eea;
padding: 1.2rem 2.4rem;
border-radius: 50px;
font-size: 1.4rem;
font-weight: 600;
margin-bottom: 3rem;
backdrop-filter: blur(10px);
border: 1px solid rgba(102, 126, 234, 0.3);
}
.hero-title {
font-size: 5.6rem;
font-weight: 900;
line-height: 1.1;
margin-bottom: 2.4rem;
background: linear-gradient(135deg, #ffffff, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.hero-subtitle {
font-size: 2rem;
font-weight: 400;
margin-bottom: 4rem;
opacity: 0.9;
max-width: 70rem;
margin-left: auto;
margin-right: auto;
color: #a0aec0;
}
/* Feed Content */
.feed-content {
background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
padding: 6rem 0;
border-radius: 40px 40px 0 0;
margin-top: -2rem;
position: relative;
z-index: 10;
}
.feed-container {
max-width: 120rem;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 300px;
gap: 4rem;
}
/* Feed Main */
.feed-main {
min-height: 50rem;
}
.feed-header {
margin-bottom: 4rem;
}
.feed-title {
font-size: 3.2rem;
font-weight: 700;
color: white;
margin-bottom: 1rem;
}
.feed-subtitle {
font-size: 1.6rem;
color: #a0aec0;
}
/* Feed Sidebar */
.feed-sidebar {
position: sticky;
top: 12rem;
height: fit-content;
}
.sidebar-section {
background: rgba(255, 255, 255, 0.05);
border-radius: 20px;
padding: 3rem;
margin-bottom: 3rem;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-title {
font-size: 2rem;
font-weight: 700;
color: white;
margin-bottom: 2rem;
}
/* Suggested Users */
.suggested-user {
display: flex;
align-items: center;
gap: 1.5rem;
padding: 1.5rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.suggested-user:last-child {
border-bottom: none;
}
.user-avatar {
width: 5rem;
height: 5rem;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
display: flex;
align-items: center;
justify-content: center;
font-size: 2rem;
font-weight: 900;
color: white;
}
.user-info {
flex: 1;
}
.user-name {
font-size: 1.6rem;
font-weight: 600;
color: white;
margin-bottom: 0.5rem;
}
.user-stats {
font-size: 1.2rem;
color: #a0aec0;
}
.follow-btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
padding: 0.8rem 1.5rem;
border-radius: 8px;
font-size: 1.2rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.follow-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.follow-btn.following {
background: rgba(34, 197, 94, 0.2);
border: 1px solid rgba(34, 197, 94, 0.3);
color: #22c55e;
}
/* Track Cards */
.track-card {
background: rgba(255, 255, 255, 0.05);
padding: 3rem;
border-radius: 20px;
backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
margin-bottom: 3rem;
}
.track-card:hover {
transform: translateY(-5px);
border-color: rgba(102, 126, 234, 0.3);
box-shadow: 0 20px 60px rgba(102, 126, 234, 0.1);
}
.track-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 2rem;
}
.track-title {
font-size: 2rem;
font-weight: 700;
color: white;
margin-bottom: 0.5rem;
}
.track-artist {
font-size: 1.4rem;
color: #667eea;
font-weight: 500;
}
.track-prompt {
font-size: 1.4rem;
color: #a0aec0;
line-height: 1.6;
margin-bottom: 2rem;
background: rgba(255, 255, 255, 0.05);
padding: 1.5rem;
border-radius: 12px;
}
.track-details {
display: flex;
gap: 2rem;
margin-bottom: 2rem;
font-size: 1.2rem;
color: #a0aec0;
}
.track-details span {
display: flex;
align-items: center;
gap: 0.5rem;
}
.track-actions {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}
.btn {
padding: 1rem 2rem;
border: none;
border-radius: 12px;
font-size: 1.4rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 0.8rem;
}
.btn-primary {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: white;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
/* Social Actions */
.social-actions {
display: flex;
gap: 1rem;
margin-top: 2rem;
padding-top: 2rem;
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.social-btn {
background: rgba(255, 255, 255, 0.05);
border: 1px solid rgba(255, 255, 255, 0.1);
color: #a0aec0;
padding: 0.8rem 1.5rem;
border-radius: 8px;
font-size: 1.2rem;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 0.5rem;
}
.social-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: white;
}
.social-btn.liked {
background: rgba(239, 68, 68, 0.2);
border-color: rgba(239, 68, 68, 0.3);
color: #ef4444;
}
.social-count {
font-size: 1.2rem;
font-weight: 600;
}
/* Empty State */
.empty-state {
text-align: center;
padding: 8rem 2rem;
color: #a0aec0;
}
.empty-icon {
font-size: 8rem;
margin-bottom: 2rem;
color: #667eea;
}
.empty-title {
font-size: 3.2rem;
color: white;
margin-bottom: 1.5rem;
}
.empty-description {
font-size: 1.8rem;
margin-bottom: 3rem;
}
/* Responsive */
@media (max-width: 1024px) {
.feed-container {
grid-template-columns: 1fr;
}
.feed-sidebar {
position: static;
}
}
@media (max-width: 768px) {
.hero {
margin-top: 6rem; /* Less margin on mobile */
padding: 6rem 0 4rem;
}
.hero-title {
font-size: 4rem;
}
.hero-subtitle {
font-size: 1.6rem;
}
.feed-container {
grid-template-columns: 1fr;
gap: 3rem;
}
.feed-title {
font-size: 2.8rem;
}
.feed-subtitle {
font-size: 1.4rem;
}
.track-card {
padding: 2rem;
}
.track-title {
font-size: 2rem;
}
.track-artist {
font-size: 1.4rem;
}
.track-prompt {
font-size: 1.4rem;
line-height: 1.5;
}
.track-details {
flex-wrap: wrap;
gap: 1rem;
}
.track-details span {
font-size: 1.2rem;
}
.track-actions {
flex-direction: column;
gap: 1rem;
}
.track-actions .btn {
width: 100%;
justify-content: center;
padding: 1.2rem 2rem;
font-size: 1.4rem;
}
.social-actions {
flex-wrap: wrap;
gap: 1rem;
justify-content: center;
}
.social-btn {
padding: 1rem 1.5rem;
font-size: 1.2rem;
}
.social-count {
font-size: 1.2rem;
}
.sidebar-section {
padding: 2rem;
}
.sidebar-title {
font-size: 1.8rem;
}
.suggested-user {
padding: 1.5rem;
}
.user-name {
font-size: 1.4rem;
}
.user-stats {
font-size: 1.2rem;
}
.follow-btn {
padding: 0.8rem 1.5rem;
font-size: 1.2rem;
}
.feed-sidebar .btn {
padding: 1.2rem 2rem;
font-size: 1.4rem;
}
.container {
padding: 0 1.5rem;
}
.feed-content {
padding: 4rem 0;
}
}
@media (max-width: 480px) {
.hero-title {
font-size: 3.2rem;
}
.hero-subtitle {
font-size: 1.4rem;
}
.feed-title {
font-size: 2.4rem;
}
.feed-subtitle {
font-size: 1.3rem;
}
.track-card {
padding: 1.5rem;
}
.track-title {
font-size: 1.8rem;
}
.track-artist {
font-size: 1.2rem;
}
.track-prompt {
font-size: 1.3rem;
}
.track-actions .btn {
padding: 1rem 1.5rem;
font-size: 1.3rem;
}
.social-btn {
padding: 0.8rem 1.2rem;
font-size: 1.1rem;
}
.sidebar-section {
padding: 1.5rem;
}
.sidebar-title {
font-size: 1.6rem;
}
.suggested-user {
padding: 1.2rem;
}
.user-name {
font-size: 1.3rem;
}
.user-stats {
font-size: 1.1rem;
}
.follow-btn {
padding: 0.6rem 1.2rem;
font-size: 1.1rem;
}
.feed-sidebar .btn {
padding: 1rem 1.5rem;
font-size: 1.3rem;
}
.container {
padding: 0 1rem;
}
.feed-content {
padding: 3rem 0;
}
}
</style>
<!-- Hero Section -->
<section class="hero">
<div class="hero-content">
<div class="hero-badge">🎵 Your Feed</div>
<h1 class="hero-title">Discover Music from Artists You Follow</h1>
<p class="hero-subtitle">Your personalized AI music feed. Stay updated with the latest tracks from your favorite creators.</p>
</div>
</section>
<!-- Feed Content -->
<section class="feed-content">
<div class="feed-container">
<!-- Feed Main -->
<div class="feed-main">
<div class="feed-header">
<h2 class="feed-title">Your Feed</h2>
<p class="feed-subtitle">
<?php
if ($user_id) {
// Check if we have follows
$follow_check = $pdo->prepare("SELECT COUNT(*) as follow_count FROM user_follows WHERE follower_id = ?");
$follow_check->execute([$user_id]);
$follows = $follow_check->fetch();
if ($follows['follow_count'] > 0) {
echo "Latest tracks from artists you follow";
} else {
echo "Discover some recent tracks while you start following artists";
}
} else {
echo "Discover some recent tracks from our community";
}
?>
</p>
</div>
<?php if (empty($feed_tracks)): ?>
<div class="empty-state">
<div class="empty-icon">🎵</div>
<h3 class="empty-title">Your feed is empty</h3>
<p class="empty-description">
Debug: User ID = <?= $user_id ? $user_id : 'Not logged in' ?><br>
Feed tracks count: <?= count($feed_tracks) ?><br>
Start following artists to see their latest tracks in your feed!
</p>
<div style="display: flex; gap: 2rem; justify-content: center; flex-wrap: wrap;">
<a href="/community.php" class="btn btn-primary">
<i class="fas fa-users"></i> Discover Artists
</a>
<a href="/create.php" class="btn btn-secondary">
<i class="fas fa-plus"></i> Create Your First Track
</a>
</div>
</div>
<?php else: ?>
<div style="background: rgba(102, 126, 234, 0.1); padding: 1rem; border-radius: 8px; margin-bottom: 2rem; color: white;">
<strong>Debug:</strong> Found <?= count($feed_tracks) ?> tracks. User ID: <?= $user_id ? 'Yes' : 'No' ?>
</div>
<?php foreach ($feed_tracks as $track): ?>
<div class="track-card">
<div class="track-header">
<div>
<div class="track-title"><?= htmlspecialchars($track['title']) ?></div>
<div class="track-artist">by <?= htmlspecialchars($track['artist_name']) ?></div>
</div>
</div>
<div class="track-prompt"><?= htmlspecialchars(substr($track['prompt'], 0, 100)) ?>...</div>
<div class="track-details">
<span><i class="fas fa-clock"></i> <?= $track['duration'] ?>s</span>
<span><i class="fas fa-calendar"></i> <?= date('M j, Y', strtotime($track['created_at'])) ?></span>
</div>
<div class="track-actions">
<button class="btn btn-primary" onclick="playTrack('<?= htmlspecialchars($track['audio_url']) ?>', '<?= htmlspecialchars($track['title']) ?>', '<?= htmlspecialchars($track['artist_name']) ?>')">
<i class="fas fa-play"></i> Play
</button>
<a href="/artist_profile.php?id=<?= $track['artist_id'] ?>" class="btn btn-secondary ajax-nav" data-page="artist_profile" data-artist-id="<?= $track['artist_id'] ?>">
<i class="fas fa-user"></i> View Artist
</a>
</div>
<!-- Social Actions -->
<div class="social-actions">
<button class="social-btn <?= $track['user_liked'] ? 'liked' : '' ?>" onclick="toggleLike(<?= $track['id'] ?>, this)">
<i class="fas fa-heart"></i>
<span class="social-count"><?= $track['like_count'] ?></span>
</button>
<button class="social-btn" onclick="showComments(<?= $track['id'] ?>)">
<i class="fas fa-comment"></i>
<span class="social-count"><?= $track['comment_count'] ?></span>
</button>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Feed Sidebar -->
<div class="feed-sidebar">
<!-- Suggested Users -->
<div class="sidebar-section">
<h3 class="sidebar-title">Suggested Artists</h3>
<?php if (empty($suggested_users)): ?>
<p style="color: #a0aec0; text-align: center;">No suggestions available</p>
<?php else: ?>
<?php foreach ($suggested_users as $user): ?>
<div class="suggested-user">
<div class="user-avatar">
<?= strtoupper(substr($user['name'], 0, 1)) ?>
</div>
<div class="user-info">
<div class="user-name"><?= htmlspecialchars($user['name']) ?></div>
<div class="user-stats"><?= $user['track_count'] ?> tracks • <?= $user['followers_count'] ?> followers</div>
</div>
<button class="follow-btn" onclick="toggleFollow(<?= $user['id'] ?>, this)">
Follow
</button>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Quick Actions -->
<div class="sidebar-section">
<h3 class="sidebar-title">Quick Actions</h3>
<div style="display: flex; flex-direction: column; gap: 1rem;">
<a href="/create.php" class="btn btn-primary">
<i class="fas fa-plus"></i> Create Music
</a>
<a href="/community.php" class="btn btn-secondary">
<i class="fas fa-users"></i> Discover Artists
</a>
<a href="/library_new.php" class="btn btn-secondary">
<i class="fas fa-music"></i> My Library
</a>
</div>
</div>
</div>
</div>
</section>
<script>
// Play track using global player - ENHANCED VERSION
async function playTrack(audioUrl, title, artist) {
console.log('🎵 Feed playTrack called:', { audioUrl, title, artist });
// Check if global player is available
if (typeof window.globalPlayer === 'undefined') {
console.log('🎵 Global player not available, trying to initialize...');
if (typeof initializeGlobalPlayer === 'function') {
initializeGlobalPlayer();
}
setTimeout(() => {
playTrack(audioUrl, title, artist);
}, 500);
return;
}
// Try the global player function first
if (typeof window.playTrackWithGlobalPlayer === 'function') {
const success = await window.playTrackWithGlobalPlayer(audioUrl, title, artist);
if (success) {
console.log('🎵 Global player playTrackWithGlobalPlayer successful');
return;
}
}
// Fallback to direct global player playTrack method
if (typeof window.globalPlayer.playTrack === 'function') {
try {
console.log('🎵 Trying fallback global player playTrack...');
window.globalPlayer.playTrack(audioUrl, title, artist);
console.log('🎵 Fallback playTrack call successful');
return;
} catch (error) {
console.error('🎵 Fallback playTrack failed:', error);
}
}
// Final fallback - show error
console.error('🎵 All playback methods failed, showing error message');
alert(`Failed to play: ${title} by ${artist}. Please try again.`);
}
// Social Functions
function toggleLike(trackId, button) {
fetch('/api_social.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'like', track_id: trackId })
})
.then(response => response.json())
.then(data => {
if (data.success) {
button.classList.toggle('liked');
const countSpan = button.querySelector('.social-count');
const currentCount = parseInt(countSpan.textContent);
countSpan.textContent = button.classList.contains('liked') ? currentCount + 1 : currentCount - 1;
}
});
}
function toggleFollow(userId, button) {
fetch('/api_social.php', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'follow', user_id: userId })
})
.then(response => response.json())
.then(data => {
if (data.success) {
button.classList.toggle('following');
button.textContent = button.classList.contains('following') ? 'Following' : 'Follow';
}
});
}
function showComments(trackId) {
// TODO: Implement comments modal
alert('Comments feature coming soon!');
}
</script>
<?php
// Include footer only for full page loads
if (!$is_ajax) {
include 'includes/footer.php';
} else {
// For AJAX requests, still include the global player
include 'includes/global_player.php';
echo '</div>';
}
?>