Файл: OldBlog by Axer/blog/inc/navig.php
Строк: 47
<?php
class Navigator
{
function __construct($all,$pnumber,$query=''){
$this->all=$all;
$this->pnumber=$pnumber;
$this->query=$query;
$this->p=isset($_GET['page']) ? (int)$_GET['page'] : 1;
if(isset($_POST['page'])){
$this->p=(int)$_POST['page'];}
}
function start()
{
$this->num_ps=ceil($this->all/$this->pnumber);
if (isset($_GET['last']))
$this->p=$this->num_ps;
$this->start=$this->p*$this->pnumber-$this->pnumber;
if ($this->p > $this->num_ps || $this->p < 1)
{
$this->p=1;
$this->start=0;
}
return $this->start;
}
function navi()
{
if ($this->num_ps<2)
return '';
$buff='<div class="link">
Страницы:<br>';
if($this->p>1){
$n=$this->p;
$n--;
$buff.= '<span class="out"><a href="'.$_SERVER['PHP_SELF'].'?page='.$n.'&'.$this->query.'"><<Назад</a></span>';}
if(($this->p>1) && ($this->p != $this->num_ps)){$buff.= ' | ';}
if($this->p != $this->num_ps){
$p=$this->p;
$p++;
$buff.= '<span class="out"><a href="'.$_SERVER['PHP_SELF'].'?page='.$p.'&'.$this->query.'" >Вперед>></a></span>';}
$buff.='<br/>';
for($pr = '', $i =1; $i <= $this->num_ps; $i++){
$buff.=
$pr=(($i == 1 || $i == $this->num_ps || abs($i-$this->p) < 2) ? ($i == $this->p ? "<span class='in'>".$i."</span>" : ' <span class="out"><a href="'.$_SERVER['SCRIPT_NAME'].'?page='.$i.'&'.$this->query.'">'.$i.'</a></span>') : (($pr == ' .. ' || $pr == '')? '' : ' .. '));
}
if($this->num_ps>5){
$buff.= '</div>
<div class="link">
<form action="'.$_SERVER['PHP_SELF'].'?'.$this->query.'" method="get">
<input type="text" size="3" name="page" value="'.$this->p.'">
<INPUT type="submit" name="" value="Перейти">
</div>';}
return $buff.'</div>';
}
}
?>