<?php
Director::addRules(2, array(
'$URLLocale/$URLSegment/$Action/$ID/$OtherID' => 'TranslatedNestedController'
));
class TranslatedNestedController extends ModelAsController {
public $locale;
public $defaultLocale = "en_GB";
public function init() {
if(!Translatable::is_enabled()) FormResponse::add('statusMessage("'._t('TranslatedModelAsController','Please enable Translatable').'","bad");');
$this->setLocale($this->request->param('URLLocale'));
parent::init();
}
public function setLocale($locale) {
Translatable::set_current_locale($locale);
$this->locale = $locale;
}
public function convertRegionToLocale($region) {
return (key_exists($region, $this->region_locale_mapping)) ? $this->region_locale_mapping[$region] : $this->defaultLocale;
}
public function getNestedController() {
$request = $this->request;
$URLSegment = ($request->param('URLSegment')) ? $request->param('URLSegment') : "home";
if(!$URLSegment) {
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
}
$sitetree = DataObject::get_one(
'SiteTree',
sprintf(
'"URLSegment" = \'%s\' %s',
Convert::raw2sql($URLSegment),
(SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null)
)
);
if(!$sitetree) {
$redirect = self::find_old_page($URLSegment);
if($redirect = self::find_old_page($URLSegment)) {
$params = $request->getVars();
if(isset($params['url'])) unset($params['url']);
$this->response = new SS_HTTPResponse();
$this->response->redirect(
Controller::join_links(
$redirect->Link(
Controller::join_links(
$request->param('Action'),
$request->param('ID'),
$request->param('OtherID')
)
),
($params) ? '?' . http_build_query($params) : null
),
301
);
return $this->response;
}
if($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
}
if($sitetree->Locale) Translatable::set_current_locale($sitetree->Locale);
if(isset($_REQUEST['debug'])) {
Debug::message("Using record #$sitetree->ID of type $sitetree->class with link {$sitetree->Link()}");
}
return self::controller_for($sitetree, $this->request->param('Action'));
}
}
?>