Пример #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;
     }
 }
Пример #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;
 }
Пример #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;
     }
 }
Пример #4
0
 /**
  * WebAPI/UpToDateCheck
  * - Checks if the given version of the app is up to date
  * @param string appId    The ID of which app to check
  * @param string version  The version that you want to check
  */
 function upToDateCheck($appId, $version)
 {
     $apiAction = "UpToDateCheck/v1?format=xml";
     if (empty($appId)) {
         echo "Error: No server address given!", PHP_EOL;
         return NULL;
     }
     if (empty($version)) {
         echo "Error: No version supplied!", PHP_EOL;
         return NULL;
     }
     // Set the params:
     $apiParams = "&appid=" . $appId;
     $apiParams .= "&version=" . $version;
     $this->versionCheck = new stdClass();
     $apiUrl = self::API_BASE . $apiAction . $apiParams;
     $parsedData = SteamUtility::fetchDataFromUrl($apiUrl);
     if (!empty($parsedData) && (bool) $parsedData->success) {
         $this->versionCheck->upToDate = (string) $parsedData->up_to_date;
         $this->versionCheck->isListable = (string) $parsedData->version_is_listable;
         $this->versionCheck->requiredVersion = (string) $parsedData->required_version;
         $this->versionCheck->message = (string) $parsedData->message;
     }
     return $this->versionCheck;
 }