-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
309 lines (268 loc) · 16.4 KB
/
index.php
File metadata and controls
309 lines (268 loc) · 16.4 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
session_start();
require_once 'function.php';
if (!isset($_COOKIE['spotify_access_token']) && isset($_SESSION['profile'])) {
session_destroy();
setcookie('spotify_access_token', '', time() - 3600, '/');
header('Location: index.php');
}
$token = $_COOKIE['spotify_access_token'] ?? null;
$profile = $_SESSION['profile'] ?? null;
$artistsData = fetchFollowedArtists($token);
$artists = $artistsData['artists']['items'] ?? [];
if (isset($_POST['artistId'], $_POST['action'])) {
$artistId = $_POST['artistId'];
$action = $_POST['action'];
if ($action === 'follow') {
followArtist($token, $artistId);
} elseif ($action === 'unfollow') {
unfollowArtist($token, $artistId);
}
$searchParam = $_POST['searchString'] ?? $_GET['searchString'] ?? '';
header('Location: index.php' . ($searchParam ? '?searchString=' . urlencode($searchParam) : ''));
exit();
}
// Gestion de la recherche
$searchResults = null;
if (isset($_GET['searchString']) && !empty($_GET['searchString'])) {
$searchResults = SearchByString($_COOKIE['spotify_access_token'] ?? null, $_GET['searchString']);
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Spotify Profile - Style Deezer</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php if ($profile): ?>
<iframe data-testid="embed-iframe"
style="border-radius:12px; position: fixed; bottom: -70px; z-index: 3;"
src="https://open.spotify.com/embed/track/069qGKeTqlWGD8lphrGG9R?utm_source=generator"
width="100%"
height="150"
frameBorder=""
allowfullscreen=""
allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture"
loading="lazy">
</iframe>
<?php endif; ?>
<div class="header">
<h1>Mon Profil Spotify</h1>
</div>
<div class="container" style="margin-bottom: 220px;">
<?php if (!$profile): ?>
<div class="login-section">
<a href="spotify.php" class="login-btn">Se connecter à Spotify</a>
</div>
<?php else: ?>
<div class="card">
<a href="spotify.php?logout=1" class="logout-btn">Se déconnecter</a>
<h2>Informations du Profil</h2>
<div class="profile-header">
<div class="avatar">
<?php if (!empty($profile['images'][0]['url'])): ?>
<img src="<?= htmlspecialchars($profile['images'][0]['url']) ?>"
alt="Profile Image">
<?php endif; ?>
</div>
<div class="profile-details">
<h3><?= htmlspecialchars($profile['display_name'] ?? 'Utilisateur Spotify') ?></h3>
<p class="artist-info">ID: <?= htmlspecialchars($profile['id'] ?? 'N/A') ?></p>
<p class="artist-info"><?= htmlspecialchars($profile['email'] ?? 'N/A') ?></p>
</div>
</div>
<div class="profile-stats">
<div class="stat-item">
<strong>Pays</strong>
<div class="stat-value"><?= htmlspecialchars($profile['country'] ?? 'N/A') ?></div>
</div>
<div class="stat-item">
<strong>Abonnés</strong>
<div class="stat-value"><?= number_format($profile['followers']['total'] ?? 0, 0, ',', ' ') ?></div>
</div>
</div>
</div>
<!-- Formulaire de recherche -->
<div class="card">
<h2>Rechercher</h2>
<form method="GET" action="" class="search-form">
<input type="text"
name="searchString"
class="search-input"
placeholder="Rechercher..."
value="<?= htmlspecialchars($_GET['searchString'] ?? '') ?>">
<button type="submit" class="search-btn">
Rechercher
</button>
</form>
<?php if (isset($_GET['searchString']) && !empty($_GET['searchString'])): ?>
<div class="search-results">
<p><strong>Recherche :</strong> <span class="search-term">"<?= htmlspecialchars($_GET['searchString']) ?>"</span></p>
<?php if ($searchResults): ?>
<!-- Affichage des artistes -->
<?php if (!empty($searchResults['artists']['items'])): ?>
<h3>Artistes</h3>
<div class="artists-grid">
<?php foreach (array_slice($searchResults['artists']['items'], 0) as $artist): ?>
<div class="artist-card">
<?php if (!empty($artist['images'][0]['url'])): ?>
<img src="<?= htmlspecialchars($artist['images'][0]['url']) ?>"
alt="<?= htmlspecialchars($artist['name']) ?>"
class="artist-image">
<?php else: ?>
<div class="placeholder-image">
</div>
<?php endif; ?>
<a href="<?= htmlspecialchars($artist['external_urls']['spotify'] ?? '#') ?>"
target="_blank"
class="artist-name">
<?= htmlspecialchars($artist['name']) ?>
</a>
<?php if (!empty($artist['genres'])): ?>
<div class="genres">
<?php foreach (array_slice($artist['genres'], 0) as $genre): ?>
<span class="genre-tag"><?= htmlspecialchars($genre) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="artist-info">
<strong>Popularité:</strong> <?= htmlspecialchars($artist['popularity'] ?? 0) ?>/100
</div>
<div class="popularity-bar">
<div class="popularity-fill" style="width: <?= ($artist['popularity'] ?? 0) ?>%"></div>
</div>
<div class="artist-info">
<strong>Abonnés:</strong>
<?= number_format($artist['followers']['total'] ?? 0, 0, ',', ' ') ?>
</div>
<form action="" method="POST">
<input type="hidden" name="artistId" value="<?= htmlspecialchars($artist['id']) ?>">
<input type="hidden" name="searchString" value="<?=$_GET['searchString'] ?? '' ?>">
<?php if (isFollowingArtist($_COOKIE['spotify_access_token'], $artist['id'])): ?>
<input type="hidden" name="action" value="unfollow">
<button type="submit" class="unfollow-btn">
Ne plus suivre
</button>
<?php else: ?>
<input type="hidden" name="action" value="follow">
<button type="submit" class="follow-btn">
Suivre
</button>
<?php endif; ?>
</form>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- Affichage des pistes -->
<?php if (!empty($searchResults['tracks']['items'])): ?>
<h3>Pistes</h3>
<div class="artists-grid">
<?php foreach (array_slice($searchResults['tracks']['items'], 0) as $track): ?>
<div class="artist-card" onclick="playTrack('<?= $track['id'] ?>')">
<?php if (!empty($track['album']['images'][0]['url'])): ?>
<img src="<?= htmlspecialchars($track['album']['images'][0]['url']) ?>"
alt="<?= htmlspecialchars($track['name']) ?>"
class="artist-image">
<?php else: ?>
<div class="placeholder-image">
</div>
<?php endif; ?>
<a href="<?= htmlspecialchars($track['external_urls']['spotify'] ?? '#') ?>"
target="_blank"
class="artist-name">
<?= htmlspecialchars($track['name']) ?>
</a>
<div class="artist-info">
<strong>Par:</strong> <?= htmlspecialchars($track['artists'][0]['name'] ?? 'Inconnu') ?>
</div>
<div class="artist-info">
<strong>Album:</strong> <?= htmlspecialchars($track['album']['name'] ?? 'Inconnu') ?>
</div>
<div class="artist-info">
<strong>Popularité:</strong> <?= htmlspecialchars($track['popularity'] ?? 0) ?>/100
</div>
<div class="popularity-bar">
<div class="popularity-fill" style="width: <?= ($track['popularity'] ?? 0) ?>%"></div>
</div>
<div class="artist-info">
<strong>Durée:</strong>
<?= gmdate("i:s", ($track['duration_ms'] ?? 0) / 1000) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php else: ?>
<p class="search-info">Aucun résultat trouvé ou erreur lors de la recherche.</p>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<!-- Artistes suivis -->
<div class="card">
<h2>Artistes Suivis</h2>
<?php if (!empty($artists)): ?>
<div class="artists-grid">
<?php foreach ($artists as $artist): ?>
<div class="artist-card">
<!-- Image de l'artiste -->
<?php if (!empty($artist['images'][0]['url'])): ?>
<img src="<?= htmlspecialchars($artist['images'][0]['url']) ?>"
alt="<?= htmlspecialchars($artist['name']) ?>"
class="artist-image">
<?php else: ?>
<div class="placeholder-image">
<p>Aucune image disponible</p>
</div>
<?php endif; ?>
<!-- Nom de l'artiste -->
<a href="<?= htmlspecialchars($artist['external_urls']['spotify'] ?? '#') ?>"
target="_blank"
class="artist-name">
<?= htmlspecialchars($artist['name']) ?>
</a>
<!-- Genres -->
<?php if (!empty($artist['genres'])): ?>
<div class="genres">
<?php foreach (array_slice($artist['genres'], 0, 3) as $genre): ?>
<span class="genre-tag"><?= htmlspecialchars($genre) ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<!-- Popularité -->
<div class="artist-info">
<strong>Popularité:</strong> <?= htmlspecialchars($artist['popularity'] ?? 0) ?>/100
</div>
<div class="popularity-bar">
<div class="popularity-fill" style="width: <?= ($artist['popularity'] ?? 0) ?>%"></div>
</div>
<!-- Abonnés -->
<div class="artist-info">
<strong>Abonnés:</strong>
<?= number_format($artist['followers']['total'] ?? 0, 0, ',', ' ') ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p class="artist-info" style="text-align: center; font-style: italic;">
Aucun artiste suivi trouvé.
</p>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</body>
<script>
function playTrack(trackId) {
const iframe = document.querySelector('iframe');
if (iframe) {
iframe.src = `https://open.spotify.com/embed/track/${trackId}?utm_source=generator`;
}
}
</script>
</html>