Skip to content

Commit

Permalink
Merge branch 'master' into talmdal_dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Almdal committed May 16, 2010
2 parents 28aee01 + 1240878 commit 29a8ba9
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 24 deletions.
3 changes: 2 additions & 1 deletion modules/comment/controllers/comments.php
Expand Up @@ -58,6 +58,7 @@ public function create($id) {
"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));
}
}
Expand All @@ -69,6 +70,6 @@ public function form_add($item_id) {
$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));
}
}
10 changes: 8 additions & 2 deletions modules/comment/helpers/comment.php
Expand Up @@ -33,7 +33,9 @@ static function get_add_form($item) {
->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");
Expand All @@ -45,13 +47,17 @@ static function get_add_form($item) {
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;
}
}
Expand Down
15 changes: 14 additions & 1 deletion modules/comment/models/comment.php
Expand Up @@ -61,7 +61,7 @@ public function validate(Validation $array=null) {
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")),
Expand Down Expand Up @@ -144,6 +144,19 @@ public function valid_author(Validation $v, $field) {
}
}

/**
* 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.
*/
Expand Down
1 change: 1 addition & 0 deletions modules/comment/tests/Comment_Event_Test.php
Expand Up @@ -25,6 +25,7 @@ public function deleting_an_item_deletes_its_comments_too_test() {
$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();

Expand Down
31 changes: 31 additions & 0 deletions modules/comment/tests/Comment_Model_Test.php
Expand Up @@ -22,6 +22,37 @@ public function teardown() {
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();

Expand Down
17 changes: 10 additions & 7 deletions modules/digibug/helpers/digibug_event.php
Expand Up @@ -26,14 +26,17 @@ static function admin_menu($menu, $theme) {
->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) {
Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/controllers/quick.php
Expand Up @@ -58,12 +58,12 @@ public function rotate($id, $dir) {

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));
}
Expand Down
60 changes: 58 additions & 2 deletions modules/gallery/helpers/gallery_event.php
Expand Up @@ -167,7 +167,7 @@ static function user_menu($menu, $theme) {
}
}

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")
Expand Down Expand Up @@ -238,6 +238,63 @@ static function site_menu($menu, $theme) {
}
}
}

$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) {
Expand Down Expand Up @@ -394,7 +451,6 @@ static function context_menu($menu, $theme, $item, $thumb_css_selector) {
->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")));
}

Expand Down
4 changes: 2 additions & 2 deletions modules/gallery/libraries/Theme_View.php
Expand Up @@ -86,9 +86,9 @@ public function user_menu() {
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();
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/models/item.php
Expand Up @@ -674,7 +674,7 @@ public function movie_img($extra_attrs) {
$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;
}
Expand Down
2 changes: 1 addition & 1 deletion themes/admin_wind/views/admin.html.php
Expand Up @@ -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 ?>
Expand Down
3 changes: 3 additions & 0 deletions themes/wind/js/ui.init.js
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions themes/wind/views/movie.html.php
Expand Up @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion themes/wind/views/page.html.php
Expand Up @@ -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>

Expand Down
3 changes: 1 addition & 2 deletions themes/wind/views/photo.html.php
Expand Up @@ -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">
Expand Down

0 comments on commit 29a8ba9

Please sign in to comment.