/**
  * @uses ModelAsController::getNestedController()
  * @param SS_HTTPRequest $request
  * @param DataModel $model
  * @return SS_HTTPResponse
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     // Check Translatable dependency
     if (!class_exists('Translatable') || !SiteTree::has_extension('Translatable') && !SiteTree::has_extension('LanguagePrefixTranslatable')) {
         throw new Exception('Dependency error: the LanguagePrefix module expects the Translatable module.');
     }
     $disablePrefixForDefaultLang = Config::inst()->get('prefixconfig', 'disable_prefix_for_default_lang');
     $firstSegment = $request->param('URLSegment');
     if ($firstSegment) {
         $prefixUsed = $this->setLocale($firstSegment);
         $defaultLocale = Translatable::default_locale();
         $isDefaultLocale = $this->locale == $defaultLocale;
         if ($prefixUsed) {
             if ($isDefaultLocale && $disablePrefixForDefaultLang) {
                 $url = substr($request->getURL(true), strlen($firstSegment));
                 return $this->redirect($url, 301);
             } else {
                 $request->shiftAllParams();
                 $request->shift(1);
             }
         } else {
             /*
              *  if no prefix is used but $disablePrefixForDefaultLang
              *  is set, we go on like nothing happened. Otherwise a
              *  404 is generated. @todo: maybe we should redirect
              *  pages that do actually exist, because this is a bit
              *  harsh?
              */
             //if (!$isDefaultLocale || !$disablePrefixForDefaultLang) {
             //	return $this->showPageNotFound();
             //}
         }
     }
     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.
  *
  * @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;
 }
 /**
  * Allows a user to view the details of their registration.
  *
  * @param SS_HTTPRequest $request
  * @return EventRegistrationDetailsController
  */
 public function registration($request)
 {
     $id = $request->param('ID');
     if (!ctype_digit($id)) {
         $this->httpError(404);
     }
     $rego = EventRegistration::get()->byID($id);
     if (!$rego || $rego->Time()->EventID != $this->ID) {
         $this->httpError(404);
     }
     $request->shift();
     $request->shiftAllParams();
     return new EventRegistrationDetailsController($this, $rego);
 }
 /**
  * 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;
 }
 /**
  * Allows a user to view the details of their registration.
  *
  * @param  SS_HTTPRequest $request
  * @return EventRegistrationDetailsController
  */
 public function registration($request)
 {
     $id = $request->param('ID');
     $rego = DataObject::get_by_id('EventRegistration', (int) $id);
     if (!$rego || $rego->Time()->EventID != $this->ID) {
         $this->httpError(404);
     }
     $request->shift();
     $request->shiftAllParams();
     return new EventRegistrationDetailsController($this, $rego);
 }
 /**
  * @param SS_HTTPRequest $request
  * @param $model
  *
  * @return HTMLText|SS_HTTPResponse
  */
 protected function handleAction($request, $model)
 {
     /**
      * We return nested controllers, so the parsed URL params need
      * to be discarded for the subsequent controllers to work
      */
     $request->shiftAllParams();
     return parent::handleAction($request, $model);
 }