public function initContext($format = null) { parent::initContext($format); // Hack to prevent duplicate content-type headers $pos = false; $response = $this->getResponse(); $headers = $response->getHeaders(); $response->clearHeaders(); foreach ($headers as $header) { $name = $header['name']; $value = $header['value']; $replace = $header['replace']; if (strtolower($name) == 'content-type') { if ($pos === true) { continue; } $pos = true; } $response->setHeader($name, $value, $replace); } if (null === $this->_currentContext || !$this->getAutoSwitchLayout()) { return; } $layoutName = $this->getLayout($this->_currentContext); if ($layoutName) { $layout = Zend_Layout::getMvcInstance(); $layout->enableLayout()->setLayout($layoutName); } }
/** * 设置对话框布局 * * @param string $format * @return void */ public function initContext($format = null) { $this->_currentContext = null; $this->setAutoDisableLayout(false); $this->setCallback('inbox', self::TRIGGER_POST, '_callbackPost'); return parent::initContext($format); }
/** * Initialize AJAX context switching * * Checks for XHR requests; if detected, attempts to perform context switch. * * @param string $format * @return void */ public function initContext($format = null) { $this->_currentContext = null; if (!$this->getRequest()->isXmlHttpRequest()) { return; } return parent::initContext($format); }
/** * Initialize AJAX context switching * * Checks for XHR requests; if detected, attempts to perform context switch. * * @param string $format * @return void */ public function initContext($format = null) { $this->_currentContext = null; $request = $this->getRequest(); if (!method_exists($request, 'isXmlHttpRequest') || !$this->getRequest()->isXmlHttpRequest()) { return; } return parent::initContext($format); }
/** * 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'); } }
/** * Setup the necessary contexts */ public function init() { parent::init(); $this->_contextSwitch = $this->_helper->getHelper('contextSwitch'); if (!$this->_contextSwitch->hasContext('rss')) { $this->_contextSwitch->addContext('rss', array('suffix' => 'rss', 'headers' => array('Content-type' => 'application/rss+xml;charset=UTF-8'))); } if (!$this->_contextSwitch->hasContext('atom')) { $this->_contextSwitch->addContext('atom', array('suffix' => 'atom', 'headers' => array('Content-type' => 'application/atom+xml'))); } $this->_contextSwitch->addActionContext('list', array('rss', 'atom'))->addActionContext('index', array('rss', 'atom'))->initContext(); }
public function initContext($format = null) { parent::initContext($format); // Hack to prevent duplicate content-type headers $pos = false; $headers = $this->getResponse()->getHeaders(); foreach ($headers as $key => $value) { if (strtolower($key) == 'content-type') { if (!$pos) { $pos = $key; } else { unset($headers[$pos]); } } } if (null === $this->_currentContext || !$this->getAutoSwitchLayout()) { return; } $layoutName = $this->getLayout($this->_currentContext); if ($layoutName) { $layout = Zend_Layout::getMvcInstance(); $layout->enableLayout()->setLayout($layoutName); } }
public function __construct($options = null) { parent::__construct($options); $this->addContext('rss', array('suffix' => 'rss', 'headers' => array('Content-Type' => 'application/xml'), 'callbacks' => array('init' => 'initRssContext', 'post' => 'postRssContext'))); $this->addContext('ajax', array()); }
/** * 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(); }
/** * 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() . ');'); }
/** * Set a specific Cache expire time for the current context * * @param integer $ttl * @return void */ protected function _setCacheTtl($ttl = self::CACHE_DEFAULT_TTL) { $this->_context->setHeader('snippet', 'Cache-Control', sprintf(self::CACHE_CONTROL_HEADER_VALUE, intval($ttl))); }