Esempio n. 1
0
 /**
  * Performs a GET on the API and boxes the XML data.
  * @param string $url Target URL
  */
 public static function fetchDataFromUrl($url)
 {
     try {
         $content = SteamUtility::fetchURL($url);
         if ($content) {
             return new SimpleXMLElement($content);
         } else {
             return null;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Esempio n. 2
0
 /**
  * GetSchemaForGame - Loads schema for a selected game
  * @param  string $lang Language for descriptions
  * @return array        Schema as an associative array cointaining ['achievements'] and ['stats']
  */
 function getSchema($lang = 'en')
 {
     if (!empty($this->appID)) {
         $base = "http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v0002/?key={$this->apiKey}&appid={$this->appID}&l={$lang}";
     }
     $json = SteamUtility::fetchURL($base);
     if (!$json) {
         return null;
     }
     $gameSchema = json_decode($json, true);
     if (!$gameSchema) {
         return null;
     }
     $this->gameSchema = array('achievements' => $gameSchema['game']['availableGameStats']['achievements'], 'stats' => $gameSchema['game']['availableGameStats']['stats']);
     return $this->gameSchema;
 }
Esempio n. 3
0
 /**
  * Returns achievements for a specific game found in user's profile.
  * @param  string $gameName Game alias on steamcommunity.com, e.g. 'FM2012'
  * @return array            An array of achievements or null on error
  */
 function getAchievements($gameName)
 {
     //Set Base URL for the query:
     if (empty($this->vanityURL)) {
         $base = "http://steamcommunity.com/profiles/{$this->userID}/stats/{$gameName}?xml=1";
     } else {
         $base = "http://steamcommunity.com/id/{$this->vanityURL}/stats/{$gameName}?xml=1";
     }
     try {
         $content = SteamUtility::fetchURL($base);
         if ($content) {
             $gameStats = new SimpleXMLElement($content);
         } else {
             return null;
         }
     } catch (Exception $e) {
         // Usually happens when service is down
         return null;
     }
     if ($gameStats) {
         if ($gameStats->privacyState != 'public') {
             // Only public profiles are supported
             return null;
         }
         $achievements = array();
         // Load achievements
         foreach ($gameStats->achievements->achievement as $ach) {
             $item = new stdClass();
             $item->apiname = (string) $ach->apiname;
             $item->name = (string) $ach->name;
             $item->description = (string) $ach->description;
             if ($ach->attributes()->closed == 1) {
                 $item->unlocked = 1;
                 $item->icon = (string) $ach->iconClosed;
                 $item->unlockTimestamp = (int) $ach->unlockTimestamp;
             } else {
                 $item->unlocked = 0;
                 $item->icon = (string) $ach->iconOpen;
             }
             $achievements[] = $item;
         }
         return $achievements;
     }
 }