Файл: system/classes/paginator.php
Строк: 45
<?php
class Paginator {
public function __construct($var, $limit)
{
global $am_pages, $page, $start;
$am_pages = $this->am_pages($var, $limit);
$page = $this->page($am_pages);
$start = $limit * $page - $limit;
}
public function page($am_pages = 1)
{
$page = 1;
if (isset($_GET['page']))
{
if ($_GET['page'] == 'end') $page = intval($am_pages);
else if (is_numeric($_GET['page'])) $page = intval($_GET['page']);
}
if ($page < 1) $page = 1;
if ($page > $am_pages) $page = $am_pages;
return $page;
}
public function am_pages($am_posts = 0, $am_p_pages = 10)
{
if ($am_posts != 0)
{
$v_pages = ceil($am_posts / $am_p_pages);
return $v_pages;
}
else return 1;
}
public function pages($link = '?', $am_pages = 1, $page = 1)
{
if ($page < 1) $page = 1;
echo '<div class="page-action">';
if ($page != 1) echo '<span><a href="'. $link .'page=1">1</a></span>';
else echo '<span>1</span>';
for ($ot=-3; $ot<=3; $ot++)
{
if ($page + $ot > 1 && $page + $ot < $am_pages)
{
if ($ot == -3 && $page + $ot > 2) echo ' <span>..</span> ';
if ($ot != 0) echo '<span><a href="'. $link .'page='. ($page + $ot) .'">'. ($page + $ot) .'</a></span>';
else echo '<span>'. ($page + $ot) .'</span></b>';
if ($ot == 3 && $page + $ot < $am_pages - 1) echo '<span> ..</span>';
}
}
if ($page != $am_pages) echo '<span><a class="page-off" href="'. $link .'page=end">'. $am_pages .'</a></span>';
else if ($am_pages > 1) echo '<span><b class="page-on">'. $am_pages .'</span>';
echo '</div>';
}
public function view($link = '?')
{
global $am_pages, $page;
if ($am_pages > 1) $this->pages($link, $am_pages, $page);
}
}
?>