/** * Perform routing. * * @param Curry_Request $request * @return Page|bool */ public function route(Curry_Request $request) { $p = explode('?', $request->getUri(), 2); $parts = explode("/", $p[0]); $query = isset($p[1]) ? "?" . $p[1] : ''; $url = ""; while (count($parts)) { $model = self::findPageModel($url ? $url : '/'); if ($model) { $slug = array_shift($parts); $remaining = join("/", $parts); $params = self::getParamFromSlug($model, $slug); if ($params) { // add params to request foreach ($params as $name => $value) { $request->setParam('get', $name, $value); } $query .= (strlen($query) ? '&' : '?') . http_build_query($params); // rebuild uri $request->setUri($url . $remaining . $query); // continue routing return true; } // put slug back and continue searching array_unshift($parts, $slug); } $url .= array_shift($parts) . "/"; } return null; }
/** * Perform routing. * * @param Curry_Request $request * @return Page|bool */ public function route(Curry_Request $request) { if (preg_match($this->regexp, $request->getUri(), $m)) { foreach ($m as $k => $v) { if (is_string($k)) { $request->setParam('get', $k, $v); } } $request->setUri($this->target); return true; } return false; }
/** * Perform routing. * * @param Curry_Request $request * @return Page|bool */ public function route(Curry_Request $request) { $uri = $request->getUri(); $qpos = strpos($uri, '?'); if ($qpos !== false) { $uri = substr($uri, 0, $qpos); } if (substr($uri, 0, strlen($this->base)) == $this->base && strlen($uri) > strlen($this->base)) { $remaining = substr($uri, strlen($this->base)); // remove trailing slash if (substr($remaining, -1) == '/') { $remaining = substr($remaining, 0, -1); } $request->setParam('get', $this->param, $remaining); $request->setUri($this->target); return true; } return false; }
/** * Perform routing. * * @param Curry_Request $request * @return Page|bool */ public function route(Curry_Request $request) { $uri = $request->getUri(); if (substr($uri, 0, strlen($this->base)) == $this->base) { $remaining = substr($uri, strlen($this->base)); $name = null; foreach (explode('/', $remaining) as $param) { if ($name) { $request->setParam('get', $name, $param); $name = null; } else { $name = $param; } } $request->setUri($this->target); return true; } return false; }
/** * Render the specified page revision. * * @param PageRevision $pageRevision * @param Curry_Request $request * @param array $vars * @param array $options */ protected function render(PageRevision $pageRevision, Curry_Request $request, array $vars, array $options) { Curry_Core::log('Showing page ' . $pageRevision->getPage()->getName() . ' (PageRevisionId: ' . $pageRevision->getPageRevisionId() . ')', Zend_Log::NOTICE); $time = microtime(true); $queries = Curry_Propel::getQueryCount(); $cacheName = __CLASS__ . '_Page_' . md5($request->getUri()); $cacheLifetime = $pageRevision->getPage()->getCacheLifetime(); $doCache = $request->getMethod() === 'GET' && $cacheLifetime !== 0; if ($doCache) { ob_start(); } $generator = self::createPageGenerator($pageRevision, $request); $generator->display($vars, $options); if ($doCache) { $cache = array('page_id' => $pageRevision->getPageId(), 'page_revision_id' => $pageRevision->getPageRevisionId(), 'headers' => headers_list(), 'content' => ob_get_flush()); Curry_Core::$cache->save($cache, $cacheName, array(), $cacheLifetime < 0 ? false : $cacheLifetime); } if (Curry_Core::$config->curry->updateTranslationStrings) { Curry_Language::updateLanguageStrings(); } $time = microtime(true) - $time; $queries = $queries !== null ? Curry_Propel::getQueryCount() - $queries : null; Curry_Core::triggerHook('Curry_Application::render', $pageRevision->getPageId(), $pageRevision->getPageRevisionId(), $time, $queries); }