Repository navigation
Expand file tree
/
Copy pathfeed.php
More file actions
99 lines (69 loc) · 1.93 KB
/
Copy pathfeed.php
File metadata and controls
99 lines (69 loc) · 1.93 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
<?php
require __DIR__.'/database.php';
require __DIR__.'/_nav.php';
$uid = (int)($_GET['user_id'] ?? 0);
$cid = (int)($_GET['channel_id'] ?? 0);
if (!$uid || !$cid) die("Missing params");
$c = db_connect();
if (isset($_GET['action'])) {
if ($_GET['action']==='sub') {
$c->query("INSERT IGNORE INTO subscriptions VALUES($uid,$cid,NOW())");
}
if ($_GET['action']==='unsub') {
$c->query("DELETE FROM subscriptions WHERE subscriber_id=$uid AND channel_id=$cid");
}
header("Location: channel.php?user_id=$uid&channel_id=$cid");
exit;
}
$ch = $c->query("
SELECT ch.*,
u.full_name,
u.country,
(SELECT COUNT(*) FROM subscriptions s WHERE s.channel_id=ch.channel_id) subs
FROM channels ch
JOIN users u ON u.user_id=ch.owner_id
WHERE ch.channel_id=$cid
")->fetch_assoc();
if (!$ch) die("Channel not found");
$isSub = $c->query("
SELECT 1 FROM subscriptions
WHERE subscriber_id=$uid AND channel_id=$cid
")->num_rows > 0;
$vids = $c->query("
SELECT * FROM videos
WHERE channel_id=$cid
ORDER BY uploaded_at DESC
");
?>
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php render_nav($uid); ?>
<div class="container">
<div class="card">
<img class="avatar avatar-lg" src="<?= h($ch['channel_image']) ?>">
<h1><?= h($ch['name']) ?></h1>
<div class="small">
<?= h($ch['full_name']) ?> · <?= h($ch['country']) ?>
· <?= $ch['subs'] ?> subs
</div>
<p><?= trim($ch['description']) ?: '(no description)' ?></p>
<a class="subscribe-btn <?= $isSub ? 'unsubscribe' : 'subscribe' ?>"
href="channel.php?user_id=<?= $uid ?>&channel_id=<?= $cid ?>&action=<?= $isSub ? 'unsub' : 'sub' ?>">
<?= $isSub ? '✓ Subscribed' : '+ Subscribe' ?>
</a>
</div>
<div class="card">
<h2>Videos</h2>
<?php while($v=$vids->fetch_assoc()): ?>
<a href="watch.php?user_id=<?= $uid ?>&video_id=<?= $v['video_id'] ?>">
<?= h($v['title']) ?>
</a><br>
<?php endwhile; ?>
</div>
</div>
</body>
</html>