diff options
-rw-r--r-- | modules/gallery/libraries/Theme_View.php | 16 | ||||
-rw-r--r-- | modules/search/views/search.html.php | 2 | ||||
-rw-r--r-- | modules/tag/controllers/tags.php | 9 | ||||
-rw-r--r-- | modules/tag/models/tag.php | 14 | ||||
-rw-r--r-- | modules/tag/views/tag_cloud.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/album.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/dynamic.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/movie.html.php | 2 | ||||
-rw-r--r-- | themes/wind/views/paginator.html.php (renamed from themes/wind/views/pager.html.php) | 32 | ||||
-rw-r--r-- | themes/wind/views/photo.html.php | 2 |
10 files changed, 54 insertions, 29 deletions
diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 5e8bc728..19dc0829 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -140,26 +140,28 @@ class Theme_View_Core extends Gallery_View { * * See themes/wind/views/pager.html for documentation on the variables generated here. */ - public function pager() { - $v = new View("pager.html"); + public function paginator() { + $v = new View("paginator.html"); $v->page_type = $this->page_type; $v->first_page_url = null; $v->previous_page_url = null; $v->next_page_url = null; $v->last_page_url = null; - if ($this->page_type == "album") { + if ($this->page_type == "album" || $this->page_type = "tag") { $v->page = $this->page; $v->max_pages = $this->max_pages; $v->total = $this->children_count; + + $model = $this->page_type == "album" ? $this->item : $this->tag; if ($this->page != 1) { - $v->first_page_url = $this->item->url(); - $v->previous_page_url = $this->item->url("page=" . ($this->page - 1)); + $v->first_page_url = $model->url(); + $v->previous_page_url = $model->url("page=" . ($this->page - 1)); } if ($this->page != $this->max_pages) { - $v->next_page_url = $this->item->url("page=" . ($this->page + 1)); - $v->last_page_url = $this->item->url("page={$this->max_pages}"); + $v->next_page_url = $model->url("page=" . ($this->page + 1)); + $v->last_page_url = $model->url("page={$this->max_pages}"); } $v->first_visible_position = ($this->page - 1) * $this->page_size + 1; diff --git a/modules/search/views/search.html.php b/modules/search/views/search.html.php index 4b67157e..fdf22a9e 100644 --- a/modules/search/views/search.html.php +++ b/modules/search/views/search.html.php @@ -40,7 +40,7 @@ </li> <? endforeach ?> </ul> - <?= $theme->pager() ?> + <?= $theme->paginator() ?> <? else: ?> <p> diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 1bd6b3cc..c3b14fcc 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -25,13 +25,18 @@ class Tags_Controller extends REST_Controller { $page = (int) $this->input->get("page", "1"); $children_count = $tag->items_count(); $offset = ($page-1) * $page_size; + $max_pages = max(ceil($children_count / $page_size), 1); // Make sure that the page references a valid offset - if ($page < 1 || ($children_count && $page > ceil($children_count / $page_size))) { - Kohana::show_404(); + if ($page < 1) { + url::redirect($album->abs_url()); + } else if ($page > $max_pages) { + url::redirect($album->abs_url("page=$max_pages")); } $template = new Theme_View("page.html", "tag"); + $template->set_global("page", $page); + $template->set_global("max_pages", $max_pages); $template->set_global("page_size", $page_size); $template->set_global("tag", $tag); $template->set_global("children", $tag->items($page_size, $offset)); diff --git a/modules/tag/models/tag.php b/modules/tag/models/tag.php index d9488e1c..49512daa 100644 --- a/modules/tag/models/tag.php +++ b/modules/tag/models/tag.php @@ -102,4 +102,18 @@ class Tag_Model extends ORM { } return $result; } + + /** + * Return the server-relative url to this item, eg: + * /gallery3/index.php/tags/35 + * + * @param string $query the query string (eg "page=3") + */ + public function url($query=null) { + $url = url::site("tags/$this->id"); + if ($query) { + $url .= "?$query"; + } + return $url; + } }
\ No newline at end of file diff --git a/modules/tag/views/tag_cloud.html.php b/modules/tag/views/tag_cloud.html.php index d6a0b5f8..de12bb49 100644 --- a/modules/tag/views/tag_cloud.html.php +++ b/modules/tag/views/tag_cloud.html.php @@ -3,7 +3,7 @@ <? foreach ($tags as $tag): ?> <li class="size<?=(int)(($tag->count / $max_count) * 7) ?>"> <span><?= $tag->count ?> photos are tagged with </span> - <a href="<?= url::site("tags/$tag->id") ?>"><?= html::clean($tag->name) ?></a> + <a href="<?= $tag->url() ?>"><?= html::clean($tag->name) ?></a> </li> <? endforeach ?> </ul> diff --git a/themes/wind/views/album.html.php b/themes/wind/views/album.html.php index 1163630d..2c2b54eb 100644 --- a/themes/wind/views/album.html.php +++ b/themes/wind/views/album.html.php @@ -38,4 +38,4 @@ </ul> <?= $theme->album_bottom() ?> -<?= $theme->pager() ?> +<?= $theme->paginator() ?> diff --git a/themes/wind/views/dynamic.html.php b/themes/wind/views/dynamic.html.php index 51e48dc0..a8a4d362 100644 --- a/themes/wind/views/dynamic.html.php +++ b/themes/wind/views/dynamic.html.php @@ -26,4 +26,4 @@ </ul> <?= $theme->dynamic_bottom() ?> -<?= $theme->pager() ?> +<?= $theme->paginator() ?> diff --git a/themes/wind/views/movie.html.php b/themes/wind/views/movie.html.php index a44b891a..27c293ce 100644 --- a/themes/wind/views/movie.html.php +++ b/themes/wind/views/movie.html.php @@ -2,7 +2,7 @@ <div id="g-item"> <?= $theme->photo_top() ?> - <?= $theme->pager() ?> + <?= $theme->paginator() ?> <div id="g-movie" class="ui-helper-clearfix"> <?= $item->movie_img(array("class" => "g-movie", "id" => "g-movie-id-{$item->id}")) ?> diff --git a/themes/wind/views/pager.html.php b/themes/wind/views/paginator.html.php index 51d52021..5d300cf4 100644 --- a/themes/wind/views/pager.html.php +++ b/themes/wind/views/paginator.html.php @@ -6,12 +6,12 @@ // for album views. // // Available variables for all page types: -// $page_type - "album", "movie" or "photo" +// $page_type - "album", "movie", "photo" or "tag" // $previous_page_url - the url to the previous page, if there is one // $next_page_url - the url to the next page, if there is one // $total - the total number of photos in this album // -// Available for the "album" page type: +// Available for the "album" and "tag" page types: // $page - what page number we're on // $max_pages - the maximum page number // $page_size - the page size @@ -22,11 +22,12 @@ // // Available for "photo" and "movie" page types: // $position - the position number of this photo +// ?> <ul class="g-pager ui-helper-clearfix"> <li class="g-first"> - <? if ($page_type == "album"): ?> + <? if ($page_type == "album" || $page_type == "tag"): ?> <? if (isset($first_page_url)): ?> <a href="<?= $first_page_url ?>" class="g-button ui-icon-left ui-state-default ui-corner-all"> <span class="ui-icon ui-icon-seek-first"></span><?= t("First") ?></a> @@ -46,17 +47,20 @@ </li> <li class="g-info"> - <? if ($page_type == "album"): ?> - <?= /* @todo This message isn't easily localizable */ - /* @todo does this really need to be a t2? why not just skip the msg when there's 1 photo? */ - t2("Photo %from_number of %count", - "Photos %from_number - %to_number of %count", - $total, - array("from_number" => $first_visible_position, - "to_number" => $last_visible_position, - "count" => $total)) ?> + <? if ($total): ?> + <? if ($page_type == "album" || $page_type == "tag"): ?> + <?= /* @todo This message isn't easily localizable */ + t2("Photo %from_number of %count", + "Photos %from_number - %to_number of %count", + $total, + array("from_number" => $first_visible_position, + "to_number" => $last_visible_position, + "count" => $total)) ?> + <? else: ?> + <?= t("%position of %total", array("position" => $position, "total" => $total)) ?> + <? endif ?> <? else: ?> - <?= t("%position of %total", array("position" => $position, "total" => $total)) ?> + <?= t("No photos") ?> <? endif ?> </li> @@ -69,7 +73,7 @@ <span class="ui-icon ui-icon-seek-next"></span><?= t("Next") ?></a> <? endif ?> - <? if ($page_type == "album"): ?> + <? if ($page_type == "album" || $page_type == "tag"): ?> <? if (isset($last_page_url)): ?> <a href="<?= $last_page_url ?>" class="g-button ui-icon-right ui-state-default ui-corner-all"> <span class="ui-icon ui-icon-seek-end"></span><?= t("Last") ?></a> diff --git a/themes/wind/views/photo.html.php b/themes/wind/views/photo.html.php index 091fd7c5..e0fae3f1 100644 --- a/themes/wind/views/photo.html.php +++ b/themes/wind/views/photo.html.php @@ -15,7 +15,7 @@ <div id="g-item"> <?= $theme->photo_top() ?> - <?= $theme->pager() ?> + <?= $theme->paginator() ?> <div id="g-photo"> <?= $theme->resize_top($item) ?> |