Файл: vzabave/class/navigator.php
Строк: 69
<?php
##########################################
# ~ Разработка отдельных модулей ~~~~~~~ #
# ~ и написание скриптов на php (c)KoT ~ #
# ~ ICQ: 7675072 ~~~~~~~~~~~~~~~~~~~~~~~ #
# ~ Site: 4atlove.ru ~~~~~~~~~~~~~~~~~~~ #
# ~ E-mail: notefree@bk.ru ~~~~~~~~~~~~~ #
##########################################
class navigator {
public $all = 0;
public $page;
public $start = 0;
public $end = 0;
public $limit = 'LIMIT 0';
public $htmlForm = '<form action="%s" method="post"><div>К странице: <input type="text" name="page" size="3" value="%s"><input type="submit" name="" value=">>"></div></form>';
public $buttonBack = '«<a href="%s&page=%s">Назад</a>';
public $buttonBackName = '«Назад';
public $buttonForward = '<a href="%s&page=%s">Вперед</a>»<br />';
public $buttonForwardName = 'Вперед»<br />';
public $separator = ' | ';
public $listStr = 'Стр: %s <a href="%s&page=%s" title="Вперед">»</a><br />';
public $blocAllNavi = '%1$s %2$s %3$s';
function __construct($all, $pnumber, $skript = '')
{
$this->all = $all;
$this->skript = $skript == '' ? $_SERVER['SCRIPT_NAME'].'?' : rtrim($skript);
$this->page = isset($_REQUEST['page']) && (int)$_REQUEST['page'] ? (int)$_REQUEST['page'] : 1;
$this->num_pages = ceil($all / $pnumber);
if(isset($_GET['last'])) $this->page = $this->num_pages;
if($this->page > $this->num_pages || $this->page < 1) $this->page = 1;
if($all){
$this->start = $this->page * $pnumber - $pnumber;
$this->end = ($end = $this->start + $pnumber) > $all ? $all : $end;
$this->limit = sprintf('LIMIT %s,%s', $this->start, $pnumber);
}
$this->pnumber = $pnumber;
}
function form(){
return ($this->num_pages < 2) ? '' : sprintf($this->htmlForm, $this->skript, $this->page);
}
function button()
{
$back = $this->page > 1 ? sprintf($this->buttonBack, $this->skript, $this->page-1) : $this->buttonBackName;
$forward = $this->page != $this->num_pages ? sprintf($this->buttonForward, $this->skript, $this->page+1) : $this->buttonForwardName;
return ($this->num_pages < 2) ? '' : $back.$this->separator.$forward;
}
function str()
{
$buff = '';
for($pr = '', $i = 1; $i <= $this->num_pages; $i++) {
$buff .= $pr = (($i == 1 || $i == $this->num_pages || abs($i - $this->page) < 3) ? ($i == $this->page ? '['.$i.']' : sprintf(' <a href="%spage=%s">%2$s</a> ', $this->skript, $i)) : (($pr == ' ... ' || $pr == '') ? '' : ' ... '));
}
return ($this->num_pages < 2) ? '' : sprintf($this->listStr, $buff, $this->skript, ($this->page != $this->num_pages ? $this->page+1 : $this->page) );
}
function navi($str = true, $button = false, $form = false)
{
$str = $str ? $this->str() : '';
$button = $button ? $this->button() : '';
$form = $form ? $this->form() : '';
return sprintf($this->blocAllNavi, $button, $str, $form);
}
}
?>