/** * Executes render action * * @param sfWebRequest $request */ public function executeRender(sfWebRequest $request) { include_once sfConfig::get('sf_lib_dir') . '/vendor/OAuth/OAuth.php'; $this->memberApplication = Doctrine::getTable('MemberApplication')->findOneByApplicationAndMember($this->application, $this->member); $this->redirectUnless($this->memberApplication, '@application_info?id=' . $this->application->getId()); $views = $this->application->getViews(); $this->forward404Unless(isset($views['mobile']) && isset($views['mobile']['type']) && isset($views['mobile']['href']) && 'URL' === strtoupper($views['mobile']['type'])); $url = $request->getParameter('url', $views['mobile']['href']); $zendUri = Zend_Uri_Http::fromString($url); $queryString = $zendUri->getQuery(); $zendUri->setQuery(''); $zendUri->setFragment(''); $url = $zendUri->getUri(); $query = array(); parse_str($queryString, $query); $params = array('opensocial_app_id' => $this->application->getId(), 'opensocial_owner_id' => $this->member->getId()); $params = array_merge($query, $params); $method = $request->isMethod(sfWebRequest::POST) ? 'POST' : 'GET'; $consumer = new OAuthConsumer(opOpenSocialToolKit::getOAuthConsumerKey(), null, null); $signatureMethod = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin(); $httpOptions = opOpenSocialToolKit::getHttpOptions(); $client = new Zend_Http_Client(); if ('POST' !== $method) { $client->setMethod(Zend_Http_Client::GET); $url .= '?' . OAuthUtil::build_http_query($params); } else { $params = array_merge($params, $request->getPostParameters()); $client->setMethod(Zend_Http_Client::POST); $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED); $client->setRawData(OAuthUtil::build_http_query($params)); } $oauthRequest = OAuthRequest::from_consumer_and_token($consumer, null, $method, $url, $params); $oauthRequest->sign_request($signatureMethod, $consumer, null); $client->setConfig($httpOptions); $client->setUri($url); $client->setHeaders($oauthRequest->to_header()); $client->setHeaders(opOpenSocialToolKit::getProxyHeaders($request, sfConfig::get('op_opensocial_is_strip_uid', true))); $response = $client->request(); if ($response->isSuccessful()) { $contentType = $response->getHeader('Content-Type'); if (preg_match('#^(text/html|application/xhtml\\+xml|application/xml|text/xml)#', $contentType, $match)) { header('Content-Type: ' . $match[0] . '; charset=Shift_JIS'); echo opOpenSocialToolKit::rewriteBodyForMobile($this, $response->getBody()); exit; } else { header('Content-Type: ' . $response->getHeader('Content-Type')); echo $response->getBody(); exit; } } return sfView::ERROR; }
/** * Executes render action * * @param sfWebRequest $request */ public function executeRender(sfWebRequest $request) { include_once sfConfig::get('sf_lib_dir') . '/vendor/OAuth/OAuth.php'; $this->memberApplication = Doctrine::getTable('MemberApplication')->findOneByApplicationAndMember($this->application, $this->member); $this->redirectUnless($this->memberApplication, '@application_info?id=' . $this->application->getId()); $views = $this->application->getViews(); $this->forward404Unless(isset($views['mobile']) && isset($views['mobile']['type']) && isset($views['mobile']['href']) && 'URL' === strtoupper($views['mobile']['type'])); $method = $request->isMethod(sfWebRequest::POST) ? 'POST' : 'GET'; $url = $request->getParameter('url', $views['mobile']['href']); $zendUri = Zend_Uri_Http::fromString($url); $queryString = $zendUri->getQuery(); $zendUri->setQuery(''); $zendUri->setFragment(''); $url = $zendUri->getUri(); $query = array(); parse_str($queryString, $query); $params = array('opensocial_app_id' => $this->application->getId(), 'opensocial_owner_id' => $this->member->getId()); $params = array_merge($query, $params); unset($params['lat']); unset($params['lon']); unset($params['geo']); if ($request->hasParameter('l') && $this->getUser()->hasFlash('op_opensocial_location')) { $method = 'p' == $request->getParameter('l') ? 'POST' : 'GET'; $location = unserialize($this->getUser()->getFlash('op_opensocial_location')); if (isset($location['lat']) && isset($location['lon']) && isset($location['geo'])) { $params['lat'] = $location['lat']; $params['lon'] = $location['lon']; $params['geo'] = $location['geo']; } } $consumer = new OAuthConsumer(opOpenSocialToolKit::getOAuthConsumerKey(), null, null); $signatureMethod = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin(); $httpOptions = opOpenSocialToolKit::getHttpOptions(); // for BC 1.2 $isAutoConvert = sfConfig::get('op_opensocial_is_auto_convert_encoding', false); $client = new Zend_Http_Client(); if ('POST' !== $method) { $client->setMethod(Zend_Http_Client::GET); $url .= '?' . OAuthUtil::build_http_query($params); } else { $postParameters = $isAutoConvert ? $this->getPostParameters() : $_POST; $params = array_merge($params, $postParameters); $client->setMethod(Zend_Http_Client::POST); $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED); $client->setRawData(OAuthUtil::build_http_query($params)); } $oauthRequest = OAuthRequest::from_consumer_and_token($consumer, null, $method, $url, $params); $oauthRequest->sign_request($signatureMethod, $consumer, null); $client->setConfig($httpOptions); $client->setUri($url); $client->setHeaders($oauthRequest->to_header()); $client->setHeaders(opOpenSocialToolKit::getProxyHeaders($request, sfConfig::get('op_opensocial_is_strip_uid', true))); if ($isAutoConvert) { $client->setHeaders('Accept-Charset: UTF-8'); } else { $client->setHeaders('Accept-Charset: Shift_JIS, UTF-8'); } try { $response = $client->request(); } catch (Zend_Http_Client_Exception $e) { $this->logMessage($e->getMessage(), 'err'); return sfView::ERROR; } if ($response->isSuccessful()) { $contentType = $response->getHeader('Content-Type'); if (preg_match('#^(text/html|application/xhtml\\+xml|application/xml|text/xml)#', $contentType, $match)) { if ($isAutoConvert) { $this->response->setContentType($match[0] . '; charset=Shift_JIS'); } else { $this->response->setContentType($contentType); } $rewriter = new opOpenSocialMobileRewriter($this); $this->response->setContent($rewriter->rewrite($response->getBody(), $contentType, $isAutoConvert)); } else { $this->response->setContentType($contentType); $this->response->setContent($response->getBody()); } if ('test' === $this->context->getConfiguration()->getEnvironment()) { return sfView::NONE; } $this->response->send(); exit; } elseif ($response->isRedirect() && ($location = $response->getHeader('location'))) { if (!Zend_Uri_Http::check($location)) { $uri = $client->getUri(); if (strpos($location, '?') !== false) { list($location, $query) = explode('?', $location, 2); } else { $query = ''; } $uri->setQuery($query); if (strpos($location, '/') === 0) { $uri->setPath($location); } else { $path = $uri->getPath(); $path = rtrim(substr($path, 0, strrpos($path, '/')), "/"); $uri->setPath($path . '/' . $location); } $location = $uri->getUri(); } $this->redirect('@application_render?id=' . $this->application->id . '&url=' . urlencode($location)); } return sfView::ERROR; }