[COLDFUSION] Habbo Imager (w. caching)
As I'm developing Roc CF with Aaron and Oleg, I thought it'd be a great idea to implement an imager. Having never understood how one would achieve such, and being unable to find an existing Coldfusion alternative - I set to work on writing my own.
Live preview: http://local.mabbohotel.net:8500/roc...ze=&action=lay
PHP Code:
action=
std [default]
wav
wlk
sit
lay
drk=1
crr=1
crr=2
crr=3
crr=5
crr=6
crr=9
crr=33
crr=42
crr=43
crr=4
crr=667
drk=2
drk=3
drk=33
drk=5
drk=6
drk=9
drk=42
drk=43
drk=44
drk=667
gesture=
std [default]
sml
sad
spk
eyb
agr
srp
direction=
1
2 [default]
3
4
5
6
7
8
head_direction=
1
2 [default]
3
4
5
6
7
8
size=
s
l [default]
Now I doubt this is the most effective way of doing so, but it works - and it's pretty neat. Without further a-do.
PHP Code:
<cfset hosts = ["http://habbo.de/", "http://habbo.com/", "http://habbo.es/", "http://habbo.nl/", "http://habbo.au/", "http://habbo.ca/"]>
<cfif not StructKeyExists(URL, "user")>
Please input a username.
<cfabort>
</cfif>
<cfquery name="getUserLook" datasource="#config.DSN#">
SELECT look
FROM users
WHERE username = <cfqueryparam value="#user#" cfsqltype="CF_SQL_CHAR" maxLength="50">
</cfquery>
<cfset args = "">
<cfif StructKeyExists(URL, "direction")>
<cfset args = "&direction=#direction#">
</cfif>
<cfif StructKeyExists(URL, "head_direction")>
<cfset args = "#args#&head_direction=#head_direction#">
</cfif>
<cfif StructKeyExists(URL, "gesture")>
<cfset args = "#args#&gesture=#gesture#">
</cfif>
<cfif StructKeyExists(URL, "size")>
<cfset args = "#args#&size=#size#">
</cfif>
<cfif StructKeyExists(URL, "img_format")>
<cfset args = "#args#&img_format=#img_format#">
</cfif>
<cfif StructKeyExists(URL, "action")>
<cfset args = "#args#&action=#action#">
</cfif>
<cfif not FileExists("#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png")>
<cfif getUserLook.RecordCount>
<cfset data = [user, getUserLook.look]>
<!--- Loop through supplied hosts. --->
<cfloop from="1" to="#arraylen(hosts)#" index="u">
<!--- Call the host. --->
<cfhttp method="head" url="#hosts[u]#" resolveurl="no" throwonerror="no" />
<!--- If called host responds with a status code --->
<cfif IsDefined("CFHTTP.responseHeader.status_code")>
<!--- Providing the host does not respond with error 403 or 404, then proceed. --->
<cfif CFHTTP.responseHeader.status_code neq "403" or CFHTTP.responseHeader.status_code neq "404">
<!--- The host loads, so let's now verify that it isn't on maintenance or closed by looking for the image. --->
<cffile action="read" file="#hosts[u]#habbo-imaging/avatarimage?figure=#getUserLook.look##args#" variable="imageValidation" />
<!--- CFFILE, having read the image's source and trimmed to the first 3 characters, is now checking it is a PNG. --->
<cfif left(imageValidation, 4) contains "PNG">
<cfimage action="write" source="#hosts[u]#habbo-imaging/avatarimage?figure=#getUserLook.look##args#" destination="#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png" overwrite="no">
<cfbreak>
</cfif>
Whoops, PNG error!
<cfabort>
</cfif>
Whoops, 403/ 404!
<cfabort>
</cfif>
Didn't respond!
<cfabort>
</cfloop>
<cfcontent type="image/png" file="#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png">
<cfelse>
Username does not exist.
</cfif>
<cfelse>
<cfset existingAvatar = "#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png">
<cfcontent type="image/png" file="#existingAvatar#">
</cfif>
If the above did not work on your web server - Aaron identified some issues when developing on Roc. Use the following - thanks to Sojoboob.
PHP Code:
<cfset hosts = ["http://habbo.de/", "http://habbo.com/", "http://habbo.es/", "http://habbo.nl/", "http://habbo.au/", "http://habbo.ca/"]>
<cfif not StructKeyExists(URL, "user")>
Please input a username.
<cfabort>
</cfif>
<cfquery name="getUserLook" datasource="#config.DSN#">
SELECT look
FROM users
WHERE username = <cfqueryparam value="#user#" cfsqltype="CF_SQL_CHAR" maxLength="50">
</cfquery>
<cfset args = "">
<cfif StructKeyExists(URL, "direction")>
<cfset args = "&direction=#direction#">
</cfif>
<cfif StructKeyExists(URL, "head_direction")>
<cfset args = "#args#&head_direction=#head_direction#">
</cfif>
<cfif StructKeyExists(URL, "gesture")>
<cfset args = "#args#&gesture=#gesture#">
</cfif>
<cfif StructKeyExists(URL, "size")>
<cfset args = "#args#&size=#size#">
</cfif>
<cfif StructKeyExists(URL, "img_format")>
<cfset args = "#args#&img_format=#img_format#">
</cfif>
<cfif StructKeyExists(URL, "action")>
<cfset args = "#args#&action=#action#">
</cfif>
<cfif not FileExists("#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png")>
<cfif getUserLook.RecordCount>
<cfset data = [user, getUserLook.look]>
<!--- Loop through supplied hosts. --->
<cfloop from="1" to="#arraylen(hosts)#" index="u">
<!--- Call the host. --->
<cfhttp method="head" url="#hosts[u]#" resolveurl="no" throwonerror="no" />
<!--- If called host responds with a status code --->
<cfif IsDefined("CFHTTP.responseHeader.status_code")>
<!--- Providing the host does not respond with error 403 or 404, then proceed. --->
<cfif CFHTTP.responseHeader.status_code neq "403" or CFHTTP.responseHeader.status_code neq "404">
<!--- The host loads, so let's now verify that it isn't on maintenance or closed by looking for the image. --->
<cfset grabthis = "#hosts[u]#habbo-imaging/avatarimage?figure=#getUserLook.look##args#">
<cfhttp method="get" url="#grabthis#" useragent="#CGI.http_user_agent#" timeout="5" getasbinary="yes" result="objGET">
<cfhttpparam type="HEADER" name="referer" value="http://habbo.com/Home/Shorty-234-Otaku-toas"/>
</cfhttp>
<cfif find("200", objGet.statusCode)>
<cfimage action="write" source="#objGet.FileContent#" destination="#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png" overwrite="no">
<cfcontent type="image/gif" variable="#objGet.FileContent#">
<cfbreak>
<cfelse>
<cfoutput>#objGet.statusCode#</cfoutput>
</cfif>
Whoops, PNG error!
<cfabort>
</cfif>
Whoops, 403/ 404!
<cfabort>
</cfif>
Didn't respond!
<cfabort>
</cfloop>
<cfcontent type="image/png" file="#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png">
<cfelse>
Username does not exist.
<cfabort>
</cfif>
<cfelse>
<cfset existingAvatar = "#GetCurrentTemplatePath()#/../avatar_cache/#Hash("#getUserLook.look##args#", "SHA-1")#.png">
<cfcontent type="image/png" file="#existingAvatar#">
</cfif>
Do ensure that in the query, #config.DSN# refers to your datasource! Please also create a folder in the same directory labelled "avatar_cache" for the cached images! :)
Re: [COLDFUSION] Habbo Imager (w. caching)
It sure is nice!
You just showed me the preview on MSN. Still cant believe you did it, lol!
Greetz,
Re: [COLDFUSION] Habbo Imager (w. caching)
Thanks for sharing this, much appreciated may use this when I'm working on my own ColdFusion projects.
Re: [COLDFUSION] Habbo Imager (w. caching)
Coldfusion, still dont know how it works lol. Maybe if I got some time left I'll start learning it cause it looks pretty awesome =D
Nice release for the coldfusion developers around here :)
Re: [COLDFUSION] Habbo Imager (w. caching)
Re: [COLDFUSION] Habbo Imager (w. caching)
Quote:
Originally Posted by
Makarov
Now explain to me what hotel runs a cold fusion web application?
Sent from my DROID RAZR using Tapatalk 2
Most hotels that do are foreign - but the point is; coldfusion CMS' do exist, and they still need supporting. This community doesn't have to be anti-Coldfusion like the rest. :):
Re: [COLDFUSION] Habbo Imager (w. caching)
Quote:
Originally Posted by
n0minal
Most hotels that do are foreign - but the point is; coldfusion CMS' do exist, and they still need supporting. This community doesn't have to be anti-Coldfusion like the rest. :):
Habboon is using coldfusion right?
Also I think if there are more coldfusion developers here will be more coldfusion releases. Coldfusion seems interesting too me :)
Re: [COLDFUSION] Habbo Imager (w. caching)
Wait, so this just mirrors Habbo's imager? Not really a genuine "imager", but, eh, it's useful for caching avatar images.
Re: [COLDFUSION] Habbo Imager (w. caching)
Quote:
Originally Posted by
Reimu
Wait, so this just mirrors Habbo's imager? Not really a genuine "imager", but, eh, it's useful for caching avatar images.
Yeah, I plan on writing a full imager soon. :):
Re: [COLDFUSION] Habbo Imager (w. caching)
Thank you n0minal, i am getting it to work now ^^
Re: [COLDFUSION] Habbo Imager (w. caching)
Verry nice thanks you i get work with this
Re: [COLDFUSION] Habbo Imager (w. caching)
Quote:
Originally Posted by
Nilenz
Verry nice thanks you i get work with this
You're welcome!
Re: [COLDFUSION] Habbo Imager (w. caching)
Haha! That's so good! But you need learn to me how to use ColdFusion, Sir. n0minal haha
+1 :)
Re: [COLDFUSION] Habbo Imager (w. caching)
Lovely, nice of you to build upon. :)