From 7724e8a2bdc1742e0ed1b579bb7117762025e725 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Wed, 16 May 2012 23:15:09 -0400 Subject: [PATCH] Support navigating within virtual albums. --- .../tag_albums/controllers/tag_albums.php | 256 +++++++----------- 1 file changed, 104 insertions(+), 152 deletions(-) diff --git a/3.0/modules/tag_albums/controllers/tag_albums.php b/3.0/modules/tag_albums/controllers/tag_albums.php index f77fa893..5ece12e8 100644 --- a/3.0/modules/tag_albums/controllers/tag_albums.php +++ b/3.0/modules/tag_albums/controllers/tag_albums.php @@ -190,10 +190,109 @@ class tag_albums_Controller extends Controller { print $template; // Set breadcrumbs on the photo pages to point back to the calendar day view. - //item::set_display_context_callback("CalendarView_Controller::get_display_day_context", $display_user, $display_year, $display_month, $display_day); + item::set_display_context_callback("tag_albums_Controller::get_display_context", 0, $id); } } + static function get_display_context($item, $tag_id, $album_id) { + // Make sure #album_id is valid, clear it out if it isn't. + $album_tags = ORM::factory("tags_album_id") + ->where("id", "=", $album_id) + ->find_all(); + if (count($album_tags) == 0) { + $album_id = 0; + } + + // Load the tag and item, make sure the user has access to the item. + $display_tag = ORM::factory("tag", $tag_id); + + // Figure out sort order from module preferences. + $sort_page_field = ""; + $sort_page_direction = ""; + if (($tag_id > 0) || (count($album_tags) == 0)) { + $sort_page_field = module::get_var("tag_albums", "subalbum_sort_by", "title"); + $sort_page_direction = module::get_var("tag_albums", "subalbum_sort_direction", "ASC"); + } else { + $parent_album = ORM::factory("item", $album_tags[0]->album_id); + $sort_page_field = $parent_album->sort_column; + $sort_page_direction = $parent_album->sort_order; + } + + // Load the number of items in the parent album, and determine previous and next items. + $sibling_count = ""; + $tag_children = ""; + $previous_item = ""; + $next_item = ""; + $position = 0; + if ($tag_id > 0) { + $sibling_count = tag_albums_Controller::_count_records(Array($tag_id), "OR", false); + $position = tag_albums_Controller::_get_position($item->$sort_page_field, $item->id, Array($tag_id), "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if ($position > 1) { + $previous_item_object = tag_albums_Controller::_get_records(Array($tag_id), 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($previous_item_object) > 0) { + $previous_item = $previous_item_object[0]; + } + } + $next_item_object = tag_albums_Controller::_get_records(Array($tag_id), 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($next_item_object) > 0) { + $next_item = $next_item_object[0]; + } + } else { + $tag_ids = Array(); + foreach (explode(",", $album_tags[0]->tags) as $tag_name) { + $tag = ORM::factory("tag")->where("name", "=", trim($tag_name))->find(); + if ($tag->loaded()) { + $tag_ids[] = $tag->id; + } + } + $album_tags_search_type = $album_tags[0]->search_type; + $sibling_count = tag_albums_Controller::_count_records($tag_ids, $album_tags_search_type, false); + $position = tag_albums_Controller::_get_position($item->$sort_page_field, $item->id, $tag_ids, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if ($position > 1) { + $previous_item_object = tag_albums_Controller::_get_records($tag_ids, 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($previous_item_object) > 0) { + $previous_item = $previous_item_object[0]; + } + } + $next_item_object = tag_albums_Controller::_get_records($tag_ids, 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); + if (count($next_item_object) > 0) { + $next_item = $next_item_object[0]; + } + + } + + // Set up breadcrumbs + $tag_album_breadcrumbs = Array(); + if ($album_id > 0) { + $counter = 0; + $tag_album_breadcrumbs[] = Breadcrumb::instance($item->title, $item->url())->set_last(); + if ($album_tags[0]->tags == "*") { + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name))); + } + $parent_item = ORM::factory("item", $album_tags[0]->album_id); + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name))); + $parent_item = ORM::factory("item", $parent_item->parent_id); + while ($parent_item->id != 1) { + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url()); + $parent_item = ORM::factory("item", $parent_item->parent_id); + } + $tag_album_breadcrumbs[] = Breadcrumb::instance($parent_item->title, $parent_item->url())->set_first(); + $tag_album_breadcrumbs[1]->url .= "?show=" . $item->id; + $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); + } else { + $tag_album_breadcrumbs[] = Breadcrumb::instance(item::root()->title, item::root()->url())->set_first(); + $tag_album_breadcrumbs[] = Breadcrumb::instance(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); + $tag_album_breadcrumbs[] = Breadcrumb::instance($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)) . "?show=" . $item->id); + $tag_album_breadcrumbs[] = Breadcrumb::instance($item->title, $item->url())->set_last(); + } + + return array("position" => $position, + "previous_item" => $previous_item, + "next_item" => $next_item, + "sibling_count" => $sibling_count, + "breadcrumbs" => $tag_album_breadcrumbs); + } + public function filter($id, $filter) { // Display the index page, but only show albums for // tags whose name begins with $filter. @@ -580,162 +679,15 @@ class tag_albums_Controller extends Controller { $template->set_global("all_siblings", $this->_get_records(Array($id), $count, 0, "items." . $sort_page_field, $sort_page_direction, "OR", false)); $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. print $template; + + // Set breadcrumbs on the photo pages to point back to the calendar day view. + item::set_display_context_callback("tag_albums_Controller::get_display_context", $id, $album_id); } public function show($item_id, $tag_id, $album_id) { + item::set_display_context_callback("tag_albums_Controller::get_display_context", $tag_id, $album_id); $item = ORM::factory("item", $item_id); url::redirect(url::abs_site("{$item->type}s/{$item->id}")); - // Display the specified photo or video ($item_id) with breadcrumbs - // that point back to a virtual album ($tag_id / $album_id). - - // Make sure #album_id is valid, clear it out if it isn't. - $album_tags = ORM::factory("tags_album_id") - ->where("id", "=", $album_id) - ->find_all(); - if (count($album_tags) == 0) { - $album_id = 0; - } - - // Load the tag and item, make sure the user has access to the item. - $display_tag = ORM::factory("tag", $tag_id); - $item = ORM::factory("item", $item_id); - access::required("view", $item); - $parent_url = ""; - - // Figure out sort order from module preferences. - $sort_page_field = ""; - $sort_page_direction = ""; - if (($tag_id > 0) || (count($album_tags) == 0)) { - $sort_page_field = module::get_var("tag_albums", "subalbum_sort_by", "title"); - $sort_page_direction = module::get_var("tag_albums", "subalbum_sort_direction", "ASC"); - } else { - $parent_album = ORM::factory("item", $album_tags[0]->album_id); - $sort_page_field = $parent_album->sort_column; - $sort_page_direction = $parent_album->sort_order; - } - - // Load the number of items in the parent album, and determine previous and next items. - $sibling_count = ""; - $tag_children = ""; - $previous_item = ""; - $next_item = ""; - $position = 0; - $dynamic_siblings = ""; - if ($tag_id > 0) { - $sibling_count = $this->_count_records(Array($tag_id), "OR", false); - $position = $this->_get_position($item->$sort_page_field, $item->id, Array($tag_id), "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if ($position > 1) { - $previous_item_object = $this->_get_records(Array($tag_id), 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($previous_item_object) > 0) { - $previous_item = new Tag_Albums_Item($previous_item_object[0]->title, url::site("tag_albums/show/" . $previous_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($previous_item_object[0]->name)), $previous_item_object[0]->type, $previous_item_object[0]->id); - } - } - $next_item_object = $this->_get_records(Array($tag_id), 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($next_item_object) > 0) { - $next_item = new Tag_Albums_Item($next_item_object[0]->title, url::site("tag_albums/show/" . $next_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($next_item_object[0]->name)), $next_item_object[0]->type, $next_item_object[0]->id); - } - $dynamic_siblings = $this->_get_records(Array($tag_id), null, null, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - } else { - $tag_ids = Array(); - foreach (explode(",", $album_tags[0]->tags) as $tag_name) { - $tag = ORM::factory("tag")->where("name", "=", trim($tag_name))->find(); - if ($tag->loaded()) { - $tag_ids[] = $tag->id; - } - } - $album_tags_search_type = $album_tags[0]->search_type; - $sibling_count = $this->_count_records($tag_ids, $album_tags_search_type, false); - $position = $this->_get_position($item->$sort_page_field, $item->id, $tag_ids, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if ($position > 1) { - $previous_item_object = $this->_get_records($tag_ids, 1, $position-2, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($previous_item_object) > 0) { - $previous_item = new Tag_Albums_Item($previous_item_object[0]->title, url::site("tag_albums/show/" . $previous_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($previous_item_object[0]->name)), $previous_item_object[0]->type); - } - } - $next_item_object = $this->_get_records($tag_ids, 1, $position, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - if (count($next_item_object) > 0) { - $next_item = new Tag_Albums_Item($next_item_object[0]->title, url::site("tag_albums/show/" . $next_item_object[0]->id . "/" . $tag_id . "/" . $album_id . "/" . urlencode($next_item_object[0]->name)), $next_item_object[0]->type); - } - $dynamic_siblings = $this->_get_records($tag_ids, null, null, "items." . $sort_page_field, $sort_page_direction, $album_tags_search_type, false); - } - - // Set up breadcrumbs - $tag_album_breadcrumbs = Array(); - if ($album_id > 0) { - $counter = 0; - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($item->title, ""); - if ($album_tags[0]->tags == "*") { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name))); - } - $parent_item = ORM::factory("item", $album_tags[0]->album_id); - if ($album_tags[0]->tags == "*") { - $parent_url = url::site("tag_albums/tag/" . $display_tag->id . "/" . $album_id . "/" . urlencode($display_tag->name)); - } else { - $parent_url = $parent_item->url(); - } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, url::site("tag_albums/album/" . $album_id . "/" . urlencode($parent_item->name))); - $parent_item = ORM::factory("item", $parent_item->parent_id); - while ($parent_item->id != 1) { - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); - $parent_item = ORM::factory("item", $parent_item->parent_id); - } - $tag_album_breadcrumbs[$counter++] = new Tag_Albums_Breadcrumb($parent_item->title, $parent_item->url()); - $tag_album_breadcrumbs[1]->url .= "?show=" . $item->id; - $tag_album_breadcrumbs = array_reverse($tag_album_breadcrumbs, true); - } else { - $tag_album_breadcrumbs[0] = new Tag_Albums_Breadcrumb(item::root()->title, item::root()->url()); - $tag_album_breadcrumbs[1] = new Tag_Albums_Breadcrumb(module::get_var("tag_albums", "tag_page_title", "All Tags"), url::site("tag_albums/")); - $tag_album_breadcrumbs[2] = new Tag_Albums_Breadcrumb($display_tag->name, url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)) . "?show=" . $item->id); - $tag_album_breadcrumbs[3] = new Tag_Albums_Breadcrumb($item->title, ""); - $parent_url = url::site("tag_albums/tag/" . $display_tag->id . "/" . urlencode($display_tag->name)); - } - - // Increase the items view count. - $item->increment_view_count(); - - // Load the page. - if ($item->is_photo()) { - $template = new Theme_View("calpage.html", "item", "photo"); - $template->page_title = $item->title; - $template->set_global("children", Array()); - $template->set_global("item", $item); - $template->set_global("previous_item", $previous_item); - $template->set_global("next_item", $next_item); - $template->set_global("is_tagalbum_page", true); // used for grey dragon - $template->set_global("tag_id", $tag_id); // used for grey dragon - $template->set_global("album_id", $album_id); // used for grey dragon - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->set_global("dynamic_siblings", $dynamic_siblings); // Used by Grey Dragon. - $template->set_global("children_count", 0); - $template->set_global("position", $position); - $template->set_global("sibling_count", $sibling_count); - $template->content = new View("photo.html"); - $template->content->title = $item->title; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); - print $template; - } elseif ($item->is_movie()) { - $template = new Theme_View("calpage.html", "item", "movie"); - $template->page_title = $item->title; - $template->set_global("children", Array()); - $template->set_global("item", $item); - $template->set_global("previous_item", $previous_item); - $template->set_global("next_item", $next_item); - $template->set_global("is_tagalbum_page", true); // used for grey dragon - $template->set_global("tag_id", $tag_id); // used for grey dragon - $template->set_global("album_id", $album_id); // used for grey dragon - $template->set_global("parent_url", $parent_url); // Used by Grey Dragon. - $template->set_global("dynamic_siblings", $dynamic_siblings); // Used by Grey Dragon. - $template->set_global("children_count", 0); - $template->set_global("position", $position); - $template->set_global("sibling_count", $sibling_count); - $template->content = new View("movie.html"); - $template->content->title = $item->title; - $template->set_global("breadcrumbs", $tag_album_breadcrumbs); - print $template; - } else { - // If it's something we don't know how to deal with, just redirect to its real page. - url::redirect(url::abs_site("{$item->type}s/{$item->id}")); - } } private function _get_position($item_title, $item_id, $tag_ids, $sort_field, $sort_direction, $search_type, $include_albums) {