diff options
author | Romain LE DISEZ <romain.git@ledisez.net> | 2009-07-20 18:46:41 +0200 |
---|---|---|
committer | Romain LE DISEZ <romain.git@ledisez.net> | 2009-07-20 18:46:41 +0200 |
commit | 00b3ca82de3a4858745988943a46d07b1c0fd006 (patch) | |
tree | 158896d430014e1f896df0b19acc57aeb602c9ab | |
parent | 8cbf43ed2abe9772045766e598bb9fe3d4def983 (diff) | |
parent | fb7d99740d9868938ec21449d57b9b3fe991f513 (diff) |
Merge commit 'upstream/master'
-rw-r--r-- | modules/gallery/controllers/albums.php | 15 | ||||
-rw-r--r-- | modules/gallery/controllers/movies.php | 11 | ||||
-rw-r--r-- | modules/gallery/controllers/photos.php | 13 | ||||
-rw-r--r-- | modules/gallery/helpers/album.php | 5 | ||||
-rw-r--r-- | modules/gallery/helpers/photo.php | 4 | ||||
-rw-r--r-- | modules/tag/helpers/tag.php | 20 | ||||
-rw-r--r-- | modules/tag/helpers/tag_event.php | 24 | ||||
-rw-r--r-- | modules/user/views/login_ajax.html.php | 2 |
8 files changed, 67 insertions, 27 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index 9980b676..56b74cb1 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -174,22 +174,23 @@ class Albums_Controller extends Items_Controller { ->from("items") ->where("parent_id", $album->parent_id) ->where("id <>", $album->id) - ->where("name", $form->edit_album->dirname->value) + ->where("name", $form->edit_item->dirname->value) ->count_records()) { - $form->edit_album->dirname->add_error("conflict", 1); + $form->edit_item->dirname->add_error("conflict", 1); $valid = false; } } if ($valid) { - $album->title = $form->edit_album->title->value; - $album->description = $form->edit_album->description->value; - $album->sort_column = $form->edit_album->sort_order->column->value; - $album->sort_order = $form->edit_album->sort_order->direction->value; + $album->title = $form->edit_item->title->value; + $album->description = $form->edit_item->description->value; + $album->sort_column = $form->edit_item->sort_order->column->value; + $album->sort_order = $form->edit_item->sort_order->direction->value; if ($album->id != 1) { - $album->rename($form->edit_album->dirname->value); + $album->rename($form->edit_item->dirname->value); } $album->save(); + module::event("item_edit_form_completed", $album, $form); log::success("content", "Updated album", "<a href=\"albums/$album->id\">view</a>"); message::success( diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index d954ad8d..c8227d74 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -77,18 +77,19 @@ class Movies_Controller extends Items_Controller { ->from("items") ->where("parent_id", $photo->parent_id) ->where("id <>", $photo->id) - ->where("name", $form->edit_photo->filename->value) + ->where("name", $form->edit_item->filename->value) ->count_records()) { - $form->edit_photo->filename->add_error("conflict", 1); + $form->edit_item->filename->add_error("conflict", 1); $valid = false; } } if ($valid) { - $photo->title = $form->edit_photo->title->value; - $photo->description = $form->edit_photo->description->value; - $photo->rename($form->edit_photo->filename->value); + $photo->title = $form->edit_item->title->value; + $photo->description = $form->edit_item->description->value; + $photo->rename($form->edit_item->filename->value); $photo->save(); + module::event("item_edit_form_completed", $photo, $form); log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>"); message::success( diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 9ce6ed23..8ee24da8 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -63,25 +63,26 @@ class Photos_Controller extends Items_Controller { $form = photo::get_edit_form($photo); if ($valid = $form->validate()) { - if ($form->edit_photo->filename->value != $photo->name) { + if ($form->edit_item->filename->value != $photo->name) { // Make sure that there's not a conflict if (Database::instance() ->from("items") ->where("parent_id", $photo->parent_id) ->where("id <>", $photo->id) - ->where("name", $form->edit_photo->filename->value) + ->where("name", $form->edit_item->filename->value) ->count_records()) { - $form->edit_photo->filename->add_error("conflict", 1); + $form->edit_item->filename->add_error("conflict", 1); $valid = false; } } } if ($valid) { - $photo->title = $form->edit_photo->title->value; - $photo->description = $form->edit_photo->description->value; - $photo->rename($form->edit_photo->filename->value); + $photo->title = $form->edit_item->title->value; + $photo->description = $form->edit_item->description->value; + $photo->rename($form->edit_item->filename->value); $photo->save(); + module::event("item_edit_form_completed", $photo, $form); log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>"); message::success( diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php index f1a6c060..5f10bd02 100644 --- a/modules/gallery/helpers/album.php +++ b/modules/gallery/helpers/album.php @@ -96,7 +96,7 @@ class album_Core { static function get_edit_form($parent) { $form = new Forge("albums/{$parent->id}", "", "post", array("id" => "gEditAlbumForm")); $form->hidden("_method")->value("put"); - $group = $form->group("edit_album")->label(t("Edit Album")); + $group = $form->group("edit_item")->label(t("Edit Album")); $group->input("title")->label(t("Title"))->value($parent->title); $group->textarea("description")->label(t("Description"))->value($parent->description); @@ -126,6 +126,9 @@ class album_Core { ->options(array("ASC" => t("Ascending"), "DESC" => t("Descending"))) ->selected($parent->sort_order); + + module::event("item_edit_form", $parent, $form); + $group->hidden("type")->value("album"); $group->submit("")->value(t("Modify")); $form->add_rules_from(ORM::factory("item")); diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index ce964c14..5cf37de1 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -137,7 +137,7 @@ class photo_Core { static function get_edit_form($photo) { $form = new Forge("photos/$photo->id", "", "post", array("id" => "gEditPhotoForm")); $form->hidden("_method")->value("put"); - $group = $form->group("edit_photo")->label(t("Edit Photo")); + $group = $form->group("edit_item")->label(t("Edit Photo")); $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); $group->input("filename")->label(t("Filename"))->value($photo->name) @@ -147,6 +147,8 @@ class photo_Core { ->callback("item::validate_no_trailing_period") ->error_messages("no_trailing_period", t("The photo name can't end in \".\"")); + module::event("item_edit_form", $photo, $form); + $group->submit("")->value(t("Modify")); $form->add_rules_from(ORM::factory("item")); return $form; diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php index ab5ee303..1fb2e940 100644 --- a/modules/tag/helpers/tag.php +++ b/modules/tag/helpers/tag.php @@ -127,4 +127,24 @@ class tag_Core { $group->submit("")->value(t("Delete Tag")); return $form; } + + /** + * Delete all tags associated with an item + */ + static function clear_all($item) { + $db = Database::instance(); + $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " . + "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)"); + $db->delete("items_tags", array("item_id" => "$item->id")); + } + + /** + * Get rid of any tags that have no associated items. + */ + static function compact() { + // @todo There's a potential race condition here which we can solve by adding a lock around + // this and all the cases where we create/update tags. I'm loathe to do that since it's an + // extremely rare case. + Database::instance() ->delete("tags", array("count" => 0)); + } }
\ No newline at end of file diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 0164f556..d13d1340 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -60,11 +60,23 @@ class tag_event_Core { } static function item_deleted($item) { - $db = Database::instance(); - $db->query("UPDATE {tags} SET `count` = `count` - 1 WHERE `count` > 0 " . - "AND `id` IN (SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)"); - $db->query("DELETE FROM {tags} WHERE `count` = 0 AND `id` IN (" . - "SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)"); - $db->delete("items_tags", array("item_id" => "$item->id")); + tag::clear_all($item); + tag::compact(); + } + + static function item_edit_form($item, $form) { + $tag_value = implode("; ", tag::item_tags($item)); + $form->edit_item->input("tags")->label(t("Tags (separate by , or ;)")) + ->value($tag_value); + } + + static function item_edit_form_completed($item, $form) { + tag::clear_all($item); + foreach (preg_split("/[,;]/", $form->edit_item->tags->value) as $tag_name) { + if ($tag_name) { + tag::add($item, $tag_name); + } + } + tag::compact(); } } diff --git a/modules/user/views/login_ajax.html.php b/modules/user/views/login_ajax.html.php index 56a6f111..d697c958 100644 --- a/modules/user/views/login_ajax.html.php +++ b/modules/user/views/login_ajax.html.php @@ -38,7 +38,7 @@ </div> </li> <li> - <a href="#" id="gForgotPasswordLink"><?= t("Forgot your Password?") ?></a> + <a href="#" id="gForgotPasswordLink"><?= t("Forgot Your Password?") ?></a> </li> </ul> </div> |