forked from php/web-people
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuserlisting.php
66 lines (52 loc) · 1.62 KB
/
userlisting.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
<?php
function getAllUsers() {
$opts = array("ignore_errors" => true);
$ctx = stream_context_create(array("http" => $opts));
$token = getenv("TOKEN");
if (!$token) {
$token = trim(file_get_contents("../token"));
}
$retval = file_get_contents("https://master.php.net/fetch/allusers.php?&token=" . rawurlencode($token), false, $ctx);
if (!$retval) {
return;
}
$json = json_decode($retval, true);
if (!is_array($json)) {
return;
}
if (isset($json["error"])) {
return;
}
return $json;
}
$now = $_SERVER["REQUEST_TIME"];
if (isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
$last = strtotime($_SERVER["HTTP_IF_MODIFIED_SINCE"]);
/* Cache the user list for a week */
if (strtotime("+1 week", $last) > $now) {
header("HTTP/1.1 304 Not Modified");
exit;
}
}
$json = getAllUsers();
if (!$json) { return; }
$future = strtotime("+1 week", $now);
$tsstring = gmdate("D, d M Y H:i:s ", $now) . "GMT";
header("Last-Modified: " . $tsstring);
header("Expires: " . date(DATE_RSS, $future));
header("Content-Type: text/javascript");
$lookup = $user = array();
foreach($json as $row) {
$lookup[] = $row["name"];
$lookup[] = $row["username"];
$data = array(
"email" => md5($row["username"] . "@php.net"),
"name" => $row["name"],
"username" => $row["username"],
);
$user[$row["username"]] = $data;
$user[$row["name"]] = $data;
}
echo 'var users = ' . json_encode($user) . ';';
echo 'var lookup = ' . json_encode($lookup) . ';';
// vim: set expandtab shiftwidth=4 softtabstop=4 tabstop=4 :