diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-13 13:00:41 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-13 13:00:41 -0800 |
commit | dcd7a8fbb8924665a07582aa53f07a86ef922287 (patch) | |
tree | d8c979b9dc72b3de943ec25dc883f25bde1750c6 | |
parent | 650845eddaad250374330a14c47cda62bf41f20a (diff) | |
parent | 36702b1397dcac9ba5a607f62e2a1caeb307ac7a (diff) |
Merge branch 'master' into talmdal_dev
-rw-r--r-- | modules/gallery/controllers/albums.php | 11 | ||||
-rw-r--r-- | modules/gallery/helpers/auth.php | 14 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 6 | ||||
-rw-r--r-- | modules/gallery/libraries/MY_Kohana_Exception.php | 59 | ||||
-rw-r--r-- | modules/gallery/libraries/Menu.php | 13 | ||||
-rw-r--r-- | modules/gallery/views/error.html.php | 12 | ||||
-rw-r--r-- | modules/gallery/views/error_404.html.php | 21 | ||||
-rw-r--r-- | modules/gallery/views/kohana_error_page.php | 127 | ||||
-rw-r--r-- | modules/gallery/views/menu.html.php | 4 | ||||
-rw-r--r-- | modules/gallery/views/menu_ajax_link.html.php | 2 | ||||
-rw-r--r-- | modules/gallery/views/menu_dialog.html.php | 2 | ||||
-rw-r--r-- | modules/gallery/views/menu_link.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/page.html.php | 2 |
13 files changed, 114 insertions, 161 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index c2b474ee..036dade0 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -29,16 +29,7 @@ class Albums_Controller extends Items_Controller { throw new Kohana_404_Exception(); } - if (!access::can("view", $album)) { - if ($album->id == 1) { - // Even show the login page to logged in users. - // It's a better user experience than a "Dang" error page. - print auth::login_page(); - return; - } else { - access::required("view", $album); - } - } + access::required("view", $album); $page_size = module::get_var("gallery", "page_size", 9); $input = Input::instance(); diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php index 8b0ce470..c3e9e6e9 100644 --- a/modules/gallery/helpers/auth.php +++ b/modules/gallery/helpers/auth.php @@ -130,18 +130,4 @@ class auth_Core { $session->set("admin_area_activity_timestamp", time()); return false; } - - /** - * Returns the themed login page. - */ - static function login_page($continue_url=null) { - $view = new Theme_View("page.html", "other", "login"); - $view->page_title = t("Log in to Gallery"); - $view->content = new View("login_ajax.html"); - $view->content->form = auth::get_login_form("login/auth_html"); - // Avoid anti-phishing protection by passing the url as session variable. - $continue_url or $continue_url = url::current(true); - Session::instance()->set("continue_url", $continue_url); - return $view; - } }
\ No newline at end of file diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 63f33c12..faf1c0c6 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -336,7 +336,7 @@ class gallery_event_Core { ->css_class("ui-icon-rotate-ccw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") - ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))) + ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))) ->append( Menu::factory("ajax_link") ->id("rotate_cw") @@ -344,7 +344,7 @@ class gallery_event_Core { ->css_class("ui-icon-rotate-cw") ->ajax_handler("function(data) { " . "\$.gallery_replace_image(data, \$('$thumb_css_selector')) }") - ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); } // @todo Don't move photos from the photo page; we don't yet have a good way of redirecting @@ -384,7 +384,7 @@ class gallery_event_Core { ->label($delete_title) ->css_class("ui-icon-trash") ->css_id("g-quick-delete") - ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); } if ($item->is_album()) { diff --git a/modules/gallery/libraries/MY_Kohana_Exception.php b/modules/gallery/libraries/MY_Kohana_Exception.php index 1c40091a..d6f1f467 100644 --- a/modules/gallery/libraries/MY_Kohana_Exception.php +++ b/modules/gallery/libraries/MY_Kohana_Exception.php @@ -33,6 +33,63 @@ class Kohana_Exception extends Kohana_Exception_Core { if ($e instanceof ORM_Validation_Exception) { Kohana_Log::add("error", "Validation errors: " . print_r($e->validation->errors(), 1)); } - return parent::handle($e); + try { + $user = identity::active_user(); + $try_themed_view = $user && !$user->admin; + } catch (Exception $e2) { + $try_themed_view = false; + } + + if ($try_themed_view) { + try { + return self::_show_themed_error_page($e); + } catch (Exception $e3) { + Kohana_Log::add("error", "Exception in exception handling code: " . self::text($e3)); + return parent::handle($e); + } + } else { + return parent::handle($e); + } + } + + /** + * Shows a themed error page. + * @see Kohana_Exception::handle + */ + private static function _show_themed_error_page(Exception $e) { + // Create a text version of the exception + $error = Kohana_Exception::text($e); + + // Add this exception to the log + Kohana_Log::add('error', $error); + + // Manually save logs after exceptions + Kohana_Log::save(); + + if (!headers_sent()) { + if ($e instanceof Kohana_Exception) { + $e->sendHeaders(); + } else { + header("HTTP/1.1 500 Internal Server Error"); + } + } + + $view = new Theme_View("page.html", "other", "error"); + if ($e instanceof Kohana_404_Exception) { + $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"); + // Avoid anti-phishing protection by passing the url as session variable. + Session::instance()->set("continue_url", url::current(true)); + } + } else { + $view->page_title = t("Dang... Something went wrong!"); + $view->content = new View("error.html"); + } + print $view; } }
\ No newline at end of file diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index e2b68d1a..7c76ab04 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -216,6 +216,19 @@ class Menu_Core extends Menu_Element { return null; } + public function is_empty() { + foreach ($this->elements as $element) { + if ($element instanceof Menu) { + if (!$element->is_empty()) { + return false; + } + } else { + return false; + } + } + return true; + } + public function render() { $view = new View(isset($this->view) ? $this->view : "menu.html"); $view->menu = $this; diff --git a/modules/gallery/views/error.html.php b/modules/gallery/views/error.html.php new file mode 100644 index 00000000..5d81b651 --- /dev/null +++ b/modules/gallery/views/error.html.php @@ -0,0 +1,12 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div id="g-error"> + <h1> + <?= t("Dang... Something went wrong!") ?> + </h1> + <h2> + <?= t("We tried really hard, but it's broken.") ?> + </h2> + <p> + <?= t("Talk to your Gallery administrator for help fixing this!") ?> + </p> +</div>
\ No newline at end of file diff --git a/modules/gallery/views/error_404.html.php b/modules/gallery/views/error_404.html.php new file mode 100644 index 00000000..4b037a79 --- /dev/null +++ b/modules/gallery/views/error_404.html.php @@ -0,0 +1,21 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<div id="g-error"> + <h1> + <?= t("Dang... Page not found!") ?> + </h1> + <? if ($is_guest): ?> + <h2> + <?= t("Hey wait, you're not signed in yet!") ?> + </h2> + <p> + <?= t("Maybe the page exists, but is only visible to authorized users.") ?> + <?= t("Please sign in to find out.") ?> + </p> + <?= $login_form ?> + <? else: ?> + <p> + <?= t("Maybe the page exists, but is only visible to authorized users.") ?> + <?= t("If you think this is an error, talk to your Gallery administrator!") ?> + </p> + <? endif; ?> +</div>
\ No newline at end of file diff --git a/modules/gallery/views/kohana_error_page.php b/modules/gallery/views/kohana_error_page.php deleted file mode 100644 index b9fdcc19..00000000 --- a/modules/gallery/views/kohana_error_page.php +++ /dev/null @@ -1,127 +0,0 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <style type="text/css"> - body { - background: #fff; - font-size: 14px; - line-height: 130%; - } - - div.big_box { - padding: 10px; - background: #eee; - border: solid 1px #ccc; - font-family: sans-serif; - color: #111; - width: 42em; - margin: 20px auto; - } - - div#framework_error { - text-align: center; - } - - div#error_details { - text-align: left; - } - - code { - font-family: monospace; - font-size: 12px; - margin: 20px; - color: #333; - white-space: pre-wrap; - white-space: -moz-pre-wrap; - word-wrap: break-word; - } - - h3 { - font-family: sans-serif; - margin: 2px 0px 0px 0px; - padding: 8px 0px 0px 0px; - border-top: 1px solid #ddd; - } - - p { - padding: 0px; - margin: 0px 0px 10px 0px; - } - - li, pre { - padding: 0px; - margin: 0px; - } - </style> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> - <title><?= t("Something went wrong!") ?></title> - </head> - <body> - <? try { $user = identity::active_user(); } catch (Exception $e) { } ?> - <? $admin = php_sapi_name() == "cli" || isset($user) && $user->admin ?> - <div class="big_box" id="framework_error"> - <h1> - <?= t("Dang... Something went wrong!") ?> - </h1> - <h2> - <?= t("We tried really hard, but it's broken.") ?> - </h2> - <? if (!$admin): ?> - <p> - <?= t("Talk to your Gallery administrator for help fixing this!") ?> - </p> - <? endif ?> - </div> - <? if ($admin): ?> - <div class="big_box" id="error_details"> - <h2> - <?= t("Hey wait, you're an admin! We can tell you stuff.") ?> - </h2> - <script type="text/javascript"> - var show_details = function() { - document.getElementById("stuff").style.display = "block"; - document.getElementById("toggle").style.display = "none"; - } - </script> - <a id="toggle" href="#" onclick="javascript:show_details(); return false;"> - <b><?= t("Ok.. tell me stuff!") ?></b> - </a> - <div id="stuff" style="display: none"> - <? if (!empty($line) and !empty($file)): ?> - <div id="summary"> - <h3> - <?= t("Help!") ?> - </h3> - <p> - <?= t("If this stuff doesn't make any sense to you, <a href=\"%url\">ask for help in the Gallery forums</a>!", array("url" => "http://gallery.menalto.com/forum/96")) ?> - </p> - <h3> - <?= t("So here's the error:") ?> - </h3> - - <code class="block"><?= $message ?></code> - <p> - <?= t("File: <b>%file</b>, line: <b>%line</b>", array("file" => $file, "line" => $line)) ?> - </p> - </div> - <? endif ?> - - <? $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTrace(); ?> - <? $trace = Kohana::backtrace($trace); ?> - <? if (!empty($trace)): ?> - <div id="stack_trace"> - <h3> - <?= t("And here's how we got there:") ?> - </h3> - <?= $trace ?> - <? endif ?> - </div> - </div> - <? else: ?> - <? $trace = $PHP_ERROR ? array_slice(debug_backtrace(), 1) : $exception->getTraceAsString(); ?> - <? if (!empty($trace)): ?> - <? Kohana_Log::add("error", print_r($trace, 1)); ?> - <? endif ?> - <? endif ?> - </body> -</html> diff --git a/modules/gallery/views/menu.html.php b/modules/gallery/views/menu.html.php index cb49bcdf..17a249dd 100644 --- a/modules/gallery/views/menu.html.php +++ b/modules/gallery/views/menu.html.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<? if ($menu->elements): // Don't show the menu if it has no choices ?> +<? if (!$menu->is_empty()): // Don't show the menu if it has no choices ?> <? if ($menu->is_root): ?> -<ul <?= isset($menu->css_id) ? "id='$menu->css_id'" : "" ?> class="<?= $menu->css_class ?>"> +<ul <?= $menu->css_id ? "id='$menu->css_id'" : "" ?> class="<?= $menu->css_class ?>"> <? foreach ($menu->elements as $element): ?> <?= $element->render() ?> <? endforeach ?> diff --git a/modules/gallery/views/menu_ajax_link.html.php b/modules/gallery/views/menu_ajax_link.html.php index 00a394bc..06cd6f92 100644 --- a/modules/gallery/views/menu_ajax_link.html.php +++ b/modules/gallery/views/menu_ajax_link.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <li> - <a id="<?= $menu->css_id ?>" + <a <?= $menu->css_id ? "id='{$menu->css_id}'" : "" ?> class="g-ajax-link <?= $menu->css_class ?>" href="<?= $menu->url ?>" title="<?= $menu->label->for_html_attr() ?>" diff --git a/modules/gallery/views/menu_dialog.html.php b/modules/gallery/views/menu_dialog.html.php index 99b1b013..b44080c3 100644 --- a/modules/gallery/views/menu_dialog.html.php +++ b/modules/gallery/views/menu_dialog.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <li> - <a id="<?= $menu->css_id ?>" + <a <?= $menu->css_id ? "id='{$menu->css_id}'" : "" ?> class="g-dialog-link <?= $menu->css_class ?>" href="<?= $menu->url ?>" title="<?= $menu->label->for_html_attr() ?>"> diff --git a/modules/gallery/views/menu_link.html.php b/modules/gallery/views/menu_link.html.php index 8e4cdb95..a36d2754 100644 --- a/modules/gallery/views/menu_link.html.php +++ b/modules/gallery/views/menu_link.html.php @@ -1,6 +1,6 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> <li> - <a id="<?= $menu->css_id ?>" + <a <?= $menu->css_id ? "id='{$menu->css_id}'" : "" ?> class="g-menu-link <?= $menu->css_class ?>" href="<?= $menu->url ?>" title="<?= $menu->label->for_html_attr() ?>"> diff --git a/themes/wind/views/page.html.php b/themes/wind/views/page.html.php index 2dcc5d70..61e34145 100644 --- a/themes/wind/views/page.html.php +++ b/themes/wind/views/page.html.php @@ -91,7 +91,7 @@ <div id="g-site-menu" style="visibility: hidden"> <?= $theme->site_menu() ?> </div> - <script> $(document).ready(function() { $("#g-site-menu").css("visibility", "visible"); }) </script> + <script type="text/javascript"> $(document).ready(function() { $("#g-site-menu").css("visibility", "visible"); }) </script> <?= $theme->header_bottom() ?> </div> |