<?php
/*-----------------------------------------------------*/
/* Title: Steam Community Wrapper */
/* Author: Dean Poot */
/* Last Updated: 14/03/09 */
/*-----------------------------------------------------*/
class steam {
// Constants
const LOGIN_URL = "https://steamcommunity.com/";
const GAMES_URL_ID = "http://steamcommunity.com/id/%s/games";
const GAMES_URL_PROFILE = "http://steamcommunity.com/profiles/%s/games";
const COOKIE = "cookie.tmp";
/* Steam Login */
/* Usage Example: login ( (string)username, (string)password ) */
/* Example Failed Return: (bool)false */
/* Example Successful Return: (string)logicalgaming */
function login($username,$password) {
unlink(self::COOKIE);
$post = sprintf("action=doLogin&goto=&steamAccountName=%s&steamPassword=%s&x=0&y=0",$username,$password);
$curl = curl_init(self::LOGIN_URL);
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_HEADER, true );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post);
curl_setopt ( $curl, CURLOPT_POST, true);
curl_setopt ( $curl, CURLOPT_COOKIE, self::COOKIE );
curl_setopt ( $curl, CURLOPT_COOKIEJAR, self::COOKIE );
curl_setopt ( $curl, CURLOPT_COOKIEFILE, self::COOKIE );
curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
$site = curl_exec($curl);
$site = str_replace( array("\n","\r"), "", $site);
$x = preg_split('/path=\/Location: (.*?)Content/',$site,-1,PREG_SPLIT_DELIM_CAPTURE);
if (count($x) == 1) {
return false;
}
if (!preg_match("#7656119#is",$x[1],$match)) {
$xx = preg_split('/http:\/\/steamcommunity.com\/id\/(.*?)\/home/', $x[1], -1, PREG_SPLIT_DELIM_CAPTURE);
if (count($xx) == 1) {
return false;
} else {
return $xx[1];
}
} else {
$xx = preg_split('/http:\/\/steamcommunity.com\/profiles\/(.*?)\/home/', $x[1], -1, PREG_SPLIT_DELIM_CAPTURE);
if (count($xx) == 1) {
return false;
} else {
return $xx[1];
}
}
}
/* Steam Get Games */
/* Usage Example: getGames( (string)logicalgaming or (int)12312312312383 );
/* Example Return: Array ( [appid] => Array ( [0] => 240 ) [image] => Array ( [0] => imageurl ) [title] => Array ( [0] => Counter-Strike: Source ) */
function getGames($id) {
if (preg_match("#7656119#is",$id,$match)) {
$link = sprintf(self::GAMES_URL_PROFILE,$id);
} else {
$link = sprintf(self::GAMES_URL_ID,$id);
}
$curl = curl_init( $link );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $curl, CURLOPT_HEADER, true );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post);
curl_setopt ( $curl, CURLOPT_POST, true);
curl_setopt ( $curl, CURLOPT_COOKIE, self::COOKIE );
curl_setopt ( $curl, CURLOPT_COOKIEJAR, self::COOKIE );
curl_setopt ( $curl, CURLOPT_COOKIEFILE, self::COOKIE );
curl_setopt ( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt ( $curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
$site = curl_exec($curl);
$site = str_replace(array("\n","\r"),"",$site);
$split = preg_split('/<div class="gameLogo">(.*?)<\/h4>/', $site, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 1; $i != count($split); $i=$i+2) {
$x = preg_split('/<a href="http:\/\/store.steampowered.com\/app\/(.*?)">/', $split[$i], -1, PREG_SPLIT_DELIM_CAPTURE);
$games['appid'][] = $x[1];
$x = preg_split('/<img src="(.*?)" \/>/', $split[$i], -1, PREG_SPLIT_DELIM_CAPTURE);
$games['image'][] = $x[1];
$x = explode("<h4>",$split[$i]);
$games['title'][] = $x[1];
}
return $games;
}
}
?>