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
|
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/config.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/partials.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/lib/users.php';
authenticate_user();
$db = new PDO(DB_URL, DB_USER, DB_PASS);
if (isset($_GET['id']) && !empty(trim($_GET['id']))) {
$stmt = $db->prepare('SELECT id, code
FROM sounds
WHERE id = ?
');
$stmt->execute([$_GET['id']]);
$sound = $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
// TODO: check if user has twitch connection
$twitch = $_SESSION['user']['connections'][0];
if ($sound) {
$emotes = [];
if (EMOTE_FETCH_BETTERTTV) {
// fetching channel emotes
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.betterttv.net/3/cached/users/twitch/" . $twitch['user_alias_id']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// parsing channel emotes
$response = json_decode($response, true);
$bttvemotes = [];
foreach ($response['channelEmotes'] as $e) {
array_push($bttvemotes, [
'code' => $e['code'],
'eid' => 'betterttv:' . $e['id'],
'url' => 'https://cdn.betterttv.net/emote/' . $e['id'] . '/2x.webp',
'uploader' => $twitch['user_alias_name']
]);
}
foreach ($response['sharedEmotes'] as $e) {
array_push($bttvemotes, [
'code' => $e['code'],
'eid' => 'betterttv:' . $e['id'],
'url' => 'https://cdn.betterttv.net/emote/' . $e['id'] . '/2x.webp',
'uploader' => $e['user']['displayName']
]);
}
// fetching global emotes
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.betterttv.net/3/cached/emotes/global");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// parsing global emotes
$response = json_decode($response, true);
foreach ($response as $e) {
array_push($bttvemotes, [
'code' => $e['code'],
'eid' => 'betterttv:' . $e['id'],
'url' => 'https://cdn.betterttv.net/emote/' . $e['id'] . '/2x.webp'
]);
}
$emotes['BetterTTV'] = $bttvemotes;
}
if (EMOTE_FETCH_7TV) {
// fetching channel emotes
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://7tv.io/v3/users/twitch/" . $twitch['user_alias_id']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// parsing channel emotes
$response = json_decode($response, true);
$stvemotes = [];
foreach ($response['emote_set']['emotes'] as $e) {
array_push($stvemotes, [
'code' => $e['name'],
'eid' => '7tv:' . $e['id'],
'url' => 'https://cdn.7tv.app/emote/' . $e['id'] . '/2x.webp',
'uploader' => $e['data']['owner']['display_name']
]);
}
// fetching global emotes
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://7tv.io/v3/emote-sets/global");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// parsing global emotes
$response = json_decode($response, true);
foreach ($response['emotes'] as $e) {
array_push($stvemotes, [
'code' => $e['name'],
'eid' => '7tv:' . $e['id'],
'url' => 'https://cdn.7tv.app/emote/' . $e['id'] . '/2x.webp',
'uploader' => $e['data']['owner']['display_name']
]);
}
$emotes['7TV'] = $stvemotes;
}
}
} else {
$stmt = $db->prepare('SELECT * FROM sounds ORDER BY uploaded_at DESC');
$stmt->execute();
$sounds = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Add sound - <?= INSTANCE_NAME ?></title>
<link rel="stylesheet" href="/static/style.css">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
</head>
<body>
<?php html_header() ?>
<main class="row gap-8">
<section class="column gap-8">
<div class="box">
<div class="tab">
<p>Adding sound - <?= $sound['code'] ?></p>
</div>
<div class="content column justify-center align-center gap-16">
<audio controls>
<source src="<?= sprintf("%s/%d.ogg", SOUND_DIRECTORY_PREFIX, $sound['id']) ?>"
type="audio/ogg">
</audio>
</div>
</div>
<div class="box" id="chat-preview">
<div class="tab">
<p>Preview</p>
</div>
<div class="content chat-preview">
<p>wip</p>
</div>
</div>
</section>
<section class="column gap-8">
<?php foreach ($emotes as $pname => $pe): ?>
<div class="box">
<div class="tab">
<p><?= $pname ?></p>
</div>
<div class="content row wrap gap-8">
<?php foreach ($pe as $e): ?>
<a href="/sounds/add.php?id=<?= $sound['id'] ?>&eid=<?= $e['eid'] ?>">
<div class="box emote-item">
<div class="icon">
<img src="<?= $e['url'] ?>" alt="<?= $e['code'] ?>" loading="lazy">
</div>
<p class="code" title="<?= $e['code'] ?>"><?= $e['code'] ?></p>
<?php if (isset($e['uploader'])): ?>
<p class="author" title="by <?= $e['uploader'] ?>">by <?= $e['uploader'] ?></p>
<?php endif; ?>
</div>
</a>
<?php endforeach; ?>
<?php if (empty($pe)): ?>
<p><i>No emotes.</i></p>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</section>
</main>
</body>
<script>
</script>
</html>
|