diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-05-15 23:36:52 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-05-15 23:36:52 -0700 |
commit | 29a8ba959ec1ec1ebd14d12c2a102fd7d3fcd012 (patch) | |
tree | d1f75ca29e54e1df32d1d5589ec27b676ca092b4 | |
parent | 28aee011307e37cd80e9bef0f08cb9b0270d89b5 (diff) | |
parent | 1240878df0f4a2b0ad0cdb32814717038ff2773f (diff) |
Merge branch 'master' into talmdal_dev
-rw-r--r-- | modules/comment/controllers/comments.php | 3 | ||||
-rw-r--r-- | modules/comment/helpers/comment.php | 10 | ||||
-rw-r--r-- | modules/comment/models/comment.php | 15 | ||||
-rw-r--r-- | modules/comment/tests/Comment_Event_Test.php | 1 | ||||
-rw-r--r-- | modules/comment/tests/Comment_Model_Test.php | 31 | ||||
-rw-r--r-- | modules/digibug/helpers/digibug_event.php | 17 | ||||
-rw-r--r-- | modules/gallery/controllers/quick.php | 4 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_event.php | 60 | ||||
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 4 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 2 | ||||
-rw-r--r-- | themes/admin_wind/views/admin.html.php | 2 | ||||
-rw-r--r-- | themes/wind/js/ui.init.js | 3 | ||||
-rw-r--r-- | themes/wind/views/movie.html.php | 3 | ||||
-rw-r--r-- | themes/wind/views/page.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/photo.html.php | 3 |
15 files changed, 136 insertions, 24 deletions
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index 9e0f86d2..465b1bcd 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -58,6 +58,7 @@ class Comments_Controller extends Controller { "view" => (string) $view, "form" => (string) comment::get_add_form($item))); } else { + $form = comment::prefill_add_form($form); print json_encode(array("result" => "error", "form" => (string) $form)); } } @@ -69,6 +70,6 @@ class Comments_Controller extends Controller { $item = ORM::factory("item", $item_id); access::required("view", $item); - print comment::get_add_form($item); + print comment::prefill_add_form(comment::get_add_form($item)); } } diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index e3486e83..94b14d0d 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -33,7 +33,9 @@ class comment_Core { ->error_messages("required", t("You must enter a name for yourself")); $group->input("email") ->label(t("Email (hidden)")) - ->id("g-email"); + ->id("g-email") + ->error_messages("required", t("You must enter a valid email address")) + ->error_messages("invalid", t("You must enter a valid email address")); $group->input("url") ->label(t("Website (hidden)")) ->id("g-url"); @@ -45,13 +47,17 @@ class comment_Core { module::event("comment_add_form", $form); $group->submit("")->value(t("Add"))->class("ui-state-default ui-corner-all"); + return $form; + } + + static function prefill_add_form($form) { $active = identity::active_user(); if (!$active->guest) { + $group = $form->add_comment; $group->inputs["name"]->value($active->full_name)->disabled("disabled"); $group->email->value($active->email)->disabled("disabled"); $group->url->value($active->url)->disabled("disabled"); } - return $form; } } diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index 48084340..fb70c79a 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -61,7 +61,7 @@ class Comment_Model extends ORM { if (!$array) { $this->rules = array( "guest_name" => array("callbacks" => array(array($this, "valid_author"))), - "guest_email" => array("rules" => array("email")), + "guest_email" => array("callbacks" => array(array($this, "valid_email"))), "guest_url" => array("rules" => array("url")), "item_id" => array("callbacks" => array(array($this, "valid_item"))), "state" => array("rules" => array("Comment_Model::valid_state")), @@ -145,6 +145,19 @@ class Comment_Model extends ORM { } /** + * Make sure that the email address is legal. + */ + public function valid_email(Validation $v, $field) { + if ($this->author_id == identity::guest()->id) { + if (empty($v->guest_email)) { + $v->add_error("guest_email", "required"); + } else if (!valid::email($v->guest_email)) { + $v->add_error("guest_email", "invalid"); + } + } + } + + /** * Make sure we have a valid associated item id. */ public function valid_item(Validation $v, $field) { diff --git a/modules/comment/tests/Comment_Event_Test.php b/modules/comment/tests/Comment_Event_Test.php index 62ffec2f..7cae9297 100644 --- a/modules/comment/tests/Comment_Event_Test.php +++ b/modules/comment/tests/Comment_Event_Test.php @@ -25,6 +25,7 @@ class Comment_Event_Test extends Gallery_Unit_Test_Case { $comment->item_id = $album->id; $comment->author_id = identity::guest()->id; $comment->guest_name = "test"; + $comment->guest_email = "test@test.com"; $comment->text = "text"; $comment->save(); diff --git a/modules/comment/tests/Comment_Model_Test.php b/modules/comment/tests/Comment_Model_Test.php index f4e944f0..ee4d3d3c 100644 --- a/modules/comment/tests/Comment_Model_Test.php +++ b/modules/comment/tests/Comment_Model_Test.php @@ -22,6 +22,37 @@ class Comment_Model_Test extends Gallery_Unit_Test_Case { identity::set_active_user(identity::admin_user()); } + public function guest_name_and_email_is_required_test() { + try { + $comment = ORM::factory("comment"); + $comment->item_id = item::root()->id; + $comment->author_id = identity::guest()->id; + $comment->text = "text"; + $comment->save(); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("guest_name" => "required", + "guest_email" => "required"), + $e->validation->errors()); + return; + } + } + + public function guest_email_must_be_well_formed_test() { + try { + $comment = ORM::factory("comment"); + $comment->item_id = item::root()->id; + $comment->author_id = identity::guest()->id; + $comment->guest_name = "guest"; + $comment->guest_email = "bogus"; + $comment->text = "text"; + $comment->save(); + } catch (ORM_Validation_Exception $e) { + $this->assert_equal(array("guest_email" => "invalid"), + $e->validation->errors()); + return; + } + } + public function cant_view_comments_for_unviewable_items_test() { $album = test::random_album(); diff --git a/modules/digibug/helpers/digibug_event.php b/modules/digibug/helpers/digibug_event.php index cf7cdf21..4c842615 100644 --- a/modules/digibug/helpers/digibug_event.php +++ b/modules/digibug/helpers/digibug_event.php @@ -26,14 +26,17 @@ class digibug_event_Core { ->url(url::site("admin/digibug"))); } - static function photo_menu($menu, $theme) { + static function site_menu($menu, $theme) { $item = $theme->item(); - $menu->append(Menu::factory("link") - ->id("digibug") - ->label(t("Print with Digibug")) - ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) - ->css_id("g-print-digibug-link") - ->css_class("g-print-digibug-link ui-icon-print")); + if ($item->type == "photo") { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("digibug") + ->label(t("Print with Digibug")) + ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) + ->css_id("g-print-digibug-link") + ->css_class("g-print-digibug-link ui-icon-print")); + } } static function context_menu($menu, $theme, $item) { diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index 813d1a93..6cfbbc62 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -58,12 +58,12 @@ class Quick_Controller extends Controller { if (Input::instance()->get("page_type") == "collection") { print json_encode( - array("src" => $item->thumb_url() . "?rnd=" . rand(), + array("src" => $item->thumb_url(), "width" => $item->thumb_width, "height" => $item->thumb_height)); } else { print json_encode( - array("src" => $item->resize_url() . "?rnd=" . rand(), + array("src" => $item->resize_url(), "width" => $item->resize_width, "height" => $item->resize_height)); } diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 2416f2e5..89ad6a4c 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -167,7 +167,7 @@ class gallery_event_Core { } } - static function site_menu($menu, $theme) { + static function site_menu($menu, $theme, $item_css_selector) { if ($theme->page_subtype != "login") { $menu->append(Menu::factory("link") ->id("home") @@ -238,6 +238,63 @@ class gallery_event_Core { } } } + + $csrf = access::csrf_token(); + $theme_item = $theme->item(); + $page_type = $theme->page_type(); + if ($item->is_photo() && graphics::can("rotate")) { + $options_menu + ->append( + Menu::factory("ajax_link") + ->id("rotate_ccw") + ->label(t("Rotate 90° counter clockwise")) + ->css_class("ui-icon-rotate-ccw") + ->ajax_handler("function(data) { " . + "\$.gallery_replace_image(data, \$('$item_css_selector')) }") + ->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") + ->label(t("Rotate 90° clockwise")) + ->css_class("ui-icon-rotate-cw") + ->ajax_handler("function(data) { " . + "\$.gallery_replace_image(data, \$('$item_css_selector')) }") + ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + } + + if ($item->id != item::root()->id) { + $parent = $item->parent(); + if (access::can("edit", $parent)) { + // We can't make this item the highlight if it's an album with no album cover, or if it's + // already the album cover. + if (($item->type == "album" && empty($item->album_cover_item_id)) || + ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) || + $parent->album_cover_item_id == $item->id) { + $disabledState = " ui-state-disabled"; + } else { + $disabledState = " "; + } + + if ($item->parent()->id != 1) { + $options_menu + ->append( + Menu::factory("ajax_link") + ->id("make_album_cover") + ->label(t("Choose as the album cover")) + ->css_class("ui-icon-star") + ->ajax_handler("function(data) { window.location.reload() }") + ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf"))); + } + $options_menu + ->append( + Menu::factory("dialog") + ->id("delete") + ->label(t("Delete this photo")) + ->css_class("ui-icon-trash") + ->css_class("g-quick-delete") + ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); + } + } } if (identity::active_user()->admin) { @@ -394,7 +451,6 @@ class gallery_event_Core { ->id("delete") ->label($delete_title) ->css_class("ui-icon-trash") - ->css_class("g-quick-delete") ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type"))); } diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 8b432fb6..6246c6f1 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -86,9 +86,9 @@ class Theme_View_Core extends Gallery_View { return $menu->render(); } - public function site_menu() { + public function site_menu($item_css_selector) { $menu = Menu::factory("root"); - module::event("site_menu", $menu, $this); + module::event("site_menu", $menu, $this, $item_css_selector); return $menu->render(); } diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 7fc37325..409ed3cc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -674,7 +674,7 @@ class Item_Model extends ORM_MPTT { $v->attrs = array_merge($extra_attrs, array("style" => "display:block;width:{$this->width}px;height:{$this->height}px")); if (empty($v->attrs["id"])) { - $v->attrs["id"] = "g-movie-id-{$this->id}"; + $v->attrs["id"] = "g-item-id-{$this->id}"; } return $v; } diff --git a/themes/admin_wind/views/admin.html.php b/themes/admin_wind/views/admin.html.php index 2f64c847..ff7b930f 100644 --- a/themes/admin_wind/views/admin.html.php +++ b/themes/admin_wind/views/admin.html.php @@ -6,7 +6,7 @@ <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title> <? if ($page_title): ?> - <?= $page_title ?> + <?= t("Gallery Admin: %page_title", array("page_title" => $page_title)) ?> <? else: ?> <?= t("Admin dashboard") ?> <? endif ?> diff --git a/themes/wind/js/ui.init.js b/themes/wind/js/ui.init.js index 6edf6be4..53b58516 100644 --- a/themes/wind/js/ui.init.js +++ b/themes/wind/js/ui.init.js @@ -108,6 +108,9 @@ $(document).ready(function() { duration: 1000, hash: true }); + + $(this).find(".g-dialog-link").gallery_dialog(); + $(this).find(".g-ajax-link").gallery_ajax(); } // Initialize button hover effect diff --git a/themes/wind/views/movie.html.php b/themes/wind/views/movie.html.php index 27c293ce..8481c7ce 100644 --- a/themes/wind/views/movie.html.php +++ b/themes/wind/views/movie.html.php @@ -5,8 +5,7 @@ <?= $theme->paginator() ?> <div id="g-movie" class="ui-helper-clearfix"> - <?= $item->movie_img(array("class" => "g-movie", "id" => "g-movie-id-{$item->id}")) ?> - <?= $theme->context_menu($item, "#g-movie-id-{$item->id}") ?> + <?= $item->movie_img(array("class" => "g-movie", "id" => "g-item-id-{$item->id}")) ?> </div> <div id="g-info"> diff --git a/themes/wind/views/page.html.php b/themes/wind/views/page.html.php index ebfbf700..4cc949ce 100644 --- a/themes/wind/views/page.html.php +++ b/themes/wind/views/page.html.php @@ -89,7 +89,7 @@ <!-- hide the menu and make it visible after the page has loaded, to minimize menu flicker --> <div id="g-site-menu" style="visibility: hidden"> - <?= $theme->site_menu() ?> + <?= $theme->site_menu($theme->item() ? "#g-item-id-{$theme->item()->id}" : "") ?> </div> <script type="text/javascript"> $(document).ready(function() { $("#g-site-menu").css("visibility", "visible"); }) </script> diff --git a/themes/wind/views/photo.html.php b/themes/wind/views/photo.html.php index e0fae3f1..f8b5511c 100644 --- a/themes/wind/views/photo.html.php +++ b/themes/wind/views/photo.html.php @@ -22,12 +22,11 @@ <? if (access::can("view_full", $item)): ?> <a href="<?= $item->file_url() ?>" class="g-fullsize-link" title="<?= t("View full size")->for_html_attr() ?>"> <? endif ?> - <?= $item->resize_img(array("id" => "g-photo-id-{$item->id}", "class" => "g-resize")) ?> + <?= $item->resize_img(array("id" => "g-item-id-{$item->id}", "class" => "g-resize")) ?> <? if (access::can("view_full", $item)): ?> </a> <? endif ?> <?= $theme->resize_bottom($item) ?> - <?= $theme->context_menu($item, "#g-photo-id-{$item->id}") ?> </div> <div id="g-info"> |