diff --git a/modules/backend/classes/BackendController.php b/modules/backend/classes/BackendController.php index fe57e12e3..88185fbd0 100644 --- a/modules/backend/classes/BackendController.php +++ b/modules/backend/classes/BackendController.php @@ -60,6 +60,21 @@ class BackendController extends ControllerBase self::extendableExtendCallback($callback); } + /** + * Pass unhandled URLs to the CMS Controller, if it exists + * + * @param string $url + * @return Response + */ + protected function passToCmsController($url) + { + if (class_exists('\Cms\Classes\Controller')) { + return App::make('Cms\Classes\Controller')->run($url); + } else { + return Response::make(View::make('backend::404'), 404); + } + } + /** * Finds and serves the requested backend controller. * If the controller cannot be found, returns the Cms page with the URL /404. @@ -78,7 +93,7 @@ class BackendController extends ControllerBase if (!App::hasDatabase()) { return Config::get('app.debug', false) ? Response::make(View::make('backend::no_database'), 200) - : App::make('Cms\Classes\Controller')->run($url); + : $this->passToCmsController($url); } /* @@ -105,7 +120,7 @@ class BackendController extends ControllerBase $pluginCode = ucfirst($author) . '.' . ucfirst($plugin); if (PluginManager::instance()->isDisabled($pluginCode)) { - return App::make('Cms\Classes\Controller')->setStatusCode(404)->run('/404'); + return Response::make(View::make('backend::404'), 404); } $controller = $params[2] ?? 'index'; @@ -124,7 +139,7 @@ class BackendController extends ControllerBase /* * Fall back on Cms controller */ - return App::make('Cms\Classes\Controller')->run($url); + return $this->passToCmsController($url); } /** diff --git a/modules/backend/classes/Controller.php b/modules/backend/classes/Controller.php index fa7b12279..bc9ab177f 100644 --- a/modules/backend/classes/Controller.php +++ b/modules/backend/classes/Controller.php @@ -339,11 +339,15 @@ class Controller extends Extendable $result = null; if (!$this->actionExists($actionName)) { - throw new SystemException(sprintf( - "Action %s is not found in the controller %s", - $actionName, - get_class($this) - )); + if (Config::get('app.debug', false)) { + throw new SystemException(sprintf( + "Action %s is not found in the controller %s", + $actionName, + get_class($this) + )); + } else { + Response::make(View::make('backend::404'), 404); + } } // Execute the action @@ -396,7 +400,7 @@ class Controller extends Extendable * Validate the handler name */ if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) { - throw new SystemException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler])); + throw new SystemException(Lang::get('backend::lang.ajax_handler.invalid_name', ['name'=>$handler])); } /* @@ -407,7 +411,7 @@ class Controller extends Extendable foreach ($partialList as $partial) { if (!preg_match('/^(?!.*\/\/)[a-z0-9\_][a-z0-9\_\-\/]*$/i', $partial)) { - throw new SystemException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial])); + throw new SystemException(Lang::get('backend::lang.partial.invalid_name', ['name'=>$partial])); } } } @@ -421,7 +425,7 @@ class Controller extends Extendable * Execute the handler */ if (!$result = $this->runAjaxHandler($handler)) { - throw new ApplicationException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler])); + throw new ApplicationException(Lang::get('backend::lang.ajax_handler.not_found', ['name'=>$handler])); } /* diff --git a/modules/backend/lang/en/lang.php b/modules/backend/lang/en/lang.php index 1d3e6a879..565eb2d44 100644 --- a/modules/backend/lang/en/lang.php +++ b/modules/backend/lang/en/lang.php @@ -17,22 +17,32 @@ return [ ], 'page' => [ 'untitled' => 'Untitled', + '404' => [ + 'label' => 'Page Not Found', + 'help' => "We searched and searched but the requested URL just couldn't be found. Perhaps you were looking for something else?", + 'back_link' => 'Go back to the previous page', + ], 'access_denied' => [ 'label' => 'Access denied', 'help' => "You don't have the required permissions to view this page.", - 'cms_link' => 'Return to the back-end' + 'cms_link' => 'Return to the back-end', ], 'no_database' => [ 'label' => 'Database missing', 'help' => "A database is required to access the back-end. Check the database is configured and migrated before trying again.", - 'cms_link' => 'Return to the homepage' + 'cms_link' => 'Return to the homepage', ], 'invalid_token' => [ - 'label' => 'Invalid security token' - ] + 'label' => 'Invalid security token', + ], ], 'partial' => [ - 'not_found_name' => "The partial ':name' is not found." + 'not_found_name' => "The partial ':name' is not found.", + 'invalid_name' => 'Invalid partial name: :name.', + ], + 'ajax_handler' => [ + 'invalid_name' => 'Invalid AJAX handler name: :name.', + 'not_found' => "AJAX handler ':name' was not found." ], 'account' => [ 'signed_in_as' => 'Signed in as :full_name', diff --git a/modules/backend/views/404.php b/modules/backend/views/404.php new file mode 100644 index 000000000..73951c509 --- /dev/null +++ b/modules/backend/views/404.php @@ -0,0 +1,19 @@ + + + + + <?= Lang::get('backend::lang.page.404.label') ?> + + + +
+

+
+

+

current()); ?>

+ +

+ +
+ + diff --git a/modules/backend/views/access_denied.php b/modules/backend/views/access_denied.php index 95c77da8f..5dcb9b2c9 100644 --- a/modules/backend/views/access_denied.php +++ b/modules/backend/views/access_denied.php @@ -9,7 +9,7 @@

- +