-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.php
237 lines (204 loc) · 9.01 KB
/
example.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
// Include the Composer autoloader
include 'vendor/autoload.php';
// Shortcut for the FQN
use HabboAPI\Entities\Badge;
use HabboAPI\Entities\Profile;
use HabboAPI\HabboAPI;
use HabboAPI\HabboParser;
// Create new Parser and API instance
$habboParser = new HabboParser('com');
$habboApi = new HabboAPI($habboParser);
try {
// Find the user 'Macklebee' and get their ID
$myHabbo = $habboApi->getHabbo('Macklebee');
// Get extra information about one of their groups
// Note: This is actually a hardcoded group ID to showcase the parseGroup() endpoint
$group = $habboApi->getGroup("g-hhus-0419705237d0e8c004195c365810e7a7");
} catch (Exception $e) {
echo '
<p>Oops. Can not find this Habbo!</p>
<p>Try to catch this exception gracefully in your application!</p>
<p>[' . $e->getCode() . '] ' . $e->getMessage() . '</p>
<hr>
' . nl2br($e->getTraceAsString()) . '
';
exit();
}
if ($myHabbo->hasProfile()) {
// Collect all the profile info
$myProfile = $habboApi->getProfile($myHabbo->getId());
} else {
// This Habbo has a closed home, only show their Habbo object
$myProfile = new Profile();
$myProfile->setHabbo($myHabbo);
}
// Get all their photos
$myPhotos = $habboApi->getPhotos($myHabbo->getId());
// Export as HTML
$html = [
'habbo' => '',
'worn_badges' => '',
'friends' => '',
'groups' => '',
'rooms' => '',
'badges' => '',
'photos' => ''
];
// Some markup for the Habbo part
$habbo = $myProfile->getHabbo();
$onlineText = $habbo->isOnline() ? "yes" : "no";
$lastAccess = ($habbo->getLastAccessTime()) ? $habbo->getLastAccessTime()->toFormattedDateString() : "N/A";
$html['habbo'] .= '<img src="http://www.habbo.com/habbo-imaging/avatarimage?figure=' . $habbo->getFigureString() . '&size=l&gesture=sml&head_direction=3"
alt="' . $habbo->getHabboName() . '" title="' . $habbo->getHabboName() . '" style="float: left; margin-right: 10px;" />';
$html['habbo'] .= '<h3>' . $habbo->getHabboName() . '</h3>';
$html['habbo'] .= '<p>' . $habbo->getMotto() . '<br><em>' . $habbo->getMemberSince()->toFormattedDateString() . '</em></p>';
$html['habbo'] .= '<p>StarGem count: ' . $habbo->getStarGemCount() . '<br>Total Experience: ' . $habbo->getTotalExperience() . ' <br> Current Level: ' . $habbo->getCurrentLevel() . '</p>';
$html['habbo'] .= '<p>Online: ' . $onlineText . '<br>Last seen: <em>' . $lastAccess . '</em></p>';
if ($habbo->getProfileVisible()) {
$html['habbo'] .= '<p><a href="https://www.habbo.com/profile/' . $habbo->getHabboName() . '">View home »</a></p>';
}
if ($badges = $habbo->getSelectedBadges()) {
foreach ($badges as $badge) {
/** @var Badge $badge */
$html['worn_badges'] .= '
<div class="media">
<div class="media-left media-middle">
<a href="#">
<img class="media-object" src="http://images.habbo.com/c_images/album1584/' . $badge->getCode() . '.gif" alt="' . $badge->getName() . '">
</a>
</div>
<div class="media-body">
<h4 class="media-heading">' . $badge->getName() . '</h4>
<em>' . $badge->getDescription() . '</em>
</div>
</div>
';
}
}
if ($myHabbo->hasProfile()) {
// Show all the other sections as an unordered list
foreach (array("friends", "groups", "rooms", "badges") as $section) {
$html[$section] .= '<ul>';
$method_name = sprintf('get%s', ucfirst($section));
foreach (call_user_func(array($myProfile, $method_name)) as $object) {
$html[$section] .= '<li>' . $object . '</li>'; // uses the __toString() method
}
$html[$section] .= '</ul>';
}
}
// Generate the photos
if ($myPhotos) {
foreach ($myPhotos as $myPhoto) {
$html['photos'] .= '
<div class="col-md-3">
<a href="https://www.habbo.com/profile/' . $myPhoto->getCreatorName() . '/photo/' . $myPhoto->getId() . '" class="thumbnail">
<img src="' . $myPhoto->getPreviewUrl() . '" alt="' . $myPhoto->getId() . '">
</a>
<div class="caption">Taken on ' . $myPhoto->getTakenOn()->toFormattedDateString() . ' by ' . $myPhoto->getCreatorName() . '</div>
</div>
';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HabboAPI</title>
<link href="https://bootswatch.com/3/lumen/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
html,
body {
margin: 20px;
}
.media-left {
min-width: 60px;
}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="jumbotron">
<h1>HabboAPI</h1>
<p>A PHP wrapper library for the undocumented API of Habbo</p>
<p><a class="btn btn-primary btn-lg" href="https://github.com/gerbenjacobs/HabboAPI" role="button" target="_blank">Learn more</a></p>
</div>
<div class="row">
<div class="col-md-6">
<?php echo $html['habbo']; ?>
</div>
<div class="col-md-6">
<?php echo $html['worn_badges']; ?>
</div>
</div>
<hr>
<div class="row">
<?php echo $html['photos']; ?>
</div>
<?php if ($myHabbo->hasProfile()) : ?>
<hr>
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<?php echo $html['badges']; ?>
</div>
<div class="col-md-6">
<?php echo $html['friends']; ?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-6">
<?php echo $html['groups']; ?>
</div>
<div class="col-md-6">
<?php echo $html['rooms']; ?>
</div>
</div>
<?php if ($group) : ?>
<hr>
<div class="row">
<div class="col-md-12">
<img src="https://www.habbo.com/habbo-imaging/badge/<?php echo $group->getBadgeCode(); ?>.gif">
<h3>
<span style="display: inline-block; border: 1px solid #000; width: 20px; background-color: #<?php echo $group->getPrimaryColor(); ?>;"> </span>
<span style="display: inline-block; border: 1px solid #000; width: 20px; background-color: #<?php echo $group->getSecondaryColor(); ?>;"> </span>
<?php echo $group->getName(); ?>
</h3>
<p>[<?php echo $group->getType(); ?>] - <?php echo $group->getDescription(); ?></p>
<p>
<a class="btn btn-default" href="https://www.habbo.com/hotel?room=<?php echo $group->getRoomId(); ?>" target="_blank">Go to room <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>
</p>
<?php $members = $group->getMembers();
if (count($members) > 0) : ?>
<p>This group has <strong><?php echo count($group->getMembers()); ?></strong> members.
Here are 10 random ones:</p>
<ul>
<?php $list = array_rand($members, 10);
foreach ($list as $i) : ?>
<li><?php echo $members[$i]->getHabboName(); ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</body>
</html>