Размер файла: 1.03Kb
<?php
defined('_CMEX_') or die('Error. You don`t have permision to access.');
class Navigator
{
function __construct($all,$pnumber,$query='')
{
$this->all=$all;
$this->pnumber=$pnumber;
$this->query=$query;
$this->page=isset($_GET['page']) ? (int)$_GET['page'] : 1;
}
function start()
{
$this->num_pages=ceil($this->all/$this->pnumber);
if (isset($_GET['last']))
$this->page=$this->num_pages;
$this->start=$this->page*$this->pnumber-$this->pnumber;
if ($this->page > $this->num_pages || $this->page < 1)
{
$this->page=1;
$this->start=0;
}
return $this->start;
}
function navi()
{
if ($this->num_pages<2)
return '';
$buff='';
for($pr = '', $i =1; $i <= $this->num_pages; $i++)
{
$buff.=
$pr=(($i == 1 || $i == $this->num_pages || abs($i-$this->page) < 2) ? ($i == $this->page ? " $i " : ' <a class="nav" href="'.$_SERVER['SCRIPT_NAME'].'?page='.$i.'&'.$this->query.'">'.$i.'</a> ') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
return $buff;
}
}
?>