diff options
Diffstat (limited to 'modules/gallery')
-rw-r--r-- | modules/gallery/controllers/albums.php | 1 | ||||
-rw-r--r-- | modules/gallery/controllers/movies.php | 1 | ||||
-rw-r--r-- | modules/gallery/controllers/photos.php | 1 | ||||
-rw-r--r-- | modules/gallery/libraries/Breadcrumb.php | 74 | ||||
-rw-r--r-- | modules/gallery/tests/Breadcrumb_Test.php | 51 |
5 files changed, 128 insertions, 0 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php index ccf6c1cb..90071fb5 100644 --- a/modules/gallery/controllers/albums.php +++ b/modules/gallery/controllers/albums.php @@ -69,6 +69,7 @@ class Albums_Controller extends Items_Controller { "item" => $album, "children" => $album->viewable()->children($page_size, $offset), "parents" => $album->parents()->as_array(), // view calls empty() on this + "breadcrumbs" => Breadcrumb::build_from_item($album), "children_count" => $children_count)); $template->content = new View("album.html"); diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 8e81c594..77d92e13 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -43,6 +43,7 @@ class Movies_Controller extends Items_Controller { "children" => array(), "children_count" => 0, "parents" => $movie->parents()->as_array(), + "breadcrumbs" => Breadcrumb::build_from_item($movie), "next_item" => $next_item, "previous_item" => $previous_item, "sibling_count" => $movie->parent()->viewable()->children_count($where), diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 054300a1..5c8c7b34 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -43,6 +43,7 @@ class Photos_Controller extends Items_Controller { "children" => array(), "children_count" => 0, "parents" => $photo->parents()->as_array(), + "breadcrumbs" => Breadcrumb::build_from_item($photo), "next_item" => $next_item, "previous_item" => $previous_item, "sibling_count" => $photo->parent()->viewable()->children_count($where), diff --git a/modules/gallery/libraries/Breadcrumb.php b/modules/gallery/libraries/Breadcrumb.php new file mode 100644 index 00000000..3a2499ba --- /dev/null +++ b/modules/gallery/libraries/Breadcrumb.php @@ -0,0 +1,74 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2011 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 Breadcrumb_Core { + public $title; + public $url; + public $id; + public $first; + public $last; + + static function build_from_item($item) { + $breadcrumbs = array(); + foreach ($item->parents() as $element) { + $breadcrumbs[] = new Breadcrumb($element->title, $element->url(), $element->id); + } + + if (!empty($breadcrumbs)) { + $breadcrumbs[] = new Breadcrumb($item->title, $item->url(), $item->id); + } + + return self::generate_show_query_strings($breadcrumbs); + } + + /** + * This static function takes a list (variable arguments) of Breadcrumbs and builds a dynamic + * breadcrumb list. Used to create a breadcrumb for dynamic albums. Will really be useful + * for the display context change. + */ + static function build_from_list() { + return self::generate_show_query_strings(func_get_args()); + } + + private static function generate_show_query_strings($breadcrumbs) { + if (!empty($breadcrumbs)) { + + end($breadcrumbs)->last = true;; + while ($breadcrumb = current($breadcrumbs)) { + if (isset($last_id) && $last_id > 0) { + $query = parse_url($breadcrumb->url, PHP_URL_QUERY); + $breadcrumb->url = $breadcrumb->url . ($query ? "&" : "?") . "show={$last_id}"; + } + $last_id = $breadcrumb->id; + $breadcrumb = prev($breadcrumbs); + } + $breadcrumbs[0]->first = true; + } + + return $breadcrumbs; + } + + public function __construct($title, $url, $id=0) { + $this->title = $title; + $this->url = $url; + $this->id = $id; + $this->first = false; + $this->last = false; + } +} diff --git a/modules/gallery/tests/Breadcrumb_Test.php b/modules/gallery/tests/Breadcrumb_Test.php new file mode 100644 index 00000000..9f9aeddc --- /dev/null +++ b/modules/gallery/tests/Breadcrumb_Test.php @@ -0,0 +1,51 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2011 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 Breadcrumb_Test extends Gallery_Unit_Test_Case { + private $album; + private $item; + + public function setup() { + $this->album = test::random_album(); + $this->item = test::random_photo($this->album); + $this->album->reload(); + } + + public function teardown() { + $this->album = null; + $this->item = null; + } + + public function build_breadcrumbs_for_item_test() { + $breadcrumbs = Breadcrumb::build_from_item($this->item); + $this->assert_equal("Gallery", $breadcrumbs[0]->title); + $this->assert_equal($this->album->title, $breadcrumbs[1]->title); + $this->assert_equal($this->item->title, $breadcrumbs[2]->title); + } + + public function build_breadcrumbs_from_items_test() { + $breadcrumbs = Breadcrumb::build_from_list( + new Breadcrumb(item::root()->title, "/", item::root()->id), + new Breadcrumb($this->album->title, $this->album->relative_path(), $this->album->id), + new Breadcrumb($this->item->title, $this->item->relative_path(), $this->item->id)); + $this->assert_equal("Gallery", $breadcrumbs[0]->title); + $this->assert_equal($this->album->title, $breadcrumbs[1]->title); + $this->assert_equal($this->item->title, $breadcrumbs[2]->title); + } +}
\ No newline at end of file |