<?php
include 'includes/db.php';
include 'includes/header.php';
if (!isset($_GET['id'])) {
header("Location: news.php");
exit();
}
$id = $_GET['id'];
$stmt = $conn->prepare("SELECT * FROM news WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$article = $result->fetch_assoc();
if (!$article) {
header("Location: news.php");
exit();
}
?>
<div id="main-content" class="container mt-5">
<!-- Back button -->
<div class="row mb-4">
<div class="col-12">
<a href="news.php" class="btn btn-outline-warning">
<i class="fas fa-arrow-right me-2"></i>العودة للأخبار
</a>
</div>
</div>
<div class="row justify-content-center">
<div class="col-lg-8 col-md-10 col-12">
<!-- Post content-->
<article class="glass-card">
<!-- Post header-->
<header class="mb-4 text-center">
<!-- Post title-->
<h1 class="fw-bolder mb-3 text-warning"><?php echo htmlspecialchars($article['title']); ?></h1>
<!-- Post meta content-->
<div class="text-muted mb-3">
<i class="fas fa-calendar-alt me-2"></i>
<?php echo date('d F Y', strtotime($article['created_at'])); ?>
</div>
</header>
<!-- Preview image figure-->
<figure class="mb-4 text-center">
<img class="img-fluid rounded shadow-lg"
src="uploads/news/<?php echo htmlspecialchars($article['image']); ?>"
alt="<?php echo htmlspecialchars($article['title']); ?>"
style="max-height: 400px; width: 100%; object-fit: cover;">
</figure>
<!-- Post video (if available) -->
<?php if (!empty($article['video_type']) && $article['video_type'] !== 'none'): ?>
<div class="mb-4 text-center">
<div class="ratio ratio-16x9 shadow-lg rounded" style="overflow: hidden;">
<?php if ($article['video_type'] === 'url' && !empty($article['video_url'])): ?>
<?php
$video_url = $article['video_url'];
if (strpos($video_url, 'youtube.com/watch?v=') !== false) {
$video_id = parse_url($video_url, PHP_URL_QUERY);
parse_str($video_id, $params);
$video_url = 'https://www.youtube.com/embed/' . ($params['v'] ?? '');
} elseif (strpos($video_url, 'youtu.be/') !== false) {
$video_id = basename(parse_url($video_url, PHP_URL_PATH));
$video_url = 'https://www.youtube.com/embed/' . $video_id;
}
?>
<iframe src="<?php echo htmlspecialchars($video_url); ?>"
title="فيديو الخبر"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
class="rounded">
</iframe>
<?php elseif ($article['video_type'] === 'file' && !empty($article['video_file'])): ?>
<video src="uploads/news/<?php echo htmlspecialchars($article['video_file']); ?>"
controls
class="rounded"
style="width: 100%; height: 100%; object-fit: cover;">
</video>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
<!-- Post content-->
<section class="mb-4">
<div class="fs-5 mb-4 text-light" style="line-height: 1.8;">
<?php echo nl2br(htmlspecialchars($article['content'])); ?>
</div>
</section>
<!-- Share buttons -->
<div class="border-top pt-4 mt-4">
<h6 class="text-warning mb-3">شارك هذا الخبر:</h6>
<div class="d-flex flex-wrap gap-2">
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>"
target="_blank" class="btn btn-primary btn-sm">
<i class="fab fa-facebook-f me-1"></i>فيسبوك
</a>
<a href="https://twitter.com/intent/tweet?url=<?php echo urlencode('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>&text=<?php echo urlencode($article['title']); ?>"
target="_blank" class="btn btn-info btn-sm">
<i class="fab fa-twitter me-1"></i>تويتر
</a>
<a href="https://wa.me/?text=<?php echo urlencode($article['title'] . ' - ' . 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); ?>"
target="_blank" class="btn btn-success btn-sm">
<i class="fab fa-whatsapp me-1"></i>واتساب
</a>
<button onclick="copyToClipboard()" class="btn btn-secondary btn-sm">
<i class="fas fa-copy me-1"></i>نسخ الرابط
</button>
</div>
</div>
</article>
</div>
</div>
</div>
<script>
function copyToClipboard() {
const url = window.location.href;
navigator.clipboard.writeText(url).then(function() {
alert('تم نسخ الرابط بنجاح!');
}, function(err) {
console.error('خطأ في نسخ الرابط: ', err);
});
}
</script>
<?php include 'includes/footer.php'; ?>