summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-05-15 23:36:52 -0700
committerTim Almdal <tnalmdal@shaw.ca>2010-05-15 23:36:52 -0700
commit29a8ba959ec1ec1ebd14d12c2a102fd7d3fcd012 (patch)
treed1f75ca29e54e1df32d1d5589ec27b676ca092b4 /modules
parent28aee011307e37cd80e9bef0f08cb9b0270d89b5 (diff)
parent1240878df0f4a2b0ad0cdb32814717038ff2773f (diff)
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/controllers/comments.php3
-rw-r--r--modules/comment/helpers/comment.php10
-rw-r--r--modules/comment/models/comment.php15
-rw-r--r--modules/comment/tests/Comment_Event_Test.php1
-rw-r--r--modules/comment/tests/Comment_Model_Test.php31
-rw-r--r--modules/digibug/helpers/digibug_event.php17
-rw-r--r--modules/gallery/controllers/quick.php4
-rw-r--r--modules/gallery/helpers/gallery_event.php60
-rw-r--r--modules/gallery/libraries/Theme_View.php4
-rw-r--r--modules/gallery/models/item.php2
10 files changed, 129 insertions, 18 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&amp;from_id=$theme_item->id&amp;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&amp;from_id=$theme_item->id&amp;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&amp;from_id=$theme_item->id&amp;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&amp;from_id=$theme_item->id&amp;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;
}