Файл: __libs/other/Pagination.php
Строк: 49
<?php
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).'"><</a>';
}
if ($this->_page < $this->_count_pages) {
$forward = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 1).'">></a>';
}
if ($this->_page > 3) {
$startpage = '<a class="nav-link" href="'.$uri.'page=1">«</a>';
}
if ($this->_page < ($this->_count_pages - 2)) {
$endpage = '<a class="nav-link" href="'.$uri.'page='.$this->_count_pages.'">»</a>';
}
if (($this->_page - 2) > 0) {
$page2left = '<a class="nav-link" href="'.$uri.'page='.($this->_page - 2).'">'.($this->_page - 2).'</a>';
}
if (($this->_page - 1) > 0) {
$page1left = '<a class="nav-link" href="'.$uri.'page='.($this->_page - 1).'">'.($this->_page - 1).'</a>';
}
if (($this->_page + 2) <= $this->_count_pages) {
$page2right = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 2).'">'.($this->_page + 2).'</a>';
}
if (($this->_page + 1) <= $this->_count_pages) {
$page1right = '<a class="nav-link" href="'.$uri.'page='.($this->_page + 1).'">'.($this->_page + 1).'</a>';
}
return $startpage . $back . $page2left . $page1left . '<span class="nav-active">' . $this->_page . '</span>' . $page1right . $page2right . $forward . $endpage;
}
}