forked from tinyspeck/glitch-mash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.php
92 lines (62 loc) · 1.81 KB
/
import.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
<?
include('include/init.php');
login_ensure_loggedin();
loadlib('curl');
#
# get player info
#
$args = array(
'player_tsid' => $cfg['user']['tsid'],
);
$ret = curl_api_call('/simple/players.getClothing', $args);
if (!$ret['ok']) error_misc($ret);
#
# store details for each clothing item
#
$avatar = array();
foreach ($ret['clothing'] as $slot => $row){
if ($row['id']){
$avatar[$slot] = $row['id'];
$hash = array(
'id' => intval($row['id']),
'name' => AddSlashes($row['name']),
'url' => AddSlashes($row['url']),
'image' => AddSlashes($row['image']),
'image_small' => AddSlashes($row['image_small']),
'image_large' => AddSlashes($row['image_large']),
'sub_only' => $row['sub_only'] ? 1 : 0,
'credits' => intval($row['credits']),
'slot' => AddSlashes($slot),
);
$hash2 = $hash;
unset($hash2['id']);
db_insert_dupe('glitchmash_clothing', $hash, $hash2);
}
}
#
# now store the avatar
#
$hash = array(
'player_tsid' => AddSlashes($cfg['user']['tsid']),
'url' => AddSlashes($ret['avatar_172']),
'date_added' => time(),
'date_updated' => time(),
'details' => AddSlashes(serialize($avatar)),
);
$hash2 = $hash;
unset($hash2['date_added']);
db_insert_dupe('glitchmash_avatars', $hash, $hash2);
#
# mark only the latest one as active
#
$tsid_enc = AddSlashes($cfg['user']['tsid']);
list($latest_id) = db_list(db_fetch("SELECT id FROM glitchmash_avatars WHERE player_tsid='$tsid_enc' ORDER BY date_updated DESC LIMIT 1"));
$latest_id = intval($latest_id);
db_write("UPDATE glitchmash_avatars SET is_active=0 WHERE player_tsid='$tsid_enc' AND id!=$latest_id");
db_write("UPDATE glitchmash_avatars SET is_active=1 WHERE player_tsid='$tsid_enc' AND id=$latest_id");
#
# done
#
header("location: /you/?imported=1");
exit;
?>