/** * Logic of custom rewrites * * @param Zend_Controller_Request_Http $request * @param Zend_Controller_Response_Http $response * @return Core_Model_Url */ public function rewrite(Zend_Controller_Request_Http $request = null, Zend_Controller_Response_Http $response = null) { if (is_null($request)) { $request = App_Main::getRequest(); } if (is_null($response)) { $response = App_Main::getResponse(); } $requestCases = array(); $requestPath = trim($request->getPathInfo(), '/'); /** * We need try to find rewrites information for both cases * More priority has url with query params */ if ($queryString = $this->_getQueryString()) { $requestCases[] = $requestPath . '?' . $queryString; $requestCases[] = $requestPath; } else { $requestCases[] = $requestPath; } $this->loadByRequestPath($requestCases); /** * Try to find rewrite by request path at first, if no luck - try to find by id_path */ if (!$this->getId()) { return false; } $request->setAlias(self::REWRITE_REQUEST_PATH_ALIAS, $this->getRequestPath()); $external = substr($this->getTargetPath(), 0, 6); $isPermanentRedirectOption = $this->hasOption('RP'); if ($external === 'http:/' || $external === 'https:') { if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header("Location: " . $this->getTargetPath()); exit; } else { $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); } $isRedirectOption = $this->hasOption('R'); if ($isRedirectOption || $isPermanentRedirectOption) { $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); if ($isPermanentRedirectOption) { header('HTTP/1.1 301 Moved Permanently'); } header('Location: ' . $targetUrl); exit; } $targetUrl = $request->getBaseUrl() . '/' . $this->getTargetPath(); if ($queryString = $this->_getQueryString()) { $targetUrl .= '?' . $queryString; } $request->setRequestUri($targetUrl); $request->setPathInfo($this->getTargetPath()); return true; }
/** * Send auth failed Headers and exit * */ public function authFailed() { App_Main::getResponse()->setHeader('HTTP/1.1', '401 Unauthorized')->setHeader('WWW-Authenticate', 'Basic realm="RSS Feeds"')->setBody('<h1>401 Unauthorized</h1>')->sendResponse(); exit; }
protected function _checkShouldBeSecure($request, $path = '') { //return true; if ($this->_shouldBeSecure($path) && !App_Main::isCurrentlySecure()) { $url = $this->_getCurrentSecureUrl($request); App_Main::getResponse()->setRedirect($url)->sendResponse(); exit; } }
public function getResponse() { return App_Main::getResponse(); }
/** * Get the response object * * @return Core_Controller_Response_Http */ protected function _getResponse() { return App_Main::getResponse(); }