summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-07-11 09:09:52 -0700
committerTim Almdal <tnalmdal@shaw.ca>2010-07-11 09:09:52 -0700
commit329abfe539371b65c95e3334e436f997ec92879f (patch)
tree0a3ee6e19be8563af6b6b6d87db795a0e6f463e2 /modules
parent213807a8073138a98b8daf9fe265e981454aaa50 (diff)
parent0389dceb475597ecdedf519d27d6d7bb36aa6276 (diff)
Merge branch 'master' into talmdal_dev
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/controllers/file_proxy.php4
-rw-r--r--modules/gallery/controllers/flash_uploader.php4
-rw-r--r--modules/gallery/controllers/quick.php30
-rw-r--r--modules/gallery/helpers/album.php2
-rw-r--r--modules/gallery/helpers/gallery_event.php55
-rw-r--r--modules/gallery/helpers/item.php4
-rw-r--r--modules/gallery/helpers/movie.php2
-rw-r--r--modules/gallery/libraries/ORM_MPTT.php3
-rw-r--r--modules/gallery/models/item.php2
-rw-r--r--modules/gallery/views/form_uploadify.html.php2
-rw-r--r--modules/organize/controllers/organize.php2
-rw-r--r--modules/server_add/controllers/server_add.php10
12 files changed, 80 insertions, 40 deletions
diff --git a/modules/gallery/controllers/file_proxy.php b/modules/gallery/controllers/file_proxy.php
index 32690fc0..bead9f3f 100644
--- a/modules/gallery/controllers/file_proxy.php
+++ b/modules/gallery/controllers/file_proxy.php
@@ -72,10 +72,10 @@ class File_Proxy_Controller extends Controller {
// necessary, it's easily resurrected.
// If we're looking for a .jpg then it's it's possible that we're requesting the thumbnail
- // for a movie. In that case, the .flv or .mp4 file would have been converted to a .jpg.
+ // for a movie. In that case, the .flv, .mp4 or .m4v file would have been converted to a .jpg.
// So try some alternate types:
if (preg_match('/.jpg$/', $path)) {
- foreach (array("flv", "mp4") as $ext) {
+ foreach (array("flv", "mp4", "m4v") as $ext) {
$movie_path = preg_replace('/.jpg$/', ".$ext", $encoded_path);
$item = ORM::factory("item")->where("relative_path_cache", "=", $movie_path)->find();
if ($item->loaded()) {
diff --git a/modules/gallery/controllers/flash_uploader.php b/modules/gallery/controllers/flash_uploader.php
index be3896cd..6bfdd851 100644
--- a/modules/gallery/controllers/flash_uploader.php
+++ b/modules/gallery/controllers/flash_uploader.php
@@ -51,7 +51,7 @@ class Flash_Uploader_Controller extends Controller {
// Uploadify adds its own field to the form, so validate that separately.
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
- "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4]");
+ "Filedata", "upload::valid", "upload::required", "upload::type[gif,jpg,jpeg,png,flv,mp4,m4v]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
@@ -64,7 +64,7 @@ class Flash_Uploader_Controller extends Controller {
$path_info = @pathinfo($temp_filename);
if (array_key_exists("extension", $path_info) &&
- in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
+ in_array(strtolower($path_info["extension"]), array("flv", "mp4", "m4v"))) {
$item->type = "movie";
$item->save();
log::success("content", t("Added a movie"),
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index 7df5bf18..253a279b 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -46,13 +46,14 @@ class Quick_Controller extends Controller {
graphics::generate($item);
- $parent = $item->parent();
- // @todo: this is an inadequate way to regenerate the parent's thumbnail after rotation.
- if ($parent->album_cover_item_id == $item->id) {
- copy($item->thumb_path(), $parent->thumb_path());
- $parent->thumb_width = $item->thumb_width;
- $parent->thumb_height = $item->thumb_height;
- $parent->save();
+ // @todo: this is an inadequate way to regenerate album cover thumbnails after rotation.
+ foreach (ORM::factory("item")
+ ->where("album_cover_item_id", "=", $item->id)
+ ->find_all() as $target) {
+ copy($item->thumb_path(), $target->thumb_path());
+ $target->thumb_width = $item->thumb_width;
+ $target->thumb_height = $item->thumb_height;
+ $target->save();
}
}
@@ -109,10 +110,21 @@ class Quick_Controller extends Controller {
}
$parent = $item->parent();
- $item->delete();
+
+ if ($item->is_album()) {
+ // Album delete will trigger deletes for all children. Do this in a batch so that we can be
+ // smart about notifications, album cover updates, etc.
+ batch::start();
+ $item->delete();
+ batch::stop();
+ } else {
+ $item->delete();
+ }
message::success($msg);
- if (Input::instance()->get("page_type") == "collection") {
+ $from_id = Input::instance()->get("from_id");
+ if (Input::instance()->get("page_type") == "collection" &&
+ $from_id != $id /* deleted the item we were viewing */) {
print json_encode(array("result" => "success", "reload" => 1));
} else {
print json_encode(array("result" => "success",
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index 0baae631..0ac5e8b0 100644
--- a/modules/gallery/helpers/album.php
+++ b/modules/gallery/helpers/album.php
@@ -58,7 +58,7 @@ class album_Core {
static function get_edit_form($parent) {
$form = new Forge(
"albums/update/{$parent->id}", "", "post", array("id" => "g-edit-album-form"));
- $form->hidden("from_id");
+ $form->hidden("from_id")->value($parent->id);
$group = $form->group("edit_item")->label(t("Edit Album"));
$group->input("title")->label(t("Title"))->value($parent->title)
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 272fd205..76bd9ee7 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -109,18 +109,44 @@ class gallery_event_Core {
$parent = $item->parent();
if (!$parent->album_cover_item_id) {
- // Assume we deleted the album cover and pick a new one. Choosing the first photo in the
- // album is logical, but it's not the most efficient in the case where we're deleting all
- // the photos in the album one at a time since we'll probably delete them in order which
- // means that we'll be resetting the album cover each time.
- if ($child = $parent->children(1)->current()) {
- item::make_album_cover($child);
+ // Assume that we deleted the album cover
+ if (batch::in_progress()) {
+ // Remember that this parent is missing an album cover, for later.
+ $batch_missing_album_cover = Session::instance()->get("batch_missing_album_cover", array());
+ $batch_missing_album_cover[$parent->id] = 1;
+ Session::instance()->set("batch_missing_album_cover", $batch_missing_album_cover);
+ } else {
+ // Choose the first child as the new cover.
+ if ($child = $parent->children(1)->current()) {
+ item::make_album_cover($child);
+ }
}
}
}
+ static function batch_complete() {
+ // Set the album covers for any items that where we probably deleted the album cover during
+ // this batch. The item may have been deleted, so don't count on it being around. Choose the
+ // first child as the new album cover.
+ // NOTE: if the first child doesn't have an album cover, then this won't work.
+ foreach (array_keys(Session::instance()->get("batch_missing_album_cover", array())) as $id) {
+ $item = ORM::factory("item", $id);
+ if ($item->loaded() && !$item->album_cover_item_id) {
+ if ($child = $item->children(1)->current()) {
+ item::make_album_cover($child);
+ }
+ }
+ }
+ Session::instance()->delete("batch_missing_album_cover");
+ }
+
static function item_moved($item, $old_parent) {
access::recalculate_permissions($item->parent());
+
+ // If the new parent doesn't have an album cover, make this it.
+ if (!$item->parent()->album_cover_item_id) {
+ item::make_album_cover($item);
+ }
}
static function user_login($user) {
@@ -249,7 +275,7 @@ class gallery_event_Core {
$options_menu->append(Menu::factory("dialog")
->id("edit_item")
->label($edit_text)
- ->url(url::site("form/edit/{$item->type}s/$item->id")));
+ ->url(url::site("form/edit/{$item->type}s/$item->id?from_id={$item->id}")));
}
if ($item->is_album()) {
@@ -263,7 +289,6 @@ class gallery_event_Core {
}
$csrf = access::csrf_token();
- $theme_item = $theme->item();
$page_type = $theme->page_type();
if ($can_edit && $item->is_photo() && graphics::can("rotate")) {
$options_menu
@@ -274,7 +299,7 @@ class gallery_event_Core {
->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")))
+ ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&amp;from_id={$item->id}&amp;page_type=$page_type")))
->append(
Menu::factory("ajax_link")
->id("rotate_cw")
@@ -282,7 +307,7 @@ class gallery_event_Core {
->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")));
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&amp;from_id={$item->id}&amp;page_type=$page_type")));
}
if ($item->id != item::root()->id) {
@@ -315,7 +340,7 @@ class gallery_event_Core {
->label($delete_text)
->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")));
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&amp;from_id={$item->id}&amp;page_type=$page_type")));
}
}
}
@@ -416,7 +441,7 @@ class gallery_event_Core {
->id("edit")
->label($edit_title)
->css_class("ui-icon-pencil")
- ->url(url::site("quick/form_edit/$item->id?from_id=$theme_item->id")));
+ ->url(url::site("quick/form_edit/$item->id?from_id={$theme_item->id}")));
if ($item->is_photo() && graphics::can("rotate")) {
$options_menu
@@ -427,7 +452,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&amp;from_id=$theme_item->id&amp;page_type=$page_type")))
+ ->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")
@@ -435,7 +460,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&amp;from_id=$theme_item->id&amp;page_type=$page_type")));
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&amp;from_id={$theme_item->id}&amp;page_type=$page_type")));
}
// @todo Don't move photos from the photo page; we don't yet have a good way of redirecting
@@ -474,7 +499,7 @@ class gallery_event_Core {
->id("delete")
->label($delete_title)
->css_class("ui-icon-trash")
- ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&amp;from_id=$theme_item->id&amp;page_type=$page_type")));
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&amp;from_id={$theme_item->id}&amp;page_type=$page_type")));
}
if ($item->is_album()) {
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index aef68c6e..8fea49cc 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -158,8 +158,10 @@ class item_Core {
*/
static function get_delete_form($item) {
$page_type = Input::instance()->get("page_type");
+ $from_id = Input::instance()->get("from_id");
$form = new Forge(
- "quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete"));
+ "quick/delete/$item->id?page_type=$page_type&from_id=$from_id", "",
+ "post", array("id" => "g-confirm-delete"));
$group = $form->group("confirm_delete")->label(t("Confirm Deletion"));
$group->submit("")->value(t("Delete"));
$form->script("")
diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php
index 6333eaf2..bbb5b66c 100644
--- a/modules/gallery/helpers/movie.php
+++ b/modules/gallery/helpers/movie.php
@@ -26,7 +26,7 @@
class movie_Core {
static function get_edit_form($movie) {
$form = new Forge("movies/update/$movie->id", "", "post", array("id" => "g-edit-movie-form"));
- $form->hidden("from_id");
+ $form->hidden("from_id")->value($movie->id);
$group = $form->group("edit_item")->label(t("Edit Movie"));
$group->input("title")->label(t("Title"))->value($movie->title)
->error_messages("required", t("You must provide a title"))
diff --git a/modules/gallery/libraries/ORM_MPTT.php b/modules/gallery/libraries/ORM_MPTT.php
index e5b8ecd4..d8d88e4e 100644
--- a/modules/gallery/libraries/ORM_MPTT.php
+++ b/modules/gallery/libraries/ORM_MPTT.php
@@ -92,6 +92,7 @@ class ORM_MPTT_Core extends ORM {
// Deleting children affects the MPTT tree, so we have to reload each child before we
// delete it so that we have current left_ptr/right_ptr pointers. This is inefficient.
// @todo load each child once, not twice.
+ set_time_limit(30);
$item->reload()->delete();
}
@@ -175,7 +176,7 @@ class ORM_MPTT_Core extends ORM {
}
/**
- * Return all of the children of this node, ordered by id.
+ * Return the number of children of this node.
*
* @chainable
* @param array additional where clauses
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 4d05e4da..eb200fa5 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -364,7 +364,7 @@ class Item_Model extends ORM_MPTT {
$this->name .= "." . $pi["extension"];
}
- $this->mime_type = strtolower($pi["extension"]) == "mp4" ? "video/mp4" : "video/x-flv";
+ $this->mime_type = in_array(strtolower($pi["extension"]), array("mp4", "m4v")) ? "video/mp4" : "video/x-flv";
}
}
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 4676fcef..937a37b6 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -9,7 +9,7 @@
uploader: "<?= url::file("lib/uploadify/uploadify.swf") ?>",
script: "<?= url::site("flash_uploader/add_photo/{$album->id}") ?>",
scriptData: <?= json_encode($script_data) ?>,
- fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.flv;*.mp4;*.GIF;*.JPG;*.JPEG;*.PNG;*.FLV;*.MP4",
+ fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.flv;*.mp4;*.m4v;*.GIF;*.JPG;*.JPEG;*.PNG;*.FLV;*.MP4;*.M4V",
fileDesc: <?= t("Photos and movies")->for_js() ?>,
cancelImg: "<?= url::file("lib/uploadify/cancel.png") ?>",
simUploadLimit: <?= $simultaneous_upload_limit ?>,
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php
index ebd40c8d..0e647e09 100644
--- a/modules/organize/controllers/organize.php
+++ b/modules/organize/controllers/organize.php
@@ -34,7 +34,7 @@ class Organize_Controller extends Controller {
$file_filter = json_encode(
array("photo" => array("label" => "Images",
"types" => array("*.jpg", "*.jpeg", "*.png", "*.gif")),
- "movie" => array("label" => "Movies", "types" => array("*.flv", "*.mp4"))));
+ "movie" => array("label" => "Movies", "types" => array("*.flv", "*.mp4", "*.m4v"))));
$v = new View("organize_dialog.html");
$v->album = $album;
diff --git a/modules/server_add/controllers/server_add.php b/modules/server_add/controllers/server_add.php
index d6c2459d..e91d9dd9 100644
--- a/modules/server_add/controllers/server_add.php
+++ b/modules/server_add/controllers/server_add.php
@@ -55,7 +55,7 @@ class Server_Add_Controller extends Admin_Controller {
}
if (!is_dir($file)) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
- if (!in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4"))) {
+ if (!in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4", "m4v"))) {
continue;
}
}
@@ -93,7 +93,7 @@ class Server_Add_Controller extends Admin_Controller {
print json_encode(
array("result" => "started",
- "status" => $task->status,
+ "status" => (string)$task->status,
"url" => url::site("server_add/run/$task->id?csrf=" . access::csrf_token())));
}
@@ -112,7 +112,7 @@ class Server_Add_Controller extends Admin_Controller {
// Prevent the JavaScript code from breaking by forcing a period as
// decimal separator for all locales with sprintf("%F", $value).
print json_encode(array("done" => (bool)$task->done,
- "status" => $task->status,
+ "status" => (string)$task->status,
"percent_complete" => sprintf("%F", $task->percent_complete)));
}
@@ -162,7 +162,7 @@ class Server_Add_Controller extends Admin_Controller {
$queue[] = array($child, $entry_id);
} else {
$ext = strtolower(pathinfo($child, PATHINFO_EXTENSION));
- if (in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4")) &&
+ if (in_array($ext, array("gif", "jpeg", "jpg", "png", "flv", "mp4", "m4v")) &&
filesize($child) > 0) {
$child_entry = ORM::factory("server_add_file");
$child_entry->task_id = $task->id;
@@ -249,7 +249,7 @@ class Server_Add_Controller extends Admin_Controller {
$photo->owner_id = $owner_id;
$photo->save();
$entry->item_id = $photo->id;
- } else if (in_array($extension, array("flv", "mp4"))) {
+ } else if (in_array($extension, array("flv", "mp4", "m4v"))) {
$movie = ORM::factory("item");
$movie->type = "movie";
$movie->parent_id = $parent->id;