Exemplo n.º 1
0
function _pagination($url_format_smp, $url_apnd, $total_items, $per_page, $offset)
{
    global $bio;
    $begin_end = 5;
    $from_middle = 2;
    $total_pages = ceil($total_items / $per_page);
    $on_page = floor($offset / $per_page) + 1;
    $url_format = _link_apnd($url_format_smp, $url_apnd);
    $tag = array('strong' => '<li class="active"><a href="#">%d</a></li>', 'span' => '<li class="disabled"><a href="#">...</a></li>', 'a' => '<li><a href="%s">%s</a></li>');
    $pages = '';
    if ($total_pages > 2 * ($begin_end + $from_middle) + 2) {
        $init_page_max = $total_pages > $begin_end ? $begin_end : $total_pages;
        for ($i = 1; $i < $init_page_max + 1; $i++) {
            $pages .= _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
        }
        if ($total_pages > $begin_end) {
            if ($on_page > 1 && $on_page < $total_pages) {
                $pages .= $on_page > $begin_end + $from_middle + 1 ? $tag['span'] : '';
                $init_page_min = $on_page > $begin_end + $from_middle ? $on_page : $begin_end + $from_middle + 1;
                $init_page_max = $on_page < $total_pages - ($begin_end + $from_middle) ? $on_page : $total_pages - ($begin_end + $from_middle);
                for ($i = $init_page_min - $from_middle; $i < $init_page_max + ($from_middle + 1); $i++) {
                    $pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
                }
                $pages .= $on_page < $total_pages - ($begin_end + $from_middle) ? $tag['span'] : '';
            } else {
                $pages .= $tag['span'];
            }
            for ($i = $total_pages - ($begin_end - 1); $i < $total_pages + 1; $i++) {
                $pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
            }
        }
    } elseif ($total_pages > 1) {
        for ($i = 1; $i < $total_pages + 1; $i++) {
            $pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
        }
    }
    $prev = $on_page > 1 ? sprintf($tag['a'], sprintf($url_format, ($on_page - 2) * $per_page), sprintf($bio->_lang('PAGES_PREV'), $per_page)) : '';
    $next = $on_page < $total_pages ? sprintf($tag['a'], sprintf($url_format, $on_page * $per_page), sprintf($bio->_lang('PAGES_NEXT'), $per_page)) : '';
    $rest = array('NUMS' => '<ul>' . $pages . '</ul>', 'PREV' => $prev, 'NEXT' => $next, 'ON' => sprintf($bio->_lang('PAGES_ON'), $on_page, max($total_pages, 1)));
    return $rest;
}
Exemplo n.º 2
0
function _pagination($url_format_smp, $url_apnd, $total_items, $per_page, $offset)
{
	global $user, $style;
	
	$begin_end = 3;
	$from_middle = 1;
	
	$total_pages = ceil($total_items / $per_page);
	$on_page = floor($offset / $per_page) + 1;
	$url_format = _link_apnd($url_format_smp, $url_apnd);
	
	$tag = array(
		'strong' => '<strong>%d</strong>',
		'span' => '<span> ... </span>',
		'a' => '<a href="%s">%s</a>'
	);
	
	$pages = '';
	if ($total_pages > ((2 * ($begin_end + $from_middle)) + 2))
	{
		$init_page_max = ($total_pages > $begin_end) ? $begin_end : $total_pages;
		for ($i = 1; $i < $init_page_max + 1; $i++)
		{
			$pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
		}
		
		if ($total_pages > $begin_end)
		{
			if ($on_page > 1 && $on_page < $total_pages)
			{
				$pages .= ($on_page > ($begin_end + $from_middle + 1)) ? $tag['span'] : '';

				$init_page_min = ($on_page > ($begin_end + $from_middle)) ? $on_page : ($begin_end + $from_middle + 1);
				$init_page_max = ($on_page < $total_pages - ($begin_end + $from_middle)) ? $on_page : $total_pages - ($begin_end + $from_middle);

				for ($i = $init_page_min - $from_middle; $i < $init_page_max + ($from_middle + 1); $i++)
				{
					$pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
				}
				
				$pages .= ($on_page < $total_pages - ($begin_end + $from_middle)) ? $tag['span'] : '';
			} else {
				$pages .= $tag['span'];
			}
			
			for ($i = $total_pages - ($begin_end - 1); $i < $total_pages + 1; $i++)
			{
				$pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
			}
		}
	} elseif ($total_pages > 1) {
		for ($i = 1; $i < $total_pages + 1; $i++)
		{
			$pages .= _space($pages) . _pagination_multi($i, $on_page, $per_page, $tag, $url_format, $url_format_smp);
		}
	}
	
	$prev = ($on_page > 1) ? sprintf($tag['a'], sprintf($url_format, (($on_page - 2) * $per_page)), sprintf(_lang('PAGES_PREV'), $per_page)) : '';
	$next = ($on_page < $total_pages) ? sprintf($tag['a'], sprintf($url_format, ($on_page * $per_page)), sprintf(_lang('PAGES_NEXT'), $per_page)) : '';
	
	$rest = array(
		'NUMS' => $pages,
		'PREV' => $prev,
		'NEXT' => $next,
		'ON' => sprintf(_lang('PAGES_ON'), $on_page, max($total_pages, 1))
	);
	return $rest;
}