From d45a73777935c86fc5131955831833d7465b5e9d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 21 Jan 2013 01:22:01 -0500 Subject: Update copyright to 2013. Fixes #1953. --- modules/search/controllers/search.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/search/controllers/search.php') diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index 52eb973c..f7f1d981 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -1,7 +1,7 @@ Date: Wed, 30 Jan 2013 12:10:18 -0500 Subject: Improve the display context API to return a "siblings_callback" field containing a callback that returns all the siblings. Fixes #1975. --- modules/gallery/controllers/albums.php | 6 ++++++ modules/search/controllers/search.php | 24 +++++++++++++----------- modules/tag/controllers/tag.php | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) (limited to 'modules/search/controllers/search.php') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index e14fe347..d545b415 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -93,10 +93,16 @@ class Albums_Controller extends Items_Controller { "previous_item" => $previous_item, "next_item" => $next_item, "sibling_count" => $item->parent()->viewable()->children_count($where), + "siblings_callback" => array("Albums_Controller::get_siblings", array($item)), "parents" => $item->parents()->as_array(), "breadcrumbs" => Breadcrumb::array_from_item_parents($item)); } + static function get_siblings($item) { + // @todo consider creating Item_Model::siblings() if we use this more broadly. + return $item->parent()->viewable()->children(); + } + public function create($parent_id) { access::verify_csrf(); $album = ORM::factory("item", $parent_id); diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index f7f1d981..673a281f 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -54,8 +54,6 @@ class Search_Controller extends Controller { list ($count, $result) = search::search_within_album($q_with_more_terms, $album, $page_size, $offset); - $title = t("Search: %q", array("q" => $q_with_more_terms)); - $max_pages = max(ceil($count / $page_size), 1); $template = new Theme_View("page.html", "collection", "search"); @@ -77,28 +75,27 @@ class Search_Controller extends Controller { print $template; - item::set_display_context_callback( - "Search_Controller::get_display_context", $album->id, $title, $q_with_more_terms, $q); + item::set_display_context_callback("Search_Controller::get_display_context", $album, $q); } - static function get_display_context($item, $album_id, $title, $query_terms, $q) { - $album = ORM::factory("item", $album_id); - $position = search::get_position_within_album($item, $query_terms, $album); + static function get_display_context($item, $album, $q) { + $q_with_more_terms = search::add_query_terms($q); + $position = search::get_position_within_album($item, $q_with_more_terms, $album); if ($position > 1) { list ($count, $result_data) = - search::search_within_album($query_terms, $album, 3, $position - 2); + search::search_within_album($q_with_more_terms, $album, 3, $position - 2); list ($previous_item, $ignore, $next_item) = $result_data; } else { $previous_item = null; list ($count, $result_data) = - search::search_within_album($query_terms, $album, 1, $position); + search::search_within_album($q_with_more_terms, $album, 1, $position); list ($next_item) = $result_data; } $search_url = url::abs_site("search" . "?q=" . urlencode($q) . - "&album=" . urlencode($album_id) . + "&album=" . urlencode($album->id) . "&show={$item->id}"); $root = item::root(); @@ -106,9 +103,14 @@ class Search_Controller extends Controller { "previous_item" => $previous_item, "next_item" => $next_item, "sibling_count" => $count, + "siblings_callback" => array("Search_Controller::get_siblings", array($q, $album)), "breadcrumbs" => array( - Breadcrumb::instance($root->title, "/", $root->id)->set_first(), + Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance(t("Search: %q", array("q" => $q)), $search_url), Breadcrumb::instance($item->title, $item->url())->set_last())); } + + static function get_siblings($q, $album) { + return search::search_within_album(search::add_query_terms($q), $album, 1000, 1)[1]; + } } diff --git a/modules/tag/controllers/tag.php b/modules/tag/controllers/tag.php index 6199c49b..bada9bac 100644 --- a/modules/tag/controllers/tag.php +++ b/modules/tag/controllers/tag.php @@ -86,6 +86,7 @@ class Tag_Controller extends Controller { "previous_item" => $previous_item, "next_item" => $next_item, "sibling_count" => $tag->items_count($where), + "siblings_callback" => array(array($tag, "items"), array()), "breadcrumbs" => array( Breadcrumb::instance($root->title, $root->url())->set_first(), Breadcrumb::instance(t("Tag: %tag_name", array("tag_name" => $tag->name)), -- cgit v1.2.3 From 27ec3b4c6c9e5bd9fa61fd613b9b68af37eab1e4 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Thu, 7 Feb 2013 15:08:55 -0500 Subject: Follow-on to 1e4d75c12072b49c3469f18af13bcf3439afc6b0 for #1975. Don't try to use an array index on a function return, that's not supported in PHP 5.3 --- modules/search/controllers/search.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/search/controllers/search.php') diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index 673a281f..b54d7699 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -111,6 +111,7 @@ class Search_Controller extends Controller { } static function get_siblings($q, $album) { - return search::search_within_album(search::add_query_terms($q), $album, 1000, 1)[1]; + $result = search::search_within_album(search::add_query_terms($q), $album, 1000, 1); + return $result[1]; } } -- cgit v1.2.3 From 9dbe2e15ad9db3b2be53e46bc5f67d382fb4089d Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 9 Feb 2013 14:53:34 -0500 Subject: Extend siblings callbacks to take a $limit and an $offset for navigating large sibling sets. Useful for the thumbnav module since we don't want to iterate a thousand siblings to find the one we care about. Fixes #1999. --- modules/gallery/controllers/albums.php | 4 ++-- modules/gallery/libraries/Theme_View.php | 6 ++++-- modules/search/controllers/search.php | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'modules/search/controllers/search.php') diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index d545b415..0fb033a8 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -98,9 +98,9 @@ class Albums_Controller extends Items_Controller { "breadcrumbs" => Breadcrumb::array_from_item_parents($item)); } - static function get_siblings($item) { + static function get_siblings($item, $limit=null, $offset=null) { // @todo consider creating Item_Model::siblings() if we use this more broadly. - return $item->parent()->viewable()->children(); + return $item->parent()->viewable()->children($limit, $offset); } public function create($parent_id) { diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index cf384109..986fc8a2 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -86,8 +86,10 @@ class Theme_View_Core extends Gallery_View { return $this->item; } - public function siblings() { - return call_user_func_array($this->siblings_callback[0], $this->siblings_callback[1]); + public function siblings($limit=null, $offset=null) { + return call_user_func_array( + $this->siblings_callback[0], + array_merge($this->siblings_callback[1], array($offset, $limit))); } public function tag() { diff --git a/modules/search/controllers/search.php b/modules/search/controllers/search.php index b54d7699..25ccd81c 100644 --- a/modules/search/controllers/search.php +++ b/modules/search/controllers/search.php @@ -110,8 +110,8 @@ class Search_Controller extends Controller { Breadcrumb::instance($item->title, $item->url())->set_last())); } - static function get_siblings($q, $album) { - $result = search::search_within_album(search::add_query_terms($q), $album, 1000, 1); + static function get_siblings($q, $album, $limit=1000, $offset=1) { + $result = search::search_within_album(search::add_query_terms($q), $album, $limit, $offset); return $result[1]; } } -- cgit v1.2.3