Файл: system/classes/Paginator.php
Строк: 59
<?php
/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) 2013, Taras Chornyi, Sergiy Mazurenko, Ivan Kotliar
* @link http://perf-engine.net
* @package PerfEngine
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
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="pnav" href="'. $link .'page=1">«</a> ';
if ($page != 1) echo '<a class="pnav" href="'. $link .'page=1">1</a>';
else echo '<b class="cpage">1</b>';
for ($from=-3; $from<=3; $from++)
{
if ($page + $from > 1 && $page + $from < $am_pages)
{
if ($from == -3 && $page + $from > 2) echo ' .. ';
if ($from != 0) echo ' <a class="pnav" href="'. $link .'page='. ($page + $from) .'">'. ($page + $from) .'</a>';
else echo ' <b class="cpage">'. ($page + $from) .'</b>';
if ($from == 3 && $page + $from < $am_pages - 1) echo ' .. ';
}
}
if ($page != $am_pages) echo ' <a class="pnav" 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="pnav" href="'. $link .'page=end">»</a>';
echo '</div>';
}
public function view($separator = '?')
{
$link = preg_replace('/?page=(.*?)|&page=(.*?)|&page=(.*?)/iSU', '', $_SERVER['REQUEST_URI']).$separator;
global $am_pages, $page;
if ($am_pages > 1) $this->pages($link, $am_pages, $page);
}
}