-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi_example.txt
153 lines (116 loc) · 4.25 KB
/
api_example.txt
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
function url_get_contents ($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
// Download and convert to array
// https://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers
$download = json_decode(url_get_contents("https://ofp-faguss.com/schedule/api?server=4abc47b3"));
$schedule = json_decode(json_encode($download),true);
// Show servers
$server_properties_to_display = [
"version" => "Version",
"modfolders" => "Mods",
"maxcustomfilesize" => "Max Custom File Size",
"game time" => "Events",
"languages" => "Language",
"location" => "Location",
"voice" => "VOIP",
"website" => "URL",
"message" => "Info",
"access" => "Schedule Password"
];
foreach($schedule["servers"] as $server) {
echo "<h2>" . ($server["name"]!="" ? $server["name"] : $server["uniqueid"]) ."</h2><dl>";
foreach($server_properties_to_display as $key=>$name) {
$value = "";
switch($key) {
case "maxcustomfilesize" : {
$bytes = intval($server[$key]);
$value = $bytes/1024 - fmod($bytes/1024, 1) . " KB";
} break;
case "website" : {
if (!empty($value)) {
$domain = parse_url($server[$key])["host"];
if (substr($domain,0,4) == "www." )
$domain = substr($domain,4);
$value = "<a href=\"$value\" target=\"_blank\">$domain</a>";
}
} break;
case "modfolders" : {
$mod_list_links = [];
foreach ($server["mods"] as $id) {
$version = $schedule["mods"][$id]["version"]!=1 ? " v{$schedule["mods"][$id]["version"]}" : "";
$mod_list_links[] = "<a href=\"https://ofp-faguss.com/schedule/show.php?mod=$id\" target=\"_blank\">{$schedule["mods"][$id]["name"]}</a> <span style=\"font-size:70%;\">{$schedule["mods"][$id]["size"]}{$version}</span>";
}
$value = implode("<br>",$mod_list_links);
} break;
case "game time" : {
foreach ($server["events"] as $event)
$value .= (empty($value) ? "" : "<br>") . $event["description"];
} break;
case "voice" : {
$value = "<a href=\"{$schedule["info"]["voice"][$server[$key]]["download"]}\">{$server[$key]}</a>";
} break;
default: $value=$server[$key];
}
if (!empty($value))
echo "<dt>{$name}:</dt><dd>{$value}</dd>";
}
echo "</dl><br><hr>";
}
// Show mods
$mod_properties_to_display = [
"description" => "Description",
"type" => "Type",
"version" => "Version",
"size" => "Download Size"
];
foreach($schedule["mods"] as $id=>$mod) {
echo "<h2>{$mod["name"]}</h2><dl>";
foreach ($mod_properties_to_display as $key=>$name) {
$value = "";
switch($key) {
case "type" : $value=$schedule["info"]["mod_types"][$mod["type"]]; break;
default: $value=$mod[$key];
}
if (!empty($value))
echo "<dt>{$name}:</dt><dd>{$value}</dd>";
}
echo "</dl>";
echo "<p>Preview <a target=\"_blank\" href=\"https://ofp-faguss.com/schedule/install_scripts\">Installation Script</a>:</p>";
foreach($mod["updates"] as $update_index=>$update) {
echo "<strong>{$update["version"]}<span style=\"font-size:10px;float:right;\">".date(DATE_RFC2822,$update["date"])."</span></strong>
<pre style=\"margin:0;border:0;\"><code>{$update["script"]}</code></pre>";
$number_of_notes = 0;
foreach ($update["note"] as $note)
if (!empty($note)) {
$number_of_notes = count($update["note"]);
break;
}
if ($number_of_notes > 0) {
echo "<div style=\"background-color:#fdffe1;\">";
foreach($update["note"] as $note_index=>$note) {
echo "<p>";
if ($number_of_notes > 1)
echo "
<span style=\"font-size:10px;\">{$update["note_version"][$note_index]}
<span style=\"float:right;\">".date(DATE_RFC2822,$update["note_date"][$note_index])."</span>
</span>
<br>
";
echo "$note</p>";
}
echo "</div>";
}
}
echo "<br><hr>";
}
?>