Вход Регистрация
Файл: core/pagination.php
Строк: 62
<?php
// Автор проекта GEARBAKC
// Офф.сайт GEARNET.RU
// http://gearnet.ru/users/1
// Только эксклюзивные скрипты!

class Pagination {
    
    private 
$_total,
            
$_perpage,
            
$_count_pages,
            
$_page,
            
$_start_pos = 0,
            
$_modrew;
    
    public function 
sett($total = 0, $perpage = 0, $modrew = false) {
        
$this->_total = $total;
        
$this->_perpage = $perpage;
        
$this->_modrew = $modrew;
        
        
$this->pagin();
    }
    
    private function 
pagin() {
        
$this->_count_pages = ceil($this->_total / $this->_perpage);
        
        if (!
$this->_count_pages) {
            
$this->_count_pages = 1;
        }
        if (!empty(
$_GET['page'])) {
        
$this->_page = abs((int)$_GET['page']);
        if (!
$this->_page) {
            
$this->_page = 1; 
        }
        } else {
            
$this->_page = 1;
        }
          
        if (
$this->_page > $this->_count_pages) {
            
$this->_page = $this->_count_pages;
        }
        
$this->_start_pos = ($this->_page - 1) * $this->_perpage;
    }
    
    public function 
limit() {
        return 
'LIMIT ' . $this->_start_pos . ', ' . $this->_perpage;
    }
    
    public function 
get() {
        
$uri = '?';
        if (!
$this->_modrew) {
            if (
$_SERVER['QUERY_STRING']) {
                unset(
$_GET['page']);
                foreach (
$_GET as $key => $value) {
                    
$uri .= $key . '=' . $value . '&';
                }
            }
        } else {
            
$url = $_SERVER['REQUEST_URI'];
            
$url = explode("?", $url);
            if (!empty(
$url[1])) {
                
$params = explode("&", $url[1]);
                foreach (
$params as $param) {
                    if (!
preg_match("#page=#", $param)) {
                        
$uri .= $param .'&';
                    }
                }
            }
        }      
        if (
$this->_page > 1) {
            
$back = '<a class="nav-link" href="'.$uri.'page='.($this->_page - 1).'">&lt;</a>';
        }else{
$back =null;}
        if (
$this->_page < $this->_count_pages) {
            
$forward = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 1).'">&gt;</a>';
        }else{
$forward =null;}
        if (
$this->_page > 3) {
            
$startpage = '<a class="nav-link" href="'.$uri.'page=1"><< </a>';
        }else{
$startpage =null;}
        if (
$this->_page < ($this->_count_pages - 2)) {
            
$endpage = '<a class="nav-link" href="'.$uri.'page='.$this->_count_pages.'"> >></a>';
        }else{
$endpage =null;}
        if ((
$this->_page - 2) > 0) {
            
$page2left = '<a class="nav-link" href="'.$uri.'page='.($this->_page - 2).'">'.($this->_page - 2).'</a>';
        }else{
$page2left =null;}
        if ((
$this->_page - 1) > 0) {
            
$page1left = '<a class="nav-link" href="'.$uri.'page='.($this->_page - 1).'">'.($this->_page - 1).'</a>';
        }else{
$page1left =null;}
        if ((
$this->_page + 2) <= $this->_count_pages) {
            
$page2right = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 2).'">'.($this->_page + 2).'</a>';
        }else{
$page2right =null;}
        if ((
$this->_page + 1) <= $this->_count_pages) {
            
$page1right = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 1).'">'.($this->_page + 1).'</a>';
        }else{
$page1right =null;}
        if (
$this->_count_pages > 1) {
return 
'<div class="rzd"></div><div class="h2"><center>
'
.$startpage . $back .' '.$page2left  .' '. $page1left .'<span class="nav-active"> <b>' . $this->_page . '</b> </span>'.$page1right .' '. $page2right .' '. $forward .' '. $endpage.'
</div><div class="rzd"></div>'
;
}else{return 
'<div class="rzd"></div>';}
    }
    
}
Онлайн: 0
Реклама