<?php

$pageinfo = array(
    'last' => $paginator->getLastPage(),
    'current' => $paginator->getCurrentPage(),
);

$pageinfo['next'] = $pageinfo['current'] + 1 > $pageinfo['last'] ? null : $pageinfo['current'] + 1;
$pageinfo['prev'] = $pageinfo['current'] - 1 < 1 ? null : $pageinfo['current'] - 1;

if($pageinfo['last'] < 2) return '';
$result = array( '<div class="ui-paging">' );
if( $pageinfo['prev'] )
{
    $url = $paginator->getUrl($pageinfo['prev']);
    $result[] = "<a class=\"ui-paging-prev\" data-page=\"{$pageinfo['prev']}\" href=\"{$url}\"><i class=\"iconfont\"></i> 上一页</a>";
}

$prev_len = 2;
$next_len = 5;
$loop_start = $pageinfo['current'] - $prev_len < 1 ? 1 : $pageinfo['current'] - $prev_len;
$loop_end = $pageinfo['current'] + $next_len > $pageinfo['last'] ? $pageinfo['last'] : $pageinfo['current'] + $next_len;


if($loop_start > 1)
{
    $url = $paginator->getUrl( 1 );
    $result[] = "<a class=\"ui-paging-item\" data-page=\"1\" href=\"{$url}\">1</a>";
    if($loop_start > 2)
        $result[] = '<span class="ui-paging-ellipsis">...</span>';
}

for(; $loop_start <= $loop_end; $loop_start++ )
{
    $url = $paginator->getUrl($loop_start);
    $current = $pageinfo['current'] == $loop_start ? '  ui-paging-current' : '';
    $result[] = "<a  class=\"ui-paging-item{$current}\"  data-page=\"{$loop_start}\" href=\"{$url}\">{$loop_start}</a>";
}
if($loop_start < $pageinfo['last'])
{
    $url = $paginator->getUrl($pageinfo['last']);
    $result[] = '<span class="ui-paging-ellipsis">...</span>';
    $result[] = "<a data-page=\"{$pageinfo['last']}\" href=\"{$url}\">{$pageinfo['last']}</a>";
}

if( $pageinfo['next'] )
{
    $url = $paginator->getUrl($pageinfo['next']);
    $result[] = "<a class=\"ui-paging-next\" data-page=\"{$pageinfo['next']}\" href=\"{$url}\">下一页<i class=\"iconfont\" title=\"右三角形\"></i></a>";
}
$result[] = "<span class=\"ui-paging-info\"><span class=\"ui-paging-bold\">{$pageinfo['current']}/{$pageinfo['last']}</span>页</span>";


$result[] = '</div>';
echo implode('', $result);
?>