-
Notifications
You must be signed in to change notification settings - Fork 0
/
marcs-office.php
86 lines (61 loc) · 1.99 KB
/
marcs-office.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
function getResponse() {
$json = file_get_contents( 'https://api.marc.tv/' );
$obj = json_decode( $json );
$current_users = $obj->row->visitors;
$max_users = getMaxUsers( $current_users );
//$response = $current_users . '(' . $max_users . ')';
$response = $current_users . ' ' . getMCUsers();
return $response;
}
function getMCUsers() {
$json = file_get_contents( 'https://mc.marc.tv/db/data.json' );
$array = json_decode( $json );
$users_online = $array->server->players_online;
if($users_online >= 0){
return $users_online;
} else {
return 'e';
}
}
function getMaxUsers( $current_users ) {
$filename = 'marctvmaxusers.txt';
$local_cache_file = sys_get_temp_dir() . '/' . $filename;
$local_cache_file_day = sys_get_temp_dir() . '/day_' . $filename;
$today = date('d');
if ( ! file_exists( $local_cache_file ) ) {
file_put_contents( $local_cache_file, $current_users );
}
if ( ! file_exists( $local_cache_file_day ) ) {
file_put_contents( $local_cache_file_day, $today );
}
$cached_day = intval( file_get_contents( $local_cache_file_day ) );
/* invalidate cache if it is the next day */
if($cached_day != $today){
file_put_contents( $local_cache_file_day, $today );
file_put_contents( $local_cache_file, '0' );
}
$cached_users_raw = intval( file_get_contents( $local_cache_file ) );
if ( is_int( $cached_users_raw ) ) {
if ( $cached_users_raw < $current_users ) {
file_put_contents( $local_cache_file, $current_users );
$max_users = $current_users;
} else {
$max_users = $cached_users_raw;
}
} else {
return - 1;
}
return $max_users;
}
spl_autoload_register( function ( $class_name ) {
include 'classes/' . $class_name . '.class.php';
} );
$LaMetricAbfahrten = new LaMetricAbfahrten(
"Lister Platz (U), Hannover",
"Misburg, Hannover"
);
$LaMetricAbfahrten->setPostfix('\' '.getResponse());
$LaMetricAbfahrten->setFrameIcon('i23135');
echo $LaMetricAbfahrten->getLaMetricJSONResponse();
?>