forked from takechi-scratch/t-cloudsystem-www
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunc.php
More file actions
42 lines (33 loc) · 1.09 KB
/
func.php
File metadata and controls
42 lines (33 loc) · 1.09 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
<?php
function checkUser($username) {
$url = "https://api.scratch.mit.edu/users/$username";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// 404の場合はfalse、それ以外はtrue
if ($http_code == 404) {
return false;
} else {
return true;
}
}
function getScratchProjectComments($authorName, $projectId, $limit, $offset) {
$cacheBust = rand(0, 9999);
$url = "https://api.scratch.mit.edu/users/{$authorName}/projects/{$projectId}/comments/?limit={$limit}&offset={$offset}&cachebust={$cacheBust}";
$response = file_get_contents($url);
$comments = json_decode($response, true);
if (!is_array($comments)) {
return [];
}
foreach ($comments as &$comment) {
$comment["source"] = "project";
$comment["source_id"] = $projectId;
}
return parseObjectList($comments);
}
function parseObjectList($comments) {
return $comments;
}