Skip to content

Commit

Permalink
Converted to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
helpfulrobot committed Dec 25, 2015
1 parent 23d6046 commit 74ef9dd
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 359 deletions.
31 changes: 16 additions & 15 deletions code/control/MultilingualGoogleSitemap.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php
class MultilingualGoogleSitemapController extends GoogleSitemapController {
private static $allowed_actions=array(
'sitemap'
class MultilingualGoogleSitemapController extends GoogleSitemapController
{
private static $allowed_actions=array(
'sitemap'
);

/**
* Specific controller action for displaying a particular list of links
* for a class
*
* @return mixed
*/
public function sitemap() {
if($this->request->param('ID')=='SiteTree') {
/**
* Specific controller action for displaying a particular list of links
* for a class
*
* @return mixed
*/
public function sitemap()
{
if ($this->request->param('ID')=='SiteTree') {
//Disable the locale filter
Translatable::disable_locale_filter();



$items=parent::sitemap();


Expand All @@ -24,9 +26,8 @@ public function sitemap() {


return $items;
}else {
} else {
return parent::sitemap();
}
}
}
}
?>
143 changes: 73 additions & 70 deletions code/control/MultilingualModelAsController.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
<?php
class MultilingualModelAsController extends ModelAsController {
class MultilingualModelAsController extends ModelAsController
{
private static $extensions=array('MultilingualOldPageRedirector');

/**
* @uses ModelAsController::getNestedController()
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$this->request=$request;
$this->setDataModel($model);

$this->pushCurrent();
/**
* @uses ModelAsController::getNestedController()
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->request=$request;
$this->setDataModel($model);

$this->pushCurrent();

//Get the local from the language param
if(Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if(Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
//Language is missing a dash 404
if(strpos($request->param('Language'), '-')===false) {
if (strpos($request->param('Language'), '-')===false) {
//Locale not found 404
if($response=ErrorPage::response_for(404)) {
if ($response=ErrorPage::response_for(404)) {
return $response;
}else {
} else {
$this->httpError(404, 'The requested page could not be found.');
}

Expand All @@ -31,45 +33,45 @@ public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
$locale[1]=strtoupper($locale[1]);

//Make sure that the language is all lowercase
if($request->param('Language')==implode('-', $locale)) {
if ($request->param('Language')==implode('-', $locale)) {
//Locale not found 404
if($response=ErrorPage::response_for(404)) {
if ($response=ErrorPage::response_for(404)) {
return $response;
}else {
} else {
$this->httpError(404, 'The requested page could not be found.');
}

return $this->response;
}

$locale=implode('_', $locale);
}else {
} else {
$locale=$request->param('Language');
}
}else if(strpos($request->param('Language'), '_')!==false) {
} elseif (strpos($request->param('Language'), '_')!==false) {
//Locale not found 404
if($response=ErrorPage::response_for(404)) {
if ($response=ErrorPage::response_for(404)) {
return $response;
}else {
} else {
$this->httpError(404, 'The requested page could not be found.');
}

return $this->response;
}else {
} else {
$locale=i18n::get_locale_from_lang($request->param('Language'));
}

if(in_array($locale, Translatable::get_allowed_locales())) {

if (in_array($locale, Translatable::get_allowed_locales())) {
//Set the current locale and remember it
Cookie::set('language', $request->param('Language'));

Translatable::set_current_locale($locale);
i18n::set_locale($locale);
}else {
} else {
//Locale not found 404
if($response=ErrorPage::response_for(404)) {
if ($response=ErrorPage::response_for(404)) {
return $response;
}else {
} else {
$this->httpError(404, 'The requested page could not be found.');
}

Expand All @@ -79,7 +81,7 @@ public function handleRequest(SS_HTTPRequest $request, DataModel $model) {

//Handle the home page for the language
$urlSegment=$request->param('URLSegment');
if(empty($urlSegment)) {
if (empty($urlSegment)) {
$controller=new MultilingualRootURLController();

$response=$controller->handleRequest($request, $model);
Expand All @@ -89,55 +91,56 @@ public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
}


//Normal page request so handle that
//Normal page request so handle that
$response=parent::handleRequest($request, $model);


$this->popCurrent();
return $response;
}


/**
* Overrides the default getNestedController() to maintain the language restrictions
* @return ContentController
*/
public function getNestedController() {
$request = $this->request;

if(!$URLSegment = $request->param('URLSegment')) {
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
}

// Find page by link
$sitetree = DataObject::get_one(
'SiteTree',
sprintf(
'"URLSegment" = \'%s\' %s',
Convert::raw2sql(rawurlencode($URLSegment)),
(SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null)
)
);

if(!$sitetree) {
* Overrides the default getNestedController() to maintain the language restrictions
* @return ContentController
*/
public function getNestedController()
{
$request = $this->request;

if (!$URLSegment = $request->param('URLSegment')) {
throw new Exception('ModelAsController->getNestedController(): was not passed a URLSegment value.');
}

// Find page by link
$sitetree = DataObject::get_one(
'SiteTree',
sprintf(
'"URLSegment" = \'%s\' %s',
Convert::raw2sql(rawurlencode($URLSegment)),
(SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null)
)
);

if (!$sitetree) {
$response = ErrorPage::response_for(404);
$this->httpError(404, $response ? $response : 'The requested page could not be found.');
}

// Enforce current language setting to the loaded SiteTree object
if(class_exists('Translatable') && $sitetree->Locale) {
if(Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
$this->httpError(404, $response ? $response : 'The requested page could not be found.');
}

// Enforce current language setting to the loaded SiteTree object
if (class_exists('Translatable') && $sitetree->Locale) {
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
Cookie::set('language', $sitetree->Locale);
}else {
} else {
Cookie::set('language', i18n::get_lang_from_locale($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'));
}

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'));
}

/**
Expand All @@ -147,13 +150,13 @@ public function getNestedController() {
* @param int $parentID The ID of the parent of the page the URLSegment belongs to.
* @return SiteTree
*/
public static function find_old_page($URLSegment, $parent = null, $ignoreNestedURLs = false) {
public static function find_old_page($URLSegment, $parent = null, $ignoreNestedURLs = false)
{
Deprecation::notice('3.2', 'Use MultilingualOldPageRedirector::find_old_page instead');
if ($parent) {
$parent = SiteTree::get()->byId($parent);
$parent = SiteTree::get()->byId($parent);
}
$url = MultilingualOldPageRedirector::find_old_page(array($URLSegment), $parent);
return SiteTree::get_by_link($url);
}
}
?>
Loading

0 comments on commit 74ef9dd

Please sign in to comment.