2015-07-20 05:14:12 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
|
|
|
class Paginator {
|
|
|
|
|
|
|
|
public static $pager = array(
|
2017-05-16 00:46:20 +02:00
|
|
|
'itemsPerPage'=>0,
|
2017-05-24 00:48:29 +02:00
|
|
|
'amountOfPages'=>1,
|
|
|
|
'amountOfItems'=>0,
|
|
|
|
'firstPage'=>1,
|
|
|
|
'nextPage'=>1,
|
|
|
|
'prevPage'=>1,
|
|
|
|
'currentPage'=>1,
|
|
|
|
'showPrev'=>false,
|
|
|
|
'showNext'=>false,
|
|
|
|
'showNextPrev'=>false
|
2015-07-20 05:14:12 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
public static function set($key, $value)
|
|
|
|
{
|
|
|
|
self::$pager[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function get($key)
|
|
|
|
{
|
|
|
|
return self::$pager[$key];
|
|
|
|
}
|
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function amountOfPages()
|
2016-01-21 03:16:32 +01:00
|
|
|
{
|
2017-05-24 00:48:29 +02:00
|
|
|
return self::get('amountOfPages');
|
|
|
|
}
|
2016-01-21 03:16:32 +01:00
|
|
|
|
2018-01-27 20:34:26 +01:00
|
|
|
public static function currentPage()
|
|
|
|
{
|
|
|
|
return self::get('currentPage');
|
|
|
|
}
|
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function nextPage()
|
|
|
|
{
|
|
|
|
return self::get('nextPage');
|
2016-01-21 03:16:32 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function prevPage()
|
2015-07-20 05:14:12 +02:00
|
|
|
{
|
2017-05-24 00:48:29 +02:00
|
|
|
return self::get('prevPage');
|
|
|
|
}
|
2016-01-17 01:11:58 +01:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function showNext()
|
|
|
|
{
|
|
|
|
return self::get('showNext');
|
|
|
|
}
|
2016-01-17 01:11:58 +01:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function showPrev()
|
|
|
|
{
|
|
|
|
return self::get('showPrev');
|
|
|
|
}
|
2015-07-20 05:14:12 +02:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
public static function firstPage()
|
|
|
|
{
|
|
|
|
return self::get('firstPage');
|
2016-01-21 03:16:32 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
// Returns the absolute URL for the first page
|
|
|
|
public static function firstPageUrl()
|
2017-04-10 16:57:30 +02:00
|
|
|
{
|
2017-07-30 14:25:16 +02:00
|
|
|
return self::numberUrl( self::firstPage() );
|
2017-05-24 00:48:29 +02:00
|
|
|
}
|
2017-04-10 16:57:30 +02:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
// Returns the absolute URL for the last page
|
|
|
|
public static function lastPageUrl()
|
|
|
|
{
|
2017-07-30 14:25:16 +02:00
|
|
|
return self::numberUrl( self::amountOfPages() );
|
2017-05-24 00:48:29 +02:00
|
|
|
}
|
2017-04-10 16:57:30 +02:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
// Returns the absolute URL for the next page
|
|
|
|
public static function nextPageUrl()
|
|
|
|
{
|
2017-07-30 14:25:16 +02:00
|
|
|
return self::numberUrl( self::nextPage() );
|
2017-05-24 00:48:29 +02:00
|
|
|
}
|
2017-04-10 16:57:30 +02:00
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
// Returns the absolute URL for the previous page
|
2018-07-18 21:48:37 +02:00
|
|
|
public static function previousPageUrl()
|
2017-05-24 00:48:29 +02:00
|
|
|
{
|
2017-07-30 14:25:16 +02:00
|
|
|
return self::numberUrl( self::prevPage() );
|
2017-04-10 16:57:30 +02:00
|
|
|
}
|
|
|
|
|
2017-07-30 14:25:16 +02:00
|
|
|
// Return the absoulte URL with the page number
|
|
|
|
public static function numberUrl($pageNumber)
|
2017-04-10 16:57:30 +02:00
|
|
|
{
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
2017-04-10 16:57:30 +02:00
|
|
|
|
|
|
|
$domain = trim(DOMAIN_BASE,'/');
|
2018-07-17 19:13:01 +02:00
|
|
|
$filter = trim($url->activeFilter(), '/');
|
2017-04-10 16:57:30 +02:00
|
|
|
|
|
|
|
if(empty($filter)) {
|
2018-07-18 21:48:37 +02:00
|
|
|
$uri = $domain.'/'.$url->slug();
|
2017-04-10 16:57:30 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-07-18 21:48:37 +02:00
|
|
|
$uri = $domain.'/'.$filter.'/'.$url->slug();
|
2017-04-10 16:57:30 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 21:48:37 +02:00
|
|
|
return $uri.'?page='.$pageNumber;
|
2017-04-10 16:57:30 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 03:16:32 +01:00
|
|
|
public static function html($textPrevPage=false, $textNextPage=false, $showPageNumber=false)
|
|
|
|
{
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2016-01-21 03:16:32 +01:00
|
|
|
|
2015-07-20 05:14:12 +02:00
|
|
|
$html = '<div id="paginator">';
|
|
|
|
$html .= '<ul>';
|
|
|
|
|
2017-08-06 21:47:17 +02:00
|
|
|
if(self::get('showNext'))
|
2015-07-20 05:14:12 +02:00
|
|
|
{
|
|
|
|
if($textPrevPage===false) {
|
2018-08-05 17:54:20 +02:00
|
|
|
$textPrevPage = '« '.$L->g('Previous page');
|
2015-07-20 05:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<li class="left">';
|
2017-08-06 21:47:17 +02:00
|
|
|
$html .= '<a href="'.self::nextPageUrl().'">'.$textPrevPage.'</a>';
|
2015-07-20 05:14:12 +02:00
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if($showPageNumber) {
|
|
|
|
$html .= '<li class="list">'.(self::get('currentPage')+1).' / '.(self::get('numberOfPages')+1).'</li>';
|
|
|
|
}
|
|
|
|
|
2017-08-06 21:47:17 +02:00
|
|
|
if(self::get('showPrev'))
|
2015-07-20 05:14:12 +02:00
|
|
|
{
|
|
|
|
if($textNextPage===false) {
|
2018-08-05 17:54:20 +02:00
|
|
|
$textNextPage = $L->g('Next page').' »';
|
2015-07-20 05:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<li class="right">';
|
2018-07-18 21:48:37 +02:00
|
|
|
$html .= '<a href="'.self::previousPageUrl().'">'.$textNextPage.'</a>';
|
2015-07-20 05:14:12 +02:00
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '</ul>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
2018-08-04 14:47:12 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bootstrap Pagination
|
|
|
|
*/
|
|
|
|
public static function bootstrap_html($textPrevPage=false, $textNextPage=false, $showPageNumber=false){
|
|
|
|
|
|
|
|
global $Language;
|
|
|
|
|
|
|
|
$total_pages = self::amountOfPages();
|
|
|
|
$howMany = 2;
|
|
|
|
$currentPage = self::currentPage();
|
|
|
|
$first_page = self::firstPage();
|
|
|
|
$last_page = self::lastPageUrl();
|
|
|
|
$show_next = (self::showNext()) ? "" : "disabled";
|
|
|
|
$show_previois = (self::showPrev()) ? "" : "disabled";
|
|
|
|
|
|
|
|
$html = '<nav aria-label="Page navigation">';
|
|
|
|
$html .= '<ul class="pagination">';
|
|
|
|
if ($currentPage > 3 || $currentPage === $total_pages){
|
|
|
|
$html .= '<li class="page-item">';
|
|
|
|
$html .= '<a class="page-link" href="'.self::firstPageUrl().'" aria-label="First"><span aria-hidden="true">«</span> '.$Language->get('First').'</a>';
|
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
if ($currentPage > 1){
|
|
|
|
$html .= '<li class="page-item'.$show_previois.'">';
|
|
|
|
$html .= '<a class="page-link" href="'.self::prevPageUrl().'" aria-label="Previous"><span aria-hidden="true">«</span> '.$Language->get('Previous').'</a>';
|
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
if ($currentPage > $howMany + 1){
|
|
|
|
$html .= '<li class="page-item disabled"><span>...</span></li>';
|
|
|
|
}
|
|
|
|
for ($pageIndex = $currentPage - $howMany; $pageIndex <= $currentPage + $howMany; $pageIndex++){
|
|
|
|
|
|
|
|
$active = ($pageIndex==self::currentPage()) ? "active" : false;
|
|
|
|
|
|
|
|
if ($pageIndex >= 1 && $pageIndex <= $total_pages){
|
|
|
|
$html .= '<li class ="'.$active.'"><a href="'.self::numberUrl($pageIndex).'">'.$pageIndex.'</a></li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($currentPage < $total_pages){
|
|
|
|
$html .= '<li class="page-item disabled"><span>...</span></li>';
|
|
|
|
}
|
|
|
|
if ($currentPage < $total_pages){
|
|
|
|
$html .= '<li class="page-item'.$show_next.'">';
|
|
|
|
$html .= '<a class="page-link" href="'.self::nextPageUrl().'" aria-label="Next">'.$Language->get('Next').' <span aria-hidden="true">»</span></a>';
|
|
|
|
$html .= '</li>';
|
|
|
|
$html .= '<li><a href="'.$last_page.'">'.$Language->get('Last').'</a></li>';
|
|
|
|
}
|
|
|
|
$html .= '</ul>';
|
|
|
|
$html .= '</nav>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
|
|
|
|
}
|
2015-07-20 05:14:12 +02:00
|
|
|
|
2017-11-24 14:15:30 +01:00
|
|
|
}
|