D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
skyconb
/
newsyacine
/
Filename :
article.php
back
Copy
<?php // =============================================== // article.php (صفحة عرض مقال واحد - مع Nav Menu) // =============================================== include 'db_connect.php'; // 1. تحديد العنوان المختصر (Slug) من الرابط $article_slug = $_GET['slug'] ?? ''; $article = null; // 🎯 يجب تعديل المسار الأساسي هنا // إذا كان مشروعك مباشرة في جذر السيرفر (مثل http://localhost/) استخدم: "/" // إذا كان مشروعك داخل مجلد فرعي (مثل http://localhost/my_site/) استخدم: "/my_site/" $path_prefix = "/"; // ⬅️ قم بتعديل هذا المسار ليناسب مشروعك (مثلاً: /my_site/) $base_url = "http://" . $_SERVER['HTTP_HOST'] . $path_prefix; // تعريف المتغيرات الافتراضية لـ Open Graph (في حالة عدم العثور على المقال) $page_title = "مقالات إخبارية"; $og_title = "المقال غير موجود"; $og_description = "عفواً، المقال الذي تبحث عنه غير موجود حالياً."; $og_image = $base_url . "default_share_image.jpg"; // صورة افتراضية للمشاركة $og_url = $base_url . "articles_list.php"; // رابط لقائمة المقالات // 2. محاولة جلب المقال if (!empty($article_slug)) { $sql = "SELECT a.title, a.content, a.created_at, u.username, a.thumbnail_url, a.slug FROM articles a LEFT JOIN users u ON a.author_id = u.id WHERE a.slug = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("s", $article_slug); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 1) { $article = $result->fetch_assoc(); } $stmt->close(); } // 3. تحديث المتغيرات إذا تم العثور على المقال if ($article) { $page_title = htmlspecialchars($article['title']); $og_title = htmlspecialchars($article['title']); // إعداد الوصف $og_description = strip_tags($article['content']); $og_description = (strlen($og_description) > 150) ? mb_substr($og_description, 0, 147, 'utf-8') . '...' : $og_description; $og_description = htmlspecialchars($og_description); // بناء رابط الصورة الكامل (Absolute URL) if (!empty($article['thumbnail_url'])) { $og_image = $base_url . htmlspecialchars($article['thumbnail_url']); } // بناء رابط الصفحة الحالي $og_url = $base_url . "article.php?slug=" . urlencode($article['slug']); } else { // إذا لم يتم العثور على المقال http_response_code(404); } $conn->close(); ?> <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title><?php echo $page_title; ?></title> <meta property="og:title" content="<?php echo $og_title; ?>" /> <meta property="og:description" content="<?php echo $og_description; ?>" /> <meta property="og:image" content="<?php echo $og_image; ?>" /> <meta property="og:url" content="<?php echo $og_url; ?>" /> <meta property="og:type" content="article" /> <meta property="og:site_name" content="اسم موقعك هنا" /> <meta property="og:locale" content="ar_AR" /> <meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="<?php echo $og_title; ?>"> <meta name="twitter:description" content="<?php echo $og_description; ?>"> <meta name="twitter:image" content="<?php echo $og_image; ?>"> <style> body { font-family: Tahoma, sans-serif; line-height: 1.6; color: #333; background-color: #f8f8f8; margin: 0; padding-top: 60px; /* مسافة للـ nav bar */ } /* 🎯 تنسيق شريط التنقل العلوي */ .main-nav { position: fixed; top: 0; right: 0; left: 0; background-color: #2c3e50; padding: 10px 0; box-shadow: 0 2px 5px rgba(0,0,0,0.2); z-index: 1000; } .main-nav ul { max-width: 900px; margin: 0 auto; list-style: none; padding: 0 20px; display: flex; justify-content: flex-start; /* لتبدأ القائمة من اليمين */ } .main-nav ul li a { color: white; text-decoration: none; padding: 10px 15px; transition: background-color 0.3s; margin-left: 10px; font-weight: bold; border-radius: 4px; } .main-nav ul li a:hover { background-color: #34495e; } .container { max-width: 900px; margin: 0 auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.05); } h1 { color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-bottom: 15px; } .article-meta { color: #7f8c8d; font-size: 0.9em; margin-bottom: 25px; } .article-meta span { margin-left: 15px; } .article-content p { margin-bottom: 20px; text-align: justify; } .not-found { color: #e74c3c; text-align: center; padding: 50px; } .main-article-image { max-width: 100%; height: auto; border-radius: 5px; margin-bottom: 20px; display: block; } </style> </head> <body> <nav class="main-nav"> <ul> <li><a href="<?php echo $base_url; ?>">الرئيسية</a></li> <li><a href="<?php echo $base_url . 'articles_list.php'; ?>">الاخبار</a></li> <li><a href="<?php echo $base_url . 'video.php'; ?>">مباشر</a></li> </ul> </nav> <div class="container"> <?php if ($article): ?> <article> <h1><?php echo $page_title; ?></h1> <div class="article-meta"> <span>الكاتب: <?php echo htmlspecialchars($article['username'] ?? 'غير معروف'); ?></span> <span>تاريخ النشر: <?php echo date("Y-m-d", strtotime($article['created_at'])); ?></span> </div> <?php if (!empty($article['thumbnail_url'])): ?> <img src="<?php echo $base_url . htmlspecialchars($article['thumbnail_url']); ?>" alt="<?php echo $page_title; ?>" class="main-article-image"> <?php endif; ?> <div class="article-content"> <?php echo nl2br(htmlspecialchars($article['content'])); ?> </div> </article> <?php else: ?> <div class="not-found"> <h1>عفواً!</h1> <p>المقال الذي تبحث عنه غير موجود حالياً.</p> </div> <?php endif; ?> </div> </body> </html>