/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * @param Zend_Controller_Request_Abstract $request * @return Zend_Controller_Request_Abstract * @throws Zend_Controller_Router_Exception */ public function route(Zend_Controller_Request_Abstract $request) { if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } // Find the matching route $routeMatched = false; foreach (array_reverse($this->_routes, true) as $name => $route) { if (method_exists($route, 'isAbstract') && $route->isAbstract()) { continue; } if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $request->getPathInfo(); } else { $match = $request; } if ($params = $route->match($match)) { $this->_setRequestParams($request, $params); $this->_currentRoute = $name; $routeMatched = true; break; } } if (!$routeMatched) { require_once 'Zend/Controller/Router/Exception.php'; throw new Zend_Controller_Router_Exception('No route matched the request', 404); } if ($this->_useCurrentParamsAsGlobal) { $params = $request->getParams(); foreach ($params as $param => $value) { $this->setGlobalParam($param, $value); } } return $request; }
public function preDispatch(Zend_Controller_Request_Abstract $request) { // Kiem tra neu chua dang nhap thi bo qua $identity = Digitalus_Auth::getIdentity(); if (!$identity) { return; } //////////////////////////////////////// // $this->_cache = ZendX_Cache_Manager::getInstance(); $this->_cache = Digitalus_Cache_Manager::getInstance(); // La la cac phuong thuc khac get() no se khong lay tu content tu cache ra if (!$request->isGet()) { self::$doNotCache = true; return; } $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $path = $request->getPathInfo(); // co loi o day , xem link de biet cach sua $this->_key = md5($path); $this->_keyTags = array($module, "{$module}_{$controller}", "{$module}_{$controller}_{$action}"); if (false !== ($data = $this->getCache())) { $response = $this->getResponse(); $response->setBody($data['default']); $response->sendResponse(); exit; } }
public function preDispatch(AbstractRequest $request) { if ($request->module === 'default' && $request->controller === 'auth') { return; } $frontController = FrontController::getInstance(); $bootstrap = $frontController->getParam('bootstrap'); $serviceManager = $bootstrap->getResource('ServiceManager'); $authService = $serviceManager->get('Zend\\Authentication\\AuthenticationService'); if (!$authService->hasIdentity()) { $response = $this->getResponse(); $currentUri = sprintf('%s://%s%s%s', $request->getScheme(), $request->getHttpHost(), $request->getBaseUrl(), $request->getPathInfo()); $adapter = $authService->getAdapter(); $adapter->setLoginParameters(array('service' => $currentUri)); // Assume user is back here from a CAS authentication if ($request->getQuery('ticket')) { $adapter->setServiceValidateParameters(array('service' => $currentUri, 'ticket' => $request->getQuery('ticket'))); // Validate the ticket $result = $authService->authenticate(); if (!$result->isValid()) { $response->setRedirect($adapter->createLoginUri()); } // Assume the user just got here } else { $response->setRedirect($adapter->createLoginUri()); } } }
/** * routeShutdown * 在 路由器 完成请求的路由后被调用 * @param Zend_Controller_Request_Abstract $request * @return void */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { /** * 检测请求的Content-type类型 */ $pathinfo = $request->getPathInfo(); if (!empty($pathinfo)) { if ($extension = pathinfo($pathinfo, PATHINFO_EXTENSION)) { if (preg_match('/^[-a-z0-9]+$/i', $extension)) { $request->setParam(static::KEY_EXT, strtolower($extension)); } } } /** * 检测是否支持json响应 */ if ($request->getParam(static::KEY_EXT) == '') { $accept = $request->getServer('HTTP_ACCEPT'); if (!empty($accept)) { if (strpos($accept, 'json') !== false) { $request->setParam(static::KEY_EXT, 'json'); } } } /** * 格式化请求目标信息,不允许[-a-zA-Z0-9]以外的字符 */ $pattern = '/[^-a-zA-Z0-9].*/'; $request->setModuleName(preg_replace($pattern, '', $request->getModuleName())); $request->setControllerName(preg_replace($pattern, '', $request->getControllerName())); $request->setActionName(preg_replace($pattern, '', $request->getActionName())); }
/** * routeStartup * 在 路由器 完成请求的路由前被调用 * * @param Zend_Controller_Request_Abstract $request * @return void */ public function routeStartup(Zend_Controller_Request_Abstract $request) { // Do nothing... return; $hostname = $request->getHttpHost(); $pathinfo = $request->getPathInfo(); /** * 根据二级域名检测请求的模块 */ if (!empty($hostname)) { $segments = explode('.', $hostname); if (isset($segments[2])) { $segmentNum = count($segments); $rootDomain = $segments[$segmentNum - 2] . '.' . $segments[$segmentNum - 1]; if ($rootDomain === parse_url(URL_FTT, PHP_URL_HOST)) { $subDomain2 = $segments[$segmentNum - 3]; if (array_key_exists($subDomain2, static::$_subDomain2ModuleMap)) { $module = static::$_subDomain2ModuleMap[$subDomain2]; $hostel = explode('/', trim($pathinfo, '/')); $hostel = trim(array_shift($hostel)); if ($hostel != '') { $this->getResponse()->setRedirect(URL_FTT . '/' . $module . '/?' . static::KEY_INN . '=' . $hostel)->sendResponse(); exit; } } } } } }
/** * Sets the application locale and translation based on the locale param, if * one is not provided it defaults to english * * @param Zend_Controller_Request_Abstract $request * @return Void */ public function routeShutdown(Zend_Controller_Request_Abstract $request) { $config = Zend_Registry::get('config'); $frontController = Zend_Controller_Front::getInstance(); $params = $request->getParams(); $registry = Zend_Registry::getInstance(); // Steps setting the locale. // 1. Default language is set in config // 2. TLD in host header // 3. Locale params specified in request $locale = $registry->get('Zend_Locale'); // Check host header TLD. $tld = preg_replace('/^.*\\./', '', $request->getHeader('Host')); // Provide a list of tld's and their corresponding default languages $tldLocales = $frontController->getParam('tldLocales'); if (is_array($tldLocales) && array_key_exists($tld, $tldLocales)) { // The TLD in the request matches one of our specified TLD -> Locales $locale->setLocale(strtolower($tldLocales[$tld])); } elseif (isset($params['locale'])) { // There is a locale specified in the request params. $locale->setLocale(strtolower($params['locale'])); } // Now that our locale is set, let's check which language has been selected // and try to load a translation file for it. $language = $locale->getLanguage(); $translate = Garp_I18n::getTranslateByLocale($locale); Zend_Registry::set('Zend_Translate', $translate); Zend_Form::setDefaultTranslator($translate); if (!$config->resources->router->locale->enabled) { return; } $path = '/' . ltrim($request->getPathInfo(), '/\\'); // If the language is in the path, then we will want to set the baseUrl // to the specified language. $langIsInUrl = preg_match('/^\\/' . $language . '\\/?/', $path); $uiDefaultLangIsInUrl = false; $uiDefaultLanguage = false; if (isset($config->resources->locale->uiDefault)) { $uiDefaultLanguage = $config->resources->locale->uiDefault; $uiDefaultLangIsInUrl = preg_match('/^\\/' . $uiDefaultLanguage . '\\/?/', $path); } if ($langIsInUrl || $uiDefaultLangIsInUrl) { if ($uiDefaultLangIsInUrl) { $frontController->setBaseUrl($frontController->getBaseUrl() . '/' . $uiDefaultLanguage); } else { $frontController->setBaseUrl($frontController->getBaseUrl() . '/' . $language); } } elseif (!empty($config->resources->router->locale->enabled) && $config->resources->router->locale->enabled) { $redirectUrl = '/' . $language . $path; if ($frontController->getRouter()->getCurrentRouteName() === 'admin' && !empty($config->resources->locale->adminDefault)) { $adminDefaultLanguage = $config->resources->locale->adminDefault; $redirectUrl = '/' . $adminDefaultLanguage . $path; } elseif ($uiDefaultLanguage) { $redirectUrl = '/' . $uiDefaultLanguage . $path; } $this->getResponse()->setRedirect($redirectUrl, 301); } }
public function routeStartup(Zend_Controller_Request_Abstract $req) { $this->_time = microtime(true); if ($req instanceof Zend_Controller_Request_Http) { $this->_method = $req->getMethod(); $this->_path = $req->getPathInfo(); } $this->_request = $req; }
/** * @param \Zend_Controller_Request_Abstract $request */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default // error page, because this is more resource-intensive than exiting right here $found = false; foreach (self::$files as $pattern) { if (preg_match($pattern, $request->getPathInfo())) { $found = true; break; } } if ($found) { if ($request->getPathInfo() == "/robots.txt") { // check for site try { $domain = Tool::getHostname(); $site = Site::getByDomain($domain); } catch (\Exception $e) { } $siteSuffix = ""; if ($site instanceof Site) { $siteSuffix = "-" . $site->getId(); } // send correct headers header("Content-Type: text/plain; charset=utf8"); while (@ob_end_flush()) { } // check for configured robots.txt in pimcore $robotsPath = PIMCORE_CONFIGURATION_DIRECTORY . "/robots" . $siteSuffix . ".txt"; if (is_file($robotsPath)) { readfile($robotsPath); } else { echo "User-agent: *\nDisallow:"; // default behavior } exit; } // if no other rule matches, exit anyway with a 404, to prevent the error page to be shown header('HTTP/1.1 404 Not Found'); echo "HTTP/1.1 404 Not Found\nFiltered by common files filter"; exit; } }
/** * Check the request to see if it is secure. If it isn't * rebuild a secure url, redirect and exit. * * @param Zend_Controller_Request_Abstract $request * @return void * @author Travis Boudreaux */ protected function _secureUrl(Zend_Controller_Request_Abstract $request) { $server = $request->getServer(); $hostname = $server['HTTP_HOST']; if (!$request->isSecure()) { //url scheme is not secure so we rebuild url with secureScheme $url = Zend_Controller_Request_Http::SCHEME_HTTPS . "://" . $hostname . $request->getPathInfo(); $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->setGoToUrl($url); $redirector->redirectAndExit(); } }
protected function _forwardLogin(Zend_Controller_Request_Abstract $request) { $request->setModuleName('kwf_controller_action_user'); $request->setControllerName('login'); $request->setDispatched(false); if (substr($request->getActionName(), 0, 4) == 'json') { $request->setActionName('json-login'); } else { $params = array('location' => $request->getBaseUrl() . '/' . ltrim($request->getPathInfo(), '/')); $request->setParams($params); $request->setActionName('index'); } }
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { $response = $this->getResponse(); $url = parse_url($_SERVER['REQUEST_URI']); $res = DOMAIN_PATH . $request->getPathInfo(); if ($request->controller == 'categories' & $request->action == 'catlist' || $request->controller == 'search' & $request->action == 'beginsearch') { $s_url = DOMAIN_PATH . $url['path'] . (isset($url['query']) ? '?' . $url['query'] : ''); $n_url = glob_makeUrlFromCookie(glob_makeBaseUrl(array('search', 'extended'))); // echo $n_url.'-'.$s_url; exit; if ($s_url !== $n_url) { $response->setRedirect($n_url); } } }
/** * Called before an action is dispatched by Zend_Controller_Dispatcher. * * This callback allows for proxy or filter behavior. By altering the * request and resetting its dispatched flag (via * {@link Zend_Controller_Request_Abstract::setDispatched() setDispatched(false)}), * the current action may be skipped. * * @param Zend_Controller_Request_Abstract $request * @return void */ public function preDispatch(Zend_Controller_Request_Abstract $request) { // reset role & resource Zend_Registry::set('Role', 'guest'); Zend_Registry::set('Resource', ''); // check if ErrorHandler wasn't fired if ($request->getParam('error_handler')) { return; } $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $pathInfo = $request->getPathInfo(); $allow = false; if ($this->_auth->hasIdentity()) { $userId = $this->_auth->getIdentity(); $roleId = $this->_auth->getRoleId(); $rolesList = $this->_em->find('Roles', $roleId); $roleName = $rolesList->getRoleName(); $role = new Zend_Acl_Role($roleName); } else { $roleName = 'guest'; $role = new Zend_Acl_Role($roleName); } $resource = $action == '' ? trim($controller) . '/index' : trim($controller) . '/' . trim($action); $resource = $module == 'default' ? $resource : $module . "/" . $resource; // on main page resource might be empty if ($resource == '') { $resource = 'index/index'; } // if resource not exist in db then check permission for controller if (!$this->_acl->has($resource) && $action != '') { $resource = trim($controller); } // check if user is allowed to see the page $allow = $this->_acl->isAllowed($role, $resource); if ($allow == false && $this->_auth->hasIdentity()) { // user logged in but denied permission $request->setModuleName('default'); $request->setControllerName('error'); $request->setActionName('forbidden'); /* $this->_response->setHeader('Content-type', 'text/html'); $this->_response->setHttpResponseCode(403); $this->_response->setBody('<h1>403 - Forbidden</h1>'); $this->_response->sendResponse(); */ } Zend_Registry::set('Role', $role); Zend_Registry::set('Resource', $resource); }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (($curRouteName = $this->_currentRoute) != null) { $route = $this->getRoute($curRouteName); if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $request->getPathInfo(); } else { $match = $request; } if ($params = $route->match($match)) { $this->_setRequestParams($request, $params); return $request; } } return parent::route($request); }
/** * Start caching * * Determine if we have a cache hit. If so, return the response; else, * start caching. * * @param Zend_Controller_Request_Abstract $request * @return void */ public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { if (!$request->isGet()) { self::$_disableCache = true; return; } $path = $request->getPathInfo(); $this->_key = md5($path); $response = Zrt_Cache::load($this->_key); if (false !== $response) { $response->sendResponse(); if (!$this->_suppressExit) { exit; } } }
public function preDispatch(Zend_Controller_Request_Abstract $request) { $controller = strtolower($request->getControllerName()); $action = strtolower($request->getActionName()); $route = $controller . '/' . $action; if (in_array($route, $this->_whitelist)) { return; } $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { return; } $request->setDispatched(false); $request->setControllerName('user'); $request->setActionName('login'); $request->setParam('next_uri', $request->getPathInfo()); }
public function preDispatch(Zend_Controller_Request_Abstract $request) { $controller = strtolower($request->getControllerName()); $action = strtolower($request->getActionName()); $route = $controller . '/' . $action; if (in_array($route, self::$_whitelist)) { return; } $auth = Infra_AuthHelper::getAuthInstance(); if ($auth->hasIdentity()) { return; } $request->setDispatched(false); $request->setControllerName(self::$defaultController); $request->setActionName(self::$defaultAction); $request->setParam('next_uri', $request->getPathInfo()); }
public function routeShutdown(Zend_Controller_Request_Abstract $request) { $session = new Zend_Session_Namespace('mobile'); if ($session->mobile) { return; } $module = $request->getModuleName(); $controlelr = $request->getControllerName(); $action = $request->getActionName(); // global_page_socialstore-product-index $bodyId = 'global_page_' . $module . '-' . $controlelr . '-' . $action; $path = $request->getPathInfo(); $result = Engine_Api::_()->yntour()->getTour($path, $bodyId); $enabled = isset($result['enable']) ? $result['enable'] : false; Zend_Registry::set('YNTOUR_ENABLED', $enabled); $view = Zend_Registry::get('Zend_View'); $view->headScript()->appendScript('en4.yntour.init(' . Zend_Json::encode($result) . ')'); }
/** * Parse PathInfo in the orginal request and then alter the original request * based on the valid RESTful API URI format: * /rest[/{moduleName}]/{controllerName}[/{methodName}][/{Id}] * note: [] means optinal parts. */ private function handlePathInfo(Zend_Controller_Request_Abstract $request) { $tokens = preg_split('@/@', $request->getPathInfo(), null, PREG_SPLIT_NO_EMPTY); array_shift($tokens); // remove 'rest' prefix if (!empty($tokens)) { if (in_array($tokens[0], Zend_Registry::get('modulesHaveApi'))) { $apiModuleName = 'api' . array_shift($tokens); $controllerName = array_shift($tokens); $request->setParam('module', $apiModuleName); $request->setParam('controller', $controllerName); $request->setModuleName($apiModuleName); $request->setControllerName($controllerName); // remove redundant parameter generated by Zend routing $request->setParam($controllerName, null); } else { array_shift($tokens); // remove controllerName } // handle method if (!empty($tokens) && !is_numeric($tokens[0])) { $methodName = array_shift($tokens); $request->setParam('method', $methodName); // remove redundant parameter generated by Zend routing $request->setParam($methodName, null); $request->setParam('id', null); } // forward to index action if id is not provided $action = $request->getActionName(); if (empty($tokens) && ($action == 'get' || $action == 'index')) { $request->setActionName('index'); } elseif (empty($tokens) && ($action == 'post' || $action == 'put')) { $request->setActionName('post'); } elseif (!empty($tokens) && is_numeric($tokens[0])) { $request->setParam('id', array_shift($tokens)); } else { $this->_response->setHttpResponseCode(400); // 400 Bad Request throw new Exception('The web API ' . $request->getPathInfo() . ' is not supported.', 400); } } }
/** * Called before Zend_Controller_Front begins evaluating the * request against its routes. * * @param Zend_Controller_Request_Abstract $request * @return void */ public function routeStartup(Zend_Controller_Request_Abstract $request) { $frontController = Zend_Controller_Front::getInstance(); // Request keys $moduleKey = $request->getModuleKey(); $controllerKey = $request->getControllerKey(); $actionKey = $request->getActionKey(); // Defaults $moduleName = $frontController->getDefaultModule(); $controllerName = $frontController->getDefaultControllerName(); $actionName = $frontController->getDefaultAction(); // Set a url path $module = $request->getQuery($moduleKey, $moduleName); $controller = $request->getQuery($controllerKey, $controllerName); $action = $request->getQuery($actionKey, $actionName); // Assemble if ($request->getPathInfo() == '/') { $modulePart = $module == $moduleName ? $module : '/' . $module; $controllerPart = $controller == $controllerName && $action == $actionName ? '' : '/' . $controller; $actionPart = $action == $actionName && $controller ? '' : '/' . $action; $request->setPathInfo($modulePart . $controllerPart . $actionPart); } }
/** * @param \Zend_Controller_Request_Abstract $request */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { if (preg_match("@^/qr~-~code/([a-zA-Z0-9_\\-]+)@", $request->getPathInfo(), $matches)) { if (array_key_exists(1, $matches) && !empty($matches[1])) { $code = Tool\Qrcode\Config::getByName($matches[1]); if ($code) { $url = $code->getUrl(); if ($code->getGoogleAnalytics()) { $glue = "?"; if (strpos($url, "?")) { $glue = "&"; } $url .= $glue; $url .= "utm_source=Mobile&utm_medium=QR-Code&utm_campaign=" . $code->getName(); } header("Location: " . $url, true, 302); exit; } else { \Logger::error("called an QR code but '" . $matches[1] . " is not a code in the system."); } } } }
public function preDispatch(Zend_Controller_Request_Abstract $request) { $this->_cache = Zend_Registry::get('cache'); // La la cac phuong thuc khac get() no se khong lay tu content tu cache ra if (!$request->isGet()) { self::$doNotCache = true; return; } $module = $request->getModuleName(); $controller = $request->getControllerName(); $action = $request->getActionName(); $path = $request->getPathInfo(); // co loi o day , xem link de biet cach sua $this->_key = md5($path); $this->_keyTags = array($module, "{$module}_{$controller}", "{$module}_{$controller}_{$action}"); if (false !== ($data = $this->getCache())) { $response = $this->getResponse(); $response->setBody($data['default']); $response->sendResponse(); exit; } }
/** * @param \Zend_Controller_Request_Abstract $request */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { if (preg_match("@^/hybridauth/endpoint@", $request->getPathInfo(), $matches)) { \Pimcore\Tool\HybridAuth::process(); } }
/** * @param \Zend_Controller_Request_Abstract $request */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default // error page, because this is more resource-intensive than exiting right here if (preg_match("@^/website/var/tmp/image-thumbnails(.*)?/([0-9]+)/thumb__([a-zA-Z0-9_\\-]+)([^\\@]+)(\\@[0-9.]+x)?\\.([a-zA-Z]{2,5})@", $request->getPathInfo(), $matches)) { $assetId = $matches[2]; $thumbnailName = $matches[3]; $format = $matches[6]; if ($asset = Asset::getById($assetId)) { try { $page = 1; $thumbnailFile = null; $thumbnailConfig = null; $deferredConfigId = "thumb_" . $assetId . "__" . md5($request->getPathInfo()); if ($thumbnailConfigItem = TmpStore::get($deferredConfigId)) { $thumbnailConfig = $thumbnailConfigItem->getData(); TmpStore::delete($deferredConfigId); if (!$thumbnailConfig instanceof Asset\Image\Thumbnail\Config) { throw new \Exception("Deferred thumbnail config file doesn't contain a valid \\Asset\\Image\\Thumbnail\\Config object"); } $tmpPage = array_pop(explode("-", $thumbnailName)); if (is_numeric($tmpPage)) { $page = $tmpPage; } } else { //get thumbnail for e.g. pdf page thumb__document_pdfPage-5 if (preg_match("|document_(.*)\\-(\\d+)\$|", $thumbnailName, $matchesThumbs)) { $thumbnailName = $matchesThumbs[1]; $page = (int) $matchesThumbs[2]; } // just check if the thumbnail exists -> throws exception otherwise $thumbnailConfig = Asset\Image\Thumbnail\Config::getByName($thumbnailName); } if ($asset instanceof Asset\Document) { $thumbnailConfig->setName(preg_replace("/\\-[\\d]+/", "", $thumbnailConfig->getName())); $thumbnailConfig->setName(str_replace("document_", "", $thumbnailConfig->getName())); $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $asset->getImageThumbnail($thumbnailConfig, $page); } else { if ($asset instanceof Asset\Image) { //check if high res image is called if (array_key_exists(5, $matches)) { $highResFactor = (double) str_replace(array("@", "x"), "", $matches[5]); $thumbnailConfig->setHighResolution($highResFactor); } $thumbnailFile = PIMCORE_DOCUMENT_ROOT . $asset->getThumbnail($thumbnailConfig); } } if ($thumbnailFile && file_exists($thumbnailFile)) { $fileExtension = \Pimcore\File::getFileExtension($thumbnailFile); if (in_array($fileExtension, array("gif", "jpeg", "jpeg", "png", "pjpeg"))) { header("Content-Type: image/" . $fileExtension, true); } else { header("Content-Type: " . $asset->getMimetype(), true); } header("Content-Length: " . filesize($thumbnailFile), true); while (@ob_end_flush()) { } flush(); readfile($thumbnailFile); exit; } } catch (\Exception $e) { // nothing to do \Logger::error("Thumbnail with name '" . $thumbnailName . "' doesn't exist"); } } } }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { throw Zend::exception('Zend_Controller_Router_Exception', 'Zend_Controller_RewriteRouter requires a Zend_Controller_Request_Http-based request object'); } if ($this->useDefaultRoutes) { $this->addDefaultRoutes(); } $pathInfo = $request->getPathInfo(); /** Find the matching route */ foreach (array_reverse($this->_routes) as $name => $route) { if ($params = $route->match($pathInfo)) { foreach ($params as $param => $value) { $request->setParam($param, $value); } $this->_currentRoute = $name; break; } } return $request; }
/** * @param \Zend_Controller_Request_Abstract $request */ public function routeStartup(\Zend_Controller_Request_Abstract $request) { // this is a filter which checks for common used files (by browser, crawlers, ...) and prevent the default // error page, because this is more resource-intensive than exiting right here if (preg_match("@/image-thumbnails(.*)?/([0-9]+)/thumb__([a-zA-Z0-9_\\-]+)([^\\@]+)(\\@[0-9.]+x)?\\.([a-zA-Z]{2,5})@", rawurldecode($request->getPathInfo()), $matches)) { $assetId = $matches[2]; $thumbnailName = $matches[3]; if ($asset = Asset::getById($assetId)) { try { $page = 1; // default $thumbnailFile = null; $thumbnailConfig = null; //get thumbnail for e.g. pdf page thumb__document_pdfPage-5 if (preg_match("|document_(.*)\\-(\\d+)\$|", $thumbnailName, $matchesThumbs)) { $thumbnailName = $matchesThumbs[1]; $page = (int) $matchesThumbs[2]; } // just check if the thumbnail exists -> throws exception otherwise $thumbnailConfig = Asset\Image\Thumbnail\Config::getByName($thumbnailName); if (!$thumbnailConfig) { // check if there's an item in the TmpStore $deferredConfigId = "thumb_" . $assetId . "__" . md5($matches[0]); if ($thumbnailConfigItem = TmpStore::get($deferredConfigId)) { $thumbnailConfig = $thumbnailConfigItem->getData(); TmpStore::delete($deferredConfigId); if (!$thumbnailConfig instanceof Asset\Image\Thumbnail\Config) { throw new \Exception("Deferred thumbnail config file doesn't contain a valid \\Asset\\Image\\Thumbnail\\Config object"); } } } if (!$thumbnailConfig) { throw new \Exception("Thumbnail '" . $thumbnailName . "' file doesn't exists"); } if ($asset instanceof Asset\Document) { $thumbnailConfig->setName(preg_replace("/\\-[\\d]+/", "", $thumbnailConfig->getName())); $thumbnailConfig->setName(str_replace("document_", "", $thumbnailConfig->getName())); $thumbnailFile = $asset->getImageThumbnail($thumbnailConfig, $page)->getFileSystemPath(); } elseif ($asset instanceof Asset\Image) { //check if high res image is called if (array_key_exists(5, $matches)) { $highResFactor = (double) str_replace(["@", "x"], "", $matches[5]); $thumbnailConfig->setHighResolution($highResFactor); } // check if a media query thumbnail was requested if (preg_match("#~\\-~([\\d]+w)#", $matches[4], $mediaQueryResult)) { $thumbnailConfig->selectMedia($mediaQueryResult[1]); } $thumbnailFile = $asset->getThumbnail($thumbnailConfig)->getFileSystemPath(); } if ($thumbnailFile && file_exists($thumbnailFile)) { // set appropriate caching headers // see also: https://github.com/pimcore/pimcore/blob/1931860f0aea27de57e79313b2eb212dcf69ef13/.htaccess#L86-L86 $lifetime = 86400 * 7; // 1 week lifetime, same as direct delivery in .htaccess header("Cache-Control: public, max-age=" . $lifetime); header("Expires: " . date("D, d M Y H:i:s T", time() + $lifetime)); $fileExtension = \Pimcore\File::getFileExtension($thumbnailFile); if (in_array($fileExtension, ["gif", "jpeg", "jpeg", "png", "pjpeg"])) { header("Content-Type: image/" . $fileExtension, true); } else { header("Content-Type: " . $asset->getMimetype(), true); } header("Content-Length: " . filesize($thumbnailFile), true); while (@ob_end_flush()) { } flush(); readfile($thumbnailFile); exit; } } catch (\Exception $e) { // nothing to do Logger::error("Thumbnail with name '" . $thumbnailName . "' doesn't exist"); } } } }
/** * Start caching * * Determine if we have a cache hit. If so, return the response; else, * start caching. * * @param Zend_Controller_Request_Abstract $request * @return void */ public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { // echo "<pre>"; // print_r($request->getRequestUri()); // echo "</pre>"; // exit(); if (!$request->isGet()) { self::$doNotCache = true; return; } $path = $request->getPathInfo(); // co loi o day , xem link de biet cach sua $this->_key = md5($path); if (false !== ($response = $this->getCache())) { $response->sendResponse(); exit; } }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { require_once 'Zend/Controller/Router/Exception.php'; throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object'); } if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } $pathInfo = $request->getPathInfo(); /** Find the matching route */ foreach (array_reverse($this->_routes) as $name => $route) { if ($params = $route->match($pathInfo)) { $this->_setRequestParams($request, $params); $this->_currentRoute = $name; break; } } return $request; }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { require_once 'Zend/Controller/Router/Exception.php'; throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object'); } if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } // Find the matching route foreach (array_reverse($this->_routes) as $name => $route) { // TODO: Should be an interface method. Hack for 1.0 BC if (method_exists($route, 'isAbstract') && $route->isAbstract()) { continue; } // TODO: Should be an interface method. Hack for 1.0 BC if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $request->getPathInfo(); } else { $match = $request; } if ($params = $route->match($match)) { $this->_setRequestParams($request, $params); $this->_currentRoute = $name; break; } } return $request; }
/** * Find a matching route to the current PATH_INFO and inject * returning values to the Request object. * * @param Zend_Controller_Request_Abstract $request * @throws Zend_Controller_Router_Exception * @return Zend_Controller_Request_Abstract Request object */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { throw new Zend_Controller_Router_Exception('Zend_Controller_Router_Rewrite requires a Zend_Controller_Request_Http-based request object'); } if ($this->_useDefaultRoutes) { $this->addDefaultRoutes(); } // Find the matching route $routeMatched = false; foreach (array_reverse($this->_routes, true) as $name => $route) { // TODO: Should be an interface method. Hack for 1.0 BC if (method_exists($route, 'isAbstract') && $route->isAbstract()) { continue; } // TODO: Should be an interface method. Hack for 1.0 BC if (!method_exists($route, 'getVersion') || $route->getVersion() == 1) { $match = $request->getPathInfo(); } else { $match = $request; } if ($params = $route->match($match)) { $this->_setRequestParams($request, $params); $this->_currentRoute = $name; $routeMatched = true; break; } } if (!$routeMatched) { throw new Zend_Controller_Router_Exception('No route matched the request', 404); } if ($this->_useCurrentParamsAsGlobal) { $params = $request->getParams(); foreach ($params as $param => $value) { $this->setGlobalParam($param, $value); } } return $request; }
/** * Route a request * * Routes requests of the format /controller/action by default (action may * be omitted). Additional parameters may be specified as key/value pairs * separated by the directory separator: * /controller/action/key/value/key/value. * * To specify a module to use (basically, subdirectory) when routing the * request, set the 'useModules' parameter via the front controller or * {@link setParam()}: $router->setParam('useModules', true) * * @param Zend_Controller_Request_Abstract $request * @return void */ public function route(Zend_Controller_Request_Abstract $request) { if (!$request instanceof Zend_Controller_Request_Http) { throw Zend::exception('Zend_Controller_Router_Exception', 'Zend_Controller_Router requires a Zend_Controller_Request_Http-based request object'); } $pathInfo = $request->getPathInfo(); $pathSegs = explode('/', trim($pathInfo, '/')); /** * Retrieve module if useModules is set in object */ $useModules = $this->getParam('useModules'); if (!empty($useModules)) { if (isset($pathSegs[0]) && !empty($pathSegs[0])) { $module = array_shift($pathSegs); } } /** * Get controller and action from request * Attempt to get from path_info; controller is first item, action * second */ if (isset($pathSegs[0]) && !empty($pathSegs[0])) { $controller = array_shift($pathSegs); } if (isset($pathSegs[0]) && !empty($pathSegs[0])) { $action = array_shift($pathSegs); } /** * Any optional parameters after the action are stored in * an array of key/value pairs: * * http://www.zend.com/controller-name/action-name/param-1/3/param-2/7 * * $params = array(2) { * ["param-1"]=> string(1) "3" * ["param-2"]=> string(1) "7" * } */ $params = array(); $segs = count($pathSegs); if (0 < $segs) { for ($i = 0; $i < $segs; $i = $i + 2) { $key = urldecode($pathSegs[$i]); $value = isset($pathSegs[$i + 1]) ? urldecode($pathSegs[$i + 1]) : null; $params[$key] = $value; } } $request->setParams($params); /** * Set module, controller and action, now that params are set */ if (isset($module)) { $request->setParam('module', urldecode($module)); } if (isset($controller)) { $request->setControllerName(urldecode($controller)); } if (isset($action)) { $request->setActionName(urldecode($action)); } return $request; }