Podcast-server/index.php

99 lines
6.5 KiB
PHP

<?php
require_once 'includes/header.php';
// Fetch episodes ordered by latest release date with play counts
$sql = "SELECT e.*, COUNT(p.id) as play_count
FROM episodes e
LEFT JOIN plays p ON e.id = p.episode_id
GROUP BY e.id
ORDER BY release_date DESC";
$stmt = $pdo->query($sql);
$episodes = $stmt->fetchAll();
$banner_url = PROJECT_ROOT_URL . "/assets/uploads/images/" . $banner_image;
if ($banner_image === 'default-banner.jpg') {
// Check if default exists, if not use a placeholder gradient
$banner_url = "https://images.unsplash.com/photo-1478737270239-2f02b77fc618?auto=format&fit=crop&q=80&w=1920&h=400";
}
?>
<div class="hero" style="background-image: url('<?php echo $banner_url; ?>');">
<div class="hero-content">
<h1><?php echo htmlspecialchars($site_title); ?></h1>
<p>Listen to our latest messages and sermons.</p>
<div style="margin-top: 2rem; display: flex; gap: 1rem; justify-content: center;">
<a href="subscribe.php" class="btn btn-primary">How to Subscribe</a>
<a href="feed.php" class="btn" style="background: rgba(255,255,255,0.1); backdrop-filter: blur(10px); border: 1px solid var(--glass-border);">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="vertical-align: middle; margin-right: 0.5rem;"><path d="M4 11a9 9 0 0 1 9 9"></path><path d="M4 4a16 16 0 0 1 16 16"></path><circle cx="5" cy="19" r="1"></circle></svg>
RSS Feed
</a>
</div>
</div>
</div>
<div class="container">
<?php foreach ($episodes as $episode): ?>
<article class="episode-card" id="episode-<?php echo $episode['id']; ?>">
<div style="display: flex; gap: 2rem; align-items: flex-start;">
<?php if ($episode['cover_image']): ?>
<div class="episode-cover">
<img src="<?php echo PROJECT_ROOT_URL; ?>/assets/uploads/images/<?php echo $episode['cover_image']; ?>" alt="<?php echo htmlspecialchars($episode['title']); ?>" style="width: 200px; height: 200px; object-fit: cover; border-radius: 16px; border: 1px solid var(--glass-border);">
</div>
<?php endif; ?>
<div style="flex: 1;">
<div class="episode-meta">
Released on <?php echo formatDate($episode['release_date']); ?> &bull;
<span style="color: var(--primary-color); font-weight: 600;"><?php echo number_format($episode['play_count']); ?> listens</span>
</div>
<h2 class="episode-title"><?php echo htmlspecialchars($episode['title']); ?></h2>
<div class="episode-description">
<?php echo nl2br(htmlspecialchars($episode['description'])); ?>
</div>
</div>
</div>
<div class="audio-player-wrapper">
<audio controls preload="none">
<source src="<?php echo PROJECT_ROOT_URL; ?>/assets/uploads/audio/<?php echo $episode['audio_file']; ?>" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
</div>
<div class="episode-actions" style="justify-content: space-between;">
<div style="display: flex; gap: 1.5rem; align-items: center;">
<a href="<?php echo PROJECT_ROOT_URL; ?>/assets/uploads/audio/<?php echo $episode['audio_file']; ?>" class="download-link" download>
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>
Download Episode
</a>
</div>
<div class="share-group">
<span style="font-size: 0.8rem; color: var(--text-muted); margin-right: 0.5rem;">Share:</span>
<?php
$share_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]" . PROJECT_ROOT_URL . "/#episode-" . $episode['id'];
$share_title = urlencode($episode['title'] . " - " . $site_title);
?>
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode($share_url); ?>" target="_blank" class="share-btn" title="Share on Facebook">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"></path></svg>
</a>
<a href="mailto:?subject=<?php echo $share_title; ?>&body=Listen to this episode: <?php echo urlencode($share_url); ?>" class="share-btn" title="Share via Email">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 4h16c1.1 0 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1 0-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg>
</a>
<button id="share-copy-<?php echo $episode['id']; ?>" onclick="copyToClipboard('<?php echo $share_url; ?>', 'share-copy-<?php echo $episode['id']; ?>')" class="share-btn" title="Copy Link">
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
</button>
</div>
</div>
</article>
<?php endforeach; ?>
<?php if (empty($episodes)): ?>
<div style="text-align: center; padding: 4rem; background: var(--bg-card); border-radius: 24px; border: 1px solid var(--glass-border);">
<h3>Welcome to our Podcast!</h3>
<p style="color: var(--text-muted); margin-top: 1rem;">We haven't uploaded any episodes yet. Please check back soon!</p>
</div>
<?php endif; ?>
</div>
<?php require_once 'includes/footer.php'; ?>