Skip to content

Commit 93537cc

Browse files
committed
Removing Server IP from Parser, updating example.php
1 parent 5bf12c6 commit 93537cc

File tree

3 files changed

+115
-37
lines changed

3 files changed

+115
-37
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This PHP wrapper library is used to collect data from the _undcoumented_ Habbo.com Beta API.
55
The project required PHP 5 and uses the Composer autoloader and PSR-4 standard.
66

7-
See the `example.php` file on how to use this library at the moment.
7+
See the `example.php` file on how you could use this library.
88

99
## How to use it
1010
1. Add [the Composer package](https://packagist.org/packages/gerbenjacobs/habbo-api) to your package.json file: `"gerbenjacobs/habbo-api": "v1.*"`
@@ -23,7 +23,7 @@ See the `example.php` file on how to use this library at the moment.
2323
use HabboAPI\HabboParser;
2424

2525
// Create new Parser and API instance
26-
$habboParser = new HabboParser('ip-of-server-here', 'https://www.habbo.com/api/public/');
26+
$habboParser = new HabboParser('https://www.habbo.com/api/public/');
2727
$habboApi = new HabboAPI($habboParser);
2828

2929
// Find the user 'koeientemmer' and get their ID
@@ -34,6 +34,7 @@ See the `example.php` file on how to use this library at the moment.
3434
```
3535

3636
## Current status
37+
October 12th, 2015 - v1.0.2 - Removed server IP, upgraded PHPUnit and tests, expanded on example.php
3738
March 30th, 2015 - v1.0.1 - Added hasProfile and more stable example.php
3839
March 28th, 2015 - v1.0.0 - Created first tagged release, includes Travis CI and Packagist integration.
3940

example.php

+110-24
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use HabboAPI\HabboParser;
1010

1111
// Create new Parser and API instance
12-
$habboParser = new HabboParser($_SERVER['SERVER_ADDR'], 'https://www.habbo.com/api/public/');
12+
$habboParser = new HabboParser('https://www.habbo.com/api/public/');
1313
$habboApi = new HabboAPI($habboParser);
1414

1515
// Find the user 'koeientemmer' and get their ID
@@ -23,47 +23,133 @@
2323
$myProfile = array('habbo' => $myHabbo);
2424
}
2525

26-
// Print all the $profile data in a pretty format
27-
$lastSection = '';
26+
// Export as HTML
27+
$html = [
28+
'habbo' => '',
29+
'worn_badges' => '',
30+
'friends' => '',
31+
'groups' => '',
32+
'rooms' => '',
33+
'badges' => ''
34+
];
35+
36+
// Print all the $profile data in a pretty format, except for 'habbo'
37+
$lastSection = 'habbo';
2838
foreach ($myProfile as $section => $data) {
2939

3040
// Print section name
3141
if ($section != $lastSection) {
3242
$lastSection = $section;
33-
echo '<h2>'.ucfirst($section).' ('.count($data).')</h2>';
43+
$html[$section] .= '<h2>' . ucfirst($section) . ' (' . count($data) . ')</h2>';
3444
}
3545

3646
// Some markup for the Habbo part
3747
if ($section == 'habbo') {
3848
/* @var Habbo $habbo */
3949
$habbo = $data;
40-
echo '<img src="http://www.habbo.com/habbo-imaging/avatarimage?figure='.$habbo->getFigureString().'&size=m&gesture=sml&head_direction=3"
41-
alt="'.$habbo->getHabboName().'" title="'.$habbo->getHabboName().'" style="float: left; margin-right: 10px;" />';
42-
echo '<h3>'.$habbo->getHabboName().'</h3>';
43-
echo '<p>'.$habbo->getMotto().'<br><em>'.date('d-M-Y', strtotime($habbo->getMemberSince())).'</em></p>';
50+
$html['habbo'] .= '<img src="http://www.habbo.com/habbo-imaging/avatarimage?figure=' . $habbo->getFigureString() . '&size=l&gesture=sml&head_direction=3"
51+
alt="' . $habbo->getHabboName() . '" title="' . $habbo->getHabboName() . '" style="float: left; margin-right: 10px;" />';
52+
$html['habbo'] .= '<h3>' . $habbo->getHabboName() . '</h3>';
53+
$html['habbo'] .= '<p>' . $habbo->getMotto() . '<br><em>' . date('d-M-Y', strtotime($habbo->getMemberSince())) . '</em></p>';
4454
if ($habbo->getProfileVisible()) {
45-
echo '<p><a href="https://www.habbo.com/profile/'.$habbo->getHabboName().'">View home &raquo;</a></p>';
55+
$html['habbo'] .= '<p><a href="https://www.habbo.com/profile/' . $habbo->getHabboName() . '">View home &raquo;</a></p>';
4656
}
4757
if ($badges = $habbo->getSelectedBadges()) {
4858
foreach ($badges as $badge) {
4959
/** @var Badge $badge */
50-
echo
51-
'<p>
52-
<img src="http://images.habbo.com/c_images/album1584/'.$badge->getCode().'.gif" alt="'.$badge->getName().'" title="'.$badge->getName().'" /><br>
53-
<strong>'.$badge->getName().'</strong><br>
54-
<em>'.$badge->getDescription().'</em>
55-
</p>
56-
';
60+
$html['worn_badges'] .=
61+
'
62+
<div class="media">
63+
<div class="media-left media-middle">
64+
<a href="#">
65+
<img class="media-object" src="http://images.habbo.com/c_images/album1584/' . $badge->getCode() . '.gif" alt="' . $badge->getName() . '">
66+
</a>
67+
</div>
68+
<div class="media-body">
69+
<h4 class="media-heading">' . $badge->getName() . '</h4>
70+
<em>' . $badge->getDescription() . '</em>
71+
</div>
72+
</div>
73+
';
74+
}
75+
}
76+
} else {
77+
// Show all the other sections as an unordered list
78+
if (in_array($section, array("friends", "groups", "rooms", "badges"))) {
79+
$html[$section] .= '<ul>';
80+
foreach ($data as $object) {
81+
$html[$section] .= '<li>' . $object . '</li>'; // uses the __toString() method
5782
}
83+
$html[$section] .= '</ul>';
5884
}
5985
}
86+
}
87+
?>
88+
<!DOCTYPE html>
89+
<html lang="en">
90+
<head>
91+
<meta charset="utf-8">
92+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
93+
<meta name="viewport" content="width=device-width, initial-scale=1">
94+
<title>HabboAPI</title>
6095

61-
// Show all the other sections as an unordered list
62-
if (in_array($section, array("friends", "groups", "rooms", "badges"))) {
63-
echo '<ul>';
64-
foreach ($data as $object) {
65-
echo '<li>'.$object.'</li>'; // uses the __toString() method
96+
<link href="http://bootswatch.com/lumen/bootstrap.min.css" rel="stylesheet">
97+
<style type="text/css">
98+
html, body {
99+
margin: 20px;
66100
}
67-
echo '</ul>';
68-
}
69-
}
101+
.media-left {
102+
min-width: 60px;
103+
}
104+
</style>
105+
106+
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
107+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
108+
<!--[if lt IE 9]>
109+
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
110+
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
111+
<![endif]-->
112+
</head>
113+
<body>
114+
115+
<div class="container">
116+
117+
<div class="jumbotron">
118+
<h1>HabboAPI</h1>
119+
120+
<p>A PHP wrapper library for the undocumented API of Habbo</p>
121+
122+
<p><a class="btn btn-primary btn-lg" href="https://github.com/gerbenjacobs/HabboAPI" role="button" target="_blank">Learn more</a></p>
123+
</div>
124+
125+
<div class="row">
126+
<div class="col-md-6">
127+
<?php echo $html['habbo']; ?>
128+
</div>
129+
<div class="col-md-6">
130+
<?php echo $html['worn_badges']; ?>
131+
</div>
132+
</div>
133+
134+
<?php if ($myHabbo->hasProfile()): ?>
135+
<div class="row">
136+
<div class="col-md-3">
137+
<?php echo $html['badges']; ?>
138+
</div>
139+
<div class="col-md-3">
140+
<?php echo $html['friends']; ?>
141+
</div>
142+
<div class="col-md-3">
143+
<?php echo $html['groups']; ?>
144+
</div>
145+
<div class="col-md-3">
146+
<?php echo $html['rooms']; ?>
147+
</div>
148+
</div>
149+
<?php endif; ?>
150+
</div>
151+
152+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
153+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
154+
</body>
155+
</html>

src/HabboAPI/HabboParser.php

+2-11
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,12 @@ class HabboParser implements HabboParserInterface
2121
private $api_base;
2222

2323
/**
24-
* The IP for the server sending out the calls
25-
* @var string $server_ip
26-
*/
27-
private $server_ip;
28-
29-
/**
30-
* HabboParser constructor, needs to be injected with $server_ip and $api_base URL
24+
* HabboParser constructor, needs to be injected with $api_base URL
3125
*
32-
* @param string $server_ip
3326
* @param string $api_base
3427
*/
35-
public function __construct($server_ip, $api_base = 'https://www.habbo.com/api/public/')
28+
public function __construct($api_base = 'https://www.habbo.com/api/public/')
3629
{
37-
$this->server_ip = $server_ip;
3830
$this->api_base = $api_base;
3931
}
4032

@@ -67,7 +59,6 @@ protected function _callUrl($url)
6759
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
6860
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
6961
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
70-
curl_setopt($ch, CURLOPT_COOKIE, "YPF8827340282Jdskjhfiw_928937459182JAX666=" . $this->server_ip);
7162
$json = curl_exec($ch);
7263
$data = json_decode($json, true);
7364
$data['habboAPI_info'] = curl_getinfo($ch);

0 commit comments

Comments
 (0)