xref: /web-bugs/www/js/userlisting.php (revision 4f2b72f6)
1<?php
2
3// Enable output compression
4ini_set('zlib.output_compression', 1);
5
6function getAllUsers()
7{
8    $opts = ['ignore_errors' => true];
9    $ctx = stream_context_create(['http' => $opts]);
10    $token = getenv('USER_TOKEN');
11
12    $retval = @file_get_contents('https://main.php.net/fetch/allusers.php?&token=' . rawurlencode($token), false, $ctx);
13
14    if (!$retval) {
15        return;
16    }
17
18    $json = json_decode($retval, true);
19
20    if (!is_array($json)) {
21        return;
22    }
23
24    if (isset($json['error'])) {
25        return;
26    }
27    return $json;
28}
29
30if (!file_exists("/tmp/svnusers.json") || filemtime("/tmp/svnusers.json") < $_SERVER["REQUEST_TIME"] - 3600) {
31    $json = getAllUsers();
32    $json_data = var_export($json, true);
33    file_put_contents("/tmp/svnusers.php", '<?php $json = '.$json_data.';');
34    $modified = time();
35} else {
36    include "/tmp/svnusers.php";
37    $modified = filemtime("/tmp/svnusers.php");
38}
39
40$tsstring = gmdate('D, d M Y H:i:s ', $modified);
41if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $tsstring) {
42    header('HTTP/1.1 304 Not Modified');
43    exit;
44} else {
45    $expires = gmdate('D, d M Y H:i:s ', strtotime('+2 months', $_SERVER['REQUEST_TIME'])) . 'GMT';
46    header("Last-Modified: {$tsstring}");
47    header("Expires: {$expires}");
48}
49
50$lookup = $user = [];
51
52if ($json) {
53    foreach ($json as $row) {
54        $lookup[] = $row['name'];
55        $lookup[] = $row["username"];
56
57        $data = [
58            'email'        => md5($row['username'] . '@php.net'),
59            'name'        => $row['name'],
60            'username'    => $row['username'],
61        ];
62        $user[$row["username"]] = $data;
63        $user[$row["name"]]     = $data;
64    }
65}
66
67echo 'var users = ', json_encode($user), ";\n",
68     'var lookup = ', json_encode($lookup), ";\n";
69