Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * HOW TO USE
- * -------------------------------------------------------
- * require_once 'PHP Datei Pfad '; // PHP Datei der Klasse laden
- *
- * $csgo = new csgo("<SteamID>","<CustomSteamURLName>", <Wenn eine Custom Url vorhanden auf True setzen>); //Object der Klasse Erzeugen und Parameter uebergeben
- * Beispiel:
- * $csgo = new csgo("76561198072526820","dermarten", TRUE);
- *
- * $csgo->GetInvHTML();//Gibt ein String mit einer HTML Table zurueck (kann eine Exception erzeugen wenn das Inventar nicht geladen werden kann)
- *
- * ---------------------------------------------------------
- *
- * @author DerMarten
- *
- */
- class csgo{
- private $InvUrl = "http://steamcommunity.com/id/DerMarten/inventory/json/730/2";
- private $invFile = "none";
- private $steamid64 = "none";
- public function __construct($steamid,$urlname = "DerMarten", $userurl = TRUE){
- //CS:GO Inventar URL erzeugen
- if($userurl == false)
- $this->InvUrl = "http://steamcommunity.com/profiles/".$urlname."/inventory/json/730/2";
- else
- $this->InvUrl = "http://steamcommunity.com/id/".$urlname."/inventory/json/730/2";
- $this->steamid64 = $steamid;
- }
- private function readCsgoInvFile(){
- //$this->invFile = file_get_contents($this->InvUrl); //Funktioniert nicht bei Nitrado
- $this->invFile = $this->url_get_contents($this->InvUrl);//Alternative
- }
- /***
- * Gibt das CSGO Inventar als HTML Table zurueck
- * @throws Exception
- */
- public function GetInvHTML($tSpalten = 5){
- $this->readCsgoInvFile();
- $returnString = "";
- if($this->invFile == "none"){
- throw new Exception('Das Inventar konnte nicht geladen werden.');
- }
- $counter = 0;
- $returnString = $returnString.'<table><tbody>';
- $invarray = json_decode($this->invFile, true);
- if($invarray['success'] != 'true'){
- throw new Exception('Das Inventar konnte nicht geladen werden.');
- }
- foreach ($invarray['rgInventory'] as $i){
- //echo $invarray['rgDescriptions'][$i['classid'].'_0'];
- foreach ($invarray['rgDescriptions'] as $y){
- if($i['classid'] == $y['classid']){
- if($counter == 0)
- print('<tr>');
- $returnString = $returnString.'<td style="border: 1px solid black; border-radius: 5px;background: #303436;">';
- $returnString = $returnString.'<center><span style="text-algin: center; color: #'.$y["name_color"].';">'.$y["market_name"].'</span><br/><img height="100px" src="http://steamcommunity-a.akamaihd.net/economy/image/'.$y['icon_url'].'"></center><br/>';
- $returnString = $returnString.'<center>'.$y['tags']['0']['name'].'</center>';
- if(array_key_exists ('actions', $y)){
- $url = str_replace("%owner_steamid%", $this->steamid64, $y['actions']['0']['link']);
- $url = str_replace("%assetid%", $i['id'], $url);
- $returnString = $returnString.'<br/><center><button><a href="'.$url.'">'.$y['actions']['0']['name'].'</a></button></center>';
- }
- $returnString = $returnString.'</td>';
- if($counter == $tSpalten)
- {
- $returnString = $returnString.'</tr>';
- $counter = 0;
- }
- else
- {
- $counter = $counter + 1;
- }
- }
- }
- }
- $returnString = $returnString.'</tbody></table>';
- return $returnString;
- }
- private function url_get_contents ($Url) {
- if (!function_exists('curl_init')){
- die('CURL is not installed!');
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $Url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement