-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.php
281 lines (144 loc) · 7.29 KB
/
user.php
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
<?php
# Replit development code
$replit_support = filter_var(@file_get_contents("./replit.txt"), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
function p(string $url_input) {
if ($GLOBALS['replit_support']) {
return 'https://apis.scratchconnect.eu.org/free-proxy/get?url=' . $url_input;
} else {
return $url_input;
}
}
# Page setup
$user = @file_get_contents(p("https://api.scratch.mit.edu/users/{$_GET['u']}"));
$page_title = "Simpleviewer - User {$_GET['u']} Not Found";
if ($user !== false) {
$user_json = json_decode($user, true);
if (@strcasecmp(@$user_json["username"], $_GET["u"]) == 0) {
$page_title = "Simpleviewer - User {$user_json["username"]}";
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title><?= $page_title; ?></title>
<link rel="stylesheet" href="/style.css">
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="View Scratch without JavaScript or a modern browser">
<meta name="keywords" content="Scratch, MIT, Legacy, Compatibility, Accessibility">
<meta name="author" content="Voxalice">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body bgcolor="#222"><font color="white" face="sans-serif">
<?php
if ($user === false) {
http_response_code(404);
echo "<h1>404 User Not Found</h1>Make sure the username has been typed correctly!<br>(Don't include the * next to Scratch Team usernames)";
} else {
$user_json = json_decode($user, true);
if (@strcasecmp(@$user_json["username"], $_GET["u"]) == 0) {
# Username (including *) and user ID
$username = $user_json["username"];
if ($user_json["scratchteam"] === true) {
$star = '*';
} else {
$star = '';
}
echo "<h1>@{$username}{$star} <img src='{$user_json["profile"]["images"]["32x32"]}' width='32'></h1>
(User #{$user_json["id"]})<br><br>";
# User statuses
$about_me = htmlspecialchars($user_json['profile']['bio']);
$wiwo = htmlspecialchars($user_json['profile']['status']);
echo nl2br("<div id='desc'><br><a href='//scratch.mit.edu/users/{$username}' tabindex='0'>View on Scratch (JS required)</a><br><br><b>About Me</b><br><br>{$about_me}<br><br><b>What I'm Working On</b><br><br>{$wiwo}<br><br></div>");
# Join date
$join_date = date('Y-m-d H:i:s', strtotime($user_json['history']['joined']));
echo "<p>Joined <b>{$join_date}</b></p>";
# Ocular status
$ocular_status = @file_get_contents("https://my-ocular.jeffalo.net/api/user/{$username}");
$ocular_status_json = json_decode($ocular_status, true);
if (@$ocular_status_json['name'] == $username) {
$ocular_status_string = htmlentities($ocular_status_json['status']);
echo "<p>Ocular status: <i>\"{$ocular_status_string}\"</i></p>";
}
# Comments
echo "<hr><h1>Comments</h1>";
if (@round(@$_GET["page"]) > 0) {
$page = @round(@$_GET["page"]);
} else {
$page = 1;
}
$comment_html = nl2br(@file_get_contents(p("https://scratch.mit.edu/site-api/comments/user/{$username}/?page={$page}")));
# Check if comments are empty
if (str_contains($comment_html, "div")) {
# Remove all tags except <div>'s, <ul>'s, and <span>'s
$final_comments = strip_tags($comment_html, ['div', 'ul', 'span']);
# Remove [data-content="reply-form"]
$final_comments = preg_replace('#<div data-content="reply-form">(.*?)</div>#is', '', $final_comments);
# Remove element IDs (all elements are selected by class)
$final_comments = preg_replace('#id="(.*?)"#is', '', $final_comments);
# Remove data-comment- attributes
$final_comments = preg_replace('# data-comment-#is', '', $final_comments);
# Remove data-thread attributes
$final_comments = preg_replace('# data-thread="(.*?)"#is', '', $final_comments);
# Remove unnecessary line-breaks in source code
$final_comments = str_replace(array("\r", "\n"), '', $final_comments);
# Add <br><br> after comment content
$final_comments = preg_replace("#<div class=\"content\">(.*?)</div>#is", "<div class='content'>$1</div><br><br>", $final_comments);
# Remove excess whitespace
$final_comments = preg_replace('/\s+/', ' ', $final_comments);
# Full comment dates
function full_date(array $sview_date_input) {
return date('Y-m-d H:i:s', strtotime($sview_date_input[1]));
}
$final_comments = preg_replace_callback('#<span class="time" title="(.*?)">(.*?)</span>#is', "full_date", $final_comments);
# Bold usernames and add links
$final_comments = preg_replace("#<div class=\"name\">\s(.*?)\s</div>#is", "<a href='/users/$1' class='userlink'><b>$1</b></a><br><br>", $final_comments);
# 1.1.0: Add links to project URLs
$final_comments = preg_replace("#(https:\/\/scratch.mit.edu\/projects(?:\/|\/\w+\/)(\d+)(?:\/|))#is", "<a href='/projects/$2'>$1</a>", $final_comments);
# Remove random unwanted strings
$final_comments = str_replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', '', $final_comments);
$final_comments = str_replace('<html><body>', '', $final_comments);
$final_comments = str_replace('</body></html>', '', $final_comments);
$final_comments = str_replace(' <span>Reply</span> ', '', $final_comments);
$final_comments = str_replace(' <ul class="replies"> </ul> ', '<br>', $final_comments);
$final_comments = str_replace('</ul>', '</ul><br>', $final_comments);
$final_comments = str_replace('<div class="actions-wrap"> </div>', '', $final_comments);
$final_comments = preg_replace('#<div class="more-replies"(.*?)</div>#is', '', $final_comments);
$final_comments = preg_replace('#<div class="button grey"(.*?)</div>#is', '', $final_comments);
# Make date small and add "Posted " before it
$final_comments = preg_replace("#<div class=\"info\">(.*?)<div class='content'>(.*?)<br><br> <div>(.*?)</div>#is", "<div class=\"info\">$1<div class='content'>$2<br><small>Posted $3</small>", $final_comments);
# We're done here (finally)
echo $final_comments;
# Add page buttons
$page_previous = $page - 1;
$page_next = $page + 1;
# Construct previous page link
$query = $_GET;
// replace parameter(s)
$query['page'] = $page_previous;
// rebuild url
$query_result_previous = "/user.php?" . http_build_query($query);
# Construct next page link
$query = $_GET;
// replace parameter(s)
$query['page'] = $page_next;
// rebuild url
$query_result_next = "/user.php?" . http_build_query($query);
# Echo page buttons / links
if ($page > 1) {
echo "<a href='{$query_result_previous}'>< Previous page</a> | ";
}
echo "<a href='{$query_result_next}'>Next page ></a>";
} else {
echo '<p>No comments</p><br>';
}
} else {
http_response_code(404);
echo "<h1>404 User Not Found</h1>Make sure the username has been typed correctly!<br>(Don't include the * next to Scratch Team usernames)";
}
}
?>
<?php include "footer.php"; ?>
</font></body>
</html>