This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.php
70 lines (63 loc) · 2.23 KB
/
common.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
<?php
/*
Scratch Wiki account creation common functions and vars
Joren Lauwers - 2010
*/
function scratchr_api($api_function, $arg1 = NULL, $arg2 = NULL , $arg3 = NULL) {
//general Scratch API function.
$request = "http://scratch.mit.edu/api/$api_function";
if (isset($arg1)) $request .= '/'.rawurlencode($arg1);
if (isset($arg2)) $request .= '/'.rawurlencode($arg2);
if (isset($arg3)) $request .= '/'.rawurlencode($arg3);
if (isset($arg4)) $request .= '/'.rawurlencode($arg4);
$reply = file_get_contents($request);
$reply = trim($reply); //Bug on ScratchR side, ticket #422 on Assembla.
$reply = ($reply!='false') ? explode(':', $reply) : false;
return $reply;
}
function scratchr_auth_api($u, $p) {
//uses a different requestform so needs a separate function
$u = rawurlencode($u);
$p = rawurlencode($p);
$request = "http://scratch.mit.edu/api/authenticateuser?username=$u&password=$p";
$reply = file_get_contents($request);
$reply = trim($reply); //Bug on ScratchR side, ticket #422 on Assembla.
$reply = ($reply!='false') ? explode(':', $reply) : false;
$reply = (count($reply)==3 && $reply[2]=='unblocked') ? $reply : false;
return $reply;
}
function parseuser($data) {
$username = $data['username'];
$description = $data['description'];
$id = $data['id'];
$state = $data['state'];
$uadmin = $data['admin'];
$html = "<b><a href=\"http://scratch.mit.edu/users/$username\">$username</a></b> | ";
switch($state) {
case 0:
$html .= "<a href=\"approve.php?a=onhold&id=$id\">on hold</a> | <a href=\"javascript:approve('$username',$id);\">approve</a><br>";
break;
case 2:
$html .= "<a href=\"approve.php?a=pending&id=$id\">pending</a> | <a href=\"javascript:approve('$username',$id);\">approve</a><br>";
break;
}
//retrieve nr of projects from api
$r = scratchr_api('getprojectsbyusername', $username);
$noprojects = count($r);
$html .= "projects: $noprojects | ";
if (strlen($uadmin)>2) {
switch($state) {
case 0:
$html .= "<b>set back to pending by $uadmin</b>";
break;
case 2:
$html .= "<b>set on hold by $uadmin</b>";
break;
}
}
$html .= '<br>'.$description;
$html .= "<br><br> \n";
return $html;
}
session_start();
?>