/**
  * generate a configutaion
  *
  * @param string $containerName
  * @param string $snsUrl
  * @param string $shindigUrl
  * @param string $apiUrl
  * @return string
  */
 public function generate($snsUrl = null, $shindigUrl = null, $apiUrl = null, $templateFile = null)
 {
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Asset'));
     if (null === $templateFile) {
         $templateFile = dirname(__FILE__) . '/../vendor/Shindig/config/container.js';
     }
     $containerTemplate = $this->loadTemplate($templateFile);
     $request = sfContext::getInstance()->getRequest();
     $snsBaseUrl = $this->addSlashToUrl(sfConfig::get('op_base_url'));
     if (null === $snsUrl) {
         if (!($snsUrl = sfConfig::get('op_opensocial_sns_url'))) {
             $snsUrl = $snsBaseUrl;
             if ($this->isDevEnvironment) {
                 $snsUrl .= 'pc_frontend_dev.php/';
             }
         }
     }
     $snsUrl = $this->addSlashToUrl($snsUrl);
     if (null === $apiUrl) {
         if (!($apiUrl = sfConfig::get('op_opensocial_api_url'))) {
             if (Doctrine::getTable('SnsConfig')->get('is_use_outer_shindig')) {
                 $apiUrl = Doctrine::getTable('SnsConfig')->get('shindig_url');
             } else {
                 $apiUrl = $snsBaseUrl . 'api';
                 if ($this->isDevEnvironment) {
                     $apiUrl .= '_dev';
                 }
                 $apiUrl .= '.php/';
             }
         }
     }
     $apiUrl = $this->addSlashToUrl($apiUrl);
     if (null === $shindigUrl) {
         if (Doctrine::getTable('SnsConfig')->get('is_use_outer_shindig')) {
             $shindigUrl = $apiUrl;
         } else {
             $shindigUrl = $snsUrl;
         }
     }
     $shindigUrl = $this->addSlashToUrl($shindigUrl);
     // override container template
     $containerTemplate['gadgets.container'] = array($this->containerName);
     $containerTemplate['gadgets.jsUriTemplate'] = $shindigUrl . 'gadgets/js/%js%';
     $jsUrl = parse_url($shindigUrl . 'gadgets/js');
     $containerTemplate['gadgets.uri.js.host'] = $jsUrl['scheme'] . '://' . $jsUrl['host'] . (isset($jsUrl['port']) ? $jsUrl['port'] : '') . '/';
     $containerTemplate['gadgets.uri.js.path'] = $jsUrl['path'];
     $containerTemplate['gadgets.securityTokenType'] = 'secure';
     $containerTemplate['gadgets.osDataUri'] = $apiUrl . 'social/rpc';
     $features =& $containerTemplate['gadgets.features'];
     $features['core.io']['proxyUrl'] = $shindigUrl . 'gadgets/proxy?refresh=%refresh%&url=%url%';
     $features['core.io']['jsonProxyUrl'] = $shindigUrl . 'gadgets/makeRequest';
     $features['views']['profile']['urlTemplate'] = $snsUrl . 'member/{var}';
     $features['views']['canvas']['urlTemplate'] = $snsUrl . 'application/canvas/id/{var}';
     $features['views']['home'] = array('isOnlyVisible' => false, 'urlTemplate' => $snsUrl, 'aliases' => array());
     $features['rpc']['parentRelayUr'] = $snsUrl . 'opOpenSocialPlugin/js/rpc_relay.html';
     $features['opensocial']['path'] = $apiUrl . 'social/rpc';
     $features['opensocial']['invalidatePath'] = $shindigUrl . 'gadgets/api/rpc';
     $export = new opOpenSocialProfileExport();
     $supportedFields = $export->getSupportedFields();
     $supportedFields = array_merge($supportedFields, array('activity' => array('id', 'title', 'userId', 'postedTime', 'streamUrl', 'appId', 'mediaItems'), 'mediaItem' => array('id', 'albumId', 'created', 'description', 'fileSize', 'lastUpdated', 'thumbnailUrl', 'title', 'type', 'url')));
     $features['opensocial']['supportedFields'] = $supportedFields;
     $features['osapi.services'][$apiUrl . 'social/rpc'] = array('system.listMethods', 'people.get', 'appdata.get', 'appdata.update', 'appdata.delete');
     $features['oapi']['endPoint'] = array($apiUrl . '/social/rpc');
     $json = json_encode($containerTemplate);
     return $json;
 }
 /**
  * generate a configutaion
  *
  * @param string $containerName
  * @param string $snsUrl
  * @param string $shindigUrl
  * @param string $apiUrl
  * @return string 
  */
 public function generate($snsUrl = null, $shindigUrl = null, $apiUrl = null)
 {
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Asset'));
     //Template
     $containerTemplate = array('gadgets.container' => array(), 'gadgets.parent' => null, 'gadgets.lockedDomainRequired' => false, 'gadgets.lockedDomainSuffix' => '-a.example.com:8080', 'gadgets.iframeBaseUri' => '/gadgets/ifr', 'gadgets.jsUriTemplate' => '#shindig_url#gadgets/js/%js%', 'gadgets.oauthGadgetCallbackTemplate' => '#shindig_url#/gadgets/oauthcallback', 'gadgets.securityTokenType' => 'secure', 'gadgets.osDataUri' => '#api_url#social/rpc', 'gadgets.features' => array('core.io' => array('proxyUrl' => '#shindig_url#gadgets/proxy?refresh=%refresh%&url=%url%', 'jsonProxyUrl' => '#shindig_url#gadgets/makeRequest'), 'views' => array('profile' => array('isOnlyVisible' => false, 'urlTemplate' => '#sns_url#member/{var}', 'aliases' => array('DASHBOARD', 'default')), 'canvas' => array('isOnlyVisible' => true, 'urlTemplate' => '#sns_url#application/canvas/id/{var}')), 'rpc' => array('parentRelayUrl' => '#sns_url#opOpenSocialPlugin/js/rpc_relay.html', 'useLegacyProtocol' => false), 'skins' => array('properties' => array('BG_COLOR' => '', 'BG_IMAGE' => '', 'BG_POSITION' => '', 'BG_REPEAT' => '', 'FONT_COLOR' => '', 'ANCHOR_COLOR' => '')), 'opensocial' => array('path' => '#api_url#social/rpc', 'invalidatePath' => '#shindig_url#gadgets/api/rpc', 'domain' => 'shindig', 'enableCaja' => false, 'supportedFields' => array()), 'osapi.services' => array('gadgets.rpc' => array('container.listMethods'), '#api_url#social/rpc' => array('system.listMethods', 'people.get', 'appdata.get', 'appdata.update', 'appdata.delete'), '#shindig_url#gadgets/api/rpc' => array('cache.invalidate')), 'osapi' => array('endPoint' => array('#api_url#social/rpc', '#shindig_url#gadgets/api/rpc')), 'osml' => array('library' => 'config/OSML_library.xml')));
     $containerTemplate['gadgets.container'][] = $this->containerName;
     $request = sfContext::getInstance()->getRequest();
     if ($snsUrl === null) {
         $snsUrl = $request->getUriPrefix() . $request->getRelativeUrlRoot() . '/';
         if ($this->isDevEnvironment) {
             $snsUrl .= 'pc_frontend_dev.php/';
         }
     }
     if ($apiUrl === null) {
         if (Doctrine::getTable('SnsConfig')->get('is_use_outer_shindig')) {
             $apiUrl = Doctrine::getTable('SnsConfig')->get('shindig_url');
             if (substr($apiUrl, -1) !== '/') {
                 $apiUrl .= '/';
             }
         } else {
             $apiUrl = $request->getUriPrefix() . $request->getRelativeUrlRoot() . '/api';
             if ($this->isDevEnvironment) {
                 $apiUrl .= '_dev';
             }
             $apiUrl .= '.php/';
         }
     }
     if ($shindigUrl === null) {
         if (Doctrine::getTable('SnsConfig')->get('is_use_outer_shindig')) {
             $shindigUrl = $apiUrl;
         } else {
             $shindigUrl = $snsUrl;
         }
     }
     $export = new opOpenSocialProfileExport();
     $supportedFields = $export->getSupportedFields();
     $supportedFields = array_merge($supportedFields, array('activity' => array('id', 'title', 'userId', 'postedTime', 'streamUrl', 'appId', 'mediaItems'), 'mediaItem' => array('id', 'albumId', 'created', 'description', 'fileSize', 'lastUpdated', 'thumbnailUrl', 'title', 'type', 'url')));
     $containerTemplate['gadgets.features']['opensocial']['supportedFields'] = $supportedFields;
     $json = json_encode($containerTemplate);
     $replace = array('/#sns_url#/' => addcslashes($snsUrl, '/'), '/#shindig_url#/' => addcslashes($shindigUrl, '/'), '/#api_url#/' => addcslashes($apiUrl, '/'));
     return preg_replace(array_keys($replace), $replace, $json);
 }