Ejemplo n.º 1
0
/**
 * Draw pagination for pages in the Admin CP.
 *
 * @param int The current page we're on
 * @param int The number of items per page
 * @param int The total number of items in this collection
 * @param string The URL for pagination of this collection
 * @return string The built pagination
 */
function draw_admin_pagination($page, $per_page, $total_items, $url)
{
    global $mybb, $lang;
    if ($total_items <= $per_page) {
        return;
    }
    $pages = ceil($total_items / $per_page);
    $pagination = "<div class=\"pagination\"><span class=\"pages\">{$lang->pages}: </span>\n";
    if ($page > 1) {
        $prev = $page - 1;
        $prev_page = fetch_page_url($url, $prev);
        $pagination .= "<a href=\"{$prev_page}\" class=\"pagination_previous\">&laquo; {$lang->previous}</a> \n";
    }
    // Maximum number of "page bits" to show
    if (!$mybb->settings['maxmultipagelinks']) {
        $mybb->settings['maxmultipagelinks'] = 5;
    }
    $max_links = $mybb->settings['maxmultipagelinks'];
    $from = $page - floor($mybb->settings['maxmultipagelinks'] / 2);
    $to = $page + floor($mybb->settings['maxmultipagelinks'] / 2);
    if ($from <= 0) {
        $from = 1;
        $to = $from + $max_links - 1;
    }
    if ($to > $pages) {
        $to = $pages;
        $from = $pages - $max_links + 1;
        if ($from <= 0) {
            $from = 1;
        }
    }
    if ($to == 0) {
        $to = $pages;
    }
    if ($from > 2) {
        $first = fetch_page_url($url, 1);
        $pagination .= "<a href=\"{$first}\" title=\"{$lang->page} 1\" class=\"pagination_first\">1</a> ... ";
    }
    for ($i = $from; $i <= $to; ++$i) {
        $page_url = fetch_page_url($url, $i);
        if ($page == $i) {
            $pagination .= "<span class=\"pagination_current\">{$i}</span> \n";
        } else {
            $pagination .= "<a href=\"{$page_url}\" title=\"{$lang->page} {$i}\">{$i}</a> \n";
        }
    }
    if ($to < $pages) {
        $last = fetch_page_url($url, $pages);
        $pagination .= "... <a href=\"{$last}\" title=\"{$lang->page} {$pages}\" class=\"pagination_last\">{$pages}</a>";
    }
    if ($page < $pages) {
        $next = $page + 1;
        $next_page = fetch_page_url($url, $next);
        $pagination .= " <a href=\"{$next_page}\" class=\"pagination_next\">{$lang->next} &raquo;</a>\n";
    }
    $pagination .= "</div>\n";
    return $pagination;
}
Ejemplo n.º 2
0
/**
 * Generate a listing of page - pagination
 *
 * @param int The number of items
 * @param int The number of items to be shown per page
 * @param int The current page number
 * @param string The URL to have page numbers tacked on to (If {page} is specified, the value will be replaced with the page #)
 * @return string The generated pagination
 */
function multipage($count, $perpage, $page, $url, $breadcrumb = false)
{
    global $theme, $templates, $lang, $mybb;
    if ($count <= $perpage) {
        return;
    }
    $url = str_replace("&amp;", "&", $url);
    $url = htmlspecialchars_uni($url);
    $pages = ceil($count / $perpage);
    $prevpage = '';
    if ($page > 1) {
        $prev = $page - 1;
        $page_url = fetch_page_url($url, $prev);
        eval("\$prevpage = \"" . $templates->get("multipage_prevpage") . "\";");
    }
    // Maximum number of "page bits" to show
    if (!$mybb->settings['maxmultipagelinks']) {
        $mybb->settings['maxmultipagelinks'] = 5;
    }
    $from = $page - floor($mybb->settings['maxmultipagelinks'] / 2);
    $to = $page + floor($mybb->settings['maxmultipagelinks'] / 2);
    if ($from <= 0) {
        $from = 1;
        $to = $from + $mybb->settings['maxmultipagelinks'] - 1;
    }
    if ($to > $pages) {
        $to = $pages;
        $from = $pages - $mybb->settings['maxmultipagelinks'] + 1;
        if ($from <= 0) {
            $from = 1;
        }
    }
    if ($to == 0) {
        $to = $pages;
    }
    $start = '';
    if ($from > 1) {
        if ($from - 1 == 1) {
            $lang->multipage_link_start = '';
        }
        $page_url = fetch_page_url($url, 1);
        eval("\$start = \"" . $templates->get("multipage_start") . "\";");
    }
    $mppage = '';
    for ($i = $from; $i <= $to; ++$i) {
        $page_url = fetch_page_url($url, $i);
        if ($page == $i) {
            if ($breadcrumb == true) {
                eval("\$mppage .= \"" . $templates->get("multipage_page_link_current") . "\";");
            } else {
                eval("\$mppage .= \"" . $templates->get("multipage_page_current") . "\";");
            }
        } else {
            eval("\$mppage .= \"" . $templates->get("multipage_page") . "\";");
        }
    }
    $end = '';
    if ($to < $pages) {
        if ($to + 1 == $pages) {
            $lang->multipage_link_end = '';
        }
        $page_url = fetch_page_url($url, $pages);
        eval("\$end = \"" . $templates->get("multipage_end") . "\";");
    }
    $nextpage = '';
    if ($page < $pages) {
        $next = $page + 1;
        $page_url = fetch_page_url($url, $next);
        eval("\$nextpage = \"" . $templates->get("multipage_nextpage") . "\";");
    }
    $lang->multipage_pages = $lang->sprintf($lang->multipage_pages, $pages);
    if ($breadcrumb == true) {
        eval("\$multipage = \"" . $templates->get("multipage_breadcrumb") . "\";");
    } else {
        eval("\$multipage = \"" . $templates->get("multipage") . "\";");
    }
    return $multipage;
}