Ejemplo n.º 1
0
 /**
  * Builds a calling context to invoke the application's AJAX endpoint.
  *
  * @param array $request the request array
  * @param RingsideSocialSession $session the social session
  * @return RingsideSocialAppContext the context
  */
 private static function buildCallContext($api_key, RingsideSocialSession $session)
 {
     $ctx = new RingsideSocialAppContext();
     $ctx->setApiKey($api_key);
     $ctx->setIsAjax(1);
     $ctx->setFlavor('ajax');
     // TODO: $ctx->setNetworkId();
     $ctx->setSessionKey($session->getApiSessionKey($api_key));
     $ctx->setExpires($session->getExpiry() == null ? 0 : $session->getExpiry());
     $ctx->setNetworkId(RingsideSocialConfig::$apiKey);
     if ($session->isLoggedIn()) {
         // We only know these if the user is logged in
         $ctx->setUser($session->getUserId());
         // TODO: Is App Added?
         $ctx->setIsAppAdded(1);
     }
     $ctx->setTime(microtime(true));
     return $ctx;
 }
Ejemplo n.º 2
0
 /**
  * Will call  a local or core application without going through a remote http call.
  * The remainder of the call semantics are attempted to hold up.
  *
  * @param unknown_type $apiKey
  * @param unknown_type $apiSecret
  * @param unknown_type $socialClient
  * @return unknown
  */
 public function renderLocal($apiKey, $apiSecret, $sessionKey, $socialClient)
 {
     // These are the contextual parameters passed to an application.
     // Create openFB request.
     $ctx = new RingsideSocialAppContext();
     $ctx->setFlavor($this->flavor);
     $ctx->setIFrame(0);
     $ctx->setInCanvas(1);
     $ctx->setTime(time());
     $ctx->setIsAppAdded(1);
     if ($socialClient->inSession()) {
         $ctx->setUser($socialClient->getCurrentUser());
         $ctx->setSessionKey($sessionKey);
         //      $ctx->setProfileUpdateTime();
         $ctx->setExpires(0);
         if ($socialClient->getNetworkSession()->getPrincipalId()) {
             $ctx->setPrincipalId($socialClient->getNetworkSession()->getPrincipalId());
         }
     }
     $ctx->setApiKey($apiKey);
     $ctx->setRequestMethod($_SERVER['REQUEST_METHOD']);
     $ctx->setNetworkId(RingsideSocialConfig::$apiKey);
     $ctx->setSocialSessionKey($socialClient->getNetworkSession()->getSessionKey());
     $cbReq = $ctx->getParameters($apiSecret);
     foreach ($cbReq as $k => $v) {
         $this->params[$k] = $v;
     }
     $text = '';
     ob_start();
     try {
         if ($this->path == '/' || $this->path == '') {
             $this->path = 'index.php';
         }
         $canvasMatch = array();
         preg_match(',^([^/]*),', $this->canvasUrl, $canvasMatch);
         error_log("Canvas matches for {$this->canvasUrl}: " . var_export($canvasMatch, true));
         error_log("Path is {$this->path}");
         $loaded = $this->_load('apps.' . $canvasMatch[1], $this->path);
         if ($loaded === false) {
             $this->error = "No such application is available.";
             ob_end_clean();
         } else {
             $text = ob_get_clean();
             if (empty($text)) {
                 $this->error = "The application rendered an empty page.";
             }
         }
     } catch (Exception $exception) {
         ob_end_clean();
         $this->error = "Exception processing request.";
         error_log("Exception processing request : {$exception}");
     }
     foreach ($cbReq as $k => $v) {
         unset($this->params[$k]);
     }
     return $text;
 }