예제 #1
0
 /**
  * This extends the default ZF JSON serialization to work with JSONP, which
  * enables cross-site AJAX using JSON.
  * 
  * @return void
  */
 public function postJsonContext()
 {
     parent::postJsonContext();
     if ($this->getAutoJsonSerialization() and $callbackParam = $this->getRequest()->get(Omeka_Controller_Plugin_Jsonp::CALLBACK_KEY)) {
         $response = $this->getResponse();
         $json = $response->getBody();
         $response->setBody($callbackParam . '(' . $json . ')');
         // Also be sure to set the content header to 'text/javascript'.
         $response->setHeader('Content-Type', 'text/javascript');
     }
 }
예제 #2
0
 /**
  * Processes view variables before the parent implementation serializes
  * to JSON.
  *
  * @return void
  */
 public function postJsonContext()
 {
     if (!$this->_extRequest || !$this->getAutoJsonSerialization()) {
         return parent::postJsonContext();
     }
     $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
     $view = $viewRenderer->view;
     if (!$view instanceof Zend_View_Interface) {
         return parent::postJsonContext();
     }
     $request = $this->getRequest();
     $params = $request->getParams();
     $extParameter = $this->_extRequest->getConfigValue('extParameter');
     if (isset($params[$extParameter])) {
         $params = $params[$extParameter];
         $vars = $view->getVars();
         $view->clearVars();
         if (is_array($params)) {
             if (isset($params['action'])) {
                 $view->action = $params['action'];
             }
             if (isset($params['method'])) {
                 $view->method = $params['method'];
             }
             if (isset($params['tid'])) {
                 $view->tid = $params['tid'];
             }
             if ($this->getResponse()->isException()) {
                 $view->type = 'exception';
                 $view->message = $vars;
             } else {
                 if (isset($params['type'])) {
                     $view->type = $params['type'];
                 }
                 $view->result = $vars;
             }
         } else {
             // can only be an exception then
             if ($this->getResponse()->isException()) {
                 $view->type = 'exception';
                 $view->message = $vars;
             } else {
                 $view->result = $vars;
             }
         }
     }
     parent::postJsonContext();
 }
예제 #3
0
 /**
  * JSONP post processing.
  * Mainly calls postJsonContext
  * 
  * @throws Zend_Controller_Action_Exception
  */
 public function postContext()
 {
     $this->contextSwitch->postJsonContext();
     $response = $this->contextSwitch->getResponse();
     $response->setBody($this->callbackFunction . '(' . $response->getBody() . ');');
 }