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
|
|
|
|
public static function prevPageUrl()
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$domain = trim(DOMAIN_BASE,'/');
|
|
|
|
$filter = trim($Url->activeFilter(), '/');
|
|
|
|
|
|
|
|
if(empty($filter)) {
|
|
|
|
$url = $domain.'/'.$Url->slug();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$url = $domain.'/'.$filter.'/'.$Url->slug();
|
|
|
|
}
|
|
|
|
|
2017-05-24 00:48:29 +02:00
|
|
|
return $url.'?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)
|
|
|
|
{
|
|
|
|
global $Language;
|
|
|
|
|
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) {
|
2017-11-24 14:15:30 +01:00
|
|
|
$textPrevPage = '« '.$Language->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) {
|
|
|
|
$textNextPage = $Language->g('Next page').' »';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '<li class="right">';
|
2017-08-06 21:47:17 +02:00
|
|
|
$html .= '<a href="'.self::prevPageUrl().'">'.$textNextPage.'</a>';
|
2015-07-20 05:14:12 +02:00
|
|
|
$html .= '</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$html .= '</ul>';
|
|
|
|
$html .= '</div>';
|
|
|
|
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
2017-11-24 14:15:30 +01:00
|
|
|
}
|