-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticle.php
More file actions
173 lines (153 loc) · 7.1 KB
/
article.php
File metadata and controls
173 lines (153 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
session_start();
require_once 'DbConnector.php';
require_once __DIR__ . '/config/env.php';
loadEnv(__DIR__ . '/.env');
$dbHost = getenv('DB_HOST');
$dbUser = getenv('DB_USER');
$dbPass = getenv('DB_PASS');
$dbName = getenv('DB_NAME');
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$db = new DbConnector($dbHost, $dbUser, $dbPass, $dbName);
$article_id = isset($_GET['id']) && is_numeric($_GET['id']) ? (int)$_GET['id'] : null;
// Fetch main article content and metadata
$query = "
SELECT a.id, a.title, a.content, a.summary, a.category, a.created_at, a.views, u.username, u.id as user_id
FROM articles a
INNER JOIN users u ON a.user_id = u.id
LEFT JOIN profile p ON u.id = p.user_id
WHERE a.id = :id AND a.visibility = 'public'
";
$stmt = $db->prepare($query);
$stmt->bindValue(':id', $article_id, PDO::PARAM_INT);
$stmt->execute();
$article = $stmt->fetch(PDO::FETCH_ASSOC);
// Increment view counter safely
$update_query = "UPDATE articles SET views = views + 1 WHERE id = :id";
$update_stmt = $db->prepare($update_query);
$update_stmt->bindValue(':id', $article_id, PDO::PARAM_INT);
$update_stmt->execute();
// Retrieve related articles from the same category
$related_query = "
SELECT a.id, a.title, a.summary, a.category, a.created_at, u.username
FROM articles a
INNER JOIN users u ON a.user_id = u.id
WHERE a.category = :category AND a.visibility = 'public' AND a.id != :id
ORDER BY a.created_at DESC
LIMIT 3
";
$related_stmt = $db->prepare($related_query);
$related_stmt->bindValue(':category', $article['category'], PDO::PARAM_STR);
$related_stmt->bindValue(':id', $article_id, PDO::PARAM_INT);
$related_stmt->execute();
$related_articles = $related_stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($article['title']) ?> - NextStudy</title>
<link rel="stylesheet" href="assets/css/article.css">
</head>
<body>
<div class="article-container">
<!-- Article Header Section -->
<header class="article-header">
<div class="article-breadcrumb">
<a href="./dashboard.php?page=resource">Risorse</a>
<span>›</span>
<span><?= ucfirst($article['category']) ?></span>
</div>
<h1 class="article-title"><?= htmlspecialchars($article['title']) ?></h1>
<p class="article-summary"><?= htmlspecialchars($article['summary']) ?></p>
<!-- Article Metadata -->
<div class="article-meta-header">
<div class="author-info">
<div class="author-details">
<span class="author-name"><?= htmlspecialchars($article['username']) ?></span>
<span class="meta-date">📅 <?= date("d M Y", strtotime($article['created_at'])) ?></span>
</div>
</div>
<div class="article-stats">
<span class="stat">👁️ <?= number_format($article['views']) ?> visualizzazioni</span>
<span class="stat category-badge"><?= ucfirst($article['category']) ?></span>
</div>
</div>
</header>
<div class="article-wrapper">
<!-- Main Content Section -->
<main class="article-main">
<article class="article-body">
<?= nl2br(htmlspecialchars($article['content'])) ?>
</article>
<!-- Social Share Buttons -->
<div class="article-share">
<h3>Condividi articolo</h3>
<div class="share-buttons">
<a href="https://www.facebook.com/sharer/sharer.php?u=<?= urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?>"
target="_blank" class="share-btn share-facebook" title="Condividi su Facebook">
f
</a>
<a href="https://twitter.com/intent/tweet?text=<?= urlencode($article['title']) ?>&url=<?= urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?>"
target="_blank" class="share-btn share-twitter" title="Condividi su Twitter">
𝕏
</a>
<a href="https://www.linkedin.com/sharing/share-offsite/?url=<?= urlencode($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']) ?>"
target="_blank" class="share-btn share-linkedin" title="Condividi su LinkedIn">
in
</a>
<button class="share-btn share-copy" onclick="copyToClipboard()" title="Copia link">
🔗
</button>
</div>
</div>
<!-- Return to resource list -->
<div class="article-back">
<a href="./dashboard.php?page=resource" class="back-button">← Torna alle risorse</a>
</div>
</main>
<!-- Sidebar Section -->
<aside class="article-sidebar">
<!-- Category card -->
<div class="sidebar-card">
<h3>Categoria</h3>
<p class="category-info"><?= ucfirst($article['category']) ?></p>
</div>
<!-- Related Articles Section -->
<?php if ($related_articles): ?>
<div class="sidebar-card">
<h3>Articoli Correlati</h3>
<div class="related-articles">
<?php foreach ($related_articles as $rel): ?>
<a href="article.php?id=<?= $rel['id'] ?>" class="related-item">
<h4><?= htmlspecialchars($rel['title']) ?></h4>
<span class="related-date">📅 <?= date("d M Y", strtotime($rel['created_at'])) ?></span>
</a>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
<!-- Author Information -->
<div class="sidebar-card author-card">
<p class="author-role">Amministratore Contenuti</p>
<p class="author-bio">Selezionato per la qualità e la profondità dei contenuti didattici.</p>
</div>
</aside>
</div>
</div>
<script>
function copyToClipboard() {
const url = window.location.href;
navigator.clipboard.writeText(url).then(() => {
alert('Link copiato negli appunti!');
}).catch(() => {
alert('Errore nel copiare il link');
});
}
</script>
</body>
</html>