|
15 | 15 | // Get donor
|
16 | 16 | $donor = $_GET["donor"];
|
17 | 17 |
|
| 18 | +// Get team |
| 19 | +$team = $_GET["team"]; |
| 20 | + |
18 | 21 | // Setting foor ssl
|
19 | 22 | $arr_context_options = array(
|
20 | 23 | "ssl" => array(
|
|
24 | 27 | ) ,
|
25 | 28 | );
|
26 | 29 |
|
27 |
| -// Request for data |
28 |
| -$donor_data = file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed"); |
29 |
| -$donor_object = json_decode($donor_data, true); |
30 |
| -if ($DEBUG) var_dump($donor_object); |
| 30 | +// Read record |
| 31 | +if (file_exists("donors/".$donor)) { |
| 32 | + $local_donor = file_get_contents("donors/".$donor); |
| 33 | + if (!$local_donor) { |
| 34 | + // Request for data |
| 35 | + $donor_data = @file_get_contents("https://api.foldingathome.org/user/".$donor, false, stream_context_create($arr_context_options)) or die("api failed"); |
| 36 | + $donor_object = json_decode($donor_data, true); |
| 37 | + if (array_key_exists("status", $donor_object)) { |
| 38 | + exit("api failed"); |
| 39 | + } |
| 40 | + if ($DEBUG) var_dump($donor_object); |
| 41 | + } else { |
| 42 | + $donor_object = json_decode($local_donor, true); |
| 43 | + } |
| 44 | +} |
| 45 | +if (file_exists("teams/".$team)) { |
| 46 | + $local_team = file_get_contents("teams/".$team); |
| 47 | + if (!$local_team) { |
| 48 | + // Request for data |
| 49 | + $team_data = @file_get_contents("https://api.foldingathome.org/team/".$team, false, stream_context_create($arr_context_options)) or die("api failed"); |
| 50 | + $team_object = json_decode($team_data, true); |
| 51 | + if (array_key_exists("status", $team_object)) { |
| 52 | + exit("api failed"); |
| 53 | + } |
| 54 | + if ($DEBUG) var_dump($team_object); |
| 55 | + } else { |
| 56 | + $team_object = json_decode($local_donor, true); |
| 57 | + } |
| 58 | +} |
31 | 59 |
|
32 |
| -$team_data = file_get_contents("https://api.foldingathome.org/team/".$_GET["team"], false, stream_context_create($arr_context_options)) or die("api failed"); |
33 |
| -$team_object = json_decode($team_data, true); |
34 |
| -if ($DEBUG) var_dump($team_object); |
| 60 | +// Save record |
| 61 | +if (!file_exists("donors/".$donor)) { |
| 62 | + file_put_contents("donors/".$donor, ""); |
| 63 | +} |
| 64 | +if (!file_exists("teams/".$team)) { |
| 65 | + file_put_contents("teams/".$team, ""); |
| 66 | +} |
35 | 67 |
|
36 | 68 | // Load canvas
|
37 | 69 | $canvas = imagecreatetruecolor(465, 92);
|
|
0 commit comments