Файл: system/classes/paginator.php
Строк: 42
<?php
class pages {
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="pages">';
if ($page != 1) echo '<a href="'. $link .'page=1"><span>1</span></a>';
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 '<a href="'. $link .'page='. ($page + $ot) .'"><span>'. ($page + $ot) .'</span></a>';
else echo '<span>'. ($page + $ot) .'</span></b>';
if ($ot == 3 && $page + $ot < $am_pages - 1) echo '<span> ..</span>';
}
}
if ($page != $am_pages) echo '<a href="'. $link .'page=end"><span>'. $am_pages .'</span></a>';
else if ($am_pages > 1) echo '<span>'. $am_pages .'</span>';
echo '</div>';
}
public function view($link = '?')
{
global $am_pages, $page;
if ($am_pages > 1) $this->pages($link, $am_pages, $page);
}
}
?>