Esempio n. 1
0
 public function getProfileUrl($bLang = true)
 {
     // load config
     $oGPCConfig = GPCConfig::getInstance('get');
     // get selected id
     $sID = $oGPCConfig->getString('id', null);
     if ($sID == null) {
         throw new Exception('No profile ID assigned');
     }
     $oSteamID = new SteamID($sID);
     $sXmlUrl = 'http://steamcommunity.com/';
     // choose if we got a numeric id or an alias
     if (!$oSteamID->isValid()) {
         // complain about invalid characters, if found
         if (!preg_match('/^[a-zA-Z0-9-_]+$/', $sID)) {
             throw new Exception("Invalid profile alias: {$sID}");
         }
         $sXmlUrl .= 'id/' . $sID;
     } else {
         $sXmlUrl .= 'profiles/' . $oSteamID->getSteamID64();
     }
     // add xml parameter so we get xml data (hopefully)
     $sXmlUrl .= '?xml=1';
     // get language setting
     $sLang = $oGPCConfig->getString('lang', null);
     if (!$bLang || $sLang == null) {
         // we're done here
         return $sXmlUrl;
     }
     $sLang = strtolower($sLang);
     if (in_array($sLang, self::$aValidLang)) {
         // add language parameter
         $sXmlUrl .= '&l=' . $sLang;
     }
     return $sXmlUrl;
 }
Esempio n. 2
0
 public function run()
 {
     $bDebug = defined('DEBUG') && DEBUG;
     try {
         // get profile URL
         $sXmlUrl = $this->getProfileUrl(false);
         // load config
         $oCommonConfig = FileConfig::getInstance('common.cfg');
         $oImageConfig = FileConfig::getInstance('image.cfg');
         $oGPCConfig = GPCConfig::getInstance('get');
         // load config vars
         $iCacheLifetime = $oCommonConfig->getInteger('cache.lifetime', 600);
         $sCacheDir = $oCommonConfig->getString('cache.dir', 'cache');
         $bImageFallback = $oImageConfig->getString('image.fallback', true);
         $sDefaultLayout = $oImageConfig->getString('image.layout.default', 'small');
         $sDefaultTheme = $oImageConfig->getString('image.theme.default', 'default');
         $sLayout = $oGPCConfig->getStringAlnum('layout', $sDefaultLayout);
         $sTheme = $oGPCConfig->getStringAlnum('theme', $sDefaultTheme);
         // init cache
         $oImageCache = new Cache($sCacheDir, $iCacheLifetime, 'png');
         $oImageFile = $oImageCache->getFile($_SERVER['QUERY_STRING']);
         $sImageBase = 'image/layouts';
         if (!file_exists("{$sImageBase}/{$sLayout}")) {
             if (!file_exists("{$sImageBase}/{$sDefaultLayout}")) {
                 throw new RuntimeException('Default layout folder not found');
             }
             $sLayout = $sDefaultLayout;
         }
         $sLayoutDir = "{$sImageBase}/{$sLayout}";
         include "{$sLayoutDir}/SteamProfileImage.php";
         try {
             // do we have a cached version of the profile image?
             if (!$oImageFile->isCached()) {
                 $oProfileImage = new SteamProfileImage();
                 // try to generate the profile image
                 $oProfileImage->createProfile($sXmlUrl, $sLayoutDir, $sTheme);
                 // save it to cache
                 $oProfileImage->toPng($oImageFile->getPath());
                 // clear stat cache to ensure that the rest of the
                 // script will notice the file modification
                 clearstatcache();
             }
             $this->displayImage($oImageFile);
         } catch (SteamProfileImageException $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but a themed error image could have been generated
             try {
                 // try a fallback to the cached image first
                 if ($bImageFallback && $oImageFile->exists()) {
                     $this->displayImage($oImageFile);
                 } else {
                     // try to display the error image
                     $oProfileImage->toPng();
                 }
             } catch (Exception $f) {
                 // didn't work, re-throw the source exception
                 throw $e;
             }
         } catch (Exception $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but we could try a fallback to the cached image
             if ($bImageFallback && $oImageFile->exists()) {
                 // redirect to cached image file
                 $this->displayImage($oImageFile);
             } else {
                 // nothing cached, re-throw exception
                 throw $e;
             }
         }
     } catch (Exception $e) {
         // quite fatal error, try to render a fail-safe error image
         if ($bDebug || !GDImage::isAvailable()) {
             $oHeader = new HTTPHeader();
             $oHeader->setResponse('Content-Type', 'text/plain');
             echo $bDebug ? "{$e}\n" : $e->getMessage();
         } else {
             $ErrorImage = new ErrorImage($e->getMessage());
             $ErrorImage->toPng();
         }
     }
 }