diff options
Diffstat (limited to 'modules')
-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 |
5 files changed, 32 insertions, 11 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> |