That could be interesting for the web guy

.
It's a small PHP class for easy use of the Steam API.
If he wants to automate a few things, this class will do some work for him. I wrote it. So I give you the rights to use them
Below are application examples.
Code: Select all
<!DOCTYPE html>
<html>
<head>
<title>Steam Feeder</title>
<meta charset="utf-8">
<!-- __________________________________________ PHP library ________________________________________-->
<?php
class SteamFeeder {
public static function getObjectCategoryFromUrl($url)
{
$startIndex = strpos($url, '.com/agecheck/');
if($startIndex !== false)
{
$url = substr($url, $startIndex+14);
}
else
{
$startIndex = strpos($url, '.com/');
if($startIndex !== false)
{
$url = substr($url, $startIndex+5);
}
else
{
return null;
}
}
$endIndex = strpos($url, '/');
if($endIndex !== false)
{
$url = substr($url, 0, $endIndex);
}
return $url;
}
public static function getObjectIdFromUrl($url)
{
$category = SteamFeeder::getObjectCategoryFromUrl($url);
$startIndex = strpos($url, '/'.$category.'/');
if($startIndex !== false)
{
$url = substr($url, $startIndex+2+strlen($category));
$endIndex = strpos($url, '/');
if($endIndex !== false)
{
$url = substr($url, 0, $endIndex);
}
return $url;
}
return null;
}
public static function getApiUrlFromUrl($url)
{
return SteamFeeder::getApiUrl(SteamFeeder::getObjectCategoryFromUrl($url), SteamFeeder::getObjectIdFromUrl($url));
}
public static function getApiUrl($category, $id)
{
$apiUrl = null;
switch($category)
{
case "app":
$apiUrl = "http://store.steampowered.com/api/appdetails?appids=";
break;
case "sub":
$apiUrl = "http://store.steampowered.com/api/packagedetails?packageids=";
break;
case "bundle":
break;
}
if($apiUrl == null)
{
return null;
}
return $apiUrl . $id;
}
public static function getObjectDataFromUrl($url)
{
return SteamFeeder::getObjectData(SteamFeeder::getObjectCategoryFromUrl($url), SteamFeeder::getObjectIdFromUrl($url));
}
public static function getObjectData($category, $id)
{
if($category == null || $id == null)
{
return null;
}
$apiUrl = SteamFeeder::getApiUrl($category, $id);
if($apiUrl == null)
{
return null;
}
try{
$json = file_get_contents($apiUrl);
$obj = json_decode($json);
$obj = $obj->{$id};
if($obj->success)
{
return $obj->data;
}
}catch (Exception $e) {
//echo $e->getMessage();
}
return null;
}
public static function getOptimizedUrlFromUrl($url)
{
return SteamFeeder::getSteamUrl(SteamFeeder::getObjectCategoryFromUrl($url), SteamFeeder::getObjectIdFromUrl($url));
}
public static function getSteamUrl($category, $id)
{
return "https://store.steampowered.com/".$category."/".$id."/";
}
}
?>
</head>
<body>
<!-- __________________________________________ Test ________________________________________-->
<form action="" method="get">
Steam URL: <input type="text" name= "url">
<input type="submit" value="Get Data">
</form>
<br/><hr><br/>
<?php
if(isset($_GET["url"]) && $_GET["url"] != "")
{
$url = $_GET["url"];
echo "<fieldset><legend>The input from the user</legend>";
echo "<b>Input:</b> " . $url . "<br/>";
echo "</fieldset>";
echo "<br/>";
echo "<fieldset><legend>These are all functions that do not need the Steam API</legend>";
echo "<b>Url:</b> " . SteamFeeder::getOptimizedUrlFromUrl($url) . "<br/>";
echo "<b>Category:</b> " . SteamFeeder::getObjectCategoryFromUrl($url) . "<br/>";
echo "<b>Id:</b> " . SteamFeeder::getObjectIdFromUrl($url) . "<br/>";
echo "<b>API:</b> " . SteamFeeder::getApiUrlFromUrl($url) . "<br/>";
echo "</fieldset>";
echo "<br/>";
echo "<fieldset><legend>Here are some data that the API returns</legend>";
$data = SteamFeeder::getObjectDataFromUrl($url);
if($data != null)
{
echo "<b>Name:</b> " . $data->name . "<br/>";
echo "<b>Required age:</b> " . $data->required_age . "<br/>";
if($data->is_free)
{
echo "<b>Price:</b> It is free<br/>";
}
else
{
// Price will return without comma. Must also be inserted manually here
$price = $data->price_overview->initial;
$price1 = substr($price, 0, strlen($price)-2);
$price2 = substr($price, strlen($price)-2);
$price = $price1 . "." . $price2;
echo "<b>Price:</b> " . $price . " " . $data->price_overview->currency . "<br/>";
}
echo "<b>Website:</b> " . $data->website . "<br/>";
}
else
{
echo "Object not found";
}
echo "</fieldset>";
}
?>
</body>
</html>
And a small picture of what the code looks like when it runs:
