protected function execute($arguments = array(), $options = array())
 {
     require_once realpath(dirname(__FILE__) . '/../../../../lib/vendor/OAuth/OAuth.php');
     new sfDatabaseManager($this->configuration);
     sfContext::createInstance($this->createConfiguration('pc_frontend', 'prod'), 'pc_frontend');
     $consumerKey = isset($options['consumer-key']) && $options['consumer-key'] ? $options['consumer-key'] : opOpenSocialToolKit::getOAuthConsumerKey();
     $consumer = new OAuthConsumer($consumerKey, null, null);
     $signatureMethod = new OAuthSignatureMethod_RSA_SHA1_opOpenSocialPlugin();
     $httpOptions = opOpenSocialToolKit::getHttpOptions();
     $queueGroups = Doctrine::getTable('ApplicationLifecycleEventQueue')->getQueueGroups();
     $limitRequest = (int) $options['limit-request'];
     $limitRequestApp = (int) $options['limit-request-app'];
     $allRequest = 0;
     foreach ($queueGroups as $group) {
         $application = Doctrine::getTable('Application')->find($group[0]);
         $links = $application->getLinks();
         $linkHash = array();
         foreach ($links as $link) {
             if (isset($link['rel']) && isset($link['href'])) {
                 $method = isset($link['method']) ? strtolower($link['method']) : '';
                 $method = 'post' !== $method ? 'get' : 'post';
                 $linkHash[$link['rel']] = array('href' => $link['href'], 'method' => $method);
             }
         }
         $queues = Doctrine::getTable('ApplicationLifecycleEventQueue')->getQueuesByApplicationId($group[0], $limitRequestApp);
         foreach ($queues as $queue) {
             if (!isset($linkHash[$queue->getName()])) {
                 $queue->delete();
                 continue;
             }
             $href = $linkHash[$queue->getName()]['href'];
             $method = $linkHash[$queue->getName()]['method'];
             $oauthRequest = OAuthRequest::from_consumer_and_token($consumer, null, $method, $href, $queue->getParams());
             $oauthRequest->sign_request($signatureMethod, $consumer, null);
             $client = new Zend_Http_Client();
             if ('post' !== $method) {
                 $method = 'get';
                 $client->setMethod(Zend_Http_Client::GET);
                 $href .= '?' . $oauthRequest->to_postdata();
             } else {
                 $client->setMethod(Zend_Http_Client::POST);
                 $client->setHeaders(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED);
                 $client->setRawData($oauthRequest->to_postdata());
             }
             $client->setConfig($httpOptions);
             $client->setUri($href);
             $client->setHeaders($oauthRequest->to_header());
             $response = $client->request();
             if ($response->isSuccessful()) {
                 $queue->delete();
             }
             $allRequest++;
             if ($limitRequest && $limitRequest <= $allRequest) {
                 break 2;
             }
         }
         $application->free(true);
         $queues->free(true);
     }
 }
 public function setup()
 {
     $this->memberApplication = $this->getOption('member_application', null);
     if (!$this->memberApplication) {
         throw new LogicException();
     }
     $this->setWidgets(array('public_flag' => new sfWidgetFormChoice(array('choices' => array_map(array(sfContext::getInstance()->getI18n(), '__'), self::$publicFlagChoices)))));
     $this->setValidators(array('public_flag' => new sfValidatorChoice(array('choices' => array_keys(self::$publicFlagChoices)))));
     if (opOpenSocialToolKit::isEnableHomeGadget()) {
         $this->setWidget('is_view_home', new sfWidgetFormInputCheckbox());
         $this->setValidator('is_view_home', new sfValidatorBoolean());
         $this->widgetSchema->setLabel('is_view_home', 'Display on the home');
     }
     if (opOpenSocialToolKit::isEnableProfileGadget()) {
         $this->setWidget('is_view_profile', new sfWidgetFormInputCheckbox());
         $this->setValidator('is_view_profile', new sfValidatorBoolean());
         $this->widgetSchema->setLabel('is_view_profile', 'Display on your profile');
     }
     foreach ($this->memberApplication->getApplicationSettings() as $name => $value) {
         if (!empty($value)) {
             $this->setDefault($name, $value);
         }
     }
     $this->setDefault('public_flag', $this->memberApplication->getPublicFlag());
     $this->widgetSchema->setNameFormat('setting[%s]');
 }
 /**
  * fetch a OpenSocial application metadata
  *
  * @param string $url
  * @param string $culture
  */
 public static function fetchGadgetMetadata($url, $culture)
 {
     $cul = explode('_', $culture);
     $context = new MetadataGadgetContext(self::arrayToObject(array('country' => isset($cul[1]) ? $cul[1] : 'ALL', 'language' => $cul[0], 'view' => 'default', 'container' => 'openpne')), $url);
     if (!self::$isInvalidatedCache) {
         self::invalidateGadgetCache($context);
         self::$isInvalidatedCache = true;
     }
     $gadgetServer = new GadgetFactory($context, null);
     $gadgets = $gadgetServer->createGadget();
     return $gadgets;
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * 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;
 }
 /**
  * add a new application
  *
  * @param string  $url
  * @param boolean $update
  * @param string  $culture
  * @return Application
  */
 public function addApplication($url, $update = false, $culture = null)
 {
     if ($culture === null) {
         $culture = sfContext::getInstance()->getUser()->getCulture();
     }
     if ($culture != sfConfig::get('sf_default_culture')) {
         self::addApplication($url, $update, sfConfig::get('sf_default_culture'));
     }
     $application = $this->findOneByUrl($url);
     if (!$application) {
         $application = new Application();
     }
     if (isset($application->Translation[$culture]) && !$update) {
         $ua = $application->getUpdatedAt();
         $time = strtotime($ua);
         if (!empty($ua) && time() - $ua <= Doctrine::getTable('SnsConfig')->get('application_cache_time', 24 * 60 * 60)) {
             return $application;
         }
     }
     $gadget = opOpenSocialToolKit::fetchGadgetMetadata($url, $culture);
     $prefs = array();
     foreach ($gadget->gadgetSpec->userPrefs as $pref) {
         $prefs[$pref['name']] = $pref;
     }
     $views = array();
     foreach ($gadget->gadgetSpec->views as $name => $view) {
         unset($view['content']);
         $views[$name] = $view;
     }
     $translation = $application->Translation[$culture];
     $application->setUrl($url);
     $application->setLinks($gadget->gadgetSpec->links);
     $translation->title = $gadget->getTitle();
     $translation->title_url = $gadget->getTitleUrl();
     $translation->description = $gadget->getDescription();
     $translation->directory_title = $gadget->getDirectoryTitle();
     $translation->screenshot = $gadget->getScreenShot();
     $translation->thumbnail = $gadget->getThumbnail();
     $translation->author = $gadget->getAuthor();
     $translation->author_aboutme = $gadget->getAuthorAboutme();
     $translation->author_affiliation = $gadget->getAuthorAffiliation();
     $translation->author_email = $gadget->getAuthorEmail();
     $translation->author_photo = $gadget->getAuthorPhoto();
     $translation->author_link = $gadget->getAuthorLink();
     $translation->author_quote = $gadget->getAuthorQuote();
     $translation->settings = $prefs;
     $translation->views = $views;
     if (isset($views['mobile'])) {
         if (!(isset($views['mobile']['type']) && 'URL' === strtoupper($views['mobile']['type']))) {
             throw new Exception();
         }
     }
     $application->setIsPc(true);
     if (count($views) == 1) {
         if (isset($views['mobile'])) {
             $application->setIsPc(false);
         }
     }
     if ($application->getIsMobile()) {
         if (!isset($views['mobile'])) {
             $application->setIsMobile(false);
         }
     }
     if ($gadget->getScrolling() == 'true') {
         $application->setScrolling(true);
     } else {
         $application->setScrolling(false);
     }
     $singleton = $gadget->getSingleton();
     if ($singleton == 'true' || empty($singleton)) {
         $application->setSingleton(true);
     } else {
         $application->setSingleton(false);
     }
     $height = $gadget->getHeight();
     $application->setHeight(!empty($height) ? $height : 0);
     $application->save();
     return $application;
 }
 public function getMediaItems($userId, $groupId, $albumId, $mediaItemIds, $collectionOptions, $fields, $token)
 {
     if (!class_exists('Album')) {
         throw new SocialSpiException("Not implemented", ResponseError::$NOT_IMPLEMENTED);
     }
     $first = $this->fixStartIndex($collectionOptions->getStartIndex());
     $max = $this->fixCount($collectionOptions->getCount());
     if (!is_object($userId)) {
         $userId = new UserId('userId', $userId);
         $groupId = new GroupId('self', 'all');
     }
     $memberIds = $this->getIdSet($userId, $groupId, $token);
     if ($groupId->getType() !== 'self' || count($memberIds) !== 1) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     $memberId = $memberIds[0];
     $albumObject = Doctrine::getTable('Album')->find($albumId);
     if (!$albumObject) {
         throw new SocialSpiException("Album Not Found", ResponseError::$BAD_REQUEST);
     }
     if ($albumObject->getMemberId() != $memberId && !($albumObject->getPublicFlag() === AlbumTable::PUBLIC_FLAG_SNS || $albumObject->getPublicFlag() === AlbumTable::PUBLIC_FLAG_OPEN)) {
         throw new SocialSpiException("Bad Request", ResponseError::$BAD_REQUEST);
     }
     $totalSize = 0;
     $query = Doctrine::getTable('AlbumImage')->createQuery()->where('album_id = ?', $albumObject->getId());
     $totalSize = $query->count();
     $query->offset($first);
     $query->limit($max);
     $objects = $query->execute();
     $results = array();
     // block check
     $isBlock = false;
     if ($token->getViewerId()) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($memberId, $token->getViewerId());
         if ($relation && $relation->getIsAccessBlock()) {
             $isBlock = true;
         }
     }
     if (!$isBlock) {
         foreach ($objects as $object) {
             $result['albumId'] = $object->getId();
             $result['created'] = $object->getCreatedAt();
             $result['description'] = opOpenSocialToolKit::convertEmojiForApi($object->getDescription());
             $result['fileSize'] = $object->getFilesize();
             $result['id'] = $object->getId();
             $result['lastUpdated'] = $object->getUpdatedAt();
             $result['thumbnailUrl'] = '';
             $result['title'] = $object->getDescription();
             $result['type'] = 'IMAGE';
             $result['url'] = '';
             if ($object->getFile()) {
                 sfContext::getInstance()->getConfiguration()->loadHelpers(array('Asset', 'sfImage'));
                 $result['thumbnailUrl'] = sf_image_path($object->getFile(), array('size' => '180x180'), true);
                 $result['url'] = sf_image_path($object->getFile(), array(), true);
             }
             $results[] = $result;
         }
     }
     $collection = new RestfulCollection($results, $first, $totalSize);
     $collection->setItemsPerPage($max);
     return $collection;
 }
 /**
  * get profile datas
  *
  * @param array $allowed
  * @return array
  */
 public function getData($allowed = array())
 {
     $result = array();
     $allowed = array_merge($this->forceFields, $allowed);
     $isBlock = false;
     // check access block
     if ($this->viewer) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($this->member->getId(), $this->viewer->getId());
         if ($relation && $relation->getIsAccessBlock()) {
             $isBlock = true;
         }
     }
     foreach ($this->tableToOpenPNE as $k => $v) {
         $checkSupportMethodName = $this->getSupportedFieldExport()->getIsSupportedMethodName($k);
         if (in_array($k, $allowed) && $this->getSupportedFieldExport()->{$checkSupportMethodName}()) {
             if ($isBlock) {
                 $result[$k] = '';
             } else {
                 $methodName = $this->getGetterMethodName($k);
                 $result[$k] = opOpenSocialToolKit::convertEmojiForApi($this->{$methodName}());
             }
         }
     }
     return $result;
 }