diff --git a/controllers/ViewPhotoAlbum.php b/controllers/ViewPhotoAlbum.php index a58ff4e..5f8c834 100644 --- a/controllers/ViewPhotoAlbum.php +++ b/controllers/ViewPhotoAlbum.php @@ -80,7 +80,8 @@ class ViewPhotoAlbum extends HTMLController } // Set the canonical url. - $this->page->setCanonicalUrl(BASEURL . '/' . (isset($_GET['tag']) ? $_GET['tag'] . '/' : '')); + $this->page->setCanonicalUrl(BASEURL . '/' . (isset($_GET['tag']) ? $_GET['tag'] . '/' : '') . + ($page > 1 ? 'page/' . $page . '/' : '')); } public function getPhotoMosaic($id_tag, $page) diff --git a/models/Dispatcher.php b/models/Dispatcher.php index 627c9c7..790e1fc 100644 --- a/models/Dispatcher.php +++ b/models/Dispatcher.php @@ -42,7 +42,7 @@ class Dispatcher return new ViewPhotoAlbum(); } // Look for particular actions... - elseif (preg_match('~^/(?[a-z]+)/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']])) + elseif (preg_match('~^/(?[a-z]+)(?:/page/(?\d+))?/?~', $_SERVER['PATH_INFO'], $path) && isset($possibleActions[$path['action']])) { $_GET = array_merge($_GET, $path); return new $possibleActions[$path['action']](); diff --git a/models/GenericTable.php b/models/GenericTable.php index fb09bec..1a8ad71 100644 --- a/models/GenericTable.php +++ b/models/GenericTable.php @@ -201,7 +201,7 @@ class GenericTable extends PageIndex } } - protected function getLink($start = null, $order = null, $dir = null) + public function getLink($start = null, $order = null, $dir = null) { if ($start === null) $start = $this->start; diff --git a/models/PageIndex.php b/models/PageIndex.php index 0070e74..f4be341 100644 --- a/models/PageIndex.php +++ b/models/PageIndex.php @@ -132,14 +132,14 @@ class PageIndex $this->page_index['next'] = $this->page_index[$this->current_page + 1]; } - protected function getLink($start = null, $order = null, $dir = null) + public function getLink($start = null, $order = null, $dir = null) { $url = $this->base_url; $amp = strpos($this->base_url, '?') ? '&' : '?'; if (!empty($start)) { - $page = ($start / $this->items_per_page) + 1; + $page = $start !== '%d' ? ($start / $this->items_per_page) + 1 : $start; $url .= strtr($this->page_slug, ['%PAGE%' => $page, '%AMP%' => $amp]); $amp = '&'; } @@ -167,6 +167,21 @@ class PageIndex return $this->page_index; } + public function getItemsPerPage() + { + return $this->items_per_page; + } + + public function getSortOrder() + { + return $this->sort_order; + } + + public function getSortDirection() + { + return $this->sort_direction; + } + public function getPageIndexClass() { return $this->index_class; diff --git a/public/css/default.css b/public/css/default.css index ae4f862..dda95c1 100644 --- a/public/css/default.css +++ b/public/css/default.css @@ -134,6 +134,10 @@ ul#nav li a:hover { background-color: transparent; } +.pagination .page-padding { + cursor: pointer; +} + /* Tiled grid ---------------*/ diff --git a/public/js/main.js b/public/js/main.js new file mode 100644 index 0000000..51b71d6 --- /dev/null +++ b/public/js/main.js @@ -0,0 +1,16 @@ +function promptGoToPage(index_no) { + var page_no = prompt('Go to which page?'); + if (page_no === null) { + return; + } + + var index = window['page_index_' + index_no]; + page_no = parseInt(page_no); + + if (isNaN(page_no) || page_no < 1 || page_no > index.num_pages) { + return alert('Invalid page number.'); + } + + var offset = index.wildcard_url.indexOf('start=') !== -1 ? (page_no - 1) * index.per_page : page_no; + window.location.href = index.wildcard_url.replace('%d', offset) +} diff --git a/templates/MainTemplate.php b/templates/MainTemplate.php index d8ec8c8..87a1c0d 100644 --- a/templates/MainTemplate.php +++ b/templates/MainTemplate.php @@ -32,6 +32,7 @@ class MainTemplate extends Template ', !empty($this->css) ? ' ' : '', $this->header_html, ' + classes) ? ' class="' . implode(' ', $this->classes) . '"' : '', '>
diff --git a/templates/Pagination.php b/templates/Pagination.php index 73a7c7e..09ab946 100644 --- a/templates/Pagination.php +++ b/templates/Pagination.php @@ -3,42 +3,61 @@ * Pagination.php * Contains the pagination template. * - * Kabuki CMS (C) 2013-2015, Aaron van Geffen + * Kabuki CMS (C) 2013-2016, Aaron van Geffen *****************************************************************************/ class Pagination extends SubTemplate { private $index; + private static $unique_index_count = 0; public function __construct(PageIndex $index) { - $this->index = $index->getPageIndex(); + $this->index = $index; $this->class = $index->getPageIndexClass(); } protected function html_content() { + $index = $this->index->getPageIndex(); + echo '
    -
  • <', !empty($this->index['previous']) ? 'a href="' . $this->index['previous']['href'] . '"' : 'span', '>« previousindex['previous']) ? 'a' : 'span', '>
  • '; +
  • <', !empty($index['previous']) ? 'a href="' . $index['previous']['href'] . '"' : 'span', '>« previous
  • '; - foreach ($this->index as $key => $page) + $num_wildcards = 0; + foreach ($index as $key => $page) { if (!is_numeric($key)) continue; if (!is_array($page)) + { + $num_wildcards++; echo ' -
  • ...
  • '; +
  • ...
  • '; + } else echo '
  • ', $page['index'], '
  • '; } echo ' -
  • <', !empty($this->index['next']) ? 'a href="' . $this->index['next']['href'] . '"' : 'span', '>next »index['next']) ? 'a' : 'span', '>
  • +
  • <', !empty($index['next']) ? 'a href="' . $index['next']['href'] . '"' : 'span', '>next »
'; + + if ($num_wildcards) + { + echo ' + '; + } } }