Файл: system/classes/paginator.php
Строк: 36
<?php
/**********************************
* @package: PerfCMS *
* @year: 2012 *
* @author: Artas *
* @link: http://perfcms.pp.ua *
**********************************/
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="top">';
if ($page != 1) echo '<a class="panv" href="'. $link .'page=1">«</a> ';
if ($page != 1) echo '<a class="panv" href="'. $link .'page=1">1</a>';
else echo '<b class="cpage">1</b>';
for ($ot=-3; $ot<=3; $ot++)
{
if ($page + $ot > 1 && $page + $ot < $am_pages)
{
if ($ot == -3 && $page + $ot > 2) echo ' .. ';
if ($ot != 0) echo ' <a class="panv" href="'. $link .'page='. ($page + $ot) .'">'. ($page + $ot) .'</a>';
else echo ' <b class="cpage">'. ($page + $ot) .'</b>';
if ($ot == 3 && $page + $ot < $am_pages - 1) echo ' .. ';
}
}
if ($page != $am_pages) echo ' <a class="panv" href="'. $link .'page=end">'. $am_pages .'</a>';
else if ($am_pages > 1) echo ' <b class="cpage">'. $am_pages .'</b>';
if ($page!=$am_pages) echo ' <a class="panv" href="'. $link .'page=end">»</a>';
echo '</div>';
}
public function view($link = '?')
{
global $am_pages, $page;
if ($am_pages > 1) $this->pages($link, $am_pages, $page);
}
}