Exemple #1
0
 /**
  * Send the file to the client (Download)
  *
  * @param  string|array $options Options for the file(s) to send
  * @throws \UnexpectedValueException
  * @throws \InvalidArgumentException
  * @return void
  */
 public function send($options = null)
 {
     if (is_string($options)) {
         $filepath = $options;
     } else {
         if (is_array($options) && isset($options['filepath'])) {
             $filepath = $options['filepath'];
         } else {
             throw new \InvalidArgumentException("Filename is not set.");
         }
     }
     if (!is_file($filepath) || !is_readable($filepath)) {
         throw new \InvalidArgumentException("File '{$filepath}' does not exists.");
     }
     $mimeType = $this->mime->getMimeType($filepath);
     $this->response->setHeader('Content-length', filesize($filepath));
     $this->response->setHeader('Content-Type', $mimeType);
     $this->response->sendHeaders();
     $handle = fopen($filepath, 'r');
     if ($handle) {
         while (($buffer = fgets($handle, 4096)) !== false) {
             echo $buffer;
         }
         if (!feof($handle)) {
             throw new \UnexpectedValueException("Unexpected end of file");
         }
         fclose($handle);
     }
 }
Exemple #2
0
 public static function prepareDiscoveryParams(array &$params, Zend_Controller_Response_Http $response, $topicType, $topicId, $selfLink, $subscriptionOption)
 {
     if (!bdApi_Option::getSubscription($topicType)) {
         // subscription for this topic type has been disabled
         return false;
     }
     // subscription discovery
     $hubLink = bdApi_Data_Helper_Core::safeBuildApiLink('subscriptions', null, array('hub.topic' => bdApi_Model_Subscription::getTopic($topicType, $topicId), 'oauth_token' => ''));
     $response->setHeader('Link', sprintf('<%s>; rel=hub', $hubLink));
     $response->setHeader('Link', sprintf('<%s>; rel=self', $selfLink));
     // subscription info
     if (!empty($subscriptionOption)) {
         $subscriptionOption = @unserialize($subscriptionOption);
         if (!empty($subscriptionOption['subscriptions'])) {
             /* @var $session bdApi_Session */
             $session = XenForo_Application::getSession();
             $clientId = $session->getOAuthClientId();
             foreach ($subscriptionOption['subscriptions'] as $subscription) {
                 if ($subscription['client_id'] == $clientId) {
                     $params['subscription_callback'] = $subscription['callback'];
                 }
             }
         }
     }
     return true;
 }
 /**
  * Send the file to the client (Download)
  *
  * @param  string|array $options Options for the file(s) to send
  * @return void
  */
 public function send($options = null)
 {
     if (is_string($options)) {
         $filepath = $options;
     } else {
         if (is_array($options)) {
             $filepath = $options['filepath'];
         } else {
             throw new Exception("Filename is not set.");
         }
     }
     if (!is_file($filepath) || !is_readable($filepath)) {
         throw new Exception("File '{$filepath}' does not exists.");
     }
     $mimeType = $this->_detectMimeType(array('name' => $filepath));
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-length', filesize($filepath));
     $response->setHeader('Content-Type', $mimeType);
     $response->sendHeaders();
     $handle = fopen($filepath, 'r');
     if ($handle) {
         while (($buffer = fgets($handle, 4096)) !== false) {
             echo $buffer;
         }
         if (!feof($handle)) {
             throw new Exception("Error: unexpected fgets() fail.");
         }
         fclose($handle);
     }
 }
Exemple #4
0
 /**
  * Constructor.
  *
  * @param XenForo_Dependencies_Abstract
  * @param Zend_Controller_Response_Http
  * @param Zend_Controller_Request_Http
  */
 public function __construct(XenForo_Dependencies_Abstract $dependencies, Zend_Controller_Response_Http $response, Zend_Controller_Request_Http $request)
 {
     $this->_dependencies = $dependencies;
     $this->_response = $response;
     $this->_request = $request;
     if (!XenForo_Application::isRegistered('config') || XenForo_Application::getConfig()->enableClickjackingProtection) {
         $this->_response->setHeader('X-Frame-Options', 'SAMEORIGIN');
     }
     $this->_preloadContainerData();
 }
 /**
  * Creates a response object, sets the Content-Type header and assigns the
  * response to the front controller.
  *
  * @return null
  */
 protected function _initResponseCharset()
 {
     $front = Zend_Controller_Front::getInstance();
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', 'text/html; charset=utf-8', false);
     $front->setResponse($response);
 }
Exemple #6
0
 /** Initialise the response and set gzip status
  */
 protected function _initResponse()
 {
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('X-Powered-By', 'Dan\'s magic army of elves')->setHeader('Host', 'finds.org.uk')->setHeader('X-Compression', 'gzip')->setHeader('Accept-Encoding', 'gzip, deflate')->setHeader('Expires', gmdate('D, d M Y H:i:s', time() + 2 * 3600) . ' GMT', true);
     $frontController = Zend_Controller_Front::getInstance();
     $frontController->setResponse($response);
 }
Exemple #7
0
 protected function _initFrontControllerOutput()
 {
     $front = $this->bootstrap('FrontController')->getResource('FrontController');
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     $front->setResponse($response);
 }
Exemple #8
0
    /**
     * Challenge Client
     *
     * Sets a 401 or 407 Unauthorized response code, and creates the
     * appropriate Authenticate header(s) to prompt for credentials.
     *
     * @return Zend_Auth_Result Always returns a non-identity Auth result
     */
    protected function _challengeClient()
    {
        if ($this->_imaProxy) {
            $statusCode = 407;
            $headerName = 'Proxy-Authenticate';
        } else {
            $statusCode = 401;
            $headerName = 'WWW-Authenticate';
        }

        $this->_response->setHttpResponseCode($statusCode);

        // Send a challenge in each acceptable authentication scheme
        if (in_array('basic', $this->_acceptSchemes)) {
            $this->_response->setHeader($headerName, $this->_basicHeader());
        }
        if (in_array('digest', $this->_acceptSchemes)) {
            $this->_response->setHeader($headerName, $this->_digestHeader());
        }
        return new Zend_Auth_Result(
            Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
            array(),
            array('Invalid or absent credentials; challenging client')
        );
    }
Exemple #9
0
 public function init()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $sysCache = $registry->get("sysCache");
     $cacheFiles = new Ml_Cache_Files($sysCache);
     Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers');
     $frontController = $this->getBootstrap()->getResource('FrontController');
     $dispatcher = $frontController->getDispatcher();
     $request = $frontController->getRequest();
     $router = $frontController->getRouter();
     $router->removeDefaultRoutes();
     $compat = new Zend_Controller_Router_Route_Module(array(), $dispatcher, $request);
     $router->addRoute(HOST_MODULE, $compat);
     $routerConfig = $cacheFiles->getConfigIni(APPLICATION_PATH . '/configs/' . HOST_MODULE . 'Routes.ini');
     $router->addConfig($routerConfig, "apiroutes");
     Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/modules/' . HOST_MODULE . '/controllers/helpers');
     $loadOauthStore = Zend_Controller_Action_HelperBroker::getStaticHelper("LoadOauthstore");
     $loadOauthStore->setinstance();
     $loadOauthStore->preloadServer();
     $frontController->setBaseUrl($config['apiroot'])->setParam('noViewRenderer', true)->addModuleDirectory(APPLICATION_PATH . '/modules')->addControllerDirectory(APPLICATION_PATH . '/modules/' . HOST_MODULE . '/controllers');
     $response = new Zend_Controller_Response_Http();
     if (filter_input(INPUT_GET, "responseformat", FILTER_UNSAFE_RAW) == 'json') {
         $contentType = 'application/json';
     } else {
         $contentType = 'text/xml';
     }
     $response->setHeader('Content-Type', $contentType . '; charset=utf-8', true);
     $frontController->setResponse($response);
 }
 /**
  * Renders page-level debugging output and replaces the original view content
  * with it. Alternatively, it could inject itself into the view content.
  *
  * @param string $originalContent Original, rendered view content
  *
  * @return string Replacement rendered view content
  */
 public function renderDebugOutput($originalContent)
 {
     $this->_response->clearHeaders();
     $this->_response->setHttpResponseCode(200);
     $this->_response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     $this->_response->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT', true);
     return XenForo_Debug::getDebugPageWrapperHtml(XenForo_Debug::getDebugHtml());
 }
Exemple #11
0
 /**
  * Challenge Client
  *
  * Sets a 401 Unauthorized response code, and creates the
  * appropriate Authenticate header(s) to prompt for credentials.
  *
  * @return Zend_Auth_Result Always returns a non-identity Auth result
  */
 protected function _challengeClient()
 {
     $this->_response->setHttpResponseCode(401);
     // Send a challenge in each acceptable authentication scheme
     foreach ($this->_schemes as $scheme => $callback) {
         $this->_response->setHeader('WWW-Authenticate', $scheme);
     }
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(), array('Invalid or absent credentials; challenging client'));
 }
Exemple #12
0
 protected function _initResponse()
 {
     $options = $this->getOptions();
     if (!isset($options['response']['defaultContentType'])) {
         return;
     }
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', $options['response']['defaultContentType'], true);
     $this->bootstrap('FrontController');
     $this->getResource('FrontController')->setResponse($response);
 }
Exemple #13
0
 /**
  * Tells the browser that the data should be downloaded (rather than displayed)
  * using the specified file name.
  *
  * @param string $fileName
  * @param boolean $inline True if the attachment should be shown inline - use with caution!
  */
 public function setDownloadFileName($fileName, $inline = false)
 {
     $type = $inline ? 'inline' : 'attachment';
     $fileName = str_replace('"', '', $fileName);
     if (preg_match('/[\\x80-\\xFF]/', $fileName)) {
         $altNamePart = "; filename*=UTF-8''" . rawurlencode($fileName);
     } else {
         $altNamePart = '';
     }
     $this->_response->setHeader('Content-Disposition', $type . '; filename="' . str_replace('"', '', $fileName) . '"' . $altNamePart, true);
 }
Exemple #14
0
 protected function _initResponse()
 {
     // Ensure front controller instance is present, and fetch it
     $this->bootstrap('FrontController');
     $front = $this->getResource('FrontController');
     /* @var $front Zend_Controller_Front */
     // Initialize and set the response object
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     $front->setResponse($response);
     return $response;
 }
 /**
  * Challenge Client
  *
  * Sets a 401 or 407 Unauthorized response code, and creates the
  * appropriate Authenticate header(s) to prompt for credentials.
  *
  * @return Zend_Auth_Result Always returns a non-identity Auth result
  */
 protected function _challengeClient()
 {
     if ($this->_imaProxy) {
         $statusCode = 407;
         $headerName = 'Proxy-Authenticate';
     } else {
         $statusCode = 401;
         $headerName = 'WWW-Authenticate';
     }
     $this->_response->setHttpResponseCode($statusCode);
     $this->_response->setHeader($headerName, $this->_getAuthHeader());
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(), array('Invalid or absent credentials; challenging client'));
 }
Exemple #16
0
 protected function _initModifiedFrontController()
 {
     $options = $this->getOption('resources');
     if (!isset($options['modifiedFrontController']['contentType'])) {
         return;
     }
     $this->bootstrap('FrontController');
     $front = $this->getResource('FrontController');
     //$front->addModuleDirectory(APPLICATION_PATH . '/modules');
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', $options['modifiedFrontController']['contentType'], true);
     $front->setResponse($response);
 }
Exemple #17
0
 public static function addHeaders(XenForo_ViewRenderer_Abstract $viewRenderer, Zend_Controller_Response_Http $response)
 {
     if (!bdApi_Option::get('cors')) {
         return;
     }
     $request = $viewRenderer->getRequest();
     $origin = $request->getHeader('Origin');
     if (!empty($origin)) {
         $response->setHeader('Access-Control-Allow-Origin', $origin, true);
         $response->setHeader('Access-Control-Allow-Credentials', 'true', true);
     } else {
         $response->setHeader('Access-Control-Allow-Origin', '*', true);
     }
     $method = $request->getHeader('Access-Control-Request-Method');
     if (!empty($method)) {
         $response->setHeader('Access-Control-Allow-Method', $method, true);
     }
     $headers = $request->getHeader('Access-Control-Request-Headers');
     if (!empty($headers)) {
         $response->setHeader('Access-Control-Allow-Headers', $headers, true);
     }
 }
 /**
  * @param array $options
  *
  * @throws Exception
  */
 public function send($options = array())
 {
     if (is_string($options)) {
         $options = array('filepath' => $options);
     } elseif (!is_array($options)) {
         $options = array();
     }
     $filepath = isset($options['filepath']) ? $options['filepath'] : '';
     if (!is_file($filepath) || !is_readable($filepath)) {
         throw new Exception("File '{$filepath}' does not exists.");
     }
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Length', filesize($filepath));
     $response->setHeader('Content-Type', $this->_detectMimeType(array('name' => $filepath)));
     if (array_key_exists('headers', $options) && is_array($options['headers'])) {
         foreach ($options['headers'] as $header => $value) {
             $response->setHeader($header, $value);
         }
     }
     $response->setHeader('ETag', md5_file($filepath));
     $response->sendHeaders();
     readfile($filepath);
 }
Exemple #19
0
 protected function sendCsv($filename, array $rows, Zend_Controller_Response_Http $response, $delimiter = "\t")
 {
     $response->setHeader('Cache-Control', 'maxage=3600')->setHeader('Pragma', 'no-cache')->setHeader('Content-type', 'text/csv')->setHeader('Content-Disposition', 'attachment; filename=' . $filename);
     foreach ($rows as &$r) {
         if (is_array($r)) {
             $out = "";
             foreach ($r as $s) {
                 $out .= ($out ? $delimiter : "") . '"' . str_replace('"', "'", $s) . '"';
             }
             $out .= "\r\n";
             $r = $out;
         }
     }
     $response->appendBody(implode("", $rows));
 }
Exemple #20
0
 /**
  * Send response to browser with json content type
  */
 public function sendResponse()
 {
     $this->_response = Mage::app()->getResponse();
     //check redirect
     if ($this->_response->isRedirect()) {
         $headers = $this->_response->getHeaders();
         $redirect = '';
         foreach ($headers as $header) {
             if ("Location" == $header["name"]) {
                 $redirect = $header["value"];
                 break;
             }
         }
         if ($redirect) {
             $this->setRedirect($redirect);
         }
     }
     $this->_response->clearHeaders();
     $this->_response->setHeader('Content-Type', 'application/json');
     $this->_response->clearBody();
     $this->_response->setBody($this->toJson());
     $this->_response->sendResponse();
     exit;
 }
Exemple #21
0
 /**
  * Enter description here...
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     if ('' == ($authHeader = $this->_request->getServer("HTTP_X_WSSE"))) {
         $this->_response->setHttpResponseCode(401, 'Unauthorized', true);
         $this->_response->setHeader('WWW-Authenticate', 'WSSE realm="' . $this->_realm . '", profile="UsernameToken"');
         return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, array(), array('Missing WSSE Header'));
     }
     $headerParts = $this->parseWsseHeader($authHeader);
     $passwordDigest = $this->createPasswordDigest($headerParts['nonce'], $headerParts['created'], $this->_credential);
     if ($passwordDigest == $headerParts['digest'] && $this->_identity == $headerParts['username']) {
         return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $this->_identity);
     }
     $this->_response->setHttpResponseCode(401, 'Unauthorized', true);
     return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, array(), array('Unauthorized'));
 }
 /**
  * Intercept a request for a link redirect
  *
  * @param string|bool $error If non-false, an error that occurred when validating the request
  */
 protected function _outputLinkRedirect($error)
 {
     if ($error === 'invalid_url') {
         header('Content-Type: text/html; utf-8', true, 500);
         die('Invalid URL');
     }
     if (empty(XenForo_Application::getOptions()->imageLinkProxy['links'])) {
         $error = 'disabled';
     }
     if (!$error) {
         /* @var $proxyModel XenForo_Model_LinkProxy */
         $proxyModel = XenForo_Model::create('XenForo_Model_LinkProxy');
         $linkId = $proxyModel->logVisit($this->_url);
         if ($linkId && !empty(XenForo_Application::getOptions()->imageLinkProxyReferrer['enabled']) && $this->_referrer) {
             $proxyModel->logLinkReferrer($linkId, $this->_referrer);
         }
         if ($this->_json) {
             header('Content-type: application/json; charset=UTF-8');
             echo json_encode(array('logged' => true));
             exit;
         }
         // this used to redirect, but we don't take this approach any longer, so we display an intersitial
     }
     $request = new Zend_Controller_Request_Http();
     XenForo_Session::startPublicSession($request);
     $this->_dependencies->preRenderView();
     if (!preg_match('#^https?://#i', $this->_url)) {
         throw new Exception('Unsafe proxy URL: ' . $this->_url);
     }
     $printable = urldecode($this->_url);
     if (!preg_match('/./u', $printable)) {
         $printable = $this->_url;
     }
     $renderer = new XenForo_ViewRenderer_HtmlPublic($this->_dependencies, $this->_response, $request);
     $contents = $renderer->createTemplateObject('link_redirect', array('url' => $this->_url, 'printable' => $printable, 'parts' => parse_url($this->_url)));
     $containerParams = $this->_dependencies->getEffectiveContainerParams(array(), $request);
     $output = $renderer->renderContainer($contents, $containerParams);
     $extraHeaders = XenForo_Application::gzipContentIfSupported($output);
     foreach ($extraHeaders as $extraHeader) {
         $this->_response->setHeader($extraHeader[0], $extraHeader[1], $extraHeader[2]);
     }
     $this->_response->setHeader('X-Proxy-Error', $error);
     $this->_response->sendHeaders();
     echo $output;
 }
Exemple #23
0
 public function __construct($app)
 {
     parent::__construct($app);
     date_default_timezone_set('America/Lima');
     $this->bootstrap('multidb');
     /* ejecuta un recurso */
     $db = $this->getPluginResource('multidb')->getDb('db');
     /* obtiene los datos del recurso */
     Zend_Db_Table::setDefaultAdapter($db);
     /* registra el adaptador */
     Zend_Registry::set('db', $db);
     /*registra la clase adaptadora*/
     Zend_Form::setDefaultTranslator(new Zend_Translate('array', APPLICATION_PATH . '/configs/lang/es.php', 'es'));
     $this->getResourceLoader()->addResourceType('entity', 'entitys/', 'Entity');
     $this->getResourceLoader()->addResourceType('service', 'services/', 'Service');
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-Type', 'text/html; charset=utf-8')->setHeader('Accept-Encoding', 'gzip, deflate')->setHeader('Expires', 'max-age=' . 20, true)->setHeader('Cache-Control', 'private', 'must-revalidate')->setHeader('Pragma', 'no-cache', true);
     $response->sendResponse();
 }
Exemple #24
0
 /**
  * Used to send the server response to the client.
  */
 public static function sendResponse(Zend_Controller_Response_Http $response)
 {
     // Set the response headers.
     $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
     // Send the response to the client.
     $response->sendResponse();
 }
Exemple #25
0
 public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs)
 {
     $user = $this->getDi()->user;
     switch ($request->getActionName()) {
         case 'c':
             $id = $this->getDi()->app->reveal($request->getFiltered('id'));
             //actualy it is notification_id
             $notification = $this->getDi()->notificationTable->load($id);
             $this->getDi()->notificationClickTable->log($user, $notification);
             Am_Controller::redirectLocation($notification->url);
             break;
         case 'get':
             if (!$user) {
                 Am_Controller::ajaxResponse(array());
             } else {
                 $items = $this->getDi()->notificationTable->getNotificationsForUser($this->getDi()->auth->getUser());
                 $dismiss = $user->data()->getBlob('notification.dismiss');
                 if (!$dismiss) {
                     $dismiss = array();
                 } else {
                     $dismiss = unserialize($dismiss);
                 }
                 $out = array();
                 foreach ($items as $item) {
                     $display = $user->data()->get('notification.display.' . $item->pk());
                     if ($item->limit && $display >= $item->limit) {
                         continue;
                     }
                     if (in_array($item->notification_id, $dismiss)) {
                         continue;
                     }
                     $user->data()->set('notification.display.' . $item->pk(), ++$display);
                     $n = new stdClass();
                     $n->id = $this->getDi()->app->obfuscate($item->notification_id);
                     $n->content = $item->content;
                     $n->is_custom = $item->is_custom ? true : false;
                     $n->is_blank = $item->is_blank ? true : false;
                     $n->link = $item->url;
                     $out[] = $n;
                 }
                 $user->save();
                 Am_Controller::ajaxResponse($out);
             }
             break;
         case 'js':
             $response->setHeader('Content-Type', 'application/x-javascript; charset=utf-8');
             echo $this->getJs();
             break;
         case 'd':
             $id = $this->getDi()->app->reveal($request->getFiltered('id'));
             if ($user && $id) {
                 $dismiss = $user->data()->getBlob('notification.dismiss');
                 if (!$dismiss) {
                     $dismiss = array();
                 } else {
                     $dismiss = unserialize($dismiss);
                 }
                 $dismiss[] = $id;
                 $user->data()->setBlob('notification.dismiss', serialize($dismiss));
                 $user->data()->update();
             }
             break;
         default:
             throw new Am_Exception_InternalError('Unknown Action');
     }
 }
 /**
  * Set response object
  *
  * @param Zend_Controller_Response_Http $response
  * @return Mage_Oauth_Model_Server
  */
 public function setResponse(Zend_Controller_Response_Http $response)
 {
     $this->_response = $response;
     $this->_response->setHeader(Zend_Http_Client::CONTENT_TYPE, Zend_Http_Client::ENC_URLENCODED, true);
     $this->_response->setHttpResponseCode(self::HTTP_OK);
     return $this;
 }
Exemple #27
0
 protected function _initModifiedFrontController()
 {
     $options = $this->getOptions();
     if (!isset($options['resources']['modifiedFrontController']['contentType'])) {
         return;
     }
     $this->bootstrap('FrontController');
     if ($this->hasResource('FrontController')) {
         $front = $this->getResource('FrontController');
     }
     $response = new Zend_Controller_Response_Http();
     $response->setHeader('Content-type', $options['resources']['modifiedFrontController']['contentType']);
     $front->setResponse($response);
     return $response;
 }
 /**
  * Retrieve response object
  *
  * @return Zend_Controller_Response_Http
  */
 public function getResponse()
 {
     if (empty($this->_response)) {
         $this->_response = new Mage_Core_Controller_Response_Http();
         $this->_response->headersSentThrowsException = Mage::$headersSentThrowsException;
         $this->_response->setHeader("Content-Type", "text/html; charset=UTF-8");
     }
     return $this->_response;
 }
Exemple #29
0
 public function run(Zend_Controller_Response_Abstract $response = null)
 {
     $args = array($this);
     $this->runCallback(self::CB_BEFORE_RUN, $args);
     if ($response === null) {
         $response = new Zend_Controller_Response_Http();
     }
     $this->response = $response;
     $action = $this->getCurrentAction();
     $this->request->setActionName($action);
     ob_start();
     $this->actionRun($action);
     if ($this->response->isRedirect() && $this->completeRequest->isXmlHttpRequest()) {
         $url = null;
         foreach ($response->getHeaders() as $header) {
             if ($header['name'] == 'Location') {
                 $url = $header['value'];
             }
         }
         $code = $response->getHttpResponseCode();
         // change request to ajax response
         $response->clearAllHeaders();
         $response->clearBody();
         $response->setHttpResponseCode(200);
         $response->setHeader("Content-Type", "application/json; charset=UTF-8", true);
         $response->setBody(Am_Controller::getJson(array('ngrid-redirect' => $url, 'status' => $code)));
         //throw new Am_Exception_Redirect($url);
     } else {
         $response->appendBody(ob_get_clean());
     }
     unset($this->response);
     return $response;
 }
Exemple #30
0
 /**
  * Set "auth failed" headers to the specified response object
  *
  * @param Zend_Controller_Response_Http $response
  * @param string $realm
  */
 public function failHttpAuthentication(Zend_Controller_Response_Http $response, $realm)
 {
     $response->setHeader('HTTP/1.1', '401 Unauthorized')->setHeader('WWW-Authenticate', 'Basic realm="' . $realm . '"')->setBody('<h1>401 Unauthorized</h1>');
 }