summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2009-05-26 14:43:31 +0000
committerTim Almdal <tnalmdal@shaw.ca>2009-05-26 14:43:31 +0000
commit908618960b831fa153d3a2a6de8ab30fc7f4430b (patch)
treec9f575e9f48b0962d98f8438ce636d9a83451150
parent7e5e70548b52462a2f91f3a06cadde7198ea8f6e (diff)
Since organize is now in the preview stage and will probably be
rewritten by beta2, pull all of its "tenticles" back into itself and out of core or tags module.
-rw-r--r--core/controllers/core_organize.php99
-rw-r--r--core/helpers/core_event.php18
-rw-r--r--modules/organize/controllers/organize.php213
-rw-r--r--modules/organize/helpers/organize.php (renamed from core/helpers/core_organize.php)33
-rw-r--r--modules/tag/controllers/tags.php116
-rw-r--r--modules/tag/helpers/tag.php23
-rw-r--r--modules/tag/helpers/tag_event.php5
7 files changed, 240 insertions, 267 deletions
diff --git a/core/controllers/core_organize.php b/core/controllers/core_organize.php
deleted file mode 100644
index ca73076d..00000000
--- a/core/controllers/core_organize.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Core_Organize_Controller extends Controller {
- public function general() {
- access::verify_csrf();
-
- $itemids = Input::instance()->post("item");
- $item = ORM::factory("item")
- ->in("id", $itemids[0])
- ->find();
- access::required("edit", $item);
-
- $form = core_organize::get_general_edit_form($item);
- if ($form->validate()) {
- $orig = clone $item;
- $item->title = $form->title->value;
- $item->description = $form->description->value;
- $item->rename($form->dirname->value);
- $item->save();
-
- module::event("item_updated", $orig, $item);
-
- if ($item->is_album()) {
- log::success("content", "Updated album", "<a href=\"albums/$item->id\">view</a>");
- $message = t("Saved album %album_title", array("album_title" => $item->title));
- } else {
- log::success("content", "Updated photo", "<a href=\"photos/$item->id\">view</a>");
- $message = t("Saved photo %photo_title", array("photo_title" => $item->title));
- }
- print json_encode(array("form" => $form->__toString(), "message" => $message));
- } else {
- print json_encode(array("form" => $form->__toString()));
- }
- }
-
- public function sort() {
- access::verify_csrf();
-
- $itemids = Input::instance()->post("item");
- $item = ORM::factory("item")
- ->in("id", $itemids[0])
- ->find();
- access::required("edit", $item);
-
- $form = core_organize::get_sort_edit_form($item);
- if ($form->validate()) {
- $orig = clone $item;
- $item->sort_column = $form->column->value;
- $item->sort_order = $form->direction->value;
- $item->save();
-
- module::event("item_updated", $orig, $item);
-
- log::success("content", "Updated album", "<a href=\"albums/$item->id\">view</a>");
- $message = t("Saved album %album_title", array("album_title" => $item->title));
- print json_encode(array("form" => $form->__toString(), "message" => $message));
- } else {
- print json_encode(array("form" => $form->__toString()));
- }
- }
-
- public function reset_general() {
- $itemids = Input::instance()->get("item");
- $item = ORM::factory("item")
- ->in("id", $itemids[0])
- ->find();
- access::required("edit", $item);
-
- print core_organize::get_general_edit_form($item);
- }
-
- public function reset_sort() {
- $itemids = Input::instance()->get("item");
- $item = ORM::factory("item")
- ->in("id", $itemids[0])
- ->find();
- access::required("edit", $item);
-
- print core_organize::get_sort_edit_form($item);
- }
-
-}
diff --git a/core/helpers/core_event.php b/core/helpers/core_event.php
index 2116eb78..bbb53cc9 100644
--- a/core/helpers/core_event.php
+++ b/core/helpers/core_event.php
@@ -35,24 +35,6 @@ class core_event_Core {
access::delete_item($item);
}
- static function organize_form_creation($event_parms) {
- if (count($event_parms->itemids) > 1) {
- return ;
- }
-
- $item = ORM::factory("item")
- ->in("id", $event_parms->itemids[0])
- ->find();
-
- $event_parms->panes[] = array("label" => $item->is_album() ? t("Edit Album") : t("Edit Photo"),
- "content" => core_organize::get_general_edit_form($item));
-
- if ($item->is_album()) {
- $event_parms->panes[] = array("label" => t("Sort Order"),
- "content" => core_organize::get_sort_edit_form($item));
- }
- }
-
static function user_login($user) {
// If this user is an admin, check to see if there are any post-install tasks that we need
// to run and take care of those now.
diff --git a/modules/organize/controllers/organize.php b/modules/organize/controllers/organize.php
index f2827d30..7df7d52f 100644
--- a/modules/organize/controllers/organize.php
+++ b/modules/organize/controllers/organize.php
@@ -212,13 +212,224 @@ class Organize_Controller extends Controller {
$event_parms->panes = array();
$event_parms->itemids = $this->input->get("item");;
- module::event("organize_form_creation", $event_parms);
+ // The following code should be done more dynamically i.e. use the event mechanism
+ if (count($event_parms->itemids) == 1) {
+ $item = ORM::factory("item")
+ ->in("id", $event_parms->itemids[0])
+ ->find();
+
+ $event_parms->panes[] = array("label" => $item->is_album() ? t("Edit Album") : t("Edit Photo"),
+ "content" => organize::get_general_edit_form($item));
+
+ if ($item->is_album()) {
+ $event_parms->panes[] = array("label" => t("Sort Order"),
+ "content" => organize::get_sort_edit_form($item));
+ }
+ }
+
+ $event_parms->panes[] = array("label" => t("Manage Tags"),
+ "content" => organize::get_tag_form($event_parms->itemids));
$v = new View("organize_edit.html");
$v->panes = $event_parms->panes;
print $v->render();
}
+ // Handlers for the album/photo edit. Probably should be in core
+ public function general() {
+ access::verify_csrf();
+
+ $itemids = $this->input->post("item");
+ $item = ORM::factory("item")
+ ->in("id", $itemids[0])
+ ->find();
+ access::required("edit", $item);
+
+ $form = organize::get_general_edit_form($item);
+ if ($form->validate()) {
+ $orig = clone $item;
+ $item->title = $form->title->value;
+ $item->description = $form->description->value;
+ $item->rename($form->dirname->value);
+ $item->save();
+
+ module::event("item_updated", $orig, $item);
+
+ if ($item->is_album()) {
+ log::success("content", "Updated album", "<a href=\"albums/$item->id\">view</a>");
+ $message = t("Saved album %album_title", array("album_title" => $item->title));
+ } else {
+ log::success("content", "Updated photo", "<a href=\"photos/$item->id\">view</a>");
+ $message = t("Saved photo %photo_title", array("photo_title" => $item->title));
+ }
+ print json_encode(array("form" => $form->__toString(), "message" => $message));
+ } else {
+ print json_encode(array("form" => $form->__toString()));
+ }
+ }
+
+ public function reset_general() {
+ $itemids = Input::instance()->get("item");
+ $item = ORM::factory("item")
+ ->in("id", $itemids[0])
+ ->find();
+ access::required("edit", $item);
+
+ print organize::get_general_edit_form($item);
+ }
+
+ public function sort() {
+ access::verify_csrf();
+
+ $itemids = $this->input->post("item");
+ $item = ORM::factory("item")
+ ->in("id", $itemids[0])
+ ->find();
+ access::required("edit", $item);
+
+ $form = organize::get_sort_edit_form($item);
+ if ($form->validate()) {
+ $orig = clone $item;
+ $item->sort_column = $form->column->value;
+ $item->sort_order = $form->direction->value;
+ $item->save();
+
+ module::event("item_updated", $orig, $item);
+
+ log::success("content", "Updated album", "<a href=\"albums/$item->id\">view</a>");
+ $message = t("Saved album %album_title", array("album_title" => $item->title));
+ print json_encode(array("form" => $form->__toString(), "message" => $message));
+ } else {
+ print json_encode(array("form" => $form->__toString()));
+ }
+ }
+
+ public function reset_sort() {
+ $itemids = Input::instance()->get("item");
+ $item = ORM::factory("item")
+ ->in("id", $itemids[0])
+ ->find();
+ access::required("edit", $item);
+
+ print organize::get_sort_edit_form($item);
+ }
+
+ public function edit_tags() {
+ access::verify_csrf();
+
+ $itemids = explode("|", $this->input->post("item"));
+ $form = organize::get_tag_form($itemids);
+ $old_tags = $form->tags->value;
+ if ($form->validate()) {
+
+ $old_tags = preg_split("/[;,\s]+/", $old_tags);
+ sort($old_tags);
+ $new_tags = preg_split("/[;,\s]+/", $form->tags->value);
+ sort($new_tags);
+
+ $HIGH_VALUE_STRING = "\256";
+ for ($old_index = $new_index = 0;;) {
+ $old_tag = $old_index >= count($old_tags) ? $HIGH_VALUE_STRING : $old_tags[$old_index];
+ $new_tag = $new_index >= count($new_tags) ? $HIGH_VALUE_STRING : $new_tags[$new_index];
+ if ($old_tag == $HIGH_VALUE_STRING && $new_tag == $HIGH_VALUE_STRING) {
+ break;
+ }
+ $matches = array();
+ $old_star = false;
+ if (preg_match("/(.*)(\*)$/", $old_tag, $matches)) {
+ $old_star = true;
+ $old_tag = $matches[1];
+ }
+ $new_star = false;
+ if (preg_match("/(.*)(\*)$/", $new_tag, $matches)) {
+ $new_star = true;
+ $new_tag = $matches[1];
+ }
+ if ($old_tag > $new_tag) {
+ // Its missing in the old list so add it
+ $this->_add_tag($new_tag, $itemids);
+ $new_index++;
+ } else if ($old_tag < $new_tag) {
+ // Its missing in the new list so its been removed
+ $this->_delete_tag($old_tag, $itemids);
+ $old_index++;
+ } else {
+ if ($old_star && !$new_star) {
+ // User wants tag to apply to all items, originally only on some of selected
+ $this->_update_tag($old_tag, $itemids);
+ } // Not changed ignore
+ $old_index++;
+ $new_index++;
+ }
+ }
+ }
+ print json_encode(array("form" => $form->__toString(), "message" => t("Tags updated")));
+ }
+
+ public function reset_edit_tags() {
+ $itemids = $this->input->get("item");
+
+ print organize::get_tag_form($itemids);
+ }
+
+ private function _add_tag($new_tag, $itemids) {
+ $tag = ORM::factory("tag")
+ ->where("name", $new_tag)
+ ->find();
+ if ($tag->loaded) {
+ $tag->count += count($itemids);
+ } else {
+ $tag->name = $new_tag;
+ $tag->count = count($itemids);
+ }
+ $tag->save();
+
+ $db = Database::instance();
+ foreach ($itemids as $item_id) {
+ $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};");
+ }
+ }
+
+ private function _delete_tag($new_tag, $itemids) {
+ $tag = ORM::factory("tag")
+ ->where("name", $new_tag)
+ ->find();
+ $tag->count -= count($itemids);
+ if ($tag->count > 0) {
+ $tag->save();
+ } else {
+ $tag->delete();
+ }
+
+ $ids = implode(", ", $itemids);
+ Database::instance()->query(
+ "DELETE FROM {items_tags} WHERE tag_id = {$tag->id} AND item_id IN ($ids);");
+ }
+
+ private function _update_tag($new_tag, $itemids) {
+ $tag = ORM::factory("tag")
+ ->where("name", $new_tag)
+ ->find();
+
+ $db = Database::instance();
+ $ids = implode(", ", $itemids);
+ $result = $db->query(
+ "SELECT item_id FROM {items_tags}
+ WHERE tag_id = {$tag->id}
+ AND item_id IN ($ids)");
+
+ $add_items = array_fill_keys($itemids, 1);
+ foreach($result as $row) {
+ unset($add_items[$row->item_id]);
+ }
+ $add_items = array_keys($add_items);
+ $tag->count += count($add_items);
+ $tag->save();
+ foreach ($add_items as $item_id) {
+ $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};");
+ }
+ }
+
private function _getOperationDefinition($item, $operation) {
switch ($operation) {
case "move":
diff --git a/core/helpers/core_organize.php b/modules/organize/helpers/organize.php
index 585e8253..3a207c95 100644
--- a/core/helpers/core_organize.php
+++ b/modules/organize/helpers/organize.php
@@ -17,10 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
-class core_organize_Core {
+class organize_Core {
static function get_general_edit_form($item) {
- $generalPane = new Forge("core_organize/__FUNCTION__", "", "post",
+ $generalPane = new Forge("organize/__FUNCTION__", "", "post",
array("id" => "gEditGeneral", "ref" => "general"));
// In this case we know there is only 1 item, but in general we should loop
// and create multiple hidden items.
@@ -39,7 +38,7 @@ class core_organize_Core {
}
static function get_sort_edit_form($item) {
- $sortPane = new Forge("core_organize/__FUNCTION__", "", "post",
+ $sortPane = new Forge("organize/__FUNCTION__", "", "post",
array("id" => "gEditSort", "ref" => "sort"));
$sortPane->hidden("item[]")->value($item->id);
$sortPane->dropdown("column", array("id" => "gAlbumSortColumn"))
@@ -60,4 +59,28 @@ class core_organize_Core {
return $sortPane;
}
-}
+
+ static function get_tag_form($itemids) {
+ $tagPane = new Forge("organize/__FUNCTION__", "", "post",
+ array("id" => "gEditTags", "ref" => "edit_tags"));
+ $tagPane->hidden("item")->value(implode("|", $itemids));
+ $item_count = count($itemids);
+ $ids = implode(", ", $itemids);
+ $tags = Database::instance()->query(
+ "SELECT t.name, COUNT(it.item_id) as count
+ FROM {items_tags} it, {tags} t
+ WHERE it.tag_id = t.id
+ AND it.item_id in($ids)
+ GROUP BY it.tag_id
+ ORDER BY t.name ASC");
+ $taglist = array();
+ foreach ($tags as $tag) {
+ $taglist[] = $tag->name . ($item_count > $tag->count ? "*" : "");
+ }
+ $taglist = implode("; ", $taglist);
+ $tagPane->textarea("tags")->label(t("Tags"))->value($taglist);
+
+ return $tagPane;
+ }
+
+} \ No newline at end of file
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 5e42526d..9090e51d 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -76,120 +76,4 @@ class Tags_Controller extends REST_Controller {
return tag::get_add_form($item);
}
-
- public function organize() {
- access::verify_csrf();
-
- $itemids = explode("|", Input::instance()->post("item"));
- $form = tag::get_organize_form($itemids);
- $old_tags = $form->tags->value;
- if ($form->validate()) {
-
- $old_tags = preg_split("/[;,\s]+/", $old_tags);
- sort($old_tags);
- $new_tags = preg_split("/[;,\s]+/", $form->tags->value);
- sort($new_tags);
-
- $HIGH_VALUE_STRING = "\256";
- for ($old_index = $new_index = 0;;) {
- $old_tag = $old_index >= count($old_tags) ? $HIGH_VALUE_STRING : $old_tags[$old_index];
- $new_tag = $new_index >= count($new_tags) ? $HIGH_VALUE_STRING : $new_tags[$new_index];
- if ($old_tag == $HIGH_VALUE_STRING && $new_tag == $HIGH_VALUE_STRING) {
- break;
- }
- $matches = array();
- $old_star = false;
- if (preg_match("/(.*)(\*)$/", $old_tag, $matches)) {
- $old_star = true;
- $old_tag = $matches[1];
- }
- $new_star = false;
- if (preg_match("/(.*)(\*)$/", $new_tag, $matches)) {
- $new_star = true;
- $new_tag = $matches[1];
- }
- if ($old_tag > $new_tag) {
- // Its missing in the old list so add it
- $this->_add_tag($new_tag, $itemids);
- $new_index++;
- } else if ($old_tag < $new_tag) {
- // Its missing in the new list so its been removed
- $this->_delete_tag($old_tag, $itemids);
- $old_index++;
- } else {
- if ($old_star && !$new_star) {
- // User wants tag to apply to all items, originally only on some of selected
- $this->_update_tag($old_tag, $itemids);
- } // Not changed ignore
- $old_index++;
- $new_index++;
- }
- }
- }
- print json_encode(array("form" => $form->__toString(), "message" => t("Tags updated")));
- }
-
- public function reset_organize() {
- $itemids = Input::instance()->get("item");
-
- print tag::get_organize_form($itemids);
- }
-
- private function _add_tag($new_tag, $itemids) {
- $tag = ORM::factory("tag")
- ->where("name", $new_tag)
- ->find();
- if ($tag->loaded) {
- $tag->count += count($itemids);
- } else {
- $tag->name = $new_tag;
- $tag->count = count($itemids);
- }
- $tag->save();
-
- $db = Database::instance();
- foreach ($itemids as $item_id) {
- $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};");
- }
- }
-
- private function _delete_tag($new_tag, $itemids) {
- $tag = ORM::factory("tag")
- ->where("name", $new_tag)
- ->find();
- $tag->count -= count($itemids);
- if ($tag->count > 0) {
- $tag->save();
- } else {
- $tag->delete();
- }
-
- $ids = implode(", ", $itemids);
- Database::instance()->query(
- "DELETE FROM {items_tags} WHERE tag_id = {$tag->id} AND item_id IN ($ids);");
- }
-
- private function _update_tag($new_tag, $itemids) {
- $tag = ORM::factory("tag")
- ->where("name", $new_tag)
- ->find();
-
- $db = Database::instance();
- $ids = implode(", ", $itemids);
- $result = $db->query(
- "SELECT item_id FROM {items_tags}
- WHERE tag_id = {$tag->id}
- AND item_id IN ($ids)");
-
- $add_items = array_fill_keys($itemids, 1);
- foreach($result as $row) {
- unset($add_items[$row->item_id]);
- }
- $add_items = array_keys($add_items);
- $tag->count += count($add_items);
- $tag->save();
- foreach ($add_items as $item_id) {
- $db->query("INSERT INTO {items_tags} SET item_id = $item_id, tag_id = {$tag->id};");
- }
- }
}
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index 50c4b41a..0ca02b42 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -104,27 +104,4 @@ class tag_Core {
$group->submit("")->value(t("Delete Tag"));
return $form;
}
-
- static function get_organize_form($itemids) {
- $tagPane = new Forge("tags/__FUNCTION__", "", "post",
- array("id" => "gEditTags", "ref" => "organize"));
- $tagPane->hidden("item")->value(implode("|", $itemids));
- $item_count = count($itemids);
- $ids = implode(", ", $itemids);
- $tags = Database::instance()->query(
- "SELECT t.name, COUNT(it.item_id) as count
- FROM {items_tags} it, {tags} t
- WHERE it.tag_id = t.id
- AND it.item_id in($ids)
- GROUP BY it.tag_id
- ORDER BY t.name ASC");
- $taglist = array();
- foreach ($tags as $tag) {
- $taglist[] = $tag->name . ($item_count > $tag->count ? "*" : "");
- }
- $taglist = implode("; ", $taglist);
- $tagPane->textarea("tags")->label(t("Tags"))->value($taglist);
-
- return $tagPane;
- }
} \ No newline at end of file
diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php
index 2a08cb6d..735422b5 100644
--- a/modules/tag/helpers/tag_event.php
+++ b/modules/tag/helpers/tag_event.php
@@ -59,9 +59,4 @@ class tag_event_Core {
"SELECT `tag_id` from {items_tags} WHERE `item_id` = $item->id)");
$db->delete("items_tags", array("item_id" => "$item->id"));
}
-
- static function organize_form_creation($event_parms) {
- $event_parms->panes[] = array("label" => t("Manage Tags"),
- "content" => tag::get_organize_form($event_parms->itemids));
- }
}