bludit/bl-kernel/helpers/paginator.class.php

145 lines
2.7 KiB
PHP
Raw Normal View History

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()
{
return self::numberUrl( self::firstPage() );
2017-05-24 00:48:29 +02:00
}
2017-05-24 00:48:29 +02:00
// Returns the absolute URL for the last page
public static function lastPageUrl()
{
return self::numberUrl( self::amountOfPages() );
2017-05-24 00:48:29 +02:00
}
2017-05-24 00:48:29 +02:00
// Returns the absolute URL for the next page
public static function nextPageUrl()
{
return self::numberUrl( self::nextPage() );
2017-05-24 00:48:29 +02:00
}
2017-05-24 00:48:29 +02:00
// Returns the absolute URL for the previous page
public static function previousPageUrl()
2017-05-24 00:48:29 +02:00
{
return self::numberUrl( self::prevPage() );
}
// Return the absoulte URL with the page number
public static function numberUrl($pageNumber)
{
global $url;
$domain = trim(DOMAIN_BASE,'/');
$filter = trim($url->activeFilter(), '/');
if(empty($filter)) {
$uri = $domain.'/'.$url->slug();
}
else {
$uri = $domain.'/'.$filter.'/'.$url->slug();
}
return $uri.'?page='.$pageNumber;
}
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) {
$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">';
$html .= '<a href="'.self::previousPageUrl().'">'.$textNextPage.'</a>';
2015-07-20 05:14:12 +02:00
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
return $html;
}
}