forked from emeth-/Multiplayer-PHP-Ajax-Games
-
Notifications
You must be signed in to change notification settings - Fork 2
/
arcadehistory.php
79 lines (61 loc) · 2.26 KB
/
arcadehistory.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
<?php
require "globals.php";
if($ir['guest']==1){die("Must have a Facebook account linked.");}
print"
<br />
<center><h2>Arcade History</h2> ><a href='arcade.php'>Go to Arcade</a><br /><br />";
$friends = $user->fbc_get_connected_friends_sb(FALSE);
$friends[] = $ir['userid'];
$friendids = implode(",", $friends);
//userid IN ($friendids)
$ahc = $db->query("SELECT * FROM flashscores WHERE userid>0 AND score>0 ORDER BY endTime DESC LIMIT 100");
$howmany = $db->num_rows($ahc);
if(!$howmany)
{
print"You and your friend's have no activity in the arcade yet! <a href='arcade.php'>Go play some games!</a>";
}
else
{
print"<table class='table'><tr><th colspan=2>Last $howmany games played</th></tr>";
while($ah = $db->fetch_row($ahc))
{
$gam=$db->fetch_row($db->query("SELECT imagename,game FROM flash2 WHERE id={$ah['gameid']}"));
$usr=$db->fetch_row($db->query("SELECT username FROM users WHERE userid={$ah['userid']}"));
$ah['score'] = (float) $ah['score'];
$ah['score'] = number_format($ah['score']);
print"<tr><td align='center'>".nicetime($ah['endTime'])."</td><td><a href='http://www.facebook.com/profile.php?id={$ah['userid']}' target='_blank'>{$usr['username']}</a> scored {$ah['score']} on the game <a href='game.php?id={$ah['gameid']}'>{$gam['game']}</a>.</td></tr>";
}
print"</table>";
}
$h->endpage();
function nicetime($date)
{
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
$unix_date = $date;
// check validity of date
if(empty($unix_date)) {
return "Bad date";
}
// is it future date or past date
if($now >= $unix_date) {
$difference = $now - $unix_date;
$tense = "ago";
} else {
$difference = $unix_date - $now;
$tense = "from now";
}
for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
if($difference != 1) {
$periods[$j].= "s";
}
return "$difference $periods[$j] {$tense}";
}
?>