![]() 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/-1dd6b30f/ |
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php');
exit;
}
require_once 'config/database.php';
$pdo = getDBConnection();
$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';
// Get feed tracks - show recent tracks from followed users first, then recent tracks as fallback
$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 20
");
$stmt->execute([$user_id]);
$feed_tracks = $stmt->fetchAll();
// Get suggested users to follow
$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();
// 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 'includes/header.php';
?>
<div class="main-content">
<style>
/* Main Content */
.main-content {
margin-top: 0;
padding: 0;
min-height: calc(100vh - 100px);
}
/* 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;
}
.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, #667eea, #764ba2);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
.hero-description {
font-size: 2rem;
color: #a0aec0;
margin-bottom: 4rem;
max-width: 60rem;
margin-left: auto;
margin-right: auto;
}
/* Feed Layout */
.feed-container {
max-width: 120rem;
margin: 0 auto;
padding: 0 2rem;
display: grid;
grid-template-columns: 1fr 30rem;
gap: 4rem;
}
.feed-main {
min-height: 50rem;
}
.feed-sidebar {
position: sticky;
top: 2rem;
height: fit-content;
}
/* Track Cards */
.track-card {
background: rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 2.4rem;
margin-bottom: 2rem;
border: 1px solid rgba(255, 255, 255, 0.1);
transition: all 0.3s ease;
position: relative;
}
.track-card:hover {
transform: translateY(-4px);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
border-color: rgba(102, 126, 234, 0.3);
}
.track-header {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: 2rem;
}
.track-info {
display: flex;
align-items: center;
gap: 1.6rem;
flex: 1;
}
.artist-profile {
position: relative;
}
.default-avatar {
width: 6rem;
height: 6rem;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
display: flex;
align-items: center;
justify-content: center;
font-size: 2.4rem;
font-weight: 700;
color: white;
cursor: pointer;
transition: all 0.3s ease;
}
.default-avatar:hover {
transform: scale(1.1);
}
.track-details-info {
flex: 1;
}
.track-title {
font-size: 2.4rem;
font-weight: 700;
color: white;
margin-bottom: 0.5rem;
display: flex;
align-items: center;
gap: 1rem;
}
.playable-badge {
background: linear-gradient(135deg, #48bb78, #38a169);
color: white;
padding: 0.4rem 1rem;
border-radius: 20px;
font-size: 1.2rem;
font-weight: 600;
display: flex;
align-items: center;
gap: 0.5rem;
}
.track-artist {
font-size: 1.6rem;
color: #a0aec0;
font-weight: 500;
}
.track-stats {
display: flex;
gap: 2rem;
align-items: center;
}
.stat-item {
display: flex;
align-items: center;
gap: 0.5rem;
color: #a0aec0;
font-size: 1.4rem;
}
.track-prompt {
background: rgba(255, 255, 255, 0.05);
padding: 1.6rem;
border-radius: 12px;
margin-bottom: 2rem;
font-size: 1.4rem;
line-height: 1.6;
color: #e2e8f0;
}
.track-details {
display: flex;
gap: 2rem;
margin-bottom: 2rem;
font-size: 1.4rem;
color: #a0aec0;
}
.track-details span {
display: flex;
align-items: center;
gap: 0.5rem;
}
.status-badge {
padding: 0.4rem 1rem;
border-radius: 20px;
font-size: 1.2rem;
font-weight: 600;
}
.status-complete {
background: linear-gradient(135deg, #48bb78, #38a169);
color: white;
}
.track-actions {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
}
.btn {
padding: 1.2rem 2.4rem;
border: none;
border-radius: 12px;
font-size: 1.4rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 0.8rem;
text-decoration: none;
}
.btn-primary {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
}
.btn-primary:hover {
transform: translateY(-2px);
box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}
.btn-secondary {
background: rgba(255, 255, 255, 0.1);
color: white;
border: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-secondary:hover {
background: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.social-actions {
display: flex;
gap: 1rem;
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);
border-radius: 12px;
padding: 1rem 1.5rem;
color: #a0aec0;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 0.8rem;
font-size: 1.4rem;
}
.social-btn:hover {
background: rgba(255, 255, 255, 0.1);
color: white;
}
.social-btn.liked {
background: linear-gradient(135deg, #e53e3e, #c53030);
color: white;
border-color: #e53e3e;
}
.social-count {
font-weight: 600;
}
/* Sidebar */
.sidebar-section {
background: rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 2.4rem;
margin-bottom: 2rem;
border: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-title {
font-size: 2rem;
font-weight: 700;
color: white;
margin-bottom: 2rem;
}
.suggested-user {
display: flex;
align-items: center;
gap: 1.2rem;
padding: 1.2rem 0;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.suggested-user:last-child {
border-bottom: none;
}
.user-avatar {
width: 4rem;
height: 4rem;
border-radius: 50%;
background: linear-gradient(135deg, #667eea, #764ba2);
display: flex;
align-items: center;
justify-content: center;
font-size: 1.6rem;
font-weight: 700;
color: white;
}
.user-info {
flex: 1;
}
.user-name {
font-size: 1.4rem;
font-weight: 600;
color: white;
margin-bottom: 0.3rem;
}
.user-stats {
font-size: 1.2rem;
color: #a0aec0;
}
.follow-btn {
background: linear-gradient(135deg, #667eea, #764ba2);
color: white;
border: none;
border-radius: 8px;
padding: 0.8rem 1.6rem;
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(255, 255, 255, 0.1);
color: #a0aec0;
}
/* Empty State */
.empty-state {
text-align: center;
padding: 8rem 2rem;
color: #a0aec0;
}
.empty-icon {
font-size: 8rem;
margin-bottom: 2rem;
}
.empty-title {
font-size: 3.2rem;
font-weight: 700;
color: white;
margin-bottom: 1.6rem;
}
.empty-description {
font-size: 1.8rem;
margin-bottom: 4rem;
max-width: 50rem;
margin-left: auto;
margin-right: auto;
}
/* Responsive */
@media (max-width: 1024px) {
.feed-container {
grid-template-columns: 1fr;
gap: 2rem;
}
.feed-sidebar {
position: static;
}
}
@media (max-width: 768px) {
.hero-title {
font-size: 4rem;
}
.track-header {
flex-direction: column;
gap: 1.6rem;
}
.track-stats {
justify-content: flex-start;
}
.track-actions {
flex-direction: column;
}
.social-actions {
flex-wrap: wrap;
}
}
</style>
<!-- Hero Section -->
<section class="hero">
<div class="container">
<div class="hero-content">
<div class="hero-badge">🎵 Your Music Feed</div>
<h1 class="hero-title">Discover Amazing AI Music</h1>
<p class="hero-description">
Explore the latest tracks from our creative community. Get inspired by AI-generated music from talented artists around the world.
</p>
</div>
</div>
</section>
<!-- Feed Content -->
<div class="feed-container">
<div class="feed-main">
<h2 style="font-size: 3.2rem; font-weight: 700; color: white; margin-bottom: 3rem;">
Latest Community Tracks
</h2>
<?php if (empty($feed_tracks)): ?>
<div class="empty-state">
<div class="empty-icon">🎵</div>
<h3 class="empty-title">No tracks yet</h3>
<p class="empty-description">Be the first to create amazing AI music and share it with the community!</p>
<a href="/create.php" class="btn btn-primary">
<i class="fas fa-plus"></i> Create Your First Track
</a>
</div>
<?php else: ?>
<?php foreach ($feed_tracks as $track): ?>
<div class="track-card" data-track-id="<?= $track['id'] ?>">
<div class="track-header">
<div class="track-info">
<div class="artist-profile">
<div class="default-avatar clickable-avatar"
title="<?= htmlspecialchars($track['artist_name']) ?>'s profile"
onclick="window.location.href='/artist_profile.php?id=<?= $track['artist_id'] ?>'">
<?= strtoupper(substr(htmlspecialchars($track['artist_name']), 0, 1)) ?>
</div>
</div>
<div class="track-details-info">
<div class="track-title">
<?= htmlspecialchars($track['title']) ?>
<span class="playable-badge" title="Available for playback">
<i class="fas fa-play-circle"></i> Playable
</span>
</div>
<div class="track-artist">by <?= htmlspecialchars($track['artist_name']) ?></div>
</div>
</div>
<div class="track-stats">
<span class="stat-item" title="Likes">
<i class="fas fa-heart"></i> <?= number_format($track['like_count']) ?>
</span>
<span class="stat-item" title="Comments">
<i class="fas fa-comment"></i> <?= number_format($track['comment_count']) ?>
</span>
</div>
</div>
<div class="track-prompt">
<strong>Original Prompt:</strong> <?= htmlspecialchars(substr($track['prompt'], 0, 150)) ?>...
</div>
<div class="track-details">
<span><i class="fas fa-clock"></i> <?= floor($track['duration'] / 60) ?>m <?= $track['duration'] % 60 ?>s</span>
<span><i class="fas fa-calendar"></i> <?= date('M j, Y', strtotime($track['created_at'])) ?></span>
<span class="status-badge status-complete">
Complete
</span>
</div>
<div class="track-actions">
<button class="btn btn-primary play-track-btn"
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">
<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>
<button class="social-btn" onclick="shareTrack(<?= $track['id'] ?>, '<?= htmlspecialchars($track['title']) ?>')">
<i class="fas fa-share"></i>
</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>
</div>
<script>
// Feed page functionality
// Play track with global player
function playTrack(audioUrl, title, artist) {
console.log('🎵 Feed playTrack called:', { audioUrl, title, artist });
// Validate audio URL
if (!audioUrl || audioUrl === 'null' || audioUrl === 'undefined' || audioUrl === '') {
console.error('🎵 INVALID AUDIO URL:', audioUrl);
return;
}
// Use the global player function
if (typeof window.playTrackWithGlobalPlayer === 'function') {
try {
window.playTrackWithGlobalPlayer(audioUrl, title, artist);
} catch (error) {
console.error('🎵 Global player error:', error);
}
} else if (typeof window.globalPlayer !== 'undefined' && window.globalPlayer.playTrack) {
try {
window.globalPlayer.playTrack(audioUrl, title, artist);
} catch (error) {
console.error('🎵 Direct global player error:', error);
}
} else {
console.error('🎵 Global player not available');
}
}
// Toggle like
function toggleLike(trackId, button) {
if (!<?= $user_id ? 'true' : 'false' ?>) {
alert('Please log in to like tracks');
return;
}
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');
if (countSpan) {
const currentCount = parseInt(countSpan.textContent);
countSpan.textContent = data.liked ? currentCount + 1 : currentCount - 1;
}
}
})
.catch(error => console.error('Like error:', error));
}
// Toggle follow
function toggleFollow(userId, button) {
if (!<?= $user_id ? 'true' : 'false' ?>) {
alert('Please log in to follow users');
return;
}
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 = data.following ? 'Following' : 'Follow';
}
})
.catch(error => console.error('Follow error:', error));
}
// Show comments (placeholder)
function showComments(trackId) {
alert('Comments feature coming soon!');
}
// Share track
function shareTrack(trackId, title) {
const shareUrl = `${window.location.origin}/artist_profile.php?id=${trackId}`;
const shareText = `Check out "${title}" on SoundStudioPro! 🎵`;
if (navigator.share) {
navigator.share({
title: title,
text: shareText,
url: shareUrl
});
} else {
navigator.clipboard.writeText(`${shareText}\n${shareUrl}`).then(() => {
alert('Track link copied to clipboard!');
});
}
}
// Page load
document.addEventListener('DOMContentLoaded', function() {
console.log('🎵 Feed page loaded');
console.log('🎵 Global player status:', typeof window.globalPlayer !== 'undefined');
console.log('🎵 playTrackWithGlobalPlayer function exists:', typeof window.playTrackWithGlobalPlayer === 'function');
});
</script>
<?php include 'includes/footer.php'; ?>