Im bringing this one back 'home'. So in return, I plan to improve and shrink the function and update it for newer PHP versions - maybe even utilize new functions.
It clearly needs a lot of work, and here will just be the updates and process along.
Original code:
For example, this:
.=
These days are not PHP 4 anymore - so we do not need to append variables. We create a empty variable and check it along the way properly.
It clearly needs a lot of work, and here will just be the updates and process along.
Original code:
function pager($rpp, $count, $href, $opts = array()) {
$pages = ceil($count / $rpp);
if (!$opts["lastpagedefault"])
$pagedefault = 0;
else {
$pagedefault = floor(($count - 1) / $rpp);
if ($pagedefault < 0)
$pagedefault = 0;
}
if (isset($_GET["page"])) {
$page = (int) $_GET["page"];
if ($page < 0)
$page = $pagedefault;
}
else
$page = $pagedefault;
$pager = "";
$mp = $pages - 1;
$as = "<b><< ".T_("PREVIOUS")."</b>";
if ($page >= 1) {
$pager .= "<a href=\"{$href}page=" . ($page - 1) . "\">";
$pager .= $as;
$pager .= "</a>";
}
else
$pager .= $as;
$pager .= " ";
$as = "<b>".T_("NEXT")." >></b>";
if ($page < $mp && $mp >= 0) {
$pager .= "<a href=\"{$href}page=" . ($page + 1) . "\">";
$pager .= $as;
$pager .= "</a>";
}
else
$pager .= $as;
if ($count) {
$pagerarr = array();
$dotted = 0;
$dotspace = 3;
$dotend = $pages - $dotspace;
$curdotend = $page - $dotspace;
$curdotstart = $page + $dotspace;
for ($i = 0; $i < $pages; $i++) {
if (($i >= $dotspace && $i <= $curdotend) || ($i >= $curdotstart && $i < $dotend)) {
if (!$dotted)
$pagerarr[] = "...";
$dotted = 1;
continue;
}
$dotted = 0;
$start = $i * $rpp + 1;
$end = $start + $rpp - 1;
if ($end > $count)
$end = $count;
$text = "$start - $end";
if ($i != $page)
$pagerarr[] = "<a href=\"{$href}page=$i\"><b>$text</b></a>";
else
$pagerarr[] = "<b>$text</b>";
}
$pagerstr = join(" | ", $pagerarr);
$pagertop = "<p align=\"center\">$pager<br />$pagerstr</p>\n";
$pagerbottom = "<p align=\"center\">$pagerstr<br />$pager</p>\n";
}
else {
$pagertop = "<p align=\"center\">$pager</p>\n";
$pagerbottom = $pagertop;
}
$start = $page * $rpp;
return array($pagertop, $pagerbottom, "LIMIT $start,$rpp");
}
For example, this:
.=
These days are not PHP 4 anymore - so we do not need to append variables. We create a empty variable and check it along the way properly.
Last edited by STorrents2020 on 2021-09-02 20:17:57