From f5e6d2ec56844a3f3dc2b5c6cbc27446d07ae1c9 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Sun, 16 Aug 2009 12:18:49 +0800 Subject: [PATCH 1/3] TagFaces bugfix. Signed-off-by: Tim Almdal --- modules/tagfaces/controllers/tagfaces.php | 15 ++++++++++++++- modules/tagfaces/helpers/tagfaces_event.php | 8 ++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/tagfaces/controllers/tagfaces.php b/modules/tagfaces/controllers/tagfaces.php index 6df1ee76..0a4fc4df 100644 --- a/modules/tagfaces/controllers/tagfaces.php +++ b/modules/tagfaces/controllers/tagfaces.php @@ -20,12 +20,25 @@ class tagfaces_Controller extends Controller { public function drawfaces($id) { // Generate the page that allows the user to draw boxes over a photo. - + // Make sure user has access to view and edit the photo. $item = ORM::factory("item", $id); access::required("view", $item); access::required("edit", $item); + // Make sure the item actually has tags on it. + $all_tags = ORM::factory("tag") + ->join("items_tags", "tags.id", "items_tags.tag_id") + ->where("items_tags.item_id", $id) + ->find_all(); + + // If it doesn't, display an error and direct back to the photo. + if (count($all_tags) == 0) { + message::error(t("Please add some tags first.")); + url::redirect(url::abs_site("{$item->type}s/{$item->id}")); + + } + // Create the page. $template = new Theme_View("page.html", "drawfaces"); $template->set_global("item_id", $id); diff --git a/modules/tagfaces/helpers/tagfaces_event.php b/modules/tagfaces/helpers/tagfaces_event.php index af5a6c82..1e876b8b 100644 --- a/modules/tagfaces/helpers/tagfaces_event.php +++ b/modules/tagfaces/helpers/tagfaces_event.php @@ -34,10 +34,14 @@ class tagfaces_event_Core { static function site_menu($menu, $theme) { // Create a menu option for adding face data. + if (!$theme->item()) { + return; + } + $item = $theme->item(); - if ((access::can("view", $item)) && (access::can("edit", $item))) { - if ($item->is_photo()) { + if ($item->is_photo()) { + if ((access::can("view", $item)) && (access::can("edit", $item))) { $menu->get("options_menu") ->append(Menu::factory("link") ->id("tagfaces") From 59ebb08666e9168699b1675992df5db69942cfec Mon Sep 17 00:00:00 2001 From: rWatcher Date: Mon, 17 Aug 2009 03:13:21 +0800 Subject: [PATCH 2/3] Initial commit of ItemChecksum module. Signed-off-by: Tim Almdal --- .../itemchecksum/controllers/itemchecksum.php | 67 +++++++++++++++++++ .../helpers/itemchecksum_installer.php | 27 ++++++++ modules/itemchecksum/module.info | 3 + 3 files changed, 97 insertions(+) create mode 100644 modules/itemchecksum/controllers/itemchecksum.php create mode 100644 modules/itemchecksum/helpers/itemchecksum_installer.php create mode 100644 modules/itemchecksum/module.info diff --git a/modules/itemchecksum/controllers/itemchecksum.php b/modules/itemchecksum/controllers/itemchecksum.php new file mode 100644 index 00000000..b23963e2 --- /dev/null +++ b/modules/itemchecksum/controllers/itemchecksum.php @@ -0,0 +1,67 @@ +where("parent_id", $album_id) + ->where("name", $file_name) + ->find_all(); + + if (count($item) > 0) { + access::required("view_full", $item[0]); + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item[0]->file_path()); + if ($item[0]->is_photo() && file_exists($original_image)) { + print md5_file($original_image); + } else { + print md5_file($item[0]->file_path()); + } + } else { + print md5_file($item[0]->file_path()); + } + } else { + print "0"; + } + } + + public function sha1($album_id, $file_name) { + + $item = ORM::factory("item") + ->where("parent_id", $album_id) + ->where("name", $file_name) + ->find_all(); + + if (count($item) > 0) { + access::required("view_full", $item[0]); + if (module::is_active("keeporiginal")) { + $original_image = VARPATH . "original/" . str_replace(VARPATH . "albums/", "", $item[0]->file_path()); + if ($item[0]->is_photo() && file_exists($original_image)) { + print sha1_file($original_image); + } else { + print sha1_file($item[0]->file_path()); + } + } else { + print sha1_file($item[0]->file_path()); + } + } else { + print "0"; + } + } +} diff --git a/modules/itemchecksum/helpers/itemchecksum_installer.php b/modules/itemchecksum/helpers/itemchecksum_installer.php new file mode 100644 index 00000000..94e78bf1 --- /dev/null +++ b/modules/itemchecksum/helpers/itemchecksum_installer.php @@ -0,0 +1,27 @@ + Date: Mon, 17 Aug 2009 03:26:02 +0800 Subject: [PATCH 3/3] Added a URL for displaying the number of items in an album (excluding sub-albums). Signed-off-by: Tim Almdal --- modules/itemchecksum/controllers/itemchecksum.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/itemchecksum/controllers/itemchecksum.php b/modules/itemchecksum/controllers/itemchecksum.php index b23963e2..b8b72afc 100644 --- a/modules/itemchecksum/controllers/itemchecksum.php +++ b/modules/itemchecksum/controllers/itemchecksum.php @@ -18,6 +18,16 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class itemchecksum_Controller extends Controller { + public function albumcount($album_id) { + $item = ORM::factory("item") + ->viewable() + ->where("parent_id", $album_id) + ->where("type !=", "album") + ->find_all(); + + print count($item); + } + public function md5($album_id, $file_name) { $item = ORM::factory("item") ->where("parent_id", $album_id)