function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { $response = parent::handleRequest($request, $model); $title = $this->Title(); if (!$response->getHeader('X-Controller')) { $response->addHeader('X-Controller', $this->class); } if (!$response->getHeader('X-Title')) { $response->addHeader('X-Title', $title); } return $response; }
static function run() { $instance = new Controller(); $instance->init(); $instance->handleRequest(); }
/** * This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to * fall over to a child controller in order to provide functionality for nested URLs. * * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request) { $child = null; $action = $request->param('Action'); // If nested URLs are enabled, and there is no action handler for the current request then attempt to pass // control to a child controller. This allows for the creation of chains of controllers which correspond to a // nested URL. if ($action && SiteTree::nested_urls() && !$this->hasAction($action)) { // See ModelAdController->getNestedController() for similar logic Translatable::disable_locale_filter(); // look for a page with this URLSegment $child = DataObject::get_one('SiteTree', sprintf("\"ParentID\" = %s AND \"URLSegment\" = '%s'", $this->ID, Convert::raw2sql($action))); Translatable::enable_locale_filter(); // if we can't find a page with this URLSegment try to find one that used to have // that URLSegment but changed. See ModelAsController->getNestedController() for similiar logic. if (!$child) { $child = ModelAsController::find_old_page($action, $this->ID); if ($child) { $response = new SS_HTTPResponse(); $params = $request->getVars(); if (isset($params['url'])) { unset($params['url']); } $response->redirect(Controller::join_links($child->Link(Controller::join_links($request->param('ID'), $request->param('OtherID'))), $params ? '?' . http_build_query($params) : null), 301); return $response; } } } // we found a page with this URLSegment. if ($child) { $request->shiftAllParams(); $request->shift(); $response = ModelAsController::controller_for($child)->handleRequest($request); } else { // If a specific locale is requested, and it doesn't match the page found by URLSegment, // look for a translation and redirect (see #5001). Only happens on the last child in // a potentially nested URL chain. if ($request->getVar('locale') && $this->dataRecord && $this->dataRecord->Locale != $request->getVar('locale')) { $translation = $this->dataRecord->getTranslation($request->getVar('locale')); if ($translation) { $response = new SS_HTTPResponse(); $response->redirect($translation->Link(), 301); throw new SS_HTTPResponse_Exception($response); } } Director::set_current_page($this->data()); $response = parent::handleRequest($request); Director::set_current_page(null); } return $response; }
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { try { $response = parent::handleRequest($request, $model); } catch (ValidationException $e) { // Nicer presentation of model-level validation errors $msgs = _t('LeftAndMain.ValidationError', 'Validation error') . ': ' . $e->getMessage(); $e = new SS_HTTPResponse_Exception($msgs, 403); $e->getResponse()->addHeader('Content-Type', 'text/plain'); $e->getResponse()->addHeader('X-Status', rawurlencode($msgs)); throw $e; } $title = $this->Title(); if (!$response->getHeader('X-Controller')) { $response->addHeader('X-Controller', $this->class); } if (!$response->getHeader('X-Title')) { $response->addHeader('X-Title', urlencode($title)); } // Prevent clickjacking, see https://developer.mozilla.org/en-US/docs/HTTP/X-Frame-Options $this->response->addHeader('X-Frame-Options', 'SAMEORIGIN'); return $response; }
function handleRequest($request, DataModel $model) { $title = $this->Title(); $response = parent::handleRequest($request, $model); $response->addHeader('X-Controller', $this->class); $response->addHeader('X-Title', $title); return $response; }
public function handleRequest(SS_HTTPRequest $request, DataModel $model) { $this->request = $request; if (!$this->authenticate()) { return $this->permissionFailure(); } if (!$this->authorize()) { return $this->permissionFailure(); } $controller_class = $this->class ? $this->class : get_class($this); $url_handlers = Config::inst()->get($controller_class, 'url_handlers', Config::FIRST_SET); if ($url_handlers) { foreach ($url_handlers as $rule => $action) { if ($params = $request->match($rule)) { $res = $this->doBeforeFilter($action, $params); if ($res) { return $res; } break; } } } return parent::handleRequest($request, $model); }
/** * This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to * fall over to a child controller in order to provide functionality for nested URLs. * * @param SS_HTTPRequest $request * @param DataModel $model * @return SS_HTTPResponse * @throws SS_HTTPResponse_Exception */ public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) { $child = null; $action = $request->param('Action'); $this->setDataModel($model); // If nested URLs are enabled, and there is no action handler for the current request then attempt to pass // control to a child controller. This allows for the creation of chains of controllers which correspond to a // nested URL. if ($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) { // See ModelAdController->getNestedController() for similar logic if (class_exists('Translatable')) { Translatable::disable_locale_filter(); } // look for a page with this URLSegment $child = $this->model->SiteTree->filter(array('ParentID' => $this->ID, 'URLSegment' => rawurlencode($action)))->first(); if (class_exists('Translatable')) { Translatable::enable_locale_filter(); } } // we found a page with this URLSegment. if ($child) { $request->shiftAllParams(); $request->shift(); $response = ModelAsController::controller_for($child)->handleRequest($request, $model); } else { // If a specific locale is requested, and it doesn't match the page found by URLSegment, // look for a translation and redirect (see #5001). Only happens on the last child in // a potentially nested URL chain. if (class_exists('Translatable')) { if ($request->getVar('locale') && $this->dataRecord && $this->dataRecord->Locale != $request->getVar('locale')) { $translation = $this->dataRecord->getTranslation($request->getVar('locale')); if ($translation) { $response = new SS_HTTPResponse(); $response->redirect($translation->Link(), 301); throw new SS_HTTPResponse_Exception($response); } } } Director::set_current_page($this->data()); try { $response = parent::handleRequest($request, $model); Director::set_current_page(null); } catch (SS_HTTPResponse_Exception $e) { $this->popCurrent(); Director::set_current_page(null); throw $e; } } return $response; }
/** * Handle the url parsing for the documentation. In order to make this * user friendly this does some tricky things.. * * The urls which should work * / - index page * /en/sapphire - the index page of sapphire (shows versions) * /2.4/en/sapphire - the docs for 2.4 sapphire. * /2.4/en/sapphire/installation/ * * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request) { // Workaround for root routing, e.g. Director::addRules(10, array('$Action' => 'DocumentationViewer')) $this->Version = $request->param('Action') ? $request->param('Action') : $request->shift(); $this->Lang = $request->shift(); $this->ModuleName = $request->shift(); $this->Remaining = $request->shift(10); DocumentationService::load_automatic_registration(); if (isset($this->Version)) { // check to see if its a valid version. If its not a float then its not actually a version // its actually a language and it needs to change. So this means we support 2 structures // /2.4/en/sapphire/page and // /en/sapphire/page which is a link to the latest one if (!is_numeric($this->Version) && $this->Version != 'current') { array_unshift($this->Remaining, $this->ModuleName); // not numeric so /en/sapphire/folder/page if (isset($this->Lang) && $this->Lang) { $this->ModuleName = $this->Lang; } $this->Lang = $this->Version; $this->Version = null; } else { // if(!DocumentationService::is_registered_version($this->Version)) { // $this->httpError(404, 'The requested version could not be found.'); // } } } if (isset($this->Lang)) { // check to see if its a valid language // if(!DocumentationService::is_registered_language($this->Lang)) { // $this->httpError(404, 'The requested language could not be found.'); // } } else { $this->Lang = 'en'; } // 'current' version mapping $module = DocumentationService::is_registered_module($this->ModuleName, null, $this->Lang); if ($this->Version && $module) { $current = $module->getCurrentVersion(); if ($this->Version == 'current') { $this->Version = $current; } else { if ($current == $this->Version) { $this->Version = 'current'; $link = $this->Link($this->Remaining); $this->response = new SS_HTTPResponse(); $this->redirect($link, 301); // permanent redirect return $this->response; } } } return parent::handleRequest($request); }
public function handleRequest(SS_HTTPRequest $request, DataModel $model) { return parent::handleRequest($request, $model); }
public function handleRequest(SS_HTTPRequest $request) { try { return parent::handleRequest($request); } catch (ValidationException $e) { // Nicer presentation of model-level validation errors return $this->httpError(403, $e->getResult()->message()); } }
/** * Handle the url parsing for the documentation. In order to make this * user friendly this does some tricky things.. * * The urls which should work * / - index page * /en/sapphire - the index page of sapphire (shows versions) * /2.4/en/sapphire - the docs for 2.4 sapphire. * /2.4/en/sapphire/installation/ * * @return SS_HTTPResponse */ public function handleRequest(SS_HTTPRequest $request) { // if we submitted a form, let that pass if (!$request->isGET() || isset($_GET['action_results'])) { return parent::handleRequest($request); } $firstParam = $request->param('Action') ? $request->param('Action') : $request->shift(); $secondParam = $request->shift(); $thirdParam = $request->shift(); $this->Remaining = $request->shift(10); DocumentationService::load_automatic_registration(); // if no params passed at all then it's the homepage if (!$firstParam && !$secondParam && !$thirdParam) { return parent::handleRequest($request); } if ($firstParam) { // allow assets if ($firstParam == "assets") { return parent::handleRequest($request); } // check for permalinks if ($link = DocumentationPermalinks::map($firstParam)) { // the first param is a shortcode for a page so redirect the user to // the short code. $this->response = new SS_HTTPResponse(); $this->redirect($link, 301); // 301 permanent redirect return $this->response; } // check to see if the module is a valid module. If it isn't, then we // need to throw a 404. if (!DocumentationService::is_registered_entity($firstParam)) { return $this->throw404(); } $this->entity = $firstParam; $this->language = $secondParam; if (isset($thirdParam) && (is_numeric($thirdParam) || in_array($thirdParam, array('master', 'trunk')))) { $this->version = $thirdParam; } else { // current version so store one area para array_unshift($this->Remaining, $thirdParam); $this->version = false; } } // 'current' version mapping $entity = DocumentationService::is_registered_entity($this->entity, null, $this->getLang()); if ($entity) { $current = $entity->getStableVersion(); $version = $this->getVersion(); if (!$version) { $this->version = $current; } // Check if page exists, otherwise return 404 if (!$this->locationExists()) { return $this->throw404(); } return parent::handleRequest($request); } return $this->throw404(); }