Advertisement
DerMarten

CSGO Inventar

Mar 25th, 2016
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.66 KB | None | 0 0
  1. <?php
  2. /*
  3.  * HOW TO USE
  4.  * -------------------------------------------------------
  5.  * require_once 'PHP Datei Pfad '; // PHP Datei der Klasse laden
  6.  *
  7.  * $csgo = new csgo("<SteamID>","<CustomSteamURLName>", <Wenn eine Custom Url vorhanden auf True setzen>); //Object der Klasse Erzeugen und Parameter uebergeben
  8.  * Beispiel:
  9.  * $csgo = new csgo("76561198072526820","dermarten", TRUE);
  10.  *
  11.  * $csgo->GetInvHTML();//Gibt ein String mit einer HTML Table zurueck (kann eine Exception erzeugen wenn das Inventar nicht geladen werden kann)
  12.  *
  13.  * ---------------------------------------------------------
  14.  *
  15.  * @author DerMarten
  16.  *
  17.  */
  18. class csgo{
  19.    
  20.     private $InvUrl = "http://steamcommunity.com/id/DerMarten/inventory/json/730/2";
  21.    
  22.     private $invFile = "none";
  23.    
  24.     private $steamid64 = "none";
  25.    
  26.     public function  __construct($steamid,$urlname = "DerMarten", $userurl = TRUE){
  27.         //CS:GO Inventar URL erzeugen
  28.         if($userurl == false)
  29.         $this->InvUrl = "http://steamcommunity.com/profiles/".$urlname."/inventory/json/730/2";
  30.         else
  31.         $this->InvUrl = "http://steamcommunity.com/id/".$urlname."/inventory/json/730/2";  
  32.         $this->steamid64 = $steamid;
  33.     }
  34.    
  35.     private function readCsgoInvFile(){
  36.         //$this->invFile = file_get_contents($this->InvUrl); //Funktioniert nicht bei Nitrado
  37.         $this->invFile = $this->url_get_contents($this->InvUrl);//Alternative
  38.        
  39.     }
  40.     /***
  41.      * Gibt das CSGO Inventar als HTML Table zurueck
  42.      * @throws Exception
  43.      */
  44.     public function GetInvHTML($tSpalten = 5){
  45.         $this->readCsgoInvFile();
  46.         $returnString = "";
  47.        
  48.         if($this->invFile == "none"){
  49.             throw new Exception('Das Inventar konnte nicht geladen werden.');
  50.            
  51.         }
  52.         $counter = 0;
  53.         $returnString = $returnString.'<table><tbody>';
  54.         $invarray = json_decode($this->invFile, true);
  55.         if($invarray['success'] != 'true'){
  56.             throw new Exception('Das Inventar konnte nicht geladen werden.');
  57.         }
  58.         foreach ($invarray['rgInventory'] as $i){
  59.            
  60.             //echo $invarray['rgDescriptions'][$i['classid'].'_0'];
  61.                
  62.                 foreach ($invarray['rgDescriptions'] as $y){
  63.                    
  64.                     if($i['classid'] == $y['classid']){
  65.                        
  66.                         if($counter == 0)
  67.                             print('<tr>');
  68.                         $returnString = $returnString.'<td style="border: 1px solid black; border-radius: 5px;background: #303436;">';
  69.                        
  70.                         $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/>';
  71.                         $returnString = $returnString.'<center>'.$y['tags']['0']['name'].'</center>';
  72.                        
  73.                         if(array_key_exists ('actions', $y)){
  74.                            
  75.                             $url = str_replace("%owner_steamid%", $this->steamid64, $y['actions']['0']['link']);
  76.                             $url = str_replace("%assetid%", $i['id'], $url);
  77.                            
  78.                             $returnString = $returnString.'<br/><center><button><a href="'.$url.'">'.$y['actions']['0']['name'].'</a></button></center>';
  79.                            
  80.                         }
  81.                        
  82.                        
  83.                         $returnString = $returnString.'</td>';
  84.                         if($counter == $tSpalten)
  85.                         {
  86.                             $returnString = $returnString.'</tr>';
  87.                             $counter = 0;
  88.                         }
  89.                         else
  90.                         {
  91.                             $counter = $counter + 1;
  92.                         }
  93.                        
  94.                     }
  95.                 }
  96.                
  97.            
  98.            
  99.         }
  100.         $returnString = $returnString.'</tbody></table>';
  101.         return $returnString;
  102.     }
  103.     private function url_get_contents ($Url) {
  104.     if (!function_exists('curl_init')){
  105.         die('CURL is not installed!');
  106.     }
  107.     $ch = curl_init();
  108.     curl_setopt($ch, CURLOPT_URL, $Url);
  109.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  110.     $output = curl_exec($ch);
  111.     curl_close($ch);
  112.     return $output;
  113.     }
  114.    
  115. }
  116.  
  117.  
  118. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement