From 41ca2b0195bf6a29429dfc5405f3c2073b1c3aba Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 19 Jun 2010 13:52:48 -0700 Subject: Rework our exception framework to fit into Kohana's model better. Instead of overwriting Kohana_Exception::handle() (which we were doing in MY_Kohana_Exception) we instead use their existing template system. gallery/views/kohana/error.php overrides system/views/kohana/error.php and is the standard error template for all exceptions. Our version of error.php figures out the appropriate view based on context (cli, authenticated admin, guest viewing a 404, guest viewing a system error) and delegates appropriately. Each delegated view has a narrow responsibility. This paves the way for us to add new error views per module. For example, the rest module will define its own template in Rest_Exception and then its exceptions can be rendered the way that it wants (json encoded, in that case). --- modules/gallery/views/error_admin.html.php | 272 ++++++++++++++++++++++++ modules/gallery/views/error_cli.txt.php | 3 + modules/gallery/views/error_user.html.php | 42 ++++ modules/gallery/views/kohana/error.php | 321 ++++------------------------- 4 files changed, 359 insertions(+), 279 deletions(-) create mode 100644 modules/gallery/views/error_admin.html.php create mode 100644 modules/gallery/views/error_cli.txt.php create mode 100644 modules/gallery/views/error_user.html.php (limited to 'modules/gallery/views') diff --git a/modules/gallery/views/error_admin.html.php b/modules/gallery/views/error_admin.html.php new file mode 100644 index 00000000..40eb7374 --- /dev/null +++ b/modules/gallery/views/error_admin.html.php @@ -0,0 +1,272 @@ + + + + + + + + <?= t("Something went wrong!") ?> + + + + + +
+

+ +

+

+ +

+
+
+

+ +

+
+

+ + [ ]: + + + + +

+
+
    +
  1. +

    + + [ ] + +

    + +
    + $row): ?>"> + +
    +
  2. + + + $step): ?> +
  3. +

    + + + + [ ] + + [ ] + + + {} + + + » + ( + + ) +

    + + + + + + +
  4. + + +
+ + +
+

+ " onclick="return koggle('')"> +

+ +
+
+ + diff --git a/modules/gallery/views/error_cli.txt.php b/modules/gallery/views/error_cli.txt.php new file mode 100644 index 00000000..b4f87fa6 --- /dev/null +++ b/modules/gallery/views/error_cli.txt.php @@ -0,0 +1,3 @@ + + + diff --git a/modules/gallery/views/error_user.html.php b/modules/gallery/views/error_user.html.php new file mode 100644 index 00000000..74c6a8fb --- /dev/null +++ b/modules/gallery/views/error_user.html.php @@ -0,0 +1,42 @@ + + + + + + + <?= t("Something went wrong!") ?> + + +
+

+ +

+

+ +

+

+ +

+
+ + diff --git a/modules/gallery/views/kohana/error.php b/modules/gallery/views/kohana/error.php index d55105a0..b0f0e907 100644 --- a/modules/gallery/views/kohana/error.php +++ b/modules/gallery/views/kohana/error.php @@ -1,280 +1,43 @@ - - - - - - - <?= t("Something went wrong!") ?> - - - - - - admin) ?> -
-

- -

-

- -

- -

- -

- -
- -
-

- -

-
-

- - [ ]: - - - - -

-
-
    -
  1. -

    - - [ ] - -

    - -
    - $row): ?>"> - -
    -
  2. - - - $step): ?> -
  3. -

    - - - - [ ] - - [ ] - - - {} - - - » - ( - - ) -

    - - - - - - -
  4. - - -
- - -
-

- " onclick="return koggle('')"> -

- -
-
- - - +validation->errors(), 1)); +} + +if (php_sapi_name() == "cli") { + include Kohana::find_file("views", "error_cli.txt"); + return; +} + +try { + // Admins get a special error page + $user = identity::active_user(); + if ($user && $user->admin) { + include Kohana::find_file("views", "error_admin.html"); + return; + } +} catch (Exception $ignored) { +} + +// Try to show a themed error page for 404 errors +if ($e instanceof Kohana_404_Exception) { + $view = new Theme_View("page.html", "other", "error"); + $view->page_title = t("Dang... Page not found!"); + $view->content = new View("error_404.html"); + $user = identity::active_user(); + $view->content->is_guest = $user && $user->guest; + if ($view->content->is_guest) { + $view->content->login_form = new View("login_ajax.html"); + $view->content->login_form->form = auth::get_login_form("login/auth_html"); + } + print $view; + return; +} + +header("HTTP/1.1 500 Internal Server Error"); +include Kohana::find_file("views", "error_user.html"); +?> -- cgit v1.2.3