summaryrefslogtreecommitdiff
path: root/modules/tag/controllers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2011-08-27 20:56:03 -0700
committerBharat Mediratta <bharat@menalto.com>2011-08-27 20:56:03 -0700
commit084c2717c0ddff6c5caa79c62abb3cdb9b4aea31 (patch)
treeaf0fc03f042d11715cbbb3d137390d7df706ec3c /modules/tag/controllers
parentdc21cf36b606048dc24532407d39bc8f5b4211fa (diff)
parent246f5b59cb0e525a5ff6eaffce6b13e9af7e70b2 (diff)
Merge branch 'master' into bharat_dev
Diffstat (limited to 'modules/tag/controllers')
-rw-r--r--modules/tag/controllers/admin_tags.php31
-rw-r--r--modules/tag/controllers/tag.php62
-rw-r--r--modules/tag/controllers/tags.php3
3 files changed, 75 insertions, 21 deletions
diff --git a/modules/tag/controllers/admin_tags.php b/modules/tag/controllers/admin_tags.php
index 73042a55..77b5f20a 100644
--- a/modules/tag/controllers/admin_tags.php
+++ b/modules/tag/controllers/admin_tags.php
@@ -81,17 +81,25 @@ class Admin_Tags_Controller extends Admin_Controller {
$in_place_edit = InPlaceEdit::factory($tag->name)
->action("admin/tags/rename/$tag->id")
- ->rules(array("required", "length[1,64]"))
- ->messages(array("in_use" => t("There is already a tag with that name")))
- ->callback(array($this, "check_for_duplicate"));
+ ->rules(array("required", "length[1,64]"));
if ($in_place_edit->validate()) {
$old_name = $tag->name;
- $tag->name = $in_place_edit->value();
+ $new_name_or_list = $in_place_edit->value();
+ $tag_list = explode(",", $new_name_or_list);
+
+ $tag->name = array_shift($tag_list);
$tag->save();
- $message = t("Renamed tag <b>%old_name</b> to <b>%new_name</b>",
- array("old_name" => $old_name, "new_name" => $tag->name));
+ if (!empty($tag_list)) {
+ $this->_copy_items_for_tags($tag, $tag_list);
+ $message = t("Split tag <i>%old_name</i> into <i>%tag_list</i>",
+ array("old_name" => $old_name, "tag_list" => $new_name_or_list));
+ } else {
+ $message = t("Renamed tag <i>%old_name</i> to <i>%new_name</i>",
+ array("old_name" => $old_name, "new_name" => $tag->name));
+ }
+
message::success($message);
log::success("tags", $message);
@@ -101,12 +109,11 @@ class Admin_Tags_Controller extends Admin_Controller {
}
}
- public function check_for_duplicate(Validation $post_data, $field) {
- $tag_exists = ORM::factory("tag")->where("name", "=", $post_data[$field])->count_all();
- if ($tag_exists) {
- $post_data->add_error($field, "in_use");
+ private function _copy_items_for_tags($tag, $tag_list) {
+ foreach ($tag->items() as $item) {
+ foreach ($tag_list as $new_tag_name) {
+ tag::add($item, trim($new_tag_name));
+ }
}
}
-
}
-
diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php
index 8f885dea..559e2a5a 100644
--- a/modules/tag/controllers/tag.php
+++ b/modules/tag/controllers/tag.php
@@ -22,7 +22,22 @@ class Tag_Controller extends Controller {
$tag_id = $function;
$tag = ORM::factory("tag")->where("id", "=", $tag_id)->find();
$page_size = module::get_var("gallery", "page_size", 9);
- $page = (int) Input::instance()->get("page", "1");
+
+ $input = Input::instance();
+ $show = $input->get("show");
+
+ if ($show) {
+ $child = ORM::factory("item", $show);
+ $index = tag::get_position($tag, $child);
+ if ($index) {
+ $page = ceil($index / $page_size);
+ $uri = "tag/$tag_id/" . urlencode($tag->name);
+ url::redirect($uri . ($page == 1 ? "" : "?page=$page"));
+ }
+ } else {
+ $page = (int) $input->get("page", "1");
+ }
+
$children_count = $tag->items_count();
$offset = ($page-1) * $page_size;
$max_pages = max(ceil($children_count / $page_size), 1);
@@ -34,16 +49,47 @@ class Tag_Controller extends Controller {
url::redirect(url::merge(array("page" => $max_pages)));
}
+ $root = item::root();
$template = new Theme_View("page.html", "collection", "tag");
- $template->set_global(array("page" => $page,
- "max_pages" => $max_pages,
- "page_size" => $page_size,
- "tag" => $tag,
- "children" => $tag->items($page_size, $offset),
- "children_count" => $children_count));
+ $template->set_global(
+ array("page" => $page,
+ "max_pages" => $max_pages,
+ "page_size" => $page_size,
+ "tag" => $tag,
+ "children" => $tag->items($page_size, $offset),
+ "breadcrumbs" => array(
+ Breadcrumb::instance($root->title, $root->url())->set_first(),
+ Breadcrumb::instance(t("Tag: %tag_name", array("tag_name" => $tag->name)),
+ $tag->url())->set_last()),
+ "children_count" => $children_count));
$template->content = new View("dynamic.html");
$template->content->title = t("Tag: %tag_name", array("tag_name" => $tag->name));
-
print $template;
+
+ item::set_display_context_callback("Tag_Controller::get_display_context", $tag->id);
+ }
+
+ static function get_display_context($item, $tag_id) {
+ $tag = ORM::factory("tag", $tag_id);
+ $where = array(array("type", "!=", "album"));
+
+ $position = tag::get_position($tag, $item, $where);
+ if ($position > 1) {
+ list ($previous_item, $ignore, $next_item) = $tag->items(3, $position - 2, $where);
+ } else {
+ $previous_item = null;
+ list ($next_item) = $tag->items(1, $position, $where);
+ }
+
+ $root = item::root();
+ return array("position" => $position,
+ "previous_item" => $previous_item,
+ "next_item" => $next_item,
+ "sibling_count" => $tag->items_count($where),
+ "breadcrumbs" => array(
+ Breadcrumb::instance($root->title, $root->url())->set_first(),
+ Breadcrumb::instance(t("Tag: %tag_name", array("tag_name" => $tag->name)),
+ $tag->url("show={$item->id}")),
+ Breadcrumb::instance($item->title, $item->url())->set_last()));
}
}
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index fe6d747b..bf41c4df 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -22,7 +22,8 @@ class Tags_Controller extends Controller {
// Far from perfection, but at least require view permission for the root album
$album = ORM::factory("item", 1);
access::required("view", $album);
- print tag::cloud(30);
+
+ print tag::cloud(module::get_var("tag", "tag_cloud_size", 30));
}
public function create($item_id) {