Пример #1
0
 public function build()
 {
     $oHeader = new HTTPHeader();
     $oHeader->setResponse('Content-Type', 'application/xml');
     echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
     echo '<response><error><![CDATA[' . $this->sMessage . ']]></error></response>';
 }
Пример #2
0
 public function start()
 {
     $content = parent::start();
     // false means cURL failed
     if ($content === false) {
         throw new Exception('cURL error: ' . $this->getErrorMessage());
     }
     // anything else than status code 2xx is most likely bad
     $iHttpCode = $this->getHTTPCode();
     if ($iHttpCode < 200 || $iHttpCode > 299) {
         throw new Exception('Server error: ' . HTTPHeader::getHTTPCodeString($iHttpCode));
     }
     // check if the we actually downloaded anything
     if (strlen($content) == 0) {
         throw new Exception('Empty profile data');
     }
     // trim extra profile data (groups, friends, most played games)
     if ($this->bTrimExtra) {
         $sEndToken = '</summary>';
         $iEndPos = strpos($content, $sEndToken);
         if ($iEndPos !== false) {
             $content = substr($content, 0, $iEndPos + strlen($sEndToken));
             $content .= "\n</profile>";
         }
     }
     // remove certain control characters that are misleadingly send by the API,
     // which are invalid in XML 1.0
     if ($this->bFilterCtlChars) {
         $aCtlChr = array();
         for ($i = 0; $i < 32; $i++) {
             // tab, lf and cr are allowed
             if ($i == 9 || $i == 10 || $i == 13) {
                 continue;
             }
             $aCtlChr[] = chr($i);
         }
         $content = str_replace($aCtlChr, '', $content);
     }
     return $content;
 }
Пример #3
0
 public function refreshResponseHeaders()
 {
     // clear old headers
     self::$aResponseHeaders = array();
     // use the apache function, if possible
     if (function_exists('apache_response_headers')) {
         self::$aResponseHeaders = apache_response_headers();
     } else {
         $aHeaderList = headers_list();
         foreach ($aHeaderList as $sHeader) {
             $aHeader = explode(':', $sHeader);
             self::$aResponseHeaders[$aHeader[0]] = trim($aHeader[1]);
         }
     }
 }
Пример #4
0
 private function displayImage(File $oImageFile)
 {
     $oHeader = new HTTPHeader();
     if (!$oHeader->isModifiedSince($oImageFile->lastModified())) {
         $oHeader->setResponseCode(304);
     } else {
         $oHeader->setResponse('Content-Type', 'image/png');
         $oImageFile->readStdOut();
     }
 }
Пример #5
0
 public function run()
 {
     try {
         // load config
         $oProxyConfig = FileConfig::getInstance('xmlproxy.cfg');
         $oCommonConfig = FileConfig::getInstance('common.cfg');
         // load config vars
         $iCacheLifetime = $oCommonConfig->getInteger('cache.lifetime', 600);
         $sCacheDir = $oCommonConfig->getString('cache.dir', 'cache');
         $iDownloaderTimeout = $oCommonConfig->getInteger('downloader.timeout', 10);
         $bXMLHttpRequestOnly = $oProxyConfig->getBoolean('proxy.check_header', true);
         $oHeader = new HTTPHeader();
         // response to XMLHttpRequest only
         if ($bXMLHttpRequestOnly && !$oHeader->isXMLHttpRequest()) {
             $oHeader->setResponseCode(204);
             return;
         }
         // get profile URL
         $sXmlUrl = $this->getProfileUrl();
         // init cache
         $oXmlCache = new Cache($sCacheDir, $iCacheLifetime, 'xml');
         $oXmlFile = $oXmlCache->getFile($sXmlUrl);
         // do we have a cached version of the xml document?
         if (!$oXmlFile->isCached()) {
             try {
                 // initialize the downloader
                 $oProfileLoader = new SteamProfileLoader($sXmlUrl, SteamProfileApp::getUserAgent(), 'Ajax');
                 $oProfileLoader->setTimeout($iDownloaderTimeout);
                 $oProfileLoader->setTrimExtra(true);
                 $oProfileLoader->setFilterCtlChars(true);
                 $sXml = '';
                 try {
                     // try to download the XML file
                     $sXml = $oProfileLoader->start();
                 } catch (Exception $e) {
                     // didn't work, close cURL handle
                     $oProfileLoader->close();
                     throw $e;
                 }
                 // close cURL handle
                 $oProfileLoader->close();
                 // kill invalid characters
                 $sXml = mb_convert_encoding($sXml, "UTF-8", "UTF-8");
                 // save document to cache
                 $oXmlFile->writeString($sXml);
                 // clear stat cache to ensure that the rest of the
                 // script will notice the file modification
                 clearstatcache();
             } catch (Exception $e) {
                 // downloading failed, but maybe we can redirect to the old file
                 if (!$oXmlFile->exists()) {
                     // no, we can't
                     throw $e;
                 }
             }
         }
         // use client cache, if possible
         if (!$oHeader->isModifiedSince($oXmlFile->lastModified())) {
             $oHeader->setResponseCode(304);
             return;
         } else {
             $oHeader->setResponse('Content-Type', 'application/xml');
             $oXmlFile->readStdOut();
         }
     } catch (Exception $e) {
         // print XML-formatted error
         $oError = new XMLError($e);
         $oError->build();
     }
 }
 protected function __construct()
 {
     parent::__construct(Config::get('http.gzip'));
     $this->tpl = new Template();
 }