/**
  * Parses and performs the (combined) os-data requests
  *
  * @param string $osDataRequests
  */
 private function performDataRequests($osDataRequests)
 {
     //TODO check with the java implementation guys if they do a caching strategy here (same as with data-pipelining),
     // would result in a much higher render performance..
     libxml_use_internal_errors(true);
     $this->doc = new DOMDocument(null, 'utf-8');
     $this->doc->preserveWhiteSpace = true;
     $this->doc->formatOutput = false;
     $this->doc->strictErrorChecking = false;
     $this->doc->recover = false;
     $this->doc->resolveExternals = false;
     if ($this->doc->loadXML($osDataRequests)) {
         $dataPipeliningRequests = array();
         // walk the one or multiple script tags, and build a combined request array
         foreach ($this->doc->childNodes as $childNode) {
             if ($childNode->tagName == 'script') {
                 $dataPipeliningRequests = array_merge($dataPipeliningRequests, DataPipelining::Parse($childNode));
             }
         }
         // and perform the requests
         if (count($dataPipeliningRequests)) {
             $this->dataInserts = DataPipelining::fetch($dataPipeliningRequests, $this->context);
             $this->addContextData($this->dataInserts);
         }
     } else {
         echo "Error parsing os-data:\n" . XmlError::getErrors($osDataRequests);
     }
 }
 /**
  * Renders a 'proxied content' view, for reference see:
  * http://opensocial-resources.googlecode.com/svn/spec/draft/OpenSocial-Data-Pipelining.xml
  *
  * @param Gadget $gadget
  * @param array $view
  */
 public function renderGadget(Shindig_Gadget $gadget, $view)
 {
     $this->setGadget($gadget);
     if (Shindig_Config::get('P3P') != '') {
         header("P3P: " . Shindig_Config::get('P3P'));
     }
     /* TODO
      * We should really re-add OAuth fetching support some day, uses these view atributes:
      * $view['oauthServiceName'], $view['oauthTokenName'], $view['oauthRequestToken'], $view['oauthRequestTokenSecret'];
      */
     $authz = $this->getAuthz($view);
     $refreshInterval = $this->getRefreshInterval($view);
     $href = $this->buildHref($view, $authz);
     if (count($view['dataPipelining'])) {
         $request = new RemoteContentRequest($href, "Content-type: application/json\n");
         $request->setMethod('POST');
         $request->getOptions()->ignoreCache = $gadget->gadgetContext->getIgnoreCache();
     } else {
         // no data-pipelining set, use GET and set cache/refresh interval options
         $request = new RemoteContentRequest($href);
         $request->setMethod('GET');
         $request->setRefreshInterval($refreshInterval);
         $request->getOptions()->ignoreCache = $gadget->gadgetContext->getIgnoreCache();
     }
     $signingFetcherFactory = $gadgetSigner = false;
     if ($authz != 'none') {
         $gadgetSigner = Shindig_Config::get('security_token_signer');
         $gadgetSigner = new $gadgetSigner();
         $token = $gadget->gadgetContext->extractAndValidateToken($gadgetSigner);
         $request->setToken($token);
         $request->setAuthType($authz);
         $request->getOptions()->ownerSigned = $this->getSignOwner($view);
         $request->getOptions()->viewerSigned = $this->getSignViewer($view);
         $signingFetcherFactory = new SigningFetcherFactory(Shindig_Config::get("private_key_file"));
     }
     $remoteFetcherClass = Shindig_Config::get('remote_content_fetcher');
     $remoteFetcher = new $remoteFetcherClass();
     $basicRemoteContent = new BasicRemoteContent($remoteFetcher, $signingFetcherFactory, $gadgetSigner);
     // Cache POST's as if they were GET's, since we don't want to re-fetch and repost the social data for each view
     $basicRemoteContent->setCachePostRequest(true);
     if (($response = $basicRemoteContent->getCachedRequest($request)) == false) {
         // Don't fetch the data-pipelining social data unless we don't have a cached version of the gadget's content
         $dataPipeliningResults = DataPipelining::fetch($view['dataPipelining'], $this->context);
         // spec stats that the proxied content data-pipelinging data is *not* available to templates (to avoid duplicate posting
         // of the data to the gadget dev's server and once to js space), so we don't assign it to the data context, and just
         // post the json encoded results to the remote url.
         $request->setPostBody(json_encode($dataPipeliningResults));
         $response = $basicRemoteContent->fetch($request);
     }
     if ($response->getHttpCode() != '200') {
         // an error occured fetching the proxied content's gadget content
         $content = '<html><body><h1>An error occured fetching the gadget content</h1><p>http error code: ' . $response->getHttpCode() . '</p><p>' . $response->getResponseContent() . '</body></html>';
     } else {
         // fetched ok, build the response document and output it
         $content = $response->getResponseContent();
         $content = $this->parseTemplates($content);
         $content = $this->rewriteContent($content);
         $content = $this->addTemplates($content);
     }
     echo $content;
 }