{# # Copyright 2006 - 2016 TubePress LLC (http://tubepress.com) # # This file is part of TubePress (http://tubepress.com) # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # # Most of this logic is loosely based on # https://github.com/KnpLabs/KnpPaginatorBundle/blob/master/Pagination/SlidingPagination.php #} {# Non-exhaustive list of variables in this template (add-ons may add other variables): paginationCurrentPageNumber int The current page number of the gallery. paginationTotalItems int The total number of items in this gallery. paginationResultsPerPage int The requested results per page. paginationHrefFormat string Anchor HREF attributes format IF YOU SIMPLY WISH TO MODIFY THE HTML, SKIP DOWN TO LINE 120. #} {% set currentPageNum = paginationCurrentPageNumber %} {% set totalItems = paginationTotalItems %} {% set itemsPerPage = paginationResultsPerPage %} {% set pageCount = (totalItems / itemsPerPage)|round(0, 'ceil') %} {% set pageRange = 5 %} {% if pageCount < currentPageNum %} {% set currentPageNum = pageCount %} {% endif %} {% if pageRange > pageCount %} {% set pageRange = pageCount %} {% endif %} {% set delta = (pageRange / 2)|round(0, 'ceil') %} {% if (currentPageNum - delta) > (pageCount - pageRange) %} {% set pages = range((pageCount - pageRange + 1), pageCount) %} {% else %} {% if (currentPageNum - delta) < 0 %} {% set delta = currentPageNum %} {% endif %} {% set offset = currentPageNum - delta %} {% set pages = range(offset + 1, offset + pageRange) %} {% endif %} {% set proximity = (pageRange / 2)|round(0, 'floor') %} {% set startPage = currentPageNum - proximity %} {% set endPage = currentPageNum + proximity %} {% if startPage < 1 %} {% set endPage = min(endPage + 1 - startPage, pageCount) %} {% set startPage = 1 %} {% endif %} {% if endPage > pageCount %} {% set startPage = max(startPage - endPage - pageCount, 1) %} {% set endPage = pageCount %} {% endif %} {% if (currentPageNum - 1) > 0 %} {% set previousPage = currentPageNum - 1 %} {% endif %} {% if (currentPageNum + 1) <= pageCount %} {% set nextPage = currentPageNum + 1 %} {% endif %} {% set firstPageInRange = min(pages) %} {% set lastPageInRange = max(pages) %} {% set currentItemCount = pages.length %} {% set firstItemNumber = ((currentPageNum - 1) * itemsPerPage) + 1 %} {% set lastItemNumber = firstItemNumber + currentItemCount - 1 %} {% macro anchor(page, anchorFormat, text) %} {% if text is empty %} {% set text = page %} {% endif %} {% set href = anchorFormat|replace({'___page-number___' : page}) %} {% if page > 1 %} {% set noFollow = ' rel="nofollow"' %} {% else %} {% set noFollow = '' %} {% endif %} {# If you modify this template, do not remove the "js-tubepress-*" class names as doing so will break Ajax pagination. #} {{ text|raw }} {% endmacro %} {% import _self as pagination %} {% if pageCount > 1 %} {% block pagination %}
{% endblock %}{# end block "pagination" #} {% endif %}