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

100 lines
2.0 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(
'numberOfPostsAndDraft'=>0,
'numberOfPosts'=>0,
'numberOfPages'=>0,
'nextPage'=>0,
'prevPage'=>0,
'currentPage'=>0,
'showOlder'=>false,
'showNewer'=>false,
'show'=>false
);
public static function set($key, $value)
{
self::$pager[$key] = $value;
}
public static function get($key)
{
return self::$pager[$key];
}
2016-01-21 03:16:32 +01:00
public static function urlNextPage()
{
global $Url;
$domain = trim(DOMAIN_BASE,'/');
$filter = trim($Url->activeFilter(), '/');
if(empty($filter)) {
$url = $domain.'/'.$Url->slug();
}
else {
$url = $domain.'/'.$filter.'/'.$Url->slug();
}
return $url.'?page='.self::get('nextPage');
}
public static function urlPrevPage()
2015-07-20 05:14:12 +02:00
{
2016-01-17 01:11:58 +01:00
global $Url;
2016-01-21 03:16:32 +01:00
$domain = trim(DOMAIN_BASE,'/');
$filter = trim($Url->activeFilter(), '/');
2016-01-17 01:11:58 +01:00
2016-01-21 03:16:32 +01:00
if(empty($filter)) {
$url = $domain.'/'.$Url->slug();
2016-01-17 01:11:58 +01:00
}
else {
2016-01-21 03:16:32 +01:00
$url = $domain.'/'.$filter.'/'.$Url->slug();
2016-01-17 01:11:58 +01:00
}
2015-07-20 05:14:12 +02:00
2016-01-21 03:16:32 +01:00
return $url.'?page='.self::get('prevPage');
}
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>';
if(self::get('showNewer'))
{
if($textPrevPage===false) {
$textPrevPage = '« '.$Language->g('Prev page');
}
$html .= '<li class="left">';
2016-01-21 03:16:32 +01:00
$html .= '<a href="'.self::urlPrevPage().'?page='.self::get('prevPage').'">'.$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>';
}
if(self::get('showOlder'))
{
if($textNextPage===false) {
$textNextPage = $Language->g('Next page').' »';
}
$html .= '<li class="right">';
2016-01-21 03:16:32 +01:00
$html .= '<a href="'.self::urlNextPage().'?page='.self::get('nextPage').'">'.$textNextPage.'</a>';
2015-07-20 05:14:12 +02:00
$html .= '</li>';
}
$html .= '</ul>';
$html .= '</div>';
return $html;
}
2016-01-21 03:16:32 +01:00
}