forked from tinyspeck/glitch-mash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
avatar.php
95 lines (62 loc) · 2.1 KB
/
avatar.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
87
88
89
90
91
92
93
94
95
<?
include('include/init.php');
#
# fetch avatar
#
$id_enc = intval($_GET['id']);
$avatar = db_single(db_fetch("SELECT * FROM glitchmash_avatars WHERE id='$id_enc'"));
if (!$avatar['id']) error_404();
$avatar['details'] = unserialize($avatar['details']);
foreach ($avatar['details'] as $slot => $id){
$clothing[$id]++;
}
#
# fetch player
#
$tsid_enc = AddSlashes($avatar['player_tsid']);
$avatar['player'] = db_single(db_fetch("SELECT * FROM glitchmash_players WHERE tsid='$tsid_enc'"));
#
# fetch all clothing rows
#
if (count($clothing)){
$clothing_ids = implode(',', array_keys($clothing));
$clothing = array();
$ret = db_fetch("SELECT * FROM glitchmash_clothing WHERE id IN ($clothing_ids)");
foreach ($ret['rows'] as $row){
$clothing[$row['id']] = $row;
}
foreach ($avatar['details'] as $slot => $id){
$avatar['details'][$slot] = $clothing[$id];
}
}
$smarty->assign('avatar', $avatar);
#
# fetch the most recent 5 battles
#
$recent_count = 5;
$ret1 = db_fetch("SELECT * FROM glitchmash_votes WHERE win_id=$id_enc ORDER BY date_updated DESC LIMIT $recent_count");
$ret2 = db_fetch("SELECT * FROM glitchmash_votes WHERE lose_id=$id_enc ORDER BY date_updated DESC LIMIT $recent_count");
$votes = array();
$smarty->assign_by_ref('votes', $votes);
foreach (array_merge($ret1['rows'], $ret2['rows']) as $row){
$opp_id = $row['win_id'] == $avatar['id'] ? $row['lose_id'] : $row['win_id'];
$opp = db_single(db_fetch("SELECT * FROM glitchmash_avatars WHERE id='$opp_id'"));
$opp_tsid_enc = AddSlashes($opp['player_tsid']);
$opp['player'] = db_single(db_fetch("SELECT * FROM glitchmash_players WHERE tsid='$opp_tsid_enc'"));
$opp['url_50'] = str_replace('_172.png', '_50.png', $opp['url']);
$votes[] = array(
'did_win' => !!($row['win_id'] == $avatar['id']),
'avatar' => $opp,
'date_updated' => $row['date_updated'],
);
}
usort($votes, 'local_vote_sort');
function local_vote_sort($a, $b){
return $b['date_updated'] - $a['date_updated'];
}
$votes = array_slice($votes, 0, $recent_count);
#
# output
#
$smarty->display('page_avatar.txt');
?>